-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertToOWL.groovy
81 lines (76 loc) · 2.67 KB
/
convertToOWL.groovy
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
// input
parser = new groovy.json.JsonSlurper();
def termList = parser.parse(new File("blueprint_20210928.json"))
// output (just to STDOUT for now)
println """<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.bigcat.unimaas.nl/sbd4nano/gracious.owl#"
xml:base="http://www.bigcat.unimaas.nl/sbd4nano/gracious.owl"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Ontology rdf:about="http://www.bigcat.unimaas.nl/sbd4nano/gracious.owl">
</owl:Ontology>
"""
// endpoints
int counter = 0
for (kb in termList.knowledgebases) {
if (kb.name == "ENDPOINT_KB" || kb.name == "IATA_KB") {
for (category in kb.enumerations) {
cathName = category.name
if (category.id != null) {
cathID = category.id
} else {
counter++;
cathID = (""+counter).padLeft(8,'0')
}
cathIRI = "https://h2020-sbd4nano.github.io/sbd4nano-gracious-owl/gracious.html#${cathID}"
sameAsIRI = "https://h2020-sbd4nano.github.io/gracious-blueprint/2021/${cathName}"
if (category.note != null) {
note = category.note.trim().replaceAll("<", "<")
cathDescription = """
<obo:IAO_0000115>${note}</obo:IAO_0000115>"""
} else {
cathDescription = ""
}
println """
<owl:Class rdf:about="${cathIRI}">
<rdfs:label xml:lang="en">${cathName}</rdfs:label>${cathDescription}
<owl:sameAs rdf:resource="${sameAsIRI}"/>
</owl:Class>
"""
for (ep in category.enumerates) {
epName = ep.name
if (ep.id != null) {
epID = ep.id
} else {
counter++;
epID = (""+counter).padLeft(8,'0')
}
epIRI = "https://h2020-sbd4nano.github.io/sbd4nano-gracious-owl/gracious.html#${epID}"
epSameAsIRI = "https://h2020-sbd4nano.github.io/gracious-blueprint/2021/${epName}"
if (ep.note != null) {
if (ep.note instanceof String) {
note = ep.note.trim().replaceAll("<", "<").replaceAll("&", "&")
} else {
note = ep.note.definition.text.trim().replaceAll("<", "<").replaceAll("&", "&")
}
epDescription = """
<obo:IAO_0000115>${note}</obo:IAO_0000115>"""
} else {
epDescription = ""
}
println """
<owl:Class rdf:about="${epIRI}">
<rdfs:subClassOf rdf:resource="${cathIRI}"/>
<rdfs:label xml:lang="en">${epName}</rdfs:label>${epDescription}
<owl:sameAs rdf:resource="${epSameAsIRI}"/>
</owl:Class>
"""
}
}
}
}
println """
</rdf:RDF>
"""