@@ -65,6 +65,19 @@ def _sparql_query_from_file_resource(cls, file_resource: FileResource) -> SPARQL
6565 query = cls ._sanitize_query (file_resource .file_content )
6666 return SPARQLQuery (title = title , description = description , xpath = xpath , query = query )
6767
68+ @classmethod
69+ def _refined_result (cls , ask_answer , sparql_query_result ,
70+ result : SPARQLQueryRefinedResultType ) -> SPARQLQueryRefinedResultType :
71+ if ask_answer and sparql_query_result .fields_covered :
72+ result = SPARQLQueryRefinedResultType .VALID .value
73+ elif not ask_answer and not sparql_query_result .fields_covered :
74+ result = SPARQLQueryRefinedResultType .UNVERIFIABLE .value
75+ elif ask_answer and not sparql_query_result .fields_covered :
76+ result = SPARQLQueryRefinedResultType .WARNING .value
77+ elif not ask_answer and sparql_query_result .fields_covered :
78+ result = SPARQLQueryRefinedResultType .INVALID .value
79+ return result
80+
6881 def _process_sparql_ask_result (self , query_result , sparql_query : SPARQLQuery ,
6982 sparql_query_result : SPARQLQueryResult ):
7083 ask_answer = query_result .askAnswer
@@ -89,14 +102,7 @@ def _process_sparql_ask_result(self, query_result, sparql_query: SPARQLQuery,
89102 sparql_query_result .missing_fields = list (sparql_query_xpath - xpaths_in_notice )
90103
91104 # Refined result
92- if ask_answer and sparql_query_result .fields_covered :
93- result = SPARQLQueryRefinedResultType .VALID .value
94- elif not ask_answer and not sparql_query_result .fields_covered :
95- result = SPARQLQueryRefinedResultType .UNVERIFIABLE .value
96- elif ask_answer and not sparql_query_result .fields_covered :
97- result = SPARQLQueryRefinedResultType .WARNING .value
98- elif not ask_answer and sparql_query_result .fields_covered :
99- result = SPARQLQueryRefinedResultType .INVALID .value
105+ result = self ._refined_result (ask_answer , sparql_query_result , result )
100106
101107 sparql_query_result .result = result
102108
@@ -155,11 +161,75 @@ def generate_report(self) -> SPARQLTestSuiteValidationReport:
155161 return self .sparql_test_suite_execution
156162
157163
158- def generate_sparql_validation_summary_report (report_notices : List [ReportNotice ], mapping_suite_package : MappingSuite ,
159- execute_full_validation : bool = True ,
160- with_html : bool = False ,
161- report : SPARQLValidationSummaryReport = None ,
162- metadata : dict = None ) -> SPARQLValidationSummaryReport :
164+ def process_sparql_validation_summary_report_data_with_notice (
165+ notice : Notice ,
166+ mapping_suite_package : MappingSuite ,
167+ report_notice_path : Path ,
168+ report : SPARQLValidationSummaryReport
169+ ):
170+ for sparql_validation in notice .rdf_manifestation .sparql_validations :
171+ test_suite_id = sparql_validation .test_suite_identifier
172+ report .test_suite_ids .append (test_suite_id )
173+ mapping_suite_versioned_id = sparql_validation .mapping_suite_identifier
174+ report .mapping_suite_ids .append (mapping_suite_versioned_id )
175+ validation : SPARQLQueryResult
176+ for validation in sparql_validation .validation_results :
177+ validation_query_result : SPARQLValidationSummaryQueryResult
178+ found_validation_query_result = list (filter (
179+ lambda record :
180+ (record .query .query == validation .query .query )
181+ and (record .query .title == validation .query .title )
182+ and (record .test_suite_identifier == test_suite_id ),
183+ report .validation_results
184+ ))
185+ if found_validation_query_result :
186+ validation_query_result = found_validation_query_result [0 ]
187+ else :
188+ validation_query_result = SPARQLValidationSummaryQueryResult (
189+ test_suite_identifier = test_suite_id ,
190+ ** validation .dict ()
191+ )
192+ notice_data : ReportPackageNoticeData = ReportPackageNoticeData (
193+ notice_id = notice .ted_id ,
194+ path = str (report_notice_path ),
195+ mapping_suite_versioned_id = mapping_suite_versioned_id ,
196+ mapping_suite_identifier = mapping_suite_package .identifier
197+ )
198+ if validation .result == SPARQLQueryRefinedResultType .VALID .value :
199+ validation_query_result .aggregate .valid .count += 1
200+ validation_query_result .aggregate .valid .notices .append (notice_data )
201+ elif validation .result == SPARQLQueryRefinedResultType .UNVERIFIABLE .value :
202+ validation_query_result .aggregate .unverifiable .count += 1
203+ validation_query_result .aggregate .unverifiable .notices .append (notice_data )
204+ elif validation .result == SPARQLQueryRefinedResultType .INVALID .value :
205+ validation_query_result .aggregate .invalid .count += 1
206+ validation_query_result .aggregate .invalid .notices .append (notice_data )
207+ elif validation .result == SPARQLQueryRefinedResultType .WARNING .value :
208+ validation_query_result .aggregate .warning .count += 1
209+ validation_query_result .aggregate .warning .notices .append (notice_data )
210+ elif validation .result == SPARQLQueryRefinedResultType .ERROR .value :
211+ validation_query_result .aggregate .error .count += 1
212+ validation_query_result .aggregate .error .notices .append (notice_data )
213+ elif validation .result == SPARQLQueryRefinedResultType .UNKNOWN .value :
214+ validation_query_result .aggregate .unknown .count += 1
215+ validation_query_result .aggregate .unknown .notices .append (notice_data )
216+ if not found_validation_query_result :
217+ report .validation_results .append (validation_query_result )
218+
219+
220+ def add_sparql_validation_summary_html_report (
221+ report : SPARQLValidationSummaryReport ,
222+ metadata : dict = None
223+ ):
224+ template_data : dict = report .dict ()
225+ template_data [TEMPLATE_METADATA_KEY ] = metadata
226+ html_report = TEMPLATES .get_template (SPARQL_SUMMARY_HTML_REPORT_TEMPLATE ).render (template_data )
227+ report .object_data = html_report
228+
229+
230+ def init_sparql_validation_summary_report (
231+ report : SPARQLValidationSummaryReport ,
232+ report_notices : List [ReportNotice ]) -> SPARQLValidationSummaryReport :
163233 if report is None :
164234 report : SPARQLValidationSummaryReport = SPARQLValidationSummaryReport (
165235 object_data = "SPARQLValidationSummaryReport" ,
@@ -170,6 +240,32 @@ def generate_sparql_validation_summary_report(report_notices: List[ReportNotice]
170240 report .notices = sorted (NoticeTransformer .transform_validation_report_notices (report_notices , group_depth = 1 ) + (
171241 report .notices or []), key = lambda report_data : report_data .notice_id )
172242
243+ return report
244+
245+
246+ def finalize_sparql_validation_summary_report (report : SPARQLValidationSummaryReport , metadata : dict = None ,
247+ with_html : bool = False ):
248+ report .test_suite_ids = list (set (report .test_suite_ids ))
249+ report .mapping_suite_ids = list (set (report .mapping_suite_ids ))
250+
251+ if with_html :
252+ add_sparql_validation_summary_html_report (
253+ report = report ,
254+ metadata = metadata
255+ )
256+
257+
258+ def generate_sparql_validation_summary_report (report_notices : List [ReportNotice ],
259+ mapping_suite_package : MappingSuite ,
260+ execute_full_validation : bool = True ,
261+ with_html : bool = False ,
262+ report : SPARQLValidationSummaryReport = None ,
263+ metadata : dict = None ) -> SPARQLValidationSummaryReport :
264+ report = init_sparql_validation_summary_report (
265+ report = report ,
266+ report_notices = report_notices
267+ )
268+
173269 for report_notice in report_notices :
174270 notice = report_notice .notice
175271 validate_notice_with_sparql_suite (
@@ -178,68 +274,19 @@ def generate_sparql_validation_summary_report(report_notices: List[ReportNotice]
178274 execute_full_validation = execute_full_validation ,
179275 with_html = False
180276 )
181- for sparql_validation in notice .rdf_manifestation .sparql_validations :
182- test_suite_id = sparql_validation .test_suite_identifier
183- report .test_suite_ids .append (test_suite_id )
184- mapping_suite_versioned_id = sparql_validation .mapping_suite_identifier
185- report .mapping_suite_ids .append (mapping_suite_versioned_id )
186-
187- validation : SPARQLQueryResult
188- for validation in sparql_validation .validation_results :
189- validation_query_result : SPARQLValidationSummaryQueryResult
190- found_validation_query_result = list (filter (
191- lambda record :
192- (record .query .query == validation .query .query )
193- and (record .query .title == validation .query .title )
194- and (record .test_suite_identifier == test_suite_id ),
195- report .validation_results
196- ))
197-
198- if found_validation_query_result :
199- validation_query_result = found_validation_query_result [0 ]
200- else :
201- validation_query_result = SPARQLValidationSummaryQueryResult (
202- test_suite_identifier = test_suite_id ,
203- ** validation .dict ()
204- )
205-
206- notice_data : ReportPackageNoticeData = ReportPackageNoticeData (
207- notice_id = notice .ted_id ,
208- path = str (report_notice .metadata .path ),
209- mapping_suite_versioned_id = mapping_suite_versioned_id ,
210- mapping_suite_identifier = mapping_suite_package .identifier
211- )
212277
213- if validation .result == SPARQLQueryRefinedResultType .VALID .value :
214- validation_query_result .aggregate .valid .count += 1
215- validation_query_result .aggregate .valid .notices .append (notice_data )
216- elif validation .result == SPARQLQueryRefinedResultType .UNVERIFIABLE .value :
217- validation_query_result .aggregate .unverifiable .count += 1
218- validation_query_result .aggregate .unverifiable .notices .append (notice_data )
219- elif validation .result == SPARQLQueryRefinedResultType .INVALID .value :
220- validation_query_result .aggregate .invalid .count += 1
221- validation_query_result .aggregate .invalid .notices .append (notice_data )
222- elif validation .result == SPARQLQueryRefinedResultType .WARNING .value :
223- validation_query_result .aggregate .warning .count += 1
224- validation_query_result .aggregate .warning .notices .append (notice_data )
225- elif validation .result == SPARQLQueryRefinedResultType .ERROR .value :
226- validation_query_result .aggregate .error .count += 1
227- validation_query_result .aggregate .error .notices .append (notice_data )
228- elif validation .result == SPARQLQueryRefinedResultType .UNKNOWN .value :
229- validation_query_result .aggregate .unknown .count += 1
230- validation_query_result .aggregate .unknown .notices .append (notice_data )
231-
232- if not found_validation_query_result :
233- report .validation_results .append (validation_query_result )
234-
235- report .test_suite_ids = list (set (report .test_suite_ids ))
236- report .mapping_suite_ids = list (set (report .mapping_suite_ids ))
278+ process_sparql_validation_summary_report_data_with_notice (
279+ notice = notice ,
280+ mapping_suite_package = mapping_suite_package ,
281+ report_notice_path = report_notice .metadata .path ,
282+ report = report
283+ )
237284
238- if with_html :
239- template_data : dict = report . dict ()
240- template_data [ TEMPLATE_METADATA_KEY ] = metadata
241- html_report = TEMPLATES . get_template ( SPARQL_SUMMARY_HTML_REPORT_TEMPLATE ). render ( template_data )
242- report . object_data = html_report
285+ finalize_sparql_validation_summary_report (
286+ report = report ,
287+ metadata = metadata ,
288+ with_html = with_html
289+ )
243290
244291 return report
245292
@@ -255,7 +302,7 @@ def validate_notice_with_sparql_suite(notice: Notice, mapping_suite_package: Map
255302 :return:
256303 """
257304
258- def sparql_validation (notice_item : Notice , rdf_manifestation : RDFManifestation , with_html : bool = False ) \
305+ def sparql_validation (notice_item : Notice , rdf_manifestation : RDFManifestation ) \
259306 -> List [SPARQLTestSuiteValidationReport ]:
260307 reports = []
261308 sparql_test_suites = mapping_suite_package .sparql_test_suites
@@ -271,12 +318,10 @@ def sparql_validation(notice_item: Notice, rdf_manifestation: RDFManifestation,
271318 return sorted (reports , key = lambda x : x .test_suite_identifier )
272319
273320 if execute_full_validation :
274- for report in sparql_validation (notice_item = notice , rdf_manifestation = notice .rdf_manifestation ,
275- with_html = with_html ):
321+ for report in sparql_validation (notice_item = notice , rdf_manifestation = notice .rdf_manifestation ):
276322 notice .set_rdf_validation (rdf_validation = report )
277323
278- for report in sparql_validation (notice_item = notice , rdf_manifestation = notice .distilled_rdf_manifestation ,
279- with_html = with_html ):
324+ for report in sparql_validation (notice_item = notice , rdf_manifestation = notice .distilled_rdf_manifestation ):
280325 notice .set_distilled_rdf_validation (rdf_validation = report )
281326
282327 return notice
0 commit comments