data2rdf 2.3.0__tar.gz → 2.4.0.dev0__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.
Files changed (79) hide show
  1. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/PKG-INFO +1 -1
  2. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/config.py +7 -0
  3. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/models/base.py +10 -8
  4. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/models/graph.py +53 -2
  5. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/base.py +51 -10
  6. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/utils.py +23 -0
  7. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/pipelines/main.py +9 -0
  8. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/qudt/utils.py +42 -0
  9. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/utils.py +16 -0
  10. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/warnings.py +4 -0
  11. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf.egg-info/PKG-INFO +1 -1
  12. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf.egg-info/SOURCES.txt +1 -0
  13. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/setup.cfg +1 -1
  14. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_empty_rows/test_parser.py +2 -2
  15. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_empty_rows/test_pipeline.py +2 -2
  16. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_pipeline_test/test_parser.py +140 -22
  17. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_pipeline_test/test_pipeline.py +139 -22
  18. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/test_parser.py +2 -2
  19. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/test_pipeline.py +2 -3
  20. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_pipeline_test/test_parser.py +29 -4
  21. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_pipeline_test/test_pipeline.py +29 -4
  22. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/test_models.py +15 -0
  23. data2rdf-2.4.0.dev0/tests/abox/utils.py +49 -0
  24. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/xls_pipeline_test/test_parser.py +103 -16
  25. data2rdf-2.4.0.dev0/tests/abox/xls_pipeline_test/test_pipeline.py +430 -0
  26. data2rdf-2.3.0/tests/abox/xls_pipeline_test/test_pipeline.py +0 -206
  27. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/LICENSE +0 -0
  28. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/README.md +0 -0
  29. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/__init__.py +0 -0
  30. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/models/__init__.py +0 -0
  31. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/models/mapping.py +0 -0
  32. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/models/utils.py +0 -0
  33. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/modes/__init__.py +0 -0
  34. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/__init__.py +0 -0
  35. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/csv.py +0 -0
  36. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/excel.py +0 -0
  37. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/parsers/json.py +0 -0
  38. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/pipelines/__init__.py +0 -0
  39. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf/qudt/__init__.py +0 -0
  40. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf.egg-info/dependency_links.txt +0 -0
  41. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf.egg-info/requires.txt +0 -0
  42. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/data2rdf.egg-info/top_level.txt +0 -0
  43. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/setup.py +0 -0
  44. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/__init__.py +0 -0
  45. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/__init__.py +0 -0
  46. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_empty_rows/__init__.py +0 -0
  47. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_empty_rows/output/__init__.py +0 -0
  48. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_pipeline_test/__init__.py +0 -0
  49. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_pipeline_test/input/__init__.py +0 -0
  50. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/__init__.py +0 -0
  51. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/input/__init__.py +0 -0
  52. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/input/data/__init__.py +0 -0
  53. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/input/data/test.csv +0 -0
  54. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/input/mapping/__init__.py +0 -0
  55. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/csv_without_header/output/__init__.py +0 -0
  56. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/dict_custom_properties/__init__.py +0 -0
  57. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/dict_custom_properties/test_pipeline.py +0 -0
  58. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_custom_relations/__init__.py +0 -0
  59. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_custom_relations/test_json_custom_relations.py +0 -0
  60. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_multiple_iris/__init__.py +0 -0
  61. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_multiple_iris/test_multiple_iris.py +0 -0
  62. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/json_pipeline_test/__init__.py +0 -0
  63. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/xls_custom_relations/__init__.py +0 -0
  64. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/xls_custom_relations/test_xlsx_custom_relations.py +0 -0
  65. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/abox/xls_pipeline_test/__init__.py +0 -0
  66. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/__init__.py +0 -0
  67. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/csv_pipeline_test/__init__.py +0 -0
  68. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/csv_pipeline_test/test_parser.py +0 -0
  69. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/csv_pipeline_test/test_pipeline.py +0 -0
  70. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/explicit_datatypes/__init__.py +0 -0
  71. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/explicit_datatypes/test_explicit_datatypes.py +0 -0
  72. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/json_pipeline_test/__init__.py +0 -0
  73. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/json_pipeline_test/test_parser.py +0 -0
  74. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/json_pipeline_test/test_pipeline.py +0 -0
  75. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/json_pipeline_test/test_title_exclusion.py +0 -0
  76. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/xls_pipeline_test/__init__.py +0 -0
  77. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/xls_pipeline_test/test_parser.py +0 -0
  78. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/tbox/xls_pipeline_test/test_pipeline.py +0 -0
  79. {data2rdf-2.3.0 → data2rdf-2.4.0.dev0}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: data2rdf
