List of usage examples for org.apache.lucene.analysis TokenStream cloneAttributes
public final AttributeSource cloneAttributes()
From source file:com.rubenlaguna.en4j.searchlucene.CustomTokenFilter.java
License:Open Source License
public CustomTokenFilter(TokenStream ts) { super(ts);//from w w w.j a va 2s . c om synonymStack = new Stack(); //#1 termAttr = (TermAttribute) addAttribute(TermAttribute.class); save = ts.cloneAttributes(); }
From source file:nl.inl.blacklab.filter.AbstractSynonymFilter.java
License:Apache License
/** * Construct a synonym filter.//from ww w .j a va 2 s . c om * * @param input * the input tokens to find synonyms for * @param includeOriginalTokens * Include the original tokens, or just the synonyms? */ public AbstractSynonymFilter(TokenStream input, boolean includeOriginalTokens) { super(input); this.includeOriginalTokens = includeOriginalTokens; synonymStack = new Stack<State>(); termAttr = addAttribute(CharTermAttribute.class); addAttribute(PositionIncrementAttribute.class); addAttribute(TypeAttribute.class); helperAttSource = input.cloneAttributes(); }
From source file:org.apache.solr.handler.AnalysisRequestHandlerBase.java
License:Apache License
/** * Analyzes the given TokenStream, collecting the Tokens it produces. * * @param tokenStream TokenStream to analyze * * @return List of tokens produced from the TokenStream *///from w w w . j av a 2 s . c o m private List<AttributeSource> analyzeTokenStream(TokenStream tokenStream) { final List<AttributeSource> tokens = new ArrayList<AttributeSource>(); final PositionIncrementAttribute posIncrAtt = tokenStream.addAttribute(PositionIncrementAttribute.class); final TokenTrackingAttribute trackerAtt = tokenStream.addAttribute(TokenTrackingAttribute.class); // for backwards compatibility, add all "common" attributes tokenStream.addAttribute(OffsetAttribute.class); tokenStream.addAttribute(TypeAttribute.class); try { tokenStream.reset(); int position = 0; while (tokenStream.incrementToken()) { position += posIncrAtt.getPositionIncrement(); trackerAtt.setActPosition(position); tokens.add(tokenStream.cloneAttributes()); } tokenStream.end(); } catch (IOException ioe) { throw new RuntimeException("Error occured while iterating over tokenstream", ioe); } finally { IOUtils.closeWhileHandlingException(tokenStream); } return tokens; }
From source file:uk.ac.ebi.fg.biostudies.lucene.SynonymFilter.java
License:Apache License
public SynonymFilter(TokenStream in, SynonymEngine engine) { super(in);//from w w w .ja v a 2 s . c om synonymStack = new Stack(); // #1 termAttr = (TermAttribute) addAttribute(TermAttribute.class); save = in.cloneAttributes(); this.engine = engine; }