Skip to content

Commit 995a5d8

Browse files
committed
Add QueryParserRunners from fcs-simple-endpoint
1 parent 53462a1 commit 995a5d8

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* This software is copyright (c) 2013-2022 by
3+
* - Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4+
* This is free software. You can redistribute it
5+
* and/or modify it under the terms described in
6+
* the GNU General Public License v3 of which you
7+
* should have received a copy. Otherwise you can download
8+
* it from
9+
*
10+
* http://www.gnu.org/licenses/gpl-3.0.txt
11+
*
12+
* @copyright Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13+
*
14+
* @license http://www.gnu.org/licenses/gpl-3.0.txt
15+
* GNU General Public License v3
16+
*/
17+
package eu.clarin.sru.fcs.qlparser.fcs;
18+
19+
import java.io.BufferedReader;
20+
import java.io.File;
21+
import java.io.FileReader;
22+
import java.io.IOException;
23+
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
import eu.clarin.sru.fcs.qlparser.QueryParserException;
28+
29+
30+
public class QueryParserRunner {
31+
private static final Logger logger = LoggerFactory
32+
.getLogger(QueryParserRunner.class);
33+
34+
35+
public static void main(String[] args) {
36+
if ((args != null) && (args.length > 0)) {
37+
File file = new File(args[0]);
38+
if (file.exists() || file.isFile()) {
39+
BufferedReader reader = null;
40+
try {
41+
reader = new BufferedReader(new FileReader(file));
42+
43+
String line;
44+
while ((line = reader.readLine()) != null) {
45+
line = line.trim();
46+
if (line.isEmpty()) {
47+
continue;
48+
}
49+
try {
50+
logger.info("PARSING QUERY: >>>{}<<<", line);
51+
QueryParser parser = new QueryParser();
52+
QueryNode tree = parser.parse(line);
53+
logger.info("{}", tree);
54+
logger.info("... PARSED OK");
55+
} catch (QueryParserException e) {
56+
logger.error(
57+
"error parsing query: " + e.getMessage(),
58+
e);
59+
}
60+
61+
}
62+
} catch (IOException e) {
63+
logger.error("error reading file", e);
64+
} finally {
65+
if (reader != null) {
66+
try {
67+
reader.close();
68+
} catch (IOException e) {
69+
/* IGNORE */
70+
}
71+
}
72+
}
73+
} else {
74+
logger.error("DOES NOT EXIST OR IS NOT A FILE: {}", args[0]);
75+
}
76+
} else {
77+
logger.error("NEED QUERY-FILE");
78+
}
79+
}
80+
81+
static {
82+
org.apache.log4j.BasicConfigurator
83+
.configure(new org.apache.log4j.ConsoleAppender(
84+
new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"),
85+
org.apache.log4j.ConsoleAppender.SYSTEM_ERR));
86+
org.apache.log4j.Logger logger = org.apache.log4j.Logger
87+
.getRootLogger();
88+
logger.setLevel(org.apache.log4j.Level.INFO);
89+
logger.getLoggerRepository().getLogger("eu.clarin")
90+
.setLevel(org.apache.log4j.Level.DEBUG);
91+
}
92+
93+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* This software is copyright (c) 2013-2025 by
3+
* - Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4+
* - Saxon Academy of Sciences and Humanities in Leipzig (https://www.saw-leipzig.de)
5+
* This is free software. You can redistribute it
6+
* and/or modify it under the terms described in
7+
* the GNU General Public License v3 of which you
8+
* should have received a copy. Otherwise you can download
9+
* it from
10+
*
11+
* http://www.gnu.org/licenses/gpl-3.0.txt
12+
*
13+
* @copyright Leibniz-Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
14+
* @copyright Saxon Academy of Sciences and Humanities in Leipzig (https://www.saw-leipzig.de)
15+
*
16+
* @license http://www.gnu.org/licenses/gpl-3.0.txt
17+
* GNU General Public License v3
18+
*/
19+
package eu.clarin.sru.fcs.qlparser.lex;
20+
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
import eu.clarin.sru.fcs.qlparser.QueryParserException;
25+
26+
public class QueryParserRunner {
27+
private static final Logger logger = LoggerFactory.getLogger(QueryParserRunner.class);
28+
29+
public static void main(String[] args) {
30+
String line = "test is /bad=worse apple or (\"not\" and lemma = hi)";
31+
try {
32+
logger.info("PARSING QUERY: >>>{}<<<", line);
33+
QueryParser parser = new QueryParser();
34+
QueryNode tree = parser.parse(line);
35+
logger.info("{}", tree);
36+
logger.info("... PARSED OK");
37+
} catch (QueryParserException e) {
38+
logger.error("error parsing query: " + e.getMessage(), e);
39+
}
40+
41+
}
42+
43+
static {
44+
org.apache.log4j.BasicConfigurator
45+
.configure(new org.apache.log4j.ConsoleAppender(
46+
new org.apache.log4j.PatternLayout("%-5p [%t] %m%n"),
47+
org.apache.log4j.ConsoleAppender.SYSTEM_ERR));
48+
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
49+
logger.setLevel(org.apache.log4j.Level.INFO);
50+
logger.getLoggerRepository().getLogger("eu.clarin")
51+
.setLevel(org.apache.log4j.Level.DEBUG);
52+
}
53+
54+
}

0 commit comments

Comments
 (0)