rdf-construct 0.3.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.
Files changed (110) hide show
  1. rdf_construct/__init__.py +12 -0
  2. rdf_construct/__main__.py +0 -0
  3. rdf_construct/cli.py +3429 -0
  4. rdf_construct/core/__init__.py +33 -0
  5. rdf_construct/core/config.py +116 -0
  6. rdf_construct/core/ordering.py +219 -0
  7. rdf_construct/core/predicate_order.py +212 -0
  8. rdf_construct/core/profile.py +157 -0
  9. rdf_construct/core/selector.py +64 -0
  10. rdf_construct/core/serialiser.py +232 -0
  11. rdf_construct/core/utils.py +89 -0
  12. rdf_construct/cq/__init__.py +77 -0
  13. rdf_construct/cq/expectations.py +365 -0
  14. rdf_construct/cq/formatters/__init__.py +45 -0
  15. rdf_construct/cq/formatters/json.py +104 -0
  16. rdf_construct/cq/formatters/junit.py +104 -0
  17. rdf_construct/cq/formatters/text.py +146 -0
  18. rdf_construct/cq/loader.py +300 -0
  19. rdf_construct/cq/runner.py +321 -0
  20. rdf_construct/diff/__init__.py +59 -0
  21. rdf_construct/diff/change_types.py +214 -0
  22. rdf_construct/diff/comparator.py +338 -0
  23. rdf_construct/diff/filters.py +133 -0
  24. rdf_construct/diff/formatters/__init__.py +71 -0
  25. rdf_construct/diff/formatters/json.py +192 -0
  26. rdf_construct/diff/formatters/markdown.py +210 -0
  27. rdf_construct/diff/formatters/text.py +195 -0
  28. rdf_construct/docs/__init__.py +60 -0
  29. rdf_construct/docs/config.py +238 -0
  30. rdf_construct/docs/extractors.py +603 -0
  31. rdf_construct/docs/generator.py +360 -0
  32. rdf_construct/docs/renderers/__init__.py +7 -0
  33. rdf_construct/docs/renderers/html.py +803 -0
  34. rdf_construct/docs/renderers/json.py +390 -0
  35. rdf_construct/docs/renderers/markdown.py +628 -0
  36. rdf_construct/docs/search.py +278 -0
  37. rdf_construct/docs/templates/html/base.html.jinja +44 -0
  38. rdf_construct/docs/templates/html/class.html.jinja +152 -0
  39. rdf_construct/docs/templates/html/hierarchy.html.jinja +28 -0
  40. rdf_construct/docs/templates/html/index.html.jinja +110 -0
  41. rdf_construct/docs/templates/html/instance.html.jinja +90 -0
  42. rdf_construct/docs/templates/html/namespaces.html.jinja +37 -0
  43. rdf_construct/docs/templates/html/property.html.jinja +124 -0
  44. rdf_construct/docs/templates/html/single_page.html.jinja +169 -0
  45. rdf_construct/lint/__init__.py +75 -0
  46. rdf_construct/lint/config.py +214 -0
  47. rdf_construct/lint/engine.py +396 -0
  48. rdf_construct/lint/formatters.py +327 -0
  49. rdf_construct/lint/rules.py +692 -0
  50. rdf_construct/localise/__init__.py +114 -0
  51. rdf_construct/localise/config.py +508 -0
  52. rdf_construct/localise/extractor.py +427 -0
  53. rdf_construct/localise/formatters/__init__.py +36 -0
  54. rdf_construct/localise/formatters/markdown.py +229 -0
  55. rdf_construct/localise/formatters/text.py +224 -0
  56. rdf_construct/localise/merger.py +346 -0
  57. rdf_construct/localise/reporter.py +356 -0
  58. rdf_construct/main.py +6 -0
  59. rdf_construct/merge/__init__.py +165 -0
  60. rdf_construct/merge/config.py +354 -0
  61. rdf_construct/merge/conflicts.py +281 -0
  62. rdf_construct/merge/formatters.py +426 -0
  63. rdf_construct/merge/merger.py +425 -0
  64. rdf_construct/merge/migrator.py +339 -0
  65. rdf_construct/merge/rules.py +377 -0
  66. rdf_construct/merge/splitter.py +1102 -0
  67. rdf_construct/puml2rdf/__init__.py +103 -0
  68. rdf_construct/puml2rdf/config.py +230 -0
  69. rdf_construct/puml2rdf/converter.py +420 -0
  70. rdf_construct/puml2rdf/merger.py +200 -0
  71. rdf_construct/puml2rdf/model.py +202 -0
  72. rdf_construct/puml2rdf/parser.py +565 -0
  73. rdf_construct/puml2rdf/validators.py +451 -0
  74. rdf_construct/refactor/__init__.py +72 -0
  75. rdf_construct/refactor/config.py +362 -0
  76. rdf_construct/refactor/deprecator.py +328 -0
  77. rdf_construct/refactor/formatters/__init__.py +8 -0
  78. rdf_construct/refactor/formatters/text.py +311 -0
  79. rdf_construct/refactor/renamer.py +294 -0
  80. rdf_construct/shacl/__init__.py +56 -0
  81. rdf_construct/shacl/config.py +166 -0
  82. rdf_construct/shacl/converters.py +520 -0
  83. rdf_construct/shacl/generator.py +364 -0
  84. rdf_construct/shacl/namespaces.py +93 -0
  85. rdf_construct/stats/__init__.py +29 -0
  86. rdf_construct/stats/collector.py +178 -0
  87. rdf_construct/stats/comparator.py +298 -0
  88. rdf_construct/stats/formatters/__init__.py +83 -0
  89. rdf_construct/stats/formatters/json.py +38 -0
  90. rdf_construct/stats/formatters/markdown.py +153 -0
  91. rdf_construct/stats/formatters/text.py +186 -0
  92. rdf_construct/stats/metrics/__init__.py +26 -0
  93. rdf_construct/stats/metrics/basic.py +147 -0
  94. rdf_construct/stats/metrics/complexity.py +137 -0
  95. rdf_construct/stats/metrics/connectivity.py +130 -0
  96. rdf_construct/stats/metrics/documentation.py +128 -0
  97. rdf_construct/stats/metrics/hierarchy.py +207 -0
  98. rdf_construct/stats/metrics/properties.py +88 -0
  99. rdf_construct/uml/__init__.py +22 -0
  100. rdf_construct/uml/context.py +194 -0
  101. rdf_construct/uml/mapper.py +371 -0
  102. rdf_construct/uml/odm_renderer.py +789 -0
  103. rdf_construct/uml/renderer.py +684 -0
  104. rdf_construct/uml/uml_layout.py +393 -0
  105. rdf_construct/uml/uml_style.py +613 -0
  106. rdf_construct-0.3.0.dist-info/METADATA +496 -0
  107. rdf_construct-0.3.0.dist-info/RECORD +110 -0
  108. rdf_construct-0.3.0.dist-info/WHEEL +4 -0
  109. rdf_construct-0.3.0.dist-info/entry_points.txt +3 -0
  110. rdf_construct-0.3.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,238 @@
