rdf-construct 0.4.1__tar.gz → 0.4.2__tar.gz

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 (123) hide show
  1. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/PKG-INFO +1 -1
  2. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/pyproject.toml +1 -1
  3. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/__init__.py +1 -1
  4. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/__init__.py +3 -2
  5. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/serialiser.py +68 -10
  6. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/LICENSE +0 -0
  7. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/README.md +0 -0
  8. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/__main__.py +0 -0
  9. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cli.py +0 -0
  10. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/config.py +0 -0
  11. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/ordering.py +0 -0
  12. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/predicate_order.py +0 -0
  13. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/profile.py +0 -0
  14. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/selector.py +0 -0
  15. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/core/utils.py +0 -0
  16. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/__init__.py +0 -0
  17. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/expectations.py +0 -0
  18. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/formatters/__init__.py +0 -0
  19. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/formatters/json.py +0 -0
  20. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/formatters/junit.py +0 -0
  21. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/formatters/text.py +0 -0
  22. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/loader.py +0 -0
  23. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/cq/runner.py +0 -0
  24. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/__init__.py +0 -0
  25. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/analyzer.py +0 -0
  26. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/documentation.py +0 -0
  27. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/formatters/__init__.py +0 -0
  28. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/formatters/json.py +0 -0
  29. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/formatters/markdown.py +0 -0
  30. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/formatters/text.py +0 -0
  31. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/hierarchy.py +0 -0
  32. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/imports.py +0 -0
  33. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/metadata.py +0 -0
  34. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/metrics.py +0 -0
  35. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/models.py +0 -0
  36. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/namespaces.py +0 -0
  37. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/describe/profiles.py +0 -0
  38. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/__init__.py +0 -0
  39. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/change_types.py +0 -0
  40. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/comparator.py +0 -0
  41. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/filters.py +0 -0
  42. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/formatters/__init__.py +0 -0
  43. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/formatters/json.py +0 -0
  44. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/formatters/markdown.py +0 -0
  45. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/diff/formatters/text.py +0 -0
  46. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/__init__.py +0 -0
  47. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/config.py +0 -0
  48. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/extractors.py +0 -0
  49. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/generator.py +0 -0
  50. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/renderers/__init__.py +0 -0
  51. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/renderers/html.py +0 -0
  52. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/renderers/json.py +0 -0
  53. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/renderers/markdown.py +0 -0
  54. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/search.py +0 -0
  55. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/base.html.jinja +0 -0
  56. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/class.html.jinja +0 -0
  57. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/hierarchy.html.jinja +0 -0
  58. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/index.html.jinja +0 -0
  59. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/instance.html.jinja +0 -0
  60. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/namespaces.html.jinja +0 -0
  61. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/property.html.jinja +0 -0
  62. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/docs/templates/html/single_page.html.jinja +0 -0
  63. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/lint/__init__.py +0 -0
  64. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/lint/config.py +0 -0
  65. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/lint/engine.py +0 -0
  66. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/lint/formatters.py +0 -0
  67. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/lint/rules.py +0 -0
  68. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/__init__.py +0 -0
  69. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/config.py +0 -0
  70. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/extractor.py +0 -0
  71. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/formatters/__init__.py +0 -0
  72. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/formatters/markdown.py +0 -0
  73. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/formatters/text.py +0 -0
  74. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/merger.py +0 -0
  75. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/localise/reporter.py +0 -0
  76. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/main.py +0 -0
  77. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/__init__.py +0 -0
  78. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/config.py +0 -0
  79. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/conflicts.py +0 -0
  80. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/formatters.py +0 -0
  81. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/merger.py +0 -0
  82. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/migrator.py +0 -0
  83. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/rules.py +0 -0
  84. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/merge/splitter.py +0 -0
  85. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/__init__.py +0 -0
  86. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/config.py +0 -0
  87. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/converter.py +0 -0
  88. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/merger.py +0 -0
  89. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/model.py +0 -0
  90. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/parser.py +0 -0
  91. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/puml2rdf/validators.py +0 -0
  92. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/__init__.py +0 -0
  93. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/config.py +0 -0
  94. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/deprecator.py +0 -0
  95. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/formatters/__init__.py +0 -0
  96. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/formatters/text.py +0 -0
  97. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/refactor/renamer.py +0 -0
  98. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/shacl/__init__.py +0 -0
  99. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/shacl/config.py +0 -0
  100. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/shacl/converters.py +0 -0
  101. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/shacl/generator.py +0 -0
  102. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/shacl/namespaces.py +0 -0
  103. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/__init__.py +0 -0
  104. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/collector.py +0 -0
  105. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/comparator.py +0 -0
  106. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/formatters/__init__.py +0 -0
  107. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/formatters/json.py +0 -0
  108. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/formatters/markdown.py +0 -0
  109. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/formatters/text.py +0 -0
  110. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/__init__.py +0 -0
  111. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/basic.py +0 -0
  112. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/complexity.py +0 -0
  113. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/connectivity.py +0 -0
  114. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/documentation.py +0 -0
  115. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/hierarchy.py +0 -0
  116. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/stats/metrics/properties.py +0 -0
  117. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/__init__.py +0 -0
  118. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/context.py +0 -0
  119. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/mapper.py +0 -0
  120. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/odm_renderer.py +0 -0
  121. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/renderer.py +0 -0
  122. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/uml_layout.py +0 -0
  123. {rdf_construct-0.4.1 → rdf_construct-0.4.2}/src/rdf_construct/uml/uml_style.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rdf-construct
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: Semantic RDF manipulation toolkit - order, serialize, and diff RDF ontologies
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [project]
6
6
  name = "rdf-construct"
