chaffjs 0.27.1 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +2 -1
  2. package/dist/cli-text.d.ts.map +1 -1
  3. package/dist/cli-text.js +6 -4
  4. package/dist/cli-text.js.map +1 -1
  5. package/dist/derived/number-word-counts.d.ts +10 -0
  6. package/dist/derived/number-word-counts.d.ts.map +1 -0
  7. package/dist/derived/number-word-counts.js +21 -0
  8. package/dist/derived/number-word-counts.js.map +1 -0
  9. package/dist/detectors/amount-scale.d.ts +3 -0
  10. package/dist/detectors/amount-scale.d.ts.map +1 -0
  11. package/dist/detectors/amount-scale.js +50 -0
  12. package/dist/detectors/amount-scale.js.map +1 -0
  13. package/dist/detectors/change-rate.d.ts.map +1 -1
  14. package/dist/detectors/change-rate.js +12 -1
  15. package/dist/detectors/change-rate.js.map +1 -1
  16. package/dist/detectors/currency-notation.d.ts +3 -1
  17. package/dist/detectors/currency-notation.d.ts.map +1 -1
  18. package/dist/detectors/currency-notation.js +2 -2
  19. package/dist/detectors/currency-notation.js.map +1 -1
  20. package/dist/detectors/derived-numbers.d.ts.map +1 -1
  21. package/dist/detectors/derived-numbers.js +9 -1
  22. package/dist/detectors/derived-numbers.js.map +1 -1
  23. package/dist/detectors/fact-consistency.d.ts.map +1 -1
  24. package/dist/detectors/fact-consistency.js +14 -1
  25. package/dist/detectors/fact-consistency.js.map +1 -1
  26. package/dist/detectors/name-variant.d.ts.map +1 -1
  27. package/dist/detectors/name-variant.js +18 -10
  28. package/dist/detectors/name-variant.js.map +1 -1
  29. package/dist/detectors/registry/amount-scale.d.ts +3 -0
  30. package/dist/detectors/registry/amount-scale.d.ts.map +1 -0
  31. package/dist/detectors/registry/amount-scale.js +3 -0
  32. package/dist/detectors/registry/amount-scale.js.map +1 -0
  33. package/dist/facts/counted-facts.d.ts +16 -0
  34. package/dist/facts/counted-facts.d.ts.map +1 -0
  35. package/dist/facts/counted-facts.js +45 -0
  36. package/dist/facts/counted-facts.js.map +1 -0
  37. package/dist/name-variants.d.ts +19 -5
  38. package/dist/name-variants.d.ts.map +1 -1
  39. package/dist/name-variants.js +60 -6
  40. package/dist/name-variants.js.map +1 -1
  41. package/dist/structure/amount-scale.d.ts +29 -0
  42. package/dist/structure/amount-scale.d.ts.map +1 -0
  43. package/dist/structure/amount-scale.js +70 -0
  44. package/dist/structure/amount-scale.js.map +1 -0
  45. package/dist/structure/subject-change.d.ts +8 -0
  46. package/dist/structure/subject-change.d.ts.map +1 -0
  47. package/dist/structure/subject-change.js +31 -0
  48. package/dist/structure/subject-change.js.map +1 -0
  49. package/package.json +3 -3
  50. package/rules/amount-scale-consistency.yaml +74 -0
  51. package/rules/change-rate-mismatch.yaml +5 -4
  52. package/rules/elapsed-years-mismatch.yaml +2 -2
  53. package/rules/name-variant.yaml +5 -2
  54. package/rules/summary-fact-mismatch.yaml +2 -2
  55. package/src/cli-text.ts +6 -4
  56. package/src/derived/number-word-counts.ts +28 -0
  57. package/src/detectors/amount-scale.ts +63 -0
  58. package/src/detectors/change-rate.ts +15 -2
  59. package/src/detectors/currency-notation.ts +2 -2
  60. package/src/detectors/derived-numbers.ts +9 -2
  61. package/src/detectors/fact-consistency.ts +17 -1
  62. package/src/detectors/name-variant.ts +14 -4
  63. package/src/detectors/registry/amount-scale.ts +4 -0
  64. package/src/facts/counted-facts.ts +59 -0
  65. package/src/name-variants.ts +106 -11
  66. package/src/structure/amount-scale.ts +97 -0
  67. package/src/structure/subject-change.ts +35 -0
@@ -0,0 +1,35 @@
1
+ import type { Token } from "../plugin.ts";
2
+
3
+ // Whether a joining word ("and") starts a clause about another subject: "Revenue was $1,000 in 2025 and costs were $1,500
4
+ // in 2026" joins two subjects, "… in 2025 and $1,500 in 2026" or "… and revenue was $1,500" one. Two words for one thing
5
+ // ("sales" and "revenue") read as two subjects, so the pair is left alone rather than read wrongly. Pure: reads the tagger's
6
+ // parts of speech and lemmas.
7
+
8
+ const NOUN: ReadonlySet<string> = new Set(["NOUN", "PROPN"]);
9
+ /** Words that may stand before the noun that starts the clause ("and the costs", "and our operating costs"). */
10
+ const BEFORE_NOUN: ReadonlySet<string> = new Set(["DET", "ADJ", "PRON"]);
11
+
12
+ const wordOf = (token: Token): string => (token.lemma ?? token.surface).toLowerCase();
13
+
14
+ /** The last noun of the run of nouns at the start of tokens, past determiners and adjectives ("the operating costs" → cost). */
15
+ const leadingNoun = (tokens: readonly Token[]): Token | undefined => {
16
+ const start = tokens.findIndex((token) => !BEFORE_NOUN.has(token.pos));
17
+ if (start < 0) return undefined;
18
+ const end = tokens.slice(start).findIndex((token) => !NOUN.has(token.pos));
19
+ const nouns = tokens.slice(start, end < 0 ? tokens.length : start + end);
20
+ return nouns.at(-1);
21
+ };
22
+
23
+ /**
24
+ * The joining word at index is followed by a noun the sentence has not used before it: "and costs were", "and costs $1,500"
25
+ * after "Revenue was $1,000", where "and revenue was" after "ACME's revenue was $1,000" names the same thing again. A
26
+ * sentence with no noun before the joining word gives nothing to compare with.
27
+ */
28
+ export const startsOtherSubject = (tokens: readonly Token[], index: number): boolean => {
29
+ const next = leadingNoun(tokens.slice(index + 1));
30
+ const before = tokens
31
+ .slice(0, index)
32
+ .filter((token) => NOUN.has(token.pos))
33
+ .map(wordOf);
34
+ return next !== undefined && before.length > 0 && !before.includes(wordOf(next));
35
+ };