Coverage Report - org.crosswire.jsword.index.lucene.analysis.ArabicLuceneAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
ArabicLuceneAnalyzer
0%
0/24
0%
0/14
3.333
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2009 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.index.lucene.analysis;
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.io.Reader;
 24  
 
 25  
 import org.apache.lucene.analysis.LowerCaseFilter;
 26  
 import org.apache.lucene.analysis.StopFilter;
 27  
 import org.apache.lucene.analysis.TokenStream;
 28  
 import org.apache.lucene.analysis.ar.ArabicAnalyzer;
 29  
 import org.apache.lucene.analysis.ar.ArabicLetterTokenizer;
 30  
 import org.apache.lucene.analysis.ar.ArabicNormalizationFilter;
 31  
 import org.apache.lucene.analysis.ar.ArabicStemFilter;
 32  
 import org.apache.lucene.util.Version;
 33  
 
 34  
 /**
 35  
  * An Analyzer whose {@link TokenStream} is built from a
 36  
  * {@link ArabicLetterTokenizer} filtered with {@link LowerCaseFilter},
 37  
  * {@link ArabicNormalizationFilter}, {@link ArabicStemFilter} (optional) and
 38  
  * Arabic {@link StopFilter} (optional).
 39  
  * 
 40  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 41  
  * @author DM Smith
 42  
  */
 43  
 public class ArabicLuceneAnalyzer extends AbstractBookAnalyzer {
 44  0
     public ArabicLuceneAnalyzer() {
 45  0
         stopSet = ArabicAnalyzer.getDefaultStopSet();
 46  0
     }
 47  
 
 48  
     /* (non-Javadoc)
 49  
      * @see org.apache.lucene.analysis.Analyzer#tokenStream(java.lang.String, java.io.Reader)
 50  
      */
 51  
     @Override
 52  
     public final TokenStream tokenStream(String fieldName, Reader reader) {
 53  0
         TokenStream result = new ArabicLetterTokenizer(reader);
 54  0
         result = new LowerCaseFilter(result);
 55  0
         result = new ArabicNormalizationFilter(result);
 56  0
         if (doStopWords && stopSet != null) {
 57  0
             result = new StopFilter(false, result, stopSet);
 58  
         }
 59  
 
 60  0
         if (doStemming) {
 61  0
             result = new ArabicStemFilter(result);
 62  
         }
 63  
 
 64  0
         return result;
 65  
     }
 66  
 
 67  
     /* (non-Javadoc)
 68  
      * @see org.apache.lucene.analysis.Analyzer#reusableTokenStream(java.lang.String, java.io.Reader)
 69  
      */
 70  
     @Override
 71  
     public TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
 72  0
         SavedStreams streams = (SavedStreams) getPreviousTokenStream();
 73  0
         if (streams == null) {
 74  0
             streams = new SavedStreams(new ArabicLetterTokenizer(reader));
 75  0
             streams.setResult(new LowerCaseFilter(streams.getResult()));
 76  0
             streams.setResult(new ArabicNormalizationFilter(streams.getResult()));
 77  
 
 78  0
             if (doStopWords && stopSet != null) {
 79  0
                 streams.setResult(new StopFilter(StopFilter.getEnablePositionIncrementsVersionDefault(matchVersion), streams.getResult(), stopSet));
 80  
             }
 81  
 
 82  0
             if (doStemming) {
 83  0
                 streams.setResult(new ArabicStemFilter(streams.getResult()));
 84  
             }
 85  
 
 86  0
             setPreviousTokenStream(streams);
 87  
         } else {
 88  0
             streams.getSource().reset(reader);
 89  
         }
 90  0
         return streams.getResult();
 91  
     }
 92  
 
 93  0
     private final Version matchVersion = Version.LUCENE_29;
 94  
 }