Skip to content

Commit 0be1604

Browse files
committed
feat: Be able to see HITOs relations
1 parent d999aa9 commit 0be1604

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

js/config.dist.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export const config = {
3939
graph: "http://www.snik.eu/ontology",
4040
instances: false,
4141
isSnik: true,
42+
// How to identify relations to display
43+
// A SPARQL query is run:
44+
// (a) ... { ?c ?r ?d } { ?c a owl:Class } { ?d a owl:Class }
45+
// (b) ... { ?c ?r ?d } { ?c xx:someIdVal ?x } { ?d xx:someIdVal ?y }
46+
// Either value "owl:class" for option (a) or an id (e.g. "hito:internalId" or "https://hitontology.eu/ontology/internalId") for option (b)
47+
// For SNIK and probably many others (like DBPedia), this should be "a owl:Class". For HITO this should be "hito:internalId".
48+
classId: "a owl:Class",
4249
},
4350
multiview: {
4451
initialTabs: 1,

js/loadGraphFromSparql.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,37 @@ async function createInstanceNodes(from: string): Promise<Array<object>> {
169169
* @returns SPARQL query result object
170170
*/
171171
async function selectTriples(from: string, fromNamed: string, instances: boolean, virtual: boolean): Promise<Array<object>> {
172+
let idA, idB, idC, idD;
173+
const isValidHttpUrl = (str) => {
174+
// https://stackoverflow.com/a/43467144
175+
let url;
176+
177+
try {
178+
url = new URL(str);
179+
} catch (_) {
180+
return false;
181+
}
182+
return url.protocol === "http:" || url.protocol === "https:";
183+
};
184+
if (config.sparql.classId === "a owl:Class") {
185+
idA = config.sparql.classId;
186+
idB = config.sparql.classId;
187+
idC = config.sparql.classId;
188+
idD = config.sparql.classId;
189+
} else if (isValidHttpUrl(config.sparql.classId) || /^\w+:\w+$/.test(config.sparql.classId)) {
190+
idA = config.sparql.classId + " ?x";
191+
idB = config.sparql.classId + " ?y";
192+
idC = idA + 1;
193+
idD = idB + 1;
194+
}
172195
const sparqlPropertiesTimer = timer("sparql-properties");
173196
const tripleQuerySimple = `
174197
select ?c ?p ?d
175198
${from}
176199
{
177200
{?c ?p ?d.} ${virtual ? " UNION {?p rdfs:domain ?c; rdfs:range ?d.}" : ""}
178-
{?c a owl:Class.} ${instances ? " UNION {?c a [a owl:Class]}" : ""}
179-
{?d a owl:Class.} ${instances ? " UNION {?d a [a owl:Class]}" : ""}
201+
{?c ${idA}.} ${instances ? ` UNION {?c a [${idC}]}` : ""}
202+
{?d ${idB}.} ${instances ? ` UNION {?d a [${idD}}` : ""}
180203
}`;
181204
// the optional part should be a union
182205
const tripleQuerySnik = `PREFIX sniko: <http://www.snik.eu/ontology/>

0 commit comments

Comments
 (0)