data2rdf 2.4.0.dev0__tar.gz → 2.4.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/PKG-INFO +1 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/config.py +0 -5
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/base.py +29 -22
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/utils.py +0 -23
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/pipelines/main.py +3 -3
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/PKG-INFO +1 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/setup.cfg +1 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/test_parser.py +3 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/test_pipeline.py +3 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/test_parser.py +3 -3
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/test_pipeline.py +3 -3
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/test_parser.py +3 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/test_pipeline.py +3 -1
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/test_parser.py +3 -3
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/test_pipeline.py +3 -3
- data2rdf-2.4.0.dev1/tests/abox/utils.py +101 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/xls_pipeline_test/test_parser.py +5 -5
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/xls_pipeline_test/test_pipeline.py +5 -5
- data2rdf-2.4.0.dev0/tests/abox/utils.py +0 -49
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/LICENSE +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/README.md +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/models/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/models/base.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/models/graph.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/models/mapping.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/models/utils.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/modes/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/csv.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/excel.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/json.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/pipelines/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/qudt/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/qudt/utils.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/utils.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf/warnings.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/SOURCES.txt +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/dependency_links.txt +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/requires.txt +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/top_level.txt +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/setup.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/output/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/input/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/test.csv +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/mapping/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/output/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/dict_custom_properties/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/dict_custom_properties/test_pipeline.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_custom_relations/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_custom_relations/test_json_custom_relations.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_multiple_iris/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_multiple_iris/test_multiple_iris.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/test_models.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/xls_custom_relations/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/xls_custom_relations/test_xlsx_custom_relations.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/xls_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/test_parser.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/test_pipeline.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/explicit_datatypes/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/explicit_datatypes/test_explicit_datatypes.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_parser.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_pipeline.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_title_exclusion.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/__init__.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/test_parser.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/test_pipeline.py +0 -0
- {data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: data2rdf
|
|
3
|
-
Version: 2.4.0.
|
|
3
|
+
Version: 2.4.0.dev1
|
|
4
4
|
Summary: A generic pipeline that can be used to map raw data to RDF.
|
|
5
5
|
Home-page: https://github.com/MI-FraunhoferIWM/data2rdf
|
|
6
6
|
Author: Paul Zierep, Yoav Nahshon, Pablo de Andres, Deepu Krishnareddy, Matthias Büschelberger
|
|
@@ -79,11 +79,6 @@ class Config(BaseSettings):
|
|
|
79
79
|
description="In TBox mode, exclude the title of the ontology in the graph.",
|
|
80
80
|
)
|
|
81
81
|
|
|
82
|
-
dsms_schema_default: bool = Field(
|
|
83
|
-
True,
|
|
84
|
-
description="""Default value for the `dsms_schema` parameter of the `to_dict` method.""",
|
|
85
|
-
)
|
|
86
|
-
|
|
87
82
|
model_config = ConfigDict(extra="ignore")
|
|
88
83
|
|
|
89
84
|
@model_validator(mode="after")
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import json
|
|
4
4
|
import warnings
|
|
5
5
|
from abc import abstractmethod
|
|
6
|
-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
7
7
|
|
|
8
8
|
from rdflib import Graph
|
|
9
9
|
|
|
10
10
|
from data2rdf.config import Config
|
|
11
11
|
from data2rdf.modes import PipelineMode
|
|
12
12
|
|
|
13
|
-
from .utils import
|
|
13
|
+
from .utils import load_mapping_file
|
|
14
14
|
|
|
15
15
|
from pydantic import ( # isort:skip
|
|
16
16
|
BaseModel,
|
|
@@ -195,12 +195,32 @@ class ABoxBaseParser(AnyBoxBaseParser):
|
|
|
195
195
|
`plain_metadata` is deprecated and will be removed in a future version.
|
|
196
196
|
Use the `to_dict()` instead."""
|
|
197
197
|
warnings.warn(message, DeprecationWarning)
|
|
198
|
-
return self.to_dict(
|
|
198
|
+
return self.to_dict()
|
|
199
199
|
|
|
200
200
|
def to_dict(
|
|
201
|
-
self,
|
|
201
|
+
self, schema: Callable = None
|
|
202
202
|
) -> "Union[Dict[str, Any], List[Dict[str, Any]]]":
|
|
203
|
-
"""
|
|
203
|
+
"""
|
|
204
|
+
Return general metadata as a list of dictionaries.
|
|
205
|
+
|
|
206
|
+
The list contains dictionaries, where the key is the label of the metadata,
|
|
207
|
+
and the value is a dictionary with the keys 'label' and 'value'. If the
|
|
208
|
+
metadata has a measurement unit associated with it, the dictionary will
|
|
209
|
+
also contain the key 'measurement_unit' with the value of the measurement
|
|
210
|
+
unit.
|
|
211
|
+
|
|
212
|
+
If the schema parameter is provided, it will be used to transform the
|
|
213
|
+
metadata list. The schema should be a callable which takes the list of
|
|
214
|
+
metadata dictionaries and returns the transformed metadata.
|
|
215
|
+
|
|
216
|
+
If no schema is provided, the function will return a dictionary where the
|
|
217
|
+
keys are the labels of the metadata, and the values are the dictionaries
|
|
218
|
+
from the list.
|
|
219
|
+
|
|
220
|
+
:param schema: A callable which takes a list of dictionaries and returns
|
|
221
|
+
the transformed metadata.
|
|
222
|
+
:return: A dictionary or list of dictionaries with the metadata.
|
|
223
|
+
"""
|
|
204
224
|
metadata = []
|
|
205
225
|
for metadatum in self.general_metadata:
|
|
206
226
|
prop = {
|
|
@@ -212,21 +232,8 @@ class ABoxBaseParser(AnyBoxBaseParser):
|
|
|
212
232
|
"measurement_unit"
|
|
213
233
|
] = metadatum.measurement_unit.model_dump(exclude={"config"})
|
|
214
234
|
metadata.append(prop)
|
|
215
|
-
if
|
|
216
|
-
|
|
217
|
-
for metadatum in metadata:
|
|
218
|
-
metadatum["id"] = generate_id()
|
|
219
|
-
metadata = {
|
|
220
|
-
"sections": [
|
|
221
|
-
{
|
|
222
|
-
"id": generate_id(),
|
|
223
|
-
"name": "General",
|
|
224
|
-
"entries": metadata,
|
|
225
|
-
}
|
|
226
|
-
]
|
|
227
|
-
}
|
|
228
|
-
else:
|
|
229
|
-
metadata = {}
|
|
235
|
+
if not isinstance(schema, type(None)):
|
|
236
|
+
metadata = schema(metadata)
|
|
230
237
|
else:
|
|
231
238
|
metadata = {datum.get("label"): datum for datum in metadata}
|
|
232
239
|
return metadata
|
|
@@ -313,10 +320,10 @@ class BaseFileParser(BaseParser):
|
|
|
313
320
|
"`plain_metadata` is not available in `tbox`-mode."
|
|
314
321
|
)
|
|
315
322
|
|
|
316
|
-
def to_dict(self,
|
|
323
|
+
def to_dict(self, schema: Callable = None) -> "List[Dict[str, Any]]":
|
|
317
324
|
"""Return list of general metadata as DSMS custom properties"""
|
|
318
325
|
if self.mode == PipelineMode.ABOX:
|
|
319
|
-
return self.abox.to_dict(
|
|
326
|
+
return self.abox.to_dict(schema=schema)
|
|
320
327
|
else:
|
|
321
328
|
raise NotImplementedError(
|
|
322
329
|
"`to_dict()` is not available in `tbox`-mode."
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"""Data2RDF parser utilities"""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
import random
|
|
5
|
-
import string
|
|
6
|
-
import time
|
|
7
4
|
import warnings
|
|
8
5
|
from typing import TYPE_CHECKING
|
|
9
6
|
|
|
@@ -219,23 +216,3 @@ def _value_exists(value: "Any") -> bool:
|
|
|
219
216
|
bool: True if the value exists and is valid, otherwise False.
|
|
220
217
|
"""
|
|
221
218
|
return pd.notnull(value) and value != ""
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
def generate_id(prefix: str = "id") -> str:
|
|
225
|
-
# Generate a unique part using time and random characters
|
|
226
|
-
"""
|
|
227
|
-
Generates a unique id using a combination of the current time and 6 random characters.
|
|
228
|
-
|
|
229
|
-
Args:
|
|
230
|
-
prefix (str): The prefix to use for the generated id. Defaults to "id".
|
|
231
|
-
|
|
232
|
-
Returns:
|
|
233
|
-
str: The generated id.
|
|
234
|
-
"""
|
|
235
|
-
unique_part = f"{int(time.time() * 1000)}" # Milliseconds since epoch
|
|
236
|
-
random_part = "".join(
|
|
237
|
-
random.choices(string.ascii_lowercase + string.digits, k=6) # nosec
|
|
238
|
-
)
|
|
239
|
-
# Combine prefix, unique part, and random part
|
|
240
|
-
generated_id = f"{prefix}{unique_part}{random_part}"
|
|
241
|
-
return generated_id
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
6
6
|
|
|
7
7
|
from rdflib import Graph
|
|
8
8
|
|
|
@@ -210,10 +210,10 @@ class Data2RDF(BaseModel):
|
|
|
210
210
|
graph += cls._validate_additional_triples(cls.additional_triples)
|
|
211
211
|
return graph
|
|
212
212
|
|
|
213
|
-
def to_dict(self,
|
|
213
|
+
def to_dict(self, schema: Callable = None) -> "List[Dict[str, Any]]":
|
|
214
214
|
"""Return list of general metadata as DSMS custom properties"""
|
|
215
215
|
if self.mode == PipelineMode.ABOX:
|
|
216
|
-
return self.parser.abox.to_dict(
|
|
216
|
+
return self.parser.abox.to_dict(schema=schema)
|
|
217
217
|
else:
|
|
218
218
|
raise NotImplementedError(
|
|
219
219
|
"`to_dict()` is not available in `tbox`-mode."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: data2rdf
|
|
3
|
-
Version: 2.4.0.
|
|
3
|
+
Version: 2.4.0.dev1
|
|
4
4
|
Summary: A generic pipeline that can be used to map raw data to RDF.
|
|
5
5
|
Home-page: https://github.com/MI-FraunhoferIWM/data2rdf
|
|
6
6
|
Author: Paul Zierep, Yoav Nahshon, Pablo de Andres, Deepu Krishnareddy, Matthias Büschelberger
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
+
from ..utils import dsms_schema
|
|
6
|
+
|
|
5
7
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
6
8
|
working_folder = os.path.join(test_folder, "input")
|
|
7
9
|
output_folder = os.path.join(test_folder, "output")
|
|
@@ -59,5 +61,5 @@ def test_csv_nan_vals() -> None:
|
|
|
59
61
|
assert len(column) == 31
|
|
60
62
|
|
|
61
63
|
assert parser.graph.isomorphic(expected_graph)
|
|
62
|
-
assert parser.to_dict(dsms_schema
|
|
64
|
+
assert parser.to_dict(schema=dsms_schema) == {}
|
|
63
65
|
assert parser.to_dict() == {}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
+
from ..utils import dsms_schema
|
|
6
|
+
|
|
5
7
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
6
8
|
working_folder = os.path.join(test_folder, "input")
|
|
7
9
|
output_folder = os.path.join(test_folder, "output")
|
|
@@ -70,5 +72,5 @@ def test_csv_na_values_pipeline() -> None:
|
|
|
70
72
|
|
|
71
73
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
72
74
|
|
|
73
|
-
assert pipeline.to_dict(dsms_schema
|
|
75
|
+
assert pipeline.to_dict(schema=dsms_schema) == {}
|
|
74
76
|
assert pipeline.to_dict() == {}
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
-
from ..utils import as_non_dsms_schema, remove_ids, sort_entries
|
|
8
|
+
from ..utils import as_non_dsms_schema, dsms_schema, remove_ids, sort_entries
|
|
9
9
|
|
|
10
10
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
11
11
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -305,7 +305,7 @@ def test_parser_csv(extension) -> None:
|
|
|
305
305
|
|
|
306
306
|
assert parser.graph.isomorphic(expected_graph)
|
|
307
307
|
|
|
308
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
308
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
309
309
|
metadata
|
|
310
310
|
)
|
|
311
311
|
assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -348,7 +348,7 @@ def test_parser_csv_input(input_kind) -> None:
|
|
|
348
348
|
|
|
349
349
|
assert parser.graph.isomorphic(expected_graph)
|
|
350
350
|
|
|
351
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
351
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
352
352
|
metadata
|
|
353
353
|
)
|
|
354
354
|
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
from ..utils import as_non_dsms_schema, remove_ids, sort_entries
|
|
6
|
+
from ..utils import as_non_dsms_schema, dsms_schema, remove_ids, sort_entries
|
|
7
7
|
|
|
8
8
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
9
9
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -294,7 +294,7 @@ def test_csv_pipeline(extension) -> None:
|
|
|
294
294
|
|
|
295
295
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
296
296
|
|
|
297
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
297
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
298
298
|
metadata
|
|
299
299
|
)
|
|
300
300
|
assert sort_entries(pipeline.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -343,7 +343,7 @@ def test_csv_pipeline_inputs(input_kind) -> None:
|
|
|
343
343
|
|
|
344
344
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
345
345
|
|
|
346
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
346
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
347
347
|
metadata
|
|
348
348
|
)
|
|
349
349
|
assert sort_entries(pipeline.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
+
from ..utils import dsms_schema
|
|
6
|
+
|
|
5
7
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
6
8
|
working_folder = os.path.join(test_folder, "input")
|
|
7
9
|
output_folder = os.path.join(test_folder, "output")
|
|
@@ -50,5 +52,5 @@ def test_csv_wo_header_parser_config() -> None:
|
|
|
50
52
|
assert len(column) == 4
|
|
51
53
|
|
|
52
54
|
assert parser.graph.isomorphic(expected_graph)
|
|
53
|
-
assert parser.to_dict(dsms_schema
|
|
55
|
+
assert parser.to_dict(schema=dsms_schema) == {}
|
|
54
56
|
assert parser.to_dict() == {}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
|
|
5
|
+
from ..utils import dsms_schema
|
|
6
|
+
|
|
5
7
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
6
8
|
working_folder = os.path.join(test_folder, "input")
|
|
7
9
|
output_folder = os.path.join(test_folder, "output")
|
|
@@ -60,5 +62,5 @@ def test_csv_wo_header_pipeline() -> None:
|
|
|
60
62
|
expected_graph.parse(expected)
|
|
61
63
|
|
|
62
64
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
63
|
-
assert pipeline.to_dict(dsms_schema
|
|
65
|
+
assert pipeline.to_dict(schema=dsms_schema) == {}
|
|
64
66
|
assert pipeline.to_dict() == {}
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
-
from ..utils import remove_ids, sort_entries
|
|
8
|
+
from ..utils import dsms_schema, remove_ids, sort_entries
|
|
9
9
|
|
|
10
10
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
11
11
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -85,7 +85,7 @@ def test_parser_json(mapping_format, data_format) -> None:
|
|
|
85
85
|
|
|
86
86
|
assert parser.graph.isomorphic(expected_graph)
|
|
87
87
|
|
|
88
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
88
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
89
89
|
metadata
|
|
90
90
|
)
|
|
91
91
|
|
|
@@ -127,6 +127,6 @@ def test_json_parser_different_mapping_files(extension) -> None:
|
|
|
127
127
|
|
|
128
128
|
assert parser.graph.isomorphic(expected_graph)
|
|
129
129
|
|
|
130
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
130
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
131
131
|
metadata
|
|
132
132
|
)
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
-
from ..utils import remove_ids, sort_entries
|
|
8
|
+
from ..utils import dsms_schema, remove_ids, sort_entries
|
|
9
9
|
|
|
10
10
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
11
11
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -90,7 +90,7 @@ def test_pipeline_json(mapping_format, data_format) -> None:
|
|
|
90
90
|
|
|
91
91
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
92
92
|
|
|
93
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
93
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
94
94
|
metadata
|
|
95
95
|
)
|
|
96
96
|
|
|
@@ -140,6 +140,6 @@ def test_json_pipeline_different_mapping_types(extension) -> None:
|
|
|
140
140
|
|
|
141
141
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
142
142
|
|
|
143
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
143
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
144
144
|
metadata
|
|
145
145
|
)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""data2rdf pytest utilty"""
|
|
2
|
+
import random
|
|
3
|
+
import string
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def remove_ids(metadata: dict) -> dict:
|
|
8
|
+
"""
|
|
9
|
+
Remove 'id' keys from metadata sections and entries.
|
|
10
|
+
|
|
11
|
+
Modifies the input metadata dictionary directly.
|
|
12
|
+
|
|
13
|
+
:param metadata: The metadata dictionary to modify.
|
|
14
|
+
:return: The input metadata dictionary, with 'id' keys removed.
|
|
15
|
+
"""
|
|
16
|
+
for section in metadata.get("sections", []):
|
|
17
|
+
section.pop("id")
|
|
18
|
+
for entry in section.get("entries", []):
|
|
19
|
+
entry.pop("id")
|
|
20
|
+
sort_entries(metadata)
|
|
21
|
+
return metadata
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def sort_entries(metadata: dict) -> dict:
|
|
25
|
+
"""
|
|
26
|
+
Sort entries in metadata by label.
|
|
27
|
+
|
|
28
|
+
Modifies the input metadata dictionary directly.
|
|
29
|
+
"""
|
|
30
|
+
for section in metadata.get("sections", []):
|
|
31
|
+
section["entries"].sort(key=lambda x: x["label"])
|
|
32
|
+
return metadata
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def as_non_dsms_schema(metadata: dict) -> dict:
|
|
36
|
+
"""
|
|
37
|
+
Convert DSMS schema to a flat dictionary.
|
|
38
|
+
|
|
39
|
+
The input should be metadata in the DSMS schema, i.e. a dictionary
|
|
40
|
+
with a "sections" key. Each section should have an "entries" key with
|
|
41
|
+
a list of dictionaries. Each of these dictionaries should have a
|
|
42
|
+
"label" key.
|
|
43
|
+
|
|
44
|
+
The output is a dictionary with the same labels as keys and the same
|
|
45
|
+
dictionaries as values.
|
|
46
|
+
"""
|
|
47
|
+
response = {}
|
|
48
|
+
for section in metadata.get("sections", []):
|
|
49
|
+
section["entries"].sort(key=lambda x: x["label"])
|
|
50
|
+
for entry in section.get("entries", []):
|
|
51
|
+
response[entry["label"]] = entry
|
|
52
|
+
return response
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def dsms_schema(metadata: dict) -> dict:
|
|
56
|
+
"""
|
|
57
|
+
Convert a flat dictionary to a DSMS schema.
|
|
58
|
+
|
|
59
|
+
The input should be a dictionary with each key-value pair representing
|
|
60
|
+
a metadata entry. The output is a dictionary in the DSMS schema, with
|
|
61
|
+
a single section named "General", containing the given metadata entries.
|
|
62
|
+
|
|
63
|
+
:param metadata: The metadata dictionary to convert.
|
|
64
|
+
:return: A dictionary in the DSMS schema.
|
|
65
|
+
"""
|
|
66
|
+
if metadata:
|
|
67
|
+
for metadatum in metadata:
|
|
68
|
+
metadatum["id"] = generate_id()
|
|
69
|
+
metadata = {
|
|
70
|
+
"sections": [
|
|
71
|
+
{
|
|
72
|
+
"id": generate_id(),
|
|
73
|
+
"name": "General",
|
|
74
|
+
"entries": metadata,
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
else:
|
|
79
|
+
metadata = {}
|
|
80
|
+
|
|
81
|
+
return metadata
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def generate_id(prefix: str = "id") -> str:
|
|
85
|
+
# Generate a unique part using time and random characters
|
|
86
|
+
"""
|
|
87
|
+
Generates a unique id using a combination of the current time and 6 random characters.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
prefix (str): The prefix to use for the generated id. Defaults to "id".
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
str: The generated id.
|
|
94
|
+
"""
|
|
95
|
+
unique_part = f"{int(time.time() * 1000)}" # Milliseconds since epoch
|
|
96
|
+
random_part = "".join(
|
|
97
|
+
random.choices(string.ascii_lowercase + string.digits, k=6) # nosec
|
|
98
|
+
)
|
|
99
|
+
# Combine prefix, unique part, and random part
|
|
100
|
+
generated_id = f"{prefix}{unique_part}{random_part}"
|
|
101
|
+
return generated_id
|
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
|
-
from ..utils import as_non_dsms_schema, remove_ids, sort_entries
|
|
8
|
+
from ..utils import as_non_dsms_schema, dsms_schema, remove_ids, sort_entries
|
|
9
9
|
|
|
10
10
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
11
11
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -198,7 +198,7 @@ def test_xlsx_parser_no_match_in_timeseries_from_mapping() -> None:
|
|
|
198
198
|
for name, column in parser.time_series.items():
|
|
199
199
|
assert len(column) == 460
|
|
200
200
|
|
|
201
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
201
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
202
202
|
metadata
|
|
203
203
|
)
|
|
204
204
|
assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -233,7 +233,7 @@ def test_csv_parser_config(config) -> None:
|
|
|
233
233
|
|
|
234
234
|
assert parser.graph.isomorphic(expected_graph)
|
|
235
235
|
assert str(parser.graph.identifier) == config["graph_identifier"]
|
|
236
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
236
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
237
237
|
metadata
|
|
238
238
|
)
|
|
239
239
|
assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -292,7 +292,7 @@ def test_parser_excel(extension) -> None:
|
|
|
292
292
|
|
|
293
293
|
assert parser.graph.isomorphic(expected_graph)
|
|
294
294
|
|
|
295
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
295
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
296
296
|
metadata
|
|
297
297
|
)
|
|
298
298
|
assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -345,7 +345,7 @@ def test_parser_excel_inputs(input_kind) -> None:
|
|
|
345
345
|
|
|
346
346
|
assert parser.graph.isomorphic(expected_graph)
|
|
347
347
|
|
|
348
|
-
assert remove_ids(parser.to_dict(dsms_schema
|
|
348
|
+
assert remove_ids(parser.to_dict(schema=dsms_schema)) == sort_entries(
|
|
349
349
|
metadata
|
|
350
350
|
)
|
|
351
351
|
assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -3,7 +3,7 @@ import os
|
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
5
|
|
|
6
|
-
from ..utils import as_non_dsms_schema, remove_ids, sort_entries
|
|
6
|
+
from ..utils import as_non_dsms_schema, dsms_schema, remove_ids, sort_entries
|
|
7
7
|
|
|
8
8
|
test_folder = os.path.dirname(os.path.abspath(__file__))
|
|
9
9
|
working_folder = os.path.join(test_folder, "input")
|
|
@@ -255,7 +255,7 @@ def test_xlsx_pipeline_config(config) -> None:
|
|
|
255
255
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
256
256
|
assert str(pipeline.graph.identifier) == config["graph_identifier"]
|
|
257
257
|
|
|
258
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
258
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
259
259
|
metadata
|
|
260
260
|
)
|
|
261
261
|
assert sort_entries(pipeline.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -321,7 +321,7 @@ def test_excel_pipeline(extension) -> None:
|
|
|
321
321
|
|
|
322
322
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
323
323
|
|
|
324
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
324
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
325
325
|
metadata
|
|
326
326
|
)
|
|
327
327
|
assert sort_entries(pipeline.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -382,7 +382,7 @@ def test_excel_pipeline_inputs(input_kind) -> None:
|
|
|
382
382
|
|
|
383
383
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
384
384
|
|
|
385
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
385
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
386
386
|
metadata
|
|
387
387
|
)
|
|
388
388
|
assert sort_entries(pipeline.to_dict()) == as_non_dsms_schema(metadata)
|
|
@@ -423,7 +423,7 @@ def test_excel_pipeline_suffix() -> None:
|
|
|
423
423
|
|
|
424
424
|
assert pipeline.graph.isomorphic(expected_graph)
|
|
425
425
|
|
|
426
|
-
assert remove_ids(pipeline.to_dict(dsms_schema
|
|
426
|
+
assert remove_ids(pipeline.to_dict(schema=dsms_schema)) == sort_entries(
|
|
427
427
|
metadata_suffix
|
|
428
428
|
)
|
|
429
429
|
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"""data2rdf pytest utilty"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def remove_ids(metadata: dict) -> dict:
|
|
5
|
-
"""
|
|
6
|
-
Remove 'id' keys from metadata sections and entries.
|
|
7
|
-
|
|
8
|
-
Modifies the input metadata dictionary directly.
|
|
9
|
-
|
|
10
|
-
:param metadata: The metadata dictionary to modify.
|
|
11
|
-
:return: The input metadata dictionary, with 'id' keys removed.
|
|
12
|
-
"""
|
|
13
|
-
for section in metadata.get("sections", []):
|
|
14
|
-
section.pop("id")
|
|
15
|
-
for entry in section.get("entries", []):
|
|
16
|
-
entry.pop("id")
|
|
17
|
-
sort_entries(metadata)
|
|
18
|
-
return metadata
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def sort_entries(metadata: dict) -> dict:
|
|
22
|
-
"""
|
|
23
|
-
Sort entries in metadata by label.
|
|
24
|
-
|
|
25
|
-
Modifies the input metadata dictionary directly.
|
|
26
|
-
"""
|
|
27
|
-
for section in metadata.get("sections", []):
|
|
28
|
-
section["entries"].sort(key=lambda x: x["label"])
|
|
29
|
-
return metadata
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def as_non_dsms_schema(metadata: dict) -> dict:
|
|
33
|
-
"""
|
|
34
|
-
Convert DSMS schema to a flat dictionary.
|
|
35
|
-
|
|
36
|
-
The input should be metadata in the DSMS schema, i.e. a dictionary
|
|
37
|
-
with a "sections" key. Each section should have an "entries" key with
|
|
38
|
-
a list of dictionaries. Each of these dictionaries should have a
|
|
39
|
-
"label" key.
|
|
40
|
-
|
|
41
|
-
The output is a dictionary with the same labels as keys and the same
|
|
42
|
-
dictionaries as values.
|
|
43
|
-
"""
|
|
44
|
-
response = {}
|
|
45
|
-
for section in metadata.get("sections", []):
|
|
46
|
-
section["entries"].sort(key=lambda x: x["label"])
|
|
47
|
-
for entry in section.get("entries", []):
|
|
48
|
-
response[entry["label"]] = entry
|
|
49
|
-
return response
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/__init__.py
RENAMED
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/test.csv
RENAMED
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/mapping/__init__.py
RENAMED
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/output/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/dict_custom_properties/test_pipeline.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/abox/json_multiple_iris/test_multiple_iris.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/explicit_datatypes/test_explicit_datatypes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{data2rdf-2.4.0.dev0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_title_exclusion.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|