From 8dae0adc376d2ecee5c355f18f6369c3981b7f56 Mon Sep 17 00:00:00 2001 From: Varun Ratnakar Date: Fri, 5 Jul 2024 14:47:47 +0530 Subject: [PATCH] Able to create lipd back from dataset classes now --- pylipd/classes/archivetype.py | 5 +- pylipd/classes/calibration.py | 218 ++--- pylipd/classes/changelog.py | 49 +- pylipd/classes/chrondata.py | 54 +- pylipd/classes/compilation.py | 35 +- pylipd/classes/dataset.py | 586 ++++++------- pylipd/classes/datatable.py | 70 +- pylipd/classes/funding.py | 101 +-- pylipd/classes/independentvariable.py | 91 +- pylipd/classes/integrationtime.py | 70 +- pylipd/classes/interpretation.py | 389 ++++----- pylipd/classes/interpretationseasonality.py | 5 +- pylipd/classes/interpretationvariable.py | 5 +- pylipd/classes/isotopeinterpretation.py | 59 +- pylipd/classes/location.py | 347 ++++---- pylipd/classes/model.py | 117 ++- pylipd/classes/paleodata.py | 77 +- pylipd/classes/paleoproxy.py | 5 +- pylipd/classes/paleoproxygeneral.py | 5 +- pylipd/classes/paleounit.py | 5 +- pylipd/classes/paleovariable.py | 5 +- pylipd/classes/person.py | 16 +- pylipd/classes/physicalsample.py | 66 +- pylipd/classes/publication.py | 468 +++++----- pylipd/classes/resolution.py | 111 ++- pylipd/classes/uncertainty.py | 16 +- pylipd/classes/variable.py | 896 ++++++++++---------- pylipd/globals/schema.py | 4 - pylipd/lipd.py | 35 + pylipd/utils/create_classes.py | 415 +++++---- 30 files changed, 2080 insertions(+), 2245 deletions(-) diff --git a/pylipd/classes/archivetype.py b/pylipd/classes/archivetype.py index 2bc42f9..cb69d62 100644 --- a/pylipd/classes/archivetype.py +++ b/pylipd/classes/archivetype.py @@ -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"] @@ -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") diff --git a/pylipd/classes/calibration.py b/pylipd/classes/calibration.py index 052492f..e7014c2 100644 --- a/pylipd/classes/calibration.py +++ b/pylipd/classes/calibration.py @@ -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': @@ -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={}): @@ -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 = { @@ -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 = { @@ -202,18 +180,7 @@ 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] = [] @@ -221,7 +188,7 @@ def to_data(self, data={}): 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): @@ -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 @@ -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 + \ No newline at end of file diff --git a/pylipd/classes/changelog.py b/pylipd/classes/changelog.py index 81b3a75..a882c31 100644 --- a/pylipd/classes/changelog.py +++ b/pylipd/classes/changelog.py @@ -9,13 +9,13 @@ class ChangeLog: def __init__(self): - self.notes: str = None 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") + self.id = self.ns + "/" + uniqid("ChangeLog.") @staticmethod def from_data(id, data) -> 'ChangeLog': @@ -30,13 +30,11 @@ def from_data(id, data) -> 'ChangeLog': 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"] @@ -45,11 +43,11 @@ def from_data(id, data) -> 'ChangeLog': 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={}): @@ -61,17 +59,6 @@ def to_data(self, data={}): } ] - - 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.changes: value_obj = self.changes obj = { @@ -79,8 +66,17 @@ def to_data(self, data={}): "@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] = [] @@ -88,7 +84,7 @@ def to_data(self, data={}): 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): @@ -112,7 +108,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 @@ -121,14 +117,15 @@ 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 getChanges(self) -> None: return self.changes def setChanges(self, changes:None): self.changes = changes + + def getNotes(self) -> str: + return self.notes + + def setNotes(self, notes:str): + self.notes = notes + \ No newline at end of file diff --git a/pylipd/classes/chrondata.py b/pylipd/classes/chrondata.py index d8f846f..6b879a1 100644 --- a/pylipd/classes/chrondata.py +++ b/pylipd/classes/chrondata.py @@ -11,13 +11,13 @@ class ChronData: def __init__(self): - self.modeledBy: list[Model] = [] self.measurementTables: list[DataTable] = [] + self.modeledBy: list[Model] = [] self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#ChronData" - self.id = self.ns + "/" + uniqid("ChronData") + self.id = self.ns + "/" + uniqid("ChronData.") @staticmethod def from_data(id, data) -> 'ChronData': @@ -32,7 +32,6 @@ def from_data(id, data) -> 'ChronData': self.type = val["@id"] elif key == "hasMeasurementTable": - for val in value: if "@id" in val: obj = DataTable.from_data(val["@id"], data) @@ -42,7 +41,6 @@ def from_data(id, data) -> 'ChronData': self.measurementTables.append(obj) elif key == "modeledBy": - for val in value: if "@id" in val: obj = Model.from_data(val["@id"], data) @@ -54,11 +52,11 @@ def from_data(id, data) -> 'ChronData': 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={}): @@ -70,18 +68,6 @@ def to_data(self, data={}): } ] - - if len(self.modeledBy): - data[self.id]["modeledBy"] = [] - for value_obj in self.modeledBy: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["modeledBy"].append(obj) - if len(self.measurementTables): data[self.id]["hasMeasurementTable"] = [] for value_obj in self.measurementTables: @@ -90,9 +76,17 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasMeasurementTable"].append(obj) + if len(self.modeledBy): + data[self.id]["modeledBy"] = [] + for value_obj in self.modeledBy: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["modeledBy"].append(obj) for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -100,7 +94,7 @@ def to_data(self, data={}): 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): @@ -124,7 +118,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 @@ -133,6 +127,15 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) + def getMeasurementTables(self) -> list[DataTable]: + return self.measurementTables + + def setMeasurementTables(self, measurementTables:list[DataTable]): + self.measurementTables = measurementTables + + def addMeasurementTable(self, measurementTables:DataTable): + self.measurementTables.append(measurementTables) + def getModeledBy(self) -> list[Model]: return self.modeledBy @@ -141,13 +144,4 @@ def setModeledBy(self, modeledBy:list[Model]): def addModeledBy(self, modeledBy:Model): self.modeledBy.append(modeledBy) - - def getMeasurementTables(self) -> list[DataTable]: - return self.measurementTables - - def setMeasurementTables(self, measurementTables:list[DataTable]): - self.measurementTables = measurementTables - - def addMeasurementTable(self, measurementTable:DataTable): - self.measurementTables.append(measurementTable) \ No newline at end of file diff --git a/pylipd/classes/compilation.py b/pylipd/classes/compilation.py index ef79fb9..63cbb06 100644 --- a/pylipd/classes/compilation.py +++ b/pylipd/classes/compilation.py @@ -15,7 +15,7 @@ def __init__(self): self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Compilation" - self.id = self.ns + "/" + uniqid("Compilation") + self.id = self.ns + "/" + uniqid("Compilation.") @staticmethod def from_data(id, data) -> 'Compilation': @@ -30,14 +30,12 @@ def from_data(id, data) -> 'Compilation': self.type = val["@id"] elif key == "hasName": - for val in value: if "@value" in val: obj = val["@value"] self.name = obj elif key == "hasVersion": - for val in value: if "@value" in val: obj = val["@value"] @@ -46,11 +44,11 @@ def from_data(id, data) -> 'Compilation': 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={}): @@ -62,27 +60,25 @@ def to_data(self, data={}): } ] - - if self.version: - value_obj = self.version + if self.name: + value_obj = self.name obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasVersion"] = [obj] - - - if self.name: - value_obj = self.name + data[self.id]["hasName"] = [obj] + + + if self.version: + value_obj = self.version obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasName"] = [obj] - - + data[self.id]["hasVersion"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -90,7 +86,7 @@ def to_data(self, data={}): 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): @@ -114,7 +110,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 @@ -128,9 +124,10 @@ def getName(self) -> str: def setName(self, name:str): self.name = name - + def getVersion(self) -> str: return self.version def setVersion(self, version:str): self.version = version + \ No newline at end of file diff --git a/pylipd/classes/dataset.py b/pylipd/classes/dataset.py index 791232b..38785d2 100644 --- a/pylipd/classes/dataset.py +++ b/pylipd/classes/dataset.py @@ -5,42 +5,42 @@ import re from pylipd.utils import uniqid -from pylipd.classes.person import Person -from pylipd.classes.funding import Funding -from pylipd.classes.publication import Publication +from pylipd.classes.archivetype import ArchiveType from pylipd.classes.changelog import ChangeLog from pylipd.classes.chrondata import ChronData +from pylipd.classes.funding import Funding from pylipd.classes.location import Location -from pylipd.classes.archivetype import ArchiveType from pylipd.classes.paleodata import PaleoData +from pylipd.classes.person import Person +from pylipd.classes.publication import Publication class Dataset: def __init__(self): - self.dataSource: str = None - self.paleoData: list[PaleoData] = [] - self.collectionName: str = None - self.location: Location = None + self.archiveType: ArchiveType = None self.changeLog: ChangeLog = None - self.notes: str = None - self.contributor: Person = None - self.spreadsheetLink: str = None - self.name: str = None - self.version: str = None self.chronData: list[ChronData] = [] - self.datasetId: str = None - self.investigators: list[Person] = [] + self.collectionName: str = None self.collectionYear: str = None - self.archiveType: ArchiveType = None - self.originalDataUrl: str = None + self.contributor: Person = None self.creators: list[Person] = [] + self.dataSource: str = None + self.datasetId: str = None self.fundings: list[Funding] = [] + self.investigators: list[Person] = [] + self.location: Location = None + self.name: str = None + self.notes: str = None + self.originalDataUrl: str = None + self.paleoData: list[PaleoData] = [] self.publications: list[Publication] = [] + self.spreadsheetLink: str = None + self.version: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Dataset" - self.id = self.ns + "/" + uniqid("Dataset") + self.id = self.ns + "/" + uniqid("Dataset.") @staticmethod def from_data(id, data) -> 'Dataset': @@ -54,73 +54,52 @@ def from_data(id, data) -> 'Dataset': for val in value: self.type = val["@id"] - elif key == "hasSpreadsheetLink": - + elif key == "hasArchiveType": for val in value: - if "@value" in val: - obj = val["@value"] - self.spreadsheetLink = obj + obj = ArchiveType.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.archiveType = obj - elif key == "hasPublication": - + elif key == "hasChangeLog": for val in value: if "@id" in val: - obj = Publication.from_data(val["@id"], data) + obj = ChangeLog.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.changeLog = obj + + elif key == "hasChronData": + for val in value: + if "@id" in val: + obj = ChronData.from_data(val["@id"], data) else: obj = val["@value"] - self.publications.append(obj) + self.chronData.append(obj) - elif key == "hasVersion": - + elif key == "hasCollectionName": for val in value: if "@value" in val: obj = val["@value"] - self.version = obj + self.collectionName = obj elif key == "hasCollectionYear": - for val in value: if "@value" in val: obj = val["@value"] self.collectionYear = obj - elif key == "hasChangeLog": - + elif key == "hasContributor": for val in value: if "@id" in val: - obj = ChangeLog.from_data(val["@id"], data) + obj = Person.from_data(val["@id"], data) else: obj = val["@value"] - self.changeLog = obj - - elif key == "hasDatasetId": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.datasetId = obj - - elif key == "hasArchiveType": - - for val in value: - obj = ArchiveType.from_synonym(re.sub("^.*?#", "", val["@id"])) - - self.archiveType = obj - - elif key == "hasFunding": - - for val in value: - if "@id" in val: - obj = Funding.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.fundings.append(obj) + self.contributor = obj elif key == "hasCreator": - for val in value: if "@id" in val: obj = Person.from_data(val["@id"], data) @@ -129,18 +108,28 @@ def from_data(id, data) -> 'Dataset': self.creators.append(obj) - elif key == "hasPaleoData": - + elif key == "hasDataSource": + for val in value: + if "@value" in val: + obj = val["@value"] + self.dataSource = obj + + elif key == "hasDatasetId": + for val in value: + if "@value" in val: + obj = val["@value"] + self.datasetId = obj + + elif key == "hasFunding": for val in value: if "@id" in val: - obj = PaleoData.from_data(val["@id"], data) + obj = Funding.from_data(val["@id"], data) else: obj = val["@value"] - self.paleoData.append(obj) + self.fundings.append(obj) elif key == "hasInvestigator": - for val in value: if "@id" in val: obj = Person.from_data(val["@id"], data) @@ -149,79 +138,71 @@ def from_data(id, data) -> 'Dataset': self.investigators.append(obj) - elif key == "hasChronData": - + elif key == "hasLocation": for val in value: if "@id" in val: - obj = ChronData.from_data(val["@id"], data) + obj = Location.from_data(val["@id"], data) else: obj = val["@value"] - - self.chronData.append(obj) + + self.location = obj elif key == "hasName": - for val in value: if "@value" in val: obj = val["@value"] self.name = obj - elif key == "hasContributor": - + elif key == "hasNotes": for val in value: - if "@id" in val: - obj = Person.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.contributor = obj + if "@value" in val: + obj = val["@value"] + self.notes = obj elif key == "hasOriginalDataUrl": - for val in value: if "@value" in val: obj = val["@value"] self.originalDataUrl = obj - elif key == "hasCollectionName": - + elif key == "hasPaleoData": for val in value: - if "@value" in val: - obj = val["@value"] - self.collectionName = obj + if "@id" in val: + obj = PaleoData.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.paleoData.append(obj) - elif key == "hasLocation": - + elif key == "hasPublication": for val in value: if "@id" in val: - obj = Location.from_data(val["@id"], data) + obj = Publication.from_data(val["@id"], data) else: obj = val["@value"] - - self.location = obj + + self.publications.append(obj) - elif key == "hasNotes": - + elif key == "hasSpreadsheetLink": for val in value: if "@value" in val: obj = val["@value"] - self.notes = obj + self.spreadsheetLink = obj - elif key == "hasDataSource": - + elif key == "hasVersion": for val in value: if "@value" in val: obj = val["@value"] - self.dataSource = obj + self.version = 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={}): @@ -233,17 +214,36 @@ def to_data(self, data={}): } ] - - if self.notes: - value_obj = self.notes + if len(self.chronData): + data[self.id]["hasChronData"] = [] + for value_obj in self.chronData: obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" + "@id": value_obj.id, + "@type": "uri" } - data[self.id]["hasNotes"] = [obj] - - + data = value_obj.to_data(data) + data[self.id]["hasChronData"].append(obj) + + if len(self.creators): + data[self.id]["hasCreator"] = [] + for value_obj in self.creators: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasCreator"].append(obj) + + if len(self.fundings): + data[self.id]["hasFunding"] = [] + for value_obj in self.fundings: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasFunding"].append(obj) + if len(self.investigators): data[self.id]["hasInvestigator"] = [] for value_obj in self.investigators: @@ -252,9 +252,28 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasInvestigator"].append(obj) - + + if len(self.paleoData): + data[self.id]["hasPaleoData"] = [] + for value_obj in self.paleoData: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasPaleoData"].append(obj) + + if len(self.publications): + data[self.id]["hasPublication"] = [] + for value_obj in self.publications: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasPublication"].append(obj) + if self.archiveType: value_obj = self.archiveType obj = { @@ -262,21 +281,19 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasArchiveType"] = [obj] - - - if len(self.creators): - data[self.id]["hasCreator"] = [] - for value_obj in self.creators: + + + if self.changeLog: + value_obj = self.changeLog obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasCreator"].append(obj) - + data[self.id]["hasChangeLog"] = [obj] + + if self.collectionName: value_obj = self.collectionName obj = { @@ -285,28 +302,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasCollectionName"] = [obj] - - - if self.name: - value_obj = self.name + + + if self.collectionYear: + value_obj = self.collectionYear obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasName"] = [obj] - - - if self.datasetId: - value_obj = self.datasetId - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasDatasetId"] = [obj] - - + data[self.id]["hasCollectionYear"] = [obj] + + if self.contributor: value_obj = self.contributor obj = { @@ -314,126 +321,88 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasContributor"] = [obj] - - - if self.version: - value_obj = self.version + + + if self.dataSource: + value_obj = self.dataSource obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasVersion"] = [obj] - - - if len(self.publications): - data[self.id]["hasPublication"] = [] - for value_obj in self.publications: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasPublication"].append(obj) - - if len(self.chronData): - data[self.id]["hasChronData"] = [] - for value_obj in self.chronData: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasChronData"].append(obj) - - if self.changeLog: - value_obj = self.changeLog + data[self.id]["hasDataSource"] = [obj] + + + if self.datasetId: + value_obj = self.datasetId obj = { - "@id": value_obj.id, - "@type": "uri" + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data = value_obj.to_data(data) - - data[self.id]["hasChangeLog"] = [obj] - - - if len(self.paleoData): - data[self.id]["hasPaleoData"] = [] - for value_obj in self.paleoData: + data[self.id]["hasDatasetId"] = [obj] + + + if self.location: + value_obj = self.location obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasPaleoData"].append(obj) - - if self.collectionYear: - value_obj = self.collectionYear + data[self.id]["hasLocation"] = [obj] + + + if self.name: + value_obj = self.name obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasCollectionYear"] = [obj] - - - if self.spreadsheetLink: - value_obj = self.spreadsheetLink + data[self.id]["hasName"] = [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]["hasSpreadsheetLink"] = [obj] - - - if self.dataSource: - value_obj = self.dataSource + data[self.id]["hasNotes"] = [obj] + + + if self.originalDataUrl: + value_obj = self.originalDataUrl obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasDataSource"] = [obj] - - - if len(self.fundings): - data[self.id]["hasFunding"] = [] - for value_obj in self.fundings: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasFunding"].append(obj) - - if self.location: - value_obj = self.location + data[self.id]["hasOriginalDataUrl"] = [obj] + + + if self.spreadsheetLink: + value_obj = self.spreadsheetLink obj = { - "@id": value_obj.id, - "@type": "uri" + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data = value_obj.to_data(data) - - data[self.id]["hasLocation"] = [obj] - - - if self.originalDataUrl: - value_obj = self.originalDataUrl + data[self.id]["hasSpreadsheetLink"] = [obj] + + + if self.version: + value_obj = self.version obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasOriginalDataUrl"] = [obj] - - + data[self.id]["hasVersion"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -441,7 +410,7 @@ def to_data(self, data={}): 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): @@ -465,7 +434,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 @@ -474,134 +443,135 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) + def getArchiveType(self) -> ArchiveType: + return self.archiveType + + def setArchiveType(self, archiveType:ArchiveType): + self.archiveType = archiveType + + def getChangeLog(self) -> ChangeLog: + return self.changeLog + + def setChangeLog(self, changeLog:ChangeLog): + self.changeLog = changeLog + + def getChronData(self) -> list[ChronData]: + return self.chronData + + def setChronData(self, chronData:list[ChronData]): + self.chronData = chronData + + def addChronData(self, chronData:ChronData): + self.chronData.append(chronData) + def getCollectionName(self) -> str: return self.collectionName def setCollectionName(self, collectionName:str): self.collectionName = collectionName + + def getCollectionYear(self) -> str: + return self.collectionYear - def getPaleoData(self) -> list[PaleoData]: - return self.paleoData - - def setPaleoData(self, paleoData:list[PaleoData]): - self.paleoData = paleoData + def setCollectionYear(self, collectionYear:str): + self.collectionYear = collectionYear + + def getContributor(self) -> Person: + return self.contributor - def addPaleoData(self, paleoData:PaleoData): - self.paleoData.append(paleoData) - - def getPublications(self) -> list[Publication]: - return self.publications + def setContributor(self, contributor:Person): + self.contributor = contributor + + def getCreators(self) -> list[Person]: + return self.creators - def setPublications(self, publications:list[Publication]): - self.publications = publications + def setCreators(self, creators:list[Person]): + self.creators = creators - def addPublication(self, publication:Publication): - self.publications.append(publication) + def addCreator(self, creators:Person): + self.creators.append(creators) + def getDataSource(self) -> str: + return self.dataSource + + def setDataSource(self, dataSource:str): + self.dataSource = dataSource + def getDatasetId(self) -> str: return self.datasetId def setDatasetId(self, datasetId:str): self.datasetId = datasetId + + def getFundings(self) -> list[Funding]: + return self.fundings + def setFundings(self, fundings:list[Funding]): + self.fundings = fundings + + def addFunding(self, fundings:Funding): + self.fundings.append(fundings) + def getInvestigators(self) -> list[Person]: return self.investigators def setInvestigators(self, investigators:list[Person]): self.investigators = investigators - def addInvestigator(self, investigator:Person): - self.investigators.append(investigator) + def addInvestigator(self, investigators:Person): + self.investigators.append(investigators) - def getFundings(self) -> list[Funding]: - return self.fundings + def getLocation(self) -> Location: + return self.location - def setFundings(self, fundings:list[Funding]): - self.fundings = fundings + def setLocation(self, location:Location): + self.location = location + + def getName(self) -> str: + return self.name - def addFunding(self, funding:Funding): - self.fundings.append(funding) - + def setName(self, name:str): + self.name = name + def getNotes(self) -> str: return self.notes def setNotes(self, notes:str): self.notes = notes - + def getOriginalDataUrl(self) -> str: return self.originalDataUrl def setOriginalDataUrl(self, originalDataUrl:str): self.originalDataUrl = originalDataUrl + + def getPaleoData(self) -> list[PaleoData]: + return self.paleoData - def getChangeLog(self) -> ChangeLog: - return self.changeLog - - def setChangeLog(self, changeLog:ChangeLog): - self.changeLog = changeLog - - def getCollectionYear(self) -> str: - return self.collectionYear - - def setCollectionYear(self, collectionYear:str): - self.collectionYear = collectionYear - - def getContributor(self) -> Person: - return self.contributor - - def setContributor(self, contributor:Person): - self.contributor = contributor + def setPaleoData(self, paleoData:list[PaleoData]): + self.paleoData = paleoData - def getVersion(self) -> str: - return self.version + def addPaleoData(self, paleoData:PaleoData): + self.paleoData.append(paleoData) + + def getPublications(self) -> list[Publication]: + return self.publications - def setVersion(self, version:str): - self.version = version + def setPublications(self, publications:list[Publication]): + self.publications = publications + def addPublication(self, publications:Publication): + self.publications.append(publications) + def getSpreadsheetLink(self) -> str: return self.spreadsheetLink def setSpreadsheetLink(self, spreadsheetLink:str): self.spreadsheetLink = spreadsheetLink + + def getVersion(self) -> str: + return self.version - def getCreators(self) -> list[Person]: - return self.creators - - def setCreators(self, creators:list[Person]): - self.creators = creators - - def addCreator(self, creator:Person): - self.creators.append(creator) - - def getChronData(self) -> list[ChronData]: - return self.chronData - - def setChronData(self, chronData:list[ChronData]): - self.chronData = chronData - - def addChronData(self, chronData:ChronData): - self.chronData.append(chronData) - - def getDataSource(self) -> str: - return self.dataSource - - def setDataSource(self, dataSource:str): - self.dataSource = dataSource - - def getLocation(self) -> Location: - return self.location - - def setLocation(self, location:Location): - self.location = location - - def getArchiveType(self) -> ArchiveType: - return self.archiveType - - def setArchiveType(self, archiveType:ArchiveType): - self.archiveType = archiveType - - def getName(self) -> str: - return self.name - - def setName(self, name:str): - self.name = name + def setVersion(self, version:str): + self.version = version + \ No newline at end of file diff --git a/pylipd/classes/datatable.py b/pylipd/classes/datatable.py index 85d219a..8c5330c 100644 --- a/pylipd/classes/datatable.py +++ b/pylipd/classes/datatable.py @@ -17,7 +17,7 @@ def __init__(self): self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#DataTable" - self.id = self.ns + "/" + uniqid("DataTable") + self.id = self.ns + "/" + uniqid("DataTable.") @staticmethod def from_data(id, data) -> 'DataTable': @@ -32,14 +32,18 @@ def from_data(id, data) -> 'DataTable': self.type = val["@id"] elif key == "hasFileName": - for val in value: if "@value" in val: obj = val["@value"] self.fileName = obj + elif key == "hasMissingValue": + for val in value: + if "@value" in val: + obj = val["@value"] + self.missingValue = obj + elif key == "hasVariable": - for val in value: if "@id" in val: obj = Variable.from_data(val["@id"], data) @@ -47,22 +51,15 @@ def from_data(id, data) -> 'DataTable': obj = val["@value"] self.variables.append(obj) - - elif key == "hasMissingValue": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.missingValue = 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={}): @@ -74,7 +71,16 @@ def to_data(self, data={}): } ] - + if len(self.variables): + data[self.id]["hasVariable"] = [] + for value_obj in self.variables: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasVariable"].append(obj) + if self.fileName: value_obj = self.fileName obj = { @@ -83,8 +89,8 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasFileName"] = [obj] - - + + if self.missingValue: value_obj = self.missingValue obj = { @@ -93,19 +99,7 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasMissingValue"] = [obj] - - - if len(self.variables): - data[self.id]["hasVariable"] = [] - for value_obj in self.variables: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasVariable"].append(obj) - + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -113,7 +107,7 @@ def to_data(self, data={}): 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): @@ -137,7 +131,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 @@ -146,24 +140,24 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getMissingValue(self) -> str: - return self.missingValue - - def setMissingValue(self, missingValue:str): - self.missingValue = missingValue - def getFileName(self) -> str: return self.fileName def setFileName(self, fileName:str): self.fileName = fileName + + def getMissingValue(self) -> str: + return self.missingValue + def setMissingValue(self, missingValue:str): + self.missingValue = missingValue + def getVariables(self) -> list[Variable]: return self.variables def setVariables(self, variables:list[Variable]): self.variables = variables - def addVariable(self, variable:Variable): - self.variables.append(variable) + def addVariable(self, variables:Variable): + self.variables.append(variables) \ No newline at end of file diff --git a/pylipd/classes/funding.py b/pylipd/classes/funding.py index 8803b1c..863baad 100644 --- a/pylipd/classes/funding.py +++ b/pylipd/classes/funding.py @@ -10,15 +10,15 @@ class Funding: def __init__(self): + self.fundingAgency: str = None self.fundingCountry: str = None self.grants: list[str] = [] self.investigators: list[Person] = [] - self.fundingAgency: str = None 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") + self.id = self.ns + "/" + uniqid("Funding.") @staticmethod def from_data(id, data) -> 'Funding': @@ -33,21 +33,24 @@ def from_data(id, data) -> 'Funding': 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) @@ -55,22 +58,15 @@ def from_data(id, data) -> 'Funding': obj = val["@value"] self.investigators.append(obj) - - elif key == "hasGrant": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.grants.append(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={}): @@ -82,7 +78,16 @@ def to_data(self, data={}): } ] - + 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: @@ -91,39 +96,27 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasInvestigator"].append(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] - - - if len(self.grants): - data[self.id]["hasGrant"] = [] - for value_obj in self.grants: + + if self.fundingAgency: + value_obj = self.fundingAgency obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasGrant"].append(obj) - - if self.fundingAgency: - value_obj = self.fundingAgency + 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]["hasFundingAgency"] = [obj] - - + data[self.id]["hasFundingCountry"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -131,7 +124,7 @@ def to_data(self, data={}): 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): @@ -155,7 +148,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 @@ -164,33 +157,33 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getGrants(self) -> list[str]: - return self.grants - - def setGrants(self, grants:list[str]): - self.grants = grants + def getFundingAgency(self) -> str: + return self.fundingAgency - def addGrant(self, grant:str): - self.grants.append(grant) - + def setFundingAgency(self, fundingAgency:str): + self.fundingAgency = fundingAgency + def getFundingCountry(self) -> str: return self.fundingCountry def setFundingCountry(self, fundingCountry:str): self.fundingCountry = fundingCountry + + def getGrants(self) -> list[str]: + return self.grants - def getFundingAgency(self) -> str: - return self.fundingAgency - - def setFundingAgency(self, fundingAgency:str): - self.fundingAgency = fundingAgency + def setGrants(self, grants:list[str]): + self.grants = grants + def addGrant(self, grants:str): + self.grants.append(grants) + def getInvestigators(self) -> list[Person]: return self.investigators def setInvestigators(self, investigators:list[Person]): self.investigators = investigators - def addInvestigator(self, investigator:Person): - self.investigators.append(investigator) + def addInvestigator(self, investigators:Person): + self.investigators.append(investigators) \ No newline at end of file diff --git a/pylipd/classes/independentvariable.py b/pylipd/classes/independentvariable.py index 78f7daf..e1804ae 100644 --- a/pylipd/classes/independentvariable.py +++ b/pylipd/classes/independentvariable.py @@ -9,15 +9,15 @@ class IndependentVariable: def __init__(self): - self.relevantQuote: str = None - self.rank: str = None self.equation: str = None self.interpretationDirection: str = None + self.rank: str = None + self.relevantQuote: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#IndependentVariable" - self.id = self.ns + "/" + uniqid("IndependentVariable") + self.id = self.ns + "/" + uniqid("IndependentVariable.") @staticmethod def from_data(id, data) -> 'IndependentVariable': @@ -31,42 +31,38 @@ def from_data(id, data) -> 'IndependentVariable': for val in value: self.type = val["@id"] - elif key == "hasRank": - + elif key == "equation": for val in value: if "@value" in val: obj = val["@value"] - self.rank = obj + self.equation = obj - elif key == "relevantQuote": - + elif key == "hasRank": for val in value: if "@value" in val: obj = val["@value"] - self.relevantQuote = obj + self.rank = obj elif key == "interpretationDirection": - for val in value: if "@value" in val: obj = val["@value"] self.interpretationDirection = obj - elif key == "equation": - + elif key == "relevantQuote": for val in value: if "@value" in val: obj = val["@value"] - self.equation = obj + self.relevantQuote = 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={}): @@ -78,17 +74,6 @@ def to_data(self, data={}): } ] - - if self.interpretationDirection: - value_obj = self.interpretationDirection - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["interpretationDirection"] = [obj] - - if self.equation: value_obj = self.equation obj = { @@ -97,18 +82,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["equation"] = [obj] - - - if self.relevantQuote: - value_obj = self.relevantQuote + + + if self.interpretationDirection: + value_obj = self.interpretationDirection obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["relevantQuote"] = [obj] - - + data[self.id]["interpretationDirection"] = [obj] + + if self.rank: value_obj = self.rank obj = { @@ -117,8 +102,17 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasRank"] = [obj] - + + if self.relevantQuote: + value_obj = self.relevantQuote + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["relevantQuote"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -126,7 +120,7 @@ def to_data(self, data={}): 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): @@ -150,7 +144,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 @@ -159,26 +153,27 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) + def getEquation(self) -> str: + return self.equation + + def setEquation(self, equation:str): + self.equation = equation + def getInterpretationDirection(self) -> str: return self.interpretationDirection def setInterpretationDirection(self, interpretationDirection:str): self.interpretationDirection = interpretationDirection - - def getRelevantQuote(self) -> str: - return self.relevantQuote - - def setRelevantQuote(self, relevantQuote:str): - self.relevantQuote = relevantQuote - + def getRank(self) -> str: return self.rank def setRank(self, rank:str): self.rank = rank + + def getRelevantQuote(self) -> str: + return self.relevantQuote - def getEquation(self) -> str: - return self.equation - - def setEquation(self, equation:str): - self.equation = equation + def setRelevantQuote(self, relevantQuote:str): + self.relevantQuote = relevantQuote + \ No newline at end of file diff --git a/pylipd/classes/integrationtime.py b/pylipd/classes/integrationtime.py index 8c3c544..b35c473 100644 --- a/pylipd/classes/integrationtime.py +++ b/pylipd/classes/integrationtime.py @@ -11,14 +11,14 @@ class IntegrationTime: def __init__(self): + self.independentVariables: list[IndependentVariable] = [] self.relevantQuote: str = None self.units: PaleoUnit = None - self.independentVariables: list[IndependentVariable] = [] self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#IntegrationTime" - self.id = self.ns + "/" + uniqid("IntegrationTime") + self.id = self.ns + "/" + uniqid("IntegrationTime.") @staticmethod def from_data(id, data) -> 'IntegrationTime': @@ -32,38 +32,35 @@ def from_data(id, data) -> 'IntegrationTime': for val in value: self.type = val["@id"] - elif key == "relevantQuote": - + elif key == "hasIndependentVariable": for val in value: - if "@value" in val: - obj = val["@value"] - self.relevantQuote = obj + if "@id" in val: + obj = IndependentVariable.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.independentVariables.append(obj) elif key == "hasUnits": - for val in value: obj = PaleoUnit.from_synonym(re.sub("^.*?#", "", val["@id"])) self.units = obj - elif key == "hasIndependentVariable": - + elif key == "relevantQuote": for val in value: - if "@id" in val: - obj = IndependentVariable.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.independentVariables.append(obj) + if "@value" in val: + obj = val["@value"] + self.relevantQuote = 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={}): @@ -75,18 +72,16 @@ def to_data(self, data={}): } ] - - if self.units: - value_obj = self.units + if len(self.independentVariables): + data[self.id]["hasIndependentVariable"] = [] + for value_obj in self.independentVariables: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasUnits"] = [obj] - - + data[self.id]["hasIndependentVariable"].append(obj) + if self.relevantQuote: value_obj = self.relevantQuote obj = { @@ -95,19 +90,17 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["relevantQuote"] = [obj] - - - if len(self.independentVariables): - data[self.id]["hasIndependentVariable"] = [] - for value_obj in self.independentVariables: + + + if self.units: + value_obj = self.units obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasIndependentVariable"].append(obj) - + data[self.id]["hasUnits"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -115,7 +108,7 @@ def to_data(self, data={}): 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): @@ -139,7 +132,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 @@ -154,17 +147,18 @@ def getIndependentVariables(self) -> list[IndependentVariable]: def setIndependentVariables(self, independentVariables:list[IndependentVariable]): self.independentVariables = independentVariables - def addIndependentVariable(self, independentVariable:IndependentVariable): - self.independentVariables.append(independentVariable) + def addIndependentVariable(self, independentVariables:IndependentVariable): + self.independentVariables.append(independentVariables) def getRelevantQuote(self) -> str: return self.relevantQuote def setRelevantQuote(self, relevantQuote:str): self.relevantQuote = relevantQuote - + def getUnits(self) -> PaleoUnit: return self.units def setUnits(self, units:PaleoUnit): self.units = units + \ No newline at end of file diff --git a/pylipd/classes/interpretation.py b/pylipd/classes/interpretation.py index 061ae4f..4690b10 100644 --- a/pylipd/classes/interpretation.py +++ b/pylipd/classes/interpretation.py @@ -6,32 +6,32 @@ import re from pylipd.utils import uniqid from pylipd.classes.integrationtime import IntegrationTime -from pylipd.classes.interpretationvariable import InterpretationVariable from pylipd.classes.interpretationseasonality import InterpretationSeasonality +from pylipd.classes.interpretationvariable import InterpretationVariable class Interpretation: def __init__(self): - self.variableGeneral: str = None - self.local: str = None - self.seasonalityOriginal: InterpretationSeasonality = None - self.variableDetail: str = None - self.rank: str = None - self.variable: InterpretationVariable = None - self.variableGeneralDirection: str = None self.basis: str = None - self.seasonalityGeneral: InterpretationSeasonality = None - self.notes: str = None - self.scope: str = None + self.integrationTime: IntegrationTime = None self.interpretationDirection: str = None + self.local: str = None self.mathematicalRelation: str = None - self.integrationTime: IntegrationTime = None + self.notes: str = None + self.rank: str = None + self.scope: str = None self.seasonality: InterpretationSeasonality = None + self.seasonalityGeneral: InterpretationSeasonality = None + self.seasonalityOriginal: InterpretationSeasonality = None + self.variable: InterpretationVariable = None + self.variableDetail: str = None + self.variableGeneral: str = None + self.variableGeneralDirection: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Interpretation" - self.id = self.ns + "/" + uniqid("Interpretation") + self.id = self.ns + "/" + uniqid("Interpretation.") @staticmethod def from_data(id, data) -> 'Interpretation': @@ -45,122 +45,107 @@ def from_data(id, data) -> 'Interpretation': for val in value: self.type = val["@id"] - elif key == "hasRank": - + elif key == "hasBasis": for val in value: if "@value" in val: obj = val["@value"] - self.rank = obj + self.basis = obj - elif key == "hasSeasonalityGeneral": - + elif key == "hasIntegrationTime": for val in value: - obj = InterpretationSeasonality.from_synonym(re.sub("^.*?#", "", val["@id"])) + if "@id" in val: + obj = IntegrationTime.from_data(val["@id"], data) + else: + obj = val["@value"] - self.seasonalityGeneral = obj + self.integrationTime = obj + + elif key == "hasInterpretationDirection": + for val in value: + if "@value" in val: + obj = val["@value"] + self.interpretationDirection = obj + + elif key == "hasMathematicalRelation": + for val in value: + if "@value" in val: + obj = val["@value"] + self.mathematicalRelation = obj elif key == "hasNotes": - for val in value: if "@value" in val: obj = val["@value"] self.notes = obj - elif key == "hasVariableGeneral": - + elif key == "hasRank": for val in value: if "@value" in val: obj = val["@value"] - self.variableGeneral = obj + self.rank = obj - elif key == "hasVariableGeneralDirection": - + elif key == "hasScope": for val in value: if "@value" in val: obj = val["@value"] - self.variableGeneralDirection = obj + self.scope = obj - elif key == "hasSeasonalityOriginal": - + elif key == "hasSeasonality": for val in value: obj = InterpretationSeasonality.from_synonym(re.sub("^.*?#", "", val["@id"])) - self.seasonalityOriginal = obj + self.seasonality = obj - elif key == "hasIntegrationTime": - + elif key == "hasSeasonalityGeneral": for val in value: - if "@id" in val: - obj = IntegrationTime.from_data(val["@id"], data) - else: - obj = val["@value"] + obj = InterpretationSeasonality.from_synonym(re.sub("^.*?#", "", val["@id"])) - self.integrationTime = obj + self.seasonalityGeneral = obj - elif key == "hasBasis": - + elif key == "hasSeasonalityOriginal": for val in value: - if "@value" in val: - obj = val["@value"] - self.basis = obj + obj = InterpretationSeasonality.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.seasonalityOriginal = obj elif key == "hasVariable": - for val in value: obj = InterpretationVariable.from_synonym(re.sub("^.*?#", "", val["@id"])) self.variable = obj - elif key == "hasScope": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.scope = obj - elif key == "hasVariableDetail": - for val in value: if "@value" in val: obj = val["@value"] self.variableDetail = obj - elif key == "hasInterpretationDirection": - + elif key == "hasVariableGeneral": for val in value: if "@value" in val: obj = val["@value"] - self.interpretationDirection = obj + self.variableGeneral = obj - elif key == "hasMathematicalRelation": - + elif key == "hasVariableGeneralDirection": for val in value: if "@value" in val: obj = val["@value"] - self.mathematicalRelation = obj + self.variableGeneralDirection = obj elif key == "isLocal": - for val in value: if "@value" in val: obj = val["@value"] self.local = obj - - elif key == "hasSeasonality": - - for val in value: - obj = InterpretationSeasonality.from_synonym(re.sub("^.*?#", "", val["@id"])) - - 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={}): @@ -172,79 +157,46 @@ def to_data(self, data={}): } ] - - if self.interpretationDirection: - value_obj = self.interpretationDirection - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasInterpretationDirection"] = [obj] - - - if self.notes: - value_obj = self.notes + if self.basis: + value_obj = self.basis obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasNotes"] = [obj] - - - if self.scope: - value_obj = self.scope + data[self.id]["hasBasis"] = [obj] + + + if self.integrationTime: + value_obj = self.integrationTime obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" + "@id": value_obj.id, + "@type": "uri" } - data[self.id]["hasScope"] = [obj] - - - if self.variableGeneralDirection: - value_obj = self.variableGeneralDirection + data = value_obj.to_data(data) + data[self.id]["hasIntegrationTime"] = [obj] + + + if self.interpretationDirection: + value_obj = self.interpretationDirection obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasVariableGeneralDirection"] = [obj] - - - if self.rank: - value_obj = self.rank + data[self.id]["hasInterpretationDirection"] = [obj] + + + if self.local: + value_obj = self.local obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasRank"] = [obj] - - - if self.variable: - value_obj = self.variable - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasVariable"] = [obj] - - - if self.seasonality: - value_obj = self.seasonality - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasSeasonality"] = [obj] - - + data[self.id]["isLocal"] = [obj] + + if self.mathematicalRelation: value_obj = self.mathematicalRelation obj = { @@ -253,49 +205,48 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasMathematicalRelation"] = [obj] - - - if self.variableGeneral: - value_obj = self.variableGeneral + + + if self.notes: + value_obj = self.notes obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasVariableGeneral"] = [obj] - - - if self.variableDetail: - value_obj = self.variableDetail + data[self.id]["hasNotes"] = [obj] + + + if self.rank: + value_obj = self.rank obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasVariableDetail"] = [obj] - - - if self.basis: - value_obj = self.basis + data[self.id]["hasRank"] = [obj] + + + if self.scope: + value_obj = self.scope obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasBasis"] = [obj] - - - if self.seasonalityOriginal: - value_obj = self.seasonalityOriginal + data[self.id]["hasScope"] = [obj] + + + if self.seasonality: + value_obj = self.seasonality obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasSeasonalityOriginal"] = [obj] - - + data[self.id]["hasSeasonality"] = [obj] + + if self.seasonalityGeneral: value_obj = self.seasonalityGeneral obj = { @@ -303,31 +254,58 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasSeasonalityGeneral"] = [obj] - - - if self.integrationTime: - value_obj = self.integrationTime + + + if self.seasonalityOriginal: + value_obj = self.seasonalityOriginal obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasIntegrationTime"] = [obj] - - - if self.local: - value_obj = self.local + data[self.id]["hasSeasonalityOriginal"] = [obj] + + + if self.variable: + value_obj = self.variable + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasVariable"] = [obj] + + + if self.variableDetail: + value_obj = self.variableDetail obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["isLocal"] = [obj] - + data[self.id]["hasVariableDetail"] = [obj] + + + if self.variableGeneral: + value_obj = self.variableGeneral + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["hasVariableGeneral"] = [obj] + + if self.variableGeneralDirection: + value_obj = self.variableGeneralDirection + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["hasVariableGeneralDirection"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -335,7 +313,7 @@ def to_data(self, data={}): 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): @@ -359,7 +337,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 @@ -368,92 +346,93 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getVariable(self) -> InterpretationVariable: - return self.variable - - def setVariable(self, variable:InterpretationVariable): - self.variable = variable - - def getNotes(self) -> str: - return self.notes - - def setNotes(self, notes:str): - self.notes = notes - def getBasis(self) -> str: return self.basis def setBasis(self, basis:str): self.basis = basis + + def getIntegrationTime(self) -> IntegrationTime: + return self.integrationTime + + def setIntegrationTime(self, integrationTime:IntegrationTime): + self.integrationTime = integrationTime + + def getInterpretationDirection(self) -> str: + return self.interpretationDirection + def setInterpretationDirection(self, interpretationDirection:str): + self.interpretationDirection = interpretationDirection + def getMathematicalRelation(self) -> str: return self.mathematicalRelation def setMathematicalRelation(self, mathematicalRelation:str): self.mathematicalRelation = mathematicalRelation + + def getNotes(self) -> str: + return self.notes - def getVariableDetail(self) -> str: - return self.variableDetail - - def setVariableDetail(self, variableDetail:str): - self.variableDetail = variableDetail - - def getVariableGeneralDirection(self) -> str: - return self.variableGeneralDirection - - def setVariableGeneralDirection(self, variableGeneralDirection:str): - self.variableGeneralDirection = variableGeneralDirection - - def getSeasonality(self) -> InterpretationSeasonality: - return self.seasonality - - def setSeasonality(self, seasonality:InterpretationSeasonality): - self.seasonality = seasonality - + def setNotes(self, notes:str): + self.notes = notes + def getRank(self) -> str: return self.rank def setRank(self, rank:str): self.rank = rank - + def getScope(self) -> str: return self.scope def setScope(self, scope:str): self.scope = scope + + def getSeasonality(self) -> InterpretationSeasonality: + return self.seasonality - def getIntegrationTime(self) -> IntegrationTime: - return self.integrationTime - - def setIntegrationTime(self, integrationTime:IntegrationTime): - self.integrationTime = integrationTime - + def setSeasonality(self, seasonality:InterpretationSeasonality): + self.seasonality = seasonality + def getSeasonalityGeneral(self) -> InterpretationSeasonality: return self.seasonalityGeneral def setSeasonalityGeneral(self, seasonalityGeneral:InterpretationSeasonality): self.seasonalityGeneral = seasonalityGeneral - + def getSeasonalityOriginal(self) -> InterpretationSeasonality: return self.seasonalityOriginal def setSeasonalityOriginal(self, seasonalityOriginal:InterpretationSeasonality): self.seasonalityOriginal = seasonalityOriginal + + def getVariable(self) -> InterpretationVariable: + return self.variable + def setVariable(self, variable:InterpretationVariable): + self.variable = variable + + def getVariableDetail(self) -> str: + return self.variableDetail + + def setVariableDetail(self, variableDetail:str): + self.variableDetail = variableDetail + def getVariableGeneral(self) -> str: return self.variableGeneral def setVariableGeneral(self, variableGeneral:str): self.variableGeneral = variableGeneral + + def getVariableGeneralDirection(self) -> str: + return self.variableGeneralDirection - def getInterpretationDirection(self) -> str: - return self.interpretationDirection - - def setInterpretationDirection(self, interpretationDirection:str): - self.interpretationDirection = interpretationDirection - + def setVariableGeneralDirection(self, variableGeneralDirection:str): + self.variableGeneralDirection = variableGeneralDirection + def isLocal(self) -> str: return self.local def setLocal(self, local:str): self.local = local + \ No newline at end of file diff --git a/pylipd/classes/interpretationseasonality.py b/pylipd/classes/interpretationseasonality.py index f167be1..f44ccc2 100644 --- a/pylipd/classes/interpretationseasonality.py +++ b/pylipd/classes/interpretationseasonality.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class InterpretationSeasonality: synonyms = SYNONYMS["INTERPRETATION"]["InterpretationSeasonality"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = InterpretationSeasonality.synonyms[synonym.lower()] return InterpretationSeasonality(synobj['id'], synobj['label']) return None - + class InterpretationSeasonalityConstants: Annual = InterpretationSeasonality("http://linked.earth/ontology/interpretation#Annual", "Annual") Winter = InterpretationSeasonality("http://linked.earth/ontology/interpretation#Winter", "Winter") diff --git a/pylipd/classes/interpretationvariable.py b/pylipd/classes/interpretationvariable.py index b283bd7..583ec9e 100644 --- a/pylipd/classes/interpretationvariable.py +++ b/pylipd/classes/interpretationvariable.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class InterpretationVariable: synonyms = SYNONYMS["INTERPRETATION"]["InterpretationVariable"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = InterpretationVariable.synonyms[synonym.lower()] return InterpretationVariable(synobj['id'], synobj['label']) return None - + class InterpretationVariableConstants: C3C4Ratio = InterpretationVariable("http://linked.earth/ontology/interpretation#C3C4Ratio", "C3C4Ratio") circulationIndex = InterpretationVariable("http://linked.earth/ontology/interpretation#circulationIndex", "circulationIndex") diff --git a/pylipd/classes/isotopeinterpretation.py b/pylipd/classes/isotopeinterpretation.py index 49ce702..44999ec 100644 --- a/pylipd/classes/isotopeinterpretation.py +++ b/pylipd/classes/isotopeinterpretation.py @@ -5,19 +5,19 @@ import re from pylipd.utils import uniqid -from pylipd.classes.integrationtime import IntegrationTime from pylipd.classes.independentvariable import IndependentVariable +from pylipd.classes.integrationtime import IntegrationTime class IsotopeInterpretation: def __init__(self): - self.integrationTime: IntegrationTime = None self.independentVariables: list[IndependentVariable] = [] + self.integrationTime: IntegrationTime = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#IsotopeInterpretation" - self.id = self.ns + "/" + uniqid("IsotopeInterpretation") + self.id = self.ns + "/" + uniqid("IsotopeInterpretation.") @staticmethod def from_data(id, data) -> 'IsotopeInterpretation': @@ -31,34 +31,32 @@ def from_data(id, data) -> 'IsotopeInterpretation': for val in value: self.type = val["@id"] - elif key == "hasIntegrationTime": - + elif key == "hasIndependentVariable": for val in value: if "@id" in val: - obj = IntegrationTime.from_data(val["@id"], data) + obj = IndependentVariable.from_data(val["@id"], data) else: obj = val["@value"] - - self.integrationTime = obj + + self.independentVariables.append(obj) - elif key == "hasIndependentVariable": - + elif key == "hasIntegrationTime": for val in value: if "@id" in val: - obj = IndependentVariable.from_data(val["@id"], data) + obj = IntegrationTime.from_data(val["@id"], data) else: obj = val["@value"] - - self.independentVariables.append(obj) + + self.integrationTime = 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={}): @@ -70,18 +68,6 @@ def to_data(self, data={}): } ] - - if self.integrationTime: - value_obj = self.integrationTime - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasIntegrationTime"] = [obj] - - if len(self.independentVariables): data[self.id]["hasIndependentVariable"] = [] for value_obj in self.independentVariables: @@ -90,9 +76,17 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasIndependentVariable"].append(obj) + if self.integrationTime: + value_obj = self.integrationTime + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasIntegrationTime"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -100,7 +94,7 @@ def to_data(self, data={}): 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): @@ -124,7 +118,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 @@ -139,11 +133,12 @@ def getIndependentVariables(self) -> list[IndependentVariable]: def setIndependentVariables(self, independentVariables:list[IndependentVariable]): self.independentVariables = independentVariables - def addIndependentVariable(self, independentVariable:IndependentVariable): - self.independentVariables.append(independentVariable) + def addIndependentVariable(self, independentVariables:IndependentVariable): + self.independentVariables.append(independentVariables) def getIntegrationTime(self) -> IntegrationTime: return self.integrationTime def setIntegrationTime(self, integrationTime:IntegrationTime): self.integrationTime = integrationTime + \ No newline at end of file diff --git a/pylipd/classes/location.py b/pylipd/classes/location.py index 132410d..40a741a 100644 --- a/pylipd/classes/location.py +++ b/pylipd/classes/location.py @@ -9,25 +9,25 @@ class Location: def __init__(self): - self.elevation: str = None - self.countryOcean: str = None - self.latitude: str = None - self.geometryType: str = None - self.description: str = None self.continent: str = None - self.notes: str = None - self.longitude: str = None self.coordinates: str = None + self.coordinatesFor: None = None + self.country: str = None + self.countryOcean: str = None + self.description: str = None + self.elevation: str = None + self.geometryType: str = None + self.latitude: str = None self.locationName: str = None + self.longitude: str = None + self.notes: str = None self.ocean: str = None - self.coordinatesFor: None = None self.siteName: str = None - self.country: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Location" - self.id = self.ns + "/" + uniqid("Location") + self.id = self.ns + "/" + uniqid("Location.") @staticmethod def from_data(id, data) -> 'Location': @@ -41,111 +41,97 @@ def from_data(id, data) -> 'Location': for val in value: self.type = val["@id"] - elif key == "hasCountry": - + elif key == "coordinates": for val in value: if "@value" in val: obj = val["@value"] - self.country = obj + self.coordinates = obj - elif key == "hasLocationName": - + elif key == "coordinatesFor": for val in value: - if "@value" in val: - obj = val["@value"] - self.locationName = obj + obj = val["@id"] + self.coordinatesFor = obj - elif key == "hasGeometryType": - + elif key == "hasContinent": for val in value: if "@value" in val: obj = val["@value"] - self.geometryType = obj + self.continent = obj - elif key == "hasNotes": - + elif key == "hasCountry": for val in value: if "@value" in val: obj = val["@value"] - self.notes = obj - - elif key == "coordinatesFor": - - for val in value: - obj = val["@id"] - self.coordinatesFor = obj + self.country = obj - elif key == "hasLatitude": - + elif key == "hasCountryOcean": for val in value: if "@value" in val: obj = val["@value"] - self.latitude = obj + self.countryOcean = obj elif key == "hasDescription": - for val in value: if "@value" in val: obj = val["@value"] self.description = obj elif key == "hasElevation": - for val in value: if "@value" in val: obj = val["@value"] self.elevation = obj - elif key == "hasLongitude": - + elif key == "hasGeometryType": for val in value: if "@value" in val: obj = val["@value"] - self.longitude = obj + self.geometryType = obj - elif key == "hasSiteName": - + elif key == "hasLatitude": for val in value: if "@value" in val: obj = val["@value"] - self.siteName = obj + self.latitude = obj - elif key == "hasOcean": - + elif key == "hasLocationName": for val in value: if "@value" in val: obj = val["@value"] - self.ocean = obj + self.locationName = obj - elif key == "hasCountryOcean": - + elif key == "hasLongitude": for val in value: if "@value" in val: obj = val["@value"] - self.countryOcean = obj + self.longitude = obj - elif key == "coordinates": - + elif key == "hasNotes": for val in value: if "@value" in val: obj = val["@value"] - self.coordinates = obj + self.notes = obj - elif key == "hasContinent": - + elif key == "hasOcean": for val in value: if "@value" in val: obj = val["@value"] - self.continent = obj + self.ocean = obj + + elif key == "hasSiteName": + for val in value: + if "@value" in val: + obj = val["@value"] + self.siteName = 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={}): @@ -157,17 +143,35 @@ def to_data(self, data={}): } ] - - if self.notes: - value_obj = self.notes + if self.continent: + value_obj = self.continent obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasNotes"] = [obj] - - + data[self.id]["hasContinent"] = [obj] + + + if self.coordinates: + value_obj = self.coordinates + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["coordinates"] = [obj] + + + if self.coordinatesFor: + value_obj = self.coordinatesFor + obj = { + "@id": value_obj, + "@type": "uri" + } + data[self.id]["coordinatesFor"] = [obj] + + if self.country: value_obj = self.country obj = { @@ -176,8 +180,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasCountry"] = [obj] - - + + + if self.countryOcean: + value_obj = self.countryOcean + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["hasCountryOcean"] = [obj] + + if self.description: value_obj = self.description obj = { @@ -186,27 +200,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasDescription"] = [obj] - - - if self.continent: - value_obj = self.continent + + + if self.elevation: + value_obj = self.elevation obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasContinent"] = [obj] - - - if self.coordinatesFor: - value_obj = self.coordinatesFor - obj = { - "@id": value_obj, - "@type": "uri" - } - data[self.id]["coordinatesFor"] = [obj] - - + data[self.id]["hasElevation"] = [obj] + + if self.geometryType: value_obj = self.geometryType obj = { @@ -215,18 +220,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasGeometryType"] = [obj] - - - if self.countryOcean: - value_obj = self.countryOcean + + + if self.latitude: + value_obj = self.latitude obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasCountryOcean"] = [obj] - - + data[self.id]["hasLatitude"] = [obj] + + if self.locationName: value_obj = self.locationName obj = { @@ -235,8 +240,8 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasLocationName"] = [obj] - - + + if self.longitude: value_obj = self.longitude obj = { @@ -245,58 +250,37 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasLongitude"] = [obj] - - - if self.siteName: - value_obj = self.siteName - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasSiteName"] = [obj] - - - if self.elevation: - value_obj = self.elevation - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasElevation"] = [obj] - - - if self.latitude: - value_obj = self.latitude + + + if self.notes: + value_obj = self.notes obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasLatitude"] = [obj] - - - if self.coordinates: - value_obj = self.coordinates + data[self.id]["hasNotes"] = [obj] + + + if self.ocean: + value_obj = self.ocean obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["coordinates"] = [obj] - - - if self.ocean: - value_obj = self.ocean + data[self.id]["hasOcean"] = [obj] + + + if self.siteName: + value_obj = self.siteName obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasOcean"] = [obj] - - + data[self.id]["hasSiteName"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -304,7 +288,7 @@ def to_data(self, data={}): 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): @@ -328,7 +312,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 @@ -337,86 +321,87 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getCoordinates(self) -> str: - return self.coordinates - - def setCoordinates(self, coordinates:str): - self.coordinates = coordinates - - def getLongitude(self) -> str: - return self.longitude - - def setLongitude(self, longitude:str): - self.longitude = longitude - - def getNotes(self) -> str: - return self.notes - - def setNotes(self, notes:str): - self.notes = notes - - def getSiteName(self) -> str: - return self.siteName - - def setSiteName(self, siteName:str): - self.siteName = siteName - - def getDescription(self) -> str: - return self.description - - def setDescription(self, description:str): - self.description = description - def getContinent(self) -> str: return self.continent def setContinent(self, continent:str): self.continent = continent + + def getCoordinates(self) -> str: + return self.coordinates - def getOcean(self) -> str: - return self.ocean + def setCoordinates(self, coordinates:str): + self.coordinates = coordinates + + def getCoordinatesFor(self) -> None: + return self.coordinatesFor - def setOcean(self, ocean:str): - self.ocean = ocean + def setCoordinatesFor(self, coordinatesFor:None): + self.coordinatesFor = coordinatesFor + + def getCountry(self) -> str: + return self.country + def setCountry(self, country:str): + self.country = country + def getCountryOcean(self) -> str: return self.countryOcean def setCountryOcean(self, countryOcean:str): self.countryOcean = countryOcean + + def getDescription(self) -> str: + return self.description - def getLocationName(self) -> str: - return self.locationName - - def setLocationName(self, locationName:str): - self.locationName = locationName - - def getCountry(self) -> str: - return self.country - - def setCountry(self, country:str): - self.country = country - + def setDescription(self, description:str): + self.description = description + def getElevation(self) -> str: return self.elevation def setElevation(self, elevation:str): self.elevation = elevation + + def getGeometryType(self) -> str: + return self.geometryType + def setGeometryType(self, geometryType:str): + self.geometryType = geometryType + def getLatitude(self) -> str: return self.latitude def setLatitude(self, latitude:str): self.latitude = latitude + + def getLocationName(self) -> str: + return self.locationName - def getGeometryType(self) -> str: - return self.geometryType + def setLocationName(self, locationName:str): + self.locationName = locationName + + def getLongitude(self) -> str: + return self.longitude - def setGeometryType(self, geometryType:str): - self.geometryType = geometryType + def setLongitude(self, longitude:str): + self.longitude = longitude + + def getNotes(self) -> str: + return self.notes - def getCoordinatesFor(self) -> None: - return self.coordinatesFor + def setNotes(self, notes:str): + self.notes = notes + + def getOcean(self) -> str: + return self.ocean - def setCoordinatesFor(self, coordinatesFor:None): - self.coordinatesFor = coordinatesFor + def setOcean(self, ocean:str): + self.ocean = ocean + + def getSiteName(self) -> str: + return self.siteName + + def setSiteName(self, siteName:str): + self.siteName = siteName + \ No newline at end of file diff --git a/pylipd/classes/model.py b/pylipd/classes/model.py index f05154d..4465490 100644 --- a/pylipd/classes/model.py +++ b/pylipd/classes/model.py @@ -10,15 +10,15 @@ class Model: def __init__(self): - self.ensembleTables: list[DataTable] = [] - self.distributionTables: list[DataTable] = [] self.code: str = None + self.distributionTables: list[DataTable] = [] + self.ensembleTables: list[DataTable] = [] self.summaryTables: list[DataTable] = [] self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Model" - self.id = self.ns + "/" + uniqid("Model") + self.id = self.ns + "/" + uniqid("Model.") @staticmethod def from_data(id, data) -> 'Model': @@ -32,51 +32,47 @@ def from_data(id, data) -> 'Model': for val in value: self.type = val["@id"] - elif key == "hasEnsembleTable": - + elif key == "hasCode": + for val in value: + if "@value" in val: + obj = val["@value"] + self.code = obj + + elif key == "hasDistributionTable": for val in value: if "@id" in val: obj = DataTable.from_data(val["@id"], data) else: obj = val["@value"] - self.ensembleTables.append(obj) + self.distributionTables.append(obj) - elif key == "hasSummaryTable": - + elif key == "hasEnsembleTable": for val in value: if "@id" in val: obj = DataTable.from_data(val["@id"], data) else: obj = val["@value"] - self.summaryTables.append(obj) + self.ensembleTables.append(obj) - elif key == "hasDistributionTable": - + elif key == "hasSummaryTable": for val in value: if "@id" in val: obj = DataTable.from_data(val["@id"], data) else: obj = val["@value"] - self.distributionTables.append(obj) - - elif key == "hasCode": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.code = obj + self.summaryTables.append(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={}): @@ -88,17 +84,16 @@ def to_data(self, data={}): } ] - - if self.code: - value_obj = self.code + if len(self.distributionTables): + data[self.id]["hasDistributionTable"] = [] + for value_obj in self.distributionTables: obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" + "@id": value_obj.id, + "@type": "uri" } - data[self.id]["hasCode"] = [obj] - - + data = value_obj.to_data(data) + data[self.id]["hasDistributionTable"].append(obj) + if len(self.ensembleTables): data[self.id]["hasEnsembleTable"] = [] for value_obj in self.ensembleTables: @@ -107,20 +102,8 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasEnsembleTable"].append(obj) - - if len(self.distributionTables): - data[self.id]["hasDistributionTable"] = [] - for value_obj in self.distributionTables: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasDistributionTable"].append(obj) - + if len(self.summaryTables): data[self.id]["hasSummaryTable"] = [] for value_obj in self.summaryTables: @@ -129,9 +112,17 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasSummaryTable"].append(obj) + if self.code: + value_obj = self.code + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" + } + data[self.id]["hasCode"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -139,7 +130,7 @@ def to_data(self, data={}): 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): @@ -163,7 +154,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 @@ -172,36 +163,36 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getSummaryTables(self) -> list[DataTable]: - return self.summaryTables - - def setSummaryTables(self, summaryTables:list[DataTable]): - self.summaryTables = summaryTables - - def addSummaryTable(self, summaryTable:DataTable): - self.summaryTables.append(summaryTable) - def getCode(self) -> str: return self.code def setCode(self, code:str): self.code = code + + def getDistributionTables(self) -> list[DataTable]: + return self.distributionTables + def setDistributionTables(self, distributionTables:list[DataTable]): + self.distributionTables = distributionTables + + def addDistributionTable(self, distributionTables:DataTable): + self.distributionTables.append(distributionTables) + def getEnsembleTables(self) -> list[DataTable]: return self.ensembleTables def setEnsembleTables(self, ensembleTables:list[DataTable]): self.ensembleTables = ensembleTables - def addEnsembleTable(self, ensembleTable:DataTable): - self.ensembleTables.append(ensembleTable) + def addEnsembleTable(self, ensembleTables:DataTable): + self.ensembleTables.append(ensembleTables) - def getDistributionTables(self) -> list[DataTable]: - return self.distributionTables + def getSummaryTables(self) -> list[DataTable]: + return self.summaryTables - def setDistributionTables(self, distributionTables:list[DataTable]): - self.distributionTables = distributionTables + def setSummaryTables(self, summaryTables:list[DataTable]): + self.summaryTables = summaryTables - def addDistributionTable(self, distributionTable:DataTable): - self.distributionTables.append(distributionTable) + def addSummaryTable(self, summaryTables:DataTable): + self.summaryTables.append(summaryTables) \ No newline at end of file diff --git a/pylipd/classes/paleodata.py b/pylipd/classes/paleodata.py index 9879661..7adc3b6 100644 --- a/pylipd/classes/paleodata.py +++ b/pylipd/classes/paleodata.py @@ -11,14 +11,14 @@ class PaleoData: def __init__(self): + self.measurementTables: list[DataTable] = [] self.modeledBy: list[Model] = [] self.name: str = None - self.measurementTables: list[DataTable] = [] self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#PaleoData" - self.id = self.ns + "/" + uniqid("PaleoData") + self.id = self.ns + "/" + uniqid("PaleoData.") @staticmethod def from_data(id, data) -> 'PaleoData': @@ -32,15 +32,7 @@ def from_data(id, data) -> 'PaleoData': for val in value: self.type = val["@id"] - elif key == "hasName": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.name = obj - elif key == "hasMeasurementTable": - for val in value: if "@id" in val: obj = DataTable.from_data(val["@id"], data) @@ -49,8 +41,13 @@ def from_data(id, data) -> 'PaleoData': self.measurementTables.append(obj) + elif key == "hasName": + for val in value: + if "@value" in val: + obj = val["@value"] + self.name = obj + elif key == "modeledBy": - for val in value: if "@id" in val: obj = Model.from_data(val["@id"], data) @@ -62,11 +59,11 @@ def from_data(id, data) -> 'PaleoData': 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={}): @@ -78,29 +75,26 @@ def to_data(self, data={}): } ] - - if len(self.modeledBy): - data[self.id]["modeledBy"] = [] - for value_obj in self.modeledBy: + if len(self.measurementTables): + data[self.id]["hasMeasurementTable"] = [] + for value_obj in self.measurementTables: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["modeledBy"].append(obj) - - if len(self.measurementTables): - data[self.id]["hasMeasurementTable"] = [] - for value_obj in self.measurementTables: + data[self.id]["hasMeasurementTable"].append(obj) + + if len(self.modeledBy): + data[self.id]["modeledBy"] = [] + for value_obj in self.modeledBy: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasMeasurementTable"].append(obj) - + data[self.id]["modeledBy"].append(obj) + if self.name: value_obj = self.name obj = { @@ -109,8 +103,7 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasName"] = [obj] - - + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -118,7 +111,7 @@ def to_data(self, data={}): 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): @@ -142,7 +135,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 @@ -151,12 +144,15 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getName(self) -> str: - return self.name + def getMeasurementTables(self) -> list[DataTable]: + return self.measurementTables - def setName(self, name:str): - self.name = name + def setMeasurementTables(self, measurementTables:list[DataTable]): + self.measurementTables = measurementTables + def addMeasurementTable(self, measurementTables:DataTable): + self.measurementTables.append(measurementTables) + def getModeledBy(self) -> list[Model]: return self.modeledBy @@ -166,12 +162,9 @@ def setModeledBy(self, modeledBy:list[Model]): def addModeledBy(self, modeledBy:Model): self.modeledBy.append(modeledBy) - def getMeasurementTables(self) -> list[DataTable]: - return self.measurementTables - - def setMeasurementTables(self, measurementTables:list[DataTable]): - self.measurementTables = measurementTables + def getName(self) -> str: + return self.name - def addMeasurementTable(self, measurementTable:DataTable): - self.measurementTables.append(measurementTable) - \ No newline at end of file + def setName(self, name:str): + self.name = name + \ No newline at end of file diff --git a/pylipd/classes/paleoproxy.py b/pylipd/classes/paleoproxy.py index 3bde5e5..2b48b7f 100644 --- a/pylipd/classes/paleoproxy.py +++ b/pylipd/classes/paleoproxy.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class PaleoProxy: synonyms = SYNONYMS["PROXIES"]["PaleoProxy"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = PaleoProxy.synonyms[synonym.lower()] return PaleoProxy(synobj['id'], synobj['label']) return None - + class PaleoProxyConstants: accumulation_rate = PaleoProxy("http://linked.earth/ontology/proxy#accumulation_rate", "accumulation rate") ACL = PaleoProxy("http://linked.earth/ontology/proxy#ACL", "ACL") diff --git a/pylipd/classes/paleoproxygeneral.py b/pylipd/classes/paleoproxygeneral.py index a0093d2..f6eb6eb 100644 --- a/pylipd/classes/paleoproxygeneral.py +++ b/pylipd/classes/paleoproxygeneral.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class PaleoProxyGeneral: synonyms = SYNONYMS["PROXIES"]["PaleoProxyGeneral"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = PaleoProxyGeneral.synonyms[synonym.lower()] return PaleoProxyGeneral(synobj['id'], synobj['label']) return None - + class PaleoProxyGeneralConstants: biogenic = PaleoProxyGeneral("http://linked.earth/ontology/proxy#biogenic", "biogenic") cryophysical = PaleoProxyGeneral("http://linked.earth/ontology/proxy#cryophysical", "cryophysical") diff --git a/pylipd/classes/paleounit.py b/pylipd/classes/paleounit.py index 3054128..a36cf53 100644 --- a/pylipd/classes/paleounit.py +++ b/pylipd/classes/paleounit.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class PaleoUnit: synonyms = SYNONYMS["UNITS"]["PaleoUnit"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = PaleoUnit.synonyms[synonym.lower()] return PaleoUnit(synobj['id'], synobj['label']) return None - + class PaleoUnitConstants: atomic_ratio = PaleoUnit("http://linked.earth/ontology/units#atomic_ratio", "atomic ratio") cgs = PaleoUnit("http://linked.earth/ontology/units#cgs", "cgs") diff --git a/pylipd/classes/paleovariable.py b/pylipd/classes/paleovariable.py index 123576a..4d76fc9 100644 --- a/pylipd/classes/paleovariable.py +++ b/pylipd/classes/paleovariable.py @@ -2,8 +2,7 @@ ############################## # Auto-generated. Do not Edit ############################## - -from ..globals.synonyms import SYNONYMS +from pylipd.globals.synonyms import SYNONYMS class PaleoVariable: synonyms = SYNONYMS["VARIABLES"]["PaleoVariable"] @@ -39,7 +38,7 @@ def from_synonym(cls, synonym): synobj = PaleoVariable.synonyms[synonym.lower()] return PaleoVariable(synobj['id'], synobj['label']) return None - + class PaleoVariableConstants: ACL = PaleoVariable("http://linked.earth/ontology/variables#ACL", "ACL") AET_PET = PaleoVariable("http://linked.earth/ontology/variables#AET_PET", "AET/PET") diff --git a/pylipd/classes/person.py b/pylipd/classes/person.py index a4bc29e..a14f334 100644 --- a/pylipd/classes/person.py +++ b/pylipd/classes/person.py @@ -14,7 +14,7 @@ def __init__(self): self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Person" - self.id = self.ns + "/" + uniqid("Person") + self.id = self.ns + "/" + uniqid("Person.") @staticmethod def from_data(id, data) -> 'Person': @@ -29,7 +29,6 @@ def from_data(id, data) -> 'Person': self.type = val["@id"] elif key == "hasName": - for val in value: if "@value" in val: obj = val["@value"] @@ -38,11 +37,11 @@ def from_data(id, data) -> 'Person': 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={}): @@ -54,7 +53,6 @@ def to_data(self, data={}): } ] - if self.name: value_obj = self.name obj = { @@ -63,8 +61,7 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasName"] = [obj] - - + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -72,7 +69,7 @@ def to_data(self, data={}): 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): @@ -96,7 +93,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 @@ -110,3 +107,4 @@ def getName(self) -> str: def setName(self, name:str): self.name = name + \ No newline at end of file diff --git a/pylipd/classes/physicalsample.py b/pylipd/classes/physicalsample.py index 7b3c651..e1b9d68 100644 --- a/pylipd/classes/physicalsample.py +++ b/pylipd/classes/physicalsample.py @@ -10,13 +10,13 @@ class PhysicalSample: def __init__(self): self.housedAt: str = None - self.name: str = None self.iGSN: str = None + self.name: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#PhysicalSample" - self.id = self.ns + "/" + uniqid("PhysicalSample") + self.id = self.ns + "/" + uniqid("PhysicalSample.") @staticmethod def from_data(id, data) -> 'PhysicalSample': @@ -30,35 +30,32 @@ def from_data(id, data) -> 'PhysicalSample': for val in value: self.type = val["@id"] - elif key == "name": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.name = obj - elif key == "hasIGSN": - for val in value: if "@value" in val: obj = val["@value"] self.iGSN = obj elif key == "housedAt": - for val in value: if "@value" in val: obj = val["@value"] self.housedAt = obj + + elif key == "name": + for val in value: + if "@value" in val: + obj = val["@value"] + self.name = 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={}): @@ -70,17 +67,16 @@ def to_data(self, data={}): } ] - - if self.name: - value_obj = self.name + if self.housedAt: + value_obj = self.housedAt obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["name"] = [obj] - - + data[self.id]["housedAt"] = [obj] + + if self.iGSN: value_obj = self.iGSN obj = { @@ -89,18 +85,17 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasIGSN"] = [obj] - - - if self.housedAt: - value_obj = self.housedAt + + + if self.name: + value_obj = self.name obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["housedAt"] = [obj] - - + data[self.id]["name"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -108,7 +103,7 @@ def to_data(self, data={}): 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): @@ -132,7 +127,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 @@ -141,20 +136,21 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) + def getHousedAt(self) -> str: + return self.housedAt + + def setHousedAt(self, housedAt:str): + self.housedAt = housedAt + def getIGSN(self) -> str: return self.iGSN def setIGSN(self, iGSN:str): self.iGSN = iGSN - + def getName(self) -> str: return self.name def setName(self, name:str): self.name = name - - def getHousedAt(self) -> str: - return self.housedAt - - def setHousedAt(self, housedAt:str): - self.housedAt = housedAt + \ No newline at end of file diff --git a/pylipd/classes/publication.py b/pylipd/classes/publication.py index 65dfc12..2d88ae1 100644 --- a/pylipd/classes/publication.py +++ b/pylipd/classes/publication.py @@ -10,29 +10,29 @@ class Publication: def __init__(self): - self.report: str = None - self.volume: str = None - self.year: int = None - self.institution: str = None - self.dOI: str = None - self.firstAuthor: Person = None - self.urls: list[str] = [] self.abstract: str = None - self.title: str = None - self.pages: str = None - self.publisher: str = None - self.citation: str = None - self.dataUrls: list[str] = [] self.authors: list[Person] = [] + self.citation: str = None self.citeKey: str = None - self.publicationType: str = None - self.journal: str = None + self.dOI: str = None + self.dataUrls: list[str] = [] + self.firstAuthor: Person = None + self.institution: str = None self.issue: str = None + self.journal: str = None + self.pages: str = None + self.publicationType: str = None + self.publisher: str = None + self.report: str = None + self.title: str = None + self.urls: list[str] = [] + self.volume: str = None + self.year: int = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Publication" - self.id = self.ns + "/" + uniqid("Publication") + self.id = self.ns + "/" + uniqid("Publication.") @staticmethod def from_data(id, data) -> 'Publication': @@ -46,50 +46,46 @@ def from_data(id, data) -> 'Publication': for val in value: self.type = val["@id"] - elif key == "hasDataUrl": - + elif key == "hasAbstract": for val in value: if "@value" in val: - obj = val["@value"] - self.dataUrls.append(obj) + obj = val["@value"] + self.abstract = obj - elif key == "hasVolume": - + elif key == "hasAuthor": for val in value: - if "@value" in val: - obj = val["@value"] - self.volume = obj + if "@id" in val: + obj = Person.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.authors.append(obj) - elif key == "hasTitle": - + elif key == "hasCitation": for val in value: if "@value" in val: obj = val["@value"] - self.title = obj + self.citation = obj - elif key == "hasIssue": - + elif key == "hasCiteKey": for val in value: if "@value" in val: obj = val["@value"] - self.issue = obj + self.citeKey = obj - elif key == "hasType": - + elif key == "hasDOI": for val in value: if "@value" in val: obj = val["@value"] - self.publicationType = obj + self.dOI = obj - elif key == "hasReport": - + elif key == "hasDataUrl": for val in value: if "@value" in val: - obj = val["@value"] - self.report = obj + obj = val["@value"] + self.dataUrls.append(obj) elif key == "hasFirstAuthor": - for val in value: if "@id" in val: obj = Person.from_data(val["@id"], data) @@ -98,94 +94,80 @@ def from_data(id, data) -> 'Publication': self.firstAuthor = obj - elif key == "hasAbstract": - + elif key == "hasInstitution": for val in value: if "@value" in val: obj = val["@value"] - self.abstract = obj + self.institution = obj - elif key == "hasCitation": - + elif key == "hasIssue": for val in value: if "@value" in val: obj = val["@value"] - self.citation = obj + self.issue = obj - elif key == "hasCiteKey": - + elif key == "hasJournal": for val in value: if "@value" in val: obj = val["@value"] - self.citeKey = obj + self.journal = obj elif key == "hasPages": - for val in value: if "@value" in val: obj = val["@value"] self.pages = obj elif key == "hasPublisher": - for val in value: if "@value" in val: obj = val["@value"] self.publisher = obj - elif key == "hasJournal": - + elif key == "hasReport": for val in value: if "@value" in val: obj = val["@value"] - self.journal = obj + self.report = obj - elif key == "hasYear": - + elif key == "hasTitle": for val in value: if "@value" in val: obj = val["@value"] - self.year = obj + self.title = obj - elif key == "hasDOI": - + elif key == "hasType": for val in value: if "@value" in val: obj = val["@value"] - self.dOI = obj + self.publicationType = obj elif key == "hasUrl": - for val in value: if "@value" in val: obj = val["@value"] self.urls.append(obj) - elif key == "hasInstitution": - + elif key == "hasVolume": for val in value: if "@value" in val: obj = val["@value"] - self.institution = obj + self.volume = obj - elif key == "hasAuthor": - + elif key == "hasYear": for val in value: - if "@id" in val: - obj = Person.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.authors.append(obj) + if "@value" in val: + obj = val["@value"] + self.year = 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={}): @@ -197,37 +179,46 @@ def to_data(self, data={}): } ] - - if self.institution: - value_obj = self.institution + if len(self.authors): + data[self.id]["hasAuthor"] = [] + for value_obj in self.authors: + obj = { + "@id": value_obj.id, + "@type": "uri" + } + data = value_obj.to_data(data) + data[self.id]["hasAuthor"].append(obj) + + if len(self.dataUrls): + data[self.id]["hasDataUrl"] = [] + for value_obj in self.dataUrls: obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasInstitution"] = [obj] - - - if self.report: - value_obj = self.report + data[self.id]["hasDataUrl"].append(obj) + + if len(self.urls): + data[self.id]["hasUrl"] = [] + for value_obj in self.urls: obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasReport"] = [obj] - - - if self.citeKey: - value_obj = self.citeKey + data[self.id]["hasUrl"].append(obj) + + if self.abstract: + value_obj = self.abstract obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasCiteKey"] = [obj] - - + data[self.id]["hasAbstract"] = [obj] + + if self.citation: value_obj = self.citation obj = { @@ -236,18 +227,28 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasCitation"] = [obj] - - - if self.year: - value_obj = self.year + + + if self.citeKey: + value_obj = self.citeKey obj = { "@value": value_obj, "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#integer" + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasYear"] = [obj] - - + data[self.id]["hasCiteKey"] = [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] + + if self.firstAuthor: value_obj = self.firstAuthor obj = { @@ -255,61 +256,29 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasFirstAuthor"] = [obj] - - - if len(self.authors): - data[self.id]["hasAuthor"] = [] - for value_obj in self.authors: - obj = { - "@id": value_obj.id, - "@type": "uri" - } - data = value_obj.to_data(data) - - data[self.id]["hasAuthor"].append(obj) - - if len(self.dataUrls): - data[self.id]["hasDataUrl"] = [] - for value_obj in self.dataUrls: - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasDataUrl"].append(obj) - - if self.volume: - value_obj = self.volume - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasVolume"] = [obj] - - - if self.publisher: - value_obj = self.publisher + + + if self.institution: + value_obj = self.institution obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasPublisher"] = [obj] - - - if self.publicationType: - value_obj = self.publicationType + data[self.id]["hasInstitution"] = [obj] + + + if self.issue: + value_obj = self.issue obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasType"] = [obj] - - + data[self.id]["hasIssue"] = [obj] + + if self.journal: value_obj = self.journal obj = { @@ -318,48 +287,48 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasJournal"] = [obj] - - - if self.dOI: - value_obj = self.dOI + + + if self.pages: + value_obj = self.pages obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasDOI"] = [obj] - - - if self.issue: - value_obj = self.issue + data[self.id]["hasPages"] = [obj] + + + if self.publicationType: + value_obj = self.publicationType obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasIssue"] = [obj] - - - if len(self.urls): - data[self.id]["hasUrl"] = [] - for value_obj in self.urls: + data[self.id]["hasType"] = [obj] + + + if self.publisher: + value_obj = self.publisher obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasUrl"].append(obj) - - if self.pages: - value_obj = self.pages + data[self.id]["hasPublisher"] = [obj] + + + if self.report: + value_obj = self.report obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasPages"] = [obj] - - + data[self.id]["hasReport"] = [obj] + + if self.title: value_obj = self.title obj = { @@ -368,18 +337,27 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasTitle"] = [obj] - - - if self.abstract: - value_obj = self.abstract + + + if self.volume: + value_obj = self.volume obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasAbstract"] = [obj] - + data[self.id]["hasVolume"] = [obj] + + if self.year: + value_obj = self.year + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#integer" + } + data[self.id]["hasYear"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -387,7 +365,7 @@ def to_data(self, data={}): 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): @@ -411,7 +389,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 @@ -425,115 +403,115 @@ def getAbstract(self) -> str: def setAbstract(self, abstract:str): self.abstract = abstract + + def getAuthors(self) -> list[Person]: + return self.authors - def getYear(self) -> int: - return self.year - - def setYear(self, year:int): - self.year = year - - def getUrls(self) -> list[str]: - return self.urls - - def setUrls(self, urls:list[str]): - self.urls = urls + def setAuthors(self, authors:list[Person]): + self.authors = authors - def addUrl(self, url:str): - self.urls.append(url) + def addAuthor(self, authors:Person): + self.authors.append(authors) - def getReport(self) -> str: - return self.report - - def setReport(self, report:str): - self.report = report - - def getIssue(self) -> str: - return self.issue - - def setIssue(self, issue:str): - self.issue = issue - - def getInstitution(self) -> str: - return self.institution - - def setInstitution(self, institution:str): - self.institution = institution - - def getPages(self) -> str: - return self.pages - - def setPages(self, pages:str): - self.pages = pages + def getCitation(self) -> str: + return self.citation - def getTitle(self) -> str: - return self.title + def setCitation(self, citation:str): + self.citation = citation + + def getCiteKey(self) -> str: + return self.citeKey - def setTitle(self, title:str): - self.title = title + def setCiteKey(self, citeKey:str): + self.citeKey = citeKey + + def getDOI(self) -> str: + return self.dOI + def setDOI(self, dOI:str): + self.dOI = dOI + def getDataUrls(self) -> list[str]: return self.dataUrls def setDataUrls(self, dataUrls:list[str]): self.dataUrls = dataUrls - def addDataUrl(self, dataUrl:str): - self.dataUrls.append(dataUrl) + def addDataUrl(self, dataUrls:str): + self.dataUrls.append(dataUrls) - def getPublicationType(self) -> str: - return self.publicationType - - def setPublicationType(self, publicationType:str): - self.publicationType = publicationType - def getFirstAuthor(self) -> Person: return self.firstAuthor def setFirstAuthor(self, firstAuthor:Person): self.firstAuthor = firstAuthor + + def getInstitution(self) -> str: + return self.institution - def getCiteKey(self) -> str: - return self.citeKey - - def setCiteKey(self, citeKey:str): - self.citeKey = citeKey + def setInstitution(self, institution:str): + self.institution = institution + + def getIssue(self) -> str: + return self.issue + def setIssue(self, issue:str): + self.issue = issue + def getJournal(self) -> str: return self.journal def setJournal(self, journal:str): self.journal = journal + + def getPages(self) -> str: + return self.pages - def getCitation(self) -> str: - return self.citation - - def setCitation(self, citation:str): - self.citation = citation - - def getVolume(self) -> str: - return self.volume - - def setVolume(self, volume:str): - self.volume = volume + def setPages(self, pages:str): + self.pages = pages + + def getPublicationType(self) -> str: + return self.publicationType + def setPublicationType(self, publicationType:str): + self.publicationType = publicationType + def getPublisher(self) -> str: return self.publisher def setPublisher(self, publisher:str): self.publisher = publisher + + def getReport(self) -> str: + return self.report - def getDOI(self) -> str: - return self.dOI + def setReport(self, report:str): + self.report = report + + def getTitle(self) -> str: + return self.title - def setDOI(self, dOI:str): - self.dOI = dOI + def setTitle(self, title:str): + self.title = title + + def getUrls(self) -> list[str]: + return self.urls - def getAuthors(self) -> list[Person]: - return self.authors + def setUrls(self, urls:list[str]): + self.urls = urls - def setAuthors(self, authors:list[Person]): - self.authors = authors + def addUrl(self, urls:str): + self.urls.append(urls) + + def getVolume(self) -> str: + return self.volume - def addAuthor(self, author:Person): - self.authors.append(author) - \ No newline at end of file + def setVolume(self, volume:str): + self.volume = volume + + def getYear(self) -> int: + return self.year + + def setYear(self, year:int): + self.year = year + \ No newline at end of file diff --git a/pylipd/classes/resolution.py b/pylipd/classes/resolution.py index 5462ec9..6ec6c5f 100644 --- a/pylipd/classes/resolution.py +++ b/pylipd/classes/resolution.py @@ -10,16 +10,16 @@ class Resolution: def __init__(self): - self.minValue: float = None self.maxValue: float = None - self.units: PaleoUnit = None self.meanValue: float = None self.medianValue: float = None + self.minValue: float = None + self.units: PaleoUnit = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Resolution" - self.id = self.ns + "/" + uniqid("Resolution") + self.id = self.ns + "/" + uniqid("Resolution.") @staticmethod def from_data(id, data) -> 'Resolution': @@ -34,48 +34,43 @@ def from_data(id, data) -> 'Resolution': self.type = val["@id"] elif key == "hasMaxValue": - for val in value: if "@value" in val: obj = val["@value"] self.maxValue = obj - elif key == "hasMinValue": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.minValue = obj - - elif key == "hasUnits": - - for val in value: - obj = PaleoUnit.from_synonym(re.sub("^.*?#", "", val["@id"])) - - self.units = obj - elif key == "hasMeanValue": - for val in value: if "@value" in val: obj = val["@value"] self.meanValue = obj elif key == "hasMedianValue": - for val in value: if "@value" in val: obj = val["@value"] self.medianValue = obj + + elif key == "hasMinValue": + for val in value: + if "@value" in val: + obj = val["@value"] + self.minValue = obj + + elif key == "hasUnits": + for val in value: + obj = PaleoUnit.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.units = 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={}): @@ -87,7 +82,6 @@ def to_data(self, data={}): } ] - if self.maxValue: value_obj = self.maxValue obj = { @@ -96,8 +90,8 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#float" } data[self.id]["hasMaxValue"] = [obj] - - + + if self.meanValue: value_obj = self.meanValue obj = { @@ -106,28 +100,28 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#float" } data[self.id]["hasMeanValue"] = [obj] - - - if self.minValue: - value_obj = self.minValue + + + if self.medianValue: + value_obj = self.medianValue obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#float" } - data[self.id]["hasMinValue"] = [obj] - - - if self.medianValue: - value_obj = self.medianValue + data[self.id]["hasMedianValue"] = [obj] + + + if self.minValue: + value_obj = self.minValue obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#float" } - data[self.id]["hasMedianValue"] = [obj] - - + data[self.id]["hasMinValue"] = [obj] + + if self.units: value_obj = self.units obj = { @@ -135,10 +129,8 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasUnits"] = [obj] - - + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -146,7 +138,7 @@ def to_data(self, data={}): 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): @@ -170,7 +162,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 @@ -179,32 +171,33 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getMinValue(self) -> float: - return self.minValue - - def setMinValue(self, minValue:float): - self.minValue = minValue + def getMaxValue(self) -> float: + return self.maxValue + def setMaxValue(self, maxValue:float): + self.maxValue = maxValue + def getMeanValue(self) -> float: return self.meanValue def setMeanValue(self, meanValue:float): self.meanValue = meanValue + + def getMedianValue(self) -> float: + return self.medianValue + + def setMedianValue(self, medianValue:float): + self.medianValue = medianValue + + def getMinValue(self) -> float: + return self.minValue + def setMinValue(self, minValue:float): + self.minValue = minValue + def getUnits(self) -> PaleoUnit: return self.units def setUnits(self, units:PaleoUnit): self.units = units - - def getMaxValue(self) -> float: - return self.maxValue - - def setMaxValue(self, maxValue:float): - self.maxValue = maxValue - - def getMedianValue(self) -> float: - return self.medianValue - - def setMedianValue(self, medianValue:float): - self.medianValue = medianValue + \ No newline at end of file diff --git a/pylipd/classes/uncertainty.py b/pylipd/classes/uncertainty.py index fc17e2b..27fce79 100644 --- a/pylipd/classes/uncertainty.py +++ b/pylipd/classes/uncertainty.py @@ -14,7 +14,7 @@ def __init__(self): 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") + self.id = self.ns + "/" + uniqid("Uncertainty.") @staticmethod def from_data(id, data) -> 'Uncertainty': @@ -29,7 +29,6 @@ def from_data(id, data) -> 'Uncertainty': self.type = val["@id"] elif key == "hasUncertaintyType": - for val in value: if "@value" in val: obj = val["@value"] @@ -38,11 +37,11 @@ def from_data(id, data) -> 'Uncertainty': 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={}): @@ -54,7 +53,6 @@ def to_data(self, data={}): } ] - if self.uncertaintyType: value_obj = self.uncertaintyType obj = { @@ -63,8 +61,7 @@ def to_data(self, data={}): "@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] = [] @@ -72,7 +69,7 @@ def to_data(self, data={}): 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): @@ -96,7 +93,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 @@ -110,3 +107,4 @@ def getUncertaintyType(self) -> str: def setUncertaintyType(self, uncertaintyType:str): self.uncertaintyType = uncertaintyType + \ No newline at end of file diff --git a/pylipd/classes/variable.py b/pylipd/classes/variable.py index 7f4bc51..146285a 100644 --- a/pylipd/classes/variable.py +++ b/pylipd/classes/variable.py @@ -5,54 +5,54 @@ import re from pylipd.utils import uniqid -from pylipd.classes.paleovariable import PaleoVariable -from pylipd.classes.paleoproxy import PaleoProxy -from pylipd.classes.resolution import Resolution +from pylipd.classes.archivetype import ArchiveType +from pylipd.classes.calibration import Calibration +from pylipd.classes.compilation import Compilation from pylipd.classes.interpretation import Interpretation +from pylipd.classes.paleoproxy import PaleoProxy from pylipd.classes.paleoproxygeneral import PaleoProxyGeneral -from pylipd.classes.compilation import Compilation from pylipd.classes.paleounit import PaleoUnit +from pylipd.classes.paleovariable import PaleoVariable +from pylipd.classes.resolution import Resolution from pylipd.classes.uncertainty import Uncertainty -from pylipd.classes.archivetype import ArchiveType -from pylipd.classes.calibration import Calibration class Variable: def __init__(self): - self.interpretations: list[Interpretation] = [] - self.values: str = None - self.variableId: str = None - self.meanValue: float = None - self.foundInDataset: None = None - self.proxy: PaleoProxy = None + self.archiveType: ArchiveType = None + self.calibratedVias: list[Calibration] = [] self.columnNumber: int = None - self.notes: str = None + self.compilationNest: str = None + self.composite: bool = None + self.description: str = None + self.foundInDataset: None = None + self.foundInTable: None = None self.instrument: None = None - self.resolution: Resolution = None - self.medianValue: float = None + self.interpretations: list[Interpretation] = [] self.maxValue: float = None - self.composite: bool = None + self.meanValue: float = None + self.medianValue: float = None + self.minValue: float = None + self.missingValue: str = None self.name: str = None - self.uncertainty: Uncertainty = None - self.description: str = None + self.notes: str = None self.partOfCompilation: Compilation = None - self.proxyGeneral: PaleoProxyGeneral = None - self.missingValue: str = None - self.calibratedVias: list[Calibration] = [] - self.foundInTable: None = None - self.variableType: str = None - self.units: PaleoUnit = None self.physicalSample: None = None self.primary: bool = None - self.compilationNest: str = None - self.archiveType: ArchiveType = None + self.proxy: PaleoProxy = None + self.proxyGeneral: PaleoProxyGeneral = None + self.resolution: Resolution = None self.standardVariable: PaleoVariable = None - self.minValue: float = None + self.uncertainty: Uncertainty = None + self.units: PaleoUnit = None + self.values: str = None + self.variableId: str = None + self.variableType: str = None self.misc = {} self.ontns = "http://linked.earth/ontology#" self.ns = "http://linked.earth/lipd" self.type = "http://linked.earth/ontology#Variable" - self.id = self.ns + "/" + uniqid("Variable") + self.id = self.ns + "/" + uniqid("Variable.") @staticmethod def from_data(id, data) -> 'Variable': @@ -66,100 +66,118 @@ def from_data(id, data) -> 'Variable': for val in value: self.type = val["@id"] - elif key == "hasMissingValue": - + elif key == "calibratedVia": for val in value: - if "@value" in val: - obj = val["@value"] - self.missingValue = obj + if "@id" in val: + obj = Calibration.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.calibratedVias.append(obj) - elif key == "hasVariableId": - + elif key == "foundInDataset": for val in value: - if "@value" in val: - obj = val["@value"] - self.variableId = obj + obj = val["@id"] + self.foundInDataset = obj - elif key == "physicalSample": - + elif key == "foundInTable": for val in value: obj = val["@id"] - self.physicalSample = obj + self.foundInTable = obj - elif key == "hasDescription": - + elif key == "hasArchiveType": + for val in value: + obj = ArchiveType.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.archiveType = obj + + elif key == "hasColumnNumber": for val in value: if "@value" in val: obj = val["@value"] - self.description = obj + self.columnNumber = obj elif key == "hasCompilationNest": - for val in value: if "@value" in val: obj = val["@value"] self.compilationNest = obj - elif key == "hasUnits": - + elif key == "hasDescription": for val in value: - obj = PaleoUnit.from_synonym(re.sub("^.*?#", "", val["@id"])) - - self.units = obj + if "@value" in val: + obj = val["@value"] + self.description = obj - elif key == "hasStandardVariable": - + elif key == "hasInstrument": for val in value: - obj = PaleoVariable.from_synonym(re.sub("^.*?#", "", val["@id"])) - - self.standardVariable = obj + obj = val["@id"] + self.instrument = obj + + elif key == "hasInterpretation": + for val in value: + if "@id" in val: + obj = Interpretation.from_data(val["@id"], data) + else: + obj = val["@value"] + + self.interpretations.append(obj) + + elif key == "hasMaxValue": + for val in value: + if "@value" in val: + obj = val["@value"] + self.maxValue = obj + + elif key == "hasMeanValue": + for val in value: + if "@value" in val: + obj = val["@value"] + self.meanValue = obj elif key == "hasMedianValue": - for val in value: if "@value" in val: obj = val["@value"] self.medianValue = obj - elif key == "hasValues": - + elif key == "hasMinValue": for val in value: if "@value" in val: obj = val["@value"] - self.values = obj + self.minValue = obj - elif key == "foundInTable": - + elif key == "hasMissingValue": for val in value: - obj = val["@id"] - self.foundInTable = obj + if "@value" in val: + obj = val["@value"] + self.missingValue = obj - elif key == "hasArchiveType": - + elif key == "hasName": for val in value: - obj = ArchiveType.from_synonym(re.sub("^.*?#", "", val["@id"])) - - self.archiveType = obj + if "@value" in val: + obj = val["@value"] + self.name = obj - elif key == "partOfCompilation": - + elif key == "hasNotes": for val in value: - if "@id" in val: - obj = Compilation.from_data(val["@id"], data) - else: - obj = val["@value"] + if "@value" in val: + obj = val["@value"] + self.notes = obj + + elif key == "hasProxy": + for val in value: + obj = PaleoProxy.from_synonym(re.sub("^.*?#", "", val["@id"])) - self.partOfCompilation = obj + self.proxy = obj - elif key == "isComposite": - + elif key == "hasProxyGeneral": for val in value: - if "@value" in val: - obj = val["@value"] - self.composite = obj + obj = PaleoProxyGeneral.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.proxyGeneral = obj elif key == "hasResolution": - for val in value: if "@id" in val: obj = Resolution.from_data(val["@id"], data) @@ -168,25 +186,19 @@ def from_data(id, data) -> 'Variable': self.resolution = obj + elif key == "hasStandardVariable": + for val in value: + obj = PaleoVariable.from_synonym(re.sub("^.*?#", "", val["@id"])) + + self.standardVariable = obj + elif key == "hasType": - for val in value: if "@value" in val: obj = val["@value"] self.variableType = obj - elif key == "hasInterpretation": - - for val in value: - if "@id" in val: - obj = Interpretation.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.interpretations.append(obj) - elif key == "hasUncertainty": - for val in value: if "@id" in val: obj = Uncertainty.from_data(val["@id"], data) @@ -195,99 +207,58 @@ def from_data(id, data) -> 'Variable': self.uncertainty = obj - elif key == "calibratedVia": - - for val in value: - if "@id" in val: - obj = Calibration.from_data(val["@id"], data) - else: - obj = val["@value"] - - self.calibratedVias.append(obj) - - elif key == "hasProxyGeneral": - + elif key == "hasUnits": for val in value: - obj = PaleoProxyGeneral.from_synonym(re.sub("^.*?#", "", val["@id"])) + obj = PaleoUnit.from_synonym(re.sub("^.*?#", "", val["@id"])) - self.proxyGeneral = obj - - elif key == "hasName": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.name = obj + self.units = obj - elif key == "hasMinValue": - + elif key == "hasValues": for val in value: if "@value" in val: obj = val["@value"] - self.minValue = obj + self.values = obj - elif key == "isPrimary": - + elif key == "hasVariableId": for val in value: if "@value" in val: obj = val["@value"] - self.primary = obj + self.variableId = obj - elif key == "hasNotes": - + elif key == "isComposite": for val in value: if "@value" in val: obj = val["@value"] - self.notes = obj + self.composite = obj - elif key == "hasColumnNumber": - + elif key == "isPrimary": for val in value: if "@value" in val: obj = val["@value"] - self.columnNumber = obj + self.primary = obj - elif key == "hasProxy": - + elif key == "partOfCompilation": for val in value: - obj = PaleoProxy.from_synonym(re.sub("^.*?#", "", val["@id"])) + if "@id" in val: + obj = Compilation.from_data(val["@id"], data) + else: + obj = val["@value"] - self.proxy = obj + self.partOfCompilation = obj - elif key == "hasMaxValue": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.maxValue = obj - - elif key == "foundInDataset": - - for val in value: - obj = val["@id"] - self.foundInDataset = obj - - elif key == "hasMeanValue": - - for val in value: - if "@value" in val: - obj = val["@value"] - self.meanValue = obj - - elif key == "hasInstrument": - + elif key == "physicalSample": for val in value: obj = val["@id"] - self.instrument = obj + self.physicalSample = 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={}): @@ -299,68 +270,26 @@ def to_data(self, data={}): } ] - - 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.values: - value_obj = self.values - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" - } - data[self.id]["hasValues"] = [obj] - - - if self.proxyGeneral: - value_obj = self.proxyGeneral + if len(self.calibratedVias): + data[self.id]["calibratedVia"] = [] + for value_obj in self.calibratedVias: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasProxyGeneral"] = [obj] - - - if self.primary: - value_obj = self.primary - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#boolean" - } - data[self.id]["isPrimary"] = [obj] - - - if self.units: - value_obj = self.units + data[self.id]["calibratedVia"].append(obj) + + if len(self.interpretations): + data[self.id]["hasInterpretation"] = [] + for value_obj in self.interpretations: obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasUnits"] = [obj] - - - if self.foundInDataset: - value_obj = self.foundInDataset - obj = { - "@id": value_obj, - "@type": "uri" - } - data[self.id]["foundInDataset"] = [obj] - - + data[self.id]["hasInterpretation"].append(obj) + if self.archiveType: value_obj = self.archiveType obj = { @@ -368,10 +297,19 @@ def to_data(self, data={}): "@type": "uri" } data = value_obj.to_data(data) - data[self.id]["hasArchiveType"] = [obj] - - + + + if self.columnNumber: + value_obj = self.columnNumber + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#integer" + } + data[self.id]["hasColumnNumber"] = [obj] + + if self.compilationNest: value_obj = self.compilationNest obj = { @@ -380,8 +318,18 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasCompilationNest"] = [obj] - - + + + if self.composite: + value_obj = self.composite + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#boolean" + } + data[self.id]["isComposite"] = [obj] + + if self.description: value_obj = self.description obj = { @@ -390,18 +338,45 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasDescription"] = [obj] - - - if self.variableType: - value_obj = self.variableType + + + if self.foundInDataset: + value_obj = self.foundInDataset + obj = { + "@id": value_obj, + "@type": "uri" + } + data[self.id]["foundInDataset"] = [obj] + + + if self.foundInTable: + value_obj = self.foundInTable + obj = { + "@id": value_obj, + "@type": "uri" + } + data[self.id]["foundInTable"] = [obj] + + + if self.instrument: + value_obj = self.instrument + obj = { + "@id": value_obj, + "@type": "uri" + } + data[self.id]["hasInstrument"] = [obj] + + + if self.maxValue: + value_obj = self.maxValue obj = { "@value": value_obj, "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#string" + "@datatype": "http://www.w3.org/2001/XMLSchema#float" } - data[self.id]["hasType"] = [obj] - - + data[self.id]["hasMaxValue"] = [obj] + + if self.meanValue: value_obj = self.meanValue obj = { @@ -410,41 +385,38 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#float" } data[self.id]["hasMeanValue"] = [obj] - - - if len(self.calibratedVias): - data[self.id]["calibratedVia"] = [] - for value_obj in self.calibratedVias: + + + if self.medianValue: + value_obj = self.medianValue obj = { - "@id": value_obj.id, - "@type": "uri" + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#float" } - data = value_obj.to_data(data) - - data[self.id]["calibratedVia"].append(obj) - - if self.resolution: - value_obj = self.resolution + data[self.id]["hasMedianValue"] = [obj] + + + if self.minValue: + value_obj = self.minValue obj = { - "@id": value_obj.id, - "@type": "uri" + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#float" } - data = value_obj.to_data(data) - - data[self.id]["hasResolution"] = [obj] - - - if self.partOfCompilation: - value_obj = self.partOfCompilation + data[self.id]["hasMinValue"] = [obj] + + + if self.missingValue: + value_obj = self.missingValue obj = { - "@id": value_obj.id, - "@type": "uri" + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data = value_obj.to_data(data) - - data[self.id]["partOfCompilation"] = [obj] - - + data[self.id]["hasMissingValue"] = [obj] + + if self.name: value_obj = self.name obj = { @@ -453,129 +425,117 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasName"] = [obj] - - - if self.missingValue: - value_obj = self.missingValue + + + if self.notes: + value_obj = self.notes obj = { "@value": value_obj, "@type": "literal", "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasMissingValue"] = [obj] - - - if self.minValue: - value_obj = self.minValue + data[self.id]["hasNotes"] = [obj] + + + if self.partOfCompilation: + value_obj = self.partOfCompilation obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#float" + "@id": value_obj.id, + "@type": "uri" } - data[self.id]["hasMinValue"] = [obj] - - - if self.foundInTable: - value_obj = self.foundInTable + data = value_obj.to_data(data) + data[self.id]["partOfCompilation"] = [obj] + + + if self.physicalSample: + value_obj = self.physicalSample obj = { "@id": value_obj, "@type": "uri" } - data[self.id]["foundInTable"] = [obj] - - - if len(self.interpretations): - data[self.id]["hasInterpretation"] = [] - for value_obj in self.interpretations: + data[self.id]["physicalSample"] = [obj] + + + if self.primary: + value_obj = self.primary + obj = { + "@value": value_obj, + "@type": "literal", + "@datatype": "http://www.w3.org/2001/XMLSchema#boolean" + } + data[self.id]["isPrimary"] = [obj] + + + if self.proxy: + value_obj = self.proxy obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasInterpretation"].append(obj) - - if self.medianValue: - value_obj = self.medianValue + data[self.id]["hasProxy"] = [obj] + + + if self.proxyGeneral: + value_obj = self.proxyGeneral obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#float" - } - data[self.id]["hasMedianValue"] = [obj] - - - if self.instrument: - value_obj = self.instrument - obj = { - "@id": value_obj, + "@id": value_obj.id, "@type": "uri" } - data[self.id]["hasInstrument"] = [obj] - - - if self.uncertainty: - value_obj = self.uncertainty + data = value_obj.to_data(data) + data[self.id]["hasProxyGeneral"] = [obj] + + + if self.resolution: + value_obj = self.resolution obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasUncertainty"] = [obj] - - - if self.composite: - value_obj = self.composite - obj = { - "@value": value_obj, - "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#boolean" - } - data[self.id]["isComposite"] = [obj] - - - if self.proxy: - value_obj = self.proxy + data[self.id]["hasResolution"] = [obj] + + + if self.standardVariable: + value_obj = self.standardVariable obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasProxy"] = [obj] - - - if self.physicalSample: - value_obj = self.physicalSample + data[self.id]["hasStandardVariable"] = [obj] + + + if self.uncertainty: + value_obj = self.uncertainty obj = { - "@id": value_obj, + "@id": value_obj.id, "@type": "uri" } - data[self.id]["physicalSample"] = [obj] - - - if self.standardVariable: - value_obj = self.standardVariable + data = value_obj.to_data(data) + data[self.id]["hasUncertainty"] = [obj] + + + if self.units: + value_obj = self.units obj = { "@id": value_obj.id, "@type": "uri" } data = value_obj.to_data(data) - - data[self.id]["hasStandardVariable"] = [obj] - - - if self.columnNumber: - value_obj = self.columnNumber + data[self.id]["hasUnits"] = [obj] + + + if self.values: + value_obj = self.values obj = { "@value": value_obj, "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#integer" + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasColumnNumber"] = [obj] - - + data[self.id]["hasValues"] = [obj] + + if self.variableId: value_obj = self.variableId obj = { @@ -584,18 +544,17 @@ def to_data(self, data={}): "@datatype": "http://www.w3.org/2001/XMLSchema#string" } data[self.id]["hasVariableId"] = [obj] - - - if self.maxValue: - value_obj = self.maxValue + + + if self.variableType: + value_obj = self.variableType obj = { "@value": value_obj, "@type": "literal", - "@datatype": "http://www.w3.org/2001/XMLSchema#float" + "@datatype": "http://www.w3.org/2001/XMLSchema#string" } - data[self.id]["hasMaxValue"] = [obj] - - + data[self.id]["hasType"] = [obj] + for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -603,7 +562,7 @@ def to_data(self, data={}): 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): @@ -627,7 +586,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 @@ -636,182 +595,183 @@ def add_non_standard_property(self, key, value): self.misc[key] = [] self.misc[key].append(value) - def getFoundInTable(self) -> None: - return self.foundInTable + def getArchiveType(self) -> ArchiveType: + return self.archiveType - def setFoundInTable(self, foundInTable:None): - self.foundInTable = foundInTable + def setArchiveType(self, archiveType:ArchiveType): + self.archiveType = archiveType + + def getCalibratedVias(self) -> list[Calibration]: + return self.calibratedVias + def setCalibratedVias(self, calibratedVias:list[Calibration]): + self.calibratedVias = calibratedVias + + def addCalibratedVia(self, calibratedVias:Calibration): + self.calibratedVias.append(calibratedVias) + def getColumnNumber(self) -> int: return self.columnNumber def setColumnNumber(self, columnNumber:int): self.columnNumber = columnNumber + + def getCompilationNest(self) -> str: + return self.compilationNest - def getMeanValue(self) -> float: - return self.meanValue - - def setMeanValue(self, meanValue:float): - self.meanValue = meanValue - - def getMaxValue(self) -> float: - return self.maxValue - - def setMaxValue(self, maxValue:float): - self.maxValue = maxValue - - def getPartOfCompilation(self) -> Compilation: - return self.partOfCompilation - - def setPartOfCompilation(self, partOfCompilation:Compilation): - self.partOfCompilation = partOfCompilation - - def isComposite(self) -> bool: - return self.composite - - def setComposite(self, composite:bool): - self.composite = composite - - def getNotes(self) -> str: - return self.notes - - def setNotes(self, notes:str): - self.notes = notes - - def getResolution(self) -> Resolution: - return self.resolution - - def setResolution(self, resolution:Resolution): - self.resolution = resolution - - def getFoundInDataset(self) -> None: - return self.foundInDataset - - def setFoundInDataset(self, foundInDataset:None): - self.foundInDataset = foundInDataset - - def getMinValue(self) -> float: - return self.minValue - - def setMinValue(self, minValue:float): - self.minValue = minValue - + def setCompilationNest(self, compilationNest:str): + self.compilationNest = compilationNest + def getDescription(self) -> str: return self.description def setDescription(self, description:str): self.description = description + + def getFoundInDataset(self) -> None: + return self.foundInDataset - def getCalibratedVias(self) -> list[Calibration]: - return self.calibratedVias - - def setCalibratedVias(self, calibratedVias:list[Calibration]): - self.calibratedVias = calibratedVias - - def addCalibratedVia(self, calibratedVia:Calibration): - self.calibratedVias.append(calibratedVia) - - def getVariableId(self) -> str: - return self.variableId - - def setVariableId(self, variableId:str): - self.variableId = variableId - - def isPrimary(self) -> bool: - return self.primary - - def setPrimary(self, primary:bool): - self.primary = primary - - def getVariableType(self) -> str: - return self.variableType + def setFoundInDataset(self, foundInDataset:None): + self.foundInDataset = foundInDataset + + def getFoundInTable(self) -> None: + return self.foundInTable - def setVariableType(self, variableType:str): - self.variableType = variableType + def setFoundInTable(self, foundInTable:None): + self.foundInTable = foundInTable + + def getInstrument(self) -> None: + return self.instrument + def setInstrument(self, instrument:None): + self.instrument = instrument + def getInterpretations(self) -> list[Interpretation]: return self.interpretations def setInterpretations(self, interpretations:list[Interpretation]): self.interpretations = interpretations - def addInterpretation(self, interpretation:Interpretation): - self.interpretations.append(interpretation) + def addInterpretation(self, interpretations:Interpretation): + self.interpretations.append(interpretations) - def getUncertainty(self) -> Uncertainty: - return self.uncertainty - - def setUncertainty(self, uncertainty:Uncertainty): - self.uncertainty = uncertainty - - def getValues(self) -> str: - return self.values - - def setValues(self, values:str): - self.values = values - - def getCompilationNest(self) -> str: - return self.compilationNest + def getMaxValue(self) -> float: + return self.maxValue - def setCompilationNest(self, compilationNest:str): - self.compilationNest = compilationNest + def setMaxValue(self, maxValue:float): + self.maxValue = maxValue + + def getMeanValue(self) -> float: + return self.meanValue - def getInstrument(self) -> None: - return self.instrument + def setMeanValue(self, meanValue:float): + self.meanValue = meanValue + + def getMedianValue(self) -> float: + return self.medianValue - def setInstrument(self, instrument:None): - self.instrument = instrument + def setMedianValue(self, medianValue:float): + self.medianValue = medianValue + + def getMinValue(self) -> float: + return self.minValue - def getProxy(self) -> PaleoProxy: - return self.proxy + def setMinValue(self, minValue:float): + self.minValue = minValue + + def getMissingValue(self) -> str: + return self.missingValue - def setProxy(self, proxy:PaleoProxy): - self.proxy = proxy + def setMissingValue(self, missingValue:str): + self.missingValue = missingValue + + def getName(self) -> str: + return self.name - def getStandardVariable(self) -> PaleoVariable: - return self.standardVariable + def setName(self, name:str): + self.name = name + + def getNotes(self) -> str: + return self.notes - def setStandardVariable(self, standardVariable:PaleoVariable): - self.standardVariable = standardVariable + def setNotes(self, notes:str): + self.notes = notes + + def getPartOfCompilation(self) -> Compilation: + return self.partOfCompilation + def setPartOfCompilation(self, partOfCompilation:Compilation): + self.partOfCompilation = partOfCompilation + def getPhysicalSample(self) -> None: return self.physicalSample def setPhysicalSample(self, physicalSample:None): self.physicalSample = physicalSample + + def getProxy(self) -> PaleoProxy: + return self.proxy + def setProxy(self, proxy:PaleoProxy): + self.proxy = proxy + def getProxyGeneral(self) -> PaleoProxyGeneral: return self.proxyGeneral def setProxyGeneral(self, proxyGeneral:PaleoProxyGeneral): self.proxyGeneral = proxyGeneral + + def getResolution(self) -> Resolution: + return self.resolution - def getArchiveType(self) -> ArchiveType: - return self.archiveType - - def setArchiveType(self, archiveType:ArchiveType): - self.archiveType = archiveType - - def getName(self) -> str: - return self.name - - def setName(self, name:str): - self.name = name - - def getMissingValue(self) -> str: - return self.missingValue + def setResolution(self, resolution:Resolution): + self.resolution = resolution + + def getStandardVariable(self) -> PaleoVariable: + return self.standardVariable - def setMissingValue(self, missingValue:str): - self.missingValue = missingValue + def setStandardVariable(self, standardVariable:PaleoVariable): + self.standardVariable = standardVariable + + def getUncertainty(self) -> Uncertainty: + return self.uncertainty + def setUncertainty(self, uncertainty:Uncertainty): + self.uncertainty = uncertainty + def getUnits(self) -> PaleoUnit: return self.units def setUnits(self, units:PaleoUnit): self.units = units + + def getValues(self) -> str: + return self.values - def getMedianValue(self) -> float: - return self.medianValue + def setValues(self, values:str): + self.values = values + + def getVariableId(self) -> str: + return self.variableId - def setMedianValue(self, medianValue:float): - self.medianValue = medianValue + def setVariableId(self, variableId:str): + self.variableId = variableId + + def getVariableType(self) -> str: + return self.variableType + + def setVariableType(self, variableType:str): + self.variableType = variableType + + def isComposite(self) -> bool: + return self.composite + + def setComposite(self, composite:bool): + self.composite = composite + + def isPrimary(self) -> bool: + return self.primary + + def setPrimary(self, primary:bool): + self.primary = primary + \ No newline at end of file diff --git a/pylipd/globals/schema.py b/pylipd/globals/schema.py index 8a5d8cb..3ffa109 100644 --- a/pylipd/globals/schema.py +++ b/pylipd/globals/schema.py @@ -712,10 +712,6 @@ 'uncertainty': { 'name': 'hasUncertainty', 'alternates': ['uncertainty', 'calibrationUncertainty', 'temperature12kUncertainty', 'transferFunctionUncertainty'], - }, - 'hasUncertainty': { - 'type': 'Individual', - 'schema': 'Uncertainty' } }, 'Person': { diff --git a/pylipd/lipd.py b/pylipd/lipd.py index fd94f73..47ce79d 100644 --- a/pylipd/lipd.py +++ b/pylipd/lipd.py @@ -20,6 +20,7 @@ except: pass +from pylipd.utils.json_to_rdf import JSONToRDF from pylipd.utils.rdf_to_json import RDFToJSON from .globals.queries import QUERY_BIBLIO, QUERY_DSID, QUERY_DSNAME, QUERY_ENSEMBLE_TABLE, QUERY_ENSEMBLE_TABLE_SHORT, QUERY_FILTER_ARCHIVE_TYPE, QUERY_FILTER_GEO, QUERY_VARIABLE, QUERY_VARIABLE_GRAPH, QUERY_UNIQUE_ARCHIVE_TYPE, QUERY_TIMESERIES_ESSENTIALS_CHRON, QUERY_TIMESERIES_ESSENTIALS_PALEO, QUERY_DISTINCT_VARIABLE, QUERY_DATASET_PROPERTIES, QUERY_VARIABLE_PROPERTIES, QUERY_MODEL_PROPERTIES, QUERY_LOCATION @@ -1186,3 +1187,37 @@ def get_datasets(self) -> 'list[Dataset]': ds = Dataset.from_data(dsuri, data) datasets.append(ds) return datasets + + + def load_datasets(self, datasets: 'list[Dataset]'): + ''' + Loads instances of Dataset class into the LiPD graph + + Parameters + ---------- + list of pylipd.classes.Dataset + A list of Dataset objects + + Examples + -------- + + pyLipd ships with existing datasets that can be loaded directly through the package. Let's load the Pages2k sample datasets using this method. + + .. jupyter-execute:: + + from pylipd.utils.dataset import load_dir + + lipd = load_dir('Pages2k') + dses = lipd.get_datasets() + + # Modify the datasets if needed, then write them to the same, or another LiPD object + + lipd2 = LiPD() + lipd2.load_datasets(dses) + + ''' + for ds in datasets: + dsuri = ds.id + j2r = JSONToRDF(self.graph, dsuri) + j2r.load_data_in_graph(ds.to_data()) + diff --git a/pylipd/utils/create_classes.py b/pylipd/utils/create_classes.py index 5cfdaa0..6f0dfed 100644 --- a/pylipd/utils/create_classes.py +++ b/pylipd/utils/create_classes.py @@ -5,16 +5,15 @@ SCRIPTDIR = os.path.dirname(os.path.realpath(__file__)) CLASSDIR = os.path.realpath(f"{SCRIPTDIR}/../classes") -# CLASSDIR = "classes" - if not os.path.exists(CLASSDIR): os.makedirs(CLASSDIR) -def get_fromdata_item(type, range): + +def get_fromdata_item(ptype, range, is_enum): fromdataitem = f""" for val in value:""" - if type == "object" and range is not None: - if "synonyms" in prop: + if ptype == "object" and range is not None: + if is_enum: fromdataitem += f""" obj = {range}.from_synonym(re.sub("^.*?#", "", val["@id"])) """ @@ -34,6 +33,7 @@ def get_fromdata_item(type, range): obj = val["@id"]""" return fromdataitem + def get_todata_item(type, range): todataitem = "" if type == "literal" and range: @@ -55,28 +55,89 @@ def get_todata_item(type, range): "@id": value_obj.id, "@type": "uri" }} - data = value_obj.to_data(data) - """ + data = value_obj.to_data(data)""" return todataitem -for sectionid in SYNONYMS: - for clsid in SYNONYMS[sectionid]: - done = {} - synonyms = SYNONYMS[sectionid][clsid] +def get_python_snippet_for_multi_value_property(propid, pname, ptype, ont_range, python_range, getter, setter, adder, is_enum): + # Create the python snippet for initialzing property variables + initvar = f"self.{pname}: list[{python_range}] = []" + + # Create the python function snippet for this property to convert the class to a dictionary (todata) + todataitem = get_todata_item(ptype, ont_range) + todata = f""" + + if len(self.{pname}): + data[self.id]["{propid}"] = [] + for value_obj in self.{pname}:{todataitem} + data[self.id]["{propid}"].append(obj)""" + + # Create the python function snippet for this property to convert from data dictionary to a class (fromdata) + fromdataitem = get_fromdata_item(ptype, python_range, is_enum) + fromdata = f""" + elif key == "{propid}":{fromdataitem} + self.{pname}.append(obj)""" + + # Create the python snippet for getter/setter/adders + fns = f""" + def {getter}(self) -> list[{python_range}]: + return self.{pname} + + def {setter}(self, {pname}:list[{python_range}]): + self.{pname} = {pname} + + def {adder}(self, {pname}:{python_range}): + self.{pname}.append({pname}) + """ + return (initvar, todata, fromdata, fns) + + +def get_python_snippet_for_property(propid, pname, ptype, ont_range, python_range, getter, setter, is_enum): + # Create the python snippet for initialzing property variables + initvar = f"self.{pname}: {python_range} = None" + + # Create the python function snippet for this property to convert the class to a dictionary (todata) + todataitem = get_todata_item(ptype, ont_range) + todata = f""" + + if self.{pname}: + value_obj = self.{pname}{todataitem} + data[self.id]["{propid}"] = [obj] + """ + # Create the python function snippet for this property to convert from data dictionary to a class (fromdata) + fromdataitem = get_fromdata_item(ptype, python_range, is_enum) + fromdata = f""" + elif key == "{propid}":{fromdataitem} + self.{pname} = obj""" + + # Create the python snippet for getter/setter/adders + fns = f""" + def {getter}(self) -> {python_range}: + return self.{pname} + + def {setter}(self, {pname}:{python_range}): + self.{pname} = {pname} + """ + return (initvar, todata, fromdata, fns) + + +def generate_enum_classes(): + for sectionid in SYNONYMS: + for clsid in SYNONYMS[sectionid]: + done = {} + synonyms = SYNONYMS[sectionid][clsid] - fileid = clsid.lower() - with open(f"{CLASSDIR}/{fileid}.py", "w") as outf: - outf.write(""" + fileid = clsid.lower() + with open(f"{CLASSDIR}/{fileid}.py", "w") as outf: + outf.write(""" ############################## # Auto-generated. Do not Edit ############################## - """) - outf.write("from pylipd.globals.synonyms import SYNONYMS\n\n") + outf.write("from pylipd.globals.synonyms import SYNONYMS\n\n") - outf.write(f"class {clsid}:") - outf.write(f""" + outf.write(f"class {clsid}:") + outf.write(f""" synonyms = SYNONYMS["{sectionid}"]["{clsid}"] def __init__(self, id, label): @@ -110,179 +171,55 @@ def from_synonym(cls, synonym): synobj = {clsid}.synonyms[synonym.lower()] return {clsid}(synobj['id'], synobj['label']) return None - + """) - outf.write(f"class {clsid}Constants:") - for synonym in synonyms: - synobj = synonyms[synonym] - synid = re.sub("[^a-zA-Z0-9]", "_", re.sub(".*?#", "", synobj["id"])) - if synid in done: - continue - done[synid] = True - outf.write(f""" + outf.write(f"class {clsid}Constants:") + for synonym in synonyms: + synobj = synonyms[synonym] + synid = re.sub("[^a-zA-Z0-9]", "_", re.sub(".*?#", "", synobj["id"])) + if synid in done: + continue + done[synid] = True + outf.write(f""" {synid} = {clsid}("{synobj['id']}", "{synobj['label']}")""") + -for clsid in SCHEMA: - props = SCHEMA[clsid] - - imports = set() - initvars = set() - fromdata = set() - todata = set() - fns = set() - - iffed = False - for pid in props: - if pid[0] == "@": - continue - prop = props[pid] - - propid = pid - if "name" in prop: - propid = prop["name"] - - pname = propid - if re.match("^has", propid): - pname = re.sub("^has", "", propid) - elif re.match("^is", propid): - pname = re.sub("^is", "", propid) - - # Fix if property name is "type". Gets mixed up - if pname.lower() == "type": - pname = f"{clsid}Type" - - pname = pname[0].lower() + pname[1:] - - multiple = prop.get("multiple", False) - mpname = pname - if multiple and not re.match(".*(data|by)$", pname, re.I): - mpname += "s" - - adder = None - suffix = pname[0].upper() + pname[1:] - setter = "set" + suffix - if re.match("^is", propid): - getter = "is" + suffix - else: - getter = "get" + suffix - if multiple: - adder = "add" + suffix - if not re.match(".*(data|by)$", pname, re.I): - setter += "s" - getter += "s" - - range = "string" - type = "literal" - if "class_type" in prop: - range = prop["class_type"] - elif "type" in prop: - range = prop["type"] - if range == "Individual": - range = None - if "class_range" in prop: - type = "object" - range = prop["class_range"] - elif "schema" in prop: - type = "object" - range = prop["schema"] - - todataitem = get_todata_item(type, range) - - # Rewriting ranges to python types - if range == "integer": - range = "int" - elif range == "string": - range = "str" - elif range == "boolean": - range = "bool" - - if type == "object": - imports.add(range) - - fromdataitem = get_fromdata_item(type, range) - - if multiple: - initvars.add(f"self.{mpname}: list[{range}] = []") - mptodataitem = f""" - if len(self.{mpname}): - data[self.id]["{propid}"] = [] - for value_obj in self.{mpname}:{todataitem} - data[self.id]["{propid}"].append(obj)""" - todata.add(mptodataitem) - - mpfromdataitem = f""" - elif key == "{propid}": -{fromdataitem} - self.{mpname}.append(obj)""" - fromdata.add(mpfromdataitem) - - fns.add(f""" - def {getter}(self) -> list[{range}]: - return self.{mpname} - - def {setter}(self, {mpname}:list[{range}]): - self.{mpname} = {mpname} - - def {adder}(self, {pname}:{range}): - self.{mpname}.append({pname}) - """) - - else: - initvars.add(f"self.{pname}: {range} = None") - sfromdataitem = f""" - elif key == "{propid}": -{fromdataitem} - self.{pname} = obj""" - fromdata.add(sfromdataitem) - - stodataitem = f""" - if self.{pname}: - value_obj = self.{pname}{todataitem} - data[self.id]["{propid}"] = [obj] - """ - todata.add(stodataitem) - - fns.add(f""" - def {getter}(self) -> {range}: - return self.{pname} - - def {setter}(self, {pname}:{range}): - self.{pname} = {pname} -""") - fileid = clsid.lower() - with open(f"{CLASSDIR}/{fileid}.py", "w") as outf: +def generate_class_file(clsid, import_snippets, initvar_snippets, todata_snippets, fromdata_snippets, fn_snippets): + filename = f"{CLASSDIR}/{clsid.lower()}.py" + + with open(filename, "w") as outf: + # Write the header outf.write(""" ############################## # Auto-generated. Do not Edit ############################## """) + # Write the imports outf.write(f"import re\n") outf.write("from pylipd.utils import uniqid\n") - - for im in imports: + for im in import_snippets: outf.write(f"from pylipd.classes.{im.lower()} import {im}\n") outf.write("\n") + + # Write the class header outf.write(f"class {clsid}:\n") + + # Write the init function outf.write(f""" def __init__(self):""") - for initvar in initvars: + for snippet in initvar_snippets: outf.write(f""" - {initvar}""") - - # namespace is hardcoded (from class generation) - # type is hardcoded (from class generation) : ontns + class - # id is generated initially (ns + class + "." + uuid) - # id can be overridden in from_data - + {snippet}""") outf.write(f""" self.misc = {{}} self.ontns = "{ONTONS}" self.ns = "{NSURL}" self.type = "{ONTONS}{clsid}" - self.id = self.ns + "/" + uniqid("{clsid}")""") - + self.id = self.ns + "/" + uniqid("{clsid}.")""") outf.write("\n") + + # Write the from_data function outf.write(f""" @staticmethod def from_data(id, data) -> '{clsid}': @@ -295,22 +232,24 @@ def from_data(id, data) -> '{clsid}': if key == "type": for val in value: self.type = val["@id"]""") - for initvar in fromdata: + for snippet in fromdata_snippets: outf.write(f""" - {initvar}""") + {snippet}""") + outf.write(f""" 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""") outf.write("\n") + # Write the to_data function outf.write(f""" def to_data(self, data={{}}): data[self.id] = {{}} @@ -319,14 +258,12 @@ def to_data(self, data={{}}): "@id": self.type, "@type": "uri" }} - ] -""") + ]""") - for tovar in todata: - outf.write(f""" - {tovar}""") - outf.write(f""" + for snippet in todata_snippets: + outf.write(f"""{snippet}""") + outf.write(f""" for key in self.misc: value = self.misc[key] data[self.id][key] = [] @@ -334,7 +271,7 @@ def to_data(self, data={{}}): 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): @@ -353,6 +290,8 @@ def to_data(self, data={{}}): return data""") outf.write("\n") + + # Write the functions to handle non standard properties outf.write(f""" def set_non_standard_property(self, key, value): if key not in self.misc: @@ -360,7 +299,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 @@ -368,6 +307,116 @@ def add_non_standard_property(self, key, value): if key not in self.misc: self.misc[key] = [] self.misc[key].append(value) - """) - for fn in fns: - outf.write(fn) \ No newline at end of file + """) + + # Write the getter/setter functions + for fn in fn_snippets: + outf.write(fn) + + +def generate_lipd_classes(): + # Check all classes in Schema + for clsid in SCHEMA: + props = SCHEMA[clsid] + + import_snippets = set() + initvar_snippets = set() + fromdata_snippets = set() + todata_snippets = set() + fn_snippets = set() + + # Check all properties + for pid in props: + if pid[0] == "@": + continue + prop = props[pid] + + propid = pid + if "name" in prop: + propid = prop["name"] + + # Create the python property name (pname) from ontology property id (propid) + pname = propid + if re.match("^has", propid): + pname = re.sub("^has", "", propid) + elif re.match("^is", propid): + pname = re.sub("^is", "", propid) + # Fix if property name is "type". Gets mixed up + if pname.lower() == "type": + pname = f"{clsid}Type" + pname = pname[0].lower() + pname[1:] + + # Check if the property is supposed to have multiple values. Rename accordingly + multiple = prop.get("multiple", False) + mpname = pname + if multiple and not re.match(".*(data|by)$", pname, re.I): + mpname += "s" + + is_enum = ("synonyms" in prop) + + # Create getter/setter/adder function names + adder = None + suffix = pname[0].upper() + pname[1:] + setter = "set" + suffix + if re.match("^is", propid): + getter = "is" + suffix + else: + getter = "get" + suffix + if multiple: + adder = "add" + suffix + if not re.match(".*(data|by)$", pname, re.I): + setter += "s" + getter += "s" + + # Get the range of the property + ont_range = "string" + ptype = "literal" + if "class_type" in prop: + ont_range = prop["class_type"] + elif "type" in prop: + ont_range = prop["type"] + if ont_range == "Individual": + ont_range = None + if "class_range" in prop: + ptype = "object" + ont_range = prop["class_range"] + elif "schema" in prop: + ptype = "object" + ont_range = prop["schema"] + + python_range = ont_range + # Rewrite the property range to python types + if ont_range == "integer": + python_range = "int" + elif ont_range == "string": + python_range = "str" + elif ont_range == "boolean": + python_range = "bool" + + # Get python snippets for initialization function, todata function, fromdata from, and the setter/getter functions + if multiple: + (initvar, todata, fromdata, fns) = get_python_snippet_for_multi_value_property(propid, mpname, ptype, + ont_range, python_range, + getter, setter, adder, is_enum) + else: + (initvar, todata, fromdata, fns) = get_python_snippet_for_property(propid, mpname, ptype, + ont_range, python_range, + getter, setter, is_enum) + + # Collect all snippets + # Import the range class (in case the range is a class) + if ptype == "object": + import_snippets.add(python_range) + initvar_snippets.add(initvar) + todata_snippets.add(todata) + fromdata_snippets.add(fromdata) + fn_snippets.add(fns) + + # Write outputs + generate_class_file(clsid, sorted(import_snippets), sorted(initvar_snippets), + sorted(todata_snippets), sorted(fromdata_snippets), sorted(fn_snippets)) + + +if __name__ == "__main__": + generate_enum_classes() + generate_lipd_classes() \ No newline at end of file