@knaw-huc/text-annotation-segmenter 0.6.0 → 0.7.0

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/dist/Model.d.ts CHANGED
@@ -14,7 +14,6 @@ export type TextSegment<T> = TextPosition & {
14
14
  annotations: T[];
15
15
  };
16
16
  export type SegmentIndex = number;
17
- export type MarkerPosition = 'prefix' | 'postfix';
18
17
  /**
19
18
  * Start and end segment index of an annotation, excluding last segment
20
19
  */
package/dist/index.d.ts CHANGED
@@ -4,6 +4,5 @@ export { findSegmentRange } from './findSegmentRange.ts';
4
4
  export { groupSegments } from './groupSegments.ts';
5
5
  export { collectGroupSegments } from './collectGroupSegments.ts';
6
6
  export type { Group, SegmentGroup } from './groupSegments.ts';
7
- export type { TextPosition, TextSegment, SegmentIndex, MarkerPosition, SegmentRange } from './Model.ts';
7
+ export type { TextPosition, TextSegment, SegmentIndex, SegmentRange } from './Model.ts';
8
8
  export type { GetOffsets } from './GetOffsets.ts';
9
- export type { GetMarkerPosition } from './GetMarkerPosition.ts';
package/dist/index.js CHANGED
@@ -1,16 +1,10 @@
1
- function segment(text, annotations, getOffsets, getMarkerPosition = () => "postfix") {
1
+ function segment(text, annotations, getOffsets) {
2
2
  const segments = [];
3
3
  let segmentCounter = -1;
4
4
  const offsetMap = /* @__PURE__ */ new Map(), getOrCreateOffset = (charIndex) => {
5
5
  let offset = offsetMap.get(charIndex);
6
6
  return offset || (offset = { charIndex, starting: [], ending: [] }, offsetMap.set(charIndex, offset)), offset;
7
- }, createMarkerSegment = (markers, charIndex) => ({
8
- index: ++segmentCounter,
9
- start: charIndex,
10
- end: charIndex,
11
- value: "",
12
- annotations: [...markers, ...activeAnnotations]
13
- });
7
+ };
14
8
  getOrCreateOffset(0), getOrCreateOffset(text.length);
15
9
  for (const annotation of annotations) {
16
10
  const offsets = getOffsets(annotation), isMarker = offsets.start === offsets.end;
@@ -35,15 +29,18 @@ function segment(text, annotations, getOffsets, getMarkerPosition = () => "postf
35
29
  });
36
30
  }
37
31
  lastOffset = offset.charIndex;
38
- const postfixMarkers = [], prefixMarkers = [];
39
- for (const annotation of offset.starting)
40
- offset.ending.includes(annotation) && (getMarkerPosition(annotation) === "prefix" ? prefixMarkers.push(annotation) : postfixMarkers.push(annotation));
41
- postfixMarkers.length && segments.push(createMarkerSegment(postfixMarkers, offset.charIndex));
32
+ const markers = [];
42
33
  for (const annotation of offset.starting)
43
- offset.ending.includes(annotation) || activeAnnotations.add(annotation);
34
+ offset.ending.includes(annotation) ? markers.push(annotation) : activeAnnotations.add(annotation);
35
+ markers.length && segments.push({
36
+ index: ++segmentCounter,
37
+ start: offset.charIndex,
38
+ end: offset.charIndex,
39
+ value: "",
40
+ annotations: [...markers, ...activeAnnotations]
41
+ });
44
42
  for (const annotation of offset.ending)
45
43
  activeAnnotations.delete(annotation);
46
- prefixMarkers.length && segments.push(createMarkerSegment(prefixMarkers, offset.charIndex));
47
44
  }
48
45
  return segments;
49
46
  }
package/dist/segment.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { TextSegment } from './Model';
2
2
  import { GetOffsets } from './GetOffsets.ts';
3
- import { GetMarkerPosition } from './GetMarkerPosition.ts';
4
3
  /**
5
4
  * Split a text into {@link TextSegment}s with character offsets and a list of applying annotations.
6
5
  *
@@ -10,19 +9,10 @@ import { GetMarkerPosition } from './GetMarkerPosition.ts';
10
9
  *
11
10
  * @param getOffsets Find the character begin and end index of an annotation
12
11
  *
13
- * @param getMarkerPosition Should a marker segment be prefixed or postfixed?
14
- * - 'prefix': include annotations that start at marker offset
15
- * - 'postfix': include annotations that end at marker offset
16
- *
17
- * For example, consider two paragraphs: <p1>aa</p1><marker/><p2>bb</p2>
18
- * The annotation <marker/> shares the end character index with annotation <p1>,
19
- * and the begin character index with annotation <p2>:
20
- * - with 'postfix': segment (2,2) will contain annotations [marker, p1]
21
- * - with 'prefix': segment (2,2) will contain annotations [marker, p2]
22
- *
23
- * By default, markers are postfixed.
12
+ * Marker segments include all annotations present at that position:
13
+ * ending, spanning, and starting. Consumers can filter these as needed.
24
14
  */
25
- export declare function segment<T>(text: string, annotations: T[], getOffsets: GetOffsets<T>, getMarkerPosition?: GetMarkerPosition<T>): TextSegment<T>[];
15
+ export declare function segment<T>(text: string, annotations: T[], getOffsets: GetOffsets<T>): TextSegment<T>[];
26
16
  export type AnnotationSegmentsByChar<T> = {
27
17
  charIndex: number;
28
18
  starting: T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knaw-huc/text-annotation-segmenter",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/knaw-huc/text-annotation-segmenter.git"
@@ -1,2 +0,0 @@
1
- import { MarkerPosition } from './Model.ts';
2
- export type GetMarkerPosition<T> = (a: T) => MarkerPosition;