@concordance-wiki/inference 0.1.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 (139) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +15 -0
  3. package/dist/combine/confidence.d.ts +16 -0
  4. package/dist/combine/confidence.d.ts.map +1 -0
  5. package/dist/combine/confidence.js +24 -0
  6. package/dist/combine/confidence.js.map +1 -0
  7. package/dist/combine/links.d.ts +15 -0
  8. package/dist/combine/links.d.ts.map +1 -0
  9. package/dist/combine/links.js +0 -0
  10. package/dist/combine/links.js.map +1 -0
  11. package/dist/display/neighbourhood.d.ts +15 -0
  12. package/dist/display/neighbourhood.d.ts.map +1 -0
  13. package/dist/display/neighbourhood.js +83 -0
  14. package/dist/display/neighbourhood.js.map +1 -0
  15. package/dist/display/options.d.ts +5 -0
  16. package/dist/display/options.d.ts.map +1 -0
  17. package/dist/display/options.js +6 -0
  18. package/dist/display/options.js.map +1 -0
  19. package/dist/display/serialize.d.ts +7 -0
  20. package/dist/display/serialize.d.ts.map +1 -0
  21. package/dist/display/serialize.js +13 -0
  22. package/dist/display/serialize.js.map +1 -0
  23. package/dist/display/types.d.ts +44 -0
  24. package/dist/display/types.d.ts.map +1 -0
  25. package/dist/display/types.js +2 -0
  26. package/dist/display/types.js.map +1 -0
  27. package/dist/duplicates/content.d.ts +29 -0
  28. package/dist/duplicates/content.d.ts.map +1 -0
  29. package/dist/duplicates/content.js +42 -0
  30. package/dist/duplicates/content.js.map +1 -0
  31. package/dist/duplicates/lsh.d.ts +8 -0
  32. package/dist/duplicates/lsh.d.ts.map +1 -0
  33. package/dist/duplicates/lsh.js +38 -0
  34. package/dist/duplicates/lsh.js.map +1 -0
  35. package/dist/duplicates/minhash.d.ts +11 -0
  36. package/dist/duplicates/minhash.d.ts.map +1 -0
  37. package/dist/duplicates/minhash.js +51 -0
  38. package/dist/duplicates/minhash.js.map +1 -0
  39. package/dist/duplicates/options.d.ts +6 -0
  40. package/dist/duplicates/options.d.ts.map +1 -0
  41. package/dist/duplicates/options.js +23 -0
  42. package/dist/duplicates/options.js.map +1 -0
  43. package/dist/duplicates/resolve.d.ts +13 -0
  44. package/dist/duplicates/resolve.d.ts.map +1 -0
  45. package/dist/duplicates/resolve.js +257 -0
  46. package/dist/duplicates/resolve.js.map +1 -0
  47. package/dist/duplicates/score.d.ts +22 -0
  48. package/dist/duplicates/score.d.ts.map +1 -0
  49. package/dist/duplicates/score.js +190 -0
  50. package/dist/duplicates/score.js.map +1 -0
  51. package/dist/duplicates/shingles.d.ts +15 -0
  52. package/dist/duplicates/shingles.d.ts.map +1 -0
  53. package/dist/duplicates/shingles.js +35 -0
  54. package/dist/duplicates/shingles.js.map +1 -0
  55. package/dist/duplicates/similarity.d.ts +23 -0
  56. package/dist/duplicates/similarity.d.ts.map +1 -0
  57. package/dist/duplicates/similarity.js +86 -0
  58. package/dist/duplicates/similarity.js.map +1 -0
  59. package/dist/duplicates/types.d.ts +97 -0
  60. package/dist/duplicates/types.d.ts.map +1 -0
  61. package/dist/duplicates/types.js +2 -0
  62. package/dist/duplicates/types.js.map +1 -0
  63. package/dist/explicit/links.d.ts +30 -0
  64. package/dist/explicit/links.d.ts.map +1 -0
  65. package/dist/explicit/links.js +173 -0
  66. package/dist/explicit/links.js.map +1 -0
  67. package/dist/explicit/types.d.ts +35 -0
  68. package/dist/explicit/types.d.ts.map +1 -0
  69. package/dist/explicit/types.js +2 -0
  70. package/dist/explicit/types.js.map +1 -0
  71. package/dist/frontmatter/links.d.ts +21 -0
  72. package/dist/frontmatter/links.d.ts.map +1 -0
  73. package/dist/frontmatter/links.js +131 -0
  74. package/dist/frontmatter/links.js.map +1 -0
  75. package/dist/frontmatter/resolve.d.ts +32 -0
  76. package/dist/frontmatter/resolve.d.ts.map +1 -0
  77. package/dist/frontmatter/resolve.js +62 -0
  78. package/dist/frontmatter/resolve.js.map +1 -0
  79. package/dist/index.d.ts +26 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +19 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/mentions/links.d.ts +43 -0
  84. package/dist/mentions/links.d.ts.map +1 -0
  85. package/dist/mentions/links.js +106 -0
  86. package/dist/mentions/links.js.map +1 -0
  87. package/dist/mentions/sections.d.ts +17 -0
  88. package/dist/mentions/sections.d.ts.map +1 -0
  89. package/dist/mentions/sections.js +26 -0
  90. package/dist/mentions/sections.js.map +1 -0
  91. package/dist/neighbourhood/accumulate.d.ts +11 -0
  92. package/dist/neighbourhood/accumulate.d.ts.map +1 -0
  93. package/dist/neighbourhood/accumulate.js +73 -0
  94. package/dist/neighbourhood/accumulate.js.map +1 -0
  95. package/dist/neighbourhood/links.d.ts +13 -0
  96. package/dist/neighbourhood/links.d.ts.map +1 -0
  97. package/dist/neighbourhood/links.js +35 -0
  98. package/dist/neighbourhood/links.js.map +1 -0
  99. package/dist/neighbourhood/options.d.ts +5 -0
  100. package/dist/neighbourhood/options.d.ts.map +1 -0
  101. package/dist/neighbourhood/options.js +6 -0
  102. package/dist/neighbourhood/options.js.map +1 -0
  103. package/dist/neighbourhood/order.d.ts +5 -0
  104. package/dist/neighbourhood/order.d.ts.map +1 -0
  105. package/dist/neighbourhood/order.js +9 -0
  106. package/dist/neighbourhood/order.js.map +1 -0
  107. package/dist/neighbourhood/serialize.d.ts +4 -0
  108. package/dist/neighbourhood/serialize.d.ts.map +1 -0
  109. package/dist/neighbourhood/serialize.js +10 -0
  110. package/dist/neighbourhood/serialize.js.map +1 -0
  111. package/dist/neighbourhood/types.d.ts +24 -0
  112. package/dist/neighbourhood/types.d.ts.map +1 -0
  113. package/dist/neighbourhood/types.js +2 -0
  114. package/dist/neighbourhood/types.js.map +1 -0
  115. package/dist/operations/index.d.ts +30 -0
  116. package/dist/operations/index.d.ts.map +1 -0
  117. package/dist/operations/index.js +118 -0
  118. package/dist/operations/index.js.map +1 -0
  119. package/dist/operations/match.d.ts +64 -0
  120. package/dist/operations/match.d.ts.map +1 -0
  121. package/dist/operations/match.js +251 -0
  122. package/dist/operations/match.js.map +1 -0
  123. package/dist/operations/merge.d.ts +14 -0
  124. package/dist/operations/merge.d.ts.map +1 -0
  125. package/dist/operations/merge.js +60 -0
  126. package/dist/operations/merge.js.map +1 -0
  127. package/dist/relations/index.d.ts +3 -0
  128. package/dist/relations/index.d.ts.map +1 -0
  129. package/dist/relations/index.js +3 -0
  130. package/dist/relations/index.js.map +1 -0
  131. package/dist/relations/labels.d.ts +14 -0
  132. package/dist/relations/labels.d.ts.map +1 -0
  133. package/dist/relations/labels.js +22 -0
  134. package/dist/relations/labels.js.map +1 -0
  135. package/dist/relations/type.d.ts +40 -0
  136. package/dist/relations/type.d.ts.map +1 -0
  137. package/dist/relations/type.js +161 -0
  138. package/dist/relations/type.js.map +1 -0
  139. package/package.json +46 -0
