Skip to content

Commit 6cc8652

Browse files
committed
Merge branch 'main' into feature/TED-405
2 parents 086d67f + e62644a commit 6cc8652

24 files changed

Lines changed: 266 additions & 230 deletions

ted_sws/core/model/manifestation.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# Email: costezki.eugen@gmail.com
77

88
""" """
9+
from datetime import datetime
910
from enum import Enum
10-
from typing import List
11+
from typing import List, Union, Optional
1112

12-
from pydantic import BaseModel, Field
13+
from pydantic import Field
1314

1415
from ted_sws.core.model import PropertyBaseModel
1516

@@ -57,10 +58,73 @@ class RDFValidationManifestation(Manifestation):
5758
"""
5859
The validation report
5960
"""
61+
created: str = datetime.now().isoformat()
62+
test_suite_identifier: str
63+
mapping_suite_identifier: str
64+
65+
66+
class SPARQLQuery(PropertyBaseModel):
67+
"""
68+
Stores SPARQL query details
69+
"""
70+
title: Optional[str]
71+
description: Optional[str]
72+
query: str
73+
74+
75+
class SPARQLQueryResult(PropertyBaseModel):
76+
"""
77+
Stores SPARQL query execution result
78+
"""
79+
query: SPARQLQuery
80+
result: Optional[str]
81+
error: Optional[str]
82+
identifier: Optional[str]
83+
84+
85+
class SPARQLTestSuiteValidationReport(RDFValidationManifestation):
86+
"""
87+
Stores execution results for a SPARQL test suite
88+
"""
89+
validation_results: Union[List[SPARQLQueryResult], str]
90+
91+
92+
class QueriedSHACLShapeValidationResult(PropertyBaseModel):
93+
"""
94+
Queried SHACL Validation Report which contains the following variables
95+
?focusNode ?message ?resultPath ?resultSeverity ?sourceConstraintComponent ?sourceShape ?value
96+
"""
97+
conforms: Optional[str]
98+
results_dict: Optional[dict]
99+
error: Optional[str]
100+
identifier: Optional[str]
101+
102+
103+
class SHACLTestSuiteValidationReport(RDFValidationManifestation):
104+
"""
105+
This is validation report for a SHACL test suite that contains json and html representation
106+
"""
107+
validation_results: Union[QueriedSHACLShapeValidationResult, str]
60108

61109

62110
class RDFManifestation(Manifestation):
63111
"""
64112
Transformed manifestation in RDF format
65113
"""
66-
validation: List[RDFValidationManifestation] = []
114+
shacl_validations: List[SHACLTestSuiteValidationReport] = []
115+
sparql_validations: List[SPARQLTestSuiteValidationReport] = []
116+
117+
def add_validation(self, validation: Union[SPARQLTestSuiteValidationReport, SHACLTestSuiteValidationReport]):
118+
if type(validation) == SHACLTestSuiteValidationReport:
119+
shacl_validation: SHACLTestSuiteValidationReport = validation
120+
if shacl_validation not in self.shacl_validations:
121+
self.shacl_validations.append(shacl_validation)
122+
elif type(validation) == SPARQLTestSuiteValidationReport:
123+
sparql_validation: SPARQLTestSuiteValidationReport = validation
124+
if sparql_validation not in self.sparql_validations:
125+
self.sparql_validations.append(sparql_validation)
126+
127+
def is_validated(self) -> bool:
128+
if len(self.shacl_validations) and len(self.sparql_validations):
129+
return True
130+
return False

ted_sws/core/model/notice.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
from datetime import datetime
1717
from enum import IntEnum
1818
from functools import total_ordering
19-
from typing import Optional, List
19+
from typing import Optional, List, Union
2020

2121
from pydantic import Field
2222

2323
from ted_sws.core.model import PropertyBaseModel
2424
from ted_sws.core.model.manifestation import METSManifestation, RDFManifestation, XMLManifestation, \
25-
RDFValidationManifestation
25+
RDFValidationManifestation, SPARQLTestSuiteValidationReport, SHACLTestSuiteValidationReport
2626
from ted_sws.core.model.metadata import TEDMetadata, NormalisedMetadata, XMLMetadata
2727

2828

@@ -184,13 +184,23 @@ def mets_manifestation(self) -> METSManifestation:
184184
def get_rdf_validation(self) -> Optional[List[RDFValidationManifestation]]:
185185
if not self.rdf_manifestation:
186186
return None
187-
188-
return self.rdf_manifestation.validation
187+
result = []
188+
for shacl_validation in self.rdf_manifestation.shacl_validations:
189+
result.append(shacl_validation)
190+
for sparql_validation in self.rdf_manifestation.sparql_validations:
191+
result.append(sparql_validation)
192+
return result
189193

