def addSentencesTrueByRules(cls, sentencesByForm, model): """ generated source for method addSentencesTrueByRules """ prover = AimaProver(model.getDescription()) for form in model.getConstantSentenceForms(): for result in prover.askAll(query, ImmutableSet.of()): ConcurrencyUtils.checkForInterruption() # Variables may end up being replaced with functions, which is not # what we want here, so we have to double-check that the form is correct. if form.matches(result): sentencesByForm.put(form, result)
class ProverStateMachine(StateMachine): """ generated source for class ProverStateMachine """ initialState = MachineState() prover = Prover() roles = List() # # * Initialize must be called before using the StateMachine # def __init__(self): """ generated source for method __init__ """ super(ProverStateMachine, self).__init__() def initialize(self, description): """ generated source for method initialize """ self.prover = AimaProver(description) self.roles = Role.computeRoles(description) self.initialState = computeInitialState() def computeInitialState(self): """ generated source for method computeInitialState """ results = self.prover.askAll(ProverQueryBuilder.getInitQuery(), HashSet()) return ProverResultParser().toState(results) def getGoal(self, state, role): """ generated source for method getGoal """ results = self.prover.askAll(ProverQueryBuilder.getGoalQuery(role), ProverQueryBuilder.getContext(state)) if len(results) != 1: GamerLogger.logError("StateMachine", "Got goal results of size: " + len(results) + " when expecting size one.") raise GoalDefinitionException(state, role) try: return Integer.parseInt(constant.__str__()) except Exception as e: raise GoalDefinitionException(state, role) def getInitialState(self): """ generated source for method getInitialState """ return self.initialState def getLegalMoves(self, state, role): """ generated source for method getLegalMoves """ results = self.prover.askAll(ProverQueryBuilder.getLegalQuery(role), ProverQueryBuilder.getContext(state)) if len(results) == 0: raise MoveDefinitionException(state, role) return ProverResultParser().toMoves(results) def getNextState(self, state, moves): """ generated source for method getNextState """ results = self.prover.askAll(ProverQueryBuilder.getNextQuery(), ProverQueryBuilder.getContext(state, getRoles(), moves)) for sentence in results: if not sentence.isGround(): raise TransitionDefinitionException(state, moves) return ProverResultParser().toState(results) def getRoles(self): """ generated source for method getRoles """ return self.roles def isTerminal(self, state): """ generated source for method isTerminal """ return self.prover.prove(ProverQueryBuilder.getTerminalQuery(), ProverQueryBuilder.getContext(state))