From: <jen...@us...> - 2011-08-26 19:33:47
|
Revision: 3134 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3134&view=rev Author: jenslehmann Date: 2011-08-26 19:33:41 +0000 (Fri, 26 Aug 2011) Log Message: ----------- implemented prefix replacement in conf files via post processing directives Modified Paths: -------------- trunk/examples/family/father.conf trunk/examples/family/father_new.conf 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/conf3.jj trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java Modified: trunk/examples/family/father.conf =================================================================== --- trunk/examples/family/father.conf 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/examples/family/father.conf 2011-08-26 19:33:41 UTC (rev 3134) @@ -15,7 +15,6 @@ // reasoner reasoner.type = "fast instance checker" reasoner.reasonerComponent = component:embeddedReasoner -reasoner.sources = {"component:ks"} embeddedReasoner.type = "org.dllearner.reasoning.OWLAPIReasoner" embeddedReasoner.sources = {"component:ks"} Modified: trunk/examples/family/father_new.conf =================================================================== --- trunk/examples/family/father_new.conf 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/examples/family/father_new.conf 2011-08-26 19:33:41 UTC (rev 3134) @@ -7,6 +7,9 @@ * Copyright (C) 2007, Jens Lehmann */ +// declare some prefixes to use as abbreviations +prefixes = [ ("kb","http://localhost/foo#") ] + // knowledge source definition ks.type = "KB file" ks.url = "father.kb" @@ -15,15 +18,14 @@ // reasoner reasoner.type = "fast instance checker" reasoner.reasonerComponent = embeddedReasoner -reasoner.sources = { ks } embeddedReasoner.type = "OWL API Reasoner" embeddedReasoner.sources = { ks } // learning problem lp.type = "posNegStandard" -lp.positiveExamples = {"http://localhost/foo#stefan","http://localhost/foo#markus","http://localhost/foo#bernd"} -lp.negativeExamples = {"http://localhost/foo#heinz","http://localhost/foo#anna","http://localhost/foo#gabi","http://localhost/foo#michelle"} +lp.positiveExamples = {"kb:stefan","kb:markus","kb:bernd"} +lp.negativeExamples = {"kb:heinz","kb:anna","kb:gabi","kb:michelle"} // plug a reasoner into the learning problem lp.reasoner = reasoner Modified: trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/cli/ConfFileOption2.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -44,6 +44,7 @@ // TODO: Do we want to store the actual value as object here or leave it up to // the corresponding PropertyEditor to create it? + @Deprecated private Object valueObject; public ConfFileOption2() { @@ -90,10 +91,12 @@ this.propertyType = propertyType; } + @Deprecated public Object getValueObject() { return valueObject; } + @Deprecated public void setValueObject(Object valueObject) { this.valueObject = valueObject; } Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/ConfParser.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -17,6 +17,9 @@ public class ConfParser implements ConfParserConstants { + // special directives (those without a property name) + private Map<String,ConfFileOption2> specialOptions = new HashMap<String,ConfFileOption2>(); + // conf file options private List<ConfFileOption2> confOptions = new LinkedList<ConfFileOption2>(); private Map<String,ConfFileOption2> confOptionsByProperty = new HashMap<String,ConfFileOption2>(); @@ -74,9 +77,15 @@ break label_1; } confOption = ConfOption(); - addConfOption(confOption); + if(confOption.getPropertyName() == null) { + specialOptions.put(confOption.getBeanName(),confOption); + } else { + addConfOption(confOption); + } } jj_consume_token(0); + PostProcessor pp = new PostProcessor(confOptions, specialOptions); + pp.applyAll(); } final public ConfFileOption2 ConfOption() throws ParseException { @@ -89,7 +98,7 @@ boolean inQuotes = false; String beanName; String propertyName = ""; - String propertyValue; + String propertyValue = ""; Class<?> propertyType; Object val = null; beanName = Id(); @@ -129,7 +138,7 @@ propertyValue = val.toString(); propertyType = Double.class; break; default: - jj_la1[6] = jj_gen; + jj_la1[2] = jj_gen; if (jj_2_4(2147483647)) { jj_consume_token(14); jj_consume_token(15); @@ -144,13 +153,13 @@ break label_2; } tmp = String(); - values.add(tmp); + values.add(tmp); propertyValue += "\u005c"" + tmp + "\u005c", "; jj_consume_token(16); } tmp = String(); - values.add(tmp); + values.add(tmp); propertyValue += "\u005c"" + tmp + "\u005c""; jj_consume_token(15); - propertyType = Set.class; propertyValue = "{ TODO }"; val = values; inQuotes = true; + propertyType = Set.class; propertyValue = "{"+ propertyValue + "}";; val = values; inQuotes = true; } else { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 14: @@ -163,16 +172,16 @@ break label_3; } tmp = Id(); - values.add(tmp); + values.add(tmp); propertyValue += tmp + ", "; jj_consume_token(16); } tmp = Id(); - values.add(tmp); + values.add(tmp); propertyValue += tmp; jj_consume_token(15); - val = values; propertyType = Set.class; propertyValue = "{ TODO }"; + val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; break; default: - jj_la1[7] = jj_gen; + jj_la1[3] = jj_gen; if (jj_2_6(2147483647)) { jj_consume_token(17); jj_consume_token(18); @@ -189,68 +198,24 @@ break label_4; } jj_consume_token(19); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp = String(); - break; - case ID: - tmp = Id(); - break; - default: - jj_la1[2] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp = String(); jj_consume_token(16); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp2 = String(); - break; - case ID: - tmp2 = Id(); - break; - default: - jj_la1[3] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp2 = String(); jj_consume_token(20); - tuples.add(new StringTuple(tmp,tmp2)); + tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c"), "; jj_consume_token(16); } jj_consume_token(19); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp = String(); - break; - case ID: - tmp = Id(); - break; - default: - jj_la1[4] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp = String(); jj_consume_token(16); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case STRING: - tmp2 = String(); - break; - case ID: - tmp2 = Id(); - break; - default: - jj_la1[5] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + tmp2 = String(); jj_consume_token(20); - tuples.add(new StringTuple(tmp,tmp2)); + tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\u005c""+ tmp + "\u005c",\u005c"" + tmp2 + "\u005c")"; jj_consume_token(18); - val = values; propertyType = List.class; + val = tuples; propertyType = List.class; propertyValue = "["+ propertyValue + "]"; break; default: - jj_la1[8] = jj_gen; + jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -258,15 +223,14 @@ } } } + option.setInQuotes(inQuotes); + option.setBeanName(beanName); if(containsSubOption) { - option.setInQuotes(inQuotes); - option.setBeanName(beanName); option.setPropertyName(propertyName); - option.setPropertyType(propertyType); - option.setValueObject(val); - } else { - // ... currently nothing here (maybe special parser directives) } + option.setPropertyType(propertyType); + option.setPropertyValue(propertyValue); + option.setValueObject(val); {if (true) return option;} throw new Error("Missing return statement in function"); } @@ -281,7 +245,7 @@ name = String(); break; default: - jj_la1[9] = jj_gen; + jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -303,7 +267,7 @@ {if (true) return t1.image;} break; default: - jj_la1[10] = jj_gen; + jj_la1[6] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -392,38 +356,6 @@ finally { jj_save(6, xla); } } - private boolean jj_3_2() { - if (jj_3R_6()) return true; - if (jj_scan_token(16)) return true; - return false; - } - - private boolean jj_3R_10() { - if (jj_3R_6()) return true; - return false; - } - - private boolean jj_3R_7() { - if (jj_3R_5()) return true; - return false; - } - - private boolean jj_3_4() { - if (jj_scan_token(14)) return true; - if (jj_scan_token(15)) return true; - return false; - } - - private boolean jj_3R_6() { - if (jj_scan_token(ID)) return true; - return false; - } - - private boolean jj_3R_8() { - if (jj_3R_6()) return true; - return false; - } - private boolean jj_3_5() { if (jj_scan_token(14)) return true; Token xsp; @@ -454,11 +386,6 @@ return false; } - private boolean jj_3R_9() { - if (jj_3R_5()) return true; - return false; - } - private boolean jj_3R_5() { if (jj_scan_token(STRING)) return true; return false; @@ -466,23 +393,31 @@ private boolean jj_3_3() { if (jj_scan_token(19)) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3R_7()) { - jj_scanpos = xsp; - if (jj_3R_8()) return true; - } + if (jj_3R_5()) return true; if (jj_scan_token(16)) return true; - xsp = jj_scanpos; - if (jj_3R_9()) { - jj_scanpos = xsp; - if (jj_3R_10()) return true; - } + if (jj_3R_5()) return true; if (jj_scan_token(20)) return true; if (jj_scan_token(16)) return true; return false; } + private boolean jj_3_2() { + if (jj_3R_6()) return true; + if (jj_scan_token(16)) return true; + return false; + } + + private boolean jj_3_4() { + if (jj_scan_token(14)) return true; + if (jj_scan_token(15)) return true; + return false; + } + + private boolean jj_3R_6() { + if (jj_scan_token(ID)) return true; + return false; + } + /** Generated Token Manager. */ public ConfParserTokenManager token_source; SimpleCharStream jj_input_stream; @@ -494,13 +429,13 @@ private Token jj_scanpos, jj_lastpos; private int jj_la; private int jj_gen; - final private int[] jj_la1 = new int[11]; + final private int[] jj_la1 = new int[7]; static private int[] jj_la1_0; static { jj_la1_init_0(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x200,0x100,0x1200,0x1200,0x1200,0x1200,0x1e00,0x4000,0x20000,0x1200,0x200,}; + jj_la1_0 = new int[] {0x200,0x100,0x1e00,0x4000,0x20000,0x1200,0x200,}; } final private JJCalls[] jj_2_rtns = new JJCalls[7]; private boolean jj_rescan = false; @@ -517,7 +452,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -532,7 +467,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -543,7 +478,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -554,7 +489,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -564,7 +499,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -574,7 +509,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 11; i++) jj_la1[i] = -1; + for (int i = 0; i < 7; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -691,7 +626,7 @@ la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 11; i++) { + for (int i = 0; i < 7; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { Added: trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/PostProcessor.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2007, 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.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.dllearner.cli.ConfFileOption2; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Performs post processing of conf files based on special parsing directives. + * + * @author Jens Lehmann + * + */ +public class PostProcessor { + + List<ConfFileOption2> confOptions; + Map<String, ConfFileOption2> directives; + + public PostProcessor(List<ConfFileOption2> confOptions, Map<String, ConfFileOption2> directives) { + this.confOptions = confOptions; + this.directives = directives; + } + + /** + * Applies all special directives by modifying the conf options. + */ + public void applyAll() { + // apply prefix directive + ConfFileOption2 prefixOption = directives.get("prefixes"); + if(prefixOption != null) { + List<StringTuple> prefixes = (List<StringTuple>) prefixOption.getValueObject(); + + // loop through all options and replaces prefixes + for(ConfFileOption2 option : confOptions) { + String value = option.getPropertyValue(); + for(StringTuple prefix : prefixes) { + // we only replace the prefix if it occurs directly after a quote + value = value.replaceAll("\"" + prefix.a + ":", "\"" + prefix.b); + } + option.setPropertyValue(value); + } + } + } +} Modified: trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/main/java/org/dllearner/confparser3/conf3.jj 2011-08-26 19:33:41 UTC (rev 3134) @@ -47,6 +47,9 @@ public class ConfParser { + // special directives (those without a property name) + private Map<String,ConfFileOption2> specialOptions = new HashMap<String,ConfFileOption2>(); + // conf file options private List<ConfFileOption2> confOptions = new LinkedList<ConfFileOption2>(); private Map<String,ConfFileOption2> confOptionsByProperty = new HashMap<String,ConfFileOption2>(); @@ -120,9 +123,16 @@ } { ( confOption = ConfOption() - { addConfOption(confOption); } + { if(confOption.getPropertyName() == null) { + specialOptions.put(confOption.getBeanName(),confOption); + } else { + addConfOption(confOption); + } + } )* <EOF> + { PostProcessor pp = new PostProcessor(confOptions, specialOptions); + pp.applyAll(); } } ConfFileOption2 ConfOption() : @@ -136,7 +146,7 @@ boolean inQuotes = false; String beanName; String propertyName = ""; - String propertyValue; + String propertyValue = ""; Class<?> propertyType; Object val = null; } @@ -158,35 +168,34 @@ // empty set | LOOKAHEAD("{" "}") "{" "}" { val = new HashSet(); propertyType = Set.class; propertyValue = "{}"; } // set with several elements which are quoted - | LOOKAHEAD(4) "{" ( LOOKAHEAD(2) tmp=String() { values.add(tmp);} "," )* - tmp=String() {values.add(tmp);} "}" - { propertyType = Set.class; propertyValue = "{ TODO }"; val = values; inQuotes = true;} + | 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;} // set with several elements which are not quoted - | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp);} "," )* - ( tmp=Id()) {values.add(tmp);} "}" - { val = values; propertyType = Set.class; propertyValue = "{ TODO }"; } + | "{" ( LOOKAHEAD(4) tmp=Id() { values.add(tmp); propertyValue += tmp + ", "; } "," )* + ( tmp=Id()) {values.add(tmp); propertyValue += tmp;} "}" + { val = values; propertyType = Set.class; propertyValue = "{"+ propertyValue + "}"; } // empty list | LOOKAHEAD("[" "]") "[" "]" { val = new LinkedList(); propertyType = List.class; propertyValue = "[]";} // a list with several elements, which tuples // e.g. [("a","b"),("c","d")] | "[" - ( LOOKAHEAD(6) "(" (tmp=String() | tmp=Id()) "," (tmp2=String() | tmp2=Id()) ")" - {tuples.add(new StringTuple(tmp,tmp2));} "," )* - "(" (tmp=String() | tmp=Id()) "," (tmp2=String() | tmp2=Id()) ")" - {tuples.add(new StringTuple(tmp,tmp2));} - "]" { val = values; propertyType = List.class;} + ( LOOKAHEAD(6) "(" tmp=String() "," tmp2=String() ")" + {tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\""+ tmp + "\",\"" + tmp2 + "\"), "; } "," )* + "(" tmp=String() "," tmp2=String() ")" + {tuples.add(new StringTuple(tmp,tmp2)); propertyValue += "(\""+ tmp + "\",\"" + tmp2 + "\")";} + "]" { val = tuples; propertyType = List.class; propertyValue = "["+ propertyValue + "]";} ) // <CONF_END> { - if(containsSubOption) { - option.setInQuotes(inQuotes); - option.setBeanName(beanName); + option.setInQuotes(inQuotes); + option.setBeanName(beanName); + if(containsSubOption) { option.setPropertyName(propertyName); - option.setPropertyType(propertyType); - option.setValueObject(val); - } else { - // ... currently nothing here (maybe special parser directives) } + option.setPropertyType(propertyType); + option.setPropertyValue(propertyValue); + option.setValueObject(val); return option; } } Modified: trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-26 18:22:14 UTC (rev 3133) +++ trunk/interfaces/src/test/java/org/dllearner/confparser3/ParseTest.java 2011-08-26 19:33:41 UTC (rev 3134) @@ -15,7 +15,7 @@ public void test() throws FileNotFoundException, ParseException { ConfParser parser = ConfParser.parseFile(new File("../examples/family/father_new.conf")); for(ConfFileOption2 option : parser.getConfOptions()) { - System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getValueObject()); + System.out.print(option.getBeanName() + "." + option.getPropertyName() + " = " + option.getPropertyValue()); if((option.getPropertyType().equals(String.class) || option.getPropertyType().equals(Set.class)) && !option.isInQuotes()) { System.out.println(" (bean reference)"); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |