Debian Codegraph @

FaCT++.Python/examples/test-pizza.py

raw symbols SCIP
1
2 from pyfactxx import coras
3 from pyfactxx.coras.cli import load_and_parse
4 import rdflib
5
6
7 def extract_name(node):
8 node = str(node)
9 return node[node.find('#') + 1:]
10
11 crs = coras.Coras()
12 load_and_parse(crs, 'pizza.owl')
13 crs.realise()
14
15
16 print('\nNamed pizzas:')
17 named_pizzas = crs.query('select ?p where { ?p <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza> . } order by ?p', scope='asserted')
18
19 for pizza_row in named_pizzas:
20 print (extract_name(pizza_row[0]), 'is', end=' ')
21
22 pizza_types = crs.query('select ?c where { ' + pizza_row[0].n3() + ' <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?c . ?c <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.co-ode.org/ontologies/pizza/pizza.owl#Pizza> . } order by ?c', scope='inferred')
23
24 pizza_types = ', '.join(extract_name(type_row[0]) for type_row in pizza_types if not isinstance(type_row[0], rdflib.BNode) and str(type_row[0]).endswith('Pizza') and not str(type_row[0]).endswith('NamedPizza'))
25
26 if pizza_types == '':
27 print('special')
28 else:
29 print(pizza_types)
30
31 print('\nUnsatisfiable (inconsistent) classes:')
32 nothing = crs.query('select ?n where { ?n <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Nothing> . } order by ?p', scope='both')
33 for row in nothing:
34 print(extract_name(row[0]))
35