|
SearchPR |
|
1 /* 2 * SearchPR.java 3 * 4 * Copyright (c) 1998-2001, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Rosen Marinov, 19/Apr/2002 12 * 13 */ 14 15 package gate.creole.ir; 16 17 import gate.*; 18 import gate.util.*; 19 import gate.creole.*; 20 import gate.gui.*; 21 22 import java.util.*; 23 import javax.swing.*; 24 25 26 public class SearchPR extends AbstractProcessingResource 27 implements ProcessingResource{ 28 29 private IndexedCorpus corpus = null; 30 private String query = null; 31 private String searcherClassName = null; 32 private QueryResultList resultList = null; 33 private int limit = -1; 34 private List fieldNames = null; 35 36 private Search searcher = null; 37 38 /** Constructor of the class*/ 39 public SearchPR(){ 40 } 41 42 /** Initialise this resource, and return it. */ 43 public Resource init() throws ResourceInstantiationException { 44 Resource result = super.init(); 45 return result; 46 } 47 48 /** 49 * Reinitialises the processing resource. After calling this method the 50 * resource should be in the state it is after calling init. 51 * If the resource depends on external resources (such as rules files) then 52 * the resource will re-read those resources. If the data used to create 53 * the resource has changed since the resource has been created then the 54 * resource will change too after calling reInit(). 55 */ 56 public void reInit() throws ResourceInstantiationException { 57 init(); 58 } 59 60 /** 61 * This method runs the coreferencer. It assumes that all the needed parameters 62 * are set. If they are not, an exception will be fired. 63 */ 64 public void execute() throws ExecutionException { 65 if ( corpus == null){ 66 throw new ExecutionException("Corpus is not initialized"); 67 } 68 if ( query == null){ 69 throw new ExecutionException("Query is not initialized"); 70 } 71 if ( searcher == null){ 72 throw new ExecutionException("Searcher is not initialized"); 73 } 74 75 try { 76 if (((IndexedCorpus) corpus).getIndexManager() == null){ 77 MainFrame.unlockGUI(); 78 JOptionPane.showMessageDialog(null, "Corpus is not indexed!\n" 79 +"Please index fisrt this corpus!", 80 "Search Procesing", JOptionPane.WARNING_MESSAGE); 81 return; 82 } 83 84 fireProgressChanged(0); 85 resultList = null; 86 searcher.setCorpus((IndexedCorpus) corpus); 87 resultList = searcher.search(query, limit, fieldNames); 88 fireProcessFinished(); 89 } 90 91 catch (SearchException ie) { 92 throw new ExecutionException(ie.getMessage()); 93 } 94 catch (IndexException ie) { 95 throw new ExecutionException(ie.getMessage()); 96 } 97 } 98 99 public void setCorpus(IndexedCorpus corpus) { 100 this.corpus = corpus; 101 } 102 103 public IndexedCorpus getCorpus() { 104 return this.corpus; 105 } 106 107 public void setQuery(String query) { 108 this.query = query; 109 } 110 111 public String getQuery() { 112 return this.query; 113 } 114 115 public void setSearcherClassName(String name){ 116 this.searcherClassName = name; 117 try { 118 searcher = (Search) Class.forName(searcherClassName).newInstance(); 119 } 120 catch(Exception e){ 121 e.printStackTrace(); 122 } 123 } 124 125 public String getSearcherClassName(){ 126 127 return this.searcher.getClass().getName(); 128 } 129 130 public void setLimit(Integer limit){ 131 this.limit = limit.intValue(); 132 } 133 134 public Integer getLimit(){ 135 return new Integer(this.limit); 136 } 137 138 public void setFieldNames(List fieldNames){ 139 this.fieldNames = fieldNames; 140 } 141 142 public List getFieldNames(){ 143 return this.fieldNames; 144 } 145 146 public QueryResultList getResult(){ 147 return resultList; 148 } 149 150 public void setResult(QueryResultList qr){ 151 throw new UnsupportedOperationException(); 152 } 153 154 }
|
SearchPR |
|