Commit 60c2941a authored by ALVISET's avatar ALVISET
Browse files

Fixed issues with refactored code

parent eb753384
......@@ -72,7 +72,7 @@ def map_filetype_and_datamode(cycle_files):
name_length = len(cycle_files[0])
cycle_number = cycle_files[0][name_length-6:name_length-3]
for file in cycle_files:
if file.contains("R"):
if "R" in file:
result["infos"].update({file: {"datamode": "R", "type": file[0]}})
result["R"].update({file[0]: file})
else:
......@@ -204,8 +204,6 @@ if __name__ == "__main__":
argo_graph = GraphWrapper(prefixes)
argo_graph.add_triple(ARGO[dac], RDF.type, ARGO.Datacenter)
argo_graph.add_triple(ARGO[dac], RDFS.label, Literal(dac, datatype=XSD.string))
# g = create_new_argo_graph(dac, prefixes)
# g2 = create_new_argo_graph(dac, prefixes)
print("DAC: {}".format(dac))
a = 1
......@@ -229,9 +227,9 @@ if __name__ == "__main__":
if float_info == None:
progress.write("Float {} metadata is nonexistent. Skipping...".format(afloat))
continue
print("TEST: "+ARGO)
pi_uri = GraphWrapper.create_uri(ARGO, float_info["deployment"]["principalInvestigatorName"])
# float_triples = {
argo_graph.add_triples({
afloat_uri: [
(RDF.type, ARGO.ArgoFloat),
......@@ -255,9 +253,8 @@ if __name__ == "__main__":
],
pi_uri: [
(RDF.type, FOAF.Person),
(FOAF.name, (float_info["deployment"]["principalInvestigatorName"], XSD.string))
],
dac_uri: [],
(FOAF.name, Literal(float_info["deployment"]["principalInvestigatorName"], datatype=XSD.string))
]
})
# Sensor node
......@@ -281,7 +278,7 @@ if __name__ == "__main__":
argo_graph.add_triple(activity_uri, RDF.type, ARGO.ActivityData)
try:
age = calculate_age(float_info["earliestCycle"]["firstStation"]["date"])
argo_graph.add_triple(activity_uri, ARGO.age, Literal(age, XSD.float))
argo_graph.add_triple(activity_uri, ARGO.age, Literal(age, datatype=XSD.float))
except TypeError:
progress.write("No cycles found for float {}".format(afloat))
ftp_access.cwd("{}/{}/{}/".format(dac_path, dac, afloat))
......@@ -331,12 +328,11 @@ if __name__ == "__main__":
# print("Float {}, cycle {} does not have cycle files ?".format(afloat, file_nb))
continue
# if c != None:
# cycleInfo = requests.get("https://dataselection.euro-argo.eu/api/find-by-id/"+str(cycleIds[nb]))
# if cycleInfo != None and cycleInfo.text != None:
# cycleInfo = json.loads(cycleInfo.text)
# for basin in cycleInfo["basins"]:
# g.add((cycle_uri, ARGO.basin, Literal(basin)))
# cycleInfo = requests.get("https://dataselection.euro-argo.eu/api/find-by-id/"+str(cycleIds[nb]))
# if cycleInfo != None and cycleInfo.text != None:
# cycleInfo = json.loads(cycleInfo.text)
# for basin in cycleInfo["basins"]:
# argo_graph.add_triple((cycle_uri, ARGO.basin, Literal(basin)))
......@@ -352,7 +348,7 @@ if __name__ == "__main__":
argo_graph.add_triple(cycle_uri, ARGO.startDate, Literal(cycle["startDate"]))
argo_graph.add_triple(cycle_uri, GEO.latitude, Literal(cycle["lat"]))
argo_graph.add_triple(cycle_uri, GEO.longitude, Literal(cycle["lon"]))
a +=
a += 1
progress.update(1)
if a == args.limit:
break
......
......@@ -15,21 +15,26 @@ class GraphWrapper():
for prefix in self.prefixes:
self.graph.bind(prefix[0], prefix[1])
def create_uri(self, args):
@staticmethod
def create_uri(namespace, *args):
"""
@param namespace: rdflib.namespace
@param args: string()
@return: rdflib.term.URIRef
"""
print(namespace)
print(args)
full_string = ""
namespace = args[0]
i = 0
# i = 0
for element in args:
if i == 0: i += 1; continue
# if i == 0: i += 1; continue
if element == None: continue
full_string += urllib.parse.quote(element)
if full_string != "":
return namespace[full_string]
try:
return namespace[full_string]
except:
print("ERROR "+str(isinstance(namespace, rdflib.Namespace))+" "+str(namespace))
else:
return None
......
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