System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>another paragra" + MATCH_START + "ph with " + MATCH_END + "<note><hi>"
+ MATCH_START + "nested" + MATCH_END + "</hi>" + MATCH_START + " inner" + MATCH_END + "</note>"
+ MATCH_START + " elements." + MATCH_END + "</para>", result);
XpathEngine xpe = XMLUnit.newXpathEngine();
NodeList matches = xpe.getMatchingNodes("//exist:match", XMLUnit.buildControlDocument(result));
StringBuilder m = new StringBuilder();
for (int i = 0; i < matches.getLength(); i++)
m.append(matches.item(i).getTextContent());
String match = m.toString();
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = "\\*.*\\?";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>Where did all the " + MATCH_START + "*s go?" + MATCH_END + "</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = ".est[][?]tes.";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "test]test" + MATCH_END + " " + MATCH_START + "test[test"
+ MATCH_END + " " + MATCH_START + "test?test" + MATCH_END + "</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
seq = xquery.execute("//para[ngram:wildcard-contains(., '^" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "test]test" + MATCH_END + " test[test test?test</para>",
result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "$')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>test]test test[test " + MATCH_START + "test?test" + MATCH_END + "</para>",
result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
wildcardQuery = "^aaa.aaa$";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "aaacaaa" + MATCH_END + "</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = ".+simple";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "a simple" + MATCH_END + " paragraph</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = "a s.?i.?m.?p.?l.?e.?";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "a simple " + MATCH_END + "paragraph</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = "a s.?i.?m.?p.?l.?e.?";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(1, seq.getItemCount());
result = queryResult2String(broker, seq, 0);
System.out.println("RESULT: " + result);
XMLAssert.assertEquals("<para>" + MATCH_START + "a simple " + MATCH_END + "paragraph</para>", result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
wildcardQuery = "b.{3,6}c";
seq = xquery.execute("//para[ngram:wildcard-contains(., '" + wildcardQuery + "')]", null,
AccessContext.TEST);
assertNotNull(seq);
assertEquals(2, seq.getItemCount());
for (int i = 0; i < 2; i++) {
result = queryResult2String(broker, seq, i);
System.out.println("RESULT: " + result);
match = xpe.evaluate("//exist:match", XMLUnit.buildControlDocument(result));
System.out.println("MATCH: " + match);
assertMatches(wildcardQuery, match);
}
} catch (Exception e) {