data2rdf 2.3.0__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.
Files changed (79) hide show
  1. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/PKG-INFO +1 -1
  2. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/config.py +2 -0
  3. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/models/base.py +10 -8
  4. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/models/graph.py +53 -2
  5. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/base.py +58 -10
  6. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/pipelines/main.py +10 -1
  7. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/qudt/utils.py +42 -0
  8. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/utils.py +16 -0
  9. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/warnings.py +4 -0
  10. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/PKG-INFO +1 -1
  11. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/SOURCES.txt +1 -0
  12. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/setup.cfg +1 -1
  13. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/test_parser.py +4 -2
  14. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/test_pipeline.py +4 -2
  15. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/test_parser.py +140 -22
  16. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/test_pipeline.py +139 -22
  17. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/test_parser.py +4 -2
  18. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/test_pipeline.py +4 -3
  19. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/test_parser.py +29 -4
  20. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/test_pipeline.py +29 -4
  21. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/test_models.py +15 -0
  22. data2rdf-2.4.0.dev1/tests/abox/utils.py +101 -0
  23. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/xls_pipeline_test/test_parser.py +103 -16
  24. data2rdf-2.4.0.dev1/tests/abox/xls_pipeline_test/test_pipeline.py +430 -0
  25. data2rdf-2.3.0/tests/abox/xls_pipeline_test/test_pipeline.py +0 -206
  26. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/LICENSE +0 -0
  27. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/README.md +0 -0
  28. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/__init__.py +0 -0
  29. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/models/__init__.py +0 -0
  30. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/models/mapping.py +0 -0
  31. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/models/utils.py +0 -0
  32. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/modes/__init__.py +0 -0
  33. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/__init__.py +0 -0
  34. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/csv.py +0 -0
  35. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/excel.py +0 -0
  36. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/json.py +0 -0
  37. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/parsers/utils.py +0 -0
  38. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/pipelines/__init__.py +0 -0
  39. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf/qudt/__init__.py +0 -0
  40. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/dependency_links.txt +0 -0
  41. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/requires.txt +0 -0
  42. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/data2rdf.egg-info/top_level.txt +0 -0
  43. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/setup.py +0 -0
  44. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/__init__.py +0 -0
  45. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/__init__.py +0 -0
  46. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/__init__.py +0 -0
  47. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_empty_rows/output/__init__.py +0 -0
  48. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/__init__.py +0 -0
  49. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_pipeline_test/input/__init__.py +0 -0
  50. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/__init__.py +0 -0
  51. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/__init__.py +0 -0
  52. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/__init__.py +0 -0
  53. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/data/test.csv +0 -0
  54. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/input/mapping/__init__.py +0 -0
  55. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/csv_without_header/output/__init__.py +0 -0
  56. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/dict_custom_properties/__init__.py +0 -0
  57. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/dict_custom_properties/test_pipeline.py +0 -0
  58. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_custom_relations/__init__.py +0 -0
  59. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_custom_relations/test_json_custom_relations.py +0 -0
  60. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_multiple_iris/__init__.py +0 -0
  61. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_multiple_iris/test_multiple_iris.py +0 -0
  62. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/json_pipeline_test/__init__.py +0 -0
  63. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/xls_custom_relations/__init__.py +0 -0
  64. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/xls_custom_relations/test_xlsx_custom_relations.py +0 -0
  65. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/abox/xls_pipeline_test/__init__.py +0 -0
  66. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/__init__.py +0 -0
  67. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/__init__.py +0 -0
  68. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/test_parser.py +0 -0
  69. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/csv_pipeline_test/test_pipeline.py +0 -0
  70. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/explicit_datatypes/__init__.py +0 -0
  71. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/explicit_datatypes/test_explicit_datatypes.py +0 -0
  72. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/__init__.py +0 -0
  73. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_parser.py +0 -0
  74. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_pipeline.py +0 -0
  75. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/json_pipeline_test/test_title_exclusion.py +0 -0
  76. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/__init__.py +0 -0
  77. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/test_parser.py +0 -0
  78. {data2rdf-2.3.0 → data2rdf-2.4.0.dev1}/tests/tbox/xls_pipeline_test/test_pipeline.py +0 -0
  79. {data2rdf-2.3.0 → 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.3.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
@@ -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
  )
