@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.
- package/dist/align/align.cjs +38 -19
- package/dist/align/align.d.cts +12 -1
- package/dist/align/align.d.ts +12 -1
- package/dist/align/align.js +38 -19
- package/dist/align/ctc/Aligner.cjs +800 -0
- package/dist/align/ctc/Aligner.d.cts +56 -0
- package/dist/align/ctc/Aligner.d.ts +56 -0
- package/dist/align/ctc/Aligner.js +789 -0
- package/dist/align/ctc/align.cjs +189 -0
- package/dist/align/ctc/align.d.cts +14 -0
- package/dist/align/ctc/align.d.ts +14 -0
- package/dist/align/ctc/align.js +132 -0
- package/dist/{process/mime.cjs → align/ctc/emissions.cjs} +7 -20
- package/dist/align/ctc/emissions.d.cts +6 -0
- package/dist/align/ctc/emissions.d.ts +6 -0
- package/dist/align/ctc/emissions.js +7 -0
- package/dist/align/ctc/forcedAlign.cjs +273 -0
- package/dist/align/ctc/forcedAlign.d.cts +21 -0
- package/dist/align/ctc/forcedAlign.d.ts +21 -0
- package/dist/align/ctc/forcedAlign.js +248 -0
- package/dist/align/ctc/greedyDecode.cjs +61 -0
- package/dist/align/ctc/greedyDecode.d.cts +15 -0
- package/dist/align/ctc/greedyDecode.d.ts +15 -0
- package/dist/align/ctc/greedyDecode.js +37 -0
- package/dist/align/ctc/mediaOverlay.cjs +248 -0
- package/dist/align/ctc/mediaOverlay.d.cts +16 -0
- package/dist/align/ctc/mediaOverlay.d.ts +16 -0
- package/dist/align/ctc/mediaOverlay.js +224 -0
- package/dist/align/ctc/report.cjs +66 -0
- package/dist/align/ctc/report.d.cts +79 -0
- package/dist/align/ctc/report.d.ts +79 -0
- package/dist/align/ctc/report.js +42 -0
- package/dist/align/ctc/search.cjs +437 -0
- package/dist/align/ctc/search.d.cts +46 -0
- package/dist/align/ctc/search.d.ts +46 -0
- package/dist/align/ctc/search.js +412 -0
- package/dist/align/getSentenceRanges.cjs +9 -3
- package/dist/align/getSentenceRanges.d.cts +1 -0
- package/dist/align/getSentenceRanges.d.ts +1 -0
- package/dist/align/getSentenceRanges.js +9 -3
- package/dist/align/parse.cjs +17 -4
- package/dist/align/parse.d.cts +8 -4
- package/dist/align/parse.d.ts +8 -4
- package/dist/align/parse.js +19 -4
- package/dist/align/search.cjs +76 -23
- package/dist/align/search.d.cts +8 -4
- package/dist/align/search.d.ts +8 -4
- package/dist/align/search.js +76 -24
- package/dist/align/slugify.cjs +3 -2
- package/dist/align/slugify.d.cts +1 -1
- package/dist/align/slugify.d.ts +1 -1
- package/dist/align/slugify.js +3 -2
- package/dist/cli/bin.cjs +204 -114
- package/dist/cli/bin.js +194 -103
- package/dist/common/ffmpeg.cjs +10 -5
- package/dist/common/ffmpeg.js +10 -5
- package/dist/common/logging.cjs +33 -1
- package/dist/common/logging.js +33 -1
- package/dist/emit/emit.cjs +105 -0
- package/dist/emit/emit.d.cts +15 -0
- package/dist/emit/emit.d.ts +15 -0
- package/dist/emit/emit.js +86 -0
- package/dist/emit/fs.cjs +227 -0
- package/dist/emit/fs.d.cts +22 -0
- package/dist/emit/fs.d.ts +22 -0
- package/dist/emit/fs.js +162 -0
- package/dist/emit/parse.cjs +68 -0
- package/dist/emit/parse.d.cts +26 -0
- package/dist/emit/parse.d.ts +26 -0
- package/dist/emit/parse.js +58 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/markup/model.cjs +0 -16
- package/dist/markup/model.d.cts +1 -1
- package/dist/markup/model.d.ts +1 -1
- package/dist/markup/model.js +0 -12
- package/dist/markup/parseDom.cjs +13 -14
- package/dist/markup/parseDom.d.cts +2 -2
- package/dist/markup/parseDom.d.ts +2 -2
- package/dist/markup/parseDom.js +13 -18
- package/dist/markup/resolvedPos.d.cts +1 -1
- package/dist/markup/resolvedPos.d.ts +1 -1
- package/dist/markup/segmentation.cjs +3 -1
- package/dist/markup/segmentation.js +3 -1
- package/dist/markup/serializeDom.cjs +1 -1
- package/dist/markup/serializeDom.d.cts +1 -1
- package/dist/markup/serializeDom.d.ts +1 -1
- package/dist/markup/serializeDom.js +1 -1
- package/dist/markup/transform.cjs +5 -2
- package/dist/markup/transform.d.cts +1 -1
- package/dist/markup/transform.d.ts +1 -1
- package/dist/markup/transform.js +5 -4
- package/dist/{model-CZ2mMHJO.d.cts → model-CeOMDDgt.d.cts} +3 -11
- package/dist/{model-CZ2mMHJO.d.ts → model-CeOMDDgt.d.ts} +3 -11
- package/dist/process/processAudiobook.cjs +12 -23
- package/dist/process/processAudiobook.js +14 -30
- package/dist/process/ranges.cjs +2 -2
- package/dist/process/ranges.js +2 -2
- package/dist/readium/guidedNavigation.cjs +8 -8
- package/dist/readium/guidedNavigation.js +8 -8
- package/dist/readium/manifest.cjs +5 -4
- package/dist/readium/manifest.js +5 -4
- package/dist/snapshot/ctc/snapshot.cjs +261 -0
- package/dist/snapshot/ctc/snapshot.d.cts +6 -0
- package/dist/snapshot/ctc/snapshot.d.ts +6 -0
- package/dist/snapshot/ctc/snapshot.js +200 -0
- package/dist/snapshot/parse.cjs +29 -16
- package/dist/snapshot/parse.d.cts +14 -10
- package/dist/snapshot/parse.d.ts +14 -10
- package/dist/snapshot/parse.js +32 -17
- package/dist/transcribe/parse.d.cts +6 -6
- package/dist/transcribe/parse.d.ts +6 -6
- package/dist/transcribe/transcribe.cjs +4 -2
- package/dist/transcribe/transcribe.js +4 -2
- package/package.json +6 -4
- package/dist/process/mime.d.cts +0 -3
- package/dist/process/mime.d.ts +0 -3
- package/dist/process/mime.js +0 -24
package/dist/align/search.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
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
|
|
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 + (
|
|
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
|
-
|
|
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) /
|
|
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
|
|
109
|
-
const boundaryVotes = collectBoundaryVotes(
|
|
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:
|
|
124
|
-
end:
|
|
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
|
});
|
package/dist/align/search.d.cts
CHANGED
|
@@ -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 };
|
package/dist/align/search.d.ts
CHANGED
|
@@ -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 };
|
package/dist/align/search.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "../chunk-BIEQXUOY.js";
|
|
2
|
-
import { max, min, range } from "itertools";
|
|
3
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
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
|
|
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 + (
|
|
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
|
-
|
|
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) /
|
|
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
|
|
84
|
-
const boundaryVotes = collectBoundaryVotes(
|
|
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:
|
|
99
|
-
end:
|
|
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
|
};
|
package/dist/align/slugify.cjs
CHANGED
|
@@ -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
|
}
|
package/dist/align/slugify.d.cts
CHANGED
|
@@ -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
|
}>;
|
package/dist/align/slugify.d.ts
CHANGED
|
@@ -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
|
}>;
|
package/dist/align/slugify.js
CHANGED
|
@@ -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
|
}
|