BlsUtils { public static TextPattern parsePatt(BlackLabIndex index, String pattern, String language, boolean required) throws BlsException { if (pattern == null || pattern.length() == 0) { if (required) throw new BadRequest("NO_PATTERN_GIVEN", "Text search pattern required. Please specify 'patt' parameter."); return null; } if (language.equals("corpusql")) { try { return CorpusQueryLanguageParser.parse(pattern); } catch (InvalidQuery e) { throw new BadRequest("PATT_SYNTAX_ERROR", "Syntax error in CorpusQL pattern: " + e.getMessage()); } } else if (language.equals("contextql")) { try { CompleteQuery q = ContextualQueryLanguageParser.parse(index, pattern); return q.pattern(); } catch (InvalidQuery e) { throw new BadRequest("PATT_SYNTAX_ERROR", "Syntax error in ContextQL pattern: " + e.getMessage()); } } throw new BadRequest("UNKNOWN_PATT_LANG", "Unknown pattern language '" + language + "'. Supported: corpusql, contextql, luceneql."); }  static Query parseFilter(BlackLabIndex index, String filter,
            String filterLang); static Query parseFilter(BlackLabIndex index, String filter,
            String filterLang, boolean required); static TextPattern parsePatt(BlackLabIndex index, String pattern,
            String language, boolean required); static TextPattern parsePatt(BlackLabIndex index, String pattern,
            String language); static int getDocIdFromPid(BlackLabIndex index, String pid); static boolean isSymlink(File file); static void delTree(File root); static FileFilter readableDirFilter; }
@Test public void testParsePatt() throws BlsException { TextPattern pattThe = new TextPatternRegex("^the$"); Assert.assertEquals(pattThe, BlsUtils.parsePatt(index, "\"the\"", "corpusql")); Assert.assertEquals(pattThe, BlsUtils.parsePatt(index, "\"the\"", "corpusql", true)); }
@Test public void testParsePattContextQL() throws BlsException { TextPattern pattThe = new TextPatternAnnotation("word", new TextPatternWildcard("the")); Assert.assertEquals(pattThe, BlsUtils.parsePatt(index, "\"the\"", "contextql")); }
@Test(expected = BadRequest.class) public void testParsePattWrongLanguage() throws BlsException { BlsUtils.parsePatt(index, "\"the\"", "swahili"); }
@Test(expected = BadRequest.class) public void testParsePattNoPattern() throws BlsException { BlsUtils.parsePatt(index, "", "corpusql", true); }