001 package aima.logic.fol.inference.otter.defaultimpl; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import aima.logic.fol.inference.Demodulation; 007 import aima.logic.fol.inference.otter.ClauseSimplifier; 008 import aima.logic.fol.kb.data.Clause; 009 import aima.logic.fol.parsing.ast.TermEquality; 010 011 /** 012 * @author Ciaran O'Reilly 013 * 014 */ 015 public class DefaultClauseSimplifier implements ClauseSimplifier { 016 017 private Demodulation demodulation = new Demodulation(); 018 private List<TermEquality> rewrites = new ArrayList<TermEquality>(); 019 020 public DefaultClauseSimplifier() { 021 022 } 023 024 public DefaultClauseSimplifier(List<TermEquality> rewrites) { 025 this.rewrites.addAll(rewrites); 026 } 027 028 // 029 // START-ClauseSimplifier 030 public Clause simplify(Clause c) { 031 Clause simplified = c; 032 033 // Apply each of the rewrite rules to 034 // the clause 035 for (TermEquality te : rewrites) { 036 Clause dc = simplified; 037 // Keep applying the rewrite as many times as it 038 // can be applied before moving on to the next one. 039 while (null != (dc = demodulation.apply(te, dc))) { 040 simplified = dc; 041 } 042 } 043 044 return simplified; 045 } 046 047 // END-ClauseSimplifier 048 // 049 }