elementary-assertions 1.0.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 (48) hide show
  1. package/CHANGELOG.md +353 -0
  2. package/LICENSE +21 -0
  3. package/README.md +211 -0
  4. package/bin/elementary-assertions.js +8 -0
  5. package/docs/DEV_TOOLING.md +98 -0
  6. package/docs/NPM_RELEASE.md +177 -0
  7. package/docs/OPERATIONAL.md +159 -0
  8. package/docs/RELEASE_NOTES_TEMPLATE.md +37 -0
  9. package/docs/REPO_WORKFLOWS.md +48 -0
  10. package/package.json +46 -0
  11. package/src/core/accepted-annotations.js +44 -0
  12. package/src/core/assertions.js +2304 -0
  13. package/src/core/determinism.js +95 -0
  14. package/src/core/diagnostics.js +496 -0
  15. package/src/core/ids.js +9 -0
  16. package/src/core/mention-builder.js +272 -0
  17. package/src/core/mention-evidence.js +52 -0
  18. package/src/core/mention-head-resolution.js +108 -0
  19. package/src/core/mention-materialization.js +31 -0
  20. package/src/core/mentions.js +149 -0
  21. package/src/core/output.js +296 -0
  22. package/src/core/projection.js +192 -0
  23. package/src/core/roles.js +164 -0
  24. package/src/core/strings.js +7 -0
  25. package/src/core/tokens.js +53 -0
  26. package/src/core/upstream.js +31 -0
  27. package/src/index.js +6 -0
  28. package/src/render/index.js +5 -0
  29. package/src/render/layouts/compact.js +10 -0
  30. package/src/render/layouts/meaning.js +7 -0
  31. package/src/render/layouts/readable.js +7 -0
  32. package/src/render/layouts/table.js +7 -0
  33. package/src/render/render.js +931 -0
  34. package/src/run.js +278 -0
  35. package/src/schema/seed.elementary-assertions.schema.json +1751 -0
  36. package/src/tools/cli.js +158 -0
  37. package/src/tools/index.js +6 -0
  38. package/src/tools/io.js +55 -0
  39. package/src/validate/ajv.js +20 -0
  40. package/src/validate/coverage.js +215 -0
  41. package/src/validate/determinism.js +115 -0
  42. package/src/validate/diagnostics-strict.js +392 -0
  43. package/src/validate/errors.js +19 -0
  44. package/src/validate/index.js +20 -0
  45. package/src/validate/integrity.js +41 -0
  46. package/src/validate/invariants.js +157 -0
  47. package/src/validate/references.js +110 -0
  48. package/src/validate/schema.js +50 -0
