Package morfologik.fsa
Class FSATraversal
- java.lang.Object
-
- 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
Constructors Constructor Description FSATraversal(FSA fsa)
Traversals of the given FSA.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 fromsequence
and starting at nodenode
.MatchResult
match(MatchResult reuse, byte[] sequence, int start, int length, int node)
Same asmatch(byte[], int, int, int)
, but allows passing a reusableMatchResult
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.
-
-
-
Field Detail
-
fsa
private final FSA fsa
Target automaton.
-
-
Constructor Detail
-
FSATraversal
public FSATraversal(FSA fsa)
Traversals of the given FSA.- Parameters:
fsa
- The target automaton for traversals.
-
-
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 thatFSA
is built withFSAFlags.NUMBERS
and corresponds to the sequential order of input sequences used at automaton construction time.- Parameters:
sequence
- The byte sequence to calculate perfect hash for.start
- Start index in the sequence array.length
- Length of the byte sequence, must be at least 1.node
- The node to start traversal from, typically the root node.- 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)
- Parameters:
sequence
- The byte sequence to calculate perfect hash for.- 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
. - See Also:
perfectHash(byte[], int, int, int)
-
match
public MatchResult match(MatchResult reuse, byte[] sequence, int start, int length, int node)
Same asmatch(byte[], int, int, int)
, but allows passing a reusableMatchResult
object so that no intermediate garbage is produced.- Parameters:
reuse
- TheMatchResult
to reuse.sequence
- Input sequence to look for in the automaton.start
- Start index in the sequence array.length
- Length of the byte sequence, must be at least 1.node
- The node to start traversal from, typically the root node.- Returns:
- The same object as
reuse
, but with updated matchMatchResult.kind
and other relevant 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 fromsequence
and starting at nodenode
.- Parameters:
sequence
- Input sequence to look for in the automaton.start
- Start index in the sequence array.length
- Length of the byte sequence, must be at least 1.node
- The node to start traversal from, typically the root node.- Returns:
MatchResult
with updated matchMatchResult.kind
.- See Also:
match(byte [], int)
-
match
public MatchResult match(byte[] sequence, int node)
- Parameters:
sequence
- Input sequence to look for in the automaton.node
- The node to start traversal from, typically the root node.- Returns:
MatchResult
with updated matchMatchResult.kind
.- See Also:
match(byte [], int)
-
match
public MatchResult match(byte[] sequence)
- Parameters:
sequence
- Input sequence to look for in the automaton.- Returns:
MatchResult
with updated matchMatchResult.kind
.- See Also:
match(byte [], int)
-
-