コード例 #1
0
ファイル: GdlChainingReasoner.py プロジェクト: hobson/ggpy
 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
コード例 #2
0
ファイル: CondensationIsolator.py プロジェクト: hobson/ggpy
 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