コード例 #1
0
 def test_add_atom_from_grounded_schema_node(self):
     test_as = AtomSpace()
     execute_atom(test_as,
             ExecutionOutputLink(
                 GroundedSchemaNode("py:add_new_link"),
                 ListLink()
             )
         )
     self.assertTrue(test_as.is_link_in_atomspace(types.InheritanceLink,
         [test_as.add_node(types.ConceptNode, "cat"),
         test_as.add_node(types.ConceptNode, "animal")]))
コード例 #2
0
ファイル: utils.py プロジェクト: opencog/rocca
def get_context_actual_truth(atomspace, cogscm, i):
    """Calculate tv of the context of cognitive schematic cogscm at time i.

    Given a cognitive schematic of that format

    PredictiveImplicationScope <tv>
      <vardecl>
      <expiry>
      And (or SimultaneousAnd?)
        <context>
        Execution
          <action>
          <input> [optional]
          <output> [optional]
      <goal>

    calculate the truth value of <context> at time i, where the
    variables have been properly instantiated.

    For now the calculation is crisp, either a context is completely
    true (stv 1 1) or completely false (stv 0 1).

    """

    # Build and run a query to check if the context is true
    vardecl = get_vardecl(cogscm)
    present_clauses, virtual_clauses = get_context(cogscm)
    stamped_present_clauses = [timestamp(pc, i) for pc in present_clauses]
    body = AndLink(PresentLink(*stamped_present_clauses),
                   IsClosedLink(*stamped_present_clauses),
                   IsTrueLink(*stamped_present_clauses),
                   *virtual_clauses)
    query = SatisfactionLink(vardecl, body)
    tv = execute_atom(atomspace, query)
    return tv
コード例 #3
0
 def test_too_few_args(self):
     atom1 = ConceptNode("atom1")
     exec_link = ExecutionOutputLink(
         GroundedSchemaNode("py:return_concept"), ListLink())
     try:
         result = execute_atom(self.space, exec_link)
         self.assertFalse("call should fail")
     except RuntimeError as e:
         self.assertTrue("missing 1 required positional argument" in str(e))
コード例 #4
0
 def test_too_many_args(self):
     atom1 = ConceptNode("atom1")
     exec_link = ExecutionOutputLink(
         GroundedSchemaNode("py:return_concept"), ListLink(atom1, atom1))
     try:
         result = execute_atom(self.space, exec_link)
         self.assertFalse("call should fail")
     except RuntimeError as e:
         self.assertTrue("but 2 were given" in str(e))
コード例 #5
0
ファイル: test_bindlink.py プロジェクト: manisabri/atomspace
    def test_tmp_atomspace(self):
        ListLink(ConceptNode("foo"), ConceptNode("bar"))

        get = GetLink(VariableNode("x"),
                AndLink(
                    PresentLink(ListLink (ConceptNode("foo"),
                                          (VariableNode("x")))),
                    EvaluationLink(GroundedPredicateNode("py: test_functions.func_one"),
                        ListLink(VariableNode("x"))),
                   EvaluationLink(GroundedPredicateNode( "py: test_functions.func_two"),
                   ListLink (VariableNode ("x")))))
        result = execute_atom(self.atomspace, get)
        self.assertFalse(result.out)
        self.assertFalse(self.atomspace.is_node_in_atomspace(types.ConceptNode, 'barleycorn'))
        test_functions.func_one_result = TruthValue(1,1)
        result = execute_atom(self.atomspace, get)
        self.assertTrue(result.out)
        # still should not be in the current namespace
        self.assertFalse(self.atomspace.is_node_in_atomspace(types.ConceptNode, 'barleycorn'))
コード例 #6
0
    def test_do_execute_value(self):
        key = PredicateNode("key")
        atom = ConceptNode("atom")
        atom.set_value(key, FloatValue([1, 2, 3]))

        value_of_link = ValueOfLink(atom, key)

        value = execute_atom(self.atomspace, value_of_link)
        self.assertEqual(FloatValue([1, 2, 3]), value)
        self.assertEqual([1, 2, 3], value.to_list())
コード例 #7
0
ファイル: test_atom.py プロジェクト: manisabri/atomspace
 def test_grounded_cond(self):
     grounded_cond = CondLink(
         EvaluationLink(GroundedPredicateNode("py:grounded_cond1"),
                        ListLink()), NumberNode('1'),
         EvaluationLink(GroundedPredicateNode("py:grounded_cond2"),
                        ListLink()), NumberNode('2'))
     result = execute_atom(self.space, grounded_cond)
     baz = NumberNode("2")
     print("got %s", result)
     print("expected %s\n", baz)
     self.assertTrue(result == baz)
