@storyteller-platform/align 0.1.56 → 0.1.58

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.
Files changed (118) hide show
  1. package/dist/align/align.cjs +38 -19
  2. package/dist/align/align.d.cts +12 -1
  3. package/dist/align/align.d.ts +12 -1
  4. package/dist/align/align.js +38 -19
  5. package/dist/align/ctc/Aligner.cjs +800 -0
  6. package/dist/align/ctc/Aligner.d.cts +56 -0
  7. package/dist/align/ctc/Aligner.d.ts +56 -0
  8. package/dist/align/ctc/Aligner.js +789 -0
  9. package/dist/align/ctc/align.cjs +189 -0
  10. package/dist/align/ctc/align.d.cts +14 -0
  11. package/dist/align/ctc/align.d.ts +14 -0
  12. package/dist/align/ctc/align.js +132 -0
  13. package/dist/{process/mime.cjs → align/ctc/emissions.cjs} +7 -20
  14. package/dist/align/ctc/emissions.d.cts +6 -0
  15. package/dist/align/ctc/emissions.d.ts +6 -0
  16. package/dist/align/ctc/emissions.js +7 -0
  17. package/dist/align/ctc/forcedAlign.cjs +273 -0
  18. package/dist/align/ctc/forcedAlign.d.cts +21 -0
  19. package/dist/align/ctc/forcedAlign.d.ts +21 -0
  20. package/dist/align/ctc/forcedAlign.js +248 -0
  21. package/dist/align/ctc/greedyDecode.cjs +61 -0
  22. package/dist/align/ctc/greedyDecode.d.cts +15 -0
  23. package/dist/align/ctc/greedyDecode.d.ts +15 -0
  24. package/dist/align/ctc/greedyDecode.js +37 -0
  25. package/dist/align/ctc/mediaOverlay.cjs +248 -0
  26. package/dist/align/ctc/mediaOverlay.d.cts +16 -0
  27. package/dist/align/ctc/mediaOverlay.d.ts +16 -0
  28. package/dist/align/ctc/mediaOverlay.js +224 -0
  29. package/dist/align/ctc/report.cjs +66 -0
  30. package/dist/align/ctc/report.d.cts +79 -0
  31. package/dist/align/ctc/report.d.ts +79 -0
  32. package/dist/align/ctc/report.js +42 -0
  33. package/dist/align/ctc/search.cjs +437 -0
  34. package/dist/align/ctc/search.d.cts +46 -0
  35. package/dist/align/ctc/search.d.ts +46 -0
  36. package/dist/align/ctc/search.js +412 -0
  37. package/dist/align/getSentenceRanges.cjs +9 -3
  38. package/dist/align/getSentenceRanges.d.cts +1 -0
  39. package/dist/align/getSentenceRanges.d.ts +1 -0
  40. package/dist/align/getSentenceRanges.js +9 -3
  41. package/dist/align/parse.cjs +17 -4
  42. package/dist/align/parse.d.cts +8 -4
  43. package/dist/align/parse.d.ts +8 -4
  44. package/dist/align/parse.js +19 -4
  45. package/dist/align/search.cjs +76 -23
  46. package/dist/align/search.d.cts +8 -4
  47. package/dist/align/search.d.ts +8 -4
  48. package/dist/align/search.js +76 -24
  49. package/dist/align/slugify.cjs +3 -2
  50. package/dist/align/slugify.d.cts +1 -1
  51. package/dist/align/slugify.d.ts +1 -1
  52. package/dist/align/slugify.js +3 -2
  53. package/dist/cli/bin.cjs +204 -114
  54. package/dist/cli/bin.js +194 -103
  55. package/dist/common/ffmpeg.cjs +10 -5
  56. package/dist/common/ffmpeg.js +10 -5
  57. package/dist/common/logging.cjs +33 -1
  58. package/dist/common/logging.js +33 -1
  59. package/dist/emit/emit.cjs +105 -0
  60. package/dist/emit/emit.d.cts +15 -0
  61. package/dist/emit/emit.d.ts +15 -0
  62. package/dist/emit/emit.js +86 -0
  63. package/dist/emit/fs.cjs +227 -0
  64. package/dist/emit/fs.d.cts +22 -0
  65. package/dist/emit/fs.d.ts +22 -0
  66. package/dist/emit/fs.js +162 -0
  67. package/dist/emit/parse.cjs +68 -0
  68. package/dist/emit/parse.d.cts +26 -0
  69. package/dist/emit/parse.d.ts +26 -0
  70. package/dist/emit/parse.js +58 -0
  71. package/dist/index.d.cts +1 -1
  72. package/dist/index.d.ts +1 -1
  73. package/dist/markup/model.cjs +0 -16
  74. package/dist/markup/model.d.cts +1 -1
  75. package/dist/markup/model.d.ts +1 -1
  76. package/dist/markup/model.js +0 -12
  77. package/dist/markup/parseDom.cjs +13 -14
  78. package/dist/markup/parseDom.d.cts +2 -2
  79. package/dist/markup/parseDom.d.ts +2 -2
  80. package/dist/markup/parseDom.js +13 -18
  81. package/dist/markup/resolvedPos.d.cts +1 -1
  82. package/dist/markup/resolvedPos.d.ts +1 -1
  83. package/dist/markup/segmentation.cjs +3 -1
  84. package/dist/markup/segmentation.js +3 -1
  85. package/dist/markup/serializeDom.cjs +1 -1
  86. package/dist/markup/serializeDom.d.cts +1 -1
  87. package/dist/markup/serializeDom.d.ts +1 -1
  88. package/dist/markup/serializeDom.js +1 -1
  89. package/dist/markup/transform.cjs +5 -2
  90. package/dist/markup/transform.d.cts +1 -1
  91. package/dist/markup/transform.d.ts +1 -1
  92. package/dist/markup/transform.js +5 -4
  93. package/dist/{model-CZ2mMHJO.d.cts → model-CeOMDDgt.d.cts} +3 -11
  94. package/dist/{model-CZ2mMHJO.d.ts → model-CeOMDDgt.d.ts} +3 -11
  95. package/dist/process/processAudiobook.cjs +12 -23
  96. package/dist/process/processAudiobook.js +14 -30
  97. package/dist/process/ranges.cjs +2 -2
  98. package/dist/process/ranges.js +2 -2
  99. package/dist/readium/guidedNavigation.cjs +8 -8
  100. package/dist/readium/guidedNavigation.js +8 -8
  101. package/dist/readium/manifest.cjs +5 -4
  102. package/dist/readium/manifest.js +5 -4
  103. package/dist/snapshot/ctc/snapshot.cjs +261 -0
  104. package/dist/snapshot/ctc/snapshot.d.cts +6 -0
  105. package/dist/snapshot/ctc/snapshot.d.ts +6 -0
  106. package/dist/snapshot/ctc/snapshot.js +200 -0
  107. package/dist/snapshot/parse.cjs +29 -16
  108. package/dist/snapshot/parse.d.cts +14 -10
  109. package/dist/snapshot/parse.d.ts +14 -10
  110. package/dist/snapshot/parse.js +32 -17
  111. package/dist/transcribe/parse.d.cts +6 -6
  112. package/dist/transcribe/parse.d.ts +6 -6
  113. package/dist/transcribe/transcribe.cjs +4 -2
  114. package/dist/transcribe/transcribe.js +4 -2
  115. package/package.json +6 -4
  116. package/dist/process/mime.d.cts +0 -3
  117. package/dist/process/mime.d.ts +0 -3
  118. package/dist/process/mime.js +0 -24