190194
def get_distilled_rdf_validation(self) -> Optional[List[RDFValidationManifestation]]:
191195
if not self.distilled_rdf_manifestation:
192196
return None
193-
return self.distilled_rdf_manifestation.validation
197+
result = []
198+
for shacl_validation in self.distilled_rdf_manifestation.shacl_validations:
199+
result.append(shacl_validation)
200+
for sparql_validation in self.distilled_rdf_manifestation.sparql_validations:
201+
result.append(sparql_validation)
202+
203+
return result
194204

195205
def set_preprocessed_xml_manifestation(self, preprocessed_xml_manifestation: XMLManifestation):
196206
"""
@@ -237,25 +247,23 @@ def set_rdf_manifestation(self, rdf_manifestation: RDFManifestation):
237247
if self.rdf_manifestation == rdf_manifestation:
238248
return
239249
self._rdf_manifestation = rdf_manifestation
240-
if not rdf_manifestation.validation:
250+
if (not rdf_manifestation.sparql_validations) and (not rdf_manifestation.shacl_validations):
241251
self.update_status_to(NoticeStatus.TRANSFORMED)
242252
else:
243253
self.update_status_to(NoticeStatus.VALIDATED)
244254

245255
def _check_status_is_validated(self) -> bool:
256+
"""
246257
247-
def _get_number_of_validation_types(validations: List[RDFValidationManifestation]):
248-
unique_validation_types = set([type(validation).__name__ for validation in validations])
249-
return len(unique_validation_types)
250-
258+
:return:
259+
"""
251260
if self._rdf_manifestation and self._distilled_rdf_manifestation:
252-
if self._rdf_manifestation.validation and self._distilled_rdf_manifestation.validation:
253-
if (_get_number_of_validation_types(self._rdf_manifestation.validation) > 1) and (
254-
_get_number_of_validation_types(self._distilled_rdf_manifestation.validation) > 1):
255-
return True
261+
if self._rdf_manifestation.is_validated() and self._distilled_rdf_manifestation.is_validated():
262+
return True
256263
return False
257264

258-
def set_rdf_validation(self, rdf_validation: RDFValidationManifestation):
265+
def set_rdf_validation(self,
266+
rdf_validation: Union[SPARQLTestSuiteValidationReport, SHACLTestSuiteValidationReport]):
259267
"""
260268
Add an RDF validation result to the notice.
261269
If METS package data are available, erase them and reset the state.
@@ -265,23 +273,23 @@ def set_rdf_validation(self, rdf_validation: RDFValidationManifestation):
265273
if not self.rdf_manifestation:
266274
raise ValueError("Cannot set the RDF validation of a non-existent RDF manifestation")
267275

268-
for validation in self._rdf_manifestation.validation:
269-
if validation == rdf_validation:
270-
return
276+
self._rdf_manifestation.add_validation(validation=rdf_validation)
271277

272-
self._rdf_manifestation.validation.append(rdf_validation)
273278
if self._check_status_is_validated():
274279
self.update_status_to(NoticeStatus.VALIDATED)
275280

276-
def set_distilled_rdf_validation(self, rdf_validation: RDFValidationManifestation):
277-
if not self.distilled_rdf_manifestation:
281+
def set_distilled_rdf_validation(self, rdf_validation: Union[
282+
SPARQLTestSuiteValidationReport, SHACLTestSuiteValidationReport]):
283+
"""
284+
285+
:param rdf_validation:
286+
:return:
287+
"""
288+
if not self._distilled_rdf_manifestation:
278289
raise ValueError("Cannot set the RDF validation of a non-existent RDF manifestation")
279290

280-
for validation in self._distilled_rdf_manifestation.validation:
281-
if validation == rdf_validation:
282-
return
291+
self._distilled_rdf_manifestation.add_validation(validation=rdf_validation)
283292

284-
self._distilled_rdf_manifestation.validation.append(rdf_validation)
285293
if self._check_status_is_validated():
286294
self.update_status_to(NoticeStatus.VALIDATED)
287295

ted_sws/core/model/validate.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
#!/usr/bin/python3
2-
3-
# validation.py
4-
# Date: 29/01/2022
5-
# Author: Eugeniu Costetchi
6-
# Email: costezki.eugen@gmail.com
7-
8-
""" """

ted_sws/data_manager/adapters/notice_repository.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ def write_large_field(large_field: Manifestation):
7878
write_large_field(notice.distilled_rdf_manifestation)
7979
write_large_field(notice.preprocessed_xml_manifestation)
8080
if notice.rdf_manifestation:
81-
for validation_report in notice.rdf_manifestation.validation:
81+
for validation_report in notice.rdf_manifestation.shacl_validations:
82+
write_large_field(validation_report)
83+
84+
for validation_report in notice.rdf_manifestation.sparql_validations:
8285
write_large_field(validation_report)
8386

8487
if notice.distilled_rdf_manifestation:
85-
for validation_report in notice.distilled_rdf_manifestation.validation:
88+
for validation_report in notice.distilled_rdf_manifestation.shacl_validations:
89+
write_large_field(validation_report)
90+
91+
for validation_report in notice.distilled_rdf_manifestation.sparql_validations:
8692
write_large_field(validation_report)
8793

