001    /**
002     * RestaurantsConnector.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     * 23/06/2007
008     */
009    package jcolibri.test.test13.connector;
010    
011    import java.io.BufferedReader;
012    import java.io.IOException;
013    import java.io.InputStreamReader;
014    import java.net.URL;
015    import java.util.ArrayList;
016    import java.util.Collection;
017    
018    import jcolibri.cbrcore.CBRCase;
019    import jcolibri.cbrcore.CaseBaseFilter;
020    import jcolibri.cbrcore.Connector;
021    import jcolibri.exception.InitializingException;
022    import jcolibri.extensions.textual.IE.opennlp.IETextOpenNLP;
023    import jcolibri.test.test13.RestaurantDescription;
024    
025    /**
026     * Obtains cases from a simple txt file. This connector is thought to work with txt files that contain
027     * descriptions of restaurants following the format:
028     * <pre>
029     * NAME
030     * ADDRESS
031     * LOCATION
032     * PHONE
033     * DESCRIPTION
034     * AUTHOR_OF_DESCRIPTION
035     * 
036     * 
037     * NAME
038     * ADDRESS
039     * ...
040     * </pre>
041     * This connector only reads cases but does not write anything to the text file.
042     * @author Juan A. Recio-Garcia
043     * @version 1.0
044     *
045     */
046    public class RestaurantsConnector implements Connector
047    {
048        private URL file;
049        public RestaurantsConnector(String sourceFile)
050        {
051            file = jcolibri.util.FileIO.findFile(sourceFile);
052        }
053    
054        /* (non-Javadoc)
055         * @see jcolibri.cbrcore.Connector#close()
056         */
057        public void close()
058        {
059            // TODO Auto-generated method stub
060    
061        }
062    
063        /* (non-Javadoc)
064         * @see jcolibri.cbrcore.Connector#deleteCases(java.util.Collection)
065         */
066        public void deleteCases(Collection<CBRCase> cases)
067        {
068            // TODO Auto-generated method stub
069    
070        }
071    
072        /* (non-Javadoc)
073         * @see jcolibri.cbrcore.Connector#initFromXMLfile(java.net.URL)
074         */
075        public void initFromXMLfile(URL file) throws InitializingException
076        {
077            // TODO Auto-generated method stub
078    
079        }
080    
081        /* (non-Javadoc)
082         * @see jcolibri.cbrcore.Connector#retrieveAllCases()
083         */
084        public Collection<CBRCase> retrieveAllCases()
085        {
086            Collection<CBRCase> res = new ArrayList<CBRCase>();
087            
088            try
089            {
090                BufferedReader br = new BufferedReader( new InputStreamReader(file.openStream()));
091                String line = "";
092                while ((line = br.readLine()) != null)
093                {
094                    RestaurantDescription restaurant = new RestaurantDescription();
095                    restaurant.setName(line);
096                    restaurant.setAddress(br.readLine());
097                    restaurant.setLocation(br.readLine());
098                    restaurant.setPhone(br.readLine());
099                    restaurant.setDescription(new IETextOpenNLP(br.readLine()));
100                    br.readLine();
101                    br.readLine();
102                    br.readLine();
103                    CBRCase _case = new CBRCase();
104                    _case.setDescription(restaurant);
105                    res.add(_case);
106                    
107                }
108                br.close();
109            } catch (IOException e)
110            {
111                org.apache.commons.logging.LogFactory.getLog(this.getClass()).error(e);
112                
113            }
114            
115            return res;
116        }
117    
118        /* (non-Javadoc)
119         * @see jcolibri.cbrcore.Connector#retrieveSomeCases(jcolibri.cbrcore.CaseBaseFilter)
120         */
121        public Collection<CBRCase> retrieveSomeCases(CaseBaseFilter filter)
122        {
123            // TODO Auto-generated method stub
124            return null;
125        }
126    
127        /* (non-Javadoc)
128         * @see jcolibri.cbrcore.Connector#storeCases(java.util.Collection)
129         */
130        public void storeCases(Collection<CBRCase> cases)
131        {
132            // TODO Auto-generated method stub
133    
134        }
135    
136    }