Skip to content

Commit 9a10e10

Browse files
committed
cleanup
1 parent b4d319c commit 9a10e10

File tree

6 files changed

+39
-59
lines changed

6 files changed

+39
-59
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yFiles-Jupyter Graphs For SPARQL
1+
# yFiles Jupyter Graphs for SPARQL
22

33
![A screenshot showing the yFiles graph widget for sparql in a jupyter lab notebook](https://raw.githubusercontent.com/yWorks/yfiles-jupyter-graphs-for-sparql/main/images/Getting_started_screenshot.png)
44

@@ -8,14 +8,16 @@ This packages provides an easy-to-use interface to
88
the [yFiles Graphs for Jupyter](https://github.com/yWorks/yfiles-jupyter-graphs) widget to directly visualize queries.
99

1010
## Installation
11-
11+
Just install it from the [Python Package Index](https://pypi.org/project/yfiles-jupyter-graphs-for-sparql/)
1212
```bash
1313
pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1
1414
```
15+
or see [README_DEV.md](https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/blob/main/README_DEV.md) to build it yourself.
1516

1617
## Usage
1718

1819
```python
20+
from SPARQLWrapper import SPARQLWrapper
1921
from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget
2022

2123
g = SparqlGraphWidget(wrapper=SPARQLWrapper("http://dbpedia.org/sparql"))
@@ -211,6 +213,7 @@ See [issues](https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/issues).
211213

212214
* [yFiles Graphs for Jupyter](https://github.com/yWorks/yfiles-jupyter-graphs)
213215
* [rdfLib](https://rdflib.readthedocs.io/en/stable/)
216+
* [SPARQLWrapper](https://sparqlwrapper.readthedocs.io/)
214217

215218
## License
216219
See [LICENSE](https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/blob/main/LICENSE.md) file.

examples/Getting_started.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"%pip install rdflib --quiet\n",
19-
"%pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1 --quiet\n",
20-
"from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget\n",
2118
"%pip install SPARQLWrapper --quiet\n",
22-
"from SPARQLWrapper import JSON, SPARQLWrapper, XML"
19+
"%pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1 --quiet\n",
20+
"from SPARQLWrapper import SPARQLWrapper, XML\n",
21+
"\n",
22+
"from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget"
2323
]
2424
},
2525
{
@@ -125,7 +125,7 @@
125125
"name": "python",
126126
"nbconvert_exporter": "python",
127127
"pygments_lexer": "ipython3",
128-
"version": "3.13.1"
128+
"version": "3.11.11"
129129
}
130130
},
131131
"nbformat": 4,

examples/beatles.ttl

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/configurations_example.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"%pip install rdflib --quiet\n",
19-
"%pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1 --quiet\n",
20-
"from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget\n",
2118
"%pip install SPARQLWrapper --quiet\n",
22-
"from SPARQLWrapper import SPARQLWrapper, JSON"
19+
"%pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1 --quiet\n",
20+
"from SPARQLWrapper import SPARQLWrapper, JSON\n",
21+
"\n",
22+
"from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget"
2323
]
2424
},
2525
{
@@ -157,7 +157,7 @@
157157
"name": "python",
158158
"nbconvert_exporter": "python",
159159
"pygments_lexer": "ipython3",
160-
"version": "3.13.1"
160+
"version": "3.11.11"
161161
}
162162
},
163163
"nbformat": 4,

pyproject.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ version = "0.9.0rc1"
44
authors = [
55
{name = "yWorks Support Team", email= "[email protected]"},
66
]
7-
description = "The open-source adapter for working with RDF databases and SPARQL queries in Jupyter notebooks leveraging the yFiles Graphs for Jupyter plugin.s"
7+
description = "The open-source adapter for working with RDF databases and SPARQL queries in Jupyter notebooks leveraging the yFiles Graphs for Jupyter plugin."
88
readme = "README.md"
99
requires-python = ">=3.8"
1010
classifiers = [
11-
"Programming Language :: Python :: 3",
12-
"License :: OSI Approved :: MIT License",
13-
"Operating System :: OS Independent",
1411
"Framework :: IPython",
1512
"Intended Audience :: Developers",
1613
"Intended Audience :: Science/Research",
@@ -22,14 +19,16 @@ classifiers = [
2219
"Framework :: Jupyter :: JupyterLab :: Extensions",
2320
"Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt",
2421
]
22+
license = {file = "LICENSE.md"}
2523
dependencies = [
26-
"yfiles_jupyter_graphs>=1.9.0",
27-
"rdflib>=7.1.2",
24+
"yfiles_jupyter_graphs>=1.9.0"
2825
]
2926

3027
[project.urls]
31-
Homepage = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql"
32-
Issues = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/issues"
28+
License = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/blob/main/LICENSE.md"
29+
"Bug Tracker" = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/issues"
30+
Documentation = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql/"
31+
Repository = "https://github.com/yWorks/yfiles-jupyter-graphs-for-sparql.git"
3332

3433
[build-system]
3534
requires = ["setuptools>=61.0"]

src/yfiles_jupyter_graphs_for_sparql/Yfiles_Sparql_Graphs.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import inspect
22
import re
33
from typing import Union, Dict, Any, Optional
4+
from importlib import import_module
45

5-
from SPARQLWrapper import JSON
66
from yfiles_jupyter_graphs import GraphWidget
7-
from rdflib import Literal
87

98
POSSIBLE_NODE_BINDINGS = {'coordinate', 'color', 'size', 'type', 'styles', 'scale_factor', 'position',
109
'layout', 'property', 'label'}
1110
POSSIBLE_EDGE_BINDINGS = {'color', 'thickness_factor', 'property', 'label'}
1211
SPARQL_LABEL_KEYS = ['name', 'title', 'text', 'description', 'caption', 'label']
1312

13+
def _try_import(module_name: str, graph_type_name: str):
14+
try:
15+
module = import_module(module_name)
16+
try:
17+
return module.__getattribute__(graph_type_name)
18+
except AttributeError:
19+
return None
20+
except ImportError:
21+
return None
22+
23+
SPARQLWrapper_JSON = _try_import('SPARQLWrapper', 'JSON')
24+
rdflib_Literal = _try_import('rdflib', 'Literal')
1425

1526
def extract_label(term, edge):
1627
"""
@@ -85,7 +96,7 @@ def _query(self, query):
8596
wrapper.setQuery(query)
8697
ret = wrapper.queryAndConvert()
8798
# SELECT query
88-
if wrapper.returnFormat == JSON and "results" in ret and "bindings" in ret["results"]:
99+
if wrapper.returnFormat == SPARQLWrapper_JSON and "results" in ret and "bindings" in ret["results"]:
89100
triples = []
90101
for row in ret["results"]["bindings"]:
91102
s = next((row[key]["value"] for key in row if key.startswith('s')), None)
@@ -145,7 +156,7 @@ def find_element_by_label(array, label):
145156

146157
o_label = str(o)
147158
o_extracted_label = extract_label(o, False)
148-
literal = isinstance(o, Literal)
159+
literal = isinstance(o, rdflib_Literal)
149160

150161
p_label = str(p)
151162
p_extracted_label = extract_label(p, True)
@@ -421,9 +432,9 @@ def show_schema(self):
421432

422433
if self._wrapper is None:
423434
raise Exception("No data was given to infer schema")
424-
elif self._wrapper.returnFormat != JSON:
435+
elif self._wrapper.returnFormat != SPARQLWrapper_JSON:
425436
return_format = self._wrapper.returnFormat
426-
self._wrapper.setReturnFormat(JSON)
437+
self._wrapper.setReturnFormat(SPARQLWrapper_JSON)
427438

428439
c = f"""
429440
SELECT DISTINCT ?s ?p ?o

0 commit comments

Comments
 (0)