@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.
- package/LICENSE +674 -0
- package/README.md +15 -0
- package/dist/combine/confidence.d.ts +16 -0
- package/dist/combine/confidence.d.ts.map +1 -0
- package/dist/combine/confidence.js +24 -0
- package/dist/combine/confidence.js.map +1 -0
- package/dist/combine/links.d.ts +15 -0
- package/dist/combine/links.d.ts.map +1 -0
- package/dist/combine/links.js +0 -0
- package/dist/combine/links.js.map +1 -0
- package/dist/display/neighbourhood.d.ts +15 -0
- package/dist/display/neighbourhood.d.ts.map +1 -0
- package/dist/display/neighbourhood.js +83 -0
- package/dist/display/neighbourhood.js.map +1 -0
- package/dist/display/options.d.ts +5 -0
- package/dist/display/options.d.ts.map +1 -0
- package/dist/display/options.js +6 -0
- package/dist/display/options.js.map +1 -0
- package/dist/display/serialize.d.ts +7 -0
- package/dist/display/serialize.d.ts.map +1 -0
- package/dist/display/serialize.js +13 -0
- package/dist/display/serialize.js.map +1 -0
- package/dist/display/types.d.ts +44 -0
- package/dist/display/types.d.ts.map +1 -0
- package/dist/display/types.js +2 -0
- package/dist/display/types.js.map +1 -0
- package/dist/duplicates/content.d.ts +29 -0
- package/dist/duplicates/content.d.ts.map +1 -0
- package/dist/duplicates/content.js +42 -0
- package/dist/duplicates/content.js.map +1 -0
- package/dist/duplicates/lsh.d.ts +8 -0
- package/dist/duplicates/lsh.d.ts.map +1 -0
- package/dist/duplicates/lsh.js +38 -0
- package/dist/duplicates/lsh.js.map +1 -0
- package/dist/duplicates/minhash.d.ts +11 -0
- package/dist/duplicates/minhash.d.ts.map +1 -0
- package/dist/duplicates/minhash.js +51 -0
- package/dist/duplicates/minhash.js.map +1 -0
- package/dist/duplicates/options.d.ts +6 -0
- package/dist/duplicates/options.d.ts.map +1 -0
- package/dist/duplicates/options.js +23 -0
- package/dist/duplicates/options.js.map +1 -0
- package/dist/duplicates/resolve.d.ts +13 -0
- package/dist/duplicates/resolve.d.ts.map +1 -0
- package/dist/duplicates/resolve.js +257 -0
- package/dist/duplicates/resolve.js.map +1 -0
- package/dist/duplicates/score.d.ts +22 -0
- package/dist/duplicates/score.d.ts.map +1 -0
- package/dist/duplicates/score.js +190 -0
- package/dist/duplicates/score.js.map +1 -0
- package/dist/duplicates/shingles.d.ts +15 -0
- package/dist/duplicates/shingles.d.ts.map +1 -0
- package/dist/duplicates/shingles.js +35 -0
- package/dist/duplicates/shingles.js.map +1 -0
- package/dist/duplicates/similarity.d.ts +23 -0
- package/dist/duplicates/similarity.d.ts.map +1 -0
- package/dist/duplicates/similarity.js +86 -0
- package/dist/duplicates/similarity.js.map +1 -0
- package/dist/duplicates/types.d.ts +97 -0
- package/dist/duplicates/types.d.ts.map +1 -0
- package/dist/duplicates/types.js +2 -0
- package/dist/duplicates/types.js.map +1 -0
- package/dist/explicit/links.d.ts +30 -0
- package/dist/explicit/links.d.ts.map +1 -0
- package/dist/explicit/links.js +173 -0
- package/dist/explicit/links.js.map +1 -0
- package/dist/explicit/types.d.ts +35 -0
- package/dist/explicit/types.d.ts.map +1 -0
- package/dist/explicit/types.js +2 -0
- package/dist/explicit/types.js.map +1 -0
- package/dist/frontmatter/links.d.ts +21 -0
- package/dist/frontmatter/links.d.ts.map +1 -0
- package/dist/frontmatter/links.js +131 -0
- package/dist/frontmatter/links.js.map +1 -0
- package/dist/frontmatter/resolve.d.ts +32 -0
- package/dist/frontmatter/resolve.d.ts.map +1 -0
- package/dist/frontmatter/resolve.js +62 -0
- package/dist/frontmatter/resolve.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mentions/links.d.ts +43 -0
- package/dist/mentions/links.d.ts.map +1 -0
- package/dist/mentions/links.js +106 -0
- package/dist/mentions/links.js.map +1 -0
- package/dist/mentions/sections.d.ts +17 -0
- package/dist/mentions/sections.d.ts.map +1 -0
- package/dist/mentions/sections.js +26 -0
- package/dist/mentions/sections.js.map +1 -0
- package/dist/neighbourhood/accumulate.d.ts +11 -0
- package/dist/neighbourhood/accumulate.d.ts.map +1 -0
- package/dist/neighbourhood/accumulate.js +73 -0
- package/dist/neighbourhood/accumulate.js.map +1 -0
- package/dist/neighbourhood/links.d.ts +13 -0
- package/dist/neighbourhood/links.d.ts.map +1 -0
- package/dist/neighbourhood/links.js +35 -0
- package/dist/neighbourhood/links.js.map +1 -0
- package/dist/neighbourhood/options.d.ts +5 -0
- package/dist/neighbourhood/options.d.ts.map +1 -0
- package/dist/neighbourhood/options.js +6 -0
- package/dist/neighbourhood/options.js.map +1 -0
- package/dist/neighbourhood/order.d.ts +5 -0
- package/dist/neighbourhood/order.d.ts.map +1 -0
- package/dist/neighbourhood/order.js +9 -0
- package/dist/neighbourhood/order.js.map +1 -0
- package/dist/neighbourhood/serialize.d.ts +4 -0
- package/dist/neighbourhood/serialize.d.ts.map +1 -0
- package/dist/neighbourhood/serialize.js +10 -0
- package/dist/neighbourhood/serialize.js.map +1 -0
- package/dist/neighbourhood/types.d.ts +24 -0
- package/dist/neighbourhood/types.d.ts.map +1 -0
- package/dist/neighbourhood/types.js +2 -0
- package/dist/neighbourhood/types.js.map +1 -0
- package/dist/operations/index.d.ts +30 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +118 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/operations/match.d.ts +64 -0
- package/dist/operations/match.d.ts.map +1 -0
- package/dist/operations/match.js +251 -0
- package/dist/operations/match.js.map +1 -0
- package/dist/operations/merge.d.ts +14 -0
- package/dist/operations/merge.d.ts.map +1 -0
- package/dist/operations/merge.js +60 -0
- package/dist/operations/merge.js.map +1 -0
- package/dist/relations/index.d.ts +3 -0
- package/dist/relations/index.d.ts.map +1 -0
- package/dist/relations/index.js +3 -0
- package/dist/relations/index.js.map +1 -0
- package/dist/relations/labels.d.ts +14 -0
- package/dist/relations/labels.d.ts.map +1 -0
- package/dist/relations/labels.js +22 -0
- package/dist/relations/labels.js.map +1 -0
- package/dist/relations/type.d.ts +40 -0
- package/dist/relations/type.d.ts.map +1 -0
- package/dist/relations/type.js +161 -0
- package/dist/relations/type.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LinkableEntity } from "../explicit/types.js";
|
|
2
|
+
/** Lookups built once over every entity: a reference is tried by identifier, by path, then by title. */
|
|
3
|
+
export interface EntityIndex {
|
|
4
|
+
byId: ReadonlyMap<string, LinkableEntity>;
|
|
5
|
+
/** Keyed by `<source name>/<path>`. */
|
|
6
|
+
byPath: ReadonlyMap<string, LinkableEntity>;
|
|
7
|
+
/** Keyed by the trimmed title; several notes may share one. */
|
|
8
|
+
byTitle: ReadonlyMap<string, readonly LinkableEntity[]>;
|
|
9
|
+
}
|
|
10
|
+
export interface ResolveContext {
|
|
11
|
+
from: LinkableEntity;
|
|
12
|
+
index: EntityIndex;
|
|
13
|
+
}
|
|
14
|
+
export type ReferenceResolution = {
|
|
15
|
+
kind: "resolved";
|
|
16
|
+
entity: LinkableEntity;
|
|
17
|
+
by: "id" | "path" | "title";
|
|
18
|
+
} | {
|
|
19
|
+
kind: "ambiguous";
|
|
20
|
+
candidates: readonly LinkableEntity[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: "unresolved";
|
|
23
|
+
};
|
|
24
|
+
export declare function indexEntities(entities: readonly LinkableEntity[]): EntityIndex;
|
|
25
|
+
/**
|
|
26
|
+
* A reference is an identifier (`specs/roles/maintainer`, or `roles/maintainer` within the
|
|
27
|
+
* source of the note), a path relative to the source root (`roles/maintainer.md`), or the exact
|
|
28
|
+
* title of a note, compared after trimming and case-sensitively. Identifiers and paths are unique; a
|
|
29
|
+
* title shared by several notes resolves nothing.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveReference(value: string, context: ResolveContext): ReferenceResolution;
|
|
32
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/frontmatter/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,wGAAwG;AACxG,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,uCAAuC;IACvC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,+DAA+D;IAC/D,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,EAAE,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,GACzE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE3B,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,WAAW,CAe9E;AA8BD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,mBAAmB,CAO5F"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { identifierFor } from "@concordance-wiki/core";
|
|
2
|
+
export function indexEntities(entities) {
|
|
3
|
+
const byId = new Map();
|
|
4
|
+
const byPath = new Map();
|
|
5
|
+
const byTitle = new Map();
|
|
6
|
+
for (const entity of entities) {
|
|
7
|
+
// The first entity of an identifier wins, as the duplicate resolution of the typing step decided.
|
|
8
|
+
if (!byId.has(entity.id))
|
|
9
|
+
byId.set(entity.id, entity);
|
|
10
|
+
const path = `${entity.source.name}/${entity.source.path}`;
|
|
11
|
+
if (!byPath.has(path))
|
|
12
|
+
byPath.set(path, entity);
|
|
13
|
+
const title = entity.title.trim();
|
|
14
|
+
const titled = byTitle.get(title) ?? [];
|
|
15
|
+
titled.push(entity);
|
|
16
|
+
byTitle.set(title, titled);
|
|
17
|
+
}
|
|
18
|
+
return { byId, byPath, byTitle };
|
|
19
|
+
}
|
|
20
|
+
function byIdentifier(value, context) {
|
|
21
|
+
return (context.index.byId.get(value) ?? context.index.byId.get(`${context.from.source.name}/${value}`));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A path carries its extension; it is tried as written, then through the identifier it derives, so
|
|
25
|
+
* that `Roles/Glossary Owner.md` names `roles/glossary-owner`.
|
|
26
|
+
*/
|
|
27
|
+
function byPath(value, context) {
|
|
28
|
+
if (!value.endsWith(".md"))
|
|
29
|
+
return undefined;
|
|
30
|
+
const source = context.from.source.name;
|
|
31
|
+
const exact = context.index.byPath.get(`${source}/${value}`);
|
|
32
|
+
if (exact !== undefined)
|
|
33
|
+
return exact;
|
|
34
|
+
const derived = identifierFor({ source, path: value, typeSuffixes: [] }).id;
|
|
35
|
+
return context.index.byId.get(derived);
|
|
36
|
+
}
|
|
37
|
+
function byTitle(value, context) {
|
|
38
|
+
const candidates = context.index.byTitle.get(value) ?? [];
|
|
39
|
+
const [single] = candidates;
|
|
40
|
+
if (single === undefined)
|
|
41
|
+
return { kind: "unresolved" };
|
|
42
|
+
return candidates.length === 1
|
|
43
|
+
? { kind: "resolved", entity: single, by: "title" }
|
|
44
|
+
: { kind: "ambiguous", candidates };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A reference is an identifier (`specs/roles/maintainer`, or `roles/maintainer` within the
|
|
48
|
+
* source of the note), a path relative to the source root (`roles/maintainer.md`), or the exact
|
|
49
|
+
* title of a note, compared after trimming and case-sensitively. Identifiers and paths are unique; a
|
|
50
|
+
* title shared by several notes resolves nothing.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveReference(value, context) {
|
|
53
|
+
const written = value.trim();
|
|
54
|
+
const identified = byIdentifier(written, context);
|
|
55
|
+
if (identified !== undefined)
|
|
56
|
+
return { kind: "resolved", entity: identified, by: "id" };
|
|
57
|
+
const located = byPath(written, context);
|
|
58
|
+
if (located !== undefined)
|
|
59
|
+
return { kind: "resolved", entity: located, by: "path" };
|
|
60
|
+
return byTitle(written, context);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/frontmatter/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAuBvD,MAAM,UAAU,aAAa,CAAC,QAAmC;IAC/D,MAAM,IAAI,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IACjD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,kGAAkG;QAClG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAClC,M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GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1D,MAAM,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;IAC5B,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IACxD,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC;QAC5B,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE;QACnD,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,OAAuB;IACrE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACxF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IACpF,OAAO,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { combineConfidences, glossaryConfidence } from "./combine/confidence.js";
|
|
2
|
+
export type { GlossaryCombination } from "./combine/confidence.js";
|
|
3
|
+
export { combineLinks, combineOptions } from "./combine/links.js";
|
|
4
|
+
export type { CombineOptions } from "./combine/links.js";
|
|
5
|
+
export { MAX_DISPLAYED_NEIGHBOURS, displayedNeighbourhood } from "./display/neighbourhood.js";
|
|
6
|
+
export { displayOptions } from "./display/options.js";
|
|
7
|
+
export { displayedNeighbourhoodToModel } from "./display/serialize.js";
|
|
8
|
+
export type { DisplayableEntity, DisplayOptions, DisplayedNeighbour, DisplayedNeighbourhood, DisplayedNeighbourhoodInput, NeighbourDirection, NeighbourKind, } from "./display/types.js";
|
|
9
|
+
export { duplicateOptions, DUPLICATE_DEFAULTS } from "./duplicates/options.js";
|
|
10
|
+
export { DUPLICATE_CHECK, formatDuplicateStats, resolveDuplicateResources, } from "./duplicates/resolve.js";
|
|
11
|
+
export type { DuplicateGroup, DuplicateInput, DuplicateLock, DuplicateMode, DuplicateOptions, DuplicatePair, DuplicateRepresentation, DuplicateResource, DuplicateResult, DuplicateSignal, DuplicateStats, } from "./duplicates/types.js";
|
|
12
|
+
export { explicitLinks, locateLink } from "./explicit/links.js";
|
|
13
|
+
export type { LocatedLink, SourceFiles } from "./explicit/links.js";
|
|
14
|
+
export type { ExplicitLinksInput, ExplicitLinksResult, LinkableEntity, SourceResource, } from "./explicit/types.js";
|
|
15
|
+
export { accumulateCooccurrences } from "./neighbourhood/accumulate.js";
|
|
16
|
+
export { cooccurrenceLinks } from "./neighbourhood/links.js";
|
|
17
|
+
export { neighbourhoodOptions } from "./neighbourhood/options.js";
|
|
18
|
+
export { neighbourhoodToModel } from "./neighbourhood/serialize.js";
|
|
19
|
+
export type { Neighbour, Neighbourhood, NeighbourhoodOptions, OccurrenceLike, } from "./neighbourhood/types.js";
|
|
20
|
+
export { frontmatterLinks, type FrontmatterLinksInput, type FrontmatterLinksResult, } from "./frontmatter/links.js";
|
|
21
|
+
export { indexEntities, resolveReference, type EntityIndex, type ReferenceResolution, type ResolveContext, } from "./frontmatter/resolve.js";
|
|
22
|
+
export { mentionLinks, type MentionLinksInput, type MentionLinksResult, type MentionOccurrence, } from "./mentions/links.js";
|
|
23
|
+
export { foldHeading, mappedSection, type MappedSection } from "./mentions/sections.js";
|
|
24
|
+
export { FALLBACK_RELATION, RELATION_ORIGIN, relationLabel, typeRelations, type RelationLabelOptions, type TypedEntity, type TypeRelationsInput, type TypeRelationsResult, } from "./relations/index.js";
|
|
25
|
+
export { attachOperations, CONTRACT_REPRESENTATION, importedOperations, MATCH_RUNGS, matchOperations, mergeOperation, OPERATION_AMBIGUOUS, OPERATION_UNMATCHED, operationNotes, redirectLinks, type Ambiguity, type AttachOperationsInput, type AttachOperationsResult, type ImportedOperation, type MatchResult, type MatchRung, type OperationMatch, type OperationNote, } from "./operations/index.js";
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACjF,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,u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ACX,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { combineConfidences, glossaryConfidence } from "./combine/confidence.js";
|
|
2
|
+
export { combineLinks, combineOptions } from "./combine/links.js";
|
|
3
|
+
export { MAX_DISPLAYED_NEIGHBOURS, displayedNeighbourhood } from "./display/neighbourhood.js";
|
|
4
|
+
export { displayOptions } from "./display/options.js";
|
|
5
|
+
export { displayedNeighbourhoodToModel } from "./display/serialize.js";
|
|
6
|
+
export { duplicateOptions, DUPLICATE_DEFAULTS } from "./duplicates/options.js";
|
|
7
|
+
export { DUPLICATE_CHECK, formatDuplicateStats, resolveDuplicateResources, } from "./duplicates/resolve.js";
|
|
8
|
+
export { explicitLinks, locateLink } from "./explicit/links.js";
|
|
9
|
+
export { accumulateCooccurrences } from "./neighbourhood/accumulate.js";
|
|
10
|
+
export { cooccurrenceLinks } from "./neighbourhood/links.js";
|
|
11
|
+
export { neighbourhoodOptions } from "./neighbourhood/options.js";
|
|
12
|
+
export { neighbourhoodToModel } from "./neighbourhood/serialize.js";
|
|
13
|
+
export { frontmatterLinks, } from "./frontmatter/links.js";
|
|
14
|
+
export { indexEntities, resolveReference, } from "./frontmatter/resolve.js";
|
|
15
|
+
export { mentionLinks, } from "./mentions/links.js";
|
|
16
|
+
export { foldHeading, mappedSection } from "./mentions/sections.js";
|
|
17
|
+
export { FALLBACK_RELATION, RELATION_ORIGIN, relationLabel, typeRelations, } from "./relations/index.js";
|
|
18
|
+
export { attachOperations, CONTRACT_REPRESENTATION, importedOperations, MATCH_RUNGS, matchOperations, mergeOperation, OPERATION_AMBIGUOUS, OPERATION_UNMATCHED, operationNotes, redirectLinks, } from "./operations/index.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAUvE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,yBAAyB,CAAC;AAcjC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,OAAO,EACL,gBAAgB,GAGjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,aAAa,EACb,gBAAgB,GAIjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,YAAY,GAIb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAsB,MAAM,wBAAwB,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,aAAa,GAKd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,cAAc,EACd,aAAa,GASd,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Link } from "@concordance-wiki/core";
|
|
2
|
+
import { type Profile } from "@concordance-wiki/profile";
|
|
3
|
+
import type { LinkableEntity } from "../explicit/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* What a mention needs to carry to become a link: the shape of an occurrence of the scan,
|
|
6
|
+
* re-declared structurally so that this package never depends on the scan itself.
|
|
7
|
+
*/
|
|
8
|
+
export interface MentionOccurrence {
|
|
9
|
+
target: {
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
/** Name of the source holding the file the mention was read in. */
|
|
13
|
+
source: string;
|
|
14
|
+
/** Forward-slash path of that file relative to the source root. */
|
|
15
|
+
path: string;
|
|
16
|
+
line: number;
|
|
17
|
+
/** Heading of the enclosing H2 section, when any. */
|
|
18
|
+
section?: string;
|
|
19
|
+
/** The confidence the scan gave this mention (type prefix bonus, homonym factor); the base of the profile when absent. */
|
|
20
|
+
confidence?: number;
|
|
21
|
+
/** Code unit offset of the match in its paragraph. */
|
|
22
|
+
position?: number;
|
|
23
|
+
/** The match as written in the note. */
|
|
24
|
+
text?: string;
|
|
25
|
+
/** The text around the match as the scan cut it; the mentions panel of the target shows it. */
|
|
26
|
+
context?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface MentionLinksInput {
|
|
29
|
+
occurrences: readonly MentionOccurrence[];
|
|
30
|
+
entities: readonly LinkableEntity[];
|
|
31
|
+
profile: Profile;
|
|
32
|
+
}
|
|
33
|
+
export interface MentionLinksResult {
|
|
34
|
+
links: Link[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Every mention of an entity in the note of another gives a link from the note to the entity: the
|
|
38
|
+
* relation the profile maps to the enclosing section when there is one and the type pair admits
|
|
39
|
+
* it, `related` at the glossary occurrence confidence otherwise. Mentions of one target in one
|
|
40
|
+
* relation merge into one link with a provenance per mention.
|
|
41
|
+
*/
|
|
42
|
+
export declare function mentionLinks(input: MentionLinksInput): MentionLinksResult;
|
|
43
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/mentions/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EAEV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0HAA0H;IAC1H,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC1C,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAgCD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CA8FzE"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { compareLinks, compareProvenances, } from "@concordance-wiki/core";
|
|
2
|
+
import { allowedRelations } from "@concordance-wiki/profile";
|
|
3
|
+
import { mappedSection } from "./sections.js";
|
|
4
|
+
function byCodeUnit(a, b) {
|
|
5
|
+
return Number(a > b) - Number(a < b);
|
|
6
|
+
}
|
|
7
|
+
function fileKey(source, path) {
|
|
8
|
+
return `${source}/${path}`;
|
|
9
|
+
}
|
|
10
|
+
/** The passage of a mention and the words matched, kept on its provenance when the scan reported them. */
|
|
11
|
+
function passageOf(occurrence) {
|
|
12
|
+
if (occurrence.context === undefined)
|
|
13
|
+
return {};
|
|
14
|
+
return {
|
|
15
|
+
...(occurrence.text === undefined ? {} : { text: occurrence.text }),
|
|
16
|
+
occurrences: [
|
|
17
|
+
{
|
|
18
|
+
line: occurrence.line,
|
|
19
|
+
...(occurrence.position === undefined ? {} : { position: occurrence.position }),
|
|
20
|
+
context: occurrence.context,
|
|
21
|
+
...(occurrence.section === undefined ? {} : { section: occurrence.section }),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Every mention of an entity in the note of another gives a link from the note to the entity: the
|
|
28
|
+
* relation the profile maps to the enclosing section when there is one and the type pair admits
|
|
29
|
+
* it, `related` at the glossary occurrence confidence otherwise. Mentions of one target in one
|
|
30
|
+
* relation merge into one link with a provenance per mention.
|
|
31
|
+
*/
|
|
32
|
+
export function mentionLinks(input) {
|
|
33
|
+
const { profile } = input;
|
|
34
|
+
const sectionConfidence = profile.confidence.section_mention ?? 0.7;
|
|
35
|
+
const occurrenceConfidence = profile.confidence.glossary_occurrence?.base ?? 0.6;
|
|
36
|
+
const byFile = new Map(input.entities.map((entity) => [fileKey(entity.source.name, entity.source.path), entity]));
|
|
37
|
+
const byId = new Map(input.entities.map((entity) => [entity.id, entity]));
|
|
38
|
+
const merged = new Map();
|
|
39
|
+
const record = (source, target, relation, attributes, provenance) => {
|
|
40
|
+
// An undirected relation goes from the smaller identifier, so that reciprocal mentions merge.
|
|
41
|
+
const undirected = profile.relations[relation]?.directed === false;
|
|
42
|
+
const [from, to] = undirected && target.id < source.id ? [target, source] : [source, target];
|
|
43
|
+
const serialised = JSON.stringify(attributes);
|
|
44
|
+
const key = `${from.id} ${to.id} ${relation} ${serialised}`;
|
|
45
|
+
const existing = merged.get(key);
|
|
46
|
+
if (existing === undefined) {
|
|
47
|
+
merged.set(key, {
|
|
48
|
+
link: {
|
|
49
|
+
from: from.id,
|
|
50
|
+
to: to.id,
|
|
51
|
+
relation,
|
|
52
|
+
attributes,
|
|
53
|
+
confidence: provenance.confidence,
|
|
54
|
+
provenance: [provenance],
|
|
55
|
+
},
|
|
56
|
+
attributes: serialised,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Every mention keeps its provenance; combining their confidences is a later step.
|
|
61
|
+
existing.link.provenance.push(provenance);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
for (const occurrence of input.occurrences) {
|
|
65
|
+
const from = byFile.get(fileKey(occurrence.source, occurrence.path));
|
|
66
|
+
const to = byId.get(occurrence.target.id);
|
|
67
|
+
if (from === undefined || to === undefined || to.id === from.id)
|
|
68
|
+
continue;
|
|
69
|
+
const type = profile.types[from.type];
|
|
70
|
+
const section = type === undefined || occurrence.section === undefined
|
|
71
|
+
? undefined
|
|
72
|
+
: mappedSection(occurrence.section, type);
|
|
73
|
+
if (section !== undefined) {
|
|
74
|
+
const { produces, inverse, attributes } = section.definition;
|
|
75
|
+
const [source, target] = inverse === true ? [to, from] : [from, to];
|
|
76
|
+
// A mention is a recognised word, not a declared reference: when the section's relation
|
|
77
|
+
// does not join these two types, the mention counts as any other one instead of erring.
|
|
78
|
+
if (allowedRelations(profile, source.type, target.type).includes(produces)) {
|
|
79
|
+
record(source, target, produces, { ...attributes }, {
|
|
80
|
+
method: "section_mention",
|
|
81
|
+
confidence: sectionConfidence,
|
|
82
|
+
path: occurrence.path,
|
|
83
|
+
line: occurrence.line,
|
|
84
|
+
section: section.name,
|
|
85
|
+
...passageOf(occurrence),
|
|
86
|
+
});
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// The relation typing step refines `related` later, once every method has spoken.
|
|
91
|
+
record(from, to, "related", {}, {
|
|
92
|
+
method: "glossary_occurrence",
|
|
93
|
+
confidence: occurrence.confidence ?? occurrenceConfidence,
|
|
94
|
+
path: occurrence.path,
|
|
95
|
+
line: occurrence.line,
|
|
96
|
+
...passageOf(occurrence),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const links = [...merged.values()]
|
|
100
|
+
.sort((a, b) => compareLinks(a.link, b.link) || byCodeUnit(a.attributes, b.attributes))
|
|
101
|
+
.map((candidate) => candidate.link);
|
|
102
|
+
for (const link of links)
|
|
103
|
+
link.provenance.sort(compareProvenances);
|
|
104
|
+
return { links };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/mentions/links.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,kBAAkB,GAGnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAgB,MAAM,2BAA2B,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAyC9C,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY;IAC3C,OAAO,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC;AAC7B,CAAC;AAED,0GAA0G;AAC1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MAAM,EAAE,iBAAiB;oBACzB,UAAU,EAAE,iBAAiB;oBAC7B,IAAI,EAAE,UAAU,CAAC,IAAI;oBACrB,IAAI,EAAE,UAAU,CAAC,IAAI;oBACrB,OAAO,EAAE,OAAO,CAAC,IAAI;oBACrB,GAAG,SAAS,CAAC,UAAU,CAAC;iBACzB,CACF,CAAC;gBACF,SAAS;YACX,CAAC;QACH,CAAC;QACD,kFAAkF;QAClF,MAAM,CACJ,IAAI,EACJ,EAAE,EACF,SAAS,EACT,EAAE,EACF;YACE,MAAM,EAAE,qBAAqB;YAC7B,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,oBAAoB;YACzD,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,GAAG,SAAS,CAAC,UAAU,CAAC;SACzB,CACF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;SAC/B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;SACtF,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACtC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACnE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SectionDefinition, TypeDefinition } from "@concordance-wiki/profile";
|
|
2
|
+
export interface MappedSection {
|
|
3
|
+
/** The key of the section in the profile, `objects` for `## Objects`. */
|
|
4
|
+
name: string;
|
|
5
|
+
definition: SectionDefinition;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The comparison form of a heading: accents folded, lower-cased, surrounding and repeated
|
|
9
|
+
* whitespace removed, so that `## OBJECTS`, `## objets` and `## Objets ` all read the same.
|
|
10
|
+
*/
|
|
11
|
+
export declare function foldHeading(heading: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* The section of `type` whose key or heading label, in any locale of the profile, reads as
|
|
14
|
+
* `heading`; sections are tried in the key order of the profile.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mappedSection(heading: string, type: TypeDefinition): MappedSection | undefined;
|
|
17
|
+
//# sourceMappingURL=sections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections.d.ts","sourceRoot":"","sources":["../../src/mentions/sections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEnF,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,iBAAiB,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAQ9F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The comparison form of a heading: accents folded, lower-cased, surrounding and repeated
|
|
3
|
+
* whitespace removed, so that `## OBJECTS`, `## objets` and `## Objets ` all read the same.
|
|
4
|
+
*/
|
|
5
|
+
export function foldHeading(heading) {
|
|
6
|
+
return heading.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim().replace(/\s+/g, " ");
|
|
7
|
+
}
|
|
8
|
+
function labelsOf(name, definition) {
|
|
9
|
+
// The key itself is accepted as a heading, so that an author may write the profile's own vocabulary.
|
|
10
|
+
// The spread gives the label an anonymous type, which `Object.values` can read locale by locale.
|
|
11
|
+
return [name, ...Object.values({ ...definition.heading })];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The section of `type` whose key or heading label, in any locale of the profile, reads as
|
|
15
|
+
* `heading`; sections are tried in the key order of the profile.
|
|
16
|
+
*/
|
|
17
|
+
export function mappedSection(heading, type) {
|
|
18
|
+
const folded = foldHeading(heading);
|
|
19
|
+
for (const [name, definition] of Object.entries(type.sections ?? {})) {
|
|
20
|
+
if (labelsOf(name, definition).some((label) => foldHeading(label) === folded)) {
|
|
21
|
+
return { name, definition };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=sections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections.js","sourceRoot":"","sources":["../../src/mentions/sections.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,UAA6B;IAC3D,qGAAqG;IACrG,iGAAiG;IACjG,OAAO,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,CAAS,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,IAAoB;IACjE,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC;QACrE,IAAI,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC;YAC9E,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Neighbourhood, NeighbourhoodOptions, OccurrenceLike } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Two entities named in the same paragraph are neighbours; their count is the number of such
|
|
4
|
+
* paragraphs. Each node keeps its own row of counts, trimmed to the best `k` whenever it grows
|
|
5
|
+
* past `2k`, so that memory stays proportional to the number of nodes times `k` and never to the
|
|
6
|
+
* square of the number of nodes. A neighbour dropped by a trim starts again from zero if it
|
|
7
|
+
* reappears: the counts of the retained neighbours are exact only when the neighbour was never
|
|
8
|
+
* dropped, which holds as soon as the frequent pairs stand out from the occasional ones.
|
|
9
|
+
*/
|
|
10
|
+
export declare function accumulateCooccurrences(occurrences: readonly OccurrenceLike[], options: NeighbourhoodOptions): Neighbourhood;
|
|
11
|
+
//# sourceMappingURL=accumulate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accumulate.d.ts","sourceRoot":"","sources":["../../src/neighbourhood/accumulate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAgDjG;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,SAAS,cAAc,EAAE,EACtC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CA6Bf"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { byCodeUnit, compareNeighbours } from "./order.js";
|
|
2
|
+
/**
|
|
3
|
+
* Distinct identifiers paired in one paragraph. A paragraph naming more entities is a list or a
|
|
4
|
+
* table rather than prose; pairing all of them would cost a quadratic number of increments for
|
|
5
|
+
* a signal that says little, so only the first ones by identifier are paired.
|
|
6
|
+
*/
|
|
7
|
+
const PARAGRAPH_CAP = 200;
|
|
8
|
+
function best(row, k) {
|
|
9
|
+
return [...row]
|
|
10
|
+
.map(([id, count]) => ({ id, count }))
|
|
11
|
+
.sort(compareNeighbours)
|
|
12
|
+
.slice(0, k);
|
|
13
|
+
}
|
|
14
|
+
function compareParagraphs(a, b) {
|
|
15
|
+
return byCodeUnit(a.source, b.source) || byCodeUnit(a.path, b.path) || a.line - b.line;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The distinct identifiers of every paragraph, paragraphs in `(source, path, line)` order and
|
|
19
|
+
* identifiers in code-unit order, so that the result depends on the set of occurrences alone.
|
|
20
|
+
*/
|
|
21
|
+
function paragraphs(occurrences) {
|
|
22
|
+
const byKey = new Map();
|
|
23
|
+
for (const occurrence of occurrences) {
|
|
24
|
+
const source = occurrence.source ?? "";
|
|
25
|
+
const key = `${source}\n${occurrence.path}\n${String(occurrence.line)}`;
|
|
26
|
+
let paragraph = byKey.get(key);
|
|
27
|
+
if (paragraph === undefined) {
|
|
28
|
+
paragraph = { source, path: occurrence.path, line: occurrence.line, members: new Set() };
|
|
29
|
+
byKey.set(key, paragraph);
|
|
30
|
+
}
|
|
31
|
+
paragraph.members.add(occurrence.target.id);
|
|
32
|
+
}
|
|
33
|
+
return [...byKey.values()]
|
|
34
|
+
.sort(compareParagraphs)
|
|
35
|
+
.map((paragraph) => [...paragraph.members].sort(byCodeUnit).slice(0, PARAGRAPH_CAP));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Two entities named in the same paragraph are neighbours; their count is the number of such
|
|
39
|
+
* paragraphs. Each node keeps its own row of counts, trimmed to the best `k` whenever it grows
|
|
40
|
+
* past `2k`, so that memory stays proportional to the number of nodes times `k` and never to the
|
|
41
|
+
* square of the number of nodes. A neighbour dropped by a trim starts again from zero if it
|
|
42
|
+
* reappears: the counts of the retained neighbours are exact only when the neighbour was never
|
|
43
|
+
* dropped, which holds as soon as the frequent pairs stand out from the occasional ones.
|
|
44
|
+
*/
|
|
45
|
+
export function accumulateCooccurrences(occurrences, options) {
|
|
46
|
+
const { k } = options;
|
|
47
|
+
const rows = new Map();
|
|
48
|
+
const bump = (from, to) => {
|
|
49
|
+
let row = rows.get(from);
|
|
50
|
+
if (row === undefined) {
|
|
51
|
+
row = new Map();
|
|
52
|
+
rows.set(from, row);
|
|
53
|
+
}
|
|
54
|
+
row.set(to, (row.get(to) ?? 0) + 1);
|
|
55
|
+
if (row.size > 2 * k) {
|
|
56
|
+
rows.set(from, new Map(best(row, k).map((neighbour) => [neighbour.id, neighbour.count])));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
for (const members of paragraphs(occurrences)) {
|
|
60
|
+
// Members are distinct: every unordered pair is met once and a node never meets itself.
|
|
61
|
+
for (const a of members) {
|
|
62
|
+
for (const b of members) {
|
|
63
|
+
if (a < b) {
|
|
64
|
+
bump(a, b);
|
|
65
|
+
bump(b, a);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const nodes = new Map([...rows].sort(([a], [b]) => byCodeUnit(a, b)).map(([id, row]) => [id, best(row, k)]));
|
|
71
|
+
return { k, nodes };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=accumulate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accumulate.js","sourceRoot":"","sources":["../../src/neighbourhood/accumulate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG3D;;;;GAIG;AACH,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,SAAS,IAAI,CAAC,GAAgC,EAAE,CAAS;IACvD,OAAO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C9C,wFAAwF;QACxF,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACxB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;oBACV,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACX,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACb,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CACtF,CAAC;IACF,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Link } from "@concordance-wiki/core";
|
|
2
|
+
import type { Profile } from "@concordance-wiki/profile";
|
|
3
|
+
import type { Neighbourhood } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* One undirected `related` link per neighbour pair at the `cooccurrence` confidence of the
|
|
6
|
+
* profile, the number of shared paragraphs as its provenance. A pair is listed by either of its
|
|
7
|
+
* nodes or by both; when the two rows disagree, a trim reset one of them and the larger count is
|
|
8
|
+
* the closer to the truth. The relation typing step may refine `related` from the type pair.
|
|
9
|
+
*/
|
|
10
|
+
export declare function cooccurrenceLinks(neighbourhood: Neighbourhood, options: {
|
|
11
|
+
profile: Profile;
|
|
12
|
+
}): Link[];
|
|
13
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/neighbourhood/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQhD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAC5B,IAAI,EAAE,CAyBR"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { compareLinks } from "@concordance-wiki/core";
|
|
2
|
+
/**
|
|
3
|
+
* One undirected `related` link per neighbour pair at the `cooccurrence` confidence of the
|
|
4
|
+
* profile, the number of shared paragraphs as its provenance. A pair is listed by either of its
|
|
5
|
+
* nodes or by both; when the two rows disagree, a trim reset one of them and the larger count is
|
|
6
|
+
* the closer to the truth. The relation typing step may refine `related` from the type pair.
|
|
7
|
+
*/
|
|
8
|
+
export function cooccurrenceLinks(neighbourhood, options) {
|
|
9
|
+
const confidence = options.profile.confidence.cooccurrence ?? 0.4;
|
|
10
|
+
const pairs = new Map();
|
|
11
|
+
for (const [id, neighbours] of neighbourhood.nodes) {
|
|
12
|
+
for (const neighbour of neighbours) {
|
|
13
|
+
const [from, to] = id < neighbour.id ? [id, neighbour.id] : [neighbour.id, id];
|
|
14
|
+
const key = `${from} ${to}`;
|
|
15
|
+
const existing = pairs.get(key);
|
|
16
|
+
if (existing === undefined) {
|
|
17
|
+
pairs.set(key, { from, to, count: neighbour.count });
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
existing.count = Math.max(existing.count, neighbour.count);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [...pairs.values()]
|
|
25
|
+
.map(({ from, to, count }) => ({
|
|
26
|
+
from,
|
|
27
|
+
to,
|
|
28
|
+
relation: "related",
|
|
29
|
+
attributes: {},
|
|
30
|
+
confidence,
|
|
31
|
+
provenance: [{ method: "cooccurrence", confidence, count }],
|
|
32
|
+
}))
|
|
33
|
+
.sort(compareLinks);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/neighbourhood/links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,MAAM,wBAAwB,CAAC;AAWjE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,aAA4B,EAC5B,OAA6B;IAE7B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,IAAI,GAAG,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IACtC,KAAK,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;QACnD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC/E,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;YAC5B,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;YACvD,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;SACvB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAQ,EAAE,CAAC,CAAC;QACnC,IAAI;QACJ,EAAE;QACF,QAAQ,EAAE,SAAS;QACnB,UAAU,EAAE,EAAE;QACd,UAAU;QACV,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;KAC5D,CAAC,CAAC;SACF,IAAI,CAAC,YAAY,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InferenceConfig } from "@concordance-wiki/core";
|
|
2
|
+
import type { NeighbourhoodOptions } from "./types.js";
|
|
3
|
+
/** `inference.neighbours.k` of the configuration, 50 when unset. */
|
|
4
|
+
export declare function neighbourhoodOptions(inference?: InferenceConfig): NeighbourhoodOptions;
|
|
5
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/neighbourhood/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAIvD,oEAAoE;AACpE,wBAAgB,oBAAoB,CAAC,SAAS,CAAC,EAAE,eAAe,GAAG,oBAAoB,CAEtF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/neighbourhood/options.ts"],"names":[],"mappings":"AAIA,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,oEAAoE;AACpE,MAAM,UAAU,oBAAoB,CAAC,SAA2B;IAC9D,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Neighbour } from "./types.js";
|
|
2
|
+
export declare function byCodeUnit(a: string, b: string): number;
|
|
3
|
+
/** Best first: the larger count, then the lower identifier. */
|
|
4
|
+
export declare function compareNeighbours(a: Neighbour, b: Neighbour): number;
|
|
5
|
+
//# sourceMappingURL=order.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../src/neighbourhood/order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CAEpE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Code-unit order, not locale order: the output must not depend on the collation data of the runtime.
|
|
2
|
+
export function byCodeUnit(a, b) {
|
|
3
|
+
return Number(a > b) - Number(a < b);
|
|
4
|
+
}
|
|
5
|
+
/** Best first: the larger count, then the lower identifier. */
|
|
6
|
+
export function compareNeighbours(a, b) {
|
|
7
|
+
return b.count - a.count || byCodeUnit(a.id, b.id);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order.js","sourceRoot":"","sources":["../../src/neighbourhood/order.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,UAAU,UAAU,CAAC,CAAS,EAAE,CAAS;IAC7C,OAAO,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB,CAAC,CAAY,EAAE,CAAY;IAC1D,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Neighbour, Neighbourhood } from "./types.js";
|
|
2
|
+
/** The `neighbours` block of `model.json`: keys in identifier order, each list best first. */
|
|
3
|
+
export declare function neighbourhoodToModel(neighbourhood: Neighbourhood): Record<string, Neighbour[]>;
|
|
4
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/neighbourhood/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3D,8FAA8F;AAC9F,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAM9F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { byCodeUnit } from "./order.js";
|
|
2
|
+
/** The `neighbours` block of `model.json`: keys in identifier order, each list best first. */
|
|
3
|
+
export function neighbourhoodToModel(neighbourhood) {
|
|
4
|
+
const block = {};
|
|
5
|
+
for (const [id, neighbours] of [...neighbourhood.nodes].sort(([a], [b]) => byCodeUnit(a, b))) {
|
|
6
|
+
block[id] = neighbours.map((neighbour) => ({ ...neighbour }));
|
|
7
|
+
}
|
|
8
|
+
return block;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../src/neighbourhood/serialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,8FAA8F;AAC9F,MAAM,UAAU,oBAAoB,CAAC,aAA4B;IAC/D,MAAM,KAAK,GAAgC,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7F,KAAK,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|