Package morfologik.fsa
Class FSATraversal
- java.lang.Object
-
- morfologik.fsa.FSATraversal
-
public final class FSATraversal extends java.lang.ObjectThis 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 MatchResultmatch(byte[] sequence)MatchResultmatch(byte[] sequence, int node)MatchResultmatch(byte[] sequence, int start, int length, int node)Finds a matching path in the dictionary for a given sequence of labels fromsequenceand starting at nodenode.MatchResultmatch(MatchResult reuse, byte[] sequence, int start, int length, int node)Same asmatch(byte[], int, int, int), but allows passing a reusableMatchResultobject so that no intermediate garbage is produced.intperfectHash(byte[] sequence)intperfectHash(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 thatFSAis built withFSAFlags.NUMBERSand 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 reusableMatchResultobject so that no intermediate garbage is produced.- Parameters:
reuse- TheMatchResultto 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.kindand 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 fromsequenceand 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:
MatchResultwith 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:
MatchResultwith 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:
MatchResultwith updated matchMatchResult.kind.- See Also:
match(byte [], int)
-
-