コード例 #8
0
ファイル: test_bindlink.py プロジェクト: manisabri/atomspace
 def test_execute_atom(self):
     result = execute_atom(self.atomspace,
             ExecutionOutputLink(
                 GroundedSchemaNode("py: test_functions.add_link"),
                 ListLink(
                     ConceptNode("one"),
                     ConceptNode("two")
                 )
             )
         )
     list_link = ListLink(
             ConceptNode("one"),
             ConceptNode("two")
         )
     self.assertEquals(result, list_link)
コード例 #9
0
    def test_do_execute_atom(self):
        (DefineLink(
            DefinedSchemaNode('add'),
            LambdaLink(
                VariableList(
                    VariableNode('$X'),
                    VariableNode('$Y')),
                PlusLink(
                    VariableNode('$X'),
                    VariableNode('$Y')))))

        res = execute_atom(self.atomspace,
                           ExecutionOutputLink(
                               DefinedSchemaNode('add'),
                               ListLink(
                                   NumberNode("3"),
                                   NumberNode("4"))))
        self.assertEqual(NumberNode("7"), res)
コード例 #10
0
ファイル: test_bindlink.py プロジェクト: manisabri/atomspace
 def test_satisfying_set(self):
     atom = execute_atom(self.atomspace, self.getlink_atom)
     self._check_result_setlink(atom, 3)
コード例 #11
0
ファイル: test_bindlink.py プロジェクト: manisabri/atomspace
 def test_bindlink(self):
     atom = execute_atom(self.atomspace, self.bindlink_atom)
     print("Bindlink found: " + str(atom))
     self._check_result_setlink(atom, 3)
コード例 #12
0
ファイル: test_bindlink.py プロジェクト: manisabri/atomspace
 def test_execute_atom_no_return_value(self):
     result = execute_atom(self.atomspace,
             PutLink(DeleteLink(VariableNode("X")),
                     ConceptNode("deleteme")))
     self.assertEquals(result, None)
コード例 #13
0
ファイル: utilities.py プロジェクト: manisabri/atomspace
        (ExecutionOutputLink
            (GroundedSchemaNode \"py: add_link\")
            (ListLink
                (ConceptNode \"one\")
                (ConceptNode \"two\")
            )
        )
    )
    '''
scheme_eval(atomspace, execute_code)

print("execute: cog-execute")
if (executed):
    print("add_link - executed successfully")
else:
    print("add_link - did NOT execute")

executed = False
execute_atom(
    atomspace,
    ExecutionOutputLink(GroundedSchemaNode("py: add_link"),
                        ListLink(ConceptNode("one"), ConceptNode("two"))))
print("execute: execute_atom")
if (executed):
    print("add_link - executed successfully")
else:
    print("add_link - did NOT execute")

finalize_opencog()
del atomspace
コード例 #14
0
ファイル: stop_go.py プロジェクト: acproject/atomspace
            ListLink(
                ConceptNode("green light")
            )
        ),
        EvaluationLink(
            GroundedPredicateNode("py: stop_go"),
            ListLink(
                ConceptNode("green light")
            )
        ),
        EvaluationLink(
            GroundedPredicateNode("py: stop_go"),
            ListLink(
                ConceptNode("red light")
            )
        ),
        EvaluationLink(
            GroundedPredicateNode("py: stop_go"),
            ListLink(
                ConceptNode("traffic ticket")
            )
        )
    )
)

# Perform the actual satisfiability search.
result = execute_atom(atomspace, satisfaction_handle)

print("Number of green lights:",  green)
print("Number of red lights:",  red)
コード例 #15
0
        print("Entering static method with\n", x1)
        return x1

    def forward(self, x1, x2):
        print("Entering LocalClass with\n", x1, x2)
        return x1


nn = LocalClass()

# local function
exlof = ExecutionOutputLink(
    GroundedSchemaNode("py:local_func"),
    ListLink(ConceptNode("aa"), ConceptNode("bb"), ConceptNode("cc")))

assert execute_atom(
    a, exlof) == ConceptNode("cc"), "Failed while calling local function"

# local object
exloc = ExecutionOutputLink(GroundedSchemaNode("py:nn.forward"),
                            ListLink(ConceptNode("aa"), ConceptNode("bb")))

assert execute_atom(
    a, exloc) == ConceptNode("aa"), "Failed while calling local object method"

# static method
exst = ExecutionOutputLink(GroundedSchemaNode("py:LocalClass.static_check"),
                           ListLink(ConceptNode("aa")))

assert execute_atom(
    a, exst) == ConceptNode("aa"), "Failed while calling static class method"
コード例 #16
0
 def test_correct_argcount(self):
     atom1 = ConceptNode("atom1")
     exec_link = ExecutionOutputLink(
         GroundedSchemaNode("py:return_concept"), ListLink(atom1))
     result = execute_atom(self.space, exec_link)
     self.assertTrue(result.name == "test")