| 1 | package morfologik.fsa; |
| 2 | |
| 3 | /** |
| 4 | * A matching result returned from {@link FSATraversal}. |
| 5 | * |
| 6 | * @see FSATraversal |
| 7 | */ |
| 8 | public final class MatchResult { |
| 9 | /** |
| 10 | * The automaton has exactly one match for the input sequence. |
| 11 | */ |
| 12 | public static final int EXACT_MATCH = 0; |
| 13 | |
| 14 | /** |
| 15 | * The automaton has no match for the input sequence and no sequence |
| 16 | * in the automaton is a prefix of the input. |
| 17 | * |
| 18 | * Note that to check for a general "input does not exist in the automaton" |
| 19 | * you have to check for both {@link #NO_MATCH} and |
| 20 | * {@link #AUTOMATON_HAS_PREFIX}. |
| 21 | */ |
| 22 | public static final int NO_MATCH = -1; |
| 23 | |
| 24 | /** |
| 25 | * The automaton contains a prefix of the input sequence (but the |
| 26 | * full sequence does not exist). This translates to: one of the input sequences |
| 27 | * used to build the automaton is a prefix of the input sequence, but the |
| 28 | * input sequence contains a non-existent suffix. |
| 29 | * |
| 30 | * <p>{@link MatchResult#index} will contain an index of the |
| 31 | * first character of the input sequence not present in the |
| 32 | * dictionary.</p> |
| 33 | */ |
| 34 | public static final int AUTOMATON_HAS_PREFIX = -3; |
| 35 | |
| 36 | /** |
| 37 | * The sequence is a prefix of at least one sequence in the automaton. |
| 38 | * {@link MatchResult#node} returns the node from which all sequences |
| 39 | * with the given prefix start in the automaton. |
| 40 | */ |
| 41 | public static final int SEQUENCE_IS_A_PREFIX = -4; |
| 42 | |
| 43 | /** |
| 44 | * One of the match types defined in this class. |
| 45 | * |
| 46 | * @see #NO_MATCH |
| 47 | * @see #EXACT_MATCH |
| 48 | * @see #AUTOMATON_HAS_PREFIX |
| 49 | * @see #SEQUENCE_IS_A_PREFIX |
| 50 | */ |
| 51 | public int kind; |
| 52 | |
| 53 | /** |
| 54 | * Input sequence's index, interpretation depends on {@link #kind}. |
| 55 | */ |
| 56 | public int index; |
| 57 | |
| 58 | /** |
| 59 | * Automaton node, interpretation depends on the {@link #kind}. |
| 60 | */ |
| 61 | public int node; |
| 62 | |
| 63 | MatchResult(int kind, int index, int node) { |
| 64 | reset(kind, index, node); |
| 65 | } |
| 66 | |
| 67 | MatchResult(int kind) { |
| 68 | reset(kind, 0, 0); |
| 69 | } |
| 70 | |
| 71 | public MatchResult() { |
| 72 | reset(NO_MATCH, 0, 0); |
| 73 | } |
| 74 | |
| 75 | final void reset(int kind, int index, int node) { |
| 76 | this.kind = kind; |
| 77 | this.index = index; |
| 78 | this.node = node; |
| 79 | } |
| 80 | } |