-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathvalidation.py
202 lines (155 loc) · 8.59 KB
/
validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Auto generated from validation.yaml by pythongen.py version: 0.0.1
# Generation date: 2024-06-27T23:15:35
# Schema: reporting
#
# id: https://w3id.org/linkml/reporting
# description: A datamodel for reports on data, based on SHACL
# license: https://creativecommons.org/publicdomain/zero/1.0/
import dataclasses
import re
from linkml_runtime.utils.jsonasobj2 import JsonObj, as_dict
from typing import Optional, List, Union, Dict, ClassVar, Any
from dataclasses import dataclass
from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int
from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
from rdflib import Namespace, URIRef
from linkml_runtime.utils.curienamespace import CurieNamespace
from .types import Nodeidentifier, String
from linkml_runtime.utils.metamodelcore import NodeIdentifier
metamodel_version = "1.7.0"
version = None
# Overwrite dataclasses _init_fn to add **kwargs in __init__
dataclasses._init_fn = dataclasses_init_fn_with_kwargs
# Namespaces
LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/')
OWL = CurieNamespace('owl', 'http://www.w3.org/2002/07/owl#')
PAV = CurieNamespace('pav', 'http://purl.org/pav/')
RDF = CurieNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
RDFS = CurieNamespace('rdfs', 'http://www.w3.org/2000/01/rdf-schema#')
REPORTING = CurieNamespace('reporting', 'https://w3id.org/linkml/report')
SCHEMA = CurieNamespace('schema', 'http://schema.org/')
SH = CurieNamespace('sh', 'https://w3id.org/shacl/')
SKOS = CurieNamespace('skos', 'http://www.w3.org/2004/02/skos/core#')
XSD = CurieNamespace('xsd', 'http://www.w3.org/2001/XMLSchema#')
DEFAULT_ = REPORTING
# Types
# Class references
@dataclass
class ValidationReport(YAMLRoot):
"""
A report object
"""
_inherited_slots: ClassVar[List[str]] = []
class_class_uri: ClassVar[URIRef] = SH["ValidationReport"]
class_class_curie: ClassVar[str] = "sh:ValidationReport"
class_name: ClassVar[str] = "ValidationReport"
class_model_uri: ClassVar[URIRef] = REPORTING.ValidationReport
results: Optional[Union[Union[dict, "ValidationResult"], List[Union[dict, "ValidationResult"]]]] = empty_list()
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if not isinstance(self.results, list):
self.results = [self.results] if self.results is not None else []
self.results = [v if isinstance(v, ValidationResult) else ValidationResult(**as_dict(v)) for v in self.results]
super().__post_init__(**kwargs)
@dataclass
class ValidationResult(YAMLRoot):
"""
An individual result arising from validation of a data instance using a particular rule
"""
_inherited_slots: ClassVar[List[str]] = []
class_class_uri: ClassVar[URIRef] = SH["ValidationResult"]
class_class_curie: ClassVar[str] = "sh:ValidationResult"
class_name: ClassVar[str] = "ValidationResult"
class_model_uri: ClassVar[URIRef] = REPORTING.ValidationResult
type: Optional[Union[str, NodeIdentifier]] = None
severity: Optional[Union[str, "SeverityOptions"]] = None
subject: Optional[Union[str, NodeIdentifier]] = None
instantiates: Optional[Union[str, NodeIdentifier]] = None
predicate: Optional[Union[str, NodeIdentifier]] = None
object: Optional[Union[str, NodeIdentifier]] = None
object_str: Optional[str] = None
node_source: Optional[Union[str, NodeIdentifier]] = None
info: Optional[str] = None
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self.type is not None and not isinstance(self.type, NodeIdentifier):
self.type = NodeIdentifier(self.type)
if self.severity is not None and not isinstance(self.severity, SeverityOptions):
self.severity = SeverityOptions(self.severity)
if self.subject is not None and not isinstance(self.subject, NodeIdentifier):
self.subject = NodeIdentifier(self.subject)
if self.instantiates is not None and not isinstance(self.instantiates, NodeIdentifier):
self.instantiates = NodeIdentifier(self.instantiates)
if self.predicate is not None and not isinstance(self.predicate, NodeIdentifier):
self.predicate = NodeIdentifier(self.predicate)
if self.object is not None and not isinstance(self.object, NodeIdentifier):
self.object = NodeIdentifier(self.object)
if self.object_str is not None and not isinstance(self.object_str, str):
self.object_str = str(self.object_str)
if self.node_source is not None and not isinstance(self.node_source, NodeIdentifier):
self.node_source = NodeIdentifier(self.node_source)
if self.info is not None and not isinstance(self.info, str):
self.info = str(self.info)
super().__post_init__(**kwargs)
# Enumerations
class ProblemType(EnumDefinitionImpl):
undeclared_slot = PermissibleValue(
text="undeclared_slot",
description="Applies when a slot is used in data but the slot is undeclared in the datamodel")
inapplicable_slot = PermissibleValue(
text="inapplicable_slot",
description="""Applies when a slot is used in an instance of a class where the slot is not applicable for that class""")
missing_slot_value = PermissibleValue(
text="missing_slot_value",
description="Applies when an instance of a class has a required slot which is not filled in")
slot_range_violation = PermissibleValue(
text="slot_range_violation",
description="Applies when the value of a slot is inconsistent with the declared range")
max_count_violation = PermissibleValue(
text="max_count_violation",
meaning=SH["MaxCountConstraintComponent"])
parsing_error = PermissibleValue(
text="parsing_error",
description="The data could not be parsed")
_defn = EnumDefinition(
name="ProblemType",
)
class SeverityOptions(EnumDefinitionImpl):
FATAL = PermissibleValue(text="FATAL")
ERROR = PermissibleValue(
text="ERROR",
meaning=SH["Violation"])
WARNING = PermissibleValue(
text="WARNING",
meaning=SH["Warning"])
INFO = PermissibleValue(
text="INFO",
meaning=SH["Info"])
_defn = EnumDefinition(
name="SeverityOptions",
)
# Slots
class slots:
pass
slots.type = Slot(uri=SH.sourceConstraintComponent, name="type", curie=SH.curie('sourceConstraintComponent'),
model_uri=REPORTING.type, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.subject = Slot(uri=SH.focusNode, name="subject", curie=SH.curie('focusNode'),
model_uri=REPORTING.subject, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.instantiates = Slot(uri=REPORTING.instantiates, name="instantiates", curie=REPORTING.curie('instantiates'),
model_uri=REPORTING.instantiates, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.predicate = Slot(uri=REPORTING.predicate, name="predicate", curie=REPORTING.curie('predicate'),
model_uri=REPORTING.predicate, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.object = Slot(uri=SH.value, name="object", curie=SH.curie('value'),
model_uri=REPORTING.object, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.object_str = Slot(uri=REPORTING.object_str, name="object_str", curie=REPORTING.curie('object_str'),
model_uri=REPORTING.object_str, domain=None, range=Optional[str])
slots.node_source = Slot(uri=REPORTING.node_source, name="node_source", curie=REPORTING.curie('node_source'),
model_uri=REPORTING.node_source, domain=None, range=Optional[Union[str, NodeIdentifier]])
slots.severity = Slot(uri=REPORTING.severity, name="severity", curie=REPORTING.curie('severity'),
model_uri=REPORTING.severity, domain=None, range=Optional[Union[str, "SeverityOptions"]])
slots.info = Slot(uri=REPORTING.info, name="info", curie=REPORTING.curie('info'),
model_uri=REPORTING.info, domain=None, range=Optional[str])
slots.validationReport__results = Slot(uri=REPORTING.results, name="validationReport__results", curie=REPORTING.curie('results'),
model_uri=REPORTING.validationReport__results, domain=None, range=Optional[Union[Union[dict, ValidationResult], List[Union[dict, ValidationResult]]]])