@zukhruf/evals 0.8.3 → 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.
Files changed (138) hide show
  1. package/README.md +22 -10
  2. package/dist/aggregation/f-measure-form.d.ts +11 -0
  3. package/dist/aggregation/f-measure-form.d.ts.map +1 -0
  4. package/dist/aggregation/f-measure-form.js +25 -0
  5. package/dist/aggregation/f-measure-form.js.map +1 -0
  6. package/dist/aggregation/f-measure-ratio.d.ts +12 -0
  7. package/dist/aggregation/f-measure-ratio.d.ts.map +1 -0
  8. package/dist/aggregation/f-measure-ratio.js +21 -0
  9. package/dist/aggregation/f-measure-ratio.js.map +1 -0
  10. package/dist/aggregation/ratio-of-sums.d.ts +1 -0
  11. package/dist/aggregation/ratio-of-sums.d.ts.map +1 -1
  12. package/dist/aggregation/ratio-of-sums.js +7 -0
  13. package/dist/aggregation/ratio-of-sums.js.map +1 -1
  14. package/dist/classification/all-class-matches.d.ts +7 -0
  15. package/dist/classification/all-class-matches.d.ts.map +1 -0
  16. package/dist/classification/all-class-matches.js +14 -0
  17. package/dist/classification/all-class-matches.js.map +1 -0
  18. package/dist/classification/class-matches.d.ts +10 -0
  19. package/dist/classification/class-matches.d.ts.map +1 -0
  20. package/dist/classification/class-matches.js +21 -0
  21. package/dist/classification/class-matches.js.map +1 -0
  22. package/dist/classification/index.d.ts +11 -0
  23. package/dist/classification/index.d.ts.map +1 -0
  24. package/dist/classification/index.js +10 -0
  25. package/dist/classification/index.js.map +1 -0
  26. package/dist/classification/label-case.d.ts +11 -0
  27. package/dist/classification/label-case.d.ts.map +1 -0
  28. package/dist/classification/label-case.js +12 -0
  29. package/dist/classification/label-case.js.map +1 -0
  30. package/dist/classification/label-comparer.d.ts +8 -0
  31. package/dist/classification/label-comparer.d.ts.map +1 -0
  32. package/dist/classification/label-comparer.js +44 -0
  33. package/dist/classification/label-comparer.js.map +1 -0
  34. package/dist/classification/label-comparison.d.ts +12 -0
  35. package/dist/classification/label-comparison.d.ts.map +1 -0
  36. package/dist/classification/label-comparison.js +23 -0
  37. package/dist/classification/label-comparison.js.map +1 -0
  38. package/dist/classification/label-config-case.d.ts +6 -0
  39. package/dist/classification/label-config-case.d.ts.map +1 -0
  40. package/dist/classification/label-config-case.js +13 -0
  41. package/dist/classification/label-config-case.js.map +1 -0
  42. package/dist/classification/label-vars-case.d.ts +6 -0
  43. package/dist/classification/label-vars-case.d.ts.map +1 -0
  44. package/dist/classification/label-vars-case.js +17 -0
  45. package/dist/classification/label-vars-case.js.map +1 -0
  46. package/dist/classification/label.d.ts +4 -0
  47. package/dist/classification/label.d.ts.map +1 -0
  48. package/dist/classification/label.js +16 -0
  49. package/dist/classification/label.js.map +1 -0
  50. package/dist/classification/labels-match.d.ts +7 -0
  51. package/dist/classification/labels-match.d.ts.map +1 -0
  52. package/dist/classification/labels-match.js +13 -0
  53. package/dist/classification/labels-match.js.map +1 -0
  54. package/dist/classification/per-class.d.ts +12 -0
  55. package/dist/classification/per-class.d.ts.map +1 -0
  56. package/dist/classification/per-class.js +17 -0
  57. package/dist/classification/per-class.js.map +1 -0
  58. package/dist/classification/read-labels.d.ts +3 -0
  59. package/dist/classification/read-labels.d.ts.map +1 -0
  60. package/dist/classification/read-labels.js +11 -0
  61. package/dist/classification/read-labels.js.map +1 -0
  62. package/dist/index.d.ts +5 -1
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +4 -1
  65. package/dist/index.js.map +1 -1
  66. package/dist/promptfoo/index.d.ts +1 -0
  67. package/dist/promptfoo/index.d.ts.map +1 -1
  68. package/dist/promptfoo/index.js +1 -0
  69. package/dist/promptfoo/index.js.map +1 -1
  70. package/dist/promptfoo/scorer-assertion.d.ts +18 -0
  71. package/dist/promptfoo/scorer-assertion.d.ts.map +1 -0
  72. package/dist/{structured/promptfoo → promptfoo}/scorer-assertion.js +5 -11
  73. package/dist/promptfoo/scorer-assertion.js.map +1 -0
  74. package/dist/scorers/f-beta.d.ts +13 -0
  75. package/dist/scorers/f-beta.d.ts.map +1 -0
  76. package/dist/scorers/f-beta.js +22 -0
  77. package/dist/scorers/f-beta.js.map +1 -0
  78. package/dist/scorers/f1.d.ts +6 -6
  79. package/dist/scorers/f1.d.ts.map +1 -1
  80. package/dist/scorers/f1.js +5 -9
  81. package/dist/scorers/f1.js.map +1 -1
  82. package/dist/scorers/penalized.d.ts.map +1 -1
  83. package/dist/scorers/penalized.js +2 -1
  84. package/dist/scorers/penalized.js.map +1 -1
  85. package/dist/scoring/bootstrap.js +3 -5
  86. package/dist/scoring/bootstrap.js.map +1 -1
  87. package/dist/scoring/comparer.d.ts +5 -0
  88. package/dist/scoring/comparer.d.ts.map +1 -0
  89. package/dist/scoring/comparer.js +2 -0
  90. package/dist/scoring/comparer.js.map +1 -0
  91. package/dist/scoring/grouped.d.ts +9 -0
  92. package/dist/scoring/grouped.d.ts.map +1 -0
  93. package/dist/scoring/grouped.js +20 -0
  94. package/dist/scoring/grouped.js.map +1 -0
  95. package/dist/scoring/scorer-set.d.ts +13 -0
  96. package/dist/scoring/scorer-set.d.ts.map +1 -0
  97. package/dist/scoring/scorer-set.js +55 -0
  98. package/dist/scoring/scorer-set.js.map +1 -0
  99. package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts +4 -1
  100. package/dist/structured/comparison/comparators/token-overlap-at-least.d.ts.map +1 -1
  101. package/dist/structured/comparison/comparators/token-overlap-at-least.js +7 -4
  102. package/dist/structured/comparison/comparators/token-overlap-at-least.js.map +1 -1
  103. package/dist/structured/comparison/json-value.d.ts +1 -0
  104. package/dist/structured/comparison/json-value.d.ts.map +1 -1
  105. package/dist/structured/comparison/json-value.js +11 -2
  106. package/dist/structured/comparison/json-value.js.map +1 -1
  107. package/dist/structured/comparison/tree-walk.d.ts +5 -5
  108. package/dist/structured/comparison/tree-walk.d.ts.map +1 -1
  109. package/dist/structured/comparison/tree-walk.js +8 -4
  110. package/dist/structured/comparison/tree-walk.js.map +1 -1
  111. package/dist/structured/cpython/python-text.d.ts +0 -1
  112. package/dist/structured/cpython/python-text.d.ts.map +1 -1
  113. package/dist/structured/cpython/python-text.js +1 -18
  114. package/dist/structured/cpython/python-text.js.map +1 -1
  115. package/dist/structured/index.d.ts +0 -2
  116. package/dist/structured/index.d.ts.map +1 -1
  117. package/dist/structured/index.js +0 -2
  118. package/dist/structured/index.js.map +1 -1
  119. package/dist/structured/scorers/token-f1.d.ts +3 -1
  120. package/dist/structured/scorers/token-f1.d.ts.map +1 -1
  121. package/dist/structured/scorers/token-f1.js +8 -5
  122. package/dist/structured/scorers/token-f1.js.map +1 -1
  123. package/dist/structured/scoring/per-field.d.ts +3 -6
  124. package/dist/structured/scoring/per-field.d.ts.map +1 -1
  125. package/dist/structured/scoring/per-field.js +8 -17
  126. package/dist/structured/scoring/per-field.js.map +1 -1
  127. package/package.json +10 -4
  128. package/dist/aggregation/f1-ratio.d.ts +0 -8
  129. package/dist/aggregation/f1-ratio.d.ts.map +0 -1
  130. package/dist/aggregation/f1-ratio.js +0 -24
  131. package/dist/aggregation/f1-ratio.js.map +0 -1
  132. package/dist/structured/promptfoo/scorer-assertion.d.ts +0 -22
  133. package/dist/structured/promptfoo/scorer-assertion.d.ts.map +0 -1
  134. package/dist/structured/promptfoo/scorer-assertion.js.map +0 -1
  135. package/dist/structured/scoring/scorer-set.d.ts +0 -15
  136. package/dist/structured/scoring/scorer-set.d.ts.map +0 -1
  137. package/dist/structured/scoring/scorer-set.js +0 -60
  138. package/dist/structured/scoring/scorer-set.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ import { Grouped } from "../scoring/grouped.js";
