@@ -8,24 +8,28 @@ class OWL2VOWL():
8
8
def __init__ (self ):
9
9
print ("init" )
10
10
11
- def getTypeForProperty (self ,prop ,graph ,typeproperty ):
11
+ @staticmethod
12
+ def getTypeForProperty (prop ,graph ,typeproperty ):
12
13
for tup in graph .objects (URIRef (prop ),URIRef (typeproperty )):
13
14
#print(tup)
14
15
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 ))
16
17
return "rdf:Property"
17
18
18
- def getBaseIRI (self ,iri ):
19
+ @staticmethod
20
+ def getBaseIRI (iri ):
19
21
if "#" in iri :
20
22
return iri [0 :iri .rfind ("#" )]
21
23
return iri [0 :iri .rfind ("/" )]
22
24
23
- def getIRILabel (self ,iri ):
25
+ @staticmethod
26
+ def getIRILabel (iri ):
24
27
if "#" in iri :
25
28
return iri [iri .rfind ("#" )+ 1 :]
26
29
return iri [iri .rfind ("/" )+ 1 :]
27
30
28
- def normalizeNS (self ,prop ):
31
+ @staticmethod
32
+ def normalizeNS (prop ):
29
33
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:" )
30
34
31
35
#def inferDomainRanges(self,g,typeproperty):
@@ -34,7 +38,8 @@ def normalizeNS(self,prop):
34
38
# for tuppred in g.objects(subj,URIRef(typeproperty)):
35
39
# subjclasses.add(tuppred)
36
40
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" ):
38
43
minivowlresult = {"info" : [{
39
44
"description" : "Created with pyowl2vowl (version 0.1) as part of the SPARQLing Unicorn QGIS Plugin" }],
40
45
"nodes" : [],"links" : []}
@@ -47,11 +52,12 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
47
52
nodeuriToId [str (pred [1 ])]= nodecounter
48
53
nodecounter += 1
49
54
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 ])})
51
56
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 ])})
53
58
if predicates != []:
54
59
for pred in predicates :
60
+
55
61
QgsMessageLog .logMessage (str (pred ), "VOWL2OWL" , Qgis .Info )
56
62
if "from" in predicates [pred ] and "to" in predicates [pred ]:
57
63
QgsMessageLog .logMessage (str (predicates [pred ]["from" ]), "VOWL2OWL" , Qgis .Info )
@@ -62,7 +68,7 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
62
68
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 ):
63
69
links .append ({"source" : nodeuriToId [str (fromsub )],
64
70
"target" : nodeuriToId [str (topred )],
65
- "valueTo" : self .getIRILabel (str (pred )),
71
+ "valueTo" : OWL2VOWL .getIRILabel (str (pred )),
66
72
"propertyTo" : "class" ,
67
73
"uriTo" : str (pred )})
68
74
else :
@@ -72,11 +78,12 @@ def convertOWL2MiniVOWL(self,g,outpath,predicates=[],typeproperty="http://www.w3
72
78
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 )})
73
79
minivowlresult ["nodes" ]= nodes
74
80
minivowlresult ["links" ] = links
75
- f = open (outpath + "/minivowl_result.js" , "w" )
81
+ f = open (outpath + "/" + str ( outfile ) , "w" )
76
82
f .write ("var minivowlresult=" + json .dumps (minivowlresult , indent = 1 ))
77
83
f .close ()
78
84
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" ):
80
87
vowlresult = {"_comment" : "Created with pyowl2vowl (version 0.1) as part of the SPARQLing Unicorn QGIS Plugin" ,
81
88
"header" : {"prefixList" : {}, "baseIris" : [], "languages" : []}, "namespace" : [], "class" : [],
82
89
"classAttribute" : [], "property" : [], "propertyAttribute" : []}
@@ -99,20 +106,20 @@ def convertOWL2VOWL(self,g,outpath,typeproperty="http://www.w3.org/1999/02/22-rd
99
106
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" :
100
107
classes .append ({"id" :idcounter ,"type" :str (pred [1 ])})
101
108
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" :[]})
103
110
idcounter += 1
104
111
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 )})
106
113
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" :[]})
108
115
idcounter += 1
109
116
110
117
for pred in g .subject_objects (URIRef ("http://www.w3.org/2000/01/rdf-schema#range" )):
111
118
print (pred )
112
119
if str (pred [1 ]) not in classiriToProdId :
113
120
classes .append ({"id" :idcounter ,"type" :"http://www.w3.org/2000/01/rdf-schema#Datatype" })
114
121
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" :[]})
116
123
idcounter += 1
117
124
118
125
for iri in classiriToProdId :
0 commit comments