예제 #1
0
 def test_context_mgr_tmp(self):
     a = ConceptNode('a')
     with tmp_atomspace() as tmp_as:
          b = ConceptNode('b')
          self.assertTrue(a in self.space)
          # verify that current default atomspace is tmp_as
          self.assertFalse(b in self.space)
     c = ConceptNode('c')
     # verify that current default atomspace is self.space
     self.assertTrue(c in self.space)
예제 #2
0
 def test_context_mgr_tmp(self):
     a = ConceptNode('a')
     with tmp_atomspace() as tmp_as:
         b = ConceptNode('b')
         self.assertTrue(a in self.space)
         # verify that current default atomspace is tmp_as
         self.assertFalse(b in self.space)
     c = ConceptNode('c')
     # verify that current default atomspace is self.space
     self.assertTrue(c in self.space)
예제 #3
0
def main():
    path_query = 'query.scm'
    path_data = 'data.scm'
    atomspace = AtomSpace()
    initialize_opencog(atomspace)
    storage = Storage()
    index = Index(storage)
    with tmp_atomspace() as tmp:
        imp = ImplicationLink(VariableNode("C"), VariableNode("B"))
        # GetLink returns only bindings for variables
        pat = BindLink(imp, imp)
        index.add_pattern(pat)

    with tmp_atomspace() as tmp:
        base = open(path_data).read()
        data = scheme_eval_h(tmp, base)
        index.add_data(data)
        query = open(path_query).read()
        q = scheme_eval_h(tmp, query)
        result = index.query(tmp, q)
        print(result)
예제 #4
0
 def run_program(self, features, program, attention):
     with tmp_atomspace() as tmp:
         prog, left = tbd_helpers.return_prog(program)
         query = tbd_helpers.ast_to_query(prog, tmp)
         scene = InputModule(
             ConceptNode("scene"), {
                 'features': features,
                 'attention': attention.clone(),
                 'name': ConceptNode("scene").name
             })
         result = execute_atom(tmp, query)
         answer = self.argmax(self.extract(result))
         return answer
예제 #5
0
    def process(self, data, label):
        """
        Accepts batch with features and labels,
        returns probability of labels
        """
        with tmp_atomspace() as atomspace:
            #  compute possible pairs of NumberNodes
            pairs = self.get_all_pairs(label, atomspace)

            # setup input images
            inp1 = InputModule(ConceptNode("img1"),
                               data[0].reshape([1, 1, 28, 28]))
            inp2 = InputModule(ConceptNode("img2"),
                               data[1].reshape([1, 1, 28, 28]))
            return self.p_correct_answer(pairs, inp1, inp2)