Commit fe77b4d4 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

[fix] Use equivalent URIs for aliases lookup

parent 476696cc137a
......@@ -19,6 +19,7 @@
******************************************************************************/
import * as $rdf from "rdflib";
import { uriEscape, uriUnescape } from "./uris";
/**
* A single RDF entity that may have aliases
......@@ -316,31 +317,42 @@ export class RdfEntityStore {
let nodes: $rdf.NamedNode[] = [];
uris.push(entity.uris[0]);
nodes.push(entity.aliases[0]);
let onNamedNode = (named: $rdf.NamedNode) => {
if (uris.indexOf(named.uri) >= 0) return;
uris.push(named.uri);
nodes.push(named);
entity.addAlias(named);
this.entities[named.uri] = entity;
};
let onUri = (uri: string) => {
if (uris.indexOf(uri) >= 0) return;
let named = this.sym(uri);
uris.push(named.uri);
nodes.push(named);
entity.addAlias(named);
this.entities[uri] = entity;
};
for (var i = 0; i != uris.length; i++) {
let others = this.store.each(nodes[i], sameas, undefined, undefined);
others.forEach((other: $rdf.Node) => {
if (other.termType == "NamedNode") {
let named = other as $rdf.NamedNode;
if (uris.indexOf(named.uri) < 0) {
named = this.sym(named.uri);
uris.push(named.uri);
nodes.push(named);
entity.addAlias(named);
this.entities[named.uri] = entity;
}
}
});
let others2 = this.aliases[uris[i]];
if (others2 != null && others2 != undefined) {
others2.forEach((alias: string) => {
if (uris.indexOf(alias) >= 0) return;
let named = this.sym(alias);
uris.push(named.uri);
nodes.push(named);
entity.addAlias(named);
this.entities[named.uri] = entity;
});
// look for (node, sameAs, x)
this.store
.each(nodes[i], sameas, undefined, undefined)
.filter((n: $rdf.Node) => n.termType == "NamedNode")
.forEach(onNamedNode);
// look for (x, sameAs, node)
this.store
.each(undefined, sameas, nodes[i], undefined)
.filter((n: $rdf.Node) => n.termType == "NamedNode")
.forEach(onNamedNode);
// look for registered aliases for this uri
let registered_aliases = this.aliases[uris[i]];
if (registered_aliases != null && registered_aliases != undefined) {
registered_aliases.forEach(onUri);
}
// look for equivalent URIs
onUri(uriEscape(uris[i]));
onUri(uriUnescape(uris[i]));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment