.. _kbcomponent:
KBComponent
===========
Background
----------
In order to understand the design of the knowledge base component of the ELTK, we provide a brief explanation of how data and ontologies are used within knowledge engineering, especially in the context of `Description Logics `_ and related languages such as the Web Ontology Language (OWL). Knowledge bases in the Description Logic world consist of two logically separate components:
* the ontology proper (called the TBox)
* the various assertions about concepts from the ontology (called the ABox)
So, the standard description of such a knowledge base (KB) is KB = , where TBox is a set of classes and relations and ABox is a set of assertions about instances of classes. For example, the fact that ``all syntactic words are syntactic units`` belongs to the TBox. But some bit of knowledge, e.g., the formula describing that a particular syntactic word has a particular prefix, belongs in the ABox. Furthermore, since we're dealing with `Linked Data `_, the situation is a bit more complex. Namely, the TBox-ABox distinction is muddied since both sorts of statements can exist in a single Linked Data resource. To capture the mixing of TBox and ABox, we use the notion of a "KB component", which can contain either type. It can also contain TBox statements from different ontologies. This kind of assumption is built in to the RDF, Semantic Web architecture.
Chunks of knowledge
--------------------
.. automodule:: eltk.kb.KBComponent
.. autoclass:: eltk.kb.KBComponent.KBComponent
.. .. automethod:: eltk.kb.Ontology.Ontology.__init__(self,identifier='')
.. .. automethod:: eltk.kb.Ontology.Ontology.parse(self, source, publicID=None, format="xml")
.. .. automethod:: eltk.kb.Ontology.Ontology.addEntity(self,ent)
.. Access methods
.. --------------
.. Ontology has several methods to access its data:
.. .. automethod:: eltk.kb.Ontology.Ontology.getClasses(self)
.. .. automethod:: eltk.kb.Ontology.Ontology.getObjProp(self)
.. .. automethod:: eltk.kb.Ontology.Ontology.getDatatypeProp(self)
.. .. automethod:: eltk.kb.Ontology.Ontology.getIndividuals(self)
.. .. automethod:: eltk.kb.Ontology.Ontology.getEntity(self,uri)
Illustration of usage
---------------------
Here's how to create a knowledge base component: ::
>>> from eltk.kb.KBComponent import KBComponent
>>> from eltk.kb.Meta import *
Create the KBComponent, and then some classes and properties: ::
>>> mykb = KBComponent(URIRef('http://foo.org/myid'))
>>> Word = Meta.OWLClass.new(u'http://blah.org/Word')
>>> w = Word(u'w')
>>> hasConstituent = Meta.OWLObjectProperty.new(u'http://purl.org/linguistics/gold#hasConstituent')
>>> Morpheme = Meta.OWLClass.new(u'http://blah.org/Morpheme')
>>> m1 = Morpheme(u'http://blah.org/m1')
>>> m2 = Morpheme(u'http://purl.org/linguistics/gold#m2')
And add a statement to the KBComponent: ::
>>> mykb += (w, hasConstituent, m1)
The statement is in the form of a triple, and is equivalent to this: ::
>>> mykb += hasConstituent(w, m1)
See :doc:`meta` for an explanation of how particular instances of classes and properties are created.
.. Ontology
.. --------
.. .. autoclass:: eltk.kb.KBComponent.Ontology
Methods
-------
Here are the methods associated with KBComponent.
.. automethod:: eltk.kb.KBComponent.KBComponent.getOWLClasses
.. automethod:: eltk.kb.KBComponent.KBComponent.buildRDFGraph
.. automethod:: eltk.kb.KBComponent.KBComponent.getTermMeaning
.. automethod:: eltk.kb.KBComponent.KBComponent.renderJSON
Depending on the contents of a particular :class:`KBComponent`, several methods could be applicable.