Skip to content

validation

This module defines auxiliary classes to represent pySHACL validation reports.

ProfileValidationReport

Validation report for a given profile.

Source code in ogc/na/validation.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class ProfileValidationReport:
    """
    Validation report for a given [profile](https://www.w3.org/TR/dx-prof/).
    """

    def __init__(self, profile_uri: URIRef, profile_token: str, report: ValidationReport):
        """
        :param profile_uri: URI for the profile
        :param profile_token: Token for the profile
        :param report: [ValidationReport][ogc.na.validation.ValidationReport]
        """
        self.profile_uri = profile_uri
        self.profile_token = profile_token
        self.report = report

    @property
    def used_resources(self) -> set[Union[str, Path]]:
        return self.report.used_resources

    @used_resources.setter
    def used_resources(self, ur: set[Union[str, Path]]):
        self.used_resources = ur

__init__(profile_uri, profile_token, report)

Parameters:

Name Type Description Default
profile_uri URIRef

URI for the profile

required
profile_token str

Token for the profile

required
report ValidationReport required
Source code in ogc/na/validation.py
25
26
27
28
29
30
31
32
33
def __init__(self, profile_uri: URIRef, profile_token: str, report: ValidationReport):
    """
    :param profile_uri: URI for the profile
    :param profile_token: Token for the profile
    :param report: [ValidationReport][ogc.na.validation.ValidationReport]
    """
    self.profile_uri = profile_uri
    self.profile_token = profile_token
    self.report = report

ProfilesValidationReport

Class to aggregate several ProfileValidationReport's coming from different profiles.

Results are exposed through the following fields:

  • reports: list of validation reports
  • result: True if all validations passed, otherwise False
  • graph: union of all SHACL validation report Graphs
  • text: full report text coming from all validation results (separated by profile)
Source code in ogc/na/validation.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class ProfilesValidationReport:
    """
    Class to aggregate several [ProfileValidationReport][ogc.na.validation.ProfileValidationReport]'s
    coming from different profiles.

    Results are exposed through the following fields:

    * `reports`: list of [validation reports][ogc.na.validation.ProfileValidationReport]
    * `result`: `True` if all validations passed, otherwise `False`
    * `graph`: union of all SHACL validation report [Graph][rdflib.Graph]s
    * `text`: full report text coming from all validation results (separated by profile)
    """

    def __init__(self, profile_reports: list[ProfileValidationReport] = None):
        """
        :param profile_reports: list of initial [validation reports][ogc.na.validation.ProfileValidationReport]
        """
        self.reports: list[ProfileValidationReport] = []
        self.result = True
        self.graph = Graph()
        self.text = ''
        if profile_reports:
            for profile_report in self.reports:
                self.add(profile_report)

    def add(self, profile_report: ProfileValidationReport):
        """
        Add a new [validation report][ogc.na.validation.ProfileValidationReport].

        :param profile_report:
        """
        self.reports.append(profile_report)
        self.result &= profile_report.report.result
        util.copy_triples(profile_report.report.graph, self.graph)
        if profile_report.report.text:
            if self.text:
                self.text += '\n'
            self.text += (f"=== {profile_report.profile_token} "
                          f"({profile_report.profile_uri}) ===\n"
                          f"{profile_report.report.text}")

    def __contains__(self, item) -> bool:
        return any(r.profile_uri == item for r in self.reports)

    @property
    def used_resources(self):
        return set(r for report in self.reports for r in report.used_resources)

__init__(profile_reports=None)

Parameters:

Name Type Description Default
profile_reports list[ProfileValidationReport]

list of initial validation reports

None
Source code in ogc/na/validation.py
57
58
59
60
61
62
63
64
65
66
67
def __init__(self, profile_reports: list[ProfileValidationReport] = None):
    """
    :param profile_reports: list of initial [validation reports][ogc.na.validation.ProfileValidationReport]
    """
    self.reports: list[ProfileValidationReport] = []
    self.result = True
    self.graph = Graph()
    self.text = ''
    if profile_reports:
        for profile_report in self.reports:
            self.add(profile_report)

add(profile_report)

Add a new validation report.

Parameters:

Name Type Description Default
profile_report ProfileValidationReport
required
Source code in ogc/na/validation.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def add(self, profile_report: ProfileValidationReport):
    """
    Add a new [validation report][ogc.na.validation.ProfileValidationReport].

    :param profile_report:
    """
    self.reports.append(profile_report)
    self.result &= profile_report.report.result
    util.copy_triples(profile_report.report.graph, self.graph)
    if profile_report.report.text:
        if self.text:
            self.text += '\n'
        self.text += (f"=== {profile_report.profile_token} "
                      f"({profile_report.profile_uri}) ===\n"
                      f"{profile_report.report.text}")