1
+ """Configuration loading and defaults for documentation generation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ import yaml
10
+
11
+
12
+ @dataclass
13
+ class DocsConfig:
14
+ """Configuration for documentation generation.
15
+
16
+ Attributes:
17
+ output_dir: Directory to write generated documentation.
18
+ format: Output format (html, markdown, json).
19
+ title: Override title for the documentation.
20
+ description: Override description for the documentation.
21
+ template_dir: Custom template directory (overrides defaults).
22
+ single_page: Generate single-page documentation.
23
+ include_instances: Whether to include instances in output.
24
+ include_imports: List of namespaces to treat as "internal".
25
+ exclude_namespaces: List of namespaces to exclude from output.
26
+ language: Preferred language for labels/definitions.
27
+ base_url: Base URL for generated links (for deployment).
28
+ logo_path: Path to logo image to include.
29
+ css_path: Path to custom CSS to include.
30
+ include_search: Generate search index for HTML output.
31
+ include_hierarchy: Generate hierarchy visualisation.
32
+ include_statistics: Include ontology statistics.
33
+ """
34
+
35
+ output_dir: Path = field(default_factory=lambda: Path("docs"))
36
+ format: str = "html"
37
+ title: str | None = None
38
+ description: str | None = None
39
+ template_dir: Path | None = None
40
+ single_page: bool = False
41
+ include_instances: bool = True
42
+ include_imports: list[str] = field(default_factory=list)
43
+ exclude_namespaces: list[str] = field(default_factory=list)
44
+ language: str = "en"
45
+ base_url: str = ""
46
+ logo_path: Path | None = None
47
+ css_path: Path | None = None
48
+ include_search: bool = True
49
+ include_hierarchy: bool = True
50
+ include_statistics: bool = True
51
+
52
+ # Entity type filtering
53
+ include_classes: bool = True
54
+ include_object_properties: bool = True
55
+ include_datatype_properties: bool = True
56
+ include_annotation_properties: bool = True
57
+
58
+ @classmethod
59
+ def from_dict(cls, data: dict[str, Any]) -> DocsConfig:
60
+ """Create configuration from a dictionary.
61
+
62
+ Args:
63
+ data: Configuration dictionary.
64
+
65
+ Returns:
66
+ DocsConfig instance.
67
+ """
68
+ config = cls()
69
+
70
+ if "output_dir" in data:
71
+ config.output_dir = Path(data["output_dir"])
72
+ if "format" in data:
73
+ config.format = data["format"]
74
+ if "title" in data:
75
+ config.title = data["title"]
76
+ if "description" in data:
77
+ config.description = data["description"]
78
+ if "template_dir" in data:
79
+ config.template_dir = Path(data["template_dir"])
80
+ if "single_page" in data:
81
+ config.single_page = data["single_page"]
82
+ if "include_instances" in data:
83
+ config.include_instances = data["include_instances"]
84
+ if "include_imports" in data:
85
+ config.include_imports = data["include_imports"]
86
+ if "exclude_namespaces" in data:
87
+ config.exclude_namespaces = data["exclude_namespaces"]
88
+ if "language" in data:
89
+ config.language = data["language"]
90
+ if "base_url" in data:
91
+ config.base_url = data["base_url"].rstrip("/")
92
+ if "logo_path" in data:
93
+ config.logo_path = Path(data["logo_path"])
94
+ if "css_path" in data:
95
+ config.css_path = Path(data["css_path"])
96
+ if "include_search" in data:
97
+ config.include_search = data["include_search"]
98
+ if "include_hierarchy" in data:
99
+ config.include_hierarchy = data["include_hierarchy"]
100
+ if "include_statistics" in data:
101
+ config.include_statistics = data["include_statistics"]
102
+
103
+ # Entity filtering
104
+ if "include_classes" in data:
105
+ config.include_classes = data["include_classes"]
106
+ if "include_object_properties" in data:
107
+ config.include_object_properties = data["include_object_properties"]
108
+ if "include_datatype_properties" in data:
109
+ config.include_datatype_properties = data["include_datatype_properties"]
110
+ if "include_annotation_properties" in data:
111
+ config.include_annotation_properties = data["include_annotation_properties"]
112
+
113
+ return config
114
+
115
+ @classmethod
116
+ def from_file(cls, path: Path) -> DocsConfig:
117
+ """Load configuration from a YAML file.
118
+
119
+ Args:
120
+ path: Path to YAML configuration file.
121
+
122
+ Returns:
123
+ DocsConfig instance.
124
+
125
+ Raises:
126
+ FileNotFoundError: If the configuration file doesn't exist.
127
+ ValueError: If the configuration file is invalid.
128
+ """
129
+ if not path.exists():
130
+ raise FileNotFoundError(f"Configuration file not found: {path}")
131
+
132
+ with open(path) as f:
133
+ data = yaml.safe_load(f)
134
+
135
+ if not isinstance(data, dict):
136
+ raise ValueError(f"Invalid configuration file: {path}")
137
+
138
+ return cls.from_dict(data)
139
+
140
+
141
+ def load_docs_config(path: Path | None = None) -> DocsConfig:
142
+ """Load documentation configuration.
143
+
144
+ If no path is provided, returns default configuration.
145
+
146
+ Args:
147
+ path: Optional path to configuration file.
148
+
149
+ Returns:
150
+ DocsConfig instance.
151
+ """
152
+ if path is None:
153
+ return DocsConfig()
154
+ return DocsConfig.from_file(path)
155
+
156
+
157
+ # Utility functions for path generation
158
+
159
+ def entity_to_filename(qname: str) -> str:
160
+ """Convert an entity QName to a safe filename.
161
+
162
+ Args:
163
+ qname: Qualified name like 'ex:Building'.
164
+
165
+ Returns:
166
+ Filesystem-safe filename like 'Building'.
167
+ """
168
+ # Strip prefix if present
169
+ if ":" in qname:
170
+ local_name = qname.split(":", 1)[1]
171
+ else:
172
+ local_name = qname
173
+
174
+ # Replace any remaining problematic characters
175
+ safe_name = local_name.replace("/", "_").replace("\\", "_").replace("#", "_")
176
+ return safe_name
177
+
178
+
179
+ def entity_to_path(
180
+ qname: str,
181
+ entity_type: str,
182
+ config: DocsConfig,
183
+ extension: str | None = None,
184
+ ) -> Path:
185
+ """Generate the output path for an entity's documentation page.
186
+
187
+ Args:
188
+ qname: Entity qualified name.
189
+ entity_type: Type of entity (class, object_property, datatype_property, instance).
190
+ config: Documentation configuration.
191
+ extension: File extension (defaults based on format).
192
+
193
+ Returns:
194
+ Relative path for the entity's documentation file.
195
+ """
196
+ if extension is None:
197
+ extension = {
198
+ "html": ".html",
199
+ "markdown": ".md",
200
+ "json": ".json",
201
+ }.get(config.format, ".html")
202
+
203
+ filename = entity_to_filename(qname) + extension
204
+
205
+ # Organise by entity type
206
+ type_dirs = {
207
+ "class": "classes",
208
+ "object_property": "properties/object",
209
+ "datatype_property": "properties/datatype",
210
+ "annotation_property": "properties/annotation",
211
+ "instance": "instances",
212
+ }
213
+
214
+ subdir = type_dirs.get(entity_type, "other")
215
+ return Path(subdir) / filename
216
+
217
+
218
+ def entity_to_url(
219
+ qname: str,
220
+ entity_type: str,
221
+ config: DocsConfig,
222
+ ) -> str:
223
+ """Generate the URL for an entity's documentation page.
224
+
225
+ Args:
226
+ qname: Entity qualified name.
227
+ entity_type: Type of entity.
228
+ config: Documentation configuration.
229
+
230
+ Returns:
231
+ URL path for linking to the entity.
232
+ """
233
+ path = entity_to_path(qname, entity_type, config)
234
+ url = str(path).replace("\\", "/") # Ensure forward slashes
235
+
236
+ if config.base_url:
237
+ return f"{config.base_url}/{url}"
238
+ return url