aima.core.logic.propositional.parsing.AbstractPLVisitor 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.
package aima.core.logic.propositional.parsing;
import aima.core.logic.propositional.parsing.ast.ComplexSentence;
import aima.core.logic.propositional.parsing.ast.Sentence;
import aima.core.logic.propositional.parsing.ast.PropositionSymbol;
/**
* Abstract implementation of the PLVisitor interface that provides default
* behavior for each of the methods.
*
* @author Ravi Mohan
* @author Ciaran O'Reilly
*
* @param
* the argument type to be passed to the visitor methods.
*/
public abstract class AbstractPLVisitor implements PLVisitor {
@Override
public Sentence visitPropositionSymbol(PropositionSymbol s, A arg) {
// default behavior is to treat propositional symbols as atomic
// and leave unchanged.
return s;
}
@Override
public Sentence visitUnarySentence(ComplexSentence s, A arg) {
// a new Complex Sentence with the same connective but possibly
// with its simpler sentence replaced by the visitor.
return new ComplexSentence(s.getConnective(), s.getSimplerSentence(0)
.accept(this, arg));
}
@Override
public Sentence visitBinarySentence(ComplexSentence s, A arg) {
// a new Complex Sentence with the same connective but possibly
// with its simpler sentences replaced by the visitor.
return new ComplexSentence(s.getConnective(), s.getSimplerSentence(0)
.accept(this, arg), s.getSimplerSentence(1).accept(this, arg));
}
}