Scheme example files for noobs

From OpenCog
Jump to: navigation, search



This page recommends some Scheme files which are present in the OpenCog repository that may help people who are new to the AtomSpace understand the functions of several types of Nodes and Links. These files will have less abstract contents than the Scheme files you would find my randomly looking through the 300 Scheme files in the OpenCog folders.


How to browse and open Scheme files for viewing

Many of the Scheme (.scm) files in the OpenCog codebase will appear highly abstract to newcomers since they deal with coordinates or grammatical concepts which require familiarity with the context in which they were created. Some Scheme files however contain concepts that will be familiar to most humans, such as People, Attractiveness, Canadians and Dogs. To go to the folder that contains these files start in your opencog folder (/src/ochack if you've followed the other tutorials in the OpenCog for Noobs category and type

cd /tests/reasoning/pln/scm/new

To list the files by number of lines, type:

wc -l * | sort -n

And to see the contents of a file you can either use 'less':

less dog.scm

or gedit if you prefer something visual:

gedit dog.scm &

The & symbol makes sure you retain access to your terminal window while gedit is running.

The Lion-Tiger file

Let's take an in depth look at LionTigerAS.scm, the contents of which are shown below:

; define concepts. Note that PLN ignores atoms with (0,0) truth values.
(define lion (ConceptNode "Lion" (stv 0.5 0.999)))
(define tiger (ConceptNode "Tiger" (stv 0.5 0.999)))
; define properties
(define mammal (ConceptNode "Mammal"))
(define carnivor (ConceptNode "Carnivor"))
(define striped (ConceptNode "Striped"))
(define predator (ConceptNode "Predator"))
(define facingExtincion (ConceptNode "FacingExtincion"))
; define default confidence
(define dc 0.5)
; Properties of Lion
(SubsetLink (stv 1 dc) lion mammal)
(SubsetLink (stv 1 dc) lion carnivor)
(SubsetLink (stv 0 dc) lion striped)
(SubsetLink (stv 1 dc) lion predator)
(SubsetLink (stv 0.8 dc) lion facingExtincion)
; Properties of NOT Lion
(SubsetLink (stv 0.2 dc) (NotLink lion) mammal)
(SubsetLink (stv 0.1 dc) (NotLink lion) carnivor)
(SubsetLink (stv 0.17 dc) (NotLink lion) striped)
(SubsetLink (stv 0.3 dc) (NotLink lion) predator)
(SubsetLink (stv 0.4 dc) (NotLink lion) facingExtincion)
; Properties of Tiger
(SubsetLink (stv 1 dc) tiger mammal)
(SubsetLink (stv 1 dc) tiger carnivor)
(SubsetLink (stv 0.9 dc) tiger striped)
(SubsetLink (stv 1 dc) tiger predator)
(SubsetLink (stv 1 dc) tiger facingExtincion)
; Properties of NOT Tiger
(SubsetLink (stv 0.2 dc) (NotLink tiger) mammal)
(SubsetLink (stv 0.1 dc) (NotLink tiger) carnivor)
(SubsetLink (stv 0.15 dc) (NotLink tiger) striped)
(SubsetLink (stv 0.3 dc) (NotLink tiger) predator)
(SubsetLink (stv 0.37 dc) (NotLink tiger) facingExtincion)

Let's go through the sections one by one now, starting with the first two lines.

; define concepts. Note that PLN ignores atoms with (0,0) truth values.
(define lion (ConceptNode "Lion" (stv 0.5 0.999)))
(define tiger (ConceptNode "Tiger" (stv 0.5 0.999)))

These lines define Concept Nodes, which in the case above simply takes a string that describes the concept, followed by a Simple Truth Value.

The 'define' operator creates a temporary definition that can be reused within a single Scheme file, similar to a variable in other languages. So here we are saying that the variable 'lion' is something...