aima.core.logic.propositional.visitors.BasicGatherer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.logic.propositional.visitors;
import java.util.Set;
import aima.core.logic.propositional.parsing.PLVisitor;
import aima.core.logic.propositional.parsing.ast.ComplexSentence;
import aima.core.logic.propositional.parsing.ast.PropositionSymbol;
import aima.core.util.SetOps;
/**
* Super class of Visitors that are "read only" and gather information from an
* existing parse tree .
*
* @author Ravi Mohan
*
* @param
* the type of elements to be gathered.
*/
public abstract class BasicGatherer implements PLVisitor, Set> {
@Override
public Set visitPropositionSymbol(PropositionSymbol s, Set arg) {
return arg;
}
@Override
public Set visitUnarySentence(ComplexSentence s, Set arg) {
return SetOps.union(arg, s.getSimplerSentence(0).accept(this, arg));
}
@Override
public Set visitBinarySentence(ComplexSentence s, Set arg) {
Set termunion = SetOps.union(
s.getSimplerSentence(0).accept(this, arg), s
.getSimplerSentence(1).accept(this, arg));
return SetOps.union(arg, termunion);
}
}