Package: jupyter-rdfify
Jupyter-RDFifyIPython Extension for semantic web technology support (Turtle, SPARQL, ShEx, etc.)This extension is meant to be used together with Jupyter Notebooks for educational purposes. Its focus is neither performance nor scalability but instead ease-of-use.Teaching Semantic Web Technologies with Jupyter-RDFifyJupyter-RDFify was developed by theChair of Information Systems at RWTH Aachen Universityto support interactive teaching of Semantic Web Technologies. You can find an examplary set of tutorial-like Jupyter Notebooks using Jupyter-RDFify athttps://github.com/SemWebNotebooks/Notebooks/tree/main/Notebooksand further information on how to teach Semantic Web Technologies with Jupyter Notebooks, Jupyter-RDFify, the Moodle elearning system and automatic grading athttps://github.com/SemWebNotebooks/Notebooks.Information concerning rdflib-jsonld warningDeprecationWarning: The rdflib-jsonld package has been integrated into rdflib as of rdflib==6.0.0.  Please remove rdflib-jsonld from your project's dependencies.You may get this deprecation warning when loading the extension. This is the fault of SPARQLWrapper which jupyter-rdfify depends on. It will stop appearing as soon as SPARQLWrapper removes json-ld from its dependencies. You can safely ignore this warning.InstallationInstall using Pippython -m pip install jupyter-rdfifyInstall from Source using Pippython -m pip install git+https://github.com/SemWebNotebooks/Jupyter-RDFifyDependenciesYou will need to haveGraphvizinstalled and added to your path.If you're using Anaconda, you can install the Graphviz binaries using conda:conda install -c conda-forge graphvizUsageBasic UsageYou first need to use the predefined%load_extor%reload_extmagic to load Jupyter-RDFify. You need to do this each time your kernel is restarted.%load_ext jupyter-rdfifyIf you've installed the extension correctly, this should register the%rdfmagic. This magic is special in that it is interpreted like a command line interface. If at any point you're wondering what arguments there are and what they do, do not hesitate to use the --help or -h flag.To list all submodules:%rdf --helpTo list all arguments of the Turtle submodule:%rdf turtle --helpSubmodulesJupyter-RDFify is split into several submodules. Select the submodule you want using%rdf <submodule>Graph Serialization SubmodulesThese submodules allow you to parse and then visualize or convert graphs. The following graph serialization modules are provided by default: turtle, n3, json-ld, xmlVisualizationTo parse and visualize a graph, just use the%%rdfcell magic with the right submodule. For example to visualize a graph in Turtle notation:%%rdfturtle@prefix:<http://example.org/>.:JupyterRDF:is:Awesome.If this throws an error you probably do not have Graphviz installed. If you do not want to use the visualization, just use--display noneor--display table.ConversionTo parse and convert a graph into a different format, use a combination of--display rawand--serialize <format>. Possible formats are: turtle, n3, json-ld, xmlTo convert a graph in Turtle notation to JSON-LD notation:%%rdfturtle--displayraw--serializejson-ld@prefix:<http://example.org/>.:JupyterRDF:is:Awesome.LabellingAfter parsing a graph, you may want to give it a label. You can later use this label to reference your graph in other submodules. With this you can for instance query, validate, draw or entail your graph later on. To give your graph a label just use the--label <label>or-l <label>argument.%%rdfturtle--labelawesome_graph@prefix:<http://example.org/>.:JupyterRDF:is:Awesome.The special labellastwill always hold the last object, even if no--labelargument was supplied.SPARQL SubmoduleYou can use the SPARQL submodule to query existing endpoints or to query local graphs.Query SPARQL EndpointsUse the--endpointargument to query an endpoint. An example using theWikidataendpoint:%%rdfsparql--endpointhttps://query.wikidata.org/sparqlSELECT?item?itemLabelWHERE{?itemwdt:P31wd:Q146.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}LIMIT10Query Local GraphsYou can querylabelledgraphs using the--local <label>argument. Note that this overrides the endpoint argument.Example querying the above labelled graph:%%rdfsparql--localawesome_graphPREFIX:<http://example.org/>SELECT?xWHERE{?x:is:Awesome}ShEx SubmoduleWith this submodule, you can validate graphs using theShExlanguage. You first need to parse a schema:%%rdfshexparse--labelawesome_schemaPREFIX:<http://example.org/>:AwesomeShape{:is[:Awesome]}We already gave the schema alabelto reference it later. Note that graph labels and schema labels use different namespaces and do not overwrite each other.To validate a graph, we need to provide the schema label (--label), the graph label (--graph) of the graph we want to validate against the schema and at least a starting shape (--start). This will check every node of the graph against the starting shape. If we want to focus on a specific node in the graph, we can use the--focusargument. To validate theawesome_graphagainst theawesome_schema, starting from the:AwesomeShapeand focussing on the:JupyterRDFnode:%rdf shex validate --label awesome_schema --graph awesome_graph --start http://example.org/AwesomeShape --focus http://example.org/JupyterRDFOther FeaturesPrefixesAs many of the languages/formats use prefix declarations and these usually just distract from the actual task, most submodules lets you outsource them. Using either the--prefixflag or theprefixaction (only for ShEx submodule), you can define a string which gets prepend to every cell magic of that submodule. A simple example for Turtle which defines some very frequent prefixes:%rdfturtle--prefix@prefixrdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.@prefixrdfs:<http://www.w3.org/2000/01/rdf-schema#>.@prefixxsd:<http://www.w3.org/2001/XMLSchema#>.Graph ManagerThe graph manager submodule lets you list, draw, entail and delete labelled graphs. You just need to specify the action and usually a graph label. To draw orawesome_graph:%rdf graph draw --label awesome_graphEntailmentUsingOWL-RL, you can generate the finite closure of a graph under either RDFS semantics, OWL-RL semantics or both. This uses a brute-force approach, so it may easily take a long time or fail for large graphs. You can either entail a parsed graph directly using the--entail <regime>argument or entail a labelled graph later using the graph manager:%rdf graph entail-<regime> --label awesome_graphFor now you can only entail graphs in-place. Possible values for <regime>: rdfs, owl, rdfs+owlDependenciesNote that these dependencies will be installed automatically if you use Pip.RDFLib: The heart of this extensionRDFLib-jsonld: Extension of RDFLib for JSON-LDSPARQLWrapper: Extension of RDFLib for SPARQLOWL-RL: Library for RDFS and OWL-RL entailmentPyShEx: Implementation of ShExGraphviz python wrapperIPython