Skip to content

Commit

Permalink
Example for ISWC paper
Browse files Browse the repository at this point in the history
  • Loading branch information
hsolbrig committed Apr 4, 2018
1 parent 933b8b1 commit c543dc9
Showing 1 changed file with 135 additions and 0 deletions.
135 changes: 135 additions & 0 deletions 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: <http://ex.example/#>\n",
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n",
"PREFIX school: <http://school.example/#>\n",
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>\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: <http://ex.example/#>\n",
"PREFIX inst: <http://example.com/users/>\n",
"PREFIX school: <http://school.example/#>\n",
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>\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
}

0 comments on commit c543dc9

Please sign in to comment.