Пример #1
0
 for (item_type, item) in parsedItems:
     if item_type == 'defrule':
         rule = item
         default_rule = {'name': '', 'lhs': [], 'rhs': [], 'declare': {'salience': 0}, 'description': ''}
         default_rule.update(rule)
         rule = default_rule
         p = Production(rule['name'], rule['lhs'], rule['rhs'], rule['declare'], rule['description'])
         rete.add_production(p)
         stats_defrule += 1
     elif item_type == 'deffacts':
         stats_deffacts += 1
         for fact in item:
             stats_facts += 1
             rete.assert_fact(fact)
     elif item_type == 'set-strategy':
         rete.agenda().changeStrategy(item)
     elif item_type == 'myclips-directive':
         # processo le direttive
         dir_type, dir_arg = item
         if dir_type == 'include':
             # inclusione di file al termine della lettura di questo
             import os
             module_path = os.path.realpath( os.path.dirname(current_file) + '/' + dir_arg )
             if isfile( module_path ):
                 parseQueue.append(module_path)
                 #print "Modulo preparato alla lettura: ", os.path.dirname(filepath) + '/' + dir_arg
             else:
                 print "File non valido: ", module_path
         elif dir_type == 'debug':
             #argomenti di debug nella forma:
             #    chiave=valore,chiave2=valore2,ecc
Пример #2
0
                        ],
                   rhs=[
                        (Printout, ["t", (Variable, 'A'), "il mio testo", "crlf"])
                        ],
                   description=""
                   )
    
    rete.add_production(p)


    rete.assert_fact(['A', 1])
    rete.assert_fact(['A', 2,'B'])
    rete.assert_fact(['A', 1,'B'])
    
    
    agenda = rete.agenda()
    
    for (node, token) in agenda:
        print "{0}: {1}".format(node.get_name(), token.linearize())

    NetworkXGraphWrapper.i().draw()