7
- version = "0.4.1"
7
+ version = "0.4.2"
8
8
  description = "Semantic RDF manipulation toolkit - order, serialize, and diff RDF ontologies"
9
9
  license = "MIT"
10
10
  readme = "README.md"
@@ -4,7 +4,7 @@ Named after the ROM construct from William Gibson's Neuromancer -
4
4
  preserved, structured knowledge that can be queried and transformed.
5
5
  """
6
6
 
7
- __version__ = "0.4.1"
7
+ __version__ = "0.4.2"
8
8
 
9
9
  from . import core, uml
10
10
  from .cli import cli
@@ -3,7 +3,7 @@
3
3
  from .ordering import sort_subjects, topo_sort_subset, sort_with_roots
4
4
  from .profile import OrderingConfig, OrderingProfile, load_yaml
5
5
  from .selector import select_subjects
6
- from .serialiser import serialise_turtle, build_section_graph
6
+ from .serialiser import collect_used_namespaces, serialise_turtle, build_section_graph
7
7
  from .utils import (
8
8
  expand_curie,
9
9
  extract_prefix_map,
@@ -23,6 +23,7 @@ __all__ = [
23
23
  # Selector
24
24
  "select_subjects",
25
25
  # Serialiser
26
+ "collect_used_namespaces",
26
27
  "serialise_turtle",
27
28
  "build_section_graph",
28
29
  # Utils
@@ -30,4 +31,4 @@ __all__ = [
30
31
  "extract_prefix_map",
31
32
  "qname_sort_key",
32
33
  "rebind_prefixes",
33
- ]
34
+ ]
@@ -26,6 +26,54 @@ except ImportError:
26
26
  )
27
27
 
28
28
 
29
+ def collect_used_namespaces(
30
+ graph: Graph,
31
+ namespace_source: Graph | None = None,
32
+ ) -> set[str]:
33
+ """Collect namespace URIs that are actually used in the graph's triples.
34
+
35
+ Scans all subjects, predicates, and objects (including Literal datatype
36
+ URIs) to find which registered namespace URIs are referenced. Uses
37
+ longest-match-first ordering to correctly handle overlapping namespaces
38
+ (e.g. ``dc:`` vs ``dcterms:``).
39
+
40
+ Args:
41
+ graph: RDF graph whose triples to scan.
42
+ namespace_source: Optional graph whose namespace registry to match
43
+ against. Defaults to *graph* itself. Use this when the graph
44
+ being scanned has a stripped namespace manager (e.g. built
45
+ with ``bind_namespaces="none"``).
46
+
47
+ Returns:
48
+ Set of namespace URI strings that appear in the graph's triples.
49
+ """
50
+ ns_graph = namespace_source if namespace_source is not None else graph
51
+
52
+ used_ns: set[str] = set()
53
+ # Sort namespaces longest-first so we match the most specific prefix
54
+ ns_uris = sorted(
55
+ [str(uri) for _, uri in ns_graph.namespace_manager.namespaces()],
56
+ key=len,
57
+ reverse=True,
58
+ )
59
+
60
+ def _match_uri(uri_str: str) -> None:
61
+ """Add the best-matching namespace for *uri_str* to used_ns."""
62
+ for ns_uri in ns_uris:
63
+ if uri_str.startswith(ns_uri):
64
+ used_ns.add(ns_uri)
65
+ return
66
+
67
+ for s, p, o in graph:
68
+ for term in (s, p, o):
69
+ if isinstance(term, URIRef):
70
+ _match_uri(str(term))
71
+ elif isinstance(term, Literal) and term.datatype is not None:
72
+ _match_uri(str(term.datatype))
73
+
74
+ return used_ns
75
+
76
+
29
77
  def format_term(graph: Graph, term, use_prefixes: bool = True) -> str:
30
78
  """Format an RDF term as a Turtle string.
