Skip to content

Commit c543dc9

Browse files
committed
Example for ISWC paper
1 parent 933b8b1 commit c543dc9

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

notebooks/school_example.ipynb

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 7,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# This assumes that the notebook root is the PyShEx directory\n",
10+
"!pip install -e .. --upgrade -q"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 8,
16+
"metadata": {
17+
"collapsed": true
18+
},
19+
"outputs": [],
20+
"source": [
21+
"from rdflib import Graph, Namespace\n",
22+
"from pyshex import ShExEvaluator, PrefixLibrary\n"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 9,
28+
"metadata": {
29+
"collapsed": true
30+
},
31+
"outputs": [],
32+
"source": [
33+
"schema = \"\"\"\n",
34+
"PREFIX ex: <http://ex.example/#>\n",
35+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n",
36+
"PREFIX school: <http://school.example/#>\n",
37+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n",
38+
"\n",
39+
"school:enrolleeAge xsd:integer MinInclusive 13 MaxInclusive 20 \n",
40+
"\n",
41+
"school:Enrollee {\n",
42+
" foaf:age @school:enrolleeAge ;\n",
43+
" ex:hasGuardian IRI {1,2}\n",
44+
"}\n",
45+
"\"\"\""
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 14,
51+
"metadata": {
52+
"collapsed": true
53+
},
54+
"outputs": [],
55+
"source": [
56+
"rdf = \"\"\"\n",
57+
"PREFIX ex: <http://ex.example/#>\n",
58+
"PREFIX inst: <http://example.com/users/>\n",
59+
"PREFIX school: <http://school.example/#>\n",
60+
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n",
61+
"\n",
62+
"inst:Alice foaf:age 13 ; \n",
63+
" ex:hasGuardian inst:Person2, inst:Person3 .\n",
64+
"\n",
65+
"inst:Bob foaf:age 15 ; \n",
66+
" ex:hasGuardian inst:Person4 . \n",
67+
"\n",
68+
"inst:Claire foaf:age 12 ; \n",
69+
" ex:hasGuardian inst:Person5 . \n",
70+
"\n",
71+
"inst:Don foaf:age 14 . \n",
72+
"\n",
73+
"inst:Eric foaf:age 20 ;\n",
74+
" ex:hasGuardian inst:PersonA, inst:PersonB, inst:PersonC .\n",
75+
"\"\"\""
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 16,
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"name": "stdout",
85+
"output_type": "stream",
86+
"text": [
87+
"http://example.com/users/Alice: Passing\n",
88+
"http://example.com/users/Bob: Passing\n",
89+
"http://example.com/users/Claire: Failing\n",
90+
"http://example.com/users/Don: Failing\n",
91+
"http://example.com/users/Eric: Passing\n"
92+
]
93+
}
94+
],
95+
"source": [
96+
"p = PrefixLibrary(rdf)\n",
97+
"for result in ShExEvaluator(rdf=rdf, \n",
98+
" schema=schema, \n",
99+
" focus=[p.INST.Alice, p.INST.Bob, p.INST.Claire, p.INST.Don, p.INST.Eric], \n",
100+
" start=p.SCHOOL.Enrollee).evaluate():\n",
101+
" print(f\"{result.focus}: {'Passing' if result.result else 'Failing'}\")"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {
108+
"collapsed": true
109+
},
110+
"outputs": [],
111+
"source": []
112+
}
113+
],
114+
"metadata": {
115+
"kernelspec": {
116+
"display_name": "Python 3",
117+
"language": "python",
118+
"name": "python3"
119+
},
120+
"language_info": {
121+
"codemirror_mode": {
122+
"name": "ipython",
123+
"version": 3
124+
},
125+
"file_extension": ".py",
126+
"mimetype": "text/x-python",
127+
"name": "python",
128+
"nbconvert_exporter": "python",
129+
"pygments_lexer": "ipython3",
130+
"version": "3.6.3"
131+
}
132+
},
133+
"nbformat": 4,
134+
"nbformat_minor": 2
135+
}

0 commit comments

Comments
 (0)