Skip to content

Commit c0c7e6a

Browse files
committed
PSOATransRun 1.2 Update
1 parent 71f1ac8 commit c0c7e6a

File tree

85 files changed

+1029
-3070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1029
-3070
lines changed

PSOA2X/.classpath

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
49
<classpathentry kind="src" path="src/main/antlr3"/>
5-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
610
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
711
<attributes>
8-
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
12+
<attribute name="maven.pomderived" value="true"/>
913
</attributes>
1014
</classpathentry>
1115
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
@@ -14,5 +18,21 @@
1418
<attribute name="optional" value="true"/>
1519
</attributes>
1620
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
27+
<attributes>
28+
<attribute name="optional" value="true"/>
29+
<attribute name="maven.pomderived" value="true"/>
30+
</attributes>
31+
</classpathentry>
32+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
33+
<attributes>
34+
<attribute name="maven.pomderived" value="true"/>
35+
</attributes>
36+
</classpathentry>
1737
<classpathentry kind="output" path="target/classes"/>
1838
</classpath>

PSOA2X/.settings/org.eclipse.m2e.core.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

PSOA2X/.settings/org.eclipse.wst.common.component

Lines changed: 0 additions & 7 deletions
This file was deleted.

PSOA2X/.settings/org.eclipse.wst.common.project.facet.core.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

PSOA2X/.settings/org.maven.ide.eclipse.prefs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
T__52=52
2-
T__53=53
3-
T__54=54
1+
T__58=58
2+
T__59=59
3+
T__60=60
4+
T__61=61
45
ALPHA=4
56
AND=5
67
BASE=6
7-
CURIE=7
8+
COMMENT=7
89
DIGIT=8
910
DOCUMENT=9
1011
ECHAR=10
@@ -16,39 +17,46 @@ FALSITY=15
1617
FORALL=16
1718
GREATER=17
1819
GROUP=18
19-
ID=19
20-
ID_CHAR=20
21-
ID_START_CHAR=21
22-
IMPLICATION=22
23-
IMPORT=23
24-
INSTANCE=24
25-
IRI=25
26-
IRI_CHAR=26
27-
IRI_REF=27
28-
IRI_START_CHAR=28
29-
LESS=29
30-
LITERAL=30
31-
LOCAL=31
32-
LPAR=32
33-
LSQBR=33
34-
MULTI_LINE_COMMENT=34
35-
NUMBER=35
36-
OR=36
37-
PREFIX=37
38-
PSOA=38
39-
RPAR=39
40-
RSQBR=40
41-
SHORTCONST=41
42-
SLOT=42
43-
SLOT_ARROW=43
44-
STRING=44
45-
SUBCLASS=45
46-
SYMSPACE_OPER=46
47-
TOP=47
48-
TUPLE=48
49-
VAR_ID=49
50-
VAR_LIST=50
51-
WHITESPACE=51
52-
'@'=52
53-
'no'=53
54-
'yes'=54
20+
HEX=19
21+
IMPLICATION=20
22+
IMPORT=21
23+
INSTANCE=22
24+
IRI=23
25+
IRI_REF=24
26+
IRI_REF_CHARACTERS=25
27+
LESS=26
28+
LITERAL=27
29+
LOCAL=28
30+
LPAR=29
31+
LSQBR=30
32+
MULTI_LINE_COMMENT=31
33+
NAMESPACE=32
34+
NUMBER=33
35+
OR=34
36+
PERCENT=35
37+
PLX=36
38+
PN_CHARS=37
39+
PN_CHARS_BASE=38
40+
PN_CHARS_U=39
41+
PN_LOCAL=40
42+
PN_LOCAL_ESC=41
43+
PN_PREFIX=42
44+
PREFIX=43
45+
PSOA=44
46+
RPAR=45
47+
RSQBR=46
48+
SHORTCONST=47
49+
SLOT=48
50+
SLOT_ARROW=49
51+
STRING=50
52+
SUBCLASS=51
53+
SYMSPACE_OPER=52
54+
TOP=53
55+
TUPLE=54
56+
VAR_ID=55
57+
VAR_LIST=56
58+
WHITESPACE=57
59+
'@'=58
60+
'_'=59
61+
'no'=60
62+
'yes'=61

PSOA2X/src/main/antlr3/org/ruleml/psoa/psoa2x/psoa2prolog/PSOA2PrologWalker.g

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ base
4848
;
4949

5050
prefix
51-
: ^(PREFIX ID IRI_REF)
51+
: ^(PREFIX NAMESPACE IRI_REF)
5252
;
5353

