Skip to content

Commit 892f7c1

Browse files
move from cls to self for instance properties
1 parent c9c513e commit 892f7c1

File tree

8 files changed

+124
-124
lines changed

8 files changed

+124
-124
lines changed

data2rdf/models/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ class BasicGraphModel(BasicConceptMapping):
7171

7272
@property
7373
@abstractmethod
74-
def json_ld(cls) -> Dict[str, Any]:
74+
def json_ld(self) -> Dict[str, Any]:
7575
"""Return dict for json-ld of graph"""
7676

7777
@property
78-
def graph(cls) -> Graph:
78+
def graph(self) -> Graph:
7979
"""Return graph object based on json-ld"""
80-
graph = Graph(identifier=cls.config.graph_identifier)
81-
graph.parse(data=json.dumps(cls.json_ld), format="json-ld")
80+
graph = Graph(identifier=self.config.graph_identifier)
81+
graph.parse(data=json.dumps(self.json_ld), format="json-ld")
8282
return graph
8383

8484

data2rdf/models/graph.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,23 @@ def validate_quantity_graph(cls, self) -> "QuantityGraph":
226226
return self
227227

228228
@property
229-
def json_ld(cls) -> Dict[str, Any]:
229+
def json_ld(self) -> Dict[str, Any]:
230230
"""Return dict of json-ld for graph"""
231231
return {
232232
"@context": {
233-
f"{cls.config.prefix_name}": make_prefix(cls.config),
233+
f"{self.config.prefix_name}": make_prefix(self.config),
234234
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
235235
"xsd": "http://www.w3.org/2001/XMLSchema#",
236236
"qudt": "http://qudt.org/schema/qudt/",
237237
},
238-
"@id": f"{cls.config.prefix_name}:{cls.suffix}",
238+
"@id": f"{self.config.prefix_name}:{self.suffix}",
239239
"@type": (
240-
[str(iri) for iri in cls.iri]
241-
if isinstance(cls.iri, list)
242-
else str(cls.iri)
240+
[str(iri) for iri in self.iri]
241+
if isinstance(self.iri, list)
242+
else str(self.iri)
243243
),
244-
**cls.unit_json,
245-
**cls.value_json,
244+
**self.unit_json,
245+
**self.value_json,
246246
}
247247

248248
@property
@@ -340,17 +340,17 @@ def validate_property_graph(cls, self: "PropertyGraph") -> "PropertyGraph":
340340
return self
341341

342342
@property
343-
def json_ld(cls) -> Dict[str, Any]:
343+
def json_ld(self) -> Dict[str, Any]:
344344
"""Return dict of json-ld for graph"""
345345
return {
346346
"@context": {
347-
f"{cls.config.prefix_name}": make_prefix(cls.config),
347+
f"{self.config.prefix_name}": make_prefix(self.config),
348348
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
349349
"xsd": "http://www.w3.org/2001/XMLSchema#",
350350
},
351-
"@id": f"{cls.config.prefix_name}:{cls.suffix}",
352-
**cls.value_json,
353-
**cls.types_json,
351+
"@id": f"{self.config.prefix_name}:{self.suffix}",
352+
**self.value_json,
353+
**self.types_json,
354354
}
355355

356356
@property
@@ -372,26 +372,26 @@ def value_json(self) -> "Optional[Dict[str, str]]":
372372
return response
373373

374374
@property
375-
def types_json(cls) -> "Dict[str, Any]":
375+
def types_json(self) -> "Dict[str, Any]":
376376
"""Dict of json-ld for class types of the individual"""
377-
if cls.annotation:
377+
if self.annotation:
378378
types = {
379379
"@type": [
380380
(
381-
[str(iri) for iri in cls.iri]
382-
if isinstance(cls.iri, list)
383-
else str(cls.iri)
381+
[str(iri) for iri in self.iri]
382+
if isinstance(self.iri, list)
383+
else str(self.iri)
384384
),
385-
cls.annotation,
385+
self.annotation,
386386
]
387387
}
388388
else:
389389
types = {
390390
"@type": [
391391
(
392-
[str(iri) for iri in cls.iri]
393-
if isinstance(cls.iri, list)
394-
else str(cls.iri)
392+
[str(iri) for iri in self.iri]
393+
if isinstance(self.iri, list)
394+
else str(self.iri)
395395
)
396396
]
397397
}