8894
return notice
@@ -104,10 +110,16 @@ def load_large_field(large_field: Manifestation):
104110
load_large_field(large_field=notice.distilled_rdf_manifestation)
105111
load_large_field(large_field=notice.preprocessed_xml_manifestation)
106112
if notice.rdf_manifestation:
107-
for validation_report in notice.rdf_manifestation.validation:
113+
for validation_report in notice.rdf_manifestation.shacl_validations:
108114
load_large_field(validation_report)
115+
for validation_report in notice.rdf_manifestation.sparql_validations:
116+
load_large_field(validation_report)
117+
109118
if notice.distilled_rdf_manifestation:
110-
for validation_report in notice.distilled_rdf_manifestation.validation:
119+
for validation_report in notice.distilled_rdf_manifestation.shacl_validations:
120+
load_large_field(validation_report)
121+
122+
for validation_report in notice.distilled_rdf_manifestation.sparql_validations:
111123
load_large_field(validation_report)
112124

113125
return notice

ted_sws/mapping_suite_processor/services/conceptual_mapping_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def mapping_suite_processor_zip_package(mapping_suite_package_path: pathlib.Path
5656
def mapping_suite_processor_expand_package(mapping_suite_package_path: pathlib.Path):
5757
"""
5858
This function reads data from conceptual_mappings.xlsx and expand provided package.
59+
Note: we don't use this at the moment
5960
:param mapping_suite_package_path:
6061
:return:
6162
"""
@@ -149,7 +150,6 @@ def mapping_suite_processor_from_github_expand_and_load_package_in_mongo_db(mapp
149150
mapping_suite_package_downloader.download(mapping_suite_package_name=mapping_suite_package_name,
150151
output_mapping_suite_package_path=tmp_dir_path)
151152
mapping_suite_package_path = tmp_dir_path / mapping_suite_package_name
152-
mapping_suite_processor_expand_package(mapping_suite_package_path=mapping_suite_package_path)
153153
mapping_suite_processor_load_package_in_mongo_db(mapping_suite_package_path=mapping_suite_package_path,
154154
mongodb_client=mongodb_client,
155155
load_test_data=load_test_data

ted_sws/notice_validator/entrypoints/cli/cmd_shacl_runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
import click
66

77
from ted_sws.core.adapters.cmd_runner import CmdRunner as BaseCmdRunner, DEFAULT_MAPPINGS_PATH, DEFAULT_OUTPUT_PATH
8-
from ted_sws.core.model.manifestation import RDFManifestation
8+
from ted_sws.core.model.manifestation import RDFManifestation, SHACLTestSuiteValidationReport
99
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryInFileSystem
1010
from ted_sws.event_manager.adapters.logger import LOG_INFO_TEXT
11-
from ted_sws.notice_validator.model.shacl_test_suite import SHACLSuiteValidationReport
12-
from ted_sws.notice_validator.services.shacl_test_suite_runner import SHACLTestSuiteRunner, SHACLReportBuilder
11+
from ted_sws.notice_validator.services.shacl_test_suite_runner import SHACLTestSuiteRunner, generate_shacl_report
1312

1413
DEFAULT_RDF_FOLDER = '{mappings_path}/{mapping_suite_id}/' + DEFAULT_OUTPUT_PATH
1514
DEFAULT_TEST_SUITE_REPORT_FOLDER = "test_suite_report"
@@ -57,8 +56,7 @@ def validate(self, rdf_file, base_report_path):
5756
shacl_test_suite=shacl_test_suite,
5857
mapping_suite=self.mapping_suite).execute_test_suite()
5958

60-
report_builder = SHACLReportBuilder(shacl_test_suite_execution=test_suite_execution)
61-
report: SHACLSuiteValidationReport = report_builder.generate_report()
59+
report: SHACLTestSuiteValidationReport = generate_shacl_report(shacl_test_suite_execution=test_suite_execution)
6260

6361
suite_id = shacl_test_suite.identifier
6462
data = report.object_data

ted_sws/notice_validator/entrypoints/cli/cmd_sparql_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import click
77

88
from ted_sws.core.adapters.cmd_runner import CmdRunner as BaseCmdRunner, DEFAULT_MAPPINGS_PATH, DEFAULT_OUTPUT_PATH
9-
from ted_sws.core.model.manifestation import RDFManifestation, RDFValidationManifestation
9+
from ted_sws.core.model.manifestation import RDFManifestation
1010
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryInFileSystem
1111
from ted_sws.event_manager.adapters.logger import LOG_INFO_TEXT
1212
from ted_sws.notice_validator.services.sparql_test_suite_runner import SPARQLTestSuiteRunner, SPARQLReportBuilder

ted_sws/notice_validator/model/__init__.py

Whitespace-only changes.

ted_sws/notice_validator/model/shacl_test_suite.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

ted_sws/notice_validator/model/sparql_test_suite.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)