dependencySubgraph = ImmutableMultimap.copyOf(dependencySubgraph);
List<Set<SentenceForm>> ordering = DependencyGraphs.toposortSafe(constantForms, dependencySubgraph);
for (Set<SentenceForm> stratum : ordering) {
// One non-differential pass, collecting the changes
GdlSentenceSet newlyTrueSentences = GdlSentenceSet.create();
for (SentenceForm form : stratum) {
for (GdlRule rule : model.getRules(form)) {
GdlSentenceSet ruleResults =
reasoner.getRuleResults(rule, domainModel, sentencesByForm);
if (!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
boolean somethingChanged = true;
while (somethingChanged) {
somethingChanged = false;
GdlSentenceSet newStuffInThisPass = GdlSentenceSet.create();
for (SentenceForm form : stratum) {
for (GdlRule rule : model.getRules(form)) {
GdlSentenceSet ruleResults =
reasoner.getRuleResultsForNewSentences(rule, domainModel, sentencesByForm,
newlyTrueSentences);
if (!reasoner.isSubsetOf(sentencesByForm, ruleResults)) {
somethingChanged = true;
newStuffInThisPass = reasoner.getUnion(newStuffInThisPass, ruleResults);