data2rdf/parsers/base.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def json_ld(self) -> Dict[str, Any]:
7272

7373
@property
7474
@abstractmethod
75-
def mapping_model(cls) -> "BaseParser":
75+
def mapping_model(self) -> "BaseParser":
7676
"""Pydantic model for validating mapping.
7777
Must be a subclass of `ABoxBaseParser` or `TBoxBaseParser`.
7878
"""
@@ -93,10 +93,10 @@ def _load_data_file(cls, self: "BaseParser") -> "Dict[str, Any]":
9393
"""Class method for loading data file"""
9494

9595
@property
96-
def graph(cls) -> "Graph":
96+
def graph(self) -> "Graph":
9797
"""Return RDF Graph from the parsed data."""
98-
graph = Graph(identifier=cls.config.graph_identifier)
99-
graph.parse(data=json.dumps(cls.json_ld), format="json-ld")
98+
graph = Graph(identifier=self.config.graph_identifier)
99+
graph.parse(data=json.dumps(self.json_ld), format="json-ld")
100100
return graph
101101

102102
@model_validator(mode="after")
@@ -313,11 +313,11 @@ def execute_parser(cls, self: "BaseFileParser") -> "BaseFileParser":
313313
return self
314314

315315
@property
316-
def plain_metadata(cls) -> Dict[str, Any]:
316+
def plain_metadata(self) -> Dict[str, Any]:
317317
"""Metadata as flat json - without units and iris.
318318
Useful e.g. for the custom properties of the DSMS."""
319-
if cls.mode == PipelineMode.ABOX:
320-
return cls.abox.plain_metadata
319+
if self.mode == PipelineMode.ABOX:
320+
return self.abox.plain_metadata
321321
else:
322322
raise NotImplementedError(
323323
"`plain_metadata` is not available in `tbox`-mode."
@@ -333,30 +333,30 @@ def to_dict(self, schema: Callable = None) -> "List[Dict[str, Any]]":
333333
)
334334

335335
@property
336-
def general_metadata(cls) -> "List[BasicConceptMapping]":
336+
def general_metadata(self) -> "List[BasicConceptMapping]":
337337
"""Return list object with general metadata"""
338-
if cls.mode == PipelineMode.ABOX:
339-
return cls.abox.general_metadata
338+
if self.mode == PipelineMode.ABOX:
339+
return self.abox.general_metadata
340340
else:
341341
raise NotImplementedError(
342342
"`general_metadata` is not available in `tbox`-mode."
343343
)
344344

345345
@property
346-
def dataframe_metadata(cls) -> "List[BasicConceptMapping]":
346+
def dataframe_metadata(self) -> "List[BasicConceptMapping]":
347347
"""Return time series metadata"""
348-
if cls.mode == PipelineMode.ABOX:
349-
return cls.abox.dataframe_metadata
348+
if self.mode == PipelineMode.ABOX:
349+
return self.abox.dataframe_metadata
350350
else:
351351
raise NotImplementedError(
352352
"`dataframe_metadata` is not available in `tbox`-mode."
353353
)
354354

