@mailwoman/core 6.5.0 → 7.0.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,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { isVisibleClassification } from "@mailwoman/core/classification";
|
|
7
|
-
import { Span, TokenContext } from "@mailwoman/core/tokenization";
|
|
8
|
-
import { Solution } from "./Solution.js";
|
|
9
|
-
import { SolutionMatch } from "./SolutionMatch.js";
|
|
10
|
-
export class HashMapSolver {
|
|
11
|
-
static MaxMatchesPerClassification = 8;
|
|
12
|
-
generateHashMap(context, includePrivate = false, includeEmpty = false) {
|
|
13
|
-
const classificationSolutionMap = new Map();
|
|
14
|
-
for (const section of context.sections) {
|
|
15
|
-
// Multi-word phrases
|
|
16
|
-
const { phrases } = section;
|
|
17
|
-
for (const phrase of phrases) {
|
|
18
|
-
for (const match of phrase.classifications.values()) {
|
|
19
|
-
if (!includePrivate && !isVisibleClassification(match)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
let solution = classificationSolutionMap.get(match.classification);
|
|
23
|
-
if (!solution) {
|
|
24
|
-
solution = new Solution();
|
|
25
|
-
classificationSolutionMap.set(match.classification, solution);
|
|
26
|
-
if (includeEmpty) {
|
|
27
|
-
solution.matches.push(new SolutionMatch(new Span(), match));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (solution.matches.length >= HashMapSolver.MaxMatchesPerClassification) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
solution.matches.push(new SolutionMatch(phrase, match));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// Single-word spans.
|
|
37
|
-
// TODO: combine with above loop, or refactor to avoid duplication.
|
|
38
|
-
for (const word of section.children) {
|
|
39
|
-
for (const classification of word.classifications.values()) {
|
|
40
|
-
if (!includePrivate && !isVisibleClassification(classification)) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
let solution = classificationSolutionMap.get(classification.classification);
|
|
44
|
-
if (!solution) {
|
|
45
|
-
solution = new Solution();
|
|
46
|
-
classificationSolutionMap.set(classification.classification, solution);
|
|
47
|
-
if (includeEmpty) {
|
|
48
|
-
solution.matches.push(new SolutionMatch(new Span(), classification));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (solution.matches.length >= HashMapSolver.MaxMatchesPerClassification) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
solution.matches.push(new SolutionMatch(word, classification));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return classificationSolutionMap;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=HashMapSolver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HashMapSolver.js","sourceRoot":"","sources":["../../solver/HashMapSolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAuB,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AAC7F,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAGjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,OAAgB,aAAa;IAClC,MAAM,CAAC,2BAA2B,GAAG,CAAC,CAAA;IAI5B,eAAe,CACxB,OAAqB,EACrB,cAAc,GAAG,KAAK,EACtB,YAAY,GAAG,KAAK;QAEpB,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAA4B,CAAA;QAErE,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACxC,qBAAqB;YACrB,MAAM,EAAE,OAAO,EAAE,GAAG,OA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CAAA;oBAE3E,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACf,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA;wBACzB,yBAAyB,CAAC,GAAG,CAAC,cAAc,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAA;wBAEtE,IAAI,YAAY,EAAE,CAAC;4BAClB,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,IAAI,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC,CAAA;wBACrE,CAAC;oBACF,CAAC;oBAED,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,aAAa,CAAC,2BAA2B,EAAE,CAAC;wBAC1E,SAAQ;oBACT,CAAC;oBAED,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAA;gBAC/D,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,yBAAyB,CAAA;IACjC,CAAC"}
|
package/out/solver/Solution.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { type Classification, type ClassificationRecord } from "@mailwoman/core/classification";
|
|
7
|
-
import type { TokenContext } from "@mailwoman/core/tokenization";
|
|
8
|
-
import { type SerializedSolutionMatch, SolutionMatch } from "./SolutionMatch.ts";
|
|
9
|
-
export interface SerializedSolution {
|
|
10
|
-
score: number;
|
|
11
|
-
penalty: number;
|
|
12
|
-
classifications: ClassificationRecord;
|
|
13
|
-
matches: SerializedSolutionMatch[];
|
|
14
|
-
}
|
|
15
|
-
export interface SolutionCreationOptions {
|
|
16
|
-
context: TokenContext;
|
|
17
|
-
matches?: SolutionMatch[];
|
|
18
|
-
}
|
|
19
|
-
export declare class Solution {
|
|
20
|
-
matches: SolutionMatch[];
|
|
21
|
-
/**
|
|
22
|
-
* All classification in the solution.
|
|
23
|
-
*/
|
|
24
|
-
collectClassifications(): Classification[];
|
|
25
|
-
/**
|
|
26
|
-
* Find the first matching pair in the solution by its classification.
|
|
27
|
-
*/
|
|
28
|
-
find(classification: Classification): SolutionMatch | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Exclude match by classification.
|
|
31
|
-
*/
|
|
32
|
-
findWithout(classification: Classification): SolutionMatch[];
|
|
33
|
-
/**
|
|
34
|
-
* Filter match by classification.
|
|
35
|
-
*/
|
|
36
|
-
filter(classification: Classification): SolutionMatch[];
|
|
37
|
-
/**
|
|
38
|
-
* Absolute score of the solution.
|
|
39
|
-
*/
|
|
40
|
-
score: number;
|
|
41
|
-
/**
|
|
42
|
-
* Penalty for the solution. This is used to penalize solutions that are not complete.
|
|
43
|
-
*/
|
|
44
|
-
penalty: number;
|
|
45
|
-
/**
|
|
46
|
-
* Create a new solution.
|
|
47
|
-
*/
|
|
48
|
-
constructor(matches?: Iterable<SolutionMatch>);
|
|
49
|
-
/**
|
|
50
|
-
* Predicate to determine if this solution covers another solution, i.e. the target solution is a subset of this
|
|
51
|
-
* solution without any unique ranges.
|
|
52
|
-
*/
|
|
53
|
-
covers(that: Solution): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Predicate to determine if a solution covers another solution with the same classification.
|
|
56
|
-
*/
|
|
57
|
-
coversSameClassification(that: Solution): boolean;
|
|
58
|
-
computeScore(contextCoverage: number): void;
|
|
59
|
-
/**
|
|
60
|
-
* @returns JSON representation of a solution
|
|
61
|
-
*/
|
|
62
|
-
toJSON(): SerializedSolution;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Compare solutions for sorting, first by score, then by classification.
|
|
66
|
-
*/
|
|
67
|
-
export declare function rankingSolutionsByAreaClassification(a: Solution, b: Solution): number;
|
|
68
|
-
//# sourceMappingURL=Solution.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Solution.d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AC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CA6BrF"}
|
package/out/solver/Solution.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { isVisibleClassification, } from "@mailwoman/core/classification";
|
|
7
|
-
import { SolutionMatch } from "./SolutionMatch.js";
|
|
8
|
-
export class Solution {
|
|
9
|
-
matches;
|
|
10
|
-
/**
|
|
11
|
-
* All classification in the solution.
|
|
12
|
-
*/
|
|
13
|
-
collectClassifications() {
|
|
14
|
-
return this.matches.map((pair) => pair.classification);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Find the first matching pair in the solution by its classification.
|
|
18
|
-
*/
|
|
19
|
-
find(classification) {
|
|
20
|
-
return this.matches.find((pair) => pair.classification === classification);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Exclude match by classification.
|
|
24
|
-
*/
|
|
25
|
-
findWithout(classification) {
|
|
26
|
-
return this.matches.filter((pair) => pair.classification !== classification);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Filter match by classification.
|
|
30
|
-
*/
|
|
31
|
-
filter(classification) {
|
|
32
|
-
return this.matches.filter((pair) => pair.classification === classification);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Absolute score of the solution.
|
|
36
|
-
*/
|
|
37
|
-
score = 0;
|
|
38
|
-
/**
|
|
39
|
-
* Penalty for the solution. This is used to penalize solutions that are not complete.
|
|
40
|
-
*/
|
|
41
|
-
penalty = 0;
|
|
42
|
-
/**
|
|
43
|
-
* Create a new solution.
|
|
44
|
-
*/
|
|
45
|
-
constructor(matches = []) {
|
|
46
|
-
this.matches = Array.from(matches);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Predicate to determine if this solution covers another solution, i.e. the target solution is a subset of this
|
|
50
|
-
* solution without any unique ranges.
|
|
51
|
-
*/
|
|
52
|
-
covers(that) {
|
|
53
|
-
return that.matches.every((pair) => this.matches.some(({ span }) => span.covers(pair.span)));
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Predicate to determine if a solution covers another solution with the same classification.
|
|
57
|
-
*/
|
|
58
|
-
coversSameClassification(that) {
|
|
59
|
-
const result = that.matches.every((pair) => this.matches.some(({ classification, span }) => {
|
|
60
|
-
return classification === pair.classification && span.covers(pair.span);
|
|
61
|
-
}));
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
computeScore(contextCoverage) {
|
|
65
|
-
const total = {
|
|
66
|
-
coverage: 0,
|
|
67
|
-
confidence: 0,
|
|
68
|
-
};
|
|
69
|
-
this.matches.forEach((match) => {
|
|
70
|
-
const { confidence, coverage } = match;
|
|
71
|
-
// Total characters covered.
|
|
72
|
-
total.coverage += coverage;
|
|
73
|
-
// Confidence of match multiplied by characters covered.
|
|
74
|
-
total.confidence += confidence * coverage;
|
|
75
|
-
});
|
|
76
|
-
// The average character score covered divided by the total coverage.
|
|
77
|
-
this.score = (total.confidence / total.coverage) * (total.coverage / contextCoverage) * (1.0 - this.penalty);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @returns JSON representation of a solution
|
|
81
|
-
*/
|
|
82
|
-
toJSON() {
|
|
83
|
-
const { matches, score, penalty } = this;
|
|
84
|
-
const classificationIDMap = new Map();
|
|
85
|
-
const classificationConfidences = new Map();
|
|
86
|
-
for (const { classification, confidence, span } of matches) {
|
|
87
|
-
if (!isVisibleClassification(classification))
|
|
88
|
-
continue;
|
|
89
|
-
let bodies = classificationIDMap.get(classification);
|
|
90
|
-
if (!bodies) {
|
|
91
|
-
bodies = [];
|
|
92
|
-
classificationIDMap.set(classification, bodies);
|
|
93
|
-
}
|
|
94
|
-
bodies.push(span.body);
|
|
95
|
-
classificationConfidences.set(classification, confidence);
|
|
96
|
-
}
|
|
97
|
-
const serialized = {
|
|
98
|
-
score: parseFloat(score.toFixed(2)),
|
|
99
|
-
penalty: parseFloat(penalty.toFixed(2)),
|
|
100
|
-
classifications: Object.fromEntries(classificationIDMap),
|
|
101
|
-
matches: matches.map((match) => match.toJSON()),
|
|
102
|
-
};
|
|
103
|
-
return serialized;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Compare solutions for sorting, first by score, then by classification.
|
|
108
|
-
*/
|
|
109
|
-
export function rankingSolutionsByAreaClassification(a, b) {
|
|
110
|
-
if (b.score !== a.score) {
|
|
111
|
-
return b.score - a.score;
|
|
112
|
-
}
|
|
113
|
-
// Enforce a slight penalty for administrative ordering.
|
|
114
|
-
const areaA = a.matches.find(({ span }) => span.is("area"));
|
|
115
|
-
const areaB = b.matches.find(({ span }) => span.is("area"));
|
|
116
|
-
const classification = {
|
|
117
|
-
a: areaA?.classification,
|
|
118
|
-
b: areaB?.classification,
|
|
119
|
-
};
|
|
120
|
-
if (classification.a === "locality")
|
|
121
|
-
return -1;
|
|
122
|
-
if (classification.b === "locality")
|
|
123
|
-
return 1;
|
|
124
|
-
if (classification.a === "region")
|
|
125
|
-
return -1;
|
|
126
|
-
if (classification.b === "region")
|
|
127
|
-
return 1;
|
|
128
|
-
if (classification.a === "country")
|
|
129
|
-
return -1;
|
|
130
|
-
if (classification.b === "country")
|
|
131
|
-
return 1;
|
|
132
|
-
// sort results by score desc
|
|
133
|
-
return b.score - a.score;
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=Solution.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Solution.js","sourceRoot":"","sources":["../../solver/Solution.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAKN,uBAAuB,GACvB,MAAM,gCAAgC,CAAA;AAGvC,OAAO,EAAgC,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAchF,MAAM,OAAO,QAAQ;IACb,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AAC,MAAM,CAAC,CAAC,CAAA;IAE3D,MAAM,cAAc,GAAG;QACtB,CAAC,EAAE,KAAK,EAAE,cAAc;QACxB,CAAC,EAAE,KAAK,EAAE,cAAc;KACyC,CAAA;IAElE,IAAI,cAAc,CAAC,CAAC,KAAK,UAAU;QAAE,OAAO,CAAC,CAAC,CAAA;IAE9C,IAAI,cAAc,CAAC,CAAC,KAAK,UAAU;QAAE,OAAO,CAAC,CAAA;IAE7C,IAAI,cAAc,CAAC,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,CAAA;IAE5C,IAAI,cAAc,CAAC,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAA;IAE3C,IAAI,cAAc,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,CAAA;IAE7C,IAAI,cAAc,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAA;IAE5C,6BAA6B;IAC7B,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;AACzB,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import type { ClassificationMatch, ClassificationsMatchInput } from "@mailwoman/core/classification";
|
|
7
|
-
import { Span } from "@mailwoman/core/tokenization";
|
|
8
|
-
export interface SerializedSolutionMatch extends ClassificationMatch {
|
|
9
|
-
/**
|
|
10
|
-
* The span of text that was matched.
|
|
11
|
-
*/
|
|
12
|
-
readonly value: string;
|
|
13
|
-
/**
|
|
14
|
-
* The start index of the span.
|
|
15
|
-
*/
|
|
16
|
-
readonly start: number;
|
|
17
|
-
/**
|
|
18
|
-
* The end index of the span.
|
|
19
|
-
*/
|
|
20
|
-
readonly end: number;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Comparator for sorting solution matches by their start index.
|
|
24
|
-
*/
|
|
25
|
-
export declare function compareMatchesByStart(a: SolutionMatch, b: SolutionMatch): number;
|
|
26
|
-
export declare class SolutionMatch implements SerializedSolutionMatch {
|
|
27
|
-
#private;
|
|
28
|
-
/**
|
|
29
|
-
* The span of text that was matched.
|
|
30
|
-
*/
|
|
31
|
-
readonly span: Span;
|
|
32
|
-
/**
|
|
33
|
-
* The classification of the match.
|
|
34
|
-
*/
|
|
35
|
-
get classification(): "adjacent" | "alpha" | "alphanumeric" | "area" | "chain" | "country" | "dependency" | "directional" | "end_token_single_character" | "end_token" | "given_name" | "house_number" | "intersection" | "level_designator" | "level" | "locality" | "middle_initial" | "multistreet" | "numeric" | "ordinal" | "person" | "personal_suffix" | "personal_title" | "place" | "postcode" | "punctuation" | "region" | "road_type" | "start_token" | "stop_word" | "street_name" | "street_prefix" | "street_proper_name" | "street_suffix" | "street" | "surname" | "toponym" | "unit_designator" | "unit" | "unknown" | "venue";
|
|
36
|
-
/**
|
|
37
|
-
* The confidence of the match, from 0 to 1.
|
|
38
|
-
*
|
|
39
|
-
* This indicates how certain the classifier is that the match is correct.
|
|
40
|
-
*/
|
|
41
|
-
get confidence(): number;
|
|
42
|
-
/**
|
|
43
|
-
* The body of the matched span.
|
|
44
|
-
*/
|
|
45
|
-
get value(): string;
|
|
46
|
-
/**
|
|
47
|
-
* The start index of the span.
|
|
48
|
-
*/
|
|
49
|
-
get start(): number;
|
|
50
|
-
/**
|
|
51
|
-
* The end index of the span.
|
|
52
|
-
*/
|
|
53
|
-
get end(): number;
|
|
54
|
-
/**
|
|
55
|
-
* The languages that the match was classified as.
|
|
56
|
-
*/
|
|
57
|
-
get languages(): import("../index.ts").Displayable<ReadonlySet<import("../index.ts").LibPostalLanguageCode | import("../index.ts").Alpha3bLanguageCode>> | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* The range of the span, i.e. the number of characters covered.
|
|
60
|
-
*/
|
|
61
|
-
get coverage(): number;
|
|
62
|
-
constructor(span: Span, classification: ClassificationsMatchInput);
|
|
63
|
-
toJSON(): SerializedSolutionMatch;
|
|
64
|
-
}
|
|
65
|
-
export declare function calculateRangeScore(match: SolutionMatch): {
|
|
66
|
-
range: number;
|
|
67
|
-
confidence: number;
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=SolutionMatch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SolutionMatch.d.ts","sourceRoot":"","sources":["../../solver/SolutionMatch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AACpG,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AAEnD,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IACnE;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,UAEvE;AAED,qBAAa,aAAc,YAAW,uBAAuB;;IAC5D;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IAOnB;;OAEG;IACH,IAAW,cAAc,8lBAExB;IAED;;;;OAIG;IACH,IAAW,UAAU,WAEpB;IAED;;OAEG;IACH,IAAW,KAAK,WAEf;IAED;;OAEG;IACH,IAAW,KAAK,WAEf;IAED;;OAEG;IACH,IAAW,GAAG,WAEb;IAED;;OAEG;IACH,IAAW,SAAS,wJAEnB;IAED;;OAEG;IACH,IAAW,QAAQ,WAElB;gBAEW,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,yBAAyB;IAY1D,MAAM,IAAI,uBAAuB;CAQxC;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa;;;EAgBvD"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { Span } from "@mailwoman/core/tokenization";
|
|
7
|
-
/**
|
|
8
|
-
* Comparator for sorting solution matches by their start index.
|
|
9
|
-
*/
|
|
10
|
-
export function compareMatchesByStart(a, b) {
|
|
11
|
-
return a.span.start - b.span.start;
|
|
12
|
-
}
|
|
13
|
-
export class SolutionMatch {
|
|
14
|
-
/**
|
|
15
|
-
* The span of text that was matched.
|
|
16
|
-
*/
|
|
17
|
-
span;
|
|
18
|
-
/**
|
|
19
|
-
* Matched classifications and their respective metadata.
|
|
20
|
-
*/
|
|
21
|
-
#match;
|
|
22
|
-
/**
|
|
23
|
-
* The classification of the match.
|
|
24
|
-
*/
|
|
25
|
-
get classification() {
|
|
26
|
-
return this.#match.classification;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* The confidence of the match, from 0 to 1.
|
|
30
|
-
*
|
|
31
|
-
* This indicates how certain the classifier is that the match is correct.
|
|
32
|
-
*/
|
|
33
|
-
get confidence() {
|
|
34
|
-
return this.#match.confidence;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The body of the matched span.
|
|
38
|
-
*/
|
|
39
|
-
get value() {
|
|
40
|
-
return this.span.body;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* The start index of the span.
|
|
44
|
-
*/
|
|
45
|
-
get start() {
|
|
46
|
-
return this.span.start;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* The end index of the span.
|
|
50
|
-
*/
|
|
51
|
-
get end() {
|
|
52
|
-
return this.span.end;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The languages that the match was classified as.
|
|
56
|
-
*/
|
|
57
|
-
get languages() {
|
|
58
|
-
return this.#match.languages;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The range of the span, i.e. the number of characters covered.
|
|
62
|
-
*/
|
|
63
|
-
get coverage() {
|
|
64
|
-
return this.span.coverage;
|
|
65
|
-
}
|
|
66
|
-
constructor(span, classification) {
|
|
67
|
-
this.span = span;
|
|
68
|
-
this.#match =
|
|
69
|
-
typeof classification === "string"
|
|
70
|
-
? {
|
|
71
|
-
classification,
|
|
72
|
-
confidence: 1,
|
|
73
|
-
}
|
|
74
|
-
: classification;
|
|
75
|
-
}
|
|
76
|
-
toJSON() {
|
|
77
|
-
return {
|
|
78
|
-
...this.#match,
|
|
79
|
-
value: this.span.body,
|
|
80
|
-
start: this.span.start,
|
|
81
|
-
end: this.span.end,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export function calculateRangeScore(match) {
|
|
86
|
-
let range;
|
|
87
|
-
if (match.span.children.size) {
|
|
88
|
-
range = Iterator
|
|
89
|
-
// ---
|
|
90
|
-
.from(match.span.children)
|
|
91
|
-
.reduce((sum, child) => sum + (child.end - child.start), 0);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
range = match.end - match.start;
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
range,
|
|
98
|
-
confidence: match.confidence * range,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=SolutionMatch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SolutionMatch.js","sourceRoot":"","sources":["../../solver/SolutionMatch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AAmBnD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,CAAgB,EAAE,CAAgB;IACvE,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;AACnC,CAAC;AAED,MAAM,OA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,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9B,KAAK,GAAG,QAAQ;YACf,MAAM;aACL,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;aACzB,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC;SAAM,CAAC;QACP,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAA;IAChC,CAAC;IAED,OAAO;QACN,KAAK;QACL,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK;KACpC,CAAA;AACF,CAAC"}
|
package/out/solver/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
export * from "./BaseSolver.ts";
|
|
7
|
-
export * from "./HashMapSolver.ts";
|
|
8
|
-
export * from "./mask.ts";
|
|
9
|
-
export * from "./Solution.ts";
|
|
10
|
-
export * from "./SolutionMatch.ts";
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../solver/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|
package/out/solver/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
export * from "./BaseSolver.js";
|
|
7
|
-
export * from "./HashMapSolver.js";
|
|
8
|
-
export * from "./mask.js";
|
|
9
|
-
export * from "./Solution.js";
|
|
10
|
-
export * from "./SolutionMatch.js";
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
package/out/solver/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../solver/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA"}
|
package/out/solver/mask.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { TokenContext } from "@mailwoman/core/tokenization";
|
|
7
|
-
import { SolutionMatch } from "./SolutionMatch.ts";
|
|
8
|
-
type MaskCode = "V" | "N" | "S" | "P" | "L" | "U" | "A";
|
|
9
|
-
/**
|
|
10
|
-
* Mapping of classification labels to mask codes.
|
|
11
|
-
*/
|
|
12
|
-
export declare const ClassificationMaskCodeMap: Map<"adjacent" | "alpha" | "alphanumeric" | "area" | "chain" | "country" | "dependency" | "directional" | "end_token_single_character" | "end_token" | "given_name" | "house_number" | "intersection" | "level_designator" | "level" | "locality" | "middle_initial" | "multistreet" | "numeric" | "ordinal" | "person" | "personal_suffix" | "personal_title" | "place" | "postcode" | "punctuation" | "region" | "road_type" | "start_token" | "stop_word" | "street_name" | "street_prefix" | "street_proper_name" | "street_suffix" | "street" | "surname" | "toponym" | "unit_designator" | "unit" | "unknown" | "venue" | "fallback", MaskCode>;
|
|
13
|
-
/**
|
|
14
|
-
* Mask which shows the areas covered by different types of classification
|
|
15
|
-
*
|
|
16
|
-
* - `N` housenumber
|
|
17
|
-
* - `S` street
|
|
18
|
-
* - `P` postcode
|
|
19
|
-
* - `A` administrative
|
|
20
|
-
* - `L` Level
|
|
21
|
-
* - `U` unit
|
|
22
|
-
*
|
|
23
|
-
* @returns Mask of the input for this solution
|
|
24
|
-
*/
|
|
25
|
-
export declare function createMask(context: TokenContext, matches: Iterable<SolutionMatch>): string;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=mask.d.ts.map
|
package/out/solver/mask.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../../solver/mask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,KAAK,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAEvD;;GAEG;AACH,eAAO,MAAM,yBAAyB,unBAUpC,CAAA;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,MAAM,CAsB1F"}
|
package/out/solver/mask.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { TokenContext } from "@mailwoman/core/tokenization";
|
|
7
|
-
import { SolutionMatch } from "./SolutionMatch.js";
|
|
8
|
-
/**
|
|
9
|
-
* Mapping of classification labels to mask codes.
|
|
10
|
-
*/
|
|
11
|
-
export const ClassificationMaskCodeMap = new Map([
|
|
12
|
-
["venue", "V"],
|
|
13
|
-
["house_number", "N"],
|
|
14
|
-
["street", "S"],
|
|
15
|
-
["postcode", "P"],
|
|
16
|
-
["level", "L"],
|
|
17
|
-
["level_designator", "L"],
|
|
18
|
-
["unit", "U"],
|
|
19
|
-
["unit_designator", "U"],
|
|
20
|
-
["fallback", "A"],
|
|
21
|
-
]);
|
|
22
|
-
/**
|
|
23
|
-
* Mask which shows the areas covered by different types of classification
|
|
24
|
-
*
|
|
25
|
-
* - `N` housenumber
|
|
26
|
-
* - `S` street
|
|
27
|
-
* - `P` postcode
|
|
28
|
-
* - `A` administrative
|
|
29
|
-
* - `L` Level
|
|
30
|
-
* - `U` unit
|
|
31
|
-
*
|
|
32
|
-
* @returns Mask of the input for this solution
|
|
33
|
-
*/
|
|
34
|
-
export function createMask(context, matches) {
|
|
35
|
-
const { body } = context.span;
|
|
36
|
-
const mask = Array.from({ length: body.length }, () => " ");
|
|
37
|
-
// Scan the input letter-by-letter from left-to-right.
|
|
38
|
-
for (let i = 0; i < body.length; i++) {
|
|
39
|
-
// find which fields cover this character (should only be covered by 0 or 1 field)
|
|
40
|
-
const [firstMatch] = Iterator.from(matches).filter((pair) => pair.span.start <= i && pair.span.end >= i);
|
|
41
|
-
if (!firstMatch)
|
|
42
|
-
continue;
|
|
43
|
-
const code = ClassificationMaskCodeMap.get(firstMatch.classification) || ClassificationMaskCodeMap.get("fallback");
|
|
44
|
-
for (let j = firstMatch.span.start; j < firstMatch.span.end; j++) {
|
|
45
|
-
mask[j] = code;
|
|
46
|
-
}
|
|
47
|
-
// Skip forward to avoid scanning the same token again.
|
|
48
|
-
i = firstMatch.span.end;
|
|
49
|
-
}
|
|
50
|
-
return mask.join("");
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=mask.js.map
|
package/out/solver/mask.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../../solver/mask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,O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C,cAAc,CAAC,IAAI,yBAAyB,CAAC,GAAG,CAAC,UAAU,CAAE,CAAA;QAEnH,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAClE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;QACf,CAAC;QAED,uDAAuD;QACvD,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAA;IACxB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACrB,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Sister Software
|
|
3
|
-
* @license AGPL-3.0
|
|
4
|
-
* @author Teffen Ellis, et al.
|
|
5
|
-
*/
|
|
6
|
-
import { HashMapSolver, Solution, TokenContext } from "@mailwoman/core";
|
|
7
|
-
export declare class ExclusiveCartesianSolver extends HashMapSolver {
|
|
8
|
-
solve(context: TokenContext): void;
|
|
9
|
-
static exclusiveCartesian(...solutions: Solution[]): Solution[];
|
|
10
|
-
}
|
|
11
|
-
export default ExclusiveCartesianSolver;
|
|
12
|
-
//# sourceMappingURL=ExclusiveCartesianSolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExclusiveCartesianSolver.d.ts","sourceRoot":"","sources":["../../solvers/ExclusiveCartesianSolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAIvE,qBAAa,wBAAyB,SAAQ,aAAa;IAC1D,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAWlC,MAAM,CAAC,kBAAkB,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE;CA8C/D;AAED,eAAe,wBAAwB,CAAA"}
|