Commit 161b8f63 authored by ALVISET's avatar ALVISET
Browse files

Included all missing relations from the ontology and created a quick merge...

Included all missing relations from the ontology and created a quick merge script to include the ontology file within the generated one
parent a0e57bd5
......@@ -54,7 +54,7 @@ if __name__ == "__main__":
# db_location = os.path.abspath(args.db)
# RDF Namespaces
ARGO = Namespace("http://www.argodatamgt.org/vocab#")
ARGO = Namespace("http://www.argodatamgt.org/argo-ontology#")
NERC = Namespace("http://vocab.nerc.ac.uk/collection/")
GEO = Namespace("https://www.w3.org/2003/01/geo/wgs84_pos#")
......@@ -70,23 +70,23 @@ if __name__ == "__main__":
g.bind("geo", GEO)
# DCAT description
argo_catalog = ARGO["catalog"+BNode()]
g.add((argo_catalog, RDF.type, DCAT.Catalog))
g.add((argo_catalog, DCTERMS.title, Literal("Argo program catalog")))
g.add((argo_catalog, DCTERMS.description, Literal("""
The Argo program RDF catalog regrouping climate and floats catalogs.
""")))
argofloats_catalog = ARGO["catalog"+BNode()]
g.add((argofloats_catalog, RDF.type, DCAT.Catalog))
g.add((argofloats_catalog, DCTERMS.title, Literal("Argo floats datasets catalog")))
g.add((argofloats_catalog, DCTERMS.description, Literal("""
The catalogue RDF node from which are connected each float of the Argo program.
Each float is represented as a DCAT dataset linked with this catalog.
This catalog is one of the sub-catalogs of the Argo program.
""")))
g.add((argo_catalog, DCTERMS.hasPart, argofloats_catalog))
# argo_catalog = ARGO["catalog"+BNode()]
# g.add((argo_catalog, RDF.type, DCAT.Catalog))
# g.add((argo_catalog, DCTERMS.title, Literal("Argo program catalog")))
# g.add((argo_catalog, DCTERMS.description, Literal("""
# The Argo program RDF catalog regrouping climate and floats catalogs.
# """)))
#
# argofloats_catalog = ARGO["catalog"+BNode()]
# g.add((argofloats_catalog, RDF.type, DCAT.Catalog))
# g.add((argofloats_catalog, DCTERMS.title, Literal("Argo floats datasets catalog")))
# g.add((argofloats_catalog, DCTERMS.description, Literal("""
# The catalogue RDF node from which are connected each float of the Argo program.
# Each float is represented as a DCAT dataset linked with this catalog.
# This catalog is one of the sub-catalogs of the Argo program.
# """)))
#
# g.add((argo_catalog, DCTERMS.hasPart, argofloats_catalog))
ftp_access = FTP("ftp.ifremer.fr")
ftp_access.login()
......@@ -108,7 +108,7 @@ if __name__ == "__main__":
# progress.update(1)
continue
afloat_uri = ARGO["argofloat" + afloat]
g.add((argofloats_catalog, DCAT.dataset, afloat_uri))
# g.add((argofloats_catalog, DCAT.dataset, afloat_uri))
deployment_uri = ARGO["deployment" + afloat]
# platform_uri = ARGO["platform" + afloat]
activity_uri = ARGO["activity" + afloat]
......@@ -116,7 +116,7 @@ if __name__ == "__main__":
if float_info == None:
progress.write("Float {} metadata is nonexistent. Skipping...".format(afloat))
float_info = json.loads(float_info.text)
g.add((argofloats_catalog, DCAT.dataset, afloat_uri))
# g.add((argofloats_catalog, DCAT.dataset, afloat_uri))
# Float node
if float_info == None:
......@@ -145,9 +145,9 @@ if __name__ == "__main__":
g.add((afloat_uri, ARGO.transmissionSystem,
NERC["R10/current/" + urllib.parse.quote(transmission)]))
n_sensor = 0
# Sensor node
for sensor in float_info["sensors"]:
sensor_uri = ARGO["sensor" + BNode() + "_" + str(n_sensor)]
sensor_uri = ARGO["sensor" + BNode()]
g.add((sensor_uri, RDF.type, SOSA.Sensor))
g.add((afloat_uri, SOSA.hosts, sensor_uri))
if sensor["id"] != None:
......@@ -156,7 +156,10 @@ if __name__ == "__main__":
g.add((sensor_uri, ARGO.maker, NERC["R26/current/" + urllib.parse.quote(sensor["maker"]) + "/"]))
if sensor["model"] != None:
g.add((sensor_uri, ARGO.model, NERC["R27/current/" + urllib.parse.quote(sensor["model"]) + "/"]))
n_sensor += 1
for calib in float_info["calibrations"]:
if calib["dimLevel"] == sensor["dimLevel"]:
g.add((sensor_uri, SOSA.observes,
NERC["R03/current/" + urllib.parse.quote(calib["parameter"])]))
# Deployment node
g.add((deployment_uri, RDF.type, SSN.Deployment))
......@@ -175,6 +178,9 @@ if __name__ == "__main__":
formatted_datetime = float_info["deployment"]["launchDate"]
g.add((deployment_uri, ARGO.launchDate,
Literal(formatted_datetime, datatype=XSD.dateTime)))
ship = float_info["deployment"]["platform"]
if ship != None:
g.add((deployment_uri, ARGO.deployedByShip, Literal(ship, datatype=XSD.string)))
# Activity node
g.add((activity_uri, RDF.type, ARGO.ActivityData))
......@@ -208,8 +214,8 @@ if __name__ == "__main__":
profiles = {}
ftp_access.cwd("{}/{}/{}/profiles/".format(dac_path, dac, afloat))
cycle_files = ftp_access.nlst()
g.add((activity_uri, ARGO.lastCycle,
Literal(float_info["latestCycle"]["id"], datatype=XSD.int)))
# g.add((activity_uri, ARGO.lastCycle,
# Literal(float_info["latestCycle"]["id"], datatype=XSD.int)))
for cycle in float_info["cycles"]:
nb = int(cycle["id"])
file_nb = (3 - len(str(nb))) * "0" + str(nb)
......@@ -227,8 +233,11 @@ if __name__ == "__main__":
file_uri = ARGO["file" + BNode()]
g.add((file_uri, RDF.type, ARGO.File))
if nb == float_info["latestCycle"]["id"]:
g.add((activity_uri, ARGO.lastCycle, cycle_uri))
for cycle_file in this_cycle_files:
g.add((file_uri, DCAT.accessURL, Literal(
g.add((file_uri, ARGO.accessURL, Literal(
"ftp://ftp.ifremer.fr/ifremer/argo/dac/{}/{}/profiles/{}".format(dac, afloat, cycle_file))))
if cycle_file.startswith("R"):
g.add((cycle_uri, ARGO.coreArgoProfile, file_uri))
......
from rdflib import Graph
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("generated", type=str, help="The generated file from the convert script")
parser.add_argument("ontology", type=str, help="The ontology file to include in the generated file")
args = parser.parse_args()
graph1 = Graph()
graph2 = Graph()
with open(args.generated) as f:
graph1.parse(f, format="ttl")
with open(args.ontology) as f:
graph2.parse(f, format="ttl")
graph3 = graph1 + graph2
with open("merged.ttl", "w") as ttl:
ttl.write(graph3.serialize(format="turtle").decode("utf-8"))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment