Class TokenList
- java.lang.Object
-
- com.attivio.sdk.token.TokenSink
-
- com.attivio.sdk.token.TokenList
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<Token>
public class TokenList extends TokenSink implements java.lang.Cloneable, java.lang.Iterable<Token>, java.io.Externalizable
A Linked List of tokens with additional markup to indicate position increments and ordering of tokens.CAUTION: unless otherwise noted, any Token instances passed to methods of a TokenList or a TokenListIterator are NOT copied when added to this TokenList. You should therefore not modify any Token instances after you have passed them into this TokenList unless you are sure of what you are doing.
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.attivio.sdk.token.TokenSink
DEFAULT_POSITION_INCREMENT
-
-
Constructor Summary
Constructors Constructor Description TokenList()The default constructorTokenList(Token token)Construct a new TokenList with a singletoken.TokenList(Token... tokens)Construct a new TokenList with the specifiedtokens.TokenList(java.lang.String token)Construct a new TokenList with a singletoken.TokenList(java.lang.String... tokens)Constructor a new TokenList with the specifiedtokens.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(Token t, int increment)Appends a token.TokenListappend(Token t)Appends a token using the default position increment.TokenListappend(Token t, int increment)Appends a token.TokenListappend(java.lang.String t)Appends a token to this TokenList using the default position increment.TokenListappend(java.lang.String t, int increment)Appends a token.voidclear()TokenListclone()java.lang.Stringconcat()Represent all primary (ie top of the stack) tokens from this TokenList as a string.static java.lang.Stringconcat(Position... positions)Represent all primary (ie top of the stack) tokens frompositionsas a string.static java.lang.Stringconcat(PositionIterator positions)Represent all primary (ie top of the stack) tokens frompositionsas a string.static java.lang.Stringconcat(java.lang.Iterable<Position> positions)Represent all primary (ie top of the stack) tokens frompositionsas a string.static java.lang.Stringconcat(java.util.Iterator<Position> positions)Represent all primary (ie top of the stack) tokens frompositionsas a string.booleancontainsToken(java.util.function.Predicate<Token> predicate)Returnstrueif any token matchespredicate.booleancontainsWildcard()Returns true if any Token in this TokenList contains ? or *booleanequals(java.lang.Object other)voidforEachToken(java.util.function.Consumer<Token> consumer)Pass all tokens toconsumer.intgetEndOffset()Get the end offset for the last token that contains offset information.TokengetFirst()Returns the first Token in this TokenList.TokengetLast()Returns the last Token in this TokenList.intgetMaxRemainingTokens()This value is a hint to tokenization.intgetPositionCount()Returns the number of unique positions for this termintgetStartOffset()Get the start offset for the first token that contains offset information.inthashCode()TokenIteratoriterator()Returns an iterator over the Tokens in this TokenList.static java.lang.Stringjoin(Token[] tokens, int startIndex, int endIndex, char joinChar)Join the text for alltokensonjoinChar.static java.lang.Stringjoin(java.lang.Iterable<Token> tokens, char joinChar)Join the text for alltokensonjoinChar.static java.lang.Stringjoin(java.util.Iterator<Token> tokens, char joinChar)Join the text for alltokensonjoinChar.TokenIteratorlistIterator()Returns a list iterator over the Tokens in this TokenList.PositionIteratorpositions()Returns an iterator that iterates over the unique positions in TokenList.TokenListreadExternal(java.io.DataInput in)GWT Incompatible - hence no @Override annotation.voidreadExternal(java.io.ObjectInput in)GWT Incompatible - hence no @Override annotation.voidremove(TokenAnnotation annotation)Remove all tokens annotated withannotation.voidsetMaxRemainingTokens(int value)Set the max remaining tokens allowed to be created.intsize()Returns the number of Tokens in this TokenList.PhrasetoPhrase()Convert this TokenList into a comparable Phrase query.PhrasetoPhrase(int offsetBase)Convert this TokenList into a comparable Phrase query.java.lang.StringtoQuotedString()java.lang.StringtoString()voidtruncate(int maxSize)static TokenListvalueOf(java.lang.String value)Parses the string representation of a TokenList back into a TokenListstatic TokenListvalueOf(java.lang.String... value)Parses the string representation of a TokenList back into a TokenListvoidwriteExternal(java.io.DataOutput out)voidwriteExternal(java.io.ObjectOutput out)protected voidwriteExternalV0(java.io.DataOutput out)Deprecated.voidwriteTo(TokenListSerializer out)Write token list toout.java.lang.StringBuilderwriteTo(java.lang.StringBuilder buffer)Write token list tobuffer.-
Methods inherited from class com.attivio.sdk.token.TokenSink
add, add, add, add, add, endScope, endScope, startLanguageRegion, startScope, startScope
-
-
-
-
Constructor Detail
-
TokenList
public TokenList()
The default constructor
-
TokenList
public TokenList(java.lang.String token)
Construct a new TokenList with a singletoken.
-
TokenList
public TokenList(Token token)
Construct a new TokenList with a singletoken.
-
TokenList
public TokenList(java.lang.String... tokens)
Constructor a new TokenList with the specifiedtokens.
-
TokenList
public TokenList(Token... tokens)
Construct a new TokenList with the specifiedtokens.
-
-
Method Detail
-
clear
public void clear()
-
truncate
public void truncate(int maxSize)
-
toPhrase
public Phrase toPhrase()
Convert this TokenList into a comparable Phrase query.
-
toPhrase
public Phrase toPhrase(int offsetBase)
Convert this TokenList into a comparable Phrase query.
-
getMaxRemainingTokens
public int getMaxRemainingTokens()
This value is a hint to tokenization.- If 0, it indicates that truncation of tokens occurred during tokenization.
- If negative, it indicates no truncation was configured.
- If positive, it indicates the maximum number of tokens that should be added to this TokenList.
-
setMaxRemainingTokens
public void setMaxRemainingTokens(int value)
Set the max remaining tokens allowed to be created.
-
getFirst
public Token getFirst()
Returns the first Token in this TokenList.
-
getLast
public Token getLast()
Returns the last Token in this TokenList.
-
size
public int size()
Returns the number of Tokens in this TokenList.
-
getStartOffset
public int getStartOffset()
Get the start offset for the first token that contains offset information.Returns
-1if no tokens contain offset information.
-
getEndOffset
public int getEndOffset()
Get the end offset for the last token that contains offset information.Returns
-1if no tokens contain offset information.
-
getPositionCount
public int getPositionCount()
Returns the number of unique positions for this term
-
containsWildcard
public boolean containsWildcard()
Returns true if any Token in this TokenList contains ? or *
-
containsToken
public boolean containsToken(java.util.function.Predicate<Token> predicate)
Returnstrueif any token matchespredicate.
-
forEachToken
public void forEachToken(java.util.function.Consumer<Token> consumer)
Pass all tokens toconsumer.
-
append
public TokenList append(java.lang.String t)
Appends a token to this TokenList using the default position increment.
-
append
public TokenList append(java.lang.String t, int increment)
Appends a token.
-
add
public void add(Token t, int increment)
Appends a token.
-
remove
public void remove(TokenAnnotation annotation)
Remove all tokens annotated withannotation.NOTE: this removal is "position" aware.
-
iterator
public TokenIterator iterator()
Returns an iterator over the Tokens in this TokenList.- Specified by:
iteratorin interfacejava.lang.Iterable<Token>
-
listIterator
public TokenIterator listIterator()
Returns a list iterator over the Tokens in this TokenList.
-
positions
public PositionIterator positions()
Returns an iterator that iterates over the unique positions in TokenList.
-
clone
public TokenList clone()
- Overrides:
clonein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toQuotedString
public java.lang.String toQuotedString()
-
writeTo
public java.lang.StringBuilder writeTo(java.lang.StringBuilder buffer)
Write token list tobuffer.
-
writeTo
public void writeTo(TokenListSerializer out)
Write token list toout.
-
valueOf
public static TokenList valueOf(java.lang.String value)
Parses the string representation of a TokenList back into a TokenList- Parameters:
value- the string value to parse- Returns:
- the TokenList that value represents
-
valueOf
public static TokenList valueOf(java.lang.String... value)
Parses the string representation of a TokenList back into a TokenList- Parameters:
value- the string value to parse- Returns:
- the TokenList that value represents
-
join
public static java.lang.String join(java.lang.Iterable<Token> tokens, char joinChar)
Join the text for alltokensonjoinChar.
-
join
public static java.lang.String join(java.util.Iterator<Token> tokens, char joinChar)
Join the text for alltokensonjoinChar.
-
join
public static java.lang.String join(Token[] tokens, int startIndex, int endIndex, char joinChar)
Join the text for alltokensonjoinChar.- Parameters:
tokens- the array of tokens to join.startIndex- the first element intokensto joinendIndex- one past the last element intokensto joinjoinChar- the character to join all tokens on.- Returns:
- the joined token array
-
concat
public java.lang.String concat()
Represent all primary (ie top of the stack) tokens from this TokenList as a string.NOTE: Uses
Token.offsetGap(Token)to determine if space should be placed between tokens.- Returns:
- the list represented as a String
-
concat
public static java.lang.String concat(PositionIterator positions)
Represent all primary (ie top of the stack) tokens frompositionsas a string.NOTE: Uses
Token.offsetGap(Token)to determine if space should be placed between tokens.- Returns:
- the list represented as a String
-
concat
public static java.lang.String concat(java.lang.Iterable<Position> positions)
Represent all primary (ie top of the stack) tokens frompositionsas a string.NOTE: Uses
Token.offsetGap(Token)to determine if space should be placed between tokens.- Returns:
- the list represented as a String
-
concat
public static java.lang.String concat(java.util.Iterator<Position> positions)
Represent all primary (ie top of the stack) tokens frompositionsas a string.NOTE: Uses
Token.offsetGap(Token)to determine if space should be placed between tokens.- Returns:
- the list represented as a String
-
concat
public static java.lang.String concat(Position... positions)
Represent all primary (ie top of the stack) tokens frompositionsas a string.NOTE: Uses
Token.offsetGap(Token)to determine if space should be placed between tokens.- Returns:
- the list represented as a String
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOExceptionGWT Incompatible - hence no @Override annotation. See com.google.gwt.emul.java.io.Externalizable- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
readExternal
public TokenList readExternal(java.io.DataInput in) throws java.io.IOException
GWT Incompatible - hence no @Override annotation. See com.google.gwt.emul.java.io.Externalizable- Throws:
java.io.IOException
-
writeExternal
public void writeExternal(java.io.DataOutput out) throws java.io.IOException- Throws:
java.io.IOException
-
writeExternalV0
@Deprecated protected void writeExternalV0(java.io.DataOutput out) throws java.io.IOExceptionDeprecated.Deprecated method to serialize a token list according to V0 format.- Throws:
java.io.IOException
-
-