[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/search/parse s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sat Oct 2 16:51:14 MST 2004


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/parse
In directory www.crosswire.org:/tmp/cvs-serv19722/java/jsword/org/crosswire/jsword/book/search/parse

Modified Files:
	IndexSearcher.java Word.properties 
Added Files:
	PhraseParamWord.java 
Log Message:
advanced search and a-a option.

Index: Word.properties
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/parse/Word.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Word.properties	14 Jun 2004 05:27:22 -0000	1.1
--- Word.properties	2 Oct 2004 23:51:12 -0000	1.2
***************
*** 1,3 ****
--- 1,4 ----
  
+ # Mappings to turn command symbols into classes to execute them
  /: org.crosswire.jsword.book.search.parse.AddCommandWord
  |: org.crosswire.jsword.book.search.parse.AddCommandWord
***************
*** 15,16 ****
--- 16,32 ----
  gr: org.crosswire.jsword.book.search.parse.GrammarParamWord
  grammar: org.crosswire.jsword.book.search.parse.GrammarParamWord
+ \": org.crosswire.jsword.book.search.parse.PhraseParamWord
+ \': org.crosswire.jsword.book.search.parse.PhraseParamWord
+ 
+ # Mappings of preferred symbols for each command
+ org.crosswire.jsword.book.search.parse.AddCommandWord: /
+ org.crosswire.jsword.book.search.parse.RetainCommandWord: +
+ org.crosswire.jsword.book.search.parse.RemoveCommandWord: -
+ org.crosswire.jsword.book.search.parse.BlurCommandWord: ~
+ org.crosswire.jsword.book.search.parse.SubLeftParamWord: (
+ org.crosswire.jsword.book.search.parse.SubRightParamWord: )
+ org.crosswire.jsword.book.search.parse.PassageLeftParamWord: [
+ org.crosswire.jsword.book.search.parse.PassageRightParamWord: ]
+ org.crosswire.jsword.book.search.parse.StartsParamWord: sw
+ org.crosswire.jsword.book.search.parse.GrammarParamWord: gr
+ org.crosswire.jsword.book.search.parse.PhraseParamWord: "

Index: IndexSearcher.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/parse/IndexSearcher.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IndexSearcher.java	29 Sep 2004 22:21:23 -0000	1.1
--- IndexSearcher.java	2 Oct 2004 23:51:12 -0000	1.2
***************
*** 1,11 ****
  package org.crosswire.jsword.book.search.parse;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
- import org.crosswire.common.util.ClassUtil;
  import org.crosswire.common.util.Logger;
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.Search;
--- 1,13 ----
  package org.crosswire.jsword.book.search.parse;
  
+ import java.io.IOException;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
+ import java.util.Properties;
  
  import org.crosswire.common.util.Logger;
+ import org.crosswire.common.util.ResourceUtil;
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.book.Search;
***************
*** 238,258 ****
          if (wordMap == null)
          {
!             Map classes = ClassUtil.getImplementorsMap(Word.class);
!             wordMap = new HashMap();
! 
!             for (Iterator it = classes.keySet().iterator(); it.hasNext(); )
              {
!                 String key = (String) it.next();
!                 Class clazz = (Class) classes.get(key);
  
!                 try
!                 {
!                     wordMap.put(key, clazz.newInstance());
!                 }
!                 catch (Exception ex)
                  {
!                     log.error("can't add CommandWord: key=" + key + " Class=" + clazz.getName(), ex); //$NON-NLS-1$ //$NON-NLS-2$
                  }
              }
          }
  
--- 240,285 ----
          if (wordMap == null)
          {
!             try
              {
!                 Properties prop = ResourceUtil.getProperties(Word.class);
  
!                 wordMap = new HashMap();
!                 preferredMap = new HashMap();
!     
!                 for (Iterator it = prop.keySet().iterator(); it.hasNext(); )
                  {
!                     String key = (String) it.next();
!                     String value = prop.getProperty(key);
! 
!                     if (key.startsWith(PACKAGE_NAME))
!                     {
!                         try
!                         {
!                             Class clazz = Class.forName(key);
!                             preferredMap.put(clazz, value);
!                         }
!                         catch (Exception ex)
!                         {
!                             log.error("can't add CommandWord: key=" + key + " Class=" + value, ex); //$NON-NLS-1$ //$NON-NLS-2$
!                         }
!                     }
!                     else
!                     {
!                         try
!                         {
!                             Class clazz = Class.forName(value);
!                             wordMap.put(key, clazz.newInstance());
!                         }
!                         catch (Exception ex)
!                         {
!                             log.error("can't add CommandWord: key=" + key + " Class=" + value, ex); //$NON-NLS-1$ //$NON-NLS-2$
!                         }
!                     }
                  }
              }
+             catch (IOException ex)
+             {
+                 log.fatal("Missing search words", ex); //$NON-NLS-1$
+             }
          }
  
***************
*** 261,264 ****
--- 288,306 ----
  
      /**
+      * Accessor for the cached list of known special lookup words
+      */
+     public static Map getPreferredMap()
+     {
+         // Check the maps have been created
+         getWordMap();
+         return preferredMap;
+     }
+ 
+     /**
+      * To distinguish command mappings from preferred mappings in Word.properties
+      */
+     private static final String PACKAGE_NAME = "org.crosswire.jsword.book.search.parse"; //$NON-NLS-1$
+ 
+     /**
       * The log stream
       */
***************
*** 271,274 ****
--- 313,321 ----
  
      /**
+      * The cache of preferred symbols for the words
+      */
+     private static Map preferredMap = null;
+ 
+     /**
       * The parsed version of the current string
       */

--- NEW FILE: PhraseParamWord.java ---
package org.crosswire.jsword.book.search.parse;

import java.util.Iterator;

import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.book.search.Index;
import org.crosswire.jsword.passage.Key;
import org.crosswire.jsword.passage.NoSuchKeyException;

/**
 * The Search Word for a Word to search for. The default
 * if no other SearchWords match.
 * 
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 *
 * Distribution Licence:<br />
 * JSword is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public License,
 * version 2 as published by the Free Software Foundation.<br />
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.<br />
 * The License is available on the internet
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA<br />
 * The copyright to this program is held by it's authors.
 * </font></td></tr></table>
 * @see gnu.gpl.Licence
 * @author Joe Walker [joe at eireneh dot com]
 * @version $Id: PhraseParamWord.java,v 1.1 2004/10/02 23:51:12 joe Exp $
 */
public class PhraseParamWord implements ParamWord
{
    /* (non-Javadoc)
     * @see org.crosswire.jsword.book.search.parse.ParamWord#getWord(org.crosswire.jsword.book.search.parse.Searcher)
     */
    public String getWord(IndexSearcher engine) throws BookException
    {
        throw new BookException(Msg.LEFT_PARAM);
    }

    /* (non-Javadoc)
     * @see org.crosswire.jsword.book.search.parse.ParamWord#Key(org.crosswire.jsword.book.search.parse.Searcher)
     */
    public Key getKeyList(IndexSearcher engine) throws BookException
    {
        Iterator it = engine.iterator();
        StringBuffer buff = new StringBuffer();

        int paren_level = 1;
        while (true)
        {
            if (!it.hasNext())
            {
                throw new BookException(Msg.LEFT_BRACKETS);
            }

            Word word = (Word) it.next();

            if (word instanceof PhraseParamWord)
            {
                paren_level++;
            }

            if (word instanceof PassageRightParamWord)
            {
                paren_level--;
            }

            if (paren_level == 0)
            {
                break;
            }

            buff.append(word);
            buff.append(" "); //$NON-NLS-1$
        }

        try
        {
            Index index = engine.getIndex();

            return index.getKey(buff.toString());
        }
        catch (NoSuchKeyException ex)
        {
            throw new BookException(Msg.ILLEGAL_PASSAGE, ex, new Object[] { buff.toString() });
        }
    }
}



More information about the jsword-svn mailing list