morfologik.fsa
Class FSATraversal

java.lang.Object
  extended by morfologik.fsa.FSATraversal

public final class FSATraversal
extends java.lang.Object

This class implements some common matching and scanning operations on a generic FSA.


Constructor Summary
FSATraversal(FSA fsa)
          Traversals of the given FSA.
 
Method Summary
 MatchResult match(byte[] sequence)
           
 MatchResult match(byte[] sequence, int node)
           
 MatchResult match(byte[] sequence, int start, int length, int node)
          Finds a matching path in the dictionary for a given sequence of labels from sequence and starting at node node.
 MatchResult match(MatchResult result, byte[] sequence, int start, int length, int node)
          Same as match(byte[], int, int, int), but allows passing a reusable MatchResult object so that no intermediate garbage is produced.
 int perfectHash(byte[] sequence)
           
 int perfectHash(byte[] sequence, int start, int length, int node)
          Calculate perfect hash for a given input sequence of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSATraversal

public FSATraversal(FSA fsa)
Traversals of the given FSA.

Method Detail

perfectHash

public int perfectHash(byte[] sequence,
                       int start,
                       int length,
                       int node)
Calculate perfect hash for a given input sequence of bytes. The perfect hash requires that FSA is built with FSAFlags.NUMBERS and corresponds to the sequential order of input sequences used at automaton construction time.

Parameters:
start - Start index in the sequence array.
length - Length of the byte sequence, must be at least 1.
Returns:
Returns a unique integer assigned to the input sequence in the automaton (reflecting the number of that sequence in the input used to build the automaton). Returns a negative integer if the input sequence was not part of the input from which the automaton was created. The type of mismatch is a constant defined in MatchResult.

perfectHash

public int perfectHash(byte[] sequence)
See Also:
perfectHash(byte[], int, int, int)

match

public MatchResult match(MatchResult result,
                         byte[] sequence,
                         int start,
                         int length,
                         int node)
Same as match(byte[], int, int, int), but allows passing a reusable MatchResult object so that no intermediate garbage is produced.

Returns:
The same object as result, but with reset internal type and other fields.

match

public MatchResult match(byte[] sequence,
                         int start,
                         int length,
                         int node)
Finds a matching path in the dictionary for a given sequence of labels from sequence and starting at node node.

Parameters:
sequence - An array of labels to follow in the FSA.
start - Starting index in sequence.
length - How many symbols to consider from sequence?
node - Start node identifier in the FSA.
See Also:
match(byte [], int)

match

public MatchResult match(byte[] sequence,
                         int node)
See Also:
match(byte[], int, int, int)

match

public MatchResult match(byte[] sequence)
See Also:
match(byte[], int, int, int)