Skip to content

Commit aaa0abc

Browse files
committed
fix: labels were not abbreviated with the use of prefixes
1 parent 0472907 commit aaa0abc

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/GraphPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class GraphPlugin {
7575
return;
7676
}
7777

78-
// Extract prefixes
79-
const prefixMap = extractPrefixes(this.yasr.results);
78+
// Extract prefixes (pass both results and yasr instance)
79+
const prefixMap = extractPrefixes(this.yasr);
8080

8181
// Transform triples to graph data
8282
const { nodes, edges } = triplesToGraph(triples, prefixMap);

src/prefixUtils.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
/**
2-
* Extract namespace prefixes from SPARQL results metadata
2+
* Extract namespace prefixes from SPARQL results metadata or YASR instance
33
* @param {Object} yasrResults - YASR results object
4+
* @param {Object} yasr - YASR instance (optional)
45
* @returns {Map<string, string>} Map of namespace URI to prefix
56
*/
6-
function extractPrefixes(yasrResults) {
7+
function extractPrefixes(yasr) {
78
const prefixMap = new Map();
89

9-
// Check for prefixes in results metadata
10-
if (yasrResults && yasrResults.getVariables) {
11-
const vars = yasrResults.getVariables();
12-
if (vars && vars.prefixes) {
13-
Object.entries(vars.prefixes).forEach(([prefix, uri]) => {
14-
prefixMap.set(uri, prefix);
10+
// Try to get prefixes from YASR instance
11+
if (yasr && yasr.getPrefixes) {
12+
const prefixes = yasr.getPrefixes();
13+
if (prefixes && typeof prefixes === 'object') {
14+
Object.entries(prefixes).forEach(([prefix, uri]) => {
15+
if (uri && prefix) {
16+
prefixMap.set(uri, prefix);
17+
}
1518
});
1619
}
17-
}
20+
}
1821

1922
// Add common RDF prefixes as fallback
2023
const commonPrefixes = {

0 commit comments

Comments
 (0)