@@ -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,8 +1,9 @@
1
1
  """Data2RDF base model for parsers"""
2
2
 
3
3
  import json
4
+ import warnings
4
5
  from abc import abstractmethod
5
- from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
6
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
6
7
 
7
8
  from rdflib import Graph
8
9
 
@@ -189,15 +190,53 @@ 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()
199
+
200
+ def to_dict(
201
+ self, schema: Callable = None
202
+ ) -> "Union[Dict[str, Any], List[Dict[str, Any]]]":
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
+ """
224
+ metadata = []
225
+ for metadatum in self.general_metadata:
226
+ prop = {
227
+ "label": metadatum.suffix,
228
+ "value": metadatum.value,
229
+ }
230
+ if hasattr(metadatum, "measurement_unit"):
231
+ prop[
232
+ "measurement_unit"
233
+ ] = metadatum.measurement_unit.model_dump(exclude={"config"})
234
+ metadata.append(prop)
235
+ if not isinstance(schema, type(None)):
236
+ metadata = schema(metadata)
237
+ else:
238
+ metadata = {datum.get("label"): datum for datum in metadata}
239
+ return metadata
201
240
 
202
241
 
203
242
  class BaseFileParser(BaseParser):
@@ -281,6 +320,15 @@ class BaseFileParser(BaseParser):
281
320
  "`plain_metadata` is not available in `tbox`-mode."
282
321
  )
283
322
 
323
+ def to_dict(self, schema: Callable = None) -> "List[Dict[str, Any]]":
324
+ """Return list of general metadata as DSMS custom properties"""
325
+ if self.mode == PipelineMode.ABOX:
326
+ return self.abox.to_dict(schema=schema)
327
+ else:
328
+ raise NotImplementedError(
329
+ "`to_dict()` is not available in `tbox`-mode."
330
+ )
331
+
284
332
  @property
285
333
  def general_metadata(cls) -> "List[BasicConceptMapping]":
286
334
  """Return list object with general metadata"""
@@ -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,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, schema: Callable = None) -> "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(schema=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.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
@@ -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.0dev1
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
@@ -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")
@@ -27,7 +29,6 @@ columns = [
27
29
  "MassDensity",
28
30
  ]
29
31
 
30
-
31
32
  config = {"graph_identifier": "https://www.example.org"}
32
33
 
33
34
 
@@ -60,4 +61,5 @@ def test_csv_nan_vals() -> None:
60
61
  assert len(column) == 31
61
62
 
62
63
  assert parser.graph.isomorphic(expected_graph)
63
- assert parser.plain_metadata == {}
64
+ assert parser.to_dict(schema=dsms_schema) == {}
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")
@@ -10,7 +12,6 @@ mapping_folder = os.path.join(working_folder, "mapping")
10
12
  raw_data = os.path.join(working_folder, "data", "data.csv")
11
13
  expected = os.path.join(output_folder, "output_csv_pipeline.ttl")
12
14
 
13
-
14
15
  parser_args = {
15
16
  "time_series_sep": ";",
16
17
  "metadata_length": 0,
@@ -71,4 +72,5 @@ def test_csv_na_values_pipeline() -> None:
71
72
 
72
73
  assert pipeline.graph.isomorphic(expected_graph)
73
74
 
74
- assert pipeline.plain_metadata == {}
75
+ assert pipeline.to_dict(schema=dsms_schema) == {}
76
+ 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, 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(schema=dsms_schema)) == 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(schema=dsms_schema)) == sort_entries(
352
+ metadata
353
+ )
354
+
355
+ assert sort_entries(parser.to_dict()) == as_non_dsms_schema(metadata)