Nfa { public void finish() { startingState.finish(new HashSet<NfaState>()); } Nfa(NfaState startingState, Collection<NfaState> danglingArrows); NfaState getStartingState(); Nfa copy(); void append(Nfa state); void repeat(int min, int max); void invert(); Collection<NfaState> getDanglingArrows(); @Override String toString(); void lookupAnnotationNumbers(ForwardIndexAccessor fiAccessor, Map<NfaState, Boolean> statesVisited); void finish();  }
@Test public void testNfaSimple() { NfaState ab = NfaState.token("contents%word@i", "a", NfaState.token("contents%word@i", "b", null)); NfaState ba = NfaState.token("contents%word@i", "b", NfaState.token("contents%word@i", "a", null)); NfaState start = NfaState.or(false, Arrays.asList(ab, ba), true); start.finish(new HashSet<NfaState>()); start.lookupPropertyNumbers(new MockFiAccessor(), new IdentityHashMap<NfaState, Boolean>()); ForwardIndexDocumentString fiDoc = new ForwardIndexDocumentString("abatoir"); Assert.assertTrue(start.matches(fiDoc, 0, 1)); Assert.assertTrue(start.matches(fiDoc, 1, 1)); Assert.assertFalse(start.matches(fiDoc, 2, 1)); Assert.assertFalse(start.matches(fiDoc, 6, 1)); }
@Test public void testNfaRepetition() { NfaState c = NfaState.token("contents%word@i", "c", null); NfaState split = NfaState.or(true, Arrays.asList(c, NfaState.token("contents%word@i", "e", null)), false); NfaState start = NfaState.token("contents%word@i", "a", split); c.setNextState(0, split); start.finish(new HashSet<NfaState>()); start.lookupPropertyNumbers(new MockFiAccessor(), new IdentityHashMap<NfaState, Boolean>()); Assert.assertTrue(start.matches(new ForwardIndexDocumentString("access"), 0, 1)); Assert.assertTrue(start.matches(new ForwardIndexDocumentString("aces"), 0, 1)); Assert.assertTrue(start.matches(new ForwardIndexDocumentString("aether"), 0, 1)); Assert.assertFalse(start.matches(new ForwardIndexDocumentString("acquire"), 0, 1)); Assert.assertFalse(start.matches(new ForwardIndexDocumentString("cesium"), 0, 1)); Assert.assertTrue(start.matches(new ForwardIndexDocumentString("ideaal"), 3, -1)); }