Skip to main content

A RDFlib-backed minimalistic knowledge based for robotic application

Project description

KnowledgeCore is a RDFlib-backed minimalistic knowledge base, initially designed for robots (in particular human-robot interaction or multi-robot interaction). It features full ROS support.

It stores triples (like RDF/OWL triples), and provides an API accessible via a simple socket protocol.

pykb provides an idiomatic Python binding, making easy to integrate the knowledge base in your applications.

It integrates with the reasonable OWL2 RL reasoner to provide OWL2 semantics and fast knowledge materialisation.

Example

This example uses the ROS API (see below), with some Pythonic syntatic sugar:

from knowledge_core.api import KB

rospy.init_node("test_knowledge_base")

kb = KB()

def on_robot_entering_antonio_property(evt):
  print("A robot entered Antonio's %s: %s" (evt[0]["place"], evt[0]["robot"]))

kb += "ari rdf:type Robot"
kb += ["antonio looksAt ari", "ari isIn kitchen"]

kb.subscribe(["?robot isIn ?place", "?place belongsTo antonio", "?robot rdf:type Robot"], onRobotEnteringAntonioProperty)

kb += "kitchen belongsTo antonio"

# try as well:
# kb -= "antonio looksAt ari" to remove facts
# kb["* rdf:type Robot"] to query the knowledge base

rospy.spin()

will print:

` A robot entered Antonio's kitchen: ari `

Installation

KnowledgeCore only supports Python 3

Prerequisite

rdlib >= 6.0.0:

$ pip install rdflib

For reasoning (optional):

$ pip install reasonable

Installation

From pypi:

$ pip install knowledge_core

From source:

$ git clone https://github.com/severin-lemaignan/knowledge_core.git
$ cd knowledge_core
$ python setup.py install
$ knowledge_core

Documentation

You can use KnowledgeCore either as a server, accessible from multiple applications (clients), or in embedded mode (which does not require to start a server process, but is limited to one single client). Note that the embedded mode is only available for Python applications.

In both case, and if your application is written in Python, it is highly recommended to use pykb to interact the knowledge base.

Server mode

To start the knowledge base as a server, simply type:

$ knowledge_core

(run knowledge_core --help for available options)

Then:

import kb

with kb.KB() as kb:
    #...

See usage examples on the pykb page, or in the KnowledgeCore unit-tests.

Embedded mode

No need to start KnowledgeCore. Simply use the following code to start using the knowledge base in your code:

import kb

with kb.KB(embedded=True) as kb:
    #...

Interacting with KnowledgeCore from other languages

  • from C++: check liboro

  • from any other language: the communication with the server relies on a simply socket-based text protocol. Feel free to get in touch if you need help to add support for your favourite language!

ROS usage

To start:

rosrun knowledge_core knowledge_core

Then, knowledge_core exposes two topics, /kb/add_facts and /kb/remove_facts, to add/remove triples to the knowledge base. Both topics expect a simple string with 3 tokens separated by spaces (if the object is a literal string, use double quotes to escape it).

It also exposes the following services:

  • /kb/revise to add/remove facts using a synchronous interface

  • /kb/query to perform simple queries

  • /kb/sparql to perform complex queries (full SPARQL end-point)

  • /kb/events to subscribe to ‘events’ by providing a (set of) partially-bound triples. Calling the service returns an event id. Subscribe then to /kb/events/<id> to be notified everytime a new instance/class match the provided pattern

  • /kb/manage to manage the knowledge base (including eg clearing all the facts)

Features

Server-Client or embedded

KnowledgeCore can be run as a stand-alone (socket) server, or directly embedded in Python applications.

Multi-models

KnowledgeCore is intended for dynamic environments, with possibly several contexts/agents requiring separate knowledge models.

New models can be created at any time and each operation (like knowledge addition/retractation/query) can operate on a specific subset of models.

Each models are also independently classified by the reasoner.

Event system

KnowledgeCore provides a mechanism to subscribe to some conditions (like: an instance of a given type is added to the knowledge base, some statement becomes true, etc.) and get notified back.

Reasoning

KnowledgeCore provides RDFS/OWL reasoning capabilities via the reasonable reasoner.

See reasonable README for the exact level of support of the different OWL2 RL rules.

Transient knowledge

KnowledgeCore allows to attach ‘lifespans’ to statements: after a given duration, they are automatically collected.

[this functionality is currently disabled. Please open an issue of you need it urgently]

Ontology walking

KnowledgeCore exposes several methods to explore the different ontological models of the knowledge base. It is compatible with the visualization tool oro-view.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

KnowledgeCore-2.8.10.tar.gz (32.9 kB view details)

Uploaded Source

File details

Details for the file KnowledgeCore-2.8.10.tar.gz.

File metadata

  • Download URL: KnowledgeCore-2.8.10.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for KnowledgeCore-2.8.10.tar.gz
Algorithm Hash digest
SHA256 a4aafbbe67751c4662ccbdc7ce73b8a0311b9accab361bdceceee47c22030415
MD5 99fa7aa7f842724eba4a59ae26b6c72c
BLAKE2b-256 91cf923903eec772037019b8efe47dda4bf87e0b4efb474103bafd282da4e3bb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page