You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consolidate case_validate CLI validation logic into case_validate.validate
This patch separates implementation points between functionality
distinct to `case_utils.validate` and `pyshacl.validate`. The
`allow_warnings` and `inference` parameters provide CASE-specific
documentation as an augmentation to `pyshacl.validate`'s documentation,
but otherwise other documentation on `pyshacl.validate`'s keyword
arguments is delegated to their upstream function.
This patch removes some hardcoded parameter values in
`pyshacl.validate`, letting the `case_validate` CLI or caller provide
any runtime-requested values.
Also, without functional impact, this patch sorts keyword parameters
alphabetically.
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
Copy file name to clipboardExpand all lines: case_utils/case_validate/__init__.py
+43-59Lines changed: 43 additions & 59 deletions
Original file line number
Diff line number
Diff line change
@@ -59,59 +59,74 @@
59
59
60
60
61
61
defvalidate(
62
-
input_file: str,
62
+
input_file: Union[List[str], str],
63
63
*args: Any,
64
64
case_version: Optional[str] =None,
65
65
supplemental_graphs: Optional[List[str]] =None,
66
-
abort_on_first: bool=False,
67
-
inference: Optional[str] =None,
68
66
**kwargs: Any,
69
67
) ->ValidationResult:
70
68
"""
71
69
Validate the given data graph against the given CASE ontology version and supplemental graphs.
70
+
72
71
:param *args: The positional arguments to pass to the underlying pyshacl.validate function.
73
-
:param input_file: The path to the file containing the data graph to validate.
74
-
:param case_version: The version of the CASE ontology to use (e.g. 1.2.0). If None, the most recent version will
75
-
be used.
76
-
:param supplemental_graphs: The supplemental graphs to use. If None, no supplemental graphs will be used.
77
-
:param abort_on_first: Whether to abort on the first validation error.
72
+
:param input_file: The path to the file containing the data graph to validate. This can also be a list of paths to files containing data graphs to pool together.
73
+
:param case_version: The version of the CASE ontology to use (e.g. 1.2.0). If None, the most recent version will be used.
74
+
:param supplemental_graphs: File paths to supplemental graphs to use. If None, no supplemental graphs will be used.
75
+
:param allow_warnings: In addition to affecting the conformance of SHACL validation, this will affect conformance based on unrecognized CDO concepts (likely, misspelled or miscapitalized) in the data graph. If allow_warnings is not True, any unrecognized concept using a CDO IRI prefix will cause conformance to be False.
78
76
:param inference: The type of inference to use. If "none" (type str), no inference will be used. If None (type NoneType), pyshacl defaults will be used. Note that at the time of this writing (pySHACL 0.23.0), pyshacl defaults are no inferencing for the data graph, and RDFS inferencing for the SHACL graph, which for case_utils.validate includes the SHACL and OWL graphs.
79
77
:param **kwargs: The keyword arguments to pass to the underlying pyshacl.validate function.
80
78
:return: The validation result object containing the defined properties.
81
79
"""
82
80
# Convert the data graph string to a rdflib.Graph object.
# Relieve RAM of the data graph after validation has run.
111
117
deldata_graph
112
118
119
+
conforms=validate_result[0]
120
+
121
+
iflen(undefined_cdo_concepts) >0:
122
+
warnings.warn(undefined_cdo_concepts_message)
123
+
ifnotkwargs.get("allow_warnings"):
124
+
undefined_cdo_concepts_alleviation_message="The data graph is SHACL-conformant with the CDO ontologies, but nonexistent-concept references raise Warnings with this tool. Please either correct the concept names in the data graph; use the --ontology-graph flag to pass a corrected CDO ontology file, also using --built-version none; or, use the --allow-warnings flag."
# Relieve RAM of the data graph after validation has run.
261
-
deldata_graph
262
-
263
-
conforms=validate_result[0]
264
-
validation_graph=validate_result[1]
265
-
validation_text=validate_result[2]
254
+
conforms=validation_result.conforms
255
+
validation_graph=validation_result.graph
256
+
validation_text=validation_result.text
266
257
267
258
# NOTE: The output logistics code is adapted from pySHACL's file
268
259
# pyshacl/cli.py. This section should be monitored for code drift.
@@ -284,13 +275,6 @@ def main() -> None:
284
275
%type(validation_graph)
285
276
)
286
277
287
-
iflen(undefined_cdo_concepts) >0:
288
-
warnings.warn(undefined_cdo_concepts_message)
289
-
ifnotargs.allow_warnings:
290
-
undefined_cdo_concepts_alleviation_message="The data graph is SHACL-conformant with the CDO ontologies, but nonexistent-concept references raise Warnings with this tool. Please either correct the concept names in the data graph; use the --ontology-graph flag to pass a corrected CDO ontology file, also using --built-version none; or, use the --allow-warnings flag."
0 commit comments