1 package org.apache.lucene.analysis.standard; 2 3 18 19 import org.apache.lucene.analysis.*; 20 21 22 23 public final class StandardFilter extends TokenFilter 24 implements StandardTokenizerConstants { 25 26 27 28 public StandardFilter(TokenStream in) { 29 super(in); 30 } 31 32 private static final String APOSTROPHE_TYPE = tokenImage[APOSTROPHE]; 33 private static final String ACRONYM_TYPE = tokenImage[ACRONYM]; 34 35 39 public final org.apache.lucene.analysis.Token next() throws java.io.IOException { 40 org.apache.lucene.analysis.Token t = input.next(); 41 42 if (t == null) 43 return null; 44 45 String text = t.termText(); 46 String type = t.type(); 47 48 if (type == APOSTROPHE_TYPE && (text.endsWith("'s") || text.endsWith("'S"))) { 50 return new org.apache.lucene.analysis.Token 51 (text.substring(0,text.length()-2), 52 t.startOffset(), t.endOffset(), type); 53 54 } else if (type == ACRONYM_TYPE) { StringBuffer trimmed = new StringBuffer (); 56 for (int i = 0; i < text.length(); i++) { 57 char c = text.charAt(i); 58 if (c != '.') 59 trimmed.append(c); 60 } 61 return new org.apache.lucene.analysis.Token 62 (trimmed.toString(), t.startOffset(), t.endOffset(), type); 63 64 } else { 65 return t; 66 } 67 } 68 } 69 | Popular Tags |