@mailwoman/core 6.5.0 → 7.1.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/README.md +0 -1
- package/out/decoder/containment.d.ts +1 -1
- package/out/decoder/index.d.ts +0 -1
- package/out/decoder/index.d.ts.map +1 -1
- package/out/decoder/index.js +0 -1
- package/out/decoder/index.js.map +1 -1
- package/out/index.d.ts +0 -3
- package/out/index.d.ts.map +1 -1
- package/out/index.js +0 -3
- package/out/index.js.map +1 -1
- package/out/pipeline/runtime-pipeline.d.ts.map +1 -1
- package/out/pipeline/runtime-pipeline.js +0 -29
- package/out/pipeline/runtime-pipeline.js.map +1 -1
- package/out/pipeline/types.d.ts +1 -16
- package/out/pipeline/types.d.ts.map +1 -1
- package/out/pipeline/types.js.map +1 -1
- package/out/policy/index.d.ts +1 -2
- package/out/policy/index.d.ts.map +1 -1
- package/out/policy/index.js +1 -2
- package/out/policy/index.js.map +1 -1
- package/out/policy/proposal-collection.d.ts +33 -0
- package/out/policy/proposal-collection.d.ts.map +1 -0
- package/out/policy/proposal-collection.js +47 -0
- package/out/policy/proposal-collection.js.map +1 -0
- package/out/resources/collections.d.ts +0 -5
- package/out/resources/collections.d.ts.map +1 -1
- package/out/resources/collections.js +0 -8
- package/out/resources/collections.js.map +1 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +5 -9
- package/out/resources/git.js.map +1 -1
- package/out/resources/libpostal.d.ts +3 -3
- package/out/resources/libpostal.js +3 -3
- package/out/tokenization/Span.d.ts +1 -1
- package/out/tokenization/Span.d.ts.map +1 -1
- package/out/tokenization/Span.js +1 -1
- package/out/tokenization/Span.js.map +1 -1
- package/out/tokenization/index.d.ts +0 -2
- package/out/tokenization/index.d.ts.map +1 -1
- package/out/tokenization/index.js +0 -2
- package/out/tokenization/index.js.map +1 -1
- package/out/{classification → types}/Classification.d.ts +2 -2
- package/out/types/Classification.d.ts.map +1 -0
- package/out/types/Classification.js.map +1 -0
- package/out/types/classifier.d.ts +3 -3
- package/out/types/classifier.js +3 -3
- package/out/types/component.d.ts +1 -1
- package/out/types/index.d.ts +1 -0
- package/out/types/index.d.ts.map +1 -1
- package/out/types/index.js +1 -0
- package/out/types/index.js.map +1 -1
- package/out/types/mapping.d.ts +1 -1
- package/out/types/mapping.d.ts.map +1 -1
- package/out/utils/python-json.d.ts +2 -2
- package/out/utils/python-json.js +2 -2
- package/out/vitest.config.d.ts +4 -2
- package/out/vitest.config.d.ts.map +1 -1
- package/out/vitest.config.js +11 -7
- package/out/vitest.config.js.map +1 -1
- package/package.json +3 -51
- package/out/classification/BaseClassifier.d.ts +0 -38
- package/out/classification/BaseClassifier.d.ts.map +0 -1
- package/out/classification/BaseClassifier.js +0 -12
- package/out/classification/BaseClassifier.js.map +0 -1
- package/out/classification/Classification.d.ts.map +0 -1
- package/out/classification/Classification.js.map +0 -1
- package/out/classification/CompositeClassifier.d.ts +0 -16
- package/out/classification/CompositeClassifier.d.ts.map +0 -1
- package/out/classification/CompositeClassifier.js +0 -113
- package/out/classification/CompositeClassifier.js.map +0 -1
- package/out/classification/PhraseClassifier.d.ts +0 -23
- package/out/classification/PhraseClassifier.d.ts.map +0 -1
- package/out/classification/PhraseClassifier.js +0 -32
- package/out/classification/PhraseClassifier.js.map +0 -1
- package/out/classification/SectionClassifier.d.ts +0 -23
- package/out/classification/SectionClassifier.d.ts.map +0 -1
- package/out/classification/SectionClassifier.js +0 -27
- package/out/classification/SectionClassifier.js.map +0 -1
- package/out/classification/WordClassifier.d.ts +0 -22
- package/out/classification/WordClassifier.d.ts.map +0 -1
- package/out/classification/WordClassifier.js +0 -33
- package/out/classification/WordClassifier.js.map +0 -1
- package/out/classification/index.d.ts +0 -13
- package/out/classification/index.d.ts.map +0 -1
- package/out/classification/index.js +0 -13
- package/out/classification/index.js.map +0 -1
- package/out/classification/scheme.d.ts +0 -46
- package/out/classification/scheme.d.ts.map +0 -1
- package/out/classification/scheme.js +0 -37
- package/out/classification/scheme.js.map +0 -1
- package/out/decoder/arbitrate-tree.d.ts +0 -45
- package/out/decoder/arbitrate-tree.d.ts.map +0 -1
- package/out/decoder/arbitrate-tree.js +0 -101
- package/out/decoder/arbitrate-tree.js.map +0 -1
- package/out/filters/InvalidSolutionFilter.d.ts +0 -19
- package/out/filters/InvalidSolutionFilter.d.ts.map +0 -1
- package/out/filters/InvalidSolutionFilter.js +0 -29
- package/out/filters/InvalidSolutionFilter.js.map +0 -1
- package/out/filters/RelationshipFilter.d.ts +0 -14
- package/out/filters/RelationshipFilter.d.ts.map +0 -1
- package/out/filters/RelationshipFilter.js +0 -64
- package/out/filters/RelationshipFilter.js.map +0 -1
- package/out/filters/SubsetFilter.d.ts +0 -10
- package/out/filters/SubsetFilter.d.ts.map +0 -1
- package/out/filters/SubsetFilter.js +0 -26
- package/out/filters/SubsetFilter.js.map +0 -1
- package/out/filters/TokenDistanceFilter.d.ts +0 -10
- package/out/filters/TokenDistanceFilter.d.ts.map +0 -1
- package/out/filters/TokenDistanceFilter.js +0 -30
- package/out/filters/TokenDistanceFilter.js.map +0 -1
- package/out/filters/index.d.ts +0 -10
- package/out/filters/index.d.ts.map +0 -1
- package/out/filters/index.js +0 -10
- package/out/filters/index.js.map +0 -1
- package/out/parser/AddressParser.d.ts +0 -93
- package/out/parser/AddressParser.d.ts.map +0 -1
- package/out/parser/AddressParser.js +0 -116
- package/out/parser/AddressParser.js.map +0 -1
- package/out/parser/index.d.ts +0 -9
- package/out/parser/index.d.ts.map +0 -1
- package/out/parser/index.js +0 -9
- package/out/parser/index.js.map +0 -1
- package/out/parser/proposal-pipeline.d.ts +0 -80
- package/out/parser/proposal-pipeline.d.ts.map +0 -1
- package/out/parser/proposal-pipeline.js +0 -142
- package/out/parser/proposal-pipeline.js.map +0 -1
- package/out/parser/solution-to-proposals.d.ts +0 -28
- package/out/parser/solution-to-proposals.d.ts.map +0 -1
- package/out/parser/solution-to-proposals.js +0 -44
- package/out/parser/solution-to-proposals.js.map +0 -1
- package/out/policy/from-config.d.ts +0 -52
- package/out/policy/from-config.d.ts.map +0 -1
- package/out/policy/from-config.js +0 -90
- package/out/policy/from-config.js.map +0 -1
- package/out/policy/input-shape-router.d.ts +0 -100
- package/out/policy/input-shape-router.d.ts.map +0 -1
- package/out/policy/input-shape-router.js +0 -85
- package/out/policy/input-shape-router.js.map +0 -1
- package/out/solver/BaseSolver.d.ts +0 -24
- package/out/solver/BaseSolver.d.ts.map +0 -1
- package/out/solver/BaseSolver.js +0 -7
- package/out/solver/BaseSolver.js.map +0 -1
- package/out/solver/HashMapSolver.d.ts +0 -15
- package/out/solver/HashMapSolver.d.ts.map +0 -1
- package/out/solver/HashMapSolver.js +0 -61
- package/out/solver/HashMapSolver.js.map +0 -1
- package/out/solver/Solution.d.ts +0 -68
- package/out/solver/Solution.d.ts.map +0 -1
- package/out/solver/Solution.js +0 -135
- package/out/solver/Solution.js.map +0 -1
- package/out/solver/SolutionMatch.d.ts +0 -69
- package/out/solver/SolutionMatch.d.ts.map +0 -1
- package/out/solver/SolutionMatch.js +0 -101
- package/out/solver/SolutionMatch.js.map +0 -1
- package/out/solver/index.d.ts +0 -11
- package/out/solver/index.d.ts.map +0 -1
- package/out/solver/index.js +0 -11
- package/out/solver/index.js.map +0 -1
- package/out/solver/mask.d.ts +0 -27
- package/out/solver/mask.d.ts.map +0 -1
- package/out/solver/mask.js +0 -52
- package/out/solver/mask.js.map +0 -1
- package/out/solvers/ExclusiveCartesianSolver.d.ts +0 -12
- package/out/solvers/ExclusiveCartesianSolver.d.ts.map +0 -1
- package/out/solvers/ExclusiveCartesianSolver.js +0 -58
- package/out/solvers/ExclusiveCartesianSolver.js.map +0 -1
- package/out/solvers/HouseNumberPositionPenalty.d.ts +0 -10
- package/out/solvers/HouseNumberPositionPenalty.d.ts.map +0 -1
- package/out/solvers/HouseNumberPositionPenalty.js +0 -63
- package/out/solvers/HouseNumberPositionPenalty.js.map +0 -1
- package/out/solvers/LeadingAreaDeclassifier.d.ts +0 -13
- package/out/solvers/LeadingAreaDeclassifier.d.ts.map +0 -1
- package/out/solvers/LeadingAreaDeclassifier.js +0 -35
- package/out/solvers/LeadingAreaDeclassifier.js.map +0 -1
- package/out/solvers/MultiStreetSolver.d.ts +0 -27
- package/out/solvers/MultiStreetSolver.d.ts.map +0 -1
- package/out/solvers/MultiStreetSolver.js +0 -105
- package/out/solvers/MultiStreetSolver.js.map +0 -1
- package/out/solvers/OrphanedLevelTypeDeclassifier.d.ts +0 -10
- package/out/solvers/OrphanedLevelTypeDeclassifier.d.ts.map +0 -1
- package/out/solvers/OrphanedLevelTypeDeclassifier.js +0 -21
- package/out/solvers/OrphanedLevelTypeDeclassifier.js.map +0 -1
- package/out/solvers/OrphanedUnitTypeDeclassifier.d.ts +0 -10
- package/out/solvers/OrphanedUnitTypeDeclassifier.d.ts.map +0 -1
- package/out/solvers/OrphanedUnitTypeDeclassifier.js +0 -21
- package/out/solvers/OrphanedUnitTypeDeclassifier.js.map +0 -1
- package/out/solvers/PostcodePositionPenalty.d.ts +0 -16
- package/out/solvers/PostcodePositionPenalty.d.ts.map +0 -1
- package/out/solvers/PostcodePositionPenalty.js +0 -33
- package/out/solvers/PostcodePositionPenalty.js.map +0 -1
- package/out/solvers/VenueCaptureSolver.d.ts +0 -13
- package/out/solvers/VenueCaptureSolver.d.ts.map +0 -1
- package/out/solvers/VenueCaptureSolver.js +0 -22
- package/out/solvers/VenueCaptureSolver.js.map +0 -1
- package/out/solvers/index.d.ts +0 -14
- package/out/solvers/index.d.ts.map +0 -1
- package/out/solvers/index.js +0 -14
- package/out/solvers/index.js.map +0 -1
- package/out/tokenization/context.d.ts +0 -38
- package/out/tokenization/context.d.ts.map +0 -1
- package/out/tokenization/context.js +0 -113
- package/out/tokenization/context.js.map +0 -1
- package/out/tokenization/permutate.d.ts +0 -28
- package/out/tokenization/permutate.d.ts.map +0 -1
- package/out/tokenization/permutate.js +0 -72
- package/out/tokenization/permutate.js.map +0 -1
- package/out/tokenization/split.d.ts +0 -22
- package/out/tokenization/split.d.ts.map +0 -1
- package/out/tokenization/split.js +0 -63
- package/out/tokenization/split.js.map +0 -1
- /package/out/{classification → types}/Classification.js +0 -0
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { compareMatchesByStart, rankingSolutionsByAreaClassification, } from "@mailwoman/core/solver";
|
|
7
|
-
import { permutate } from "./permutate.js";
|
|
8
|
-
import { Span } from "./Span.js";
|
|
9
|
-
import { fieldsFuncBoundary, fieldsFuncHyphenOrWhiteSpace, fieldsFuncWhiteSpace, splitByField } from "./split.js";
|
|
10
|
-
/**
|
|
11
|
-
* Tokenizes a string into sections and phrases.
|
|
12
|
-
*/
|
|
13
|
-
export class TokenContext {
|
|
14
|
-
#span;
|
|
15
|
-
#sections = [];
|
|
16
|
-
#coverage = 0;
|
|
17
|
-
#solutions = [];
|
|
18
|
-
get solutions() {
|
|
19
|
-
return this.#solutions;
|
|
20
|
-
}
|
|
21
|
-
set solutions(nextSolutions) {
|
|
22
|
-
// if (this.#solutions.length && nextSolutions.length < this.#solutions.length) {
|
|
23
|
-
// console.log(`--------------------------------------`)
|
|
24
|
-
// console.log(`${this.#solutions.length} Solution(s)`)
|
|
25
|
-
// for (const [i, solution] of this.#solutions.entries()) {
|
|
26
|
-
// console.log(`Solution ${i + 1}`, solution.toJSON())
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
this.#solutions = nextSolutions;
|
|
30
|
-
}
|
|
31
|
-
get span() {
|
|
32
|
-
return this.#span;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Sections of the tokenization.
|
|
36
|
-
*/
|
|
37
|
-
get sections() {
|
|
38
|
-
return this.#sections;
|
|
39
|
-
}
|
|
40
|
-
constructor(input = "") {
|
|
41
|
-
this.#span = Span.from(input);
|
|
42
|
-
// Split the input into sections.
|
|
43
|
-
const sections = splitByField(this.#span, fieldsFuncBoundary);
|
|
44
|
-
for (const section of sections) {
|
|
45
|
-
// Then, split each section into phrases.
|
|
46
|
-
section.children.add(...splitByField(section, fieldsFuncWhiteSpace));
|
|
47
|
-
section.children.add(...splitByField(section, fieldsFuncHyphenOrWhiteSpace));
|
|
48
|
-
}
|
|
49
|
-
this.#sections = sections;
|
|
50
|
-
this.#coverage = computeCoverage(sections);
|
|
51
|
-
// Permute the phrases of each section.
|
|
52
|
-
for (const section of this.sections) {
|
|
53
|
-
const permutations = permutate(section.children, { from: 0, to: 10 });
|
|
54
|
-
section.phrases.add(...permutations);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Evaluate and rank the solutions.
|
|
59
|
-
*
|
|
60
|
-
* This method is called after the solver has generated solutions, modifying the solutions in-place.
|
|
61
|
-
*/
|
|
62
|
-
evaluateAndRank(solutionLimit) {
|
|
63
|
-
if (this.#solutions.length === 0)
|
|
64
|
-
return;
|
|
65
|
-
for (const solution of this.#solutions) {
|
|
66
|
-
// Re-compute scores.
|
|
67
|
-
solution.computeScore(this.#coverage);
|
|
68
|
-
// Re-sort matches.
|
|
69
|
-
solution.matches.sort(compareMatchesByStart);
|
|
70
|
-
}
|
|
71
|
-
// Re-sort the solutions.
|
|
72
|
-
this.#solutions.sort(rankingSolutionsByAreaClassification);
|
|
73
|
-
// Finally, we keep only the best solutions.
|
|
74
|
-
this.#solutions = this.#solutions.slice(0, solutionLimit);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Serialize the tokenizer.
|
|
78
|
-
*/
|
|
79
|
-
toJSON() {
|
|
80
|
-
return {
|
|
81
|
-
span: this.span.toJSON(),
|
|
82
|
-
sections: this.sections.map((s) => s.toJSON()),
|
|
83
|
-
solutions: this.#solutions.map((s) => s.toJSON()),
|
|
84
|
-
coverage: this.#coverage,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Compute the coverage of the tokenization.
|
|
90
|
-
*/
|
|
91
|
-
function computeCoverageRec(sum, currentSpan) {
|
|
92
|
-
if (!currentSpan)
|
|
93
|
-
return sum;
|
|
94
|
-
sum += currentSpan.end - currentSpan.start;
|
|
95
|
-
if (currentSpan.end < currentSpan.start) {
|
|
96
|
-
throw new Error(`Tokenizer: invalid span ${currentSpan.start} ${currentSpan.end}`);
|
|
97
|
-
}
|
|
98
|
-
return computeCoverageRec(sum, currentSpan.nextSibling);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Compute the coverage of the tokenization.
|
|
102
|
-
*/
|
|
103
|
-
function computeCoverage(sections) {
|
|
104
|
-
let coverage = 0;
|
|
105
|
-
for (const [i, section] of sections.entries()) {
|
|
106
|
-
const firstChild = section.children.first;
|
|
107
|
-
if (!firstChild)
|
|
108
|
-
throw new Error(`Tokenizer: section ${i} has no children`);
|
|
109
|
-
coverage += computeCoverageRec(0, firstChild);
|
|
110
|
-
}
|
|
111
|
-
return coverage;
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../tokenization/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,qBAAqB,EACrB,oCAAoC,GAGpC,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAuB,IAAI,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AASjH;;GAEG;AACH,MAAM,OAAO,YAAY;IACxB,KAAK,CAAO;IACZ,SAAS,GAAW,EAAE,CAAA;IACtB,SAAS,GAAW,CAAC,CAAA;IAErB,UAAU,GAAe,EAAE,CAAA;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AW,CAAC,KAAK,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,kBAAkB,CAAC,GAAG,EAAE,WAAW,CAAC,WAAW,CAAC,CAAA;AACxD,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,QAAgB;IACxC,IAAI,QAAQ,GAAG,CAAC,CAAA;IAEhB,KAAK,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;QAEzC,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;QAE3E,QAAQ,IAAI,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IAC9C,CAAC;IAED,OAAO,QAAQ,CAAA;AAChB,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { Span } from "./Span.ts";
|
|
7
|
-
export interface PermutateOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The minimum amount of tokens which can be returned in a single window.
|
|
10
|
-
*/
|
|
11
|
-
from: number;
|
|
12
|
-
/**
|
|
13
|
-
* The maximum amount of tokens which can be returned in a single window.
|
|
14
|
-
*/
|
|
15
|
-
to: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Produce all the possible token groups from adjacent input tokens (without reordering tokens).
|
|
19
|
-
*
|
|
20
|
-
* Example: ['soho', 'new', 'york', 'usa'] [ ['soho', 'new', 'york', 'usa'], ['soho', 'new', 'york'], ['soho', 'new'],
|
|
21
|
-
* ['soho'], ['new', 'york', 'usa'], ['new', 'york'], ['new'], ['york', 'usa'], ['york'], ['usa'], ]
|
|
22
|
-
*
|
|
23
|
-
* @param spans - The spans to permutate
|
|
24
|
-
*
|
|
25
|
-
* @returns The permutations
|
|
26
|
-
*/
|
|
27
|
-
export declare function permutate(spans: Iterable<Span>, { from, to }: PermutateOptions): Span[];
|
|
28
|
-
//# sourceMappingURL=permutate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"permutate.d.ts","sourceRoot":"","sources":["../../tokenization/permutate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAiEhC,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;CACV;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,gBAAgB,GAAG,IAAI,EAAE,CAQvF"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { Span } from "./Span.js";
|
|
7
|
-
const JOIN_CHAR = " ";
|
|
8
|
-
/**
|
|
9
|
-
* Produce all the possible token groups from adjacent input tokens (without reordering tokens)
|
|
10
|
-
*
|
|
11
|
-
* WindowMin: the minimum amount of tokens which can be returned in a single window windowMax: the maximum amount of
|
|
12
|
-
* tokens which can be returned in a single window
|
|
13
|
-
*
|
|
14
|
-
* Note: we should honor word boundary delimiters (such as comma) when creating permutations ported:
|
|
15
|
-
* https://github.com/pelias/placeholder/blob/master/lib/permutations.js
|
|
16
|
-
*/
|
|
17
|
-
function permutateRec(prevSpan, currentSpan, windowCur, windowMin, windowMax, permutations) {
|
|
18
|
-
// Stops when the window is reached
|
|
19
|
-
if (windowCur > windowMax)
|
|
20
|
-
return;
|
|
21
|
-
// Create new span base on the previous and the next one
|
|
22
|
-
const span = new Span(prevSpan.body + (prevSpan.body.length > 0 ? JOIN_CHAR : "") + currentSpan.body, prevSpan.start);
|
|
23
|
-
// Add all children from the previous span to the new one, they will have the same ones + the next one
|
|
24
|
-
// Add to all children from the previous span the new span as parent + the next one
|
|
25
|
-
prevSpan.children.forEach((child) => {
|
|
26
|
-
span.children.add(child);
|
|
27
|
-
child.parents.add(span);
|
|
28
|
-
});
|
|
29
|
-
span.children.add(currentSpan);
|
|
30
|
-
currentSpan.parents.add(span);
|
|
31
|
-
const isFirst = span.body === currentSpan.body;
|
|
32
|
-
const isLast = !currentSpan.nextSibling;
|
|
33
|
-
if (isFirst) {
|
|
34
|
-
span.start = currentSpan.start;
|
|
35
|
-
span.end = currentSpan.end;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
if (currentSpan.start < span.start) {
|
|
39
|
-
span.start = currentSpan.start;
|
|
40
|
-
}
|
|
41
|
-
if (currentSpan.end > span.end) {
|
|
42
|
-
span.end = currentSpan.end;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// go through the graph recursively, check all next spans
|
|
46
|
-
if (!isLast) {
|
|
47
|
-
currentSpan.nextSiblings.forEach((next) => {
|
|
48
|
-
permutateRec(span, next, windowCur + 1, windowMin, windowMax, permutations);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
if (windowMin <= windowCur) {
|
|
52
|
-
permutations.push(span);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Produce all the possible token groups from adjacent input tokens (without reordering tokens).
|
|
57
|
-
*
|
|
58
|
-
* Example: ['soho', 'new', 'york', 'usa'] [ ['soho', 'new', 'york', 'usa'], ['soho', 'new', 'york'], ['soho', 'new'],
|
|
59
|
-
* ['soho'], ['new', 'york', 'usa'], ['new', 'york'], ['new'], ['york', 'usa'], ['york'], ['usa'], ]
|
|
60
|
-
*
|
|
61
|
-
* @param spans - The spans to permutate
|
|
62
|
-
*
|
|
63
|
-
* @returns The permutations
|
|
64
|
-
*/
|
|
65
|
-
export function permutate(spans, { from, to }) {
|
|
66
|
-
const permutations = [];
|
|
67
|
-
for (const span of spans) {
|
|
68
|
-
permutateRec(new Span(), span, 1, from, to, permutations);
|
|
69
|
-
}
|
|
70
|
-
return permutations;
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=permutate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"permutate.js","sourceRoot":"","sources":["../../tokenization/permutate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,MAAM,SAAS,GAAG,GAAG,CAAA;AAErB;;;;;;;;GAQG;AACH,SAAS,YAAY,CACpB,QAAc,EACd,WAAiB,EACjB,SAAiB,EACjB,SAAiB,EACjB,SAAiB,EACjB,YAAoB;IAEpB,mCAAmC;IACnC,IAAI,SAAS,GAAG,SAAS;QAAE,OAAM;IAEjC,wDAAwD;IACxD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAErH,sGAAsG;IACtG,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACnC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACxB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;I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AAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,CAAC,CAAA;IAC1D,CAAC;IAED,OAAO,YAAY,CAAA;AACpB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { Span } from "./Span.ts";
|
|
7
|
-
type FieldMatchPredicate = (char: string) => boolean;
|
|
8
|
-
export declare function splitByField(span: Span, predicate: FieldMatchPredicate): Span[];
|
|
9
|
-
/**
|
|
10
|
-
* Predicate to test if a character is a field boundary
|
|
11
|
-
*/
|
|
12
|
-
export declare const fieldsFuncBoundary: FieldMatchPredicate;
|
|
13
|
-
/**
|
|
14
|
-
* Predicate to test if a character is a field whitespace.
|
|
15
|
-
*/
|
|
16
|
-
export declare const fieldsFuncWhiteSpace: FieldMatchPredicate;
|
|
17
|
-
/**
|
|
18
|
-
* Predicate to test if a character is a hyphen or whitespace.
|
|
19
|
-
*/
|
|
20
|
-
export declare const fieldsFuncHyphenOrWhiteSpace: FieldMatchPredicate;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=split.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"split.d.ts","sourceRoot":"","sources":["../../tokenization/split.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,KAAK,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;AAEpD,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB,GAAG,IAAI,EAAE,CA8C/E;AAKD;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,mBAGhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,mBAElC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,mBAE1C,CAAA"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { Span } from "./Span.js";
|
|
7
|
-
export function splitByField(span, predicate) {
|
|
8
|
-
// A span is used to record a slice of s of the form s[start:end].
|
|
9
|
-
// The start index is inclusive and the end index is exclusive.
|
|
10
|
-
const spans = [];
|
|
11
|
-
// Find the field start and end indices.
|
|
12
|
-
let wasField = false;
|
|
13
|
-
let fromIndex = 0;
|
|
14
|
-
// Iterate unicode code points in string
|
|
15
|
-
for (let i = 0; i < span.body.length; i++) {
|
|
16
|
-
const char = span.body.charAt(i);
|
|
17
|
-
if (predicate(char)) {
|
|
18
|
-
if (wasField) {
|
|
19
|
-
let appendedChild = Iterator.from(span.children).find((child) => {
|
|
20
|
-
return child.start === span.start + fromIndex && child.body === span.body.substring(fromIndex, i);
|
|
21
|
-
});
|
|
22
|
-
appendedChild ||= Span.from(span.body.substring(fromIndex, i), {
|
|
23
|
-
start: span.start + fromIndex,
|
|
24
|
-
});
|
|
25
|
-
spans.push(appendedChild);
|
|
26
|
-
wasField = false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else if (!wasField) {
|
|
30
|
-
fromIndex = i;
|
|
31
|
-
wasField = true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Last field might end at EOF.
|
|
35
|
-
if (wasField) {
|
|
36
|
-
spans.push(Iterator.from(span.children).find((s) => s.start === span.start + fromIndex && s.body === span.body.substring(fromIndex, span.body.length)) || Span.from(span.body.substring(fromIndex, span.body.length), { start: span.start + fromIndex }));
|
|
37
|
-
}
|
|
38
|
-
// Add siblings to graph
|
|
39
|
-
Span.connectSiblings(...spans);
|
|
40
|
-
return spans;
|
|
41
|
-
}
|
|
42
|
-
const quotes = '"«»‘’‚‛“”„‟‹›⹂「」『』〝〞〟﹁﹂﹃﹄"'「」';
|
|
43
|
-
const fieldBoundaryPattern = /\n|\t|,/;
|
|
44
|
-
/**
|
|
45
|
-
* Predicate to test if a character is a field boundary
|
|
46
|
-
*/
|
|
47
|
-
export const fieldsFuncBoundary = (char) => {
|
|
48
|
-
// TODO: this should ideally only work for 'matching pairs' of quotes.
|
|
49
|
-
return fieldBoundaryPattern.test(char) || quotes.includes(char);
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Predicate to test if a character is a field whitespace.
|
|
53
|
-
*/
|
|
54
|
-
export const fieldsFuncWhiteSpace = (char) => {
|
|
55
|
-
return char.trim().length === 0;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Predicate to test if a character is a hyphen or whitespace.
|
|
59
|
-
*/
|
|
60
|
-
export const fieldsFuncHyphenOrWhiteSpace = (char) => {
|
|
61
|
-
return char === "-" || char === "/" || fieldsFuncWhiteSpace(char);
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=split.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"split.js","sourceRoot":"","sources":["../../tokenization/split.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,MAAM,UAAU,YAAY,CAAC,IAAU,EAAE,SAA8B;IACtE,kEAAkE;IAClE,+DAA+D;IAC/D,MAAM,KAAK,GAAW,EAAE,CAAA;IAExB,wCAAwC;IACxC,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,SAAS,GAAG,CAAC,CAAA;IAEjB,wCAAwC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC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