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
ruml_parser/__init__.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Parsing of RUML documents into the internal ``RumlDocument``, and its model.
|
|
4
|
+
|
|
5
|
+
The entry points: ``RumlParser``, or ``ParsedRumlDocument`` for a Pydantic field.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ruml_parser.internal.extension import (
|
|
9
|
+
CapabilityExtension,
|
|
10
|
+
PayloadSchemas,
|
|
11
|
+
)
|
|
12
|
+
from ruml_parser.internal.mapping import to_internal
|
|
13
|
+
from ruml_parser.internal.ruml import (
|
|
14
|
+
AbstractCapabilityDeclaration,
|
|
15
|
+
AbstractNode,
|
|
16
|
+
AbstractNodeCapability,
|
|
17
|
+
Action,
|
|
18
|
+
ActionsCapabilityDeclaration,
|
|
19
|
+
ActionsNodeCapability,
|
|
20
|
+
AiQueryCapabilityDeclaration,
|
|
21
|
+
AiQueryDeclarationConfig,
|
|
22
|
+
AiQueryNodeCapability,
|
|
23
|
+
AiQueryNodeConfig,
|
|
24
|
+
Author,
|
|
25
|
+
BranchNode,
|
|
26
|
+
CapabilityDeclarations,
|
|
27
|
+
CapabilityDeclarationWithData,
|
|
28
|
+
CapabilityId,
|
|
29
|
+
CapabilityPayload,
|
|
30
|
+
CapabilityRole,
|
|
31
|
+
Cardinality,
|
|
32
|
+
Context,
|
|
33
|
+
ContextCapabilityDeclaration,
|
|
34
|
+
ContextCategory,
|
|
35
|
+
ContextId,
|
|
36
|
+
ContextInput,
|
|
37
|
+
ContextRefsNodeCapability,
|
|
38
|
+
ContextRole,
|
|
39
|
+
ContextType,
|
|
40
|
+
Datapoint,
|
|
41
|
+
DatapointId,
|
|
42
|
+
DatapointsCapabilityDeclaration,
|
|
43
|
+
DatapointSet,
|
|
44
|
+
DatapointType,
|
|
45
|
+
DecisionMode,
|
|
46
|
+
DerivationType,
|
|
47
|
+
DerivedFrom,
|
|
48
|
+
DocumentStatus,
|
|
49
|
+
DocumentType,
|
|
50
|
+
DraftCapabilityDeclaration,
|
|
51
|
+
Effort,
|
|
52
|
+
ExpressionCapabilityDeclaration,
|
|
53
|
+
ExpressionNodeCapability,
|
|
54
|
+
ExtensionCapabilityDeclaration,
|
|
55
|
+
ExtensionNodeCapability,
|
|
56
|
+
ExternalBinding,
|
|
57
|
+
ExternalSourceType,
|
|
58
|
+
Hash,
|
|
59
|
+
InputBinding,
|
|
60
|
+
LanguageCode,
|
|
61
|
+
LeafNode,
|
|
62
|
+
LegislativeStatus,
|
|
63
|
+
LexId,
|
|
64
|
+
Metadata,
|
|
65
|
+
Node,
|
|
66
|
+
NodeCapabilities,
|
|
67
|
+
NodeCapability,
|
|
68
|
+
OfficialCapabilityId,
|
|
69
|
+
Operator,
|
|
70
|
+
Option,
|
|
71
|
+
OtherNodeCapability,
|
|
72
|
+
ProtocolCapabilityDeclaration,
|
|
73
|
+
ProtocolConfig,
|
|
74
|
+
ProtocolLevel,
|
|
75
|
+
QueryCapabilityDeclaration,
|
|
76
|
+
QueryInputs,
|
|
77
|
+
QueryNodeCapability,
|
|
78
|
+
RumlDocument,
|
|
79
|
+
SetId,
|
|
80
|
+
Text,
|
|
81
|
+
TextAnchor,
|
|
82
|
+
TextAnchorType,
|
|
83
|
+
TextId,
|
|
84
|
+
TextReferenceCapabilityDeclaration,
|
|
85
|
+
TextRefsNodeCapability,
|
|
86
|
+
TextSource,
|
|
87
|
+
TextType,
|
|
88
|
+
Validation,
|
|
89
|
+
)
|
|
90
|
+
from ruml_parser.pydantic import ParsedRumlDocument
|
|
91
|
+
from ruml_parser.ruml_parser import RumlParser
|
|
92
|
+
from ruml_parser.schema_files import RESULT_SCHEMA_PATH, SCHEMA_PATH, schema_id
|
|
93
|
+
from ruml_parser.schema_validation import RumlValidationError
|
|
94
|
+
from ruml_parser.structural_error import RumlStructuralError, StructuralViolation
|
|
95
|
+
|
|
96
|
+
__all__ = [
|
|
97
|
+
"RESULT_SCHEMA_PATH",
|
|
98
|
+
"SCHEMA_PATH",
|
|
99
|
+
"AbstractCapabilityDeclaration",
|
|
100
|
+
"AbstractNode",
|
|
101
|
+
"AbstractNodeCapability",
|
|
102
|
+
"Action",
|
|
103
|
+
"ActionsCapabilityDeclaration",
|
|
104
|
+
"ActionsNodeCapability",
|
|
105
|
+
"AiQueryCapabilityDeclaration",
|
|
106
|
+
"AiQueryDeclarationConfig",
|
|
107
|
+
"AiQueryNodeCapability",
|
|
108
|
+
"AiQueryNodeConfig",
|
|
109
|
+
"Author",
|
|
110
|
+
"BranchNode",
|
|
111
|
+
"CapabilityDeclarationWithData",
|
|
112
|
+
"CapabilityDeclarations",
|
|
113
|
+
"CapabilityExtension",
|
|
114
|
+
"CapabilityId",
|
|
115
|
+
"CapabilityPayload",
|
|
116
|
+
"CapabilityRole",
|
|
117
|
+
"Cardinality",
|
|
118
|
+
"Context",
|
|
119
|
+
"ContextCapabilityDeclaration",
|
|
120
|
+
"ContextCategory",
|
|
121
|
+
"ContextId",
|
|
122
|
+
"ContextInput",
|
|
123
|
+
"ContextRefsNodeCapability",
|
|
124
|
+
"ContextRole",
|
|
125
|
+
"ContextType",
|
|
126
|
+
"Datapoint",
|
|
127
|
+
"DatapointId",
|
|
128
|
+
"DatapointSet",
|
|
129
|
+
"DatapointType",
|
|
130
|
+
"DatapointsCapabilityDeclaration",
|
|
131
|
+
"DecisionMode",
|
|
132
|
+
"DerivationType",
|
|
133
|
+
"DerivedFrom",
|
|
134
|
+
"DocumentStatus",
|
|
135
|
+
"DocumentType",
|
|
136
|
+
"Effort",
|
|
137
|
+
"DraftCapabilityDeclaration",
|
|
138
|
+
"ExpressionCapabilityDeclaration",
|
|
139
|
+
"ExpressionNodeCapability",
|
|
140
|
+
"ExtensionCapabilityDeclaration",
|
|
141
|
+
"ExtensionNodeCapability",
|
|
142
|
+
"ExternalBinding",
|
|
143
|
+
"ExternalSourceType",
|
|
144
|
+
"Hash",
|
|
145
|
+
"InputBinding",
|
|
146
|
+
"LanguageCode",
|
|
147
|
+
"LeafNode",
|
|
148
|
+
"LegislativeStatus",
|
|
149
|
+
"LexId",
|
|
150
|
+
"Metadata",
|
|
151
|
+
"Node",
|
|
152
|
+
"NodeCapabilities",
|
|
153
|
+
"NodeCapability",
|
|
154
|
+
"OfficialCapabilityId",
|
|
155
|
+
"Operator",
|
|
156
|
+
"Option",
|
|
157
|
+
"OtherNodeCapability",
|
|
158
|
+
"ParsedRumlDocument",
|
|
159
|
+
"PayloadSchemas",
|
|
160
|
+
"ProtocolCapabilityDeclaration",
|
|
161
|
+
"ProtocolConfig",
|
|
162
|
+
"ProtocolLevel",
|
|
163
|
+
"QueryCapabilityDeclaration",
|
|
164
|
+
"QueryInputs",
|
|
165
|
+
"QueryNodeCapability",
|
|
166
|
+
"RumlDocument",
|
|
167
|
+
"RumlParser",
|
|
168
|
+
"RumlStructuralError",
|
|
169
|
+
"RumlValidationError",
|
|
170
|
+
"SetId",
|
|
171
|
+
"StructuralViolation",
|
|
172
|
+
"Text",
|
|
173
|
+
"TextAnchor",
|
|
174
|
+
"TextAnchorType",
|
|
175
|
+
"TextId",
|
|
176
|
+
"TextReferenceCapabilityDeclaration",
|
|
177
|
+
"TextRefsNodeCapability",
|
|
178
|
+
"TextSource",
|
|
179
|
+
"TextType",
|
|
180
|
+
"Validation",
|
|
181
|
+
"schema_id",
|
|
182
|
+
"to_internal",
|
|
183
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Rulemapping Group GmbH
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Interfaces for extensions to the parser."""
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from collections.abc import Mapping
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ruml_parser.internal.ruml import (
|
|
11
|
+
CapabilityId,
|
|
12
|
+
CapabilityPayload,
|
|
13
|
+
ExtensionCapabilityDeclaration,
|
|
14
|
+
ExtensionNodeCapability,
|
|
15
|
+
RumlDocument,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True, slots=True, kw_only=True)
|
|
20
|
+
class PayloadSchemas:
|
|
21
|
+
"""The JSON Schemas of a capability's payloads, at the root and on a node."""
|
|
22
|
+
|
|
23
|
+
root: Mapping[str, Any]
|
|
24
|
+
"""JSON Schema document (draft 2020-12) of the root-level declaration's payload"""
|
|
25
|
+
node: Mapping[str, Any]
|
|
26
|
+
"""JSON Schema document (draft 2020-12) of a node-level entry's payload"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CapabilityExtension(ABC):
|
|
30
|
+
"""Draft/3rd-party capability extension for the parser.
|
|
31
|
+
|
|
32
|
+
Draft and third-party capability payloads are (almost by definition) "free-form" in
|
|
33
|
+
the official RUML schema, and would therefore normally be represented as generic
|
|
34
|
+
``DraftCapabilityDeclaration``/``CapabilityDeclarationWithData``/
|
|
35
|
+
``OtherNodeCapability`` instances in the internal model returned by the parser. For
|
|
36
|
+
a given capability, implementations of this interface facilitate the representation
|
|
37
|
+
as models specific to that capability instead.
|
|
38
|
+
|
|
39
|
+
Before that, ``ruml_parser.ruml_parser.RumlParser`` checks the payloads against the
|
|
40
|
+
extension's ``payload_schemas``.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def id(self) -> CapabilityId:
|
|
46
|
+
"""The id of the capability this extension models; never an official one."""
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def payload_schemas(self) -> PayloadSchemas:
|
|
51
|
+
"""The JSON Schemas of the capability's payloads."""
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def declaration(
|
|
55
|
+
self, payload: CapabilityPayload, *, required: bool
|
|
56
|
+
) -> ExtensionCapabilityDeclaration:
|
|
57
|
+
"""Turn a free-form capability root payload into this extension's specific one.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
payload: The declaration's payload; an absent one is passed as an empty one.
|
|
61
|
+
required: Whether the declaration marks the capability as required.
|
|
62
|
+
|
|
63
|
+
Raises:
|
|
64
|
+
ValueError: If the payload has the wrong shape. A Pydantic
|
|
65
|
+
``ValidationError`` (``ValueError`` subclass) is reported as such a
|
|
66
|
+
mismatch, naming the capability.
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def node(self, payload: CapabilityPayload) -> ExtensionNodeCapability:
|
|
71
|
+
"""Model one node-level entry of the capability.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
payload: The entry's payload; an absent one is passed as an empty one.
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
ValueError: If the payload has the wrong shape. A Pydantic
|
|
78
|
+
``ValidationError`` (which is one) is reported as such a mismatch,
|
|
79
|
+
naming the capability.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
def validate(self, document: RumlDocument) -> None:
|
|
83
|
+
"""Check the capability's cross-object rules on the document built with it.
|
|
84
|
+
|
|
85
|
+
``to_internal`` calls this after its own checks of the spec's rules, which a
|
|
86
|
+
capability's rules may rely on. Does nothing unless overridden.
|
|
87
|
+
|
|
88
|
+
Raises:
|
|
89
|
+
ValueError: If the document violates one of the rules, naming its error
|
|
90
|
+
code.
|
|
91
|
+
"""
|