Changeset 2118
- Timestamp:
- Nov 18, 2009, 8:46:32 AM (16 years ago)
- Location:
- trunk/src/de/mpiwg/itgroup/fulltext/ocropus
- Files:
-
- 1 added
- 2 edited
-
OCRFulltextSearchXML.java (modified) (6 diffs)
-
SearchAndShowThread.java (modified) (6 diffs)
-
SearchAndShowThreadMem.java (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/de/mpiwg/itgroup/fulltext/ocropus/OCRFulltextSearchXML.java
r1884 r2118 5 5 import java.io.FileInputStream; 6 6 import java.io.FileNotFoundException; 7 import java.io.FileReader; 7 8 import java.io.IOException; 8 9 import java.util.ArrayList; … … 57 58 private HashMap<String,OCRSearchThread> searchThreads = null; 58 59 59 static private HashMap<String, SearchAndShowThread> generalThreads;60 static private HashMap<String, Object> generalThreads; 60 61 61 62 //static private HashMap<String,WrapperThread> wrapperThreads; … … 172 173 if (generalThreads==null) 173 174 { 174 generalThreads = new HashMap<String,SearchAndShowThread>(); 175 } 175 generalThreads = new HashMap<String,Object>(); 176 } 177 178 if (notEnoughMemory()){ 179 generalThreads.put(ticket,null); 180 return ticket; 181 } 182 176 183 ArrayList<String> ll = new ArrayList<String>(); 177 184 System.out.println("languages:"+languages); … … 213 220 if (generalThreads==null) 214 221 { 215 generalThreads = new HashMap<String,SearchAndShowThread>(); 222 generalThreads = new HashMap<String,Object>(); 223 } 224 225 if (notEnoughMemory()){ 226 generalThreads.put(ticket,null); 227 return ticket; 216 228 } 217 229 … … 230 242 231 243 232 System.err.println("THREAD :"+generalThreads);244 System.err.println("THREADS:"+generalThreads.size()); 233 245 return ticket; 234 246 235 247 } 236 248 249 //test ob noch genug heapSpace fuer neuen thread, annahme mindestens 20 000 000 Bytes. 250 251 private boolean notEnoughMemory() { 252 long fm = Runtime.getRuntime().freeMemory(); 253 if (fm < 20000000){ 254 System.err.println("not enough memory:"+String.valueOf(fm)); 255 return true; 256 } 257 258 259 return false; 260 261 } 262 237 263 public String getSearchResult(String ticket){ 238 264 System.out.println("myTicket:"+ticket); 239 265 System.out.println(this.generalThreads); 240 SearchAndShowThread st = generalThreads.get(ticket); 266 267 Object stObj = generalThreads.get(ticket); 268 SearchAndShowThread st=null; 269 270 if (SearchAndShowThread.class.isInstance(stObj)) 271 st = (SearchAndShowThread)generalThreads.get(ticket); 272 273 else 274 return "<error value=\"not enough memory\" valueNum=\"1\"/>"; 275 241 276 if (st.returnValue==null){ 242 277 //System..println("ret: WAIT"); … … 245 280 } 246 281 else { 247 String txt= st.returnValue; 282 //String txt= st.returnValue; 283 File retFile = st.returnValue; 284 byte[] buffer = new byte[(int) retFile.length()]; 285 FileInputStream f; 286 try { 287 f = new FileInputStream(retFile); 288 f.read(buffer); 289 f.close(); 290 } catch (FileNotFoundException e) { 291 // TODO Auto-generated catch block 292 System.err.println("getSearchResult: Cannot find temporary file with results:"+retFile.getPath()); 293 } catch (IOException e) { 294 System.err.println("getSearchResult: IO error:"+retFile.getPath()); 295 e.printStackTrace(); 296 } 297 retFile.delete(); 298 299 248 300 generalThreads.remove(ticket); 249 301 //System.err.println("ret:"+txt); 250 return txt; 302 return new String(buffer); 303 //return txt; 251 304 252 305 } -
trunk/src/de/mpiwg/itgroup/fulltext/ocropus/SearchAndShowThread.java
r1887 r2118 1 1 package de.mpiwg.itgroup.fulltext.ocropus; 2 2 3 import java.io.File; 4 import java.io.FileWriter; 3 5 import java.io.IOException; 4 6 import java.util.ArrayList; … … 15 17 private HashMap<String, Hits> results; 16 18 17 public StringreturnValue = null;19 public File returnValue = null; 18 20 public String currentLanguage = null; 19 21 public int counter = 0; … … 87 89 } 88 90 89 private StringwrapResultsInXMLShort(HashMap<String, Hits> results) throws CorruptIndexException, IOException91 private File wrapResultsInXMLShort(HashMap<String, Hits> results) throws CorruptIndexException, IOException 90 92 { 93 long mem0 = Runtime.getRuntime().freeMemory(); 94 long mem1; 95 96 File tempFile = File.createTempFile("temp", ".tmp" ); 97 98 FileWriter fw = new FileWriter(tempFile); 99 100 //String ret="<searchresult encoding=\"utf-8\">"; 101 fw.write("<searchresult encoding=\"utf-8\">"); 102 for (String lang: results.keySet()) 103 //gehe durch alle Sprachen 104 { 105 currentLanguage=lang; 106 107 HashMap<String, ArrayList<String>> linesInPath = new HashMap<String,ArrayList<String>>(); 108 HashMap<String, ArrayList<String>> boxesInPath = new HashMap<String,ArrayList<String>>(); 109 HashMap<String, ArrayList<String>> dimInPath = new HashMap<String,ArrayList<String>>(); 110 HashMap<String, String> dcMetaDataInPath = new HashMap<String,String>(); 111 fw.write("<results lang=\""+lang+"\"><resultsShort>"); 112 analyseResults(results, lang, linesInPath, boxesInPath, dimInPath,dcMetaDataInPath); 113 //String mdString = dcMetaDataInPath.toString(); 114 //System.out.println("mdString:"+mdString.getBytes("utf-8")); 115 fw.write("<dcMetaDatas>"+dcMetaDataInPath.toString()+"</dcMetaDatas>"); 116 117 //System.out.println("wrapResultsInXMLShort: Analised the results:"+lang); 118 //setze das jetzt in XML 119 120 fw.write("<lines>"+pack(linesInPath)+"</lines>"); 121 fw.write("<boxes>"+pack(boxesInPath)+"</boxes>"); 122 fw.write("<dims>"+pack(dimInPath)+"</dims>"); 123 124 System.out.println("wrapResultsInXMLShort: Wrapped the results:"+lang 125 ); 126 fw.write("</resultsShort></results>"); 127 } 128 System.out.println("wrapResultsInXMLShort: Wrapped the results"); 129 mem1 = Runtime.getRuntime().freeMemory(); 130 Runtime.getRuntime().gc(); 131 System.out.println("free memory changed:"+String.valueOf(mem1-mem0)); 132 System.out.println("free memory current:"+String.valueOf(mem1)); 133 fw.write("</searchresult>"); 134 fw.close(); 135 return tempFile; 136 } 137 138 private String wrapResultsInXMLShortMem(HashMap<String, Hits> results) throws CorruptIndexException, IOException 139 { 140 long mem0 = Runtime.getRuntime().totalMemory() - 141 Runtime.getRuntime().freeMemory(); 142 143 91 144 String ret="<searchresult encoding=\"utf-8\">"; 92 145 for (String lang: results.keySet()) … … 117 170 } 118 171 System.out.println("wrapResultsInXMLShort: Wrapped the results"); 172 long mem1 = Runtime.getRuntime().totalMemory() - 173 Runtime.getRuntime().freeMemory(); 174 175 System.out.println("memory:"+String.valueOf(mem1-mem0)); 119 176 return ret+"</searchresult>"; 120 177 } … … 133 190 // TODO Auto-generated catch block 134 191 e1.printStackTrace(); 135 returnValue = "";192 returnValue =null; 136 193 } catch (IOException e1) { 137 194 // TODO Auto-generated catch block 138 195 e1.printStackTrace(); 139 returnValue = "";196 returnValue =null; 140 197 } 141 198 try { … … 143 200 } catch (CorruptIndexException e) { 144 201 e.printStackTrace(); 145 returnValue = "";202 returnValue =null; 146 203 } catch (IOException e) { 147 204 // TODO Auto-generated catch block 148 205 e.printStackTrace(); 149 returnValue = "";206 returnValue =null; 150 207 151 208 }
Note: See TracChangeset
for help on using the changeset viewer.