spdx_tools.spdx3.validation.json_ld.shacl_validation

 1# SPDX-FileCopyrightText: 2023 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from beartype.typing import Optional
 5from pyshacl import validate
 6from rdflib import Graph
 7
 8
 9def validate_against_shacl_from_file(
10    data_file: str, shacl_file: str, data_format: Optional[str] = "json-ld", shacl_format: Optional[str] = "ttl"
11):
12    data_graph = Graph()
13    with open(data_file) as file:
14        data_graph.parse(file, format=data_format)
15
16    shacl_graph = Graph()
17    with open(shacl_file) as file:
18        shacl_graph.parse(file, format=shacl_format)
19
20    return validate(data_graph=data_graph, shacl_graph=shacl_graph, ont_graph=shacl_graph)
def validate_against_shacl_from_file( data_file: str, shacl_file: str, data_format: Optional[str] = 'json-ld', shacl_format: Optional[str] = 'ttl'):
10def validate_against_shacl_from_file(
11    data_file: str, shacl_file: str, data_format: Optional[str] = "json-ld", shacl_format: Optional[str] = "ttl"
12):
13    data_graph = Graph()
14    with open(data_file) as file:
15        data_graph.parse(file, format=data_format)
16
17    shacl_graph = Graph()
18    with open(shacl_file) as file:
19        shacl_graph.parse(file, format=shacl_format)
20
21    return validate(data_graph=data_graph, shacl_graph=shacl_graph, ont_graph=shacl_graph)