3
- Version: 2.3.0
3
+ Version: 2.4.0.dev0
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
@@ -20,6 +20,8 @@ class Config(BaseSettings):
20
20
  description="URI to QUDT quantity kind ontology for unit conversion",
21
21
  )
22
22
 
23
+ language: str = Field("en", description="Language for the unit labels")
24
+
23
25
  base_iri: Union[str, AnyUrl] = Field(
24
26
  "https://www.example.org", description="Base IRI for individuals."
25
27
  )
@@ -77,6 +79,11 @@ class Config(BaseSettings):
77
79
  description="In TBox mode, exclude the title of the ontology in the graph.",
78
80
  )
79
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
+
80
87
  model_config = ConfigDict(extra="ignore")
81
88
 
82
89
  @model_validator(mode="after")
@@ -10,8 +10,8 @@ from pydantic import (
10
10
  BaseModel,
11
11
  ConfigDict,
12
12
  Field,
13
- ValidationInfo,
14
13
  field_validator,
14
+ model_validator,
15
15
  )
16
16
  from rdflib import Graph
17
17
 
@@ -106,16 +106,18 @@ class BasicSuffixModel(BaseConfigModel):
106
106
  value = [AnyUrl(str(iterable).strip()) for iterable in value]
107
107
  return value
108
108
 
109
- @field_validator("suffix")
109
+ @model_validator(mode="after")
110
110
  @classmethod
111
111
  def validate_suffix(
112
- cls, value: Optional[str], info: ValidationInfo
113
- ) -> str:
112
+ cls,
113
+ self: "BasicSuffixModel",
114
+ ) -> "BasicSuffixModel":
114
115
  """Return suffix for individal"""
115
116
 
116
- iri = info.data["iri"]
117
- config = info.data["config"]
118
- if isinstance(iri, list) and value is None:
117
+ if isinstance(self.iri, list) and self.suffix is None:
119
118
  raise TypeError("If the iri is a list, the suffix must be set ")
120
119
 
121
- return value or str(iri).split(config.separator)[-1]
120
+ self.suffix = (
121
+ self.suffix or str(self.iri).split(self.config.separator)[-1]
122
+ )
123
+ return self
@@ -3,8 +3,8 @@
3
3
  import warnings
4
4
  from typing import Any, Dict, List, Optional, Union
5
5
 
6
- from data2rdf.qudt.utils import _get_query_match
7
- from data2rdf.utils import make_prefix
6
+ from data2rdf.qudt.utils import _get_qudt_label_and_symbol, _get_query_match
7
+ from data2rdf.utils import make_prefix, split_namespace
8
8
  from data2rdf.warnings import ParserWarning
9
9
 
10
10
  from data2rdf.models.utils import ( # isort:skip
@@ -18,6 +18,7 @@ from data2rdf.models.base import ( # isort:skip
18
18
  BasicGraphModel,
19
19
  BasicSuffixModel,
20
20
  RelationType,
21
+ BaseConfigModel,
21
22
  )
22
23
 
23
24
  from pydantic import ( # isort:skip
@@ -109,6 +110,39 @@ class ClassTypeGraph(BasicGraphModel):
109
110
  }
110
111
 
111
112
 
113
+ class MeasurementUnit(BaseConfigModel):
114
+ iri: Union[str, AnyUrl] = Field(
115
+ ...,
116
+ description="Ontological IRI related to the measurement unit",
117
+ )
118
+ label: Optional[str] = Field(
119
+ None,
120
+ description="Label of the measurement unit",
121
+ )
122
+ symbol: Optional[str] = Field(
123
+ None,
124
+ description="Symbol of the measurement unit",
125
+ )
126
+ namespace: Optional[str] = Field(
127
+ None,
128
+ description="Namespace of the measurement unit",
129
+ )
130
+
131
+ @model_validator(mode="after")
132
+ @classmethod
133
+ def validate_measurement_unit(cls, self) -> "MeasurementUnit":
134
+ unit = _get_qudt_label_and_symbol(
135
+ self.iri, self.config.qudt_units, self.config.language
136
+ )
137
+ if not self.label and "label" in unit:
138
+ self.label = unit["label"]
139
+ if not self.symbol and "symbol" in unit:
140
+ self.symbol = unit["symbol"]
141
+ if not self.namespace:
142
+ self.namespace = split_namespace(self.iri)
143
+ return self
144
+
145
+
112
146
  class QuantityGraph(BasicGraphModel, BasicSuffixModel):
113
147
  """Quantity with or without a discrete value and a unit
114
148
  E.g. a quantity with a single value and unit _or_
@@ -133,6 +167,14 @@ class QuantityGraph(BasicGraphModel, BasicSuffixModel):
133
167
  for mapping the data value to the individual.""",
134
168
  )
