001 /** 002 * IEutils.java 003 * jCOLIBRI2 framework. 004 * @author Juan A. Recio-García. 005 * GAIA - Group for Artificial Intelligence Applications 006 * http://gaia.fdi.ucm.es 007 * 21/06/2007 008 */ 009 package jcolibri.extensions.textual.IE; 010 011 import java.util.ArrayList; 012 import java.util.Collection; 013 014 import jcolibri.cbrcore.Attribute; 015 import jcolibri.cbrcore.CBRCase; 016 import jcolibri.cbrcore.CBRQuery; 017 import jcolibri.cbrcore.CaseComponent; 018 import jcolibri.exception.AttributeAccessException; 019 import jcolibri.extensions.textual.IE.representation.IEText; 020 021 /** 022 * Utility functions for the IE extension. 023 * @author Juan A. Recio-Garcia 024 * @version 1.0 025 */ 026 public class IEutils 027 { 028 public static Collection<IEText> getTexts(CBRCase _case) 029 { 030 ArrayList<IEText> res = new ArrayList<IEText>(); 031 addTexts(_case.getDescription(), res); 032 addTexts(_case.getSolution(), res); 033 addTexts(_case.getJustificationOfSolution(), res); 034 addTexts(_case.getResult(), res); 035 return res; 036 } 037 038 public static Collection<IEText> getTexts(CBRQuery query) 039 { 040 ArrayList<IEText> res = new ArrayList<IEText>(); 041 addTexts(query.getDescription(), res); 042 return res; 043 } 044 045 public static void addTexts(CaseComponent cc, Collection<IEText> list) 046 { 047 if(cc==null) 048 return; 049 Attribute[] attrs = jcolibri.util.AttributeUtils.getAttributes(cc.getClass()); 050 for(int i=0; i<attrs.length; i++) 051 { 052 try 053 { 054 Object o = attrs[i].getValue(cc); 055 if(o instanceof IEText) 056 list.add((IEText)o); 057 else if(o instanceof CaseComponent) 058 addTexts((CaseComponent)o, list); 059 } catch (AttributeAccessException e) 060 { 061 org.apache.commons.logging.LogFactory.getLog(IEutils.class).error(e); 062 } 063 } 064 } 065 066 067 068 }