@@ -0,0 +1,3 @@
1
+ export { relationLabel } from "./labels.js";
2
+ export { FALLBACK_RELATION, RELATION_ORIGIN, typeRelations, } from "./type.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/relations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6B,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,GAId,MAAM,WAAW,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Locale } from "@concordance-wiki/core";
2
+ import type { Profile } from "@concordance-wiki/profile";
3
+ export interface RelationLabelOptions {
4
+ /** Read the relation from its target, the way a screen names the application it is part of. */
5
+ inverse?: boolean;
6
+ }
7
+ /**
8
+ * The label the profile gives a relation, read from the source by default and from the target with
9
+ * `inverse`: the `inverse_label` of the relation, or its plain label when it has none, as an
10
+ * undirected one. A relation the profile does not declare reads as its slug: the site never
11
+ * invents a label.
12
+ */
13
+ export declare function relationLabel(profile: Profile, relation: string, locale: Locale, options?: RelationLabelOptions): string;
14
+ //# sourceMappingURL=labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/relations/labels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAS,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IACnC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AASD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAQR"}
@@ -0,0 +1,22 @@
1
+ /** The label of `locale`, else of its language (`fr` for `fr-CA`), else the English one. */
2
+ function localised(label, locale) {
3
+ // The spread gives the label an anonymous type that a locale string can index.
4
+ const byLocale = { ...label };
5
+ return byLocale[locale] ?? byLocale[locale.replace(/-[^]*/, "")] ?? label.en;
6
+ }
7
+ /**
8
+ * The label the profile gives a relation, read from the source by default and from the target with
9
+ * `inverse`: the `inverse_label` of the relation, or its plain label when it has none, as an
10
+ * undirected one. A relation the profile does not declare reads as its slug: the site never
11
+ * invents a label.
12
+ */
13
+ export function relationLabel(profile, relation, locale, options = {}) {
14
+ const definition = profile.relations[relation];
15
+ if (definition === undefined)
16
+ return relation;
17
+ const label = options.inverse === true && definition.inverse_label !== undefined
18
+ ? definition.inverse_label
19
+ : definition.label;
20
+ return localised(label, locale);
21
+ }
22
+ //# sourceMappingURL=labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.js","sourceRoot":"","sources":["../../src/relations/labels.ts"],"names":[],"mappings":"AAQA,4FAA4F;AAC5F,SAAS,SAAS,CAAC,KAAY,EAAE,MAAc;IAC7C,+EAA+E;IAC/E,MAAM,QAAQ,GAAoC,EAAE,GAAG,KAAK,EAAE,CAAC;IAC/D,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,QAAgB,EAChB,MAAc,EACd,UAAgC,EAAE;IAElC,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC9C,MAAM,KAAK,GACT,OAAO,CAAC,OAAO,KAAK,IAAI,IAAI,UAAU,CAAC,aAAa,KAAK,SAAS;QAChE,CAAC,CAAC,UAAU,CAAC,aAAa;QAC1B,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IACvB,OAAO,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { type Finding, type Link } from "@concordance-wiki/core";
2
+ import { type Profile } from "@concordance-wiki/profile";
3
+ /** What the typing step needs of an entity; the file lets a finding name the source it was read in. */
4
+ export interface TypedEntity {
5
+ id: string;
6
+ type: string;
7
+ source?: {
8
+ name: string;
9
+ /** Forward-slash path relative to the source root. */
10
+ path: string;
11
+ };
12
+ }
13
+ export interface TypeRelationsInput {
14
+ links: readonly Link[];
15
+ entities: readonly TypedEntity[];
16
+ profile: Profile;
17
+ }
18
+ export interface TypeRelationsResult {
19
+ links: Link[];
20
+ findings: Finding[];
21
+ }
22
+ /** The relation a producer gives a link it cannot name; the profile caps it and allows it everywhere. */
23
+ export declare const FALLBACK_RELATION = "related";
24
+ /** The attribute that says the type pair named the relation, not a section or a frontmatter attribute. */
25
+ export declare const RELATION_ORIGIN = "relation_origin";
26
+ /**
27
+ * Names the relation of every link from the profile, once every producer has spoken and their
28
+ * links are combined. A relation a producer named, from a mapped section or a typed frontmatter
29
+ * attribute, stands: the step only checks that the profile allows it between the two types and
30
+ * drops it with `E-META-REL` otherwise. A `related` link, which no producer could name, takes the
31
+ * single relation the profile admits for its type pair, marked `relation_origin: pair`, turned
32
+ * around when only the reverse pair admits one; it stays `related` when the pair admits none or
33
+ * several. Links that now say the same thing are combined again, a pair-named link joining a
34
+ * declared link of the same triple and attributes and losing its marker; then the cap of the
35
+ * relation applies and every `related` link yields `I-REL-AMBIGUOUS`, located on the first
36
+ * provenance that names a file, unless co-occurrence alone knows it. A link with an endpoint the
37
+ * entity list does not type is kept as produced, since nothing can check it. Pure and idempotent.
38
+ */
39
+ export declare function typeRelations(input: TypeRelationsInput): TypeRelationsResult;
40
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/relations/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,IAAI,EAAmB,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAK3F,uGAAuG;AACvG,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,sDAAsD;QACtD,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IACvB,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,yGAAyG;AACzG,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,0GAA0G;AAC1G,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAuIjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CA2D5E"}
@@ -0,0 +1,161 @@
1
+ import { compareFindings } from "@concordance-wiki/core";
2
+ import { allowedRelations, singleRelation } from "@concordance-wiki/profile";
3
+ import { combineLinks, combineOptions } from "../combine/links.js";
4
+ import { byCodeUnit } from "../neighbourhood/order.js";
5
+ /** The relation a producer gives a link it cannot name; the profile caps it and allows it everywhere. */
6
+ export const FALLBACK_RELATION = "related";
7
+ /** The attribute that says the type pair named the relation, not a section or a frontmatter attribute. */
8
+ export const RELATION_ORIGIN = "relation_origin";
9
+ const PAIR_ORIGIN = "pair";
10
+ const AMBIGUOUS_REMEDIATION = "Move the mention under a mapped section, or declare the reference in frontmatter.";
11
+ const OUTSIDE_MATRIX_REMEDIATION = "Point the reference at an entity of an allowed type, or extend the profile's allowed pairs for that relation.";
12
+ function describe(id, entity) {
13
+ return entity === undefined ? id : `${entity.type} ${id}`;
14
+ }
15
+ /** The endpoint whose file the provenance was read in; `from` when no file matches or none is named. */
16
+ function carrierOf(link, provenance, ends) {
17
+ const named = [ends.from, ends.to].find((entity) => entity?.source !== undefined && entity.source.path === provenance?.path);
18
+ return named ?? ends.from ?? { id: link.from };
19
+ }
20
+ /** A finding points at a file when any provenance names one; a co-occurrence names none. */
21
+ function located(link, ends) {
22
+ const provenance = link.provenance.find((candidate) => candidate.path !== undefined) ?? link.provenance[0];
23
+ const carrier = carrierOf(link, provenance, ends);
24
+ return {
25
+ ...(carrier.source === undefined ? {} : { source: carrier.source.name }),
26
+ ...(provenance?.path === undefined ? {} : { path: provenance.path }),
27
+ ...(provenance?.line === undefined ? {} : { line: provenance.line }),
28
+ entity: carrier.id,
29
+ };
30
+ }
31
+ function outsideMatrix(link, ends, reason) {
32
+ const attribute = link.provenance.find((candidate) => candidate.attribute !== undefined)?.attribute;
33
+ const declared = attribute === undefined ? "" : ` (attribute ${attribute})`;
34
+ return {
35
+ check: "E-META-REL",
36
+ severity: "error",
37
+ ...located(link, ends),
38
+ message: `relation ${link.relation} from ${describe(link.from, ends.from)} to ${describe(link.to, ends.to)} ${reason}${declared}`,
39
+ remediation: OUTSIDE_MATRIX_REMEDIATION,
40
+ };
41
+ }
42
+ function ambiguous(link, ends) {
43
+ return {
44
+ check: "I-REL-AMBIGUOUS",
45
+ severity: "info",
46
+ ...located(link, ends),
47
+ message: `the link from ${link.from} to ${link.to} fell back to the generic ${FALLBACK_RELATION} relation`,
48
+ remediation: AMBIGUOUS_REMEDIATION,
49
+ };
50
+ }
51
+ /**
52
+ * A link known from co-occurrences alone: nobody wrote it, so nobody can be asked to name it. The
53
+ * ambiguity finding is for a written link or a located mention that fell back to `related`.
54
+ */
55
+ function unnamedByNature(link) {
56
+ return link.provenance.every((provenance) => provenance.method === "cooccurrence");
57
+ }
58
+ /** An undirected relation joins its pair in either order. */
59
+ function allowedBetween(profile, relation, undirected, ends) {
60
+ return (allowedRelations(profile, ends.from.type, ends.to.type).includes(relation) ||
61
+ (undirected && allowedRelations(profile, ends.to.type, ends.from.type).includes(relation)));
62
+ }
63
+ /** The attributes without the origin marker, keys in code-unit order so that equal sets serialise alike. */
64
+ function bareAttributes(link) {
65
+ const entries = Object.entries(link.attributes ?? {})
66
+ .filter(([key]) => key !== RELATION_ORIGIN)
67
+ .sort(([a], [b]) => byCodeUnit(a, b));
68
+ return Object.fromEntries(entries);
69
+ }
70
+ function stripped(link) {
71
+ return { ...link, attributes: bareAttributes(link), provenance: [...link.provenance] };
72
+ }
73
+ function groupKey(link) {
74
+ return [link.from, link.to, link.relation, JSON.stringify(bareAttributes(link))].join(" ");
75
+ }
76
+ /**
77
+ * The relation the type pair names for a fallback link: the single one the profile admits from the
78
+ * source type to the target type, else the single one it admits the other way round, in which case
79
+ * the link is turned around. Nothing when either end is untyped or the pair admits none or several.
80
+ */
81
+ function fromPair(link, ends, profile) {
82
+ if (ends.from === undefined || ends.to === undefined)
83
+ return undefined;
84
+ const forward = singleRelation(profile, ends.from.type, ends.to.type);
85
+ if (forward !== undefined)
86
+ return { ...stripped(link), relation: forward };
87
+ const backward = singleRelation(profile, ends.to.type, ends.from.type);
88
+ if (backward !== undefined) {
89
+ return { ...stripped(link), from: link.to, to: link.from, relation: backward };
90
+ }
91
+ return undefined;
92
+ }
93
+ /** An undirected link goes from the smaller identifier, so that the two readings of one pair merge. */
94
+ function oriented(link, undirected) {
95
+ return undirected.has(link.relation) && link.to < link.from
96
+ ? { ...link, from: link.to, to: link.from }
97
+ : link;
98
+ }
99
+ /**
100
+ * Names the relation of every link from the profile, once every producer has spoken and their
101
+ * links are combined. A relation a producer named, from a mapped section or a typed frontmatter
102
+ * attribute, stands: the step only checks that the profile allows it between the two types and
103
+ * drops it with `E-META-REL` otherwise. A `related` link, which no producer could name, takes the
104
+ * single relation the profile admits for its type pair, marked `relation_origin: pair`, turned
105
+ * around when only the reverse pair admits one; it stays `related` when the pair admits none or
106
+ * several. Links that now say the same thing are combined again, a pair-named link joining a
107
+ * declared link of the same triple and attributes and losing its marker; then the cap of the
108
+ * relation applies and every `related` link yields `I-REL-AMBIGUOUS`, located on the first
109
+ * provenance that names a file, unless co-occurrence alone knows it. A link with an endpoint the
110
+ * entity list does not type is kept as produced, since nothing can check it. Pure and idempotent.
111
+ */
112
+ export function typeRelations(input) {
113
+ const { profile } = input;
114
+ const entities = new Map(input.entities.map((entity) => [entity.id, entity]));
115
+ const definitions = Object.entries(profile.relations);
116
+ const undirected = new Set(definitions.filter(([, d]) => !d.directed).map(([slug]) => slug));
117
+ const caps = new Map(definitions.flatMap(([slug, d]) => (d.cap === undefined ? [] : [[slug, d.cap]])));
118
+ const findings = [];
119
+ const kept = [];
120
+ for (const link of input.links) {
121
+ const ends = { from: entities.get(link.from), to: entities.get(link.to) };
122
+ if (!Object.hasOwn(profile.relations, link.relation)) {
123
+ findings.push(outsideMatrix(link, ends, "is not a relation of the profile"));
124
+ continue;
125
+ }
126
+ if (link.relation === FALLBACK_RELATION) {
127
+ const named = fromPair(link, ends, profile);
128
+ kept.push(named === undefined ? { link, pair: false } : { link: named, pair: true });
129
+ continue;
130
+ }
131
+ if (ends.from !== undefined &&
132
+ ends.to !== undefined &&
133
+ !allowedBetween(profile, link.relation, undirected.has(link.relation), {
134
+ from: ends.from,
135
+ to: ends.to,
136
+ })) {
137
+ findings.push(outsideMatrix(link, ends, "is not allowed between these types"));
138
+ continue;
139
+ }
140
+ kept.push({ link, pair: link.attributes?.[RELATION_ORIGIN] === PAIR_ORIGIN });
141
+ }
142
+ const declared = new Set(kept.filter((entry) => !entry.pair).map((entry) => groupKey(oriented(entry.link, undirected))));
143
+ const combined = combineLinks(kept.map((entry) => stripped(oriented(entry.link, undirected))), combineOptions(profile));
144
+ const links = combined.map((link) => {
145
+ const cap = caps.get(link.relation);
146
+ return {
147
+ ...link,
148
+ attributes: declared.has(groupKey(link))
149
+ ? { ...link.attributes }
150
+ : { ...link.attributes, [RELATION_ORIGIN]: PAIR_ORIGIN },
151
+ confidence: cap === undefined ? link.confidence : Math.min(link.confidence, cap),
152
+ };
153
+ });
154
+ for (const link of links) {
155
+ if (link.relation === FALLBACK_RELATION && !unnamedByNature(link)) {
156
+ findings.push(ambiguous(link, { from: entities.get(link.from), to: entities.get(link.to) }));
157
+ }
158
+ }
159
+ return { links, findings: findings.toSorted(compareFindings) };
160
+ }
161
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/relations/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA4C,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAgB,MAAM,2BAA2B,CAAC;AAE3F,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAwBvD,yGAAyG;AACzG,MAAM,CAAC,MAAM,iBAAiB,GAAG,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IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;AACjE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@concordance-wiki/inference",
3
+ "version": "0.1.0",
4
+ "description": "Link production, confidence combination, relation typing, bounded neighbourhood, term candidates.",
5
+ "license": "GPL-3.0-or-later",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/concordance-wiki/concordance.git",
9
+ "directory": "packages/inference"
10
+ },
11
+ "homepage": "https://github.com/concordance-wiki/concordance/tree/main/packages/inference#readme",
12
+ "bugs": "https://github.com/concordance-wiki/concordance/issues",
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "engines": {
16
+ "node": ">=22"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "default": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "typecheck": "tsc -b tsconfig.json"
34
+ },
35
+ "dependencies": {
36
+ "@concordance-wiki/core": "workspace:*",
37
+ "@concordance-wiki/ingest": "workspace:*",
38
+ "@concordance-wiki/profile": "workspace:*"
39
+ },
40
+ "devDependencies": {
41
+ "@concordance-wiki/nlp": "workspace:*",
42
+ "@concordance-wiki/plugin-contract-openapi": "workspace:*",
43
+ "@concordance-wiki/plugin-contract-wsdl": "workspace:*",
44
+ "@concordance-wiki/typing": "workspace:*"
45
+ }
46
+ }