diff --git a/notebooks/school_example.ipynb b/notebooks/school_example.ipynb new file mode 100644 index 0000000..ca98e6a --- /dev/null +++ b/notebooks/school_example.ipynb @@ -0,0 +1,135 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# This assumes that the notebook root is the PyShEx directory\n", + "!pip install -e .. --upgrade -q" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from rdflib import Graph, Namespace\n", + "from pyshex import ShExEvaluator, PrefixLibrary\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "schema = \"\"\"\n", + "PREFIX ex: \n", + "PREFIX xsd: \n", + "PREFIX school: \n", + "PREFIX foaf: \n", + "\n", + "school:enrolleeAge xsd:integer MinInclusive 13 MaxInclusive 20 \n", + "\n", + "school:Enrollee {\n", + " foaf:age @school:enrolleeAge ;\n", + " ex:hasGuardian IRI {1,2}\n", + "}\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "rdf = \"\"\"\n", + "PREFIX ex: \n", + "PREFIX inst: \n", + "PREFIX school: \n", + "PREFIX foaf: \n", + "\n", + "inst:Alice foaf:age 13 ; \n", + " ex:hasGuardian inst:Person2, inst:Person3 .\n", + "\n", + "inst:Bob foaf:age 15 ; \n", + " ex:hasGuardian inst:Person4 . \n", + "\n", + "inst:Claire foaf:age 12 ; \n", + " ex:hasGuardian inst:Person5 . \n", + "\n", + "inst:Don foaf:age 14 . \n", + "\n", + "inst:Eric foaf:age 20 ;\n", + " ex:hasGuardian inst:PersonA, inst:PersonB, inst:PersonC .\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "http://example.com/users/Alice: Passing\n", + "http://example.com/users/Bob: Passing\n", + "http://example.com/users/Claire: Failing\n", + "http://example.com/users/Don: Failing\n", + "http://example.com/users/Eric: Passing\n" + ] + } + ], + "source": [ + "p = PrefixLibrary(rdf)\n", + "for result in ShExEvaluator(rdf=rdf, \n", + " schema=schema, \n", + " focus=[p.INST.Alice, p.INST.Bob, p.INST.Claire, p.INST.Don, p.INST.Eric], \n", + " start=p.SCHOOL.Enrollee).evaluate():\n", + " print(f\"{result.focus}: {'Passing' if result.result else 'Failing'}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "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.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}