355355
@property
356-
def dataframe(cls) -> "Dict[str, Any]":
356+
def dataframe(self) -> "Dict[str, Any]":
357357
"""Return time series"""
358-
if cls.mode == PipelineMode.ABOX:
359-
return cls.abox.dataframe
358+
if self.mode == PipelineMode.ABOX:
359+
return self.abox.dataframe
360360
else:
361361
raise NotImplementedError(
362362
"`dataframe` is not available in `tbox`-mode."

data2rdf/parsers/csv.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ class CSVTBoxParser(TBoxBaseParser):
6868

6969
# OVERRIDE
7070
@property
71-
def mapping_model(cls) -> TBoxBaseMapping:
71+
def mapping_model(self) -> TBoxBaseMapping:
7272
"""TBox Mapping Model for CSV Parser"""
7373
return TBoxBaseMapping
7474

7575
# OVERRIDE
7676
@property
77-
def json_ld(cls) -> "Dict[str, Any]":
77+
def json_ld(self) -> "Dict[str, Any]":
7878
"""Make the json-ld if pipeline is in abox-mode"""
79-
return _make_tbox_json_ld(cls)
79+
return _make_tbox_json_ld(self)
8080

8181
# OVERRIDE
8282
@classmethod
@@ -137,13 +137,13 @@ class CSVABoxParser(ABoxBaseParser):
137137

138138
# OVERRIDE
139139
@property
140-
def mapping_model(cls) -> ABoxBaseMapping:
140+
def mapping_model(self) -> ABoxBaseMapping:
141141
"""ABox Mapping Model for CSV Parser"""
142142
return ABoxBaseMapping
143143

144144
# OVERRIDE
145145
@property
146-
def json_ld(cls) -> "Dict[str, Any]":
146+
def json_ld(self) -> "Dict[str, Any]":
147147
"""
148148
Returns a JSON-LD representation of the CSV data in ABox mode.
149149
@@ -162,17 +162,17 @@ def json_ld(cls) -> "Dict[str, Any]":
162162
Dict[str, Any]: A JSON-LD object representing the CSV data in ABox mode.
163163
"""
164164

165-
if not cls.config.suppress_file_description:
165+
if not self.config.suppress_file_description:
166166
tables = []
167167

168-
if cls.general_metadata:
168+
if self.general_metadata:
169169
meta_table = {
170170
"@type": "csvw:Table",
171171
"rdfs:label": "Metadata",
172172
"csvw:row": [],
173173
}
174174

175-
for n, mapping in enumerate(cls.general_metadata):
175+
for n, mapping in enumerate(self.general_metadata):
176176
if isinstance(mapping, QuantityGraph):
177177
row = {
178178
"@type": "csvw:Row",
@@ -207,7 +207,7 @@ def json_ld(cls) -> "Dict[str, Any]":
207207
)
208208
tables += [meta_table]
209209

210-
if cls.dataframe_metadata:
210+
if self.dataframe_metadata:
211211
column_schema = {"@type": "csvw:Schema", "csvw:column": []}
212212
tables += [
213213
{
@@ -216,7 +216,7 @@ def json_ld(cls) -> "Dict[str, Any]":
216216
"csvw:tableSchema": column_schema,
217217
}
218218
]
219-
for idx, mapping in enumerate(cls.dataframe_metadata):
219+
for idx, mapping in enumerate(self.dataframe_metadata):
220220
if isinstance(mapping, QuantityGraph):
221221
entity = {"qudt:quantity": mapping.json_ld}
222222
elif isinstance(mapping, PropertyGraph):
@@ -226,12 +226,12 @@ def json_ld(cls) -> "Dict[str, Any]":
226226
f"Mapping must be of type {QuantityGraph} or {PropertyGraph}, not {type(mapping)}"
227227
)
228228

229-
if cls.config.data_download_uri:
229+
if self.config.data_download_uri:
230230
download_url = {
231231
"dcterms:identifier": {
232232
"@type": "xsd:anyURI",
233233
"@value": urljoin(
234-
str(cls.config.data_download_uri),
234+
str(self.config.data_download_uri),
235235
f"column-{idx}",
236236
),
237237
}
@@ -272,7 +272,7 @@ def json_ld(cls) -> "Dict[str, Any]":
272272

273273
json_ld = {
274274
"@context": {
275-
f"{cls.config.prefix_name}": make_prefix(cls.config),
275+
f"{self.config.prefix_name}": make_prefix(self.config),
276276
"csvw": "http://www.w3.org/ns/csvw#",
277277
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
278278
"dcat": "http://www.w3.org/ns/dcat#",
@@ -282,14 +282,14 @@ def json_ld(cls) -> "Dict[str, Any]":
282282
"csvw": "http://www.w3.org/ns/csvw#",
283283
"foaf": "http://xmlns.com/foaf/spec/",
284284
},
285-
"@id": f"{cls.config.prefix_name}:tableGroup",
285+
"@id": f"{self.config.prefix_name}:tableGroup",
286286
"@type": "csvw:TableGroup",
287287
**csvw_tables,
288288
}
289289
else:
290290
json_ld = {
291-
"@graph": [model.json_ld for model in cls.general_metadata]
292-
+ [model.json_ld for model in cls.dataframe_metadata]
291+
"@graph": [model.json_ld for model in self.general_metadata]
292+
+ [model.json_ld for model in self.dataframe_metadata]
293293
}
294294
return json_ld
295295

0 commit comments

Comments
 (0)