Skip to content

Commit

Permalink
Able to create lipd back from dataset classes now
Browse files Browse the repository at this point in the history
  • Loading branch information
IKCAP committed Jul 5, 2024
1 parent 8c25e18 commit 8dae0ad
Show file tree
Hide file tree
Showing 30 changed files with 2,080 additions and 2,245 deletions.
5 changes: 2 additions & 3 deletions pylipd/classes/archivetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
##############################
# Auto-generated. Do not Edit
##############################

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

class ArchiveType:
synonyms = SYNONYMS["ARCHIVES"]["ArchiveType"]
Expand Down Expand Up @@ -39,7 +38,7 @@ def from_synonym(cls, synonym):
synobj = ArchiveType.synonyms[synonym.lower()]
return ArchiveType(synobj['id'], synobj['label'])
return None

class ArchiveTypeConstants:
Borehole = ArchiveType("http://linked.earth/ontology/archive#Borehole", "Borehole")
Coral = ArchiveType("http://linked.earth/ontology/archive#Coral", "Coral")
Expand Down
218 changes: 90 additions & 128 deletions pylipd/classes/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@

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

class Calibration:

def __init__(self):
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.uncertainty: str = None
self.datasetRange: str = None
self.equation: str = None
self.notes: str = None
self.proxyDataset: str = None
self.seasonality: str = None
self.targetDataset: str = None
self.uncertainty: 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")
self.id = self.ns + "/" + uniqid("Calibration.")

@staticmethod
def from_data(id, data) -> 'Calibration':
Expand All @@ -37,80 +35,62 @@ def from_data(id, data) -> 'Calibration':
for val in value:
self.type = val["@id"]

elif key == "hasTargetDataset":

elif key == "hasDOI":
for val in value:
if "@value" in val:
obj = val["@value"]
self.targetDataset = obj
self.dOI = obj

elif key == "hasProxyDataset":

elif key == "hasDatasetRange":
for val in value:
if "@value" in val:
obj = val["@value"]
self.proxyDataset = obj
self.datasetRange = obj

elif key == "hasDatasetRange":

elif key == "hasEquation":
for val in value:
if "@value" in val:
obj = val["@value"]
self.datasetRange = obj
self.equation = obj

elif key == "hasNotes":

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

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":

elif key == "hasProxyDataset":
for val in value:
if "@value" in val:
obj = val["@value"]
self.seasonality = obj
self.proxyDataset = obj

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":

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

elif key == "hasDOI":

elif key == "seasonality":
for val in value:
if "@value" in val:
obj = val["@value"]
self.dOI = obj
self.seasonality = obj
else:
for val in value:
obj = None
if "@id" in val:
obj = mydata[val["@id"]]
obj = data[val["@id"]]
elif "@value" in val:
obj = val["@value"]
self.set_non_standard_property(key, obj)

return self

def to_data(self, data={}):
Expand All @@ -122,37 +102,46 @@ def to_data(self, data={}):
}
]


if self.notes:
value_obj = self.notes
if self.dOI:
value_obj = self.dOI
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
data[self.id]["hasDOI"] = [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]["seasonality"] = [obj]

if self.datasetRange:
value_obj = self.datasetRange
data[self.id]["hasDatasetRange"] = [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]["hasDatasetRange"] = [obj]


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


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.proxyDataset:
value_obj = self.proxyDataset
obj = {
Expand All @@ -161,39 +150,28 @@ def to_data(self, data={}):
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasProxyDataset"] = [obj]

if self.targetDataset:
value_obj = self.targetDataset

if self.seasonality:
value_obj = self.seasonality
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
data[self.id]["seasonality"] = [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]["hasEquation"] = [obj]

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

if self.uncertainty:
value_obj = self.uncertainty
obj = {
Expand All @@ -202,26 +180,15 @@ def to_data(self, data={}):
"@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":
elif tp == "float" or tp == "double":
ptype = "http://www.w3.org/2001/XMLSchema#float"
elif tp == "str":
if re.match("\d{4}-\d{2}-\d{2}", value):
Expand All @@ -245,7 +212,7 @@ def set_non_standard_property(self, key, value):

def get_non_standard_property(self, key):
return self.misc[key]

def get_all_non_standard_properties(self):
return self.misc

Expand All @@ -254,56 +221,51 @@ def add_non_standard_property(self, key, value):
self.misc[key] = []
self.misc[key].append(value)

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

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

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

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

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

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

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

def setEquation(self, equation:str):
self.equation = equation

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

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

def setUncertainty(self, uncertainty:str):
self.uncertainty = uncertainty
def setNotes(self, notes:str):
self.notes = notes
def getProxyDataset(self) -> str:
return self.proxyDataset

def setProxyDataset(self, proxyDataset:str):
self.proxyDataset = proxyDataset

def getSeasonality(self) -> str:
return self.seasonality

def setSeasonality(self, seasonality:str):
self.seasonality = seasonality

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

def getProxyDataset(self) -> str:
return self.proxyDataset

def setProxyDataset(self, proxyDataset:str):
self.proxyDataset = proxyDataset

def getUncertainty(self) -> Uncertainty:
def setTargetDataset(self, targetDataset:str):
self.targetDataset = targetDataset

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

def setUncertainty(self, uncertainty:Uncertainty):
def setUncertainty(self, uncertainty:str):
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 8dae0ad

Please sign in to comment.