@@ -21,13 +21,15 @@ __export(search_exports, {
21
21
  buildNgramIndex: () => buildNgramIndex,
22
22
  collectBoundaryVotes: () => collectBoundaryVotes,
23
23
  findBoundaries: () => findBoundaries,
24
+ findCtcBoundaries: () => findCtcBoundaries,
24
25
  ngrams: () => ngrams
25
26
  });
26
27
  module.exports = __toCommonJS(search_exports);
27
28
  var import_itertools = require("itertools");
28
- function buildNgramIndex(text) {
29
+ var import_mapping = require("@storyteller-platform/mapping");
30
+ function buildNgramIndex(text, ngramSize, gramDelimiter) {
29
31
  const index = /* @__PURE__ */ new Map();
30
- for (const [ngram, pos] of ngrams(text)) {
32
+ for (const [ngram, pos] of ngrams(text, ngramSize, gramDelimiter)) {
31
33
  const positions = index.get(ngram);
32
34
  if (positions) {
33
35
  positions.push(pos);
@@ -37,22 +39,21 @@ function buildNgramIndex(text) {
37
39
  }
38
40
  return index;
39
41
  }
40
- const NGRAM_SIZE = 5;
41
- function* ngrams(text) {
42
- const words = text.split("-");
43
- for (const i of (0, import_itertools.range)(words.length - NGRAM_SIZE - 1)) {
44
- const ngram = words.slice(i, i + NGRAM_SIZE).join("-");
42
+ function* ngrams(text, ngramSize, gramDelimiter) {
43
+ const grams = text.split(gramDelimiter);
44
+ for (const i of (0, import_itertools.range)(grams.length - ngramSize + 1)) {
45
+ const ngram = grams.slice(i, i + ngramSize).join(gramDelimiter);
45
46
  yield [ngram, i];
46
47
  }
47
48
  }
48
- function collectBoundaryVotes(query, document) {
49
- const queryWords = query.split("-");
50
- const documentIndex = buildNgramIndex(document);
49
+ function collectBoundaryVotes(query, document, ngramSize, gramDelimiter) {
50
+ const queryGrams = query.split(gramDelimiter);
51
+ const documentIndex = buildNgramIndex(document, ngramSize, gramDelimiter);
51
52
  let skippedNgrams = 0;
52
53
  let totalNgrams = 0;
53
54
  const startVotes = [];
54
55
  const endVotes = [];
55
- for (const [ngram, start] of ngrams(query)) {
56
+ for (const [ngram, start] of ngrams(query, ngramSize, gramDelimiter)) {
56
57
  totalNgrams++;
57
58
  const documentStarts = documentIndex.get(ngram);
58
59
  if (!documentStarts) {
@@ -61,7 +62,7 @@ function collectBoundaryVotes(query, document) {
61
62
  }
62
63
  for (const documentStart of documentStarts) {
63
64
  startVotes.push(documentStart - start);
64
- endVotes.push(documentStart + (queryWords.length - start));
65
+ endVotes.push(documentStart + (queryGrams.length - start));
65
66
  }
66
67
  }
67
68
  if (skippedNgrams > totalNgrams / 2) {
@@ -69,13 +70,12 @@ function collectBoundaryVotes(query, document) {
69
70
  }
70
71
  return { startVotes, endVotes };
71
72
  }
72
- const BIN_SIZE = 1e3;
73
- function binBoundaryVotes(votes) {
73
+ function binBoundaryVotes(votes, binSize) {
74
74
  const start = (0, import_itertools.min)(votes);
75
75
  const bins = /* @__PURE__ */ new Map();
76
76
  if (start === void 0) return bins;
77
77
  for (const vote of votes) {
78
- const binIndex = Math.floor((vote - start) / BIN_SIZE);
78
+ const binIndex = Math.floor((vote - start) / binSize);
79
79
  const bin = bins.get(binIndex);
80
80
  if (bin) {
81
81
  bin.push(vote);
@@ -97,31 +97,83 @@ function chooseBestFromBins(bins, dir) {
97
97
  }
98
98
  return dir > 0 ? (0, import_itertools.max)(best) ?? null : (0, import_itertools.min)(best) ?? null;
99
99
  }
100
- function getOffsetFromWordIndex(wordIndex, document) {
101
- const words = document.split("-");
100
+ function getOffsetFromWordIndex(wordIndex, document, gramDelimiter) {
101
+ const words = document.split(gramDelimiter);
102
102
  let offset = 0;
103
103
  for (const i of (0, import_itertools.range)(Math.min(words.length, Math.max(0, wordIndex)))) {
104
104
  offset += words[i].length + 1;
105
105
  }
106
106
  return offset;
107
107
  }
108
- function findBoundaries(query, document) {
109
- const boundaryVotes = collectBoundaryVotes(query, document);
108
+ function findBoundariesInternal(query, document, ngramSize, binSize, gramDelimiter) {
109
+ const boundaryVotes = collectBoundaryVotes(
110
+ query,
111
+ document,
112
+ ngramSize,
113
+ gramDelimiter
114
+ );
110
115
  if (!boundaryVotes) return null;
111
116
  const { startVotes, endVotes } = boundaryVotes;
112
- const startBins = binBoundaryVotes(startVotes);
117
+ const startBins = binBoundaryVotes(startVotes, binSize);
113
118
  const bestStart = chooseBestFromBins(startBins, -1);
114
119
  if (bestStart === null) {
115
120
  return null;
116
121
  }
117
- const endBins = binBoundaryVotes(endVotes);
122
+ const endBins = binBoundaryVotes(endVotes, binSize);
118
123
  const bestEnd = chooseBestFromBins(endBins, 1);
119
124
  if (bestEnd === null) {
120
125
  return null;
121
126
  }
127
+ return { bestStart, bestEnd };
128
+ }
129
+ function findBoundaries(query, document) {
130
+ const ngramSize = 5;
131
+ const binSize = 1e3;
132
+ const gramDelimiter = "-";
133
+ const result = findBoundariesInternal(
134
+ query,
135
+ document,
136
+ ngramSize,
137
+ binSize,
138
+ gramDelimiter
139
+ );
140
+ if (!result) return null;
141
+ const { bestStart, bestEnd } = result;
142
+ return {
143
+ start: getOffsetFromWordIndex(bestStart, document, gramDelimiter),
144
+ end: getOffsetFromWordIndex(bestEnd, document, gramDelimiter)
145
+ };
146
+ }
147
+ function smooshWords(input) {
148
+ const mapping = new import_mapping.Mapping();
149
+ let smooshed = "";
150
+ for (const [i, c] of (0, import_itertools.enumerate)(input)) {
151
+ if (c !== "-") {
152
+ smooshed += c;
153
+ continue;
154
+ }
155
+ mapping.insertMap(i, 1, 0);
156
+ }
157
+ return { smooshed, mapping };
158
+ }
159
+ function findCtcBoundaries(query, document) {
160
+ const ngramSize = 10;
161
+ const binSize = 5e3;
162
+ const gramDelimiter = "";
163
+ const { smooshed: smooshedQuery } = smooshWords(query);
164
+ const { smooshed: smooshedDocument, mapping: documentMapping } = smooshWords(document);
165
+ const result = findBoundariesInternal(
166
+ smooshedQuery,
167
+ smooshedDocument,
168
+ ngramSize,
169
+ binSize,
170
+ gramDelimiter
171
+ );
172
+ if (!result) return null;
173
+ const { bestStart, bestEnd } = result;
122
174
  return {
123
- start: getOffsetFromWordIndex(bestStart, document),
124
- end: getOffsetFromWordIndex(bestEnd, document)
175
+ start: documentMapping.cursor().map(Math.max(bestStart, 0), "start"),
176
+ end: documentMapping.cursor().map(Math.min(bestEnd, document.length - 1), "end")
125
177
  };
126
178
  }
127
179
  // Annotate the CommonJS export names for ESM import in node:
@@ -129,5 +181,6 @@ function findBoundaries(query, document) {
129
181
  buildNgramIndex,
130
182
  collectBoundaryVotes,
131
183
  findBoundaries,
184
+ findCtcBoundaries,
132
185
  ngrams
133
186
  });
@@ -1,6 +1,6 @@
1
- declare function buildNgramIndex(text: string): Map<string, number[]>;
2
- declare function ngrams(text: string): Generator<readonly [string, number], void, unknown>;
3
- declare function collectBoundaryVotes(query: string, document: string): {
1
+ declare function buildNgramIndex(text: string, ngramSize: number, gramDelimiter: string): Map<string, number[]>;
2
+ declare function ngrams(text: string, ngramSize: number, gramDelimiter: string): Generator<readonly [string, number], void, unknown>;
3
+ declare function collectBoundaryVotes(query: string, document: string, ngramSize: number, gramDelimiter: string): {
4
4
  startVotes: number[];
5
5
  endVotes: number[];
6
6
  } | null;
@@ -8,5 +8,9 @@ declare function findBoundaries(query: string, document: string): {
8
8
  start: number;
9
9
  end: number;
10
10
  } | null;
11
+ declare function findCtcBoundaries(query: string, document: string): {
12
+ start: number;
13
+ end: number;
14
+ } | null;
11
15
 
12
- export { buildNgramIndex, collectBoundaryVotes, findBoundaries, ngrams };
16
+ export { buildNgramIndex, collectBoundaryVotes, findBoundaries, findCtcBoundaries, ngrams };
@@ -1,6 +1,6 @@
1
- declare function buildNgramIndex(text: string): Map<string, number[]>;
2
- declare function ngrams(text: string): Generator<readonly [string, number], void, unknown>;
3
- declare function collectBoundaryVotes(query: string, document: string): {
1
+ declare function buildNgramIndex(text: string, ngramSize: number, gramDelimiter: string): Map<string, number[]>;
2
+ declare function ngrams(text: string, ngramSize: number, gramDelimiter: string): Generator<readonly [string, number], void, unknown>;
3
+ declare function collectBoundaryVotes(query: string, document: string, ngramSize: number, gramDelimiter: string): {
4
4
  startVotes: number[];
5
5
  endVotes: number[];
6
6
  } | null;
@@ -8,5 +8,9 @@ declare function findBoundaries(query: string, document: string): {
8
8
  start: number;
9
9
  end: number;
10
10
  } | null;
11
+ declare function findCtcBoundaries(query: string, document: string): {
12
+ start: number;
13
+ end: number;
14
+ } | null;
11
15
 
12
- export { buildNgramIndex, collectBoundaryVotes, findBoundaries, ngrams };
16
+ export { buildNgramIndex, collectBoundaryVotes, findBoundaries, findCtcBoundaries, ngrams };
@@ -1,8 +1,9 @@
1
1
  import "../chunk-BIEQXUOY.js";
2
- import { max, min, range } from "itertools";
3
- function buildNgramIndex(text) {
2
+ import { enumerate, max, min, range } from "itertools";
3
+ import { Mapping } from "@storyteller-platform/mapping";
4
+ function buildNgramIndex(text, ngramSize, gramDelimiter) {
4
5
  const index = /* @__PURE__ */ new Map();
5
- for (const [ngram, pos] of ngrams(text)) {
6
+ for (const [ngram, pos] of ngrams(text, ngramSize, gramDelimiter)) {
6
7
  const positions = index.get(ngram);
7
8
  if (positions) {
8
9
  positions.push(pos);
@@ -12,22 +13,21 @@ function buildNgramIndex(text) {
12
13
  }
13
14
  return index;
14
15
  }
15
- const NGRAM_SIZE = 5;
16
- function* ngrams(text) {
17
- const words = text.split("-");
18
- for (const i of range(words.length - NGRAM_SIZE - 1)) {
19
- const ngram = words.slice(i, i + NGRAM_SIZE).join("-");
16
+ function* ngrams(text, ngramSize, gramDelimiter) {
17
+ const grams = text.split(gramDelimiter);
18
+ for (const i of range(grams.length - ngramSize + 1)) {
19
+ const ngram = grams.slice(i, i + ngramSize).join(gramDelimiter);
20
20
  yield [ngram, i];
21
21
  }
22
22
  }
23
- function collectBoundaryVotes(query, document) {
24
- const queryWords = query.split("-");
25
- const documentIndex = buildNgramIndex(document);
23
+ function collectBoundaryVotes(query, document, ngramSize, gramDelimiter) {
24
+ const queryGrams = query.split(gramDelimiter);
25
+ const documentIndex = buildNgramIndex(document, ngramSize, gramDelimiter);
26
26
  let skippedNgrams = 0;
27
27
  let totalNgrams = 0;
28
28
  const startVotes = [];
29
29
  const endVotes = [];
30
- for (const [ngram, start] of ngrams(query)) {
30
+ for (const [ngram, start] of ngrams(query, ngramSize, gramDelimiter)) {
31
31
  totalNgrams++;
32
32
  const documentStarts = documentIndex.get(ngram);
33
33
  if (!documentStarts) {
@@ -36,7 +36,7 @@ function collectBoundaryVotes(query, document) {
36
36
  }
37
37
  for (const documentStart of documentStarts) {
38
38
  startVotes.push(documentStart - start);
39
- endVotes.push(documentStart + (queryWords.length - start));
39
+ endVotes.push(documentStart + (queryGrams.length - start));
40
40
  }
41
41
  }
42
42
  if (skippedNgrams > totalNgrams / 2) {
@@ -44,13 +44,12 @@ function collectBoundaryVotes(query, document) {
44
44
  }
45
45
  return { startVotes, endVotes };
46
46
  }
47
- const BIN_SIZE = 1e3;
48
- function binBoundaryVotes(votes) {
47
+ function binBoundaryVotes(votes, binSize) {
49
48
  const start = min(votes);
50
49
  const bins = /* @__PURE__ */ new Map();
51
50
  if (start === void 0) return bins;
52
51
  for (const vote of votes) {
53
- const binIndex = Math.floor((vote - start) / BIN_SIZE);
52
+ const binIndex = Math.floor((vote - start) / binSize);
54
53
  const bin = bins.get(binIndex);
55
54
  if (bin) {
56
55
  bin.push(vote);
@@ -72,36 +71,89 @@ function chooseBestFromBins(bins, dir) {
72
71
  }
73
72
  return dir > 0 ? max(best) ?? null : min(best) ?? null;
74
73
  }
75
- function getOffsetFromWordIndex(wordIndex, document) {
76
- const words = document.split("-");
74
+ function getOffsetFromWordIndex(wordIndex, document, gramDelimiter) {
75
+ const words = document.split(gramDelimiter);
77
76
  let offset = 0;
78
77
  for (const i of range(Math.min(words.length, Math.max(0, wordIndex)))) {
79
78
  offset += words[i].length + 1;
80
79
  }
81
80
  return offset;
82
81
  }
83
- function findBoundaries(query, document) {
84
- const boundaryVotes = collectBoundaryVotes(query, document);
82
+ function findBoundariesInternal(query, document, ngramSize, binSize, gramDelimiter) {
83
+ const boundaryVotes = collectBoundaryVotes(
84
+ query,
85
+ document,
86
+ ngramSize,
87
+ gramDelimiter
88
+ );
85
89
  if (!boundaryVotes) return null;
86
90
  const { startVotes, endVotes } = boundaryVotes;
87
- const startBins = binBoundaryVotes(startVotes);
91
+ const startBins = binBoundaryVotes(startVotes, binSize);
88
92
  const bestStart = chooseBestFromBins(startBins, -1);
89
93
  if (bestStart === null) {
90
94
  return null;
91
95
  }
92
- const endBins = binBoundaryVotes(endVotes);
96
+ const endBins = binBoundaryVotes(endVotes, binSize);
93
97
  const bestEnd = chooseBestFromBins(endBins, 1);
94
98
  if (bestEnd === null) {
95
99
  return null;
96
100
  }
101
+ return { bestStart, bestEnd };
102
+ }
103
+ function findBoundaries(query, document) {
104
+ const ngramSize = 5;
105
+ const binSize = 1e3;
106
+ const gramDelimiter = "-";
107
+ const result = findBoundariesInternal(
108
+ query,
109
+ document,
110
+ ngramSize,
111
+ binSize,
112
+ gramDelimiter
113
+ );
114
+ if (!result) return null;
115
+ const { bestStart, bestEnd } = result;
116
+ return {
117
+ start: getOffsetFromWordIndex(bestStart, document, gramDelimiter),
118
+ end: getOffsetFromWordIndex(bestEnd, document, gramDelimiter)
119
+ };
120
+ }
121
+ function smooshWords(input) {
122
+ const mapping = new Mapping();
123
+ let smooshed = "";
124
+ for (const [i, c] of enumerate(input)) {
125
+ if (c !== "-") {
126
+ smooshed += c;
127
+ continue;
128
+ }
129
+ mapping.insertMap(i, 1, 0);
130
+ }
131
+ return { smooshed, mapping };
132
+ }
133
+ function findCtcBoundaries(query, document) {
134
+ const ngramSize = 10;
135
+ const binSize = 5e3;
136
+ const gramDelimiter = "";
137
+ const { smooshed: smooshedQuery } = smooshWords(query);
138
+ const { smooshed: smooshedDocument, mapping: documentMapping } = smooshWords(document);
139
+ const result = findBoundariesInternal(
140
+ smooshedQuery,
141
+ smooshedDocument,
142
+ ngramSize,
143
+ binSize,
144
+ gramDelimiter
145
+ );
146
+ if (!result) return null;
147
+ const { bestStart, bestEnd } = result;
97
148
  return {
98
- start: getOffsetFromWordIndex(bestStart, document),
99
- end: getOffsetFromWordIndex(bestEnd, document)
149
+ start: documentMapping.cursor().map(Math.max(bestStart, 0), "start"),
150
+ end: documentMapping.cursor().map(Math.min(bestEnd, document.length - 1), "end")
100
151
  };
101
152
  }
102
153
  export {
103
154
  buildNgramIndex,
104
155
  collectBoundaryVotes,
105
156
  findBoundaries,
157
+ findCtcBoundaries,
106
158
  ngrams
107
159
  };
@@ -128,13 +128,14 @@ function createReplacers(locale) {
128
128
  [numberRegex, numberReplacer]
129
129
  ];
130
130
  }
131
- async function slugify(text, locale) {
131
+ async function slugify(text, locale, separator = "-") {
132
132
  const replacers = replacerMap.get(locale) ?? createReplacers(locale);
133
133
  replacerMap.set(locale, replacers);
134
134
  const { result, mapping } = await (0, import_transliteration.slugify)(text, {
135
135
  allowedChars: "a-zA-Z0-9",
136
136
  locale,
137
- replace: replacers
137
+ replace: replacers,
138
+ separator
138
139
  });
139
140
  return { result, mapping };
140
141
  }
@@ -1,6 +1,6 @@
1
1
  import * as _storyteller_platform_mapping from '@storyteller-platform/mapping';
2
2
 
3
- declare function slugify(text: string, locale: Intl.Locale): Promise<{
3
+ declare function slugify(text: string, locale: Intl.Locale, separator?: string): Promise<{
4
4
  result: string;
5
5
  mapping: _storyteller_platform_mapping.Mapping;
6
6
  }>;
@@ -1,6 +1,6 @@
1
1
  import * as _storyteller_platform_mapping from '@storyteller-platform/mapping';
2
2
 
3
- declare function slugify(text: string, locale: Intl.Locale): Promise<{
3
+ declare function slugify(text: string, locale: Intl.Locale, separator?: string): Promise<{
4
4
  result: string;
5
5
  mapping: _storyteller_platform_mapping.Mapping;
6
6
  }>;
@@ -106,13 +106,14 @@ function createReplacers(locale) {
106
106
  [numberRegex, numberReplacer]
107
107
  ];
108
108
  }
109
- async function slugify(text, locale) {
109
+ async function slugify(text, locale, separator = "-") {
110
110
  const replacers = replacerMap.get(locale) ?? createReplacers(locale);
111
111
  replacerMap.set(locale, replacers);
112
112
  const { result, mapping } = await transliterateSlugify(text, {
113
113
  allowedChars: "a-zA-Z0-9",
114
114
  locale,
115
- replace: replacers
115
+ replace: replacers,
116
+ separator
116
117
  });
117
118
  return { result, mapping };
118
119
  }