Package morfologik.fsa
Class FSATraversal
java.lang.Object
morfologik.fsa.FSATraversal
This class implements some common matching and scanning operations on a
generic FSA.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionmatch
(byte[] sequence) match
(byte[] sequence, int node) 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
.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 Details
-
fsa
Target automaton.
-
-
Constructor Details
-
FSATraversal
Traversals of the given FSA.- Parameters:
fsa
- The target automaton for traversals.
-
-
Method Details
-
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:
-
match
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
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
- 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
- Parameters:
sequence
- Input sequence to look for in the automaton.- Returns:
MatchResult
with updated matchMatchResult.kind
.- See Also:
-