Skip to content

Commit

Permalink
Updated classes to allow converting back
Browse files Browse the repository at this point in the history
  • Loading branch information
IKCAP committed Jul 4, 2024
1 parent 9a6128d commit 8c25e18
Show file tree
Hide file tree
Showing 29 changed files with 3,466 additions and 958 deletions.
14 changes: 13 additions & 1 deletion pylipd/classes/archivetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Auto-generated. Do not Edit
##############################

from pylipd.globals.synonyms import SYNONYMS
from ..globals.synonyms import SYNONYMS

class ArchiveType:
synonyms = SYNONYMS["ARCHIVES"]["ArchiveType"]
Expand All @@ -21,6 +21,18 @@ def getLabel(self):
def getId(self):
return self.id

def to_data(self, data={}):
data[self.id] ={
"label": [
{
"@datatype": None,
"@type": "literal",
"@value": self.label
}
]
}
return data

@classmethod
def from_synonym(cls, synonym):
if synonym.lower() in ArchiveType.synonyms:
Expand Down
225 changes: 179 additions & 46 deletions pylipd/classes/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,59 @@
##############################

import re
from pylipd.utils import uniqid
from pylipd.classes.uncertainty import Uncertainty

class Calibration:

def __init__(self):
self.uncertainty: str = None
self.proxyDataset: str = None
self.datasetRange: str = None
self.dOI: str = None
self.targetDataset: str = None
self.uncertainty: Uncertainty = None
self.notes: str = None
self.seasonality: str = None
self.targetDataset: str = None
self.dOI: str = None
self.proxyDataset: str = None
self.uncertainty: str = None
self.equation: str = None
self.datasetRange: str = None
self.seasonality: str = None
self.misc = {}
self.ontns = "http://linked.earth/ontology#"
self.ns = "http://linked.earth/lipd"
self.type = "http://linked.earth/ontology#Calibration"
self.id = self.ns + "/" + uniqid("Calibration")

@staticmethod
def from_data(id, data) -> 'Calibration':
self = Calibration()
self.id = id
mydata = data[id]
for key in mydata:
value = mydata[key]
obj = None
if key == "type":
continue

elif key == "hasUncertainty":

for val in value:
if "@id" in val:
obj = Uncertainty.from_data(val["@id"], data)
else:
obj = val["@value"]

self.uncertainty = obj
self.type = val["@id"]

elif key == "hasEquation":
elif key == "hasTargetDataset":

for val in value:
if "@value" in val:
obj = val["@value"]
self.equation = obj
self.targetDataset = obj

elif key == "hasUncertainty":
elif key == "hasProxyDataset":

for val in value:
if "@value" in val:
obj = val["@value"]
self.uncertainty = obj
self.proxyDataset = obj

elif key == "seasonality":
elif key == "hasDatasetRange":

for val in value:
if "@value" in val:
obj = val["@value"]
self.seasonality = obj
self.datasetRange = obj

elif key == "hasNotes":

Expand All @@ -68,33 +65,43 @@ def from_data(id, data) -> 'Calibration':
obj = val["@value"]
self.notes = obj

elif key == "hasDOI":
elif key == "hasUncertainty":

for val in value:
if "@id" in val:
obj = Uncertainty.from_data(val["@id"], data)
else:
obj = val["@value"]

self.uncertainty = obj

elif key == "seasonality":

for val in value:
if "@value" in val:
obj = val["@value"]
self.dOI = obj
self.seasonality = obj

elif key == "hasTargetDataset":
elif key == "hasEquation":

for val in value:
if "@value" in val:
obj = val["@value"]
self.targetDataset = obj
self.equation = obj

elif key == "hasDatasetRange":
elif key == "hasUncertainty":

for val in value:
if "@value" in val:
obj = val["@value"]
self.datasetRange = obj
self.uncertainty = obj

elif key == "hasProxyDataset":
elif key == "hasDOI":

for val in value:
if "@value" in val:
obj = val["@value"]
self.proxyDataset = obj
self.dOI = obj
else:
for val in value:
obj = None
Expand All @@ -106,6 +113,132 @@ def from_data(id, data) -> 'Calibration':

return self

def to_data(self, data={}):
data[self.id] = {}
data[self.id]["type"] = [
{
"@id": self.type,
"@type": "uri"
}
]


if self.notes:
value_obj = self.notes
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasNotes"] = [obj]


if self.seasonality:
value_obj = self.seasonality
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["seasonality"] = [obj]


if self.datasetRange:
value_obj = self.datasetRange
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasDatasetRange"] = [obj]


if self.proxyDataset:
value_obj = self.proxyDataset
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasProxyDataset"] = [obj]


if self.targetDataset:
value_obj = self.targetDataset
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasTargetDataset"] = [obj]


if self.uncertainty:
value_obj = self.uncertainty
obj = {
"@id": value_obj.id,
"@type": "uri"
}
data = value_obj.to_data(data)

data[self.id]["hasUncertainty"] = [obj]


if self.equation:
value_obj = self.equation
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasEquation"] = [obj]


if self.uncertainty:
value_obj = self.uncertainty
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasUncertainty"] = [obj]


if self.dOI:
value_obj = self.dOI
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasDOI"] = [obj]


for key in self.misc:
value = self.misc[key]
data[self.id][key] = []
ptype = None
tp = type(value).__name__
if tp == "int":
ptype = "http://www.w3.org/2001/XMLSchema#integer"
elif tp == "float":
ptype = "http://www.w3.org/2001/XMLSchema#float"
elif tp == "str":
if re.match("\d{4}-\d{2}-\d{2}", value):
ptype = "http://www.w3.org/2001/XMLSchema#date"
else:
ptype = "http://www.w3.org/2001/XMLSchema#string"
elif tp == "bool":
ptype = "http://www.w3.org/2001/XMLSchema#boolean"

data[self.id][key].append({
"@value": value,
"@type": "literal",
"@datatype": ptype
})

return data

def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
Expand All @@ -121,30 +254,18 @@ def add_non_standard_property(self, key, value):
self.misc[key] = []
self.misc[key].append(value)

def getUncertainty(self) -> Uncertainty:
return self.uncertainty
def getNotes(self) -> str:
return self.notes

def setUncertainty(self, uncertainty:Uncertainty):
self.uncertainty = uncertainty
def setNotes(self, notes:str):
self.notes = notes

def getTargetDataset(self) -> str:
return self.targetDataset

def setTargetDataset(self, targetDataset:str):
self.targetDataset = targetDataset

def getDatasetRange(self) -> str:
return self.datasetRange

def setDatasetRange(self, datasetRange:str):
self.datasetRange = datasetRange

def getNotes(self) -> str:
return self.notes

def setNotes(self, notes:str):
self.notes = notes

def getEquation(self) -> str:
return self.equation

Expand All @@ -169,8 +290,20 @@ def getProxyDataset(self) -> str:
def setProxyDataset(self, proxyDataset:str):
self.proxyDataset = proxyDataset

def getUncertainty(self) -> Uncertainty:
return self.uncertainty

def setUncertainty(self, uncertainty:Uncertainty):
self.uncertainty = uncertainty

def getDOI(self) -> str:
return self.dOI

def setDOI(self, dOI:str):
self.dOI = dOI

def getDatasetRange(self) -> str:
return self.datasetRange

def setDatasetRange(self, datasetRange:str):
self.datasetRange = datasetRange
Loading

0 comments on commit 8c25e18

Please sign in to comment.