forked from jupyrdf/ipyradiant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace default QueryWidget in library. Minor improvements to related code.
- Loading branch information
Showing
12 changed files
with
479 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Query Widget\n", | ||
"\n", | ||
"A simple widget for construting and visualizing a SPARQL query and its results.\n", | ||
"\n", | ||
"Reusable self-contained widgets are preferrable to monolithic widgets. Therefore, we\n", | ||
"break down the widget components available in `ipyradiant` that are aggregated into a\n", | ||
"unified `QueryWidget`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First, we load an example graph file from the library data." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyradiant import FileManager, PathLoader\n", | ||
"\n", | ||
"lw = FileManager(loader=PathLoader(path=\"data\"))\n", | ||
"lw.loader.file_picker.value = lw.loader.file_picker.options[\"starwars.ttl\"]\n", | ||
"lw" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## QueryPreview\n", | ||
"\n", | ||
"The `QueryPreview` widget allows users to enter a `query` in the left panel, and see\n", | ||
"live syntax highlighting in the right panel.\n", | ||
"\n", | ||
"In a future update, it may be possible to provide syntax highlighting and tips as part\n", | ||
"of a single query entry widget." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyradiant.query.visualize import QueryPreview\n", | ||
"\n", | ||
"qp = QueryPreview()\n", | ||
"# Specify an example query for demonstration pu\n", | ||
"qp.query = \"\"\"\\\n", | ||
"PREFIX voc: <https://swapi.co/vocabulary/>\n", | ||
"CONSTRUCT {\n", | ||
" ?s ?p ?o .\n", | ||
" voc:Character a rdfs:Class .\n", | ||
"} WHERE {\n", | ||
" {\n", | ||
" SELECT DISTINCT ?s\n", | ||
" WHERE {\n", | ||
" ?s a voc:Character .\n", | ||
" }\n", | ||
" LIMIT 3\n", | ||
" }\n", | ||
" ?s ?p ?o .\n", | ||
"}\n", | ||
"\"\"\"\n", | ||
"qp" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## QueryResultsGrid\n", | ||
"\n", | ||
"The `QueryResultsGrid` provides a simple way to view the results of a query as a grid.\n", | ||
"\n", | ||
"A future update may include the ability to apply operations on the grid (i.e.\n", | ||
"filtering)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyradiant.query.visualize import QueryResultsGrid\n", | ||
"\n", | ||
"qrg = QueryResultsGrid(namespaces=dict(lw.graph.namespaces()))\n", | ||
"# set the query results for the demonstration\n", | ||
"qrg.query_result = lw.graph.query(qp.query)\n", | ||
"qrg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## QueryWidget\n", | ||
"\n", | ||
"The `QueryWidget` aggregates the `QueryPreview` and `QueryResultsGrid` together with a\n", | ||
"\"Run Query\" button to support the workflow of query specification, execution, and\n", | ||
"analysis of results.\n", | ||
"\n", | ||
"> Tip: The results of the query can be collected via `QueryWidget.query_result`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from ipyradiant.query.app import QueryWidget\n", | ||
"\n", | ||
"qw = QueryWidget(graph=lw.graph)\n", | ||
"# specify an example query for demonstration\n", | ||
"qw.query = \"\"\"\\\n", | ||
"CONSTRUCT {\n", | ||
" ?s ?p ?o .\n", | ||
" voc:Character a rdfs:Class .\n", | ||
"} WHERE {\n", | ||
" {\n", | ||
" SELECT DISTINCT ?s\n", | ||
" WHERE {\n", | ||
" ?s a voc:Character .\n", | ||
" }\n", | ||
" LIMIT 3\n", | ||
" }\n", | ||
" ?s ?p ?o .\n", | ||
"}\n", | ||
"\"\"\"\n", | ||
"# automate the execution of the query for demonstration\n", | ||
"qw.run_button.click()\n", | ||
"qw" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.