Example #1
0
 def addSentencesTrueByRulesDifferentially(cls, sentencesByForm, domainModel, reasoner):
     """ generated source for method addSentencesTrueByRulesDifferentially """
     model = domainModel
     constantForms = model.getConstantSentenceForms()
     # Find the part of the dependency graph dealing only with the constant forms.
     dependencySubgraph = Multimaps.filterKeys(model.getDependencyGraph(), Predicates.in_(constantForms))
     dependencySubgraph = Multimaps.filterValues(model.getDependencyGraph(), Predicates.in_(constantForms))
     dependencySubgraph = ImmutableMultimap.copyOf(dependencySubgraph)
     ordering = DependencyGraphs.toposortSafe(constantForms, dependencySubgraph)
     for stratum in ordering:
         #  One non-differential pass, collecting the changes
         for form in stratum:
             for rule in model.getRules(form):
                 if not reasoner.isSubsetOf(sentencesByForm, ruleResults):
                     sentencesByForm = reasoner.getUnion(sentencesByForm, ruleResults)
                     newlyTrueSentences = reasoner.getUnion(newlyTrueSentences, ruleResults)
         #  Now a lot of differential passes to deal with recursion efficiently
         while somethingChanged:
             somethingChanged = False
             for form in stratum:
                 for rule in model.getRules(form):
                     if not reasoner.isSubsetOf(sentencesByForm, ruleResults):
                         somethingChanged = True
                         newStuffInThisPass = reasoner.getUnion(newStuffInThisPass, ruleResults)
             sentencesByForm = reasoner.getUnion(sentencesByForm, newStuffInThisPass)
             newlyTrueSentences = newStuffInThisPass
Example #2
0
 def getFormsByName(cls, model):
     """ generated source for method getFormsByName """
     return Multimaps.index(getAllSentenceForms(model), Function())
Example #3
0
 def getSentences(self):
     """ generated source for method getSentences """
     return Multimaps.unmodifiableSetMultimap(self.sentences)
Example #4
0
 def reverseGraph(cls, graph):
     """ generated source for method reverseGraph """
     return Multimaps.invertFrom(graph, HashMultimap.create())
Example #5
0
 def createWithForwardChaining(cls, model):
     """ generated source for method createWithForwardChaining """
     reasoner = GdlChainingReasoner.create(model)
     sentencesByForm = reasoner.getConstantSentences()
     addSentencesTrueByRulesDifferentially(sentencesByForm, model, reasoner)
     return ImmutableConstantChecker.create(model, Multimaps.filterKeys(sentencesByForm.getSentences(), Predicates.in_(model.getConstantSentenceForms())))