Class 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)
      Returns true if any token at this position is marked with annotation.
      boolean containsToken​(java.util.function.Predicate<Token> predicate)
      Returns true if this position contains a token that matches predicate .
      Token endScope​(java.lang.String name)
      Mark this position as the last position in scope name.
      void filter​(java.util.function.Predicate<Token> predicate)
      Remove all tokens from this position that do not match predicate.
      void forEach​(java.util.function.Consumer<Token> consumer)
      Pass each token in this position to consumer.
      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 the ScopeInfo for all scope changes new for this position.
      ScopeInfo getScopePostfix​(ScopeInfo reuse)
      Advanced form of getScopePrefix() that supports reusing ScopeInfo instances.
      ScopeInfo getScopePrefix()
      Get the ScopeInfo for all scope changes new for this position.
      ScopeInfo getScopePrefix​(ScopeInfo reuse)
      Advanced form of getScopePrefix() that supports reusing ScopeInfo 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()
      Returns true if this position causes a phrase break.
      boolean isValid()
      Returns true if this Position is valid.
      void remove()
      Remove this position.
      void remove​(TokenAnnotation annotation)
      Remove all tokens from this Position with the specified annotation.
      Position seek​(Position other)
      Expert: Seek this position to the same position as other.
      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 scope name.
      Token startScope​(java.lang.String name, int increment)
      Mark this position as the first position in scope name.
      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 match predicate.
      Phrase toPhrase()  
      Phrase toPhrase​(int offsetBase)  
      void toQueryString​(java.lang.StringBuilder buffer)
      Encode this Position into buffer suitable for parsing inside a phrase() operator.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.
    • Constructor Detail

      • Position

        public Position()
        Expert: create an unpositioned 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 match predicate.
      • seek

        public Position seek​(Position other)
        Expert: Seek this position to the same position as other.
      • isValid

        public boolean isValid()
        Returns true if this Position is valid.
      • getScopePrefix

        public ScopeInfo getScopePrefix()
        Get the ScopeInfo for all scope changes new for this position.

        Returns null if no scope transitions occur prior to this position.

      • getScopePostfix

        public ScopeInfo getScopePostfix()
        Get the ScopeInfo for all scope changes new for this position.

        Returns null if no scope transitions occur prior to this position.

      • 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()
        Returns true 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 scope name.

        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 scope name.

        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 scope name.

        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 specified annotation.

        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 match predicate.
      • remove

        public void remove()
        Remove this position.
      • get

        public Token get()
        Get the primary Token for this position.
      • 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 to consumer.
      • contains

        public boolean contains​(TokenAnnotation annotation)
        Returns true if any token at this position is marked with annotation.
      • containsToken

        public boolean containsToken​(java.util.function.Predicate<Token> predicate)
        Returns true if this position contains a token that matches predicate .
      • 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 class java.lang.Object
      • toQueryString

        public void toQueryString​(java.lang.StringBuilder buffer)
        Encode this Position into buffer suitable for parsing inside a phrase() operator.
      • clone

        public Position clone()
        TODO: document caution when working with cloned Positions.
        Overrides:
        clone in class java.lang.Object