# HG changeset patch # User drewp@bigasterisk.com # Date 1576442291 28800 # Node ID c751380b70c57248cbdd999962682540e7fef858 # Parent e0f5da648199bf02add78ae9024f135d319b9b9e uniqueness problem with NamedNodes in set diff -r e0f5da648199 -r c751380b70c5 src/graph_view.ts --- a/src/graph_view.ts Fri Dec 13 23:53:56 2019 -0800 +++ b/src/graph_view.ts Sun Dec 15 12:38:11 2019 -0800 @@ -11,24 +11,36 @@ type TypeToSubjs = Map>; function groupByRdfType(graph: N3Store): { byType: TypeToSubjs, untyped: Set } { const rdfType = namedNode(rdf.type); - const byType: TypeToSubjs = new Map(); // type : subjs + const byType: TypeToSubjs = new Map(); const untyped: Set = new Set(); // subjs + const internSubjs = new Map(); graph.forEach((q) => { + if (!Util.isNamedNode(q.subject)) { + throw new Error("unsupported " + q.subject.value); + } + const subj = q.subject as NamedNode; + let subjType: NamedNode | null = null; graph.forObjects((o: Quad) => { if (Util.isNamedNode(o.object)) { subjType = o.object as NamedNode; } - }, q.subject, rdfType, null); + }, subj, rdfType, null); if (subjType !== null) { + // (subj, rdf:type, subjType) in graph if (!byType.has(subjType)) { byType.set(subjType, new Set()); } - (byType.get(subjType) as Set).add(q.subject as NamedNode); + (byType.get(subjType) as Set).add(subj); } else { - untyped.add(q.subject as NamedNode); + // no rdf:type stmt in graph + if (!internSubjs.has(subj.value)) { + internSubjs.set(subj.value, subj); + } + const intSubj: NamedNode = internSubjs.get(subj.value as string) as NamedNode; + untyped.add(intSubj); } }, null, null, null, null); return { byType: byType, untyped: untyped }; @@ -52,18 +64,31 @@ return html`${n.value}${dtPart}`; } - if (n.termType == "NamedNode") { - let dn: string | undefined = this.labels.getLabelForNode(n.value); - if (dn === undefined) { - throw new Error(`dn=${dn}`); + if (n.termType == "NamedNode") { + let shortened = false; + let uriValue: string = n.value; + for (let [long, short] of [ + ["http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:"], + ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"], + ["http://purl.org/dc/elements/1.1/", "dc:"], + ["http://www.w3.org/2001/XMLSchema#", "xsd:"]]) { + if (uriValue?.startsWith(long)) { + uriValue = short + uriValue.substr(long.length); + shortened = true; + break; + } } - if (dn!.match(/XMLSchema#.*/)) { - dn = dn!.replace('XMLSchema#', 'xsd:'); + if (!shortened) { + + let dn: string | undefined = this.labels.getLabelForNode(uriValue); + if (dn === undefined) { + throw new Error(`dn=${dn}`); + } + uriValue = dn; } - if (dn!.match(/rdf-schema#.*/)) { - dn = dn!.replace('rdf-schema#', 'rdfs:'); - } - return html`${dn}`; + + + return html`${uriValue}`; } return html`[${n.termType} ${n.value}]`; diff -r e0f5da648199 -r c751380b70c5 src/suffixLabels.ts --- a/src/suffixLabels.ts Fri Dec 13 23:53:56 2019 -0800 +++ b/src/suffixLabels.ts Sun Dec 15 12:38:11 2019 -0800 @@ -62,6 +62,7 @@ } + // a substring to show for this uri getLabelForNode(node: string) { return this.displayNodes.get(node)!.label; }