Changeset 376 for trunk/src/org/expeditee/agents
- Timestamp:
- 11/02/08 13:05:01 (16 years ago)
- Location:
- trunk/src/org/expeditee/agents
- Files:
-
- 4 added
- 4 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/agents/Format.java
r307 r376 5 5 import java.util.Collections; 6 6 import java.util.Comparator; 7 import java.util.HashSet; 7 8 import java.util.List; 8 9 … … 45 46 @Override 46 47 public Frame process(Frame start) { 47 //TODO What will happen if user runs the SIMPLE form of this... 48 //Does format box need to be disabled?!?! 49 //Check the position of the cursor and only format stuff inside the same box as the cursor 48 // TODO What will happen if user runs the SIMPLE form of this... 49 // Does format box need to be disabled?!?! 50 // Check the position of the cursor and only format stuff inside the 51 // same box as the cursor 50 52 Collection<Text> itemsToFormat = FrameUtils.getCurrentTextItems(); 51 if(itemsToFormat.size() < 1){ 53 54 // If the cursor is not inside a box... 55 if (itemsToFormat.size() < 1) { 56 // Add all the items that are in free space 52 57 itemsToFormat = start.getBodyTextItems(true); 58 // Remove all the enclosed items 59 Collection<Item> seen = new HashSet<Item>(); 60 for (Item i : start.getVisibleItems()) { 61 if (!seen.contains(i) && i.isEnclosed()) { 62 seen.addAll(i.getEnclosingDots()); 63 itemsToFormat.removeAll(i.getEnclosedItems()); 64 } 65 } 53 66 } 54 67 55 68 ArrayList<Item> columnHeads = new ArrayList<Item>(); 56 69 … … 175 188 overwriteMessage("Formatting complete."); 176 189 } 177 190 178 191 @Override 179 192 protected void message(String message) { -
trunk/src/org/expeditee/agents/SearchAgent.java
r362 r376 1 1 package org.expeditee.agents; 2 3 import java.util.Collection; 2 4 3 5 import org.expeditee.gui.Frame; … … 24 26 25 27 public SearchAgent(String searchText) { 26 _pattern = searchText.toLowerCase(); 28 if (searchText != null) 29 _pattern = searchText.toLowerCase(); 27 30 } 28 31 … … 39 42 false); 40 43 } 41 return initialise(frame, item, frame.getFramesetName(), resultFrameset,44 return initialise(frame, item, getSearchDescription(frame), resultFrameset, 42 45 null, pattern); 46 } 47 48 /** 49 * @param frame 50 * @return 51 */ 52 protected String getSearchDescription(Frame frame) { 53 return frame.getFramesetName(); 43 54 } 44 55 … … 56 67 public boolean initialise(Frame frame, Item item, String startName, 57 68 String resultsFrameset, String replacementString, String pattern) { 58 //TODO: Put the init params in the constructor!! Dont want to be setting _pattern in two places! 59 69 // TODO: Put the init params in the constructor!! Dont want to be 70 // setting _pattern in two places! 71 60 72 if (_pattern == null) 61 73 _pattern = pattern.toLowerCase(); … … 66 78 // and type as the title 67 79 String title = this.getClass().getSimpleName() + " [" + startName 68 + "] [" + _pattern + "]"; 69 _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title, false, true); 80 + "]"+getResultsTitleSuffix(); 81 _results = new FrameCreator(resultsFrameset, FrameIO.FRAME_PATH, title, 82 false, true); 70 83 // Set the frame to be displayed after running the agent 71 84 _end = _results.getFirstFrame(); 72 85 73 86 return super.initialise(frame, item); 87 } 88 89 protected String getResultsTitleSuffix() { 90 return " [" + _pattern + "]"; 74 91 } 75 92 … … 111 128 return true; 112 129 } 130 131 protected int addResults(String frameName, Collection<String> found) { 132 return addResults(frameName, frameName, found); 133 } 134 135 /** 136 * @param frameNumber 137 * @param frameName 138 * @param found 139 * @return 140 */ 141 protected int addResults(String frameNumber, String frameName, Collection<String> found) { 142 int size = found == null ? 0 : found.size(); 143 // If the frame exists 144 if (found != null) 145 _frameCount++; 146 if (size > 0) { 147 // String repeats = size > 1? ("("+ size+ ")") : ""; 148 for (String s : found) { 149 StringBuffer surrogate = new StringBuffer(); 150 surrogate.append("[").append(frameNumber).append("] "); 151 if (s.length() > SearchAgent.SURROGATE_LENGTH) 152 surrogate.append( 153 s.substring(0, SearchAgent.SURROGATE_LENGTH - 3)) 154 .append("..."); 155 else { 156 surrogate.append(s); 157 } 158 159 _results.addText(surrogate.toString(), null, 160 frameName, null, false); 161 FrameGraphics.requestRefresh(true); 162 } 163 } 164 return size; 165 } 113 166 } -
trunk/src/org/expeditee/agents/SearchFrameset.java
r362 r376 4 4 5 5 import org.expeditee.gui.Frame; 6 import org.expeditee.gui.FrameGraphics;7 6 import org.expeditee.gui.FrameIO; 8 7 9 public class SearchFrameset Fastextends SearchAgent {8 public class SearchFrameset extends SearchAgent { 10 9 private long _firstFrame = 1; 11 10 12 11 private long _maxFrame = Integer.MAX_VALUE; 13 12 14 public SearchFrameset Fast(long firstFrame, long maxFrame, String searchText) {13 public SearchFrameset(long firstFrame, long maxFrame, String searchText) { 15 14 this(searchText); 16 15 _firstFrame = firstFrame; … … 18 17 } 19 18 20 public SearchFrameset Fast(String searchText) {19 public SearchFrameset(String searchText) { 21 20 super(searchText); 22 21 } … … 38 37 Collection<String> found = FrameIO.searchFrame(frameName, _pattern, 39 38 path); 40 int size = found == null ? 0 : found.size(); 41 // If the frame exists 42 if (found != null) 43 _frameCount++; 44 if (size > 0) { 45 // String repeats = size > 1? ("("+ size+ ")") : ""; 46 for (String s : found) { 47 StringBuffer surrogate = new StringBuffer(); 48 surrogate.append("[").append(i).append("] "); 49 if (s.length() > SearchAgent.SURROGATE_LENGTH) 50 surrogate.append( 51 s.substring(0, SearchAgent.SURROGATE_LENGTH - 3)) 52 .append("..."); 53 else { 54 surrogate.append(s); 55 } 56 57 _results.addText(surrogate.toString(), null, 58 frameName, null, false); 59 FrameGraphics.requestRefresh(true); 60 } 61 } 39 addResults(i + "", frameName, found); 62 40 } 63 41 _results.save(); -
trunk/src/org/expeditee/agents/SearchGreenstone.java
r336 r376 1 1 package org.expeditee.agents; 2 2 3 import java.util.Enumeration;4 3 import java.util.HashMap; 5 4 import java.util.Map; … … 30 29 protected static Greenstone3Connection _gsdl = null; 31 30 31 public static Greenstone3Connection getConnection() { 32 return _gsdl; 33 } 34 32 35 private static String _maxResults = "10"; 33 36 … … 84 87 } 85 88 89 public SearchGreenstone(int resultsCount) { 90 this(null); 91 _thisMaxResults = resultsCount + ""; 92 } 93 86 94 public SearchGreenstone() { 87 95 super(null); … … 113 121 else if (attribute.equals("autoconnect")) 114 122 connect(); 115 116 123 else if (attribute.equals("maxresults")) { 117 124 try { … … 119 126 } catch (Exception e) { 120 127 } 121 } 122 123 else if (attribute.equals("dostemming")) 128 } else if (attribute.equals("dostemming")) 124 129 _doStemming = true; 125 130 else if (attribute.startsWith("showabstract")) … … 139 144 } 140 145 146 protected String getResultsTitle() { 147 return this.getClass().getSimpleName() + "[" + getCursorText() + "]"; 148 } 149 141 150 @Override 142 151 protected Frame process(Frame frame) { 143 String resultsTitle = this.getClass().getSimpleName() + "[" 144 + _fullCaseSearchQuery + "]"; 152 String resultsTitle = getResultsTitle(); 145 153 _results.setTitle(resultsTitle); 146 154 … … 150 158 } else if (_currentResultSet != null) { 151 159 Text newText = DisplayIO.getCurrentFrame().createNewText( 152 _fullCaseSearchQuery);160 getCursorText()); 153 161 _clicked = newText; 154 162 FrameMouseActions.pickup(newText); 155 163 } 156 164 157 if (_currentResultSet == null ) {158 MessageBay.errorMessage( "Could not find Greenstone query text");165 if (_currentResultSet == null || _currentResultSet.size() == 0) { 166 MessageBay.errorMessage(getNoResultsMessage()); 159 167 return null; 160 168 } … … 171 179 172 180 return _results.getFirstFrame(); 181 } 182 183 protected String getNoResultsMessage() { 184 return "Could not find Greenstone query text"; 185 } 186 187 /** 188 * @return 189 */ 190 protected String getCursorText() { 191 return _fullCaseSearchQuery; 173 192 } 174 193 … … 189 208 Query query = createQuery(queryText); 190 209 QueryOutcome queryOutcome = _gsdl.issueQueryToServer(query); 191 _currentResultSet = getResultSetMetadata(queryOutcome); 210 if (queryOutcome != null) 211 _currentResultSet = getResultSetMetadata(queryOutcome); 192 212 } 193 213 … … 281 301 282 302 if (rd.metadataExists("Title")) { 283 resultText.append("title =" + rd.getTitle()).append('\n');303 resultText.append("title: " + rd.getTitle()).append('\n'); 284 304 } 285 305 if (rd.metadataExists("Date")) { 286 resultText.append("date =" + rd.getDate()).append('\n');306 resultText.append("date: " + rd.getDate()).append('\n'); 287 307 } 288 308 if (rd.metadataExists("Booktitle")) { 289 resultText.append("booktitle =" + rd.getBooktitle()).append('\n');309 resultText.append("booktitle: " + rd.getBooktitle()).append('\n'); 290 310 } 291 311 if (rd.metadataExists("Pages")) { 292 resultText.append("pages =" + rd.getPages()).append('\n');312 resultText.append("pages: " + rd.getPages()).append('\n'); 293 313 } 294 314 if (rd.metadataExists("Journal")) { 295 resultText.append("journal =" + rd.getJournal()).append('\n');315 resultText.append("journal: " + rd.getJournal()).append('\n'); 296 316 } 297 317 if (rd.metadataExists("Volume")) { 298 resultText.append("volume =" + rd.getVolume()).append('\n');318 resultText.append("volume: " + rd.getVolume()).append('\n'); 299 319 } 300 320 if (rd.metadataExists("Number")) { 301 resultText.append("number =" + rd.getNumber()).append('\n');321 resultText.append("number: " + rd.getNumber()).append('\n'); 302 322 } 303 323 if (rd.metadataExists("Editor")) { 304 resultText.append("editor =" + rd.getEditor()).append('\n');324 resultText.append("editor: " + rd.getEditor()).append('\n'); 305 325 } 306 326 if (rd.metadataExists("Publisher")) { 307 resultText.append("publisher =" + rd.getPublisher()).append('\n');327 resultText.append("publisher: " + rd.getPublisher()).append('\n'); 308 328 } 309 329 if (rd.metadataExists("Abstract")) { 310 resultText.append("abstract = " + rd.getAbstract()).append('\n'); 311 } 312 Vector<String> authors = rd.getAuthors(); 313 for (Enumeration a = authors.elements(); a.hasMoreElements();) { 314 String author = (String) a.nextElement(); 315 resultText.append("author = " + author).append('\n'); 316 } 317 Vector<String> keywords = rd.getKeywords(); 318 for (Enumeration k = keywords.elements(); k.hasMoreElements();) { 319 String keyword = (String) k.nextElement(); 320 resultText.append("keyword = " + keyword).append('\n'); 321 } 330 resultText.append("abstract: " + rd.getAbstract()).append('\n'); 331 } 332 for (String author : rd.getAuthors()) { 333 resultText.append("author: " + author).append('\n'); 334 } 335 336 for (String keyword : rd.getKeywords()) { 337 resultText.append("keyword: " + keyword).append('\n'); 338 } 339 322 340 resultText.deleteCharAt(resultText.length() - 1); 323 341 … … 356 374 } 357 375 376 public static void clearSession() { 377 getConnection().getSessionResults().clear(); 378 _currentResultSet = null; 379 } 380 358 381 } -
trunk/src/org/expeditee/agents/SearchTree.java
r362 r376 11 11 import java.util.Map; 12 12 13 import org.expeditee.gui.AttributeValuePair; 13 14 import org.expeditee.gui.Frame; 14 import org.expeditee.gui.FrameGraphics;15 15 import org.expeditee.gui.FrameIO; 16 16 import org.expeditee.gui.UserSettings; 17 17 import org.expeditee.io.Conversion; 18 18 19 public class SearchTree Fastextends SearchAgent {19 public class SearchTree extends SearchAgent { 20 20 private Map<String, Collection<String>> _searchResults = new HashMap<String, Collection<String>>(); 21 21 22 public SearchTree Fast(String searchText) {22 public SearchTree(String searchText) { 23 23 super(searchText); 24 24 } 25 25 26 26 @Override 27 27 protected Frame process(Frame frame) { 28 if (frame == null)28 if (frame == null) 29 29 frame = FrameIO.LoadFrame(_startName); 30 31 searchTree(frame.getName(), _pattern, _searchResults, new HashSet<String>()); 32 30 31 searchTree(frame.getName(), _searchResults, new HashSet<String>()); 33 32 _results.save(); 34 33 … … 36 35 if (_clicked != null) 37 36 _clicked.setLink(resultFrameName); 38 37 39 38 return _results.getFirstFrame(); 40 39 } 41 40 41 @Override 42 /** 43 * @param frame 44 * @return 45 */ 46 protected String getSearchDescription(Frame frame) { 47 return frame.getName(); 48 } 49 42 50 /** 43 51 * Returns a list of the frames searched and any matches on those frames. 44 * @param frameName the name of the top not in the tree of frames to search 45 * @param pattern the pattern to search for 46 * @param results a list of frames on which matches were found and the text that matched the pattern 47 * @param visited a list of the frames that were visited in the searchTree 52 * 53 * @param frameName 54 * the name of the top not in the tree of frames to search 55 * @param pattern 56 * the pattern to search for 57 * @param results 58 * a list of frames on which matches were found and the text that 59 * matched the pattern 60 * @param visited 61 * a list of the frames that were visited in the searchTree 48 62 */ 49 public void searchTree(String frameName, String pattern, Map<String, Collection<String>> results, Collection<String> visited) { 50 //Check if this node has already been visited 51 if(visited.contains(frameName)) 63 public void searchTree(String frameName, 64 Map<String, Collection<String>> results, Collection<String> visited) { 65 // Check if this node has already been visited 66 if (visited.contains(frameName)) 52 67 return; 53 68 54 69 visited.add(frameName); 55 70 56 71 String fullPath = null; 57 72 for (String possiblePath : UserSettings.FrameDirs) { … … 64 79 if (fullPath == null) 65 80 return; 66 81 67 82 _frameCount++; 68 83 overwriteMessage("Searching " + frameName); 69 84 70 85 String frameset = Conversion.getFramesetName(frameName); 71 86 72 87 Collection<String> frameResults = new LinkedList<String>(); 73 88 // Open the file and search the text items … … 75 90 BufferedReader reader = new BufferedReader(new FileReader(fullPath)); 76 91 String next; 92 StringBuffer sb = new StringBuffer(); 93 String link = null; 94 boolean ignore = false; 95 77 96 while (reader.ready() && ((next = reader.readLine()) != null)) { 78 if (next.startsWith("T")) { 79 String toSearch = next.substring(2); 80 if (toSearch.toLowerCase().contains(pattern)) 81 frameResults.add(toSearch); 82 }else if (next.startsWith("F")) { 83 String link = next.substring(2); 84 if(!FrameIO.isValidFrameName(link)) 97 98 if (next.length() == 0) { 99 // Ignore annotations 100 if (ignore) { 101 ignore = false; 102 link = null; 103 continue; 104 } 105 106 // Ignore non text items 107 if (sb.length() == 0) { 108 link = null; 109 continue; 110 } 111 112 String toSearch = sb.substring(0, sb.length() - 1); 113 String resultSurrogate = getResultSurrogate(toSearch); 114 if (resultSurrogate != null) { 115 frameResults.add(resultSurrogate); 116 } 117 118 if (link != null) { 119 searchTree(link, results, visited); 120 } 121 122 // Reinit the item variables 123 link = null; 124 sb = new StringBuffer(); 125 126 } else if (ignore) { 127 continue; 128 } else if (next.startsWith("T")) { 129 String text = next.substring(2).trim(); 130 // Ignore the rest of annotation items... 131 if (text.length() > 0 132 && text.charAt(0) == AttributeValuePair.ANNOTATION_CHAR) { 133 ignore = true; 134 continue; 135 } 136 sb.append(text).append('\n'); 137 } else if (next.startsWith("F")) { 138 link = next.substring(2); 139 // Convert number only links 140 if (Character.isDigit(link.charAt(0))) 85 141 link = frameset + link; 86 searchTree(link, pattern, results, visited);87 142 } 88 143 } 89 // Only add the results if a match was found on the frame90 if (frameResults.size() > 0){144 // Only add the results if a match was found on the frame 145 if (frameResults.size() > 0) { 91 146 results.put(frameName, frameResults); 92 147 } … … 97 152 } 98 153 int size = frameResults.size(); 99 if(size > 0){ 100 String repeats = size > 1? ("("+ size+ ")") : ""; 101 _results.addText(frameName + repeats, null, frameName, null, false); 102 FrameGraphics.requestRefresh(true); 154 if (size > 0) { 155 addResults(frameName, frameResults); 156 157 // String repeats = size > 1 ? ("(" + size + ")") : ""; 158 // _results.addText(frameName + repeats, null, frameName, null, 159 // false); 160 // FrameGraphics.requestRefresh(true); 103 161 } 104 162 } 163 164 protected String getResultSurrogate(String toSearch) { 165 if (toSearch.toLowerCase().contains(_pattern)) 166 return toSearch; 167 return null; 168 } 105 169 } -
trunk/src/org/expeditee/agents/wordprocessing/JSpellChecker.java
r362 r376 1 1 package org.expeditee.agents.wordprocessing; 2 2 3 import java.awt.Color; 3 4 import java.io.File; 4 5 import java.io.FileNotFoundException; … … 8 9 import java.util.List; 9 10 11 import org.expeditee.gui.Frame; 10 12 import org.expeditee.gui.FrameIO; 13 import org.expeditee.gui.MessageBay; 14 import org.expeditee.items.Text; 11 15 12 16 import com.swabunga.spell.engine.Configuration; … … 59 63 public static JSpellChecker _theInstance = null; 60 64 61 public static JSpellChecker getInstance() throws FileNotFoundException, IOException { 65 public static JSpellChecker getInstance() throws FileNotFoundException, 66 IOException { 62 67 if (_theInstance == null) { 63 68 create(); … … 66 71 } 67 72 73 public static void create(Frame frame) throws FileNotFoundException, 74 IOException { 75 if(_theInstance == null) 76 _theInstance = new JSpellChecker(); 77 _theInstance.init(); 78 79 if (frame != null) { 80 for (Text t : frame.getBodyTextItems(false)) { 81 for (String s : t.getText().split(" ")) { 82 _theInstance.checker.addToDictionary(s); 83 } 84 } 85 } 86 } 87 68 88 public static void create() throws FileNotFoundException, IOException { 69 _theInstance = new JSpellChecker(); 70 _theInstance.init(); 71 } 72 73 public static String dictFile = FrameIO.PARENT_FOLDER + "dict/english.0"; 89 create(null); 90 } 91 92 public static String dictDirectory = FrameIO.PARENT_FOLDER + "dict/"; 74 93 75 94 public JSpellChecker() { … … 79 98 public void init() throws FileNotFoundException, IOException { 80 99 log(this.hashCode() + ": JSpellChecker.init"); 100 MessageBay.displayMessage("Loading spell checker..."); 81 101 82 102 checker = new SpellChecker(); 83 84 checker.addDictionary(new SpellDictionaryHashMap(new File(dictFile))); 103 SpellDictionaryHashMap dictionaryHashMap = new SpellDictionaryHashMap(); 104 105 for (File dict : new File(dictDirectory).listFiles()) { 106 dictionaryHashMap.addDictionary(dict); 107 } 108 109 checker.addDictionary(dictionaryHashMap); 85 110 86 111 initialized = true; 112 113 MessageBay.displayMessage("Spell checker Loaded", Color.green.darker()); 87 114 } 88 115 … … 97 124 checker.addSpellCheckListener(listener); 98 125 checker.reset(); 126 event = null; 99 127 } 100 128 … … 137 165 138 166 } 139 140 if (s.length() == 0){167 168 if (s.length() == 0) { 141 169 return "No suggestions"; 142 170 } … … 146 174 // + "|"; 147 175 // } 148 return s.substring(0, s.length() -1);176 return s.substring(0, s.length() - 1); 149 177 } 150 178
Note:
See TracChangeset
for help on using the changeset viewer.