##############################
# Auto-generated. Do not Edit
##############################
import re
from pylipd.utils import uniqid
[docs]
class Uncertainty:
def __init__(self):
self.uncertaintyType: str = None
self.misc = {}
self.ontns = "http://linked.earth/ontology#"
self.ns = "http://linked.earth/lipd"
self.type = "http://linked.earth/ontology#Uncertainty"
self.id = self.ns + "/" + uniqid("Uncertainty.")
[docs]
@staticmethod
def from_data(id, data) -> 'Uncertainty':
self = Uncertainty()
self.id = id
mydata = data[id]
for key in mydata:
value = mydata[key]
obj = None
if key == "type":
for val in value:
self.type = val["@id"]
elif key == "hasUncertaintyType":
for val in value:
if "@value" in val:
obj = val["@value"]
self.uncertaintyType = obj
else:
for val in value:
obj = None
if "@id" in val:
obj = data[val["@id"]]
elif "@value" in val:
obj = val["@value"]
self.set_non_standard_property(key, obj)
return self
[docs]
def to_data(self, data={}):
data[self.id] = {}
data[self.id]["type"] = [
{
"@id": self.type,
"@type": "uri"
}
]
if self.uncertaintyType:
value_obj = self.uncertaintyType
obj = {
"@value": value_obj,
"@type": "literal",
"@datatype": "http://www.w3.org/2001/XMLSchema#string"
}
data[self.id]["hasUncertaintyType"] = [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" or tp == "double":
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
[docs]
def to_json(self):
data = {
"@id": self.id
}
if self.uncertaintyType:
value_obj = self.uncertaintyType
obj = value_obj
data["uncertaintyType"] = obj
for key in self.misc:
value = self.misc[key]
data[key] = value
return data
[docs]
@staticmethod
def from_json(data) -> 'Uncertainty':
self = Uncertainty()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "uncertaintyType":
value = pvalue
obj = value
self.uncertaintyType = obj
else:
self.set_non_standard_property(key, pvalue)
return self
[docs]
def set_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = value
[docs]
def get_non_standard_property(self, key):
return self.misc[key]
[docs]
def get_all_non_standard_properties(self):
return self.misc
[docs]
def add_non_standard_property(self, key, value):
if key not in self.misc:
self.misc[key] = []
self.misc[key].append(value)
[docs]
def getUncertaintyType(self) -> str:
return self.uncertaintyType
[docs]
def setUncertaintyType(self, uncertaintyType:str):
self.uncertaintyType = uncertaintyType