unexpected plan

Help
Dr_Muttley
2012-04-13
2013-05-17
  • Dr_Muttley
    Dr_Muttley
    2012-04-13

    Hi,

    I am pretty new to the world of expert system, so excuse my ignorance.

    I am trying to write a tool to match two lists of strings, and catalog the differences by type of mistake (e.g. typo, punctuation error etc.)

    I have several BC rules that extablish that one 'istitute' entity is matched in both target and reference:

    institute_validated
        use institute_validated($id)
        when
            reference.isinstitute($id, $name1)  
            target_pdf.isinstitute($id, $name2)
            check the_same($name1, $name2)
        with 
            print $id, $name1, "matches."
    

    I would also like to test the negation, i.e. when the institute is not validated. I have therefore added a new BC rule:

    institute_not_validated
        use institute_not_validated($iid)
        when
            reference.isinstitute($iid, $name1)
            notany
                institute_validated($iid)
        with    
            print $iid, "not found."
    

    The goal is proven for some items, but I get a runtime crash after a while:

    Traceback (most recent call last):
      File "driver.py", line 121, in <module>
        bc_test()
      File "driver.py", line 92, in bc_test
        for vars,plan in gen:
      File "/usr/lib/python2.6/site-packages/pyke/rule_base.py", line 50, in next
        return self.iterator.next()
      File "/usr/lib/python2.6/site-packages/pyke/knowledge_engine.py", line 41, in from_iterable
        for x in iterable: yield x
      File "/usr/lib/python2.6/site-packages/pyke/knowledge_engine.py", line 41, in from_iterable
        for x in iterable: yield x
      File "/afs/cern.ch/user/m/mbarison/pyke-1.1.1/examples/authorlist_fun/compiled_krb/example_bc.py", line 204, in institute_not_validated
        "example.institute_not_validated: got unexpected plan from when clause 2"
    AssertionError: example.institute_not_validated: got unexpected plan from when clause 2
    

    It is not clear to me what is wrong, could you please help?

    Thanks,
             M.

     
  • Your institute_validated rule has a with clause on it, therefore it will produce a plan when the rule fires.

    Your call to institute_validated within institute_not_validated does not say what to do with this plan.  In this case, it really can't do anything with the plan because if institute_validated succeeds (with a plan), the notany clause containing it will fail and so will the institute_not_validated rule.  But, nonetheless, you are required to place an "as" clause on the call to institute_validated, such as:

    institute_not_validated
        use institute_not_validated($iid)
        when
            reference.isinstitute($iid, $name1)
            notany
                institute_validated($iid) as $unneeded_plan
        with    
            print $iid, "not found."
    
     
  • Dr_Muttley
    Dr_Muttley
    2012-04-19

    It worked, thank you very much for your help.