-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.hito.ts
132 lines (128 loc) · 4.71 KB
/
config.hito.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import hitoView from "./initialView/hito.json" assert { type: "json" };
import { NODE } from "../node";
import type { NodeSingular } from "cytoscape";
let shapeMap: Map<string, string> = new Map([
["Citation", "rectangle"],
["Classified", "ellipse"],
["Catalogue", "triangle"],
]);
const colorMap = new Map([
["UserGroup", "grey"],
["Feature", "green"],
["EnterpriseFunction", "yellow"],
["ApplicationSystemType", "red"],
["OrganizationalUnit", "blue"],
]);
/**
* Finds the first key of the map included in the search string.
* @param search String in which to search for keys
* @param map Map whose keys to use
* @returns The first key found which the string includes
*/
function getMapKeyIncludedInString<V>(search: string, map: Map<string, V>): string | undefined {
for (const key of map.keys()) {
if (search.includes(key)) {
return key;
}
}
return undefined;
}
export default {
id: "hito",
name: "HITO",
initialView: hitoView,
snik: null,
style: {
/**
* Finds out which shape to use for any specific node using a map (Citation => rectangle, Classified => ellipse, Catalogue => triangle).
* If the node contains any of these words, use the shape.
* If the node B contains any of these words and is the rdf:type of node A, then node A also has this shape.
* If none of this is true, then the node will be a hexagon.
* @param node Node which should have this shape when displayed
* @returns A string containing a code for a shape ("rectangle", "ellipse" or "triangle")
*/
shape: (node: NodeSingular) =>
shapeMap.get(getMapKeyIncludedInString(node.data(NODE.ID), shapeMap)) ||
shapeMap.get(
// get shape of parent (node rdf:type parent)
getMapKeyIncludedInString(node.outgoers("[p='http://www.w3.org/1999/02/22-rdf-syntax-ns#type']").targets().first()?.data(NODE.ID) || "", shapeMap)
) ||
"hexagon",
/**
* Finds out which shape to use for any specific node using a map.
* If the node contains any of the keys in the map, use this color.
* If the node B contains any of these words and is the rdf:type of node A, then node A also has this shape.
* If none of this is true, then the node will be orange.
* @param node Node which should have this colour when displayed (as a NodeSingular cytoscape.js object) OR id of parent of the node (as a string)
* @returns A string containing a name of a color
*/
color: (node: string | NodeSingular) =>
colorMap.get(getMapKeyIncludedInString(typeof node === "string" ? node : node.data(NODE.ID), colorMap)) ||
(typeof node === "object" && // verify that node is object
"outgoers" in node && // verify that node is NodeSingular
colorMap.get(
// get color of parent (node rdf:type parent)
getMapKeyIncludedInString(node.outgoers("[p='http://www.w3.org/1999/02/22-rdf-syntax-ns#type']").targets().first()?.data(NODE.ID) || "", colorMap)
)) ||
"orange",
colorMap: colorMap,
},
sparql: {
// without trailing slashes!
endpoint: "https://hitontology.eu/sparql",
graph: "http://hitontology.eu/ontology",
instances: true,
queries: {
//
/**
* Get SPARQL Query which loads the list of nodes from which all triples are formed.
* Only nodes with labels which are an owl:Class and their instances are loaded.
* @param from "FROM ..." SPARQL clause
* @returns A string containing a SPARQL query which still needs to be executed
*/
nodes: (from: string): string => `
PREFIX ov: <http://open.vocab.org/terms/>
SELECT DISTINCT(?c)
GROUP_CONCAT(DISTINCT(CONCAT(?l,"@",lang(?l)));separator="|") AS ?l
SAMPLE(?st) AS ?st
SAMPLE(?inst) AS ?inst
?src
${from}
{
?c rdfs:label ?l.
?c a owl:Class.
OPTIONAL {?inst a ?c.}
OPTIONAL {?src ov:defines ?c.}
OPTIONAL {?c rdf:type ?st. FILTER(?st!=owl:Class)}
}
`,
/**
* Loads all triples from HITO which we display.
* @param from "FROM ..." SPARQL clause
* @param fromNamed "FROM NAMED ..." SPARQL clause
* @param virtualTriples (ignored here)
* @param instances Whether or not to include instances in the fetched triples. Highly recommended for HITO.
* @returns A string containing a SPARQL query which still needs to be executed
*/
triples: (from: string, fromNamed: string, virtualTriples: boolean, instances: boolean): string => `
select ?c ?p ?d ?g (MIN(?ax) as ?ax)
${from}
${fromNamed}
{
{?c a owl:Class.} ${instances ? " UNION {?c a [a owl:Class].}" : ""}
{?d a owl:Class.} ${instances ? " UNION {?d a [a owl:Class].}" : ""}
{
?p rdfs:domain ?c.
?p rdfs:range ?d.
FILTER(CONTAINS(STR(?c),"hitontology.eu"))
FILTER(CONTAINS(STR(?d),"hitontology.eu"))
}
UNION
{
graph ?g {?c ?p ?d.}
filter(?p!=owl:equivalentClass)
}
}`,
},
},
};