Пример #1
0
    def load(self, wmemory, agenda, goals):
        
        assert isinstance(wmemory, WorkingMemory)
        assert isinstance(agenda, Agenda)
        assert isinstance(goals, list)
                
        tparser = TemplateParser()
        
        [wmemory.def_template(x) for x in tparser.load_file(self._dirpath+'/templates.json')] 
    
        fparser = FactParser()
    
        [wmemory.assert_fact(x) for x in fparser.load_file(self._dirpath + "/facts.json")]
        
        rparser = RuleParser(ClipsLike())

        [agenda.set_regola(x) for x in rparser.parse(self._dirpath + "/rules.txt")]
        
        gparser = RuleParser(GoalClipsLike())
        
        goals.extend(gparser.parse(self._dirpath + "/goals.txt"))
        
        
        
Пример #2
0
        
        operatore = Word(alphas, alphanums+"_")
        funzione << Group( operatore +  LPAR + Group( operando + ZeroOrMore( ( Suppress(",") + operando) ) ) + RPAR )
         
        dizionario << Group( Suppress("{") + Group(copy(stringa).setParseAction(lambda t:t[0]) + Suppress(":") + operando) + ZeroOrMore( Suppress(",") + Group(copy(stringa).setParseAction(lambda t:t[0]) + Suppress(":") + operando) ) + Suppress("}") )
        
        congiunzione << Group( oneOf(" ".join(condizioni.congiunzioni())) + LPAR + Group( OneOrMore( congiunzione | condizione ) ) + RPAR )
        
        header = Suppress(DEFGOAL_START) + Word(alphas, alphanums + "._-") + Suppress(':')
        separatore = Suppress(DEFGOAL_SEPARATOR)
        closer = Suppress(DEFGOAL_END)
        
        goal = Group(header + Group(OneOrMore(condizione | congiunzione)) + separatore + Group(ZeroOrMore(azione)) + closer)
        
        return goal
    
    
if __name__ == '__main__':

    from icse.ps.rules.Parser import Parser
    import os
    
    g = ClipsLike()
    parser = Parser(g)
    
    r = parser.parse(os.getcwd() + "/../../../../../games/8/goals.txt")
    
    print "\n".join([str(x) for x in r])