3737import os
3838import sys
3939import warnings
40- from typing import Dict , List , Optional , Set , Tuple , Union
40+ from typing import Any , Dict , List , Optional , Set , Tuple , Union
4141
4242import pyshacl # type: ignore
4343import rdflib
@@ -65,6 +65,14 @@ class NonExistentCDOConceptWarning(UserWarning):
6565 pass
6666
6767
68+ class NonExistentCASEVersionError (Exception ):
69+ """
70+ This class is used when an invalid CASE version is requested that is not supported by the library.
71+ """
72+
73+ pass
74+
75+
6876class ValidationResult :
6977 def __init__ (
7078 self ,
@@ -204,10 +212,21 @@ def get_ontology_graph(
204212
205213 if case_version != "none" :
206214 # Load bundled CASE ontology at requested version.
207- if case_version is None :
215+ if case_version is None or case_version == "" :
208216 case_version = CURRENT_CASE_VERSION
217+ # If the first character case_version is numeric, prepend case- to it. This allows for the version to be passed
218+ # by the library as both case-1.2.0 and 1.2.0
219+ if case_version [0 ].isdigit ():
220+ case_version = "case-" + case_version
209221 ttl_filename = case_version + ".ttl"
210222 _logger .debug ("ttl_filename = %r." , ttl_filename )
223+ # Ensure the requested version of the CASE ontology is available and if not, throw an appropriate exception
224+ # that can be returned in a user-friendly message.
225+ if not importlib .resources .is_resource (case_utils .ontology , ttl_filename ):
226+ raise NonExistentCASEVersionError (
227+ f"The requested version ({ case_version } ) of the CASE ontology is not available. Please choose a "
228+ f"different version. The latest supported version is: { CURRENT_CASE_VERSION } "
229+ )
211230 ttl_data = importlib .resources .read_text (case_utils .ontology , ttl_filename )
212231 ontology_graph .parse (data = ttl_data , format = "turtle" )
213232
@@ -221,19 +240,23 @@ def get_ontology_graph(
221240
222241def validate (
223242 input_file : str ,
243+ * args : Any ,
224244 case_version : Optional [str ] = None ,
225245 supplemental_graphs : Optional [List [str ]] = None ,
226246 abort_on_first : bool = False ,
227247 inference : Optional [str ] = "none" ,
248+ ** kwargs : Any ,
228249) -> ValidationResult :
229250 """
230251 Validate the given data graph against the given CASE ontology version and supplemental graphs.
231-
252+ :param *args: The positional arguments to pass to the underlying pyshacl.validate function.
232253 :param input_file: The path to the file containing the data graph to validate.
233- :param case_version: The version of the CASE ontology to use. If None, the most recent version will be used.
254+ :param case_version: The version of the CASE ontology to use (e.g. 1.2.0). If None, the most recent version will
255+ be used.
234256 :param supplemental_graphs: The supplemental graphs to use. If None, no supplemental graphs will be used.
235257 :param abort_on_first: Whether to abort on the first validation error.
236258 :param inference: The type of inference to use. If "none", no inference will be used.
259+ :param **kwargs: The keyword arguments to pass to the underlying pyshacl.validate function.
237260 :return: The validation result object containing the defined properties.
238261 """
239262 # Convert the data graph string to a rdflib.Graph object.
@@ -260,6 +283,8 @@ def validate(
260283 allow_warnings = False ,
261284 debug = False ,
262285 do_owl_imports = False ,
286+ args = args ,
287+ kwargs = kwargs ,
263288 )
264289
265290 # Relieve RAM of the data graph after validation has run.
@@ -409,7 +434,7 @@ def main() -> None:
409434 allow_warnings = True if args .allow_warnings else False ,
410435 debug = True if args .debug else False ,
411436 do_owl_imports = True if args .imports else False ,
412- ** validator_kwargs
437+ ** validator_kwargs ,
413438 )
414439
415440 # Relieve RAM of the data graph after validation has run.
0 commit comments