def test_satisfy(self): satisfaction_atom = SatisfactionLink( VariableList(), # no variables SequentialAndLink( EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("green light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("green light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("red light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("traffic ticket") ) ) ) ) atom = satisfaction_link(self.atomspace, satisfaction_atom) self.assertTrue(atom is not None and atom.mean <= 0.5) self.assertEquals(green_count(), 2) self.assertEquals(red_count(), 1)
def test_satisfy(self): satisfaction_handle = SatisfactionLink( VariableList(), # no variables SequentialAndLink( EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("green light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("green light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("red light") ) ), EvaluationLink( GroundedPredicateNode("py: test_functions.stop_go"), ListLink( ConceptNode("traffic ticket") ) ) ) ).h result = satisfaction_link(self.atomspace, satisfaction_handle) self.assertTrue(result is not None and result.mean <= 0.5) self.assertEquals(green_count(), 2) self.assertEquals(red_count(), 1)
red += 1 return TruthValue(0, 1) else: print "Oh No!! Car wreck!" assert (false) return TruthValue(0, 0) # This is the pattern that the pattern matcher attempts to ground. # It consists of two green lights, which evaluate to true, followed # by a red light, which halts the satsifiability search. The last # term is thus never encountered. Which is a good thing. satisfaction_handle = SatisfactionLink( SequentialAndLink( EvaluationLink(GroundedPredicateNode("py: stop_go"), 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 = satisfaction_link(atomspace, satisfaction_handle) print "Number of green lights:", green print "Number of red lights:", red
# The ROS layer. evl = EvaControl() # Global functions, beause that's what PythonEval expects. # The must return a TruthValue, since EvaluationLinks # expect TruthValues. def do_look_left(): evl.look_left() return TruthValue(1, 1) def do_look_right(): evl.look_right() return TruthValue(1, 1) # Define an executable pattern satisfaction_handle = SatisfactionLink( SequentialAndLink( EvaluationLink( # GroundedPredicateNode("py: evl.look_right"), # GroundedPredicateNode("py: do_look_right"), GroundedPredicateNode("py: do_look_left"), ListLink() ) ) ).h # See if the pattern can be satsified. This should result # in a ROS message being sent. result = satisfaction_link(atomspace, satisfaction_handle)