001 /* 002 * Created on Jul 25, 2005 003 * 004 */ 005 package aima.learning.inductive; 006 007 import aima.learning.framework.Example; 008 import aima.util.Util; 009 010 /** 011 * @author Ravi Mohan 012 * 013 */ 014 public class ConstantDecisonTree extends DecisionTree { 015 // represents leaf nodes like "Yes" or "No" 016 private String value; 017 018 public ConstantDecisonTree(String value) { 019 this.value = value; 020 } 021 022 @Override 023 public void addLeaf(String attributeValue, String decision) { 024 throw new RuntimeException("cannot add Leaf to ConstantDecisonTree"); 025 } 026 027 @Override 028 public void addNode(String attributeValue, DecisionTree tree) { 029 throw new RuntimeException("cannot add Node to ConstantDecisonTree"); 030 } 031 032 @Override 033 public Object predict(Example e) { 034 return value; 035 } 036 037 @Override 038 public String toString() { 039 return "DECISION -> " + value; 040 } 041 042 @Override 043 public String toString(int depth, StringBuffer buf) { 044 buf.append(Util.ntimes("\t", depth + 1)); 045 buf.append("DECISION -> " + value + "\n"); 046 return buf.toString(); 047 } 048 }