From d003ab8b411473cef0131b4dc3d649ecd18c2818 Mon Sep 17 00:00:00 2001 From: Kolea Plesco Date: Tue, 11 Oct 2022 08:53:43 +0300 Subject: [PATCH 1/2] WIP --- .../services/conceptual_mapping_reader.py | 2 +- .../notice_validator/adapters/xpath_coverage_runner.py | 8 ++++---- .../resources/templates/xpath_coverage_report.jinja2 | 2 +- .../resources/shacl_shapes/{ => epo}/ePO_shacl_shapes.rdf | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename ted_sws/resources/shacl_shapes/{ => epo}/ePO_shacl_shapes.rdf (100%) diff --git a/ted_sws/mapping_suite_processor/services/conceptual_mapping_reader.py b/ted_sws/mapping_suite_processor/services/conceptual_mapping_reader.py index 9a16dc7c1..1ec9d0034 100644 --- a/ted_sws/mapping_suite_processor/services/conceptual_mapping_reader.py +++ b/ted_sws/mapping_suite_processor/services/conceptual_mapping_reader.py @@ -213,7 +213,7 @@ def mapping_suite_read_conceptual_mapping(conceptual_mappings_file_path: Path) - conceptual_mapping.rml_modules = _read_conceptual_mapping_rml_modules( dfs[CONCEPTUAL_MAPPINGS_RML_MODULES_SHEET_NAME]) conceptual_mapping.xpaths = _read_conceptual_mapping_xpaths( - rules_df=dfs[CONCEPTUAL_MAPPINGS_RULES_SHEET_NAME], + rules_df=dfs[CONCEPTUAL_MAPPINGS_RULES_SHEET_NAME][1:].copy(), base_xpath=metadata.base_xpath ) diff --git a/ted_sws/notice_validator/adapters/xpath_coverage_runner.py b/ted_sws/notice_validator/adapters/xpath_coverage_runner.py index 545363038..76f3644b5 100644 --- a/ted_sws/notice_validator/adapters/xpath_coverage_runner.py +++ b/ted_sws/notice_validator/adapters/xpath_coverage_runner.py @@ -73,7 +73,7 @@ def xpath_assertions(self, notice_xpaths: XPATH_TYPE, xpath_assertion.notice_hit = self.find_notice_by_xpath(notice_xpaths, xpath) xpath_assertion.query_result = xpath_assertion.count > 0 xpath_assertions.append(xpath_assertion) - return xpath_assertions + return sorted(xpath_assertions, key=lambda x: x.form_field) def validate_xpath_coverage_report(self, report: XPATHCoverageValidationReport, notice_xpaths: XPATH_TYPE, xpaths_list: List[str], notice_id: List[str]): @@ -82,9 +82,9 @@ def validate_xpath_coverage_report(self, report: XPATHCoverageValidationReport, validation_result: XPATHCoverageValidationResult = XPATHCoverageValidationResult() validation_result.notice_id = notice_id validation_result.xpath_assertions = self.xpath_assertions(notice_xpaths, xpaths_list) - validation_result.xpath_covered = list(self.conceptual_xpaths & unique_notice_xpaths) - validation_result.xpath_not_covered = list(unique_notice_xpaths - self.conceptual_xpaths) - validation_result.xpath_extra = list(self.conceptual_xpaths - unique_notice_xpaths) + validation_result.xpath_covered = sorted(list(self.conceptual_xpaths & unique_notice_xpaths)) + validation_result.xpath_not_covered = sorted(list(unique_notice_xpaths - self.conceptual_xpaths)) + validation_result.xpath_extra = sorted(list(self.conceptual_xpaths - unique_notice_xpaths)) unique_notice_xpaths_len = len(unique_notice_xpaths) xpath_covered_len = len(validation_result.xpath_covered) conceptual_xpaths_len = len(self.conceptual_xpaths) diff --git a/ted_sws/notice_validator/resources/templates/xpath_coverage_report.jinja2 b/ted_sws/notice_validator/resources/templates/xpath_coverage_report.jinja2 index ec0066f90..9d815770b 100644 --- a/ted_sws/notice_validator/resources/templates/xpath_coverage_report.jinja2 +++ b/ted_sws/notice_validator/resources/templates/xpath_coverage_report.jinja2 @@ -100,7 +100,7 @@ {% if validation_result.xpath_assertions|length > 0 %}

XPATH Assertions

- +
diff --git a/ted_sws/resources/shacl_shapes/ePO_shacl_shapes.rdf b/ted_sws/resources/shacl_shapes/epo/ePO_shacl_shapes.rdf similarity index 100% rename from ted_sws/resources/shacl_shapes/ePO_shacl_shapes.rdf rename to ted_sws/resources/shacl_shapes/epo/ePO_shacl_shapes.rdf From 301d3960a9565aeb855535e4ef3b2efaf0c2f312 Mon Sep 17 00:00:00 2001 From: Kolea Plesco Date: Tue, 11 Oct 2022 09:40:23 +0300 Subject: [PATCH 2/2] Validation reports improvements --- .../shacl_shape_validation_results_report.jinja2 | 2 +- .../templates/sparql_query_results_report.jinja2 | 2 +- .../notice_validator/services/shacl_test_suite_runner.py | 9 ++++++++- .../services/sparql_test_suite_runner.py | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ted_sws/notice_validator/resources/templates/shacl_shape_validation_results_report.jinja2 b/ted_sws/notice_validator/resources/templates/shacl_shape_validation_results_report.jinja2 index 8e7068cde..94bbac819 100644 --- a/ted_sws/notice_validator/resources/templates/shacl_shape_validation_results_report.jinja2 +++ b/ted_sws/notice_validator/resources/templates/shacl_shape_validation_results_report.jinja2 @@ -56,7 +56,7 @@

Extended results

{{ validation_results.identifier }}

-
Form Field
+
diff --git a/ted_sws/notice_validator/resources/templates/sparql_query_results_report.jinja2 b/ted_sws/notice_validator/resources/templates/sparql_query_results_report.jinja2 index b9e0d3b5f..db60199df 100644 --- a/ted_sws/notice_validator/resources/templates/sparql_query_results_report.jinja2 +++ b/ted_sws/notice_validator/resources/templates/sparql_query_results_report.jinja2 @@ -112,7 +112,7 @@
focusNode

Results

- +
diff --git a/ted_sws/notice_validator/services/shacl_test_suite_runner.py b/ted_sws/notice_validator/services/shacl_test_suite_runner.py index 56c94f75a..803836e29 100644 --- a/ted_sws/notice_validator/services/shacl_test_suite_runner.py +++ b/ted_sws/notice_validator/services/shacl_test_suite_runner.py @@ -42,6 +42,13 @@ def execute_test_suite(self) -> SHACLTestSuiteValidationReport: shacl_shape_validation_result.results_dict = json.loads( result_graph.query(shacl_shape_result_query).serialize( format='json').decode("UTF-8")) + + if (shacl_shape_validation_result.results_dict + and shacl_shape_validation_result.results_dict["results"] + and shacl_shape_validation_result.results_dict["results"]["bindings"]): + shacl_shape_validation_result.results_dict["results"]["bindings"].sort( + key=lambda x: x["focusNode"]["value"]) + except Exception as e: shacl_shape_validation_result.error = str(e)[:100] @@ -80,7 +87,7 @@ def shacl_validation(rdf_manifestation: RDFManifestation) -> List[SHACLTestSuite mapping_suite=mapping_suite_package).execute_test_suite() reports.append(generate_shacl_report(shacl_test_suite_execution=test_suite_execution)) - return reports + return sorted(reports, key=lambda x: x.test_suite_identifier) for report in shacl_validation(rdf_manifestation=notice.rdf_manifestation): notice.set_rdf_validation(rdf_validation=report) diff --git a/ted_sws/notice_validator/services/sparql_test_suite_runner.py b/ted_sws/notice_validator/services/sparql_test_suite_runner.py index 1bed90720..cc056fd49 100644 --- a/ted_sws/notice_validator/services/sparql_test_suite_runner.py +++ b/ted_sws/notice_validator/services/sparql_test_suite_runner.py @@ -116,6 +116,8 @@ def execute_test_suite(self) -> SPARQLTestSuiteValidationReport: sparql_query_result.error = str(e)[:100] sparql_query_result.result = SPARQLQueryRefinedResultType.ERROR test_suite_executions.validation_results.append(sparql_query_result) + + test_suite_executions.validation_results.sort(key=lambda x: x.query.title) return test_suite_executions @@ -152,7 +154,7 @@ def sparql_validation(rdf_manifestation: RDFManifestation) -> List[SPARQLTestSui mapping_suite=mapping_suite_package).execute_test_suite() report_builder = SPARQLReportBuilder(sparql_test_suite_execution=test_suite_execution) reports.append(report_builder.generate_report()) - return reports + return sorted(reports, key=lambda x: x.test_suite_identifier) for report in sparql_validation(rdf_manifestation=notice.rdf_manifestation): notice.set_rdf_validation(rdf_validation=report)
Form Field