englishTagger.tagCoreLabels(sentence);
Tree result = englishParser.apply(sentence);
// pretty much need to make the test rely on the parser being consistent
assertEquals("(ROOT (S (NP (PRP It)) (VP (VBD was) (NP (NNP Carolina) (NNP Reapers))) (. .)))", result.toString());
ParserConstraint constraint = new ParserConstraint(2, 4, ".*");
List<ParserConstraint> constraints = Collections.singletonList(constraint);
ParserQuery pq = englishParser.parserQuery();
pq.setConstraints(constraints);
assertTrue(pq.parse(sentence));
result = pq.getBestParse();
assertEquals("(ROOT (S (NP (PRP It)) (VP (VBD was) (NP (NNP Carolina) (NNP Reapers))) (. .)))", result.toString());
constraint = new ParserConstraint(2, 4, "NP");
constraints = Collections.singletonList(constraint);
pq = englishParser.parserQuery();
pq.setConstraints(constraints);
assertTrue(pq.parse(sentence));
result = pq.getBestParse();
assertEquals("(ROOT (S (NP (PRP It)) (VP (VBD was) (NP (NNP Carolina) (NNP Reapers))) (. .)))", result.toString());
constraint = new ParserConstraint(2, 4, "ADJP");
constraints = Collections.singletonList(constraint);
pq = englishParser.parserQuery();
pq.setConstraints(constraints);
assertTrue(pq.parse(sentence));
result = pq.getBestParse();
assertEquals("(ROOT (S (NP (PRP It)) (VP (VBD was) (ADJP (NP (NNP Carolina) (NNP Reapers)))) (. .)))", result.toString());
constraint = new ParserConstraint(1, 3, "VP");
constraints = Collections.singletonList(constraint);
pq = englishParser.parserQuery();
pq.setConstraints(constraints);
assertTrue(pq.parse(sentence));
result = pq.getBestParse();