iolanta 1.2.11__py3-none-any.whl → 2.0.1__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.
@@ -7,7 +7,7 @@ from iolanta.cli.formatters.json import print_json
7
7
  from iolanta.cli.formatters.pretty import pretty_print
8
8
  from iolanta.models import QueryResultsFormat
9
9
  from iolanta.node_to_qname import node_to_qname
10
- from ldflex.ldflex import SelectResult
10
+ from iolanta.query_result import SelectResult
11
11
 
12
12
 
13
13
  # @cli_print.instance(SelectResult)
@@ -4,7 +4,7 @@ import sys
4
4
  from classes import typeclass
5
5
  from rdflib import Graph
6
6
 
7
- from ldflex.ldflex import QueryResult, SelectResult
7
+ from iolanta.query_result import QueryResult, SelectResult
8
8
 
9
9
 
10
10
  @typeclass
@@ -4,7 +4,7 @@ import sys
4
4
  from classes import typeclass
5
5
  from rdflib import Graph
6
6
 
7
- from ldflex.ldflex import QueryResult, SelectResult
7
+ from iolanta.query_result import QueryResult, SelectResult
8
8
 
9
9
 
10
10
  @typeclass
@@ -1,5 +1,4 @@
1
1
  import itertools
2
- from datetime import date
3
2
  from typing import Union
4
3
 
5
4
  from classes import typeclass
@@ -10,7 +9,7 @@ from rich.table import Table
10
9
 
11
10
  from iolanta.cli.pretty_print import render_literal_value
12
11
  from iolanta.models import ComputedQName
13
- from ldflex.ldflex import QueryResult, SelectResult
12
+ from iolanta.query_result import QueryResult, SelectResult
14
13
 
15
14
 
16
15
  @typeclass
iolanta/cli/main.py CHANGED
@@ -111,7 +111,7 @@ def render_command( # noqa: WPS231, WPS238, WPS210, C901
111
111
  )
112
112
 
113
113
  try:
114
- renderable, stack = iolanta.render(
114
+ renderable = iolanta.render(
115
115
  node=URIRef(node),
116
116
  as_datatype=URIRef(as_datatype),
117
117
  )
iolanta/facets/facet.py CHANGED
@@ -2,14 +2,12 @@ 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, Iterable, List, Optional, TypeVar, Union
5
+ from typing import Any, Generic, Iterable, Optional, TypeVar, Union
6
6
 
7
7
  from rdflib.term import BNode, Literal, Node, URIRef
8
8
 
9
9
  from iolanta.models import NotLiteralNode, Triple, TripleTemplate
10
- from iolanta.stack import Stack
11
- from ldflex import LDFlex
12
- from ldflex.ldflex import QueryResult, SPARQLQueryArgument
10
+ from iolanta.query_result import QueryResult, SPARQLQueryArgument
13
11
 
14
12
  FacetOutput = TypeVar('FacetOutput')
15
13
 
@@ -21,18 +19,12 @@ class Facet(Generic[FacetOutput]):
21
19
  iri: NotLiteralNode
22
20
  iolanta: 'iolanta.Iolanta' = field(repr=False)
23
21
  as_datatype: Optional[NotLiteralNode] = None
24
- stack_children: List[Stack] = field(default_factory=list, repr=False)
25
22
 
26
23
  @property
27
24
  def stored_queries_path(self) -> Path:
28
25
  """Construct directory for stored queries for this facet."""
29
26
  return Path(inspect.getfile(self.__class__)).parent / 'sparql'
30
27
 
31
- @property
32
- def ldflex(self) -> LDFlex:
33
- """Extract LDFLex instance."""
34
- return self.iolanta.ldflex
35
-
36
28
  @cached_property
37
29
  def uriref(self) -> NotLiteralNode:
38
30
  """Format as URIRef."""
@@ -47,7 +39,7 @@ class Facet(Generic[FacetOutput]):
47
39
  **kwargs: SPARQLQueryArgument,
48
40
  ) -> QueryResult:
49
41
  """SPARQL query."""
50
- return self.ldflex.query(
42
+ return self.iolanta.query(
51
43
  query_text=query_text,
52
44
  **kwargs,
53
45
  )
@@ -58,15 +50,11 @@ class Facet(Generic[FacetOutput]):
58
50
  as_datatype: NotLiteralNode,
59
51
  ) -> Any:
60
52
  """Shortcut to render something via iolanta."""
