All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.logic.propositional.visitors.BasicGatherer Maven / Gradle / Ivy

Go to download

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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy