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 import aima.logic.propositional.parsing.ast.UnarySentence; 013 import aima.util.SetOps; 014 015 /** 016 * @author Ravi Mohan 017 * 018 */ 019 020 public class NegativeSymbolCollector extends BasicTraverser { 021 @Override 022 public Object visitNotSentence(UnarySentence ns, Object arg) { 023 Set<Symbol> s = (Set<Symbol>) arg; 024 if (ns.getNegated() instanceof Symbol) { 025 s.add((Symbol) ns.getNegated()); 026 } else { 027 s = new SetOps<Symbol>().union(s, (Set<Symbol>) ns.getNegated() 028 .accept(this, arg)); 029 } 030 return s; 031 } 032 033 public Set<Symbol> getNegativeSymbolsIn(Sentence s) { 034 return (Set<Symbol>) s.accept(this, new HashSet()); 035 } 036 037 }