mdld-parse 1.0.4 → 1.0.6
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/README.md +85 -17
- package/dist/index.js +127 -50
- package/package.json +34 -28
package/README.md
CHANGED
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
**Markdown-Linked Data** — Write RDF knowledge graphs as plain Markdown. Parse to quads, generate back, merge documents. Zero dependencies, round-trip safe.
|
|
4
4
|
|
|
5
|
-
Unlike Turtle, JSON-LD,
|
|
5
|
+
MD-LD is the only RDF format that is both writable by humans and parseable by machines in the same document. Unlike Turtle (write-only), JSON-LD (machine-only), and RDFa (embedded-in-HTML-only), MD-LD annotations flow with natural Markdown prose — making knowledge graphs readable without a renderer.
|
|
6
6
|
|
|
7
|
-
[
|
|
7
|
+
**[mdld.js.org](https://mdld.js.org/)**
|
|
8
8
|
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## 📚 Documentation Hub
|
|
13
|
-
|
|
14
|
-
- **📋 [Specification](./spec/index.md)** — Formal specification and test suite
|
|
15
|
-
- **📖 [Documentation](./docs/index.md)** — Complete documentation with guides and references
|
|
16
|
-
- **🎯 [Examples](./examples/index.md)** — Real-world MD-LD examples and use cases
|
|
17
|
-
- **📚 [Grammar](./grammar/index.md)** — EBNF grammar specification
|
|
18
|
-
- **🧩 [Ontologies](./ontologies/index.md)** — W3C and related standard ontologies used in RDF
|
|
9
|
+
[](https://www.npmjs.com/package/mdld-parse/)
|
|
19
10
|
|
|
20
11
|
## 🎯 What is MD-LD?
|
|
21
12
|
|
|
@@ -93,6 +84,7 @@ MD-LD removes the intermediary. Writing becomes publishing. Publishing becomes g
|
|
|
93
84
|
- **Decentralized authority** — RFC 4151 tag: URIs enable self-sovereign identity without central registries
|
|
94
85
|
- **Text-native agent memory** - LLM Agent memory substrate in plain text — parse context, write knowledge, merge with other agents, all as Markdown files. No database required.
|
|
95
86
|
|
|
87
|
+
|
|
96
88
|
### Real-World Applications
|
|
97
89
|
|
|
98
90
|
#### Personal Knowledge Management
|
|
@@ -518,6 +510,80 @@ Comprehensive test suite covering:
|
|
|
518
510
|
- Round-trip parse/generate cycles
|
|
519
511
|
- Origin tracking and provenance
|
|
520
512
|
|
|
513
|
+
|
|
514
|
+
## 📚 Documentation Hub
|
|
515
|
+
|
|
516
|
+
- **📋 [Specification](./spec/index.md)** — Formal specification and test suite
|
|
517
|
+
- [Formal Specification](./spec/Spec.md)
|
|
518
|
+
- [Compact Spec](./spec/Spec-compact.md)
|
|
519
|
+
- [Ultra Compact Spec](./spec/Spec-ultra.md)
|
|
520
|
+
- **📚 [Grammar](./grammar/index.md)** — EBNF+TextMate grammar specifications
|
|
521
|
+
- [The TextMate grammar](./grammar/mdld.tmLanguage.json)
|
|
522
|
+
- [ISO 14977 EBNF grammar](./grammar/mdld.ebnf)
|
|
523
|
+
- **📖 [Documentation](./docs/index.md)** — Complete documentation with guides and references
|
|
524
|
+
- [MD-LD Authoring Guide](./docs/Guide.md)
|
|
525
|
+
- [One Page Guide](./docs/one-page.md)
|
|
526
|
+
- [Semantic Infrastructure as Readable Text](./docs/Semantic-Text.md)
|
|
527
|
+
- [Elevated Statements](./docs/statements.md)
|
|
528
|
+
- [Primary Metadata System](./docs/primary-subject.md)
|
|
529
|
+
- [Origin System](./docs/origin.md)
|
|
530
|
+
- [Polarity & Retraction](./docs/polarity.md)
|
|
531
|
+
- [Subject System](./docs/Subject.md)
|
|
532
|
+
- [API Reference](./docs/API.md)
|
|
533
|
+
- [Generate: Quads to MDLD](./docs/generate.md)
|
|
534
|
+
- [Diff Documents](./docs/diff.md)
|
|
535
|
+
- [Syntax Reference](./docs/Syntax.md)
|
|
536
|
+
- [Architecture & Design](./docs/Architecture.md)
|
|
537
|
+
- [Parser Architecture](./docs/Parser.md)
|
|
538
|
+
- [Performance Benchmarks](./docs/Performance.md)
|
|
539
|
+
- [Token Efficiency](./docs/Token-Efficiency.md)
|
|
540
|
+
- [Knowledge Round Trip](./docs/Knowledge-Round-Trip.md)
|
|
541
|
+
- [Human-Scale Software & Semantic Infrastructure](./docs/Human-Scale.md)
|
|
542
|
+
- [Quad[] as a Universal Semantic Runtime](./docs/quad-runtime.md)
|
|
543
|
+
- [Use Cases](./docs/Use-Cases.md)
|
|
544
|
+
- **🎯 [Examples](./examples/index.md)** — Real-world MD-LD examples and use cases
|
|
545
|
+
- [Minimal](./examples/demo/minimal.md)
|
|
546
|
+
- [One-Page Guide](./examples/one-page.md)
|
|
547
|
+
- [Few-Shot Examples](./examples/few-shot.md)
|
|
548
|
+
- [Journal](./examples/demo/journal.md)
|
|
549
|
+
- [Tasks](./examples/demo/tasks.md)
|
|
550
|
+
- [Medical AI Research](./examples/demo/research.md)
|
|
551
|
+
- [Cookbook](./examples/Cookbook.md)
|
|
552
|
+
- [Website Redesign Project](./examples/demo/project.md)
|
|
553
|
+
- [Task Management System](./examples/demo/tasks.md)
|
|
554
|
+
- [Cassini-Huygens Mission](./examples/demo/space-mission.md)
|
|
555
|
+
- [RDF Fundamentals](./examples/demo/rdf.md)
|
|
556
|
+
- [PROV-O Patterns](./examples/demo/prov.md)
|
|
557
|
+
- [SHACL Validation](./examples/demo/shacl.md)
|
|
558
|
+
- [XSD Datatypes](./examples/demo/xsd.md)
|
|
559
|
+
- [Status & SHACL Validation](./examples/Status-SHACL.md)
|
|
560
|
+
- [LLM Time Workflow](./examples/llm-time-workflow.md)
|
|
561
|
+
- [Research Workflow](./examples/workflow.md)
|
|
562
|
+
- [Dogfood](./examples/dogfood.md)
|
|
563
|
+
- **🧩 [Ontologies](./ontologies/index.md)** — W3C and related standard ontologies used in RDF
|
|
564
|
+
- [RDF — Resource Description Framework](./ontologies/rdf.md)
|
|
565
|
+
- [RDFS — RDF Schema](./ontologies/rdfs.md)
|
|
566
|
+
- [SHACL — Shapes Constraint Language](./ontologies/shacl.md)
|
|
567
|
+
- [PROV-O — W3C Provenance Ontology](./ontologies/prov-o.md)
|
|
568
|
+
- [XSD — XML Schema Definition Datatypes](./ontologies/xsd.md)
|
|
569
|
+
- [DCTERMS — Dublin Core Metadata Terms](./ontologies/dcterms.md)
|
|
570
|
+
- [DCAT — Data Catalog Vocabulary](./ontologies/dcat.md)
|
|
571
|
+
- [FOAF — Friend of a Friend](./ontologies/foaf.md)
|
|
572
|
+
- [VCard](./ontologies/vcard.md)
|
|
573
|
+
- [Time — OWL-Time Ontology](./ontologies/time.md)
|
|
574
|
+
- [Activity Streams 2.0](./ontologies/activity-streams-2.md)
|
|
575
|
+
- [SKOS — Simple Knowledge Organization System](./ontologies/skos.md)
|
|
576
|
+
- [Schema.org](./ontologies/schemaorg.md)
|
|
577
|
+
- [CIDOC CRM — Conceptual Reference Model](./ontologies/cidoc_crm.md)
|
|
578
|
+
- [SOSA — Sensor, Observation, Sample, and Actuator](./ontologies/sosa.md)
|
|
579
|
+
- [QUDT — Quantities, Units, Dimensions and Types](./ontologies/qudt.md)
|
|
580
|
+
- [GOLD — General Ontology for Linguistic Description](./ontologies/gold.md)
|
|
581
|
+
- [LexInfo — Lexical Information Ontology](./ontologies/lexinfo.md)
|
|
582
|
+
- [OWL — Web Ontology Language](./ontologies/owl.md)
|
|
583
|
+
- [P-PLAN — Plan Ontology](./ontologies/p-plan.md)
|
|
584
|
+
- [Hydra — Hypermedia API Vocabulary](./ontologies/hydra.md)
|
|
585
|
+
- [Web Annotations](./ontologies/web-annotations.md)
|
|
586
|
+
|
|
521
587
|
## Governance
|
|
522
588
|
|
|
523
589
|
MD-LD is a craft project. Its coherence comes from a single evolving understanding of how semantic text should work — not from consensus, but from sustained attention to the same problem over time.
|
|
@@ -532,12 +598,14 @@ This means:
|
|
|
532
598
|
|
|
533
599
|
## Licensing
|
|
534
600
|
|
|
535
|
-
MD-LD is published as copyrighted source material.
|
|
601
|
+
MD-LD is currently published as copyrighted source material.
|
|
602
|
+
|
|
603
|
+
The project is under active development and no open-source license has been selected yet.
|
|
536
604
|
|
|
537
|
-
|
|
605
|
+
Individuals, researchers, educators, and non-commercial users are welcome to experiment with the technology.
|
|
538
606
|
|
|
539
|
-
|
|
607
|
+
Organizations interested in production or commercial use should contact the author.
|
|
540
608
|
|
|
541
|
-
|
|
609
|
+
The long-term governance and licensing model remains under evaluation.
|
|
542
610
|
|
|
543
|
-
|
|
611
|
+
The primary goal at this stage is preserving the simplicity, interoperability, and long-term integrity of the system while the ecosystem forms around it.
|
package/dist/index.js
CHANGED
|
@@ -133,10 +133,12 @@ var DataFactory = {
|
|
|
133
133
|
let datatype = languageOrDataType ? languageOrDataType.value : "";
|
|
134
134
|
if (datatype === "") {
|
|
135
135
|
if (typeof value === "boolean") datatype = XSD_BOOLEAN;
|
|
136
|
-
else if (typeof value === "number")
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
else if (typeof value === "number") {
|
|
137
|
+
if (Number.isFinite(value)) datatype = Number.isInteger(value) ? XSD_INTEGER : XSD_DOUBLE;
|
|
138
|
+
else {
|
|
139
|
+
datatype = XSD_DOUBLE;
|
|
140
|
+
if (!Number.isNaN(value)) value = value > 0 ? "INF" : "-INF";
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
return datatype === "" || datatype === "http://www.w3.org/2001/XMLSchema#string" ? new Literal(`"${escapedValue}"`) : new Literal(`"${escapedValue}"^^${datatype}`);
|
|
@@ -773,9 +775,7 @@ function scanInlineCarriers(text, baseOffset = 0) {
|
|
|
773
775
|
case "_":
|
|
774
776
|
detected = detectEmphasis(text, pos);
|
|
775
777
|
break;
|
|
776
|
-
case "`":
|
|
777
|
-
detected = detectCodeSpan(text, pos);
|
|
778
|
-
break;
|
|
778
|
+
case "`": detected = detectCodeSpan(text, pos);
|
|
779
779
|
}
|
|
780
780
|
if (!detected) {
|
|
781
781
|
pos++;
|
|
@@ -1060,6 +1060,7 @@ function parse(firstArg, secondArg = {}) {
|
|
|
1060
1060
|
primarySubject: null,
|
|
1061
1061
|
primaryType: null,
|
|
1062
1062
|
primaryLabel: null,
|
|
1063
|
+
primaryComment: null,
|
|
1063
1064
|
tokens: null,
|
|
1064
1065
|
currentTokenIndex: -1,
|
|
1065
1066
|
statements: [],
|
|
@@ -1088,12 +1089,11 @@ function parse(firstArg, secondArg = {}) {
|
|
|
1088
1089
|
}
|
|
1089
1090
|
TOKEN_PROCESSORS[token.type]?.(token, state);
|
|
1090
1091
|
}
|
|
1091
|
-
|
|
1092
|
-
for (const quad of state.quads) quadKeys.add(quadIndexKey(quad.subject, quad.predicate, quad.object));
|
|
1092
|
+
state.quads = Array.from(state.quadBuffer.values());
|
|
1093
1093
|
const filteredRemove = [];
|
|
1094
1094
|
for (const quad of state.removeSet) {
|
|
1095
1095
|
const key = quadIndexKey(quad.subject, quad.predicate, quad.object);
|
|
1096
|
-
if (!
|
|
1096
|
+
if (!state.quadBuffer.has(key)) filteredRemove.push(quad);
|
|
1097
1097
|
}
|
|
1098
1098
|
const primary = {
|
|
1099
1099
|
subject: state.primarySubject,
|
|
@@ -1114,7 +1114,8 @@ function parse(firstArg, secondArg = {}) {
|
|
|
1114
1114
|
}
|
|
1115
1115
|
function getCarriers(token) {
|
|
1116
1116
|
if (token.type === "code") return [];
|
|
1117
|
-
|
|
1117
|
+
const baseOffset = token.valueRange ? token.valueRange[0] : token.range[0];
|
|
1118
|
+
return token._carriers || (token._carriers = extractInlineCarriers(token.text, baseOffset));
|
|
1118
1119
|
}
|
|
1119
1120
|
function scanTokens(text) {
|
|
1120
1121
|
const tokens = [];
|
|
@@ -1122,6 +1123,48 @@ function scanTokens(text) {
|
|
|
1122
1123
|
const lines = text.split("\n");
|
|
1123
1124
|
let pos = 0;
|
|
1124
1125
|
let codeBlock = null;
|
|
1126
|
+
let sfcBlock = null;
|
|
1127
|
+
function detectSfcStart(trimmed) {
|
|
1128
|
+
if (trimmed.startsWith("<!--")) return true;
|
|
1129
|
+
return /^<(script|style|template)\b/i.test(trimmed);
|
|
1130
|
+
}
|
|
1131
|
+
function checkSfcClose(line) {
|
|
1132
|
+
if (!sfcBlock) return;
|
|
1133
|
+
if (sfcBlock.tag === "comment") {
|
|
1134
|
+
if (line.includes("-->")) sfcBlock = null;
|
|
1135
|
+
} else if (sfcBlock.tag === "script" || sfcBlock.tag === "style") {
|
|
1136
|
+
if (new RegExp(`</\\s*${sfcBlock.tag}\\s*>`, "i").test(line)) sfcBlock = null;
|
|
1137
|
+
} else if (sfcBlock.tag === "template") {
|
|
1138
|
+
const openMatches = (line.match(/<template\b/gi) || []).length;
|
|
1139
|
+
const closeMatches = (line.match(/<\/template>/gi) || []).length;
|
|
1140
|
+
sfcBlock.depth += openMatches - closeMatches;
|
|
1141
|
+
if (sfcBlock.depth <= 0) sfcBlock = null;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
function handleSfcStart(line) {
|
|
1145
|
+
const trimmed = line.trim();
|
|
1146
|
+
if (trimmed.startsWith("<!--")) sfcBlock = {
|
|
1147
|
+
tag: "comment",
|
|
1148
|
+
depth: 1
|
|
1149
|
+
};
|
|
1150
|
+
else {
|
|
1151
|
+
const match = trimmed.match(/^<(script|style|template)\b/i);
|
|
1152
|
+
if (!match) return false;
|
|
1153
|
+
const tag = match[1].toLowerCase();
|
|
1154
|
+
sfcBlock = {
|
|
1155
|
+
tag,
|
|
1156
|
+
depth: tag === "template" ? 0 : 1
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
mdLines.push(line);
|
|
1160
|
+
checkSfcClose(line);
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
function handleSfcContent(line) {
|
|
1164
|
+
mdLines.push(line);
|
|
1165
|
+
checkSfcClose(line);
|
|
1166
|
+
return true;
|
|
1167
|
+
}
|
|
1125
1168
|
const PROCESSORS = [
|
|
1126
1169
|
{
|
|
1127
1170
|
type: "fence",
|
|
@@ -1129,10 +1172,20 @@ function scanTokens(text) {
|
|
|
1129
1172
|
process: handleFence
|
|
1130
1173
|
},
|
|
1131
1174
|
{
|
|
1132
|
-
type: "
|
|
1175
|
+
type: "codeContent",
|
|
1133
1176
|
test: () => codeBlock,
|
|
1134
1177
|
process: (line) => codeBlock.content.push(line)
|
|
1135
1178
|
},
|
|
1179
|
+
{
|
|
1180
|
+
type: "sfcContent",
|
|
1181
|
+
test: () => sfcBlock,
|
|
1182
|
+
process: handleSfcContent
|
|
1183
|
+
},
|
|
1184
|
+
{
|
|
1185
|
+
type: "sfcStart",
|
|
1186
|
+
test: (line) => detectSfcStart(line.trim()),
|
|
1187
|
+
process: handleSfcStart
|
|
1188
|
+
},
|
|
1136
1189
|
{
|
|
1137
1190
|
type: "prefix",
|
|
1138
1191
|
test: (line) => detectPrefix(line),
|
|
@@ -1192,7 +1245,7 @@ function scanTokens(text) {
|
|
|
1192
1245
|
const valueEnd = Math.max(valueStart, lineStart - 1);
|
|
1193
1246
|
tokens.push({
|
|
1194
1247
|
type: "code",
|
|
1195
|
-
range: [codeBlock.start,
|
|
1248
|
+
range: [codeBlock.start, pos - 1],
|
|
1196
1249
|
text: codeBlock.content.join("\n"),
|
|
1197
1250
|
lang: codeBlock.lang,
|
|
1198
1251
|
attrs: codeBlock.attrs,
|
|
@@ -1252,17 +1305,38 @@ function scanTokens(text) {
|
|
|
1252
1305
|
return true;
|
|
1253
1306
|
}
|
|
1254
1307
|
function handlePara(line, lineStart, pos) {
|
|
1255
|
-
|
|
1308
|
+
const leadingWhitespace = line.search(/\S/);
|
|
1309
|
+
const valueStart = leadingWhitespace === -1 ? lineStart : lineStart + leadingWhitespace;
|
|
1310
|
+
const trimmed = line.trim();
|
|
1311
|
+
const valueEnd = valueStart + trimmed.length;
|
|
1312
|
+
tokens.push(createToken("para", [lineStart, pos - 1], trimmed, null, null, [valueStart, valueEnd]));
|
|
1256
1313
|
let cleanPara = line;
|
|
1314
|
+
const codeSpans = [];
|
|
1315
|
+
cleanPara = cleanPara.replace(/`[^`]+`/g, (match) => {
|
|
1316
|
+
codeSpans.push(match);
|
|
1317
|
+
return `__INLINE_CODE_${codeSpans.length - 1}__`;
|
|
1318
|
+
});
|
|
1319
|
+
const mustaches = [];
|
|
1320
|
+
cleanPara = cleanPara.replace(/\{\{(?:[^{}]|\{[^{}]*\})*\}\}/g, (match) => {
|
|
1321
|
+
mustaches.push(match);
|
|
1322
|
+
return `__VUE_INTERPOLATION_${mustaches.length - 1}__`;
|
|
1323
|
+
});
|
|
1257
1324
|
const carriers = scanInlineCarriers(cleanPara, 0);
|
|
1258
|
-
for (
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
|
|
1325
|
+
for (let i = carriers.length - 1; i >= 0; i--) {
|
|
1326
|
+
const carrier = carriers[i];
|
|
1327
|
+
if (carrier.attrs && (carrier.type === "emphasis" || carrier.type === "code")) {
|
|
1328
|
+
const before = cleanPara.substring(0, carrier.range[0]);
|
|
1329
|
+
const after = cleanPara.substring(carrier.range[1]);
|
|
1330
|
+
cleanPara = before + (carrier.text || "") + after;
|
|
1331
|
+
}
|
|
1262
1332
|
}
|
|
1263
1333
|
cleanPara = cleanPara.replace(/\[([^\]]+)\]\s*\{[^}]+\}/g, "$1");
|
|
1264
|
-
cleanPara = cleanPara.replace(
|
|
1265
|
-
cleanPara = cleanPara.replace(
|
|
1334
|
+
cleanPara = cleanPara.replace(/([^{]|^)\{[^{}]+\}(?=[^}]|$)/g, "$1");
|
|
1335
|
+
cleanPara = cleanPara.replace(/__VUE_INTERPOLATION_(\d+)__/g, (_, idx) => mustaches[Number(idx)]);
|
|
1336
|
+
cleanPara = cleanPara.replace(/__INLINE_CODE_(\d+)__/g, (_, idx) => codeSpans[Number(idx)]);
|
|
1337
|
+
const trailingSpaces = cleanPara.match(/ {2,}$/);
|
|
1338
|
+
if (trailingSpaces) cleanPara = cleanPara.replace(/[ \t]+$/, trailingSpaces[0]);
|
|
1339
|
+
else cleanPara = cleanPara.replace(/[ \t]+$/, "");
|
|
1266
1340
|
mdLines.push(cleanPara);
|
|
1267
1341
|
return true;
|
|
1268
1342
|
}
|
|
@@ -1448,33 +1522,35 @@ function createBlock(subject, types, predicates, range, attrsRange, valueRange,
|
|
|
1448
1522
|
text: text || ""
|
|
1449
1523
|
};
|
|
1450
1524
|
}
|
|
1451
|
-
|
|
1525
|
+
/**
|
|
1526
|
+
* Hardened O(1) quad emitter.
|
|
1527
|
+
* Uses state.quadBuffer (Map) as single source of truth during parsing.
|
|
1528
|
+
*/
|
|
1529
|
+
function emitQuad(state, block, subject, predicate, object, meta = null) {
|
|
1452
1530
|
if (!subject || !predicate || !object) return;
|
|
1453
|
-
const
|
|
1454
|
-
if (meta?.remove
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
} else removeSet.add(quad);
|
|
1462
|
-
} else {
|
|
1463
|
-
const quadKey = quadIndexKey(quad.subject, quad.predicate, quad.object);
|
|
1464
|
-
quadBuffer.set(quadKey, quad);
|
|
1465
|
-
quads.push(quad);
|
|
1466
|
-
if (state) {
|
|
1467
|
-
if (!state.primaryType && predicate.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") state.primaryType = object.value;
|
|
1468
|
-
if (!state.primaryLabel && predicate.value === "http://www.w3.org/2000/01/rdf-schema#label" && object.termType === "Literal") state.primaryLabel = object.value;
|
|
1469
|
-
if (!state.primaryComment && predicate.value === "http://www.w3.org/2000/01/rdf-schema#comment" && object.termType === "Literal") state.primaryComment = object.value;
|
|
1470
|
-
}
|
|
1471
|
-
detectStatementPatternSinglePass(quad, dataFactory, meta, statements, statementCandidates);
|
|
1472
|
-
const originEntry = createLeanOriginEntry(block, subject, predicate, meta);
|
|
1473
|
-
quadIndex.set(quadKey, originEntry);
|
|
1474
|
-
if (state.currentBlock && block.id === state.currentBlock.id) {
|
|
1475
|
-
if (!state.currentBlock.quadKeys) state.currentBlock.quadKeys = [];
|
|
1476
|
-
state.currentBlock.quadKeys.push(quadKey);
|
|
1531
|
+
const quadKey = quadIndexKey(subject, predicate, object);
|
|
1532
|
+
if (Boolean(meta?.remove)) {
|
|
1533
|
+
if (state.quadBuffer.has(quadKey)) {
|
|
1534
|
+
state.quadBuffer.delete(quadKey);
|
|
1535
|
+
state.origin.quadIndex.delete(quadKey);
|
|
1536
|
+
} else {
|
|
1537
|
+
const retractQuad = state.df.quad(subject, predicate, object, state.graph);
|
|
1538
|
+
state.removeSet.add(retractQuad);
|
|
1477
1539
|
}
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
const quad = state.df.quad(subject, predicate, object, state.graph);
|
|
1543
|
+
state.quadBuffer.set(quadKey, quad);
|
|
1544
|
+
const predVal = predicate.value;
|
|
1545
|
+
if (!state.primaryType && predVal === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") state.primaryType = object.value;
|
|
1546
|
+
else if (!state.primaryLabel && predVal === "http://www.w3.org/2000/01/rdf-schema#label" && object.termType === "Literal") state.primaryLabel = object.value;
|
|
1547
|
+
else if (!state.primaryComment && predVal === "http://www.w3.org/2000/01/rdf-schema#comment" && object.termType === "Literal") state.primaryComment = object.value;
|
|
1548
|
+
if (state.statements && state.statementCandidates) detectStatementPatternSinglePass(quad, state.df, meta, state.statements, state.statementCandidates);
|
|
1549
|
+
const originEntry = createLeanOriginEntry(block, subject, predicate, meta);
|
|
1550
|
+
state.origin.quadIndex.set(quadKey, originEntry);
|
|
1551
|
+
if (block && state.currentBlock && block.id === state.currentBlock.id) {
|
|
1552
|
+
if (!state.currentBlock.quadKeys) state.currentBlock.quadKeys = [];
|
|
1553
|
+
state.currentBlock.quadKeys.push(quadKey);
|
|
1478
1554
|
}
|
|
1479
1555
|
}
|
|
1480
1556
|
function detectStatementPatternSinglePass(quad, dataFactory, meta, statements = null, statementCandidates = null) {
|
|
@@ -1505,13 +1581,13 @@ var createTypeQuad = (typeIRI, subject, state, block, entryIndex = null) => {
|
|
|
1505
1581
|
entryIndex,
|
|
1506
1582
|
remove: false
|
|
1507
1583
|
};
|
|
1508
|
-
emitQuad(state
|
|
1584
|
+
emitQuad(state, block, subject, state.df.namedNode(expandIRI("rdf:type", state.ctx)), state.df.namedNode(expandedType), {
|
|
1509
1585
|
kind: "type",
|
|
1510
1586
|
token: `.${typeIRI}`,
|
|
1511
1587
|
expandedType,
|
|
1512
1588
|
entryIndex: typeInfo.entryIndex,
|
|
1513
1589
|
remove: typeInfo.remove
|
|
1514
|
-
}
|
|
1590
|
+
});
|
|
1515
1591
|
};
|
|
1516
1592
|
function processTypeAnnotations(sem, newSubject, localObject, carrierO, S, block, state, carrier) {
|
|
1517
1593
|
sem.types.forEach((t) => {
|
|
@@ -1550,14 +1626,14 @@ function processPredicateAnnotations(sem, newSubject, previousSubject, localObje
|
|
|
1550
1626
|
const role = determinePredicateRole(pred, carrier, newSubject, previousSubject, localObject, newSubjectOrCarrierO, S, L);
|
|
1551
1627
|
if (role) {
|
|
1552
1628
|
const P = state.df.namedNode(expandIRI(pred.iri, state.ctx));
|
|
1553
|
-
emitQuad(state
|
|
1629
|
+
emitQuad(state, block, role.subject, P, role.object, {
|
|
1554
1630
|
kind: "pred",
|
|
1555
1631
|
token: `${pred.form}${pred.iri}`,
|
|
1556
1632
|
form: pred.form,
|
|
1557
1633
|
expandedPredicate: P.value,
|
|
1558
1634
|
entryIndex: pred.entryIndex,
|
|
1559
1635
|
remove: pred.remove || false
|
|
1560
|
-
}
|
|
1636
|
+
});
|
|
1561
1637
|
}
|
|
1562
1638
|
});
|
|
1563
1639
|
}
|
|
@@ -1584,11 +1660,12 @@ function processStandaloneSubject(token, state) {
|
|
|
1584
1660
|
if (!result) return;
|
|
1585
1661
|
const sem = parseSemCached(`{=${result.content}}`);
|
|
1586
1662
|
const attrsStart = token.range[0] + token.text.indexOf("{=");
|
|
1663
|
+
const fullAttrLength = 3 + (result.content ? result.content.length : 0);
|
|
1587
1664
|
processAnnotation({
|
|
1588
1665
|
type: "standalone",
|
|
1589
1666
|
text: "",
|
|
1590
1667
|
range: token.range,
|
|
1591
|
-
attrsRange: [attrsStart, attrsStart +
|
|
1668
|
+
attrsRange: [attrsStart, attrsStart + fullAttrLength],
|
|
1592
1669
|
valueRange: null
|
|
1593
1670
|
}, sem, state);
|
|
1594
1671
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdld-parse",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Write RDF knowledge graphs as plain Markdown. Parse to quads, generate back, merge documents. The human-friendly semantic web format.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rdf",
|
|
7
|
+
"linked-data",
|
|
8
|
+
"semantic-web",
|
|
9
|
+
"knowledge-graph",
|
|
10
|
+
"markdown",
|
|
11
|
+
"semantic-annotations",
|
|
12
|
+
"provenance",
|
|
13
|
+
"prov-o",
|
|
14
|
+
"shacl",
|
|
15
|
+
"agent-memory",
|
|
16
|
+
"llm",
|
|
17
|
+
"md-ld",
|
|
18
|
+
"mdld",
|
|
19
|
+
"semantic-markdown",
|
|
20
|
+
"quad-store",
|
|
21
|
+
"crdt",
|
|
22
|
+
"rdfs",
|
|
23
|
+
"ontology",
|
|
24
|
+
"triple-store"
|
|
25
|
+
],
|
|
5
26
|
"type": "module",
|
|
6
|
-
"packageManager": "pnpm@
|
|
27
|
+
"packageManager": "pnpm@11.24.0+sha512.bd27e345e976dcb0be0b7a1228217b049a817e21b1f355c90dbe7dc46671895a8bc1e6d06c24554505ea93ea0b45f489a27ec1bfbc8de6a9659fca0f16fa0000",
|
|
7
28
|
"main": "./dist/index.js",
|
|
8
29
|
"exports": {
|
|
9
30
|
".": "./dist/index.js"
|
|
@@ -16,21 +37,6 @@
|
|
|
16
37
|
"dev": "vite dev",
|
|
17
38
|
"build": "vite build && vite build --config vite.config.lib.js && cp -r docs/ dist/docs/ && cp -r examples/ dist/examples/ && cp -r grammar/ dist/grammar/ && cp -r ontologies/ dist/ontologies/ && cp -r spec/ dist/spec/ && cp -r README.md dist/README.md && cp -r docs.html dist/docs.html && cp -r demo/ dist/demo/"
|
|
18
39
|
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"mdld",
|
|
21
|
-
"markdown",
|
|
22
|
-
"rdf",
|
|
23
|
-
"semantic-web",
|
|
24
|
-
"linked-data",
|
|
25
|
-
"n3",
|
|
26
|
-
"rdfjs",
|
|
27
|
-
"browser",
|
|
28
|
-
"web-worker",
|
|
29
|
-
"parser",
|
|
30
|
-
"prefix-folding",
|
|
31
|
-
"curie",
|
|
32
|
-
"iri-authoring"
|
|
33
|
-
],
|
|
34
40
|
"author": "davay42",
|
|
35
41
|
"repository": {
|
|
36
42
|
"type": "git",
|
|
@@ -41,17 +47,17 @@
|
|
|
41
47
|
"url": "https://github.com/davay42/mdld-parse/issues"
|
|
42
48
|
},
|
|
43
49
|
"devDependencies": {
|
|
44
|
-
"@unocss/extractor-pug": "^66.
|
|
45
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
46
|
-
"@vueuse/core": "^14.
|
|
50
|
+
"@unocss/extractor-pug": "^66.8.1",
|
|
51
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
52
|
+
"@vueuse/core": "^14.4.0",
|
|
47
53
|
"codejar": "^4.3.0",
|
|
48
|
-
"markdown-it": "^
|
|
49
|
-
"n3": "^2.0
|
|
50
|
-
"shiki": "^4.
|
|
51
|
-
"unocss": "^66.
|
|
52
|
-
"vite": "^8.
|
|
54
|
+
"markdown-it": "^15.0.0",
|
|
55
|
+
"n3": "^2.6.0",
|
|
56
|
+
"shiki": "^4.4.3",
|
|
57
|
+
"unocss": "^66.8.1",
|
|
58
|
+
"vite": "^8.2.2",
|
|
53
59
|
"vite-plugin-singlefile": "^2.3.3",
|
|
54
60
|
"vscode-textmate": "^9.3.2",
|
|
55
|
-
"vue": "^3.6.0-beta.
|
|
61
|
+
"vue": "^3.6.0-beta.17"
|
|
56
62
|
}
|
|
57
|
-
}
|
|
63
|
+
}
|