JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
  Previous Section Next Section

Knowledge Representation Formalisms

Languages can be created to define knowledge representations in a high-level fashion. These are known as KR formalisms. There are different KR formalisms used to represent knowledge because there are various kinds of knowledge. Knowledge can range from simple statements to complex relationships, including natural-language sentences and mathematical formulas, not forgetting meta-knowledge (knowledge about knowledge) and compound associations, or even hierarchies of inheritance between classes.

KR formalisms are just concepts, and rely on lower-level programming details to be implemented. Many different C++ constructs can be used to express the following formalisms.


Facts can be stored in a straightforward fashion as symbols. A symbol represents an object as a text string or number. Any primitive data type can be used (for instance, integers, floating-point numbers, Boolean, or character array):

[left_obstacle_distance 4.0]
[right_obstacle "unknown"]

In fact, it's believed humans store knowledge as symbols. The major problem with this approach is that each concept of the problem will need its own variable.


The object-attribute–value paradigm resolves this problem by allowing objects or concepts to have multiple variables associated with them. If an object O has an attribute A with value V, this is generally noted A(O,V):


This way, concepts can easily have multiple attributes, which limits the number of objects. C++ structures and classes are conceptually the same thing.


A frame defines an object by specifying its current state and relationship to other frames. This is achieved with slots containing attributes or references, often referred to as fillers:

     distance:        (4.0)
     present:         (true)
     entity:          (frame-fred)

Accessing the information about any concept is made extremely easy with this method. On the other hand, modifying it can be slightly trickier, because consistency often needs to be maintained. In C++, this could be understood as pointers or references to other instances.

Semantic Network

A semantic network stores relationships between the objects in a graph-like structure. Nodes correspond to a single concept, and the links describe the relationship (see Figure 9.1).

Figure 9.1. A semantic network that links symbols together. In this example, the symbols represent entities in the environment.


Common relationships include is-a, has-a, and instance-of, although there are no formalized restrictions to the type of links. Concepts such as inheritance or dependencies in C++ can be understood with semantic networks.

The Power of Introspection

The C++ language has analogous constructs for each of the formalisms presented. However, the C++ approach is generally static, so the higher-level knowledge is removed at compile time. For example, there's no way of knowing the name of a variable defined in the C++ code, or even query the inheritance tree between classes.

For the KR formalisms to have their maximal impact, they need to be implemented in a way that supports introspection—allowing the properties of the knowledge to be queried dynamically by the AI. This is possible with C++ by using additional variables to store the necessary information explicitly. When doing so, the KR formalisms previously described can be of great assistance.

      Previous Section Next Section

    JavaScript EditorAjax Editor     JavaScript Editor