-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from w3c/tripu/metadata
Add method for metadata extraction
- Loading branch information
Showing
22 changed files
with
3,865 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Pseudo-profile for metadata extraction. | ||
*/ | ||
|
||
exports.name = 'Metadata'; | ||
|
||
exports.rules = [ | ||
require('../rules/metadata/profile') | ||
, require('../rules/metadata/deliverers') | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Pseudo-rule for metadata extraction: deliverers' IDs. | ||
*/ | ||
|
||
// Settings: | ||
const REGEX_DELIVERER_URL = /^((https?:)?\/\/)?(www\.)?w3\.org\/2004\/01\/pp-impl\/\d+\/status(#.*)?$/i | ||
, REGEX_DELIVERER_TEXT = /^public\s+list\s+of\s+any\s+patent\s+disclosures(\s+\(.+\))?$/i | ||
, REGEX_DELIVERER_ID = /pp-impl\/(\d+)\/status/i | ||
; | ||
|
||
exports.name = 'metadata.deliverers'; | ||
|
||
exports.check = function(sr, done) { | ||
|
||
var ids = []; | ||
|
||
if (sr && sr.getSotDSection() && sr.getSotDSection().find('a[href]')) { | ||
|
||
sr.getSotDSection().find('a[href]').each(function() { | ||
|
||
var item = sr.$(this) | ||
, href = item.attr('href') | ||
, text = sr.norm(item.text()) | ||
, found = {} | ||
; | ||
|
||
if (REGEX_DELIVERER_URL.test(href) && REGEX_DELIVERER_TEXT.test(text)) { | ||
var id = REGEX_DELIVERER_ID.exec(href); | ||
if (id && id.length > 1 && !found[id[1]]) { | ||
found[id] = true; | ||
ids.push(parseInt(id[1], 10)); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
|
||
done({delivererIDs: ids}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Pseudo-rule for metadata extraction: profile. | ||
*/ | ||
|
||
// Settings: | ||
const SELECTOR_SUBTITLE = 'body div.head h2'; | ||
|
||
// Internal packages: | ||
const profiles = require('../../../public/data/profiles'); | ||
|
||
exports.name = 'metadata.profile'; | ||
|
||
exports.check = function(sr, done) { | ||
|
||
var candidate | ||
, track | ||
, profile | ||
, matchedLength = 0 | ||
, id | ||
, i | ||
, j | ||
; | ||
|
||
sr.$(SELECTOR_SUBTITLE).each(function() { | ||
candidate = sr.norm(sr.$(this).text()).toLowerCase(); | ||
i = 0; | ||
while (i < profiles.tracks.length) { | ||
track = profiles.tracks[i].profiles; | ||
j = 0; | ||
while (j < track.length) { | ||
profile = track[j]; | ||
if (-1 !== candidate.indexOf(profile.name.toLowerCase()) && matchedLength < profile.name.length) { | ||
id = profile.id; | ||
matchedLength = profile.name.length; | ||
} | ||
j++; | ||
} | ||
i++; | ||
} | ||
}); | ||
if (id) { | ||
done({profile: id}); | ||
} | ||
else { | ||
done(); | ||
} | ||
|
||
}; |
Oops, something went wrong.