@zukhruf/evals 0.0.0-stage → 0.8.4
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/LICENSE +21 -0
- package/NOTICE +82 -0
- package/README.md +540 -2
- package/dist/aggregation/counts.d.ts +11 -0
- package/dist/aggregation/counts.d.ts.map +1 -0
- package/dist/aggregation/counts.js +14 -0
- package/dist/aggregation/counts.js.map +1 -0
- package/dist/aggregation/f-measure-form.d.ts +11 -0
- package/dist/aggregation/f-measure-form.d.ts.map +1 -0
- package/dist/aggregation/f-measure-form.js +25 -0
- package/dist/aggregation/f-measure-form.js.map +1 -0
- package/dist/aggregation/f-measure-ratio.d.ts +12 -0
- package/dist/aggregation/f-measure-ratio.d.ts.map +1 -0
- package/dist/aggregation/f-measure-ratio.js +21 -0
- package/dist/aggregation/f-measure-ratio.js.map +1 -0
- package/dist/aggregation/ratio-of-sums.d.ts +9 -0
- package/dist/aggregation/ratio-of-sums.d.ts.map +1 -0
- package/dist/aggregation/ratio-of-sums.js +28 -0
- package/dist/aggregation/ratio-of-sums.js.map +1 -0
- package/dist/aggregation/ratio.d.ts +8 -0
- package/dist/aggregation/ratio.d.ts.map +1 -0
- package/dist/aggregation/ratio.js +20 -0
- package/dist/aggregation/ratio.js.map +1 -0
- package/dist/classification/all-class-matches.d.ts +7 -0
- package/dist/classification/all-class-matches.d.ts.map +1 -0
- package/dist/classification/all-class-matches.js +14 -0
- package/dist/classification/all-class-matches.js.map +1 -0
- package/dist/classification/class-matches.d.ts +10 -0
- package/dist/classification/class-matches.d.ts.map +1 -0
- package/dist/classification/class-matches.js +21 -0
- package/dist/classification/class-matches.js.map +1 -0
- package/dist/classification/index.d.ts +11 -0
- package/dist/classification/index.d.ts.map +1 -0
- package/dist/classification/index.js +10 -0
- package/dist/classification/index.js.map +1 -0
- package/dist/classification/label-case.d.ts +11 -0
- package/dist/classification/label-case.d.ts.map +1 -0
- package/dist/classification/label-case.js +12 -0
- package/dist/classification/label-case.js.map +1 -0
- package/dist/classification/label-comparer.d.ts +8 -0
- package/dist/classification/label-comparer.d.ts.map +1 -0
- package/dist/classification/label-comparer.js +44 -0
- package/dist/classification/label-comparer.js.map +1 -0
- package/dist/classification/label-comparison.d.ts +12 -0
- package/dist/classification/label-comparison.d.ts.map +1 -0
- package/dist/classification/label-comparison.js +23 -0
- package/dist/classification/label-comparison.js.map +1 -0
- package/dist/classification/label-config-case.d.ts +6 -0
- package/dist/classification/label-config-case.d.ts.map +1 -0
- package/dist/classification/label-config-case.js +13 -0
- package/dist/classification/label-config-case.js.map +1 -0
- package/dist/classification/label-vars-case.d.ts +6 -0
- package/dist/classification/label-vars-case.d.ts.map +1 -0
- package/dist/classification/label-vars-case.js +17 -0
- package/dist/classification/label-vars-case.js.map +1 -0
- package/dist/classification/label.d.ts +4 -0
- package/dist/classification/label.d.ts.map +1 -0
- package/dist/classification/label.js +16 -0
- package/dist/classification/label.js.map +1 -0
- package/dist/classification/labels-match.d.ts +7 -0
- package/dist/classification/labels-match.d.ts.map +1 -0
- package/dist/classification/labels-match.js +13 -0
- package/dist/classification/labels-match.js.map +1 -0
- package/dist/classification/per-class.d.ts +12 -0
- package/dist/classification/per-class.d.ts.map +1 -0
- package/dist/classification/per-class.js +17 -0
- package/dist/classification/per-class.js.map +1 -0
- package/dist/classification/read-labels.d.ts +3 -0
- package/dist/classification/read-labels.d.ts.map +1 -0
- package/dist/classification/read-labels.js +11 -0
- package/dist/classification/read-labels.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/promptfoo/assertion-module.d.ts +23 -0
- package/dist/promptfoo/assertion-module.d.ts.map +1 -0
- package/dist/promptfoo/assertion-module.js +45 -0
- package/dist/promptfoo/assertion-module.js.map +1 -0
- package/dist/promptfoo/index.d.ts +4 -0
- package/dist/promptfoo/index.d.ts.map +1 -0
- package/dist/promptfoo/index.js +4 -0
- package/dist/promptfoo/index.js.map +1 -0
- package/dist/promptfoo/promptfoo-assertion.d.ts +18 -0
- package/dist/promptfoo/promptfoo-assertion.d.ts.map +1 -0
- package/dist/promptfoo/promptfoo-assertion.js +31 -0
- package/dist/promptfoo/promptfoo-assertion.js.map +1 -0
- package/dist/promptfoo/scorer-assertion.d.ts +18 -0
- package/dist/promptfoo/scorer-assertion.d.ts.map +1 -0
- package/dist/promptfoo/scorer-assertion.js +28 -0
- package/dist/promptfoo/scorer-assertion.js.map +1 -0
- package/dist/scorers/at-least.d.ts +9 -0
- package/dist/scorers/at-least.d.ts.map +1 -0
- package/dist/scorers/at-least.js +18 -0
- package/dist/scorers/at-least.js.map +1 -0
- package/dist/scorers/f-beta.d.ts +13 -0
- package/dist/scorers/f-beta.d.ts.map +1 -0
- package/dist/scorers/f-beta.js +22 -0
- package/dist/scorers/f-beta.js.map +1 -0
- package/dist/scorers/f1.d.ts +9 -0
- package/dist/scorers/f1.d.ts.map +1 -0
- package/dist/scorers/f1.js +8 -0
- package/dist/scorers/f1.js.map +1 -0
- package/dist/scorers/gate.d.ts +7 -0
- package/dist/scorers/gate.d.ts.map +1 -0
- package/dist/scorers/gate.js +10 -0
- package/dist/scorers/gate.js.map +1 -0
- package/dist/scorers/matches.d.ts +5 -0
- package/dist/scorers/matches.d.ts.map +1 -0
- package/dist/scorers/matches.js +2 -0
- package/dist/scorers/matches.js.map +1 -0
- package/dist/scorers/mean-of.d.ts +8 -0
- package/dist/scorers/mean-of.d.ts.map +1 -0
- package/dist/scorers/mean-of.js +15 -0
- package/dist/scorers/mean-of.js.map +1 -0
- package/dist/scorers/penalized.d.ts +9 -0
- package/dist/scorers/penalized.d.ts.map +1 -0
- package/dist/scorers/penalized.js +29 -0
- package/dist/scorers/penalized.js.map +1 -0
- package/dist/scorers/penalty.d.ts +7 -0
- package/dist/scorers/penalty.d.ts.map +1 -0
- package/dist/scorers/penalty.js +11 -0
- package/dist/scorers/penalty.js.map +1 -0
- package/dist/scorers/precision.d.ts +9 -0
- package/dist/scorers/precision.d.ts.map +1 -0
- package/dist/scorers/precision.js +13 -0
- package/dist/scorers/precision.js.map +1 -0
- package/dist/scorers/recall.d.ts +9 -0
- package/dist/scorers/recall.d.ts.map +1 -0
- package/dist/scorers/recall.js +13 -0
- package/dist/scorers/recall.js.map +1 -0
- package/dist/scorers/sample-averaged.d.ts +10 -0
- package/dist/scorers/sample-averaged.d.ts.map +1 -0
- package/dist/scorers/sample-averaged.js +17 -0
- package/dist/scorers/sample-averaged.js.map +1 -0
- package/dist/scorers/scorer.d.ts +5 -0
- package/dist/scorers/scorer.d.ts.map +1 -0
- package/dist/scorers/scorer.js +2 -0
- package/dist/scorers/scorer.js.map +1 -0
- package/dist/scorers/shortfall-penalty.d.ts +11 -0
- package/dist/scorers/shortfall-penalty.d.ts.map +1 -0
- package/dist/scorers/shortfall-penalty.js +25 -0
- package/dist/scorers/shortfall-penalty.js.map +1 -0
- package/dist/scoring/bootstrap.d.ts +16 -0
- package/dist/scoring/bootstrap.d.ts.map +1 -0
- package/dist/scoring/bootstrap.js +29 -0
- package/dist/scoring/bootstrap.js.map +1 -0
- package/dist/scoring/comparer.d.ts +5 -0
- package/dist/scoring/comparer.d.ts.map +1 -0
- package/dist/scoring/comparer.js +2 -0
- package/dist/scoring/comparer.js.map +1 -0
- package/dist/scoring/grouped.d.ts +9 -0
- package/dist/scoring/grouped.d.ts.map +1 -0
- package/dist/scoring/grouped.js +20 -0
- package/dist/scoring/grouped.js.map +1 -0
- package/dist/scoring/scorecard-scorer.d.ts +11 -0
- package/dist/scoring/scorecard-scorer.d.ts.map +1 -0
- package/dist/scoring/scorecard-scorer.js +2 -0
- package/dist/scoring/scorecard-scorer.js.map +1 -0
- package/dist/scoring/scorecard.d.ts +15 -0
- package/dist/scoring/scorecard.d.ts.map +1 -0
- package/dist/scoring/scorecard.js +2 -0
- package/dist/scoring/scorecard.js.map +1 -0
- package/dist/scoring/scorer-set.d.ts +13 -0
- package/dist/scoring/scorer-set.d.ts.map +1 -0
- package/dist/scoring/scorer-set.js +55 -0
- package/dist/scoring/scorer-set.js.map +1 -0
- package/dist/scoring/totals.d.ts +9 -0
- package/dist/scoring/totals.d.ts.map +1 -0
- package/dist/scoring/totals.js +23 -0
- package/dist/scoring/totals.js.map +1 -0
- package/dist/structured/comparison/alignment.d.ts +9 -0
- package/dist/structured/comparison/alignment.d.ts.map +1 -0
- package/dist/structured/comparison/alignment.js +2 -0
- package/dist/structured/comparison/alignment.js.map +1 -0
- package/dist/structured/comparison/alignments/by-best-match.d.ts +9 -0
- package/dist/structured/comparison/alignments/by-best-match.d.ts.map +1 -0
- package/dist/structured/comparison/alignments/by-best-match.js +25 -0
- package/dist/structured/comparison/alignments/by-best-match.js.map +1 -0
- package/dist/structured/comparison/alignments/by-position.d.ts +6 -0
- package/dist/structured/comparison/alignments/by-position.d.ts.map +1 -0
- package/dist/structured/comparison/alignments/by-position.js +9 -0
- package/dist/structured/comparison/alignments/by-position.js.map +1 -0
- package/dist/structured/comparison/bag-of-words.d.ts +10 -0
- package/dist/structured/comparison/bag-of-words.d.ts.map +1 -0
- package/dist/structured/comparison/bag-of-words.js +48 -0
- package/dist/structured/comparison/bag-of-words.js.map +1 -0
- package/dist/structured/comparison/comparator.d.ts +5 -0
- package/dist/structured/comparison/comparator.d.ts.map +1 -0
- package/dist/structured/comparison/comparator.js +2 -0
- package/dist/structured/comparison/comparator.js.map +1 -0
- package/dist/structured/comparison/comparators/json-equality.d.ts +7 -0
- package/dist/structured/comparison/comparators/json-equality.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/json-equality.js +18 -0
- package/dist/structured/comparison/comparators/json-equality.js.map +1 -0
- package/dist/structured/comparison/comparators/normalized-text.d.ts +7 -0
- package/dist/structured/comparison/comparators/normalized-text.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/normalized-text.js +13 -0
- package/dist/structured/comparison/comparators/normalized-text.js.map +1 -0
- package/dist/structured/comparison/comparators/normalized.d.ts +2 -0
- package/dist/structured/comparison/comparators/normalized.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/normalized.js +3 -0
- package/dist/structured/comparison/comparators/normalized.js.map +1 -0
- package/dist/structured/comparison/comparators/number-within.d.ts +9 -0
- package/dist/structured/comparison/comparators/number-within.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/number-within.js +18 -0
- package/dist/structured/comparison/comparators/number-within.js.map +1 -0
- package/dist/structured/comparison/comparators/python-equality.d.ts +7 -0
- package/dist/structured/comparison/comparators/python-equality.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/python-equality.js +15 -0
- package/dist/structured/comparison/comparators/python-equality.js.map +1 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts +12 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.js +23 -0
- package/dist/structured/comparison/comparators/token-overlap-at-least.js.map +1 -0
- package/dist/structured/comparison/comparators/typed-comparator.d.ts +8 -0
- package/dist/structured/comparison/comparators/typed-comparator.d.ts.map +1 -0
- package/dist/structured/comparison/comparators/typed-comparator.js +10 -0
- package/dist/structured/comparison/comparators/typed-comparator.js.map +1 -0
- package/dist/structured/comparison/comparison-spec.d.ts +17 -0
- package/dist/structured/comparison/comparison-spec.d.ts.map +1 -0
- package/dist/structured/comparison/comparison-spec.js +36 -0
- package/dist/structured/comparison/comparison-spec.js.map +1 -0
- package/dist/structured/comparison/comparison.d.ts +25 -0
- package/dist/structured/comparison/comparison.d.ts.map +1 -0
- package/dist/structured/comparison/comparison.js +94 -0
- package/dist/structured/comparison/comparison.js.map +1 -0
- package/dist/structured/comparison/field.d.ts +10 -0
- package/dist/structured/comparison/field.d.ts.map +1 -0
- package/dist/structured/comparison/field.js +29 -0
- package/dist/structured/comparison/field.js.map +1 -0
- package/dist/structured/comparison/item-pairs.d.ts +8 -0
- package/dist/structured/comparison/item-pairs.d.ts.map +1 -0
- package/dist/structured/comparison/item-pairs.js +2 -0
- package/dist/structured/comparison/item-pairs.js.map +1 -0
- package/dist/structured/comparison/json-path-query.d.ts +7 -0
- package/dist/structured/comparison/json-path-query.d.ts.map +1 -0
- package/dist/structured/comparison/json-path-query.js +133 -0
- package/dist/structured/comparison/json-path-query.js.map +1 -0
- package/dist/structured/comparison/json-value.d.ts +11 -0
- package/dist/structured/comparison/json-value.d.ts.map +1 -0
- package/dist/structured/comparison/json-value.js +56 -0
- package/dist/structured/comparison/json-value.js.map +1 -0
- package/dist/structured/comparison/leaf-pair.d.ts +24 -0
- package/dist/structured/comparison/leaf-pair.d.ts.map +1 -0
- package/dist/structured/comparison/leaf-pair.js +2 -0
- package/dist/structured/comparison/leaf-pair.js.map +1 -0
- package/dist/structured/comparison/match.d.ts +5 -0
- package/dist/structured/comparison/match.d.ts.map +1 -0
- package/dist/structured/comparison/match.js +2 -0
- package/dist/structured/comparison/match.js.map +1 -0
- package/dist/structured/comparison/name-selector.d.ts +6 -0
- package/dist/structured/comparison/name-selector.d.ts.map +1 -0
- package/dist/structured/comparison/name-selector.js +41 -0
- package/dist/structured/comparison/name-selector.js.map +1 -0
- package/dist/structured/comparison/path.d.ts +10 -0
- package/dist/structured/comparison/path.d.ts.map +1 -0
- package/dist/structured/comparison/path.js +27 -0
- package/dist/structured/comparison/path.js.map +1 -0
- package/dist/structured/comparison/tree-walk.d.ts +10 -0
- package/dist/structured/comparison/tree-walk.d.ts.map +1 -0
- package/dist/structured/comparison/tree-walk.js +140 -0
- package/dist/structured/comparison/tree-walk.js.map +1 -0
- package/dist/structured/cpython/python-text.d.ts +4 -0
- package/dist/structured/cpython/python-text.d.ts.map +1 -0
- package/dist/structured/cpython/python-text.js +62 -0
- package/dist/structured/cpython/python-text.js.map +1 -0
- package/dist/structured/index.d.ts +37 -0
- package/dist/structured/index.d.ts.map +1 -0
- package/dist/structured/index.js +27 -0
- package/dist/structured/index.js.map +1 -0
- package/dist/structured/schema/draft-07-schema.d.ts +3 -0
- package/dist/structured/schema/draft-07-schema.d.ts.map +1 -0
- package/dist/structured/schema/draft-07-schema.js +243 -0
- package/dist/structured/schema/draft-07-schema.js.map +1 -0
- package/dist/structured/schema/draft-2020-12-schema.d.ts +4 -0
- package/dist/structured/schema/draft-2020-12-schema.d.ts.map +1 -0
- package/dist/structured/schema/draft-2020-12-schema.js +280 -0
- package/dist/structured/schema/draft-2020-12-schema.js.map +1 -0
- package/dist/structured/schema/is-record.d.ts +2 -0
- package/dist/structured/schema/is-record.d.ts.map +1 -0
- package/dist/structured/schema/is-record.js +3 -0
- package/dist/structured/schema/is-record.js.map +1 -0
- package/dist/structured/schema/json-schema.d.ts +20 -0
- package/dist/structured/schema/json-schema.d.ts.map +1 -0
- package/dist/structured/schema/json-schema.js +244 -0
- package/dist/structured/schema/json-schema.js.map +1 -0
- package/dist/structured/schema/schema-type-walk.d.ts +11 -0
- package/dist/structured/schema/schema-type-walk.d.ts.map +1 -0
- package/dist/structured/schema/schema-type-walk.js +196 -0
- package/dist/structured/schema/schema-type-walk.js.map +1 -0
- package/dist/structured/scorers/all-matched.d.ts +10 -0
- package/dist/structured/scorers/all-matched.d.ts.map +1 -0
- package/dist/structured/scorers/all-matched.js +36 -0
- package/dist/structured/scorers/all-matched.js.map +1 -0
- package/dist/structured/scorers/exact-match.d.ts +7 -0
- package/dist/structured/scorers/exact-match.d.ts.map +1 -0
- package/dist/structured/scorers/exact-match.js +13 -0
- package/dist/structured/scorers/exact-match.js.map +1 -0
- package/dist/structured/scorers/item-matches.d.ts +7 -0
- package/dist/structured/scorers/item-matches.d.ts.map +1 -0
- package/dist/structured/scorers/item-matches.js +17 -0
- package/dist/structured/scorers/item-matches.js.map +1 -0
- package/dist/structured/scorers/leaf-matches.d.ts +14 -0
- package/dist/structured/scorers/leaf-matches.d.ts.map +1 -0
- package/dist/structured/scorers/leaf-matches.js +28 -0
- package/dist/structured/scorers/leaf-matches.js.map +1 -0
- package/dist/structured/scorers/parse-success.d.ts +7 -0
- package/dist/structured/scorers/parse-success.d.ts.map +1 -0
- package/dist/structured/scorers/parse-success.js +11 -0
- package/dist/structured/scorers/parse-success.js.map +1 -0
- package/dist/structured/scorers/path-matches.d.ts +5 -0
- package/dist/structured/scorers/path-matches.d.ts.map +1 -0
- package/dist/structured/scorers/path-matches.js +9 -0
- package/dist/structured/scorers/path-matches.js.map +1 -0
- package/dist/structured/scorers/required-key-recall.d.ts +8 -0
- package/dist/structured/scorers/required-key-recall.d.ts.map +1 -0
- package/dist/structured/scorers/required-key-recall.js +50 -0
- package/dist/structured/scorers/required-key-recall.js.map +1 -0
- package/dist/structured/scorers/schema-compliance.d.ts +8 -0
- package/dist/structured/scorers/schema-compliance.d.ts.map +1 -0
- package/dist/structured/scorers/schema-compliance.js +29 -0
- package/dist/structured/scorers/schema-compliance.js.map +1 -0
- package/dist/structured/scorers/token-f1.d.ts +16 -0
- package/dist/structured/scorers/token-f1.d.ts.map +1 -0
- package/dist/structured/scorers/token-f1.js +47 -0
- package/dist/structured/scorers/token-f1.js.map +1 -0
- package/dist/structured/scorers/type-precision.d.ts +10 -0
- package/dist/structured/scorers/type-precision.d.ts.map +1 -0
- package/dist/structured/scorers/type-precision.js +30 -0
- package/dist/structured/scorers/type-precision.js.map +1 -0
- package/dist/structured/scorers/valid-schema.d.ts +7 -0
- package/dist/structured/scorers/valid-schema.d.ts.map +1 -0
- package/dist/structured/scorers/valid-schema.js +11 -0
- package/dist/structured/scorers/valid-schema.js.map +1 -0
- package/dist/structured/scorers/value-matches.d.ts +6 -0
- package/dist/structured/scorers/value-matches.d.ts.map +1 -0
- package/dist/structured/scorers/value-matches.js +9 -0
- package/dist/structured/scorers/value-matches.js.map +1 -0
- package/dist/structured/scoring/case.d.ts +14 -0
- package/dist/structured/scoring/case.d.ts.map +1 -0
- package/dist/structured/scoring/case.js +14 -0
- package/dist/structured/scoring/case.js.map +1 -0
- package/dist/structured/scoring/config-case.d.ts +11 -0
- package/dist/structured/scoring/config-case.d.ts.map +1 -0
- package/dist/structured/scoring/config-case.js +22 -0
- package/dist/structured/scoring/config-case.js.map +1 -0
- package/dist/structured/scoring/per-field.d.ts +6 -0
- package/dist/structured/scoring/per-field.d.ts.map +1 -0
- package/dist/structured/scoring/per-field.js +14 -0
- package/dist/structured/scoring/per-field.js.map +1 -0
- package/dist/structured/scoring/text-vars-case.d.ts +12 -0
- package/dist/structured/scoring/text-vars-case.d.ts.map +1 -0
- package/dist/structured/scoring/text-vars-case.js +31 -0
- package/dist/structured/scoring/text-vars-case.js.map +1 -0
- package/package.json +84 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PYTHON_SPACE, PYTHON_WORD } from '@zukhruf/python';
|
|
2
|
+
import { Counts } from "../../aggregation/counts.js";
|
|
3
|
+
import { pythonStr } from "../cpython/python-text.js";
|
|
4
|
+
// The words of a leaf, each with how often it occurs, as SQuAD's
|
|
5
|
+
// normalize_answer reads them: str() of the value, lower case, punctuation
|
|
6
|
+
// and the articles a, an, the as spaces, then the runs of Python's \w
|
|
7
|
+
// (normalize_tokens of SOB's evaluate.py).
|
|
8
|
+
export class BagOfWords {
|
|
9
|
+
static #punctuation = new RegExp(`[^${PYTHON_WORD}${PYTHON_SPACE}]`, 'gu');
|
|
10
|
+
// Python's \b is a border between \w and not \w; JavaScript's \b knows only
|
|
11
|
+
// ASCII words.
|
|
12
|
+
static #articles = new RegExp(`(?<![${PYTHON_WORD}])(?:a|an|the)(?![${PYTHON_WORD}])`, 'gu');
|
|
13
|
+
static #spaces = new RegExp(`[${PYTHON_SPACE}]+`, 'u');
|
|
14
|
+
size;
|
|
15
|
+
#counts;
|
|
16
|
+
constructor(words) {
|
|
17
|
+
const counts = new Map();
|
|
18
|
+
for (const word of words)
|
|
19
|
+
counts.set(word, (counts.get(word) ?? 0) + 1);
|
|
20
|
+
this.size = words.length;
|
|
21
|
+
this.#counts = counts;
|
|
22
|
+
}
|
|
23
|
+
static of(value) {
|
|
24
|
+
return new BagOfWords(BagOfWords.#text(value)
|
|
25
|
+
.toLowerCase()
|
|
26
|
+
.replaceAll(BagOfWords.#punctuation, ' ')
|
|
27
|
+
.replaceAll(BagOfWords.#articles, ' ')
|
|
28
|
+
.split(BagOfWords.#spaces)
|
|
29
|
+
.filter((word) => word !== ''));
|
|
30
|
+
}
|
|
31
|
+
// The words that this expected bag shares with a stated bag, as often as
|
|
32
|
+
// both have them (Counter & Counter), with the size of each bag.
|
|
33
|
+
shared(stated) {
|
|
34
|
+
let hits = 0;
|
|
35
|
+
for (const [word, count] of this.#counts)
|
|
36
|
+
hits += Math.min(count, stated.#counts.get(word) ?? 0);
|
|
37
|
+
return new Counts({ hits, stated: stated.size, expected: this.size });
|
|
38
|
+
}
|
|
39
|
+
// str() of a leaf, with None and bool as evaluate.py names them.
|
|
40
|
+
static #text(value) {
|
|
41
|
+
if (value === null)
|
|
42
|
+
return 'null';
|
|
43
|
+
if (typeof value === 'boolean')
|
|
44
|
+
return value ? 'true' : 'false';
|
|
45
|
+
return pythonStr(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=bag-of-words.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bag-of-words.js","sourceRoot":"","sources":["../../../src/structured/comparison/bag-of-words.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGtD,iEAAiE;AACjE,2EAA2E;AAC3E,sEAAsE;AACtE,2CAA2C;AAC3C,MAAM,OAAO,UAAU;IACrB,MAAM,CAAU,YAAY,GAAG,IAAI,MAAM,CACvC,KAAK,WAAW,GAAG,YAAY,GAAG,EAClC,IAAI,CACL,CAAC;IACF,4EAA4E;IAC5E,eAAe;IACf,MAAM,CAAU,SAAS,GAAG,IAAI,MAAM,CACpC,QAAQ,WAAW,qBAAqB,WAAW,IAAI,EACvD,IAAI,CACL,CAAC;IACF,MAAM,CAAU,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,IAAI,EAAE,GAAG,CAAC,CAAC;IAEvD,IAAI,CAAS;IACb,OAAO,CAA8B;IAE9C,YAAoB,KAAwB;QAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;QACzC,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,KAAgB;QACxB,OAAO,IAAI,UAAU,CACnB,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC;aACpB,WAAW,EAAE;aACb,UAAU,CAAC,UAAU,CAAC,YAAY,EAAE,GAAG,CAAC;aACxC,UAAU,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;aACrC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;aACzB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CACjC,CAAC;IACJ,CAAC;IAED,yEAAyE;IACzE,iEAAiE;IACjE,MAAM,CAAC,MAAkB;QACvB,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO;YACtC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,OAAO,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,iEAAiE;IACjE,MAAM,CAAC,KAAK,CAAC,KAAgB;QAC3B,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC;QAClC,IAAI,OAAO,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QAChE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/comparator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC;CACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparator.js","sourceRoot":"","sources":["../../../src/structured/comparison/comparator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Comparator } from '../comparator.ts';
|
|
2
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
3
|
+
export declare class JsonEquality implements Comparator {
|
|
4
|
+
#private;
|
|
5
|
+
agrees(stated: LeafValue, expected: LeafValue): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=json-equality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-equality.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/json-equality.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,qBAAa,YAAa,YAAW,UAAU;;IAC7C,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO;CAaxD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Two leaves agree when JSON Schema calls them equal (2020-12, Core section
|
|
2
|
+
// 4.2.2): the same type and the same value. A number is one type, so the int
|
|
3
|
+
// 1 agrees with the float 1.0, exactly; true does not agree with 1.
|
|
4
|
+
export class JsonEquality {
|
|
5
|
+
agrees(stated, expected) {
|
|
6
|
+
if (typeof stated === 'bigint' && typeof expected === 'number')
|
|
7
|
+
return JsonEquality.#intIsFloat(stated, expected);
|
|
8
|
+
if (typeof stated === 'number' && typeof expected === 'bigint')
|
|
9
|
+
return JsonEquality.#intIsFloat(expected, stated);
|
|
10
|
+
return stated === expected;
|
|
11
|
+
}
|
|
12
|
+
// An int equals a float when the float is integral and has the same value,
|
|
13
|
+
// exactly.
|
|
14
|
+
static #intIsFloat(int, float) {
|
|
15
|
+
return Number.isInteger(float) && BigInt(float) === int;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=json-equality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-equality.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/json-equality.ts"],"names":[],"mappings":"AAGA,4EAA4E;AAC5E,6EAA6E;AAC7E,oEAAoE;AACpE,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,MAAiB,EAAE,QAAmB;QAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAC5D,OAAO,YAAY,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QACpD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ;YAC5D,OAAO,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACpD,OAAO,MAAM,KAAK,QAAQ,CAAC;IAC7B,CAAC;IAED,2EAA2E;IAC3E,WAAW;IACX,MAAM,CAAC,WAAW,CAAC,GAAW,EAAE,KAAa;QAC3C,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
2
|
+
import { TypedComparator } from './typed-comparator.ts';
|
|
3
|
+
export declare class NormalizedText extends TypedComparator<string> {
|
|
4
|
+
protected accepts(value: LeafValue): value is string;
|
|
5
|
+
protected compare(stated: string, expected: string): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=normalized-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized-text.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/normalized-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,qBAAa,cAAe,SAAQ,eAAe,CAAC,MAAM,CAAC;IACzD,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,MAAM;IAIpD,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;CAG7D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { normalized } from "./normalized.js";
|
|
2
|
+
import { TypedComparator } from "./typed-comparator.js";
|
|
3
|
+
// Two texts agree when they are the same after Unicode NFKC, lower case, and
|
|
4
|
+
// one space between words.
|
|
5
|
+
export class NormalizedText extends TypedComparator {
|
|
6
|
+
accepts(value) {
|
|
7
|
+
return typeof value === 'string';
|
|
8
|
+
}
|
|
9
|
+
compare(stated, expected) {
|
|
10
|
+
return normalized(stated) === normalized(expected);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=normalized-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized-text.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/normalized-text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,6EAA6E;AAC7E,2BAA2B;AAC3B,MAAM,OAAO,cAAe,SAAQ,eAAuB;IAC/C,OAAO,CAAC,KAAgB;QAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;IAES,OAAO,CAAC,MAAc,EAAE,QAAgB;QAChD,OAAO,UAAU,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/normalized.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAC+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/normalized.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CACzC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
2
|
+
import { TypedComparator } from './typed-comparator.ts';
|
|
3
|
+
export declare class NumberWithin extends TypedComparator<bigint | number> {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(tolerance: number);
|
|
6
|
+
protected accepts(value: LeafValue): value is bigint | number;
|
|
7
|
+
protected compare(stated: bigint | number, expected: bigint | number): boolean;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=number-within.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-within.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/number-within.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxD,qBAAa,YAAa,SAAQ,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;;gBAGpD,SAAS,EAAE,MAAM;IAK7B,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,MAAM,GAAG,MAAM;IAI7D,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;CAGrE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypedComparator } from "./typed-comparator.js";
|
|
2
|
+
// Two numbers agree when they differ by at most the tolerance. An int and a
|
|
3
|
+
// float compare as JavaScript numbers, so an int past 2^53 loses its last
|
|
4
|
+
// digits.
|
|
5
|
+
export class NumberWithin extends TypedComparator {
|
|
6
|
+
#tolerance;
|
|
7
|
+
constructor(tolerance) {
|
|
8
|
+
super();
|
|
9
|
+
this.#tolerance = tolerance;
|
|
10
|
+
}
|
|
11
|
+
accepts(value) {
|
|
12
|
+
return typeof value === 'bigint' || typeof value === 'number';
|
|
13
|
+
}
|
|
14
|
+
compare(stated, expected) {
|
|
15
|
+
return Math.abs(Number(stated) - Number(expected)) <= this.#tolerance;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=number-within.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-within.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/number-within.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,4EAA4E;AAC5E,0EAA0E;AAC1E,UAAU;AACV,MAAM,OAAO,YAAa,SAAQ,eAAgC;IACvD,UAAU,CAAS;IAE5B,YAAY,SAAiB;QAC3B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAES,OAAO,CAAC,KAAgB;QAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;IAChE,CAAC;IAES,OAAO,CAAC,MAAuB,EAAE,QAAyB;QAClE,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Comparator } from '../comparator.ts';
|
|
2
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
3
|
+
export declare class PythonEquality implements Comparator {
|
|
4
|
+
#private;
|
|
5
|
+
agrees(stated: LeafValue, expected: LeafValue): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=python-equality.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-equality.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/python-equality.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,qBAAa,cAAe,YAAW,UAAU;;IAG/C,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO;CAWxD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { JsonEquality } from "./json-equality.js";
|
|
2
|
+
// Two leaves agree as Python's == says: a bool is an int (True == 1 == 1.0),
|
|
3
|
+
// and otherwise as JSON equality says. SOB's caller gives it (evaluate.py:571).
|
|
4
|
+
export class PythonEquality {
|
|
5
|
+
#json = new JsonEquality();
|
|
6
|
+
agrees(stated, expected) {
|
|
7
|
+
return this.#json.agrees(PythonEquality.#asInt(stated), PythonEquality.#asInt(expected));
|
|
8
|
+
}
|
|
9
|
+
static #asInt(value) {
|
|
10
|
+
if (typeof value === 'boolean')
|
|
11
|
+
return value ? 1n : 0n;
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=python-equality.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-equality.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/python-equality.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,6EAA6E;AAC7E,gFAAgF;AAChF,MAAM,OAAO,cAAc;IAChB,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;IAEpC,MAAM,CAAC,MAAiB,EAAE,QAAmB;QAC3C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CACtB,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAC7B,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAChC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAgB;QAC5B,IAAI,OAAO,KAAK,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FMeasureForm } from '../../../aggregation/f-measure-form.ts';
|
|
2
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
3
|
+
import { TypedComparator } from './typed-comparator.ts';
|
|
4
|
+
export declare class TokenOverlapAtLeast extends TypedComparator<string> {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(threshold: number, { form }?: {
|
|
7
|
+
readonly form?: FMeasureForm;
|
|
8
|
+
});
|
|
9
|
+
protected accepts(value: LeafValue): value is string;
|
|
10
|
+
protected compare(stated: string, expected: string): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=token-overlap-at-least.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-overlap-at-least.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/token-overlap-at-least.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxD,qBAAa,mBAAoB,SAAQ,eAAe,CAAC,MAAM,CAAC;;gBAK5D,SAAS,EAAE,MAAM,EACjB,EAAE,IAAuB,EAAE,GAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAA;KAAO;IAOpE,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,MAAM;IAIpD,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;CAI7D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CountsForm, } from "../../../aggregation/f-measure-form.js";
|
|
2
|
+
import { BagOfWords } from "../bag-of-words.js";
|
|
3
|
+
import { TypedComparator } from "./typed-comparator.js";
|
|
4
|
+
// Two texts agree when the F1 of their shared words, as SQuAD reads words,
|
|
5
|
+
// reaches the threshold. Two texts that share no word have the F1 0. The form
|
|
6
|
+
// is the arithmetic of the F1.
|
|
7
|
+
export class TokenOverlapAtLeast extends TypedComparator {
|
|
8
|
+
#threshold;
|
|
9
|
+
#form;
|
|
10
|
+
constructor(threshold, { form = new CountsForm() } = {}) {
|
|
11
|
+
super();
|
|
12
|
+
this.#threshold = threshold;
|
|
13
|
+
this.#form = form;
|
|
14
|
+
}
|
|
15
|
+
accepts(value) {
|
|
16
|
+
return typeof value === 'string';
|
|
17
|
+
}
|
|
18
|
+
compare(stated, expected) {
|
|
19
|
+
const counts = BagOfWords.of(expected).shared(BagOfWords.of(stated));
|
|
20
|
+
return this.#form.of(counts, 1) >= this.#threshold;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=token-overlap-at-least.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-overlap-at-least.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/token-overlap-at-least.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAEX,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,2EAA2E;AAC3E,8EAA8E;AAC9E,+BAA+B;AAC/B,MAAM,OAAO,mBAAoB,SAAQ,eAAuB;IACrD,UAAU,CAAS;IACnB,KAAK,CAAe;IAE7B,YACE,SAAiB,EACjB,EAAE,IAAI,GAAG,IAAI,UAAU,EAAE,KAAuC,EAAE;QAElE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAES,OAAO,CAAC,KAAgB;QAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;IACnC,CAAC;IAES,OAAO,CAAC,MAAc,EAAE,QAAgB;QAChD,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Comparator } from '../comparator.ts';
|
|
2
|
+
import type { LeafValue } from '../leaf-pair.ts';
|
|
3
|
+
export declare abstract class TypedComparator<T extends LeafValue> implements Comparator {
|
|
4
|
+
protected abstract accepts(value: LeafValue): value is T;
|
|
5
|
+
protected abstract compare(stated: T, expected: T): boolean;
|
|
6
|
+
agrees(stated: LeafValue, expected: LeafValue): boolean;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=typed-comparator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-comparator.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/typed-comparator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,8BAAsB,eAAe,CACnC,CAAC,SAAS,SAAS,CACnB,YAAW,UAAU;IACrB,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,IAAI,CAAC;IAExD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO;IAE3D,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,GAAG,OAAO;CAOxD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// A comparator of the leaves of one type: two leaves agree only when both
|
|
2
|
+
// have the type, and the subclass agrees on them (Template Method).
|
|
3
|
+
export class TypedComparator {
|
|
4
|
+
agrees(stated, expected) {
|
|
5
|
+
return (this.accepts(stated) &&
|
|
6
|
+
this.accepts(expected) &&
|
|
7
|
+
this.compare(stated, expected));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=typed-comparator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-comparator.js","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/typed-comparator.ts"],"names":[],"mappings":"AAGA,0EAA0E;AAC1E,oEAAoE;AACpE,MAAM,OAAgB,eAAe;IAOnC,MAAM,CAAC,MAAiB,EAAE,QAAmB;QAC3C,OAAO,CACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;YACpB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YACtB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Alignment } from './alignment.ts';
|
|
2
|
+
import type { Comparator } from './comparator.ts';
|
|
3
|
+
import type { Field } from './field.ts';
|
|
4
|
+
export type ComparisonSpecOptions = {
|
|
5
|
+
readonly arrays?: Readonly<Record<string, Alignment>>;
|
|
6
|
+
readonly comparator?: Comparator;
|
|
7
|
+
readonly fields?: Readonly<Record<string, Comparator>>;
|
|
8
|
+
readonly exclude?: readonly string[];
|
|
9
|
+
};
|
|
10
|
+
export declare class ComparisonSpec {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options?: ComparisonSpecOptions);
|
|
13
|
+
alignmentOf(field: Field): Alignment;
|
|
14
|
+
comparatorOf(field: Field): Comparator;
|
|
15
|
+
excludes(field: Field): boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=comparison-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison-spec.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/comparison-spec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,MAAM,MAAM,qBAAqB,GAAG;IAGlC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAEtD,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAEjC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IAEvD,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC,CAAC;AAMF,qBAAa,cAAc;;gBAQb,OAAO,GAAE,qBAA0B;IAS/C,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS;IAIpC,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU;IAItC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;CAYhC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ByPosition } from "./alignments/by-position.js";
|
|
2
|
+
import { JsonEquality } from "./comparators/json-equality.js";
|
|
3
|
+
import { JsonPathQuery } from "./json-path-query.js";
|
|
4
|
+
// The rules to compare two values of one kind. A key is a field written as a
|
|
5
|
+
// JSONPath query (RFC 9535) of name selectors and the wildcard selector, such
|
|
6
|
+
// as `$.offers[*].value.amount` or `$['a.b']`; `$` is the root. A key that is
|
|
7
|
+
// not such a query throws a SyntaxError when the spec is built.
|
|
8
|
+
export class ComparisonSpec {
|
|
9
|
+
static #byPosition = new ByPosition();
|
|
10
|
+
#comparator;
|
|
11
|
+
#arrays;
|
|
12
|
+
#fields;
|
|
13
|
+
#exclude;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.#comparator = options.comparator ?? new JsonEquality();
|
|
16
|
+
this.#arrays = ComparisonSpec.#byField(options.arrays ?? {});
|
|
17
|
+
this.#fields = ComparisonSpec.#byField(options.fields ?? {});
|
|
18
|
+
this.#exclude = new Set((options.exclude ?? []).map((key) => new JsonPathQuery(key).field.id));
|
|
19
|
+
}
|
|
20
|
+
alignmentOf(field) {
|
|
21
|
+
return this.#arrays.get(field.id) ?? ComparisonSpec.#byPosition;
|
|
22
|
+
}
|
|
23
|
+
comparatorOf(field) {
|
|
24
|
+
return this.#fields.get(field.id) ?? this.#comparator;
|
|
25
|
+
}
|
|
26
|
+
excludes(field) {
|
|
27
|
+
return this.#exclude.has(field.id);
|
|
28
|
+
}
|
|
29
|
+
static #byField(entries) {
|
|
30
|
+
return new Map(Object.entries(entries).map(([key, value]) => [
|
|
31
|
+
new JsonPathQuery(key).field.id,
|
|
32
|
+
value,
|
|
33
|
+
]));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=comparison-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison-spec.js","sourceRoot":"","sources":["../../../src/structured/comparison/comparison-spec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAcrD,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,gEAAgE;AAChE,MAAM,OAAO,cAAc;IACzB,MAAM,CAAU,WAAW,GAAG,IAAI,UAAU,EAAE,CAAC;IAEtC,WAAW,CAAa;IACxB,OAAO,CAAiC;IACxC,OAAO,CAAkC;IACzC,QAAQ,CAAsB;IAEvC,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,YAAY,EAAE,CAAC;QAC5D,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CACrB,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CACtE,CAAC;IACJ,CAAC;IAED,WAAW,CAAC,KAAY;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,cAAc,CAAC,WAAW,CAAC;IAClE,CAAC;IAED,YAAY,CAAC,KAAY;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC;IACxD,CAAC;IAED,QAAQ,CAAC,KAAY;QACnB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,QAAQ,CAAI,OAAoC;QACrD,OAAO,IAAI,GAAG,CACZ,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YAC5C,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;YAC/B,KAAK;SACN,CAAC,CACH,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { JsonData } from '@zukhruf/python';
|
|
2
|
+
import type { JsonSchema, Validation } from '../schema/json-schema.ts';
|
|
3
|
+
import type { Case } from '../scoring/case.ts';
|
|
4
|
+
import type { Field } from './field.ts';
|
|
5
|
+
import type { ItemPairs } from './item-pairs.ts';
|
|
6
|
+
import type { LeafPair } from './leaf-pair.ts';
|
|
7
|
+
import type { Path } from './path.ts';
|
|
8
|
+
export declare class Comparison {
|
|
9
|
+
#private;
|
|
10
|
+
readonly case: Case;
|
|
11
|
+
readonly parsed: boolean;
|
|
12
|
+
readonly stated: JsonData;
|
|
13
|
+
constructor(testCase: Case, stated: JsonData, leaves: readonly LeafPair[], statedPaths: readonly Path[], arrays: readonly ItemPairs[]);
|
|
14
|
+
leaves({ nullIsMissing }?: {
|
|
15
|
+
readonly nullIsMissing: boolean;
|
|
16
|
+
}): readonly LeafPair[];
|
|
17
|
+
arrays(): readonly ItemPairs[];
|
|
18
|
+
fields(): readonly Field[];
|
|
19
|
+
only(field: Field): Comparison;
|
|
20
|
+
statedFields(): readonly Field[];
|
|
21
|
+
get schema(): JsonSchema;
|
|
22
|
+
get compliant(): boolean;
|
|
23
|
+
get validation(): Validation;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=comparison.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/comparison.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAatC,qBAAa,UAAU;;IACrB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAGpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAGzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;gBAMxB,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,WAAW,EAAE,SAAS,IAAI,EAAE,EAC5B,MAAM,EAAE,SAAS,SAAS,EAAE;IAa9B,MAAM,CACJ,EAAE,aAAa,EAAE,GAAE;QAAE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAA;KAEnD,GACA,SAAS,QAAQ,EAAE;IActB,MAAM,IAAI,SAAS,SAAS,EAAE;IAM9B,MAAM,IAAI,SAAS,KAAK,EAAE;IAc1B,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU;IAgB9B,YAAY,IAAI,SAAS,KAAK,EAAE;IAMhC,IAAI,MAAM,IAAI,UAAU,CAOvB;IAID,IAAI,SAAS,IAAI,OAAO,CAEvB;IAID,IAAI,UAAU,IAAI,UAAU,CAG3B;CACF"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// The result of the walk for one stated value and its case: the leaf pairs,
|
|
2
|
+
// the item pairs of each array, and if the stated value is parsed. The
|
|
3
|
+
// scorers share it, so each fact is computed once.
|
|
4
|
+
export class Comparison {
|
|
5
|
+
case;
|
|
6
|
+
// parse_candidate of SOB's evaluate.py: only an object or an array counts
|
|
7
|
+
// as parsed.
|
|
8
|
+
parsed;
|
|
9
|
+
// The stated value when it is parsed, else null (the candidate of
|
|
10
|
+
// evaluate.py).
|
|
11
|
+
stated;
|
|
12
|
+
#whole;
|
|
13
|
+
#leaves;
|
|
14
|
+
#arrays;
|
|
15
|
+
constructor(testCase, stated, leaves, statedPaths, arrays) {
|
|
16
|
+
this.case = testCase;
|
|
17
|
+
this.parsed = stated instanceof Map || Array.isArray(stated);
|
|
18
|
+
this.stated = this.parsed ? stated : null;
|
|
19
|
+
this.#whole = { stated, statedPaths };
|
|
20
|
+
this.#leaves = leaves;
|
|
21
|
+
this.#arrays = arrays;
|
|
22
|
+
}
|
|
23
|
+
// The leaf pairs: the expected leaves in the order of the expected value,
|
|
24
|
+
// as evaluate.py reads them. With nullIsMissing, a null side is no value,
|
|
25
|
+
// so a pair keeps only its other side, and a pair of two nulls goes.
|
|
26
|
+
leaves({ nullIsMissing } = {
|
|
27
|
+
nullIsMissing: false,
|
|
28
|
+
}) {
|
|
29
|
+
if (!nullIsMissing)
|
|
30
|
+
return this.#leaves;
|
|
31
|
+
return this.#leaves.flatMap((pair) => {
|
|
32
|
+
const expected = pair.expected?.value === null ? undefined : pair.expected;
|
|
33
|
+
const stated = pair.stated?.value === null ? undefined : pair.stated;
|
|
34
|
+
if (expected !== undefined && stated !== undefined)
|
|
35
|
+
return [pair];
|
|
36
|
+
if (expected !== undefined)
|
|
37
|
+
return [{ expected }];
|
|
38
|
+
if (stated !== undefined)
|
|
39
|
+
return [{ stated }];
|
|
40
|
+
return [];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// The item pairs of each array that the walk reached, on either side.
|
|
44
|
+
arrays() {
|
|
45
|
+
return this.#arrays;
|
|
46
|
+
}
|
|
47
|
+
// The fields of the leaf pairs and of the item pairs, each once, in the
|
|
48
|
+
// order the walk reached them.
|
|
49
|
+
fields() {
|
|
50
|
+
const fields = new Map();
|
|
51
|
+
for (const pair of this.#leaves) {
|
|
52
|
+
const field = (pair.expected ?? pair.stated).path.field;
|
|
53
|
+
if (!fields.has(field.id))
|
|
54
|
+
fields.set(field.id, field);
|
|
55
|
+
}
|
|
56
|
+
for (const { field } of this.#arrays)
|
|
57
|
+
if (!fields.has(field.id))
|
|
58
|
+
fields.set(field.id, field);
|
|
59
|
+
return [...fields.values()];
|
|
60
|
+
}
|
|
61
|
+
// The comparison of one field: its leaf pairs and its item pairs. The
|
|
62
|
+
// facts of the whole stated value stay, so a gate such as SchemaCompliance
|
|
63
|
+
// still reads the whole record.
|
|
64
|
+
only(field) {
|
|
65
|
+
const comparison = new Comparison(this.case, this.#whole.stated, this.#leaves.filter((pair) => (pair.expected ?? pair.stated).path.field.id === field.id), this.#whole.statedPaths, this.#arrays.filter((items) => items.field.id === field.id));
|
|
66
|
+
comparison.#whole = this.#whole;
|
|
67
|
+
return comparison;
|
|
68
|
+
}
|
|
69
|
+
// The field of each value of the stated value under its root, of objects
|
|
70
|
+
// and arrays too.
|
|
71
|
+
statedFields() {
|
|
72
|
+
return this.#whole.statedPaths.map((path) => path.field);
|
|
73
|
+
}
|
|
74
|
+
// The JSON Schema of the case. A scorer that reads it throws for a case
|
|
75
|
+
// without one.
|
|
76
|
+
get schema() {
|
|
77
|
+
const { schema } = this.case;
|
|
78
|
+
if (schema === undefined)
|
|
79
|
+
throw new Error('The case has no JSON Schema: give its case reader one, for the scorers that read the schema');
|
|
80
|
+
return schema;
|
|
81
|
+
}
|
|
82
|
+
// schema_compliance of evaluate.py: parsed, a valid schema, and the stated
|
|
83
|
+
// value agrees with it.
|
|
84
|
+
get compliant() {
|
|
85
|
+
return this.parsed && this.schema.valid && this.validation.valid;
|
|
86
|
+
}
|
|
87
|
+
// What the validator says about the stated value; the schema must be
|
|
88
|
+
// valid.
|
|
89
|
+
get validation() {
|
|
90
|
+
this.#whole.validation ??= this.schema.validate(this.#whole.stated);
|
|
91
|
+
return this.#whole.validation;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=comparison.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparison.js","sourceRoot":"","sources":["../../../src/structured/comparison/comparison.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type FieldStep = string | typeof Field.item;
|
|
2
|
+
export declare class Field {
|
|
3
|
+
static readonly item: unique symbol;
|
|
4
|
+
readonly steps: readonly FieldStep[];
|
|
5
|
+
readonly id: string;
|
|
6
|
+
constructor(steps: readonly FieldStep[]);
|
|
7
|
+
toString(): string;
|
|
8
|
+
child(step: FieldStep): Field;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/field.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,KAAK,CAAC,IAAI,CAAC;AAKnD,qBAAa,KAAK;IAChB,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,MAAM,CAAiC;IAEpE,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;IAIrC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAER,KAAK,EAAE,SAAS,SAAS,EAAE;IAWvC,QAAQ,IAAI,MAAM;IAMlB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK;CAG9B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NameSelector } from "./name-selector.js";
|
|
2
|
+
// A path without its item positions, such as offers, an item, value, amount
|
|
3
|
+
// (written $.offers[*].value.amount). A field is its steps, as a path is, so a
|
|
4
|
+
// property named "a.b" and the property b of a are different fields.
|
|
5
|
+
export class Field {
|
|
6
|
+
static item = Symbol('an item of an array');
|
|
7
|
+
steps;
|
|
8
|
+
// The identity of the field: two fields with the same steps have the same
|
|
9
|
+
// id. A key is a JSON string and an item is 0, so no two step lists share an
|
|
10
|
+
// id.
|
|
11
|
+
id;
|
|
12
|
+
constructor(steps) {
|
|
13
|
+
this.steps = steps;
|
|
14
|
+
this.id = JSON.stringify(steps.map((step) => (step === Field.item ? 0 : step)));
|
|
15
|
+
}
|
|
16
|
+
// The field as a JSONPath query (RFC 9535), as a key of a ComparisonSpec
|
|
17
|
+
// writes it: the wildcard selector for an item, such as
|
|
18
|
+
// $.offers[*].value.amount, and a bracketed name selector for a key that is
|
|
19
|
+
// not a member-name-shorthand, such as $['a.b'].
|
|
20
|
+
toString() {
|
|
21
|
+
return `$${this.steps
|
|
22
|
+
.map((step) => (step === Field.item ? '[*]' : NameSelector.segment(step)))
|
|
23
|
+
.join('')}`;
|
|
24
|
+
}
|
|
25
|
+
child(step) {
|
|
26
|
+
return new Field([...this.steps, step]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../../src/structured/comparison/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,4EAA4E;AAC5E,+EAA+E;AAC/E,qEAAqE;AACrE,MAAM,OAAO,KAAK;IAChB,MAAM,CAAU,IAAI,GAAkB,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAE3D,KAAK,CAAuB;IACrC,0EAA0E;IAC1E,6EAA6E;IAC7E,MAAM;IACG,EAAE,CAAS;IAEpB,YAAY,KAA2B;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,SAAS,CACtB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,yEAAyE;IACzE,wDAAwD;IACxD,4EAA4E;IAC5E,iDAAiD;IACjD,QAAQ;QACN,OAAO,IAAI,IAAI,CAAC,KAAK;aAClB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;aACzE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,IAAe;QACnB,OAAO,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-pairs.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/item-pairs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKxC,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-pairs.js","sourceRoot":"","sources":["../../../src/structured/comparison/item-pairs.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-path-query.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/json-path-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAC;AAQnD,qBAAa,aAAa;;IAYxB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;gBAIV,IAAI,EAAE,MAAM;CAsGzB"}
|