-
-
Save jbkoh/37fbec75d023eff23baeee0e7c721dd0 to your computer and use it in GitHub Desktop.
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
import rdflib | |
from rdflib import RDF, OWL, RDFS, Namespace | |
import owlready2 | |
BRICK_VERSION = '1.1.0' | |
BRICK = Namespace("https://brickschema.org/schema/{0}/Brick#".format(BRICK_VERSION)) | |
TAG = Namespace("https://brickschema.org/schema/{0}/BrickTag#".format(BRICK_VERSION)) | |
SKOS = Namespace("http://www.w3.org/2004/02/skos/core#") | |
def rereason(G, filename): | |
world = owlready2.World() | |
with open(filename,'wb') as f: | |
f.write(G.serialize(format='ntriples')) | |
on = world.get_ontology(f"file://./{filename}").load() | |
owlready2.sync_reasoner(world, infer_property_values =True) | |
G = world.as_rdflib_graph() | |
G.bind('rdf', RDF) | |
G.bind('owl', OWL) | |
G.bind('rdfs', RDFS) | |
G.bind('brick', BRICK) | |
G.bind('tag', TAG) | |
return G | |
g = rdflib.Graph() | |
g.parse('Brick.ttl', format='turtle') | |
expanded_g = rereason(g, 'Brick_inferred.n3') | |
q_prefix = """ | |
prefix brick: <https://brickschema.org/schema/1.1.0/Brick#> | |
prefix owl: <http://www.w3.org/2002/07/owl#> | |
""" | |
qstr = q_prefix + """ | |
select ?a where { | |
?a a brick:Quantity. | |
} | |
""" | |
for row in expanded_g.query(qstr): | |
print(row) | |
print('This should not print anything.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment