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.Cloneable
Represents 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.Element
head
The head pointer for this Position.protected com.attivio.sdk.token.TokenList.Element
tail
The tail pointer for this Position.protected TokenList
tokens
The 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 void
add(Token t)
Add a Token to this Position.void
add(java.lang.CharSequence token, TokenAnnotation annotation, boolean indexed)
Add an annotated token to this Position.void
add(java.lang.String token)
Add an indexed token to this Position.void
add(java.lang.String token, TokenAnnotation annotation)
Add an annotated token to this Position.void
add(java.lang.String token, TokenAnnotation annotation, boolean indexed)
Add an annotated token to this Position.Position
clone()
TODO: document caution when working with cloned Positions.boolean
contains(TokenAnnotation annotation)
Returnstrue
if any token at this position is marked withannotation
.boolean
containsToken(java.util.function.Predicate<Token> predicate)
Returnstrue
if this position contains a token that matchespredicate
.Token
endScope(java.lang.String name)
Mark this position as the last position in scopename
.void
filter(java.util.function.Predicate<Token> predicate)
Remove all tokens from this position that do not matchpredicate
.void
forEach(java.util.function.Consumer<Token> consumer)
Pass each token in this position toconsumer
.Token
get()
Get the primary Token for this position.Token[]
get(TokenAnnotation annotation)
Get all Tokens for this position that contain the specified annotation.int
getEndOffset()
Get the end offset from the source text for this position.int
getIncrement()
Gets the position increment for this Position.ScopeInfo
getScopePostfix()
Get theScopeInfo
for all scope changes new for this position.ScopeInfo
getScopePostfix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()
that supports reusingScopeInfo
instances.ScopeInfo
getScopePrefix()
Get theScopeInfo
for all scope changes new for this position.ScopeInfo
getScopePrefix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()
that supports reusingScopeInfo
instances.int
getStartOffset()
Get the start offset from the source text for this position.Token
getSurfaceToken()
Returns the first token in this position that is a surface token.Token[]
getTokens()
Gets all Tokens for this Position.boolean
isIndexed()
Gets if this position has any indexed tokens.boolean
isPhraseBreak()
Returnstrue
if this position causes a phrase break.boolean
isValid()
Returnstrue
if this Position is valid.void
remove()
Remove this position.void
remove(TokenAnnotation annotation)
Remove all tokens from this Position with the specifiedannotation
.Position
seek(Position other)
Expert: Seek this position to the same position asother
.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.void
setIncrement(int increment)
Sets the position increment for this Position.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.Token
startScope(java.lang.String name)
Mark this position as the first position in scopename
.Token
startScope(java.lang.String name, int increment)
Mark this position as the first position in scopename
.int
tokenCount()
Returns the number of tokens in this position.int
tokenCount(java.util.function.Predicate<Token> predicate)
Returns the number of tokens in this position that matchpredicate
.Phrase
toPhrase()
Phrase
toPhrase(int offsetBase)
void
toQueryString(java.lang.StringBuilder buffer)
Encode this Position intobuffer
suitable for parsing inside a phrase() operator.java.lang.String
toString()
-
-
-
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()
Returnstrue
if this Position is valid.
-
getScopePrefix
public ScopeInfo getScopePrefix()
Get theScopeInfo
for all scope changes new for this position.Returns
null
if no scope transitions occur prior to this position.
-
getScopePostfix
public ScopeInfo getScopePostfix()
Get theScopeInfo
for all scope changes new for this position.Returns
null
if no scope transitions occur prior to this position.
-
getScopePrefix
public ScopeInfo getScopePrefix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()
that supports reusingScopeInfo
instances.
-
getScopePostfix
public ScopeInfo getScopePostfix(ScopeInfo reuse)
Advanced form ofgetScopePrefix()
that supports reusingScopeInfo
instances.
-
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()
Returnstrue
if 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
Token
to 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
Token
to support adding additional annotations.
-
endScope
public Token endScope(java.lang.String name)
Mark this position as the last position in scopename
.Returns the scope
Token
to 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
annotation
then 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)
Returnstrue
if any token at this position is marked withannotation
.
-
containsToken
public boolean containsToken(java.util.function.Predicate<Token> predicate)
Returnstrue
if 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:
toString
in classjava.lang.Object
-
toQueryString
public void toQueryString(java.lang.StringBuilder buffer)
Encode this Position intobuffer
suitable for parsing inside a phrase() operator.
-
clone
public Position clone()
TODO: document caution when working with cloned Positions.- Overrides:
clone
in classjava.lang.Object
-
-