LayeredTokenPattern { public LayeredTokenMatcher matcher(LayeredSequence seq) throws SequenceException { String encoded = encodeSequence(seq); Matcher m = encodedPattern.matcher(encoded); return new LayeredTokenMatcher(m); } LayeredTokenPattern(String patternString); @Override String toString(); LayeredTokenMatcher matcher(LayeredSequence seq); Pattern getEncodedPattern();  }
@Test public void testMatcher2() throws SequenceException { String patternStr = "B-NP_n I-NP_n*"; LayeredTokenPattern pat = new LayeredTokenPattern(patternStr); LayeredTokenMatcher m = pat.matcher(seq); assertTrue(m.find()); assertEquals(2, m.start()); assertEquals(4, m.end()); assertTrue(m.find()); assertEquals(5, m.start()); assertEquals(6, m.end()); assertFalse(m.find()); }
@Test public void testMatcher3() throws SequenceException { String patternStr = "B-NP_n I-NP_n* ._p?$"; LayeredTokenPattern pat = new LayeredTokenPattern(patternStr); LayeredTokenMatcher m = pat.matcher(seq); assertTrue(m.find()); assertEquals(5, m.start()); assertEquals(7, m.end()); assertFalse(m.find()); }
@Test public void testMatcher4() throws SequenceException { String patternStr = "..."; LayeredTokenPattern pat = new LayeredTokenPattern(patternStr); LayeredTokenMatcher m = pat.matcher(seq); assertTrue(m.find()); assertEquals(0, m.start()); assertEquals(3, m.end()); assertTrue(m.find()); assertEquals(3, m.start()); assertEquals(6, m.end()); assertFalse(m.find()); }
@Test(expected=SequenceException.class) public void testMatcher6() throws Exception { String patternStr = "B-NP_np I-NP_np* from_word the_word B-NP_np I-NP_np*"; LayeredTokenPattern pattern = new LayeredTokenPattern(patternStr); OpenNlpSentenceChunker chunker = new OpenNlpSentenceChunker(); pattern.matcher(chunker.chunkSentence("Hello, world.")); }
@Test public void testMatcher1() throws SequenceException { String patternStr = "There_w are_w CD_p [B-NP_n I-NP_n]+ (IN_p [B-NP_n I-NP_n]+)*"; LayeredTokenPattern pat = new LayeredTokenPattern(patternStr); LayeredTokenMatcher m = pat.matcher(seq); assertTrue(m.find()); assertEquals(0, m.start()); assertEquals(6, m.end()); }