Skip to content

Commit

Permalink
Update srsbuild.py
Browse files Browse the repository at this point in the history
  • Loading branch information
situx authored Dec 29, 2024
1 parent 6f8921c commit f8fce08
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions scripts/srsbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

exont={}

prefixtoClasses={"geosrs":[]}
classToPrefix={}

gcore = Graph()
gcore.bind("geosrs", "https://w3id.org/geosrs#")
gcore.bind("skos","http://www.w3.org/2004/02/skos/core#")
Expand All @@ -14,11 +17,19 @@
gcore.add((URIRef("https://w3id.org/geosrs"),VANN.preferredNamespacePrefix,Literal("geosrs",datatype=XSD.string)))
gcore.add((URIRef("https://w3id.org/geosrs"),VANN.preferredNamespaceUri,Literal("https://w3id.org/geosrs#",datatype=XSD.anyURI)))



geocrsNS="https://w3id.org/geosrs#"
coreprefix="geosrs"

def getPrefixForClass(cls,prefixmap):
if cls in prefixmap:
return prefixmap[cls]["prefix"]
return coreprefix

def getNSForClass(cls,prefixmap):
if cls in prefixmap:
return prefixmap[cls]["ns"]
return geocrsNS

dirname = os.path.dirname(__file__)
abspath = os.path.join(dirname, '../csv/class/')

Expand All @@ -32,6 +43,7 @@
curns="http://www.opengis.net/ont/srs/"+filename.replace(".csv","")+"/"
g.bind(curprefix,curns)
g.bind("skos","http://www.w3.org/2004/02/skos/core#")
g.bind(curprefix,curns)

g.add((URIRef("https://w3id.org/geosrs/"+filename.replace(".csv","")),RDF.type,OWL.Ontology))
g.add((URIRef("https://w3id.org/geosrs/"+filename.replace(".csv","")),RDFS.label,Literal("SRS Ontology: "+curprefix.capitalize(),lang="en")))
Expand All @@ -46,6 +58,8 @@
if "Core Class?" in row and row["Core Class?"]=="Core Ontology":
core=True
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDF.type,OWL.Class))
prefixtoclasses[coreprefix].append(row["Concept"].replace(coreprefix+":",geocrsNS))
classToPrefix[row["Concept"]]={"prefix":coreprefix, "ns":geocrsNS}
if "Label" in row and row["Label"]!="":
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.label,Literal(row["Label"],lang="en")))
if "Definition" in row and row["Definition"]!="":
Expand All @@ -58,6 +72,8 @@
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.subClassOf,URIRef(row["SuperClass"].replace("geosrs:",geocrsNS))))
else:
g.add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDF.type,OWL.Class))
prefixtoclasses[curprefix].append(row["Concept"].replace(curprefix+":",curns))
classToPrefix[row["Concept"]]={"prefix":curprefix, "ns":curns}
if "Label" in row and row["Label"]!="":
g.add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDFS.label,Literal(row["Label"],lang="en")))
if "Definition" in row and row["Definition"]!="":
Expand All @@ -71,7 +87,8 @@
else:
continue


print(prefixestoclasses)
print(classToPrefix)
dirname = os.path.dirname(__file__)
abspath = os.path.join(dirname, '../csv/prop/')
directory = os.fsencode(abspath)
Expand Down Expand Up @@ -110,9 +127,9 @@
if "Definition" in row and row["Definition"]!="":
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),SKOS.definition,Literal(row["Definition"],lang="en")))
if "Range" in row and row["Range"]!="":
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.range,URIRef(row["Range"].replace("geosrs:",geocrsNS))))
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.range,URIRef(row["Range"].replace("geosrs:", getNSForClass(row["Range"],classToPrefix)))))
if "Domain" in row and row["Domain"]!="":
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.domain,URIRef(row["Domain"].replace("geosrs:",geocrsNS))))
gcore.add((URIRef(row["Concept"].replace(coreprefix+":",geocrsNS)),RDFS.domain,URIRef(row["Domain"].replace("geosrs:",getNSForClass(row["Domain"],classToPrefix)))))
else:
if row["Core Property?"].lower() in exont:
if objprop:
Expand All @@ -124,9 +141,9 @@
if "Definition" in row and row["Definition"]!="":
exont[row["Core Property?"].lower()].add((URIRef(row["Concept"].replace(curprefix+":",curns)),SKOS.definition,Literal(row["Definition"],lang="en")))
if "Range" in row and row["Range"]!="":
exont[row["Core Property?"].lower()].add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDFS.range,URIRef(row["Range"].replace("geosrs:",geocrsNS))))
exont[row["Core Property?"].lower()].add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDFS.range,URIRef(row["Range"].replace("geosrs:",getNSForClass(row["Range"],classToPrefix)))))
if "Domain" in row and row["Domain"]!="":
exont[row["Core Property?"].lower()].add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDFS.domain,URIRef(row["Domain"].replace("geosrs:",geocrsNS))))
exont[row["Core Property?"].lower()].add((URIRef(row["Concept"].replace(curprefix+":",curns)),RDFS.domain,URIRef(row["Domain"].replace("geosrs:",getNSForClass(row["Domain"],classToPrefix)))))
g.serialize(destination=filename.replace(".csv","")+".ttl")
else:
continue
Expand Down

0 comments on commit f8fce08

Please sign in to comment.