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

Ontology to KB export, TBox/ABox modifications, unit tests, ontology interface usage examples #16

Merged
merged 70 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 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
199012c
[ontology_query_interface] Added a util fn that returns the names of …
alex-mitrevski Mar 7, 2020
c6e6e46
[ontology_query_interface] Added a fn for retrieving all subjects and…
alex-mitrevski Mar 8, 2020
0e0258d
[ontology_query_interface] Added a fn for retrieving the domain and r…
alex-mitrevski Mar 8, 2020
a9d19c1
[ontology_query_interface/get_property_domain_range] Inverse properti…
alex-mitrevski Mar 8, 2020
5508356
Added a script for performing a simple ontology export to the KB
alex-mitrevski Mar 8, 2020
58f8220
[ontology_query_interface] Added a util fn that returns the names of …
alex-mitrevski Mar 10, 2020
0189760
[ontology_query_interface] Added a fn that returns the class hierarch…
alex-mitrevski Mar 10, 2020
e689db2
Merge branch 'devel' of github.com:b-it-bots/mas_knowledge_base into …
alex-mitrevski Mar 10, 2020
b640c75
Remove duplicated Furniture class declaration
Sushant-Chavan Mar 12, 2020
e98e4cb
Fix class name typos in the ontology
Sushant-Chavan Mar 12, 2020
b5b8e61
Add methods to insert and remove class and property assertions
Sushant-Chavan Mar 12, 2020
fa80d6e
Add python script to load and insert assertions specified in a yaml file
Sushant-Chavan Mar 13, 2020
6241ec7
Rename aBoxYamlLoader class
Sushant-Chavan Mar 13, 2020
a6ad57d
Rebase Fixes
Sushant-Chavan Mar 13, 2020
e710fba
Cache loaded class and property names to speed up successive queries
Sushant-Chavan Mar 13, 2020
5939967
Add validation checks to detect TBox and ABox existence
Sushant-Chavan Mar 13, 2020
e4d6a80
Move definition of type-check functions before their usage in script
Sushant-Chavan Mar 13, 2020
cc38aea
Avoid using escape characters for printing double-quotes
Sushant-Chavan Mar 14, 2020
76eb6a0
Add a sample ontology representing a minimal apartment
Sushant-Chavan Mar 14, 2020
6134aff
Rename instances simple in the ontology
Sushant-Chavan Mar 14, 2020
0ce1525
Add unit tests to validate the ontology query interface APIs
Sushant-Chavan Mar 14, 2020
bffcf7b
Fix issues with the ontology query interface found from the unit tests
Sushant-Chavan Mar 14, 2020
30dee4f
Fix import path in the ABoxYAMLLoader script
Sushant-Chavan Mar 14, 2020
b0bcc80
Add Travis config
Sushant-Chavan Mar 14, 2020
8ed9680
Install bare bones ROS in Travis CI
Sushant-Chavan Mar 14, 2020
175f567
Remove commented code from sample ontology
Sushant-Chavan Mar 14, 2020
8186b2b
Remove unused variable
Sushant-Chavan Mar 15, 2020
b92dc74
Merge branch 'master' of github.com:b-it-bots/mas_knowledge_base into…
alex-mitrevski Mar 15, 2020
6c5b256
Merge branch 'devel' of github.com:b-it-bots/mas_knowledge_base into …
alex-mitrevski Mar 15, 2020
66e83d9
[ontology_query_interface] The class prefix can now - at least in pri…
alex-mitrevski Mar 16, 2020
efc3ba7
Add modified version of sample ontology that doesnt have a class_prefix
Sushant-Chavan Mar 17, 2020
aa6d7dc
Update class_name APIs to support no class_prefix
Sushant-Chavan Mar 17, 2020
ad61206
Update TBox insertion APIs to support no class_prefix
Sushant-Chavan Mar 17, 2020
55ccdfd
Remove "apartment" ontology declaration from the new sample ontology
Sushant-Chavan Mar 17, 2020
05a0741
Extend the unit tests to test ontology's that dont have class_prefix
Sushant-Chavan Mar 17, 2020
a7de72c
Update API documentation
Sushant-Chavan Mar 17, 2020
8f181d1
Extend unit tests for get_subclasses_of and get_parent_classes_of APIs
Sushant-Chavan Mar 19, 2020
fc7c2d4
Update the API to return immediate child/parent classes
Sushant-Chavan Mar 19, 2020
a0274ef
[scripts/export_ontology_to_kb] Error fixes; assertions are now indee…
alex-mitrevski Mar 19, 2020
a1ab402
Implement API to insert new class definitions
Sushant-Chavan Mar 15, 2020
96ff799
Implement API to insert new property definition
Sushant-Chavan Mar 15, 2020
77e0962
Add unit test to validate the insert_class_definition API
Sushant-Chavan Mar 15, 2020
688a324
Implement API in OntologyQueryInterface to get the types of a property
Sushant-Chavan Mar 15, 2020
6bfc0d2
Add unit test to validate the insert_property_definition API
Sushant-Chavan Mar 15, 2020
d7f2748
Rebase fixes to support ontology's without namespace
Sushant-Chavan Mar 18, 2020
3cc7ee8
Implement API to get a list of all properties associated with a class
Sushant-Chavan Mar 18, 2020
041cc42
Cleanup insert_class_definition API
Sushant-Chavan Mar 18, 2020
9ef589d
Implement APIs to remove class and property definitions
Sushant-Chavan Mar 18, 2020
e182818
Add unit-tests for new APIs
Sushant-Chavan Mar 19, 2020
5319d57
Update the OntologyQueryInterface APIs to fix errors found by unit-tests
Sushant-Chavan Mar 19, 2020
63434cb
Remove namespace param in the get_property_domain_range and cleanup code
Sushant-Chavan Mar 19, 2020
b8b4017
Add sample definitions YAML file
Sushant-Chavan Mar 19, 2020
b24b622
Implement TBoxYAMLLoader
Sushant-Chavan Mar 19, 2020
d7e3797
Add verbose flag in ABoxYAMLLoader
Sushant-Chavan Mar 19, 2020
0a95689
Code cleanup
Sushant-Chavan Mar 19, 2020
8e5af5c
Fix review findings
Sushant-Chavan Mar 20, 2020
ed5d802
Fix a typo
Sushant-Chavan Mar 20, 2020
abe065f
Started working on a notebook illustrating the usage of the ontology …
alex-mitrevski Mar 17, 2020
97df938
[examples/ontology_interface] Added examples for retrieving class dat…
alex-mitrevski Mar 17, 2020
b3dde8c
[examples/ontology_interface] Added examples for retrieving property …
alex-mitrevski Mar 17, 2020
e0ba6b0
[examples/ontology_interface] Added metadata for rendering the notebo…
alex-mitrevski Mar 17, 2020
842a0ad
[examples/ontology_interface] Added an example use of the export func…
alex-mitrevski Mar 17, 2020
f3b15a1
[examples/ontology_interface] Added examples for the newly added TBox…
alex-mitrevski Mar 20, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
.ipynb_checkpoints/
docs/html/*
docs/latex/*
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sudo: required

language: python

before_install:
# Install ROS
- sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list'
- sudo curl -sSL 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xC1CF6E31E6BADE8868B172B4F42ED6FBAB17C654' | sudo apt-key add -
- sudo apt-get update
- sudo apt-get install -y --no-install-recommends ros-kinetic-ros-base
- sudo rosdep init
- rosdep update
- sudo apt install -y --no-install-recommends python-rosinstall python-rosinstall-generator python-wstool build-essential python-catkin-tools ros-kinetic-roslint
- sudo pip install catkin_pkg empy
- source /opt/ros/kinetic/setup.bash
# Install RDFLib
- sudo pip install rdflib

install:
- cd ../ && mkdir -p catkin_ws/src
- cp -r mas_knowledge_base catkin_ws/src/
- cd catkin_ws && catkin init && cd src && catkin build
- source ../devel/setup.bash
- cd mas_knowledge_base

stages:
- test

jobs:
include:
- stage: test
script:
- python common/tests/ontology_query_interface_unit_tests.py
23 changes: 23 additions & 0 deletions common/assertions/test_apartment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class_assertions:
Male: [Alex, Sushant]
Female: [Argentina]
Room: [RopodLab, atWorkLab]
Chair: [AlexChair, ArgentinaChair, SushantChair]
HighTable: [RopodWorkDesk, atWorkDesk]
property_assertions:
defaultLocation:
AlexChair: RopodLab
ArgentinaChair: RopodLab
SushantChair: RopodLab
RopodWorkDesk: RopodLab
atWorkDesk: atWorkLab
locatedAt:
AlexChair: RopodLab
ArgentinaChair: RopodLab
SushantChair: atWorkLab
RopodWorkDesk: RopodLab
atWorkDesk: atWorkLab
nextTo:
AlexChair: RopodWorkDesk
ArgentinaChair: RopodWorkDesk
SushantChair: atWorkDesk
15 changes: 15 additions & 0 deletions common/definitions/test_apartment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class_definitions:
Person: []
Male: [Person]
Female: [Person]
Chair: [Furniture]
HighTable: [Furniture]
property_definitions:
nextTo:
domain: [None, Object]
range: [None, Object]
type: SymmetricProperty
age:
domain: [None, Person]
range: [xsd, integer]
type: None
151 changes: 151 additions & 0 deletions common/mas_knowledge_utils/abox_yaml_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import yaml
import argparse
import os
from mas_knowledge_utils.ontology_query_interface import OntologyQueryInterface

class ABoxYAMLLoader:
'''Updates an ontology with class and property assertions
that are specified in a yaml file.

Constructor arguments:
@param ontology_file -- full URL of an ontology file (of the form file://<absolute-path>)
@param ontology_class_prefix -- class prefix of the items in the given ontology
@param assertions_file -- absolute-path to the yaml file containing assertions
@param verbose -- boolean to enable debug console logging, which is disabled by default.

@author Sushant Chavan
@contact [email protected]

'''
def __init__(self, ontology_file, ontology_class_prefix, assertions_file, verbose=False):
self.ontology_if = OntologyQueryInterface(ontology_file=ontology_file,
class_prefix=ontology_class_prefix, verbose=verbose)
self.class_assertions = None
self.property_assertions = None
self.verbose = verbose

self.__load_assertions(assertions_file)

def update_ontology(self, export_path):
'''Inserts the class and property assertions and updates/exports the ontology.

Keyword arguments:
export_path -- string representing the filepath (of the form file://<absolute-path>)
if the ontology has to be exported to a new file.
If it is 'None', the loaded ontology will be updated with the assertions

'''
self.process_class_assertions()
self.process_property_assertions()
self.export_ontology(export_path)

def process_class_assertions(self):
'''Inserts the class assertions into the loaded ontology.

'''
if self.class_assertions is None:
return

for class_name in self.class_assertions.keys():
instance_names = self.class_assertions[class_name]
for instance_name in instance_names:
self.ontology_if.insert_class_assertion(class_name, instance_name)
self.__verbose("Inserting class assertion: {0}, {1}".format(
class_name, instance_name))

def process_property_assertions(self):
'''Inserts the property assertions into the loaded ontology.

'''
if self.property_assertions is None:
return

for property_name in self.property_assertions.keys():
for subj, obj in self.property_assertions[property_name].items():
self.ontology_if.insert_property_assertion(property_name, (subj, obj))
self.__verbose("Inserting property assertion: {0}, {1}, {2}".format(
subj, property_name, obj))

def export_ontology(self, export_path):
'''Updates/exports the ontology.

Keyword arguments:
export_path -- string representing the filepath (of the form file://<absolute-path>)
if the ontology has to be exported to a new file.
If it is 'None', the loaded ontology will be updated with the assertions

'''
if export_path is None:
# Overwrite the existing ontology file with the updated ontology
self.__verbose("No export filepath specified. Updating the loaded ontology.")
self.ontology_if.update()
else:
# Save the updated ontology at the given file location
self.__verbose("Exporting the ontology to {0}".format(export_path))
self.ontology_if.export(export_path)

def __load_assertions(self, assertions_file):
'''Loads the class and property assertions as two separate
dictionaries from the yaml file

Keyword arguments:
assertions_file -- absolute-path to the yaml file containing assertions

'''
assertions = None
with open(assertions_file, 'r') as f:
assertions = yaml.load(f, Loader=yaml.FullLoader)

if assertions is None:
raise Exception("Could not load the assertion file!")
else:
self.class_assertions = assertions['class_assertions']
self.property_assertions = assertions['property_assertions']

def __verbose(self, content):
'''Console debug logger to print the content along with the
'[ABoxYAMLLoader]' tag only if the self.verbose flag is set

Keyword arguments:
@param content -- string representing the content to be printed

'''
if self.verbose:
print("[ABoxYAMLLoader] {0}".format(content))

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('asserts', type=str,
help="Name of the yaml file containing the assertions \
(eg.: apartment_asserts)")
parser.add_argument('-o', '--ontology', type=str, action='store',
help="Filename of the ontology (default: apartment_go_2019)",
default='apartment_go_2019')
parser.add_argument('-c', '--class-prefix', type=str, action='store',
help="class prefix (or namespace) of the items in the \
given ontology (default: apartment)",
default='apartment')
parser.add_argument('-e', '--export-file', type=str, action='store',
help="Filename for exporting the updated ontology \
(eg.: apartment_go_2019_updated). If not \
specified, the loaded ontology will be updated.",
default=None)
parser.add_argument('-v', '--verbose', action='store_true',
help="Enable debug console logs")

args = parser.parse_args()

script_dir = os.path.abspath(os.path.dirname(__file__))
ontology_dir = os.path.join(os.path.dirname(script_dir), "ontology")
assertions_dir = os.path.join(os.path.dirname(script_dir), "assertions")

ontology_file_path = "file://" + os.path.join(ontology_dir, args.ontology + ".owl")
assertions_file_path = os.path.join(assertions_dir, args.asserts + ".yaml")

export_file_path = None
if args.export_file is not None:
export_file_path = "file://" + os.path.join(ontology_dir, args.export_file + ".owl")

loader = ABoxYAMLLoader(ontology_file_path, args.class_prefix,
assertions_file_path, verbose=args.verbose)
loader.update_ontology(export_file_path)
Loading