Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End-of-2020 stable version #40

Merged
merged 29 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1fa4391
[domestic_kb_interface/get_obj_category_map] cat -> class
alex-mitrevski Jan 26, 2020
73bdb91
[apartment.owl] Added properties for pose definitions
alex-mitrevski Jan 29, 2020
fcf6cb0
[apartment.owl] Added a Thing superclass
alex-mitrevski Jan 29, 2020
5c998e9
[apartment.owl] Added a NamedPose class and a pose property
alex-mitrevski Jan 29, 2020
15edd06
[apartment.owl] Added a GraspingStrategy class
alex-mitrevski Jan 29, 2020
4d8d643
[apartment.owl] Fixed various subclass axiom errors
alex-mitrevski Jan 29, 2020
c47c625
Merge branch 'master' of github.com:b-it-bots/mas_knowledge_base into…
alex-mitrevski Jan 29, 2020
b92dc74
Merge branch 'master' of github.com:b-it-bots/mas_knowledge_base into…
alex-mitrevski Mar 15, 2020
7c0c961
Merge branch 'master' of github.com:b-it-bots/mas_knowledge_base into…
alex-mitrevski Mar 20, 2020
7a648f4
[kb_interface] Added a fn that retrieves all objects of a given type
alex-mitrevski Apr 29, 2020
e7a41b0
[domestic_kb_interface] Added a fn that retrieves all objects of a ty…
alex-mitrevski Apr 29, 2020
919a298
[kb_interface] Added fns for adding and removing instances to/from th…
alex-mitrevski May 1, 2020
859e3a0
[export_ontology_to_kb] Object instances are now also added to the KB
alex-mitrevski May 1, 2020
d79f6e5
Kitchen and Food related classes added
samuelpg May 2, 2020
9ee7873
[otology/homelab] Added Food and Kitchen related classes
samuelpg May 2, 2020
274ac7a
[ontology/apartment] Made apartment.owl consistent with homelab.owl
samuelpg May 2, 2020
ad8650d
Removed local paths
samuelpg May 3, 2020
bb3924c
[ontology_query_interface] Added utility fns for checking if a class …
alex-mitrevski May 3, 2020
811e7ff
[export_ontology_to_kb] Fixed an issue with instances being exported …
alex-mitrevski May 3, 2020
b5cae12
[ontology_query_interface_tests] Added tests for 'is_subclass_of' and…
alex-mitrevski May 3, 2020
db73000
Merge remote-tracking branch 'upstream/master'
samuelpg May 4, 2020
d02546c
Merge pull request #33 from samuelpg/master
alex-mitrevski May 4, 2020
196de1f
[apartment/homelab.owl] Removed the xml:base and xmlns attributes fro…
alex-mitrevski May 5, 2020
9dfc672
[kb_interface] Added a mongodb store client for permanent data
alex-mitrevski Aug 15, 2020
853e2f4
[domestic_kb_interface] Added a function for recognising people given…
alex-mitrevski Aug 16, 2020
0834a9d
[domestic_kb_interface/recognise_person] Calculating avg embedding di…
alex-mitrevski Aug 16, 2020
68e09f0
[domestic_kb_interface/recognise_person] Return None if there are no …
alex-mitrevski Aug 20, 2020
72cca08
[domestic_kb_interface/recognise_person] Return None if the face of t…
alex-mitrevski Aug 22, 2020
f14e810
[README] Added a Travis badge
alex-mitrevski Sep 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.com/b-it-bots/mas_knowledge_base.svg?branch=master)](https://travis-ci.com/github/b-it-bots/mas_knowledge_base)

# ``mas_knowledge_base``

# Table of Contents
Expand Down
78 changes: 54 additions & 24 deletions common/mas_knowledge_utils/ontology_query_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,36 @@ def is_instance_of(self, obj_name, class_name):
return obj_name in self.get_instances_of(class_name)
return False

def is_subclass_of(self, class1, class2):
'''Returns True if class1 is a subclass of class2; returns False otherwise.
Raises a ValueError if either class1 or class2 is not a valid class in the ontology.

Keyword arguments:
class1: str -- name of a class
class2: str -- name of a hypothesised parent class

'''
if not self.is_class(class1):
raise ValueError('"{0}" does not exist as a class in the ontology!'.format(class1))
if not self.is_class(class2):
raise ValueError('"{0}" does not exist as a class in the ontology!'.format(class2))
return class1 in self.get_subclasses_of(class2)

def is_parent_class_of(self, class1, class2):
'''Returns True if class1 is a parent class of class2; returns False otherwise.
Raises a ValueError if either class1 or class2 is not a valid class in the ontology.

Keyword arguments:
class1: str -- name of a class
class2: str -- name of a hypothesised subclass

'''
if not self.is_class(class1):
raise ValueError('"{0}" does not exist as a class in the ontology!'.format(class1))
if not self.is_class(class2):
raise ValueError('"{0}" does not exist as a class in the ontology!'.format(class2))
return class2 in self.get_subclasses_of(class1)

def get_class_hierarchy(self):
'''Returns a dictionary in which each key is a class and the value
is a list of subclasses of that class. The dictionary thus represents
Expand Down Expand Up @@ -153,7 +183,7 @@ def get_subclasses_of(self, class_name, only_children=False):

Keyword arguments:
@param class_name -- string representing the name of a class
@param only_children -- boolean if set to True, only the immediate
@param only_children -- boolean if set to True, only the immediate
children of class_name will be returned

'''
Expand All @@ -173,7 +203,7 @@ def get_parent_classes_of(self, class_name, only_parents=False):

Keyword arguments:
@param class_name -- string representing the name of a class
@param only_parents -- boolean if set to True, only the immediate
@param only_parents -- boolean if set to True, only the immediate
parents of class_name will be returned

'''
Expand All @@ -196,8 +226,8 @@ def get_subjects_of(self, prop, obj):

Keyword arguments:
@param prop -- string representing the name of a property
@param object -- string representing an entity in the ontology.
This could either be an instance of a class or a value
@param object -- string representing an entity in the ontology.
This could either be an instance of a class or a value
of a specific data-type (such as a float).

'''
Expand Down Expand Up @@ -284,7 +314,7 @@ def get_property_domain_range(self, prop):
raise ValueError('"{0}" does not exist as a property in the ontology!'.format(prop))

def get_property_types(self, prop):
'''Returns a list that specifies the types (such as FunctionalProperty)
'''Returns a list that specifies the types (such as FunctionalProperty)
defined for the property.

Keyword arguments:
Expand All @@ -303,7 +333,7 @@ def get_property_types(self, prop):
raise ValueError('"{0}" does not exist as a property in the ontology!'.format(prop))

def get_associated_properties(self, class_name):
'''Returns a list of properties that contain the class name either as
'''Returns a list of properties that contain the class name either as
the domain or the range of the property.

Keyword arguments:
Expand All @@ -318,8 +348,8 @@ def get_associated_properties(self, class_name):
return associated_properties

def insert_class_definition(self, class_name, parent_class_names=[]):
'''Defines a new class in the ontology. If the class_name already exists,
and new parent classes are passed, only the sub_class relations between
'''Defines a new class in the ontology. If the class_name already exists,
and new parent classes are passed, only the sub_class relations between
the class_name and new parent classes are established.

Keyword arguments:
Expand All @@ -343,7 +373,7 @@ def insert_class_definition(self, class_name, parent_class_names=[]):
self.knowledge_graph.add((class_uri, rdflib.RDFS.subClassOf,
parent_class_uri))

# Reset class names list to ensure that the newly added
# Reset class names list to ensure that the newly added
# class is included in the next query to the class_list
self.__class_names = None

Expand All @@ -354,10 +384,10 @@ def insert_property_definition(self, property_name, domain, range,
Keyword arguments:
property_name -- string representing the name of the new property
domain -- string representing the domain of the new property
range -- string representing the range of the new property.
range -- string representing the range of the new property.
This could be a class or a data type (such as float)
prop_type -- string/None representing the type (such as FunctionalProperty).
If 'None', the property will have only the default ObjectProperty
prop_type -- string/None representing the type (such as FunctionalProperty).
If 'None', the property will have only the default ObjectProperty
type and no additional type will be added.
domain_ns -- string representing the optional namespace for the domain.
By default the class_prefix is used as the namespace.
Expand Down Expand Up @@ -392,7 +422,7 @@ def insert_property_definition(self, property_name, domain, range,
self.knowledge_graph.add((prop_uri, URIRefConstants.RDF_TYPE,
prop_type_uri))

# Reset property names list to ensure that the newly added
# Reset property names list to ensure that the newly added
# property is included in the next query to the property_list
self.__property_names = None

Expand Down Expand Up @@ -420,7 +450,7 @@ def insert_property_assertion(self, property_name, instance):
Keyword arguments:
property_name -- string representing the name of the predicate
instance -- tuple(string, string) representing the subject and the object respectively.
While the subject has to be an instance of a class, the object could be
While the subject has to be an instance of a class, the object could be
an instance of a class or a value of a data-type (such as float)

'''
Expand All @@ -434,9 +464,9 @@ def insert_property_assertion(self, property_name, instance):
rdflib.URIRef(self.__get_entity_url(instance[1]))))

def remove_class_definition(self, class_name):
'''Removes an existing class from the ontology.
Additionally, also removes all instances of this class and
all property definitions which contain this class as domain/range and
'''Removes an existing class from the ontology.
Additionally, also removes all instances of this class and
all property definitions which contain this class as domain/range and
all their assertions

Keyword arguments:
Expand Down Expand Up @@ -479,7 +509,7 @@ def remove_class_definition(self, class_name):
self.__verbose('Class "{0}" successfully removed from ontology'.format(class_name))

def remove_property_definition(self, property_name):
'''Removes an existing property from the ontology
'''Removes an existing property from the ontology
along with all its assertions

Keyword arguments:
Expand Down Expand Up @@ -527,7 +557,7 @@ def remove_property_assertion(self, property_name, instance):
Keyword arguments:
property_name -- string representing the name of the predicate
instance -- tuple(string, string) representing the subject and the object respectively.
While the subject has to be an instance of a class, the object could be
While the subject has to be an instance of a class, the object could be
an instance of a class or a value of a data-type (such as float)

'''
Expand Down Expand Up @@ -602,14 +632,14 @@ def __get_entity_uriref(self, entity):
return rdflib.URIRef(self.__get_entity_url(entity))

def __extract_class_name(self, rdf_class, delimiter=':'):
'''Extracts the name of a class given a string of the format
"class_prefix:class_name" or "class_prefix#class_name".
However, if the rdf_class is a URL the function returns the last
'''Extracts the name of a class given a string of the format
"class_prefix:class_name" or "class_prefix#class_name".
However, if the rdf_class is a URL the function returns the last
element in the URL as the class name

Keyword arguments:
@param rdf_class -- string of the form "prefix:class"
@param delimiter -- char representing the delimiter between the
@param delimiter -- char representing the delimiter between the
class_prefix and the class_name

'''
Expand All @@ -629,7 +659,7 @@ def __extract_obj_name(self, obj_url):
return obj_url[obj_url.rfind('/')+1:]

def __is_url(self, rdf_class):
'''Returns True if the rdf_class is specified as a URL and False if the
'''Returns True if the rdf_class is specified as a URL and False if the
rdf_class is specified in the form of class_prefix:class_name

Keyword arguments:
Expand Down
Loading