31
79
 
@@ -79,8 +127,11 @@ def serialise_turtle(
79
127
  This custom serialiser respects the exact order of subjects provided,
80
128
  unlike rdflib's built-in serialisers which always sort alphabetically.
81
129
 
130
+ Only prefix declarations for namespaces actually used in the graph's
131
+ triples are emitted, filtering out rdflib's built-in defaults.
132
+
82
133
  Formatting features:
83
- - Prefixes sorted alphabetically at top
134
+ - Prefixes sorted alphabetically at top (used namespaces only)
84
135
  - Subjects in specified order
85
136
  - rdf:type predicate listed first for each subject
86
137
  - Predicates ordered according to predicate_order config (or alphabetically)
@@ -95,10 +146,11 @@ def serialise_turtle(
95
146
  """
96
147
  lines = []
97
148
 
98
- # Write prefixes
149
+ # Write prefixes — only those actually used in the graph
150
+ used_ns = collect_used_namespaces(graph)
99
151
  prefixes = sorted(graph.namespace_manager.namespaces(), key=lambda x: x[0])
100
152
  for prefix, namespace in prefixes:
101
- if prefix: # Skip the default namespace
153
+ if prefix and str(namespace) in used_ns:
102
154
  lines.append(f"PREFIX {prefix}: <{namespace}>")
103
155
  lines.append("") # Blank line after prefixes
104
156
 
@@ -208,8 +260,9 @@ def build_section_graph(base: Graph, subjects_ordered: list) -> Graph:
208
260
  """Build a new graph containing only the specified subjects and their triples.
209
261
 
210
262
  Creates a filtered view of the base graph that includes all triples
211
- where the subject is in the provided list. Preserves all namespace
212
- bindings from the base graph.
263
+ where the subject is in the provided list. Only namespace bindings
264
+ that are actually used by the included triples are carried over;
265
+ rdflib's built-in well-known namespace defaults are suppressed.
213
266
 
214
267
  Args:
215
268
  base: Source RDF graph to filter
@@ -218,15 +271,20 @@ def build_section_graph(base: Graph, subjects_ordered: list) -> Graph:
218
271
  Returns:
219
272
  New graph containing only triples for the specified subjects
220
273
  """
221
- sg = Graph()
222
-
223
- # Copy namespace bindings
224
- for pfx, uri in base.namespace_manager.namespaces():
225
- sg.namespace_manager.bind(pfx, uri, override=True, replace=True)
274
+ # Suppress rdflib's automatic well-known namespace bindings so the
275
+ # sub-graph starts with a clean namespace manager.
276
+ sg = Graph(bind_namespaces="none")
226
277
 
227
278
  # Copy triples for each subject
228
279
  for s in subjects_ordered:
229
280
  for p, o in base.predicate_objects(s):
230
281
  sg.add((s, p, o))
231
282
 
283
+ # Match sub-graph triples against the *base* graph's namespace registry
284
+ # (the sub-graph's own registry is intentionally empty at this point).
285
+ used_ns = collect_used_namespaces(sg, namespace_source=base)
286
+ for pfx, uri in base.namespace_manager.namespaces():
287
+ if str(uri) in used_ns:
288
+ sg.namespace_manager.bind(pfx, uri, override=True, replace=True)
289
+
232
290
  return sg
File without changes
File without changes