Adding New Atom Types

From OpenCog
Jump to: navigation, search

Many important atoms are both declarative and active: they can be used to declare knowledge, but also do things, when called upon. The prototypical example of this is the GreaterThanLink, which can be used to declare that one thing is greater than another. The axioms describing order are well-known: one can perform reasoning and inference with GreaterThanLink, because one knows what it means. It has a semantics to it. It's well-defined.

Yet, it is impossible to store all possible number-pairs in the AtomSpace. So if you need to know when some particular number is greater than some other number, you have to compute it algorithmically. So, GreaterThanLink does that too: under the covers, in hard-coded C++ code.

And so it goes. If you have some kind of data, and it describes knowledge, but the only way to describe it is with an algorithm, then you must create a new atom type for it, and you must write C++ code to implement it. (Sure call out to Python if you wish. Or ROS. Or your local GPU, cellphone tower of wifi hotspot.) Your new atom type can now be reasoned over, because it has a semantics, but it can also do useful computations, when needed.

Lesson Overview

This provides an example of how to add new custom atom types to the AtomSpace. Currently, the only way to add new custom types is to define their type hierarchy in an atom_types.script file, and then write C++ code that actually implements whatever it is that you want the atoms to do. Very roughly speaking, one atom type corresponds to one C++ class. You will typically create a handful of atom types that work together to accomplish some task.

Load the scheme file

Sanity check: During compilation, a scheme wrapper for the new atom types should have been created, in the build directory

./examples/atomtypes/example_types.scm

Now it's time to load the example_types scheme file. From a shell prompt (not from the cogserver prompt), pipe the example_types.scm into the cogserver: $ cat examples/atomtypes/example_types.scm | telnet localhost 17001

Use the new atom types. You should be at the 'guile>' prompt, and create some atoms:

   guile> (FooNode "asdf")
   (FooNode "asdf")

   guile> (define xxx (ListLink (FooNode "hee") (BarNode "haw")))

   guile> xxx
   (ListLink
      (FooNode "hee")
      (BarNode "haw")
   )

   guile>

That's all folks .. the rest is up to you.

Quiz

Issues

Unable to find libcustomtypes.so

Note that if libcustomtypes.io doesn't exist then its likely the examples haven't been built yet. Note the examples are not built by default when you build opencog. To build the examples, in the directory above execute: make examples or if you are in the examples directory simply execute: make.

Notes

Contact:(Yenat)

GIt https://github.com/opencog/opencog/tree/master/examples/atomtypes

  • We need a better example. Maybe, say, a ComplexNumberNode would be an OK toy example…