##############################
# Auto-generated. Do not Edit
##############################
import re
from pylipd.utils import uniqid
[docs]
class ChangeLog:
def __init__(self):
self.changes: None = None
self.notes: str = None
self.misc = {}
self.ontns = "http://linked.earth/ontology#"
self.ns = "http://linked.earth/lipd"
self.type = "http://linked.earth/ontology#ChangeLog"
self.id = self.ns + "/" + uniqid("ChangeLog.")
[docs]
@staticmethod
def from_data(id, data) -> 'ChangeLog':
self = ChangeLog()
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 == "hasChanges":
for val in value:
obj = val["@id"]
self.changes = obj
elif key == "hasNotes":
for val in value:
if "@value" in val:
obj = val["@value"]
self.notes = 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.changes:
value_obj = self.changes
obj = {
"@id": value_obj,
"@type": "uri"
}
data[self.id]["hasChanges"] = [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]
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(r"\d{4}-\d{2}-\d{2}( |T)\d{2}:\d{2}:\d{2}", value):
ptype = "http://www.w3.org/2001/XMLSchema#datetime"
elif re.match(r"\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.changes:
value_obj = self.changes
obj = value_obj
data["changes"] = obj
if self.notes:
value_obj = self.notes
obj = value_obj
data["notes"] = obj
for key in self.misc:
value = self.misc[key]
data[key] = value
return data
[docs]
@staticmethod
def from_json(data) -> 'ChangeLog':
self = ChangeLog()
for key in data:
pvalue = data[key]
if key == "@id":
self.id = pvalue
elif key == "changes":
value = pvalue
obj = value
self.changes = obj
elif key == "notes":
value = pvalue
obj = value
self.notes = 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 getChanges(self) -> None:
return self.changes
[docs]
def setChanges(self, changes:None):
assert isinstance(changes, None), f"Error: '{changes}' is not of type None"
self.changes = changes
[docs]
def getNotes(self) -> str:
return self.notes
[docs]
def setNotes(self, notes:str):
assert isinstance(notes, str), f"Error: '{notes}' is not of type str"
self.notes = notes