Skip to content

Commit

Permalink
add suffix unit test for xlsx parser
Browse files Browse the repository at this point in the history
  • Loading branch information
MBueschelberger committed Dec 18, 2024
1 parent bcaf83c commit 6d2b2ab
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 8 deletions.
18 changes: 10 additions & 8 deletions data2rdf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
BaseModel,
ConfigDict,
Field,
ValidationInfo,
field_validator,
model_validator,
)
from rdflib import Graph

Expand Down Expand Up @@ -106,16 +106,18 @@ def validate_iri(cls, value: Union[AnyUrl, List[AnyUrl]]) -> AnyUrl:
value = [AnyUrl(str(iterable).strip()) for iterable in value]
return value

@field_validator("suffix")
@model_validator(mode="after")
@classmethod
def validate_suffix(
cls, value: Optional[str], info: ValidationInfo
) -> str:
cls,
self: "BasicSuffixModel",
) -> "BasicSuffixModel":
"""Return suffix for individal"""

iri = info.data["iri"]
config = info.data["config"]
if isinstance(iri, list) and value is None:
if isinstance(self.iri, list) and self.suffix is None:
raise TypeError("If the iri is a list, the suffix must be set ")

return value or str(iri).split(config.separator)[-1]
self.suffix = (
self.suffix or str(self.iri).split(self.config.separator)[-1]
)
return self
127 changes: 127 additions & 0 deletions tests/abox/xls_pipeline_test/input/mapping/mapping_suffix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
[
{
"iri": "https://w3id.org/steel/ProcessOntology/Remark",
"key": "Bemerkungen",
"value_location": "UU31",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/WidthChange",
"key": "Breiten\u00e4nderung",
"time_series_start": "E15",
"unit_location": "E14",
"worksheet": "Messdaten"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/TimeStamp",
"key": "Datum",
"value_location": "AD6",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/PercentageElongation",
"key": "Dehnung",
"time_series_start": "Q15",
"unit": "\u00f7",
"worksheet": "Messdaten"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/OriginalGaugeLength",
"key": "Messl\u00e4nge Standardweg",
"unit_location": "P16",
"value_location": "M16",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/SpecimenWidth",
"key": "Probenbreite b",
"unit_location": "P15",
"value_location": "M15",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/SpecimenThickness",
"key": "Probendicke a",
"unit_location": "P14",
"value_location": "M14",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/SpecimenType",
"key": "Probenform",
"value_location": "AE7",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/SampleIdentifier-2",
"key": "Probenkennung 2",
"value_location": "U7",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/ProjectNumber",
"key": "Projekt",
"value_location": "F6",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/Tester",
"key": "Pr\u00fcfer",
"value_location": "U6",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/TestingRate",
"key": "Pr\u00fcfgeschwindigkeit",
"value_location": "J9",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/MachineData",
"key": "Pr\u00fcfmaschine",
"value_location": "I8",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/Temperature",
"key": "Pr\u00fcftemperatur",
"value_location": "U8",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/StandardForce",
"key": "Standardkraft",
"time_series_start": "C15",
"unit_location": "C14",
"worksheet": "Messdaten"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/Extension",
"key": "Standardweg",
"time_series_start": "D15",
"unit_location": "D14",
"worksheet": "Messdaten"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/AbsoluteCrossheadTravel",
"key": "Traversenweg absolut",
"time_series_start": "B15",
"unit_location": "B14",
"worksheet": "Messdaten"
},
{
"annotation": "https://w3id.org/steel/ProcessOntology",
"iri": "https://w3id.org/steel/ProcessOntology/Material",
"key": "Werkstoff",
"value_location": "H7",
"worksheet": "Protokoll"
},
{
"iri": "https://w3id.org/steel/ProcessOntology/TestTime",
"key": "Zeit",
"suffix": "Time",
"time_series_start": "A15",
"unit_location": "A14",
"worksheet": "Messdaten"
}
]
Loading

0 comments on commit 6d2b2ab

Please sign in to comment.