| 1 | |
| 2 | from pyfactxx import coras |
| 3 | from pyfactxx.coras.cli import load_and_parse |
| 4 | import rdflib |
| 5 | |
| 6 | |
| 7 | crs = coras.Coras() |
| 8 | load_and_parse(crs, 'people.rdf') |
| 9 | crs.realise() |
| 10 | |
| 11 | def test(scope): |
| 12 | cat_owners = crs.query('ask where {<http://cohse.semanticweb.org/ontologies/people#cat_owner> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://cohse.semanticweb.org/ontologies/people#cat_liker> }', scope=scope) |
| 13 | print("Cat owners like cats", list(cat_owners)) |
| 14 | |
| 15 | old_ladies = crs.query('ask where {<http://cohse.semanticweb.org/ontologies/people#old_lady> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://cohse.semanticweb.org/ontologies/people#cat_owner> }', scope=scope) |
| 16 | print("Old ladies own cats", list(old_ladies)) |
| 17 | |
| 18 | mad_cow = crs.query('ask where {<http://cohse.semanticweb.org/ontologies/people#mad_cow> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2002/07/owl#Nothing> }', scope=scope) |
| 19 | print("Mad cow does not exist", list(mad_cow)) |
| 20 | |
| 21 | pete = crs.query('ask where {<http://cohse.semanticweb.org/ontologies/people#Pete> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://cohse.semanticweb.org/ontologies/people#person> }', scope=scope) |
| 22 | print("Pete is a person", list(pete)) |
| 23 | |
| 24 | spike = crs.query('ask where {<http://cohse.semanticweb.org/ontologies/people#Spike> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://cohse.semanticweb.org/ontologies/people#animal> }', scope=scope) |
| 25 | print("Spike is an animal", list(spike)) |
| 26 | |
| 27 | print('\nWithout inferences:') |
| 28 | test('asserted') |
| 29 | |
| 30 | print('\nWith inferences:') |
| 31 | test('inferred') |