Ignore:
Timestamp:
11/02/08 13:05:01 (16 years ago)
Author:
ra33
Message:
 
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  
    55import java.util.Collections;
    66import java.util.Comparator;
     7import java.util.HashSet;
    78import java.util.List;
    89
     
    4546        @Override
    4647        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
    5052                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
    5257                        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                        }
    5366                }
    54                
     67
    5568                ArrayList<Item> columnHeads = new ArrayList<Item>();
    5669
     
    175188                        overwriteMessage("Formatting complete.");
    176189        }
    177        
     190
    178191        @Override
    179192        protected void message(String message) {
  • trunk/src/org/expeditee/agents/SearchAgent.java

    r362 r376  
    11package org.expeditee.agents;
     2
     3import java.util.Collection;
    24
    35import org.expeditee.gui.Frame;
     
    2426
    2527        public SearchAgent(String searchText) {
    26                 _pattern = searchText.toLowerCase();
     28                if (searchText != null)
     29                        _pattern = searchText.toLowerCase();
    2730        }
    2831
     
    3942                                        false);
    4043                }
    41                 return initialise(frame, item, frame.getFramesetName(), resultFrameset,
     44                return initialise(frame, item, getSearchDescription(frame), resultFrameset,
    4245                                null, pattern);
     46        }
     47
     48        /**
     49         * @param frame
     50         * @return
     51         */
     52        protected String getSearchDescription(Frame frame) {
     53                return frame.getFramesetName();
    4354        }
    4455
     
    5667        public boolean initialise(Frame frame, Item item, String startName,
    5768                        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
    6072                if (_pattern == null)
    6173                        _pattern = pattern.toLowerCase();
     
    6678                // and type as the title
    6779                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);
    7083                // Set the frame to be displayed after running the agent
    7184                _end = _results.getFirstFrame();
    7285
    7386                return super.initialise(frame, item);
     87        }
     88
     89        protected String getResultsTitleSuffix() {
     90                return " [" + _pattern + "]";
    7491        }
    7592
     
    111128                return true;
    112129        }
     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        }
    113166}
  • trunk/src/org/expeditee/agents/SearchFrameset.java

    r362 r376  
    44
    55import org.expeditee.gui.Frame;
    6 import org.expeditee.gui.FrameGraphics;
    76import org.expeditee.gui.FrameIO;
    87
    9 public class SearchFramesetFast extends SearchAgent {
     8public class SearchFrameset extends SearchAgent {
    109        private long _firstFrame = 1;
    1110
    1211        private long _maxFrame = Integer.MAX_VALUE;
    1312
    14         public SearchFramesetFast(long firstFrame, long maxFrame, String searchText) {
     13        public SearchFrameset(long firstFrame, long maxFrame, String searchText) {
    1514                this(searchText);
    1615                _firstFrame = firstFrame;
     
    1817        }
    1918
    20         public SearchFramesetFast(String searchText) {
     19        public SearchFrameset(String searchText) {
    2120                super(searchText);
    2221        }
     
    3837                        Collection<String> found = FrameIO.searchFrame(frameName, _pattern,
    3938                                        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);
    6240                }
    6341                _results.save();
  • trunk/src/org/expeditee/agents/SearchGreenstone.java

    r336 r376  
    11package org.expeditee.agents;
    22
    3 import java.util.Enumeration;
    43import java.util.HashMap;
    54import java.util.Map;
     
    3029        protected static Greenstone3Connection _gsdl = null;
    3130
     31        public static Greenstone3Connection getConnection() {
     32                return _gsdl;
     33        }
     34
    3235        private static String _maxResults = "10";
    3336
     
    8487        }
    8588
     89        public SearchGreenstone(int resultsCount) {
     90                this(null);
     91                _thisMaxResults = resultsCount + "";
     92        }
     93
    8694        public SearchGreenstone() {
    8795                super(null);
     
    113121                        else if (attribute.equals("autoconnect"))
    114122                                connect();
    115 
    116123                        else if (attribute.equals("maxresults")) {
    117124                                try {
     
    119126                                } catch (Exception e) {
    120127                                }
    121                         }
    122 
    123                         else if (attribute.equals("dostemming"))
     128                        } else if (attribute.equals("dostemming"))
    124129                                _doStemming = true;
    125130                        else if (attribute.startsWith("showabstract"))
     
    139144        }
    140145
     146        protected String getResultsTitle() {
     147                return this.getClass().getSimpleName() + "[" + getCursorText() + "]";
     148        }
     149
    141150        @Override
    142151        protected Frame process(Frame frame) {
    143                 String resultsTitle = this.getClass().getSimpleName() + "["
    144                                 + _fullCaseSearchQuery + "]";
     152                String resultsTitle = getResultsTitle();
    145153                _results.setTitle(resultsTitle);
    146154
     
    150158                } else if (_currentResultSet != null) {
    151159                        Text newText = DisplayIO.getCurrentFrame().createNewText(
    152                                         _fullCaseSearchQuery);
     160                                        getCursorText());
    153161                        _clicked = newText;
    154162                        FrameMouseActions.pickup(newText);
    155163                }
    156164
    157                 if (_currentResultSet == null) {
    158                         MessageBay.errorMessage("Could not find Greenstone query text");
     165                if (_currentResultSet == null || _currentResultSet.size() == 0) {
     166                        MessageBay.errorMessage(getNoResultsMessage());
    159167                        return null;
    160168                }
     
    171179
    172180                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;
    173192        }
    174193
     
    189208                Query query = createQuery(queryText);
    190209                QueryOutcome queryOutcome = _gsdl.issueQueryToServer(query);
    191                 _currentResultSet = getResultSetMetadata(queryOutcome);
     210                if (queryOutcome != null)
     211                        _currentResultSet = getResultSetMetadata(queryOutcome);
    192212        }
    193213
     
    281301
    282302                if (rd.metadataExists("Title")) {
    283                         resultText.append("title = " + rd.getTitle()).append('\n');
     303                        resultText.append("title: " + rd.getTitle()).append('\n');
    284304                }
    285305                if (rd.metadataExists("Date")) {
    286                         resultText.append("date = " + rd.getDate()).append('\n');
     306                        resultText.append("date: " + rd.getDate()).append('\n');
    287307                }
    288308                if (rd.metadataExists("Booktitle")) {
    289                         resultText.append("booktitle = " + rd.getBooktitle()).append('\n');
     309                        resultText.append("booktitle: " + rd.getBooktitle()).append('\n');
    290310                }
    291311                if (rd.metadataExists("Pages")) {
    292                         resultText.append("pages = " + rd.getPages()).append('\n');
     312                        resultText.append("pages: " + rd.getPages()).append('\n');
    293313                }
    294314                if (rd.metadataExists("Journal")) {
    295                         resultText.append("journal = " + rd.getJournal()).append('\n');
     315                        resultText.append("journal: " + rd.getJournal()).append('\n');
    296316                }
    297317                if (rd.metadataExists("Volume")) {
    298                         resultText.append("volume = " + rd.getVolume()).append('\n');
     318                        resultText.append("volume: " + rd.getVolume()).append('\n');
    299319                }
    300320                if (rd.metadataExists("Number")) {
    301                         resultText.append("number = " + rd.getNumber()).append('\n');
     321                        resultText.append("number: " + rd.getNumber()).append('\n');
    302322                }
    303323                if (rd.metadataExists("Editor")) {
    304                         resultText.append("editor = " + rd.getEditor()).append('\n');
     324                        resultText.append("editor: " + rd.getEditor()).append('\n');
    305325                }
    306326                if (rd.metadataExists("Publisher")) {
    307                         resultText.append("publisher = " + rd.getPublisher()).append('\n');
     327                        resultText.append("publisher: " + rd.getPublisher()).append('\n');
    308328                }
    309329                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
    322340                resultText.deleteCharAt(resultText.length() - 1);
    323341
     
    356374        }
    357375
     376        public static void clearSession() {
     377                getConnection().getSessionResults().clear();
     378                _currentResultSet = null;
     379        }
     380
    358381}
  • trunk/src/org/expeditee/agents/SearchTree.java

    r362 r376  
    1111import java.util.Map;
    1212
     13import org.expeditee.gui.AttributeValuePair;
    1314import org.expeditee.gui.Frame;
    14 import org.expeditee.gui.FrameGraphics;
    1515import org.expeditee.gui.FrameIO;
    1616import org.expeditee.gui.UserSettings;
    1717import org.expeditee.io.Conversion;
    1818
    19 public class SearchTreeFast extends SearchAgent {
     19public class SearchTree extends SearchAgent {
    2020        private Map<String, Collection<String>> _searchResults = new HashMap<String, Collection<String>>();
    2121
    22         public SearchTreeFast(String searchText) {
     22        public SearchTree(String searchText) {
    2323                super(searchText);
    2424        }
    25        
     25
    2626        @Override
    2727        protected Frame process(Frame frame) {
    28                 if(frame == null)
     28                if (frame == null)
    2929                        frame = FrameIO.LoadFrame(_startName);
    30                
    31                 searchTree(frame.getName(), _pattern, _searchResults, new HashSet<String>());
    32                
     30
     31                searchTree(frame.getName(), _searchResults, new HashSet<String>());
    3332                _results.save();
    3433
     
    3635                if (_clicked != null)
    3736                        _clicked.setLink(resultFrameName);
    38                
     37
    3938                return _results.getFirstFrame();
    4039        }
    41        
     40
     41        @Override
     42        /**
     43         * @param frame
     44         * @return
     45         */
     46        protected String getSearchDescription(Frame frame) {
     47                return frame.getName();
     48        }
     49
    4250        /**
    4351         * 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
    4862         */
    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))
    5267                        return;
    53                
     68
    5469                visited.add(frameName);
    55                
     70
    5671                String fullPath = null;
    5772                for (String possiblePath : UserSettings.FrameDirs) {
     
    6479                if (fullPath == null)
    6580                        return;
    66                
     81
    6782                _frameCount++;
    6883                overwriteMessage("Searching " + frameName);
    69                
     84
    7085                String frameset = Conversion.getFramesetName(frameName);
    71                
     86
    7287                Collection<String> frameResults = new LinkedList<String>();
    7388                // Open the file and search the text items
     
    7590                        BufferedReader reader = new BufferedReader(new FileReader(fullPath));
    7691                        String next;
     92                        StringBuffer sb = new StringBuffer();
     93                        String link = null;
     94                        boolean ignore = false;
     95
    7796                        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)))
    85141                                                link = frameset + link;
    86                                         searchTree(link, pattern, results, visited);
    87142                                }
    88143                        }
    89                         //Only add the results if a match was found on the frame
    90                         if(frameResults.size() > 0){
     144                        // Only add the results if a match was found on the frame
     145                        if (frameResults.size() > 0) {
    91146                                results.put(frameName, frameResults);
    92147                        }
     
    97152                }
    98153                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);
    103161                }
    104162        }
     163
     164        protected String getResultSurrogate(String toSearch) {
     165                if (toSearch.toLowerCase().contains(_pattern))
     166                        return toSearch;
     167                return null;
     168        }
    105169}
  • trunk/src/org/expeditee/agents/wordprocessing/JSpellChecker.java

    r362 r376  
    11package org.expeditee.agents.wordprocessing;
    22
     3import java.awt.Color;
    34import java.io.File;
    45import java.io.FileNotFoundException;
     
    89import java.util.List;
    910
     11import org.expeditee.gui.Frame;
    1012import org.expeditee.gui.FrameIO;
     13import org.expeditee.gui.MessageBay;
     14import org.expeditee.items.Text;
    1115
    1216import com.swabunga.spell.engine.Configuration;
     
    5963        public static JSpellChecker _theInstance = null;
    6064
    61         public static JSpellChecker getInstance() throws FileNotFoundException, IOException {
     65        public static JSpellChecker getInstance() throws FileNotFoundException,
     66                        IOException {
    6267                if (_theInstance == null) {
    6368                        create();
     
    6671        }
    6772
     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
    6888        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/";
    7493
    7594        public JSpellChecker() {
     
    7998        public void init() throws FileNotFoundException, IOException {
    8099                log(this.hashCode() + ": JSpellChecker.init");
     100                MessageBay.displayMessage("Loading spell checker...");
    81101
    82102                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);
    85110
    86111                initialized = true;
     112
     113                MessageBay.displayMessage("Spell checker Loaded", Color.green.darker());
    87114        }
    88115
     
    97124                checker.addSpellCheckListener(listener);
    98125                checker.reset();
     126                event = null;
    99127        }
    100128
     
    137165
    138166                }
    139                
    140                 if(s.length() == 0){
     167
     168                if (s.length() == 0) {
    141169                        return "No suggestions";
    142170                }
     
    146174                // + "|";
    147175                // }
    148                 return s.substring(0, s.length()-1);
     176                return s.substring(0, s.length() - 1);
    149177        }
    150178
Note: See TracChangeset for help on using the changeset viewer.