You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <chr...@us...> - 2012-06-11 19:02:05
|
Revision: 3733 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3733&view=rev Author: christinaunger Date: 2012-06-11 19:01:59 +0000 (Mon, 11 Jun 2012) Log Message: ----------- [tbsl] minor corrections and extensions in lexicon and template refinement Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2012-06-11 17:06:18 UTC (rev 3732) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2012-06-11 19:01:59 UTC (rev 3733) @@ -56,11 +56,23 @@ } for (String arg : args) { for (Slot s : argslots) { - if (s.anchor.equals("SLOT_arg") && s.words.contains(arg.replace("?",""))) { + if (s.words.contains(arg.replace("?",""))) { if (s.type.equals(SlotType.LITERAL)) slot.type = SlotType.DATATYPEPROPERTY; else if (s.type.equals(SlotType.RESOURCE)) slot.type = SlotType.OBJECTPROPERTY; } } + if (slot.type.equals(SlotType.PROPERTY) || slot.type.equals(SlotType.SYMPROPERTY)) { // still + Set<String> values = new HashSet<String>(); + for (SPARQL_Triple triple : query.conditions) { + if (triple.property.toString().equals("?"+slot.anchor)) values.add(triple.value.toString()); + } + for (SPARQL_Triple triple : query.conditions) { + for (String val : values) { + if (triple.variable.toString().equals(val) && triple.property.toString().equals("rdf:type")) + slot.type = SlotType.OBJECTPROPERTY; + } + } + } } } } Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-06-11 17:06:18 UTC (rev 3732) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-06-11 19:01:59 UTC (rev 3733) @@ -2,7 +2,7 @@ // PREPOSITIONS close to || (NP NP* (PP P:'close' P:'to' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_closeto(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_closeto/OBJECTPROPERTY/near ]> - in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location ]> + in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location^city^postal_code ]> since || (NP NP* (PP P:'since' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_since(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_since/PROPERTY/since ]> for . pounds || (NP NP* (PP P:'for' (NP NUM[num] N:'pounds'))) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y) ] ], [ (l2,y,num,e) ], [ l2=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> @@ -12,9 +12,9 @@ with || (NP NP* (PP P:'with' DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[]> with || (NP NP* (PP P:'with' NUM[num] DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y), count(y,z) ] ], [ (l2,y,dp,<<e,t>,t>),(l3,z,num,e) ], [ l2=l1,l3=l1 ],[ SLOT_arg/RESOURCE/y ]> - with || (NP NP* (PP P:'with' NUM[num] DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y), equals(y,z) ] ], [ (l2,y,dp,<<e,t>,t>),(l3,z,num,e) ], [ l2=l1,l3=l1 ],[ SLOT_arg/LITERAL/y ]> + with || (NP NP* (PP P:'with' NUM[num] DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y), equal(y,z) ] ], [ (l2,y,dp,<<e,t>,t>),(l3,z,num,e) ], [ l2=l1,l3=l1 ],[ SLOT_arg/LITERAL/y ]> + square meters || (DP N:'square' N:'meters') || <x,l1,<<e,t>,t>>, [l1:[ | SLOT_size(x,y) ]], [],[],[SLOT_size/DATATYPEPROPERTY/size ]> - // MONTHS january || (DP DP:'january') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,1) ]], [],[],[]> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-06-11 17:06:29
|
Revision: 3732 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3732&view=rev Author: christinaunger Date: 2012-06-11 17:06:18 +0000 (Mon, 11 Jun 2012) Log Message: ----------- [tbsl] differentiated object and datatype properties, and filtered templates inconsistent with those requirements Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/data/Dude.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SlotType.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/TemplatorHandler.java trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java Added Paths: ----------- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -76,7 +76,7 @@ } template = new Template(new Query()); - // slots = ls; + slots = ls; Query q = convert(drs, new Query(), false); if (q == null) { @@ -127,6 +127,8 @@ } } + for (Slot s : slots) if (s.getAnchor().equals("SLOT_arg")) template.addSlot(s); + Set<SPARQL_Triple> statements = new HashSet<SPARQL_Triple>(); for (DRS_Condition condition : drs.getConditions()) { @@ -242,7 +244,7 @@ } } SPARQL_Property prop = new SPARQL_Property(predicate); - prop.setIsVariable(true); + if (!predicate.contains(":")) prop.setIsVariable(true); boolean literal = false; if (simple.getArguments().size() > 1 && simple.getArguments().get(1).getValue().matches("\\d+")) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/GrammarFilter.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -131,12 +131,18 @@ */ try { - TreeNode tree = c.construct("NUM:'" + token + "'"); + TreeNode tree = c.construct("NUM:'" + token + "'"); + TreeNode tree2 = c.construct("(NP NUM:'" + token + "' NP*)"); int gid = grammar.addTree(grammar.size(), new Pair<String,TreeNode>(token,tree), - Collections.singletonList("<x,l1,e,[l1:[ x | equal(x," + token + ")]],[],[],[]>")); + Collections.singletonList("<x,l1,e,[l1:[ x | equal(x," + token + ")]],[],[],[ SLOT_arg/LITERAL/x ]>")); add(parseG, tree, gid-1, localID); localID++; + +// int gid = grammar.addTree(grammar.size(), new Pair<String,TreeNode>(token,tree2), +// Collections.singletonList("<x,l1,<e,t>,[l1:[ | count(x," + token + ")]],[],[],[ SLOT_arg/RESOURCE/x ]>")); +// add(parseG, tree2, gid-1, localID); +// localID++; foundCandidates = true; coveredTokens.add(token); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/data/Dude.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/data/Dude.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/data/Dude.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -1,11 +1,11 @@ package org.dllearner.algorithm.tbsl.sem.dudes.data; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.dllearner.algorithm.tbsl.sem.drs.DRS; +import org.dllearner.algorithm.tbsl.sem.drs.DiscourseReferent; import org.dllearner.algorithm.tbsl.sem.drs.Simple_DRS_Condition; import org.dllearner.algorithm.tbsl.sem.util.DomType; import org.dllearner.algorithm.tbsl.sem.util.DominanceConstraint; @@ -14,6 +14,7 @@ import org.dllearner.algorithm.tbsl.sem.util.Type; import org.dllearner.algorithm.tbsl.sparql.BasicSlot; import org.dllearner.algorithm.tbsl.sparql.Slot; +import org.dllearner.algorithm.tbsl.sparql.SlotType; public class Dude implements SemanticRepresentation{ @@ -156,9 +157,9 @@ output.components.addAll(input.components); output.dominanceConstraints.addAll(input.dominanceConstraints); output.arguments.remove(argument); - output.arguments.addAll(dude.arguments); - output.slots.addAll(input.slots); - + output.arguments.addAll(dude.arguments); + output.slots.addAll(input.slots); + return output; } @@ -177,7 +178,7 @@ output.components.addAll(input.components); output.dominanceConstraints.addAll(input.dominanceConstraints); output.arguments.addAll(input.arguments); - output.slots.addAll(input.slots); + output.slots.addAll(input.slots); // finally add a constraint to link the main input-component to the bottom output-component (with DomType.equal) DominanceConstraint newConstraint = new DominanceConstraint(getBottomLabel(output),input.mainLabel); @@ -359,6 +360,9 @@ } for (Slot slot : slots) { slot.replaceReferent(ref1.replace("?",""),ref2.replace("?","")); + String minus = null; + for (String w : slot.getWords()) if (w.equals(ref1.replace("?",""))) minus = w; + if (minus != null) { slot.getWords().remove(minus); slot.getWords().add(ref2.replace("?","")); } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -491,8 +491,11 @@ } if (type.toString().equals("CLASS")) { slottype = SlotType.CLASS; } else if (type.toString().equals("RESOURCE")) { slottype = SlotType.RESOURCE; } + else if (type.toString().equals("DATATYPEPROPERTY")) { slottype = SlotType.DATATYPEPROPERTY; } + else if (type.toString().equals("OBJECTPROPERTY")) { slottype = SlotType.OBJECTPROPERTY; } else if (type.toString().equals("PROPERTY")) { slottype = SlotType.PROPERTY; } else if (type.toString().equals("SYMPROPERTY")) { slottype = SlotType.SYMPROPERTY; } + else if (type.toString().equals("LITERAL")) { slottype = SlotType.LITERAL; } else { slottype = SlotType.UNSPEC; } {if (true) return new Slot(ref.toString(),slottype,words);} @@ -827,6 +830,14 @@ finally { jj_save(39, xla); } } + private boolean jj_3R_13() { + if (jj_3R_7()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3_36()) jj_scanpos = xsp; + return false; + } + private boolean jj_3_12() { if (jj_scan_token(2)) return true; if (jj_3R_1()) return true; @@ -838,14 +849,6 @@ return false; } - private boolean jj_3R_13() { - if (jj_3R_7()) return true; - Token xsp; - xsp = jj_scanpos; - if (jj_3_36()) jj_scanpos = xsp; - return false; - } - private boolean jj_3_11() { if (jj_scan_token(2)) return true; if (jj_3R_3()) return true; @@ -883,20 +886,14 @@ return false; } - private boolean jj_3R_11() { - if (jj_scan_token(LABEL)) return true; - if (jj_scan_token(11)) return true; - return false; - } - private boolean jj_3_40() { if (jj_scan_token(B)) return true; return false; } - private boolean jj_3R_16() { - if (jj_3R_7()) return true; - if (jj_scan_token(14)) return true; + private boolean jj_3R_11() { + if (jj_scan_token(LABEL)) return true; + if (jj_scan_token(11)) return true; return false; } @@ -905,8 +902,9 @@ return false; } - private boolean jj_3_23() { - if (jj_scan_token(MOST)) return true; + private boolean jj_3R_16() { + if (jj_3R_7()) return true; + if (jj_scan_token(14)) return true; return false; } @@ -915,12 +913,6 @@ return false; } - private boolean jj_3_30() { - if (jj_3R_10()) return true; - if (jj_scan_token(6)) return true; - return false; - } - private boolean jj_3R_7() { Token xsp; xsp = jj_scanpos; @@ -931,9 +923,8 @@ return false; } - private boolean jj_3_34() { - if (jj_scan_token(2)) return true; - if (jj_3R_4()) return true; + private boolean jj_3_23() { + if (jj_scan_token(MOST)) return true; return false; } @@ -942,6 +933,12 @@ return false; } + private boolean jj_3_30() { + if (jj_3R_10()) return true; + if (jj_scan_token(6)) return true; + return false; + } + private boolean jj_3R_10() { Token xsp; xsp = jj_scanpos; @@ -952,6 +949,12 @@ return false; } + private boolean jj_3_34() { + if (jj_scan_token(2)) return true; + if (jj_3R_4()) return true; + return false; + } + private boolean jj_3R_3() { if (jj_3R_15()) return true; return false; @@ -1110,6 +1113,12 @@ return false; } + private boolean jj_3_36() { + if (jj_scan_token(15)) return true; + if (jj_3R_13()) return true; + return false; + } + private boolean jj_3_25() { if (jj_scan_token(THELEAST)) return true; return false; @@ -1126,12 +1135,6 @@ return false; } - private boolean jj_3_36() { - if (jj_scan_token(15)) return true; - if (jj_3R_13()) return true; - return false; - } - private boolean jj_3_18() { if (jj_scan_token(2)) return true; if (jj_3R_8()) return true; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-06-11 17:06:18 UTC (rev 3732) @@ -451,8 +451,11 @@ } if (type.toString().equals("CLASS")) { slottype = SlotType.CLASS; } else if (type.toString().equals("RESOURCE")) { slottype = SlotType.RESOURCE; } + else if (type.toString().equals("DATATYPEPROPERTY")) { slottype = SlotType.DATATYPEPROPERTY; } + else if (type.toString().equals("OBJECTPROPERTY")) { slottype = SlotType.OBJECTPROPERTY; } else if (type.toString().equals("PROPERTY")) { slottype = SlotType.PROPERTY; } else if (type.toString().equals("SYMPROPERTY")) { slottype = SlotType.SYMPROPERTY; } + else if (type.toString().equals("LITERAL")) { slottype = SlotType.LITERAL; } else { slottype = SlotType.UNSPEC; } return new Slot(ref.toString(),slottype,words); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SlotType.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SlotType.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SlotType.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.sparql; public enum SlotType { - CLASS, PROPERTY, SYMPROPERTY, RESOURCE, LITERAL, UNSPEC + RESOURCE, CLASS, OBJECTPROPERTY, DATATYPEPROPERTY, PROPERTY, LITERAL, UNSPEC, + SYMPROPERTY // TODO don't use them anymore } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Template.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -2,7 +2,9 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class Template implements Serializable, Comparable<Template>{ @@ -27,6 +29,47 @@ public void addSlot(Slot s) { slots.add(s); } + + public Template checkandrefine() { + + Set<Slot> argslots = new HashSet<Slot>(); + for (Slot slot : slots) if (slot.anchor.equals("SLOT_arg")) argslots.add(slot); + + for (Slot slot : slots) { + // check for clashes + if (slot.type.equals(SlotType.CLASS)) { + for (SPARQL_Triple triple : query.conditions) { + if (triple.property.toString().equals("rdf:type") && triple.value.toString().equals("?"+slot.anchor)) { + for (Slot s : argslots) { + if (s.words.contains(triple.variable.toString().replace("?","")) && s.type.equals(SlotType.LITERAL)) + return null; + } + } + } + } + // refine property if possible + if (slot.type.equals(SlotType.PROPERTY) || slot.type.equals(SlotType.SYMPROPERTY)) { + Set<String> args = new HashSet<String>(); + for (SPARQL_Triple triple : query.conditions) { + if (triple.property.toString().equals("?"+slot.anchor)) + args.add(triple.value.toString()); + } + for (String arg : args) { + for (Slot s : argslots) { + if (s.anchor.equals("SLOT_arg") && s.words.contains(arg.replace("?",""))) { + if (s.type.equals(SlotType.LITERAL)) slot.type = SlotType.DATATYPEPROPERTY; + else if (s.type.equals(SlotType.RESOURCE)) slot.type = SlotType.OBJECTPROPERTY; + } + } + } + } + } + + // finally remove all argslots + slots.removeAll(argslots); + + return this; + } public String toString() { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -39,15 +39,16 @@ public boolean UNTAGGED_INPUT = true; public BasicTemplator() { - List<InputStream> grammarFiles = new ArrayList<InputStream>(); - for(int i = 0; i < GRAMMAR_FILES.length; i++){ - grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); - } + + List<InputStream> grammarFiles = new ArrayList<InputStream>(); + for(int i = 0; i < GRAMMAR_FILES.length; i++){ + grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); + } - g = LTAG_Constructor.construct(grammarFiles); + g = LTAG_Constructor.construct(grammarFiles); - tagger = new StanfordPartOfSpeechTagger(); -// tagger = new ApachePartOfSpeechTagger(); + tagger = new StanfordPartOfSpeechTagger(); +// tagger = new ApachePartOfSpeechTagger(); p = new Parser(); p.SHOW_GRAMMAR = true; @@ -61,6 +62,14 @@ d2s = new DRS2BasicSPARQL_Converter(); } + public void setGrammarFiles(String[] files) { + GRAMMAR_FILES = files; + List<InputStream> grammarFiles = new ArrayList<InputStream>(); + for(int i = 0; i < GRAMMAR_FILES.length; i++){ + grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); + } + } + public void setUNTAGGED_INPUT(boolean b) { UNTAGGED_INPUT = b; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/SlotBuilder.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -299,15 +299,15 @@ result.add(wasGerEntry); } else if (pos.equals("WHEN")) { - String dateSlot = "SLOT_" + token + "/PROPERTY/" + token +"^" + token + "_date"; - String tokenSlot = "SLOT_" + token + "/PROPERTY/" + token; + String dateSlot = "SLOT_" + token + "/DATATYPEPROPERTY/" + token +"^" + token + "_date"; + String tokenSlot = "SLOT_" + token + "/DATATYPEPROPERTY/" + token; String[] whenEntry1 = {token, "(S DP[subj] (VP V:'" + token + "'))", "<x,l1,t,[ l1:[ ?y | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>)],[ l2=l1 ],[ " + dateSlot + " ]>"}; String[] whenEntry2 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", "<x,l1,t,[ l1:[|], l4:[ ?z | SLOT_" + token + "(x,y), SLOT_date(x,z) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ]," + - "[" + tokenSlot + ", SLOT_date/PROPERTY/date ]>"}; + "[" + tokenSlot + ", SLOT_date/DATATYPEPROPERTY/date ]>"}; result.add(whenEntry1); result.add(whenEntry2); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -33,7 +33,7 @@ private static final Logger logger = Logger.getLogger(Templator.class); - String[] GRAMMAR_FILES = {"tbsl/lexicon/english.lex"}; + String[] GRAMMAR_FILES = {"tbsl/lexicon/english.lex","tbsl/lexicon/english_oxford.lex"}; private String[] noun = {"NN","NNS","NNP","NNPS","NPREP","JJNN","JJNPREP"}; private String[] adjective = {"JJ","JJR","JJS","JJH"}; @@ -67,16 +67,16 @@ } public Templator(final PartOfSpeechTagger tagger, WordNet wordnet) { - this.tagger = tagger; - this.wordnet = wordnet; + this.tagger = tagger; + this.wordnet = wordnet; + + List<InputStream> grammarFiles = new ArrayList<InputStream>(); + for(int i = 0; i < GRAMMAR_FILES.length; i++){ + grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); + } - List<InputStream> grammarFiles = new ArrayList<InputStream>(); - for(int i = 0; i < GRAMMAR_FILES.length; i++){ - grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); - } + g = LTAG_Constructor.construct(grammarFiles); - g = LTAG_Constructor.construct(grammarFiles); - p = new Parser(); p.SHOW_GRAMMAR = true; p.USE_DPS_AS_INITTREES = true; @@ -87,16 +87,16 @@ } public Templator(boolean b) { - this.tagger = new StanfordPartOfSpeechTagger(); - this.USE_WORDNET = false; - VERBOSE = b; + this.tagger = new StanfordPartOfSpeechTagger(); + this.USE_WORDNET = false; + VERBOSE = b; - List<InputStream> grammarFiles = new ArrayList<InputStream>(); - for(int i = 0; i < GRAMMAR_FILES.length; i++){ - grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); - } + List<InputStream> grammarFiles = new ArrayList<InputStream>(); + for(int i = 0; i < GRAMMAR_FILES.length; i++){ + grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); + } - g = LTAG_Constructor.construct(grammarFiles); + g = LTAG_Constructor.construct(grammarFiles); p = new Parser(); p.SHOW_GRAMMAR = false; @@ -119,7 +119,12 @@ VERBOSE = b; } public void setGrammarFiles(String[] gf) { - GRAMMAR_FILES = gf; + GRAMMAR_FILES = gf; + List<InputStream> grammarFiles = new ArrayList<InputStream>(); + for(int i = 0; i < GRAMMAR_FILES.length; i++){ + grammarFiles.add(this.getClass().getClassLoader().getResourceAsStream(GRAMMAR_FILES[i])); + } + g = LTAG_Constructor.construct(grammarFiles); } public Set<Template> buildTemplates(String s) { @@ -196,6 +201,7 @@ try { Template temp = d2s.convert(drs,slots); + temp = temp.checkandrefine(); if (temp == null) { continue; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/TemplatorHandler.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/TemplatorHandler.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/TemplatorHandler.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -7,20 +7,16 @@ public class TemplatorHandler { - static String[] GRAMMAR_FILES; Templator templator; BasicTemplator basictemplator; public TemplatorHandler(String[] files) { templator = new Templator(); basictemplator = new BasicTemplator(); - GRAMMAR_FILES = files; + templator.setGrammarFiles(files); + basictemplator.setGrammarFiles(files); } - public void setGRAMMAR_FILES(String[] g) { - GRAMMAR_FILES = g; - } - public Set<Template> buildTemplates(String s) { return templator.buildTemplates(s); } Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-06-11 17:06:18 UTC (rev 3732) @@ -75,8 +75,8 @@ least || (ADJ DET:'least' ADJ*) || <x,l1,<e,t>,[ l1:[ | minimum(a,x,x) ] ], [],[],[]> - how many || (DET DET:'how' DET:'many') || <x,l1,e, [ l1:[ ?x | ] ], [],[],[]> - how many || (DET DET:'how' DET:'many') || <x,l1,e, [ l1:[ ?c,x | count(a,x,c) ] ], [],[],[]> + how many || (DET DET:'how' DET:'many') || <x,l1,e, [ l1:[ ?x | ] ], [],[],[ SLOT_arg/DATATYPEPROPERTY/x ]> + how many || (DET DET:'how' DET:'many') || <x,l1,e, [ l1:[ ?c,x | count(a,x,c) ] ], [],[],[ SLOT_arg/OBJECTPROPERTY_CLASS/x ]> a || (DET DET:'a') || <x,l1,e, [ l1:[ x |] ], [],[],[]> an || (DET DET:'an') || <x,l1,e, [ l1:[ x |] ], [],[],[]> which || (DET DET:'which') || <x,l1,e, [ l1:[ ?x |] ], [],[],[]> @@ -85,11 +85,11 @@ the least || (DET DET:'the' DET:'least') || <y, l1, e, [ l1:[ | l2:[ y | ] THELEAST y l3:[|] ] ], [], [],[]> // NECESSARY "CHEAT" - highest || (NP ADJ:'highest' NP*) || <x, l1, e, [ l1:[ | maximum(x) ] ], [], [],[]> ;; <x, l1, e, [ l1:[ j | SLOT_high(x,j), maximum(j) ] ],[],[],[ SLOT_high/PROPERTY/height ]> + highest || (NP ADJ:'highest' NP*) || <x, l1, e, [ l1:[ | maximum(x) ] ], [], [],[]> ;; <x, l1, e, [ l1:[ j | SLOT_high(x,j), maximum(j) ] ],[],[],[ SLOT_high/DATATYPEPROPERTY/height ]> // COUNT - more than || (DP DET:'more' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count(y,c), greater(c,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> ;; <y,l1,<<e,t>,t>,[ l1:[ y | greater(y,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> - less than || (DP DET:'less' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count(y,c), less(c,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> ;; <y,l1,<<e,t>,t>,[ l1:[ y | less(y,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[]> + more than || (DP DET:'more' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count(y,c), greater(c,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[ SLOT_arg/RESOURCE/y ]> ;; <y,l1,<<e,t>,t>,[ l1:[ y | greater(y,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[ SLOT_arg/LITERAL/y ]> + less than || (DP DET:'less' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count(y,c), less(c,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[ SLOT_arg/RESOURCE/y ]> ;; <y,l1,<<e,t>,t>,[ l1:[ y | less(y,z) ] ],[(l2,y,np,<e,t>),(l3,z,num,e)],[l2=l1,l3=l1],[ SLOT_arg/LITERAL/y ]> // HOW // how || (DP DET:'how' ADJ[adj]) || <x,l1,<<e,t>,t>,[ l1:[?x,|] ],[ (x,l2,adj,<e,t>) ],[l2=l1],[]> @@ -115,7 +115,7 @@ what || (DP WH:'what') || <x, l1, <<e,t>,t>, [ l1:[ ?x | ] ], [], [], []> which || (DP WH:'which') || <x, l1, <<e,t>,t>, [ l1:[ ?x | ] ], [], [], []> - how many || (DP WH:'how' ADJ:'many' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] HOWMANY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + how many || (DP WH:'how' ADJ:'many' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] HOWMANY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[ SLOT_arg/RESOURCE/y ]> who || (DP WH:'who') || <x, l1, <<e,t>,t>, [ l1:[ ?x | ] ], [], [], []> whom || (DP WH:'whom') || <x, l1, <<e,t>,t>, [ l1:[ ?x | ] ], [], [], []> when || (S WH:'when' S[s]) || <x, l1, t, [ l1:[ ?x | SLOT_p(y,x) ] ], [(l2,y,s,t)], [l2=l1], [ SLOT_p/PROPERTY/date ]> @@ -162,24 +162,25 @@ // NUMBERS (1-10) // --------------------- - one || (NP NUM:'one' NP*) || <x,l1,<e,t>,[l1:[x|count(x,1)]],[],[],[]> - two || (NP NUM:'two' NP*) || <x,l1,<e,t>,[l1:[x|count(x,2)]],[],[],[]> - three || (NP NUM:'three' NP*) || <x,l1,<e,t>,[l1:[x|count(x,3)]],[],[],[]> - four || (NP NUM:'four' NP*) || <x,l1,<e,t>,[l1:[x|count(x,4)]],[],[],[]> - five || (NP NUM:'five' NP*) || <x,l1,<e,t>,[l1:[x|count(x,5)]],[],[],[]> - six || (NP NUM:'six' NP*) || <x,l1,<e,t>,[l1:[x|count(x,6)]],[],[],[]> - seven || (NP NUM:'seven' NP*) || <x,l1,<e,t>,[l1:[x|count(x,7)]],[],[],[]> - eight || (NP NUM:'eight' NP*) || <x,l1,<e,t>,[l1:[x|count(x,8)]],[],[],[]> - nine || (NP NUM:'nine' NP*) || <x,l1,<e,t>,[l1:[x|count(x,9)]],[],[],[]> - ten || (NP NUM:'ten' NP*) || <x,l1,<e,t>,[l1:[x|count(x,10)]],[],[],[]> + one || (NP NUM:'one' NP*) || <x,l1,<e,t>,[l1:[x|count(x,1)]],[],[],[ SLOT_arg/RESOURCE/x ]> + two || (NP NUM:'two' NP*) || <x,l1,<e,t>,[l1:[x|count(x,2)]],[],[],[ SLOT_arg/RESOURCE/x ]> + three || (NP NUM:'three' NP*) || <x,l1,<e,t>,[l1:[x|count(x,3)]],[],[],[ SLOT_arg/RESOURCE/x ]> + four || (NP NUM:'four' NP*) || <x,l1,<e,t>,[l1:[x|count(x,4)]],[],[],[ SLOT_arg/RESOURCE/x ]> + five || (NP NUM:'five' NP*) || <x,l1,<e,t>,[l1:[x|count(x,5)]],[],[],[ SLOT_arg/RESOURCE/x ]> + six || (NP NUM:'six' NP*) || <x,l1,<e,t>,[l1:[x|count(x,6)]],[],[],[ SLOT_arg/RESOURCE/x ]> + seven || (NP NUM:'seven' NP*) || <x,l1,<e,t>,[l1:[x|count(x,7)]],[],[],[ SLOT_arg/RESOURCE/x ]> + eight || (NP NUM:'eight' NP*) || <x,l1,<e,t>,[l1:[x|count(x,8)]],[],[],[ SLOT_arg/RESOURCE/x ]> + nine || (NP NUM:'nine' NP*) || <x,l1,<e,t>,[l1:[x|count(x,9)]],[],[],[ SLOT_arg/RESOURCE/x ]> + ten || (NP NUM:'ten' NP*) || <x,l1,<e,t>,[l1:[x|count(x,10)]],[],[],[ SLOT_arg/RESOURCE/x ]> - one || (NUM NUM:'one') || <x,l1,e,[l1:[x|equal(x,1)]],[],[],[]> - two || (NUM NUM:'two') || <x,l1,e,[l1:[x|equal(x,2)]],[],[],[]> - three || (NUM NUM:'three') || <x,l1,e,[l1:[x|equal(x,3)]],[],[],[]> - four || (NUM NUM:'four') || <x,l1,e,[l1:[x|equal(x,4)]],[],[],[]> - five || (NUM NUM:'five') || <x,l1,e,[l1:[x|equal(x,5)]],[],[],[]> - six || (NUM NUM:'six') || <x,l1,e,[l1:[x|equal(x,6)]],[],[],[]> - seven || (NUM NUM:'seven') || <x,l1,e,[l1:[x|equal(x,7)]],[],[],[]> - eight || (NUM NUM:'eight') || <x,l1,e,[l1:[x|equal(x,8)]],[],[],[]> - nine || (NUM NUM:'nine') || <x,l1,e,[l1:[x|equal(x,9)]],[],[],[]> - ten || (NUM NUM:'ten') || <x,l1,e,[l1:[x|equal(x,10)]],[],[],[]> \ No newline at end of file + one || (NUM NUM:'one') || <x,l1,e,[l1:[x|equal(x,1)]],[],[],[ SLOT_arg/LITERAL/x ]> + two || (NUM NUM:'two') || <x,l1,e,[l1:[x|equal(x,2)]],[],[],[ SLOT_arg/LITERAL/x ]> + three || (NUM NUM:'three') || <x,l1,e,[l1:[x|equal(x,3)]],[],[],[ SLOT_arg/LITERAL/x ]> + four || (NUM NUM:'four') || <x,l1,e,[l1:[x|equal(x,4)]],[],[],[ SLOT_arg/LITERAL/x ]> + five || (NUM NUM:'five') || <x,l1,e,[l1:[x|equal(x,5)]],[],[],[ SLOT_arg/LITERAL/x ]> + six || (NUM NUM:'six') || <x,l1,e,[l1:[x|equal(x,6)]],[],[],[ SLOT_arg/LITERAL/x ]> + seven || (NUM NUM:'seven') || <x,l1,e,[l1:[x|equal(x,7)]],[],[],[ SLOT_arg/LITERAL/x ]> + eight || (NUM NUM:'eight') || <x,l1,e,[l1:[x|equal(x,8)]],[],[],[ SLOT_arg/LITERAL/x ]> + nine || (NUM NUM:'nine') || <x,l1,e,[l1:[x|equal(x,9)]],[],[],[ SLOT_arg/LITERAL/x ]> + ten || (NUM NUM:'ten') || <x,l1,e,[l1:[x|equal(x,10)]],[],[],[ SLOT_arg/LITERAL/x ]> + Copied: trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex (from rev 3728, trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex) =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex (rev 0) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-06-11 17:06:18 UTC (rev 3732) @@ -0,0 +1,31 @@ + +// PREPOSITIONS + + close to || (NP NP* (PP P:'close' P:'to' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_closeto(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_closeto/OBJECTPROPERTY/near ]> + in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location ]> + since || (NP NP* (PP P:'since' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_since(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_since/PROPERTY/since ]> + + for . pounds || (NP NP* (PP P:'for' (NP NUM[num] N:'pounds'))) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y) ] ], [ (l2,y,num,e) ], [ l2=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> + for more than . pounds || (NP NP* (PP P:'for' (NP NUM[num] N:'pounds'))) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y), greater(y,z) ] ], [ (l2,z,num,e) ], [ l2=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> + for less than . pounds || (NP NP* (PP P:'for' (NP NUM[num] N:'pounds'))) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y), less(y,z) ] ], [ (l2,y,num,e) ], [ l2=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> + from . to . pounds || (NP NP* (PP P:'from' NUM[num1] P:'to' NUM[num2] N:'pounds')) || <x,l1,<e,t>, [ l1:[ | SLOT_price(x,y), greaterorequal(y,n1), lessorequal(y,n2) ] ], [ (l2,n1,num1,e),(l3,n2,num2,e) ], [ l2=l1,l3=l1 ],[ SLOT_price/DATATYPEPROPERTY/price ]> + + with || (NP NP* (PP P:'with' DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[]> + with || (NP NP* (PP P:'with' NUM[num] DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y), count(y,z) ] ], [ (l2,y,dp,<<e,t>,t>),(l3,z,num,e) ], [ l2=l1,l3=l1 ],[ SLOT_arg/RESOURCE/y ]> + with || (NP NP* (PP P:'with' NUM[num] DP[dp])) || <x,l1,<e,t>, [ l1:[ | empty(x,y), equals(y,z) ] ], [ (l2,y,dp,<<e,t>,t>),(l3,z,num,e) ], [ l2=l1,l3=l1 ],[ SLOT_arg/LITERAL/y ]> + + +// MONTHS + + january || (DP DP:'january') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,1) ]], [],[],[]> + february || (DP DP:'february') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,2) ]], [],[],[]> + march || (DP DP:'march') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,3) ]], [],[],[]> + april || (DP DP:'april') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,4) ]], [],[],[]> + may || (DP DP:'may') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,5) ]], [],[],[]> + june || (DP DP:'june') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,6) ]], [],[],[]> + july || (DP DP:'july') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,7) ]], [],[],[]> + august || (DP DP:'august') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,8) ]], [],[],[]> + september || (DP DP:'september') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,9) ]], [],[],[]> + october || (DP DP:'october') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,10) ]], [],[],[]> + november || (DP DP:'november') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,11) ]], [],[],[]> + december || (DP DP:'december') || <x,l1,<<e,t>,t>, [ l1:[ x | xsd:month(x,12) ]], [],[],[]> \ No newline at end of file Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2012-06-11 13:06:58 UTC (rev 3731) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2012-06-11 17:06:18 UTC (rev 3732) @@ -11,7 +11,7 @@ public class TestFrontend { - static String[] GRAMMAR_FILES = {"src/main/resources/lexicon/english.lex"}; + static String[] GRAMMAR_FILES = {"tbsl/lexicon/english.lex","tbsl/lexicon/english_oxford.lex"}; static boolean BASIC_MODE = false; // true for BASIC mode, false for LEIPZIG mode public static void main(String[] args) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-06-11 13:07:08
|
Revision: 3731 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3731&view=rev Author: lorenz_b Date: 2012-06-11 13:06:58 +0000 (Mon, 11 Jun 2012) Log Message: ----------- Changed query to get URIs for property label. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java 2012-06-11 12:38:21 UTC (rev 3730) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java 2012-06-11 13:06:58 UTC (rev 3731) @@ -16,8 +16,8 @@ "LIMIT %d OFFSET %d"; super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT * WHERE {\n" + -// "?s ?uri ?o.\n" + - "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.} " + + "?s ?uri ?o.\n" + +// "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.} " + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-11 12:38:21 UTC (rev 3730) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-11 13:06:58 UTC (rev 3731) @@ -41,18 +41,6 @@ } catch (FileNotFoundException e) { e.printStackTrace(); } - System.out.println(model.size()); - String queryStr = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?uri WHERE {" + -// "?s ?uri ?o." + - "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.}" + - "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label." + - "FILTER(REGEX(STR(?label), 'bathroom', 'i'))" + - "}" + - "LIMIT 20 OFFSET 0"; - System.out.println( - ResultSetFormatter.asText( - QueryExecutionFactory.create( - QueryFactory.create(queryStr, Syntax.syntaxARQ), model).execSelect())); } @Test @@ -100,11 +88,12 @@ Index resourcesIndex = new SPARQLIndex(endpoint); Index classesIndex = new SPARQLClassesIndex(endpoint); Index propertiesIndex = new SPARQLPropertiesIndex(endpoint); + System.out.println(propertiesIndex.getResources("near")); SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); learner.init(); - String question = "Give me all houses with more than 2 bedrooms and more than 3 bathrooms."; + String question = "Give me all houses near a school."; learner.setQuestion(question); learner.learnSPARQLQueries(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-06-11 12:38:30
|
Revision: 3730 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3730&view=rev Author: christinaunger Date: 2012-06-11 12:38:21 +0000 (Mon, 11 Jun 2012) Log Message: ----------- [tbsl] repaired GROUP BY construct Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-06-11 12:19:30 UTC (rev 3729) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-06-11 12:38:21 UTC (rev 3730) @@ -155,16 +155,22 @@ if (qt == SPARQL_QueryType.SELECT) { retVal += "\nSELECT "; - - String lastSelectTerm = null; + + boolean group = false; for (SPARQL_Term term : selTerms) { retVal += term.toString() + " "; if(selTerms.size() > 1 && term.toString().contains("COUNT")){ - groupBy = lastSelectTerm; + group = true; } - lastSelectTerm = term.toString(); } + if (group) { + groupBy = ""; + for (SPARQL_Term t : selTerms) { + if (!t.toString().contains("COUNT")) + groupBy += t.toString() + " "; + } + } } else retVal += "\nASK "; @@ -185,7 +191,7 @@ retVal += "}\n"; if(groupBy != null){ - retVal += "GROUP BY (" + groupBy + ")\n"; + retVal += "GROUP BY " + groupBy + "\n"; } if (orderBy != null && !orderBy.isEmpty()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-06-11 12:19:40
|
Revision: 3729 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3729&view=rev Author: lorenz_b Date: 2012-06-11 12:19:30 +0000 (Mon, 11 Jun 2012) Log Message: ----------- Added method to test on remote endpoint. Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-09 10:46:58 UTC (rev 3728) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TBSLTest.java 2012-06-11 12:19:30 UTC (rev 3729) @@ -20,6 +20,7 @@ import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -27,18 +28,31 @@ public class TBSLTest extends TestCase{ private Model model; + private SparqlEndpoint endpoint; @Override protected void setUp() throws Exception { super.setUp(); - + endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); model = ModelFactory.createOntologyModel(); try { model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/ontology.ttl")), null, "TURTLE"); - model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/finders.ttl")), "http://diadem.cs.ox.ac.uk/ontologies/real-estate#", "TURTLE"); + model.read(new FileInputStream(new File("/home/lorenz/arbeit/papers/question-answering-iswc-2012/examples/data/wwagency-letting-triple.ttl")), "http://diadem.cs.ox.ac.uk/ontologies/real-estate#", "TURTLE"); } catch (FileNotFoundException e) { e.printStackTrace(); } + System.out.println(model.size()); + String queryStr = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?uri WHERE {" + +// "?s ?uri ?o." + + "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.}" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label." + + "FILTER(REGEX(STR(?label), 'bathroom', 'i'))" + + "}" + + "LIMIT 20 OFFSET 0"; + System.out.println( + ResultSetFormatter.asText( + QueryExecutionFactory.create( + QueryFactory.create(queryStr, Syntax.syntaxARQ), model).execSelect())); } @Test @@ -62,7 +76,7 @@ } @Test - public void testOxford() throws Exception{ + public void testOxfordLocal() throws Exception{ Index resourcesIndex = new SPARQLIndex(model); Index classesIndex = new SPARQLClassesIndex(model); @@ -71,7 +85,7 @@ SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(model, resourcesIndex, classesIndex, propertiesIndex); learner.init(); - String question = "Give me all flats where pets are allowed"; + String question = "Give me all houses with more than 2 bedrooms."; learner.setQuestion(question); learner.learnSPARQLQueries(); @@ -81,10 +95,30 @@ } @Test + public void testOxfordRemote() throws Exception{ + + Index resourcesIndex = new SPARQLIndex(endpoint); + Index classesIndex = new SPARQLClassesIndex(endpoint); + Index propertiesIndex = new SPARQLPropertiesIndex(endpoint); + + SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.init(); + + String question = "Give me all houses with more than 2 bedrooms and more than 3 bathrooms."; + + learner.setQuestion(question); + learner.learnSPARQLQueries(); + System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + System.out.println(learner.getLearnedPosition()); + } + + @Test public void testSPARQLIndex(){ Index classesIndex = new SPARQLClassesIndex(model); System.out.println(classesIndex.getResources("flat")); + } @Test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-06-09 10:47:05
|
Revision: 3728 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3728&view=rev Author: christinaunger Date: 2012-06-09 10:46:58 +0000 (Sat, 09 Jun 2012) Log Message: ----------- NP/DP conjunction Modified Paths: -------------- trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex 2012-06-07 13:57:47 UTC (rev 3727) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex 2012-06-09 10:46:58 UTC (rev 3728) @@ -150,7 +150,7 @@ and || (S S* CC:'and' S[s]) || <x,l1,t,[l1:[|]],[(l2,y,s,t)],[l1=l2],[]> and || (DP DP* CC:'and' DP[dp]) || <x,l1,<<e,t>,t>,[l1:[|]],[(l2,y,dp,<<e,t>,t>)],[l1=l2],[]> - and || (NP NP* CC:'and' NP[np]) || <x,l1,<e,t>,[l1:[|]],[(l2,y,np,<e,t>)],[l1=l2],[]> + and || (NP NP* CC:'and' NP[np]) || <x,l1,<e,t>,[l1:[|x=y]],[(l2,y,np,<e,t>)],[l1=l2],[]> and || (VP VP* CC:'and' VP[vp]) || - and || (ADJ ADJ* CC:'and' ADJ[adj]) || - Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-06-07 13:57:47 UTC (rev 3727) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-06-09 10:46:58 UTC (rev 3728) @@ -140,7 +140,7 @@ and || (S S* CC:'and' S[s]) || <x,l1,t,[l1:[|]],[(l2,y,s,t)],[l1=l2],[]> and || (DP DP* CC:'and' DP[dp]) || <x,l1,<<e,t>,t>,[l1:[|]],[(l2,y,dp,<<e,t>,t>)],[l1=l2],[]> - and || (NP NP* CC:'and' NP[np]) || <x,l1,<e,t>,[l1:[|]],[(l2,y,np,<e,t>)],[l1=l2],[]> + and || (NP NP* CC:'and' NP[np]) || <x,l1,<e,t>,[l1:[|x=y]],[(l2,y,np,<e,t>)],[l1=l2],[]> and || (VP VP* CC:'and' VP[vp]) || - and || (ADJ ADJ* CC:'and' ADJ[adj]) || - Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2012-06-07 13:57:47 UTC (rev 3727) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2012-06-09 10:46:58 UTC (rev 3728) @@ -12,7 +12,7 @@ public class TestFrontend { static String[] GRAMMAR_FILES = {"src/main/resources/lexicon/english.lex"}; - static boolean BASIC_MODE = true; // true for BASIC mode, false for LEIPZIG mode + static boolean BASIC_MODE = false; // true for BASIC mode, false for LEIPZIG mode public static void main(String[] args) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-06-07 13:57:58
|
Revision: 3727 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3727&view=rev Author: kirdie Date: 2012-06-07 13:57:47 +0000 (Thu, 07 Jun 2012) Log Message: ----------- added missing statement to new extractiondbcache constructor initialising md5. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-06-07 13:48:06 UTC (rev 3726) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-06-07 13:57:47 UTC (rev 3727) @@ -72,6 +72,8 @@ public ExtractionDBCache(Connection conn) throws SQLException { this.conn=conn; + try{md5 = MessageDigest.getInstance("MD5");} + catch(NoSuchAlgorithmException e) {throw new RuntimeException("Should never happen - MD5 not found.");} // create cache table if it does not exist Statement stmt = conn.createStatement(); stmt.execute("CREATE TABLE IF NOT EXISTS QUERY_CACHE(QUERYHASH BINARY PRIMARY KEY,QUERY VARCHAR(20000), TRIPLES CLOB, STORE_TIME TIMESTAMP)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-06-07 13:48:12
|
Revision: 3726 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3726&view=rev Author: kirdie Date: 2012-06-07 13:48:06 +0000 (Thu, 07 Jun 2012) Log Message: ----------- temporarily fixed snapshot version of jena-iri, because the newest one on the maven archiva server lacks the jar file. Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-06-07 11:06:43 UTC (rev 3725) +++ trunk/pom.xml 2012-06-07 13:48:06 UTC (rev 3726) @@ -119,6 +119,11 @@ as version is retrieved from the parent. - - Remember, default scope is compile in Maven. --> <dependencies> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-iri</artifactId> + <version>0.9.1-incubating-20120305.120450-12</version> + </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi</artifactId> @@ -539,4 +544,4 @@ </build> </profile> </profiles> -</project> \ No newline at end of file +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-06-07 11:06:53
|
Revision: 3725 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3725&view=rev Author: kirdie Date: 2012-06-07 11:06:43 +0000 (Thu, 07 Jun 2012) Log Message: ----------- added new constructor to extraction db cache Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-06-01 09:27:59 UTC (rev 3724) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-06-07 11:06:43 UTC (rev 3725) @@ -69,6 +69,14 @@ private Monitor mon = MonitorFactory.getTimeMonitor("Query"); + public ExtractionDBCache(Connection conn) throws SQLException + { + this.conn=conn; + // create cache table if it does not exist + Statement stmt = conn.createStatement(); + stmt.execute("CREATE TABLE IF NOT EXISTS QUERY_CACHE(QUERYHASH BINARY PRIMARY KEY,QUERY VARCHAR(20000), TRIPLES CLOB, STORE_TIME TIMESTAMP)"); + } + public ExtractionDBCache(String cacheDir) { databaseDirectory = cacheDir; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-06-01 09:28:08
|
Revision: 3724 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3724&view=rev Author: lorenz_b Date: 2012-06-01 09:27:59 +0000 (Fri, 01 Jun 2012) Log Message: ----------- Added additional constructor. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-05-22 00:31:06 UTC (rev 3723) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-06-01 09:27:59 UTC (rev 3724) @@ -140,12 +140,17 @@ } public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ this.endpoint = endpoint; this.resourcesIndex = resourcesIndex; this.classesIndex = classesIndex; this.propertiesIndex = propertiesIndex; this.posTagger = posTagger; this.wordNet = wordNet; + this.cache = cache; setOptions(options); } @@ -163,12 +168,17 @@ } public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(model, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ this.model = model; this.resourcesIndex = resourcesIndex; this.classesIndex = classesIndex; this.propertiesIndex = propertiesIndex; this.posTagger = posTagger; this.wordNet = wordNet; + this.cache = cache; setOptions(options); } @@ -1406,31 +1416,6 @@ return rs; } - private List<String> getResultFromRemoteEndpoint(String query){ - List<String> resources = new ArrayList<String>(); - try { - String queryString = query; - if(!query.contains("LIMIT") && !query.contains("ASK")){ - queryString = query + " LIMIT 10"; - } - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, queryString)); - QuerySolution qs; - String projectionVar; - while(rs.hasNext()){ - qs = rs.next(); - projectionVar = qs.varNames().next(); - if(qs.get(projectionVar).isLiteral()){ - resources.add(qs.get(projectionVar).asLiteral().getLexicalForm()); - } else if(qs.get(projectionVar).isURIResource()){ - resources.add(qs.get(projectionVar).asResource().getURI()); - } - - } - } catch (Exception e) {e.printStackTrace(); - logger.error("Query execution failed.", e); - } - return resources; - } public int getLearnedPosition() { if(learnedPos >= 0){ @@ -1438,15 +1423,7 @@ } return learnedPos; } - - - - - - - - @Override public void start() { } Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-05-22 00:31:06 UTC (rev 3723) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-06-01 09:27:59 UTC (rev 3724) @@ -72,7 +72,7 @@ QuerySolution qs; while(rs.hasNext()){ - qs = rs.next();System.out.println(qs); + qs = rs.next(); RDFNode uriNode = qs.get("uri"); if(uriNode.isURIResource()){ resources.add(uriNode.asResource().getURI()); Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java 2012-05-22 00:31:06 UTC (rev 3723) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLPropertiesIndex.java 2012-06-01 09:27:59 UTC (rev 3724) @@ -15,8 +15,9 @@ "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; - super.queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + - "?s ?uri ?o.\n" + + super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT * WHERE {\n" + +// "?s ?uri ?o.\n" + + "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.} " + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; @@ -31,8 +32,9 @@ "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; - super.queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + - "?s ?uri ?o.\n" + + super.queryWithLabelTemplate = "PREFIX owl:<http://www.w3.org/2002/07/owl#> SELECT DISTINCT * WHERE {\n" + +// "?s ?uri ?o.\n" + + "{?uri a owl:DatatypeProperty.} UNION {?uri a owl:ObjectProperty.} " + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-22 00:31:12
|
Revision: 3723 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3723&view=rev Author: tcanvn Date: 2012-05-22 00:31:06 +0000 (Tue, 22 May 2012) Log Message: ----------- Add "stopOnFirstDefinition" option for CELOE algorithm. If this is set to true, the algorithm will stop when the first definition is found Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-05-18 11:10:14 UTC (rev 3722) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-05-22 00:31:06 UTC (rev 3723) @@ -21,7 +21,6 @@ import java.io.File; import java.text.DecimalFormat; -import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -193,7 +192,13 @@ @ConfigOption(name = "maxDepth", defaultValue="7", description="maximum depth of description") private double maxDepth = 7; + @ConfigOption(name = "stopOnFirstDefinition", defaultValue="false", description="algorithm will terminate immediately when a correct definition is found") + private boolean stopOnFirstDefinition = false; + private int expressionTestCountLastImprovement; + + + @SuppressWarnings("unused") private long timeLastImprovement = 0; // public CELOEConfigurator getConfigurator() { @@ -787,7 +792,8 @@ (maxClassExpressionTests != 0 && (expressionTests >= maxClassExpressionTests)) || (maxExecutionTimeInSecondsAfterImprovement != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSecondsAfterImprovement*1000000000l))) || (maxExecutionTimeInSeconds != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSeconds*1000000000l))) || - (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)); + (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)) || + (stopOnFirstDefinition && (getCurrentlyBestAccuracy() >= 1)); } private void reset() { @@ -1072,7 +1078,16 @@ public void setMaxDepth(double maxDepth) { this.maxDepth = maxDepth; } + + + public boolean isStopOnFirstDefinition() { + return stopOnFirstDefinition; + } + public void setStopOnFirstDefinition(boolean stopOnFirstDefinition) { + this.stopOnFirstDefinition = stopOnFirstDefinition; + } + public static void main(String[] args) throws Exception{ AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); ks.init(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-05-18 11:10:24
|
Revision: 3722 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3722&view=rev Author: jenslehmann Date: 2012-05-18 11:10:14 +0000 (Fri, 18 May 2012) Log Message: ----------- changed comment Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java trunk/interfaces/src/main/java/org/dllearner/cli/Start.java Modified: trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java 2012-05-18 11:07:51 UTC (rev 3721) +++ trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java 2012-05-18 11:10:14 UTC (rev 3722) @@ -20,6 +20,7 @@ public void testGetComponentsOfType() { Collection<Class<? extends Component>> components = AnnComponentManager.getInstance().getComponentsOfType(ReasonerComponent.class); +// System.out.println(components); Assert.assertEquals(3,components.size()); } } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Start.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2012-05-18 11:07:51 UTC (rev 3721) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2012-05-18 11:10:14 UTC (rev 3722) @@ -116,9 +116,9 @@ */ public static void main(String[] args) { - System.out.println("********************************************************************************"); - System.out.println("* Caution: The command line interface is currently unlikely to work correctly. *"); - System.out.println("********************************************************************************"); + System.out.println("************************************************************************************************************"); + System.out.println("* Please use the new CLI interfach: org.dllearner.cli.CLI - this interface is unlikely to work as expected *"); + System.out.println("************************************************************************************************************"); System.out.println("DL-Learner " + Info.build + " command line interface"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-18 11:08:02
|
Revision: 3721 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3721&view=rev Author: lorenz_b Date: 2012-05-18 11:07:51 +0000 (Fri, 18 May 2012) Log Message: ----------- Removed exclusion of Xerces lib because it is needed for JENA ARQ. Modified Paths: -------------- trunk/components-core/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-05-18 09:18:52 UTC (rev 3720) +++ trunk/components-core/pom.xml 2012-05-18 11:07:51 UTC (rev 3721) @@ -140,12 +140,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-arq</artifactId> - <exclusions> - <exclusion> - <artifactId>xercesImpl</artifactId> - <groupId>xerces</groupId> - </exclusion> - </exclusions> + </dependency> <!--JSON is in Central --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-05-18 09:19:03
|
Revision: 3720 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3720&view=rev Author: christinaunger Date: 2012-05-18 09:18:52 +0000 (Fri, 18 May 2012) Log Message: ----------- [tbsl] and another correction in javacc parser (Das h?\195?\182rt nie auf! ;) Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-18 08:22:35 UTC (rev 3719) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-18 09:18:52 UTC (rev 3720) @@ -249,7 +249,7 @@ //TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":"])+>} //TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} -TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'"])+>} +TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'","_"])+>} TOKEN: {<B: (["a"-"z","A"-"Z","_",".","#","0"-"9"])+":"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} // oder eher: SLOT_([...])+ TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-18 08:22:35 UTC (rev 3719) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-18 09:18:52 UTC (rev 3720) @@ -447,7 +447,7 @@ case 4: if ((0x7fffffe87fffffeL & l) != 0L) jjCheckNAddTwoStates(3, 4); - if ((0x7fffffe07fffffeL & l) != 0L) + if ((0x7fffffe87fffffeL & l) != 0L) { if (kind > 20) kind = 20; @@ -457,7 +457,7 @@ case 0: if ((0x7fffffe87fffffeL & l) != 0L) jjCheckNAddTwoStates(3, 4); - if ((0x7fffffe07fffffeL & l) != 0L) + if ((0x7fffffe87fffffeL & l) != 0L) { if (kind > 20) kind = 20; @@ -467,7 +467,7 @@ jjstateSet[jjnewStateCnt++] = 1; break; case 2: - if ((0x7fffffe07fffffeL & l) == 0L) + if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 20) kind = 20; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-05-18 08:22:35 UTC (rev 3719) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-05-18 09:18:52 UTC (rev 3720) @@ -501,7 +501,7 @@ //TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":","0"-"9"])+>} //TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} -TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'"])+>} +TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'","_"])+>} TOKEN: {<B: (["a"-"z","A"-"Z","_",".","#","0"-"9"])+":"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} // oder eher: SLOT_([...])+ TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java 2012-05-18 08:22:35 UTC (rev 3719) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java 2012-05-18 09:18:52 UTC (rev 3720) @@ -486,7 +486,7 @@ case 4: if ((0x7fffffe87fffffeL & l) != 0L) jjCheckNAddTwoStates(3, 4); - if ((0x7fffffe07fffffeL & l) != 0L) + if ((0x7fffffe87fffffeL & l) != 0L) { if (kind > 26) kind = 26; @@ -496,7 +496,7 @@ case 0: if ((0x7fffffe87fffffeL & l) != 0L) jjCheckNAddTwoStates(3, 4); - if ((0x7fffffe07fffffeL & l) != 0L) + if ((0x7fffffe87fffffeL & l) != 0L) { if (kind > 26) kind = 26; @@ -506,7 +506,7 @@ jjstateSet[jjnewStateCnt++] = 1; break; case 2: - if ((0x7fffffe07fffffeL & l) == 0L) + if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 26) kind = 26; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-05-18 08:19:54
|
Revision: 3718 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3718&view=rev Author: christinaunger Date: 2012-05-18 08:19:44 +0000 (Fri, 18 May 2012) Log Message: ----------- [tbsl] me vs javacc (part 2718) Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-17 09:35:54 UTC (rev 3717) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-18 08:19:44 UTC (rev 3718) @@ -249,7 +249,7 @@ //TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":"])+>} //TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} -TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9"])+>} +TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'"])+>} TOKEN: {<B: (["a"-"z","A"-"Z","_",".","#","0"-"9"])+":"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} // oder eher: SLOT_([...])+ TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-17 09:35:54 UTC (rev 3717) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-18 08:19:44 UTC (rev 3718) @@ -364,7 +364,7 @@ jjCheckNAddTwoStates(3, 4); else if (curChar == 58) jjCheckNAdd(5); - if ((0x3ff000000000000L & l) != 0L) + if ((0x3ff008000000000L & l) != 0L) { if (kind > 20) kind = 20; @@ -378,7 +378,7 @@ jjCheckNAdd(9); else if ((0x8000000200000000L & l) != 0L) jjCheckNAdd(7); - if ((0x3ff000000000000L & l) != 0L) + if ((0x3ff008000000000L & l) != 0L) { if (kind > 20) kind = 20; @@ -393,7 +393,7 @@ jjstateSet[jjnewStateCnt++] = 1; break; case 2: - if ((0x3ff000000000000L & l) == 0L) + if ((0x3ff008000000000L & l) == 0L) break; if (kind > 20) kind = 20; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-05-17 09:35:54 UTC (rev 3717) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_Parser.jj 2012-05-18 08:19:44 UTC (rev 3718) @@ -342,7 +342,7 @@ | - dr1 = dr() "=" dr2 = dr() + dr1 = dr() "=" dr2 = dr() { Simple_DRS_Condition condition; @@ -501,7 +501,7 @@ //TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":","0"-"9"])+>} //TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} -TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9"])+>} +TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9","'"])+>} TOKEN: {<B: (["a"-"z","A"-"Z","_",".","#","0"-"9"])+":"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} // oder eher: SLOT_([...])+ TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java 2012-05-17 09:35:54 UTC (rev 3717) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/dudes/reader/DUDE_ParserTokenManager.java 2012-05-18 08:19:44 UTC (rev 3718) @@ -403,7 +403,7 @@ jjCheckNAddTwoStates(3, 4); else if (curChar == 58) jjCheckNAdd(5); - if ((0x3ff000000000000L & l) != 0L) + if ((0x3ff008000000000L & l) != 0L) { if (kind > 26) kind = 26; @@ -417,7 +417,7 @@ jjCheckNAdd(9); else if ((0x8000000200000000L & l) != 0L) jjCheckNAdd(7); - if ((0x3ff000000000000L & l) != 0L) + if ((0x3ff008000000000L & l) != 0L) { if (kind > 26) kind = 26; @@ -432,7 +432,7 @@ jjstateSet[jjnewStateCnt++] = 1; break; case 2: - if ((0x3ff000000000000L & l) == 0L) + if ((0x3ff008000000000L & l) == 0L) break; if (kind > 26) kind = 26; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-05-17 09:36:02
|
Revision: 3717 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3717&view=rev Author: sebastianwtr Date: 2012-05-17 09:35:54 +0000 (Thu, 17 May 2012) Log Message: ----------- [tbsl exploration] updated the Query Manipulation part Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -217,11 +217,18 @@ } if(slot.toString().contains("PROPERTY")){ + System.out.println("Slot.toString(): "+slot.toString()); String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); + System.out.println(tmp); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); - list_of_hypothesis.add(tmp_hypothesis); + if(tmp_array.length>1){ + System.out.println("tmp_array[0]:"+tmp_array[0]); + System.out.println("tmp_array[1]:"+tmp_array[1]); + + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); + list_of_hypothesis.add(tmp_hypothesis); + } } if(slot.toString().contains("RESOURCE")){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -11,19 +11,17 @@ /* * TODO: test if the sorted queries are given back properly */ - public static ArrayList<QueryPair> doSort(ArrayList<QueryPair> qp, String question){ + public static ArrayList<QueryPair> doHeuristicSort(ArrayList<QueryPair> qp, String question){ boolean change=true; //while(change){ //change=false; for(int i = 0; i<qp.size()-1;i++){ - if(qp.get(i).getRank()==qp.get(i+1).getRank()&&question.contains("of")){ + if(qp.get(i).getRank()==qp.get(i+1).getRank()&&(question.toLowerCase().contains("of")||question.toLowerCase().contains("which")||question.toLowerCase().contains("who"))){ //change=true; QueryPair one = qp.get(i); QueryPair two = qp.get(i+1); String string = one.getQuery(); - //Pattern p = Pattern.compile (".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*"); - //Matcher m = p.matcher (string); if(string.matches(".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*")){ qp.set(i, one); qp.set(i+1, two); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -42,12 +42,19 @@ givenHypothesenList=t.getHypothesen(); } + int anzahl_globalrank=0; for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; + String Resource=null; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ + if(h.getType().toLowerCase().contains("resource")){ + Resource=h.getName(); + } + + condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); /* * Dont create a Query with variables, which dont have a correct uri @@ -59,6 +66,11 @@ //just in case... condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); + /*if(h.getType().toLowerCase().contains("property")){ + global_rank=global_rank+h.getRank(); + anzahl_globalrank+=1; + }*/ + } /* @@ -66,25 +78,21 @@ */ global_rank = global_rank/hypothesenList.size(); - + //global_rank=global_rank/anzahl_globalrank; //System.out.println("New_Condition after replacing "+condition_new); - if(t.getQuestion().toLowerCase().contains("who")){ - /* - * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> -SELECT DISTINCT ?uri ?string -WHERE { - res:Brooklyn_Bridge dbp:designer ?uri . - OPTIONAL { ?uri rdfs:label ?string. FILTER (lang(?string) = 'en') } - */ + if(t.getQuestion().toLowerCase().contains("who")&&!t.getSelectTerm().toLowerCase().contains("count")){ + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+t.getQueryType()+" "+t.getSelectTerm()+"?string WHERE {"+ condition_new+" OPTIONAL { "+ t.getSelectTerm()+" rdfs:label ?string. FILTER (lang(?string) = 'en') }"+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); + qp.setResource(Resource); if(addQuery)queryList.add(qp); } else{ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); + qp.setResource(Resource); if(addQuery)queryList.add(qp); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -2,6 +2,7 @@ public class QueryPair { private String Query; + private String Resource; private double rank; public String getQuery() { return Query; @@ -25,6 +26,12 @@ this.setQuery(query_new); this.setRank(rank_new); } + public String getResource() { + return Resource; + } + public void setResource(String resource) { + Resource = resource; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -20,7 +20,7 @@ private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; - private static int timeToTimeoutOnServer=30000; + private static int timeToTimeoutOnServer=3000; public static HashMap<String, String> generatesQueryForOutsideClasses(String query){ String working_query= ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -12,6 +12,7 @@ import java.util.ArrayList; import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; @@ -38,7 +39,7 @@ * false, goes through all */ boolean wait = false; - Setting.setThresholdSelect(0.5); + //Setting.setThresholdSelect(0.5); if(Setting.isWaitModus())wait=true; @@ -105,7 +106,7 @@ //sort QueryPairs qp=LinearSort.doSort(qp); - qp=HeuristicSort.doSort(qp, Question); + qp=HeuristicSort.doHeuristicSort(qp, Question); //if(Setting.isDebugModus())printQueries(qp, "NORMAL", Question); //printQueries(qp, "NORMAL", Question); Setting.setAnzahlAbgeschickterQueries(10); @@ -162,23 +163,15 @@ } if(wait)DebugMode.waitForButton(); - - /* - * If there is no answer, start IterationMode with Levensthein - */ - if(answers.isEmpty()&&Setting.getModuleStep()>=2){ + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ - answers.clear(); - //Setting.setLevenstheinMin(0.65); - //Setting.setAnzahlAbgeschickterQueries(10); - answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); - if(wait)DebugMode.waitForButton(); + answers.clear(); + //Setting.setLevenstheinMin(0.65); + //Setting.setAnzahlAbgeschickterQueries(10); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); + if(wait)DebugMode.waitForButton(); } - /* - * still no answer, start IterationMode with Wordnet - */ - if(answers.isEmpty()&&Setting.getModuleStep()>=3){ answers.clear(); @@ -186,7 +179,8 @@ answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET","neu")); if(wait)DebugMode.waitForButton(); } - + + if(answers.isEmpty()&&Setting.getModuleStep()>=4){ answers.clear(); @@ -197,23 +191,18 @@ } if(answers.isEmpty()&&Setting.getModuleStep()>=5){ - System.out.println("Stufe 5"); - DebugMode.waitForButton(); + System.out.println("NO Answer from Server =>Start Query Manipulation"); answers.clear(); - //Setting.setAnzahlAbgeschickterQueries(10); - //Setting.setThresholdSelect(0.2); - //ArrayList<String> answers.addAll(stufe5(myindex,wordnet,lemmatiser,wait,template_list)); if(wait)DebugMode.waitForButton(); } - /*if(answers.isEmpty()){ - System.out.println(""); - //answers.add("No answers were found with the three Modules"); - }*/ + + + /* * return answers! */ @@ -240,23 +229,23 @@ boolean special=false; int anzahl; boolean go_on; - if(type.contains("SPECIAL")){ + /*if(type.contains("SPECIAL")){ type ="LEVENSTHEIN"; special=true; - } + }*/ System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - if(test.contains("alt")){ + /*if(test.contains("alt")){ ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); - } + }*/ - if(test.contains("neu")){ - System.err.println("IN NEU!!!!!"); + //if(test.contains("neu")){ + // System.err.println("IN NEU!!!!!"); ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); @@ -279,7 +268,7 @@ } - } + //} catch (Exception e){ } @@ -311,10 +300,7 @@ //sort QueryPairs qp=LinearSort.doSort(qp); //printQueries(qp, type, Question); - /* - * Only for test! - */ - qp=HeuristicSort.doSort(qp, Question); + qp=HeuristicSort.doHeuristicSort(qp, Question); System.out.println("Following Querries were created:"); for(QueryPair z : qp){ @@ -336,7 +322,7 @@ //else go_on=false; //go_on=true; go_on=false; - if(special) go_on=true; + System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); if(qp.size()>(id+1)){ //&&anzahl<2 @@ -344,6 +330,11 @@ go_on=true; } } + /* + * in which queries with an answer, dont accept a second Query, is there is already an answer. + */ + if(Question.toLowerCase().contains("which")) go_on=false; + if(Question.toLowerCase().contains("who")) go_on=false; boolean contains_uri=false; @@ -557,10 +548,112 @@ * iterate over Templates to create new one's but only if you have [isa][resource] and condition.size=2; */ for(Template t: template_list){ + //t.printAll(); + if(t.getCondition().size()==1){ + System.out.println("Nur eine Condition"); + ArrayList<String> condition=t.getCondition().get(0); + boolean go_on=false; + if(condition.get(1).toLowerCase().equals("isa")) go_on=true; + System.out.println("go_on:"+go_on); + if(go_on){ + + String resource_variable=condition.get(0); + String class_variable=condition.get(2); + Hypothesis resource_h = null; + Hypothesis class_h = null; + boolean go_on_resource=false; + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource_variable)){ + if(h.getType().toLowerCase().contains("resource")) { + go_on_resource=true; + resource_h=h; + } + } + if(h.getVariable().equals(class_variable)){ + class_h=h; + } + } + + } + System.out.println("go_on_resource:"+go_on_resource); + if(go_on_resource){ + + /* + * manipulate Class variable to make a property from it + */ + class_h.setType("PROPERTY"); + class_h.setUri(class_h.getUri().toLowerCase()); + class_h.setVariable("?y"); + resource_h.setVariable("?x"); + ArrayList<ArrayList<Hypothesis>> new_hypothesen_list = new ArrayList<ArrayList<Hypothesis>>(); + ArrayList<Hypothesis> small_h_list = new ArrayList<Hypothesis>(); + small_h_list.add(resource_h); + small_h_list.add(class_h); + new_hypothesen_list.add(small_h_list); + + ArrayList<String> condition_new = new ArrayList<String>(); + condition_new.add("?x"); + condition_new.add("?y"); + condition_new.add("?z"); + + ArrayList<ArrayList<String>> new_c_list = new ArrayList<ArrayList<String>>(); + new_c_list.add(condition_new); + + Template new_Template = new Template(new_c_list, t.getQueryType(), "","" , "?z", "", "", t.getQuestion()); + + new_Template.setHypothesen(new_hypothesen_list); + Elements elm = new Elements(new_Template.getCondition(),new_Template.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + new_Template.setElm(elm); + new_template_list.add(new_Template); + } + + Template template_reverse_conditions = new Template(new_Template.getCondition(),new_Template.getQueryType(), new_Template.getHaving(), new_Template.getFilter(), new_Template.getSelectTerm(), new_Template.getOrderBy(), new_Template.getLimit(), new_Template.getQuestion()); + template_reverse_conditions.setHypothesen(new_hypothesen_list); + + ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); + ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); + + + for (ArrayList<String> x : condition_template_reverse_conditions){ + ArrayList<String> new_list = new ArrayList<String>(); + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } + + + template_reverse_conditions.setCondition(condition_reverse_new); + + Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); + if(elm_reverse.isElementEmty()==false){ + //elm.printAll(); + template_reverse_conditions.setElm(elm_reverse); + new_template_list.add(template_reverse_conditions); + } + + + + } + + + + + } + } + + + + /* * only if condition.size==2 */ if(t.getCondition().size()==2){ + System.out.println("Yeah, found two Conditions!"); + /* * now look if one have the [isa][resource] or [resource][isa] case */ @@ -569,24 +662,55 @@ condition1=t.getCondition().get(0); condition2=t.getCondition().get(1); + System.out.println("condition1:"+condition1); + System.out.println("condition2:"+condition2); boolean go_on=false; if(condition1.get(1).toLowerCase().contains("isa")&&!condition2.get(1).toLowerCase().contains("isa")){ - if(condition2.get(0).contains("resource/")||condition2.get(2).contains("resource/")){ + String resource1_variable=condition2.get(0); + String resource2_variable=condition2.get(2); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource2_variable)||h.getVariable().equals(resource1_variable)){ + if(h.getType().toLowerCase().contains("resource")) go_on=true; + } + } + + } + + /*if(condition2.get(0).contains("resource/")||condition2.get(2).contains("resource/")){ go_on=true; } - else go_on=false; + else go_on=false;*/ } - else if(!condition1.get(1).toLowerCase().contains("isa")&&condition2.get(1).toLowerCase().contains("isa")){ - if(condition1.get(0).contains("resource/")||condition1.get(2).contains("resource/")){ + else if(condition2.get(1).toLowerCase().contains("isa")){ + + String resource1_variable=condition1.get(0); + String resource2_variable=condition1.get(2); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource2_variable)||h.getVariable().equals(resource1_variable)){ + if(h.getType().toLowerCase().contains("resource")) go_on=true; + } + } + + } + + + /* + * in the conditions there is for sure no resource!!! + */ + /*if(condition1.get(0).contains("resource/")||condition1.get(2).contains("resource/")){ go_on=true; } - else go_on=false; + else go_on=false;*/ } else go_on=false; + + System.out.println("Go_on:"+go_on); if(go_on==true){ /* @@ -607,6 +731,13 @@ } /* + * New HypothesenList + */ + System.out.println("New Hypothesen List"); + for(ArrayList<Hypothesis> h_blub : new_hypothesen_list){ + for(Hypothesis blub:h_blub) blub.printAll(); + } + /* * create new ArrayList for Conditions, only with the */ ArrayList<String> new_condition= new ArrayList<String>(); @@ -629,6 +760,8 @@ * Elements can still be the same */ new_Template.setElm(t.getElm()); + new_template_list.add(new_Template); + //new_Template.printAll(); } @@ -640,6 +773,7 @@ * if there are new templates, start rescursive call; */ if(new_template_list.size()>0){ + System.out.println("Generated new Templates"); try { return singleSteps(myindex, wordnet, lemmatiser, wait,new_template_list); } catch (IOException e) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -10,6 +10,10 @@ private static double thresholdSelect; private static double thresholdAsk; private static int moduleStep; + private static double EsaMin; + private static boolean loadedProperties; + private static int version; + private static boolean saveAnsweredQueries; @@ -62,6 +66,30 @@ public static void setModuleStep(int moduleStep) { Setting.moduleStep = moduleStep; } + public static double getEsaMin() { + return EsaMin; + } + public static void setEsaMin(double esaMin) { + EsaMin = esaMin; + } + public static boolean isLoadedProperties() { + return loadedProperties; + } + public static void setLoadedProperties(boolean loadedProperties) { + Setting.loadedProperties = loadedProperties; + } + public static int getVersion() { + return version; + } + public static void setVersion(int version) { + Setting.version = version; + } + public static boolean isSaveAnsweredQueries() { + return saveAnsweredQueries; + } + public static void setSaveAnsweredQueries(boolean saveAnsweredQueries) { + Setting.saveAnsweredQueries = saveAnsweredQueries; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -63,13 +63,18 @@ Setting.setLevenstheinMin(0.95); Setting.setAnzahlAbgeschickterQueries(10); Setting.setThresholdAsk(0.9); - Setting.setThresholdSelect(0.6); + Setting.setThresholdSelect(0.5); + Setting.setLoadedProperties(false); + Setting.setSaveAnsweredQueries(false); + //default + //Setting.setVersion(1); /* * 1= only "Normal" * 2= "Normal" + Levensthein * 3= Normal+Levensthein+Wordnet */ - Setting.setModuleStep(4); + Setting.setModuleStep(5); + Setting.setEsaMin(0.4); @@ -133,71 +138,106 @@ if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - for(int i = 1; i<2;i++){ - double min = 0.95; - min+=(i*0.05); - - //Setting.setLevenstheinMin(min); - Setting.setLevenstheinMin(0.95); - //Setting.setModuleStep(i); - + //for(int i = 1; i<2;i++){ + //double min = 0.95; + //min+=(i*0.05); - /*System.out.println("Please enter Path of xml File:"); - line=in.readLine();*/ - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-questions.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-onlyWithWorking.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + /*if(i==1){ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + } + if(i==2){ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; + }*/ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; - //create Structs - ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - - list_of_structs=generateStruct(line,true); - //Start Time measuring - long startTime = System.currentTimeMillis(); - - int anzahl=0; - int anzahl_query_with_answers=0; - int yago_querys=0; - for(queryInformation qi : list_of_structs){ - anzahl=anzahl+1; - System.out.println(""); - if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); - String question = qi.getQuery(); - ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); - qi.setResult(answers); + for(int j=1;j<2;j++){ + + Setting.setVersion(1); + + for(int z=1;z<7;z++){ + //Setting.setLevenstheinMin(min); + Setting.setLevenstheinMin(0.95); + //Setting.setThresholdSelect(0.4); + Setting.setModuleStep(2); + Setting.setThresholdSelect(0.5); + Setting.setEsaMin(0.0+(z/10.0)); + Setting.setLoadedProperties(false); + /*if(i==2)Setting.setLoadedProperties(true); + else Setting.setLoadedProperties(false); + */ + + + + + //create Structs + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + + list_of_structs=generateStruct(line,true); + //Start Time measuring + long startTime = System.currentTimeMillis(); + + int anzahl=0; + int anzahl_query_with_answers=0; + int yago_querys=0; + for(queryInformation qi : list_of_structs){ + anzahl=anzahl+1; + System.out.println(""); + if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); + String question = qi.getQuery(); + ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); + qi.setResult(answers); + } + + + long stopTime = System.currentTimeMillis(); + System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); + + String filename=""; + filename=createXML(list_of_structs,((stopTime-startTime)/1000)); + String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/"+filename; + String execute=""; + if(filename_for_evaluation.contains("train")){ + execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation-C.py "+filename_for_evaluation+" 0"; + } + else{ + execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation-C.py "+filename_for_evaluation+" 1"; + + } + System.out.println(filename_for_evaluation); + /* + * First only for training + */ + + System.out.println("execute: "+execute); + + + try + { + Runtime r = Runtime.getRuntime(); + Process p = r.exec(execute); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + p.waitFor(); + while (br.ready()) + System.out.println(br.readLine()); + + } + catch (Exception e) + { + String cause = e.getMessage(); + if (cause.equals("python: not found")) + System.out.println("No python interpreter found."); + } + + + } + + } + - long stopTime = System.currentTimeMillis(); - System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); - - String systemid=""; - systemid=createXML(list_of_structs); - String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; - String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; - System.out.println(filename_for_evaluation); - /* - * First only for training - */ - - System.out.println("execute: "+execute); - Runtime r = Runtime.getRuntime(); - Process p = r.exec(execute); - - /* String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; - execute ="firefox "+ open_file; - p = r.exec(execute);*/ - } + // } /*schleife=false; System.out.println("Bye!"); System.exit(0);*/ @@ -288,13 +328,14 @@ } - private static String createXML(ArrayList<queryInformation> list){ + private static String createXML(ArrayList<queryInformation> list, double average_time){ java.util.Date now = new java.util.Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); String systemid = sdf.format(now); System.out.println("In createXML"); + String filename=null; String xmlDocument=""; int counter=0; @@ -325,6 +366,8 @@ if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else if(i.matches("[0-9][.][0-9]"))input="<number>"+i+"</number>\n"; + //<number>1.8</number> else if(i.matches("[0-9]*-[0-9][0-9]-[0-9]*"))input="<date>"+i+"</date>\n"; else if(i.length()>=1 && !i.equals(" "))input="<string>"+i+"</string>\n"; tmp+="<answer>"+input+"</answer>\n"; @@ -337,7 +380,8 @@ xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+"NLD"+Setting.getLevenstheinMin()+"Stufe"+Setting.getModuleStep()+"Type"+xmltype+"Anzahl"+anzahl+".xml"); + filename="result"+systemid.replace(" ", "_")+"NLD"+Setting.getLevenstheinMin()+"Stufe"+Setting.getModuleStep()+"Type"+xmltype+"Anzahl"+anzahl+"Time"+average_time+"Threshold"+Setting.getThresholdSelect()+"ESA"+Setting.getEsaMin()+"LoadedProperty"+Setting.isLoadedProperties()+"Version"+Setting.getVersion()+".xml"; + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/"+filename); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); @@ -350,7 +394,7 @@ } System.out.println("In createXML - Done"); - return systemid; + return filename; } private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -30,308 +30,8 @@ * */ public class IterationModule { - - /** - * returns ArrayList<ArrayList<Hypothesis>> which than can be added using - * @param elm - * @param hypothesen - * @param condition - * @return ArrayList<ArrayList<Hypothesis>> - * @throws SQLException - */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ - - - - boolean gotResource=true; - ArrayList<ElementList> resources = new ArrayList<ElementList>(); - try{ - resources = elm.getElements(); - } - catch (Exception e){ - gotResource=false; - if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt get any Resource"); - } - - //System.out.println("Anzahl der Resource Listen: "+resources.size()); - - ArrayList<ArrayList<Hypothesis>>finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); - - - for(ArrayList<Hypothesis> hl :givenHypothesenList){ - /* - * foundedResourcesClasses - */ - ArrayList<Hypothesis> RL = new ArrayList<Hypothesis>(); - - /* - * foundedProperty - */ - ArrayList<String> PL = new ArrayList<String>(); - - /* - * hypothesenListBeforSorting - */ - ArrayList<Hypothesis>HL = new ArrayList<Hypothesis>(); - - - /* - * AL abhängig von jeder einzelnen Resource R aus RL - */ - ArrayList<ArrayList<ArrayList<Hypothesis>>> ALR = new ArrayList<ArrayList<ArrayList<Hypothesis>>>(); - - - /* - * First look for resources and generate List with properties - */ - for(Hypothesis h : hl){ - - //System.out.println("In Hypothesis Loop"); - if(h.getType().contains("RESOURCE")){ - /* - * Get Variable from Resource - */ - String variable = h.getVariable(); - String name = h.getName(); - RL.add(h); - if(Setting.isDebugModus())DebugMode.debugPrint("Found Resource "+h.getName() +" "+h.getUri()); - - - /* - * Look in Condition for the Set, in which the variable appears - */ - ArrayList<String> propertyVariableList = new ArrayList<String>(); - for(ArrayList<String> cl : givenConditionList){ - for(String s : cl){ - if(s.contains(variable)){ - if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+name); - else propertyVariableList.add(cl.get(1)+"LEFT::"+name); - } - } - } - - /* - * Now get for each found Property the Name - */ - ArrayList<String> propertyNameList = new ArrayList<String>(); - for(String s : propertyVariableList){ - for(Hypothesis h_t : hl){ - String variable_t = s; - variable_t=variable_t.replace("RIGHT", ""); - variable_t=variable_t.replace("LEFT", ""); - String[] variable_t1=variable_t.split("::"); - if(h_t.getVariable().contains(variable_t1[0])){ - propertyNameList.add(h_t.getName()+"::"+s); - } - - } - } - /* - * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc - */ - - if(gotResource){ - for(String s : propertyNameList){ - String[] array = s.split("::"); - - - /* - * array[0] contains name of Property - * array[1] contains LEFT/RIGHT and Variable of Property - * array[2] contains Name of Resource - */ - - String side="LEFT"; - if(array[1].contains("RIGHT")) side="RIGHT"; - - for(ElementList el : resources){ - if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ - String propertyVariable = array[1]; - propertyVariable=propertyVariable.replace("LEFT", ""); - propertyVariable=propertyVariable.replace("RIGHT", ""); - ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - try { - /* - * Here start levenstehin, wordnet etc etc - */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,array[0],el.getHm()); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); - if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JWNLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); - - } - } - - } - } - - - } - - if(h.getType().contains("ISA")){ - /* - * TODO:Add special case, if we have only one condition but with an isA in it. - */ - RL.add(h); - if(Setting.isDebugModus())DebugMode.debugPrint("Found Class "+h.getName() +" "+h.getUri()); - - for(ElementList el:resources){ - /* - * Find the resource with the same uri as in h an then start Levensthein/Wordnet etc - */ - if(el.getURI().contains(h.getUri())){ - /* - * Iterate over condition and find the coressesponding variable of the Class, wich is used for the new Hypothesis - */ - ArrayList<String> propertyVariableList= new ArrayList<String>(); - for(ArrayList<String> cl : givenConditionList){ - /* - * Dont look for line, where e.g. ?x isA ?y - */ - //get(1) is the middle Term and if there is an isa, than its there - if(!cl.get(1).contains("ISA")){ - for(String s : cl){ - if(s.contains(h.getVariable())){ - propertyVariableList.add(s); - } - } - } - - } - for(String propertyVariable : propertyVariableList){ - for(ArrayList<Hypothesis> hl_small :givenHypothesenList){ - for(Hypothesis h_small : hl_small){ - if(h_small.getVariable().contains(propertyVariable)){ - try { - ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); - /* - * Here start levenstehin, wordnet etc etc - */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,h_small.getName(),el.getHm()); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); - if(!PL.contains(propertyVariable)) PL.add(propertyVariable); - for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - } - //for(Hypothesis h_p : finalHypothesenList) h_p.printAll(); - - - } - } - - - - } - - - } - - - /* - * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case - */ - - /*for(Hypothesis h : RL){ - h.printAll(); - } - - for(String s : PL){ - System.out.println("Variable P: "+s); - }*/ - - /* - * Here add new function! - */ - for(Hypothesis R : RL){ - /* - * AL, abhängig von jeder einzelnen P aus PL und R aus RL - */ - ArrayList<ArrayList<Hypothesis>> AL = new ArrayList<ArrayList<Hypothesis>>(); - - - for(String P : PL){ - if(P.contains(R.getVariable())){ - for(Hypothesis H : HL){ - if(P.contains(H.getVariable())){ - ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); - t_h_l.add(H); - t_h_l.add(R); - AL.add(t_h_l); - } - } - } - } - - ALR.add(AL); - } - - if(ALR.size()==1){ - System.out.println("ONLY One Element in ALR"); - finalHypothesenList=ALR.get(0); - System.out.println("One Element in ALR added to finalHypothesenList"); - } - if(ALR.size()==2){ - System.out.println("Two Elements in ALR"); - for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ - for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ - ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); - for(Hypothesis h_t : hl_t) al_t.add(h_t); - for(Hypothesis h_t : hl1_t) al_t.add(h_t); - finalHypothesenList.add(al_t); - } - } - System.out.println("Two Element in ALR added to finalHypothesenList"); - - } - - if(ALR.size()==2){ - System.out.println("Three Elements in ALR"); - for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ - for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ - for(ArrayList<Hypothesis> hl2_t : ALR.get(2)){ - ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); - for(Hypothesis h_t : hl_t) al_t.add(h_t); - for(Hypothesis h_t : hl1_t) al_t.add(h_t); - for(Hypothesis h_t : hl2_t) al_t.add(h_t); - finalHypothesenList.add(al_t); - } - - } - } - System.out.println("Three Element in ALR added to finalHypothesenList"); - - } - - - } - - - - System.out.println("######################DONE######################"); - - return finalHypothesenList; - - } - /* * Use Here only one Hypothesen Set at each time, so for each "AusgangshypothesenSet" start this function */ @@ -458,7 +158,7 @@ /* * Here start levenstehin, wordnet etc etc */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm()); + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm(),h.getName()); if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(condition.get(1),property_name,el.getHm(),myindex,wordnet,lemmatiser); if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(condition.get(1),property_name,el.getHm()); for(Hypothesis h_temp : resultHypothesenList) { @@ -623,13 +323,13 @@ resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable_local, property_name, el); + property_variable_local, property_name, el.getHm(),resource_h.getName()); for(Hypothesis h_temp : resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(class_h); temp_al.add(h_temp); temp_al.add(resource_h); - System.out.println("Hypothesen:"); + //System.out.println("Hypothesen:"); //class_h.printAll(); //h_temp.printAll(); finalHypothesenList.add(temp_al); @@ -687,7 +387,7 @@ ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable, property_name, el); + property_variable, property_name, el.getHm(),class_h.getName()); for(Hypothesis h_temp : resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(class_h); @@ -726,28 +426,19 @@ String second_property_name=""; String property_variable=""; String second_property_variable=""; + String property_side_new="LEFT"; if(condition1_exists_resource){ - //property_variable= condition1.get(1); - //second_property_variable=condition2.get(1); property_variable= condition2.get(1); second_property_variable=condition1.get(1); + property_side_new="RIGHT"; } if(condition2_exists_resource){ - //property_variable= condition2.get(1); - //second_property_variable=condition1.get(1); property_variable= condition1.get(1); second_property_variable=condition2.get(1); + property_side_new="LEFT"; } - //System.out.println("property_variable: " + property_variable); - //System.out.println("scond_property_variable: " + second_property_variable); - /*for(ArrayList<String> al : givenConditionList){ - for(String s : al) System.out.println(s); - } - for(Hypothesis h : givenHypothesenList){ - h.printAll(); - }*/ for(Hypothesis h_t : givenHypothesenList){ if(h_t.getVariable().contains(property_variable)){ @@ -759,8 +450,7 @@ } } - // System.out.println("property_name: " + property_name); - // System.out.println("second_property_name: " + second_property_name); + if(Setting.isWaitModus())DebugMode.waitForButton(); @@ -775,10 +465,11 @@ ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable, property_name, el); + property_variable, property_name, el.getHm(),resource_h.getName()); + for(Hypothesis h_temp : resultHypothesenList) { String Query=""; - if(property_Side.contains("LEFT")){ + if(property_side_new.contains("LEFT")){ Query= "SELECT DISTINCT ?s ?x WHERE {<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } @@ -795,16 +486,9 @@ ArrayList<Hypothesis> second_resultHypothesenList=new ArrayList<Hypothesis>(); - - - if(type.contains("LEVENSTHEIN"))second_resultHypothesenList= LevenstheinModule.doLevensthein(second_property_variable,second_property_name,hm_newClasses); - if(type.contains("RELATE"))second_resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(second_property_variable,second_property_name,hm_newClasses); - - if(type.contains("WORDNET"))second_resultHypothesenList= WordnetModule.doWordnet(second_property_variable,second_property_name,hm_newClasses,myindex,wordnet,lemmatiser); - //System.out.println("SIze of second_resultHypothesenList: "+second_resultHypothesenList.size()); second_resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, second_property_variable, - second_property_name,el); + second_property_name,hm_newClasses,resource_h.getName()); for(Hypothesis second_h_temp : second_resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); @@ -924,7 +608,7 @@ property_name1=proptery1_hypothesis.getName(); resultHypothesenListPropertyOne = creatNewPropertyList(type, myindex, wordnet, lemmatiser, property_variable1, - property_name1, el); + property_name1, el.getHm(),class_hypothesis.getName()); } } @@ -941,7 +625,7 @@ property_name1=property2_hypothesis.getName(); resultHypothesenListPropertyTwo = creatNewPropertyList(type, myindex, wordnet, lemmatiser, property_variable2, - property_name2, el); + property_name2, el.getHm(),class_hypothesis.getName()); } } @@ -975,15 +659,15 @@ SQLiteIndex myindex, WordNet wordnet, StanfordLemmatizer lemmatiser, String property_variable, String property_name, - ElementList el) throws SQLException, JWNLException { + HashMap<String, String> hm, String resourceName) throws SQLException, JWNLException { /* * Here start levenstehin, wordnet etc etc */ ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,el.getHm()); + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,hm,resourceName); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,hm); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,hm,myindex,wordnet,lemmatiser); //System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); return resultHypothesenList; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -1,94 +1,233 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; public class LevenstheinModule { //private final static double LevenstheinMin=0.65; - public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) + public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties, String resource_name) throws SQLException { ArrayList<Hypothesis> listOfNewHypothesen= new ArrayList<Hypothesis>(); - - //iterate over properties - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.toLowerCase(); - String value = entry.getValue(); - // System.out.println("Key: "+key); - - ArrayList<String> property_array=new ArrayList<String>(); - property_array.add(property_to_compare_with); - if(property_to_compare_with.contains(" ")){ + /* + * First Read in propertyFile, then iterate with keys over the entries. But first look, if there is a property for the property_to_compare with and if so, check if the + * resulting giving property is in keys. if it is so, set a high rank and close levenstheinMode. + * + * File: MostPropertyCombinations + */ + + String dateiname="/home/swalter/workspace/MostPropertyCombinations"; + HashMap<String, String> loaded_properties = new HashMap<String, String>(); + + boolean found_property_in_loaded_property=false; + boolean found_property_in_created_property=false; + if(Setting.isLoadedProperties()){ + System.out.println("in Loaded!!"); + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + String[] tmp_array = thisLine.split("::"); + if(tmp_array.length>1){ + loaded_properties.put(tmp_array[0].replace("\n", ""), tmp_array[1].replace("\n", "")); + } + + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + for (Entry<String, String> entry_loaded : loaded_properties.entrySet()) { + + String key_loaded= entry_loaded.getKey(); + String value_loaded= entry_loaded.getValue(); + if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ + System.out.println("FOUND!!"); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + /*System.out.println("KEY_old:"+key); + System.out.println("value_loaded:"+value_loaded+"DONE"); + System.out.println("Value:"+value); + System.out.println("\n");*/ + if(key.equals(value_loaded)){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + h.printAll(); + found_property_in_loaded_property=true; + } + } + } + + } + } + + /* + * createdPropertyCombinations + */ + + /* + * Second read in File with the propertys, which were created, when a query produced an answer and query had the rank >0.8 + * and the property hast the given "matserresource" + */ + + /* if(found_property_in_loaded_property==false&&Setting.isSaveAnsweredQueries()){ + HashMap<String, String> created_properties = new HashMap<String, String>(); + System.out.println("in Save!!"); + dateiname="/home/swalter/workspace/createdPropertyCombinations"; + System.out.println("Resource to compare: "+resource_name); + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + String[] tmp_array = thisLine.split("::"); + if(tmp_array.length>2){ + + // check, if the given resource is equal to the reosource loaded from the file! + + if(tmp_array[0].toLowerCase().replace("\n", "").equals(resource_name.toLowerCase())){ + created_properties.put(tmp_array[1].replace("\n", ""), tmp_array[2].replace("\n", "")); + } + + } + + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + if(!created_properties.isEmpty()){ + for (Entry<String, String> entry_loaded : created_properties.entrySet()) { + + String key_loaded= entry_loaded.getKey(); + String value_loaded= entry_loaded.getValue(); + if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ + System.out.println("FOUND!!"); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + System.out.println("KEY_old:"+key); + System.out.println("value_loaded:"+value_loaded+"DONE"); + System.out.println("Value:"+value); + System.out.println("\n"); + if(key.equals(value_loaded)){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + h.printAll(); + found_property_in_created_property=true; + } + } + } + + } + } + + + }*/ + + if(found_property_in_loaded_property==false||found_property_in_created_property==false){ + + //} + + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + // System.out.println("Key: "+key); - String[] array_temp = property_to_compare_with.split(" "); - for(String s : array_temp) property_array.add(s); - } - for(String compare_property :property_array ){ - // System.out.println("compare_property: "+compare_property); - double nld=Levenshtein.nld(compare_property.toLowerCase(), key); - - /* - * At the beginning first realy test with the original Property, to make sure, if there is a match, that only this one is taken. - */ - if(key.toLowerCase().equals(property_to_compare_with.toLowerCase())||key.toLowerCase().equals(property_to_compare_with.replace(" ", "").toLowerCase()) ){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); + ArrayList<String> property_array=new ArrayList<String>(); + property_array.add(property_to_compare_with); + if(property_to_compare_with.contains(" ")){ + + String[] array_temp = property_to_compare_with.split(" "); + for(String s : array_temp) property_array.add(s); } - else if((key.contains(compare_property)||compare_property.contains(key))){ + for(String compare_property :property_array ){ + // System.out.println("compare_property: "+compare_property); + double nld=Levenshtein.nld(compare_property.toLowerCase(), key); - double score=0; - if(compare_property.length()>key.length()){ - score = 0.8+(key.length()/compare_property.length()); - } - else{ - score=0.8+(compare_property.length()/key.length()); - } - - - if(compare_property.length()>4&&key.length()>4) { - //0.95 - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score); - listOfNewHypothesen.add(h); - } - else{ - //0.7 - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score-0.2); - listOfNewHypothesen.add(h); - } - - - // Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (key.length()/compare_property.length())); - // listOfNewHypothesen.add(h); - + /* + * At the beginning first realy test with the original Property, to make sure, if there is a match, that only this one is taken. + */ + if(key.toLowerCase().equals(property_to_compare_with.toLowerCase())||key.toLowerCase().equals(property_to_compare_with.replace(" ", "").toLowerCase()) ){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + } + //else + else if((key.... [truncated message content] |
From: <tc...@us...> - 2012-05-17 03:45:56
|
Revision: 3716 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3716&view=rev Author: tcanvn Date: 2012-05-17 03:45:50 +0000 (Thu, 17 May 2012) Log Message: ----------- cleanup empty packages nz.ac.massey and org.dllearner.algorithms.PADCEL Removed Paths: ------------- trunk/components-core/src/main/java/nz/ac/massey/ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-17 03:10:07
|
Revision: 3715 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3715&view=rev Author: tcanvn Date: 2012-05-17 03:09:57 +0000 (Thu, 17 May 2012) Log Message: ----------- change the PADCEL algorithm's name (PADCEL --> ParCEL). Package name, examples, CLI and test units have been updated Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown2008.java trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELComplenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCompletenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCorrectnessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCoverageGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCoveredNegativeExampleComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefaultHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionGenerationTimeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionLengthComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionLengthReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELEvaluationResult.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELExtraNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELGenerationTimeReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELImprovedCovegareGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELOntologyUtil.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELPosNegLP.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELScore.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELStringUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELTaskComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerThreadFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearnerMBean.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearnerMat.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ParCELDoubleSplitterAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ParCELDoubleSplitterV1.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ValueCount.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ValuesSet.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCELEx/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCELEx/ParCELExAbstract.java trunk/examples/carcinogenesis/carcinogenesis_parcel.conf trunk/examples/family-benchmark/Aunt_parcel.conf trunk/examples/family-benchmark/Brother_parcel.conf trunk/examples/family-benchmark/Cousin_parcel.conf trunk/examples/family-benchmark/Daughter_parcel.conf trunk/examples/family-benchmark/Father_parcel.conf trunk/examples/family-benchmark/Grandson_parcel.conf trunk/examples/family-benchmark/Uncle_parcel.conf trunk/examples/forte/uncle_owl_large_parcel.conf trunk/examples/moral_reasoner/moral_all_examples_simple_owl_parcel.conf trunk/examples/poker/straight_owl_parcel.conf trunk/examples/showering-duration/uca1_150_parcel.conf trunk/examples/showering-duration/uca2_300_parcel.conf trunk/interfaces/src/main/java/org/dllearner/cli/ParCELCrossValidation.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELCLITestAbstract.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELCarcinoGenesisTest.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELFamilyBenchmarkTest.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELMultiExamplesTest.java Removed Paths: ------------- trunk/components-core/src/main/java/nz/ac/massey/abd/ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELRefinementOperatorFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELRefinementOperatorPool.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELScore.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELStringUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELTaskComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELWorker.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELWorkerThreadFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearnerMBean.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/split/ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCELEx/ trunk/examples/carcinogenesis/carcinogenesis_padcel.conf trunk/examples/family-benchmark/Aunt_padcel.conf trunk/examples/family-benchmark/Brother_padcel.conf trunk/examples/family-benchmark/Cousin_padcel.conf trunk/examples/family-benchmark/Daughter_padcel.conf trunk/examples/family-benchmark/Father_padcel.conf trunk/examples/family-benchmark/Grandson_padcel.conf trunk/examples/family-benchmark/Uncle_padcel.conf trunk/examples/forte/uncle_owl_large_padcel.conf trunk/examples/moral_reasoner/moral_all_examples_simple_owl_padcel.conf trunk/examples/poker/straight_owl_padcel.conf trunk/examples/showering-duration/uca1_150_padcel.conf trunk/examples/showering-duration/uca2_300_padcel.conf trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,142 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Set; -import java.util.SortedSet; -import java.util.concurrent.ConcurrentSkipListSet; - -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.NamedClass; - -/** - * Abstract class for all PDL-Learner algorithms family - * - * @author An C. Tran - * - */ -public abstract class PADCELAbstract extends AbstractCELA { - - // ---------------------------------- - // configuration options - // ---------------------------------- - @ConfigOption(name = "numberOfWorkers", defaultValue = "2", description = "This option is used to set the number of workers will be created to serve the leaner. This should be = 2 * total number of cores of CPUs") - protected int numberOfWorkers = 4; // max number of workers will be created - - @ConfigOption(name = "maxExecutionTimeInSeconds", defaultValue = "0", description = "maximum execution of the algorithm in seconds") - protected int maxExecutionTimeInSeconds = 0; - - @ConfigOption(name = "noisePercentage", defaultValue = "0.0", description = "The percentage of noise within the examples") - protected double noisePercentage = 0.0; - - @ConfigOption(name = "maxNoOfSplits", defaultValue = "10", description = "Max number of splits will be applied for data properties with double range") - protected int maxNoOfSplits = 10; - - @ConfigOption(name = "ignoredConcepts", defaultValue = "", description = "set of concepts that will be ignored in learning the target concept") - protected Set<NamedClass> ignoredConcepts = null; - - - /** - * All generated descriptions thread-safe set is used to avoid concurrently - * accessing - */ - protected ConcurrentSkipListSet<Description> allDescriptions = null; - - /** - * Search tree. It hold all evaluated descriptions that are not correct and - * not weak ==> candidate for partial definitions Nodes in the search tree - * must be ordered using heuristic so that it can help the searching more - * efficiently (best search rather than 'blind' breadth first of depth - * first) NOTE: node = (description + accuracy/correctness/completeness/... - * value) - */ - protected ConcurrentSkipListSet<PADCELNode> searchTree = null; // thread safe - // set - - /** - * partial definitions (they should be sorted so that we can get the best - * partial definition at any time - */ - protected SortedSet<PADCELExtraNode> partialDefinitions = null; - - /** - * Default constructor - */ - public PADCELAbstract() { - super(); - } - - /** - * ======================================================================== - * Constructor for the learning algorithm - * - * @param learningProblem - * Must be a PDLLPosNegLP - * @param reasoningService - * A reasoner - */ - public PADCELAbstract(PADCELPosNegLP learningProblem, AbstractReasonerComponent reasoningService) { - super(learningProblem, reasoningService); - } - - public abstract Description getUnionCurrenlyBestDescription(); - - public abstract int getNoOfCompactedPartialDefinition(); - - public abstract Set<PADCELExtraNode> getPartialDefinitions(); - - public abstract double getCurrentlyOveralMaxCompleteness(); - - public long getNumberOfPartialDefinitions() { - return this.partialDefinitions.size(); - } - - - // ------------------------------------------------ - // setters and getters for configuration options - // ------------------------------------------------ - - public void setNumberOfWorkers(int numberOfWorkers) { - this.numberOfWorkers = numberOfWorkers; - } - - public int getNumberOfWorkers() { - return numberOfWorkers; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTime) { - this.maxExecutionTimeInSeconds = maxExecutionTime; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setNoisePercentage(double noise) { - this.noisePercentage = noise; - } - - public double getNoisePercentage() { - return this.noisePercentage; - } - - - public int getMaxNoOfSplits() { - return maxNoOfSplits; - } - - public void setMaxNoOfSplits(int maxNoOfSplits) { - this.maxNoOfSplits = maxNoOfSplits; - } - - public Set<NamedClass> getIgnoredConcepts() { - return ignoredConcepts; - } - - public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { - this.ignoredConcepts = ignoredConcepts; - } - - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,37 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Comparator for PDLLNode based on the completeness of the description If two - * nodes has the same completeness, description length will be taken into the - * consideration and finally the ConceptComparator - * - * @author An C. Tran - * - */ - -public class PADCELComplenessComparator implements Comparator<PADCELNode> { - - @Override - public int compare(PADCELNode node1, PADCELNode node2) { - int v1 = node1.getCoveredPositiveExamples().size(); - int v2 = node2.getCoveredPositiveExamples().size(); - if (v1 > v2) - return -1; - else if (v1 < v2) - return 1; - else { - if (node1.getDescription().getLength() < node2.getDescription().getLength()) - return -1; - else if (node1.getDescription().getLength() > node2.getDescription().getLength()) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on their completeness (coverage). The description - * length and ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCompletenessComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - - int v1 = node1.getCoveredPositiveExamples().size(); - int v2 = node2.getCoveredPositiveExamples().size(); - - if (v1 > v2) - return -1; - else if (v1 < v2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on their correctness. The description length and - * ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCorrectnessComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - double correctness1 = node1.getCorrectness(); - double correctness2 = node2.getCorrectness(); - - if (correctness1 > correctness2) - return -1; // smaller will be on the top - else if (correctness1 < correctness2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,82 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * This class implements a simple strategy for compacting the partial definition set In this - * strategy, the partial definition will be chosen based on their accuracy. The partial definition - * with the best accuracy will be chosen first and the rests will not be re-calculated before the - * next reduction - * - * @author An C. Tran - * - */ -public class PADCELCoverageGreedyReducer implements PADCELReducer { - - /** - * Compact partial definitions - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover all positive examples - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover (positive examples \ uncovered positive - * examples) - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELCorrectnessComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = partialDefinitions.iterator(); - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on the number of covered negative examples. The - * description length and ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCoveredNegativeExampleComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - int coveredNeg1 = node1.getCoveredNegativeExamples().size(); - int coveredNeg2 = node2.getCoveredPositiveExamples().size(); - - if (coveredNeg1 > coveredNeg2) - return -1; // smaller will be on the top - else if (coveredNeg1 < coveredNeg2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,95 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Implements the heuristic used to expand the search tree. Dimensions used: <br> - * + correctness: main value<br> - * + horizontal expansion: penalty<br> - * + accuracy gained from the parent node: bonus<br> - * + refinement nodes: penalty<br> - * + concept type + name (org.dllearner.utilities.owl.ConceptComparator) - * - * @author An C. Tran - * - */ -public class PADCELDefaultHeuristic implements PADCELHeuristic { - - // penalty for long descriptions - protected double expansionPenaltyFactor = 0.1; - - // bonus for gained accuracy - protected double gainBonusFactor = 0.2; - - // penalty if a node description has very many refinements since exploring - // such a node is computationally very expensive - protected double nodeRefinementPenalty = 0.0001; - - // award for node with high accuracy - protected double accuracyAwardFactor = 0.01; - - // syntactic comparison as final comparison criterion - protected ConceptComparator conceptComparator = new ConceptComparator(); - - /** - * Compare two node - * - * @param node1 - * Node to compare - * @param node2 - * Node to compare - * - * @return 1 if node1 "greater" than node2 and vice versa - */ - public int compare(PADCELNode node1, PADCELNode node2) { - double diff = getNodeScore(node1) - getNodeScore(node2); - - if (diff > 0) { // node1 has better score than node2 - return 1; - } else if (diff < 0) { - return -1; - } else { - int comp = conceptComparator.compare(node1.getDescription(), node2.getDescription()); - - // this allows duplicate descriptions exists in the set - if (comp != 0) - return comp; - else - return -1; - - } - } - - /** - * Calculate score for a node which is used as the searching heuristic - * - * @param node - * Node to be scored - * - * @return Score of the node - */ - protected double getNodeScore(PADCELNode node) { - - // the scoring mainly bases on correctness - double score = node.getCorrectness(); - - // bonus for the accuracy gained - if (!node.isRoot()) { - double parentAccuracy = ((PADCELNode) (node.getParent())).getAccuracy(); - score += (parentAccuracy - node.getAccuracy()) * gainBonusFactor; - } - - // award node with high accuracy - score += node.getAccuracy() * accuracyAwardFactor; - - // penalty for horizontal expansion - score -= node.getHorizontalExpansion() * expansionPenaltyFactor; - // score -= node.getDescription().getLength() * expansionPenaltyFactor; - - return score; - } - - public double getScore(PADCELNode node) { - return this.getNodeScore(node); - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,37 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -/** - * Compare two node based on their generation time. - * This will be used in the Generation Time Greedy Compactness strategy - * GOLR - * - * @author An C. Tran - */ - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -public class PADCELDefinitionGenerationTimeComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - double genTime1 = node1.getGenerationTime(); - double genTime2 = node2.getGenerationTime(); - - if (genTime1 < genTime2) - return -1; - else if (genTime1 > genTime2) - return 1; - else { - if (node1.getDescription().getLength() < node2.getDescription().getLength()) - return -1; - else if (node1.getDescription().getLength() > node2.getDescription().getLength()) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,29 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Compare two node based on their definition length. This will be used in the Definition Length - * Greedy Compactness strategy - * - * @author An C. Tran - * - */ - -public class PADCELDefinitionLengthComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), node2.getDescription()); - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,59 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * Compact set of partial definitions using Definition Length Grredy Reduction strategy - * - * @author An C. Tran - * - */ -public class PADCELDefinitionLengthReducer implements PADCELReducer { - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> newSortedPartialDefinitions = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionLengthComparator()); - synchronized (partialDefinitions) { - newSortedPartialDefinitions.addAll(partialDefinitions); - } - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = newSortedPartialDefinitions.iterator(); - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,132 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Set; - -import org.dllearner.core.owl.Individual; - -/** - * This class represents the result of an evaluation result return from the PDLL learning problem - * (PDLLPosNegLP) <br> - * Information included in a PDLL evaluation includes: - * <ol> - * <li>- accuracy: double</li> - * <li>- correctness: double</li> - * <li>- completeness: double</li> - * <li>- covered positive examples: Set<Individual></li> - * <li>- covered negative examples: Set<Individual></li> - * </ol> - * - * @author An C. Tran - * - */ -public class PADCELEvaluationResult { - - protected double accuracy = -1; - protected double correctness = -1; - protected double completeness = -1; - protected Set<Individual> coveredPossitiveExamples = null; - protected Set<Individual> coveredNegativeExamples = null; - - /** - * Default constructor, use default value for all properties - */ - public PADCELEvaluationResult() { - - } - - /** - * This use to create an evaluation result that is not for a correct definition. So, we don't - * need to hold the set of covered positive examples - * - * @param accuracy - * @param correctness - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness) { - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - } - - /** - * Used to create an evaluation result for a correct definition.<br> - * Covered positive examples have to be kept to be used in the result compactness later on.<br> - * This is usually used in case of partial definition - * - * @param accuracy - * @param correctness - * @param completeness - * @param coveredPossitiveExamples - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness, - Set<Individual> coveredPossitiveExamples) { - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - this.coveredPossitiveExamples = coveredPossitiveExamples; - } - - /** - * Used to create an evaluation result for a correct definition.<br> - * Both covered positive examples and covered negative examples will be kept to be used in the - * result compactness later on. - * - * @param accuracy - * @param correctness - * @param completeness - * @param coveredPositiveExamples - * @param coveredNegativeExamples - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness, - Set<Individual> coveredPositiveExamples, Set<Individual> coveredNegativeExamples) { - - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - this.coveredPossitiveExamples = coveredPositiveExamples; - this.coveredNegativeExamples = coveredNegativeExamples; - } - - // --------------------------------------- - // Getters and setters - // --------------------------------------- - public double getAccuracy() { - return accuracy; - } - - public void setAccuracy(double accuracy) { - this.accuracy = accuracy; - } - - public double getCorrectness() { - return correctness; - } - - public void setCorrectness(double correctness) { - this.correctness = correctness; - } - - public double getCompleteness() { - return completeness; - } - - public void setCompleteness(double completeness) { - this.completeness = completeness; - } - - public Set<Individual> getCoveredPossitiveExamples() { - return coveredPossitiveExamples; - } - - public void setCoveredPossitiveExamples(Set<Individual> coveredPossitiveExamples) { - this.coveredPossitiveExamples = coveredPossitiveExamples; - } - - public Set<Individual> getCoveredNegativeExamples() { - return coveredNegativeExamples; - } - - public void setCoveredNegativeExamples(Set<Individual> coveredNegativeExamples) { - this.coveredNegativeExamples = coveredNegativeExamples; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,132 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.algorithms.celoe.OENode; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -/** - * Generation time and node type is added into PADCELNode. This information is necessary for some - * reduction algorithms - * - * @author An C. Tran - * - */ -public class PADCELExtraNode extends PADCELNode { - - private double generationTime = Double.MIN_VALUE; // time in ms that the node was generated - private int type = -1; - - Set<OENode> compositeNodes = new HashSet<OENode>(); - - /** - * ============================================================================================ - * Constructor with correctness of the description - * - * @param parentNode - * Parent node of this node - * @param description - * Description of the node - * @param accuracy - * Accuracy of the node - * @param distance - * Distance between the node and the learning problem - * @param correctness - * Correctness of the node - */ - public PADCELExtraNode(OENode parentNode, Description description, double accuracy, - double correctness) { - super(parentNode, description, accuracy, correctness); - } - - public PADCELExtraNode(OENode parentNode, Description description, double accuracy) { - super(parentNode, description, accuracy); - } - - public PADCELExtraNode(PADCELNode node) { - super(node.getParent(), node.getDescription(), node.getAccuracy(), node.getCorrectness()); - setCoveredPositiveExamples(node.getCoveredPositiveExamples()); - setCoveredNegativeExamples(node.getCoveredNegativeExamples()); - } - - public PADCELExtraNode(PADCELNode node, Set<Individual> cp, double generationTime) { - super(node.getParent(), node.getDescription(), node.getAccuracy(), node.getCorrectness()); - super.coveredPositiveExamples = cp; - this.generationTime = generationTime; - } - - /** - * ============================================================================================ - * Constructor with the correctness and the generation time of the description - * - * @param parentNode - * Parent node of this node - * @param description - * Description of the node - * @param accuracy - * Accuracy of the node - * @param distance - * Distance between the node and the learning problem - * @param correctness - * Correctness of the node - * @param genTime - * Time in ms that the work used to generate this node - */ - public PADCELExtraNode(PADCELNode parentNode, Description description, double accuracy, - double correctness, double genTime) { - super(parentNode, description, accuracy, correctness); - this.coveredPositiveExamples = null; - this.generationTime = genTime; - } - - /** - * ============================================================================================ - * Constructor with the set of positive examples covered by the description of the node - * - * @param parentNode - * @param description - * @param accuracy - * @param distance - * @param correctness - * @param cn - * Covered positive examples - */ - public PADCELExtraNode(PADCELNode parentNode, Description description, double accuracy, - double correctness, Set<Individual> cp) { - super(parentNode, description, accuracy, correctness); - super.setCoveredPositiveExamples(cp); - } - - // ------------------------- - // getters and setters - // ------------------------- - public void setCoveredPositiveExamples(Set<Individual> cpn) { - super.setCoveredPositiveExamples(cpn); - } - - public double getGenerationTime() { - return generationTime; - } - - public void setGenerationTime(double d) { - this.generationTime = d; - } - - public void setType(int t) { - this.type = t; - } - - public int getType() { - return this.type; - } - - public void setCompositeList(Set<PADCELExtraNode> compositeNodes) { - this.compositeNodes.addAll(compositeNodes); - } - - public Set<OENode> getCompositeNodes() { - return this.compositeNodes; - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,62 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * Compact two a partial definitions set using Generation Time Greedy strategy - * - * @author An C. Tran - * - */ - -public class PADCELGenerationTimeReducer implements PADCELReducer { - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> newSortedPartialDefinitions = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - synchronized (partialDefinitions) { - newSortedPartialDefinitions.addAll(partialDefinitions); - } - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = newSortedPartialDefinitions.iterator(); - - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,16 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -/** - * Interface for heuristics used in PADCEL - * - * @author An C. Tran - * - */ -public interface PADCELHeuristic extends Comparator<PADCELNode> { - - public int compare(PADCELNode node1, PADCELNode node2); - - public double getScore(PADCELNode node); -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,115 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.dllearner.core.owl.Individual; - -/** - * This class implements "wise" coverage greedy strategy for compacting the partial definitions In - * this strategy, the partial definitions will be chosen based on their coverage. When a partial - * definition has been chosen, coverage of other partial definition will be recalculated - * - * @author An C. Tran - * - */ - -public class PADCELImprovedCovegareGreedyReducer implements PADCELReducer { - - Logger logger = Logger.getLogger(this.getClass()); - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover all positive examples - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return this.compact(partialDefinitions, positiveExamples, 0); - } - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover (positive examples \ uncovered positive - * examples) - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> reducedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELCompletenessComparator()); - - if (partialDefinitions.size() == 0) - return reducedPartialDefinition; - - synchronized (partialDefinitions) { - Object[] partialDefs = partialDefinitions.toArray(); - - // the highest accurate partial definition - // reducedPartialDefinition.add((PDLLExtraNode)partialDefs[0]); - // positiveExamplesTmp.removeAll(((PDLLExtraNode)partialDefs[0]).getCoveredPositiveExamples()); - - for (int i = 0; (positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (i < partialDefinitions.size()); i++) { - - // count the number of different positive examples covered - int counti = 0; - for (Individual indi : ((PADCELExtraNode) partialDefs[i]) - .getCoveredPositiveExamples()) { - if (positiveExamplesTmp.contains(indi)) - counti++; - } // count the number of different covered positive examples by - // i - - for (int j = i + 1; j < partialDefinitions.size(); j++) { - int countj = 0; - - for (Individual indj : ((PADCELExtraNode) partialDefs[j]) - .getCoveredPositiveExamples()) - if (positiveExamplesTmp.contains(indj)) - countj++; - - // TODO: revise this code: Swapping should be done only one - // time at the end - // swap the partial definition so that the "best" partial - // definition will be in the top - if (countj > counti) { - PADCELExtraNode tmp = (PADCELExtraNode) partialDefs[j]; - partialDefs[j] = partialDefs[i]; - partialDefs[i] = tmp; - counti = countj; - } - } - - reducedPartialDefinition.add((PADCELExtraNode) partialDefs[i]); - positiveExamplesTmp.removeAll(((PADCELExtraNode) partialDefs[i]) - .getCoveredPositiveExamples()); - } - } - - return reducedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,113 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.text.DecimalFormat; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.algorithms.celoe.OENode; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -/** - * Represents a node in the search tree used in the PDLLeanring<br> - * A node includes description and its corresponding properties such as: correctness, accuracy, - * distance between the description the leaning problem, parent node of the description. It also - * contains a flag which indicates the node is processed or not. - * - * @author An C. Tran - * - */ -public class PADCELNode extends OENode { - - private double correctness = -1.0; - private double completeness = -1.0; - - protected Set<Individual> coveredPositiveExamples = new HashSet<Individual>(); - protected Set<Individual> coveredNegativeExamples = new HashSet<Individual>(); - - private DecimalFormat dfPercent = new DecimalFormat("0.00%"); - - public PADCELNode(OENode parentNode, Description description, double accuracy) { - super(parentNode, description, accuracy); - } - - public PADCELNode(OENode parentNode, Description description, double accuracy, double correctness) { - super(parentNode, description, accuracy); - this.correctness = correctness; - } - - public PADCELNode(OENode parentNode, Description description, double accuracy, - double correctness, double completeness) { - super(parentNode, description, accuracy); - this.correctness = correctness; - this.completeness = completeness; - } - - public PADCELNode(OENode parentNode, Description description) { - super(parentNode, description, 0); - } - - public PADCELNode(OENode parentNode, Description description, - Set<Individual> coveredPositiveExamples, Set<Individual> coveredNegativeExamples) { - super(parentNode, description, 0); - this.coveredPositiveExamples.addAll(coveredPositiveExamples); - this.coveredNegativeExamples.addAll(coveredNegativeExamples); - } - - public void setCorrectness(double cor) { - this.correctness = cor; - } - - public double getCorrectness() { - return this.correctness; - } - - public void setCompleteness(double comp) { - this.completeness = comp; - } - - public double getCompleteness() { - return this.completeness; - } - - public void setAccuracy(double acc) { - this.accuracy = acc; - } - - public Set<Individual> getCoveredPositiveExamples() { - return this.coveredPositiveExamples; - } - - public Set<Individual> getCoveredNegativeExamples() { - return this.coveredNegativeExamples; - } - - public void setCoveredPositiveExamples(Set<Individual> coveredPositiveExamples) { - if (coveredPositiveExamples != null) - this.coveredPositiveExamples.addAll(coveredPositiveExamples); - else - this.coveredPositiveExamples.clear(); - } - - public void setCoveredNegativeExamples(Set<Individual> coveredNegativeExamples) { - if (coveredNegativeExamples != null) - this.coveredNegativeExamples.addAll(coveredNegativeExamples); - else - this.coveredNegativeExamples.clear(); - } - - @Override - public String toString() { - String ret = this.getDescription().toString(null, null) + " ["; - ret += "acc:" + dfPercent.format(this.getAccuracy()) + ", "; - ret += "cor:" + dfPercent.format(this.getCorrectness()) + ", "; - ret += "comp:" + dfPercent.format(this.completeness) + "]"; - return ret; - - } - - public void setDescription(Description newDescription) { - this.description = newDescription; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,87 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.OWLOntologyStorageException; - -/** - * Some utility functions for ontology manipulation - * - * @author An C. Tran - * - */ - -public class PADCELOntologyUtil { - - /** - * ========================================================================================== - * Get ontology given its file path - * - * @param ontologyFilePath - * - * @return Opened ontology - * @throws OWLOntologyCreationException - */ - public static OWLOntology loadOntology(String ontologyFilePath) - throws OWLOntologyCreationException { - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology ontology; - - String flash = (System.getProperty("os.name").contains("Windows")) ? "/" : ""; - - File f = new File(ontologyFilePath); - - if (!ontologyFilePath.contains("file:")) - ontologyFilePath = "file:" + flash + f.getAbsolutePath(); - - ontologyFilePath = ontologyFilePath.replace('\\', '/'); - - ontology = manager.loadOntology(IRI.create(ontologyFilePath)); - - return ontology; - } - - /** - * ============================================================================================ - * Persist the ontology - * - * @param ontology - * Ontology which need to be persisted - * - * @throws OWLOntologyStorageException - */ - public static void persistOntology(OWLOntology ontology) throws OWLOntologyStorageException { - OWLOntologyManager manager = ontology.getOWLOntologyManager(); - manager.saveOntology(ontology); - } - - /** - * ============================================================================================ - * Persist ontology to another ontology - * - * @param ontology - * Ontology contains changes - * @param newFilePath - * Path to the new ontology file - * - * @throws OWLOntologyStorageException - * @throws IOException - */ - public static void persistOntology(OWLOntology ontology, String newFilePath) - throws OWLOntologyStorageException, IOException { - OWLOntologyManager manager = ontology.getOWLOntologyManager(); - - File f = new File(newFilePath); - FileOutputStream fo = new FileOutputStream(f); - - manager.saveOntology(ontology, fo); - fo.close(); - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,493 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -/** - * PDLL Learning problem: provides correctness, completeness, and accuracy calculation. - * Predictive accuracy calculation is used. - * - * @author An C. Tran - */ - -import java.util.Set; - -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedList; - -import org.apache.log4j.Logger; -import org.dllearner.core.AbstractLearningProblem; -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.StringSetConfigOption; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -@ComponentAnn(name = "PDLLPosNegLP", shortName = "pdllPosNegLP", version = 0.1, description = "PDLL positive negative learning problem") -public class PADCELPosNegLP extends AbstractLearningProblem { - - protected Set<Individual> positiveExamples; - protected Set<Individual> negativeExamples; - - protected Set<Individual> uncoveredPositiveExamples; - - private Logger logger = Logger.getLogger(this.getClass()); - - // reasoner component is declared in AbstractLearningProblem class - - /** - * Constructor, used in case that positive and negative examples are provided when this - * component is initialized - * - * @param reasoningService - * Reasoner, provides reasoning service. Used to checking the instance type - * @param positiveExamples - * Positive examples - * @param negativeExamples - * Negative examples - */ - public PADCELPosNegLP(AbstractReasonerComponent reasoningService, - Set<Individual> positiveExamples, Set<Individual> negativeExamples) { - super(reasoningService); - this.positiveExamples = positiveExamples; - this.negativeExamples = negativeExamples; - this.uncoveredPositiveExamples = this.positiveExamples; - } - - /** - * This constructor is used when the learning configuration file is used - * - * @param reasoningService - */ - public PADCELPosNegLP(AbstractReasonerComponent reasoningService) { - super(reasoningService); - } - - /** - * This constructor can be used by SpringDefinition to create bean object Properties of new bean - * may be initialised later using setters - */ - public PADCELPosNegLP() { - super(); - - if (logger.isDebugEnabled()) - logger.debug("Learning problem created: " + this); - } - - /** - * Get list of positive examples covered by a description - * - * @param description - * Description - * - * @return Set of positive examples covered by the description - */ - protected Set<Individual> coveredPositiveExamples(Description description) { - Set<Individual> coveredPositiveExamples = new HashSet<Individual>(); - - for (Individual example : positiveExamples) - if (reasoner.hasType(description, example)) - coveredPositiveExamples.add(example); - - return coveredPositiveExamples; - } - - /** - * Get number of positive examples covered by a description - * - * @param description - * Description - * @return Number if positive examples covered by the description - */ - protected int getNumberCoveredPositiveExamples(Description description) { - int coveredPos = 0; - - for (Individual example : positiveExamples) - if (reasoner.hasType(description, example)) - coveredPos++; - - return coveredPos; - } - - /** - * Get number of negative examples covered by a description - * - * @param description - * Description to test - * - * @return Number of negative examples covered by the description - */ - protected int getNumberOfCoveredNegativeExamples(Description description) { - int coveredNeg = 0; - for (Individual example : negativeExamples) { - if (reasoner.hasType(description, example)) { - coveredNeg++; - } - } - - return coveredNeg; - } - - /** - * Calculate predictive accuracy of a description pred-accuracy(D) = - * (covered-positive-examples(D) + uncovered-negative-examples(D)) / all-examples - * -... [truncated message content] |
From: <chr...@us...> - 2012-05-15 07:21:02
|
Revision: 3714 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3714&view=rev Author: christinaunger Date: 2012-05-15 07:20:52 +0000 (Tue, 15 May 2012) Log Message: ----------- [tbsl] updated DRS reader again Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-14 16:58:45 UTC (rev 3713) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-15 07:20:52 UTC (rev 3714) @@ -250,7 +250,7 @@ //TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9"])+>} -TOKEN: {<B: "SLOT_"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} +TOKEN: {<B: (["a"-"z","A"-"Z","_",".","#","0"-"9"])+":"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} // oder eher: SLOT_([...])+ TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} Token dr() : { Token t; }{ (t=<A> | t=<C>) { return t; } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-14 16:58:45 UTC (rev 3713) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-15 07:20:52 UTC (rev 3714) @@ -20,20 +20,13 @@ switch (pos) { case 0: - if ((active0 & 0x7ee00L) != 0L) + if ((active0 & 0x7fe00L) != 0L) { jjmatchedKind = 20; - return 2; + return 4; } - if ((active0 & 0x1000L) != 0L) - { - jjmatchedKind = 20; - return 7; - } return -1; case 1: - if ((active0 & 0x20200L) != 0L) - return 2; if ((active0 & 0x5fc00L) != 0L) { if (jjmatchedPos != 1) @@ -41,37 +34,39 @@ jjmatchedKind = 20; jjmatchedPos = 1; } - return 2; + return 4; } + if ((active0 & 0x20200L) != 0L) + return 4; return -1; case 2: - if ((active0 & 0x200L) != 0L) - return 2; if ((active0 & 0x5fc00L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 2; - return 2; + return 4; } + if ((active0 & 0x200L) != 0L) + return 4; return -1; case 3: + if ((active0 & 0x19800L) != 0L) + return 4; if ((active0 & 0x46400L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 3; - return 2; + return 4; } - if ((active0 & 0x19800L) != 0L) - return 2; return -1; case 4: if ((active0 & 0x400L) != 0L) - return 2; + return 4; if ((active0 & 0x46000L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 4; - return 2; + return 4; } return -1; case 5: @@ -79,18 +74,18 @@ { jjmatchedKind = 20; jjmatchedPos = 5; - return 2; + return 4; } return -1; case 6: + if ((active0 & 0x42000L) != 0L) + return 4; if ((active0 & 0x4000L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 6; - return 2; + return 4; } - if ((active0 & 0x42000L) != 0L) - return 2; return -1; default : return -1; @@ -194,7 +189,7 @@ return jjMoveStringLiteralDfa3_0(active0, 0x800L); case 84: if ((active0 & 0x200L) != 0L) - return jjStartNfaWithStates_0(2, 9, 2); + return jjStartNfaWithStates_0(2, 9, 4); break; case 87: return jjMoveStringLiteralDfa3_0(active0, 0x40000L); @@ -216,7 +211,7 @@ { case 69: if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(3, 12, 2); + return jjStartNfaWithStates_0(3, 12, 4); break; case 76: return jjMoveStringLiteralDfa4_0(active0, 0x4000L); @@ -226,15 +221,15 @@ return jjMoveStringLiteralDfa4_0(active0, 0x400L); case 84: if ((active0 & 0x800L) != 0L) - return jjStartNfaWithStates_0(3, 11, 2); + return jjStartNfaWithStates_0(3, 11, 4); break; case 87: if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(3, 15, 2); + return jjStartNfaWithStates_0(3, 15, 4); break; case 89: if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(3, 16, 2); + return jjStartNfaWithStates_0(3, 16, 4); break; default : break; @@ -260,7 +255,7 @@ return jjMoveStringLiteralDfa5_0(active0, 0x2000L); case 89: if ((active0 & 0x400L) != 0L) - return jjStartNfaWithStates_0(4, 10, 2); + return jjStartNfaWithStates_0(4, 10, 4); break; default : break; @@ -304,11 +299,11 @@ return jjMoveStringLiteralDfa7_0(active0, 0x4000L); case 84: if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(6, 13, 2); + return jjStartNfaWithStates_0(6, 13, 4); break; case 89: if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(6, 18, 2); + return jjStartNfaWithStates_0(6, 18, 4); break; default : break; @@ -328,7 +323,7 @@ { case 84: if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(7, 14, 2); + return jjStartNfaWithStates_0(7, 14, 4); break; default : break; @@ -349,7 +344,7 @@ private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 14; + jjnewStateCnt = 11; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -364,19 +359,39 @@ { switch(jjstateSet[--i]) { - case 0: + case 4: + if ((0x3ff400800000000L & l) != 0L) + jjCheckNAddTwoStates(3, 4); + else if (curChar == 58) + jjCheckNAdd(5); if ((0x3ff000000000000L & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAdd(2); } + break; + case 0: + if ((0x3ff400800000000L & l) != 0L) + jjCheckNAddTwoStates(3, 4); else if (curChar == 39) - jjCheckNAdd(12); + jjCheckNAdd(9); else if ((0x8000000200000000L & l) != 0L) - jjCheckNAdd(10); + jjCheckNAdd(7); + if ((0x3ff000000000000L & l) != 0L) + { + if (kind > 20) + kind = 20; + jjCheckNAdd(2); + } break; - case 7: + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 19) + kind = 19; + jjstateSet[jjnewStateCnt++] = 1; + break; case 2: if ((0x3ff000000000000L & l) == 0L) break; @@ -384,40 +399,37 @@ kind = 20; jjCheckNAdd(2); break; - case 1: - if ((0x3ff000000000000L & l) == 0L) - break; - if (kind > 19) - kind = 19; - jjstateSet[jjnewStateCnt++] = 1; + case 3: + if ((0x3ff400800000000L & l) != 0L) + jjCheckNAddTwoStates(3, 4); break; - case 4: + case 5: if ((0x3ff400800000000L & l) == 0L) break; if (kind > 21) kind = 21; - jjstateSet[jjnewStateCnt++] = 4; + jjCheckNAdd(5); break; - case 9: + case 6: if ((0x8000000200000000L & l) != 0L) - jjCheckNAdd(10); + jjCheckNAdd(7); break; - case 10: + case 7: if ((0x3ff000000000000L & l) == 0L) break; if (kind > 22) kind = 22; - jjCheckNAdd(10); + jjCheckNAdd(7); break; - case 11: + case 8: if (curChar == 39) - jjCheckNAdd(12); + jjCheckNAdd(9); break; - case 12: + case 9: if ((0xffffff7fffffffffL & l) != 0L) - jjCheckNAddTwoStates(12, 13); + jjCheckNAddTwoStates(9, 10); break; - case 13: + case 10: if (curChar == 39 && kind > 23) kind = 23; break; @@ -432,27 +444,27 @@ { switch(jjstateSet[--i]) { - case 0: + case 4: + if ((0x7fffffe87fffffeL & l) != 0L) + jjCheckNAddTwoStates(3, 4); if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAdd(2); } - if (curChar == 83) - jjstateSet[jjnewStateCnt++] = 7; - else if (curChar == 108) - jjstateSet[jjnewStateCnt++] = 1; break; - case 7: + case 0: + if ((0x7fffffe87fffffeL & l) != 0L) + jjCheckNAddTwoStates(3, 4); if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAdd(2); } - if (curChar == 76) - jjstateSet[jjnewStateCnt++] = 6; + if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 1; break; case 2: if ((0x7fffffe07fffffeL & l) == 0L) @@ -462,36 +474,24 @@ jjCheckNAdd(2); break; case 3: - if (curChar == 95) - jjCheckNAdd(4); + if ((0x7fffffe87fffffeL & l) != 0L) + jjCheckNAddTwoStates(3, 4); break; - case 4: + case 5: if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 21) kind = 21; - jjCheckNAdd(4); + jjstateSet[jjnewStateCnt++] = 5; break; - case 5: - if (curChar == 84) - jjstateSet[jjnewStateCnt++] = 3; - break; - case 6: - if (curChar == 79) - jjstateSet[jjnewStateCnt++] = 5; - break; - case 8: - if (curChar == 83) - jjstateSet[jjnewStateCnt++] = 7; - break; - case 10: + case 7: if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 22) kind = 22; - jjstateSet[jjnewStateCnt++] = 10; + jjstateSet[jjnewStateCnt++] = 7; break; - case 12: + case 9: jjAddStates(0, 1); break; default : break; @@ -506,7 +506,7 @@ { switch(jjstateSet[--i]) { - case 12: + case 9: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(0, 1); break; @@ -521,14 +521,14 @@ kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 14 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 11 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 12, 13, + 9, 10, }; /** Token literal values. */ @@ -549,8 +549,8 @@ 0xf000000L, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[14]; -private final int[] jjstateSet = new int[28]; +private final int[] jjrounds = new int[11]; +private final int[] jjstateSet = new int[22]; protected char curChar; /** Constructor. */ public DRSParserTokenManager(SimpleCharStream stream){ @@ -577,7 +577,7 @@ { int i; jjround = 0x80000001; - for (i = 14; i-- > 0;) + for (i = 11; i-- > 0;) jjrounds[i] = 0x80000000; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-05-14 16:58:52
|
Revision: 3713 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3713&view=rev Author: christinaunger Date: 2012-05-14 16:58:45 +0000 (Mon, 14 May 2012) Log Message: ----------- [tbsl] updated DRS reader Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserConstants.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.java 2012-05-14 13:24:12 UTC (rev 3712) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.java 2012-05-14 16:58:45 UTC (rev 3713) @@ -126,7 +126,7 @@ DRS drs1; DRS drs2; if (jj_2_15(2)) { - predicate = jj_consume_token(WORD); + predicate = word(); jj_consume_token(6); dr_list = DR_List(); jj_consume_token(7); @@ -236,19 +236,31 @@ final public Token dr() throws ParseException { Token t; if (jj_2_20(2)) { - t = jj_consume_token(WORD); + t = jj_consume_token(A); } else if (jj_2_21(2)) { - t = jj_consume_token(DR); - } else if (jj_2_22(2)) { - t = jj_consume_token(QUOTED_STRING); + t = jj_consume_token(C); } else { jj_consume_token(-1); throw new ParseException(); } - {if (true) return t;} + {if (true) return t;} throw new Error("Missing return statement in function"); } + final public Token word() throws ParseException { + Token t; + if (jj_2_22(2)) { + t = jj_consume_token(A); + } else if (jj_2_23(2)) { + t = jj_consume_token(B); + } else { + jj_consume_token(-1); + throw new ParseException(); + } + {if (true) return t;} + throw new Error("Missing return statement in function"); + } + private boolean jj_2_1(int xla) { jj_la = xla; jj_lastpos = jj_scanpos = token; try { return !jj_3_1(); } @@ -403,13 +415,20 @@ finally { jj_save(21, xla); } } + private boolean jj_2_23(int xla) { + jj_la = xla; jj_lastpos = jj_scanpos = token; + try { return !jj_3_23(); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(22, xla); } + } + private boolean jj_3_2() { if (jj_3R_1()) return true; return false; } private boolean jj_3_18() { - if (jj_3R_4()) return true; + if (jj_3R_5()) return true; return false; } @@ -420,13 +439,13 @@ private boolean jj_3_19() { if (jj_scan_token(5)) return true; - if (jj_3R_5()) return true; + if (jj_3R_6()) return true; return false; } private boolean jj_3_17() { if (jj_scan_token(9)) return true; - if (jj_3R_4()) return true; + if (jj_3R_5()) return true; return false; } @@ -436,7 +455,7 @@ } private boolean jj_3R_2() { - if (jj_3R_6()) return true; + if (jj_3R_7()) return true; return false; } @@ -445,16 +464,11 @@ return false; } - private boolean jj_3R_5() { - if (jj_3R_3()) return true; + private boolean jj_3R_6() { + if (jj_3R_4()) return true; return false; } - private boolean jj_3_22() { - if (jj_scan_token(QUOTED_STRING)) return true; - return false; - } - private boolean jj_3_3() { if (jj_3R_2()) return true; return false; @@ -466,7 +480,7 @@ return false; } - private boolean jj_3R_4() { + private boolean jj_3R_5() { Token xsp; xsp = jj_scanpos; if (jj_3_1()) jj_scanpos = xsp; @@ -483,7 +497,7 @@ } private boolean jj_3_16() { - if (jj_3R_3()) return true; + if (jj_3R_4()) return true; if (jj_scan_token(8)) return true; return false; } @@ -493,8 +507,13 @@ return false; } + private boolean jj_3_23() { + if (jj_scan_token(B)) return true; + return false; + } + private boolean jj_3_21() { - if (jj_scan_token(DR)) return true; + if (jj_scan_token(C)) return true; return false; } @@ -509,7 +528,7 @@ return false; } - private boolean jj_3R_6() { + private boolean jj_3R_7() { Token xsp; xsp = jj_scanpos; if (jj_3_15()) { @@ -525,8 +544,13 @@ return false; } + private boolean jj_3_22() { + if (jj_scan_token(A)) return true; + return false; + } + private boolean jj_3_15() { - if (jj_scan_token(WORD)) return true; + if (jj_3R_3()) return true; if (jj_scan_token(6)) return true; return false; } @@ -536,37 +560,44 @@ return false; } + private boolean jj_3R_3() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_22()) { + jj_scanpos = xsp; + if (jj_3_23()) return true; + } + return false; + } + private boolean jj_3_5() { if (jj_scan_token(5)) return true; if (jj_3R_2()) return true; return false; } - private boolean jj_3_14() { - if (jj_scan_token(NO)) return true; + private boolean jj_3_20() { + if (jj_scan_token(A)) return true; return false; } - private boolean jj_3_20() { - if (jj_scan_token(WORD)) return true; + private boolean jj_3_14() { + if (jj_scan_token(NO)) return true; return false; } - private boolean jj_3R_3() { + private boolean jj_3R_4() { Token xsp; xsp = jj_scanpos; if (jj_3_20()) { jj_scanpos = xsp; - if (jj_3_21()) { - jj_scanpos = xsp; - if (jj_3_22()) return true; + if (jj_3_21()) return true; } - } return false; } private boolean jj_3R_1() { - if (jj_3R_3()) return true; + if (jj_3R_4()) return true; Token xsp; xsp = jj_scanpos; if (jj_3_4()) jj_scanpos = xsp; @@ -597,7 +628,7 @@ private static void jj_la1_init_0() { jj_la1_0 = new int[] {}; } - final private JJCalls[] jj_2_rtns = new JJCalls[22]; + final private JJCalls[] jj_2_rtns = new JJCalls[23]; private boolean jj_rescan = false; private int jj_gc = 0; @@ -781,7 +812,7 @@ /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[27]; + boolean[] la1tokens = new boolean[28]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -795,7 +826,7 @@ } } } - for (int i = 0; i < 27; i++) { + for (int i = 0; i < 28; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; @@ -822,7 +853,7 @@ private void jj_rescan_token() { jj_rescan = true; - for (int i = 0; i < 22; i++) { + for (int i = 0; i < 23; i++) { try { JJCalls p = jj_2_rtns[i]; do { @@ -851,6 +882,7 @@ case 19: jj_3_20(); break; case 20: jj_3_21(); break; case 21: jj_3_22(); break; + case 22: jj_3_23(); break; } } p = p.next; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-14 13:24:12 UTC (rev 3712) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParser.jj 2012-05-14 16:58:45 UTC (rev 3713) @@ -67,12 +67,12 @@ dr_set = new HashSet<DiscourseReferent>(); } drs = new DRS(); - if (label != null) + if (label != null) { drs.setLabel(label.toString()); } drs.setDiscourseReferents(dr_set); - if (conditions != null) + if (conditions != null) { drs.setDRSConditions(conditions); } @@ -139,7 +139,7 @@ } { - predicate=<WORD> "(" dr_list=DR_List() ")" + predicate=word() "(" dr_list=DR_List() ")" { Simple_DRS_Condition condition; @@ -224,8 +224,8 @@ return dr_list; } } - + TOKEN: {<EVERY: "EVERY">} TOKEN: {<MOST: "MOST">} @@ -242,18 +242,22 @@ TOKEN: {<NO: "NO">} -TOKEN: {<HOWMANY: "HOWMANY">} +TOKEN: {<HOWMANY: "HOWMANY">} TOKEN: {<LABEL: "l"(["0"-"9"])+>} -TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":"])+>} +//TOKEN: {<WORD: (["a"-"z","A"-"Z","_",".","#",":"])+>} +//TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} -TOKEN: {<DR: (["?","!"])?(["a"-"z","A"-"Z","0"-"9","."])+>} +TOKEN: {<A: (["a"-"z","A"-"Z","0"-"9"])+>} +TOKEN: {<B: "SLOT_"(["a"-"z","A"-"Z","_",".","#","0"-"9"])+>} +TOKEN: {<C: ["?","!"](["a"-"z","A"-"Z","0"-"9"])+>} +Token dr() : { Token t; }{ (t=<A> | t=<C>) { return t; } } +Token word() : { Token t; }{ (t=<A> | t=<B>) { return t; } } + TOKEN: {<QUOTED_STRING: "\'" (~["\'"])+ "\'" >} -Token dr() : { Token t; }{ (t=<WORD> | t=<DR> | t=<QUOTED_STRING>) { return t; } } - SKIP : { " " | "\t" | "\n" | "\r" } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserConstants.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserConstants.java 2012-05-14 13:24:12 UTC (rev 3712) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserConstants.java 2012-05-14 16:58:45 UTC (rev 3713) @@ -31,11 +31,13 @@ /** RegularExpression Id. */ int LABEL = 19; /** RegularExpression Id. */ - int WORD = 20; + int A = 20; /** RegularExpression Id. */ - int DR = 21; + int B = 21; /** RegularExpression Id. */ - int QUOTED_STRING = 22; + int C = 22; + /** RegularExpression Id. */ + int QUOTED_STRING = 23; /** Lexical state. */ int DEFAULT = 0; @@ -62,8 +64,9 @@ "\"NO\"", "\"HOWMANY\"", "<LABEL>", - "<WORD>", - "<DR>", + "<A>", + "<B>", + "<C>", "<QUOTED_STRING>", "\" \"", "\"\\t\"", Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-14 13:24:12 UTC (rev 3712) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/reader/DRSParserTokenManager.java 2012-05-14 16:58:45 UTC (rev 3713) @@ -20,15 +20,20 @@ switch (pos) { case 0: - if ((active0 & 0x2L) != 0L) + if ((active0 & 0x7ee00L) != 0L) + { + jjmatchedKind = 20; return 2; - if ((active0 & 0x7fe00L) != 0L) + } + if ((active0 & 0x1000L) != 0L) { jjmatchedKind = 20; - return 8; + return 7; } return -1; case 1: + if ((active0 & 0x20200L) != 0L) + return 2; if ((active0 & 0x5fc00L) != 0L) { if (jjmatchedPos != 1) @@ -36,47 +41,45 @@ jjmatchedKind = 20; jjmatchedPos = 1; } - return 8; + return 2; } - if ((active0 & 0x20200L) != 0L) - return 8; return -1; case 2: + if ((active0 & 0x200L) != 0L) + return 2; if ((active0 & 0x5fc00L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 2; - return 8; + return 2; } - if ((active0 & 0x200L) != 0L) - return 8; return -1; case 3: if ((active0 & 0x46400L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 3; - return 8; + return 2; } if ((active0 & 0x19800L) != 0L) - return 8; + return 2; return -1; case 4: + if ((active0 & 0x400L) != 0L) + return 2; if ((active0 & 0x46000L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 4; - return 8; + return 2; } - if ((active0 & 0x400L) != 0L) - return 8; return -1; case 5: if ((active0 & 0x46000L) != 0L) { jjmatchedKind = 20; jjmatchedPos = 5; - return 8; + return 2; } return -1; case 6: @@ -84,10 +87,10 @@ { jjmatchedKind = 20; jjmatchedPos = 6; - return 8; + return 2; } if ((active0 & 0x42000L) != 0L) - return 8; + return 2; return -1; default : return -1; @@ -114,7 +117,7 @@ case 44: return jjStopAtPos(0, 5); case 58: - return jjStartNfaWithStates_0(0, 1, 2); + return jjStopAtPos(0, 1); case 61: return jjStopAtPos(0, 8); case 65: @@ -191,7 +194,7 @@ return jjMoveStringLiteralDfa3_0(active0, 0x800L); case 84: if ((active0 & 0x200L) != 0L) - return jjStartNfaWithStates_0(2, 9, 8); + return jjStartNfaWithStates_0(2, 9, 2); break; case 87: return jjMoveStringLiteralDfa3_0(active0, 0x40000L); @@ -213,7 +216,7 @@ { case 69: if ((active0 & 0x1000L) != 0L) - return jjStartNfaWithStates_0(3, 12, 8); + return jjStartNfaWithStates_0(3, 12, 2); break; case 76: return jjMoveStringLiteralDfa4_0(active0, 0x4000L); @@ -223,15 +226,15 @@ return jjMoveStringLiteralDfa4_0(active0, 0x400L); case 84: if ((active0 & 0x800L) != 0L) - return jjStartNfaWithStates_0(3, 11, 8); + return jjStartNfaWithStates_0(3, 11, 2); break; case 87: if ((active0 & 0x8000L) != 0L) - return jjStartNfaWithStates_0(3, 15, 8); + return jjStartNfaWithStates_0(3, 15, 2); break; case 89: if ((active0 & 0x10000L) != 0L) - return jjStartNfaWithStates_0(3, 16, 8); + return jjStartNfaWithStates_0(3, 16, 2); break; default : break; @@ -257,7 +260,7 @@ return jjMoveStringLiteralDfa5_0(active0, 0x2000L); case 89: if ((active0 & 0x400L) != 0L) - return jjStartNfaWithStates_0(4, 10, 8); + return jjStartNfaWithStates_0(4, 10, 2); break; default : break; @@ -301,11 +304,11 @@ return jjMoveStringLiteralDfa7_0(active0, 0x4000L); case 84: if ((active0 & 0x2000L) != 0L) - return jjStartNfaWithStates_0(6, 13, 8); + return jjStartNfaWithStates_0(6, 13, 2); break; case 89: if ((active0 & 0x40000L) != 0L) - return jjStartNfaWithStates_0(6, 18, 8); + return jjStartNfaWithStates_0(6, 18, 2); break; default : break; @@ -325,7 +328,7 @@ { case 84: if ((active0 & 0x4000L) != 0L) - return jjStartNfaWithStates_0(7, 14, 8); + return jjStartNfaWithStates_0(7, 14, 2); break; default : break; @@ -346,7 +349,7 @@ private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 8; + jjnewStateCnt = 14; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -362,36 +365,24 @@ switch(jjstateSet[--i]) { case 0: - if ((0x3ff400000000000L & l) != 0L) + if ((0x3ff000000000000L & l) != 0L) { - if (kind > 21) - kind = 21; - jjCheckNAdd(4); - } - else if (curChar == 39) - jjCheckNAdd(6); - else if ((0x8000000200000000L & l) != 0L) - jjCheckNAdd(4); - if ((0x400400800000000L & l) != 0L) - { if (kind > 20) kind = 20; jjCheckNAdd(2); } + else if (curChar == 39) + jjCheckNAdd(12); + else if ((0x8000000200000000L & l) != 0L) + jjCheckNAdd(10); break; - case 8: - if ((0x3ff400000000000L & l) != 0L) - { - if (kind > 21) - kind = 21; - jjCheckNAdd(4); - } - if ((0x400400800000000L & l) != 0L) - { - if (kind > 20) - kind = 20; - jjCheckNAdd(2); - } + case 7: + case 2: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 20) + kind = 20; + jjCheckNAdd(2); break; case 1: if ((0x3ff000000000000L & l) == 0L) @@ -400,35 +391,35 @@ kind = 19; jjstateSet[jjnewStateCnt++] = 1; break; - case 2: - if ((0x400400800000000L & l) == 0L) + case 4: + if ((0x3ff400800000000L & l) == 0L) break; - if (kind > 20) - kind = 20; - jjCheckNAdd(2); + if (kind > 21) + kind = 21; + jjstateSet[jjnewStateCnt++] = 4; break; - case 3: + case 9: if ((0x8000000200000000L & l) != 0L) - jjCheckNAdd(4); + jjCheckNAdd(10); break; - case 4: - if ((0x3ff400000000000L & l) == 0L) + case 10: + if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 21) - kind = 21; - jjCheckNAdd(4); + if (kind > 22) + kind = 22; + jjCheckNAdd(10); break; - case 5: + case 11: if (curChar == 39) - jjCheckNAdd(6); + jjCheckNAdd(12); break; - case 6: + case 12: if ((0xffffff7fffffffffL & l) != 0L) - jjCheckNAddTwoStates(6, 7); + jjCheckNAddTwoStates(12, 13); break; - case 7: - if (curChar == 39 && kind > 22) - kind = 22; + case 13: + if (curChar == 39 && kind > 23) + kind = 23; break; default : break; } @@ -442,50 +433,65 @@ switch(jjstateSet[--i]) { case 0: - if ((0x7fffffe87fffffeL & l) != 0L) + if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAdd(2); } - if ((0x7fffffe07fffffeL & l) != 0L) - { - if (kind > 21) - kind = 21; - jjCheckNAdd(4); - } - if (curChar == 108) + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 7; + else if (curChar == 108) jjstateSet[jjnewStateCnt++] = 1; break; - case 8: - if ((0x7fffffe87fffffeL & l) != 0L) + case 7: + if ((0x7fffffe07fffffeL & l) != 0L) { if (kind > 20) kind = 20; jjCheckNAdd(2); } - if ((0x7fffffe07fffffeL & l) != 0L) - { - if (kind > 21) - kind = 21; - jjCheckNAdd(4); - } + if (curChar == 76) + jjstateSet[jjnewStateCnt++] = 6; break; case 2: - if ((0x7fffffe87fffffeL & l) == 0L) + if ((0x7fffffe07fffffeL & l) == 0L) break; if (kind > 20) kind = 20; jjCheckNAdd(2); break; + case 3: + if (curChar == 95) + jjCheckNAdd(4); + break; case 4: - if ((0x7fffffe07fffffeL & l) == 0L) + if ((0x7fffffe87fffffeL & l) == 0L) break; if (kind > 21) kind = 21; jjCheckNAdd(4); break; + case 5: + if (curChar == 84) + jjstateSet[jjnewStateCnt++] = 3; + break; case 6: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 8: + if (curChar == 83) + jjstateSet[jjnewStateCnt++] = 7; + break; + case 10: + if ((0x7fffffe07fffffeL & l) == 0L) + break; + if (kind > 22) + kind = 22; + jjstateSet[jjnewStateCnt++] = 10; + break; + case 12: jjAddStates(0, 1); break; default : break; @@ -500,7 +506,7 @@ { switch(jjstateSet[--i]) { - case 6: + case 12: if ((jjbitVec0[i2] & l2) != 0L) jjAddStates(0, 1); break; @@ -515,14 +521,14 @@ kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 8 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 14 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } } } static final int[] jjnextStates = { - 6, 7, + 12, 13, }; /** Token literal values. */ @@ -530,21 +536,21 @@ "", "\72", "\133", "\174", "\135", "\54", "\50", "\51", "\75", "\116\117\124", "\105\126\105\122\131", "\115\117\123\124", "\123\117\115\105", "\124\110\105\115\117\123\124", "\124\110\105\114\105\101\123\124", "\101\106\105\127", "\115\101\116\131", "\116\117", -"\110\117\127\115\101\116\131", null, null, null, null, null, null, null, null, }; +"\110\117\127\115\101\116\131", null, null, null, null, null, null, null, null, null, }; /** Lexer state names. */ public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0x7fffffL, + 0xffffffL, }; static final long[] jjtoSkip = { - 0x7800000L, + 0xf000000L, }; protected SimpleCharStream input_stream; -private final int[] jjrounds = new int[8]; -private final int[] jjstateSet = new int[16]; +private final int[] jjrounds = new int[14]; +private final int[] jjstateSet = new int[28]; protected char curChar; /** Constructor. */ public DRSParserTokenManager(SimpleCharStream stream){ @@ -571,7 +577,7 @@ { int i; jjround = 0x80000001; - for (i = 8; i-- > 0;) + for (i = 14; i-- > 0;) jjrounds[i] = 0x80000000; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-14 13:24:23
|
Revision: 3712 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3712&view=rev Author: lorenz_b Date: 2012-05-14 13:24:12 +0000 (Mon, 14 May 2012) Log Message: ----------- Started integration of classes for non-SOLR indexes to be more flexible in QTL and TBSL. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/impl/QueryTreeFactoryImpl.java trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrSearch.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/common/ trunk/components-ext/src/main/java/org/dllearner/common/index/ trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/datastructures/impl/QueryTreeImpl.java 2012-05-14 04:54:18 UTC (rev 3711) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/datastructures/impl/QueryTreeImpl.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -784,7 +784,7 @@ Literal l; while(iter.hasNext()){ l = iter.next(); - if(l.getDatatype() == XSDDatatype.XSDinteger){ + if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ min = (l.getInt() < min.getInt()) ? l : min; } else if(l.getDatatype() == XSDDatatype.XSDdouble){ min = (l.getDouble() < min.getDouble()) ? l : min; @@ -801,7 +801,7 @@ Literal l; while(iter.hasNext()){ l = iter.next(); - if(l.getDatatype() == XSDDatatype.XSDinteger){ + if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ max = (l.getInt() > max.getInt()) ? l : max; } else if(l.getDatatype() == XSDDatatype.XSDdouble){ max = (l.getDouble() > max.getDouble()) ? l : max; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/impl/QueryTreeFactoryImpl.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/impl/QueryTreeFactoryImpl.java 2012-05-14 04:54:18 UTC (rev 3711) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/impl/QueryTreeFactoryImpl.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -245,7 +245,10 @@ // subTree = new QueryTreeImpl<String>(lit.toString()); subTree.setId(nodeId++); subTree.setLiteralNode(true); - if(lit.getDatatype() == XSDDatatype.XSDinteger || lit.getDatatype() == XSDDatatype.XSDdouble || lit.getDatatype() == XSDDatatype.XSDdate){ + if(lit.getDatatype() == XSDDatatype.XSDinteger + || lit.getDatatype() == XSDDatatype.XSDdouble + || lit.getDatatype() == XSDDatatype.XSDdate + || lit.getDatatype() == XSDDatatype.XSDint){ subTree.addLiteral(lit); } tree.addChild(subTree, st.getPredicate().toString()); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java 2012-05-14 04:54:18 UTC (rev 3711) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -35,9 +35,11 @@ import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Triple; import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.sparql.expr.E_Equals; import com.hp.hpl.jena.sparql.expr.E_LogicalNot; import com.hp.hpl.jena.sparql.expr.ExprVar; @@ -62,6 +64,7 @@ private ExtractionDBCache selectCache; private SparqlEndpoint endpoint; + private Model model; private String query; private int limit; @@ -94,6 +97,12 @@ noSequences = new ArrayList<List<QueryTreeChange>>(); } + public NBR(Model model){ + this.model = model; + + noSequences = new ArrayList<List<QueryTreeChange>>(); + } + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds){ this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; } @@ -1385,16 +1394,22 @@ } private ResultSet executeSelectQuery(String query){ - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), query); - queryExecution.setTimeOut(maxExecutionTimeInSeconds * 1000); - for (String dgu : endpoint.getDefaultGraphURIs()) { - queryExecution.addDefaultGraph(dgu); - } - for (String ngu : endpoint.getNamedGraphURIs()) { - queryExecution.addNamedGraph(ngu); - } - ResultSet resultset = queryExecution.execSelect(); - return resultset; + ResultSet rs; + if(model == null){ + ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), query); + queryExecution.setTimeOut(maxExecutionTimeInSeconds * 1000); + for (String dgu : endpoint.getDefaultGraphURIs()) { + queryExecution.addDefaultGraph(dgu); + } + for (String ngu : endpoint.getNamedGraphURIs()) { + queryExecution.addNamedGraph(ngu); + } + rs = queryExecution.execSelect(); + } else { + rs = QueryExecutionFactory.create(query, model).execSelect(); + } + + return rs; } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-05-14 04:54:18 UTC (rev 3711) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -11,6 +11,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -18,6 +19,10 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.apache.log4j.Logger; import org.dllearner.algorithm.qtl.util.ModelGenerator; @@ -37,7 +42,6 @@ import org.dllearner.algorithm.tbsl.sparql.RatedQuery; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Prefix; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -60,14 +64,36 @@ import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; +import com.hp.hpl.jena.graph.Triple; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.sparql.core.Var; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.sparql.syntax.Element; +import com.hp.hpl.jena.sparql.syntax.ElementAssign; +import com.hp.hpl.jena.sparql.syntax.ElementBind; +import com.hp.hpl.jena.sparql.syntax.ElementDataset; +import com.hp.hpl.jena.sparql.syntax.ElementExists; +import com.hp.hpl.jena.sparql.syntax.ElementFetch; +import com.hp.hpl.jena.sparql.syntax.ElementFilter; +import com.hp.hpl.jena.sparql.syntax.ElementGroup; +import com.hp.hpl.jena.sparql.syntax.ElementMinus; +import com.hp.hpl.jena.sparql.syntax.ElementNamedGraph; +import com.hp.hpl.jena.sparql.syntax.ElementNotExists; +import com.hp.hpl.jena.sparql.syntax.ElementOptional; +import com.hp.hpl.jena.sparql.syntax.ElementPathBlock; +import com.hp.hpl.jena.sparql.syntax.ElementService; +import com.hp.hpl.jena.sparql.syntax.ElementSubQuery; +import com.hp.hpl.jena.sparql.syntax.ElementTriplesBlock; +import com.hp.hpl.jena.sparql.syntax.ElementUnion; +import com.hp.hpl.jena.sparql.syntax.ElementVisitor; import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -667,10 +693,29 @@ logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); - for(Slot slot : t.getSlots()){ + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); + List<Future<SortedSet<Allocation>>> list = new ArrayList<Future<SortedSet<Allocation>>>(); + + for (Slot slot : t.getSlots()) { + Callable<SortedSet<Allocation>> worker = new SlotProcessor(slot); + Future<SortedSet<Allocation>> submit = executor.submit(worker); + list.add(submit); + } + +// for (Future<SortedSet<Allocation>> future : list) { +// try { +// future.get(); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } catch (ExecutionException e) { +// e.printStackTrace(); +// } +// } + + /*for(Slot slot : t.getSlots()){ allocations = slot2Allocations2.get(slot); if(allocations == null){ - allocations = computeAllocations(slot, 20); + allocations = computeAllocations(slot, 10); slot2Allocations2.put(slot, allocations); } slot2Allocations.put(slot, allocations); @@ -687,7 +732,7 @@ } } allocations.addAll(tmp); - } + }*/ Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); @@ -868,7 +913,7 @@ if(slot.getSlotType() == SlotType.RESOURCE){ rs = index.getResourcesWithScores(word, 250); } else { - rs = index.getResourcesWithScores(word, 30); + rs = index.getResourcesWithScores(word, 20); } @@ -1514,7 +1559,7 @@ * @throws InvalidFileFormatException */ public static void main(String[] args) throws NoTemplateFoundException, InvalidFileFormatException, FileNotFoundException, IOException { -// Logger.getLogger(DefaultHttpParams.class).setLevel(Level.OFF); + // Logger.getLogger(DefaultHttpParams.class).setLevel(Level.OFF); // Logger.getLogger(HttpClient.class).setLevel(Level.OFF); // Logger.getLogger(HttpMethodBase.class).setLevel(Level.OFF); // String question = "Who/WP was/VBD the/DT wife/NN of/IN president/NN Lincoln/NNP"; @@ -1578,7 +1623,22 @@ // TODO Auto-generated method stub } + + class SlotProcessor implements Callable<SortedSet<Allocation>>{ + + private Slot slot; + + public SlotProcessor(Slot slot) { + this.slot = slot; + } + @Override + public SortedSet<Allocation> call() throws Exception { + return computeAllocations(slot); + } + + } + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrSearch.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrSearch.java 2012-05-14 04:54:18 UTC (rev 3711) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/search/SolrSearch.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -165,7 +165,13 @@ lastTotalHits = (int) docList.getNumFound(); for(SolrDocument d : docList){ - items.add(new SolrQueryResultItem((String) d.get(labelField), (String) d.get("uri"), (Float) d.get("score"))); + float score = 0; + if(d.get("score") instanceof ArrayList){ + score = ((Float)((ArrayList)d.get("score")).get(1)); + } else { + score = (Float) d.get("score"); + } + items.add(new SolrQueryResultItem((String) d.get(labelField), (String) d.get("uri"), score)); } } catch (SolrServerException e) { e.printStackTrace(); @@ -183,4 +189,8 @@ this.hitsPerPage = hitsPerPage; } + public static void main(String[] args) { + new SolrSearch("http://139.18.2.173:8080/apache-solr-3.3.0/dbpedia_classes").getResources("Leipzig"); + } + } Added: trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -0,0 +1,9 @@ +package org.dllearner.common.index; + +import java.util.List; + +public interface Index { + List<String> getResources(String queryString); + List<String> getResources(String queryString, int limit); + List<String> getResources(String queryString, int limit, int offset); +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -0,0 +1,61 @@ +package org.dllearner.common.index; + +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.BinaryRequestWriter; +import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrDocumentList; +import org.apache.solr.common.params.ModifiableSolrParams; + +public class SOLRIndex implements Index{ + +private CommonsHttpSolrServer server; + + private static final int DEFAULT_LIMIT = 10; + private static final int DEFAULT_OFFSET = 0; + + public SOLRIndex(String solrServerURL){ + try { + server = new CommonsHttpSolrServer(solrServerURL); + server.setRequestWriter(new BinaryRequestWriter()); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + @Override + public List<String> getResources(String queryString) { + return getResources(queryString, DEFAULT_LIMIT); + } + + @Override + public List<String> getResources(String queryString, int limit) { + return getResources(queryString, limit, DEFAULT_OFFSET); + } + + @Override + public List<String> getResources(String queryString, int limit, int offset) { + List<String> resources = new ArrayList<String>(); + QueryResponse response; + try { + ModifiableSolrParams params = new ModifiableSolrParams(); + params.set("q", queryString); + params.set("rows", limit); + params.set("start", offset); + response = server.query(params); + SolrDocumentList docList = response.getResults(); + for(SolrDocument d : docList){ + resources.add((String) d.get("uri")); + } + } catch (SolrServerException e) { + e.printStackTrace(); + } + return resources; + } + +} Added: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-05-14 13:24:12 UTC (rev 3712) @@ -0,0 +1,90 @@ +package org.dllearner.common.index; + +import java.util.ArrayList; +import java.util.List; + +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; + +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; + +public class SPARQLIndex implements Index{ + + private static final int DEFAULT_LIMIT = 10; + private static final int DEFAULT_OFFSET = 0; + + private SparqlEndpoint endpoint; + private ExtractionDBCache cache; + + private Model model; + + protected String queryTemplate = "SELECT DISTINCT(?uri) WHERE {\n" + + "?uri a ?type.\n" + + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + + "FILTER(REGEX(STR(?label), '%s'))}\n" + + "LIMIT %d OFFSET %d"; + + + public SPARQLIndex(SparqlEndpoint endpoint) { + this(endpoint, null); + } + + public SPARQLIndex(Model model) { + this.model = model; + } + + public SPARQLIndex(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + } + + @Override + public List<String> getResources(String queryString) { + return getResources(queryString, DEFAULT_LIMIT); + } + + @Override + public List<String> getResources(String queryString, int limit) { + return getResources(queryString, limit, DEFAULT_OFFSET); + } + + @Override + public List<String> getResources(String queryString, int limit, int offset) { + List<String> resources = new ArrayList<String>(); + + String query = buildResourcesQuery(queryString, limit, offset); + + ResultSet rs; + if(model == null){ + if(cache == null){ + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), queryString); + qe.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + rs = qe.execSelect(); + } else { + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + } + } else { + rs = QueryExecutionFactory.create(queryString, model).execSelect(); + } + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + RDFNode uriNode = qs.get("uri"); + if(uriNode.isURIResource()){ + resources.add(uriNode.asResource().getURI()); + } + } + return resources; + } + + protected String buildResourcesQuery(String searchTerm, int limit, int offset){ + return String.format(queryTemplate, searchTerm, limit, offset); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-14 04:54:24
|
Revision: 3711 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3711&view=rev Author: tcanvn Date: 2012-05-14 04:54:18 +0000 (Mon, 14 May 2012) Log Message: ----------- Correct the wrong learning configuration file path in the CarcinoGenesis JUnit test Modified Paths: -------------- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java Modified: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java 2012-05-14 04:07:58 UTC (rev 3710) +++ trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java 2012-05-14 04:54:18 UTC (rev 3711) @@ -15,7 +15,7 @@ @Override public String getConfigurationFilePath() { - return "../examples/carcinogenesis/carcinogenesis_pdll.conf"; + return "../examples/carcinogenesis/carcinogenesis_padcel.conf"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-14 04:08:04
|
Revision: 3710 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3710&view=rev Author: tcanvn Date: 2012-05-14 04:07:58 +0000 (Mon, 14 May 2012) Log Message: ----------- Move some commons methods of the PADCEL algorithms family into the abstract class PADCELAbstract Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-14 04:04:43 UTC (rev 3709) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-14 04:07:58 UTC (rev 3710) @@ -6,7 +6,9 @@ import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; /** * Abstract class for all PDL-Learner algorithms family @@ -16,6 +18,25 @@ */ public abstract class PADCELAbstract extends AbstractCELA { + // ---------------------------------- + // configuration options + // ---------------------------------- + @ConfigOption(name = "numberOfWorkers", defaultValue = "2", description = "This option is used to set the number of workers will be created to serve the leaner. This should be = 2 * total number of cores of CPUs") + protected int numberOfWorkers = 4; // max number of workers will be created + + @ConfigOption(name = "maxExecutionTimeInSeconds", defaultValue = "0", description = "maximum execution of the algorithm in seconds") + protected int maxExecutionTimeInSeconds = 0; + + @ConfigOption(name = "noisePercentage", defaultValue = "0.0", description = "The percentage of noise within the examples") + protected double noisePercentage = 0.0; + + @ConfigOption(name = "maxNoOfSplits", defaultValue = "10", description = "Max number of splits will be applied for data properties with double range") + protected int maxNoOfSplits = 10; + + @ConfigOption(name = "ignoredConcepts", defaultValue = "", description = "set of concepts that will be ignored in learning the target concept") + protected Set<NamedClass> ignoredConcepts = null; + + /** * All generated descriptions thread-safe set is used to avoid concurrently * accessing @@ -71,4 +92,51 @@ return this.partialDefinitions.size(); } + + // ------------------------------------------------ + // setters and getters for configuration options + // ------------------------------------------------ + + public void setNumberOfWorkers(int numberOfWorkers) { + this.numberOfWorkers = numberOfWorkers; + } + + public int getNumberOfWorkers() { + return numberOfWorkers; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTime) { + this.maxExecutionTimeInSeconds = maxExecutionTime; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setNoisePercentage(double noise) { + this.noisePercentage = noise; + } + + public double getNoisePercentage() { + return this.noisePercentage; + } + + + public int getMaxNoOfSplits() { + return maxNoOfSplits; + } + + public void setMaxNoOfSplits(int maxNoOfSplits) { + this.maxNoOfSplits = maxNoOfSplits; + } + + public Set<NamedClass> getIgnoredConcepts() { + return ignoredConcepts; + } + + public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { + this.ignoredConcepts = ignoredConcepts; + } + + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java 2012-05-14 04:04:43 UTC (rev 3709) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java 2012-05-14 04:07:58 UTC (rev 3710) @@ -39,7 +39,6 @@ import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; @@ -52,30 +51,12 @@ import org.dllearner.utilities.owl.EvaluatedDescriptionComparator; import org.springframework.beans.factory.annotation.Autowired; -@ComponentAnn(name = "PDCCEL", shortName = "PDCCEL", version = 0.1, description = "Parallel and Devide&Conquer Class Exprerssion Learner") +@ComponentAnn(name = "PADCEL", shortName = "PADCEL", version = 0.1, description = "Parallel and Devide&Conquer Exprerssion Learning") public class PADCELearner extends PADCELAbstract implements PADCELearnerMBean { - // ---------------------------------- - // configuration options - // ---------------------------------- - @ConfigOption(name = "numberOfWorkers", defaultValue = "2", description = "This option is used to set the number of workers will be created to serve the leaner. This should be = 2 * total number of cores of CPUs") - private int numberOfWorkers = 4; // max number of workers will be created - @ConfigOption(name = "maxExecutionTimeInSeconds", defaultValue = "0", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = 0; + private RefinementOperator refinementOperator = null; - @ConfigOption(name = "noisePercentage", defaultValue = "0.0", description = "The percentage of noise within the examples") - private double noisePercentage = 0.0; - - @ConfigOption(name = "maxNoOfSplits", defaultValue = "10", description = "Max number of splits will be applied for data properties with double range") - private int maxNoOfSplits = 10; - - // set of concepts that will not be used in learning the target concept - private Set<NamedClass> ignoredConcepts = null; - - private RefinementOperator refinementOperator = null; // auto-wired will be used for this - // property - private PADCELDoubleSplitterAbstract splitter = null; private static Logger logger = Logger.getLogger(PADCELearner.class); @@ -671,6 +652,7 @@ //wait until all workers are terminated try { + //System.out.println("-------------Waiting for worker pool----------------"); workerPool.awaitTermination(0, TimeUnit.SECONDS); } catch (InterruptedException ie) { @@ -872,34 +854,6 @@ return miliLearningTime; } - // ------------------------------------------------ - // setters and getters for configuration options - // ------------------------------------------------ - - public void setNumberOfWorkers(int numberOfWorkers) { - this.numberOfWorkers = numberOfWorkers; - } - - public int getNumberOfWorkers() { - return numberOfWorkers; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTime) { - this.maxExecutionTimeInSeconds = maxExecutionTime; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setNoisePercentage(double noise) { - this.noisePercentage = noise; - } - - public double getNoisePercentage() { - return this.noisePercentage; - } - @Autowired(required = false) public void setRefinementOperator(RefinementOperator refinementOp) { this.refinementOperator = refinementOp; @@ -914,25 +868,10 @@ this.splitter = splitter; } - public int getMaxNoOfSplits() { - return maxNoOfSplits; - } - - public void setMaxNoOfSplits(int maxNoOfSplits) { - this.maxNoOfSplits = maxNoOfSplits; - } - - public Set<NamedClass> getIgnoredConcepts() { - return ignoredConcepts; - } - - public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { - this.ignoredConcepts = ignoredConcepts; - } - public int getNoOfCompactedPartialDefinition() { return this.noOfCompactedPartialDefinition; } + // =============== MBean section ===================== public int getActiveCount() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-14 04:04:50
|
Revision: 3709 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3709&view=rev Author: tcanvn Date: 2012-05-14 04:04:43 +0000 (Mon, 14 May 2012) Log Message: ----------- Rename the PADCEL cross validation class (PDLLCrossValidation.java --> PADCELCrossValidation.java) Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java Removed Paths: ------------- trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-05-14 04:00:47 UTC (rev 3708) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-05-14 04:04:43 UTC (rev 3709) @@ -120,7 +120,7 @@ //this test is added for PDLL algorithm since it does not use the PosNegLP try { PADCELPosNegLP lp = context.getBean(PADCELPosNegLP.class); - new PDLLCrossValidation(la, lp, rs, nrOfFolds, false); + new PADCELCrossValidation(la, lp, rs, nrOfFolds, false); } catch (BeansException be) { PosNegLP lp = context.getBean(PosNegLP.class); Copied: trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java (from rev 3708, trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java) =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java 2012-05-14 04:04:43 UTC (rev 3709) @@ -0,0 +1,320 @@ +package org.dllearner.cli; + +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.PADCEL.PADCELAbstract; +import org.dllearner.algorithms.PADCEL.PADCELPosNegLP; +import org.dllearner.algorithms.PADCELEx.PADCELExAbstract; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.Heuristics; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.utilities.Files; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.statistics.Stat; + +/** + * Add PDLL cross validation support to Jens Lehmann work ( + * {@link org.dllearner.cli.CrossValidation}). In this cross validation, + * some more addition dimensions will be investigated such as: + * number partial definitions, partial definition length, etc. + * + * + * @author actran + * + */ + +public class PADCELCrossValidation extends CrossValidation { + + protected Stat noOfPartialDef = new Stat(); + protected Stat partialDefinitionLength = new Stat(); + + Logger logger = Logger.getLogger(this.getClass()); + + protected boolean interupted = false; + + /** + * Default constructor + */ + + public PADCELCrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, + int folds, boolean leaveOneOut) { + super(la, lp, rs, folds, leaveOneOut); + } + + /** + * This is for PDLL cross validation + * + * @param la + * @param lp + * @param rs + * @param folds + * @param leaveOneOut + */ + public PADCELCrossValidation(AbstractCELA la, PADCELPosNegLP lp, AbstractReasonerComponent rs, + int folds, boolean leaveOneOut) { + + super(); // do nothing + + DecimalFormat df = new DecimalFormat(); + + // the training and test sets used later on + List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); + + // get examples and shuffle them too + Set<Individual> posExamples = lp.getPositiveExamples(); + List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); + Collections.shuffle(posExamplesList, new Random(1)); + Set<Individual> negExamples = lp.getNegativeExamples(); + List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); + Collections.shuffle(negExamplesList, new Random(2)); + + // sanity check whether nr. of folds makes sense for this benchmark + if (!leaveOneOut && (posExamples.size() < folds && negExamples.size() < folds)) { + System.out.println("The number of folds is higher than the number of " + + "positive/negative examples. This can result in empty test sets. Exiting."); + System.exit(0); + } + + if (leaveOneOut) { + // note that leave-one-out is not identical to k-fold with + // k = nr. of examples in the current implementation, because + // with n folds and n examples there is no guarantee that a fold + // is never empty (this is an implementation issue) + int nrOfExamples = posExamples.size() + negExamples.size(); + for (int i = 0; i < nrOfExamples; i++) { + // ... + } + System.out.println("Leave-one-out not supported yet."); + System.exit(1); + } else { + // calculating where to split the sets, ; note that we split + // positive and negative examples separately such that the + // distribution of positive and negative examples remains similar + // (note that there are better but more complex ways to implement + // this, + // which guarantee that the sum of the elements of a fold for pos + // and neg differs by at most 1 - it can differ by 2 in our + // implementation, + // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) + int[] splitsPos = calculateSplits(posExamples.size(), folds); + int[] splitsNeg = calculateSplits(negExamples.size(), folds); + + // System.out.println(splitsPos[0]); + // System.out.println(splitsNeg[0]); + + // calculating training and test sets + for (int i = 0; i < folds; i++) { + Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); + Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); + testSetsPos.add(i, testPos); + testSetsNeg.add(i, testNeg); + trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); + trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); + } + + } + + // run the algorithm + int terminatedBypartialDefinition = 0, terminatedByCounterPartialDefinitions = 0; + + for (int currFold = 0; (currFold < folds); currFold++) { + + if (this.interupted) { + outputWriter("Cross validation has been interupted"); + return; + } + + // Set<String> pos = + // Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); + // Set<String> neg = + // Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); + lp.setPositiveExamples(trainingSetsPos.get(currFold)); + lp.setNegativeExamples(trainingSetsNeg.get(currFold)); + + try { + lp.init(); + la.init(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + + long algorithmStartTime = System.nanoTime(); + try { + la.start(); + } catch (OutOfMemoryError e) { + System.out.println("out of memory at " + + (System.currentTimeMillis() - algorithmStartTime) / 1000 + "s"); + } + + long algorithmDuration = System.nanoTime() - algorithmStartTime; + runtime.addNumber(algorithmDuration / (double) 1000000000); + + Description concept = ((PADCELAbstract) la).getUnionCurrenlyBestDescription(); + + Set<Individual> tmp = rs.hasType(concept, trainingSetsPos.get(currFold)); + Set<Individual> tmp2 = Helper.difference(trainingSetsPos.get(currFold), tmp); + Set<Individual> tmp3 = rs.hasType(concept, trainingSetsNeg.get(currFold)); + + outputWriter("training set errors pos (" + tmp2.size() + "): " + tmp2); + outputWriter("training set errors neg (" + tmp3.size() + "): " + tmp3); + + tmp = rs.hasType(concept, testSetsPos.get(currFold)); + tmp2 = Helper.difference(testSetsPos.get(currFold), tmp); + tmp3 = rs.hasType(concept, testSetsNeg.get(currFold)); + + outputWriter("test set errors pos: " + tmp2); + outputWriter("test set errors neg: " + tmp3); + + // calculate training accuracies + int trainingCorrectPosClassified = getCorrectPosClassified(rs, concept, + trainingSetsPos.get(currFold)); + int trainingCorrectNegClassified = getCorrectNegClassified(rs, concept, + trainingSetsNeg.get(currFold)); + int trainingCorrectExamples = trainingCorrectPosClassified + + trainingCorrectNegClassified; + double trainingAccuracy = 100 * ((double) trainingCorrectExamples / (trainingSetsPos + .get(currFold).size() + trainingSetsNeg.get(currFold).size())); + + double trainingCompleteness = 100 * (double) trainingCorrectPosClassified + / trainingSetsPos.get(currFold).size(); + double trainingCorrectness = 100 * (double) trainingCorrectNegClassified + / trainingSetsNeg.get(currFold).size(); + + accuracyTraining.addNumber(trainingAccuracy); + trainingCompletenessStat.addNumber(trainingCompleteness); + trainingCorrectnessStat.addNumber(trainingCorrectness); + + // calculate test accuracies + int correctPosClassified = getCorrectPosClassified(rs, concept, + testSetsPos.get(currFold)); + int correctNegClassified = getCorrectNegClassified(rs, concept, + testSetsNeg.get(currFold)); + int correctExamples = correctPosClassified + correctNegClassified; + double currAccuracy = 100 * ((double) correctExamples / (testSetsPos.get(currFold) + .size() + testSetsNeg.get(currFold).size())); + + double testingCompleteness = 100 * (double) correctPosClassified + / testSetsPos.get(currFold).size(); + double testingCorrectness = 100 * (double) correctNegClassified + / testSetsNeg.get(currFold).size(); + + accuracy.addNumber(currAccuracy); + testingCompletenessStat.addNumber(testingCompleteness); + testingCorrectnessStat.addNumber(testingCorrectness); + + // calculate training F-Score + int negAsPosTraining = rs.hasType(concept, trainingSetsNeg.get(currFold)).size(); + double precisionTraining = trainingCorrectPosClassified + negAsPosTraining == 0 ? 0 + : trainingCorrectPosClassified + / (double) (trainingCorrectPosClassified + negAsPosTraining); + double recallTraining = trainingCorrectPosClassified + / (double) trainingSetsPos.get(currFold).size(); + fMeasureTraining.addNumber(100 * Heuristics + .getFScore(recallTraining, precisionTraining)); + // calculate test F-Score + int negAsPos = rs.hasType(concept, testSetsNeg.get(currFold)).size(); + double precision = correctPosClassified + negAsPos == 0 ? 0 : correctPosClassified + / (double) (correctPosClassified + negAsPos); + double recall = correctPosClassified / (double) testSetsPos.get(currFold).size(); + // System.out.println(precision);System.out.println(recall); + fMeasure.addNumber(100 * Heuristics.getFScore(recall, precision)); + + length.addNumber(concept.getLength()); + + outputWriter("fold " + currFold + ":"); + outputWriter(" training: " + trainingCorrectPosClassified + "/" + + trainingSetsPos.get(currFold).size() + " positive and " + + trainingCorrectNegClassified + "/" + trainingSetsNeg.get(currFold).size() + + " negative examples"); + outputWriter(" testing: " + correctPosClassified + "/" + + testSetsPos.get(currFold).size() + " correct positives, " + + correctNegClassified + "/" + testSetsNeg.get(currFold).size() + + " correct negatives"); + outputWriter(" concept: " + concept); + outputWriter(" accuracy: " + df.format(currAccuracy) + "% (correctness: " + + df.format(testingCorrectness) + "%; completeness: " + + df.format(testingCompleteness) + "%) --- training set: " + + df.format(trainingAccuracy) + "% (correctness: " + + df.format(trainingCorrectness) + "%; completeness: " + + df.format(trainingCompleteness) + "%)"); + outputWriter(" length: " + df.format(concept.getLength())); + outputWriter(" runtime: " + df.format(algorithmDuration / (double) 1000000000) + "s"); + + if (la instanceof PADCELAbstract) { + int pn = ((PADCELAbstract) la).getNoOfCompactedPartialDefinition(); + this.noOfPartialDef.addNumber(pn); + outputWriter(" number of partial definitions: " + pn + " (total: " + + ((PADCELAbstract) la).getNumberOfPartialDefinitions() + ")"); + + double pl = concept.getLength() / (double) pn; + this.partialDefinitionLength.addNumber(pl); + outputWriter(" avarage partial definition length: " + df.format(pl)); + + // show more information on counter partial definitions + if (la instanceof PADCELExAbstract) { + PADCELExAbstract pdllexla = (PADCELExAbstract) la; + outputWriter(" number of partial definitions for each type: 1:" + + pdllexla.getNumberOfPartialDefinitions(1) + "; 2:" + + pdllexla.getNumberOfPartialDefinitions(2) + "; 3:" + + pdllexla.getNumberOfPartialDefinitions(3) + "; 4:" + + pdllexla.getNumberOfPartialDefinitions(4)); + outputWriter(" number of counter partial definition used: " + + (concept.toString().split("NOT ").length - 1) + "/" + + pdllexla.getNumberOfCounterPartialDefinitionUsed()); + if (pdllexla.terminatedByCounterDefinitions()) { + outputWriter(" terminated by counter partial definitions"); + terminatedByCounterPartialDefinitions++; + } else if (pdllexla.terminatedByPartialDefinitions()) { + outputWriter(" terminated by partial definitions"); + terminatedBypartialDefinition++; + } else + outputWriter(" neither terminated by partial definition nor counter partial definition"); + } + } + + } + + outputWriter(""); + outputWriter("Finished " + folds + "-folds cross-validation."); + outputWriter("runtime: " + statOutput(df, runtime, "s")); + outputWriter("#partial definitions: " + statOutput(df, noOfPartialDef, "")); + outputWriter("avg. partial definition length: " + + statOutput(df, partialDefinitionLength, "")); + outputWriter("length: " + statOutput(df, length, "")); + outputWriter("F-Measure on training set: " + statOutput(df, fMeasureTraining, "%")); + outputWriter("F-Measure: " + statOutput(df, fMeasure, "%")); + outputWriter("predictive accuracy on training set: " + + statOutput(df, accuracyTraining, "%") + " --- correctness: " + + statOutput(df, trainingCorrectnessStat, "%") + "; completeness: " + + statOutput(df, trainingCompletenessStat, "%")); + outputWriter("predictive accuracy: " + statOutput(df, accuracy, "%") + " --- correctness: " + + statOutput(df, testingCorrectnessStat, "%") + "; completeness: " + + statOutput(df, testingCompletenessStat, "%")); + if (la instanceof PADCELExAbstract) + outputWriter("terminated by: partial def.: " + terminatedBypartialDefinition + + "; counter partial def.: " + terminatedByCounterPartialDefinitions); + } + + @Override + protected void outputWriter(String output) { + logger.info(output); + + if (writeToFile) + Files.appendToFile(outputFile, output + "\n"); + } + +} Property changes on: trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java 2012-05-14 04:00:47 UTC (rev 3708) +++ trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java 2012-05-14 04:04:43 UTC (rev 3709) @@ -1,320 +0,0 @@ -package org.dllearner.cli; - -import java.text.DecimalFormat; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Set; - - -import org.apache.log4j.Logger; -import org.dllearner.algorithms.PADCEL.PADCELAbstract; -import org.dllearner.algorithms.PADCEL.PADCELPosNegLP; -import org.dllearner.algorithms.PADCELEx.PADCELExAbstract; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; -import org.dllearner.learningproblems.Heuristics; -import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.utilities.Files; -import org.dllearner.utilities.Helper; -import org.dllearner.utilities.statistics.Stat; - -/** - * Add PDLL cross validation support to Jens Lehmann work ( - * {@link org.dllearner.cli.CrossValidation}). In this cross validation, - * some more addition dimensions will be investigated such as: - * number partial definitions, partial definition length, etc. - * - * - * @author actran - * - */ - -public class PDLLCrossValidation extends CrossValidation { - - protected Stat noOfPartialDef = new Stat(); - protected Stat partialDefinitionLength = new Stat(); - - Logger logger = Logger.getLogger(this.getClass()); - - protected boolean interupted = false; - - /** - * Default constructor - */ - - public PDLLCrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, - int folds, boolean leaveOneOut) { - super(la, lp, rs, folds, leaveOneOut); - } - - /** - * This is for PDLL cross validation - * - * @param la - * @param lp - * @param rs - * @param folds - * @param leaveOneOut - */ - public PDLLCrossValidation(AbstractCELA la, PADCELPosNegLP lp, AbstractReasonerComponent rs, - int folds, boolean leaveOneOut) { - - super(); // do nothing - - DecimalFormat df = new DecimalFormat(); - - // the training and test sets used later on - List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); - List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); - List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); - List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); - - // get examples and shuffle them too - Set<Individual> posExamples = lp.getPositiveExamples(); - List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); - Collections.shuffle(posExamplesList, new Random(1)); - Set<Individual> negExamples = lp.getNegativeExamples(); - List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); - Collections.shuffle(negExamplesList, new Random(2)); - - // sanity check whether nr. of folds makes sense for this benchmark - if (!leaveOneOut && (posExamples.size() < folds && negExamples.size() < folds)) { - System.out.println("The number of folds is higher than the number of " - + "positive/negative examples. This can result in empty test sets. Exiting."); - System.exit(0); - } - - if (leaveOneOut) { - // note that leave-one-out is not identical to k-fold with - // k = nr. of examples in the current implementation, because - // with n folds and n examples there is no guarantee that a fold - // is never empty (this is an implementation issue) - int nrOfExamples = posExamples.size() + negExamples.size(); - for (int i = 0; i < nrOfExamples; i++) { - // ... - } - System.out.println("Leave-one-out not supported yet."); - System.exit(1); - } else { - // calculating where to split the sets, ; note that we split - // positive and negative examples separately such that the - // distribution of positive and negative examples remains similar - // (note that there are better but more complex ways to implement - // this, - // which guarantee that the sum of the elements of a fold for pos - // and neg differs by at most 1 - it can differ by 2 in our - // implementation, - // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) - int[] splitsPos = calculateSplits(posExamples.size(), folds); - int[] splitsNeg = calculateSplits(negExamples.size(), folds); - - // System.out.println(splitsPos[0]); - // System.out.println(splitsNeg[0]); - - // calculating training and test sets - for (int i = 0; i < folds; i++) { - Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); - Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); - testSetsPos.add(i, testPos); - testSetsNeg.add(i, testNeg); - trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); - trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); - } - - } - - // run the algorithm - int terminatedBypartialDefinition = 0, terminatedByCounterPartialDefinitions = 0; - - for (int currFold = 0; (currFold < folds); currFold++) { - - if (this.interupted) { - outputWriter("Cross validation has been interupted"); - return; - } - - // Set<String> pos = - // Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); - // Set<String> neg = - // Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); - lp.setPositiveExamples(trainingSetsPos.get(currFold)); - lp.setNegativeExamples(trainingSetsNeg.get(currFold)); - - try { - lp.init(); - la.init(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } - - long algorithmStartTime = System.nanoTime(); - try { - la.start(); - } catch (OutOfMemoryError e) { - System.out.println("out of memory at " - + (System.currentTimeMillis() - algorithmStartTime) / 1000 + "s"); - } - - long algorithmDuration = System.nanoTime() - algorithmStartTime; - runtime.addNumber(algorithmDuration / (double) 1000000000); - - Description concept = ((PADCELAbstract) la).getUnionCurrenlyBestDescription(); - - Set<Individual> tmp = rs.hasType(concept, trainingSetsPos.get(currFold)); - Set<Individual> tmp2 = Helper.difference(trainingSetsPos.get(currFold), tmp); - Set<Individual> tmp3 = rs.hasType(concept, trainingSetsNeg.get(currFold)); - - outputWriter("training set errors pos (" + tmp2.size() + "): " + tmp2); - outputWriter("training set errors neg (" + tmp3.size() + "): " + tmp3); - - tmp = rs.hasType(concept, testSetsPos.get(currFold)); - tmp2 = Helper.difference(testSetsPos.get(currFold), tmp); - tmp3 = rs.hasType(concept, testSetsNeg.get(currFold)); - - outputWriter("test set errors pos: " + tmp2); - outputWriter("test set errors neg: " + tmp3); - - // calculate training accuracies - int trainingCorrectPosClassified = getCorrectPosClassified(rs, concept, - trainingSetsPos.get(currFold)); - int trainingCorrectNegClassified = getCorrectNegClassified(rs, concept, - trainingSetsNeg.get(currFold)); - int trainingCorrectExamples = trainingCorrectPosClassified - + trainingCorrectNegClassified; - double trainingAccuracy = 100 * ((double) trainingCorrectExamples / (trainingSetsPos - .get(currFold).size() + trainingSetsNeg.get(currFold).size())); - - double trainingCompleteness = 100 * (double) trainingCorrectPosClassified - / trainingSetsPos.get(currFold).size(); - double trainingCorrectness = 100 * (double) trainingCorrectNegClassified - / trainingSetsNeg.get(currFold).size(); - - accuracyTraining.addNumber(trainingAccuracy); - trainingCompletenessStat.addNumber(trainingCompleteness); - trainingCorrectnessStat.addNumber(trainingCorrectness); - - // calculate test accuracies - int correctPosClassified = getCorrectPosClassified(rs, concept, - testSetsPos.get(currFold)); - int correctNegClassified = getCorrectNegClassified(rs, concept, - testSetsNeg.get(currFold)); - int correctExamples = correctPosClassified + correctNegClassified; - double currAccuracy = 100 * ((double) correctExamples / (testSetsPos.get(currFold) - .size() + testSetsNeg.get(currFold).size())); - - double testingCompleteness = 100 * (double) correctPosClassified - / testSetsPos.get(currFold).size(); - double testingCorrectness = 100 * (double) correctNegClassified - / testSetsNeg.get(currFold).size(); - - accuracy.addNumber(currAccuracy); - testingCompletenessStat.addNumber(testingCompleteness); - testingCorrectnessStat.addNumber(testingCorrectness); - - // calculate training F-Score - int negAsPosTraining = rs.hasType(concept, trainingSetsNeg.get(currFold)).size(); - double precisionTraining = trainingCorrectPosClassified + negAsPosTraining == 0 ? 0 - : trainingCorrectPosClassified - / (double) (trainingCorrectPosClassified + negAsPosTraining); - double recallTraining = trainingCorrectPosClassified - / (double) trainingSetsPos.get(currFold).size(); - fMeasureTraining.addNumber(100 * Heuristics - .getFScore(recallTraining, precisionTraining)); - // calculate test F-Score - int negAsPos = rs.hasType(concept, testSetsNeg.get(currFold)).size(); - double precision = correctPosClassified + negAsPos == 0 ? 0 : correctPosClassified - / (double) (correctPosClassified + negAsPos); - double recall = correctPosClassified / (double) testSetsPos.get(currFold).size(); - // System.out.println(precision);System.out.println(recall); - fMeasure.addNumber(100 * Heuristics.getFScore(recall, precision)); - - length.addNumber(concept.getLength()); - - outputWriter("fold " + currFold + ":"); - outputWriter(" training: " + trainingCorrectPosClassified + "/" - + trainingSetsPos.get(currFold).size() + " positive and " - + trainingCorrectNegClassified + "/" + trainingSetsNeg.get(currFold).size() - + " negative examples"); - outputWriter(" testing: " + correctPosClassified + "/" - + testSetsPos.get(currFold).size() + " correct positives, " - + correctNegClassified + "/" + testSetsNeg.get(currFold).size() - + " correct negatives"); - outputWriter(" concept: " + concept); - outputWriter(" accuracy: " + df.format(currAccuracy) + "% (correctness: " - + df.format(testingCorrectness) + "%; completeness: " - + df.format(testingCompleteness) + "%) --- training set: " - + df.format(trainingAccuracy) + "% (correctness: " - + df.format(trainingCorrectness) + "%; completeness: " - + df.format(trainingCompleteness) + "%)"); - outputWriter(" length: " + df.format(concept.getLength())); - outputWriter(" runtime: " + df.format(algorithmDuration / (double) 1000000000) + "s"); - - if (la instanceof PADCELAbstract) { - int pn = ((PADCELAbstract) la).getNoOfCompactedPartialDefinition(); - this.noOfPartialDef.addNumber(pn); - outputWriter(" number of partial definitions: " + pn + " (total: " - + ((PADCELAbstract) la).getNumberOfPartialDefinitions() + ")"); - - double pl = concept.getLength() / (double) pn; - this.partialDefinitionLength.addNumber(pl); - outputWriter(" avarage partial definition length: " + df.format(pl)); - - // show more information on counter partial definitions - if (la instanceof PADCELExAbstract) { - PADCELExAbstract pdllexla = (PADCELExAbstract) la; - outputWriter(" number of partial definitions for each type: 1:" - + pdllexla.getNumberOfPartialDefinitions(1) + "; 2:" - + pdllexla.getNumberOfPartialDefinitions(2) + "; 3:" - + pdllexla.getNumberOfPartialDefinitions(3) + "; 4:" - + pdllexla.getNumberOfPartialDefinitions(4)); - outputWriter(" number of counter partial definition used: " - + (concept.toString().split("NOT ").length - 1) + "/" - + pdllexla.getNumberOfCounterPartialDefinitionUsed()); - if (pdllexla.terminatedByCounterDefinitions()) { - outputWriter(" terminated by counter partial definitions"); - terminatedByCounterPartialDefinitions++; - } else if (pdllexla.terminatedByPartialDefinitions()) { - outputWriter(" terminated by partial definitions"); - terminatedBypartialDefinition++; - } else - outputWriter(" neither terminated by partial definition nor counter partial definition"); - } - } - - } - - outputWriter(""); - outputWriter("Finished " + folds + "-folds cross-validation."); - outputWriter("runtime: " + statOutput(df, runtime, "s")); - outputWriter("#partial definitions: " + statOutput(df, noOfPartialDef, "")); - outputWriter("avg. partial definition length: " - + statOutput(df, partialDefinitionLength, "")); - outputWriter("length: " + statOutput(df, length, "")); - outputWriter("F-Measure on training set: " + statOutput(df, fMeasureTraining, "%")); - outputWriter("F-Measure: " + statOutput(df, fMeasure, "%")); - outputWriter("predictive accuracy on training set: " - + statOutput(df, accuracyTraining, "%") + " --- correctness: " - + statOutput(df, trainingCorrectnessStat, "%") + "; completeness: " - + statOutput(df, trainingCompletenessStat, "%")); - outputWriter("predictive accuracy: " + statOutput(df, accuracy, "%") + " --- correctness: " - + statOutput(df, testingCorrectnessStat, "%") + "; completeness: " - + statOutput(df, testingCompletenessStat, "%")); - if (la instanceof PADCELExAbstract) - outputWriter("terminated by: partial def.: " + terminatedBypartialDefinition - + "; counter partial def.: " + terminatedByCounterPartialDefinitions); - } - - @Override - protected void outputWriter(String output) { - logger.info(output); - - if (writeToFile) - Files.appendToFile(outputFile, output + "\n"); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-14 04:00:54
|
Revision: 3708 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3708&view=rev Author: tcanvn Date: 2012-05-14 04:00:47 +0000 (Mon, 14 May 2012) Log Message: ----------- 1. Add cross validation procedure for PADCEL 2. Modify CLI.java + CrossValidation.java to let them know about PADCEL 3. JUnit tests for the new comers Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java Added Paths: ----------- trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-05-14 03:55:41 UTC (rev 3707) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -27,8 +27,10 @@ import java.util.List; import java.util.Map.Entry; + import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.xmlbeans.XmlObject; +import org.dllearner.algorithms.PADCEL.PADCELPosNegLP; import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; @@ -40,6 +42,7 @@ import org.dllearner.utilities.Files; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; @@ -91,7 +94,7 @@ public void run() throws IOException { - if(writeSpringConfiguration) { + if (writeSpringConfiguration) { SpringConfigurationXMLBeanConverter converter = new SpringConfigurationXMLBeanConverter(); XmlObject xml; if(configuration == null) { @@ -110,16 +113,25 @@ } } - if(performCrossValidation) { + if (performCrossValidation) { AbstractReasonerComponent rs = context.getBean(AbstractReasonerComponent.class); - PosNegLP lp = context.getBean(PosNegLP.class); AbstractCELA la = context.getBean(AbstractCELA.class); - new CrossValidation(la,lp,rs,nrOfFolds,false); + + //this test is added for PDLL algorithm since it does not use the PosNegLP + try { + PADCELPosNegLP lp = context.getBean(PADCELPosNegLP.class); + new PDLLCrossValidation(la, lp, rs, nrOfFolds, false); + } + catch (BeansException be) { + PosNegLP lp = context.getBean(PosNegLP.class); + new CrossValidation(la,lp,rs,nrOfFolds,false); + } + } else { // knowledgeSource = context.getBeansOfType(Knowledge1Source.class).entrySet().iterator().next().getValue(); for(Entry<String, LearningAlgorithm> entry : context.getBeansOfType(LearningAlgorithm.class).entrySet()){ algorithm = entry.getValue(); - logger.info("Running algorithm instance \"" + entry.getKey() + "\"(" + algorithm.getClass().getSimpleName() + ")"); + logger.info("Running algorithm instance \"" + entry.getKey() + "\" (" + algorithm.getClass().getSimpleName() + ")"); algorithm.start(); } } @@ -205,7 +217,7 @@ * @param e The exception to analyze * @return The primary cause of the exception. */ - private static Throwable findPrimaryCause(Exception e) { + private static Throwable findPrimaryCause(Exception e) { // The throwables from the stack of the exception Throwable[] throwables = ExceptionUtils.getThrowables(e); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2012-05-14 03:55:41 UTC (rev 3707) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -20,7 +20,6 @@ package org.dllearner.cli; import java.io.File; -import java.io.FileNotFoundException; import java.text.DecimalFormat; import java.util.Collections; import java.util.HashSet; @@ -29,20 +28,13 @@ import java.util.Random; import java.util.Set; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.statistics.Stat; @@ -57,18 +49,27 @@ */ public class CrossValidation { - private static Logger logger = Logger.getRootLogger(); + // statistical values + protected Stat runtime = new Stat(); + protected Stat accuracy = new Stat(); + protected Stat length = new Stat(); + protected Stat accuracyTraining = new Stat(); + protected Stat fMeasure = new Stat(); + protected Stat fMeasureTraining = new Stat(); + protected static boolean writeToFile = false; + protected static File outputFile; - // statistical values - private Stat runtime = new Stat(); - private Stat accuracy = new Stat(); - private Stat length = new Stat(); - private Stat accuracyTraining = new Stat(); - private Stat fMeasure = new Stat(); - private Stat fMeasureTraining = new Stat(); - private static boolean writeToFile = false; - private static File outputFile; - + + protected Stat trainingCompletenessStat = new Stat(); + protected Stat trainingCorrectnessStat = new Stat(); + + protected Stat testingCompletenessStat = new Stat(); + protected Stat testingCorrectnessStat = new Stat(); + + public CrossValidation() { + + } + public CrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, int folds, boolean leaveOneOut) { DecimalFormat df = new DecimalFormat(); @@ -211,11 +212,11 @@ } - private int getCorrectPosClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetPos) { + protected int getCorrectPosClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetPos) { return rs.hasType(concept, testSetPos).size(); } - private int getCorrectNegClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetNeg) { + protected int getCorrectNegClassified(AbstractReasonerComponent rs, Description concept, Set<Individual> testSetNeg) { return testSetNeg.size() - rs.hasType(concept, testSetNeg).size(); } @@ -273,7 +274,7 @@ return runtime; } - private void outputWriter(String output) { + protected void outputWriter(String output) { if(writeToFile) { Files.appendToFile(outputFile, output +"\n"); System.out.println(output); Added: trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java (rev 0) +++ trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -0,0 +1,320 @@ +package org.dllearner.cli; + +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Random; +import java.util.Set; + + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.PADCEL.PADCELAbstract; +import org.dllearner.algorithms.PADCEL.PADCELPosNegLP; +import org.dllearner.algorithms.PADCELEx.PADCELExAbstract; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.Heuristics; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.utilities.Files; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.statistics.Stat; + +/** + * Add PDLL cross validation support to Jens Lehmann work ( + * {@link org.dllearner.cli.CrossValidation}). In this cross validation, + * some more addition dimensions will be investigated such as: + * number partial definitions, partial definition length, etc. + * + * + * @author actran + * + */ + +public class PDLLCrossValidation extends CrossValidation { + + protected Stat noOfPartialDef = new Stat(); + protected Stat partialDefinitionLength = new Stat(); + + Logger logger = Logger.getLogger(this.getClass()); + + protected boolean interupted = false; + + /** + * Default constructor + */ + + public PDLLCrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, + int folds, boolean leaveOneOut) { + super(la, lp, rs, folds, leaveOneOut); + } + + /** + * This is for PDLL cross validation + * + * @param la + * @param lp + * @param rs + * @param folds + * @param leaveOneOut + */ + public PDLLCrossValidation(AbstractCELA la, PADCELPosNegLP lp, AbstractReasonerComponent rs, + int folds, boolean leaveOneOut) { + + super(); // do nothing + + DecimalFormat df = new DecimalFormat(); + + // the training and test sets used later on + List<Set<Individual>> trainingSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> trainingSetsNeg = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsPos = new LinkedList<Set<Individual>>(); + List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); + + // get examples and shuffle them too + Set<Individual> posExamples = lp.getPositiveExamples(); + List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); + Collections.shuffle(posExamplesList, new Random(1)); + Set<Individual> negExamples = lp.getNegativeExamples(); + List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); + Collections.shuffle(negExamplesList, new Random(2)); + + // sanity check whether nr. of folds makes sense for this benchmark + if (!leaveOneOut && (posExamples.size() < folds && negExamples.size() < folds)) { + System.out.println("The number of folds is higher than the number of " + + "positive/negative examples. This can result in empty test sets. Exiting."); + System.exit(0); + } + + if (leaveOneOut) { + // note that leave-one-out is not identical to k-fold with + // k = nr. of examples in the current implementation, because + // with n folds and n examples there is no guarantee that a fold + // is never empty (this is an implementation issue) + int nrOfExamples = posExamples.size() + negExamples.size(); + for (int i = 0; i < nrOfExamples; i++) { + // ... + } + System.out.println("Leave-one-out not supported yet."); + System.exit(1); + } else { + // calculating where to split the sets, ; note that we split + // positive and negative examples separately such that the + // distribution of positive and negative examples remains similar + // (note that there are better but more complex ways to implement + // this, + // which guarantee that the sum of the elements of a fold for pos + // and neg differs by at most 1 - it can differ by 2 in our + // implementation, + // e.g. with 3 folds, 4 pos. examples, 4 neg. examples) + int[] splitsPos = calculateSplits(posExamples.size(), folds); + int[] splitsNeg = calculateSplits(negExamples.size(), folds); + + // System.out.println(splitsPos[0]); + // System.out.println(splitsNeg[0]); + + // calculating training and test sets + for (int i = 0; i < folds; i++) { + Set<Individual> testPos = getTestingSet(posExamplesList, splitsPos, i); + Set<Individual> testNeg = getTestingSet(negExamplesList, splitsNeg, i); + testSetsPos.add(i, testPos); + testSetsNeg.add(i, testNeg); + trainingSetsPos.add(i, getTrainingSet(posExamples, testPos)); + trainingSetsNeg.add(i, getTrainingSet(negExamples, testNeg)); + } + + } + + // run the algorithm + int terminatedBypartialDefinition = 0, terminatedByCounterPartialDefinitions = 0; + + for (int currFold = 0; (currFold < folds); currFold++) { + + if (this.interupted) { + outputWriter("Cross validation has been interupted"); + return; + } + + // Set<String> pos = + // Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); + // Set<String> neg = + // Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); + lp.setPositiveExamples(trainingSetsPos.get(currFold)); + lp.setNegativeExamples(trainingSetsNeg.get(currFold)); + + try { + lp.init(); + la.init(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + + long algorithmStartTime = System.nanoTime(); + try { + la.start(); + } catch (OutOfMemoryError e) { + System.out.println("out of memory at " + + (System.currentTimeMillis() - algorithmStartTime) / 1000 + "s"); + } + + long algorithmDuration = System.nanoTime() - algorithmStartTime; + runtime.addNumber(algorithmDuration / (double) 1000000000); + + Description concept = ((PADCELAbstract) la).getUnionCurrenlyBestDescription(); + + Set<Individual> tmp = rs.hasType(concept, trainingSetsPos.get(currFold)); + Set<Individual> tmp2 = Helper.difference(trainingSetsPos.get(currFold), tmp); + Set<Individual> tmp3 = rs.hasType(concept, trainingSetsNeg.get(currFold)); + + outputWriter("training set errors pos (" + tmp2.size() + "): " + tmp2); + outputWriter("training set errors neg (" + tmp3.size() + "): " + tmp3); + + tmp = rs.hasType(concept, testSetsPos.get(currFold)); + tmp2 = Helper.difference(testSetsPos.get(currFold), tmp); + tmp3 = rs.hasType(concept, testSetsNeg.get(currFold)); + + outputWriter("test set errors pos: " + tmp2); + outputWriter("test set errors neg: " + tmp3); + + // calculate training accuracies + int trainingCorrectPosClassified = getCorrectPosClassified(rs, concept, + trainingSetsPos.get(currFold)); + int trainingCorrectNegClassified = getCorrectNegClassified(rs, concept, + trainingSetsNeg.get(currFold)); + int trainingCorrectExamples = trainingCorrectPosClassified + + trainingCorrectNegClassified; + double trainingAccuracy = 100 * ((double) trainingCorrectExamples / (trainingSetsPos + .get(currFold).size() + trainingSetsNeg.get(currFold).size())); + + double trainingCompleteness = 100 * (double) trainingCorrectPosClassified + / trainingSetsPos.get(currFold).size(); + double trainingCorrectness = 100 * (double) trainingCorrectNegClassified + / trainingSetsNeg.get(currFold).size(); + + accuracyTraining.addNumber(trainingAccuracy); + trainingCompletenessStat.addNumber(trainingCompleteness); + trainingCorrectnessStat.addNumber(trainingCorrectness); + + // calculate test accuracies + int correctPosClassified = getCorrectPosClassified(rs, concept, + testSetsPos.get(currFold)); + int correctNegClassified = getCorrectNegClassified(rs, concept, + testSetsNeg.get(currFold)); + int correctExamples = correctPosClassified + correctNegClassified; + double currAccuracy = 100 * ((double) correctExamples / (testSetsPos.get(currFold) + .size() + testSetsNeg.get(currFold).size())); + + double testingCompleteness = 100 * (double) correctPosClassified + / testSetsPos.get(currFold).size(); + double testingCorrectness = 100 * (double) correctNegClassified + / testSetsNeg.get(currFold).size(); + + accuracy.addNumber(currAccuracy); + testingCompletenessStat.addNumber(testingCompleteness); + testingCorrectnessStat.addNumber(testingCorrectness); + + // calculate training F-Score + int negAsPosTraining = rs.hasType(concept, trainingSetsNeg.get(currFold)).size(); + double precisionTraining = trainingCorrectPosClassified + negAsPosTraining == 0 ? 0 + : trainingCorrectPosClassified + / (double) (trainingCorrectPosClassified + negAsPosTraining); + double recallTraining = trainingCorrectPosClassified + / (double) trainingSetsPos.get(currFold).size(); + fMeasureTraining.addNumber(100 * Heuristics + .getFScore(recallTraining, precisionTraining)); + // calculate test F-Score + int negAsPos = rs.hasType(concept, testSetsNeg.get(currFold)).size(); + double precision = correctPosClassified + negAsPos == 0 ? 0 : correctPosClassified + / (double) (correctPosClassified + negAsPos); + double recall = correctPosClassified / (double) testSetsPos.get(currFold).size(); + // System.out.println(precision);System.out.println(recall); + fMeasure.addNumber(100 * Heuristics.getFScore(recall, precision)); + + length.addNumber(concept.getLength()); + + outputWriter("fold " + currFold + ":"); + outputWriter(" training: " + trainingCorrectPosClassified + "/" + + trainingSetsPos.get(currFold).size() + " positive and " + + trainingCorrectNegClassified + "/" + trainingSetsNeg.get(currFold).size() + + " negative examples"); + outputWriter(" testing: " + correctPosClassified + "/" + + testSetsPos.get(currFold).size() + " correct positives, " + + correctNegClassified + "/" + testSetsNeg.get(currFold).size() + + " correct negatives"); + outputWriter(" concept: " + concept); + outputWriter(" accuracy: " + df.format(currAccuracy) + "% (correctness: " + + df.format(testingCorrectness) + "%; completeness: " + + df.format(testingCompleteness) + "%) --- training set: " + + df.format(trainingAccuracy) + "% (correctness: " + + df.format(trainingCorrectness) + "%; completeness: " + + df.format(trainingCompleteness) + "%)"); + outputWriter(" length: " + df.format(concept.getLength())); + outputWriter(" runtime: " + df.format(algorithmDuration / (double) 1000000000) + "s"); + + if (la instanceof PADCELAbstract) { + int pn = ((PADCELAbstract) la).getNoOfCompactedPartialDefinition(); + this.noOfPartialDef.addNumber(pn); + outputWriter(" number of partial definitions: " + pn + " (total: " + + ((PADCELAbstract) la).getNumberOfPartialDefinitions() + ")"); + + double pl = concept.getLength() / (double) pn; + this.partialDefinitionLength.addNumber(pl); + outputWriter(" avarage partial definition length: " + df.format(pl)); + + // show more information on counter partial definitions + if (la instanceof PADCELExAbstract) { + PADCELExAbstract pdllexla = (PADCELExAbstract) la; + outputWriter(" number of partial definitions for each type: 1:" + + pdllexla.getNumberOfPartialDefinitions(1) + "; 2:" + + pdllexla.getNumberOfPartialDefinitions(2) + "; 3:" + + pdllexla.getNumberOfPartialDefinitions(3) + "; 4:" + + pdllexla.getNumberOfPartialDefinitions(4)); + outputWriter(" number of counter partial definition used: " + + (concept.toString().split("NOT ").length - 1) + "/" + + pdllexla.getNumberOfCounterPartialDefinitionUsed()); + if (pdllexla.terminatedByCounterDefinitions()) { + outputWriter(" terminated by counter partial definitions"); + terminatedByCounterPartialDefinitions++; + } else if (pdllexla.terminatedByPartialDefinitions()) { + outputWriter(" terminated by partial definitions"); + terminatedBypartialDefinition++; + } else + outputWriter(" neither terminated by partial definition nor counter partial definition"); + } + } + + } + + outputWriter(""); + outputWriter("Finished " + folds + "-folds cross-validation."); + outputWriter("runtime: " + statOutput(df, runtime, "s")); + outputWriter("#partial definitions: " + statOutput(df, noOfPartialDef, "")); + outputWriter("avg. partial definition length: " + + statOutput(df, partialDefinitionLength, "")); + outputWriter("length: " + statOutput(df, length, "")); + outputWriter("F-Measure on training set: " + statOutput(df, fMeasureTraining, "%")); + outputWriter("F-Measure: " + statOutput(df, fMeasure, "%")); + outputWriter("predictive accuracy on training set: " + + statOutput(df, accuracyTraining, "%") + " --- correctness: " + + statOutput(df, trainingCorrectnessStat, "%") + "; completeness: " + + statOutput(df, trainingCompletenessStat, "%")); + outputWriter("predictive accuracy: " + statOutput(df, accuracy, "%") + " --- correctness: " + + statOutput(df, testingCorrectnessStat, "%") + "; completeness: " + + statOutput(df, testingCompletenessStat, "%")); + if (la instanceof PADCELExAbstract) + outputWriter("terminated by: partial def.: " + terminatedBypartialDefinition + + "; counter partial def.: " + terminatedByCounterPartialDefinitions); + } + + @Override + protected void outputWriter(String output) { + logger.info(output); + + if (writeToFile) + Files.appendToFile(outputFile, output + "\n"); + } + +} Property changes on: trunk/interfaces/src/main/java/org/dllearner/cli/PDLLCrossValidation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java (rev 0) +++ trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -0,0 +1,117 @@ +package org.dllearner.cli; + +import java.io.File; +import java.io.IOException; + +import org.dllearner.algorithms.PADCEL.PADCELAbstract; +import org.dllearner.algorithms.PADCEL.PADCELPosNegLP; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.ApplicationContext; + +/** + * JUnit test for PDCCEL + * <ul> + * <li>validate the configuration</li> + * <li>execute the learning algorithm</li> + * <li>validate the result</li> + * </ul> + * + * @author An C. Tran + * + */ +public abstract class PADCELCLITestAbstract { + + private CLI cli; + + public abstract String getConfigurationFilePath(); + + /** + * Default constructor + + */ + public PADCELCLITestAbstract() { + super(); + } + + /** + * Setup the testing + */ + @Before + public void setup() { + try { + + System.out.println("---------------------------------------------------------------"); + System.out.println("Dataset: \"" + this.getConfigurationFilePath() + "\""); + System.out.println("---------------------------------------------------------------"); + + File carcinoConfFile = new File(this.getConfigurationFilePath()); + cli = new CLI(carcinoConfFile); + cli.init(); + } + catch (Exception e) { + //do nothing + } + } + + + /** + * Run validations + * + * @throws IOException + */ + @Test + public void runValidation() throws IOException { + validateConfiguration(); + + validateLearningResult(); + } + + /** + * Validate the configuration + * + * @param context + */ + public void validateConfiguration() { + //check CLI + Assert.assertNotNull(cli); + + //get application context for validating the configuration + ApplicationContext context = cli.getContext(); + Assert.assertNotNull(context); + + //learning problem + Assert.assertNotNull(context.getBean("lp", PADCELPosNegLP.class)); + + //learning algorithm + Assert.assertNotNull(context.getBean("alg", PADCELAbstract.class)); + + //PDLL splitter (some algorithms do not have) + //Assert.assertNotNull(context.getBean("splitter", PADCELDoubleSplitterAbstract.class)); + } + + + /** + * Validate the learning result + * + * @param learner + * @throws IOException + */ + public void validateLearningResult() throws IOException { + Assert.assertNotNull(cli); + + //get application context for validating the configuration + ApplicationContext context = cli.getContext(); + Assert.assertNotNull(context); + + PADCELAbstract learner = context.getBean("alg", PADCELAbstract.class); + + //we shorten timeout for all testings to 30s for a faster validation + learner.setMaxExecutionTimeInSeconds(30); + learner.start(); //start the learner instead to avoid cross validation in this test + + Assert.assertTrue(learner.getNumberOfPartialDefinitions() > 0); + Assert.assertNotNull(learner.getUnionCurrenlyBestDescription()); + } +} Property changes on: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java (rev 0) +++ trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -0,0 +1,21 @@ +package org.dllearner.cli; + +/** + * JUnit test for PDCCEL + * <ul> + * <li>validate the configuration</li> + * <li>execute the learning algorithm</li> + * <li>validate the result</li> + * </ul> + * + * @author An C. Tran + * + */ +public class PADCELCarcinoGenesisTest extends PADCELCLITestAbstract { + + @Override + public String getConfigurationFilePath() { + return "../examples/carcinogenesis/carcinogenesis_pdll.conf"; + } + +} Property changes on: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java (rev 0) +++ trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -0,0 +1,46 @@ +package org.dllearner.cli; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Run validation for multiple examples + * + * @author An C. Tran + * + */ +@RunWith(value = Parameterized.class) +public class PADCELFamilyBenchmarkTest extends PADCELCLITestAbstract { + + private String confFile; + + public PADCELFamilyBenchmarkTest(String confFile) { + super(); + this.confFile = confFile; + } + + @Override + public String getConfigurationFilePath() { + return this.confFile; + } + + @Parameters + public static Collection<String[]> data() { + String[][] data = new String[][] { + // each row is an array of parameters that will be used to instantiate this class + {"../examples/family-benchmark/Aunt_padcel.conf"}, + {"../examples/family-benchmark/Brother_padcel.conf"}, + {"../examples/family-benchmark/Cousin_padcel.conf"}, + {"../examples/family-benchmark/Daughter_padcel.conf"}, + {"../examples/family-benchmark/Father_padcel.conf"}, + {"../examples/family-benchmark/Grandson_padcel.conf"}, + {"../examples/family-benchmark/Uncle_padcel.conf"} + }; + return Arrays.asList(data); + } + +} Property changes on: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java (rev 0) +++ trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java 2012-05-14 04:00:47 UTC (rev 3708) @@ -0,0 +1,44 @@ +package org.dllearner.cli; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * Run validation for multiple examples + * + * @author An C. Tran + * + */ +@RunWith(value = Parameterized.class) +public class PADCELMultiExamplesTest extends PADCELCLITestAbstract { + + private String confFile; + + public PADCELMultiExamplesTest(String confFile) { + super(); + this.confFile = confFile; + } + + @Override + public String getConfigurationFilePath() { + return this.confFile; + } + + @Parameters + public static Collection<String[]> data() { + String[][] data = new String[][] { + // each row is an array of parameters that will be used to instantiate this class + {"../examples/moral_reasoner/moral_all_examples_simple_owl_padcel.conf"}, + {"../examples/poker/straight_owl_padcel.conf"}, + {"../examples/forte/uncle_owl_large_padcel.conf"}, + {"../examples/carcinogenesis/carcinogenesis_padcel.conf"}, + {"../examples/showering-duration/uca1_150_padcel.conf"} + }; + return Arrays.asList(data); + } + +} Property changes on: trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |