@zukhruf/relevance-filtering 0.4.1 → 0.5.1

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 (50) hide show
  1. package/README.md +110 -52
  2. package/dist/binormal.d.ts +1 -15
  3. package/dist/binormal.d.ts.map +1 -1
  4. package/dist/binormal.js +6 -12
  5. package/dist/binormal.js.map +1 -1
  6. package/dist/decision-scorer.d.ts +12 -0
  7. package/dist/decision-scorer.d.ts.map +1 -0
  8. package/dist/decision-scorer.js +29 -0
  9. package/dist/decision-scorer.js.map +1 -0
  10. package/dist/expected-f-threshold.d.ts +10 -0
  11. package/dist/expected-f-threshold.d.ts.map +1 -0
  12. package/dist/expected-f-threshold.js +33 -0
  13. package/dist/expected-f-threshold.js.map +1 -0
  14. package/dist/index.d.ts +8 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +6 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/profile.d.ts +1 -16
  19. package/dist/profile.d.ts.map +1 -1
  20. package/dist/profile.js +3 -88
  21. package/dist/profile.js.map +1 -1
  22. package/dist/scorer.d.ts +12 -0
  23. package/dist/scorer.d.ts.map +1 -0
  24. package/dist/scorer.js +2 -0
  25. package/dist/scorer.js.map +1 -0
  26. package/dist/scores.d.ts +23 -0
  27. package/dist/scores.d.ts.map +1 -0
  28. package/dist/scores.js +51 -0
  29. package/dist/scores.js.map +1 -0
  30. package/dist/similarity-scorer.d.ts +16 -0
  31. package/dist/similarity-scorer.d.ts.map +1 -0
  32. package/dist/similarity-scorer.js +109 -0
  33. package/dist/similarity-scorer.js.map +1 -0
  34. package/dist/threshold.d.ts +6 -0
  35. package/dist/threshold.d.ts.map +1 -0
  36. package/dist/threshold.js +2 -0
  37. package/dist/threshold.js.map +1 -0
  38. package/dist/utility-threshold.d.ts +10 -0
  39. package/dist/utility-threshold.d.ts.map +1 -0
  40. package/dist/utility-threshold.js +22 -0
  41. package/dist/utility-threshold.js.map +1 -0
  42. package/package.json +7 -4
  43. package/dist/expected-f.d.ts +0 -2
  44. package/dist/expected-f.d.ts.map +0 -1
  45. package/dist/expected-f.js +0 -23
  46. package/dist/expected-f.js.map +0 -1
  47. package/dist/relevance-filter.d.ts +0 -47
  48. package/dist/relevance-filter.d.ts.map +0 -1
  49. package/dist/relevance-filter.js +0 -100
  50. package/dist/relevance-filter.js.map +0 -1
@@ -1,100 +0,0 @@
1
- import { UnknownArticleError } from "./errors.js";
2
- // The decisions of a profile on one stream.
3
- class Decisions {
4
- #probabilities;
5
- #accepted;
6
- #order;
7
- constructor(options) {
8
- this.#probabilities = options.probabilities;
9
- this.#accepted = options.accepted;
10
- this.#order = options.order;
11
- }
12
- // The probability that the article is relevant to the profile.
13
- probability(id) {
14
- const probability = this.#probabilities.get(id);
15
- if (probability === undefined)
16
- throw new UnknownArticleError(id);
17
- return probability;
18
- }
19
- // The ids of the stream, the best first (docs/adr/0004). With a range, only
20
- // the articles published in it, in the same order: the best N of a day are
21
- // ranked({ from, to }).slice(0, n).
22
- ranked(range) {
23
- const inRange = range === undefined
24
- ? this.#order
25
- : this.#order.filter(({ publishedAt }) => publishedAt >= range.from && publishedAt <= range.to);
26
- return inRange.map(({ id }) => id);
27
- }
28
- // True when the expected-F0.5 threshold accepts the article. Not
29
- // recommended for decisions: use ranked (docs/adr/0004).
30
- accepts(id) {
31
- if (!this.#probabilities.has(id))
32
- throw new UnknownArticleError(id);
33
- return this.#accepted.has(id);
34
- }
35
- // The accepted articles, the most probable first. Equal probabilities keep
36
- // the order of the stream. Not recommended for decisions: use ranked
37
- // (docs/adr/0004).
38
- accepted() {
39
- return [...this.#accepted].toSorted((a, b) => this.probability(b) - this.probability(a));
40
- }
41
- }
42
- // A filter that learned from at least one relevant answer. Its probabilities
43
- // are calibrated. It ranks by probability, then by similarity, then by id.
44
- export class CalibratedFilter extends Decisions {
45
- kind = 'calibrated';
46
- calibration;
47
- // The lowest probability that the expected-F0.5 threshold accepts.
48
- // Undefined when nothing is accepted.
49
- threshold;
50
- constructor(options) {
51
- const { stream, probabilities, threshold } = options;
52
- const probability = (id) => probabilities.get(id) ?? 0;
53
- super({
54
- probabilities,
55
- accepted: new Set(threshold === undefined
56
- ? []
57
- : [...probabilities]
58
- .filter(([, value]) => value >= threshold)
59
- .map(([id]) => id)),
60
- order: stream.toSorted((a, b) => probability(b.id) - probability(a.id) ||
61
- b.similarity - a.similarity ||
62
- compareIds(a.id, b.id)),
63
- });
64
- this.calibration = options.calibration;
65
- this.threshold = threshold;
66
- }
67
- }
68
- // A filter with no relevant answer to learn from. It accepts the articles
69
- // that match a keyword of the profile: the probability is 1 for a match and
70
- // 0 for the others, and it is not calibrated. It ranks the matches first,
71
- // the newest first, and then the other articles by similarity.
72
- export class KeywordFilter extends Decisions {
73
- kind = 'keywords';
74
- constructor(options) {
75
- const { stream, matches } = options;
76
- const match = (id) => matches.get(id) ?? false;
77
- super({
78
- probabilities: new Map([...matches].map(([id, value]) => [id, value ? 1 : 0])),
79
- accepted: new Set([...matches].filter(([, value]) => value).map(([id]) => id)),
80
- order: stream.toSorted((a, b) => {
81
- if (match(a.id) !== match(b.id))
82
- return match(a.id) ? -1 : 1;
83
- const key = match(a.id)
84
- ? b.publishedAt.getTime() - a.publishedAt.getTime()
85
- : b.similarity - a.similarity;
86
- return key || compareIds(a.id, b.id);
87
- }),
88
- });
89
- }
90
- }
91
- // Compares by code unit, not by locale, so the order is the same on every
92
- // machine.
93
- function compareIds(left, right) {
94
- if (left < right)
95
- return -1;
96
- if (left > right)
97
- return 1;
98
- return 0;
99
- }
100
- //# sourceMappingURL=relevance-filter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"relevance-filter.js","sourceRoot":"","sources":["../src/relevance-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAqBlD,4CAA4C;AAC5C,MAAe,SAAS;IACb,cAAc,CAA8B;IAC5C,SAAS,CAAsB;IAC/B,MAAM,C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