Skip to content

Commit

Permalink
Merge pull request #13 from SynBioDex/11-ontology_dependencies
Browse files Browse the repository at this point in the history
Ontology dependencies
  • Loading branch information
bbartley authored Jun 21, 2021
2 parents 2f09b19 + 267d08b commit 4cecc24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions sbol_factory/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@

class Query():

graph = rdflib.Graph()
graph.parse(posixpath.join(os.path.dirname(os.path.realpath(__file__)), 'rdf/sbol3.ttl'), format ='ttl')
OWL = rdflib.URIRef('http://www.w3.org/2002/07/owl#')
RDF = rdflib.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
SBOL = rdflib.URIRef('http://sbols.org/v2#')
OPIL = rdflib.URIRef('http://bioprotocols.org/opil/v1#')
RDFS = rdflib.URIRef('http://www.w3.org/2000/01/rdf-schema#')
XSD = rdflib.URIRef('http://www.w3.org/2001/XMLSchema#')
OM = rdflib.URIRef('http://www.ontology-of-units-of-measure.org/resource/om-2/')
graph.namespace_manager.bind('sbol', SBOL)
graph.namespace_manager.bind('opil', OPIL)
graph.namespace_manager.bind('owl', OWL)
graph.namespace_manager.bind('rdfs', RDFS)
graph.namespace_manager.bind('rdf', RDF)
graph.namespace_manager.bind('xsd', XSD)
graph.namespace_manager.bind('om', OM)

def __init__(self, ontology_path):
graph = rdflib.Graph()
graph.parse(ontology_path, format=rdflib.util.guess_format(ontology_path))
graph.parse(posixpath.join(os.path.dirname(os.path.realpath(__file__)), 'rdf/sbol3.ttl'), format ='ttl')
graph.namespace_manager.bind('sbol', Query.SBOL)
graph.namespace_manager.bind('opil', Query.OPIL)
graph.namespace_manager.bind('owl', Query.OWL)
graph.namespace_manager.bind('rdfs', Query.RDFS)
graph.namespace_manager.bind('rdf', Query.RDF)
graph.namespace_manager.bind('xsd', Query.XSD)
graph.namespace_manager.bind('om', Query.OM)
self.graph = graph
Query.graph.parse(ontology_path, format=rdflib.util.guess_format(ontology_path))
self.graph = Query.graph

def query_base_class(self, cls):
try:
Expand Down Expand Up @@ -80,6 +80,8 @@ def query_superclass(self, subclass):
if len(response) == 0:
raise Exception('{} has no superclass'.format(subclass))
if len(response) > 1:
for r in response:
print(str(r[0]))
raise Exception('{} has more than one superclass'.format(subclass))
for row in response:
superclass = str(row[0])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
description='Ontology-driven data modeling',
version='1.0a4',
install_requires=[
'sbol3==1.0a9',
'sbol3==1.0a10',
'rdflib>=5.0.0',
'rdflib-jsonld>=0.5.0',
'sparqlwrapper>=1.8.5',
Expand Down

0 comments on commit 4cecc24

Please sign in to comment.