From: <jen...@us...> - 2011-08-27 09:55:23
|
Revision: 3137 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3137&view=rev Author: jenslehmann Date: 2011-08-27 09:55:16 +0000 (Sat, 27 Aug 2011) Log Message: ----------- added beanref-flag in ConfFileOption2; introduced special notation for empty bean set (probably very rarely needed) Modified Paths: -------------- trunk/interfaces/doc/manual/manual.tex trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java Modified: trunk/interfaces/doc/manual/manual.tex =================================================================== --- trunk/interfaces/doc/manual/manual.tex 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/doc/manual/manual.tex 2011-08-27 09:55:16 UTC (rev 3137) @@ -201,6 +201,10 @@ \section{DL-Learner Interfaces} +\subsection{Command Line Interface} + +\todo{Description of Conf File Syntax; special cases: empty set of beans is denoted by ``-''; the name of a bean must not be ``true'' or ``false'' or start with a number; config options must not have the name ``type''; these conentions are introduced in order to be a able to provide a very compact syntax} + One interface you have already used in Section \ref{sec:start} is the command line. There are two executables, which can be used for starting DL-Learner on the commandline: \verb|dl-learner| and \verb|quickstart|. The first one takes a conf file as argument, whereas the latter one lists all conf files in the examples folder and allows you to select one of those. \begin{figure} Modified: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-27 09:55:16 UTC (rev 3137) @@ -31,10 +31,8 @@ */ public class ConfFileOption2 { - // a boolean flag which indicates whether the value was in quotes - // TODO: alternatively, we could use a flag "isBeanReferrence" - bean references are (currently) - // those options which do not have quotes, but have type "String" or "Set" - private boolean inQuotes; + // a boolean flag which indicates whether it is a reference to a bean (or set/list of beans) + private boolean isBeanRef; private String beanName; @@ -54,14 +52,6 @@ } - public boolean isInQuotes() { - return inQuotes; - } - - public void setInQuotes(boolean inQuotes) { - this.inQuotes = inQuotes; - } - public String getBeanName() { return beanName; } @@ -103,5 +93,13 @@ public void setValueObject(Object valueObject) { this.valueObject = valueObject; } + + public boolean isBeanRef() { + return isBeanRef; + } + + public void setBeanRef(boolean isBeanRef) { + this.isBeanRef = isBeanRef; + } } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-27 09:55:16 UTC (rev 3137) @@ -95,7 +95,7 @@ List<StringTuple> tuples = new LinkedList<StringTuple>(); ConfFileOption2 option = new ConfFileOption2(); - boolean inQuotes = false; + boolean isBeanRef = false; String beanName; String propertyName = ""; String propertyValue = ""; @@ -122,12 +122,12 @@ if(propertyValue.equals("true") || propertyValue.equals("false")) { val = Boolean.valueOf(propertyValue); propertyType = Boolean.class; } else { - val = propertyValue; propertyType = String.class; + val = propertyValue; propertyType = String.class; isBeanRef = true; } break; case STRING: propertyValue = String(); - val = propertyValue; inQuotes = true; propertyType = String.class; + val = propertyValue; propertyType = String.class; break; case NUMBER: val = Integer(); @@ -159,9 +159,13 @@ tmp = String(); values.add(tmp); propertyValue += "\u005c"" + tmp + "\u005c""; jj_consume_token(15); - propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; inQuotes = true; + propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 17: + jj_consume_token(17); + val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanRef = true; + break; case 14: jj_consume_token(14); label_3: @@ -178,18 +182,18 @@ tmp = Id(); values.add(tmp); propertyValue += tmp; jj_consume_token(15); - val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; + val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanRef = true; break; default: jj_la1[3] = jj_gen; if (jj_2_6(2147483647)) { - jj_consume_token(17); jj_consume_token(18); + jj_consume_token(19); val = new LinkedList(); propertyType = List.class; propertyValue = "[]"; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case 17: - jj_consume_token(17); + case 18: + jj_consume_token(18); label_4: while (true) { if (jj_2_3(6)) { @@ -197,21 +201,21 @@ } else { break label_4; } - jj_consume_token(19); + jj_consume_token(20); tmp = String(); jj_consume_token(16); tmp2 = String(); - jj_consume_token(20); + jj_consume_token(21); tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c"), "; jj_consume_token(16); } - jj_consume_token(19); + jj_consume_token(20); tmp = String(); jj_consume_token(16); tmp2 = String(); - jj_consume_token(20); + jj_consume_token(21); tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c")"; - jj_consume_token(18); + jj_consume_token(19); val = tuples; propertyType = List.class; propertyValue = "["+ propertyValue + "]"; break; default: @@ -223,7 +227,7 @@ } } } - option.setInQuotes(inQuotes); + option.setBeanRef(isBeanRef); option.setBeanName(beanName); if(containsSubOption) { option.setPropertyName(propertyName); @@ -257,7 +261,7 @@ Token t1,t2; if (jj_2_7(2)) { t1 = jj_consume_token(ID); - jj_consume_token(21); + jj_consume_token(22); t2 = jj_consume_token(ID); {if (true) return t1.image + ":" + t2.image;} } else { @@ -375,32 +379,32 @@ } private boolean jj_3_6() { - if (jj_scan_token(17)) return true; if (jj_scan_token(18)) return true; + if (jj_scan_token(19)) return true; return false; } private boolean jj_3_7() { if (jj_scan_token(ID)) return true; - if (jj_scan_token(21)) return true; + if (jj_scan_token(22)) return true; return false; } - private boolean jj_3R_5() { - if (jj_scan_token(STRING)) return true; - return false; - } - private boolean jj_3_3() { - if (jj_scan_token(19)) return true; + if (jj_scan_token(20)) return true; if (jj_3R_5()) return true; if (jj_scan_token(16)) return true; if (jj_3R_5()) return true; - if (jj_scan_token(20)) return true; + if (jj_scan_token(21)) return true; if (jj_scan_token(16)) return true; return false; } + private boolean jj_3R_5() { + if (jj_scan_token(STRING)) return true; + return false; + } + private boolean jj_3_2() { if (jj_3R_6()) return true; if (jj_scan_token(16)) return true; @@ -435,7 +439,7 @@ jj_la1_init_0(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x200,0x100,0x1e00,0x4000,0x20000,0x1200,0x200,}; + jj_la1_0 = new int[] {0x200,0x100,0x1e00,0x24000,0x40000,0x1200,0x200,}; } final private JJCalls[] jj_2_rtns = new JJCalls[7]; private boolean jj_rescan = false; @@ -621,7 +625,7 @@ /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[22]; + boolean[] la1tokens = new boolean[23]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -635,7 +639,7 @@ } } } - for (int i = 0; i < 22; i++) { + for (int i = 0; i < 23; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserConstants.java 2011-08-27 09:55:16 UTC (rev 3137) @@ -49,6 +49,7 @@ "\"{\"", "\"}\"", "\",\"", + "\"-\"", "\"[\"", "\"]\"", "\"(\"", Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParserTokenManager.java 2011-08-27 09:55:16 UTC (rev 3137) @@ -44,21 +44,23 @@ switch(curChar) { case 40: - return jjStopAtPos(0, 19); + return jjStopAtPos(0, 20); case 41: - return jjStopAtPos(0, 20); + return jjStopAtPos(0, 21); case 44: return jjStopAtPos(0, 16); + case 45: + return jjStopAtPos(0, 17); case 46: return jjStopAtPos(0, 8); case 58: - return jjStopAtPos(0, 21); + return jjStopAtPos(0, 22); case 61: return jjStopAtPos(0, 13); case 91: - return jjStopAtPos(0, 17); + return jjStopAtPos(0, 18); case 93: - return jjStopAtPos(0, 18); + return jjStopAtPos(0, 19); case 123: return jjStopAtPos(0, 14); case 125: @@ -349,14 +351,14 @@ /** Token literal values. */ public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, null, "\56", null, null, null, null, -"\75", "\173", "\175", "\54", "\133", "\135", "\50", "\51", "\72", }; +"\75", "\173", "\175", "\54", "\55", "\133", "\135", "\50", "\51", "\72", }; /** Lexer state names. */ public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0x3fff01L, + 0x7fff01L, }; static final long[] jjtoSkip = { 0xfeL, Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-27 09:55:16 UTC (rev 3137) @@ -143,7 +143,7 @@ List<StringTuple> tuples = new LinkedList<StringTuple>(); ConfFileOption2 option = new ConfFileOption2(); - boolean inQuotes = false; + boolean isBeanRef = false; String beanName; String propertyName = ""; String propertyValue = ""; @@ -159,10 +159,10 @@ if(propertyValue.equals("true") || propertyValue.equals("false")) { val = Boolean.valueOf(propertyValue); propertyType = Boolean.class; } else { - val = propertyValue; propertyType = String.class; + val = propertyValue; propertyType = String.class; isBeanRef = true; } } // simple string enclosed in quotes - | propertyValue = String() { val = propertyValue; inQuotes = true; propertyType = String.class; } + | propertyValue = String() { val = propertyValue; propertyType = String.class; } | val = Integer() { propertyValue = val.toString(); propertyType = Integer.class;} | val = Double() { propertyValue = val.toString(); propertyType = Double.class; } // empty set @@ -170,11 +170,13 @@ // set with several elements which are quoted | LOOKAHEAD(4) "{" ( LOOKAHEAD(2) tmp=String() { values.add(tmp); propertyValue += "\"" + tmp + "\", ";} "," )* tmp=String() {values.add(tmp); propertyValue += "\"" + tmp + "\"";} "}" - { propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; inQuotes = true;} + { propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; } + // empty bean set + | "-" { val = new HashSet(); propertyType = Set.class; propertyValue = "-"; isBeanRef = true;} // set with several elements which are not quoted | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp); propertyValue += tmp + ", "; } "," )* ( tmp=Id()) {values.add(tmp); propertyValue += tmp;} "}" - { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; } + { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; isBeanRef = true;} // empty list | LOOKAHEAD("[" "]") "[" "]" { val = new LinkedList(); propertyType = List.class; propertyValue = "[]";} // a list with several elements, which tuples @@ -188,7 +190,7 @@ ) // <CONF_END> { - option.setInQuotes(inQuotes); + option.setBeanRef(isBeanRef); option.setBeanName(beanName); if(containsSubOption) { option.setPropertyName(propertyName); Modified: trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-26 20:22:41 UTC (rev 3136) +++ trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-27 09:55:16 UTC (rev 3137) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ package org.dllearner.confparser3; import java.io.File; @@ -2,9 +21,12 @@ import java.io.FileNotFoundException; -import java.util.Set; import org.dllearner.cli.ConfFileOption2; -import org.dllearner.confparser3.ConfParser; -import org.dllearner.confparser3.ParseException; import org.junit.Test; +/** + * Conf parser tests. + * + * @author Jens Lehmann + * + */ public class ParseTest { @@ -16,7 +38,7 @@ ConfParser parser = ConfParser.parseFile(new File("../examples/family/father_new.conf")); for(ConfFileOption2 option : parser.getConfOptions()) { System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getPropertyValue()); - if((option.getPropertyType().equals(String.class) || option.getPropertyType().equals(Set.class)) && !option.isInQuotes()) { + if(option.isBeanRef()) { System.out.println(" (bean reference)"); } else { System.out.println(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |