Skip to content

Commit d1e4834

Browse files
committed
fix vowl export
1 parent 5cf569a commit d1e4834

File tree

3 files changed

+77
-17
lines changed

3 files changed

+77
-17
lines changed

util/doc/docdefaults.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,60 @@ class DocDefaults:
19961996
</script>
19971997
""",
19981998

1999-
"vowltemplate": "",
1999+
"vowltemplate": """<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/situx/mini-vowl@master/docs/css/vowl.css"/>
2000+
<script src="{{vowlpath}}"></script>
2001+
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.2.2/d3.v3.min.js"></script>
2002+
<script src="https://cdn.jsdelivr.net/gh/situx/mini-vowl@master/docs/js/webVOWLGraphProd.js"></script>
2003+
<div id="wrapper">
2004+
<section id="vowl">
2005+
<div id="graph">
2006+
<div id="resetOption"></div>
2007+
<div id="sliderOption"></div>
2008+
</div>
2009+
</section>
2010+
<a href="vowl_result.js" target="_blank">Download VOWL File</a> <a href="minivowl_result.js" target="_blank">Download Mini VOWL File</a>
2011+
<script>var graphTag = document.getElementById('graph')
2012+
, linkDistanceClassSlider
2013+
, linkDistanceClassLabel
2014+
, linkDistanceLiteralLabel
2015+
, linkDistanceLiteralSlider
2016+
, onLoadCalled = false;
2017+
var height = 600
2018+
, width = document.getElementById("vowl").offsetWidth;
2019+
var graphOptions = function graphOptionsFunct() {
2020+
2021+
var resetOption = document.getElementById('resetOption')
2022+
, sliderOption = document.getElementById('sliderOption');
2023+
2024+
d3.select(resetOption)
2025+
.append("button")
2026+
.attr("id", "reset")
2027+
.property("type", "reset")
2028+
.text("Reset")
2029+
.on("click", resetGraph);
2030+
2031+
var slidDiv = d3.select(sliderOption)
2032+
.append("div")
2033+
.attr("id", "distanceSlider");
2034+
2035+
linkDistanceClassLabel = slidDiv.append("label")
2036+
.attr("for", "distanceSlider")
2037+
.text(DEFAULT_VISIBLE_LINKDISTANCE);
2038+
linkDistanceLiteralLabel = linkDistanceClassLabel;
2039+
2040+
linkDistanceClassSlider = slidDiv.append("input")
2041+
.attr("type", "range")
2042+
.attr("min", 10)
2043+
.attr("max", 600)
2044+
.attr("value", DEFAULT_VISIBLE_LINKDISTANCE)
2045+
.attr("step", 10)
2046+
.on("input", changeDistance);
2047+
linkDistanceLiteralSlider = linkDistanceClassSlider;
2048+
};
2049+
json=minivowlresult
2050+
drawGraph(graphTag, width, height);
2051+
</script>
2052+
</div>""",
20002053

20012054
"htmlcommenttemplate": """<p class="comment"><b>Description:</b> {{comment}}</p>""",
20022055

util/doc/ontdocgeneration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def getPropertyRelations(self, graph, outpath):
671671
predicatecounter += 1
672672
predicatelength += len(str(pred))
673673
if self.createVOWL:
674-
OWL2VOWL().convertOWL2MiniVOWL(graph, outpath, "minivowl_result.js", predicates)
674+
OWL2VOWL.convertOWL2MiniVOWL(graph, outpath, "minivowl_result.js", predicates)
675675
with open(outpath + "proprelations.js", 'w', encoding='utf-8') as f:
676676
f.write("var proprelations=" + json.dumps(predicates))
677677
f.close()

util/export/data/exporter/rdf/vowlexporter.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,28 @@ class OWL2VOWL():
88
def __init__(self):
99
print("init")
1010

11-
def getTypeForProperty(self,prop,graph,typeproperty):
11+
@staticmethod
12+
def getTypeForProperty(prop,graph,typeproperty):
1213
for tup in graph.objects(URIRef(prop),URIRef(typeproperty)):
1314
#print(tup)
1415
if str(tup)!="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property":
15-
return self.normalizeNS(str(tup))
16+
return OWL2VOWL.normalizeNS(str(tup))
1617
return "rdf:Property"
1718

18-
def getBaseIRI(self,iri):
19+
@staticmethod
20+
def getBaseIRI(iri):
1921
if "#" in iri:
2022
return iri[0:iri.rfind("#")]
2123
return iri[0:iri.rfind("/")]
2224

23-
def getIRILabel(self,iri):
25+
@staticmethod
26+
def getIRILabel(iri):
2427
if "#" in iri:
2528
return iri[iri.rfind("#")+1:]
2629
return iri[iri.rfind("/")+1:]
2730

28-
def normalizeNS(self,prop):
31+
@staticmethod
32+
def normalizeNS(prop):
2933
return prop.replace("http://www.w3.org/1999/02/22-rdf-syntax-ns#","rdf:").replace("http://www.w3.org/2000/01/rdf-schema#","rdfs:").replace("http://www.w3.org/2002/07/owl#","owl:")
3034

3135
#def inferDomainRanges(self,g,typeproperty):
@@ -34,7 +38,8 @@ def normalizeNS(self,prop):
3438
# for tuppred in g.objects(subj,URIRef(typeproperty)):
3539
# subjclasses.add(tuppred)
3640

37-
def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",labelproperty="http://www.w3.org/2000/01/rdf-schema#label"):
41+
@staticmethod
42+
def convertOWL2MiniVOWL(g,outpath,outfile=None,predicates=[],typeproperty="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",labelproperty="http://www.w3.org/2000/01/rdf-schema#label"):
3843
minivowlresult={"info": [{
3944
"description": "Created with pyowl2vowl (version 0.1) as part of the SPARQLing Unicorn QGIS Plugin"}],
4045
"nodes": [],"links": []}
@@ -47,11 +52,12 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
4752
nodeuriToId[str(pred[1])]=nodecounter
4853
nodecounter+=1
4954
if str(pred[1])=="http://www.w3.org/2002/07/owl#Class" or str(pred[1])=="http://www.w3.org/2000/01/rdf-schema#Class" or str(pred[1])=="http://www.w3.org/2000/01/rdf-schema#Datatype":
50-
nodes.append({"name":self.getIRILabel(str(pred[1])),"type":"class","uri":str(pred[1])})
55+
nodes.append({"name":OWL2VOWL.getIRILabel(str(pred[1])),"type":"class","uri":str(pred[1])})
5156
else:
52-
nodes.append({"name": self.getIRILabel(str(pred[1])), "type": "class", "uri": str(pred[1])})
57+
nodes.append({"name": OWL2VOWL.getIRILabel(str(pred[1])), "type": "class", "uri": str(pred[1])})
5358
if predicates!=[]:
5459
for pred in predicates:
60+
5561
QgsMessageLog.logMessage(str(pred), "VOWL2OWL", Qgis.Info)
5662
if "from" in predicates[pred] and "to" in predicates[pred]:
5763
QgsMessageLog.logMessage(str(predicates[pred]["from"]), "VOWL2OWL", Qgis.Info)
@@ -62,7 +68,7 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
6268
if "http://www.w3.org/1999/02/22-rdf-syntax-ns#" not in str(topred) and "http://www.w3.org/2002/07/owl#" not in str(topred):
6369
links.append({"source": nodeuriToId[str(fromsub)],
6470
"target": nodeuriToId[str(topred)],
65-
"valueTo": self.getIRILabel(str(pred)),
71+
"valueTo": OWL2VOWL.getIRILabel(str(pred)),
6672
"propertyTo": "class",
6773
"uriTo": str(pred)})
6874
else:
@@ -72,11 +78,12 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
7278
links.append({"source":nodeuriToId[node],"target":nodeuriToId[str(predobj[1])],"valueTo": self.getIRILabel(str(predobj[0])),"propertyTo":("class" if isinstance(predobj[1],URIRef) else "datatype"), "uriTo":(str(predobj[1]) if isinstance(predobj[1],URIRef) else predobj[1].datatype)})
7379
minivowlresult["nodes"]=nodes
7480
minivowlresult["links"] = links
75-
f = open(outpath + "/minivowl_result.js", "w")
81+
f = open(outpath + "/"+str(outfile), "w")
7682
f.write("var minivowlresult=" + json.dumps(minivowlresult, indent=1))
7783
f.close()
7884

79-
def convertOWL2VOWL(self,g,outpath,typeproperty="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",labelproperty="http://www.w3.org/2000/01/rdf-schema#label"):
85+
@staticmethod
86+
def convertOWL2VOWL(g,outpath,typeproperty="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",labelproperty="http://www.w3.org/2000/01/rdf-schema#label"):
8087
vowlresult = {"_comment": "Created with pyowl2vowl (version 0.1) as part of the SPARQLing Unicorn QGIS Plugin",
8188
"header": {"prefixList": {}, "baseIris": [], "languages": []}, "namespace": [], "class": [],
8289
"classAttribute": [], "property": [], "propertyAttribute": []}
@@ -99,20 +106,20 @@ def convertOWL2VOWL(self,g,outpath,typeproperty="http://www.w3.org/1999/02/22-rd
99106
if str(pred[1])=="http://www.w3.org/2002/07/owl#Class" or str(pred[1])=="http://www.w3.org/2000/01/rdf-schema#Class" or str(pred[1])=="http://www.w3.org/2000/01/rdf-schema#Datatype":
100107
classes.append({"id":idcounter,"type":str(pred[1])})
101108
classiriToProdId[str(pred[0])]={"id":idcounter,"attid":len(classAttributes)-1}
102-
classAttributes.append({"id":idcounter,"iri":str(pred[0]),"baseIRI":self.getBaseIRI(str(pred[0])),"instances":0,"label":{"IRI-based":self.getIRILabel(str(pred[0]))},"annotations":{},"subClasses":[],"superClasses":[]})
109+
classAttributes.append({"id":idcounter,"iri":str(pred[0]),"baseIRI":OWL2VOWL.getBaseIRI(str(pred[0])),"instances":0,"label":{"IRI-based":OWL2VOWL.getIRILabel(str(pred[0]))},"annotations":{},"subClasses":[],"superClasses":[]})
103110
idcounter+=1
104111
else:
105-
props.append({"id":idcounter,"type":self.getTypeForProperty(str(pred[0]),g,typeproperty)})
112+
props.append({"id":idcounter,"type":OWL2VOWL.getTypeForProperty(str(pred[0]),g,typeproperty)})
106113
propiriToProdId[str(pred[0])]={"id":idcounter,"attid":len(propAttributes)-1}
107-
propAttributes.append({"id":idcounter,"iri":str(pred[0]),"baseIRI":self.getBaseIRI(str(pred[0])),"instances":0,"label":{"IRI-based":self.getIRILabel(str(pred[0]))},"annotations":{},"range":[],"domain":[],"subProperties":[],"superProperties":[]})
114+
propAttributes.append({"id":idcounter,"iri":str(pred[0]),"baseIRI":OWL2VOWL.getBaseIRI(str(pred[0])),"instances":0,"label":{"IRI-based":OWL2VOWL.getIRILabel(str(pred[0]))},"annotations":{},"range":[],"domain":[],"subProperties":[],"superProperties":[]})
108115
idcounter+=1
109116

110117
for pred in g.subject_objects(URIRef("http://www.w3.org/2000/01/rdf-schema#range")):
111118
print(pred)
112119
if str(pred[1]) not in classiriToProdId:
113120
classes.append({"id":idcounter,"type":"http://www.w3.org/2000/01/rdf-schema#Datatype"})
114121
classiriToProdId[str(pred[1])]={"id":idcounter,"attid":len(classAttributes)-1}
115-
classAttributes.append({"id":idcounter,"iri":str(pred[1]),"baseIRI":self.getBaseIRI(str(pred)),"instances":0,"label":{"IRI-based":self.getIRILabel(str(pred[1]))},"annotations":{},"subClasses":[],"superClasses":[]})
122+
classAttributes.append({"id":idcounter,"iri":str(pred[1]),"baseIRI":OWL2VOWL.getBaseIRI(str(pred)),"instances":0,"label":{"IRI-based":OWL2VOWL.getIRILabel(str(pred[1]))},"annotations":{},"subClasses":[],"superClasses":[]})
116123
idcounter+=1
117124

118125
for iri in classiriToProdId:

0 commit comments

Comments
 (0)