Esempio n. 1
0
 def fol_bc_and(KB, goals, theta):
     if theta is None:
         pass
     elif not goals:
         yield ([], theta)
     else:
         first, rest = goals[0], goals[1:]
         for theta1 in fol_bc_or(KB, subst(theta, first), theta):
             for theta2 in fol_bc_and(KB, rest, theta1[1]):
                 yield (theta1[0] + theta2[0], theta2[1])
Esempio n. 2
0
 def fol_bc_and(KB, goals, theta):
     if theta is None:
         pass
     elif not goals:
         yield ([], theta)
     else:
         first, rest = goals[0], goals[1:]
         for theta1 in fol_bc_or(KB, subst(theta, first), theta):
             for theta2 in fol_bc_and(KB, rest, theta1[1]):
                 yield (theta1[0] + theta2[0], theta2[1])
Esempio n. 3
0
    def update_examples(self, target, examples, extended_examples):
        """Add to the kb those examples what are represented in extended_examples
        List of omitted examples is returned."""
        uncovered = []
        for example in examples:
            represents = lambda d: all(d[x] == example[x] for x in example)
            if any(represents(l) for l in extended_examples):
                self.tell(subst(example, target))
            else:
                uncovered.append(example)

        return uncovered
Esempio n. 4
0
    def update_examples(self, target, examples, extended_examples):
        """Adds to the kb those examples what are represented in extended_examples
        List of omitted examples is returned"""
        uncovered = []
        for example in examples:
            def represents(d):
                return all(d[x] == example[x] for x in example)
            if any(represents(l) for l in extended_examples):
                self.tell(subst(example, target))
            else:
                uncovered.append(example)

        return uncovered
Esempio n. 5
0
 def __init__(self, varname, kb, query, width=800, height=600, cid=None):
     Canvas.__init__(self, varname, width, height, cid)
     self.kb = kb
     self.query = query
     self.l = 1/20
     self.b = 3*self.l
     bc_out = list(self.fol_bc_ask())
     if len(bc_out) is 0:
         self.valid = False
     else:
         self.valid = True
         graph = bc_out[0][0][0]
         s = bc_out[0][1]
         while True:
             new_graph = subst(s, graph)
             if graph == new_graph:
                 break
             graph = new_graph
         self.make_table(graph)
     self.context = None
     self.draw_table()
Esempio n. 6
0
 def __init__(self, varname, kb, query, width=800, height=600, cid=None):
     Canvas.__init__(self, varname, width, height, cid)
     self.kb = kb
     self.query = query
     self.l = 1/20
     self.b = 3*self.l
     bc_out = list(self.fol_bc_ask())
     if len(bc_out) is 0:
         self.valid = False
     else:
         self.valid = True
         graph = bc_out[0][0][0]
         s = bc_out[0][1]
         while True:
             new_graph = subst(s, graph)
             if graph == new_graph:
                 break
             graph = new_graph
         self.make_table(graph)
     self.context = None
     self.draw_table()
Esempio n. 7
0
 def extend_example(self, example, literal):
     """Generate extended examples which satisfy the literal."""
     # find all substitutions that satisfy literal
     for s in self.ask_generator(subst(example, literal)):
         s.update(example)
         yield s
Esempio n. 8
0
 def extend_example(self, example, literal):
     """Generates extended examples which satisfy the literal"""
     # find all substitutions that satisfy literal
     for s in self.ask_generator(subst(example, literal)):
         s.update(example)
         yield s