@knaw-huc/text-annotation-segmenter 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,13 +35,14 @@ annotation bc: __
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import {
|
|
38
|
+
import {segment} from "@knaw-huc/text-annotation-segmenter";
|
|
39
39
|
|
|
40
40
|
const text = 'abc';
|
|
41
41
|
const ab = {id: 'ab', begin: 0, end: 2};
|
|
42
42
|
const bc = {id: 'bc', begin: 1, end: 3};
|
|
43
43
|
|
|
44
|
-
const
|
|
44
|
+
const getOffsets = annotation => annotation;
|
|
45
|
+
const segments = segment(text, [ab, bc], getOffsets);
|
|
45
46
|
|
|
46
47
|
expect(segments).toEqual([
|
|
47
48
|
{index: 0, begin: 0, end: 1, body: 'a', annotations: [ab]},
|
|
@@ -69,7 +70,8 @@ const text = 'aabb';
|
|
|
69
70
|
const section = {id: 'section', type: 'section', begin: 0, end: 4};
|
|
70
71
|
const paragraph = {id: 'paragraph', type: 'paragraph', begin: 0, end: 2};
|
|
71
72
|
|
|
72
|
-
const
|
|
73
|
+
const getOffsets = annotation => annotation;
|
|
74
|
+
const segments = segment(text, [section, paragraph], getOffsets);
|
|
73
75
|
|
|
74
76
|
const isGroup = a => a.type === 'section' || a.type === 'paragraph';
|
|
75
77
|
const getId = a => a.id;
|
package/dist/index.js
CHANGED
|
@@ -29,23 +29,23 @@ function segment(text, annotations, getOffsets) {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
lastOffset = offset.charIndex;
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (const annotation of offset.ending)
|
|
37
|
-
activeAnnotations.delete(annotation);
|
|
38
|
-
if (hasMarkers) {
|
|
39
|
-
markerSegmentAnnotations.push(...activeAnnotations);
|
|
32
|
+
const markers = [];
|
|
33
|
+
for (const annotation of offset.starting)
|
|
34
|
+
offset.ending.includes(annotation) && markers.push(annotation);
|
|
35
|
+
if (markers.length) {
|
|
40
36
|
const index = ++segmentCounter;
|
|
41
37
|
segments.push({
|
|
42
38
|
index,
|
|
43
39
|
begin: offset.charIndex,
|
|
44
40
|
end: offset.charIndex,
|
|
45
41
|
body: "",
|
|
46
|
-
annotations:
|
|
42
|
+
annotations: [...markers, ...activeAnnotations]
|
|
47
43
|
});
|
|
48
44
|
}
|
|
45
|
+
for (const annotation of offset.starting)
|
|
46
|
+
offset.ending.includes(annotation) || activeAnnotations.add(annotation);
|
|
47
|
+
for (const annotation of offset.ending)
|
|
48
|
+
activeAnnotations.delete(annotation);
|
|
49
49
|
}
|
|
50
50
|
return segments;
|
|
51
51
|
}
|