@@ -0,0 +1,53 @@
1
+ const { deepCloneJson } = require('./determinism');
2
+
3
+ function buildTokenIndex(seed) {
4
+ if (!Array.isArray(seed.tokens) || seed.tokens.length === 0) throw new Error('relations seed missing tokens');
5
+ const byId = new Map();
6
+ for (const t of seed.tokens) {
7
+ if (!t || typeof t.id !== 'string') throw new Error('token missing id');
8
+ if (typeof t.segment_id !== 'string') throw new Error(`token ${t.id} missing segment_id`);
9
+ if (!t.span || typeof t.span.start !== 'number' || typeof t.span.end !== 'number') {
10
+ throw new Error(`token ${t.id} missing span`);
11
+ }
12
+ if (typeof t.i !== 'number') throw new Error(`token ${t.id} missing i`);
13
+ if (!t.pos || typeof t.pos.tag !== 'string') throw new Error(`token ${t.id} missing pos.tag`);
14
+ byId.set(t.id, t);
15
+ }
16
+ return byId;
17
+ }
18
+
19
+
20
+ function getTokenWikipediaEvidence(token) {
21
+ if (!token || !token.lexicon || typeof token.lexicon !== 'object') return null;
22
+ const ev = token.lexicon.wikipedia_title_index;
23
+ if (!ev || typeof ev !== 'object') return null;
24
+ return deepCloneJson(ev);
25
+ }
26
+
27
+ function buildTokenWikiById(relationsSeed) {
28
+ const out = new Map();
29
+ const tokens = Array.isArray(relationsSeed && relationsSeed.tokens) ? relationsSeed.tokens : [];
30
+ for (const token of tokens) {
31
+ if (!token || typeof token.id !== 'string') continue;
32
+ const ev = getTokenWikipediaEvidence(token);
33
+ if (!ev) continue;
34
+ out.set(token.id, ev);
35
+ }
36
+ return out;
37
+ }
38
+
39
+ function getTokenMetadataProjection(token) {
40
+ const out = {};
41
+ if (token && typeof token.normalized === 'string') out.normalized = token.normalized;
42
+ if (token && token.flags && typeof token.flags === 'object') out.flags = deepCloneJson(token.flags);
43
+ if (token && token.joiner && typeof token.joiner === 'object') out.joiner = deepCloneJson(token.joiner);
44
+ return out;
45
+ }
46
+
47
+
48
+ module.exports = {
49
+ buildTokenIndex,
50
+ getTokenWikipediaEvidence,
51
+ buildTokenWikiById,
52
+ getTokenMetadataProjection,
53
+ };
@@ -0,0 +1,31 @@
1
+ function annotationHasSource(annotation, name) {
2
+ return Array.isArray(annotation && annotation.sources) && annotation.sources.some((s) => s && s.name === name);
3
+ }
4
+
5
+ function collectStep11Relations(relationsSeed, tokenById) {
6
+ const out = [];
7
+ const annotations = Array.isArray(relationsSeed && relationsSeed.annotations) ? relationsSeed.annotations : [];
8
+ for (const annotation of annotations) {
9
+ if (!annotation || annotation.kind !== "dependency" || annotation.status !== "accepted") continue;
10
+ if (!annotationHasSource(annotation, "relation-extraction")) continue;
11
+ if (!annotation.head || typeof annotation.head.id !== "string" || !tokenById.has(annotation.head.id)) continue;
12
+ if (!annotation.dep || typeof annotation.dep.id !== "string" || !tokenById.has(annotation.dep.id)) continue;
13
+ out.push({
14
+ id: typeof annotation.id === "string" ? annotation.id : "",
15
+ label: String(annotation.label || ""),
16
+ head_token_id: annotation.head.id,
17
+ dep_token_id: annotation.dep.id,
18
+ evidence:
19
+ (Array.isArray(annotation.sources)
20
+ ? annotation.sources.find((src) => src && src.name === "relation-extraction")
21
+ : null
22
+ )?.evidence || {},
23
+ });
24
+ }
25
+ return out;
26
+ }
27
+
28
+ module.exports = {
29
+ annotationHasSource,
30
+ collectStep11Relations,
31
+ };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ const { runFromRelations, runElementaryAssertions } = require("./run");
2
+
3
+ module.exports = {
4
+ runFromRelations,
5
+ runElementaryAssertions,
6
+ };
@@ -0,0 +1,5 @@
1
+ const { renderElementaryAssertions } = require("./render");
2
+
3
+ module.exports = {
4
+ renderElementaryAssertions,
5
+ };
@@ -0,0 +1,10 @@
1
+ function renderCompact(doc) {
2
+ const lines = [];
3
+ for (const a of doc.assertions || []) {
4
+ const pred = (a.predicate && a.predicate.mention_id) || "<pred>";
5
+ lines.push(`${a.id}: ${pred}`);
6
+ }
7
+ return lines.join("\n") + (lines.length > 0 ? "\n" : "");
8
+ }
9
+
10
+ module.exports = { renderCompact };
@@ -0,0 +1,7 @@
1
+ const { renderCompact } = require("./compact");
2
+
3
+ function renderMeaning(doc) {
4
+ return renderCompact(doc);
5
+ }
6
+
7
+ module.exports = { renderMeaning };
@@ -0,0 +1,7 @@
1
+ const { renderCompact } = require("./compact");
2
+
3
+ function renderReadable(doc) {
4
+ return renderCompact(doc);
5
+ }
6
+
7
+ module.exports = { renderReadable };
@@ -0,0 +1,7 @@
1
+ const { renderCompact } = require("./compact");
2
+
3
+ function renderTable(doc) {
4
+ return renderCompact(doc);
5
+ }
6
+
7
+ module.exports = { renderTable };