61
- rendered, stack = self.iolanta.render(
53
+ return self.iolanta.render(
62
54
  node=node,
63
55
  as_datatype=as_datatype,
64
56
  )
65
57
 
66
- self.stack_children.append(stack)
67
-
68
- return rendered
69
-
70
58
  def render_all(
71
59
  self,
72
60
  node: Node,
@@ -92,19 +80,6 @@ class Facet(Generic[FacetOutput]):
92
80
  """Preferred language for Iolanta output."""
93
81
  return self.iolanta.language
94
82
 
95
- @property
96
- def stack(self):
97
- """
98
- Return stack.
99
-
100
- FIXME: I have no idea. Maybe delete this nonsense.
101
- """
102
- return Stack(
103
- node=self.iri,
104
- facet=self,
105
- children=self.stack_children,
106
- )
107
-
108
83
  def find_triple(
109
84
  self,
110
85
  triple: TripleTemplate,
@@ -29,7 +29,7 @@ class PageTitle(IolantaWidgetMixin, Static):
29
29
  return self.iolanta.render(
30
30
  self.iri,
31
31
  as_datatype=DATATYPES.title,
32
- )[0]
32
+ )
33
33
 
34
34
  def on_mount(self):
35
35
  """Initialize rendering of a title."""
@@ -131,7 +131,7 @@ class PageSwitcher(IolantaWidgetMixin, ContentSwitcher): # noqa: WPS214
131
131
  self.iolanta.render,
132
132
  facet,
133
133
  as_datatype=DATATYPES.title,
134
- )[0],
134
+ ),
135
135
  )
136
136
  for facet in other_facets
137
137
  ]
@@ -103,7 +103,7 @@ class InstancesList(ListView): # noqa: WPS214
103
103
  self.app.iolanta.render(
104
104
  instance_item.node,
105
105
  as_datatype=DATATYPES.title,
106
- )[0],
106
+ ),
107
107
  )
108
108
 
109
109
  def stream_instance_items_chunk(
@@ -60,7 +60,7 @@ class PropertyName(Widget, can_focus=True, inherit_bindings=False):
60
60
 
61
61
  def render_title(self):
62
62
  """Render title in a separate thread."""
63
- return self.app.iolanta.render(self.iri, DATATYPES.title)[0]
63
+ return self.app.iolanta.render(self.iri, DATATYPES.title)
64
64
 
65
65
  def render(self) -> RenderResult:
66
66
  """Render node title."""
@@ -202,7 +202,7 @@ class PropertiesContainer(Vertical):
202
202
  widget.renderable = self.app.iolanta.render(
203
203
  widget.iri,
204
204
  as_datatype=DATATYPES.title,
205
- )[0]
205
+ )
206
206
 
207
207
  def on_mount(self):
208
208
  """Initiate rendering in the background."""
@@ -22,7 +22,7 @@ class GraphFacet(Facet[Widget]):
22
22
  triples_view = self.iolanta.render(
23
23
  self.iri,
24
24
  as_datatype=DATATYPES['textual-graph-triples'],
25
- )[0]
25
+ )
26
26
 
27
27
  return VerticalScroll(
28
28
  PageTitle(self.iri, extra=f'({triple_count} triples)'),
@@ -121,7 +121,7 @@ class TriplesView(IolantaWidgetMixin, Vertical):
121
121
  term_view.renderable = self.iolanta.render(
122
122
  term_view.uri,
123
123
  as_datatype=term_view.as_datatype,
124
- )[0]
124
+ )
125
125
 
126
126
 
127
127
  class GraphTriplesFacet(Facet[Widget]):
@@ -61,7 +61,7 @@ class NanopublicationScreen(IolantaWidgetMixin, VerticalScroll):
61
61
  yield self.iolanta.render(
62
62
  row['assertion'],
63
63
  as_datatype=DATATYPES['textual-graph-triples'],
64
- )[0]
64
+ )
65
65
 
66
66
  provenance = []
67
67
  if row.get('author'):
@@ -36,4 +36,4 @@ class TermList(IolantaWidgetMixin, Horizontal):
36
36
  child.renderable = self.iolanta.render(
37
37
  child.uri,
38
38
  as_datatype=child.as_datatype,
39
- )[0]
39
+ )
iolanta/iolanta.py CHANGED
@@ -18,8 +18,10 @@ from typing import ( # noqa: WPS235
18
18
  import funcy
19
19
  import loguru
20
20
  import yaml_ld
21
- from rdflib import ConjunctiveGraph, Literal, Namespace, URIRef
21
+ from pyparsing import ParseException
22
+ from rdflib import ConjunctiveGraph, Graph, Literal, Namespace, URIRef
22
23
  from rdflib.namespace import NamespaceManager
24
+ from rdflib.plugins.sparql.processor import SPARQLResult
23
25
  from rdflib.term import Node
24
26
  from yaml_ld.document_loaders.content_types import ParserNotFound
25
27
  from yaml_ld.errors import YAMLLDError
@@ -44,9 +46,13 @@ from iolanta.node_to_qname import node_to_qname
44
46
  from iolanta.parse_quads import parse_quads
45
47
  from iolanta.parsers.yaml import YAML
46
48
  from iolanta.plugin import Plugin
49
+ from iolanta.query_result import (
50
+ QueryResult,
51
+ SPARQLParseException,
52
+ SPARQLQueryArgument,
53
+ format_query_bindings,
54
+ )
47
55
  from iolanta.resolvers.python_import import PythonImportResolver
48
- from iolanta.stack import Stack
49
- from ldflex import LDFlex
50
56
 
51
57
 
52
58
  class LoggerProtocol(Protocol):
@@ -125,14 +131,56 @@ class Iolanta: # noqa: WPS214
125
131
  for plugin_class in self.plugin_classes
126
132
  ]
