Changeset 31254


Ignore:
Timestamp:
2016-12-20T15:29:56+13:00 (7 years ago)
Author:
davidb
Message:

Experimenting with Lucene lowercase filter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/SolrDocJSON.java

    r31252 r31254  
    1212import java.util.ArrayList;
    1313import java.util.Iterator;
    14 import java.util.Set;
    15 
    1614import org.apache.commons.compress.compressors.CompressorException;
    1715import org.json.JSONObject;
     
    2018import org.apache.lucene.analysis.icu.segmentation.ICUTokenizer;
    2119import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
    22 import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
     20import org.apache.lucene.analysis.core.LowerCaseFilter;
    2321
    2422public class SolrDocJSON {
     
    2725                                                             boolean icu_tokenize)
    2826    {
     27        boolean lowercase_filter = true;
    2928       
    3029        ArrayList<String> words = new ArrayList<String>();
     
    3938                    Reader reader = new StringReader(token);
    4039                   
    41                     Tokenizer tokenizer = new ICUTokenizer();
    42                     tokenizer.setReader(reader);
     40                    ICUTokenizer icu_tokenizer = new ICUTokenizer();
     41                    icu_tokenizer.setReader(reader);
    4342                       
    44                     CharTermAttribute charTermAttribute = tokenizer.addAttribute(CharTermAttribute.class);
    45 
     43                    CharTermAttribute charTermAttribute = icu_tokenizer.addAttribute(CharTermAttribute.class);
     44
     45                    TokenStream token_stream = null;
     46                   
     47                    if (lowercase_filter) {
     48                        token_stream = new LowerCaseFilter(icu_tokenizer);
     49                    }
     50                    else {
     51                        token_stream = icu_tokenizer;
     52                    }
     53                   
    4654                    try {
    47                         tokenizer.reset();
     55                        token_stream.reset();
    4856                       
    49                         while (tokenizer.incrementToken()) {
     57                        while (token_stream.incrementToken()) {
    5058                            String term = charTermAttribute.toString();
    5159                            words.add(term);
    5260                        }
    5361                       
    54                         tokenizer.end();
    55                         tokenizer.close();
     62                        token_stream.end();
     63                        token_stream.close();
    5664                    }
    5765                    catch (IOException e) {
Note: See TracChangeset for help on using the changeset viewer.