iolanta 2.0.0__tar.gz → 2.0.1__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 (133) hide show
  1. {iolanta-2.0.0 → iolanta-2.0.1}/PKG-INFO +1 -1
  2. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/formatters/choose.py +1 -1
  3. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/formatters/csv.py +1 -1
  4. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/formatters/json.py +1 -1
  5. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/formatters/pretty.py +1 -2
  6. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/facet.py +3 -9
  7. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/iolanta.py +56 -13
  8. iolanta-2.0.1/iolanta/query_result.py +73 -0
  9. {iolanta-2.0.0 → iolanta-2.0.1}/pyproject.toml +1 -6
  10. iolanta-2.0.0/ldflex/__init__.py +0 -1
  11. iolanta-2.0.0/ldflex/ldflex.py +0 -138
  12. {iolanta-2.0.0 → iolanta-2.0.1}/README.md +0 -0
  13. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/__init__.py +0 -0
  14. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/base_plugin.py +0 -0
  15. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/__init__.py +0 -0
  16. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/formatters/__init__.py +0 -0
  17. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/main.py +0 -0
  18. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/models.py +0 -0
  19. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cli/pretty_print.py +0 -0
  20. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/context.py +0 -0
  21. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/conversions.py +0 -0
  22. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cyberspace/__init__.py +0 -0
  23. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cyberspace/inference/wikibase-claim.sparql +0 -0
  24. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cyberspace/inference/wikibase-statement-property.sparql +0 -0
  25. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/cyberspace/processor.py +0 -0
  26. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/data/cli.yaml +0 -0
  27. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/data/context.yaml +0 -0
  28. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/data/html.yaml +0 -0
  29. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/data/iolanta.yaml +0 -0
  30. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/data/textual-browser.yaml +0 -0
  31. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/ensure_is_context.py +0 -0
  32. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/entry_points.py +0 -0
  33. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/errors.py +0 -0
  34. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/__init__.py +0 -0
  35. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/__init__.py +0 -0
  36. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/base.py +0 -0
  37. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/default.py +0 -0
  38. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/record.py +0 -0
  39. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/sparql/link.sparql +0 -0
  40. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/cli/sparql/record.sparql +0 -0
  41. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/errors.py +0 -0
  42. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/foaf_person_title/__init__.py +0 -0
  43. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/foaf_person_title/facet.py +0 -0
  44. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/foaf_person_title/sparql/names.sparql +0 -0
  45. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/generic/__init__.py +0 -0
  46. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/generic/bool_literal.py +0 -0
  47. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/generic/date_literal.py +0 -0
  48. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/generic/default.py +0 -0
  49. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/generic/sparql/default.sparql +0 -0
  50. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/html/__init__.py +0 -0
  51. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/html/base.py +0 -0
  52. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/html/code_literal.py +0 -0
  53. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/html/default.py +0 -0
  54. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/icon.py +0 -0
  55. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/locator.py +0 -0
  56. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/page_title.py +0 -0
  57. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/qname.py +0 -0
  58. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/__init__.py +0 -0
  59. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/app.py +0 -0
  60. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/facet.py +0 -0
  61. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/history.py +0 -0
  62. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/home.py +0 -0
  63. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/location.py +0 -0
  64. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/models.py +0 -0
  65. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/page.py +0 -0
  66. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_browser/page_switcher.py +0 -0
  67. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_class/__init__.py +0 -0
  68. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_class/facets.py +0 -0
  69. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_class/sparql/instances.sparql +0 -0
  70. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/__init__.py +0 -0
  71. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/facets.py +0 -0
  72. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/sparql/inverse-properties.sparql +0 -0
  73. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/sparql/label.sparql +0 -0
  74. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/sparql/nodes-for-property.sparql +0 -0
  75. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/sparql/properties.sparql +0 -0
  76. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/tcss/default.tcss +0 -0
  77. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/templates/default.md +0 -0
  78. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/triple_uri_ref.py +0 -0
  79. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_default/widgets.py +0 -0
  80. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_graph/__init__.py +0 -0
  81. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_graph/facets.py +0 -0
  82. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_graph/sparql/triples.sparql +0 -0
  83. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_graph_triples.py +0 -0
  84. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_link/__init__.py +0 -0
  85. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_link/facet.py +0 -0
  86. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/__init__.py +0 -0
  87. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/facet.py +0 -0
  88. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/models.py +0 -0
  89. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/nanopublication_widget.py +0 -0
  90. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/term_list_widget.py +0 -0
  91. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_nanopublication/term_widget.py +0 -0
  92. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_ontology/__init__.py +0 -0
  93. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_ontology/facets.py +0 -0
  94. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_ontology/sparql/terms.sparql +0 -0
  95. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_ontology/sparql/visualization-vocab.sparql +0 -0
  96. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_provenance/__init__.py +0 -0
  97. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_provenance/facets.py +0 -0
  98. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_provenance/sparql/graphs.sparql +0 -0
  99. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/textual_provenance/sparql/triples.sparql +0 -0
  100. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/title/__init__.py +0 -0
  101. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/title/facets.py +0 -0
  102. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/title/sparql/title.sparql +0 -0
  103. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/wikibase_statement_title/__init__.py +0 -0
  104. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/wikibase_statement_title/facets.py +0 -0
  105. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/facets/wikibase_statement_title/sparql/statement-title.sparql +0 -0
  106. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/__init__.py +0 -0
  107. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/base.py +0 -0
  108. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/data_type_choice.py +0 -0
  109. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/dict_loader.py +0 -0
  110. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/errors.py +0 -0
  111. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/http.py +0 -0
  112. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/local_directory.py +0 -0
  113. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/local_file.py +0 -0
  114. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/loaders/scheme_choice.py +0 -0
  115. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/models.py +0 -0
  116. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/namespaces.py +0 -0
  117. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/node_to_qname.py +0 -0
  118. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parse_quads.py +0 -0
  119. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/__init__.py +0 -0
  120. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/base.py +0 -0
  121. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/dict_parser.py +0 -0
  122. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/errors.py +0 -0
  123. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/json.py +0 -0
  124. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/markdown.py +0 -0
  125. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/parsers/yaml.py +0 -0
  126. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/plugin.py +0 -0
  127. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/reformat_blank_nodes.py +0 -0
  128. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/resolvers/__init__.py +0 -0
  129. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/resolvers/base.py +0 -0
  130. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/resolvers/python_import.py +0 -0
  131. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/shortcuts.py +0 -0
  132. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/widgets/__init__.py +0 -0
  133. {iolanta-2.0.0 → iolanta-2.0.1}/iolanta/widgets/mixin.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iolanta
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Semantic Web browser
5
5
  License: MIT
