Example #1
0
from opencog.atomspace import AtomSpace, TruthValue, Atom
from opencog.atomspace import types as t

a = AtomSpace()

TV = TruthValue(1, 1)
A = a.add_node(t.ConceptNode, 'A', TV)
B = a.add_node(t.ConceptNode, 'B', TruthValue(0.5, 1))
C = a.add_node(t.ConceptNode, 'C', TV)
AB = a.add_link(t.InheritanceLink, [A, B], TV)
BC = a.add_link(t.InheritanceLink, [B, C], TV)
AC = a.add_link(t.InheritanceLink, [A, C])

a.print_list()

import logic
from tree import *

target = tree_from_atom(AC)
chainer = logic.Chainer(a)
results = chainer.bc(target)

print '\n---------------------------\n'

print results
print AC
Example #2
0
atomspace = AtomSpace()
__init__(atomspace)
for item in [coreTypes, utilities, timeLinks, data]:
    load_scm(atomspace, item)

# initialize chainer
chainer = Chainer(atomspace,
                  stimulateAtoms=False,
                  allow_output_with_variables=True,
                  delete_temporary_variables=True)
for rule in create_temporal_rules(chainer):
    chainer.add_rule(rule)

if print_starting_contents:
    print('AtomSpace starting contents:')
    atomspace.print_list()

outputs_produced = 0

for i in range(0, num_steps):
    result = chainer.forward_step()

    output = None
    input = None
    rule = None
    if result is not None:
        atomspace_string = ""
        (rule, input, output) = result
        outputs_produced += 1

        print("\n----- [Output # {0}] -----".format(outputs_produced))
Example #3
0
                            log.debug("%s -> %s"%(atom_stack[i].name, uni_node_id))
                            tree.add_edge(atom_stack[i].name, uni_node_id)
                        else:
                            log.debug("%s -> %s"%(atom_stack[i].name, uni_link_id))
                            tree.add_edge(atom_stack[i].name, uni_link_id)
                            ## set the 'order' attribute
                        tree.get_node_attr(atom_stack[i].name).setdefault('order',-1)
                        tree.get_node_attr(atom_stack[i].name)['order'] += 1
                        order = tree.get_node_attr(atom_stack[i].name)['order']
                        if is_node:
                            tree.set_edge_attr(atom_stack[i].name, uni_node_id, order = order)
                        else:
                            tree.set_edge_attr(atom_stack[i].name, uni_link_id, order = order)
                        break

        ## deal with the last segment
        if tree.number_of_nodes() > 0:
            add_tree_to_atomspace(a, tree, root)
            tree.clear()
        log.info("loaded scm file sucessfully!" )
    except IOError:
        log.error("failed to read file %s "%filename )
        raise IOError
    else:
        f.close()

if __name__ == "__main__":
    a = AtomSpace()
    load_scm_file(a, "./examples/test_load_scm_file.scm")
    a.print_list()