• R/O
  • SSH
  • HTTPS

morilibprolog: コミット


コミットメタ情報

リビジョン6 (tree)
日時2013-03-02 18:08:33
作者y-moriguchi

ログメッセージ

prepare for release

変更サマリ

差分

--- trunk/prolog/test/net/morilib/predicate/operator/OperatorTest1.java (revision 5)
+++ trunk/prolog/test/net/morilib/predicate/operator/OperatorTest1.java (revision 6)
@@ -28,7 +28,6 @@
2828
2929 static final Object CNT1 = new Object() {
3030
31- @SuppressWarnings("unused")
3231 @Continuatable
3332 public Object execute(
3433 Term r2, OpTreeKbn k2, boolean rel2) {
--- trunk/prolog/test/net/morilib/predicate/operator/OperatorTest2.java (revision 5)
+++ trunk/prolog/test/net/morilib/predicate/operator/OperatorTest2.java (revision 6)
@@ -30,7 +30,6 @@
3030
3131 static final Object CNT1 = new Object() {
3232
33- @SuppressWarnings("unused")
3433 @Continuatable
3534 public Object execute(
3635 Polynomial<String, Rational> f1) {
--- trunk/prolog/test/net/morilib/predicate/parser/JPParserTest1.java (revision 5)
+++ trunk/prolog/test/net/morilib/predicate/parser/JPParserTest1.java (nonexistent)
@@ -1,63 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser;
17-
18-import java.io.StringReader;
19-
20-import net.morilib.predicate.Query;
21-import net.morilib.predicate.Result;
22-import net.morilib.predicate.Rule;
23-import net.morilib.predicate.RuleBase;
24-import net.morilib.predicate.parser.jp.JPParser;
25-import net.morilib.predicate.parser.jp.JPQueryParser;
26-
27-public class JPParserTest1 {
28-
29- private static final String TEXT1 =
30- "<b>真田幸村</b>は<b>人間</b>である。" +
31- "<b>伊達政宗</b>は<b>人間</b>である。" +
32- "<b>直江兼続</b>は<b>人間</b>である。" +
33- "<i>X</i>は<b>生きる</b>ならば<i>X</i>は<b>人間</b>である。" +
34- "<b>武将</b>(<i>X</i>, <i>Y</i>)." +
35- "[<b>a</b>, <b>b</b>, <b>c</b>]." +
36- "[<b>a</b>|<b>b</b>]." +
37- "";
38-
39- private static final String TEXT2 =
40- "<i>X</i>は<b>生きる</b>か。";
41-
42- public static void main(String[] args) {
43- JPParser prs = new JPParser(new StringReader(TEXT1));
44- JPQueryParser pqs = new JPQueryParser(new StringReader(TEXT2));
45- RuleBase base = new RuleBase();
46- Rule r;
47- Query q;
48-
49- while((r = prs.parse()) != null) {
50- System.out.println(r);
51- base.addClause(r);
52- }
53-
54- while((q = pqs.parse()) != null) {
55- Result rs = base.query(q);
56-
57- while(rs.next()) {
58- System.out.println(rs.getAll());
59- }
60- }
61- }
62-
63-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/test/net/morilib/predicate/parser/JPLexerTest1.java (revision 5)
+++ trunk/prolog/test/net/morilib/predicate/parser/JPLexerTest1.java (nonexistent)
@@ -1,37 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser;
17-
18-import java.io.StringReader;
19-
20-import net.morilib.predicate.parser.jp.JPLexer;
21-
22-public class JPLexerTest1 {
23-
24- private static final String TEXT1 =
25- "<span class=\"variable\">X</span>は<b>生きる</b>。";
26-
27-
28- public static void main(String[] args) {
29- JPLexer lex = new JPLexer(new StringReader(TEXT1));
30- Object obj;
31-
32- while((obj = lex.getToken()) != JPLexer.EOF) {
33- System.out.println(obj);
34- }
35- }
36-
37-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/RuleBase.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/RuleBase.java (revision 6)
@@ -41,7 +41,6 @@
4141
4242 private class Suc {
4343
44- @SuppressWarnings("unused")
4544 @Continuatable
4645 public Object execute(
4746 Substitution s,
@@ -91,7 +90,6 @@
9190
9291 private class Fal {
9392
94- @SuppressWarnings("unused")
9593 @Continuatable
9694 public Object execute(
9795 Substitution s,
@@ -130,7 +128,6 @@
130128 }
131129
132130
133- @SuppressWarnings("unused")
134131 @Continuatable
135132 public Object execute(
136133 Substitution s,
@@ -255,7 +252,6 @@
255252 //
256253 static final Object _OZ = new Object() {
257254
258- @SuppressWarnings("unused")
259255 @Continuatable
260256 public Object execute(
261257 Substitution s,
--- trunk/prolog/src/net/morilib/predicate/operator/BinOp.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/operator/BinOp.java (revision 6)
@@ -55,7 +55,6 @@
5555
5656 return new CPS(new Object() {
5757
58- @SuppressWarnings("unused")
5958 @Continuatable
6059 public CPS execute() {
6160 Object cnt1 = new Object() {
@@ -114,7 +113,6 @@
114113
115114 return new CPS(new Object() {
116115
117- @SuppressWarnings("unused")
118116 @Continuatable
119117 public Object execute() {
120118 Object cnt1 = new Object() {
--- trunk/prolog/src/net/morilib/predicate/operator/UnOp.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/operator/UnOp.java (revision 6)
@@ -45,7 +45,6 @@
4545
4646 return new CPS(new Object() {
4747
48- @SuppressWarnings("unused")
4948 @Continuatable
5049 public CPS execute() {
5150 Object cnt1 = new Object() {
@@ -81,7 +80,6 @@
8180
8281 return new CPS(new Object() {
8382
84- @SuppressWarnings("unused")
8583 @Continuatable
8684 public Object execute() {
8785 Object cnt1 = new Object() {
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPVar.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPVar.java (nonexistent)
@@ -1,25 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class JPVar extends JPToken {
19-
20-
21- public JPVar(String value) {
22- super(value);
23- }
24-
25-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/TagEnd.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/TagEnd.java (nonexistent)
@@ -1,40 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class TagEnd {
19-
20- //
21- private String name;
22-
23-
24- /*package*/ TagEnd(String name) {
25- this.name = name;
26- }
27-
28- /**
29- * @return the name
30- */
31- public String getName() {
32- return name;
33- }
34-
35-
36- public String toString() {
37- return name;
38- }
39-
40-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPParser.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPParser.java (nonexistent)
@@ -1,425 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-import java.io.Reader;
19-import java.util.ArrayList;
20-import java.util.HashMap;
21-import java.util.List;
22-import java.util.Map;
23-
24-import net.morilib.predicate.NormalTerm;
25-import net.morilib.predicate.Rule;
26-import net.morilib.predicate.Term;
27-import net.morilib.predicate.Terms;
28-import net.morilib.predicate.Variable;
29-import net.morilib.predicate.parser.FailObject;
30-import net.morilib.predicate.parser.Followable;
31-import net.morilib.predicate.parser.PredicateParserException;
32-import static net.morilib.predicate.parser.jp.JPLexer.CDR;
33-import static net.morilib.predicate.parser.jp.JPLexer.COM;
34-import static net.morilib.predicate.parser.jp.JPLexer.LIE;
35-import static net.morilib.predicate.parser.jp.JPLexer.LIS;
36-import static net.morilib.predicate.parser.jp.JPLexer.LPR;
37-import static net.morilib.predicate.parser.jp.JPLexer.PRD;
38-import static net.morilib.predicate.parser.jp.JPLexer.RPR;
39-import net.morilib.util.Objects;
40-import net.morilib.util.Tokenizer;
41-import net.morilib.util.cont.CPS;
42-import net.morilib.util.cont.Continuatable;
43-
44-public class JPParser {
45-
46-
47- /*package*/ static class Tok2 implements Tokenizer<Object> {
48-
49- //
50- private Tokenizer<Object> lexer;
51-
52- public Tok2(Tokenizer<Object> lexer) {
53- this.lexer = lexer;
54- }
55-
56- private boolean isB(TagInfo t) {
57- return t.getName().equalsIgnoreCase("b") || (
58- t.getName().equalsIgnoreCase("span") &&
59- "id".equalsIgnoreCase(t.getAttr("class")));
60- }
61-
62- private boolean isI(TagInfo t) {
63- return t.getName().equalsIgnoreCase("i") || (
64- t.getName().equalsIgnoreCase("span") &&
65- "variable".equalsIgnoreCase(t.getAttr("class")));
66- }
67-
68- private boolean isU(TagInfo t) {
69- return t.getName().equalsIgnoreCase("u") || (
70- t.getName().equalsIgnoreCase("span") &&
71- "keyword".equalsIgnoreCase(t.getAttr("class")));
72- }
73-
74- private Object skipTag(TagInfo b) {
75- Object o;
76-
77- while((o = lexer.getToken()) != JPLexer.EOF) {
78- if(o instanceof TagInfo) {
79- // do nothing
80- } else if(o instanceof TagEnd) {
81- if(((TagEnd)o).getName().equalsIgnoreCase(
82- b.getName())) {
83- return o;
84- }
85- } else {
86- return o;
87- }
88- }
89- return o;
90- }
91-
92- public Object getToken() {
93- Object o = lexer.getToken();
94-
95- if(o instanceof TagInfo) {
96- TagInfo t = (TagInfo)o;
97-
98- if(isB(t)) {
99- Object p = skipTag(t);
100-
101- if(p instanceof String) {
102- if(skipTag(t) instanceof TagEnd) {
103- return new JPID((String)p);
104- }
105- }
106- return new FailObject();
107- } else if(isU(t)) {
108- Object p = skipTag(t);
109-
110- if(p instanceof String) {
111- if(skipTag(t) instanceof TagEnd) {
112- return new JPKeyword((String)p);
113- }
114- }
115- return new FailObject();
116- } else if(isI(t)) {
117- Object p = skipTag(t);
118-
119- if(p instanceof String) {
120- if(skipTag(t) instanceof TagEnd) {
121- return new JPVar((String)p);
122- }
123- }
124- return new FailObject();
125- } else {
126- return new FailObject();
127- }
128- } else {
129- return o;
130- }
131- }
132-
133- }
134-
135- //
136- /*package*/ static class _Cla {
137-
138- @Continuatable
139- public Object execute(
140- Tok2 tok, final Term hed,
141- final List<Term> lst,
142- final Map<String, Term> vm) {
143- return new CPS(TER, new Followable() {
144-
145- @SuppressWarnings("unused")
146- @Continuatable
147- public Object execute(Tok2 tok, Object v, Term t0) {
148- lst.add(t0);
149- if("である".equals(v)) {
150- v = tok.getToken();
151- }
152-
153- if(v.equals(PRD)) {
154- return new Rule(hed, lst);
155- }
156-
157- if(!(v.equals(COM) ||
158- "かつ".equals(v))) {
159- v = tok.getToken();
160- if(v.equals(COM)) {
161- v = tok.getToken();
162- }
163- return new CPS(CLA, hed, lst, vm, false);
164- }
165- return new FailObject();
166- }
167-
168- public boolean follow(Object v) {
169- return ("である".equals(v) ||
170- "かつ".equals(v) ||
171- COM.equals(v) ||
172- PRD.equals(v));
173- }
174-
175- }, tok, vm, false);
176- }
177-
178- }
179-
180- //
181- /*package*/ static class _Ter {
182-
183- @Continuatable
184- public Object execute(
185- final Followable cont,
186- Tok2 tok,
187- final Map<String, Term> vm,
188- boolean eof) {
189- Object t = tok.getToken();
190- final Object cnt1 = new Object() {
191-
192- @SuppressWarnings("unused")
193- @Continuatable
194- public Object execute(Tok2 tok, Object s, Term t1) {
195- if("は".equals(s) || "が".equals(s)) {
196- Object u = tok.getToken();
197- Term t0;
198-
199- if(!(u instanceof JPID)) {
200- return new FailObject();
201- }
202-
203- t0 = new NormalTerm(((JPID)u).getValue(), t1);
204-
205- Object v = tok.getToken();
206- if(cont.follow(v)) {
207- return new CPS(cont, tok, v, t0);
208- }
209- } else if(cont.follow(s)) {
210- return new CPS(cont, tok, s, t1);
211- }
212- return new FailObject();
213- }
214-
215- };
216- final Object cnt2 = new Object() {
217-
218- @SuppressWarnings("unused")
219- @Continuatable
220- public Object execute(
221- Tok2 tok,
222- final List<Term> lst,
223- final Object cnt1,
224- final Object id) {
225- return new CPS(TER, new Followable() {
226-
227- @Continuatable
228- public Object execute(
229- Tok2 tok, Object s, Term t) {
230- lst.add(t);
231- if(COM.equals(s)) {
232- return new CPS(
233- TER, this, tok, vm, false);
234- } else if(RPR.equals(s)) {
235- return new CPS(
236- cnt1, tok, tok.getToken(),
237- new NormalTerm(id, lst));
238- } else {
239- return new FailObject();
240- }
241- }
242-
243- public boolean follow(Object o) {
244- return COM.equals(o) || RPR.equals(o);
245- }
246-
247- }, tok, vm, false);
248-
249- }
250-
251- };
252- final Object cnt3 = new Object() {
253-
254- @SuppressWarnings("unused")
255- @Continuatable
256- public Object execute(
257- Tok2 tok,
258- final List<Term> lst,
259- final Object cnt1) {
260- final Object cnta = new Followable() {
261-
262- @Continuatable
263- public Object execute(
264- Tok2 tok, Object s, Term t) {
265- Term rs;
266-
267- if(!LIE.equals(s)) {
268- return new FailObject();
269- }
270- rs = Terms.toTermList(lst, t);
271- return new CPS(
272- cnt1, tok, tok.getToken(), rs);
273- }
274-
275- public boolean follow(Object o) {
276- return LIE.equals(o);
277- }
278-
279- };
280-
281- return new CPS(TER, new Followable() {
282-
283- @Continuatable
284- public Object execute(
285- Tok2 tok, Object s, final Term t) {
286- lst.add(t);
287- if(COM.equals(s)) {
288- return new CPS(
289- TER, this, tok, vm, false);
290- } else if(CDR.equals(s)) {
291- return new CPS(
292- TER, cnta, tok, vm, false);
293- } else if(LIE.equals(s)) {
294- return new CPS(
295- cnt1, tok, tok.getToken(),
296- Terms.toTermList(lst));
297- } else {
298- return new FailObject();
299- }
300- }
301-
302- public boolean follow(Object o) {
303- return (COM.equals(o) ||
304- LIE.equals(o) ||
305- CDR.equals(o));
306- }
307-
308- }, tok, vm, false);
309-
310- }
311-
312- };
313-
314- if(t == JPLexer.EOF) {
315- return eof ? t : new FailObject();
316- } else if(t instanceof JPID) {
317- Object s = tok.getToken();
318-
319- if(LPR.equals(s)) {
320- return new CPS(
321- cnt2, tok,
322- new ArrayList<Term>(),
323- cnt1, ((JPID)t).getValue());
324- } else {
325- return new CPS(cnt1, tok, s, toTerm0(t, vm));
326- }
327- } else if(t instanceof JPVar) {
328- return new CPS(
329- cnt1, tok, tok.getToken(), toTerm0(t, vm));
330- } else if(LIS.equals(t)) {
331- return new CPS(
332- cnt3, tok, new ArrayList<Term>(), cnt1);
333- } else {
334- return new FailObject();
335- }
336- }
337-
338- }
339-
340- //
341- /*package*/ static class _Init {
342-
343- @Continuatable
344- public Object execute(Tok2 tok) {
345- final Map<String, Term> vm = new HashMap<String, Term>();
346-
347- return new CPS(TER, new Followable() {
348-
349- @SuppressWarnings("unused")
350- @Continuatable
351- public Object execute(Tok2 tok, Object v, Term t0) {
352- if("である".equals(v)) {
353- v = tok.getToken();
354- }
355-
356- if(v.equals(PRD)) {
357- return new Rule(t0);
358- } else if("ならば".equals(v) || "とは".equals(v)) {
359- return new CPS(CLA, tok, t0,
360- new ArrayList<Term>(),
361- vm);
362- }
363- return new FailObject();
364- }
365-
366- public boolean follow(Object v) {
367- return ("である".equals(v) ||
368- "ならば".equals(v) ||
369- "とは".equals(v) ||
370- PRD.equals(v));
371- }
372-
373- }, tok, vm, true);
374- }
375-
376- }
377-
378-
379- //
380- /*package*/ static final Object CLA = new _Cla();
381- /*package*/ static final Object TER = new _Ter();
382- /*package*/ static final Object INIT = new _Init();
383-
384- //
385- private Tok2 tokenizer;
386-
387-
388- /*package*/ static Term toTerm0(Object o, Map<String, Term> vm) {
389- if(o instanceof JPID) {
390- return new NormalTerm(((JPID)o).getValue());
391- } else if(o instanceof JPVar) {
392- String n = ((JPVar)o).getValue();
393-
394- if(vm == null) {
395- return Variable.newTemporary(n);
396- } else if(!vm.containsKey(n)) {
397- vm.put(n, Variable.newTemporary(n));
398- }
399- return vm.get(n);
400- } else if(o instanceof JPKeyword) {
401- throw new RuntimeException();
402- } else {
403- return null;
404- }
405- }
406-
407-
408- public JPParser(Reader rd) {
409- tokenizer = new Tok2(new JPLexer(rd));
410- }
411-
412-
413- public Rule parse() {
414- Object res = CPS.invoke(INIT, tokenizer);
415-
416- if(res instanceof Rule) {
417- return (Rule)res;
418- } else if(res == JPLexer.EOF) {
419- return null;
420- } else {
421- throw new PredicateParserException(Objects.toString(res));
422- }
423- }
424-
425-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/TagAttr.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/TagAttr.java (nonexistent)
@@ -1,49 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class TagAttr {
19-
20- //
21- private String key;
22- private String value;
23-
24-
25- /*package*/ TagAttr(String key, String value) {
26- this.key = key;
27- this.value = value;
28- }
29-
30- /**
31- * @return the key
32- */
33- public String getKey() {
34- return key;
35- }
36-
37- /**
38- * @return the value
39- */
40- public String getValue() {
41- return value;
42- }
43-
44-
45- public String toString() {
46- return key + "=" + value;
47- }
48-
49-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPID.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPID.java (nonexistent)
@@ -1,25 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class JPID extends JPToken {
19-
20-
21- public JPID(String value) {
22- super(value);
23- }
24-
25-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/TagInfo.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/TagInfo.java (nonexistent)
@@ -1,53 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-import java.util.HashMap;
19-import java.util.List;
20-import java.util.Map;
21-
22-/*package*/ class TagInfo {
23-
24- //
25- private String name;
26- private Map<String, String> attrs = new HashMap<String, String>();
27-
28-
29- /*package*/ TagInfo(String name, List<TagAttr> attrs) {
30- this.name = name;
31- for(TagAttr t : attrs) {
32- this.attrs.put(t.getKey(), t.getValue());
33- }
34- }
35-
36- /**
37- * @return the name
38- */
39- public String getName() {
40- return name;
41- }
42-
43-
44- public String getAttr(String key) {
45- return attrs.get(key);
46- }
47-
48-
49- public String toString() {
50- return name + ":" + attrs;
51- }
52-
53-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPLexer.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPLexer.java (nonexistent)
@@ -1,353 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-import java.io.Reader;
19-import java.util.ArrayList;
20-import java.util.List;
21-
22-import net.morilib.predicate.parser.FailObject;
23-import net.morilib.predicate.parser.PredicateParserException;
24-import net.morilib.util.ReaderCharTape;
25-import net.morilib.util.Tokenizer;
26-import net.morilib.util.cont.CPS;
27-import net.morilib.util.cont.Continuatable;
28-
29-public class JPLexer implements Tokenizer<Object> {
30-
31-
32- public static final Object EOF = new Object() {
33-
34- public String toString() {
35- return "EOF";
36- }
37-
38- };
39-
40- //
41- private static final FailObject FAIL = new FailObject();
42- private static final _Init INIT = new _Init();
43- private static final _ID1 ID1 = new _ID1();
44- private static final _IDQ IDQ = new _IDQ();
45- private static final _Atr1 ATR1 = new _Atr1();
46- private static final _Tag TAG = new _Tag();
47- private static final _TagE TAGZ = new _TagE();
48-
49- //
50- private Rdr1 stream;
51-
52-
53- /*package*/ static final boolean isKuten(int c) {
54- return c == ',' || c == '、' || c == ',';
55- }
56-
57- /*package*/ static final boolean isToten(int c) {
58- return c == '.' || c == '。' || c == '.';
59- }
60-
61- /*package*/ static final boolean isCompare(int c) {
62- return "<>=<>≦≧=≠".indexOf(c) >= 0;
63- }
64-
65- /*package*/ static final boolean isOperator(int c) {
66- return "+-*/^()+ー×・/÷()".indexOf(c) >= 0;
67- }
68-
69- /*package*/ static final boolean isQuote(int c) {
70- return "\"'".indexOf(c) >= 0;
71- }
72-
73- /*package*/ static final boolean isListOp(int c) {
74- return "[]|".indexOf(c) >= 0;
75- }
76-
77-
78- //
79- private static final class Rdr1 {
80-
81- //
82- private ReaderCharTape tp;
83-
84- public Rdr1(Reader ins) {
85- tp = new ReaderCharTape(ins, 10);
86- }
87-
88- public int read() {
89- tp.moveRight();
90- return tp.readc();
91- }
92-
93- public void unread() {
94- if(!tp.moveLeft()) {
95- throw new PredicateParserException();
96- }
97- }
98-
99- }
100-
101- //
102- /*package*/ static final class _ID1 {
103-
104- @Continuatable
105- public Object execute(Rdr1 ins, Object cont) {
106- StringBuilder bld = new StringBuilder();
107-
108- while(true) {
109- int c = ins.read();
110-
111- if(c < 0) {
112- return FAIL;
113- } else if(Character.isWhitespace(c)) {
114- ins.unread();
115- return new CPS(cont, ins, bld.toString());
116- } else if(isKuten(c)) {
117- ins.unread();
118- return new CPS(cont, ins, bld.toString());
119- } else if(isToten(c)) {
120- ins.unread();
121- return new CPS(cont, ins, bld.toString());
122- } else if(isCompare(c)) {
123- ins.unread();
124- return new CPS(cont, ins, bld.toString());
125- } else if(isOperator(c)) {
126- ins.unread();
127- return new CPS(cont, ins, bld.toString());
128- } else if(isQuote(c)) {
129- ins.unread();
130- return new CPS(cont, ins, bld.toString());
131- } else {
132- bld.append((char)c);
133- }
134- }
135- }
136-
137- }
138-
139- //
140- /*package*/ static final class _IDQ {
141-
142- @Continuatable
143- public Object execute(Rdr1 ins, Object cont) {
144- StringBuilder bld = new StringBuilder();
145- int c0 = ins.read();
146-
147- if(!isQuote(c0)) {
148- return FAIL;
149- }
150-
151- while(true) {
152- int c = ins.read();
153-
154- if(c < 0) {
155- return FAIL;
156- } else if(c == c0) {
157- return new CPS(cont, ins, bld.toString());
158- } else {
159- bld.append((char)c);
160- }
161- }
162- }
163-
164- }
165-
166- //
167- /*package*/ static final class _Atr1 {
168-
169- @Continuatable
170- public Object execute(Rdr1 ins, final Object cont) {
171- return new CPS(ID1, ins, new Object() {
172-
173- @SuppressWarnings("unused")
174- @Continuatable
175- public Object execute(Rdr1 ins, final String s1) {
176- int c;
177-
178- do {
179- if((c = ins.read()) < 0) {
180- return FAIL;
181- }
182- } while(Character.isWhitespace(c));
183-
184- if(c != '=') {
185- return FAIL;
186- }
187- return new CPS(IDQ, ins, new Object() {
188-
189- @Continuatable
190- public Object execute(Rdr1 ins, String s2) {
191- return new CPS(
192- cont, ins, new TagAttr(s1, s2));
193- }
194-
195- });
196- }
197-
198- });
199- }
200-
201- }
202-
203- //
204- /*package*/ static final class _Tag {
205-
206- @Continuatable
207- public Object execute(Rdr1 ins) {
208- final List<TagAttr> lst = new ArrayList<TagAttr>();
209- int c;
210-
211- do {
212- if((c = ins.read()) < 0) {
213- return FAIL;
214- }
215- } while(Character.isWhitespace(c));
216-
217- if(c == '/') {
218- return new CPS(TAGZ, ins);
219- }
220-
221- ins.unread();
222- return new CPS(ID1, ins, new Object() {
223-
224- @SuppressWarnings("unused")
225- @Continuatable
226- public Object execute(Rdr1 ins, final String str) {
227- return new CPS(new Object() {
228-
229- @Continuatable
230- public Object execute(Rdr1 ins) {
231- final Object o1 = this;
232- int c;
233-
234- do {
235- if((c = ins.read()) < 0) {
236- return FAIL;
237- }
238- } while(Character.isWhitespace(c));
239-
240- if(c == '>') {
241- return new TagInfo(str, lst);
242- }
243-
244- ins.unread();
245- return new CPS(ATR1, ins, new Object() {
246-
247- @Continuatable
248- public Object execute(
249- Rdr1 ins, TagAttr atr) {
250- lst.add(atr);
251- return new CPS(o1, ins);
252- }
253-
254- });
255- }
256-
257- }, ins);
258- }
259-
260- });
261- }
262-
263- }
264-
265- //
266- /*package*/ static final class _TagE {
267-
268- @Continuatable
269- public Object execute(Rdr1 ins) {
270- return new CPS(ID1, ins, new Object() {
271-
272- @SuppressWarnings("unused")
273- @Continuatable
274- public Object execute(Rdr1 ins, String str) {
275- int c = ins.read();
276-
277- if(c != '>') {
278- return FAIL;
279- }
280- return new TagEnd(str);
281- }
282-
283- });
284- }
285-
286- }
287-
288- //
289- /*package*/ static final class _Init {
290-
291- @Continuatable
292- public Object execute(Rdr1 ins) {
293- int c;
294-
295- do {
296- if((c = ins.read()) < 0) {
297- return EOF;
298- }
299- } while(Character.isWhitespace(c));
300-
301- if(c == '<') {
302- return new CPS(TAG, ins);
303- } else if(isKuten(c)) {
304- return new Character(',');
305- } else if(isToten(c)) {
306- return new Character('.');
307- } else if(isCompare(c)) {
308- return new Character((char)c);
309- } else if(isOperator(c)) {
310- return new Character((char)c);
311- } else if(isListOp(c)) {
312- return new Character((char)c);
313- } else if(isQuote(c)) {
314- return FAIL;
315- } else {
316- ins.unread();
317- return new CPS(ID1, ins, new Object() {
318-
319- @SuppressWarnings("unused")
320- @Continuatable
321- public Object execute(Rdr1 ins, String str) {
322- return str;
323- }
324-
325- });
326- }
327- }
328-
329- }
330-
331- //
332- /*package*/ static final Object PRD = new Character('.');
333- /*package*/ static final Object COM = new Character(',');
334- /*package*/ static final Object LPR = new Character('(');
335- /*package*/ static final Object RPR = new Character(')');
336- /*package*/ static final Object LIS = new Character('[');
337- /*package*/ static final Object LIE = new Character(']');
338- /*package*/ static final Object CDR = new Character('|');
339-
340-
341- public JPLexer(Reader rd) {
342- stream = new Rdr1(rd);
343- }
344-
345-
346- public Object getToken() {
347- Object res = CPS.invoke(INIT, stream);
348-
349-// System.out.println(res);
350- return res;
351- }
352-
353-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPToken.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPToken.java (nonexistent)
@@ -1,33 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class JPToken {
19-
20- //
21- private String value;
22-
23-
24- public JPToken(String value) {
25- this.value = value;
26- }
27-
28-
29- public String getValue() {
30- return value;
31- }
32-
33-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPQueryParser.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPQueryParser.java (nonexistent)
@@ -1,115 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-import java.io.Reader;
19-import java.util.ArrayList;
20-import java.util.HashMap;
21-import java.util.List;
22-import java.util.Map;
23-
24-import net.morilib.predicate.Query;
25-import net.morilib.predicate.Term;
26-import net.morilib.predicate.parser.FailObject;
27-import net.morilib.predicate.parser.Followable;
28-import net.morilib.predicate.parser.PredicateParserException;
29-import net.morilib.predicate.parser.jp.JPParser.Tok2;
30-import net.morilib.util.Objects;
31-import net.morilib.util.cont.CPS;
32-import net.morilib.util.cont.Continuatable;
33-
34-public class JPQueryParser {
35-
36- //
37- /*package*/ static class _Cla {
38-
39- @Continuatable
40- public Object execute(
41- Tok2 tok,
42- final List<Term> lst,
43- final Map<String, Term> vm,
44- boolean eof) {
45- return new CPS(JPParser.TER, new Followable() {
46-
47- @SuppressWarnings("unused")
48- @Continuatable
49- public Object execute(Tok2 tok, Object v, Term t0) {
50-// Object v;
51-
52- lst.add(t0);
53-// v = tok.getToken();
54- if(v.equals(new Character('?'))) {
55- return new Query(lst, vm);
56- } else if("か".equals(v)) {
57- v = tok.getToken();
58- if(v.equals(new Character('.')) ||
59- v.equals(new Character('?'))) {
60- return new Query(lst, vm);
61- }
62- }
63-
64- if(!(v.equals(new Character(',')) ||
65- "かつ".equals(v))) {
66- v = tok.getToken();
67- if(v.equals(new Character(','))) {
68- v = tok.getToken();
69- }
70- return new CPS(CLA, tok, lst, vm, false);
71- }
72- return new FailObject();
73- }
74-
75- public boolean follow(Object v) {
76- return ("か".equals(v) ||
77- "かつ".equals(v) ||
78- new Character(',').equals(v) ||
79- new Character('?').equals(v));
80- }
81-
82- }, tok, vm, eof);
83- }
84-
85- }
86-
87-
88- //
89- private static final Object CLA = new _Cla();
90-
91- //
92- private Tok2 tokenizer;
93-
94-
95- public JPQueryParser(Reader rd) {
96- tokenizer = new Tok2(new JPLexer(rd));
97- }
98-
99-
100- public Query parse() {
101- Object res = CPS.invoke(CLA, tokenizer,
102- new ArrayList<Term>(),
103- new HashMap<String, Term>(),
104- true);
105-
106- if(res instanceof Query) {
107- return (Query)res;
108- } else if(res == JPLexer.EOF) {
109- return null;
110- } else {
111- throw new PredicateParserException(Objects.toString(res));
112- }
113- }
114-
115-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/jp/JPKeyword.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/jp/JPKeyword.java (nonexistent)
@@ -1,25 +0,0 @@
1-/*
2- * Copyright 2009-2010 Yuichiro Moriguchi
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-package net.morilib.predicate.parser.jp;
17-
18-/*package*/ class JPKeyword extends JPToken {
19-
20-
21- public JPKeyword(String value) {
22- super(value);
23- }
24-
25-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/prolog/src/net/morilib/predicate/parser/prolog/Prolog.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/prolog/Prolog.java (revision 6)
@@ -22,6 +22,7 @@
2222 import net.morilib.predicate.PredicateSystemException;
2323 import net.morilib.predicate.Result;
2424 import net.morilib.predicate.RuleBase;
25+import net.morilib.predicate.parser.PredicateParserException;
2526
2627 /**
2728 *
@@ -61,11 +62,17 @@
6162 line = line.substring(0, line.length() - 1);
6263 rs = parser.parseQuery(base, line);
6364 while(rs.next()) {
64- System.out.println(rs.getAll());
65+ for(String s : rs.getAll().keySet()) {
66+ System.out.print(s);
67+ System.out.print("=");
68+ System.out.println(rs.get(s));
69+ }
6570 }
6671 }
6772 } catch(PredicateSystemException e) {
6873 e.printStackTrace(System.err);
74+ } catch(PredicateParserException e) {
75+ e.printStackTrace(System.err);
6976 }
7077 System.out.print(" >");
7178 }
--- trunk/prolog/src/net/morilib/predicate/parser/prolog/PrologLexer.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/parser/prolog/PrologLexer.java (revision 6)
@@ -135,7 +135,6 @@
135135
136136 private final Object _ATMO = new Object() {
137137
138- @SuppressWarnings("unused")
139138 @Continuatable
140139 public Object execute(Rdr1 ins, String str) {
141140 return new PrologTerm._Atom(str);
@@ -145,7 +144,6 @@
145144
146145 private final Object _VARO = new Object() {
147146
148- @SuppressWarnings("unused")
149147 @Continuatable
150148 public Object execute(Rdr1 ins, String str) {
151149 variables.put(str, new Variable(str));
--- trunk/prolog/src/net/morilib/predicate/NormalTerm.java (revision 5)
+++ trunk/prolog/src/net/morilib/predicate/NormalTerm.java (revision 6)
@@ -131,7 +131,8 @@
131131
132132
133133 public String toString() {
134- return value + "/" + getArities();
134+// return value + "/" + getArities();
135+ return value + "";
135136 }
136137
137138
--- trunk/prolog/src/net/morilib/math/expr/poly/Polynomial.java (revision 5)
+++ trunk/prolog/src/net/morilib/math/expr/poly/Polynomial.java (revision 6)
@@ -38,7 +38,6 @@
3838 //
3939 private static final long serialVersionUID = -1554655061800510876L;
4040
41- @SuppressWarnings("unused")
4241 @Continuatable
4342 C execute(C x, C y) {
4443 if(x == null) {
@@ -55,7 +54,6 @@
5554 //
5655 private static final long serialVersionUID = -1554655061800510876L;
5756
58- @SuppressWarnings("unused")
5957 @Continuatable
6058 C execute(C x, C y) {
6159 if(x == null) {
@@ -182,7 +180,6 @@
182180
183181 res.coefficients = Maps.map(new Object() {
184182
185- @SuppressWarnings("unused")
186183 @Continuatable
187184 C execute(C x) {
188185 return x.multiply(y);
@@ -201,7 +198,6 @@
201198 // System.out.println("coe:" + n);
202199 res.coefficients = Maps.map(new Object() {
203200
204- @SuppressWarnings("unused")
205201 @Continuatable
206202 C execute(C x) {
207203 return x.multiply(y);
@@ -245,7 +241,6 @@
245241
246242 res.coefficients = Maps.map(new Object() {
247243
248- @SuppressWarnings("unused")
249244 @Continuatable
250245 C execute(C x) {
251246 return x.divide(y);
--- trunk/prolog/src/net/morilib/math/expr/poly/Factor.java (revision 5)
+++ trunk/prolog/src/net/morilib/math/expr/poly/Factor.java (revision 6)
@@ -91,7 +91,6 @@
9191
9292 res.orders = Maps.map(new Object() {
9393
94- @SuppressWarnings("unused")
9594 @Continuatable
9695 Integer execute(Integer x) {
9796 return x * y;
--- trunk/prolog/src/net/morilib/util/operator/OperatorPrecedence.java (revision 5)
+++ trunk/prolog/src/net/morilib/util/operator/OperatorPrecedence.java (revision 6)
@@ -79,7 +79,6 @@
7979 // this.fol = fol;
8080 }
8181
82- @SuppressWarnings("unused")
8382 @Continuatable
8483 public Object execute(
8584 Object s,
@@ -177,7 +176,6 @@
177176 _Shift sft = new _Shift(o);
178177 Object cz = new Object() {
179178
180- @SuppressWarnings("unused")
181179 @Continuatable
182180 public Object execute(T s) {
183181 return s;
--- trunk/prolog/src/net/morilib/util/cont/Continuations.java (revision 5)
+++ trunk/prolog/src/net/morilib/util/cont/Continuations.java (revision 6)
@@ -27,7 +27,6 @@
2727 //
2828 private static final long serialVersionUID = -247120899698518733L;
2929
30- @SuppressWarnings("unused")
3130 @Continuatable
3231 Integer execute(Integer x, Integer y) {
3332 if(x == null) {
@@ -45,7 +44,6 @@
4544 //
4645 private static final long serialVersionUID = -5419312055177649355L;
4746
48- @SuppressWarnings("unused")
4947 @Continuatable
5048 Integer execute(Integer x, Integer y) {
5149 if(x == null) {
旧リポジトリブラウザで表示