6
6
  Author: Anatoly Scherbakov
@@ -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
@@ -2,13 +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 ldflex import LDFlex
11
- from ldflex.ldflex import QueryResult, SPARQLQueryArgument
10
+ from iolanta.query_result import QueryResult, SPARQLQueryArgument
12
11
 
13
12
  FacetOutput = TypeVar('FacetOutput')
14
13
 
@@ -26,11 +25,6 @@ class Facet(Generic[FacetOutput]):
26
25
  """Construct directory for stored queries for this facet."""
27
26
  return Path(inspect.getfile(self.__class__)).parent / 'sparql'
28
27
 
29
- @property
30
- def ldflex(self) -> LDFlex:
31
- """Extract LDFLex instance."""
32
- return self.iolanta.ldflex
33
-
34
28
  @cached_property
35
29
  def uriref(self) -> NotLiteralNode:
36
30
  """Format as URIRef."""
@@ -45,7 +39,7 @@ class Facet(Generic[FacetOutput]):
45
39
  **kwargs: SPARQLQueryArgument,
46
40
  ) -> QueryResult:
47
41
  """SPARQL query."""
48
- return self.ldflex.query(
42
+ return self.iolanta.query(
49
43
  query_text=query_text,
50
44
  **kwargs,
51
45
  )
@@ -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,8 +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 ldflex import LDFlex
49
56
 
50
57
 
51
58
  class LoggerProtocol(Protocol):
@@ -124,14 +131,56 @@ class Iolanta: # noqa: WPS214
124
131
  for plugin_class in self.plugin_classes
125
132
  ]
126
133
 
127
- @property
128
- def ldflex(self) -> LDFlex:
134
+ def query(
135
+ self,
136
+ query_text: str,
137
+ **kwargs: SPARQLQueryArgument,
138
+ ) -> QueryResult:
129
139
  """
130
- Create ldflex instance.
140
+ Run a SPARQL `SELECT`, `CONSTRUCT`, or `ASK` query.
131
141
 
132
- 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`.
133
160
  """
134
- 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)
135
184
 
136
185
  @functools.cached_property
137
186
  def namespaces_to_bind(self) -> Dict[str, Namespace]:
@@ -253,12 +302,6 @@ class Iolanta: # noqa: WPS214
253
302
  self.graph.bind(prefix='dcterms', namespace=namespaces.DCTERMS)
254
303
  self.graph.bind(prefix='rdfg', namespace=namespaces.RDFG)
255
304
 
256
- @property
257
- def query(self):
258
- """Make a SPARQL query."""
259
- self.maybe_infer()
260
- return self.ldflex.query
261
-
262
305
  @functools.cached_property
263
306
  def context_paths(self) -> Iterable[Path]:
264
307
  """
@@ -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,16 +1,11 @@
1
1
  [tool.poetry]
2
2
  name = "iolanta"
3
- version = "2.0.0"
3
+ version = "2.0.1"
4
4
  description = "Semantic Web browser"
5
5
  authors = ["Anatoly Scherbakov <altaisoft@gmail.com>"]
6
6
  license = "MIT"
7
7
  readme = "README.md"
8
8
 
9
- packages = [
10
- { include = "ldflex" },
11
- { include = "iolanta" },
12
- ]
13
-
14
9
  [tool.poetry.dependencies]
15
10
  python = ">=3.10,<4.0"
16
11
  rdflib = "<8.0"
@@ -1 +0,0 @@
1
- from ldflex.ldflex import LDFlex
@@ -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)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes