Source code for pylipd.classes.funding


##############################
# Auto-generated. Do not Edit
##############################

import re
from pylipd.utils import uniqid
from pylipd.classes.person import Person

[docs] class Funding: def __init__(self): self.fundingAgency: str = None self.fundingCountry: str = None self.grants: list[str] = [] self.investigators: list[Person] = [] self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Funding" self.id = self.ns + "/" + uniqid("Funding.")
[docs] @staticmethod def from_data(id, data) -> 'Funding': self = Funding() 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 == "hasFundingAgency": for val in value: if "@value" in val: obj = val["@value"] self.fundingAgency = obj elif key == "hasFundingCountry": for val in value: if "@value" in val: obj = val["@value"] self.fundingCountry = obj elif key == "hasGrant": for val in value: if "@value" in val: obj = val["@value"] self.grants.append(obj) elif key == "hasInvestigator": for val in value: if "@id" in val: obj = Person.from_data(val["@id"], data) else: obj = val["@value"] self.investigators.append(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 len(self.grants): data[self.id]["hasGrant"] = [] for value_obj in self.grants: obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasGrant"].append(obj) if len(self.investigators): data[self.id]["hasInvestigator"] = [] for value_obj in self.investigators: if type(value_obj) is str: obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } else: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) data[self.id]["hasInvestigator"].append(obj) if self.fundingAgency: value_obj = self.fundingAgency obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasFundingAgency"] = [obj] if self.fundingCountry: value_obj = self.fundingCountry obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasFundingCountry"] = [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 len(self.grants): data["grant"] = [] for value_obj in self.grants: obj = value_obj data["grant"].append(obj) if len(self.investigators): data["investigator"] = [] for value_obj in self.investigators: obj = value_obj.to_json() data["investigator"].append(obj) if self.fundingAgency: value_obj = self.fundingAgency obj = value_obj data["agency"] = obj if self.fundingCountry: value_obj = self.fundingCountry obj = value_obj data["country"] = obj for key in self.misc: value = self.misc[key] data[key] = value return data
[docs] @staticmethod def from_json(data) -> 'Funding': self = Funding() for key in data: pvalue = data[key] if key == "@id": self.id = pvalue elif key == "agency": value = pvalue obj = value self.fundingAgency = obj elif key == "country": value = pvalue obj = value self.fundingCountry = obj elif key == "grant": for value in pvalue: obj = value self.grants.append(obj) elif key == "investigator": for value in pvalue: obj = Person.from_json(value) self.investigators.append(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 getFundingAgency(self) -> str: return self.fundingAgency
[docs] def setFundingAgency(self, fundingAgency:str): assert isinstance(fundingAgency, str), f"Error: '{fundingAgency}' is not of type str" self.fundingAgency = fundingAgency
[docs] def getFundingCountry(self) -> str: return self.fundingCountry
[docs] def setFundingCountry(self, fundingCountry:str): assert isinstance(fundingCountry, str), f"Error: '{fundingCountry}' is not of type str" self.fundingCountry = fundingCountry
[docs] def getGrants(self) -> list[str]: return self.grants
[docs] def setGrants(self, grants:list[str]): assert isinstance(grants, list), "Error: grants is not a list" assert all(isinstance(x, str) for x in grants), f"Error: '{grants}' is not of type str" self.grants = grants
[docs] def addGrant(self, grants:str): assert isinstance(grants, str), f"Error: '{grants}' is not of type str" self.grants.append(grants)
[docs] def getInvestigators(self) -> list[Person]: return self.investigators
[docs] def setInvestigators(self, investigators:list[Person]): assert isinstance(investigators, list), "Error: investigators is not a list" assert all(isinstance(x, Person) for x in investigators), f"Error: '{investigators}' is not of type Person" self.investigators = investigators
[docs] def addInvestigator(self, investigators:Person): assert isinstance(investigators, Person), f"Error: '{investigators}' is not of type Person" self.investigators.append(investigators)