127
133
 
128
- @property
129
- def ldflex(self) -> LDFlex:
134
+ def query(
135
+ self,
136
+ query_text: str,
137
+ **kwargs: SPARQLQueryArgument,
138
+ ) -> QueryResult:
130
139
  """
131
- Create ldflex instance.
140
+ Run a SPARQL `SELECT`, `CONSTRUCT`, or `ASK` query.
132
141
 
133
- FIXME: Get rid of it.
142
+ Args:
143
+ query_text: The SPARQL text;
144
+ **kwargs: bind variables in the query to values if necessary. For
145
+ example:
146
+
147
+ ```python
148
+ iolanta.query(
149
+ 'SELECT ?title WHERE { ?page rdfs:label ?title }',
150
+ ?page=page_iri,
151
+ )
152
+ ```
153
+
154
+ Returns:
155
+ Results of the query:
156
+
157
+ - a graph for `CONSTRUCT`,
158
+ - a list of dicts for `SELECT`,
159
+ - or a boolean for `ASK`.
134
160
  """
135
- return LDFlex(self.graph)
161
+ try:
162
+ sparql_result: SPARQLResult = self.graph.query(
163
+ query_text,
164
+ processor='cyberspace',
165
+ initBindings=kwargs,
166
+ )
167
+ except ParseException as err:
168
+ raise SPARQLParseException(
169
+ error=err,
170
+ query=query_text,
171
+ ) from err
172
+
173
+ if sparql_result.askAnswer is not None:
174
+ return sparql_result.askAnswer
175
+
176
+ if sparql_result.graph is not None:
177
+ graph: Graph = sparql_result.graph
178
+ for prefix, namespace in self.graph.namespaces():
179
+ graph.bind(prefix, namespace)
180
+
181
+ return graph
182
+
183
+ return format_query_bindings(sparql_result.bindings)
136
184
 
137
185
  @functools.cached_property
138
186
  def namespaces_to_bind(self) -> Dict[str, Namespace]:
@@ -254,12 +302,6 @@ class Iolanta: # noqa: WPS214
254
302
  self.graph.bind(prefix='dcterms', namespace=namespaces.DCTERMS)
255
303
  self.graph.bind(prefix='rdfg', namespace=namespaces.RDFG)
256
304
 
257
- @property
258
- def query(self):
259
- """Make a SPARQL query."""
260
- self.maybe_infer()
261
- return self.ldflex.query
262
-
263
305
  @functools.cached_property
264
306
  def context_paths(self) -> Iterable[Path]:
