}
private static void addSentencesTrueByRulesDifferentially(
GdlSentenceSet sentencesByForm,
SentenceDomainModel domainModel, GdlChainingReasoner reasoner) throws InterruptedException {
SentenceFormModel model = domainModel;
Set<SentenceForm> constantForms = model.getConstantSentenceForms();
//Find the part of the dependency graph dealing only with the constant forms.
Multimap<SentenceForm, SentenceForm> dependencySubgraph =
Multimaps.filterKeys(model.getDependencyGraph(), Predicates.in(constantForms));
dependencySubgraph = Multimaps.filterValues(model.getDependencyGraph(), Predicates.in(constantForms));
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;