Dunque...
1) Pensavo, con quell'istruzione, di creare un nuovo dizionario, come posso evitare che sovrascriva?
2) Prima ci sono altre righe di codice che non ho messo perchè inutili e che inseriscono un elemento nella lista
3) Hai ragione, incollato male il codice, fate conto che sia indentato bene
Ecco il codice di applyRule:
Già che ci sono metto pure il codice di applyConclusion, non si può mai sapere, anche se qui c'è semplicemente la modifica di temp_wrkmry, che vi ricordo essere un dizionario:codice:def applyRule(self, working_memory): temp_wrkmry = working_memory for conclusion in self.conclusions: temp_wrkmry = conclusion.applyConclusion(temp_wrkmry) return temp_wrkmry
codice:def applyConclusion(self, working_memory): temp = working_memory if (self.conclusion_name == 'retract'): if (not temp.has_keys(self.fact.getFactName())): raise FactNotFoundException(self.fact.getFactName()) del temp[self.fact.getFactName()] elif (self.conclusion_name == 'assert'): tempFact = Fact.Fact() tempFact.setFactName(self.fact.getFactName()) for att_value in self.fact.attributes: if (isinstance(att_value.getValue(), str)): att_value.setValue(self.rule.variables[att_value.getValue()]) tempFact.addValAtt(att_value) del temp[self.fact.getFactName()] temp[self.fact.getFactName()] = tempFact


Rispondi quotando