iolanta 2.1.10__py3-none-any.whl → 2.1.12__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.
- iolanta/facets/facet.py +15 -9
- iolanta/facets/mermaid_roadmap/__init__.py +0 -0
- iolanta/facets/mermaid_roadmap/facet.py +133 -0
- iolanta/facets/mermaid_roadmap/inference/blocks.sparql +13 -0
- iolanta/facets/mermaid_roadmap/inference/has-task-default-type.sparql +16 -0
- iolanta/facets/mermaid_roadmap/inference/task.sparql +26 -0
- iolanta/facets/mermaid_roadmap/inference/unblocked.sparql +21 -0
- iolanta/facets/mermaid_roadmap/mermaid_roadmap.yamlld +59 -0
- iolanta/facets/mermaid_roadmap/sparql/edges.sparql +25 -0
- iolanta/facets/mermaid_roadmap/sparql/nodes.sparql +17 -0
- iolanta/iolanta.py +146 -55
- iolanta/mcp/cli.py +1 -17
- iolanta/mermaid/models.py +61 -36
- iolanta/parse_quads.py +18 -15
- iolanta/sparqlspace/processor.py +250 -255
- iolanta/sparqlspace/redirects.py +79 -0
- {iolanta-2.1.10.dist-info → iolanta-2.1.12.dist-info}/METADATA +2 -2
- {iolanta-2.1.10.dist-info → iolanta-2.1.12.dist-info}/RECORD +20 -12
- {iolanta-2.1.10.dist-info → iolanta-2.1.12.dist-info}/entry_points.txt +1 -0
- iolanta/mcp/prompts/nanopublication_assertion_authoring_rules.md +0 -63
- iolanta/mcp/prompts/rules.md +0 -83
- {iolanta-2.1.10.dist-info → iolanta-2.1.12.dist-info}/WHEEL +0 -0
iolanta/facets/facet.py
CHANGED
|
@@ -2,32 +2,38 @@ import inspect
|
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from functools import cached_property
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
from typing import Any, Generic,
|
|
5
|
+
from typing import Any, Generic, Optional, TypeVar, Union
|
|
6
6
|
|
|
7
|
-
from rdflib.term import
|
|
7
|
+
from rdflib.term import Literal, Node
|
|
8
8
|
|
|
9
|
-
from iolanta.models import NotLiteralNode
|
|
9
|
+
from iolanta.models import NotLiteralNode
|
|
10
10
|
from iolanta.query_result import QueryResult, SPARQLQueryArgument
|
|
11
11
|
|
|
12
|
-
FacetOutput = TypeVar(
|
|
12
|
+
FacetOutput = TypeVar("FacetOutput")
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@dataclass
|
|
16
|
-
class Facet(Generic[FacetOutput]):
|
|
16
|
+
class Facet(Generic[FacetOutput]): # noqa: WPS214
|
|
17
17
|
"""Base facet class."""
|
|
18
18
|
|
|
19
19
|
this: Node
|
|
20
|
-
iolanta:
|
|
20
|
+
iolanta: "iolanta.Iolanta" = field(repr=False)
|
|
21
21
|
as_datatype: Optional[NotLiteralNode] = None
|
|
22
22
|
|
|
23
23
|
def __post_init__(self):
|
|
24
|
-
if
|
|
25
|
-
|
|
24
|
+
if not isinstance(self.this, Node):
|
|
25
|
+
facet_name = self.__class__.__name__
|
|
26
|
+
this_type = type(self.this).__name__
|
|
27
|
+
raise ValueError(
|
|
28
|
+
f"Facet {facet_name} received a non-Node as this: {self.this} (type: {this_type})"
|
|
29
|
+
)
|
|
26
30
|
|
|
27
31
|
@property
|
|
28
32
|
def stored_queries_path(self) -> Path:
|
|
29
33
|
"""Construct directory for stored queries for this facet."""
|
|
30
|
-
return Path(inspect.getfile(self.__class__)).parent /
|
|
34
|
+
return Path(inspect.getfile(self.__class__)).parent / "sparql"
|
|
35
|
+
|
|
36
|
+
inference_path: Optional[Path] = None
|
|
31
37
|
|
|
32
38
|
def query(
|
|
33
39
|
self,
|
|
File without changes
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Iterable
|
|
3
|
+
|
|
4
|
+
from rdflib import BNode, Literal, Node, URIRef
|
|
5
|
+
|
|
6
|
+
from iolanta import Facet
|
|
7
|
+
from iolanta.mermaid.models import (
|
|
8
|
+
Diagram,
|
|
9
|
+
MermaidBlankNode,
|
|
10
|
+
MermaidEdge,
|
|
11
|
+
MermaidLiteral,
|
|
12
|
+
MermaidScalar,
|
|
13
|
+
MermaidSubgraph,
|
|
14
|
+
MermaidURINode,
|
|
15
|
+
)
|
|
16
|
+
from iolanta.namespaces import DATATYPES
|
|
17
|
+
from pydantic import AnyUrl
|
|
18
|
+
from rdflib import URIRef as RDFURIRef
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class TaskNode(MermaidScalar):
|
|
22
|
+
"""A Mermaid node with attached CSS classes."""
|
|
23
|
+
|
|
24
|
+
node: MermaidURINode | MermaidBlankNode | MermaidLiteral
|
|
25
|
+
classes: list[str] = []
|
|
26
|
+
|
|
27
|
+
def __str__(self) -> str:
|
|
28
|
+
"""Render the wrapped node."""
|
|
29
|
+
return str(self.node)
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def id(self) -> str:
|
|
33
|
+
"""Get the ID of the wrapped node."""
|
|
34
|
+
return self.node.id
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class BlocksEdge(MermaidEdge):
|
|
38
|
+
"""
|
|
39
|
+
{self.source.id} --> {self.target.id}
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, source, target):
|
|
43
|
+
# Initialize with empty title and a dummy predicate
|
|
44
|
+
super().__init__(
|
|
45
|
+
source=source,
|
|
46
|
+
target=target,
|
|
47
|
+
predicate=RDFURIRef('https://iolanta.tech/roadmap/blocks'),
|
|
48
|
+
title='',
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def __str__(self) -> str:
|
|
52
|
+
# Override to remove intermediate node - just direct arrow
|
|
53
|
+
return f'{self.source.id} --> {self.target.id}'
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Rebuild Pydantic models to resolve forward references
|
|
57
|
+
# Need to rebuild MermaidEdge first so MermaidSubgraph is available
|
|
58
|
+
MermaidEdge.model_rebuild()
|
|
59
|
+
BlocksEdge.model_rebuild()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class MermaidRoadmap(Facet[str]):
|
|
63
|
+
"""Mermaid roadmap diagram."""
|
|
64
|
+
|
|
65
|
+
META = Path(__file__).parent / 'mermaid_roadmap.yamlld'
|
|
66
|
+
|
|
67
|
+
inference_path = Path(__file__).parent / 'inference'
|
|
68
|
+
|
|
69
|
+
def show(self) -> str:
|
|
70
|
+
"""Render mermaid roadmap diagram."""
|
|
71
|
+
children = list(self.construct_mermaid_for_graph(self.this))
|
|
72
|
+
|
|
73
|
+
# Extract class assignments from TaskNode instances
|
|
74
|
+
tail_parts = ['classDef unblocked fill:#0a5,stroke:#063,stroke-width:2px,color:#fff;']
|
|
75
|
+
for child in children:
|
|
76
|
+
if isinstance(child, TaskNode) and child.classes:
|
|
77
|
+
for class_name in child.classes:
|
|
78
|
+
tail_parts.append(f'class {child.id} {class_name}')
|
|
79
|
+
|
|
80
|
+
tail = '\n'.join(tail_parts)
|
|
81
|
+
|
|
82
|
+
return str(Diagram(
|
|
83
|
+
children=children,
|
|
84
|
+
tail=tail,
|
|
85
|
+
))
|
|
86
|
+
|
|
87
|
+
def as_mermaid(self, node: Node):
|
|
88
|
+
"""Convert RDF node to Mermaid node."""
|
|
89
|
+
match node:
|
|
90
|
+
case URIRef() as uri:
|
|
91
|
+
return MermaidURINode(
|
|
92
|
+
uri=uri,
|
|
93
|
+
url=AnyUrl(uri),
|
|
94
|
+
title=self.render(uri, as_datatype=DATATYPES.title),
|
|
95
|
+
)
|
|
96
|
+
case Literal() as literal:
|
|
97
|
+
return MermaidLiteral(literal=literal)
|
|
98
|
+
case BNode() as bnode:
|
|
99
|
+
return MermaidBlankNode(
|
|
100
|
+
node=bnode,
|
|
101
|
+
title=self.render(bnode, as_datatype=DATATYPES.title),
|
|
102
|
+
)
|
|
103
|
+
case unknown:
|
|
104
|
+
unknown_type = type(unknown)
|
|
105
|
+
raise ValueError(f'Unknown node type: {unknown} ({unknown_type})')
|
|
106
|
+
|
|
107
|
+
def construct_mermaid_for_graph(self, graph: URIRef) -> Iterable[MermaidScalar]:
|
|
108
|
+
"""Render graph as mermaid."""
|
|
109
|
+
# Get nodes
|
|
110
|
+
node_rows = self.stored_query('nodes.sparql')
|
|
111
|
+
node_rows_list = list(node_rows)
|
|
112
|
+
|
|
113
|
+
nodes = [
|
|
114
|
+
TaskNode(
|
|
115
|
+
node=self.as_mermaid(row['node']),
|
|
116
|
+
classes=['unblocked'] if row.get('is_unblocked', False) else [],
|
|
117
|
+
)
|
|
118
|
+
for row in node_rows_list
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
# Get edges for roadmap:blocks relationships
|
|
122
|
+
edge_rows = self.stored_query('edges.sparql')
|
|
123
|
+
edge_rows_list = list(edge_rows)
|
|
124
|
+
|
|
125
|
+
edges = [
|
|
126
|
+
BlocksEdge(
|
|
127
|
+
source=self.as_mermaid(row['source']),
|
|
128
|
+
target=self.as_mermaid(row['target']),
|
|
129
|
+
)
|
|
130
|
+
for row in edge_rows_list
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
return [*nodes, *edges]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
PREFIX roadmap: <https://iolanta.tech/roadmap/>
|
|
2
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
3
|
+
|
|
4
|
+
CONSTRUCT {
|
|
5
|
+
?item a roadmap:Task .
|
|
6
|
+
}
|
|
7
|
+
WHERE {
|
|
8
|
+
# Find items that are values of roadmap:has-task property
|
|
9
|
+
?container roadmap:has-task ?item .
|
|
10
|
+
|
|
11
|
+
# Only infer if the item isn't already typed as a roadmap type
|
|
12
|
+
FILTER NOT EXISTS {
|
|
13
|
+
?item rdf:type ?type .
|
|
14
|
+
FILTER(?type IN (roadmap:Task, roadmap:Event, roadmap:Bug))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# It is imperative that this query executes after `blocks.sparql` because it relies upon proper `roadmap:blocks` relations.
|
|
2
|
+
|
|
3
|
+
PREFIX roadmap: <https://iolanta.tech/roadmap/>
|
|
4
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
5
|
+
|
|
6
|
+
CONSTRUCT {
|
|
7
|
+
?other a roadmap:Task .
|
|
8
|
+
}
|
|
9
|
+
WHERE {
|
|
10
|
+
# Match either Task or Event
|
|
11
|
+
{
|
|
12
|
+
?task rdf:type roadmap:Task .
|
|
13
|
+
} UNION {
|
|
14
|
+
?task rdf:type roadmap:Event .
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Find nodes connected via roadmap:blocks chain (in either direction)
|
|
18
|
+
# ^roadmap:blocks is the inverse (equivalent to roadmap:is-blocked-by)
|
|
19
|
+
?task (roadmap:blocks | ^roadmap:blocks)+ ?other .
|
|
20
|
+
|
|
21
|
+
# Only infer if the node isn't already a Task
|
|
22
|
+
# (to avoid redundant triples, but allow inference even if node has other types)
|
|
23
|
+
FILTER NOT EXISTS {
|
|
24
|
+
?other rdf:type roadmap:Task .
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
PREFIX roadmap: <https://iolanta.tech/roadmap/>
|
|
2
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
3
|
+
|
|
4
|
+
CONSTRUCT {
|
|
5
|
+
?task a roadmap:Unblocked .
|
|
6
|
+
}
|
|
7
|
+
WHERE {
|
|
8
|
+
# Match Task, Event, or Bug instances
|
|
9
|
+
{
|
|
10
|
+
?task a roadmap:Task .
|
|
11
|
+
} UNION {
|
|
12
|
+
?task a roadmap:Event .
|
|
13
|
+
} UNION {
|
|
14
|
+
?task a roadmap:Bug .
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Only infer if there are no incoming blocks links
|
|
18
|
+
FILTER NOT EXISTS {
|
|
19
|
+
?other roadmap:blocks ?task .
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"@context":
|
|
2
|
+
"@import": https://json-ld.org/contexts/dollar-convenience.jsonld
|
|
3
|
+
roadmap: https://roadmap.iolanta.tech/
|
|
4
|
+
iolanta: https://iolanta.tech/
|
|
5
|
+
rdfs: http://www.w3.org/2000/01/rdf-schema#
|
|
6
|
+
prov: http://www.w3.org/ns/prov#
|
|
7
|
+
owl: http://www.w3.org/2002/07/owl#
|
|
8
|
+
|
|
9
|
+
$: rdfs:label
|
|
10
|
+
|
|
11
|
+
rdfs:subClassOf:
|
|
12
|
+
"@type": "@id"
|
|
13
|
+
|
|
14
|
+
rdfs:subPropertyOf:
|
|
15
|
+
"@type": "@id"
|
|
16
|
+
|
|
17
|
+
owl:inverseOf:
|
|
18
|
+
"@type": "@id"
|
|
19
|
+
|
|
20
|
+
→:
|
|
21
|
+
"@type": "@id"
|
|
22
|
+
"@id": iolanta:outputs
|
|
23
|
+
|
|
24
|
+
↦:
|
|
25
|
+
"@id": iolanta:matches
|
|
26
|
+
"@type": iolanta:SPARQLText
|
|
27
|
+
|
|
28
|
+
$id: pkg:pypi/iolanta#mermaid-roadmap
|
|
29
|
+
$: Mermaid Roadmap
|
|
30
|
+
|
|
31
|
+
→:
|
|
32
|
+
$id: https://iolanta.tech/roadmap/datatypes/mermaid
|
|
33
|
+
$: Mermaid
|
|
34
|
+
$type: iolanta:OutputDatatype
|
|
35
|
+
rdfs:subClassOf: https://iolanta.tech/datatypes/mermaid
|
|
36
|
+
|
|
37
|
+
↦:
|
|
38
|
+
- ASK WHERE { GRAPH $this { ?s ?p ?o } }
|
|
39
|
+
|
|
40
|
+
$included:
|
|
41
|
+
- $id: roadmap:Task
|
|
42
|
+
rdfs:subClassOf: prov:Activity
|
|
43
|
+
$: Task
|
|
44
|
+
|
|
45
|
+
- $id: roadmap:Bug
|
|
46
|
+
rdfs:subClassOf: roadmap:Task
|
|
47
|
+
$: Bug
|
|
48
|
+
|
|
49
|
+
- $id: roadmap:Event
|
|
50
|
+
rdfs:subClassOf: prov:Activity
|
|
51
|
+
$: Event
|
|
52
|
+
|
|
53
|
+
- $id: roadmap:is-blocked-by
|
|
54
|
+
rdfs:subPropertyOf: prov:wasInformedBy
|
|
55
|
+
$: Is blocked by
|
|
56
|
+
|
|
57
|
+
- $id: roadmap:blocks
|
|
58
|
+
owl:inverseOf: roadmap:is-blocked-by
|
|
59
|
+
$: Blocks
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
PREFIX roadmap: <https://iolanta.tech/roadmap/>
|
|
2
|
+
|
|
3
|
+
SELECT DISTINCT ?source ?target WHERE {
|
|
4
|
+
# Find roadmap:blocks relationships across all graphs (including inferred)
|
|
5
|
+
?source roadmap:blocks ?target .
|
|
6
|
+
|
|
7
|
+
# Only include edges where both source and target are Task/Event/Bug nodes
|
|
8
|
+
# (they will be filtered by the nodes query, but this ensures we only show
|
|
9
|
+
# relevant edges)
|
|
10
|
+
{
|
|
11
|
+
?source a roadmap:Task .
|
|
12
|
+
} UNION {
|
|
13
|
+
?source a roadmap:Event .
|
|
14
|
+
} UNION {
|
|
15
|
+
?source a roadmap:Bug .
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
?target a roadmap:Task .
|
|
20
|
+
} UNION {
|
|
21
|
+
?target a roadmap:Event .
|
|
22
|
+
} UNION {
|
|
23
|
+
?target a roadmap:Bug .
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
PREFIX roadmap: <https://iolanta.tech/roadmap/>
|
|
2
|
+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
3
|
+
|
|
4
|
+
SELECT DISTINCT ?node ?is_unblocked WHERE {
|
|
5
|
+
# Search across all graphs (including inference graphs)
|
|
6
|
+
# This finds both original types and inferred types
|
|
7
|
+
{
|
|
8
|
+
?node rdf:type roadmap:Task .
|
|
9
|
+
} UNION {
|
|
10
|
+
?node rdf:type roadmap:Event .
|
|
11
|
+
} UNION {
|
|
12
|
+
?node rdf:type roadmap:Bug .
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
# Check if node is unblocked (has roadmap:Unblocked type)
|
|
16
|
+
BIND(EXISTS { ?node rdf:type roadmap:Unblocked } AS ?is_unblocked)
|
|
17
|
+
}
|