-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-passages.js
43 lines (39 loc) · 1.04 KB
/
parse-passages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Converts a data file with aligned passages to two sets of
* W3C Web Annotations.
*/
function parseAlignedPassages(passage_data) {
// Helper to convert a passage data record to WebAnno
function toAnnotation(id, passage) {
return {
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": id,
"type": "Annotation",
"body": [{
"type": "TextualBody",
"value": passage.text
}],
"target": {
"selector": [{
"type": "TextQuoteSelector",
"exact": passage.text
},{
"type": "TextPositionSelector",
"start": passage.start,
"end": passage.end
}]
}
}
}
// Maps the left passage side to WebAnno
var left = passage_data.map(function(pair, idx) {
var id = 'left_' + idx;
return toAnnotation(id, pair.a)
});
// Maps the right passage side to WebAnno
var right = passage_data.map(function(pair, idx) {
var id = 'right_' + idx;
return toAnnotation(id, pair.b);
});
return { left, right };
}