265
307
  """
@@ -318,7 +360,7 @@ class Iolanta: # noqa: WPS214
318
360
  self,
319
361
  node: Node,
320
362
  as_datatype: NotLiteralNode,
321
- ) -> Tuple[Any, Stack]:
363
+ ) -> Any:
322
364
  """Find an Iolanta facet for a node and render it."""
323
365
  node = normalize_term(node)
324
366
 
@@ -345,7 +387,7 @@ class Iolanta: # noqa: WPS214
345
387
  )
346
388
 
347
389
  try:
348
- return facet.show(), facet.stack
390
+ return facet.show()
349
391
 
350
392
  except Exception as err:
351
393
  raise FacetError(
@@ -0,0 +1,73 @@
1
+ from dataclasses import dataclass
2
+ from typing import Dict, List, Mapping, Optional, Union
3
+
4
+ from documented import DocumentedError
5
+ from frozendict import frozendict
6
+ from pyparsing import ParseException
7
+ from rdflib import Graph
8
+ from rdflib.term import Identifier, Node, Variable
9
+
10
+ SelectRow = Mapping[str, Node]
11
+
12
+
13
+ class SelectResult(List[SelectRow]):
14
+ """Result of a SPARQL SELECT."""
15
+
16
+ @property
17
+ def first(self) -> Optional[SelectRow]:
18
+ """Return first element of the list."""
19
+ return self[0] if self else None
20
+
21
+
22
+ SPARQLQueryArgument = Optional[Union[Node, str, int, float]]
23
+
24
+
25
+ QueryResult = Union[
26
+ SelectResult, # SELECT
27
+ Graph, # CONSTRUCT
28
+ bool, # ASK
29
+ ]
30
+
31
+
32
+ def format_query_bindings(
33
+ bindings: List[Dict[Variable, Identifier]],
34
+ ) -> SelectResult:
35
+ """
36
+ Format bindings before returning them.
37
+
38
+ Converts Variable to str for ease of addressing.
39
+ """
40
+ return SelectResult([
41
+ frozendict({
42
+ str(variable_name): rdf_value
43
+ for variable_name, rdf_value # noqa: WPS361
44
+ in row.items()
45
+ })
46
+ for row in bindings
47
+ ])
48
+
49
+
50
+ @dataclass
51
+ class SPARQLParseException(DocumentedError):
52
+ """
53
+ SPARQL query is invalid.
54
+
55
+ Error:
56
+
57
+ ```
58
+ {self.error}
59
+ ```
60
+
61
+ Query:
62
+ ```sparql hl_lines="{self.highlight_code}"
63
+ {self.query}
64
+ ```
65
+ """ # noqa: D412
66
+
67
+ error: ParseException
68
+ query: str
69
+
70
+ @property
71
+ def highlight_code(self):
72
+ """Define lines to highlight."""
73
+ return self.error.lineno
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iolanta
3
- Version: 1.2.11
3
+ Version: 2.0.1
4
4
  Summary: Semantic Web browser
5
5
  License: MIT
6
6
  Author: Anatoly Scherbakov
@@ -19,7 +19,6 @@ Requires-Dist: diskcache (>=5.6.3)
19
19
  Requires-Dist: documented (>=0.1.1)
20
20
  Requires-Dist: dominate (>=2.6.0)
21
21
  Requires-Dist: funcy (>=2.0)
22
- Requires-Dist: iolanta-tables (>=0.1.7,<0.2.0) ; extra == "all"
23
22
  Requires-Dist: loguru (>=0.7.3)
24
23
  Requires-Dist: more-itertools (>=9.0.0)
25
24
  Requires-Dist: nanopub (>=2.0.1)
@@ -2,11 +2,11 @@ iolanta/__init__.py,sha256=BvLP-LYFmNYS5F8VPXdzpEEMk8zcm9NMmlUWw9yEtj0,153
2
2
  iolanta/base_plugin.py,sha256=vI4DRSIITlKZw8x7Q58BFkChWlg1h8zV-tuNvIKURBI,86
3
3
  iolanta/cli/__init__.py,sha256=IV6_RPmrbpPWbdKojuFczwaJAaKm1DIDQh5aZWbeR1U,69
4
4
  iolanta/cli/formatters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- iolanta/cli/formatters/choose.py,sha256=Ac4hNoptvnhuJB77K9KOn5oMF7j2RxmNuaLko28Wlns,1122
6
- iolanta/cli/formatters/csv.py,sha256=OVucZxhcMjihUli0wkbSOKo500-i7DNV0Zdf6oIougU,753
7
- iolanta/cli/formatters/json.py,sha256=jkNldFApSWw0kcMkeIPvI2Vt4JTE-Rvx5mWqKJb3Sj4,741
8
- iolanta/cli/formatters/pretty.py,sha256=Ik75CR5GMBDJCvES9eF0bQPj64ZJD40iFDSSZH0s9aA,2920
9
- iolanta/cli/main.py,sha256=93pfYqhXsldasyh1vnJin8Tt6EkUiCsVrwA4v4f6Ibc,3134
5
+ iolanta/cli/formatters/choose.py,sha256=LWzsO_9IBSSgYNIyLlItkp8TNvpW3v6YCQ8-6kbICI4,1129
6
+ iolanta/cli/formatters/csv.py,sha256=ceJ_DTz0beqeK-d6FPBQqqjXrziEfF0FRSLoGZCt_fs,760
7
+ iolanta/cli/formatters/json.py,sha256=Og5B9UrSM_0NWqW5Afpsy6WH8ZfYgPMVXYvT3i-43Jc,748
8
+ iolanta/cli/formatters/pretty.py,sha256=IypZRAr2vNqcXFY6NOIc75mpyfpFWh56aCBlOPDDieQ,2901
9
+ iolanta/cli/main.py,sha256=exDWPljllufn7DiGC9lS1pvojFX9YZJciQ2RPCedKMU,3127
10
10
  iolanta/cli/models.py,sha256=cjbpowdzI4wAP0DUk3qoVHyimk6AZwlXi9CGmusZTuM,159
11
11
  iolanta/cli/pretty_print.py,sha256=M6E3TmhzA6JY5GeUVmDZLmOh5u70-393PVit4voFKDI,977
12
12
  iolanta/context.py,sha256=bZR-tbZIrDQ-Vby01PMDZ6ifxM-0YMK68RJvAsyqCTs,507
@@ -31,7 +31,7 @@ iolanta/facets/cli/record.py,sha256=lBsECxLkwVSXC-yHmUwfosxAdLBI-0UoqHe8GOCablY,
31
31
  iolanta/facets/cli/sparql/link.sparql,sha256=WtWEfLAvdGc2gP0IhZil6Vglkydc3VO24vk4GwRnR5I,163
32
32
  iolanta/facets/cli/sparql/record.sparql,sha256=GBWkmNelvaSDbvl7v0-LsJHdjFPbsSAW49kNFOUeoGQ,63
33
33
  iolanta/facets/errors.py,sha256=sEBmnzhFcRIgOT18hfNwyMMjry0waa6IB-jC2NVTA50,4124
34
- iolanta/facets/facet.py,sha256=S4csQz_R5hofGXI7CEPRkyrZqHdv1xhifKXL2-x096w,3317
34
+ iolanta/facets/facet.py,sha256=jDbtdcu-qhT9zrXVLw_wMkApTlk0xKm2aCLRpd7cfNA,2720
35
35
  iolanta/facets/foaf_person_title/__init__.py,sha256=oj4MNVQvv8Dysb27xiWjtZCii8-nT7-WFa3WMWUwbtU,67
36
36
  iolanta/facets/foaf_person_title/facet.py,sha256=Q9TajjGp1v729quDzAM_Lfzawls3yujp1Z_6jXrG3gY,632
37
37
  iolanta/facets/foaf_person_title/sparql/names.sparql,sha256=p_2hHZXhEaJ8IwGlvLoN0vb0vhGqo44uAVRpDyTzflU,107
@@ -46,7 +46,7 @@ iolanta/facets/html/code_literal.py,sha256=qCddzBrg6Y5XMIKohFQ52Tf9GPOcU7bj83tfA
46
46
  iolanta/facets/html/default.py,sha256=Dmf_kYiL2M954iigyYsiWrMstwZ1nvxKetuR6aW3xYY,647
47
47
  iolanta/facets/icon.py,sha256=ddZcolx1Q5_wo3w0jqiCzcc5Lsru6-jA7s7oAd1T8Og,494
48
48
  iolanta/facets/locator.py,sha256=tFwxGT4ujwEjwkgTevK6gwWfj3_1lU9Q305IU7a-I3Y,7697
49
- iolanta/facets/page_title.py,sha256=CI2V8f7zSSrwbQginhyycZttNoAZTHq34SiO8Ql59bQ,1410
49
+ iolanta/facets/page_title.py,sha256=TwgZK2g_e5UoWYjKNgDzzkmq1EI3cY58680iC8N9kZI,1407
50
50
  iolanta/facets/qname.py,sha256=ztyBbjjcW8dNZzuiNMqhcWfAUxk-gSjbseVGrQE7kVY,531
51
51
  iolanta/facets/textual_browser/__init__.py,sha256=sKgDvXOwib9n9d63kdtKCEv26-FoL0VN6zxDmfcheZ8,104
52
52
  iolanta/facets/textual_browser/app.py,sha256=6-cmEkwRqj9UptVvXKVNIxT3PcDDOZP1OLpv8gPmB_Q,3202
@@ -56,9 +56,9 @@ iolanta/facets/textual_browser/home.py,sha256=GfDD1G2HiwdLkPkNdcYRqVIxDl5tWH9few
56
56
  iolanta/facets/textual_browser/location.py,sha256=w0La8bVTpJiVo1_hFTDQeIUdDdqfhYnoihuZW-f130c,205
57
57
  iolanta/facets/textual_browser/models.py,sha256=DqTBjhkkTt5mNwqr4DzNbPSqzV-QtNqfKj7wpn6T3ao,173
58
58
  iolanta/facets/textual_browser/page.py,sha256=NkcQ5rSKZRbp63C8ozgsR_iVhcKHGv_SytUCQyGa7ss,786
59
- iolanta/facets/textual_browser/page_switcher.py,sha256=1-mWI56n2gLDThPBjfqHLun3utkUYdOkKSzejCIziEk,9953
59
+ iolanta/facets/textual_browser/page_switcher.py,sha256=WOsFY9hSFEnuf3za1eCUhPaQ6uTaeBuMPIAHjHhnvDY,9950
60
60
  iolanta/facets/textual_class/__init__.py,sha256=tiL0p-3JspGcBRj4qa3rmoBFAuadk71l2ja2lJN6CEs,75
61
- iolanta/facets/textual_class/facets.py,sha256=W3-N7bekk-bKwrb2rTPwmySGF42-uV7aqLPAiHwFSU4,6496
61
+ iolanta/facets/textual_class/facets.py,sha256=qDljrtu7poPuvwRFwtmOlLccsIMhAKrzIQ5_OHeXQZE,6493
62
62
  iolanta/facets/textual_class/sparql/instances.sparql,sha256=tmG4tuYrROKo3A7idjOEblAeNPXiiExHxc6k3fhalSM,113
63
63
  iolanta/facets/textual_default/__init__.py,sha256=snxA0FEY9qfAxNv3MlZLrJsXugD4dvs5hLStZWV7soM,158
64
64
  iolanta/facets/textual_default/facets.py,sha256=Pf5GttQ7EG0ZodjwwVXzYMffHus3MAZdJUIcbddcYtw,4738
@@ -69,18 +69,18 @@ iolanta/facets/textual_default/sparql/properties.sparql,sha256=stDbvFP4g6YKYphpN
69
69
  iolanta/facets/textual_default/tcss/default.tcss,sha256=v6k6LvZMndRW4t9Iq-7QF59U_LJTdohRsyavwTY5ruI,69
70
70
  iolanta/facets/textual_default/templates/default.md,sha256=CuD5lISsE2eAVnm2z6kfNff-vEgrNG95Wi5LTgkieWY,21
71
71
  iolanta/facets/textual_default/triple_uri_ref.py,sha256=XfuNPaAe-YxH8IyrdrHQ641aWh5zVMVs0L0WC3D6A4M,1279
72
- iolanta/facets/textual_default/widgets.py,sha256=yOw3qJlwXYNqz3HuuRiVM0IZ-YSto_IeI2Hgv6n1BxU,9189
72
+ iolanta/facets/textual_default/widgets.py,sha256=0f8gJmo447O5e_KwVxyb3hdVNzDJQTUf9GmRnp6hfrA,9183
73
73
  iolanta/facets/textual_graph/__init__.py,sha256=DWd2gljzL8SiyYKQdBH78HouF1EMqgCH-w0K5OEmL2I,59
74
- iolanta/facets/textual_graph/facets.py,sha256=ZjWEEjzYGHRODvTUPiTFjKEjFQx59Bq-1v_RXU54M9k,876
74
+ iolanta/facets/textual_graph/facets.py,sha256=NGg0i1XYmdR8gjMd-D4Ckvu_n7m7s1FA68VSUm7cpj0,873
75
75
  iolanta/facets/textual_graph/sparql/triples.sparql,sha256=5rFVGcvZzEHZj2opQQp0YlxJLpEdl-r1RjkPwo8j7t0,145
76
- iolanta/facets/textual_graph_triples.py,sha256=EsJvNFw_pqXjHXQYuMmhGCGrIN85Y6rBfl_UEsuTdY8,3867
76
+ iolanta/facets/textual_graph_triples.py,sha256=oJa4pj71r-gODYk9otIrq-tSiV2SsaofhErUXJWRlKE,3864
77
77
  iolanta/facets/textual_link/__init__.py,sha256=ShlMaq2nrpinGZFutjGNKaZQhGKQGOz_VUQzUqq3U7o,95
78
78
  iolanta/facets/textual_link/facet.py,sha256=XJXq97M3_IJBXSYWV3NAYzT96TrvNDgrUQXLP81d3K0,655
79
79
  iolanta/facets/textual_nanopublication/__init__.py,sha256=ZYYw08MZbIiTpX4xm8AJ3eJnu9GgdOeuRDVibBDOtZc,114
80
80
  iolanta/facets/textual_nanopublication/facet.py,sha256=1F-8E5tU0n_ukHPqcnksu8UlmRyyL_vxgG4qUWFp5ZA,369
81
81
  iolanta/facets/textual_nanopublication/models.py,sha256=MphggSvKmYac6v866GOKW5lcQjNIbGvwIuJonKuQRVs,177
82
- iolanta/facets/textual_nanopublication/nanopublication_widget.py,sha256=jDqHtmWdNUBH571QbDY9C3efmni32OPu6DXA62mjPlA,2390
83
- iolanta/facets/textual_nanopublication/term_list_widget.py,sha256=_xfVNT1kz3WHqT4uVGci18DHBtGb25_GDt3cuH1N60E,995
82
+ iolanta/facets/textual_nanopublication/nanopublication_widget.py,sha256=sQPgEx25XJ15VqB5zjZuz2q2bf_B5GWXEp32FAufxQ4,2387
83
+ iolanta/facets/textual_nanopublication/term_list_widget.py,sha256=NZNATKjFmgI2sE5R0ebyQh5Qk2g-kf-MT4YZ-Vw78M4,992
84
84
  iolanta/facets/textual_nanopublication/term_widget.py,sha256=uI5msCTSIYumAIS3I8nBfUz57_vRzvCKkouevrS3Qwk,3536
85
85
  iolanta/facets/textual_ontology/__init__.py,sha256=3H6bfYaEbXFr90C6ZpGWC4O-24uaO18tnTXx7mckQSA,94
86
86
  iolanta/facets/textual_ontology/facets.py,sha256=60g8ANmePb9_i_-d4ui-FdtNwg9aktrOKXHkTQtLp1w,3338
@@ -96,7 +96,7 @@ iolanta/facets/title/sparql/title.sparql,sha256=4rz47tjwX2OJavWMzftaYKil1-ZHB76Z
96
96
  iolanta/facets/wikibase_statement_title/__init__.py,sha256=_yk1akxgSJOiUBJIc8QGrD2vovvmx_iw_vJDuv1rD7M,91
97
97
  iolanta/facets/wikibase_statement_title/facets.py,sha256=mUH7twlAgoeX7DgLQuRBQv4ORT6GWbN-0eJ1aliSfiQ,724
98
98
  iolanta/facets/wikibase_statement_title/sparql/statement-title.sparql,sha256=n07DQWxKqB5c3CA4kacq2HSN0R0dLgnMnLP1AxMo5YA,320
99
- iolanta/iolanta.py,sha256=cIfhM9zhositho4C6jZ2th2oB3d50BSlYsRRozS4tP4,12911
99
+ iolanta/iolanta.py,sha256=ZZ5hBXuVci4v-36xYLeaqDjgo85kEnnYCA07eJMo9ME,14230
100
100
  iolanta/loaders/__init__.py,sha256=QTiKCsQc1BTS-IlY2CQsN9iVpEIPqYFvI9ERMYVZCbU,99
101
101
  iolanta/loaders/base.py,sha256=-DxYwqG1bfDXB2p_S-mKpkc_3Sh14OHhePbe65Iq3-s,3381
102
102
  iolanta/loaders/data_type_choice.py,sha256=zRUXBIzjvuW28P_dhMDVevE9C8EFEIx2_X39WydWrtM,1982
@@ -118,17 +118,15 @@ iolanta/parsers/json.py,sha256=3VrDiz-SaVXP9_B03Gl62VSIk2fKeRrrb2hpTLxqBk4,967
118
118
  iolanta/parsers/markdown.py,sha256=wv-PhszgoDOzWdisykIeZyYBD1edCVmw7UQ8jEn4siw,1669
119
119
  iolanta/parsers/yaml.py,sha256=MeTe5_OaDK27XB38AzxjqWfCxybAm4tqgqn7LLh-YB0,1244
120
120
  iolanta/plugin.py,sha256=MSxpuOIx93AgBahfS8bYh31MEgcwtUSQhj4Js7fgdSI,1096
121
+ iolanta/query_result.py,sha256=VLLBkewUEymtzfB0jeIeRE3Np6pAgo959RPgNsEmiq8,1545
121
122
  iolanta/reformat_blank_nodes.py,sha256=MAVcXusUioKzAoTEHAMume5Gt9vBEpxJGrngqFzmkJI,712
122
123
  iolanta/resolvers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
124
  iolanta/resolvers/base.py,sha256=cc9bcrVZ0wTwn85I-IYCwcIRU5Lwaph8D00C0dwSOm8,302
124
125
  iolanta/resolvers/python_import.py,sha256=kDOhApBDFfxnrDgK9M7ztMkqXfcny81Zo86FgPFb-LI,1301
125
126
  iolanta/shortcuts.py,sha256=j8b0E_yeoas8GumsPOfxO2v2jO0noqpmKJ6LFxFfsu4,1892
126
- iolanta/stack.py,sha256=ZN1P3CbZ5r0V61SDWtQNDsKAcl-10RU9cCU9_6rcUfY,234
127
127
  iolanta/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  iolanta/widgets/mixin.py,sha256=nDRCOc-gizCf1a5DAcYs4hW8eZEd6pHBPFsfm0ncv7E,251
129
- ldflex/__init__.py,sha256=8IELqR55CQXuI0BafjobXSK7_kOc-qKVTrEtEwXnZRA,33
130
- ldflex/ldflex.py,sha256=omKmOo5PUyn8Evw4q_lqKCJOq6yqVOcLAYxnYkdwOUs,3332
131
- iolanta-1.2.11.dist-info/METADATA,sha256=2wGXN9mncu09r8MrbLUvMM_VYavsuM6u7dkQTEbLNsc,2295
132
- iolanta-1.2.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
133
- iolanta-1.2.11.dist-info/entry_points.txt,sha256=fIp9g4kzjSNcTsTSjUCk4BIG3laHd3b3hUZlkjgFAGU,179
134
- iolanta-1.2.11.dist-info/RECORD,,
129
+ iolanta-2.0.1.dist-info/METADATA,sha256=pcU438uX93qgFW-t4I6fQwDMJcM62G1wXO8FtLxg9zM,2230
130
+ iolanta-2.0.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
131
+ iolanta-2.0.1.dist-info/entry_points.txt,sha256=fIp9g4kzjSNcTsTSjUCk4BIG3laHd3b3hUZlkjgFAGU,179
132
+ iolanta-2.0.1.dist-info/RECORD,,
iolanta/stack.py DELETED
@@ -1,11 +0,0 @@
1
- from dataclasses import dataclass, field
2
- from typing import List
3
-
4
- from rdflib.term import Node
5
-
6
-
7
- @dataclass
8
- class Stack:
9
- node: Node
10
- facet: 'iolanta.facets.facet.Facet'
11
- children: List['Stack'] = field(default_factory=list)
ldflex/__init__.py DELETED
@@ -1 +0,0 @@
1
- from ldflex.ldflex import LDFlex
ldflex/ldflex.py DELETED
@@ -1,138 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Dict, List, Mapping, Optional, Union
3
-
4
- from documented import DocumentedError
5
- from frozendict import frozendict
6
- from pyparsing import ParseException
7
- from rdflib import Graph
8
- from rdflib.plugins.sparql.processor import SPARQLResult
9
- from rdflib.term import Identifier, Node, Variable
10
-
11
- from iolanta.cyberspace.processor import GlobalSPARQLProcessor
12
-
13
- SelectRow = Mapping[str, Node]
14
-
15
-
16
- class SelectResult(List[SelectRow]):
17
- """Result of a SPARQL SELECT."""
18
-
19
- @property
20
- def first(self) -> Optional[SelectRow]:
21
- """Return first element of the list."""
22
- return self[0] if self else None
23
-
24
-
25
- SPARQLQueryArgument = Optional[Union[Node, str, int, float]]
26
-
27
-
28
- QueryResult = Union[
29
- SelectResult, # SELECT
30
- Graph, # CONSTRUCT
31
- bool, # ASK
32
- ]
33
-
34
-
35
- def _format_query_bindings(
36
- bindings: List[Dict[Variable, Identifier]],
37
- ) -> SelectResult:
38
- """
39
- Format bindings before returning them.
40
-
41
- Converts Variable to str for ease of addressing.
42
- """
43
- return SelectResult([
44
- frozendict({
45
- str(variable_name): rdf_value
46
- for variable_name, rdf_value
47
- in row.items()
48
- })
49
- for row in bindings
50
- ])
51
-
52
-
53
- @dataclass
54
- class SPARQLParseException(DocumentedError):
55
- """
56
- SPARQL query is invalid.
57
-
58
- Error:
59
-
60
- ```
61
- {self.error}
62
- ```
63
-
64
- Query:
65
- ```sparql hl_lines="{self.highlight_code}"
66
- {self.query}
67
- ```
68
- """
69
-
70
- error: ParseException
71
- query: str
72
-
73
- @property
74
- def highlight_code(self):
75
- """Define lines to highlight."""
76
- return self.error.lineno
77
-
78
-
79
- @dataclass
80
- class LDFlex:
81
- """Fluent interface to a semantic graph."""
82
-
83
- graph: Graph
84
-
85
- def query(
86
- self,
87
- query_text: str,
88
- **kwargs: SPARQLQueryArgument,
89
- ) -> QueryResult:
90
- """
91
- Run a SPARQL `SELECT`, `CONSTRUCT`, or `ASK` query.
92
-
93
- Args:
94
- query_text: The SPARQL text;
95
- **kwargs: bind variables in the query to values if necessary. For
96
- example:
97
-
98
- ```python
99
- ldflex.query(
100
- 'SELECT ?title WHERE { ?page rdfs:label ?title }',
101
- ?page=page_iri,
102
- )
103
- ```
104
-
105
- Returns:
106
- Results of the query:
107
-
108
- - a graph for `CONSTRUCT`,
109
- - a list of dicts for `SELECT`,
110
- - or a boolean for `ASK`.
111
- """
112
- try:
113
- sparql_result: SPARQLResult = self.graph.query(
114
- query_text,
115
- processor='cyberspace',
116
- initBindings=kwargs,
117
- )
118
- except ParseException as err:
119
- raise SPARQLParseException(
120
- error=err,
121
- query=query_text,
122
- ) from err
123
-
124
- if sparql_result.askAnswer is not None:
125
- return sparql_result.askAnswer
126
-
127
- if sparql_result.graph is not None:
128
- graph: Graph = sparql_result.graph
129
- for prefix, namespace in self.graph.namespaces():
130
- graph.bind(prefix, namespace)
131
-
132
- return graph
133
-
134
- return _format_query_bindings(sparql_result.bindings)
135
-
136
- def update(self, sparql_query: str):
137
- """Apply the given SPARQL INSERT query."""
138
- self.graph.update(sparql_query)