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

aima.core.logic.propositional.visitors.SymbolCollector 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.LinkedHashSet;
import java.util.Set;

import aima.core.logic.propositional.parsing.ast.Sentence;
import aima.core.logic.propositional.parsing.ast.PropositionSymbol;

/**
 * Utility class for collecting propositional symbols from sentences. Will
 * exclude the always false and true symbols.
 * 
 * @author Ravi Mohan
 * @author Ciaran O'Reilly
 */
public class SymbolCollector extends BasicGatherer {

	/**
	 * Collect a set of propositional symbols from a list of given sentences.
	 * 
	 * @param sentences
	 *            a list of sentences from which to collect symbols.
	 * @return a set of all the proposition symbols that are not always true or
	 *         false contained within the input sentences.
	 */
	public static Set getSymbolsFrom(Sentence... sentences) {
		Set result = new LinkedHashSet();

		SymbolCollector symbolCollector = new SymbolCollector();
		for (Sentence s : sentences) {
			result = s.accept(symbolCollector, result);
		}

		return result;
	}

	@Override
	public Set visitPropositionSymbol(PropositionSymbol s,
			Set arg) {
		// Do not add the always true or false symbols
		if (!s.isAlwaysTrue() && !s.isAlwaysFalse()) {
			arg.add(s);
		}
		return arg;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy