Class Position
- java.lang.Object
-
- com.attivio.sdk.token.Position
-
- All Implemented Interfaces:
java.lang.Cloneable
public final class Position extends java.lang.Object implements java.lang.CloneableRepresents a "Position" in a TokenList.More specifically, a Position is a window over a TokenList representing all tokens at the same position.
-
-
Field Summary
Fields Modifier and Type Field Description protected com.attivio.sdk.token.TokenList.ElementheadThe head pointer for this Position.protected com.attivio.sdk.token.TokenList.ElementtailThe tail pointer for this Position.protected TokenListtokensThe TokenList this Position points into.
-
Constructor Summary
Constructors Constructor Description Position()Expert: create an unpositioned position.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(Token t)Add a Token to this Position.voidadd(java.lang.CharSequence token, TokenAnnotation annotation, boolean indexed)Add an annotated token to this Position.voidadd(java.lang.String token)Add an indexed token to this Position.voidadd(java.lang.String token, TokenAnnotation annotation)Add an annotated token to this Position.voidadd(java.lang.String token, TokenAnnotation annotation, boolean indexed)Add an annotated token to this Position.Positionclone()TODO: document caution when working with cloned Positions.booleancontains(TokenAnnotation annotation)Returnstrueif any token at this position is marked withannotation.booleancontainsToken(java.util.function.Predicate<Token> predicate)Returnstrueif this position contains a token that matchespredicate.TokenendScope(java.lang.String name)Mark this position as the last position in scopename.voidfilter(java.util.function.Predicate<Token> predicate)Remove all tokens from this position that do not matchpredicate.voidforEach(java.util.function.Consumer<Token> consumer)Pass each token in this position toconsumer.Tokenget()Get the primary Token for this position.Token[]get(TokenAnnotation annotation)Get all Tokens for this position that contain the specified annotation.intgetEndOffset()Get the end offset from the source text for this position.intgetIncrement()Gets the position increment for this Position.ScopeInfogetScopePostfix()Get theScopeInfofor all scope changes new for this position.ScopeInfogetScopePostfix(ScopeInfo reuse)Advanced form ofgetScopePrefix()that supports reusingScopeInfoinstances.ScopeInfogetScopePrefix()Get theScopeInfofor all scope changes new for this position.ScopeInfogetScopePrefix(ScopeInfo reuse)Advanced form ofgetScopePrefix()that supports reusingScopeInfoinstances.intgetStartOffset()Get the start offset from the source text for this position.TokengetSurfaceToken()Returns the first token in this position that is a surface token.Token[]getTokens()Gets all Tokens for this Position.booleanisIndexed()Gets if this position has any indexed tokens.booleanisPhraseBreak()Returnstrueif this position causes a phrase break.booleanisValid()Returnstrueif this Position is valid.voidremove()Remove this position.voidremove(TokenAnnotation annotation)Remove all tokens from this Position with the specifiedannotation.Positionseek(Position other)Expert: Seek this position to the same position asother.voidsetEndOffset(int offset)Deprecated.token offsets should not be modified at the position level and should instead be set when the token is created.voidsetIncrement(int increment)Sets the position increment for this Position.voidsetStartOffset(int offset)Deprecated.token offsets should not be modified at the position level and should instead be set when the token is created.TokenstartScope(java.lang.String name)Mark this position as the first position in scopename.TokenstartScope(java.lang.String name, int increment)Mark this position as the first position in scopename.inttokenCount()Returns the number of tokens in this position.inttokenCount(java.util.function.Predicate<Token> predicate)Returns the number of tokens in this position that matchpredicate.PhrasetoPhrase()PhrasetoPhrase(int offsetBase)voidtoQueryString(java.lang.StringBuilder buffer)Encode this Position intobuffersuitable for parsing inside a phrase() operator.java.lang.StringtoString()
-
-
-
Field Detail
-
tokens
protected TokenList tokens
The TokenList this Position points into.
-
head
protected com.attivio.sdk.token.TokenList.Element head
The head pointer for this Position.
-
tail
protected com.attivio.sdk.token.TokenList.Element tail
The tail pointer for this Position.
-
-
Method Detail
-
tokenCount
public int tokenCount()
Returns the number of tokens in this position.
-
tokenCount
public int tokenCount(java.util.function.Predicate<Token> predicate)
Returns the number of tokens in this position that matchpredicate.
-
seek
public Position seek(Position other)
Expert: Seek this position to the same position asother.
-
isValid
public boolean isValid()
Returnstrueif this Position is valid.
-
getScopePrefix
public ScopeInfo getScopePrefix()
Get theScopeInfofor all scope changes new for this position.Returns
nullif no scope transitions occur prior to this position.
-
getScopePostfix
public ScopeInfo getScopePostfix()
Get theScopeInfofor all scope changes new for this position.Returns
nullif no scope transitions occur prior to this position.
-
getScopePrefix
public ScopeInfo getScopePrefix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()that supports reusingScopeInfoinstances.
-
getScopePostfix
public ScopeInfo getScopePostfix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()that supports reusingScopeInfoinstances.
-
getStartOffset
public int getStartOffset()
Get the start offset from the source text for this position.NOTE: this is the start offset for the surface token for this position.
-
getEndOffset
public int getEndOffset()
Get the end offset from the source text for this position.NOTE: this is the end offset for the surface token for this position.
-
setStartOffset
@Deprecated public void setStartOffset(int offset)
Deprecated.token offsets should not be modified at the position level and should instead be set when the token is created.Set the start offset from the source text for this position.
-
setEndOffset
@Deprecated public void setEndOffset(int offset)
Deprecated.token offsets should not be modified at the position level and should instead be set when the token is created.Set the end offset from the source text for this position.
-
isIndexed
public boolean isIndexed()
Gets if this position has any indexed tokens.
-
isPhraseBreak
public boolean isPhraseBreak()
Returnstrueif this position causes a phrase break.NOTE: phrase searches will not match across a phrase break.
-
getIncrement
public int getIncrement()
Gets the position increment for this Position.
-
setIncrement
public void setIncrement(int increment)
Sets the position increment for this Position.
-
startScope
public Token startScope(java.lang.String name)
Mark this position as the first position in scopename.Returns the scope
Tokento support adding additional annotations.
-
startScope
public Token startScope(java.lang.String name, int increment)
Mark this position as the first position in scopename.Returns the scope
Tokento support adding additional annotations.
-
endScope
public Token endScope(java.lang.String name)
Mark this position as the last position in scopename.Returns the scope
Tokento support adding additional annotations.
-
getSurfaceToken
public Token getSurfaceToken()
Returns the first token in this position that is a surface token.
-
remove
public void remove(TokenAnnotation annotation)
Remove all tokens from this Position with the specifiedannotation.NOTE: if every Token at this Position is annotated with
annotationthen the entire position will be removed.
-
filter
public void filter(java.util.function.Predicate<Token> predicate)
Remove all tokens from this position that do not matchpredicate.
-
remove
public void remove()
Remove this position.
-
get
public Token get()
Get the primary Token for this position.
-
getTokens
public Token[] getTokens()
Gets all Tokens for this Position.NOTE: is it recommended to use
forEach(java.util.function.Consumer<com.attivio.sdk.token.Token>)instead.
-
toPhrase
public Phrase toPhrase()
-
toPhrase
public Phrase toPhrase(int offsetBase)
-
get
public Token[] get(TokenAnnotation annotation)
Get all Tokens for this position that contain the specified annotation.If no tokens with the specified annotation exist at this position, a 0 length array is returned.
-
forEach
public void forEach(java.util.function.Consumer<Token> consumer)
Pass each token in this position toconsumer.
-
contains
public boolean contains(TokenAnnotation annotation)
Returnstrueif any token at this position is marked withannotation.
-
containsToken
public boolean containsToken(java.util.function.Predicate<Token> predicate)
Returnstrueif this position contains a token that matchespredicate.
-
add
public void add(Token t)
Add a Token to this Position.
-
add
public void add(java.lang.String token)
Add an indexed token to this Position.
-
add
public void add(java.lang.String token, TokenAnnotation annotation)Add an annotated token to this Position.This method is appropriate for adding lemmas, and similar tokens.
NOTE: This token will not be indexed. Use add(String, TokenAnnotation, boolean) to add an indexed token.
-
add
public void add(java.lang.String token, TokenAnnotation annotation, boolean indexed)Add an annotated token to this Position.This method is appropriate for adding lemmas, and similar tokens.
-
add
public void add(java.lang.CharSequence token, TokenAnnotation annotation, boolean indexed)Add an annotated token to this Position.This method is appropriate for adding lemmas, and similar tokens.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toQueryString
public void toQueryString(java.lang.StringBuilder buffer)
Encode this Position intobuffersuitable for parsing inside a phrase() operator.
-
clone
public Position clone()
TODO: document caution when working with cloned Positions.- Overrides:
clonein classjava.lang.Object
-
-