-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
135 additions
and
0 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,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 | ||
} |