-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ontology_query_interface] Added a util fn that returns the names of …
…all properties
- Loading branch information
1 parent
89c9732
commit 199012c
Showing
1 changed file
with
12 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
|
||
import rdflib | ||
|
||
class URIRefConstants(object): | ||
RDF_TYPE = rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type') | ||
OWL_OBJECT_PROPERTY = rdflib.term.URIRef('http://www.w3.org/2002/07/owl#ObjectProperty') | ||
|
||
class OntologyQueryInterface(object): | ||
'''Defines an interface for interacting with an OWL knowledge base. | ||
|
@@ -14,12 +18,20 @@ class OntologyQueryInterface(object): | |
@contact [email protected] | ||
''' | ||
|
||
def __init__(self, ontology_file, class_prefix): | ||
self.knowledge_graph = rdflib.Graph() | ||
self.knowledge_graph.load(ontology_file) | ||
self.class_prefix = class_prefix | ||
self.ontology_url = ontology_file[0:ontology_file.rfind('/')] | ||
|
||
def get_object_properties(self): | ||
'''Returns a list with the names of all object properties in the ontology. | ||
''' | ||
return [self.__extract_class_name(triple[0]) for triple in self.knowledge_graph[:] | ||
if triple[1] == URIRefConstants.RDF_TYPE and \ | ||
triple[2] == URIRefConstants.OWL_OBJECT_PROPERTY] | ||
|
||
def is_instance_of(self, obj_name, class_name): | ||
'''Checks whether 'obj_name' is an instance of 'class_name'. | ||
|