2
+ // A scorer for each class of a comparison: in a ScorerSet, it gives the ratio
3
+ // of its scorer on the comparison of each class, under the label
4
+ // `${class} ${label}`. Without labels, the classes are the labels of both
5
+ // sides of the answer; with labels, only those classes.
6
+ export class PerClass extends Grouped {
7
+ #labels;
8
+ constructor(scorer, { labels } = {}) {
9
+ super(scorer);
10
+ this.#labels = labels;
11
+ }
12
+ *groups(comparison) {
13
+ for (const label of this.#labels ?? comparison.labels())
14
+ yield [`${label}`, comparison.only(label)];
15
+ }
16
+ }
17
+ //# sourceMappingURL=per-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"per-class.js","sourceRoot":"","sources":["../../src/classification/per-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIhD,8EAA8E;AAC9E,iEAAiE;AACjE,0EAA0E;AAC1E,wDAAwD;AACxD,MAAM,OAAO,QAAS,SAAQ,OAAwB;IAC3C,OAAO,CAA+B;IAE/C,YACE,MAA+B,EAC/B,EAAE,MAAM,KAA6C,EAAE;QAEvD,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAES,CAAC,MAAM,CACf,UAA2B;QAE3B,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE;YACrD,MAAM,CAAC,GAAG,KAAK,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { type Label } from './label.ts';
2
+ export declare function readLabels(value: unknown, name: string): Label | Label[];
3
+ //# sourceMappingURL=read-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-labels.d.ts","sourceRoot":"","sources":["../../src/classification/read-labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAW,MAAM,YAAY,CAAC;AAIjD,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,CAMxE"}
@@ -0,0 +1,11 @@
1
+ import { isLabel } from "./label.js";
2
+ // The expected labels of a plain object of a runner: a label or a list of
3
+ // labels.
4
+ export function readLabels(value, name) {
5
+ if (isLabel(value))
6
+ return value;
7
+ if (Array.isArray(value) && value.every(isLabel))
8
+ return value;
9
+ throw new Error(`${name} is a label (a number or a string) or a list of labels, not ${JSON.stringify(value)}`);
10
+ }
11
+ //# sourceMappingURL=read-labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-labels.js","sourceRoot":"","sources":["../../src/classification/read-labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjD,0EAA0E;AAC1E,UAAU;AACV,MAAM,UAAU,UAAU,CAAC,KAAc,EAAE,IAAY;IACrD,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/D,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,+DAA+D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAC9F,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { Ratio } from './aggregation/ratio.ts';
2
2
  export { RatioOfSums } from './aggregation/ratio-of-sums.ts';
3
3
  export { Counts } from './aggregation/counts.ts';
4
- export { F1Ratio } from './aggregation/f1-ratio.ts';
4
+ export { CountsForm, type FMeasureForm, PrecisionRecallForm, } from './aggregation/f-measure-form.ts';
5
5
  export type { Check, Scorecard } from './scoring/scorecard.ts';
6
6
  export type { CaseReader, ScorecardScorer, Weighted, } from './scoring/scorecard-scorer.ts';
7
7
  export { Totals } from './scoring/totals.ts';
@@ -10,6 +10,7 @@ export type { Scorer } from './scorers/scorer.ts';
10
10
  export type { Matches } from './scorers/matches.ts';
11
11
  export { Precision } from './scorers/precision.ts';
12
12
  export { Recall } from './scorers/recall.ts';
13
+ export { FBeta } from './scorers/f-beta.ts';
13
14
  export { F1 } from './scorers/f1.ts';
14
15
  export { Penalty } from './scorers/penalty.ts';
15
16
  export { Gate } from './scorers/gate.ts';
@@ -18,4 +19,7 @@ export { AtLeast } from './scorers/at-least.ts';
18
19
  export { ShortfallPenalty } from './scorers/shortfall-penalty.ts';
19
20
  export { SampleAveraged } from './scorers/sample-averaged.ts';
20
21
  export { MeanOf } from './scorers/mean-of.ts';
22
+ export type { Comparer } from './scoring/comparer.ts';
23
+ export { Grouped } from './scoring/grouped.ts';
24
+ export { ScorerSet } from './scoring/scorer-set.ts';
21
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EACV,UAAU,EACV,eAAe,EACf,QAAQ,GACT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,YAAY,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SA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E,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,YAAY,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export { Ratio } from "./aggregation/ratio.js";
2
2
  export { RatioOfSums } from "./aggregation/ratio-of-sums.js";
3
3
  export { Counts } from "./aggregation/counts.js";
4
- export { F1Ratio } from "./aggregation/f1-ratio.js";
4
+ export { CountsForm, PrecisionRecallForm, } from "./aggregation/f-measure-form.js";
5
5
  export { Totals } from "./scoring/totals.js";
6
6
  export { Bootstrap } from "./scoring/bootstrap.js";
7
7
  export { Precision } from "./scorers/precision.js";
8
8
  export { Recall } from "./scorers/recall.js";
9
+ export { FBeta } from "./scorers/f-beta.js";
9
10
  export { F1 } from "./scorers/f1.js";
10
11
  export { Penalty } from "./scorers/penalty.js";
11
12
  export { Gate } from "./scorers/gate.js";
@@ -14,4 +15,6 @@ export { AtLeast } from "./scorers/at-least.js";
14
15
  export { ShortfallPenalty } from "./scorers/shortfall-penalty.js";
15
16
  export { SampleAveraged } from "./scorers/sample-averaged.js";
16
17
  export { MeanOf } from "./scorers/mean-of.js";
18
+ export { Grouped } from "./scoring/grouped.js";
19
+ export { ScorerSet } from "./scoring/scorer-set.js";
17
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE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ACnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { AssertionModule, type FileAssertion, type ModuleAssertion, type VarsContext, } from './assertion-module.ts';
2
2
  export { type AssertionContext, type GradingResult, PromptfooAssertion, } from './promptfoo-assertion.ts';
3
+ export { ScorerAssertion } from './scorer-assertion.ts';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/promptfoo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/promptfoo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { AssertionModule, } from "./assertion-module.js";
2
2
  export { PromptfooAssertion, } from "./promptfoo-assertion.js";
3
+ export { ScorerAssertion } from "./scorer-assertion.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/promptfoo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAIhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,kBAAkB,GACnB,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/promptfoo/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAIhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { Scorer } from '../scorers/scorer.ts';
2
+ import type { Comparer } from '../scoring/comparer.ts';
3
+ import type { CaseReader, Weighted } from '../scoring/scorecard-scorer.ts';
4
+ import type { VarsContext } from './assertion-module.ts';
5
+ export declare class ScorerAssertion<Case extends Weighted, Input> {
6
+ readonly metric: string | undefined;
7
+ readonly weight: number;
8
+ readonly threshold: number;
9
+ readonly value: (output: string, context: VarsContext) => number;
10
+ constructor(scorer: Scorer<Input>, { weight, threshold, metric, comparer, cases, }: {
11
+ readonly weight: number;
12
+ readonly threshold: number;
13
+ readonly metric?: string;
14
+ readonly comparer: Comparer<Case, Input>;
15
+ readonly cases: CaseReader<Case>;
16
+ });
17
+ }
18
+ //# sourceMappingURL=scorer-assertion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scorer-assertion.d.ts","sourceRoot":"","sources":["../../src/promptfoo/scorer-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAiBzD,qBAAa,eAAe,CAAC,IAAI,SAAS,QAAQ,EAAE,KAAK;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;gBAG/D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EACrB,EACE,MAAM,EACN,SAAS,EACT,MAAM,EACN,QAAQ,EACR,KAAK,GACN,EAAE;QACD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;KAClC;CAQJ"}
@@ -1,7 +1,3 @@
1
- import { ComparisonSpec } from "../comparison/comparison-spec.js";
2
- import { statedData } from "../comparison/json-value.js";
3
- import { TreeWalk } from "../comparison/tree-walk.js";
4
- import { TextVarsCase } from "../scoring/text-vars-case.js";
5
1
  // One scorer with the rule of its promptfoo assertion (ADR 0007, ADR 0013):
6
2
  // how much it counts in the score of the test (weight: the score is the sum
7
3
  // of value × weight over the sum of the weights), when it passes (threshold:
@@ -14,21 +10,19 @@ import { TextVarsCase } from "../scoring/text-vars-case.js";
14
10
  // and gives the value of the ratio of the scorer: promptfoo takes the mean of
15
11
  // the values of one metric, so a SampleAveraged scorer gives its samples
16
12
  // average. The case comes from the vars of the test, as its case reader reads
17
- // them (a TextVarsCase that reads each schema with the draft of its $schema,
18
- // unless the caller gives one): an assertion that defaultTest shares gets
19
- // only the vars of each test, and JSON text keeps 7.0 a float. The spec tells
20
- // the walk how to compare the answer with the case.
13
+ // them: an assertion that defaultTest shares gets only the vars of each test.
14
+ // The comparer compares the answer with the case and gives the input of the
15
+ // scorer.
21
16
  export class ScorerAssertion {
22
17
  metric;
23
18
  weight;
24
19
  threshold;
25
20
  value;
26
- constructor(scorer, { weight, threshold, metric, spec = new ComparisonSpec(), cases = new TextVarsCase(), }) {
21
+ constructor(scorer, { weight, threshold, metric, comparer, cases, }) {
27
22
  this.metric = metric;
28
23
  this.weight = weight;
29
24
  this.threshold = threshold;
30
- const walk = new TreeWalk(spec);
31
- this.value = (output, { vars }) => scorer.score(walk.compare(statedData(output), cases.from(vars))).value;
25
+ this.value = (output, { vars }) => scorer.score(comparer.compare(output, cases.from(vars))).value;
32
26
  }
33
27
  }
34
28
  //# sourceMappingURL=scorer-assertion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scorer-assertion.js","sourceRoot":"","sources":["../../src/promptfoo/scorer-assertion.ts"],"names":[],"mappings":"AAKA,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,2EAA2E;AAC3E,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,UAAU;AACV,MAAM,OAAO,eAAe;IACjB,MAAM,CAAqB;IAC3B,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,KAAK,CAAmD;IAEjE,YACE,MAAqB,EACrB,EACE,MAAM,EACN,SAAS,EACT,MAAM,EACN,QAAQ,EACR,KAAK,GAON;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAChC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import { type FMeasureForm } from '../aggregation/f-measure-form.ts';
2
+ import type { Ratio } from '../aggregation/ratio.ts';
3
+ import type { Matches } from './matches.ts';
4
+ import type { Scorer } from './scorer.ts';
5
+ export declare class FBeta<Input> implements Scorer<Input> {
6
+ #private;
7
+ constructor(matches: Matches<Input>, { beta, form, }: {
8
+ readonly beta: number;
9
+ readonly form?: FMeasureForm;
10
+ });
11
+ score(input: Input): Ratio;
12
+ }
13
+ //# sourceMappingURL=f-beta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"f-beta.d.ts","sourceRoot":"","sources":["../../src/scorers/f-beta.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAClB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,qBAAa,KAAK,CAAC,KAAK,CAAE,YAAW,MAAM,CAAC,KAAK,CAAC;;gBAM9C,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,EACE,IAAI,EACJ,IAAuB,GACxB,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAA;KAAE;IAO5D,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAM3B"}
@@ -0,0 +1,22 @@
1
+ import { CountsForm, } from "../aggregation/f-measure-form.js";
2
+ import { FMeasureRatio } from "../aggregation/f-measure-ratio.js";
3
+ // The F-beta of the hits, as scikit-learn's fbeta_score: β weighs recall β
4
+ // times as much as precision. The form is the arithmetic of the value, and
5
+ // CountsForm is the form of scikit-learn.
6
+ export class FBeta {
7
+ #matches;
8
+ #beta;
9
+ #form;
10
+ constructor(matches, { beta, form = new CountsForm(), }) {
11
+ this.#matches = matches;
12
+ this.#beta = beta;
13
+ this.#form = form;
14
+ }
15
+ score(input) {
16
+ return new FMeasureRatio(this.#matches.counts(input), {
17
+ beta: this.#beta,
18
+ form: this.#form,
19
+ });
20
+ }
21
+ }
22
+ //# sourceMappingURL=f-beta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"f-beta.js","sourceRoot":"","sources":["../../src/scorers/f-beta.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,GAEX,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAKlE,2EAA2E;AAC3E,2EAA2E;AAC3E,0CAA0C;AAC1C,MAAM,OAAO,KAAK;IACP,QAAQ,CAAiB;IACzB,KAAK,CAAS;IACd,KAAK,CAAe;IAE7B,YACE,OAAuB,EACvB,EACE,IAAI,EACJ,IAAI,GAAG,IAAI,UAAU,EAAE,GACiC;QAE1D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,KAAY;QAChB,OAAO,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YACpD,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,IAAI,EAAE,IAAI,CAAC,KAAK;SACjB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,9 +1,9 @@
1
- import { F1Ratio } from '../aggregation/f1-ratio.ts';
1
+ import type { FMeasureForm } from '../aggregation/f-measure-form.ts';
2
+ import { FBeta } from './f-beta.ts';
2
3
  import type { Matches } from './matches.ts';
3
- import type { Scorer } from './scorer.ts';
4
- export declare class F1<Input> implements Scorer<Input> {
5
- #private;
6
- constructor(matches: Matches<Input>);
7
- score(input: Input): F1Ratio;
4
+ export declare class F1<Input> extends FBeta<Input> {
5
+ constructor(matches: Matches<Input>, options?: {
6
+ readonly form?: FMeasureForm;
7
+ });
8
8
  }
9
9
  //# sourceMappingURL=f1.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"f1.d.ts","sourceRoot":"","sources":["../../src/scorers/f1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,qBAAa,EAAE,CAAC,KAAK,CAAE,YAAW,MAAM,CAAC,KAAK,CAAC;;gBAGjC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;IAInC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;CAG7B"}
1
+ {"version":3,"file":"f1.d.ts","sourceRoot":"","sources":["../../src/scorers/f1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,qBAAa,EAAE,CAAC,KAAK,CAAE,SAAQ,KAAK,CAAC,KAAK,CAAC;gBAEvC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,OAAO,GAAE;QAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,CAAA;KAAO;CAIjD"}
@@ -1,12 +1,8 @@
1
- import { F1Ratio } from "../aggregation/f1-ratio.js";
2
- // The F1 of the hits: an F1Ratio of the counts.
3
- export class F1 {
4
- #matches;
5
- constructor(matches) {
6
- this.#matches = matches;
7
- }
8
- score(input) {
9
- return new F1Ratio(this.#matches.counts(input));
1
+ import { FBeta } from "./f-beta.js";
2
+ // The F1 of the hits: the F-beta with β = 1.
3
+ export class F1 extends FBeta {
4
+ constructor(matches, options = {}) {
5
+ super(matches, { ...options, beta: 1 });
10
6
  }
11
7
  }
12
8
  //# sourceMappingURL=f1.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"f1.js","sourceRoot":"","sources":["../../src/scorers/f1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAIrD,gDAAgD;AAChD,MAAM,OAAO,EAAE;IACJ,QAAQ,CAAiB;IAElC,YAAY,OAAuB;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,KAAY;QAChB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC;CACF"}
1
+ {"version":3,"file":"f1.js","sourceRoot":"","sources":["../../src/scorers/f1.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,6CAA6C;AAC7C,MAAM,OAAO,EAAU,SAAQ,KAAY;IACzC,YACE,OAAuB,EACvB,UAA4C,EAAE;QAE9C,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"penalized.d.ts","sourceRoot":"","sources":["../../src/scorers/penalized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQ1C,qBAAa,SAAS,CAAC,KAAK,CAAE,YAAW,MAAM,CAAC,KAAK,CAAC;;gBAIxC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,EAAE,SAAS,OAAO,CAAC,KAAK,CAAC,EAAE;IAK1E,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAgB3B"}
1
+ {"version":3,"file":"penalized.d.ts","sourceRoot":"","sources":["../../src/scorers/penalized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAS1C,qBAAa,SAAS,CAAC,KAAK,CAAE,YAAW,MAAM,CAAC,KAAK,CAAC;;gBAIxC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,EAAE,SAAS,OAAO,CAAC,KAAK,CAAC,EAAE;IAK1E,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAgB3B"}
@@ -4,7 +4,8 @@ import { Ratio } from "../aggregation/ratio.js";
4
4
  // record that fails a gate keeps its expected values in the denominator of
5
5
  // recall. A penalty on the means would give mean(a) × mean(b), so the
6
6
  // penalty is per record (ADR 0004). When every factor is 1, the ratio of the
7
- // scorer stays as it is, so an F1Ratio keeps its value (ADR 0012).
7
+ // scorer stays as it is, so an F-measure keeps the value of its form (ADR
8
+ // 0012).
8
9
  export class Penalized {
9
10
  #scorer;
10
11
  #penalties;
@@ -1 +1 @@
1
- {"version":3,"file":"penalized.js","sourceRoot":"","sources":["../../src/scorers/penalized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAIhD,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,sEAAsE;AACtE,6EAA6E;AAC7E,mEAAmE;AACnE,MAAM,OAAO,SAAS;IACX,OAAO,CAAgB;IACvB,UAAU,CAA4B;IAE/C,YAAY,MAAqB,EAAE,GAAG,SAAoC;QACxE,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,KAAY;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC;gBAC/B,MAAM,IAAI,UAAU,CAClB,6BAA6B,MAAM,2BAA2B,CAC/D,CAAC;YACJ,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC1D,OAAO,IAAI,KAAK,CACd,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,MAAM,EAAE,KAAK,CAAC,IA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,CAAC;CACF"}
@@ -18,14 +18,12 @@ export class Bootstrap {
18
18
  return this.#bootstrap.interval(rows, (resample) => Bootstrap.#mean(resample, name), this.#interval);
19
19
  }
20
20
  static #mean(rows, name) {
21
- const sum = new RatioOfSums();
22
- for (const { scorecard, weight } of rows) {
21
+ return RatioOfSums.of(rows.map(({ scorecard, weight }) => {
23
22
  const ratio = scorecard.ratios.get(name);
24
23
  if (ratio === undefined)
25
24
  throw new Error(`No scorecard ratio named "${name}"`);
26
- sum.add(new Ratio(ratio.value, 1).times(weight));
27
- }
28
- return sum.value;
25
+ return new Ratio(ratio.value, 1).times(weight);
26
+ })).value;
29
27
  }
30
28
  }
31
29
  //# sourceMappingURL=bootstrap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/scoring/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,GACb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAQhD,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,8DAA8D;AAC9D,MAAM,OAAO,SAAS;IACX,UAAU,CAAe;IACzB,SAAS,CAA2B;IAE7C,YAAY,EACV,UAAU,EACV,WAAW,EACX,QAAQ,GAKT;QACC,IAAI,CAAC,UAAU,GAAG,IAAI,YAAY,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,QAAQ,CACN,IAAkC,EAClC,IAAY;QAEZ,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAC7B,IAAI,EACJ,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,EAC7C,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,QAAQ,CAC7B,IAAI,EACJ,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,EAC7C,IAAI,CAAC,SAAS,CACf,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAkC,EAAE,IAAY;QAC3D,OAAO,WAAW,CAAC,EAAE,CACnB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;YACjC,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,KAAK,KAAK,SAAS;gBACrB,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,GAAG,CAAC,CAAC;YACxD,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,CAAC,CAAC,CACH,CAAC,KAAK,CAAC;IACV,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import type { Weighted } from './scorecard-scorer.ts';
2
+ export interface Comparer<Case extends Weighted, Input> {
3
+ compare(stated: unknown, testCase: Case): Input;
4
+ }
5
+ //# sourceMappingURL=comparer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparer.d.ts","sourceRoot":"","sources":["../../src/scoring/comparer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAItD,MAAM,WAAW,QAAQ,CAAC,IAAI,SAAS,QAAQ,EAAE,KAAK;IACpD,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;CACjD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=comparer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comparer.js","sourceRoot":"","sources":["../../src/scoring/comparer.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { Ratio } from '../aggregation/ratio.ts';
2
+ import type { Scorer } from '../scorers/scorer.ts';
3
+ export declare abstract class Grouped<Input> {
4
+ #private;
5
+ constructor(scorer: Scorer<Input>);
6
+ protected abstract groups(input: Input): Iterable<[string, Input]>;
7
+ ratios(input: Input, label: string): [string, Ratio][];
8
+ }
9
+ //# sourceMappingURL=grouped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grouped.d.ts","sourceRoot":"","sources":["../../src/scoring/grouped.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAOnD,8BAAsB,OAAO,CAAC,KAAK;;gBAGrB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC;IAIjC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAElE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;CAQvD"}
@@ -0,0 +1,20 @@
1
+ // A scorer for each group of an input: in a ScorerSet, it gives the ratio of
2
+ // its scorer on each group, under the label `${group} ${label}`. A subclass
3
+ // gives the groups (Template Method). A group gives no ratio when the scorer
4
+ // counts nothing in it (the whole 0): a ratio with the whole 0 adds nothing
5
+ // to a ratio of sums, so the totals stay the same.
6
+ export class Grouped {
7
+ #scorer;
8
+ constructor(scorer) {
9
+ this.#scorer = scorer;
10
+ }
11
+ ratios(input, label) {
12
+ return [...this.groups(input)]
13
+ .map(([group, part]) => [
14
+ `${group} ${label}`,
15
+ this.#scorer.score(part),
16
+ ])
17
+ .filter(([, ratio]) => ratio.whole !== 0);
18
+ }
19
+ }
20
+ //# sourceMappingURL=grouped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grouped.js","sourceRoot":"","sources":["../../src/scoring/grouped.ts"],"names":[],"mappings":"AAGA,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,mDAAmD;AACnD,MAAM,OAAgB,OAAO;IAClB,OAAO,CAAgB;IAEhC,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAID,MAAM,CAAC,KAAY,EAAE,KAAa;QAChC,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aAC3B,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAmB,EAAE,CAAC;YACvC,GAAG,KAAK,IAAI,KAAK,EAAE;YACnB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;SACzB,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import type { Scorer } from '../scorers/scorer.ts';
2
+ import type { Comparer } from './comparer.ts';
3
+ import { Grouped } from './grouped.ts';
4
+ import type { ScorecardScorer, Weighted } from './scorecard-scorer.ts';
5
+ import type { Scorecard } from './scorecard.ts';
6
+ export declare class ScorerSet<Case extends Weighted, Input> implements ScorecardScorer<Case> {
7
+ #private;
8
+ constructor(entries: Readonly<Record<string, Scorer<Input> | Grouped<Input>>>, { comparer }: {
9
+ readonly comparer: Comparer<Case, Input>;
10
+ });
11
+ score(stated: unknown, testCase: Case): Scorecard;
12
+ }
13
+ //# sourceMappingURL=scorer-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scorer-set.d.ts","sourceRoot":"","sources":["../../src/scoring/scorer-set.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQvD,qBAAa,SAAS,CACpB,IAAI,SAAS,QAAQ,EACrB,KAAK,CACL,YAAW,eAAe,CAAC,IAAI,CAAC;;gBAQ9B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EACjE,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;KAAE;IAM5D,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,SAAS;CAqClD"}
@@ -0,0 +1,55 @@
1
+ import { RatioOfSums } from "../aggregation/ratio-of-sums.js";
2
+ import { Ratio } from "../aggregation/ratio.js";
3
+ import { Gate } from "../scorers/gate.js";
4
+ import { Grouped } from "./grouped.js";
5
+ // Scores a stated value with labelled scorers, on the input that the comparer
6
+ // gives: the ratio of each scorer under its label, and of a Grouped scorer
7
+ // under the label of each group, so a ratio of sums of a label adds the parts
8
+ // and the wholes of the records. The record passes when each of its gates
9
+ // holds, and the reason is the explanations of the gates that fail. Each gate
10
+ // is a check. The score is the mean of the values of the scorers.
11
+ export class ScorerSet {
12
+ #entries;
13
+ #comparer;
14
+ constructor(entries, { comparer }) {
15
+ this.#entries = Object.entries(entries);
16
+ this.#comparer = comparer;
17
+ }
18
+ score(stated, testCase) {
19
+ const input = this.#comparer.compare(stated, testCase);
20
+ const ratios = [];
21
+ const mean = new RatioOfSums();
22
+ const checks = [];
23
+ for (const [label, entry] of this.#entries) {
24
+ if (entry instanceof Grouped) {
25
+ ratios.push(...entry.ratios(input, label));
26
+ continue;
27
+ }
28
+ const ratio = entry.score(input);
29
+ ratios.push([label, ratio]);
30
+ mean.add(new Ratio(ratio.value, 1));
31
+ if (entry instanceof Gate) {
32
+ const holds = entry.holds(input);
33
+ checks.push({
34
+ name: label,
35
+ passed: holds,
36
+ score: ratio.value,
37
+ reason: holds
38
+ ? `${label} holds`
39
+ : `${label}: ${entry.explain(input)}`,
40
+ });
41
+ }
42
+ }
43
+ const failed = checks.filter((check) => !check.passed);
44
+ return {
45
+ passed: failed.length === 0,
46
+ score: mean.value,
47
+ reason: failed.length === 0
48
+ ? 'each gate holds'
49
+ : failed.map((check) => check.reason).join('; '),
50
+ ratios: new Map(ratios),
51
+ checks,
52
+ };
53
+ }
54
+ }
55
+ //# sourceMappingURL=scorer-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scorer-set.js","sourceRoot":"","sources":["../../src/scoring/scorer-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAIvC,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAC9E,kEAAkE;AAClE,MAAM,OAAO,SAAS;IAIX,QAAQ,CAGZ;IACI,SAAS,CAAwB;IAE1C,YACE,OAAiE,EACjE,EAAE,QAAQ,EAAgD;QAE1D,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,MAAe,EAAE,QAAc;QACnC,MAAM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AAM,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EACJ,MAAM,CAAC,MAAM,KAAK,CAAC;gBACjB,CAAC,CAAC,iBAAiB;gBACnB,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACpD,MAAM,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC;YACvB,MAAM;SACP,CAAC;IACJ,CAAC;CACF"}
@@ -1,8 +1,11 @@
1
+ import { type FMeasureForm } from '../../../aggregation/f-measure-form.ts';
1
2
  import type { LeafValue } from '../leaf-pair.ts';
2
3
  import { TypedComparator } from './typed-comparator.ts';
3
4
  export declare class TokenOverlapAtLeast extends TypedComparator<string> {
4
5
  #private;
5
- constructor(threshold: number);
6
+ constructor(threshold: number, { form }?: {
7
+ readonly form?: FMeasureForm;
8
+ });
6
9
  protected accepts(value: LeafValue): value is string;
7
10
  protected compare(stated: string, expected: string): boolean;
8
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"token-overlap-at-least.d.ts","sourceRoot":"","sources":["../../../../src/structured/comparison/comparators/token-overlap-at-least.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAIxD,qBAAa,mBAAoB,SAAQ,eAAe,CAAC,MAAM,CAAC;;gBAGlD,SAAS,EAAE,MAAM;IAK7B,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"}
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"}
@@ -1,20 +1,23 @@
1
- import { F1Ratio } from "../../../aggregation/f1-ratio.js";
1
+ import { CountsForm, } from "../../../aggregation/f-measure-form.js";
2
2
  import { BagOfWords } from "../bag-of-words.js";
3
3
  import { TypedComparator } from "./typed-comparator.js";
4
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.
5
+ // reaches the threshold. Two texts that share no word have the F1 0. The form
6
+ // is the arithmetic of the F1.
6
7
  export class TokenOverlapAtLeast extends TypedComparator {
7
8
  #threshold;
8
- constructor(threshold) {
9
+ #form;
10
+ constructor(threshold, { form = new CountsForm() } = {}) {
9
11
  super();
10
12
  this.#threshold = threshold;
13
+ this.#form = form;
11
14
  }
12
15
  accepts(value) {
13
16
  return typeof value === 'string';
14
17
  }
15
18
  compare(stated, expected) {
16
19
  const counts = BagOfWords.of(expected).shared(BagOfWords.of(stated));
17
- return new F1Ratio(counts).value >= this.#threshold;
20
+ return this.#form.of(counts, 1) >= this.#threshold;
18
21
  }
19
22
  }
20
23
  //# sourceMappingURL=token-overlap-at-least.js.map
@@ -1 +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,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,2EAA2E;AAC3E,qEAAqE;AACrE,MAAM,OAAO,mBAAoB,SAAQ,eAAuB;IACrD,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,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,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC;IACtD,CAAC;CACF"}
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"}
@@ -1,5 +1,6 @@
1
1
  import { type JsonData } from '@zukhruf/python';
2
2
  export declare class JsonValue {
3
+ #private;
3
4
  readonly value: JsonData;
4
5
  constructor(value: JsonData);
5
6
  static parse(text: string): JsonValue;
@@ -1 +1 @@
1
- {"version":3,"file":"json-value.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/json-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAK3D,qBAAa,SAAS;IACpB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAEb,KAAK,EAAE,QAAQ;IAK3B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAOrC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS;CAKvC;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CASpD;AAID,wBAAgB,OAAO,CACrB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAGV"}
1
+ {"version":3,"file":"json-value.d.ts","sourceRoot":"","sources":["../../../src/structured/comparison/json-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAK3D,qBAAa,SAAS;;IACpB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAEb,KAAK,EAAE,QAAQ;IAK3B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IASrC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS;CAevC;AAQD,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CASpD;AAID,wBAAgB,OAAO,CACrB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAGV"}
@@ -13,9 +13,18 @@ export class JsonValue {
13
13
  }
14
14
  // An integral number becomes an int, so an integral float such as 7.0 is
15
15
  // already 7. JSON.stringify gives no text for undefined, which stands for no
16
- // value (None).
16
+ // value (None). JSON.stringify gives {} for a Map and a Set, at any depth, so
17
+ // a dict of JsonData would become an empty object: that value is refused,
18
+ // and not read.
17
19
  static from(value) {
18
- return new JsonValue(value === undefined ? null : loadsJson(JSON.stringify(value)));
20
+ return new JsonValue(value === undefined
21
+ ? null
22
+ : loadsJson(JSON.stringify(value, JsonValue.#refuseCollections)));
23
+ }
24
+ static #refuseCollections(_key, item) {
25
+ if (item instanceof Map || item instanceof Set)
26
+ throw new TypeError(`JsonValue.from cannot read a ${item instanceof Map ? 'Map' : 'Set'}, because JSON.stringify loses its entries. Give JSON text, a JsonValue or a plain JavaScript value.`);
27
+ return item;
19
28
  }
20
29
  }
21
30
  // What a stated value is to the walk: a value that JsonValue.parse or
@@ -1 +1 @@
1
- {"version":3,"file":"json-value.js","sourceRoot":"","sources":["../../../src/structured/comparison/json-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAi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