001 /* 002 * Created on Dec 4, 2004 003 * 004 */ 005 package aima.logic.propositional.visitors; 006 007 import java.util.HashSet; 008 import java.util.Set; 009 010 import aima.logic.propositional.parsing.ast.Sentence; 011 import aima.logic.propositional.parsing.ast.Symbol; 012 013 /** 014 * @author Ravi Mohan 015 * 016 */ 017 018 public class SymbolCollector extends BasicTraverser { 019 020 @Override 021 public Object visitSymbol(Symbol s, Object arg) { 022 Set<Symbol> symbolsCollectedSoFar = (Set) arg; 023 symbolsCollectedSoFar.add(new Symbol(s.getValue())); 024 return symbolsCollectedSoFar; 025 } 026 027 public Set<Symbol> getSymbolsIn(Sentence s) { 028 if (s == null) {// empty knowledge bases == null fix this later 029 return new HashSet<Symbol>(); 030 } 031 return (Set<Symbol>) s.accept(this, new HashSet()); 032 } 033 034 }