def getNewFormDomain(cls, condensingRule, oldModel, newForm): """ generated source for method getNewFormDomain """ varDomains = SentenceDomainModels.getVarDomains(condensingRule, oldModel, VarDomainOpts.BODY_ONLY) domainsForSlots = Lists.newArrayList() for term in GdlUtils.getTupleFromSentence(condensingRule.getHead()): if not (isinstance(term, (GdlVariable, ))): raise RuntimeException("Expected all slots in the head of a condensing rule to be variables, but the rule was: " + condensingRule) domainsForSlots.add(varDomains.get(term)) return CartesianSentenceFormDomain.create(newForm, domainsForSlots)
def goodCondensationSetByHeuristic(cls, minSet, rule, model, checker, sentenceNameSource): """ generated source for method goodCondensationSetByHeuristic """ assignments = AssignmentsImpl.getNumAssignmentsEstimate(rule, SentenceDomainModels.getVarDomains(rule, model, VarDomainOpts.INCLUDE_HEAD), checker) literals = rule.arity() if literals > 1: literals += 1 curRuleHeuristic = assignments * literals newRules = cls.applyCondensation(minSet, rule, sentenceNameSource) r1 = newRules.get(0) r2 = newRules.get(1) newModel = augmentModelWithNewForm(model, newRules) a1 = AssignmentsImpl.getNumAssignmentsEstimate(r1, SentenceDomainModels.getVarDomains(r1, newModel, VarDomainOpts.INCLUDE_HEAD), checker) a2 = AssignmentsImpl.getNumAssignmentsEstimate(r2, SentenceDomainModels.getVarDomains(r2, newModel, VarDomainOpts.INCLUDE_HEAD), checker) l1 = r1.arity() if l1 > 1: l1 += 1 l2 = r2.arity() if l2 > 1: l2 += 1 newRulesHeuristic = a1 * l1 + a2 * l2 return newRulesHeuristic < curRuleHeuristic
def getRuleResults(self, rule, domainModel, sentencesSoFar): """ generated source for method getRuleResults """ ConcurrencyUtils.checkForInterruption() headForm = self.model.getSentenceForm(rule.getHead()) varDomains = SentenceDomainModels.getVarDomains(rule, domainModel, VarDomainOpts.INCLUDE_HEAD) functionInfoMap = sentencesSoFar.getFunctionInfo() completedSentenceFormValues = sentencesSoFar.getSentences().asMap() assignments = AssignmentsImpl(rule, varDomains, functionInfoMap, completedSentenceFormValues) asnItr = assignments.getIterator() sentencesToAdd = GdlSentenceSet.create() while asnItr.hasNext(): for literal in rule.getBody(): ConcurrencyUtils.checkForInterruption() if not satisfies(assignment, literal, sentencesSoFar.getSentences()): asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment) allSatisfied = False break if allSatisfied: sentencesToAdd.put(headForm, CommonTransforms.replaceVariables(head, assignment)) asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment) return sentencesToAdd
def addRuleResultsForChosenLiteral(self, rule, chosenLiteral, chosenNewSentences, domainModel, allSentences, sentencesToAdd): """ generated source for method addRuleResultsForChosenLiteral """ headForm = self.model.getSentenceForm(rule.getHead()) varDomains = SentenceDomainModels.getVarDomains(rule, domainModel, VarDomainOpts.INCLUDE_HEAD) functionInfoMap = allSentences.getFunctionInfo() completedSentenceFormValues = allSentences.getSentences().asMap() for chosenNewSentence in chosenNewSentences: if preassignments != None: while asnItr.hasNext(): for literal in rule.getBody(): if literal == chosenLiteral: # Already satisfied continue if not self.satisfies(assignment, literal, allSentences.getSentences()): asnItr.changeOneInNext(GdlUtils.getVariables(literal), assignment) allSatisfied = False break if allSatisfied: if not allSentences.containsSentence(headForm, newHead): sentencesToAdd.put(headForm, newHead) asnItr.changeOneInNext(GdlUtils.getVariables(head), assignment)
def getAssignmentsForRule(cls, rule, model, functionInfoMap, completedSentenceFormValues): """ generated source for method getAssignmentsForRule """ return AssignmentsImpl(rule, SentenceDomainModels.getVarDomains(rule, model, VarDomainOpts.INCLUDE_HEAD), functionInfoMap, completedSentenceFormValues)