Skip to content
Snippets Groups Projects
Commit 7e799689 authored by Laurenz Alexander Neumann's avatar Laurenz Alexander Neumann
Browse files

removed unused cgi package, removed shex module

parent decf1ea9
Branches
No related tags found
No related merge requests found
...@@ -4,7 +4,6 @@ from IPython.display import display_javascript ...@@ -4,7 +4,6 @@ from IPython.display import display_javascript
from .jupyter_rdf import JupyterRDF from .jupyter_rdf import JupyterRDF
from .serialization import SerializationModule from .serialization import SerializationModule
from .sparql import SPARQLModule from .sparql import SPARQLModule
from .shex import ShexModule
from .graph_manager import GraphManagerModule from .graph_manager import GraphManagerModule
...@@ -15,7 +14,7 @@ def load_ipython_extension(ipython): ...@@ -15,7 +14,7 @@ def load_ipython_extension(ipython):
js_highlight = """ js_highlight = """
if (typeof IPython !== "undefined") { if (typeof IPython !== "undefined") {
IPython.CodeCell.options_default.highlight_modes['application/sparql-query'] = {'reg':[/^%%rdf sparql/]}; IPython.CodeCell.options_default.highlight_modes['application/sparql-query'] = {'reg':[/^%%rdf sparql/]};
IPython.CodeCell.options_default.highlight_modes['text/turtle'] = {'reg':[/^%%rdf turtle/, /^%%rdf shex/]}; IPython.CodeCell.options_default.highlight_modes['text/turtle'] = {'reg':[/^%%rdf turtle/]};
IPython.CodeCell.options_default.highlight_modes['application/ld+json'] = {'reg':[/^%%rdf json-ld/]}; IPython.CodeCell.options_default.highlight_modes['application/ld+json'] = {'reg':[/^%%rdf json-ld/]};
IPython.notebook.get_cells().map(function(cell){ if (cell.cell_type == 'code'){ cell.auto_highlight(); } }); IPython.notebook.get_cells().map(function(cell){ if (cell.cell_type == 'code'){ cell.auto_highlight(); } });
} }
...@@ -39,7 +38,6 @@ def load_ipython_extension(ipython): ...@@ -39,7 +38,6 @@ def load_ipython_extension(ipython):
SerializationModule, "xml", "XML+RDF module", "XML+RDF") SerializationModule, "xml", "XML+RDF module", "XML+RDF")
jupyter_rdf.register_module( jupyter_rdf.register_module(
SPARQLModule, "sparql", "SPARQL module", "SPARQL") SPARQLModule, "sparql", "SPARQL module", "SPARQL")
jupyter_rdf.register_module(ShexModule, "shex", "ShEx module", "ShEx")
jupyter_rdf.register_module( jupyter_rdf.register_module(
GraphManagerModule, "graph", "Graph management module", "Graphman") GraphManagerModule, "graph", "Graph management module", "Graphman")
ipython.register_magics(jupyter_rdf) ipython.register_magics(jupyter_rdf)
from pyshex.utils.schema_loader import SchemaLoader
from pyshex import ShExEvaluator
from .rdf_module import RDFModule
class ShexModule(RDFModule):
def __init__(self, name, parser, logger, description, displayname):
super().__init__(name, parser, logger, description, displayname)
self.parser.add_argument(
"action", choices=["parse", "validate", "prefix"], help="Action to perform")
self.parser.add_argument(
"--label", "-l", help="Shape label for referencing")
self.parser.add_argument(
"--graph", "-g", help="Graph label for validation")
self.parser.add_argument(
"--focus", "-f", help="URI of node to focus on"
)
self.parser.add_argument(
"--start", "-s", help="Starting shape"
)
self.loader = SchemaLoader()
self.evaluator = ShExEvaluator()
self.prefix = ""
def print_result(self, result):
self.log(f"Evaluating shape '{result.start}' on node '{result.focus}'")
if result.result:
self.logger.print("PASSED!")
else:
self.logger.print(f"FAILED! Reason:\n{result.reason}\n")
def handle(self, params, store):
if params.action == "prefix":
self.prefix = params.cell + "\n"
self.log("Stored Prefix.")
elif params.action == "parse":
if params.cell is not None:
try:
schema = self.loader.loads(self.prefix + params.cell)
if params.label is not None and schema is not None:
store["rdfshapes"][params.label] = schema
self.log("Shape successfully parsed.")
except Exception as e:
self.log(f"Error during shape parse:\n{str(e)}")
else:
self.log("No cell content to parse.")
elif params.action == "validate":
if params.label is not None and params.graph is not None:
if params.label in store["rdfshapes"]:
if params.graph in store["rdfgraphs"]:
result = self.evaluator.evaluate(
store["rdfgraphs"][params.graph],
store["rdfshapes"][params.label],
start=params.start,
focus=params.focus
)
for r in result:
self.print_result(r)
else:
self.log(
f"Found no graph with label '{params.graph}'.")
else:
self.log(f"Found no shape with label '{params.label}'.")
else:
self.log("A shape and a graph label are required for validation.")
from IPython.display import display, display_pretty from IPython.display import display, display_pretty
from SPARQLWrapper import SPARQLWrapper from SPARQLWrapper import SPARQLWrapper
from cgi import parse_header
from .rdf_module import RDFModule from .rdf_module import RDFModule
from .graph import parse_graph, draw_graph from .graph import parse_graph, draw_graph
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment