ruml-parser 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ruml_parser/__init__.py +183 -0
- ruml_parser/internal/__init__.py +2 -0
- ruml_parser/internal/extension.py +91 -0
- ruml_parser/internal/mapping.py +731 -0
- ruml_parser/internal/ruml/__init__.py +237 -0
- ruml_parser/internal/ruml/actions/__init__.py +2 -0
- ruml_parser/internal/ruml/actions/actions_capability_declaration.py +23 -0
- ruml_parser/internal/ruml/actions/actions_node_capability.py +40 -0
- ruml_parser/internal/ruml/ai_query/__init__.py +2 -0
- ruml_parser/internal/ruml/ai_query/ai_query_capability_declaration.py +25 -0
- ruml_parser/internal/ruml/ai_query/ai_query_node_capability.py +66 -0
- ruml_parser/internal/ruml/aliases.py +93 -0
- ruml_parser/internal/ruml/capability/__init__.py +2 -0
- ruml_parser/internal/ruml/capability/abstract_capability_declaration.py +23 -0
- ruml_parser/internal/ruml/capability/abstract_node_capability.py +14 -0
- ruml_parser/internal/ruml/capability/capability_declaration.py +52 -0
- ruml_parser/internal/ruml/capability/capability_declarations.py +199 -0
- ruml_parser/internal/ruml/capability/extension_node_capability.py +17 -0
- ruml_parser/internal/ruml/capability/node_capabilities.py +113 -0
- ruml_parser/internal/ruml/capability/other_node_capability.py +21 -0
- ruml_parser/internal/ruml/context/__init__.py +2 -0
- ruml_parser/internal/ruml/context/context.py +40 -0
- ruml_parser/internal/ruml/context/context_capability_declaration.py +25 -0
- ruml_parser/internal/ruml/context/context_refs_node_capability.py +17 -0
- ruml_parser/internal/ruml/datapoints/__init__.py +2 -0
- ruml_parser/internal/ruml/datapoints/datapoint.py +101 -0
- ruml_parser/internal/ruml/datapoints/datapoint_set.py +20 -0
- ruml_parser/internal/ruml/datapoints/datapoints_capability_declaration.py +29 -0
- ruml_parser/internal/ruml/datapoints/option.py +11 -0
- ruml_parser/internal/ruml/expression/__init__.py +2 -0
- ruml_parser/internal/ruml/expression/expression_capability_declaration.py +23 -0
- ruml_parser/internal/ruml/expression/expression_node_capability.py +20 -0
- ruml_parser/internal/ruml/metadata.py +83 -0
- ruml_parser/internal/ruml/nodes/__init__.py +2 -0
- ruml_parser/internal/ruml/nodes/abstract_node.py +29 -0
- ruml_parser/internal/ruml/nodes/branch_node.py +15 -0
- ruml_parser/internal/ruml/nodes/leaf_node.py +10 -0
- ruml_parser/internal/ruml/nodes/node.py +6 -0
- ruml_parser/internal/ruml/protocol/__init__.py +2 -0
- ruml_parser/internal/ruml/protocol/protocol_capability_declaration.py +29 -0
- ruml_parser/internal/ruml/query/__init__.py +2 -0
- ruml_parser/internal/ruml/query/query_capability_declaration.py +23 -0
- ruml_parser/internal/ruml/query/query_node_capability.py +17 -0
- ruml_parser/internal/ruml/ruml_document.py +45 -0
- ruml_parser/internal/ruml/text_reference/__init__.py +2 -0
- ruml_parser/internal/ruml/text_reference/text.py +69 -0
- ruml_parser/internal/ruml/text_reference/text_reference_capability_declaration.py +25 -0
- ruml_parser/internal/ruml/text_reference/text_refs_node_capability.py +32 -0
- ruml_parser/internal/ruml/tree/__init__.py +2 -0
- ruml_parser/internal/ruml/tree/tree_capability_declarations.py +30 -0
- ruml_parser/internal/validation/__init__.py +14 -0
- ruml_parser/internal/validation/capabilities.py +227 -0
- ruml_parser/internal/validation/contexts.py +51 -0
- ruml_parser/internal/validation/datapoint_sets.py +125 -0
- ruml_parser/internal/validation/modular.py +42 -0
- ruml_parser/internal/validation/recursion.py +197 -0
- ruml_parser/internal/validation/root.py +36 -0
- ruml_parser/internal/validation/texts.py +50 -0
- ruml_parser/model/__init__.py +2 -0
- ruml_parser/model/ruml.py +1156 -0
- ruml_parser/model/ruml_result.py +430 -0
- ruml_parser/node_result_status.py +19 -0
- ruml_parser/pydantic.py +96 -0
- ruml_parser/ruml_parser.py +75 -0
- ruml_parser/schema_files.py +23 -0
- ruml_parser/schema_validation.py +354 -0
- ruml_parser/structural_error.py +36 -0
- ruml_parser/text.py +220 -0
- ruml_parser-1.0.0.dist-info/METADATA +119 -0
- ruml_parser-1.0.0.dist-info/RECORD +72 -0
- ruml_parser-1.0.0.dist-info/WHEEL +4 -0
- ruml_parser-1.0.0.dist-info/licenses/LICENSE +73 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping, Sequence
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from more_itertools import only
|
|
7
|
+
|
|
8
|
+
from ruml_parser.internal.ruml.actions.actions_capability_declaration import (
|
|
9
|
+
ActionsCapabilityDeclaration,
|
|
10
|
+
)
|
|
11
|
+
from ruml_parser.internal.ruml.ai_query.ai_query_capability_declaration import (
|
|
12
|
+
AiQueryCapabilityDeclaration,
|
|
13
|
+
)
|
|
14
|
+
from ruml_parser.internal.ruml.aliases import CapabilityId, CapabilityRole
|
|
15
|
+
from ruml_parser.internal.ruml.capability.abstract_capability_declaration import (
|
|
16
|
+
AbstractCapabilityDeclaration,
|
|
17
|
+
)
|
|
18
|
+
from ruml_parser.internal.ruml.capability.capability_declaration import (
|
|
19
|
+
CapabilityDeclarationWithData,
|
|
20
|
+
DraftCapabilityDeclaration,
|
|
21
|
+
ExtensionCapabilityDeclaration,
|
|
22
|
+
)
|
|
23
|
+
from ruml_parser.internal.ruml.context.context_capability_declaration import (
|
|
24
|
+
ContextCapabilityDeclaration,
|
|
25
|
+
)
|
|
26
|
+
from ruml_parser.internal.ruml.datapoints.datapoints_capability_declaration import (
|
|
27
|
+
DatapointsCapabilityDeclaration,
|
|
28
|
+
)
|
|
29
|
+
from ruml_parser.internal.ruml.expression.expression_capability_declaration import (
|
|
30
|
+
ExpressionCapabilityDeclaration,
|
|
31
|
+
)
|
|
32
|
+
from ruml_parser.internal.ruml.protocol.protocol_capability_declaration import (
|
|
33
|
+
ProtocolCapabilityDeclaration,
|
|
34
|
+
)
|
|
35
|
+
from ruml_parser.internal.ruml.query.query_capability_declaration import (
|
|
36
|
+
QueryCapabilityDeclaration,
|
|
37
|
+
)
|
|
38
|
+
from ruml_parser.internal.ruml.text_reference.text_reference_capability_declaration import (
|
|
39
|
+
TextReferenceCapabilityDeclaration,
|
|
40
|
+
)
|
|
41
|
+
from ruml_parser.internal.ruml.tree.tree_capability_declarations import (
|
|
42
|
+
TreeIncludeCapabilityDeclaration,
|
|
43
|
+
TreeReferenceCapabilityDeclaration,
|
|
44
|
+
)
|
|
45
|
+
from ruml_parser.model import ruml as model
|
|
46
|
+
|
|
47
|
+
#
|
|
48
|
+
# The schema declares a capability as an entry `{id, required, payload}` whose payload
|
|
49
|
+
# schema depends on the id. The classes here merge entry and payload into one object
|
|
50
|
+
# per capability: `required` sits next to the payload's fields, and the id is the
|
|
51
|
+
# `CapabilityDeclarations` field (or key) the object is held under.
|
|
52
|
+
#
|
|
53
|
+
# Every declaration is an `AbstractCapabilityDeclaration`, which knows its `id` and the
|
|
54
|
+
# `role` it plays (§4.1). Draft and third-party ids must declare theirs (CAP-03). An
|
|
55
|
+
# official id's role is fixed by its chapter, and its entry must not declare one
|
|
56
|
+
# (CAP-05); an extension fixes its capability's role, and the entry must declare the
|
|
57
|
+
# same (CAP-04).
|
|
58
|
+
# `CapabilityDeclarations.get_by_id()` answers for any declared id.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
62
|
+
class CapabilityDeclarations:
|
|
63
|
+
"""Root-level capability declarations.
|
|
64
|
+
|
|
65
|
+
Replaces the generated `list[CapabilityEntry]`, whose payload is a free-form object
|
|
66
|
+
whatever the entry's id: here each official capability is a field of the type the
|
|
67
|
+
schema prescribes for it, and the draft and third-party ones are grouped by kind,
|
|
68
|
+
each keyed by its id.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
datapoints: DatapointsCapabilityDeclaration | None = None
|
|
72
|
+
"""`ruml:datapoints`"""
|
|
73
|
+
text_reference: TextReferenceCapabilityDeclaration | None = None
|
|
74
|
+
"""`ruml:text-reference`"""
|
|
75
|
+
tree_reference: TreeReferenceCapabilityDeclaration | None = None
|
|
76
|
+
"""`ruml:tree-reference`"""
|
|
77
|
+
tree_include: TreeIncludeCapabilityDeclaration | None = None
|
|
78
|
+
"""`ruml:tree-include`"""
|
|
79
|
+
context: ContextCapabilityDeclaration | None = None
|
|
80
|
+
"""`ruml:context`"""
|
|
81
|
+
query: QueryCapabilityDeclaration | None = None
|
|
82
|
+
"""`ruml:query`"""
|
|
83
|
+
ai_query: AiQueryCapabilityDeclaration | None = None
|
|
84
|
+
"""`ruml:ai-query`"""
|
|
85
|
+
expression: ExpressionCapabilityDeclaration | None = None
|
|
86
|
+
"""`ruml:expression`"""
|
|
87
|
+
actions: ActionsCapabilityDeclaration | None = None
|
|
88
|
+
"""`ruml:actions`"""
|
|
89
|
+
protocol: ProtocolCapabilityDeclaration | None = None
|
|
90
|
+
"""`ruml:protocol`"""
|
|
91
|
+
draft: Mapping[CapabilityId, DraftCapabilityDeclaration] = field(
|
|
92
|
+
default_factory=dict
|
|
93
|
+
)
|
|
94
|
+
"""Draft capabilities (`ruml:draft/...`), keyed by id"""
|
|
95
|
+
third_party: Mapping[CapabilityId, CapabilityDeclarationWithData] = field(
|
|
96
|
+
default_factory=dict
|
|
97
|
+
)
|
|
98
|
+
"""Third-party capabilities (`com.example/...`), keyed by id"""
|
|
99
|
+
extensions: Mapping[CapabilityId, ExtensionCapabilityDeclaration] = field(
|
|
100
|
+
default_factory=dict
|
|
101
|
+
)
|
|
102
|
+
"""Draft or third-party capabilities modeled by an extension, keyed by id; these
|
|
103
|
+
are in neither ``draft`` nor ``third_party``"""
|
|
104
|
+
declaration_order: Sequence[CapabilityId] = field(default_factory=list)
|
|
105
|
+
"""Every id declared, in the order the document declares the capabilities in.
|
|
106
|
+
|
|
107
|
+
The fields above cannot keep that order, which the spec makes significant (§4.2).
|
|
108
|
+
When left empty, it is derived from the fields (in field order, ``draft``,
|
|
109
|
+
``third_party`` and ``extensions`` keys last), so hand-built instances need not
|
|
110
|
+
spell it out.
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
def __post_init__(self) -> None:
|
|
114
|
+
if self.declaration_order:
|
|
115
|
+
return
|
|
116
|
+
official = {
|
|
117
|
+
model.OfficialCapabilityId.ruml_datapoints: self.datapoints,
|
|
118
|
+
model.OfficialCapabilityId.ruml_text_reference: self.text_reference,
|
|
119
|
+
model.OfficialCapabilityId.ruml_tree_reference: self.tree_reference,
|
|
120
|
+
model.OfficialCapabilityId.ruml_tree_include: self.tree_include,
|
|
121
|
+
model.OfficialCapabilityId.ruml_context: self.context,
|
|
122
|
+
model.OfficialCapabilityId.ruml_query: self.query,
|
|
123
|
+
model.OfficialCapabilityId.ruml_ai_query: self.ai_query,
|
|
124
|
+
model.OfficialCapabilityId.ruml_expression: self.expression,
|
|
125
|
+
model.OfficialCapabilityId.ruml_actions: self.actions,
|
|
126
|
+
model.OfficialCapabilityId.ruml_protocol: self.protocol,
|
|
127
|
+
}
|
|
128
|
+
derived = [
|
|
129
|
+
*(str(id) for id, value in official.items() if value is not None),
|
|
130
|
+
*self.draft,
|
|
131
|
+
*self.third_party,
|
|
132
|
+
*self.extensions,
|
|
133
|
+
]
|
|
134
|
+
object.__setattr__(self, "declaration_order", derived) # frozen
|
|
135
|
+
|
|
136
|
+
@property
|
|
137
|
+
def ids(self) -> frozenset[CapabilityId]:
|
|
138
|
+
"""Every declared capability id, official or not."""
|
|
139
|
+
return frozenset(self.declaration_order)
|
|
140
|
+
|
|
141
|
+
def extension[T: ExtensionCapabilityDeclaration](self, kind: type[T]) -> T | None:
|
|
142
|
+
"""Return the declaration of type ``kind`` in ``extensions``, or ``None``."""
|
|
143
|
+
return only(
|
|
144
|
+
(
|
|
145
|
+
declared
|
|
146
|
+
for declared in self.extensions.values()
|
|
147
|
+
if isinstance(declared, kind)
|
|
148
|
+
),
|
|
149
|
+
default=None,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def get_by_id(self, capability_id: CapabilityId) -> AbstractCapabilityDeclaration:
|
|
153
|
+
"""Return the declaration of the capability with the given id.
|
|
154
|
+
|
|
155
|
+
Its ``role`` is the one the capability plays (§4.1).
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
KeyError: `capability_id` is not declared.
|
|
159
|
+
"""
|
|
160
|
+
match capability_id:
|
|
161
|
+
case model.OfficialCapabilityId.ruml_datapoints if self.datapoints:
|
|
162
|
+
return self.datapoints
|
|
163
|
+
case model.OfficialCapabilityId.ruml_text_reference if self.text_reference:
|
|
164
|
+
return self.text_reference
|
|
165
|
+
case model.OfficialCapabilityId.ruml_tree_reference if self.tree_reference:
|
|
166
|
+
return self.tree_reference
|
|
167
|
+
case model.OfficialCapabilityId.ruml_tree_include if self.tree_include:
|
|
168
|
+
return self.tree_include
|
|
169
|
+
case model.OfficialCapabilityId.ruml_context if self.context:
|
|
170
|
+
return self.context
|
|
171
|
+
case model.OfficialCapabilityId.ruml_query if self.query:
|
|
172
|
+
return self.query
|
|
173
|
+
case model.OfficialCapabilityId.ruml_ai_query if self.ai_query:
|
|
174
|
+
return self.ai_query
|
|
175
|
+
case model.OfficialCapabilityId.ruml_expression if self.expression:
|
|
176
|
+
return self.expression
|
|
177
|
+
case model.OfficialCapabilityId.ruml_actions if self.actions:
|
|
178
|
+
return self.actions
|
|
179
|
+
case model.OfficialCapabilityId.ruml_protocol if self.protocol:
|
|
180
|
+
return self.protocol
|
|
181
|
+
case _ if capability_id in self.extensions:
|
|
182
|
+
return self.extensions[capability_id]
|
|
183
|
+
case _ if capability_id in self.draft:
|
|
184
|
+
return self.draft[capability_id]
|
|
185
|
+
case _ if capability_id in self.third_party:
|
|
186
|
+
return self.third_party[capability_id]
|
|
187
|
+
case _:
|
|
188
|
+
raise KeyError(capability_id)
|
|
189
|
+
|
|
190
|
+
def get_by_role(self, role: CapabilityRole) -> list[AbstractCapabilityDeclaration]:
|
|
191
|
+
"""Return the declarations of every capability playing ``role`` (§4.1).
|
|
192
|
+
|
|
193
|
+
They come in declaration order, each once even if its id is declared twice.
|
|
194
|
+
"""
|
|
195
|
+
return [
|
|
196
|
+
declaration
|
|
197
|
+
for capability_id in dict.fromkeys(self.declaration_order)
|
|
198
|
+
if (declaration := self.get_by_id(capability_id)).role == role
|
|
199
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from ruml_parser.internal.ruml.capability.abstract_node_capability import (
|
|
6
|
+
AbstractNodeCapability,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
11
|
+
class ExtensionNodeCapability(AbstractNodeCapability):
|
|
12
|
+
"""Base class for node-level entries of a capability an extension models.
|
|
13
|
+
|
|
14
|
+
The extension is a ``ruml_parser.internal.extension.CapabilityExtension``.
|
|
15
|
+
Subclasses are dataclasses defined by the extension, frozen like this one, with the
|
|
16
|
+
capability's id as a class attribute.
|
|
17
|
+
"""
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
from more_itertools import only
|
|
7
|
+
|
|
8
|
+
from ruml_parser.internal.ruml.actions.actions_node_capability import (
|
|
9
|
+
ActionsNodeCapability,
|
|
10
|
+
)
|
|
11
|
+
from ruml_parser.internal.ruml.ai_query.ai_query_node_capability import (
|
|
12
|
+
AiQueryNodeCapability,
|
|
13
|
+
)
|
|
14
|
+
from ruml_parser.internal.ruml.aliases import CapabilityId
|
|
15
|
+
from ruml_parser.internal.ruml.capability.extension_node_capability import (
|
|
16
|
+
ExtensionNodeCapability,
|
|
17
|
+
)
|
|
18
|
+
from ruml_parser.internal.ruml.capability.other_node_capability import (
|
|
19
|
+
OtherNodeCapability,
|
|
20
|
+
)
|
|
21
|
+
from ruml_parser.internal.ruml.context.context_refs_node_capability import (
|
|
22
|
+
ContextRefsNodeCapability,
|
|
23
|
+
)
|
|
24
|
+
from ruml_parser.internal.ruml.expression.expression_node_capability import (
|
|
25
|
+
ExpressionNodeCapability,
|
|
26
|
+
)
|
|
27
|
+
from ruml_parser.internal.ruml.query.query_node_capability import QueryNodeCapability
|
|
28
|
+
from ruml_parser.internal.ruml.text_reference.text_refs_node_capability import (
|
|
29
|
+
TextRefsNodeCapability,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
type NodeCapability = (
|
|
33
|
+
QueryNodeCapability
|
|
34
|
+
| ActionsNodeCapability
|
|
35
|
+
| ContextRefsNodeCapability
|
|
36
|
+
| AiQueryNodeCapability
|
|
37
|
+
| TextRefsNodeCapability
|
|
38
|
+
| ExpressionNodeCapability
|
|
39
|
+
| ExtensionNodeCapability
|
|
40
|
+
| OtherNodeCapability
|
|
41
|
+
)
|
|
42
|
+
"""One node-level capability entry."""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
46
|
+
class NodeCapabilities:
|
|
47
|
+
"""Node-level capability values.
|
|
48
|
+
|
|
49
|
+
Replaces the generated `list[NodeCapabilityEntry]`: each entry is the typed model
|
|
50
|
+
of its capability — or an `OtherNodeCapability` for ids without a node-level model —
|
|
51
|
+
kept in declaration order, which the spec makes significant (§4.3): the decision
|
|
52
|
+
modes depend on it.
|
|
53
|
+
|
|
54
|
+
In a spec-compliant document, every capability here is also declared in the
|
|
55
|
+
root-level `CapabilityDeclarations` (see `RumlDocument`).
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
entries: Sequence[NodeCapability] = ()
|
|
59
|
+
"""The node's capability entries, in declaration order"""
|
|
60
|
+
|
|
61
|
+
def __post_init__(self) -> None:
|
|
62
|
+
object.__setattr__(self, "entries", tuple(self.entries)) # frozen
|
|
63
|
+
|
|
64
|
+
def all_of_type[EntryT: NodeCapability](self, clazz: type[EntryT]) -> list[EntryT]:
|
|
65
|
+
return [entry for entry in self.entries if isinstance(entry, clazz)]
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def ids(self) -> list[CapabilityId]:
|
|
69
|
+
"""Every id present, in declaration order; a duplicate appears repeatedly."""
|
|
70
|
+
return [entry.id for entry in self.entries]
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def actions(self) -> list[ActionsNodeCapability]:
|
|
74
|
+
"""`ruml:actions`, in declaration order; a reaction may repeat (CAP-06)"""
|
|
75
|
+
return self.all_of_type(ActionsNodeCapability)
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def expression(self) -> ExpressionNodeCapability | None:
|
|
79
|
+
"""`ruml:expression`"""
|
|
80
|
+
return self._sole(ExpressionNodeCapability)
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def context(self) -> ContextRefsNodeCapability | None:
|
|
84
|
+
"""`ruml:context`"""
|
|
85
|
+
return self._sole(ContextRefsNodeCapability)
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def text_reference(self) -> TextRefsNodeCapability | None:
|
|
89
|
+
"""`ruml:text-reference`"""
|
|
90
|
+
return self._sole(TextRefsNodeCapability)
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def extensions(self) -> Sequence[ExtensionNodeCapability]:
|
|
94
|
+
# TODO: Müssen wir nicht eigentlich gewährleisten, dass auch **Extension**-
|
|
95
|
+
# Capabilities in der **Rolle** zurückgegeben werden, in der sie gebraucht
|
|
96
|
+
# werden?
|
|
97
|
+
return self.all_of_type(ExtensionNodeCapability)
|
|
98
|
+
|
|
99
|
+
def _sole[EntryT: NodeCapability](self, kind: type[EntryT]) -> EntryT | None:
|
|
100
|
+
"""Return the entry of type ``kind``, or `None`.
|
|
101
|
+
|
|
102
|
+
For a `data` or `combiner` capability only: their ids do not repeat on a node
|
|
103
|
+
(CAP-06, OP-02).
|
|
104
|
+
"""
|
|
105
|
+
return only(
|
|
106
|
+
self.all_of_type(kind),
|
|
107
|
+
default=None,
|
|
108
|
+
# TODO: This can be an AssertionError once `to_internal` rejects repeated
|
|
109
|
+
# entries (CAP-06, OP-02) before anything reads them.
|
|
110
|
+
too_long=ValueError(
|
|
111
|
+
f"Expected at most one {kind.__name__} entry (CAP-06, OP-02)"
|
|
112
|
+
),
|
|
113
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from ruml_parser.internal.ruml.aliases import CapabilityId, CapabilityPayload
|
|
6
|
+
from ruml_parser.internal.ruml.capability.abstract_node_capability import (
|
|
7
|
+
AbstractNodeCapability,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
12
|
+
class OtherNodeCapability(AbstractNodeCapability):
|
|
13
|
+
"""A node-level capability entry the internal model has no dedicated type for.
|
|
14
|
+
|
|
15
|
+
Draft ids and third-party ids that no extension models, and ``ruml:datapoints``
|
|
16
|
+
(which has no node-level model), keep their free-form payload here.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
id: CapabilityId
|
|
20
|
+
payload: CapabilityPayload | None = None
|
|
21
|
+
"""The entry's payload; `None` for an entry that carries none"""
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from datetime import date, datetime
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ruml_parser.internal.ruml.aliases import ContextCategory, ContextType, Hash
|
|
9
|
+
from ruml_parser.model import ruml as model
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
13
|
+
class Context:
|
|
14
|
+
title: str
|
|
15
|
+
"""Title of the context entry"""
|
|
16
|
+
category: ContextCategory
|
|
17
|
+
"""Category of the context"""
|
|
18
|
+
type: ContextType = model.Type4.embedded
|
|
19
|
+
"""How the context content is carried"""
|
|
20
|
+
timestamp: datetime
|
|
21
|
+
"""Modification time of the context"""
|
|
22
|
+
subject: bool = False
|
|
23
|
+
"""Whether this context is the subject of the evaluation"""
|
|
24
|
+
metadata: Mapping[str, Any] = field(default_factory=dict)
|
|
25
|
+
"""Free-form metadata about the context"""
|
|
26
|
+
content: Mapping[str, Any] | None = None
|
|
27
|
+
"""Embedded context content"""
|
|
28
|
+
source: Mapping[str, Any] | None = None
|
|
29
|
+
"""Free-form description of the context source"""
|
|
30
|
+
url: str | None = None
|
|
31
|
+
"""URL of the context; required for type 'url'"""
|
|
32
|
+
container_path: str | None = None
|
|
33
|
+
"""Path to the context inside the RUML container (below `.context/`); required
|
|
34
|
+
for type 'container'"""
|
|
35
|
+
ref: str | None = None
|
|
36
|
+
"""Symbolic reference; required for type 'external'"""
|
|
37
|
+
hash: Hash | None = None
|
|
38
|
+
"""Integrity hash"""
|
|
39
|
+
access_date: date | None = None
|
|
40
|
+
"""Date the context url was last accessed"""
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from ruml_parser.internal.ruml.aliases import (
|
|
7
|
+
CapabilityRole,
|
|
8
|
+
ContextId,
|
|
9
|
+
OfficialCapabilityId,
|
|
10
|
+
)
|
|
11
|
+
from ruml_parser.internal.ruml.capability.abstract_capability_declaration import (
|
|
12
|
+
AbstractCapabilityDeclaration,
|
|
13
|
+
)
|
|
14
|
+
from ruml_parser.internal.ruml.context.context import Context
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
18
|
+
class ContextCapabilityDeclaration(AbstractCapabilityDeclaration):
|
|
19
|
+
id = str(OfficialCapabilityId.ruml_context)
|
|
20
|
+
role = CapabilityRole.data
|
|
21
|
+
|
|
22
|
+
required: bool = False
|
|
23
|
+
"""Whether this capability must be resolved to evaluate"""
|
|
24
|
+
data: Mapping[ContextId, Context] = field(default_factory=dict)
|
|
25
|
+
"""Context entries, keyed by context id"""
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
from ruml_parser.internal.ruml.aliases import ContextId, OfficialCapabilityId
|
|
7
|
+
from ruml_parser.internal.ruml.capability.abstract_node_capability import (
|
|
8
|
+
AbstractNodeCapability,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
13
|
+
class ContextRefsNodeCapability(AbstractNodeCapability):
|
|
14
|
+
id = str(OfficialCapabilityId.ruml_context)
|
|
15
|
+
|
|
16
|
+
refs: Sequence[ContextId]
|
|
17
|
+
"""Ids of root-level context entries referenced by the node; at least one"""
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Sequence
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ruml_parser.internal.ruml.aliases import DatapointType, ExternalSourceType, SetId
|
|
8
|
+
from ruml_parser.internal.ruml.datapoints.option import Option
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
12
|
+
class InputBinding:
|
|
13
|
+
"""The datapoint value is supplied by user input."""
|
|
14
|
+
|
|
15
|
+
hint: str | None = None
|
|
16
|
+
"""Hint shown to the user when entering the value"""
|
|
17
|
+
placeholder: str | None = None
|
|
18
|
+
"""Placeholder text for the input field"""
|
|
19
|
+
default_value: Any | None = None
|
|
20
|
+
"""Default value pre-filled for the input"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
24
|
+
class ExternalBinding:
|
|
25
|
+
"""The datapoint value is fetched from an external source."""
|
|
26
|
+
|
|
27
|
+
ref: str
|
|
28
|
+
"""Symbolic reference to the external source"""
|
|
29
|
+
description: str | None = None
|
|
30
|
+
"""Description of the external source"""
|
|
31
|
+
source_type: ExternalSourceType | None = None
|
|
32
|
+
"""Kind of external source the value is fetched from"""
|
|
33
|
+
fallback: InputBinding | None = None
|
|
34
|
+
"""Input binding used when the external source cannot be reached"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
38
|
+
class Validation:
|
|
39
|
+
"""Validation rules applied to a datapoint value.
|
|
40
|
+
|
|
41
|
+
Unlike elsewhere in this model, `None` means "not specified" for every field here,
|
|
42
|
+
`required` included: the schema declares no defaults for them.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
required: bool | None = None
|
|
46
|
+
"""Whether a value must be provided"""
|
|
47
|
+
min: float | str | None = None
|
|
48
|
+
"""Minimum value (number, or ISO-8601 string for temporal types)"""
|
|
49
|
+
max: float | str | None = None
|
|
50
|
+
"""Maximum value (number, or ISO-8601 string for temporal types)"""
|
|
51
|
+
min_length: int | None = None
|
|
52
|
+
"""Minimum length of the value"""
|
|
53
|
+
max_length: int | None = None
|
|
54
|
+
"""Maximum length of the value"""
|
|
55
|
+
pattern: str | None = None
|
|
56
|
+
"""Regular expression the value must match"""
|
|
57
|
+
enum: Sequence[Any] | None = None
|
|
58
|
+
"""Explicit set of allowed values"""
|
|
59
|
+
message: str | None = None
|
|
60
|
+
"""Custom validation error message"""
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
64
|
+
class Cardinality:
|
|
65
|
+
"""How often an object datapoint repeats (§4.7.4).
|
|
66
|
+
|
|
67
|
+
A datapoint without a cardinality is a single object; a `max` above one makes its
|
|
68
|
+
value a list of objects. Like `Validation`, `None` means "not specified" here: the
|
|
69
|
+
schema declares no defaults for the bounds.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
min: int | None = None
|
|
73
|
+
"""Least number of objects; zero or more"""
|
|
74
|
+
max: int | None = None
|
|
75
|
+
"""Greatest number of objects; one or more"""
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
79
|
+
class Datapoint:
|
|
80
|
+
name: str
|
|
81
|
+
"""Human-readable name of the datapoint"""
|
|
82
|
+
type: DatapointType
|
|
83
|
+
"""Data type of the datapoint"""
|
|
84
|
+
description: str | None = None
|
|
85
|
+
"""Description of what the datapoint represents"""
|
|
86
|
+
unit: str | None = None
|
|
87
|
+
"""Unit of the value; required for type 'currency'"""
|
|
88
|
+
sensitive: bool = False
|
|
89
|
+
"""Whether the datapoint holds sensitive/personal data"""
|
|
90
|
+
format: str | None = None
|
|
91
|
+
"""Format refining the type (e.g. taxId for identifier)"""
|
|
92
|
+
options: Sequence[Option] = field(default_factory=list)
|
|
93
|
+
"""Allowed options; required and non-empty for type 'enum'"""
|
|
94
|
+
binding: InputBinding | ExternalBinding
|
|
95
|
+
"""How the datapoint value is sourced"""
|
|
96
|
+
validation: Validation | None = None
|
|
97
|
+
"""Validation rules applied to the datapoint value"""
|
|
98
|
+
set: SetId | None = None
|
|
99
|
+
"""The set this datapoint instantiates; required when type is 'object' (§4.7.4)"""
|
|
100
|
+
cardinality: Cardinality | None = None
|
|
101
|
+
"""Repetition of the object; absent means a single object"""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
from ruml_parser.internal.ruml.aliases import DatapointId
|
|
7
|
+
from ruml_parser.internal.ruml.datapoints.datapoint import Datapoint
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
11
|
+
class DatapointSet:
|
|
12
|
+
"""A reusable structured type: a named group of datapoints (§4.7.4)."""
|
|
13
|
+
|
|
14
|
+
name: str
|
|
15
|
+
"""Display name of the set (at least one character)"""
|
|
16
|
+
description: str | None = None
|
|
17
|
+
"""What the set represents"""
|
|
18
|
+
fields: Mapping[DatapointId, Datapoint]
|
|
19
|
+
"""Member datapoints, keyed by datapoint id; a field may itself be of type 'object'
|
|
20
|
+
(nesting)"""
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from ruml_parser.internal.ruml.aliases import (
|
|
7
|
+
CapabilityRole,
|
|
8
|
+
DatapointId,
|
|
9
|
+
OfficialCapabilityId,
|
|
10
|
+
SetId,
|
|
11
|
+
)
|
|
12
|
+
from ruml_parser.internal.ruml.capability.abstract_capability_declaration import (
|
|
13
|
+
AbstractCapabilityDeclaration,
|
|
14
|
+
)
|
|
15
|
+
from ruml_parser.internal.ruml.datapoints.datapoint import Datapoint
|
|
16
|
+
from ruml_parser.internal.ruml.datapoints.datapoint_set import DatapointSet
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
20
|
+
class DatapointsCapabilityDeclaration(AbstractCapabilityDeclaration):
|
|
21
|
+
id = str(OfficialCapabilityId.ruml_datapoints)
|
|
22
|
+
role = CapabilityRole.data
|
|
23
|
+
|
|
24
|
+
required: bool = False
|
|
25
|
+
"""Whether this capability must be resolved to evaluate"""
|
|
26
|
+
data: Mapping[DatapointId, Datapoint] = field(default_factory=dict)
|
|
27
|
+
"""Datapoint definitions, keyed by datapoint id"""
|
|
28
|
+
sets: Mapping[SetId, DatapointSet] = field(default_factory=dict)
|
|
29
|
+
"""Reusable structured types, keyed by set id"""
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
7
|
+
class Option:
|
|
8
|
+
value: str
|
|
9
|
+
"""Value of the option"""
|
|
10
|
+
label: str | None = None
|
|
11
|
+
"""Human-readable label for the option"""
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ruml_parser.internal.ruml.aliases import CapabilityRole, OfficialCapabilityId
|
|
8
|
+
from ruml_parser.internal.ruml.capability.abstract_capability_declaration import (
|
|
9
|
+
AbstractCapabilityDeclaration,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
14
|
+
class ExpressionCapabilityDeclaration(AbstractCapabilityDeclaration):
|
|
15
|
+
"""Root-level declaration of `ruml:expression` (`PlainPayload`)."""
|
|
16
|
+
|
|
17
|
+
id = str(OfficialCapabilityId.ruml_expression)
|
|
18
|
+
role = CapabilityRole.combiner
|
|
19
|
+
|
|
20
|
+
required: bool = False
|
|
21
|
+
"""Whether this capability must be resolved to evaluate"""
|
|
22
|
+
config: Mapping[str, Any] | None = None
|
|
23
|
+
"""Capability-specific configuration"""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
from ruml_parser.internal.ruml.aliases import OfficialCapabilityId
|
|
6
|
+
from ruml_parser.internal.ruml.capability.abstract_node_capability import (
|
|
7
|
+
AbstractNodeCapability,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
12
|
+
class ExpressionNodeCapability(AbstractNodeCapability):
|
|
13
|
+
"""The combiner of a `DELEGATED` node (§3.6.2), which computes its status."""
|
|
14
|
+
|
|
15
|
+
id = str(OfficialCapabilityId.ruml_expression)
|
|
16
|
+
expression: str
|
|
17
|
+
"""JSONata expression computing the node's status from `$children` and the
|
|
18
|
+
datapoints"""
|
|
19
|
+
description: str
|
|
20
|
+
"""Human-readable statement of the rule the expression encodes"""
|