mdld-parse 0.7.4 → 0.7.5
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/package.json +1 -1
- package/src/merge.js +30 -19
- package/src/parse.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdld-parse",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "A standards-compliant parser for **MD-LD (Markdown-Linked Data)** — a human-friendly RDF authoring format that extends Markdown with semantic annotations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/src/merge.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse } from './parse.js';
|
|
2
|
-
import {
|
|
2
|
+
import { quadToKeyForOrigin } from './utils.js';
|
|
3
3
|
import { DEFAULT_CONTEXT } from './constants.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ import { DEFAULT_CONTEXT } from './constants.js';
|
|
|
8
8
|
* @returns {string}
|
|
9
9
|
*/
|
|
10
10
|
function quadKey(quad) {
|
|
11
|
-
return
|
|
11
|
+
return quadToKeyForOrigin(quad);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -41,6 +41,7 @@ export function merge(docs, options = {}) {
|
|
|
41
41
|
const allDocuments = [];
|
|
42
42
|
const quadIndex = new Map();
|
|
43
43
|
const allStatements = []; // Collect statements from all documents
|
|
44
|
+
const accumulatedContext = new Map(); // Track all unique prefixes across documents
|
|
44
45
|
|
|
45
46
|
// Process each document in order
|
|
46
47
|
for (let i = 0; i < docs.length; i++) {
|
|
@@ -52,6 +53,16 @@ export function merge(docs, options = {}) {
|
|
|
52
53
|
// Normalize input to ParseResult
|
|
53
54
|
const doc = normalizeInput(input, options, docContext);
|
|
54
55
|
|
|
56
|
+
// Accumulate context from this document
|
|
57
|
+
if (doc.context) {
|
|
58
|
+
for (const [prefix, namespace] of Object.entries(doc.context)) {
|
|
59
|
+
// Don't override default context entries unless explicitly provided in options
|
|
60
|
+
if (!accumulatedContext.has(prefix) && !DEFAULT_CONTEXT[prefix]) {
|
|
61
|
+
accumulatedContext.set(prefix, namespace);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
// Create document origin
|
|
56
67
|
const documentOrigin = {
|
|
57
68
|
index: i,
|
|
@@ -73,14 +84,12 @@ export function merge(docs, options = {}) {
|
|
|
73
84
|
sessionBuffer.set(key, quad);
|
|
74
85
|
|
|
75
86
|
// Create quad origin with document index and polarity
|
|
76
|
-
const existingOrigin = doc.origin.quadIndex.get(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
}
|
|
87
|
+
const existingOrigin = doc.origin.quadIndex.get(key);
|
|
88
|
+
quadIndex.set(key, {
|
|
89
|
+
...(existingOrigin || {}),
|
|
90
|
+
documentIndex: i,
|
|
91
|
+
polarity: '+'
|
|
92
|
+
});
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
// Fold retractions
|
|
@@ -96,14 +105,12 @@ export function merge(docs, options = {}) {
|
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
// Create quad origin for remove quads
|
|
99
|
-
const existingOrigin = doc.origin.quadIndex.get(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
}
|
|
108
|
+
const existingOrigin = doc.origin.quadIndex.get(key);
|
|
109
|
+
quadIndex.set(key, {
|
|
110
|
+
...(existingOrigin || {}),
|
|
111
|
+
documentIndex: i,
|
|
112
|
+
polarity: '-'
|
|
113
|
+
});
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
116
|
|
|
@@ -118,7 +125,11 @@ export function merge(docs, options = {}) {
|
|
|
118
125
|
};
|
|
119
126
|
|
|
120
127
|
// Build final context (union of all contexts)
|
|
121
|
-
const finalContext = {
|
|
128
|
+
const finalContext = {
|
|
129
|
+
...DEFAULT_CONTEXT,
|
|
130
|
+
...options.context,
|
|
131
|
+
...Object.fromEntries(accumulatedContext)
|
|
132
|
+
};
|
|
122
133
|
|
|
123
134
|
// Enforce hard invariant
|
|
124
135
|
const quadKeys = new Set(finalQuads.map(quadKey));
|
package/src/parse.js
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
createCarrier,
|
|
27
27
|
createListToken,
|
|
28
28
|
parseSemCached,
|
|
29
|
-
EMPTY_SEM,
|
|
30
29
|
parseLangAndAttrs,
|
|
31
30
|
findMatchingBracket,
|
|
32
31
|
extractUrlFromBrackets,
|
|
@@ -40,7 +39,6 @@ import {
|
|
|
40
39
|
RDF_PREDICATE,
|
|
41
40
|
RDF_OBJECT,
|
|
42
41
|
createLeanOriginEntry,
|
|
43
|
-
resolveFragment,
|
|
44
42
|
resolveSubject,
|
|
45
43
|
resolveObject,
|
|
46
44
|
processTokenWithBlockTracking
|