135
169
 
170
+ measurement_unit: Optional[MeasurementUnit] = Field(
171
+ None,
172
+ description="Detailed QUDT Measurement Unit specification",
173
+ alias=AliasChoices(
174
+ "measurement_unit", "measurementunit", "measurementUnit"
175
+ ),
176
+ )
177
+
136
178
  @field_validator("value", mode="after")
137
179
  @classmethod
138
180
  def validate_value(
@@ -174,6 +216,15 @@ class QuantityGraph(BasicGraphModel, BasicSuffixModel):
174
216
  value = str(value)
175
217
  return value
176
218
 
219
+ @model_validator(mode="after")
220
+ @classmethod
221
+ def validate_quantity_graph(cls, self) -> "QuantityGraph":
222
+ if not self.measurement_unit and self.unit:
223
+ self.measurement_unit = MeasurementUnit(iri=self.unit)
224
+ if self.measurement_unit and not self.unit:
225
+ self.unit = self.measurement_unit.iri
226
+ return self
227
+
177
228
  @property
178
229
  def json_ld(cls) -> Dict[str, Any]:
179
230
  """Return dict of json-ld for graph"""
@@ -1,6 +1,7 @@
1
1
  """Data2RDF base model for parsers"""
2
2
 
3
3
  import json
4
+ import warnings
4
5
  from abc import abstractmethod
5
6
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
6
7
 
@@ -9,7 +10,7 @@ from rdflib import Graph
9
10
  from data2rdf.config import Config
10
11
  from data2rdf.modes import PipelineMode
11
12
 
12
- from .utils import load_mapping_file
13
+ from .utils import generate_id, load_mapping_file
13
14
 
14
15
  from pydantic import ( # isort:skip
15
16
  BaseModel,
@@ -189,15 +190,46 @@ class ABoxBaseParser(AnyBoxBaseParser):
189
190
  return self._time_series
190
191
 
191
192
  @property
192
- def plain_metadata(self) -> "Dict[str, Any]":
193
- """Metadata as flat json - without units and iris.
194
- Useful e.g. for the custom properties of the DSMS."""
195
- return {
196
- str(metadatum.iri).split(self.config.separator)[
197
- -1
198
- ]: metadatum.value
199
- for metadatum in self.general_metadata
200
- }
193
+ def plain_metadata(self) -> List[Dict[str, Any]]:
194
+ message = """
195
+ `plain_metadata` is deprecated and will be removed in a future version.
196
+ Use the `to_dict()` instead."""
197
+ warnings.warn(message, DeprecationWarning)
198
+ return self.to_dict(dsms_schema=self.config.dsms_schema_default)
199
+
200
+ def to_dict(
201
+ self, dsms_schema: bool = False
202
+ ) -> "Union[Dict[str, Any], List[Dict[str, Any]]]":
203
+ """Return list of general metadata as DSMS custom properties"""
204
+ metadata = []
205
+ for metadatum in self.general_metadata:
206
+ prop = {
207
+ "label": metadatum.suffix,
208
+ "value": metadatum.value,
209
+ }
210
+ if hasattr(metadatum, "measurement_unit"):
211
+ prop[
212
+ "measurement_unit"
213
+ ] = metadatum.measurement_unit.model_dump(exclude={"config"})
214
+ metadata.append(prop)
215
+ if dsms_schema:
216
+ if metadata:
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 = {}
230
+ else:
231
+ metadata = {datum.get("label"): datum for datum in metadata}
232
+ return metadata
201
233
 
202
234
 
203
235
  class BaseFileParser(BaseParser):
@@ -281,6 +313,15 @@ class BaseFileParser(BaseParser):
281
313
  "`plain_metadata` is not available in `tbox`-mode."
282
314
  )
283
315
 
316
+ def to_dict(self, dsms_schema: bool = False) -> "List[Dict[str, Any]]":
317
+ """Return list of general metadata as DSMS custom properties"""
318
+ if self.mode == PipelineMode.ABOX:
319
+ return self.abox.to_dict(dsms_schema=dsms_schema)
320
+ else:
321
+ raise NotImplementedError(
322
+ "`to_dict()` is not available in `tbox`-mode."
323
+ )
324
+
284
325
  @property
285
326
  def general_metadata(cls) -> "List[BasicConceptMapping]":
286
327
  """Return list object with general metadata"""
@@ -1,6 +1,9 @@
1
1
  """Data2RDF parser utilities"""
2
2
 
3
3
  import json
4
+ import random
5
+ import string
6
+ import time
4
7
  import warnings
5
8
  from typing import TYPE_CHECKING
6
9
 
@@ -216,3 +219,23 @@ def _value_exists(value: "Any") -> bool:
216
219
  bool: True if the value exists and is valid, otherwise False.
217
220
  """
218
221
  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
@@ -210,6 +210,15 @@ class Data2RDF(BaseModel):
210
210
  graph += cls._validate_additional_triples(cls.additional_triples)
211
211
  return graph
212
212
 
213
+ def to_dict(self, dsms_schema: bool = False) -> "List[Dict[str, Any]]":
214
+ """Return list of general metadata as DSMS custom properties"""
215
+ if self.mode == PipelineMode.ABOX:
216
+ return self.parser.abox.to_dict(dsms_schema=dsms_schema)
217
+ else:
218
+ raise NotImplementedError(
219
+ "`to_dict()` is not available in `tbox`-mode."
220
+ )
221
+
213
222
  @property
214
223
  def plain_metadata(cls) -> Dict[str, Any]:
215
224
  """Metadata as flat json - without units and iris.
@@ -7,6 +7,8 @@ from typing import List, Optional
7
7
  import requests
8
8
  from rdflib import Graph
9
9
 
10
+ from data2rdf.warnings import QUDTMappingWarning
11
+
10
12
 
11
13
  def _qudt_sparql(symbol: str) -> str:
12
14
  return f"""PREFIX qudt: <http://qudt.org/schema/qudt/>
@@ -82,3 +84,43 @@ def _check_qudt_mapping(symbol: Optional[str]) -> Optional[str]:
82
84
  else:
83
85
  unit = {}
84
86
  return unit
87
+
88
+
89
+ def _get_qudt_label_and_symbol(
90
+ iri: str, qudt_iri: str, language: str
91
+ ) -> Optional[str]:
92
+ graph = _get_qudt_graph(qudt_iri)
93
+ gen_query = f"""PREFIX qudt: <http://qudt.org/schema/qudt/>
94
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
95
+ SELECT DISTINCT ?label ?symbol
96
+ WHERE {{
97
+ <{iri}> qudt:symbol ?symbol .
98
+ OPTIONAL {{
99
+ <{iri}> rdfs:label ?label .
100
+ FILTER (LANG(?label) = "{language}")
101
+ }}
102
+ OPTIONAL {{
103
+ <{iri}> rdfs:label ?label_no_lang .
104
+ FILTER (LANG(?label_no_lang) = "")
105
+ }}
106
+ BIND(COALESCE(?label, ?label_no_lang) AS ?label)
107
+ }}"""
108
+ match = [
109
+ {"label": str(row["label"]), "symbol": str(row["symbol"])}
110
+ for row in graph.query(gen_query)
111
+ ]
112
+ if len(match) == 0:
113
+ warnings.warn(
114
+ f"No QUDT label and symbol found for unit with iri `{iri}`.",
115
+ QUDTMappingWarning,
116
+ )
117
+ unit = {}
118
+ elif len(match) > 1:
119
+ warnings.warn(
120
+ f"Multiple QUDT symbols and labels found for unit with iri `{iri}`.",
121
+ QUDTMappingWarning,
122
+ )
123
+ unit = match[0]
124
+ else:
125
+ unit = match.pop()
126
+ return unit
@@ -12,3 +12,19 @@ def make_prefix(config: "Config") -> str:
12
12
  else:
13
13
  prefix = str(config.base_iri)
14
14
  return prefix
15
+
16
+
17
+ def split_namespace(iri: str) -> tuple[str, str]:
18
+ """
19
+ Split the given iri into a namespace and a localname.
20
+
21
+ Args:
22
+ iri: The iri to split.
23
+
24
+ Returns:
25
+ A tuple of the namespace and the localname.
26
+ """
27
+ if "#" in iri:
28
+ return iri.split("#")[0]
29
+ else:
30
+ return "/".join(iri.split("/")[:-1])
@@ -7,3 +7,7 @@ class MappingMissmatchWarning(UserWarning):
7
7
 
8
8
  class ParserWarning(UserWarning):
9
9
  """A warning raised for a specific context set for a parser"""
10
+
11
+
12
+ class QUDTMappingWarning(UserWarning):
13
+ """A warning raised for a specific context set for a QUDT mapping"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: data2rdf
3
- Version: 2.3.0
3
+ Version: 2.4.0.dev0
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
@@ -31,6 +31,7 @@ tests/__init__.py
31
31
  tests/test_utils.py
32
32
  tests/abox/__init__.py
33
33
  tests/abox/test_models.py
34
+ tests/abox/utils.py
34
35
  tests/abox/csv_empty_rows/__init__.py
35
36
  tests/abox/csv_empty_rows/test_parser.py
36
37
  tests/abox/csv_empty_rows/test_pipeline.py
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = data2rdf
3
- version = v2.3.0
3
+ version = v2.4.0dev0
4
4
  description = A generic pipeline that can be used to map raw data to RDF.
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -27,7 +27,6 @@ columns = [
27
27
  "MassDensity",
28
28
  ]
29
29
 
30
-
31
30
  config = {"graph_identifier": "https://www.example.org"}
32
31
 
33
32
 
@@ -60,4 +59,5 @@ def test_csv_nan_vals() -> None:
60
59
  assert len(column) == 31
61
60
 
62
61
  assert parser.graph.isomorphic(expected_graph)
63
- assert parser.plain_metadata == {}
62
+ assert parser.to_dict(dsms_schema=True) == {}
63
+ assert parser.to_dict() == {}
@@ -10,7 +10,6 @@ mapping_folder = os.path.join(working_folder, "mapping")
10
10
  raw_data = os.path.join(working_folder, "data", "data.csv")
11
11
  expected = os.path.join(output_folder, "output_csv_pipeline.ttl")
12
12
 
13
-
14
13
  parser_args = {
15
14
  "time_series_sep": ";",
16
15
  "metadata_length": 0,
@@ -71,4 +70,5 @@ def test_csv_na_values_pipeline() -> None:
71
70
 
72
71
  assert pipeline.graph.isomorphic(expected_graph)
73
72
 
74
- assert pipeline.plain_metadata == {}
73
+ assert pipeline.to_dict(dsms_schema=True) == {}
74
+ assert pipeline.to_dict() == {}
@@ -5,6 +5,8 @@ import os
5
5
 
6
6
  import pytest
7
7
 
8
+ from ..utils import as_non_dsms_schema, remove_ids, sort_entries
9
+
8
10
  test_folder = os.path.dirname(os.path.abspath(__file__))
9
11
  working_folder = os.path.join(test_folder, "input")
10
12
  output_folder = os.path.join(test_folder, "output")
@@ -20,26 +22,135 @@ parser_args = {
20
22
  }
21
23
 
22
24
  metadata = {
23
- "TestingFacility": "institute_1",
24
- "ProjectNumber": "123456",
25
- "ProjectName": "proj_name_1",
26
- "TimeStamp": "44335.4",
27
- "MachineData": "maschine_1",
28
- "ForceMeasuringDevice": "Kraftaufnehmer_1",
29
- "DisplacementTransducer": "Wegaufnehmer_1",
30
- "TestStandard": "ISO-XX",
31
- "Material": "Werkstoff_1",
32
- "SpecimenType": "Probentyp_1",
33
- "Tester": "abc",
34
- "SampleIdentifier-2": "Probentyp_2",
35
- "OriginalGaugeLength": 80,
36
- "ParallelLength": 120,
37
- "SpecimenThickness": 1.55,
38
- "SpecimenWidth": 20.04,
39
- "TestingRate": 0.1,
40
- "Preload": 2,
41
- "Temperature": 22,
42
- "Remark": "",
25
+ "sections": [
26
+ {
27
+ "entries": [
28
+ {
29
+ "label": "TestingFacility",
30
+ "value": "institute_1",
31
+ },
32
+ {
33
+ "label": "ProjectNumber",
34
+ "value": "123456",
35
+ },
36
+ {
37
+ "label": "ProjectName",
38
+ "value": "proj_name_1",
39
+ },
40
+ {
41
+ "label": "TimeStamp",
42
+ "value": "44335.4",
43
+ },
44
+ {
45
+ "label": "MachineData",
46
+ "value": "maschine_1",
47
+ },
48
+ {
49
+ "label": "ForceMeasuringDevice",
50
+ "value": "Kraftaufnehmer_1",
51
+ },
52
+ {
53
+ "label": "DisplacementTransducer",
54
+ "value": "Wegaufnehmer_1",
55
+ },
56
+ {
57
+ "label": "TestStandard",
58
+ "value": "ISO-XX",
59
+ },
60
+ {
61
+ "label": "Material",
62
+ "value": "Werkstoff_1",
63
+ },
64
+ {
65
+ "label": "SpecimenType",
66
+ "value": "Probentyp_1",
67
+ },
68
+ {
69
+ "label": "Tester",
70
+ "value": "abc",
71
+ },
72
+ {
73
+ "label": "SampleIdentifier-2",
74
+ "value": "Probentyp_2",
75
+ },
76
+ {
77
+ "label": "OriginalGaugeLength",
78
+ "measurement_unit": {
79
+ "iri": "http://qudt.org/vocab/unit/MilliM",
80
+ "label": "Millimetre",
81
+ "namespace": "http://qudt.org/vocab/unit",
82
+ "symbol": "mm",
83
+ },
84
+ "value": 80,
85
+ },
86
+ {
87
+ "label": "ParallelLength",
88
+ "measurement_unit": {
89
+ "iri": "http://qudt.org/vocab/unit/MilliM",
90
+ "label": "Millimetre",
91
+ "namespace": "http://qudt.org/vocab/unit",
92
+ "symbol": "mm",
93
+ },
94
+ "value": 120,
95
+ },
96
+ {
97
+ "label": "SpecimenThickness",
98
+ "measurement_unit": {
99
+ "iri": "http://qudt.org/vocab/unit/MilliM",
100
+ "label": "Millimetre",
101
+ "namespace": "http://qudt.org/vocab/unit",
102
+ "symbol": "mm",
103
+ },
104
+ "value": 1.55,
105
+ },
106
+ {
107
+ "label": "SpecimenWidth",
108
+ "measurement_unit": {
109
+ "iri": "http://qudt.org/vocab/unit/MilliM",
110
+ "label": "Millimetre",
111
+ "namespace": "http://qudt.org/vocab/unit",
112
+ "symbol": "mm",
113
+ },
114
+ "value": 20.04,
115
+ },
116
+ {
117
+ "label": "TestingRate",
118
+ "measurement_unit": {
119
+ "iri": "http://qudt.org/vocab/unit/MilliM-PER-SEC",
120
+ "label": "Millimetre per Second",
121
+ "namespace": "http://qudt.org/vocab/unit",
122
+ "symbol": "mm/s",
123
+ },
124
+ "value": 0.1,
125
+ },
126
+ {
127
+ "label": "Preload",
128
+ "measurement_unit": {
129
+ "iri": "http://qudt.org/vocab/unit/MegaPA",
130
+ "label": "Megapascal",
131
+ "namespace": "http://qudt.org/vocab/unit",
132
+ "symbol": "MPa",
133
+ },
134
+ "value": 2,
135
+ },
136
+ {
137
+ "label": "Temperature",
138
+ "measurement_unit": {
139
+ "iri": "http://qudt.org/vocab/unit/DEG_C",
140
+ "label": "degree Celsius",
141
+ "namespace": "http://qudt.org/vocab/unit",
142
+ "symbol": "°C",
143
+ },
144
+ "value": 22,
145
+ },
146
+ {
147
+ "label": "Remark",
148
+ "value": "",
149
+ },
150
+ ],
151
+ "name": "General",
152
+ },
153
+ ],
43
154
  }
44
155
 
45
156
  columns = [
@@ -194,7 +305,10 @@ def test_parser_csv(extension) -> None:
194
305
 
195
306
  assert parser.graph.isomorphic(expected_graph)
196
307
 
197
- assert parser.plain_metadata == metadata
308
+ assert remove_ids(parser.to_dict(dsms_schema=True)) == sort_entries(
309
+ metadata
310
+ )
311
+ assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)
198
312
 
199
313
 
200
314
  @pytest.mark.parametrize("input_kind", ["path", "content"])
@@ -234,4 +348,8 @@ def test_parser_csv_input(input_kind) -> None:
234
348
 
235
349
  assert parser.graph.isomorphic(expected_graph)
236
350
 
237
- assert parser.plain_metadata == metadata
351
+ assert remove_ids(parser.to_dict(dsms_schema=True)) == sort_entries(
352
+ metadata
353
+ )
354
+
355
+ assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)