aboutsummaryrefslogtreecommitdiff
path: root/src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-10 18:17:06 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-11 12:34:47 +0100
commit17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch)
tree47e9310a0cff869d9ec017dcb2c81876407782c8 /src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g
parent8651164cd632a5db310b457ce32d4fbc97bdc41c (diff)
downloadACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz
ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip
[pagoda] Move project to Scala
This commit includes a few changes: - The repository still uses Maven to manage dependency but it is now a Scala project. - The code has been ported from OWLAPI 3.4.10 to 5.1.20 - A proof of concept program using both RSAComb and PAGOdA has been added.
Diffstat (limited to 'src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g')
-rw-r--r--src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g140
1 files changed, 0 insertions, 140 deletions
diff --git a/src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g b/src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g
deleted file mode 100644
index 621b0ce..0000000
--- a/src/org/semanticweb/karma2/model/cqparser/ConjunctiveQuery.g
+++ /dev/null
@@ -1,140 +0,0 @@
1grammar ConjunctiveQuery;
2
3options {
4 language = Java;
5 output = AST;
6}
7
8tokens {
9 VARIABLE;
10 CONSTANT;
11 SCONSTANT;
12 ATOM;
13 HEADATOM;
14 PREDICATE;
15 ATOM_LIST;
16 TERM_LIST;
17 RULE;
18 EXPRESSION;
19 PREFIX_LIST;
20 ID;
21 PREFIX;
22 PREDICATE;
23}
24
25@header {
26package org.semanticweb.karma2.model.cqparser;
27
28import java.io.File;
29import java.io.FileInputStream;
30import java.io.InputStream;
31import java.io.FileNotFoundException;
32import java.io.IOException;
33import java.util.Set;
34
35import org.semanticweb.karma2.model.ConjunctiveQuery;
36
37
38import org.semanticweb.karma2.model.cqparser.ConjunctiveQueryWalker;
39import org.semanticweb.karma2.exception.IllegalInputQueryException;
40
41
42
43}
44
45@members{
46
47
48
49 public ConjunctiveQueryParser(String string)
50 throws FileNotFoundException, IOException {
51 this(new CommonTokenStream(new ConjunctiveQueryLexer(new ANTLRStringStream(string))));
52 }
53
54 public ConjunctiveQueryParser(InputStream istream) throws FileNotFoundException, IOException {
55 this(new CommonTokenStream(new ConjunctiveQueryLexer(new ANTLRInputStream(istream))));
56
57 }
58
59
60 public ConjunctiveQueryParser(File file) throws FileNotFoundException, IOException {
61 this(new CommonTokenStream(new ConjunctiveQueryLexer(new ANTLRInputStream(new FileInputStream(file)))));
62
63 }
64
65 public ConjunctiveQuery parse() throws IllegalInputQueryException {
66 cq_return r = null;
67 try {
68 r = cq();
69 } catch (RecognitionException e) {
70 e.printStackTrace();
71 }
72 CommonTree t = (CommonTree) r.getTree();
73
74 //System.out.println(t.toStringTree());
75 CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
76 // AST nodes have payloads that point into token stream
77 nodes.setTokenStream(input);
78
79
80 ConjunctiveQueryWalker walker = new ConjunctiveQueryWalker();
81
82 ConjunctiveQuery cq = walker.walkExpressionNode(t);
83 return cq;
84 }
85
86 public ConjunctiveQuery parseCQ() throws IllegalInputQueryException {
87 return parse();
88 }
89
90}
91
92
93@lexer::header{
94package org.semanticweb.karma2.model.cqparser;
95}
96
97cq :
98 prefixlist rulebody -> ^(EXPRESSION prefixlist rulebody );
99
100prefixlist:
101 prefix (',' prefix)* -> ^(PREFIX_LIST prefix*);
102
103prefix:
104 'prefix' id ':' '<' url '>' -> ^(PREFIX id url);
105
106
107rulebody:
108 headatom ('<-'|':') body '.'? -> ^(RULE headatom body);
109
110body:
111 atom (',' atom)* -> ^(ATOM_LIST atom*);
112
113
114headatom:
115 id '(' term (',' term)* ')' -> ^(HEADATOM term*);
116
117atom:
118 compositeid '(' term (',' term)* ')' -> ^(ATOM compositeid term*);
119
120compositeid:
121 (id) ':' (id) -> ^(ID id id);
122
123
124term:
125 variable -> ^(VARIABLE variable)
126 | simpleid -> ^(SCONSTANT simpleid)
127 | compositeid -> ^(CONSTANT compositeid);
128
129id : (STRING);
130simpleid : '<' URLSTRING '>' | '<' STRING '>';
131
132// TODO: FIXIT X1 can be parsed as variable
133variable:
134 ('?') id -> ^(id);
135
136 url : (URLSTRING);
137
138URLSTRING : ('http://'|'file:/') ('a'..'z'|'A'..'Z'|'0'..'9'|'/'|'#'|'.'|'-'|'~'|'_')+;
139STRING : ('a'..'z'|'A'..'Z'|'0'..'9'|'/'|'#'|'.'|'-'|'_')+;
140WS : (' '|'\n'|'\r')+ {$channel=HIDDEN;} ;