* Removes rules with sentences with empty domains. These simply won't have
* sentence forms in the generated sentence model, so this is fairly easy.
* @throws InterruptedException
*/
private static List<Gdl> cleanUpIrrelevantRules(List<Gdl> expandedRules) throws InterruptedException {
final ImmutableSentenceFormModel model = SentenceFormModelFactory.create(expandedRules);
return ImmutableList.copyOf(Collections2.filter(expandedRules, new Predicate<Gdl>() {
@Override
public boolean apply(Gdl input) {
if (!(input instanceof GdlRule)) {
// If it's not a rule, leave it in
return true;
}
GdlRule rule = (GdlRule) input;
// Used just as a boolean we can change from the inner class
final AtomicBoolean shouldRemove = new AtomicBoolean(false);
GdlVisitors.visitAll(rule, new GdlVisitor() {
@Override
public void visitSentence(GdlSentence sentence) {
SentenceForm form = model.getSentenceForm(sentence);
if (!model.getSentenceForms().contains(form)) {
shouldRemove.set(true);
}
}
});
return !shouldRemove.get();