from pyfactxx import coras from pyfactxx.coras.cli import load_and_parse import rdflib def extract_name(node): node = str(node) return node[node.find('#') + 1:] crs = coras.Coras() load_and_parse(crs, 'pizza.owl') crs.realise() print('\nNamed pizzas:') named_pizzas = crs.query('select ?p where { ?p . } order by ?p', scope='asserted') for pizza_row in named_pizzas: print (extract_name(pizza_row[0]), 'is', end=' ') pizza_types = crs.query('select ?c where { ' + pizza_row[0].n3() + ' ?c . ?c . } order by ?c', scope='inferred') 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')) if pizza_types == '': print('special') else: print(pizza_types) print('\nUnsatisfiable (inconsistent) classes:') nothing = crs.query('select ?n where { ?n . } order by ?p', scope='both') for row in nothing: print(extract_name(row[0]))