Towards a Java Framework for Knowledge Representation and Inference

Arya MirSoftware and s/w Development

Apr 27, 2012 (6 years and 26 days ago)


The Knowledge Representation Package consist of a framework that implement several kinds of processing engines. The framework using a data structure based on the Blackboard pattern [2], is written in Java and has three main components: knowledge representation, knowledge repository and inference engine. It can be used for make reasoning in semantic networks, frames or rule based systems. In inference we propose an uniform representation for knowledge using rules. The inference engine allow to construct all first–order logic constructs.

Towards a Java Framework for Knowledge
Representation and Inference
University of Craiova,
Faculty of Mathematics and Computer Science
Abstract.The Knowledge Representation Package consist of a frame-
work that implement several kinds of processing engines.The framework
using a data structure based on the Blackboard pattern [2],is written in
Java and has three main components:knowledge representation,knowl-
edge repository and inference engine.It can be used for make reasoning
in semantic networks,frames or rule based systems.In inference we pro-
pose an uniform representation for knowledge using rules.The inference
engine allow to construct all first–order logic constructs.
AMS Classification.Primary:68R99,Secondary:68T30
Keywords:knowledge representation,inference,OOP,Java,blackboard
1 Motivation
It is probably safe to say that we will never have enough computing power to
solve the problems people really want to solve.These problems are complex and
multifaced,often requiring solutions that employ several kinds of representation
and reasoning mechanisms simultaneously.As computers become more powerful
and applications become more sophisticated,the complex problems of yesterday
are understood and solved,but there are always new problems that are even
more complex on the horizon.It is a never ending cycle.
What is needed in this kind of environment is a set of tools that enable soft-
ware developers the ability to represent knowledge about complex problems in
the application and to apply multiple reasoning mechanisms to that knowledge
in order to derive solutions.These tools must be designed in a such way that
they can evolve over long periods of time as software developers improve our
understanding of the problems they seek to solve and as their computing envi-
ronments become more powerful.The study of Artificial Intelligence (AI) and
Object-Orientation (OO) provide the technology for creating the right king of
tools for solving complex problems.
AI provides the means through wich applications represent knowledge about
complex problems and reason about that knowledge.OO provides the means
through which application components can be constructed so they are reusable
and maintainable.The complexity of the AI components are managed by the
powerful abstraction and layering facilities of OO language and methodologies.
2 Adrian GIURCA
OO technology also can be used to construct applications that can evolve over
time without succumbing to architectural entropy.Object-oriented architectures,
commonly known as frameworks,allow Ai components to be built in a such a
way that:
– they can rapidly integrated into applications with a minimum amount of
– they can be reused in multiple applications,eliminating the need for ”custom-
built” AI applications
– they retain their architectural integrity with less effort than AI subsystems
built using other types of architectures (functional,procedural,etc),allowing
for coherent system evolution.
2 The Blackboard Pattern
Our design choice is the Blackboard architectural pattern [2].In the following
we make a short description of the Blackboard pattern to motivate or choice.
The idea behind the Blackboard architecture is a collection of independent
programs that work cooperatively on a common data structure.Each programis
specialized for solving a particular part of the overall task,and all programs work
together on the solution.These specialized programs are independent of each
other.They do not call each other,nor is there a predetermined sequence for their
activation.Instead,the direction taken by the system is mainly determined by
the current state of progress.A central control component evaluates the current
state of processing and coordinates the specialized programs.This data-directed
control regime makes experimentation with different algorithms possible,and
allows experimentally-derived heuristics to control processing.The structure is
presented in figure 1.
2.1 Blackboard Component
The blackboard component provides a central data store for all hypotheses cre-
ated during analysis.The main functions are:
– Stores current state of the solution space
– Stores all control data
– Delivers requested data to the operating knowledge sources
– Since the Blackboard is essentially a shared memory repository,synchroniza-
tion techniques may be required for multiple writers and readers (multiple
knowledge sources)
2.2 Knowledge Source Component
Knowledge Sources are separate and independent systems that individually solve
parts of the problem in piecemeal fashion.Each knowledge source has a certain
area of ”expertise”,or at least ”focus”.In this they can be seen as ”specialists”.
Knowledge sources obtain data from the blackboard,and return hypotheses de-
veloped from the data.Each hypothesis is made up of things like:
Towards a Java Framework for Knowledge Representation and Inference 3
Fig.1.Blackboard Pattern [2]
4 Adrian GIURCA
– an abstraction level:the distance from the input
– an estimated confidence factor
– a time interval covered by the hypothesis
Also,knowledge sources are reactive in the sense that they react to changes in
the problem domain as rendered by the blackboard.
2.3 Control Component
The controller runs continually monitoring the state of the blackboard,and will
end processing whenever an ”acceptable” solution is found.The controller uses
heuristics to develop alternate strategies according to the current state of the
blackboard,and schedules knowledge sources based on the current strategy.He
activates each knowledge source when its scheduled time has arrived.
The controller can query a knowledge source to determine its estimated prob-
ability of success or its estimated time of execution,and can update its strategy
accordingly,often according to a user-delivered desired confidence level.
Often,a complete search of the solution space is not feasible.In this case,
algorithms must be developed that filter ”significant” information from ”noise”.
Adata-directed (but not driven) mechanismof coordinating or non–coordinating
subsystems uses opportunistic problem solving to provide some solution.Such
opportunistic analysis with multiple algorithms of various talents and biases may
produce heuristics that can be used to refine searches.
Using this pattern we have the followings advantages:
– Fault tolerant.
– Reusable.
– Allows for experimentation.
– Potential parallel execution,which can greatly enhance cost-effectiveness
over traditional message-based systems.
There exist also several disadvantages:
– Low testability.
– Solutions are variable in terms of quality and not guaranteed.
– Usually inefficient,costly in terms of execution.
Based on this pattern,our framework has three different views organized
around the type of functionality provided by the components in each view and
their collaborations.These views are:
– Knowledge Representation
– Knowledge Repository
– Inference Engine
The following sections will describe all of this views.
Towards a Java Framework for Knowledge Representation and Inference 5
3 Knowledge Representation
In the study of AI,knowledge representation is the combination of data struc-
tures and interpretive procedures that,if used correctly,will lead to ”knowl-
edgeable” behavior (see [1]).The types of knowledge represented in AI systems
– objects - AI systems typically reason about objects in the world around us.
– relationships - Real world objects interact with each other.These interactions
are characterized by relationships.
– events - We know about actions and events in the world and how they affect
objects and their relationships.
– instructions - Some types of knowledge describe how to do things.This may
involves ”scripts” that can be followed by computers or people.
– meta-knowledge - We also need to model knowledge about what we know.
We may need to know about the reliability of an information source or we
may need to be cognizant of out limitations when observing the world.
Given the above description of knowledge representation in AI terms,knowl-
edge representation in object-oriented terms is the reification of domain specific
knowledge into objects that can be manipulated by the framework and the clients
of the framework.In an object-oriented system,all types of knowledge is rep-
resented by objects or methods of objects.In our framework,the basic knowl-
edge (”atom of knowledge”) is an object that implement the AtomKnowledge
interface.This interface provides methods for identifying the knowledge atom
and serves as the placeholder whereby domain specific objects implementing the
AtomKnowledge interface can be managed.
The following interfaces and classes are designed:
– AtomKnowledge - This interface extends the Observable interface (see the
Observer pattern) by declaring additional methods for knowledge atomiden-
tification.Blackboard objects manage knowledge atoms through the AtomKnowledge
– AbstractAtomKnowledge - this abstract class partially implements the
AtomKnowledge interface and assimilates the Subject mixin class.
Subclasses of the AbstractAtomKnowledge abstract class must provide the
remaining functionality and structure to fully implement the AtomKnowledge
– ConcreteKnowledge - This concrete class represents a programmer defined
atom knowledge.This class extends the AbstractAtomKnowledge abstract
class by providing some kind of domain-specific functionality and structure
that models an atom of knowledge for that domain.Several examples will be
given in the next sections to illustrate howto extend the AbstractAtomKnowledge
class to create different types of knowledge atoms.
6 Adrian GIURCA
Fig.2.Knowledge Representation
3.1 Semantic Network
The first class in this example (SemanticLink) represents the links in a seman-
tic network.The SemanticLink class has a name to identify the link type,a
description which contains information about what the link represents,and a
SemanticNode node which makes up the other end of the link.
Example 1 (A Semantic link).
package semanticNetwork;
public class SemanticLink{
private String label;
private String description ="";
private SemanticNode node;
public SemanticLink(String label,
String description,
SemanticNode node){
public String getlabel(){
Towards a Java Framework for Knowledge Representation and Inference 7
return label;
public String getDescription(){
return description;
public SemanticNode getNode(){
return node;
public String toString(){
if (null!= node){
} else{
return null;
private void setLabel(String label)
throws IllegalArgumentException{
if (null!= label){
this.label = label;
} else{
new IllegalArgumentException("label cannot be null!");
private void setDescription(String description){
if (null!= description){
this.description = description;
private void setNode(SemanticNode node)
throws IllegalArgumentException{
if (null!= node){
this.node = node;
} else{
new IllegalArgumentException("node cannot be null!");
8 Adrian GIURCA
The second class in the example (SemanticNode) represents the nodes in a se-
mantic network.SemanticNode extends the AbstractAtomKnowledge abstract
class by adding a description which contains information about what the node
represents and a list of links which represent relationships between other nodes.
SemanticNode provides methods for accessing its information,including meth-
ods for accessing the individual links in the link list or iterating through the
entire list.
Example 2 (A Semantic Node).
package semanticNetwork;
import java.util.*;
public class SemanticNode extends AbstractAtomKnowledge{
private String description;
private List links;
public SemanticNode(String description,List links){
this.description = description;
public List getLinks(){
return links;
public String getDescription(){
return description;
public int getNoOfLinks(){
return links.length;
public SemanticLink getLink(int index){
if (index <= links.length-1){
return (SemanticLink)links.get(index);
} else{
return null;
public List getLinks(String label){
List result = new ArrayList();
Iterator i = links.iterator();
Towards a Java Framework for Knowledge Representation and Inference 9
while (i.hasNext()){
SemanticLink link = (SemanticLink);
if (link.getLabel() == label){
return result;
public List getLinkedNodes(){
List result = new ArrayList();
Iterator i = links.iterator();
while (i.hasNext()){
SemanticLink link = (SemanticLink);
return result;
public boolean setLink(SemanticLink link){
return this.links.add(link);
private void setLinks(List links){
Iterator i = links.iterator();
while (i.hasNext()){
SemanticLink link = (SemanticLink);
3.2 Frames
Frames are similar to semantic networks.In fact,frames can be used to model
semantic networks if they are structured in the right way.FrameData is an in-
terface class that combines the Clonable and Countable interfaces together to
provide the base interface of frame data objects.FrameBehavior is similar to
FrameData but it combines the Clonable,Countable,and Executable interface
together to provide the base interface of frame behavior objects.
The Frame class is created by implementing the FrameData interfaces and
extending the AbstractAtomKnowledge abstract class.Frame contains a map of
frame data objects and a map of frame behavior objects.Methods for accessing
individual objects in either map are provided as well as methods for iterating
over the whole map.
10 Adrian GIURCA
Fig.3.The Structure of Frames
The knowledge representation facilities provided by the framework instanti-
ate the Observer design pattern described in [3].The Observer design pattern
provides a means for notifying dependents of knowledge atoms of state changes.
In the figure 4 we present the structure of the framework notifications.
4 Knowledge Repository
A blackboard architecture also serves as a repository of knowledge in addition to
representing individual atoms of knowledge.This repository is often called the
blackboard or work area.The blackboard is the common area where knowledge
is read,written,and manipulated during the process of inference.The structure
is presented in the figure 5.
5 Inference Engine
Our inference engine enables the flexible construction of inference networks based
on rules for a wide variety of domains.The engine is possible to be extended
for other types of mechanisms.Formally,the inference engine allow to construct
all first–order logic constructs.Using the inference engine we have the following
Towards a Java Framework for Knowledge Representation and Inference 11
Fig.4.Object Notification
– Modularity.Groups of related rules can be interchanged without effecting the
overall structure of the system.They behave much like independent pieces
of knowledge.
– Uniformity.Imposes a uniform structure on the knowledge modelled by the
inference network.Since all knowledge must be encoded in a rule form,it
can often be more easily understood.
– Naturalness.Rules are a common way of expressing ”what to do” in a pre-
determined situations.
However,there are some liabilities:
– Inefficiency.Program execution is much more inefficient than in procedural
– Non-obvious flow control.It is hard to follow the flow of control through
the execution of inference networks.Algorithmic knowledge is not expressed
naturally in inference networks.
1.Barr,Avron and Edward A.Feigenbaum (eds.) The Handbook of Artificial Intel-
ligence,vol1,pp.144-145,Adison-Wesley Inc.1981.
2.Buschmann,Frank,Regine Meunier,Hans Rohnert,Peter Sommerland and
Michael Stal,Pattern Oriented Software Architecture:ASystemof Patterns,pp.71-
95,John Willey & Sons Ltd.,1996.
12 Adrian GIURCA
Fig.5.Knowledge Repository
Towards a Java Framework for Knowledge Representation and Inference 13
3.Gamma Erich,Richard Helm,Ralph Johnson and John Vlissides,Design Patterns:
Elements of Reusable Object-Oriented Software,pp.117-126,207-217,257-271,
293-303,Addison wesley,1995.