Skip to content
opcode81 edited this page May 9, 2013 · 1 revision

In the following, we describe only the most basic functionality of the library; there are many advanced functions that are not mentioned. For in-depth information, please refer to the source (probcog/python/datagen.py).

The datagen Jython library allows to conveniently build up a relational database, which can then be used for training or as an evidence database.

The first step is, of course, to import the library:

import datagen

World

An instance of the class World is used to represent the entire database (i.e. in logical terms, the domain of discourse).

world = datagen.World()

Objects

The entities that we add to our world are instances of Object (or of classes derived from this class). Entities are typed, so for every entity we instantiate, we provide the name of the type to which the entity belongs. For instance, we could create an object belonging to the type ''person'' using

o = datagen.Object("person")

To make an object part of the database, we add it to the world:

world.addObject(o)

This will add the object to a container in the world object that is specific to the type of the object.

Any object/entity will ultimately be referenced by some constant/identifier in the database. By default, the identifier is auto-generated, but we can also set it manually when constructing the object if need be:

o = datagen.Object("person", constantName="Alice")

Attributes

We can set an attribute of an object as follows

o.setAttr("height", "tall")

or alternatively using

o["height"] = "tall"

Attributes can be retrieved in the following ways:

height = o.getAttr("height")
height = o["height"]

Links

Objects can be linked to other objects as follows:

lnk = o.linkto("takesCourse", c)

In this example, we create a relation ''takesCourse'' that links the objects ''o'' and ''c'' (indicating that the person ''o'' takes the course ''c'').

The link object that is returned can be used to, for example, set attributes of the link:

lnk["grade"] = "A"

Attribute Generators

TO BE CONTINUED

Object Selectors

TO BE CONTINUED

Clone this wiki locally