mdld-parse 0.8.2 → 0.8.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdld-parse",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
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/generate.js CHANGED
@@ -90,6 +90,9 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null) {
90
90
  let text = '';
91
91
  const usedPrefixes = collectUsedPrefixes(subjectGroups, context);
92
92
 
93
+ // Build label lookup map for all IRIs that have rdfs:label
94
+ const labelLookup = buildLabelLookup(subjectGroups);
95
+
93
96
  // Add prefixes first (deterministic order), but exclude default context prefixes
94
97
  const sortedPrefixes = Object.entries(context).sort(([a], [b]) => a.localeCompare(b));
95
98
  for (const [prefix, namespace] of sortedPrefixes) {
@@ -133,7 +136,7 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null) {
133
136
  });
134
137
 
135
138
  sortQuadsByPredicate(objects).forEach(quad => {
136
- text += generateObjectText(quad, context);
139
+ text += generateObjectText(quad, context, labelLookup);
137
140
  });
138
141
 
139
142
  text += '\n';
@@ -141,3 +144,18 @@ function buildDeterministicMDLD(subjectGroups, context, primarySubject = null) {
141
144
 
142
145
  return { text };
143
146
  }
147
+
148
+ function buildLabelLookup(subjectGroups) {
149
+ const labelLookup = new Map();
150
+ const rdfsLabelIRI = 'http://www.w3.org/2000/01/rdf-schema#label';
151
+
152
+ for (const subjectQuads of subjectGroups.values()) {
153
+ for (const quad of subjectQuads) {
154
+ if (quad.predicate.value === rdfsLabelIRI && quad.object.termType === 'Literal') {
155
+ labelLookup.set(quad.subject.value, quad.object.value);
156
+ }
157
+ }
158
+ }
159
+
160
+ return labelLookup;
161
+ }
package/src/shared.js CHANGED
@@ -428,10 +428,16 @@ export function generateLiteralText(quad, context) {
428
428
  return `[${quad.object.value}] {${annotation}}\n`;
429
429
  }
430
430
 
431
- export const generateObjectText = (quad, context) => {
431
+ export const generateObjectText = (quad, context, labelLookup = null) => {
432
432
  const objShort = shortenIRI(quad.object.value, context);
433
433
  const predShort = shortenIRI(quad.predicate.value, context);
434
- return `[${objShort}] {+${objShort} ?${predShort}}\n`;
434
+
435
+ // Use rdfs:label if available, otherwise use shortened IRI
436
+ const displayText = labelLookup && labelLookup.has(quad.object.value)
437
+ ? labelLookup.get(quad.object.value)
438
+ : objShort;
439
+
440
+ return `[${displayText}] {+${objShort} ?${predShort}}\n`;
435
441
  };
436
442
 
437
443
  // Optimized quad filtering - destructuring for smaller minified output