Class GraphTokenFilter
- java.lang.Object
-
- org.apache.lucene.util.AttributeSource
-
- org.apache.lucene.analysis.TokenStream
-
- org.apache.lucene.analysis.TokenFilter
-
- org.apache.lucene.analysis.GraphTokenFilter
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
FixedShingleFilter
public abstract class GraphTokenFilter extends TokenFilter
An abstract TokenFilter that exposes its input stream as a graph CallincrementBaseToken()to move the root of the graph to the next position in the TokenStream,incrementGraphToken()to move along the current graph, andincrementGraph()to reset to the next graph based at the current root. For example, given the stream 'a b/c:2 d e`, then with the base token at 'a', incrementGraphToken() will produce the stream 'a b d e', and then after calling incrementGraph() will produce the stream 'a c e'.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGraphTokenFilter.Token-
Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
AttributeSource.State
-
-
Field Summary
Fields Modifier and Type Field Description private GraphTokenFilter.TokenbaseTokenprivate intcacheSizeprivate java.util.List<GraphTokenFilter.Token>currentGraphprivate intfinalOffsetsprivate intgraphDepthprivate intgraphPosstatic intMAX_GRAPH_STACK_SIZEThe maximum permitted number of routes through a graphstatic intMAX_TOKEN_CACHE_SIZEThe maximum permitted read-ahead in the token streamprivate OffsetAttributeoffsetAttprivate PositionIncrementAttributeposIncAttprivate intstackSizeprivate java.util.Deque<GraphTokenFilter.Token>tokenPoolprivate inttrailingPositions-
Fields inherited from class org.apache.lucene.analysis.TokenFilter
input
-
Fields inherited from class org.apache.lucene.analysis.TokenStream
DEFAULT_TOKEN_ATTRIBUTE_FACTORY
-
-
Constructor Summary
Constructors Constructor Description GraphTokenFilter(TokenStream input)Create a new GraphTokenFilter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intcachedTokenCount()voidend()This method is called by the consumer after the last token has been consumed, afterTokenStream.incrementToken()returnedfalse(using the newTokenStreamAPI).intgetTrailingPositions()Return the number of trailing positions at the end of the graph NB this should only be called afterincrementGraphToken()has returnedfalseprotected booleanincrementBaseToken()Move the root of the graph to the next token in the wrapped TokenStreamprotected booleanincrementGraph()Reset to the root token again, and move down the next route through the graphprotected booleanincrementGraphToken()Move to the next token in the current route through the graphprivate booleanlastInStack(GraphTokenFilter.Token token)private GraphTokenFilter.TokennewToken()private GraphTokenFilter.TokennextTokenInGraph(GraphTokenFilter.Token token)private GraphTokenFilter.TokennextTokenInStream(GraphTokenFilter.Token token)private voidrecycleToken(GraphTokenFilter.Token token)voidreset()This method is called by a consumer before it begins consumption usingTokenStream.incrementToken().-
Methods inherited from class org.apache.lucene.analysis.TokenFilter
close
-
Methods inherited from class org.apache.lucene.analysis.TokenStream
incrementToken
-
Methods inherited from class org.apache.lucene.util.AttributeSource
addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString
-
-
-
-
Field Detail
-
tokenPool
private final java.util.Deque<GraphTokenFilter.Token> tokenPool
-
currentGraph
private final java.util.List<GraphTokenFilter.Token> currentGraph
-
MAX_GRAPH_STACK_SIZE
public static final int MAX_GRAPH_STACK_SIZE
The maximum permitted number of routes through a graph- See Also:
- Constant Field Values
-
MAX_TOKEN_CACHE_SIZE
public static final int MAX_TOKEN_CACHE_SIZE
The maximum permitted read-ahead in the token stream- See Also:
- Constant Field Values
-
baseToken
private GraphTokenFilter.Token baseToken
-
graphDepth
private int graphDepth
-
graphPos
private int graphPos
-
trailingPositions
private int trailingPositions
-
finalOffsets
private int finalOffsets
-
stackSize
private int stackSize
-
cacheSize
private int cacheSize
-
posIncAtt
private final PositionIncrementAttribute posIncAtt
-
offsetAtt
private final OffsetAttribute offsetAtt
-
-
Constructor Detail
-
GraphTokenFilter
public GraphTokenFilter(TokenStream input)
Create a new GraphTokenFilter
-
-
Method Detail
-
incrementBaseToken
protected final boolean incrementBaseToken() throws java.io.IOExceptionMove the root of the graph to the next token in the wrapped TokenStream- Returns:
falseif the underlying stream is exhausted- Throws:
java.io.IOException
-
incrementGraphToken
protected final boolean incrementGraphToken() throws java.io.IOExceptionMove to the next token in the current route through the graph- Returns:
falseif there are not more tokens in the current graph- Throws:
java.io.IOException
-
incrementGraph
protected final boolean incrementGraph() throws java.io.IOExceptionReset to the root token again, and move down the next route through the graph- Returns:
- false if there are no more routes through the graph
- Throws:
java.io.IOException
-
getTrailingPositions
public int getTrailingPositions()
Return the number of trailing positions at the end of the graph NB this should only be called afterincrementGraphToken()has returnedfalse
-
end
public void end() throws java.io.IOExceptionDescription copied from class:TokenFilterThis method is called by the consumer after the last token has been consumed, afterTokenStream.incrementToken()returnedfalse(using the newTokenStreamAPI). Streams implementing the old API should upgrade to use this feature.This method can be used to perform any end-of-stream operations, such as setting the final offset of a stream. The final offset of a stream might differ from the offset of the last token eg in case one or more whitespaces followed after the last token, but a WhitespaceTokenizer was used.
Additionally any skipped positions (such as those removed by a stopfilter) can be applied to the position increment, or any adjustment of other attributes where the end-of-stream value may be important.
If you override this method, always call
super.end().NOTE: The default implementation chains the call to the input TokenStream, so be sure to call
super.end()first when overriding this method.- Overrides:
endin classTokenFilter- Throws:
java.io.IOException- If an I/O error occurs
-
reset
public void reset() throws java.io.IOExceptionDescription copied from class:TokenFilterThis method is called by a consumer before it begins consumption usingTokenStream.incrementToken().Resets this stream to a clean state. Stateful implementations must implement this method so that they can be reused, just as if they had been created fresh.
If you override this method, always call
super.reset(), otherwise some internal state will not be correctly reset (e.g.,Tokenizerwill throwIllegalStateExceptionon further usage).NOTE: The default implementation chains the call to the input TokenStream, so be sure to call
super.reset()when overriding this method.- Overrides:
resetin classTokenFilter- Throws:
java.io.IOException
-
cachedTokenCount
int cachedTokenCount()
-
newToken
private GraphTokenFilter.Token newToken()
-
recycleToken
private void recycleToken(GraphTokenFilter.Token token)
-
nextTokenInGraph
private GraphTokenFilter.Token nextTokenInGraph(GraphTokenFilter.Token token) throws java.io.IOException
- Throws:
java.io.IOException
-
lastInStack
private boolean lastInStack(GraphTokenFilter.Token token) throws java.io.IOException
- Throws:
java.io.IOException
-
nextTokenInStream
private GraphTokenFilter.Token nextTokenInStream(GraphTokenFilter.Token token) throws java.io.IOException
- Throws:
java.io.IOException
-
-