5454
importDecl
@@ -157,8 +157,7 @@ atom
157157
equal
158158
: ^(EQUAL t1=term t2=term)
159159
{
160-
if ($t1.type == TermType.VAR &&
161-
$t2.type == TermType.FUNC_EXTERNAL)
160+
if ($t2.type == TermType.FUNC_EXTERNAL)
162161
{
163162
append(_output, "is(", $t1.output, ",", $t2.output, ")");
164163
}
@@ -295,7 +294,7 @@ slot
295294
;
296295

297296
constant
298-
: ^(LITERAL IRI) // { print("\'", $IRI.text, "\'"); }
297+
: ^(LITERAL IRI) { append($term::outputBuilder, "\'\"", $LITERAL.text, "\"^^", $IRI.text, "\'"); }
299298
| ^(SHORTCONST constshort)
300299
| TOP
301300
;
@@ -304,7 +303,7 @@ constshort
304303
:
305304
// TODO: Handle special datatypes, e.g. string, int, etc.
306305
IRI { appendIRIConst($term::outputBuilder, $IRI.text); }
307-
| LITERAL { append($term::outputBuilder, "\'\"", $LITERAL.text, "\"\'"); }
306+
| LITERAL { append($term::outputBuilder, "\'\"", $LITERAL.text.replace("\'","\'\'"), "\"\'"); }
308307
| NUMBER { $term::outputBuilder.append($NUMBER.text); }
309308
| LOCAL { append($term::outputBuilder, "\'_", $LOCAL.text, "\'"); }
310309
;

PSOA2X/src/main/antlr3/org/ruleml/psoa/psoa2x/psoa2tptp/DirectTranslatorWalker.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ base
4141
;
4242

4343
prefix
44-
: ^(PREFIX ID IRI_REF)
44+
: ^(PREFIX NAMESPACE IRI_REF)
4545
;
4646

4747
importDecl

PSOA2X/src/main/antlr3/org/ruleml/psoa/psoa2x/psoa2tptp/TPTPASOTranslatorWalker.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ base
5151
;
5252

5353
prefix
54-
: ^(PREFIX ID IRI_REF)
54+
: ^(PREFIX NAMESPACE IRI_REF)
5555
;
5656

5757
importDecl

PSOA2X/src/main/java/org/ruleml/psoa/psoa2x/common/ANTLRBasedTranslator.java

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,83 @@
1010
import org.antlr.runtime.*;
1111
import org.antlr.runtime.tree.*;
1212
import org.ruleml.psoa.parser.*;
13-
import org.ruleml.psoa.normalizer.*;
13+
import org.ruleml.psoa.FreshNameGenerator;
14+
import org.ruleml.psoa.PSOAInput;
15+
import org.ruleml.psoa.PSOAKB;
16+
import org.ruleml.psoa.PSOAQuery;
17+
import org.ruleml.psoa.analyzer.KBInfoCollector;
18+
import org.ruleml.psoa.transformer.*;
1419

1520
public abstract class ANTLRBasedTranslator extends Translator {
16-
abstract protected TranslatorWalker createTranslatorWalker(CommonTreeNodeStream astNodes);
21+
abstract protected TranslatorWalker createTranslatorWalker(TreeNodeStream astNodes);
22+
abstract protected <T extends PSOAInput<T>> T normalize(T input);
23+
protected PSOAKB m_kb;
1724

1825
@Override
1926
public void translateKB(String kb, OutputStream out) throws TranslatorException {
20-
translateKB(new ANTLRStringStream(kb), out);
27+
m_kb = new PSOAKB();
28+
m_kb.loadFromText(kb);
29+
translateKB(m_kb, out);
2130
}
2231

2332
@Override
2433
public void translateKB(InputStream kb, OutputStream out) throws TranslatorException {
2534
try {
26-
translateKB(new ANTLRInputStream(kb), out);
35+
FreshNameGenerator.reset();
36+
m_kb = new PSOAKB();
37+
m_kb.load(kb);
38+
translateKB(m_kb, out);
2739
} catch (IOException e) {
28-
throw new TranslatorException(e.getMessage());
40+
throw new TranslatorException(e);
2941
}
3042
}
3143

32-
public void translateKB(CharStream kb, OutputStream out) throws TranslatorException {
33-
translate(kb, false, out);
44+
public void translateKB(PSOAKB kb, OutputStream out) throws TranslatorException {
45+
try {
46+
kb.loadImports();
47+
kb.setPrintAfterTransformation(debugMode);
48+
TreeNodeStream stream = normalize(kb).getTreeNodeStream();
49+
TranslatorWalker walker = createTranslatorWalker(stream);
50+
walker.setOutputStream(getPrintStream(out));
51+
walker.document();
52+
} catch (RecognitionException e) {
53+
throw new TranslatorException(e);
54+
} catch (IOException e) {
55+
throw new TranslatorException(e);
56+
}
3457
}
3558

3659
@Override
3760
public void translateQuery(String query, OutputStream out) throws TranslatorException {
38-
translateQuery(new ANTLRStringStream(query), out);
61+
PSOAQuery psoaquery = new PSOAQuery(m_kb);
62+
psoaquery.loadFromText(query);
63+
translateQuery(psoaquery, out);
3964
}
4065

4166
@Override
4267
public void translateQuery(InputStream query, OutputStream out) throws TranslatorException {
4368
try {
44-
translateQuery(new ANTLRInputStream(query), out);
69+
PSOAQuery psoaquery = new PSOAQuery(m_kb);
70+
psoaquery.load(query);
71+
translateQuery(psoaquery, out);
4572
} catch (IOException e) {
46-
throw new TranslatorException(e.getMessage());
73+
throw new TranslatorException(e);
74+
}
75+
}
76+
77+
public void translateQuery(PSOAQuery query, OutputStream out) {
78+
try {
79+
query.setPrintAfterTransformation(debugMode);
80+
TreeNodeStream stream = normalize(query).getTreeNodeStream();
81+
TranslatorWalker walker = createTranslatorWalker(stream);
82+
walker.setOutputStream(getPrintStream(out));
83+
_queryVarMap = walker.query();
84+
} catch (RecognitionException e) {
85+
throw new TranslatorException(e);
4786
}
4887
}
4988

89+
/*
5090
public void translateQuery(CharStream query, OutputStream out) throws TranslatorException {
5191
translate(query, true, out);
5292
}
@@ -113,6 +153,7 @@ protected static void debugPrintTree(CommonTreeNodeStream stream)
113153
if (debugMode)
114154
System.out.println(((CommonTree)stream.getTreeSource()).toStringTree());
115155
}
156+
*/
116157

117158
public static abstract class TranslatorWalker extends TreeParser {
118159
protected PrintStream _outStream = System.out;

0 commit comments

Comments
 (0)