OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
create_atoms_simple.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 #
3 # create_atoms_simple.py
4 #
5 """
6 A simple way of creating atoms in the AtomSpace.
7 See also create_stoms_by_type.py for an alternate API for atoms.
8 """
9 
10 from opencog.atomspace import AtomSpace, TruthValue, Atom
11 from opencog.atomspace import types
12 from opencog.type_constructors import *
13 
14 a = AtomSpace()
15 
16 # Tell the type constructors which atomspace to use.
17 set_type_ctor_atomspace(a)
18 
19 # Create a truth value asserting true and mostly confident.
20 TV = TruthValue(1, 0.8)
21 
22 # Add three nodes
23 # A = a.add_node(types.ConceptNode, 'Apple', TV)
24 # B = a.add_node(types.ConceptNode, 'Berry', TruthValue(0.5,1))
25 # C = a.add_node(types.ConceptNode, 'Comestible', TV)
26 A = ConceptNode('Apple', TV)
27 B = ConceptNode('Berry', TruthValue(0.5, 0.75))
28 C = ConceptNode('Comestible', TV)
29 
30 # Add three inhertance links, asserting that apples are berries
31 # and that berries are edible.
32 # AB = a.add_link(types.InheritanceLink, [A, B], TV)
33 # BC = a.add_link(types.InheritanceLink, [B, C], TV)
34 # AC = a.add_link(types.InheritanceLink, [A, C])
35 
36 AB = InheritanceLink(A, B, TV)
37 BC = InheritanceLink(B, C, TV)
38 AC = InheritanceLink(A, C)
39 
40 
41 print "The atomspace contains:\n\n", a.get_atoms_by_type(types.Atom)