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: <lor...@us...> - 2012-01-06 03:59:57
|
Revision: 3532 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3532&view=rev Author: lorenz_b Date: 2012-01-06 03:59:49 +0000 (Fri, 06 Jan 2012) Log Message: ----------- Added more tests. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-01-05 17:44:19 UTC (rev 3531) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-01-06 03:59:49 UTC (rev 3532) @@ -23,6 +23,7 @@ import java.text.DecimalFormat; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -85,6 +86,7 @@ @ComponentAnn(name="PCELOE", shortName="pceloe", version=1.0, description="CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.") public class PCELOE extends AbstractCELA { + Map<Thread, RefinementOperator> ops = new HashMap<Thread, RefinementOperator>(); //parameters for thread pool //Parallel running Threads(Executor) on System private static int corePoolSize = 5; @@ -440,12 +442,30 @@ int nrOfThreads = Runtime.getRuntime().availableProcessors(); ExecutorService service = Executors.newFixedThreadPool(nrOfThreads); - + for(int i = 0; i < 2; i++){ service.submit(new Runnable() { + + @Override public void run() { + // we use a default operator and inject the class hierarchy for now + RefinementOperator operator = new RhoDRDown(); + ((RhoDRDown)operator).setStartClass(startClass); + ((RhoDRDown)operator).setReasoner(reasoner); + try { + ((RhoDRDown)operator).init(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + // TODO: find a better solution as this is quite difficult to debug + ((RhoDRDown)operator).setSubHierarchy(reasoner.getClassHierarchy().clone()); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + + ops.put(Thread.currentThread(), operator); + OENode nextNode; double highestAccuracy = 0.0; int loop = 0; @@ -458,7 +478,9 @@ } // chose best node according to heuristics + logger.info("Get next node to expand..."); nextNode = getNextNodeToExpand(); + logger.info("...done"); try { Thread.sleep(10); } catch (InterruptedException e) { @@ -471,8 +493,10 @@ // apply operator Monitor mon = MonitorFactory.start("refineNode"); + logger.info("Refine node..."); TreeSet<Description> refinements = refineNode(nextNode); mon.stop(); + logger.info("...done"); while(refinements.size() != 0) { // pick element from set @@ -485,8 +509,10 @@ // System.out.println("potentially adding " + refinement + " to search tree as child of " + nextNode + " " + new Date()); Monitor mon2 = MonitorFactory.start("addNode"); + logger.info("Add node..."); addNode(refinement, nextNode); mon2.stop(); + logger.info("...done"); // adding nodes is potentially computationally expensive, so we have // to check whether max time is exceeded if(terminationCriteriaSatisfied()) { @@ -564,6 +590,8 @@ nodes.remove(node); // System.out.println("refining: " + node); int horizExp = node.getHorizontalExpansion(); +// TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); + RefinementOperator operator = ops.get(Thread.currentThread()); //logger.info("Got operator"); TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); node.incHorizontalExpansion(); node.setRefinementCount(refinements.size()); @@ -582,15 +610,17 @@ if(!nonRedundant) { return false; } - + logger.info("Check if description is allowed..."); // check whether the description is allowed if(!isDescriptionAllowed(description, parentNode)) { return false; } + logger.info("...done"); // System.out.println("Test " + new Date()); // quality of description (return if too weak) double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); + logger.info("Accuracy: " + accuracy); // issue a warning if accuracy is not between 0 and 1 or -1 (too weak) if(accuracy > 1.0 || (accuracy < 0.0 && accuracy != -1)) { logger.warn("Invalid accuracy value " + accuracy + " for description " + description + ". This could be caused by a bug in the heuristic measure and should be reported to the DL-Learner bug tracker."); @@ -634,6 +664,7 @@ // we need to make sure that this does not get called more often than // necessary since rewriting is expensive boolean isCandidate = !bestEvaluatedDescriptions.isFull(); + logger.info("Is candidate:" + isCandidate); if(!isCandidate) { EvaluatedDescription worst = bestEvaluatedDescriptions.getWorst(); double accThreshold = worst.getAccuracy(); @@ -665,17 +696,22 @@ } } } + logger.info("Point 2"); // System.out.println("shorter description? " + shorterDescriptionExists + " nice: " + niceDescription); - + filterFollowsFromKB = false; if(!shorterDescriptionExists) { if(!filterFollowsFromKB || !((ClassLearningProblem)learningProblem).followsFromKB(niceDescription)) { // System.out.println("Test2"); - bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem); + synchronized (bestEvaluatedDescriptions) { + bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem); + } + // System.out.println("acc: " + accuracy); // System.out.println(bestEvaluatedDescriptions); } } + logger.info("Point 3"); // System.out.println(bestEvaluatedDescriptions.getSet().size()); } @@ -1038,7 +1074,7 @@ PCELOE alg = new PCELOE(lp, rc); alg.setMaxExecutionTimeInSeconds(10); - alg.setMaxClassDescriptionTests(200); + alg.setMaxClassDescriptionTests(100); alg.init(); alg.start(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-01-05 17:44:31
|
Revision: 3531 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3531&view=rev Author: christinaunger Date: 2012-01-05 17:44:19 +0000 (Thu, 05 Jan 2012) Log Message: ----------- [tbsl] added HAVING-part to basic templates Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Having.java trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2012-01-05 17:42:15 UTC (rev 3530) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2012-01-05 17:44:19 UTC (rev 3531) @@ -16,6 +16,7 @@ import org.dllearner.algorithm.tbsl.sparql.Path; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Aggregate; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Having; import org.dllearner.algorithm.tbsl.sparql.SPARQL_OrderBy; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; @@ -242,21 +243,41 @@ } } else if (predicate.equals("count")) { - // COUNT(?x) AS ?c - if (!literal) { - temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, simple.getArguments().get(1).getValue())); - return temp; + if (simple.getArguments().size() == 1) { + temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT)); } else { - String fresh = "c"+createFresh(); - temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, fresh)); - temp.addFilter(new SPARQL_Filter( - new SPARQL_Pair( - new SPARQL_Term(fresh), - new SPARQL_Term(simple.getArguments().get(1).getValue(),true), - SPARQL_PairType.EQ))); - return temp; + if (!literal) { + temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, simple.getArguments().get(1).getValue())); + return temp; + } + else { // COUNT(?x) AS ?c + // String fresh = "c"+createFresh(); + // temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, fresh)); + // temp.addFilter(new SPARQL_Filter( + // new SPARQL_Pair( + // new SPARQL_Term(fresh), + // new SPARQL_Term(simple.getArguments().get(1).getValue(),true), + // SPARQL_PairType.EQ))); + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") = "+simple.getArguments().get(1).getValue())); + return temp; + } } + } else if (predicate.equals("count_greater")) { + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") > "+simple.getArguments().get(1).getValue())); + return temp; + } else if (predicate.equals("count_less")) { + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") < "+simple.getArguments().get(1).getValue())); + return temp; + } else if (predicate.equals("count_greatereq")) { + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") >= "+simple.getArguments().get(1).getValue())); + return temp; + } else if (predicate.equals("count_lesseq")) { + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") <= "+simple.getArguments().get(1).getValue())); + return temp; + } else if (predicate.equals("count_eq")) { + temp.addHaving(new SPARQL_Having("COUNT(?"+simple.getArguments().get(0).getValue() + ") = "+simple.getArguments().get(1).getValue())); + return temp; } else if (predicate.equals("sum")) { temp.addSelTerm(new SPARQL_Term(simple.getArguments().get(1).getValue(), SPARQL_Aggregate.SUM)); return temp; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2012-01-05 17:42:15 UTC (rev 3530) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2012-01-05 17:44:19 UTC (rev 3531) @@ -87,7 +87,7 @@ Pattern vpassPattern = Pattern.compile("\\s(\\w+/VBD.(\\w+)/VBN)"); Pattern vpassinPattern = Pattern.compile("\\s((\\w+)/VPASS.\\w+/IN)"); Pattern gerundinPattern = Pattern.compile("\\s((\\w+)/((VBG)|(VBN)).\\w+/IN)"); - Pattern vprepPattern = Pattern.compile("\\s((\\w+)/V[A-Z]+\\s\\w+/(IN|TO))"); + Pattern vprepPattern = Pattern.compile("\\s((\\w+)(?<!have)/V[A-Z]+\\s\\w+/(IN|TO))"); Pattern whenPattern = Pattern.compile("(?i)(when/WRB\\s(.+\\s)(\\w+)/((V[A-Z]+)|(PASS[A-Z]+)))"); Pattern wherePattern = Pattern.compile("(?i)(where/WRB\\s(.+\\s)(\\w+)/((V[A-Z]+)|(PASS[A-Z]+)))"); Pattern adjsPattern = Pattern.compile("((\\w+)/JJ.(\\w+)/JJ)"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java 2012-01-05 17:42:15 UTC (rev 3530) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java 2012-01-05 17:44:19 UTC (rev 3531) @@ -13,6 +13,7 @@ Set<Path> conditions; Set<SPARQL_Term> orderBy; Set<SPARQL_Filter> filter; + Set<SPARQL_Having> having; SPARQL_QueryType qt = SPARQL_QueryType.SELECT; List<Slot> slots; @@ -27,6 +28,7 @@ conditions = new HashSet<Path>(); orderBy = new HashSet<SPARQL_Term>(); filter = new HashSet<SPARQL_Filter>(); + having = new HashSet<SPARQL_Having>(); slots = new ArrayList<Slot>(); } @@ -71,6 +73,10 @@ } retVal += "}\n"; + + for (SPARQL_Having h : having) { + retVal += h + "\n"; + } if (orderBy != null && !orderBy.isEmpty()) { @@ -152,6 +158,14 @@ this.filter.add(f); } + + public Set<SPARQL_Having> getHavings() { + return having; + } + + public void addHaving(SPARQL_Having h) { + having.add(h); + } public Set<SPARQL_Term> getOrderBy() { @@ -241,7 +255,10 @@ public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + + ((conditions == null) ? 0 : conditions.hashCode()); result = prime * result + ((filter == null) ? 0 : filter.hashCode()); + result = prime * result + ((having == null) ? 0 : having.hashCode()); result = prime * result + limit; result = prime * result + offset; result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode()); @@ -263,11 +280,21 @@ if (getClass() != obj.getClass()) return false; BasicQueryTemplate other = (BasicQueryTemplate) obj; + if (conditions == null) { + if (other.conditions != null) + return false; + } else if (!conditions.equals(other.conditions)) + return false; if (filter == null) { if (other.filter != null) return false; } else if (!filter.equals(other.filter)) return false; + if (having == null) { + if (other.having != null) + return false; + } else if (!having.equals(other.having)) + return false; if (limit != other.limit) return false; if (offset != other.offset) @@ -300,4 +327,5 @@ return true; } + } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Having.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Having.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Having.java 2012-01-05 17:44:19 UTC (rev 3531) @@ -0,0 +1,14 @@ +package org.dllearner.algorithm.tbsl.sparql; + +public class SPARQL_Having { + + public String filter; + + public SPARQL_Having(String s) { + filter = s; + } + + public String toString() { + return "HAVING (" + filter + ")"; + } +} Property changes on: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Having.java ___________________________________________________________________ Added: svn:mime-type + text/plain 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-01-05 17:42:15 UTC (rev 3530) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java 2012-01-05 17:44:19 UTC (rev 3531) @@ -24,7 +24,7 @@ public class BasicTemplator { - String[] GRAMMAR_FILES = {"tbsl/lexicon/english.lex"}; + String[] GRAMMAR_FILES = {"tbsl/lexicon/basic_english.lex"}; PartOfSpeechTagger tagger; LTAGLexicon g; Added: trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex (rev 0) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/basic_english.lex 2012-01-05 17:44:19 UTC (rev 3531) @@ -0,0 +1,185 @@ + +// TO BE +// ------ + + is || (S DP[subject] (VP V:'is' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + is || (S DP[subject] (VP V:'is' ADJ[comp])) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + was || (S DP[subject] (VP V:'was' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + was || (S DP[subject] (VP V:'was' ADJ[comp])) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + which is || (NP NP* (S C:'which' (VP V:'is' DP[object]))) || <x, l1, t, [ l1:[ | x=y ] ], [ (l2,y,object,<<e,t>,t>) ], [ l2=l1 ],[]> + that is || (NP NP* (S C:'that' (VP V:'is' DP[object]))) || <x, l1, t, [ l1:[ | x=y ] ], [ (l2,y,object,<<e,t>,t>) ], [ l2=l1 ],[]> + + are || (S DP[subject] (VP V:'are' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + are || (S DP[subject] (VP V:'are' ADJ[comp])) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + were || (S DP[subject] (VP V:'were' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + were || (S DP[subject] (VP V:'were' ADJ[comp])) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + which are || (NP NP* (S C:'which' (VP V:'are' DP[object]))) || <x, l1, t, [ l1:[ | x=y ] ], [ (l2,y,object,<<e,t>,t>) ], [ l2=l1 ],[]> + that are || (NP NP* (S C:'that' (VP V:'are' DP[object]))) || <x, l1, t, [ l1:[ | x=y ] ], [ (l2,y,object,<<e,t>,t>) ], [ l2=l1 ],[]> + + is there || (S V:'is' C:'there' DP[dp]) || <x, l1, t, [ l1:[ | ] ], [ (l2,x,dp,<<e,t>,t>) ], [ l2=l1 ],[]> + are there || (S V:'are' C:'there' DP[dp]) || <x, l1, t, [ l1:[ | ] ], [ (l2,x,dp,<<e,t>,t>) ], [ l2=l1 ],[]> + is there || (S DP[dp] (VP V:'is' C:'there')) || <x, l1, t, [ l1:[ | ] ], [ (l2,x,dp,<<e,t>,t>) ], [ l2=l1 ],[]> + are there || (S DP[dp] (VP V:'are' C:'there')) || <x, l1, t, [ l1:[ | ] ], [ (l2,x,dp,<<e,t>,t>) ], [ l2=l1 ],[]> + +// TO BE: YES/NO QUESTIONS + + is || (S (VP V:'is' DP[subject] DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + is || (S (VP V:'is' DP[subject] ADJ[comp])) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + was || (S V:'was' DP[subject] DP[object]) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + was || (S V:'was' DP[subject] ADJ[comp]) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + are || (S V:'are' DP[subject] DP[object]) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + are || (S V:'are' DP[subject] ADJ[comp]) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + were || (S V:'were' DP[subject] DP[object]) || <x, l1, t, [ l1:[ | ], l2:[ | x=y ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + were || (S V:'were' DP[subject] ADJ[comp]) || <x, l1, t, [ l1:[ | x=y ]], [ (l2,x,subject,<<e,t>,t>), (l3,y,comp,<e,t>) ], [ l2=l1, l3=l2 ],[]> + + did || (S V:'did' S*) || <x,l1,t,[ l1:[|] ],[],[],[]> + +// IMPERATIVES +// --------------------- + + give me || (S (VP V:'give' (DP N:'me') DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + name || (S (VP V:'name' DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> +// give me all || (S (VP V:'give' (DP N:'me') DET:'all' DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> +// name all || (S (VP V:'name' DET:'all' DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + show me || (S (VP V:'show' (DP N:'me') DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + show || (S (VP V:'show' DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + list me || (S (VP V:'list' (DP N:'me') DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + list || (S (VP V:'list' DP[object])) || <x,l1,t,[ l1:[ ?x | x=y ] ],[ (l2,y,object,<<e,t>,t>) ],[ l1=l2 ],[]> + + +// DETERMINER +// ---------- + + a || (DP DET:'a' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] SOME y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + an || (DP DET:'an' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] SOME y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + all || (DP DET:'all' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] EVERY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + all the || (DP DET:'all' DET:'the' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ y | ] ], [ (l2,y,noun,<e,t>) ], [ l2=l1 ],[]> + every || (DP DET:'every' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] EVERY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + no || (DP DET:'no' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] NO y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + each || (DP DET:'each' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] EVERY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + the most || (DP DET:'the' ADJ:'most' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] THEMOST y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + the least || (DP DET:'the' ADJ:'least' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] THELEAST y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + most || (DP DET:'most' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] MOST y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + a few || (DP DET:'a' ADJ:'few' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] AFEW y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + some || (DP DET:'some' NP[noun]) || <x, l1, <<e,t>,t>, [ l1:[ x | ] ], [ (l2,x,noun,<e,t>) ], [ l2=l1 ],[]> + which || (DP DET:'which' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ ?y | ] ], [ (l2,y,noun,<e,t>) ], [ l2=l1 ],[]> + what || (DP DET:'what' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ ?y | ] ], [ (l2,y,noun,<e,t>) ], [ l2=l1 ],[]> + many || (DP DET:'many' NP[noun]) || <y, l1, <<e,t>,t>, [ l1:[ | l2:[ y | ] MANY y l3:[|] ] ], [ (l4,y,noun,<e,t>) ], [ l4=l2 ],[]> + the || (DP DET:'the' NP[noun]) || <x, l1, <<e,t>,t>, [ l1:[x|] ], [ (l2,x,noun,<e,t>) ], [ l2=l1 ],[]> + at least || (DP DET:'at' DET:'least' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y | count_greatereq(y,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> + at most || (DP DET:'at' DET:'most' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y | count_lesseq(y,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> + exactly || (DP DET:'exactly' NUM[num] NP[noun]) || <y,l1,<<e,t>,t>,[l1:[ y | count_eq(y,x) ]],[(l2,y,noun,<e,t>),(l3,x,num,e)],[ l1=l2, l2=l3 ],[]> + + other || (NP ADJ:'other' NP*) || <x,l1,<e,t>,[ l1:[ | ] ], [],[],[]> + total || (NP ADJ:'total' NP[np]) || <s,l1,<e,t>,[ l1:[ ?s | sum(a,x,s) ] ], [ (l2,x,np,<e,t>) ],[ l2=l1 ],[]> + + 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:[ | count(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 |] ], [],[],[]> + the || (DET DET:'the') || <x,l1,e, [ l1:[ x |] ], [],[],[]> + the most || (DET DET:'the' DET:'most') || <y, l1, e, [ l1:[ | l2:[ y | ] THEMOST y l3:[|] ] ], [], [],[]> + 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 ]> + + // COUNT + more than || (DP DET:'more' DET:'than' NUM[num] NP[np]) || <y,l1,<<e,t>,t>,[ l1:[ y,c | count_greater(y,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_less(y,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],[]> + + // HOW + // how || (DP DET:'how' ADJ[adj]) || <x,l1,<<e,t>,t>,[ l1:[?x,|] ],[ (x,l2,adj,<e,t>) ],[l2=l1],[]> + + +// EMPTY STUFF +// ------------ + + also || (VP ADV:'also' VP*) || <x,l1,t,[ l1:[|] ],[],[],[]> + also || (DP ADV:'also' DP*) || <x,l1,<<e,t>,t>,[ l1:[|] ],[],[],[]> + + has || (S DP[subject] (VP V:'has' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | empty(x,y) ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + have || (S DP[subject] (VP V:'have' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | empty(x,y) ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + had || (S DP[subject] (VP V:'had' DP[object])) || <x, l1, t, [ l1:[ | ], l2:[ | empty(x,y) ] ], [ (l3,x,subject,<<e,t>,t>), (l4,y,object,<<e,t>,t>) ], [ l3<l1, l4<l1, l2<scope(l3), l2<scope(l4) ],[]> + +// with || (NP NP* (PP P:'with' DP[dp])) || <x,l1,<e,t>,[ l1:[| empty(x,y) ] ],[(l2,y,dp,<<e,t>,t>)],[l2=l1],[]> + + people || (NP N:'people') || <x,l1,<e,t>,[ l1:[|] ],[],[],[]> + + +// WH WORDS +// -------- + + 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 ],[]> + 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 ]> + when || (DP WH:'when') || <y, l1, <<e,t>,t>, [ l1:[ ?x | SLOT_p(y,x) ] ], [], [], [ SLOT_p/PROPERTY/date ]> + where || (S WH:'where' S[s]) || <x, l1, t, [ l1:[ ?x | SLOT_p(y,x) ] ], [(l2,y,s,t)], [l2=l1], [ SLOT_p/PROPERTY/place ]> + where || (DP WH:'where') || <y, l1, <<e,t>,t>, [ l1:[ ?x | SLOT_p(y,x) ] ], [], [], [ SLOT_p/PROPERTY/place ]> + where in || (DP WH:'where' (PP P:'in' DP[dp])) || <y, l1, <<e,t>,t>, [ l1:[ ?x | SLOT_p(y,x), SLOT_in(x,z) ] ], [(l2,z,dp,<<e,t>,t>)], [l2=l1], [ SLOT_p/PROPERTY/place ]> + + +// NEGATION +// -------- + + not || (ADJ NEG:'not' ADJ*) || <x,l2,t,[ l1:[ | NOT l2:[|] ] ],[],[],[]> + not || (VP NEG:'not' VP*) || <x,l2,t,[ l1:[ | NOT l2:[|] ] ],[],[],[]> + did not || (VP V:'did' NEG:'not' VP*) || <x,l2,t,[ l1:[ | NOT l2:[|] ] ],[],[],[]> + does not || (VP V:'does' NEG:'not' VP*) || <x,l2,t,[ l1:[ | NOT l2:[|] ] ],[],[],[]> + do not || (VP V:'do' NEG:'not' VP*) || <x,l2,t,[ l1:[ | NOT l2:[|] ] ],[],[],[]> + + +// COORDINATION +// ------------ + + 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 || (VP VP* CC:'and' VP[vp]) || - + and || (ADJ ADJ* CC:'and' ADJ[adj]) || - + + as well as || (NP NP* CC:'as' CC:'well' CC:'as' NP[np]) || <x,l1,<e,t>,[l1:[|]],[(l2,y,np,<e,t>)],[l1=l2],[]> + + or || (S S* CC:'or' S[2]) || - + or || (DP DP* CC:'or' DP[2]) || - + or || (NP NP* CC:'or' NP[2]) || - + or || (VP VP* CC:'or' VP[2]) || - + or || (ADJ ADJ* CC:'or' ADJ[2]) || - + + +// EXISTENTIAL +// ----------- + + there || (DP (NP EX:'there')) || <x,l1,<<e,t>,t>,[l1:[|]],[],[],[]> + + +// 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 || (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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-01-05 17:42:22
|
Revision: 3530 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3530&view=rev Author: jenslehmann Date: 2012-01-05 17:42:15 +0000 (Thu, 05 Jan 2012) Log Message: ----------- start to re-integrate family benchmark Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/test/family-benchmark/Aunt.conf 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-01-05 15:15:28 UTC (rev 3529) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-01-05 17:42:15 UTC (rev 3530) @@ -178,11 +178,11 @@ @ConfigOption(name = "maxClassExpressionTestsAfterImprovement", defaultValue="0", description = "The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") private int maxClassExpressionTestsAfterImprovement = 0; - @ConfigOption(defaultValue = "0", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = 0; + @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSeconds = 10; - @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSecondsAfterImprovement", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSecondsAfterImprovement = 10; + @ConfigOption(defaultValue = "0", name = "maxExecutionTimeInSecondsAfterImprovement", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSecondsAfterImprovement = 0; @ConfigOption(name = "terminateOnNoiseReached", defaultValue="false", description="specifies whether to terminate when noise criterion is met") private boolean terminateOnNoiseReached = false; @@ -219,6 +219,10 @@ @Override public void init() throws ComponentInitException { + if(maxExecutionTimeInSeconds != 0) { + maxExecutionTimeInSeconds = Math.min(maxExecutionTimeInSeconds, maxExecutionTimeInSecondsAfterImprovement); + } + // compute used concepts/roles from allowed/ignored // concepts/roles Set<NamedClass> usedConcepts; Modified: trunk/test/family-benchmark/Aunt.conf =================================================================== --- trunk/test/family-benchmark/Aunt.conf 2012-01-05 15:15:28 UTC (rev 3529) +++ trunk/test/family-benchmark/Aunt.conf 2012-01-05 17:42:15 UTC (rev 3530) @@ -1,88 +1,115 @@ -import("family-benchmark.owl"); -// TODO All Quantifier causes "wrong" areas of the search space to be explored -ocel.useAllConstructor = false; +// declare some prefixes to use as abbreviations +prefixes = [ ("ex","http://www.benchmark.org/family#") ] -+"http://www.benchmark.org/family#F2F14" -+"http://www.benchmark.org/family#F2F12" -+"http://www.benchmark.org/family#F2F19" -+"http://www.benchmark.org/family#F2F26" -+"http://www.benchmark.org/family#F2F28" -+"http://www.benchmark.org/family#F2F36" -+"http://www.benchmark.org/family#F3F52" -+"http://www.benchmark.org/family#F3F53" -+"http://www.benchmark.org/family#F5F62" -+"http://www.benchmark.org/family#F6F72" -+"http://www.benchmark.org/family#F6F79" -+"http://www.benchmark.org/family#F6F77" -+"http://www.benchmark.org/family#F6F86" -+"http://www.benchmark.org/family#F6F91" -+"http://www.benchmark.org/family#F6F84" -+"http://www.benchmark.org/family#F6F96" -+"http://www.benchmark.org/family#F6F101" -+"http://www.benchmark.org/family#F6F93" -+"http://www.benchmark.org/family#F7F114" -+"http://www.benchmark.org/family#F7F106" -+"http://www.benchmark.org/family#F7F116" -+"http://www.benchmark.org/family#F7F119" -+"http://www.benchmark.org/family#F7F126" -+"http://www.benchmark.org/family#F7F121" -+"http://www.benchmark.org/family#F9F148" -+"http://www.benchmark.org/family#F9F150" -+"http://www.benchmark.org/family#F9F143" -+"http://www.benchmark.org/family#F9F152" -+"http://www.benchmark.org/family#F9F154" -+"http://www.benchmark.org/family#F9F141" -+"http://www.benchmark.org/family#F9F160" -+"http://www.benchmark.org/family#F9F163" -+"http://www.benchmark.org/family#F9F158" -+"http://www.benchmark.org/family#F9F168" -+"http://www.benchmark.org/family#F10F174" -+"http://www.benchmark.org/family#F10F179" -+"http://www.benchmark.org/family#F10F181" -+"http://www.benchmark.org/family#F10F192" -+"http://www.benchmark.org/family#F10F193" -+"http://www.benchmark.org/family#F10F186" -+"http://www.benchmark.org/family#F10F195" +// knowledge source definition +ks.type = "OWL File" +ks.fileName = "family-benchmark.owl" --"http://www.benchmark.org/family#F6M99" --"http://www.benchmark.org/family#F10F200" --"http://www.benchmark.org/family#F9F156" --"http://www.benchmark.org/family#F6M69" --"http://www.benchmark.org/family#F2F15" --"http://www.benchmark.org/family#F6M100" --"http://www.benchmark.org/family#F8F133" --"http://www.benchmark.org/family#F3F48" --"http://www.benchmark.org/family#F2F30" --"http://www.benchmark.org/family#F4F55" --"http://www.benchmark.org/family#F6F74" --"http://www.benchmark.org/family#F10M199" --"http://www.benchmark.org/family#F7M104" --"http://www.benchmark.org/family#F9M146" --"http://www.benchmark.org/family#F6M71" --"http://www.benchmark.org/family#F2F22" --"http://www.benchmark.org/family#F2M13" --"http://www.benchmark.org/family#F9F169" --"http://www.benchmark.org/family#F5F65" --"http://www.benchmark.org/family#F6M81" --"http://www.benchmark.org/family#F7M131" --"http://www.benchmark.org/family#F7F129" --"http://www.benchmark.org/family#F7M107" --"http://www.benchmark.org/family#F10F189" --"http://www.benchmark.org/family#F8F135" --"http://www.benchmark.org/family#F8M136" --"http://www.benchmark.org/family#F10M188" --"http://www.benchmark.org/family#F9F164" --"http://www.benchmark.org/family#F7F118" --"http://www.benchmark.org/family#F2F10" --"http://www.benchmark.org/family#F6F97" --"http://www.benchmark.org/family#F7F111" --"http://www.benchmark.org/family#F9M151" --"http://www.benchmark.org/family#F4M59" --"http://www.benchmark.org/family#F2M37" --"http://www.benchmark.org/family#F1M1" --"http://www.benchmark.org/family#F9M142" --"http://www.benchmark.org/family#F4M57" --"http://www.benchmark.org/family#F9M170" --"http://www.benchmark.org/family#F5M66" --"http://www.benchmark.org/family#F9F145" +// reasoner +reasoner.type = "fast instance checker" +reasoner.sources = { ks } + +// learning problem +lp.type = "posNegStandard" +lp.positiveExamples = { +"ex:F2F14", +"ex:F2F12", +"ex:F2F19", +"ex:F2F26", +"ex:F2F28", +"ex:F2F36", +"ex:F3F52", +"ex:F3F53", +"ex:F5F62" +,"ex:F6F72" +,"ex:F6F79" +,"ex:F6F77" +,"ex:F6F86" +,"ex:F6F91" +,"ex:F6F84" +,"ex:F6F96" +,"ex:F6F101" +,"ex:F6F93" +,"ex:F7F114" +,"ex:F7F106" +,"ex:F7F116" +,"ex:F7F119" +,"ex:F7F126" +,"ex:F7F121" +,"ex:F9F148" +,"ex:F9F150" +,"ex:F9F143" +,"ex:F9F152" +,"ex:F9F154" +,"ex:F9F141" +,"ex:F9F160" +,"ex:F9F163" +,"ex:F9F158" +,"ex:F9F168" +,"ex:F10F174" +,"ex:F10F179" +,"ex:F10F181" +,"ex:F10F192" +,"ex:F10F193" +,"ex:F10F186" +,"ex:F10F195" +} + +lp.negativeExamples = { +"ex:F6M99" +,"ex:F10F200" +,"ex:F9F156" +,"ex:F6M69" +,"ex:F2F15" +,"ex:F6M100" +,"ex:F8F133" +,"ex:F3F48" +,"ex:F2F30" +,"ex:F4F55" +,"ex:F6F74" +,"ex:F10M199" +,"ex:F7M104" +,"ex:F9M146" +,"ex:F6M71" +,"ex:F2F22" +,"ex:F2M13" +,"ex:F9F169" +,"ex:F5F65" +,"ex:F6M81" +,"ex:F7M131" +,"ex:F7F129" +,"ex:F7M107" +,"ex:F10F189" +,"ex:F8F135" +,"ex:F8M136" +,"ex:F10M188" +,"ex:F9F164" +,"ex:F7F118" +,"ex:F2F10" +,"ex:F6F97" +,"ex:F7F111" +,"ex:F9M151" +,"ex:F4M59" +,"ex:F2M37" +,"ex:F1M1" +,"ex:F9M142" +,"ex:F4M57" +,"ex:F9M170" +,"ex:F5M66" +,"ex:F9F145" +} + +op.type = "rho" +op.useAllConstructor = false +op.useCardinalityRestrictions = false + +// create learning algorithm to run +alg.type = "celoe" +alg.operator = op +alg.maxExecutionTimeInSecondsAfterImprovement = 200 + + + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-01-05 15:15:35
|
Revision: 3529 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3529&view=rev Author: lorenz_b Date: 2012-01-05 15:15:28 +0000 (Thu, 05 Jan 2012) Log Message: ----------- Added some tests for CELOE. Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java Added: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-01-05 15:15:28 UTC (rev 3529) @@ -0,0 +1,1048 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.dllearner.algorithms.celoe; + +import java.io.File; +import java.text.DecimalFormat; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; +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.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Restriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.ClassLearningProblem; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.refinementoperators.OperatorInverter; +import org.dllearner.refinementoperators.RefinementOperator; +import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.utilities.Files; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.owl.DescriptionMinimizer; +import org.dllearner.utilities.owl.EvaluatedDescriptionSet; +import org.dllearner.utilities.owl.PropertyContext; +import org.springframework.beans.factory.annotation.Autowired; + +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + +/** + * The CELOE (Class Expression Learner for Ontology Engineering) algorithm. + * It adapts and extends the standard supervised learning algorithm for the + * ontology engineering use case. + * + * @author Jens Lehmann + * + */ +@ComponentAnn(name="PCELOE", shortName="pceloe", version=1.0, description="CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.") +public class PCELOE extends AbstractCELA { + + //parameters for thread pool + //Parallel running Threads(Executor) on System + private static int corePoolSize = 5; + //Maximum Threads allowed in Pool + private static int maximumPoolSize = 20; + //Keep alive time for waiting threads for jobs(Runnable) + private static long keepAliveTime = 10; + + + private static Logger logger = Logger.getLogger(PCELOE.class); +// private CELOEConfigurator configurator; + + private boolean isRunning = false; + private boolean stop = false; + +// private OEHeuristicStable heuristicStable = new OEHeuristicStable(); +// private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); + + private RefinementOperator operator; + private DescriptionMinimizer minimizer; + @ConfigOption(name="useMinimizer", defaultValue="true", description="Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.") + private boolean useMinimizer = true; + + // all nodes in the search tree (used for selecting most promising node) + private TreeSet<OENode> nodes; + private OEHeuristicRuntime heuristic; // = new OEHeuristicRuntime(); + // root of search tree + private OENode startNode; + // the class with which we start the refinement process + @ConfigOption(name = "startClass", defaultValue="owl:Thing", description="You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.") + private Description startClass; + + // all descriptions in the search tree plus those which were too weak (for fast redundancy check) + private TreeSet<Description> descriptions; + + private EvaluatedDescriptionSet bestEvaluatedDescriptions; + + // if true, then each solution is evaluated exactly instead of approximately + // private boolean exactBestDescriptionEvaluation = false; + @ConfigOption(name = "singleSuggestionMode", defaultValue="false", description="Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.") + private boolean singleSuggestionMode; + private Description bestDescription; + private double bestAccuracy = Double.MIN_VALUE; + + private NamedClass classToDescribe; + // examples are either 1.) instances of the class to describe 2.) positive examples + // 3.) union of pos.+neg. examples depending on the learning problem at hand + private Set<Individual> examples; + + // CELOE was originally created for learning classes in ontologies, but also + // works for other learning problem types + private boolean isClassLearningProblem; + private boolean isEquivalenceProblem; + + private long nanoStartTime; + + // important parameters (non-config options but internal) + private double noise; + + private boolean filterFollowsFromKB; + + // less important parameters + // forces that one solution cannot be subexpression of another expression; this option is useful to get diversity + // but it can also suppress quite useful expressions + private boolean forceMutualDifference = false; + + // utility variables + private String baseURI; + private Map<String, String> prefixes; + private DecimalFormat dfPercent = new DecimalFormat("0.00%"); + private ConceptComparator descriptionComparator = new ConceptComparator(); + + // statistical variables + private int expressionTests = 0; + private int minHorizExp = 0; + private int maxHorizExp = 0; + + // TODO: turn those into config options + + // important: do not initialise those with empty sets + // null = no settings for allowance / ignorance + // empty set = allow / ignore nothing (it is often not desired to allow no class!) + Set<NamedClass> allowedConcepts = null; + Set<NamedClass> ignoredConcepts = null; + + @ConfigOption(name = "writeSearchTree", defaultValue="false", description="specifies whether to write a search tree") + private boolean writeSearchTree = false; + + @ConfigOption(name = "searchTreeFile", defaultValue="log/searchTree.txt", description="file to use for the search tree") + private String searchTreeFile = "log/searchTree.txt"; + + @ConfigOption(name = "replaceSearchTree", defaultValue="false", description="specifies whether to replace the search tree in the log file after each run or append the new search tree") + private boolean replaceSearchTree = false; + + @ConfigOption(name = "maxNrOfResults", defaultValue="10", description="Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).") + private int maxNrOfResults = 10; + + @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") + private double noisePercentage = 0.0; + + @ConfigOption(name = "filterDescriptionsFollowingFromKB", defaultValue="false", description="If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.") + private boolean filterDescriptionsFollowingFromKB = false; + + @ConfigOption(name = "reuseExistingDescription", defaultValue="false", description="If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.") + private boolean reuseExistingDescription = false; + + @ConfigOption(name = "maxClassDescriptionTests", defaultValue="0", description="The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") + private int maxClassDescriptionTests = 0; + + @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSeconds = 10; + + @ConfigOption(name = "terminateOnNoiseReached", defaultValue="false", description="specifies whether to terminate when noise criterion is met") + private boolean terminateOnNoiseReached = false; + + @ConfigOption(name = "maxDepth", defaultValue="7", description="maximum depth of description") + private double maxDepth = 7; + + private Set<OENode> currentlyProcessedNodes = Collections.synchronizedSet(new HashSet<OENode>()); + +// public CELOEConfigurator getConfigurator() { +// return configurator; +// } + + public PCELOE() { + + } + + public PCELOE(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { + super(problem, reasoner); +// configurator = new CELOEConfigurator(this); + } + +// public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { +// Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); +// problems.add(AbstractLearningProblem.class); +// return problems; +// } + + public static String getName() { + return "CELOE"; + } + + @Override + public void init() throws ComponentInitException { + + // compute used concepts/roles from allowed/ignored + // concepts/roles + Set<NamedClass> usedConcepts; +// Set<NamedClass> allowedConcepts = configurator.getAllowedConcepts()==null ? null : CommonConfigMappings.getAtomicConceptSet(configurator.getAllowedConcepts()); +// Set<NamedClass> ignoredConcepts = configurator.getIgnoredConcepts()==null ? null : CommonConfigMappings.getAtomicConceptSet(configurator.getIgnoredConcepts()); + if(allowedConcepts != null) { + // sanity check to control if no non-existing concepts are in the list + Helper.checkConcepts(reasoner, allowedConcepts); + usedConcepts = allowedConcepts; + } else if(ignoredConcepts != null) { + usedConcepts = Helper.computeConceptsUsingIgnoreList(reasoner, ignoredConcepts); + } else { + usedConcepts = Helper.computeConcepts(reasoner); + } + + // copy class hierarchy and modify it such that each class is only + // reachable via a single path +// ClassHierarchy classHierarchy = reasoner.getClassHierarchy().clone(); + ClassHierarchy classHierarchy = reasoner.getClassHierarchy().cloneAndRestrict(usedConcepts); + classHierarchy.thinOutSubsumptionHierarchy(); + + // if no one injected a heuristic, we use a default one + if(heuristic == null) { + heuristic = new OEHeuristicRuntime(); + } + + minimizer = new DescriptionMinimizer(reasoner); + + // start at owl:Thing by default + if(startClass == null) { + startClass = Thing.instance; + } + +// singleSuggestionMode = configurator.getSingleSuggestionMode(); + /* + // create refinement operator + if(operator == null) { + operator = new RhoDRDown(); + ((RhoDRDown)operator).setStartClass(startClass); + ((RhoDRDown)operator).setReasoner(reasoner); + } + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((RhoDRDown)operator).init(); + */ + // create a refinement operator and pass all configuration + // variables to it + if(operator == null) { + // we use a default operator and inject the class hierarchy for now + operator = new RhoDRDown(); + ((RhoDRDown)operator).setStartClass(startClass); + ((RhoDRDown)operator).setReasoner(reasoner); + ((RhoDRDown)operator).init(); + } + // TODO: find a better solution as this is quite difficult to debug + ((RhoDRDown)operator).setSubHierarchy(classHierarchy); + ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + + +// operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); + baseURI = reasoner.getBaseURI(); + prefixes = reasoner.getPrefixes(); + if(writeSearchTree) { + File f = new File(searchTreeFile ); + Files.clearFile(f); + } + + bestEvaluatedDescriptions = new EvaluatedDescriptionSet(maxNrOfResults); + + isClassLearningProblem = (learningProblem instanceof ClassLearningProblem); + + // we put important parameters in class variables + noise = noisePercentage/100d; +// System.out.println("noise " + noise); +// maxDepth = configurator.getMaxDepth(); + // (filterFollowsFromKB is automatically set to false if the problem + // is not a class learning problem + filterFollowsFromKB = filterDescriptionsFollowingFromKB && isClassLearningProblem; + +// Set<Description> concepts = operator.refine(Thing.instance, 5); +// for(Description concept : concepts) { +// System.out.println(concept); +// } +// System.out.println("refinements of thing: " + concepts.size()); + + // actions specific to ontology engineering + if(isClassLearningProblem) { + ClassLearningProblem problem = (ClassLearningProblem) learningProblem; + classToDescribe = problem.getClassToDescribe(); + isEquivalenceProblem = problem.isEquivalenceProblem(); + + examples = reasoner.getIndividuals(classToDescribe); + + // start class: intersection of super classes for definitions (since it needs to + // capture all instances), but owl:Thing for learning subclasses (since it is + // superfluous to add super classes in this case) + if(isEquivalenceProblem) { + Set<Description> existingDefinitions = reasoner.getAssertedDefinitions(classToDescribe); + if(reuseExistingDescription && (existingDefinitions.size() > 0)) { + // the existing definition is reused, which in the simplest case means to + // use it as a start class or, if it is already too specific, generalise it + + // pick the longest existing definition as candidate + Description existingDefinition = null; + int highestLength = 0; + for(Description exDef : existingDefinitions) { + if(exDef.getLength() > highestLength) { + existingDefinition = exDef; + highestLength = exDef.getLength(); + } + } + + LinkedList<Description> startClassCandidates = new LinkedList<Description>(); + startClassCandidates.add(existingDefinition); + ((RhoDRDown)operator).setDropDisjuncts(true); + RefinementOperator upwardOperator = new OperatorInverter(operator); + + // use upward refinement until we find an appropriate start class + boolean startClassFound = false; + Description candidate; + do { + candidate = startClassCandidates.pollFirst(); + if(((ClassLearningProblem)learningProblem).getRecall(candidate)<1.0) { + // add upward refinements to list + Set<Description> refinements = upwardOperator.refine(candidate, candidate.getLength()); +// System.out.println("ref: " + refinements); + LinkedList<Description> refinementList = new LinkedList<Description>(refinements); +// Collections.reverse(refinementList); +// System.out.println("list: " + refinementList); + startClassCandidates.addAll(refinementList); +// System.out.println("candidates: " + startClassCandidates); + } else { + startClassFound = true; + } + } while(!startClassFound); + startClass = candidate; + + if(startClass.equals(existingDefinition)) { + logger.info("Reusing existing description " + startClass.toManchesterSyntaxString(baseURI, prefixes) + " as start class for learning algorithm."); + } else { + logger.info("Generalised existing description " + existingDefinition.toManchesterSyntaxString(baseURI, prefixes) + " to " + startClass.toManchesterSyntaxString(baseURI, prefixes) + ", which is used as start class for the learning algorithm."); + } + +// System.out.println("start class: " + startClass); +// System.out.println("existing def: " + existingDefinition); +// System.out.println(reasoner.getIndividuals(existingDefinition)); + + ((RhoDRDown)operator).setDropDisjuncts(false); + + } else { + Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); + if(superClasses.size() > 1) { + startClass = new Intersection(new LinkedList<Description>(superClasses)); + } else if(superClasses.size() == 1){ + startClass = (Description) superClasses.toArray()[0]; + } else { + startClass = Thing.instance; + logger.warn(classToDescribe + " is equivalent to owl:Thing. Usually, it is not " + + "sensible to learn a description in this case."); + } + } + } + } else if(learningProblem instanceof PosOnlyLP) { + examples = ((PosOnlyLP)learningProblem).getPositiveExamples(); + } else if(learningProblem instanceof PosNegLP) { + examples = Helper.union(((PosNegLP)learningProblem).getPositiveExamples(),((PosNegLP)learningProblem).getNegativeExamples()); + } + } + + @Override + public Description getCurrentlyBestDescription() { + EvaluatedDescription ed = getCurrentlyBestEvaluatedDescription(); + return ed == null ? null : ed.getDescription(); + } + + @Override + public List<Description> getCurrentlyBestDescriptions() { + return bestEvaluatedDescriptions.toDescriptionList(); + } + + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + return bestEvaluatedDescriptions.getBest(); + } + + @Override + public TreeSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() { + return bestEvaluatedDescriptions.getSet(); + } + + public double getCurrentlyBestAccuracy() { + return bestEvaluatedDescriptions.getBest().getAccuracy(); + } + + @Override + public void start() { +// System.out.println(configurator.getMaxExecutionTimeInSeconds()); + + stop = false; + isRunning = true; + reset(); + nanoStartTime = System.nanoTime(); + + addNode(startClass, null); + + int nrOfThreads = Runtime.getRuntime().availableProcessors(); + ExecutorService service = Executors.newFixedThreadPool(nrOfThreads); + + for(int i = 0; i < 2; i++){ + service.submit(new Runnable() { + + @Override + public void run() { + OENode nextNode; + double highestAccuracy = 0.0; + int loop = 0; + while (!terminationCriteriaSatisfied()) { + + + if(!singleSuggestionMode && bestEvaluatedDescriptions.getBestAccuracy() > highestAccuracy) { + highestAccuracy = bestEvaluatedDescriptions.getBestAccuracy(); + logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); + } + + // chose best node according to heuristics + nextNode = getNextNodeToExpand(); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + logger.info("next Node: " + nextNode); + if(nextNode != null){ + int horizExp = nextNode.getHorizontalExpansion(); + + // apply operator + Monitor mon = MonitorFactory.start("refineNode"); + TreeSet<Description> refinements = refineNode(nextNode); + mon.stop(); + + while(refinements.size() != 0) { + // pick element from set + Description refinement = refinements.pollFirst(); + int length = refinement.getLength(); + + // we ignore all refinements with lower length and too high depth + // (this also avoids duplicate node children) + if(length > horizExp && refinement.getDepth() <= maxDepth) { + +// System.out.println("potentially adding " + refinement + " to search tree as child of " + nextNode + " " + new Date()); + Monitor mon2 = MonitorFactory.start("addNode"); + addNode(refinement, nextNode); + mon2.stop(); + // adding nodes is potentially computationally expensive, so we have + // to check whether max time is exceeded + if(terminationCriteriaSatisfied()) { + break; + } +// System.out.println("addNode finished" + " " + new Date()); + } + +// System.out.println(" refinement queue length: " + refinements.size()); + } + +// updateMinMaxHorizExp(nextNode); + + loop++; + currentlyProcessedNodes.remove(nextNode); + } + + } + + } + }); + } + + try { + service.awaitTermination(maxExecutionTimeInSeconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if(singleSuggestionMode) { + bestEvaluatedDescriptions.add(bestDescription, bestAccuracy, learningProblem); + } + + if (stop) { + logger.info("Algorithm stopped ("+expressionTests+" descriptions tested). " + nodes.size() + " nodes in the search tree.\n"); + } else { + logger.info("Algorithm terminated successfully ("+expressionTests+" descriptions tested). " + nodes.size() + " nodes in the search tree.\n"); + logger.info(reasoner.toString()); + } + + // print solution(s) + logger.info("solutions:\n" + getSolutionString()); + +// System.out.println(startNode.toTreeString(baseURI)); + + isRunning = false; +// System.out.println("isRunning: " + isRunning); + service.shutdown(); + + } + + private OENode getNextNodeToExpand() { + // we expand the best node of those, which have not achieved 100% accuracy + // already and have a horizontal expansion equal to their length + // (rationale: further extension is likely to add irrelevant syntactical constructs) + Iterator<OENode> it = nodes.descendingIterator();//logger.info(nodes.size()); + while(it.hasNext()) { + OENode node = it.next(); + if(!currentlyProcessedNodes.contains(node) && (node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < node.getDescription().getLength())) { + currentlyProcessedNodes.add(node); + return node; + } + } + + // this should practically never be called, since for any reasonable learning + // task, we will always have at least one node with less than 100% accuracy + return null; + } + + // expand node horizontically + private TreeSet<Description> refineNode(OENode node) { + // we have to remove and add the node since its heuristic evaluation changes through the expansion + // (you *must not* include any criteria in the heuristic which are modified outside of this method, + // otherwise you may see rarely occurring but critical false ordering in the nodes set) + nodes.remove(node); +// System.out.println("refining: " + node); + int horizExp = node.getHorizontalExpansion(); + TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); + node.incHorizontalExpansion(); + node.setRefinementCount(refinements.size()); + nodes.add(node); + return refinements; + } + + // add node to search tree if it is not too weak + // returns true if node was added and false otherwise + private boolean addNode(Description description, OENode parentNode) { + +// System.out.println("d: " + description); + + // redundancy check (return if redundant) + boolean nonRedundant = descriptions.add(description); + if(!nonRedundant) { + return false; + } + + // check whether the description is allowed + if(!isDescriptionAllowed(description, parentNode)) { + return false; + } + +// System.out.println("Test " + new Date()); + // quality of description (return if too weak) + double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); + // issue a warning if accuracy is not between 0 and 1 or -1 (too weak) + if(accuracy > 1.0 || (accuracy < 0.0 && accuracy != -1)) { + logger.warn("Invalid accuracy value " + accuracy + " for description " + description + ". This could be caused by a bug in the heuristic measure and should be reported to the DL-Learner bug tracker."); + System.exit(0); + } + +// System.out.println("Test2 " + new Date()); + expressionTests++; +// System.out.println("acc: " + accuracy); +// System.out.println(description + " " + accuracy); + if(accuracy == -1) { + return false; + } + + OENode node = new OENode(parentNode, description, accuracy); + + // link to parent (unless start node) + if(parentNode == null) { + startNode = node; + } else { + parentNode.addChild(node); + } + + nodes.add(node); +// System.out.println("Test3 " + new Date()); + + // in some cases (e.g. mutation) fully evaluating even a single description is too expensive + // due to the high number of examples -- so we just stick to the approximate accuracy + if(singleSuggestionMode) { + if(accuracy > bestAccuracy) { + bestAccuracy = accuracy; + bestDescription = description; + logger.info("more accurate (" + dfPercent.format(bestAccuracy) + ") class expression found: " + descriptionToString(bestDescription)); // + getTemporaryString(bestDescription)); + } + return true; + } + +// System.out.println("description " + description + " accuracy " + accuracy); + + // maybe add to best descriptions (method keeps set size fixed); + // we need to make sure that this does not get called more often than + // necessary since rewriting is expensive + boolean isCandidate = !bestEvaluatedDescriptions.isFull(); + if(!isCandidate) { + EvaluatedDescription worst = bestEvaluatedDescriptions.getWorst(); + double accThreshold = worst.getAccuracy(); + isCandidate = + (accuracy > accThreshold || + (accuracy >= accThreshold && description.getLength() < worst.getDescriptionLength())); + } + +// System.out.println(isCandidate); + +// System.out.println("Test4 " + new Date()); + if(isCandidate) { + + Description niceDescription = rewriteNode(node); + ConceptTransformation.transformToOrderedForm(niceDescription, descriptionComparator); +// Description niceDescription = node.getDescription(); + + // another test: none of the other suggested descriptions should be + // a subdescription of this one unless accuracy is different + // => comment: on the one hand, this appears to be too strict, because once A is a solution then everything containing + // A is not a candidate; on the other hand this suppresses many meaningless extensions of A + boolean shorterDescriptionExists = false; + if(forceMutualDifference) { + for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet()) { + if(Math.abs(ed.getAccuracy()-accuracy) <= 0.00001 && ConceptTransformation.isSubdescription(niceDescription, ed.getDescription())) { +// System.out.println("shorter: " + ed.getDescription()); + shorterDescriptionExists = true; + break; + } + } + } + +// System.out.println("shorter description? " + shorterDescriptionExists + " nice: " + niceDescription); + + if(!shorterDescriptionExists) { + if(!filterFollowsFromKB || !((ClassLearningProblem)learningProblem).followsFromKB(niceDescription)) { +// System.out.println("Test2"); + bestEvaluatedDescriptions.add(niceDescription, accuracy, learningProblem); +// System.out.println("acc: " + accuracy); +// System.out.println(bestEvaluatedDescriptions); + } + } + +// System.out.println(bestEvaluatedDescriptions.getSet().size()); + } + +// System.out.println("Test5 " + new Date()); +// System.out.println("best evaluated descriptions size: " + bestEvaluatedDescriptions.size() + " worst: " + bestEvaluatedDescriptions.getWorst()); + return true; + } + + // checks whether the description is allowed + private boolean isDescriptionAllowed(Description description, OENode parentNode) { + if(isClassLearningProblem) { + if(isEquivalenceProblem) { + // the class to learn must not appear on the outermost property level + if(occursOnFirstLevel(description, classToDescribe)) { + return false; + } + } else { + // none of the superclasses of the class to learn must appear on the + // outermost property level + TreeSet<Description> toTest = new TreeSet<Description>(descriptionComparator); + toTest.add(classToDescribe); + while(!toTest.isEmpty()) { + Description d = toTest.pollFirst(); + if(occursOnFirstLevel(description, d)) { + return false; + } + toTest.addAll(reasoner.getClassHierarchy().getSuperClasses(d)); + } + } + } + + // perform forall sanity tests + if(parentNode != null && ConceptTransformation.getForallOccurences(description) > ConceptTransformation.getForallOccurences(parentNode.getDescription())) { + // we have an additional \forall construct, so we now fetch the contexts + // in which it occurs + SortedSet<PropertyContext> contexts = ConceptTransformation.getForallContexts(description); + SortedSet<PropertyContext> parentContexts = ConceptTransformation.getForallContexts(parentNode.getDescription()); + contexts.removeAll(parentContexts); +// System.out.println("parent description: " + parentNode.getDescription()); +// System.out.println("description: " + description); +// System.out.println("contexts: " + contexts); + // we now have to perform sanity checks: if \forall is used, then there + // should be at least on class instance which has a filler at the given context + for(PropertyContext context : contexts) { + // transform [r,s] to \exists r.\exists s.\top + Description existentialContext = context.toExistentialContext(); + boolean fillerFound = false; + for(Individual instance : examples) { + if(reasoner.hasType(existentialContext, instance)) { +// System.out.println(instance + " " + existentialContext); + fillerFound = true; + break; + } + } + // if we do not find a filler, this means that putting \forall at + // that position is not meaningful + if(!fillerFound) { + return false; + } + } + } + + // we do not want to have negations of sibling classes on the outermost level + // (they are expressed more naturally by saying that the siblings are disjoint, + // so it is reasonable not to include them in solutions) +// Set<Description> siblingClasses = reasoner.getClassHierarchy().getSiblingClasses(classToDescribe); +// for now, we just disable negation + + return true; + } + + // determine whether a named class occurs on the outermost level, i.e. property depth 0 + // (it can still be at higher depth, e.g. if intersections are nested in unions) + private boolean occursOnFirstLevel(Description description, Description clazz) { + if(description instanceof NamedClass) { + if(description.equals(clazz)) { + return true; + } + } + + if(description instanceof Restriction) { + return false; + } + + for(Description child : description.getChildren()) { + if(occursOnFirstLevel(child, clazz)) { + return true; + } + } + + return false; + } + + // check whether the node is a potential solution candidate + private Description rewriteNode(OENode node) { + Description description = node.getDescription(); + // minimize description (expensive!) - also performes some human friendly rewrites + Description niceDescription; + if(useMinimizer) { + niceDescription = minimizer.minimizeClone(description); + } else { + niceDescription = description; + } + // replace \exists r.\top with \exists r.range(r) which is easier to read for humans + ConceptTransformation.replaceRange(niceDescription, reasoner); + return niceDescription; + } + + private boolean terminationCriteriaSatisfied() { + return + stop || + (maxClassDescriptionTests != 0 && (expressionTests >= maxClassDescriptionTests)) || + (maxExecutionTimeInSeconds != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSeconds*1000000000l))) || + (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)); + } + + private void reset() { + // set all values back to their default values (used for running + // the algorithm more than once) + nodes = new TreeSet<OENode>(heuristic); + descriptions = new TreeSet<Description>(new ConceptComparator()); + bestEvaluatedDescriptions.getSet().clear(); + expressionTests = 0; + } + + @Override + public boolean isRunning() { + return isRunning; + } + + @Override + public void stop() { + stop = true; + } + + public OENode getSearchTreeRoot() { + return startNode; + } + + // central function for printing description + private String descriptionToString(Description description) { + return description.toManchesterSyntaxString(baseURI, prefixes); + } + + @SuppressWarnings("unused") + private String bestDescriptionToString() { + EvaluatedDescription best = bestEvaluatedDescriptions.getBest(); + return best.getDescription().toManchesterSyntaxString(baseURI, prefixes) + " (accuracy: " + dfPercent.format(best.getAccuracy()) + ")"; + } + + private String getSolutionString() { + int current = 1; + String str = ""; + for(EvaluatedDescription ed : bestEvaluatedDescriptions.getSet().descendingSet()) { + // temporary code + if(learningProblem instanceof PosNegLPStandard) { + str += current + ": " + descriptionToString(ed.getDescription()) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(ed.getDescription(),1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(ed.getDescription(),1)) + ")\n"; + } else { + str += current + ": " + descriptionToString(ed.getDescription()) + " " + dfPercent.format(ed.getAccuracy()) + "\n"; +// System.out.println(ed); + } + current++; + } + return str; + } + +// private String getTemporaryString(Description description) { +// return descriptionToString(description) + " (pred. acc.: " + dfPercent.format(((PosNegLPStandard)learningProblem).getPredAccuracyOrTooWeakExact(description,1)) + ", F-measure: "+ dfPercent.format(((PosNegLPStandard)learningProblem).getFMeasureOrTooWeakExact(description,1)) + ")"; +// } + + private void updateMinMaxHorizExp(OENode node) { + int newHorizExp = node.getHorizontalExpansion(); + + // update maximum value + maxHorizExp = Math.max(maxHorizExp, newHorizExp); + + // we just expanded a node with minimum horizontal expansion; + // we need to check whether it was the last one + if(minHorizExp == newHorizExp - 1) { + + // the best accuracy that a node can achieve + double scoreThreshold = heuristic.getNodeScore(node) + 1 - node.getAccuracy(); + + for(OENode n : nodes.descendingSet()) { + if(n != node) { + if(n.getHorizontalExpansion() == minHorizExp) { + // we can stop instantly when another node with min. + return; + } + if(heuristic.getNodeScore(n) < scoreThreshold) { + // we can stop traversing nodes when their score is too low + break; + } + } + } + + // inc. minimum since we found no other node which also has min. horiz. exp. + minHorizExp++; + +// System.out.println("minimum horizontal expansion is now " + minHorizExp); + } + } + + public int getMaximumHorizontalExpansion() { + return maxHorizExp; + } + + public int getMinimumHorizontalExpansion() { + return minHorizExp; + } + + /** + * @return the expressionTests + */ + public int getClassExpressionTests() { + return expressionTests; + } + + public RefinementOperator getOperator() { + return operator; + } + + @Autowired(required=false) + public void setOperator(RefinementOperator operator) { + this.operator = operator; + } + + public Description getStartClass() { + return startClass; + } + + public void setStartClass(Description startClass) { + this.startClass = startClass; + } + + public Set<NamedClass> getAllowedConcepts() { + return allowedConcepts; + } + + public void setAllowedConcepts(Set<NamedClass> allowedConcepts) { + this.allowedConcepts = allowedConcepts; + } + + public Set<NamedClass> getIgnoredConcepts() { + return ignoredConcepts; + } + + public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { + this.ignoredConcepts = ignoredConcepts; + } + + public boolean isWriteSearchTree() { + return writeSearchTree; + } + + public void setWriteSearchTree(boolean writeSearchTree) { + this.writeSearchTree = writeSearchTree; + } + + public String getSearchTreeFile() { + return searchTreeFile; + } + + public void setSearchTreeFile(String searchTreeFile) { + this.searchTreeFile = searchTreeFile; + } + + public int getMaxNrOfResults() { + return maxNrOfResults; + } + + public void setMaxNrOfResults(int maxNrOfResults) { + this.maxNrOfResults = maxNrOfResults; + } + + public double getNoisePercentage() { + return noisePercentage; + } + + public void setNoisePercentage(double noisePercentage) { + this.noisePercentage = noisePercentage; + } + + public boolean isFilterDescriptionsFollowingFromKB() { + return filterDescriptionsFollowingFromKB; + } + + public void setFilterDescriptionsFollowingFromKB(boolean filterDescriptionsFollowingFromKB) { + this.filterDescriptionsFollowingFromKB = filterDescriptionsFollowingFromKB; + } + + public boolean isReplaceSearchTree() { + return replaceSearchTree; + } + + public void setReplaceSearchTree(boolean replaceSearchTree) { + this.replaceSearchTree = replaceSearchTree; + } + + public int getMaxClassDescriptionTests() { + return maxClassDescriptionTests; + } + + public void setMaxClassDescriptionTests(int maxClassDescriptionTests) { + this.maxClassDescriptionTests = maxClassDescriptionTests; + } + + public int getMaxExecutionTimeInSeconds() { + return maxExecutionTimeInSeconds; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + public boolean isTerminateOnNoiseReached() { + return terminateOnNoiseReached; + } + + public void setTerminateOnNoiseReached(boolean terminateOnNoiseReached) { + this.terminateOnNoiseReached = terminateOnNoiseReached; + } + + public boolean isReuseExistingDescription() { + return reuseExistingDescription; + } + + public void setReuseExistingDescription(boolean reuseExistingDescription) { + this.reuseExistingDescription = reuseExistingDescription; + } + + public boolean isUseMinimizer() { + return useMinimizer; + } + + public void setUseMinimizer(boolean useMinimizer) { + this.useMinimizer = useMinimizer; + } + + public OEHeuristicRuntime getHeuristic() { + return heuristic; + } + + public void setHeuristic(OEHeuristicRuntime heuristic) { + this.heuristic = heuristic; + } + + + public static void main(String[] args) throws Exception{ + AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); + ks.init(); + + AbstractReasonerComponent rc = new FastInstanceChecker(ks); + rc.init(); + + ClassLearningProblem lp = new ClassLearningProblem(rc); + lp.setClassToDescribe(new NamedClass("http://example.com/father#father")); + lp.init(); + + PCELOE alg = new PCELOE(lp, rc); + alg.setMaxExecutionTimeInSeconds(10); + alg.setMaxClassDescriptionTests(200); + alg.init(); + + alg.start(); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-01-05 14:12:57
|
Revision: 3528 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3528&view=rev Author: jenslehmann Date: 2012-01-05 14:12:51 +0000 (Thu, 05 Jan 2012) Log Message: ----------- refined termination criteria for CELOE 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-01-05 13:54:07 UTC (rev 3527) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-01-05 14:12:51 UTC (rev 3528) @@ -172,17 +172,26 @@ @ConfigOption(name = "reuseExistingDescription", defaultValue="false", description="If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.") private boolean reuseExistingDescription = false; - @ConfigOption(name = "maxClassDescriptionTests", defaultValue="0", description="The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") - private int maxClassDescriptionTests = 0; + @ConfigOption(name = "maxClassExpressionTests", defaultValue="0", description="The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") + private int maxClassExpressionTests = 0; - @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = 10; + @ConfigOption(name = "maxClassExpressionTestsAfterImprovement", defaultValue="0", description = "The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)") + private int maxClassExpressionTestsAfterImprovement = 0; + + @ConfigOption(defaultValue = "0", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSeconds = 0; + @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSecondsAfterImprovement", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSecondsAfterImprovement = 10; + @ConfigOption(name = "terminateOnNoiseReached", defaultValue="false", description="specifies whether to terminate when noise criterion is met") private boolean terminateOnNoiseReached = false; @ConfigOption(name = "maxDepth", defaultValue="7", description="maximum depth of description") private double maxDepth = 7; + + private int expressionTestCountLastImprovement; + private long timeLastImprovement = 0; // public CELOEConfigurator getConfigurator() { // return configurator; @@ -427,7 +436,9 @@ if(!singleSuggestionMode && bestEvaluatedDescriptions.getBestAccuracy() > highestAccuracy) { highestAccuracy = bestEvaluatedDescriptions.getBestAccuracy(); - logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); + expressionTestCountLastImprovement = expressionTests; + timeLastImprovement = System.nanoTime(); + logger.info("more accurate (" + dfPercent.format(highestAccuracy) + ") class expression found: " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); } // chose best node according to heuristics @@ -765,7 +776,9 @@ private boolean terminationCriteriaSatisfied() { return stop || - (maxClassDescriptionTests != 0 && (expressionTests >= maxClassDescriptionTests)) || + (maxClassExpressionTestsAfterImprovement != 0 && (expressionTests - expressionTestCountLastImprovement >= maxClassExpressionTestsAfterImprovement)) || + (maxClassExpressionTests != 0 && (expressionTests >= maxClassExpressionTests)) || + (maxExecutionTimeInSecondsAfterImprovement != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSecondsAfterImprovement*1000000000l))) || (maxExecutionTimeInSeconds != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSeconds*1000000000l))) || (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)); } @@ -954,11 +967,11 @@ } public int getMaxClassDescriptionTests() { - return maxClassDescriptionTests; + return maxClassExpressionTests; } public void setMaxClassDescriptionTests(int maxClassDescriptionTests) { - this.maxClassDescriptionTests = maxClassDescriptionTests; + this.maxClassExpressionTests = maxClassDescriptionTests; } public int getMaxExecutionTimeInSeconds() { @@ -999,6 +1012,24 @@ public void setHeuristic(OEHeuristicRuntime heuristic) { this.heuristic = heuristic; + } + + public int getMaxClassExpressionTestsWithoutImprovement() { + return maxClassExpressionTestsAfterImprovement; + } + + public void setMaxClassExpressionTestsWithoutImprovement( + int maxClassExpressionTestsWithoutImprovement) { + this.maxClassExpressionTestsAfterImprovement = maxClassExpressionTestsWithoutImprovement; + } + + public int getMaxExecutionTimeInSecondsAfterImprovement() { + return maxExecutionTimeInSecondsAfterImprovement; + } + + public void setMaxExecutionTimeInSecondsAfterImprovement( + int maxExecutionTimeInSecondsAfterImprovement) { + this.maxExecutionTimeInSecondsAfterImprovement = maxExecutionTimeInSecondsAfterImprovement; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-01-05 13:54:14
|
Revision: 3527 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3527&view=rev Author: christinaunger Date: 2012-01-05 13:54:07 +0000 (Thu, 05 Jan 2012) Log Message: ----------- [tbsl] fixed entry for "highest" Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java 2012-01-04 15:01:50 UTC (rev 3526) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java 2012-01-05 13:54:07 UTC (rev 3527) @@ -505,7 +505,7 @@ drs1.replaceReferent(oldV,newV); } - // Hack: If it looks the same, it is the same. + // If it looks the same, it is the same. DRS_Constructor dc = new DRS_Constructor(); if (dc.construct(drs1.toString()).equals(dc.construct(drs2.toString()))) { Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-01-04 15:01:50 UTC (rev 3526) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english.lex 2012-01-05 13:54:07 UTC (rev 3527) @@ -84,8 +84,8 @@ the most || (DET DET:'the' DET:'most') || <y, l1, e, [ l1:[ | l2:[ y | ] THEMOST y l3:[|] ] ], [], [],[]> the least || (DET DET:'the' DET:'least') || <y, l1, e, [ l1:[ | l2:[ y | ] THELEAST y l3:[|] ] ], [], [],[]> - // 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^elevation ]> + // 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 ]> // 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],[]> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-04 15:02:01
|
Revision: 3526 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3526&view=rev Author: sebastianwtr Date: 2012-01-04 15:01:50 +0000 (Wed, 04 Jan 2012) Log Message: ----------- [tbsl exploration] writes now into XML-Files Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -133,7 +133,7 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ + public queryInformation create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); @@ -143,9 +143,7 @@ long startIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); ArrayList<String> final_answer = new ArrayList<String>(); - ArrayList<String> final_query = new ArrayList<String>(); Set<String> final_query_hash = new HashSet<String>(); - Set<String> final_answer_hash = new HashSet<String>(); if(lstquery.isEmpty()){ saveNotParsedQuestions(query_struct.getQuery()); @@ -332,7 +330,41 @@ try{ String anfrage=it.next().toString(); answer_tmp=sendServerQuestionRequest(anfrage); - final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + answer_tmp=answer_tmp.replace("\"@en", ""); + answer_tmp=answer_tmp.replace("\"", ""); + + //filter answers! + if(query_struct.isHint()){ + System.out.println("Using hint!"); + /* + * Answertyps: resource, string, boolean, num, date + */ + if(query_struct.getType().contains("boolean")){ + if(answer_tmp.contains("true")||answer_tmp.contains("false")) final_answer.add(answer_tmp); + + } + else if (query_struct.getType().contains("resource")){ + final_answer.add(answer_tmp); + } + else if (query_struct.getType().contains("string")){ + if(!answer_tmp.contains("http")&&!answer_tmp.contains("EmtyAnswer")) { + String[] tmparray = answer_tmp.split("\n"); + for(String z : tmparray)final_answer.add(z); + } + + } + else if (query_struct.getType().contains("num")){ + if(answer_tmp.matches("[0-9]*")) final_answer.add(answer_tmp); + + } + else if (query_struct.getType().contains("date")){ + final_answer.add(answer_tmp); + } + } + else{ + //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + final_answer.add(answer_tmp); + } } catch (Exception e){ @@ -341,68 +373,9 @@ + query_struct.setResult(final_answer); - BufferedReader in = null; - - String tmp=""; - // Lies Textzeilen aus der Datei in einen Vector: - try { - in = new BufferedReader( - new InputStreamReader( - new FileInputStream( "/tmp/answer" ) ) ); - String s; - while( null != (s = in.readLine()) ) { - tmp+="\n"+s; - } - } catch( FileNotFoundException ex ) { - } catch( Exception ex ) { - System.out.println( ex ); - } finally { - if( in != null ) - try { - in.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - String out=""; - for(String answer : final_answer){ - if(answer!=null){ - //only answered question - if(!answer.contains("Error in searching Wordnet with word") && !answer.contains("EmtyAnswer")&& !answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; - - /* - //only questions with wordnet error - if(answer.contains("Error in searching Wordnet with word"))out=out+ "\n"+answer+"\n"; - - //only questions with emty answers - if(answer.contains("EmtyAnswer"))out=out+ "\n"+answer+"\n"; -*/ - //only questions with Error in Properties - // if(answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; - - //out+= "\n"+answer+"\n"; - } - else{ - System.out.println("Answer was null"); - } - - } - System.out.println(query_struct.getQuery()); - out = out.replace("@en","").replace("\"","").replace("^^<http://www.w3.org/2001/XMLSchema#int> ", ""); - System.out.println(out); - - BufferedWriter outfile = new BufferedWriter( - new OutputStreamWriter( - new FileOutputStream( "/tmp/answer" ) ) ); - - outfile.write(tmp+"\n"+query_struct.getQuery()+" :\n"+out); - outfile.close(); - long stopIterationTime = System.currentTimeMillis(); - System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); - System.out.println("The Iteration took "+ (stopIterationTime-startIterationTime)+ " ms"); - System.out.println("All took "+ (stopIterationTime-startParsingTime)+ " ms"); + return query_struct; } private ArrayList<String> newIteration(ArrayList<String> querylist, String query) throws SQLException, Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -1,5 +1,7 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; +import java.util.ArrayList; + public class queryInformation { // <question id="32" type="boolean" fusion="false" aggregation="false" yago="false"> public final String query; @@ -10,8 +12,18 @@ public final String id; public final String XMLtype; public final boolean hint; + public ArrayList<String> result = new ArrayList<String>(); - public boolean isHint() { + public ArrayList<String> getResult() { + return result; + } + + public void setResult(ArrayList<String> new_result) { + this.result=new_result; + } + + + public boolean isHint() { return hint; } 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-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -1,9 +1,11 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -121,7 +123,12 @@ //get each line and send it to the parser //String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1 queryInformation newQuery = new queryInformation(s,"0","",false,false,false,"non",false); - sparql.create_Sparql_query(newQuery); + queryInformation result = new queryInformation(s,"0","",false,false,false,"non",false); + result=sparql.create_Sparql_query(newQuery); + ArrayList<String> ergebnis = result.getResult(); + for(String i: ergebnis){ + System.out.println(i); + } } long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -138,6 +145,7 @@ //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + ArrayList<queryInformation> list_of_resultstructs = new ArrayList<queryInformation>(); //if you dont want to use the hints in the questions, use false list_of_structs=generateStruct(line,true); //Start Time measuring @@ -152,12 +160,16 @@ System.out.println("Query: "+s.getQuery()); System.out.println("Type: "+s.getType()); System.out.println("XMLType: "+s.getXMLtype()); - sparql.create_Sparql_query(s); + list_of_resultstructs.add(sparql.create_Sparql_query(s)); } - //sparql.create_Sparql_query(s); - + //Print to Console + System.out.println("\n#############\n Result:"); + for(queryInformation s : list_of_resultstructs){ + System.out.println(s.getResult()); + } + createXML(list_of_resultstructs); long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -168,7 +180,12 @@ else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); - sparql.create_Sparql_query(newQuery); + queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); + result= sparql.create_Sparql_query(newQuery); + ArrayList<String> ergebnis = result.getResult(); + for(String i: ergebnis){ + System.out.println(i); + } long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -182,6 +199,39 @@ } + private static void createXML(ArrayList<queryInformation> list){ + + + String xmlDocument=""; + int counter=0; + for (queryInformation s : list){ + String tmp; + if(counter==0){ + counter=counter+1; + xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + } + tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string><query></query><ANSWERS>"; + for(String i : s.getResult())tmp+="<answer>"+i+"</answer>"; + tmp+="</ANSWERS></question>"; + xmlDocument+=tmp; + + } + xmlDocument+="</dataset>"; + File file; + FileWriter writer; + file = new File("/home/swalter/result.xml"); + try { + writer = new FileWriter(file ,false); + writer.write(xmlDocument); + writer.flush(); + + + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-04 13:49:52
|
Revision: 3525 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3525&view=rev Author: sebastianwtr Date: 2012-01-04 13:49:40 +0000 (Wed, 04 Jan 2012) Log Message: ----------- [tbsl exploration] started to implement XML input/output Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -16,6 +16,10 @@ public class GetRessourcePropertys { + //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //String Prefix="http://dbpedia.org/sparql"; + String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; + public HashMap<String,String> getPropertys(String element, String side) throws IOException{ return sendServerPropertyRequest(element,side); @@ -55,10 +59,10 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp_left="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_left="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String tmp_left=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; //System.out.println("property right!!! : " +tmp_right); - String tmp_right="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String tmp_right=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String verarbeitungsurl=null; if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -13,6 +13,8 @@ import java.net.URL; import java.util.ArrayList; 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; @@ -43,6 +45,7 @@ + public class SparqlObject { //global Variable dict @@ -57,6 +60,12 @@ private static mySQLDictionary myindex; boolean only_best_levensthein_query; + //change here and in getRessourcePropertys + //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //String Prefix="http://dbpedia.org/sparql"; + String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; + + //Konstruktor public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ @@ -75,7 +84,7 @@ //normaly 1 setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren - setIterationdepth(1); + setIterationdepth(9); setNumberofanswers(1); only_best_levensthein_query=false; @@ -124,20 +133,22 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(String question) throws JWNLException, IOException, SQLException{ + public void create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); long startParsingTime = System.currentTimeMillis(); - lstquery=getQuery(question); + lstquery=getQuery(query_struct.getQuery()); long endParsingTime = System.currentTimeMillis(); long startIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); ArrayList<String> final_answer = new ArrayList<String>(); ArrayList<String> final_query = new ArrayList<String>(); + Set<String> final_query_hash = new HashSet<String>(); + Set<String> final_answer_hash = new HashSet<String>(); if(lstquery.isEmpty()){ - saveNotParsedQuestions(question); + saveNotParsedQuestions(query_struct.getQuery()); } for(ArrayList<String> querylist : lstquery){ @@ -179,7 +190,7 @@ String out=null; if (query.equals("") || query.equals(" ")||query.length()==0) query="Could not parse"; - out=tmp + "\n" + question + ":\n"+query+"\n"; + out=tmp + "\n" + query_struct.getQuery() + ":\n"+query+"\n"; BufferedWriter outfile = new BufferedWriter( new OutputStreamWriter( @@ -219,9 +230,8 @@ e.printStackTrace(); } } - String answer; - answer=sendServerQuestionRequest(query); - final_answer.add("Begin:\n"+query +"\n"+answer+" \n End"); + + final_query_hash.add(query); } /* @@ -236,68 +246,28 @@ ArrayList<String> final_answer_tmp = new ArrayList<String>(); ArrayList<String> final_query_tmp=new ArrayList<String>(); if(querylist.size()==4){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); - //final_query_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN"); for(String i: final_query_tmp){ + final_query_hash.add(i); - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } } } if(querylist.size()>4&&query.contains("rdf:type")){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN"); for(String i: final_query_tmp){ - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&!query.contains("rdf:type")){ final_query_tmp=advancedCase(querylist, query,"LEVENSTHEIN"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } @@ -321,106 +291,28 @@ final_query_tmp=simpleCase(querylist, query, "WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&query.contains("rdf:type")){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&!query.contains("rdf:type")){ final_query_tmp=advancedCase(querylist, query,"WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } - /* if(querylist.size()==4){ - - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); - final_query_tmp = simpleWordnetIteration(querylist, query); - for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } - } - } - final_answer_tmp=simpleWordnetIteration(querylist, query); - //if(querylist.size()>4)final_answer=complexWordnetIteration(querylist, query); - - //for a test only use: - if(querylist.size()>4){ - final_query_tmp=newIteration(querylist,query); - for(String i: final_query_tmp){ - boolean double_query=false; - for(String s: final_query ){ - if(s.contains(i)){ - double_query=true; - } - } - if(double_query==false){ - final_query.add(i); - } - } - }*/ + } @@ -431,16 +323,25 @@ * Send Query to Server and get answers */ - for(String anfrage : final_query){ - String answer_tmp; - answer_tmp=sendServerQuestionRequest(anfrage); - //System.out.println("Antwort vom Server: "+answer_tmp); - if(!final_answer.contains(anfrage)) - final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - } + Iterator it = final_query_hash.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + String answer_tmp; + try{ + String anfrage=it.next().toString(); + answer_tmp=sendServerQuestionRequest(anfrage); + final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + } + catch (Exception e){ + + } + } + + + + BufferedReader in = null; String tmp=""; @@ -488,7 +389,7 @@ } } - System.out.println(question); + System.out.println(query_struct.getQuery()); out = out.replace("@en","").replace("\"","").replace("^^<http://www.w3.org/2001/XMLSchema#int> ", ""); System.out.println(out); @@ -496,7 +397,7 @@ new OutputStreamWriter( new FileOutputStream( "/tmp/answer" ) ) ); - outfile.write(tmp+"\n"+question+" :\n"+out); + outfile.write(tmp+"\n"+query_struct.getQuery()+" :\n"+out); outfile.close(); long stopIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); @@ -1928,7 +1829,7 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); + String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); URL url; InputStream is; InputStreamReader isr; @@ -1966,7 +1867,7 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); URL url; @@ -2001,11 +1902,8 @@ } private String createAnswer(String string){ - //<td>Klaus Wowereit</td> - //get with regex all between <td> </td> - - Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); + /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); Matcher m = p.matcher (string); String result=""; @@ -2013,8 +1911,23 @@ if(m.group(1)!=null) result = result+" "+ m.group(1); } - + */ + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + String result=""; + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + result = result+"\n"+ m.group(1); + + } + } + if (result.length()==0) result="EmtyAnswer"; + if(string.matches("true")|| string.matches("false")) result=string; return result; @@ -2024,17 +1937,31 @@ //get with regex all between <td> </td> - Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); + /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); Matcher m = p.matcher (string); ArrayList<String> result=new ArrayList<String>(); while (m.find()) { if(m.group(1)!=null) result.add(m.group(1)); - } + }*/ + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + ArrayList<String> result= new ArrayList<String>(); + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + result.add(m.group(1)); + + } + } + //if (result.length()==0) result="EmtyAnswer"; - + if(string.matches("true")|| string.matches("false")) result.add(string); return result; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -0,0 +1,53 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +public class queryInformation { + // <question id="32" type="boolean" fusion="false" aggregation="false" yago="false"> + public final String query; + public final String type; + public final boolean fusion; + public final boolean aggregation; + public final boolean yago; + public final String id; + public final String XMLtype; + public final boolean hint; + + public boolean isHint() { + return hint; + } + + + public String getXMLtype() { + return XMLtype; + } + + + public String getId() { + return id; + } + public String getQuery() { + return query; + } + public String getType() { + return type; + } + public boolean isFusion() { + return fusion; + } + public boolean isAggregation() { + return aggregation; + } + public boolean isYago() { + return yago; + } + + public queryInformation(String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1, boolean hint1){ + this.query=query1; + this.type=type1; + this.fusion=fusion1; + this.aggregation=aggregation1; + this.yago=yago1; + this.id=id1; + this.XMLtype=XMLtype1; + this.hint=hint1; + } +} 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-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -2,6 +2,7 @@ import java.io.BufferedReader; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -9,10 +10,14 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.didion.jwnl.JWNLException; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; +import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -114,7 +119,9 @@ System.out.println(s); anzahl++; //get each line and send it to the parser - sparql.create_Sparql_query(s); + //String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1 + queryInformation newQuery = new queryInformation(s,"0","",false,false,false,"non",false); + sparql.create_Sparql_query(newQuery); } long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -122,9 +129,46 @@ System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); } + if(line.contains(":xml")&& schleife==true){ + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + + + System.out.println("Please enter Path of xml File:"); + line=in.readLine(); + + //create Structs + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + //if you dont want to use the hints in the questions, use false + list_of_structs=generateStruct(line,true); + //Start Time measuring + long startTime = System.currentTimeMillis(); + + int anzahl=0; + for(queryInformation s : list_of_structs){ + anzahl=anzahl+1; + System.out.println(""); + if(s.getId()==""||s.getId()==null)System.out.println("NO"); + System.out.println("ID: "+s.getId()); + System.out.println("Query: "+s.getQuery()); + System.out.println("Type: "+s.getType()); + System.out.println("XMLType: "+s.getXMLtype()); + sparql.create_Sparql_query(s); + } + + + //sparql.create_Sparql_query(s); + + long timeNow = System.currentTimeMillis(); + long diff = timeNow-startTime; + + System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); + + } + else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); - sparql.create_Sparql_query(line); + queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); + sparql.create_Sparql_query(newQuery); long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -139,20 +183,126 @@ - private static String getEntity(String query, String name) throws IOException, InterruptedException{ + private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { - // String query_complete="wget "+"\""+query+"\""+" -O "+"\""+name+"\""; - URL url = new URL(query); - ReadableByteChannel rbc = Channels.newChannel(url.openStream()); - //System.out.println(rbc.toString()); - FileOutputStream fos = new FileOutputStream(name); - //max 200MB = 209715200 Byte - fos.getChannel().transferFrom(rbc, 0, 209715200 ); - + String XMLType=null; + + BufferedReader in = null; + + String tmp=""; + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream(filename) ) ); + String s; + while( null != (s = in.readLine()) ) { + tmp=tmp+s; + //System.out.println(tmp); + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } - return name; + String string=tmp; + Pattern p = Pattern.compile (".*\\<question(.*)\\</question\\>.*"); + Matcher m = p.matcher (string); + + + if(string.contains("id=\"dbpedia-train\"><question")){ + string=string.replace("id=\"dbpedia-train\"><question", ""); + XMLType="dbpedia-train"; + System.out.println("dbpedia-train"); + } + if(string.contains("id=\"dbpedia-test\"><question")){ + string=string.replace("id=\"dbpedia-test\"><question", ""); + XMLType="dbpedia-test"; + //System.out.println("dbpedia-test"); + } + ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); + String [] bla = string.split("</question><question"); + for(String s : bla){ + String query=""; + String type=""; + boolean fusion=false; + boolean aggregation=false; + boolean yago=false; + String id=""; + + Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + Matcher m1 = p1.matcher(s); + //System.out.println(""); + while(m1.find()){ + //System.out.println(m1.group(1)); + Pattern p2= Pattern.compile(".*><string>(.*)"); + Matcher m2 = p2.matcher(m1.group(1)); + while(m2.find()){ + //System.out.println("Query: "+ m2.group(1)); + query=m2.group(1); + } + Pattern p3= Pattern.compile("id=\"(.*)\" answer.*"); + Matcher m3 = p3.matcher(m1.group(1)); + while(m3.find()){ + //System.out.println("Id: "+ m3.group(1)); + id=m3.group(1); + } + + Pattern p4= Pattern.compile(".*answertype=\"(.*)\" fusion.*"); + Matcher m4 = p4.matcher(m1.group(1)); + while(m4.find()){ + //System.out.println("answertype: "+ m4.group(1)); + type=m4.group(1); + } + + Pattern p5= Pattern.compile(".*fusion=\"(.*)\" aggregation.*"); + Matcher m5 = p5.matcher(m1.group(1)); + while(m5.find()){ + //System.out.println("fusion: "+ m5.group(1)); + if(m5.group(1).contains("true"))fusion=true; + else fusion=false; + } + + Pattern p6= Pattern.compile(".*aggregation=\"(.*)\" yago.*"); + Matcher m6 = p6.matcher(m1.group(1)); + while(m6.find()){ + //System.out.println("aggregation: "+ m6.group(1)); + if(m6.group(1).contains("true"))aggregation=true; + else aggregation=false; + } + + Pattern p7= Pattern.compile(".*yago=\"(.*)\" ><string>.*"); + Matcher m7 = p7.matcher(m1.group(1)); + while(m7.find()){ + //System.out.println("yago: "+ m7.group(1)); + if(m7.group(1).contains("true"))yago=true; + else yago=false; + } + + + + } + queryInformation blaquery=new queryInformation(query, id,type,fusion,aggregation,yago,XMLType,hint); + if(id!=""&&id!=null) querylist.add(blaquery); + } + /* for(queryInformation s : querylist){ + System.out.println(""); + if(s.getId()==""||s.getId()==null)System.out.println("NO"); + System.out.println("ID: "+s.getId()); + System.out.println("Query: "+s.getQuery()); + System.out.println("Type: "+s.getType()); + System.out.println("XMLType: "+s.getXMLtype()); + }*/ + return querylist; } + - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-03 12:56:18
|
Revision: 3524 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3524&view=rev Author: sebastianwtr Date: 2012-01-03 12:56:11 +0000 (Tue, 03 Jan 2012) Log Message: ----------- [tbsl exploration] refactoring Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-03 12:26:07 UTC (rev 3523) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-03 12:56:11 UTC (rev 3524) @@ -78,7 +78,7 @@ setIterationdepth(1); setNumberofanswers(1); - only_best_levensthein_query=true; + only_best_levensthein_query=false; } /* @@ -259,8 +259,10 @@ } - if(querylist.size()>4){ - final_query_tmp=complexeLevinstheinIteration(querylist, query); + if(querylist.size()>4&&query.contains("rdf:type")){ + //System.out.println("YEAH!!!!!"); + //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN"); for(String i: final_query_tmp){ //do it unnice for first @@ -279,10 +281,30 @@ } } + if(querylist.size()>4&&!query.contains("rdf:type")){ + final_query_tmp=advancedCase(querylist, query,"LEVENSTHEIN"); + for(String i: final_query_tmp){ + + //do it unnice for first + boolean double_query=false; + for(String s: final_query ){ + + if(s.contains(i)){ + double_query=true; + + } + } + if(double_query==false){ + + final_query.add(i); + } + } + } + } /* * ################################################################################################# @@ -338,6 +360,27 @@ } } + if(querylist.size()>4&&!query.contains("rdf:type")){ + final_query_tmp=advancedCase(querylist, query,"WORDNET"); + for(String i: final_query_tmp){ + + //do it unnice for first + boolean double_query=false; + for(String s: final_query ){ + + if(s.contains(i)){ + double_query=true; + + } + } + if(double_query==false){ + + final_query.add(i); + } + } + } + + /* if(querylist.size()==4){ @@ -823,10 +866,9 @@ return new_queries; } - private ArrayList<String> complexeLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, + private ArrayList<String> advancedCase(ArrayList<String> querylist, String query, String fall) throws SQLException, JWNLException { - ArrayList<String> final_answer=new ArrayList<String>(); ArrayList<String> new_queries= new ArrayList<String>(); String resourceOne=""; String property_to_compare_withOne=""; @@ -902,56 +944,11 @@ //Iterate over property from resource one - for (Entry<String, String> entryOne : propertiesOne.entrySet()) { - - String queryOne=query; - String keyOne = entryOne.getKey(); - keyOne=keyOne.replace("\"",""); - keyOne=keyOne.replace("@en",""); - String valueOne = entryOne.getValue(); - - - double levnstheinDistanzeOne=Levenshtein.nld(property_to_compare_withOne.toLowerCase(), keyOne); - - /*if distance is higher or equals LevenstheinMin, replace old uri with new uri - * and use that new query, for the property of the second resource - */ - if(levnstheinDistanzeOne>=LevenstheinMin){ - String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); - if(!queryOne.contains(replacementOne)){ - replacementOne=replacementOne.replace("ontology", "property"); - } - queryOne=queryOne.replace(replacementOne,valueOne); - - - /* - * Iterate now over the second set of properties, but this time not using the original query in which - * to replace the old uri with the new one, but using queryOne from the first step. - */ - for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { - String keyTwo = entryTwo.getKey(); - String valueTwo = entryTwo.getValue(); - keyTwo=keyTwo.replace("\"",""); - keyTwo=keyTwo.replace("@en",""); - - //again calculate the nld with the property from the second condition and the property from the propertyset - double levnstheinDistanzeTwo=Levenshtein.nld(property_to_compare_withTwo.toLowerCase(), keyTwo); - - if(levnstheinDistanzeTwo>LevenstheinMin){ - String queryTwo=queryOne; - String replacement = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); - if(!queryTwo.contains(replacement)){ - replacement=replacement.replace("ontology", "property"); - } - queryTwo=queryTwo.replace(replacement,valueTwo); - System.out.println("Complex Levensthein Query: "+ queryTwo); - new_queries.add(queryTwo); - } - - } - } - } + + if(fall.contains("LEVENSTHEIN"))new_queries=doComplexLevensthein(query, property_to_compare_withOne,property_to_compare_withTwo, getUriFromIndex(property_to_compare_withOne.toLowerCase(),1),propertiesOne,propertiesTwo); + if(fall.contains("WORDNET")) new_queries=doComplexeWordnet(query, property_to_compare_withOne,property_to_compare_withTwo, propertiesOne, propertiesTwo); + //add original query for iteration new_queries.add(query); } @@ -959,7 +956,42 @@ return new_queries; } +private ArrayList<String> doComplexLevensthein(String query, String property_to_compare_withOne, String property_to_compare_withTwo, String uri_of_property_one, HashMap<String,String> propertiesOne,HashMap<String,String> propertiesTwo) throws SQLException{ + ArrayList<String> new_queries= new ArrayList<String>(); + for (Entry<String, String> entryOne : propertiesOne.entrySet()) { + + String queryOne=query; + String keyOne = entryOne.getKey(); + keyOne=keyOne.replace("\"",""); + keyOne=keyOne.replace("@en",""); + String valueOne = entryOne.getValue(); + + + double levnstheinDistanzeOne=Levenshtein.nld(property_to_compare_withOne.toLowerCase(), keyOne); + + /*if distance is higher or equals LevenstheinMin, replace old uri with new uri + * and use that new query, for the property of the second resource + */ + if(levnstheinDistanzeOne>=LevenstheinMin){ + //String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); + String replacementOne =uri_of_property_one; + if(!queryOne.contains(replacementOne)){ + replacementOne=replacementOne.replace("ontology", "property"); + } + queryOne=queryOne.replace(replacementOne,valueOne); + + + /* + * Iterate now over the second set of properties, but this time not using the original query in which + * to replace the old uri with the new one, but using queryOne from the first step. + */ + new_queries=doLevensthein(queryOne, property_to_compare_withTwo, getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1), propertiesTwo); + } + } + return new_queries; +} + private ArrayList<String> doWordnet(String query, String property, String uri_of_property,HashMap<String,String> properties) throws SQLException, JWNLException { @@ -1044,241 +1076,174 @@ } - private ArrayList<String> complexWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, - JWNLException { - ArrayList<String> final_answer=new ArrayList<String>(); - ArrayList<String> new_queries= new ArrayList<String>(); - - String resourceOne=""; - String property_to_compare_withOne=""; - String resourceTwo=""; - String property_to_compare_withTwo=""; - String sideOfPropertyOne="LEFT"; - String sideOfPropertyTwo="LEFT"; - + private ArrayList<String> doComplexeWordnet(String query, + String property_to_compare_withOne, + String property_to_compare_withTwo, + HashMap<String, String> propertiesOne, + HashMap<String, String> propertiesTwo) throws SQLException, + JWNLException { - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - tmpcounter=tmpcounter+1; - //get resource and property from the first condtion - if(tmpcounter>=1&&tmpcounter<=4){ - if(s.contains("LEFT")){ - sideOfPropertyOne="LEFT"; - resourceOne=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfPropertyOne="RIGHT"; - resourceOne=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_withOne=s.replace("PROPERTY",""); - } - - } - //get resource and property from the second condtion - if(tmpcounter>4){ - if(s.contains("LEFT")){ - sideOfPropertyTwo="LEFT"; - resourceTwo=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfPropertyTwo="RIGHT"; - resourceTwo=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_withTwo=s.replace("PROPERTY",""); - } - - } - } - System.out.println("Property to compare:: "+ property_to_compare_withOne); - System.out.println("Resource: "+ resourceOne); + ArrayList<String> new_queries = new ArrayList<String> (); + /* + * #################################### Semantics One############################################# + */ - HashMap<String,String> propertiesOne = new HashMap<String, String>(); - HashMap<String,String> propertiesTwo = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - Boolean goOnAfterProperty = true; + + //System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); + ArrayList<String> semanticsOne=new ArrayList<String>(); + ArrayList<String> tmp_semanticsOne=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchPropertiesOne=new ArrayList<String>(); + semanticsOne.add(property_to_compare_withOne); - //gets the properties for both conditions - try { - propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); - propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); - if (propertiesOne==null){ - - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - } + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_One=myindex.getWordnetHelp(property_to_compare_withOne); + if(_temp_One==null){ + tmp_semanticsOne=semanticsOne; + } + else{ + semanticsOne.clear(); + semanticsOne.add(_temp_One); + tmp_semanticsOne=semanticsOne; + } + + //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached + Boolean goOnAfterWordnet = true; + for(int i=0;i<=explorationdepthwordnet;i++){ - } catch (IOException e) { - - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - - } - if(goOnAfterProperty==true){ - - /* - * #################################### Semantics One############################################# - */ - - - //System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); - ArrayList<String> semanticsOne=new ArrayList<String>(); - ArrayList<String> tmp_semanticsOne=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchPropertiesOne=new ArrayList<String>(); - semanticsOne.add(property_to_compare_withOne); - - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_One=myindex.getWordnetHelp(property_to_compare_withOne); - if(_temp_One==null){ - tmp_semanticsOne=semanticsOne; - } - else{ - semanticsOne.clear(); - semanticsOne.add(_temp_One); - tmp_semanticsOne=semanticsOne; - } - - //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached - Boolean goOnAfterWordnet = true; - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semanticsOne=getSemantics(tmp_semanticsOne); - if (tmp_semanticsOne==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semanticsOne){ - if(!semanticsOne.contains(k)) semanticsOne.add(k); - } - } - - } catch (IOException e) { - + try { + tmp_semanticsOne=getSemantics(tmp_semanticsOne); + if (tmp_semanticsOne==null){ goOnAfterWordnet=false; System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); - + } - - - } - /* - * #################################### Semantics Two############################################# - */ + else{ + //each word only one time + for(String k : tmp_semanticsOne){ + if(!semanticsOne.contains(k)) semanticsOne.add(k); + } + } + + } catch (IOException e) { - System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); - ArrayList<String> semanticsTwo=new ArrayList<String>(); - ArrayList<String> tmp_semanticsTwo=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchPropertiesTwo=new ArrayList<String>(); - semanticsTwo.add(property_to_compare_withTwo); + goOnAfterWordnet=false; + System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); + + } - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_Two=myindex.getWordnetHelp(property_to_compare_withTwo); - if(_temp_Two==null){ - tmp_semanticsOne=semanticsTwo; - } - else{ - semanticsTwo.clear(); - semanticsTwo.add(_temp_Two); - tmp_semanticsTwo=semanticsTwo; - } - - //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached - for(int i=0;i<=explorationdepthwordnet;i++){ + + } + /* + * #################################### Semantics Two############################################# + */ - try { - tmp_semanticsTwo=getSemantics(tmp_semanticsTwo); - if (tmp_semanticsTwo==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); + System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); + ArrayList<String> semanticsTwo=new ArrayList<String>(); + ArrayList<String> tmp_semanticsTwo=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchPropertiesTwo=new ArrayList<String>(); + semanticsTwo.add(property_to_compare_withTwo); + + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_Two=myindex.getWordnetHelp(property_to_compare_withTwo); + if(_temp_Two==null){ + tmp_semanticsOne=semanticsTwo; + } + else{ + semanticsTwo.clear(); + semanticsTwo.add(_temp_Two); + tmp_semanticsTwo=semanticsTwo; + } + + //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached + for(int i=0;i<=explorationdepthwordnet;i++){ - } - else{ - //each word only one time - for(String k : tmp_semanticsTwo){ - if(!semanticsTwo.contains(k)) semanticsTwo.add(k); - } - } - - } catch (IOException e) { - + try { + tmp_semanticsTwo=getSemantics(tmp_semanticsTwo); + if (tmp_semanticsTwo==null){ goOnAfterWordnet=false; System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); - + } - - - } + else{ + //each word only one time + for(String k : tmp_semanticsTwo){ + if(!semanticsTwo.contains(k)) semanticsTwo.add(k); + } + } + + } catch (IOException e) { + + goOnAfterWordnet=false; + System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); + + } + + } + + + if(goOnAfterWordnet==true){ - if(goOnAfterWordnet==true){ - + + //start iterating over the propery sets + for (Entry<String, String> entryOne : propertiesOne.entrySet()) { + String keyOne = entryOne.getKey(); + String valueOne = entryOne.getValue(); + String queryOne=query; + keyOne=keyOne.replace("\"",""); + keyOne=keyOne.replace("@en",""); - //start iterating over the propery sets - for (Entry<String, String> entryOne : propertiesOne.entrySet()) { - String keyOne = entryOne.getKey(); - String valueOne = entryOne.getValue(); - String queryOne=query; - keyOne=keyOne.replace("\"",""); - keyOne=keyOne.replace("@en",""); - - for(String b : semanticsOne){ - if(keyOne.contains(b.toLowerCase())){ - if(!result_SemanticsMatchPropertiesOne.contains(keyOne)){ - //create new query - result_SemanticsMatchPropertiesOne.add(keyOne); - String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); - if(!queryOne.contains(replacementOne)){ - replacementOne=replacementOne.replace("ontology", "property"); - } - queryOne=queryOne.replace(replacementOne,valueOne); - - for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { - String keyTwo = entryTwo.getKey(); - String valueTwo = entryTwo.getValue(); - keyTwo=keyTwo.replace("\"",""); - keyTwo=keyTwo.replace("@en",""); - - for(String z : semanticsTwo){ - if(keyTwo.contains(z.toLowerCase())){ - if(!result_SemanticsMatchPropertiesTwo.contains(keyTwo)){ - //create new query - result_SemanticsMatchPropertiesTwo.add(keyTwo); - String queryTwo=queryOne; - String replacementTwo = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); - if(!queryTwo.contains(replacementTwo)){ - replacementTwo=replacementTwo.replace("ontology", "property"); - } - queryTwo=queryTwo.replace(replacementTwo,valueTwo); - System.out.println("Complexe Wordnet Query: "+ queryTwo); - new_queries.add(queryTwo); - } + for(String b : semanticsOne){ + if(keyOne.contains(b.toLowerCase())){ + if(!result_SemanticsMatchPropertiesOne.contains(keyOne)){ + //create new query + result_SemanticsMatchPropertiesOne.add(keyOne); + String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); + if(!queryOne.contains(replacementOne)){ + replacementOne=replacementOne.replace("ontology", "property"); + } + queryOne=queryOne.replace(replacementOne,valueOne); + + for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { + String keyTwo = entryTwo.getKey(); + String valueTwo = entryTwo.getValue(); + keyTwo=keyTwo.replace("\"",""); + keyTwo=keyTwo.replace("@en",""); + + for(String z : semanticsTwo){ + if(keyTwo.contains(z.toLowerCase())){ + if(!result_SemanticsMatchPropertiesTwo.contains(keyTwo)){ + //create new query + result_SemanticsMatchPropertiesTwo.add(keyTwo); + String queryTwo=queryOne; + String replacementTwo = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); + if(!queryTwo.contains(replacementTwo)){ + replacementTwo=replacementTwo.replace("ontology", "property"); + } + queryTwo=queryTwo.replace(replacementTwo,valueTwo); + System.out.println("Complexe Wordnet Query: "+ queryTwo); + new_queries.add(queryTwo); } } } - - } } + + } } - - - - } + } - //add original query for iteration - new_queries.add(query); - + } - } - + + + //add original query for iteration + new_queries.add(query); + + } + return new_queries; -} + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-03 12:26:15
|
Revision: 3523 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3523&view=rev Author: sebastianwtr Date: 2012-01-03 12:26:07 +0000 (Tue, 03 Jan 2012) Log Message: ----------- [tbsl exploration] finished with IsA Case and started to refactor the Code Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-03 08:50:54 UTC (rev 3522) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-03 12:26:07 UTC (rev 3523) @@ -64,7 +64,7 @@ if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; if(side.contains("LEFT")) verarbeitungsurl=tmp_left; - System.out.println(verarbeitungsurl); + //System.out.println(verarbeitungsurl); //just in case..... if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; @@ -115,7 +115,7 @@ //System.out.println(tmp_array[i-1].toLowerCase() + " " +tmp_array[i]); } - System.out.println("created Properties: "+hm); + // System.out.println("created Properties: "+hm); return hm; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-03 08:50:54 UTC (rev 3522) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-03 12:26:07 UTC (rev 3523) @@ -55,6 +55,7 @@ BasicTemplator btemplator; Templator templator; private static mySQLDictionary myindex; + boolean only_best_levensthein_query; //Konstruktor public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ @@ -74,8 +75,10 @@ //normaly 1 setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren - setIterationdepth(0); + setIterationdepth(1); setNumberofanswers(1); + + only_best_levensthein_query=true; } /* @@ -235,7 +238,8 @@ if(querylist.size()==4){ //System.out.println("YEAH!!!!!"); //final_answer_tmp=simpleLevinstheinIteration(querylist, query); - final_query_tmp=simpleLevinstheinIteration(querylist, query); + //final_query_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN"); for(String i: final_query_tmp){ //do it unnice for first @@ -288,10 +292,54 @@ * Only Wordnet!!! */ if(getIterationdepth()==2&&startIterating==true||getIterationdepth()==9&&startIterating==true){ - ArrayList<String> final_answer_tmp = new ArrayList<String>(); ArrayList<String> final_query_tmp = new ArrayList<String>(); - + //isAIteration(querylist, query); + if(querylist.size()==4){ + + final_query_tmp=simpleCase(querylist, query, "WORDNET"); + for(String i: final_query_tmp){ + + //do it unnice for first + boolean double_query=false; + for(String s: final_query ){ + + if(s.contains(i)){ + double_query=true; + + } + } + if(double_query==false){ + + final_query.add(i); + } + } + } + + if(querylist.size()>4&&query.contains("rdf:type")){ + //System.out.println("YEAH!!!!!"); + //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"WORDNET"); + for(String i: final_query_tmp){ + + //do it unnice for first + boolean double_query=false; + for(String s: final_query ){ + + if(s.contains(i)){ + double_query=true; + + } + } + if(double_query==false){ + + final_query.add(i); + } + } + } + + + /* if(querylist.size()==4){ //final_answer_tmp=simpleLevinstheinIteration(querylist, query); final_query_tmp = simpleWordnetIteration(querylist, query); @@ -329,7 +377,7 @@ final_query.add(i); } } - } + }*/ } @@ -474,7 +522,7 @@ querylist_new.add("PROPERTY"+firstProperty); querylist_new.add(sideOfProperty+firstResource); if(answer_tmp.isEmpty()){ - answer_tmp=simpleWordnetIterationArray(querylist_new,firstquery); + answer_tmp=simpleCase(querylist_new,firstquery,"WORDNET"); } //if answer_tmp is still empty return null and exit function if(answer_tmp.isEmpty()){final_answer.add("new Iteration didnt work"); @@ -516,7 +564,7 @@ for(ArrayList as: secondquerylist){ ArrayList<String> answer_tmp_two=new ArrayList<String>(); //answer_tmp_two=sendServerQuestionRequestArray(s); - answer_tmp=simpleWordnetIterationArray(as,as.get(0).toString()); + answer_tmp=simpleCase(as,as.get(0).toString(),"WORDNET"); for(String t :answer_tmp_two){ final_answer.add(t); System.out.println("Answer from advanced Iteration: "+ t); @@ -529,27 +577,141 @@ } - /* - * if there are more than one condition and if there is an isA Case in it, use this function. - * TODO: Change other simple Case function, that they have a Resource to deal with, or change the get Query function - */ - private ArrayList<String> isAIteration(ArrayList<String> querylist, String query) throws SQLException, + + private ArrayList<String> isAIteration(ArrayList<String> querylist, String query, String fall) throws SQLException, JWNLException { - //only for special case, that the first condition has a resource - ArrayList<String> final_answer=new ArrayList<String>(); + ArrayList<String> new_queries= new ArrayList<String>(); + //TODO: in get Query change, that there will be a second query, but only with the part of the condition upsidedown, which doesnt contains an isA + System.out.println("\n In IsA Iteration \n"); - return final_answer; + /* Erster Schritt, alle x rausbekommen: + e.g: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE {?x rdf:type <http://dbpedia.org/ontology/Country>.} + + */ + //take query and use regex, to take only the part beween the {} + Pattern p = Pattern.compile (".*\\{(.*\\<http.*)\\}.*"); + Matcher m = p.matcher (query); + ArrayList<String> list_of_x=new ArrayList<String>(); + String query_for_x=null; + while(m.find()){ + String tmp=m.group(1); + + Pattern p2=Pattern.compile (".*(http://dbpedia.org/ontology/[A-Z].*)\\>\\W.*"); + Matcher m2 = p2.matcher (tmp); + //now we know, that we are in the part with the rdf type thing + while(m2.find()){ + query_for_x="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE { ?x rdf:type <"+m2.group(1)+">}"; + //System.out.println("Done: "+ query_for_x); + } + + } + + //now send query_for_x to the server, to get all x + System.out.println("IsA x-query: "+query_for_x); + if(query_for_x!=null)list_of_x=sendServerQuestionRequestArray(query_for_x); + + + /* + * Zweiter Schritt: + * alle Propertys z.B. der ersten 5 xe holen und in eine Liste packen + */ + + int number_of_x_used=5; + int tmpcounter=0; + + HashMap<String,String> list_of_properties=new HashMap<String,String>(); + + for(String s: list_of_x){ + /* + * First use left and also right Propertys + */ + tmpcounter++; + if(tmpcounter <=number_of_x_used){ + HashMap<String,String> propertiesleft = new HashMap<String, String>(); + HashMap<String,String> propertiesright = new HashMap<String, String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + + try { + propertiesleft=property.getPropertys(s,"LEFT"); + propertiesright=property.getPropertys(s,"RIGHT"); + } + catch (Exception e){ + + } + + /* + * now put the properties togehter + */ + list_of_properties.putAll(propertiesright); + list_of_properties.putAll(propertiesleft); + } + + } + //System.out.println(list_of_properties); + + /* + * get Property used in the original query + * + */ + + System.out.println("Original Query: "+query); + + //http://dbpedia.org/ontology/officialLanguage + + //look for property + Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/property/.*)\\>\\W\\?.*"); + Matcher m3 = p3.matcher(query); + while(m3.find()) System.out.println("Property in IsA: "+m3.group(1)); + + //look for ontology, which is NO class + //Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/^[A-Z].*)\\>\\W.*"); + Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[a-z].*)\\>\\W\\?.*"); + Matcher m4 = p4.matcher(query); + String uri_property=null; + while(m4.find()) { + uri_property=m4.group(1); + System.out.println("Uri_Property: "+ uri_property); + } + + /* + * Nice, now i get http://dbpedia.org/ontology/officialLanguage + */ + if(uri_property!=null){ + String property=uri_property.replace("http://dbpedia.org/ontology/", "").replace("http://dbpedia.org/property/", ""); + String property_to_compare_with=""; + + + for(String s : querylist){ + if(s.contains("PROPERTY")){ + property_to_compare_with=s.replace("PROPERTY",""); + } + + } + + + /* + * Dritter Schritt: original Query nehmen und über die Liste mit den Propertys laufen und normal mit wordnet/levensthein vergleichen + */ + + //I think, i dont need here the last part of the uri but the original word from the query! + //new_queries=doWordnet(query,property,uri_property,list_of_properties); + + //if you want to use wordnet: + if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,uri_property,list_of_properties); + if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with,uri_property,list_of_properties); + } + + return new_queries; + } - - - private ArrayList<String> simpleLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, + + private ArrayList<String> simpleCase(ArrayList<String> querylist, String query, String fall) throws SQLException, JWNLException { - System.out.println("In Simpe levensthein case!!"); - ArrayList<String> final_answer=new ArrayList<String>(); + System.out.println("In Simpe levensthein case!!"); String resource=""; String property_to_compare_with=""; String sideOfProperty="LEFT"; @@ -582,6 +744,7 @@ HashMap<String,String> properties = new HashMap<String, String>(); GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); @@ -604,56 +767,14 @@ } if(goOnAfterProperty==true){ - String bestQuery=""; - double highestNLD=0; - //iterate over properties - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - String value = entry.getValue(); - // System.out.println("Key "+ key +" and value "+value); - - //compare property gotten from the resource with the property from the original query - double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); - - //check if nld is greater than Levensthein - if(nld>=LevenstheinMin){ - //if its so, replace old uri with the new one - String querynew=query; - String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - if(!querynew.contains(replacement)){ - replacement=replacement.replace("ontology", "property"); - } - querynew=querynew.replace(replacement,value); - if(nld>highestNLD){ - bestQuery=querynew; - highestNLD=nld; - } - /* System.out.println("Simple Levensthein Query: "+ querynew); - new_queries.add(querynew);*/ - //only add, if nld is greater than the already existing nld. - - new_queries.add(querynew); - } - + if(fall.contains("WORDNET")) new_queries=doWordnet(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); + if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); + //new_queries=doLevensthein(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); + + //add original query + new_queries.add(query); + } - - - /*new_queries.add(bestQuery); - System.out.println("Best Query "+bestQuery);*/ - //add original query for iteration - - new_queries.add(query); - - //iterate over all Queries and get answer from Server - /* for(String anfrage : new_queries){ - String answer_tmp; - answer_tmp=sendServerQuestionRequest(anfrage); - System.out.println("Antwort vom Server: "+answer_tmp); - final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - }*/ - } //test to returnqueries, put them together and than send them to the server. @@ -661,6 +782,47 @@ //return final_answer; } + + + + private ArrayList<String> doLevensthein(String query, String property_to_compare_with,String uri_of_property, HashMap<String, String> properties) + throws SQLException { + ArrayList<String> new_queries= new ArrayList<String>(); + String bestQuery=""; + double highestNLD=0; + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + String value = entry.getValue(); + + //compare property gotten from the resource with the property from the original query + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + + //check if nld is greater than Levensthein + if(nld>=LevenstheinMin){ + //if its so, replace old uri with the new one + String querynew=query; + //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + String replacement =uri_of_property ; + if(!querynew.contains(replacement)){ + replacement=replacement.replace("ontology", "property"); + } + querynew=querynew.replace(replacement,value); + if(nld>highestNLD){ + bestQuery=querynew; + highestNLD=nld; + } + if(only_best_levensthein_query==true) new_queries.add(bestQuery); + else new_queries.add(querynew); + } + + } + + return new_queries; + } + private ArrayList<String> complexeLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { @@ -798,308 +960,90 @@ } -private ArrayList<String> simpleWordnetIterationArray(ArrayList<String> querylist, String query) throws SQLException, - JWNLException { - ArrayList<String> final_answer=new ArrayList<String>(); - - System.out.println("In simpleWordnetIteration"); - - String resource=""; - String property_to_compare_with=""; - String sideOfProperty="LEFT"; + +private ArrayList<String> doWordnet(String query, String property, String uri_of_property,HashMap<String,String> properties) throws SQLException, +JWNLException { + ArrayList<String> new_queries= new ArrayList<String>(); - - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - tmpcounter=tmpcounter+1; - if(tmpcounter>=1){ - if(s.contains("LEFT")){ - sideOfProperty="LEFT"; - resource=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfProperty="RIGHT"; - resource=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_with=s.replace("PROPERTY",""); - } - - } - } - System.out.println("Property to compare:: "+ property_to_compare_with); - System.out.println("Resource: "+ resource); + System.out.println("Start Iterating Wordnet with "+property+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + semantics.add(property); + System.out.println("Semantics: "+ semantics); + + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_=myindex.getWordnetHelp(property); + if(_temp_==null){ + tmp_semantics=semantics; + } + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + } + + System.out.println("tmp_semantics: "+ tmp_semantics); + Boolean goOnAfterWordnet = true; - - HashMap<String,String> properties = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - Boolean goOnAfterProperty = true; + for(int i=0;i<=explorationdepthwordnet;i++){ + try { - properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); - if (properties==null){ + tmp_semantics=getSemantics(tmp_semantics); + System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); + if (tmp_semantics==null){ + goOnAfterWordnet=false; + System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; } + else{ + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + } } catch (IOException e) { - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; + goOnAfterWordnet=false; + System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); } - if(goOnAfterProperty==true){ - - ArrayList<String> new_queries= new ArrayList<String>(); - - System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(property_to_compare_with); - System.out.println("Semantics: "+ semantics); - - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_=myindex.getWordnetHelp(property_to_compare_with); - if(_temp_==null){ - tmp_semantics=semantics; - } - else{ - semantics.clear(); - semantics.add(_temp_); - tmp_semantics=semantics; - } - - System.out.println("tmp_semantics: "+ tmp_semantics); - Boolean goOnAfterWordnet = true; - - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semantics=getSemantics(tmp_semantics); - System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); - if (tmp_semantics==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); - } - } - - } catch (IOException e) { - - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - - } - - } - - if(goOnAfterWordnet==true){ - - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - key=key.replace("\"",""); - key=key.replace("@en",""); - - for(String b : semantics){ - if(key.contains(b.toLowerCase())){ - if(!result_SemanticsMatchProperties.contains(key)){ - result_SemanticsMatchProperties.add(key); - String query_tmp=query; - String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - if(!query_tmp.contains(replacement)){ - replacement=replacement.replace("ontology", "property"); - } - query_tmp=query_tmp.replace(replacement,value); - System.out.println("Simple Wordnet Query: "+ query_tmp); - new_queries.add(query_tmp); - } - } - } - } - //add original query for iteration - new_queries.add(query); - //iterate over all Queries and get answer from Server - for(String bla : new_queries){ - ArrayList<String>answer_tmp=new ArrayList<String>(); - answer_tmp=sendServerQuestionRequestArray(bla); - for(String s: answer_tmp)final_answer.add(s); - //final_answer.add("Begin:\n"+bla +"\n"+answer_tmp+" \n End"); - } - } - } + } - - return final_answer; -} - - private ArrayList<String> simpleWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, - JWNLException { - ArrayList<String> final_answer=new ArrayList<String>(); - ArrayList<String> new_queries= new ArrayList<String>(); - - System.out.println("In simpleWordnetIteration"); - - String resource=""; - String property_to_compare_with=""; - String sideOfProperty="LEFT"; - + if(goOnAfterWordnet==true){ - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - tmpcounter=tmpcounter+1; - if(tmpcounter>=1){ - if(s.contains("LEFT")){ - sideOfProperty="LEFT"; - resource=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfProperty="RIGHT"; - resource=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_with=s.replace("PROPERTY",""); - } - - } - } - System.out.println("Property to compare:: "+ property_to_compare_with); - System.out.println("Resource: "+ resource); - - - HashMap<String,String> properties = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - Boolean goOnAfterProperty = true; - try { - properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); - if (properties==null){ - - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - } - - } catch (IOException e) { - - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - - } - if(goOnAfterProperty==true){ - - - - System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(property_to_compare_with); - System.out.println("Semantics: "+ semantics); - - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_=myindex.getWordnetHelp(property_to_compare_with); - if(_temp_==null){ - tmp_semantics=semantics; - } - else{ - semantics.clear(); - semantics.add(_temp_); - tmp_semantics=semantics; - } - if(property_to_compare_with.contains("_")){ - String[] array=property_to_compare_with.split("_"); - for(String i : array) tmp_semantics.add(i); - tmp_semantics.add(property_to_compare_with.replace("_"," ")); - } - System.out.println("tmp_semantics: "+ tmp_semantics); - Boolean goOnAfterWordnet = true; - - - System.out.println("##########################"); - System.out.println("properties for "+getUriFromIndex(resource.toLowerCase(),0)+": "+properties); - System.out.println("Property to compare with: "+property_to_compare_with); - System.out.println("Semantics: "+semantics); - System.out.println("##########################"); - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semantics=getSemantics(tmp_semantics); - System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); - if (tmp_semantics==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + key=key.replace("\"",""); + key=key.replace("@en",""); + + for(String b : semantics){ + if(key.contains(b.toLowerCase())){ + if(!result_SemanticsMatchProperties.contains(key)){ + result_SemanticsMatchProperties.add(key); + String query_tmp=query; + //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + String replacement = uri_of_property; + if(!query_tmp.contains(replacement)){ + replacement=replacement.replace("ontology", "property"); } + query_tmp=query_tmp.replace(replacement,value); + System.out.println("Simple Wordnet Query: "+ query_tmp); + new_queries.add(query_tmp); } - - } catch (IOException e) { - - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - } - - } - - if(goOnAfterWordnet==true){ - System.out.println("in actual wordnet function"); - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - - String value = entry.getValue(); - //System.out.println("Key "+ key +" and value "+value); - // System.out.println("Value propery: "+ value); - - for(String b : semantics){ - if(key.contains(b.toLowerCase())){ - //to check, if no property is used twice... - if(!result_SemanticsMatchProperties.contains(key)){ - result_SemanticsMatchProperties.add(key); - String query_tmp=query; - String test = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - - //could happen, that there is an ontology and not a property or upsidedown in the query - if(!query_tmp.contains(test)){ - test=test.replace("ontology", "property"); - } - query_tmp=query_tmp.replace(test,value); - System.out.println("\n"); - System.out.println("Match with "+ b); - System.out.println("Original Query: "+ query); - System.out.println("Simple Wordnet Query: "+ query_tmp); - System.out.println("\n"); - new_queries.add(query_tmp); - } - } - } - } - - //add original query for iteration - new_queries.add(query); - - } + } } + + } - - return new_queries; + return new_queries; } + - private ArrayList<String> complexWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { ArrayList<String> final_answer=new ArrayList<String>(); @@ -1347,7 +1291,7 @@ /** - * Iterates thru the conditions and returns an array, where one can see, if the Property is left or right from the resource + * Iterates thrue the conditions and returns an array, where one can see, if the Property is left or right from the resource * @param query * @return returns an array, where one can see, if the Property is left or right from the resource */ @@ -1358,40 +1302,63 @@ ArrayList<String> lstquery = new ArrayList<String>(); while (m.find()) { String tmp= m.group(1); - tmp=tmp.replace("http://dbpedia.org/resource/","").replace("http://dbpedia.org/property/", "").replace("http://dbpedia.org/ontology/", ""); + //if there is an .../ontology/C, dann ist das eine Klasse und das ganze soll dann nicht ersetzt reingepackt werden, sondern so bleiben, wie es ist. + System.out.println("Before new pattern and checking "+tmp); + Pattern p1=Pattern.compile (".*(http://dbpedia.org/ontology/[A-Z].*)\\>\\W.*"); + Matcher m1 = p1.matcher (tmp); + String resourceTemp=""; - //split on . for sign for end of conditions - String[] firstArray=tmp.split("\\."); - for(String i : firstArray){ - - String[] secondArray=i.split(" "); - //always in three counts - int counter=0; - for(String j : secondArray){ - counter=counter+1; - //only one condition - if(secondArray.length%3==0){ - if(counter==1&&j.contains("<")){ - //position of Property is right - lstquery.add("RIGHT"+j.replace("<", "").replace(">","")); - } - else if(counter==3&&j.contains("<")){ - //position of Property is left - lstquery.add("RIGHT"+j.replace("<", "").replace(">","")); - } - else if(counter==2){ - lstquery.add("PROPERTY"+j.replace("<", "").replace(">","")); - } - - else if(j.contains("?")) lstquery.add("VARIABLE"); - } - if(counter==0)counter=0; - - - } + while(m1.find()){ + resourceTemp="RESOURCE"+m1.group(1); + tmp=tmp.replace("<"+m1.group(1)+">", "SKIP"); + System.out.println("New temp: "+tmp); } + /* if(m1.find()){ + System.out.println("YEAHHHHHHHHHHHHHHHHHHHH "+m1.group(1)); + } + else{*/ + + + tmp=tmp.replace("http://dbpedia.org/resource/","").replace("http://dbpedia.org/property/", "").replace("http://dbpedia.org/ontology/", ""); + + //split on . for sign for end of conditions + String[] firstArray=tmp.split("\\."); + for(String i : firstArray){ + + String[] secondArray=i.split(" "); + //always in three counts + int counter=0; + for(String j : secondArray){ + //System.out.println("j "+j); + counter=counter+1; + //only one condition + if(secondArray.length%3==0){ + if(counter==1&&j.contains("<")&&!j.contains("SKIP")&&!j.contains("rdf:type")){ + //position of Property is right + lstquery.add("RIGHT"+j.replace("<", "").replace(">","")); + } + else if(counter==3&&j.contains("<")&&!j.contains("SKIP")&&!j.contains("rdf:type")){ + //position of Property is left + //here was RIGHT before.... + lstquery.add("LEFT"+j.replace("<", "").replace(">","")); + } + else if(counter==2&&!j.contains("SKIP")&&!j.contains("rdf:type")){ + lstquery.add("PROPERTY"+j.replace("<", "").replace(">","")); + } + + else if(j.contains("?")) lstquery.add("VARIABLE"); + else if(j.contains("SKIP"))lstquery.add(resourceTemp); + else if(j.contains("rdf:type"))lstquery.add("IsA"); + } + if(counter==0)counter=0; + + + } + } + //} } + //System.out.println("lstquery "+lstquery); return lstquery; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-01-03 08:51:00
|
Revision: 3522 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3522&view=rev Author: lorenz_b Date: 2012-01-03 08:50:54 +0000 (Tue, 03 Jan 2012) Log Message: ----------- Enabled separate cache for each endpoint to avoid concurrency problems when running several threads in parallel. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2012-01-03 04:33:55 UTC (rev 3521) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2012-01-03 08:50:54 UTC (rev 3522) @@ -33,6 +33,7 @@ import org.dllearner.utilities.datastructures.StringTuple; import org.dllearner.utilities.owl.OWLVocabulary; +import com.clarkparsia.owlapiv3.OWL; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetFactory; @@ -710,6 +711,9 @@ } } + //remove trivial classes + classes.remove(OWL.Nothing.toStringID()); + classes.remove(OWL.Thing.toStringID()); return classes; } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-01-03 04:33:55 UTC (rev 3521) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-01-03 08:50:54 UTC (rev 3522) @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; import java.net.MalformedURLException; @@ -36,6 +37,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLEncoder; import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; @@ -104,6 +106,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubClassAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; @@ -208,6 +211,8 @@ private boolean useInference; private SPARQLReasoner reasoner; + private ExtractionDBCache cache; + private String cacheDir = "cache"; // lists of algorithms to apply private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; @@ -234,6 +239,14 @@ this.nrOfAxiomsToLearn = nrOfAxiomsToLearn; this.useInference = useInference; + try { + cacheDir = "cache" + File.separator + URLEncoder.encode(se.getURL().toString(), "UTF-8"); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + cache = new ExtractionDBCache(cacheDir); + objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); @@ -282,7 +295,7 @@ // ks.setSupportsSPARQL_1_1(supportsSPARQL_1_1); if(useInference){ - reasoner = new SPARQLReasoner(ks); + reasoner = new SPARQLReasoner(ks, cache); System.out.print("Precomputing subsumption hierarchy ... "); long startTime = System.currentTimeMillis(); reasoner.prepareSubsumptionHierarchy(); @@ -332,7 +345,13 @@ runDataPropertyAlgorithms(ks, (DatatypeProperty) resource); } else if(resource instanceof NamedClass) { System.out.println(resource + " appears to be a class. Running appropriate algorithms.\n"); - runClassLearningAlgorithms(ks, (NamedClass) resource); + try { + runClassLearningAlgorithms(ks, (NamedClass) resource); + } catch (Exception e) { + System.out.println(e.getCause()); + } catch (Error e) { + System.out.println(e.getCause()); + } } else { throw new Error("The type " + resource.getClass() + " of resource " + resource + " cannot be handled by this enrichment tool."); } @@ -401,6 +420,7 @@ ks2.setDefaultGraphURIs(new TreeSet<String>(ks.getEndpoint().getDefaultGraphURIs())); ks2.setUseLits(false); ks2.setUseCacheDatabase(true); + ks2.setCacheDir(cacheDir); ks2.setRecursionDepth(2); ks2.setCloseAfterRecursion(true); ks2.setSaveExtractedFragment(true); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-01-03 04:33:55 UTC (rev 3521) +++ trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-01-03 08:50:54 UTC (rev 3522) @@ -31,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -74,7 +75,7 @@ //parameters for thread pool //Parallel running Threads(Executor) on System - private static int corePoolSize = 10; + private static int corePoolSize = 1; //Maximum Threads allowed in Pool private static int maximumPoolSize = 20; //Keep alive time for waiting threads for jobs(Runnable) @@ -103,7 +104,7 @@ Logger.getRootLogger().addAppender(consoleAppender); // get all SPARQL endpoints and their graphs - the key is a name-identifier - Map<String,SparqlEndpoint> endpoints = new HashMap<String,SparqlEndpoint>(); + Map<String,SparqlEndpoint> endpoints = new TreeMap<String,SparqlEndpoint>(); String query = ""; query += "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"; @@ -130,7 +131,7 @@ ResultSet rs = sq.send(); while(rs.hasNext()) { QuerySolution qs = rs.next(); - String endpoint = qs.get("endpoint").toString(); + String endpoint = qs.get("endpoint").toString();System.out.println(endpoint); String shortName = qs.get("shortName").toString(); endpoints.put(shortName, new SparqlEndpoint(new URL(endpoint))); } @@ -170,18 +171,20 @@ // run enrichment script - we make a case distinguish to see which kind of problems we get // (could be interesting for statistics later on) try { - e.start(); - success = true; - } catch(StackOverflowError error) { try { + e.start(); + success = true; + } catch (Exception ex){ + ex.printStackTrace(new PrintStream(log)); + } catch(StackOverflowError error) { error.printStackTrace(new PrintStream(log)); - } catch (FileNotFoundException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + Files.appendToFile(log, "stack overflows could be caused by cycles in class hierarchies"); + error.printStackTrace(); } - Files.appendToFile(log, "stack overflows could be caused by cycles in class hierarchies"); - error.printStackTrace(); - } catch(ResultSetException ex) { + } catch (FileNotFoundException e2) { + e2.printStackTrace(); + } + /*catch(ResultSetException ex) { try { ex.printStackTrace(new PrintStream(log)); } catch (FileNotFoundException e1) { @@ -202,7 +205,7 @@ } catch(Exception ex) { System.out.println("class of exception: " + ex.getClass()); - } + }*/ // save results to a file (TODO: check if enrichment format if(success) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-01-03 04:34:01
|
Revision: 3521 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3521&view=rev Author: shadowtm Date: 2012-01-03 04:33:55 +0000 (Tue, 03 Jan 2012) Log Message: ----------- Renamed 1.0.1 branch as the version number is not correct - this should avoid confusion in the future - this is way behind the current version in trunk Added Paths: ----------- branches/cs_0.1/ Removed Paths: ------------- branches/1.0.1/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-01-02 15:06:30
|
Revision: 3520 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3520&view=rev Author: lorenz_b Date: 2012-01-02 15:06:23 +0000 (Mon, 02 Jan 2012) Log Message: ----------- Several changes to fix some bugs detected during global enrichment test. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/InverseObjectPropertyAxiom.java trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -169,7 +169,6 @@ Model newModel = executeConstructQuery(query); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); NamedClass cls; - Integer oldCnt; while(newModel.size() != 0){ model.add(newModel); //get total number of distinct instances @@ -183,18 +182,11 @@ rs = executeSelectQuery(query, model); QuerySolution qs; while(rs.hasNext()){ - qs = rs.next();System.out.println(qs); + qs = rs.next(); if(qs.getResource("type") != null && !qs.getResource("type").isAnon()){ cls = new NamedClass(qs.getResource("type").getURI()); int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(cls); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); - } else { - oldCnt += newCnt; - } - - result.put(cls, oldCnt); + result.put(cls, newCnt); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -156,7 +156,6 @@ oldCnt = Integer.valueOf(newCnt); } result.put(prop, oldCnt); - qs.getLiteral("count").getInt(); repeat = true; } if(!result.isEmpty()){ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -120,7 +120,7 @@ offset += limit; - query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -115,7 +115,7 @@ offset += limit; - query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/InverseObjectPropertyAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/InverseObjectPropertyAxiom.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/InverseObjectPropertyAxiom.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -69,6 +69,6 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return "INVERSEOBJECTPROPERTYAXIOM NOT IMPLEMENTED"; + return role.toManchesterSyntaxString(baseURI, prefixes) + " InverseOf: " + inverseRole.toManchesterSyntaxString(baseURI, prefixes); } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/kb/SparqlEndpointKS.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -46,6 +46,7 @@ private SparqlEndpoint endpoint; private boolean supportsSPARQL_1_1 = false; private boolean isRemote = true; + private boolean initialized = false; // TODO: turn those into config options @@ -68,10 +69,13 @@ @Override public void init() throws ComponentInitException { - if(endpoint == null) { - endpoint = new SparqlEndpoint(url, defaultGraphURIs, namedGraphURIs); + if(!initialized){ + if(endpoint == null) { + endpoint = new SparqlEndpoint(url, defaultGraphURIs, namedGraphURIs); + } + supportsSPARQL_1_1 = new SPARQLTasks(endpoint).supportsSPARQL_1_1(); + initialized = true; } - supportsSPARQL_1_1 = new SPARQLTasks(endpoint).supportsSPARQL_1_1(); } public SparqlEndpoint getEndpoint() { 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-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -194,7 +194,7 @@ } for (String ngu : endpoint.getNamedGraphURIs()) { queryExecution.addNamedGraph(ngu); - } + } com.hp.hpl.jena.query.ResultSet tmp = queryExecution.execSelect(); ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(tmp); String json = SparqlQuery.convertResultSetToJSON(rs2); Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlQuery.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -274,10 +274,10 @@ * errors. * @return JSON representation of the result set. */ - public static String convertResultSetToJSON(ResultSetRewindable resultSet) { + public static String convertResultSetToJSON(ResultSet resultSet) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ResultSetFormatter.outputAsJSON(baos, resultSet); - resultSet.reset(); +// resultSet.reset(); try { return baos.toString("UTF-8"); } catch (UnsupportedEncodingException e) { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -102,6 +102,11 @@ } } + public SPARQLReasoner(SparqlEndpointKS ks, ExtractionDBCache cache) { + this.ks = ks; + this.cache = cache; + } + public SPARQLReasoner(OntModel model) { this.model = model; } @@ -602,10 +607,7 @@ } public int getPropertyCount(ObjectProperty property){ - String query = String.format("SELECT COUNT(*) WHERE {" + - "?s <%s> ?o." + - "}", - property.getName()); + String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o.}", property.getName()); ResultSet rs = executeSelectQuery(query); int cnt = rs.next().get(rs.getResultVars().get(0)).asLiteral().getInt(); return cnt; @@ -615,7 +617,7 @@ public SortedSet<ObjectProperty> getInverseObjectProperties(ObjectProperty property){ SortedSet<ObjectProperty> inverseObjectProperties = new TreeSet<ObjectProperty>(); String query = "SELECT ?p WHERE {" + - "{<%p> <%ax> ?p.} UNION {?p <%ax> <%p>}}".replace("%p", property.getName()).replace("%ax", OWL.inverseOf.getURI());System.out.println(query); + "{<%p> <%ax> ?p.} UNION {?p <%ax> <%p>}}".replace("%p", property.getName()).replace("%ax", OWL.inverseOf.getURI()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-01-02 09:37:56 UTC (rev 3519) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-01-02 15:06:23 UTC (rev 3520) @@ -36,6 +36,8 @@ import com.clarkparsia.owlapiv3.OntologyUtils; public class JustificationBasedCoherentOntologyExtractor implements CoherentOntologyExtractor{ + + private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(JustificationBasedCoherentOntologyExtractor.class); private static final int NUMBER_OF_JUSTIFICATIONS = 5; // private PelletReasoner reasoner; @@ -60,20 +62,31 @@ OWLOntologyManager man = incoherentOntology.getOWLOntologyManager(); // man.addOntologyChangeListener(reasoner); + + //compute the unsatisfiable classes StructureBasedRootClassFinder rootFinder = new StructureBasedRootClassFinder(reasoner); rootFinder.computeRootDerivedClasses(); - Set<OWLClass> unsatClasses = rootFinder.getRootUnsatisfiableClasses();//reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - int cnt = unsatClasses.size(); + Set<OWLClass> unsatClasses = rootFinder.getRootUnsatisfiableClasses(); + Set<OWLClass> derivedUnsatClasses = rootFinder.getDerivedUnsatisfiableClasses(); + int rootCnt = unsatClasses.size(); + int derivedCnt = derivedUnsatClasses.size(); +// Set<OWLClass> unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + int cnt = rootCnt + derivedCnt; + logger.info("Detected " + cnt + " unsatisfiable classes, " + rootCnt + " of them as root."); //if the ontology is not incoherent we return it here if(unsatClasses.isEmpty()){ return incoherentOntology; } //compute the logical modules for each unsatisfiable class + logger.info("Computing module for each unsatisfiable class..."); cls2ModuleMap = extractModules(unsatClasses); + logger.info("...done."); //compute initial explanations for each unsatisfiable class + logger.info("Computing initial explanations..."); Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = getInitialExplanationsForUnsatClasses(unsatClasses); + logger.info("...done."); while(!unsatClasses.isEmpty()){ //get frequency for each axiom @@ -86,7 +99,7 @@ } //we remove the most frequent axiom from the ontology OWLAxiom toRemove = sortedEntries.get(0).getKey(); - System.out.println("Removing axiom " + toRemove); + logger.info("Removing axiom " + toRemove + "."); man.removeAxiom(incoherentOntology, toRemove); man.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); removeFromExplanations(cls2Explanations, toRemove); @@ -94,26 +107,34 @@ //recompute the unsatisfiable classes reasoner.classify(); +// unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + rootFinder = new StructureBasedRootClassFinder(reasoner); rootFinder.computeRootDerivedClasses(); - unsatClasses = rootFinder.getRootUnsatisfiableClasses();//reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - System.out.println("Remaining unsatisfiable classes: " + unsatClasses.size()); + unsatClasses = rootFinder.getRootUnsatisfiableClasses(); + rootCnt = unsatClasses.size(); + derivedUnsatClasses = rootFinder.getDerivedUnsatisfiableClasses(); + derivedCnt = derivedUnsatClasses.size(); + logger.info("Remaining unsatisfiable classes: " + (rootCnt + derivedCnt) + "(" + rootCnt + " roots)."); //save - if(cnt - unsatClasses.size() >= 10){ + if(cnt - (rootCnt+derivedCnt) >= 10){ + cnt = rootCnt + derivedCnt; OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); try { - toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_" + unsatClasses.size() + ".owl"))); + toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_" + cnt + ".owl"))); } catch (OWLOntologyStorageException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } - cnt = unsatClasses.size(); + cnt = rootCnt + derivedCnt; } //recompute explanations if necessary + logger.info("Recomputing explanations..."); refillExplanations(unsatClasses, cls2Explanations); + logger.info("...done."); System.gc(); } @@ -246,10 +267,9 @@ public static void main(String[] args) throws Exception{ Logger.getLogger(RBox.class.getName()).setLevel(Level.OFF); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); -// OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("../components-core/cohaerent.owl")); +// OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("/home/lorenz/dbpedia_0.75_no_datapropaxioms.owl")); + OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("log/dbpedia_95.owl")); // System.out.println(schema.getLogicalAxiomCount()); - OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("/home/lorenz/arbeit/dbpedia_0.75_no_datapropaxioms.owl")); -// System.out.println(schema.getLogicalAxiomCount()); // OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("log/dbpedia_coherent.owl")); System.out.println(schema.getLogicalAxiomCount()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-02 09:38:03
|
Revision: 3519 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3519&view=rev Author: sebastianwtr Date: 2012-01-02 09:37:56 +0000 (Mon, 02 Jan 2012) Log Message: ----------- [tbsl exploration] started implementing the isA-Case for advanced Questions Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2011-12-30 10:26:03 UTC (rev 3518) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-02 09:37:56 UTC (rev 3519) @@ -51,10 +51,14 @@ String vergleichorig = vergleich; - - String tmp_left="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + /* + * change to dbpedia http://dbpedia.org/sparql + */ + //String tmp_left="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String tmp_left="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + //System.out.println("property right!!! : " +tmp_right); - String tmp_right="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String tmp_right="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String verarbeitungsurl=null; if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-12-30 10:26:03 UTC (rev 3518) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-02 09:37:56 UTC (rev 3519) @@ -58,11 +58,12 @@ //Konstruktor public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ + wordnet = new WordNet(); System.out.println("Loading SPARQL Templator"); // btemplator = new BasicTemplator(); - btemplator.UNTAGGED_INPUT = false; + //btemplator.UNTAGGED_INPUT = false; //templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); System.out.println("Start Indexing"); @@ -73,7 +74,7 @@ //normaly 1 setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren - setIterationdepth(1); + setIterationdepth(0); setNumberofanswers(1); } @@ -123,7 +124,7 @@ public void create_Sparql_query(String question) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); - ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); + ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); long startParsingTime = System.currentTimeMillis(); lstquery=getQuery(question); long endParsingTime = System.currentTimeMillis(); @@ -158,7 +159,7 @@ new InputStreamReader( new FileInputStream( "/tmp/testresult.txt" ) ) ); while( null != (s = in.readLine()) ) { - tmp+="\n"+s; + tmp=tmp.concat("\n".concat(s)); } } catch( FileNotFoundException ex ) { } catch( Exception ex ) { @@ -174,7 +175,7 @@ } String out=null; - if (query=="" || query==" "||query.length()==0) query="Could not parse"; + if (query.equals("") || query.equals(" ")||query.length()==0) query="Could not parse"; out=tmp + "\n" + question + ":\n"+query+"\n"; BufferedWriter outfile = new BufferedWriter( @@ -527,9 +528,27 @@ } + + /* + * if there are more than one condition and if there is an isA Case in it, use this function. + * TODO: Change other simple Case function, that they have a Resource to deal with, or change the get Query function + */ + private ArrayList<String> isAIteration(ArrayList<String> querylist, String query) throws SQLException, + JWNLException { + //only for special case, that the first condition has a resource + ArrayList<String> final_answer=new ArrayList<String>(); + + return final_answer; + + } + + + + private ArrayList<String> simpleLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { - + + System.out.println("In Simpe levensthein case!!"); ArrayList<String> final_answer=new ArrayList<String>(); String resource=""; String property_to_compare_with=""; @@ -1043,7 +1062,7 @@ key=key.replace("@en",""); String value = entry.getValue(); - System.out.println("Key "+ key +" and value "+value); + //System.out.println("Key "+ key +" and value "+value); // System.out.println("Value propery: "+ value); for(String b : semantics){ @@ -1060,6 +1079,7 @@ } query_tmp=query_tmp.replace(test,value); System.out.println("\n"); + System.out.println("Match with "+ b); System.out.println("Original Query: "+ query); System.out.println("Simple Wordnet Query: "+ query_tmp); System.out.println("\n"); @@ -1375,6 +1395,9 @@ return lstquery; } + + //TODO: Plural Singual abfragen über die Wordnetdatei... + /** * Method gets a String and takes the information from the templator to creat a Sparql query. * @param question question in natural language @@ -1419,8 +1442,35 @@ filters=""; addQuery=false; } + + //if there is no order by, replace with "" + String orderdBy="ORDER BY "; + try{ + for(SPARQL_Term tmp : temp.getOrderBy()) { + System.out.println("Yeah"); + orderdBy=orderdBy+tmp+" "; + } + if((temp.getOrderBy()).size()==0)orderdBy=""; + } + catch(Exception e){ + orderdBy=""; + addQuery=false; + } + + //if limit == 0, then set limit as "" + String limit=""; + try{ + limit="LIMIT "+temp.getLimit(); + + if(temp.getLimit()==0)limit=""; + } + catch(Exception e){ + limit=""; + addQuery=false; + } + if(addQuery==true){ - query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions.replace("--","") + filters+"}"; + query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions.replace("--","") + filters+"}"+orderdBy +" "+limit; String conditions_new = ""; for(Path condition: temp.getConditions()){ @@ -1444,11 +1494,63 @@ System.out.println("Conditions_new: " + conditions_new); - String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+ "}"; + String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+ "}" + orderdBy +" "+limit; String[] slots= null; + + + /* + * replace isA with rdf:type + */ + query_upside_down=query_upside_down.replace("isA", "rdf:type"); + query=query.replace("isA", "rdf:type"); + int slotcounter=1; + + /* + * the one after the isA, has to be an ontology Class!!! + * so first find out, which one is behind the isA + * best with regex or so.... take the condition, regex the thing between isA and . for End of Condition + * kind of regex=[*a IsA (\\?*a.)*a] + * Then put the isA thing in the variable isaComponent and mark it as later on as Resource! + */ + String isaComponent=""; + + Pattern p = Pattern.compile (".*isA (\\?.*)\\..*"); + + /* + * use conditions, because only in this case, there is the right resource right of the isA + */ + Matcher m = p.matcher (conditions.replace("--", "").replace(" ", " ")); + String result=""; + + System.out.println("################"); + while (m.find()) { + if(m.group(1)!=null) + //System.out.println(m.group(1)); + isaComponent=m.group(1); + } + System.out.println("isaComponent "+isaComponent); + + /* + * just in case, there is still a . in it... + * funzt + * + */ + if(isaComponent.contains(".")){ + String[] tmp_array=isaComponent.split("\\."); + for(String i: tmp_array) System.out.println("tmp_array "+i); + isaComponent=tmp_array[0]; + + System.out.println("new isaComponent "+isaComponent); + } + + if(isaComponent=="") isaComponent="No isa Component"; + System.out.println("isaComponent "+isaComponent); + System.out.println("################"); + for(Slot slot : temp.getSlots()){ + System.out.println("Slot: "+slot); //see below slotcounter=slotcounter+1; @@ -1469,8 +1571,56 @@ //query=query.replace(replace, "<"+hm_result+">"); - if(resource!=""){ + /*System.out.println("Recource "+resource); + System.out.println("Property "+property);*/ + + boolean skip=false; + if(resource.contains(isaComponent.replace("?", "")) || property.contains(isaComponent.replace("?", ""))){ + skip=true; + + /* + * now replace the variable with the value of OntologyClass + */ String replace=""; + String tmp=""; + + if(resource.contains(isaComponent.replace("?", ""))) tmp=resource; + if(property.contains(isaComponent.replace("?", ""))) tmp=property; + + String[] array = tmp.split(":"); + if(array[0].length()<2)replace = "?"+array[0]+" "; + else replace="?"+array[0]; + try{ + array[1]=array[1].replace(" ", ""); + } + catch(Exception e){ + + } + String hm_result=myindex.getontologyClassURI(array[1]); + if(hm_result==null)hm_result="http://dbpedia.org/ontology/"+Character.toUpperCase(array[1].charAt(0)) + array[1].substring(1, array[1].length()); + System.out.println(array[1]+" for getOntologyClass "+hm_result); + //System.out.print("URI for_ThingGettingURIfor: "+hm_result); + try + { + if(hm_result.contains("Category:")) hm_result=hm_result.replace("Category:",""); + } + catch ( Exception e ) + { + + } + + query=query.replace(replace, "<"+hm_result+">"); + //System.out.println("Query: "+query); + query_upside_down=query_upside_down.replace(replace, "<"+hm_result+">"); + //System.out.println("Query Up Side Down: "+query_upside_down); + + } + + + + + if(resource!=""&&skip==false){ + String replace=""; String[] array = resource.split(":"); if(array[0].length()<2)replace = "?"+array[0]+" "; else replace="?"+array[0]; @@ -1493,7 +1643,7 @@ } - if(property!=""){ + if(property!=""&&skip==false){ String replace=""; String[] array = property.split(":"); if(array[0].length()<2)replace = "?"+array[0]+" "; @@ -1512,6 +1662,8 @@ query_upside_down=query_upside_down.replace("><","> <").replace(">?", "> ?"); query=query.replace("><","> <").replace(">?", "> ?"); + query=query.replace("/__", "/"); + query_upside_down=query_upside_down.replace("/__", "/"); lstquerupsidedown.add(query_upside_down); lstquerynew.add(query); System.out.println("Query: "+query); @@ -1519,6 +1671,10 @@ + /* + * Add, that the one with the isa is an Resource!!! + * An ontology Resource! + */ ArrayList<String> lsttmp=createLeftAndRightPropertyArray(query); //if its lower than three, we dont have any conditions and dont need to check it. //also if the size%3 isnt 0, than something else is wrong and we dont need to test the query @@ -1601,6 +1757,10 @@ * @throws SQLException */ private String getUriFromIndex(String string, int fall) throws SQLException{ + + /* + * something like /dbpedia.org/property/__bla nicht erlauben, also /__ durch / ersetzen + */ String originalString=string; string=string.replace("_", " "); string=string.replace("-", " "); @@ -1646,7 +1806,7 @@ if(result==null) { if(fall==1)return "http://dbpedia.org/property/"+tmp; if(fall==0) { - String bla ="http://dbpedia.org/resource/"+tmp; + String hotfix ="http://dbpedia.org/resource/"+tmp; if(tmp.contains("_")){ String[] newarraytmp=tmp.split("_"); String tmpneu=""; @@ -1654,17 +1814,23 @@ tmpneu+= "_"+ Character.toUpperCase(s.charAt(0)) + s.substring(1); } tmpneu=tmpneu.replaceFirst("_", ""); - bla ="http://dbpedia.org/resource/"+tmpneu; - System.out.println("Hotfix: "+bla); + hotfix ="http://dbpedia.org/resource/"+tmpneu; + hotfix=hotfix.replace("/__", "/"); + System.out.println("Hotfix: "+hotfix); } - return bla; + hotfix=hotfix.replace("/__", "/"); + return hotfix; } else{ + result=result.replace("/__","/"); System.out.println("return result: "+result); return result; } } - else return result; + else { + result=result.replace("/__","/"); + return result; + } } @@ -1826,8 +1992,11 @@ //SPARQL-Endpoint of Semantic Computing Group //5171 - String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - System.out.println(tmp); + /* + * change to dbpedia http://dbpedia.org/sparql + */ + //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); URL url; InputStream is; InputStreamReader isr; @@ -1861,7 +2030,12 @@ private ArrayList<String> sendServerQuestionRequestArray(String query){ //SPARQL-Endpoint of Semantic Computing Group - String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + /* + * change to dbpedia http://dbpedia.org/sparql + */ + //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + System.out.println(tmp); URL url; InputStream is; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-30 10:26:10
|
Revision: 3518 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3518&view=rev Author: lorenz_b Date: 2011-12-30 10:26:03 +0000 (Fri, 30 Dec 2011) Log Message: ----------- Added 2 classes actually needed to compile successfully. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/RootClassFinder.java trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2011-12-30 10:04:59 UTC (rev 3517) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2011-12-30 10:26:03 UTC (rev 3518) @@ -14,10 +14,10 @@ import java.util.logging.Level; import java.util.logging.Logger; -import org.aksw.mole.ore.rootderived.StructureBasedRootClassFinder; import org.mindswap.pellet.RBox; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; +import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLEntity; @@ -50,7 +50,7 @@ @Override public OWLOntology getCoherentOntology(OWLOntology ontology) { - this.ontology = ontology; + this.ontology = ontology;ontology.getOWLOntologyManager().removeAxioms(ontology, ontology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY)); this.incoherentOntology = getOntologyWithoutAnnotations(ontology); // reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(incoherentOntology); Added: trunk/components-core/src/main/java/org/dllearner/utilities/RootClassFinder.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/RootClassFinder.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/RootClassFinder.java 2011-12-30 10:26:03 UTC (rev 3518) @@ -0,0 +1,12 @@ +package org.dllearner.utilities; + +import java.util.Set; + +import org.semanticweb.owlapi.model.OWLClass; + +public interface RootClassFinder { + Set<OWLClass> getRootUnsatisfiableClasses(); + Set<OWLClass> getDerivedUnsatisfiableClasses(); + Set<OWLClass> getDependentChildClasses(OWLClass unsatClass); + +} Added: trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java 2011-12-30 10:26:03 UTC (rev 3518) @@ -0,0 +1,415 @@ +package org.dllearner.utilities; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.AddAxiom; +import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLClassExpressionVisitor; +import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectCardinalityRestriction; +import org.semanticweb.owlapi.model.OWLObjectComplementOf; +import org.semanticweb.owlapi.model.OWLObjectExactCardinality; +import org.semanticweb.owlapi.model.OWLObjectHasSelf; +import org.semanticweb.owlapi.model.OWLObjectHasValue; +import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; +import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; +import org.semanticweb.owlapi.model.OWLObjectMinCardinality; +import org.semanticweb.owlapi.model.OWLObjectOneOf; +import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; +import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectUnionOf; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyChange; +import org.semanticweb.owlapi.model.OWLOntologyChangeException; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLQuantifiedRestriction; +import org.semanticweb.owlapi.model.RemoveAxiom; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; + +import uk.ac.manchester.cs.owlapi.modularity.ModuleType; + +import com.clarkparsia.modularity.ModularityUtils; +import com.clarkparsia.owlapi.modularity.locality.LocalityClass; +import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; + +public class StructureBasedRootClassFinder implements RootClassFinder, OWLClassExpressionVisitor { + + private OWLOntologyManager manager; + private OWLReasoner reasoner; + private OWLReasonerFactory reasonerFactory; + + private Set<OWLClass> depend2Classes; + private OWLOntology ontology; + + + private Set<OWLClass> rootClasses; + private Set<OWLClass> derivedClasses; + private Set<OWLClass> unsatClasses; + + private boolean ontologyChanged = true; + + + private int depth; + private Map<Integer, Set<OWLObjectAllValuesFrom>> depth2UniversalRestrictionPropertyMap; + private Map<Integer, Set<OWLObjectPropertyExpression>> depth2ExistsRestrictionPropertyMap; + + private Map<OWLClass, Set<OWLClass>> child2Parents; + private Map<OWLClass, Set<OWLClass>> parent2Children; + +// private Map<OWLClass, Map<OWLAxiom, Set<OWLClass>>> class2Dependency; + + public StructureBasedRootClassFinder(OWLReasoner reasoner){ + + this.manager = OWLManager.createOWLOntologyManager(); + this.reasoner = reasoner; + this.reasonerFactory = new PelletReasonerFactory(); + try { + this.ontology = manager.createOntology(IRI.create("http://all"), reasoner.getRootOntology().getImportsClosure()); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (OWLOntologyChangeException e) { + e.printStackTrace(); + } + rootClasses = new HashSet<OWLClass>(); + derivedClasses = new HashSet<OWLClass>(); + unsatClasses = new HashSet<OWLClass>(); + + depend2Classes = new HashSet<OWLClass>(); + depth2UniversalRestrictionPropertyMap = new HashMap<Integer, Set<OWLObjectAllValuesFrom>>(); + depth2ExistsRestrictionPropertyMap = new HashMap<Integer, Set<OWLObjectPropertyExpression>>(); + + child2Parents = new HashMap<OWLClass, Set<OWLClass>>(); + parent2Children = new HashMap<OWLClass, Set<OWLClass>>(); + +// class2Dependency = new HashMap<OWLClass, Map<OWLAxiom, Set<OWLClass>>>(); + + } + + public void computeRootDerivedClasses(){ + unsatClasses.clear(); + rootClasses.clear(); + derivedClasses.clear(); + depend2Classes.clear(); + depth2ExistsRestrictionPropertyMap.clear(); + depth2UniversalRestrictionPropertyMap.clear(); + child2Parents.clear(); + parent2Children.clear(); + computePossibleRoots(); + pruneRoots(); + derivedClasses.addAll(unsatClasses); + derivedClasses.removeAll(rootClasses); + + rootClasses.remove(manager.getOWLDataFactory().getOWLNothing()); + } + + private void computePossibleRoots(){ + unsatClasses.addAll(reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom()); + + for(OWLClass cls : unsatClasses){ + reset(); + for(OWLClassExpression equi : cls.getEquivalentClasses(ontology)){ + equi.accept(this); + } + for(OWLClassExpression sup : cls.getSuperClasses(ontology)){ + sup.accept(this); + } + for(Integer depth : depth2UniversalRestrictionPropertyMap.keySet()){ + Set<OWLObjectPropertyExpression> successors = depth2ExistsRestrictionPropertyMap.get(depth); + if(successors != null){ + for(OWLObjectAllValuesFrom all : depth2UniversalRestrictionPropertyMap.get(depth)){ + if(successors.contains(all.getProperty())){ + depend2Classes.add(all.getFiller().asOWLClass()); + } + } + } + } + child2Parents.put(cls, depend2Classes); + if(depend2Classes.isEmpty()){ + rootClasses.add(cls); + } + } + + } + + private void pruneRoots() { + try { + Set<OWLClass> roots = new HashSet<OWLClass>(rootClasses); + List<OWLOntologyChange> appliedChanges = new ArrayList<OWLOntologyChange>(); + Set<OWLClass> potentialRoots = new HashSet<OWLClass>(); + for (OWLDisjointClassesAxiom dis : new ArrayList<OWLDisjointClassesAxiom>( + ontology.getAxioms(AxiomType.DISJOINT_CLASSES))) { + for (OWLClass cls : roots) { + if (dis.getSignature().contains(cls)) { + OWLOntologyChange rem = new RemoveAxiom(ontology, dis); + manager.applyChange(rem); + appliedChanges.add(rem); + for (OWLEntity ent : dis.getSignature()) { + if (ent.isOWLClass()) { + potentialRoots.add(ent.asOWLClass()); + } + } + } + } + } + for (OWLClass cls : roots) { + OWLOntologyChange add = new AddAxiom(ontology, manager.getOWLDataFactory() + .getOWLDeclarationAxiom(cls)); + manager.applyChange(add); + appliedChanges.add(add); + } + OWLReasoner checker = null; + for (OWLClass root : new ArrayList<OWLClass>(roots)) { + + checker = reasonerFactory.createNonBufferingReasoner(manager.createOntology(ModularityUtils.extractModule + (ontology, root.getSignature(), ModuleType.TOP_OF_BOT))); + if (!potentialRoots.contains(root) && checker.isSatisfiable(root)) { + rootClasses.remove(root); + } + } + for(OWLOntologyChange change: appliedChanges){ + if(change instanceof RemoveAxiom){ + manager.applyChange(new AddAxiom(ontology, change.getAxiom())); + } else if(change instanceof AddAxiom){ + manager.applyChange(new RemoveAxiom(ontology, change.getAxiom())); + } + } + } catch (OWLOntologyChangeException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void reset(){ + depend2Classes.clear(); + depth2ExistsRestrictionPropertyMap.clear(); + depth2UniversalRestrictionPropertyMap.clear(); + } + + + private void checkObjectRestriction(OWLQuantifiedRestriction<OWLClassExpression,OWLObjectPropertyExpression,OWLClassExpression> restr){ + OWLClassExpression filler = restr.getFiller(); + + if(filler.isAnonymous()){ + depth++; + filler.accept(this); + depth--; + } else { + if(unsatClasses.contains(filler.asOWLClass())){ + depend2Classes.add(filler.asOWLClass()); + if(restr instanceof OWLObjectAllValuesFrom){ + addAllRestrictionProperty((OWLObjectAllValuesFrom) restr); + return; + } + } + addExistsRestrictionProperty(restr.getProperty()); + } + + + } + + private void checkObjectCardinalityRestriction(OWLObjectCardinalityRestriction restr){ + OWLClassExpression filler = restr.getFiller(); + + if(filler.isAnonymous()){ + depth++; + filler.accept(this); + depth--; + } else { + if(unsatClasses.contains(filler.asOWLClass())){ + depend2Classes.add(filler.asOWLClass()); + } + addExistsRestrictionProperty(restr.getProperty()); + } + + + } + + private void addExistsRestrictionProperty(OWLObjectPropertyExpression expr){ + Set<OWLObjectPropertyExpression> properties = depth2ExistsRestrictionPropertyMap.get(Integer.valueOf(depth)); + if(properties == null){ + properties = new HashSet<OWLObjectPropertyExpression>(); + depth2ExistsRestrictionPropertyMap.put(Integer.valueOf(depth), properties); + } + properties.add(expr); + } + + private void addAllRestrictionProperty(OWLObjectAllValuesFrom all){ + Set<OWLObjectAllValuesFrom> properties = depth2UniversalRestrictionPropertyMap.get(Integer.valueOf(depth)); + if(properties == null){ + properties = new HashSet<OWLObjectAllValuesFrom>(); + depth2UniversalRestrictionPropertyMap.put(Integer.valueOf(depth), properties); + } + properties.add(all); + } + + + @Override + public void visit(OWLClass cls) { + if(unsatClasses.contains(cls)) { + depend2Classes.add(cls); + } + } + + @Override + public void visit(OWLObjectIntersectionOf and) { + + + for(OWLClassExpression op : and.getOperands()) { + if(op.isAnonymous()){ + op.accept(this); + } else if(unsatClasses.contains(op.asOWLClass())) { + depend2Classes.add(op.asOWLClass()); + } + } + + } + + @Override + public void visit(OWLObjectUnionOf or) { + + // check whether one of the union operands is satisfiable + for (OWLClassExpression op : or.getOperands()) { + if (!unsatClasses.contains(op)) { + return; + } + } + // all operands are unsatisfiable + for (OWLClassExpression op : or.getOperands()) { + if (op.isAnonymous()) { + op.accept(this); + } else { + depend2Classes.add(op.asOWLClass()); + } + } + + } + + @Override + public void visit(OWLObjectAllValuesFrom all) { + checkObjectRestriction(all); + } + + @Override + public void visit(OWLObjectMinCardinality min) { + checkObjectCardinalityRestriction(min); + } + + @Override + public void visit(OWLObjectExactCardinality exact) { + checkObjectCardinalityRestriction(exact); + } + + @Override + public void visit(OWLObjectMaxCardinality ce) { + + } + + @Override + public void visit(OWLObjectHasSelf self) { + addExistsRestrictionProperty(self.getProperty()); + } + + @Override + public void visit(OWLObjectSomeValuesFrom some) { + checkObjectRestriction(some); + } + + @Override + public void visit(OWLObjectComplementOf arg0) { + } + + @Override + public void visit(OWLObjectHasValue arg0) { + } + + @Override + public void visit(OWLObjectOneOf arg0) { + } + + @Override + public void visit(OWLDataSomeValuesFrom arg0) { + } + + @Override + public void visit(OWLDataAllValuesFrom arg0) { + } + + @Override + public void visit(OWLDataHasValue arg0) { + } + + @Override + public void visit(OWLDataMinCardinality arg0) { + } + + @Override + public void visit(OWLDataExactCardinality arg0) { + } + + @Override + public void visit(OWLDataMaxCardinality arg0) { + } + + + @Override + public Set<OWLClass> getRootUnsatisfiableClasses() { + if(ontologyChanged){ + computeRootDerivedClasses(); + ontologyChanged = false; + } + return Collections.unmodifiableSet(rootClasses); + } + + @Override + public Set<OWLClass> getDerivedUnsatisfiableClasses() { + if(ontologyChanged){ + computeRootDerivedClasses(); + ontologyChanged = false; + } + return Collections.unmodifiableSet(derivedClasses); + } + + @Override + public Set<OWLClass> getDependentChildClasses(OWLClass unsatClass) { + // TODO Auto-generated method stub + return null; + } + + public void refresh(){ + ontologyChanged = true; + } + + public static void main(String[] args) throws OWLOntologyCreationException{ + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = manager.loadOntology(IRI.create("file:/home/lorenz/arbeit/dbpedia_0.75_no_datapropaxioms.owl")); + OWLReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); + StructureBasedRootClassFinder f = new StructureBasedRootClassFinder(reasoner); + System.out.println(f.getRootUnsatisfiableClasses().size()); + System.out.println(f.getDerivedUnsatisfiableClasses().size()); + } + + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-30 10:05:05
|
Revision: 3517 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3517&view=rev Author: lorenz_b Date: 2011-12-30 10:04:59 +0000 (Fri, 30 Dec 2011) Log Message: ----------- small change in score. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-12-28 11:21:46 UTC (rev 3516) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2011-12-30 10:04:59 UTC (rev 3517) @@ -130,7 +130,7 @@ //get subjects with types int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + + String queryTemplate = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o." + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + "}"; String query; @@ -178,7 +178,7 @@ properties.add(entry.getKey()); int popularity = reasoner.getPropertyCount(entry.getKey()); int total = popularity;//Math.max(popularity, all); - int success = entry.getValue();//System.out.println(entry.getKey());System.out.println(total);System.out.println(success); + int success = entry.getValue();//System.out.println(entry.getKey());System.out.println(entry.getKey());System.out.println(total);System.out.println(success); Score score = computeScore(total, success); evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties),score); axioms.add(evalAxiom); @@ -191,7 +191,7 @@ public static void main(String[] args) throws Exception{ EquivalentObjectPropertyAxiomLearner l = new EquivalentObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint( new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())));//.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/thirdDriverCountry")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/state")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-28 11:21:54
|
Revision: 3516 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3516&view=rev Author: lorenz_b Date: 2011-12-28 11:21:46 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Some small changes to avoid problems with anonymous classes when running on local model. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-28 11:00:47 UTC (rev 3515) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-28 11:21:46 UTC (rev 3516) @@ -60,6 +60,7 @@ 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.rdf.model.Resource; /** * Learns disjoint classes using SPARQL queries. @@ -143,7 +144,7 @@ subClasses.add(new NamedClass(sub.getURI())); } } - for(OntClass sup : cls.listSuperClasses().toSet()){System.out.println(cls.listSuperClasses().toSet()); + for(OntClass sup : cls.listSuperClasses().toSet()){ if(!sup.isAnon()){ subClasses.add(new NamedClass(sup.getURI())); } @@ -151,7 +152,7 @@ } if(ks.supportsSPARQL_1_1()){ - runSPARQL1_0_Mode(); + runSPARQL1_1_Mode(); } else { runSPARQL1_0_Mode(); } @@ -226,9 +227,11 @@ ResultSet rs = executeSelectQuery(query); QuerySolution qs; repeat = false; + Resource res; while(rs.hasNext()){ - qs = rs.next();System.out.println(qs); - if(qs.getResource("type") != null){ + qs = rs.next(); + res = qs.getResource("type"); + if(res != null && !res.isAnon()){ cls = new NamedClass(qs.getResource("type").getURI()); int newCnt = qs.getLiteral("count").getInt(); oldCnt = result.get(cls); @@ -302,10 +305,9 @@ // Integer all = class2Count.get(classToDescribe); class2Count.remove(classToDescribe); - //get complete disjoint classes Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); - completeDisjointclasses.removeAll(class2Count.keySet());System.out.println(completeDisjointclasses); + completeDisjointclasses.removeAll(class2Count.keySet()); // we remove the asserted subclasses here completeDisjointclasses.removeAll(subClasses); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-28 11:00:57
|
Revision: 3515 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3515&view=rev Author: lorenz_b Date: 2011-12-28 11:00:47 +0000 (Wed, 28 Dec 2011) Log Message: ----------- Made more usage of JENA reasoning capabilities. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-27 10:36:53 UTC (rev 3514) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-28 11:00:47 UTC (rev 3515) @@ -183,7 +183,7 @@ QuerySolution qs; while(rs.hasNext()){ qs = rs.next();System.out.println(qs); - if(qs.getResource("type") != null){ + if(qs.getResource("type") != null && !qs.getResource("type").isAnon()){ cls = new NamedClass(qs.getResource("type").getURI()); int newCnt = qs.getLiteral("count").getInt(); oldCnt = result.get(cls); @@ -301,35 +301,35 @@ //Remove temporarily classToDescribe but keep track of their count // Integer all = class2Count.get(classToDescribe); class2Count.remove(classToDescribe); - + + //get complete disjoint classes Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); - completeDisjointclasses.removeAll(class2Count.keySet()); + completeDisjointclasses.removeAll(class2Count.keySet());System.out.println(completeDisjointclasses); + // we remove the asserted subclasses here + completeDisjointclasses.removeAll(subClasses); + for (Description subClass : subClasses) { + class2Count.remove(subClass); + } + //drop all classes which have a super class in this set - if(suggestMostGeneralClasses && reasoner.isPrepared()){ + if(suggestMostGeneralClasses){ keepMostGeneralClasses(completeDisjointclasses); } - //we remove the asserted subclasses here - completeDisjointclasses.removeAll(subClasses); - for(Description subClass : subClasses){ - class2Count.remove(subClass); - } + EvaluatedDescription evalDesc; //firstly, create disjoint classexpressions which not occur and give score of 1 - if(reasoner.isPrepared()){ - SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); - } for(NamedClass cls : completeDisjointclasses){ if(useClassPopularity){ int popularity = 0; if(ks.isRemote()){ popularity = reasoner.getIndividualsCount(cls); } else { - popularity = ((LocalModelBasedSparqlEndpointKS)ks).getModel().getOntClass(cls.getName()).listInstances(true).toSet().size(); + popularity = ((LocalModelBasedSparqlEndpointKS)ks).getModel().getOntClass(cls.getName()).listInstances().toSet().size(); } //we skip classes with no instances if(popularity == 0) continue; @@ -362,9 +362,33 @@ private void keepMostGeneralClasses(Set<NamedClass> classes){ - ClassHierarchy h = reasoner.getClassHierarchy(); - for(NamedClass nc : new HashSet<NamedClass>(classes)){ - classes.removeAll(h.getSubClasses(nc)); + if(ks.isRemote()){ + if(reasoner.isPrepared()){ + ClassHierarchy h = reasoner.getClassHierarchy(); + for(NamedClass nc : new HashSet<NamedClass>(classes)){ + classes.removeAll(h.getSubClasses(nc)); + } + } + } else { + OntModel model = ((LocalModelBasedSparqlEndpointKS)ks).getModel(); + +// Set<NamedClass> topClasses = new HashSet<NamedClass>(); +// for(OntClass cls : model.listNamedClasses().toSet()){ +// Set<OntClass> superClasses = cls.listSuperClasses().toSet(); +// if(superClasses.isEmpty() || +// (superClasses.size() == 1 && superClasses.contains(model.getOntClass(com.hp.hpl.jena.vocabulary.OWL.Thing.getURI())))){ +// topClasses.add(new NamedClass(cls.getURI())); +// } +// +// } +// classes.retainAll(topClasses); + for(NamedClass nc : new HashSet<NamedClass>(classes)){//System.out.print(nc + "::"); + for(OntClass cls : model.getOntClass(nc.getName()).listSubClasses().toSet()){//System.out.print(cls + "|"); + classes.remove(new NamedClass(cls.getURI())); + } +// System.out.println(); + } + } } @@ -378,7 +402,7 @@ // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); l.start(); - for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.2)){ + for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.0)){ System.out.println(e); } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-27 10:36:53 UTC (rev 3514) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-28 11:00:47 UTC (rev 3515) @@ -46,6 +46,8 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.AxiomComparator; import org.openrdf.model.vocabulary.OWL; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -195,7 +197,7 @@ return new SPARQLTasks(((SparqlEndpointKS) ks).getEndpoint()).getAllClasses(); } else { Set<NamedClass> classes = new TreeSet<NamedClass>(); - for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().filterDrop(new OWLFilter()).toList()){ + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().filterDrop(new OWLFilter()).filterDrop(new RDFSFilter()).filterDrop(new RDFFilter()).toList()){ if(!cls.isAnon()){ classes.add(new NamedClass(cls.getURI())); } @@ -331,5 +333,29 @@ } + class RDFSFilter extends Filter<OntClass>{ + @Override + public boolean accept(OntClass cls) { + if(!cls.isAnon()){ + return cls.getURI().startsWith(RDFS.NAMESPACE); + } + return false; + } + + } + + class RDFFilter extends Filter<OntClass>{ + + @Override + public boolean accept(OntClass cls) { + if(!cls.isAnon()){ + return cls.getURI().startsWith(RDF.NAMESPACE); + } + return false; + } + + } + + } Modified: trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-27 10:36:53 UTC (rev 3514) +++ trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-28 11:00:47 UTC (rev 3515) @@ -35,7 +35,7 @@ // read the RDF/XML file baseModel.read(in, null); - model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF, baseModel); + model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, baseModel); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-27 10:37:00
|
Revision: 3514 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3514&view=rev Author: lorenz_b Date: 2011-12-27 10:36:53 +0000 (Tue, 27 Dec 2011) Log Message: ----------- Continued to get working disjointness algorithm on local model. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -24,6 +24,7 @@ import java.util.Collections; 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; @@ -44,17 +45,21 @@ import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; -import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.learningproblems.Heuristics; +import org.openrdf.model.vocabulary.OWL; +import org.openrdf.model.vocabulary.RDF; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; 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; /** * Learns disjoint classes using SPARQL queries. @@ -123,64 +128,85 @@ allClasses.remove(classToDescribe); //get the subclasses - if(reasoner.isPrepared()){ - subClasses = reasoner.getClassHierarchy().getSubClasses(classToDescribe, false); + if(ks.isRemote()){ + if(reasoner.isPrepared()){ + subClasses = reasoner.getClassHierarchy().getSubClasses(classToDescribe, false); + } else { + subClasses = reasoner.getSubClasses(classToDescribe, true); + } } else { - subClasses = reasoner.getSubClasses(classToDescribe, true); + subClasses = new TreeSet<Description>(); + OntModel ontModel = ((LocalModelBasedSparqlEndpointKS)ks).getModel(); + OntClass cls = ontModel.getOntClass(classToDescribe.getName()); + for(OntClass sub : cls.listSubClasses(false).toSet()){ + if(!sub.isAnon()){ + subClasses.add(new NamedClass(sub.getURI())); + } + } + for(OntClass sup : cls.listSuperClasses().toSet()){System.out.println(cls.listSuperClasses().toSet()); + if(!sup.isAnon()){ + subClasses.add(new NamedClass(sup.getURI())); + } + } } if(ks.supportsSPARQL_1_1()){ runSPARQL1_0_Mode(); } else { - runSPARQL1_1_Mode(); + runSPARQL1_0_Mode(); } - //get classes and how often they occur - - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } private void runSPARQL1_0_Mode(){ + Model model = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; - String queryTemplate = "SELECT ?s ?type WHERE {?s a <%s>. ?s a ?type.} LIMIT %d OFFSET %d"; - String query; + String baseQuery = "CONSTRUCT {?s a <%s>. ?s a ?type.} WHERE {?s a <%s>. ?s a ?type.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, classToDescribe.getName(), classToDescribe.getName(), limit, offset);System.out.println(query); + Model newModel = executeConstructQuery(query); Map<NamedClass, Integer> result = new HashMap<NamedClass, Integer>(); NamedClass cls; Integer oldCnt; - boolean repeat = true; - - int total = 0; - - String resource = ""; - while(!terminationCriteriaSatisfied() && repeat){ - query = String.format(queryTemplate, classToDescribe, limit, offset); - ResultSet rs = executeSelectQuery(query); + while(newModel.size() != 0){ + model.add(newModel); + //get total number of distinct instances + query = "SELECT (COUNT(DISTINCT ?s) AS ?count) WHERE {?s a ?type.}"; + ResultSet rs = executeSelectQuery(query, model); + int total = rs.next().getLiteral("count").getInt(); + + // get number of instances of s with <s p o> + query = "SELECT ?type (COUNT(?s) AS ?count) WHERE {?s a ?type.}" + + " GROUP BY ?type"; + rs = executeSelectQuery(query, model); QuerySolution qs; - repeat = false; while(rs.hasNext()){ - qs = rs.next(); - String newResource = qs.getResource("?s").getURI(); - if(newResource != resource){ - total++; - resource = newResource; + qs = rs.next();System.out.println(qs); + if(qs.getResource("type") != null){ + cls = new NamedClass(qs.getResource("type").getURI()); + int newCnt = qs.getLiteral("count").getInt(); + oldCnt = result.get(cls); + if(oldCnt == null){ + oldCnt = Integer.valueOf(newCnt); + } else { + oldCnt += newCnt; + } + + result.put(cls, oldCnt); } - cls = new NamedClass(qs.getResource("type").getURI()); - oldCnt = result.get(cls); - if(oldCnt == null){ - oldCnt = Integer.valueOf(0); - } - int newCnt = oldCnt + 1; - result.put(cls, newCnt); - repeat = true; } + if(!result.isEmpty()){ - currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, total); - offset += 1000; + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses, total); } + + offset += limit; + query = String.format(baseQuery, classToDescribe.getName(), classToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } + } private void runSPARQL1_1_Mode(){ @@ -201,7 +227,7 @@ QuerySolution qs; repeat = false; while(rs.hasNext()){ - qs = rs.next(); + qs = rs.next();System.out.println(qs); if(qs.getResource("type") != null){ cls = new NamedClass(qs.getResource("type").getURI()); int newCnt = qs.getLiteral("count").getInt(); @@ -218,7 +244,7 @@ } if(!result.isEmpty()){ - currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses); + currentlyBestEvaluatedDescriptions = buildEvaluatedClassDescriptions(result, allClasses, result.get(classToDescribe)); offset += 1000; } } @@ -269,11 +295,11 @@ return axioms; } - private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, Set<NamedClass> allClasses){ + private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, Set<NamedClass> allClasses, int total){ List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); //Remove temporarily classToDescribe but keep track of their count - Integer all = class2Count.get(classToDescribe); +// Integer all = class2Count.get(classToDescribe); class2Count.remove(classToDescribe); //get complete disjoint classes @@ -299,7 +325,12 @@ } for(NamedClass cls : completeDisjointclasses){ if(useClassPopularity){ - int popularity = reasoner.getIndividualsCount(cls); + int popularity = 0; + if(ks.isRemote()){ + popularity = reasoner.getIndividualsCount(cls); + } else { + popularity = ((LocalModelBasedSparqlEndpointKS)ks).getModel().getOntClass(cls.getName()).listInstances(true).toSet().size(); + } //we skip classes with no instances if(popularity == 0) continue; double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); @@ -314,66 +345,10 @@ //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ + //drop classes from OWL and RDF namespace + if(entry.getKey().getName().startsWith(OWL.NAMESPACE) || entry.getKey().getName().startsWith(RDF.NAMESPACE))continue; // evalDesc = new EvaluatedDescription(entry.getKey(), // new AxiomScore(1 - (entry.getValue() / (double)all))); - double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(all, entry.getValue()); - double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; - evalDesc = new EvaluatedDescription(entry.getKey(), - new AxiomScore(1 - accuracy)); - evalDescs.add(evalDesc); - } - - class2Count.put(classToDescribe, all); - return evalDescs; - } - - private List<EvaluatedDescription> buildEvaluatedClassDescriptions(Map<NamedClass, Integer> class2Count, int total){ - List<EvaluatedDescription> evalDescs = new ArrayList<EvaluatedDescription>(); - - //Remove temporarily classToDescribe but keep track of their count - class2Count.remove(classToDescribe); - - //get complete disjoint classes - Set<NamedClass> completeDisjointclasses = new TreeSet<NamedClass>(allClasses); - completeDisjointclasses.removeAll(class2Count.keySet()); - - //drop all classes which have a super class in this set - if(suggestMostGeneralClasses && reasoner.isPrepared()){ - keepMostGeneralClasses(completeDisjointclasses); - } - - //we remove the asserted subclasses here - completeDisjointclasses.removeAll(subClasses); - for(Description subClass : subClasses){ - class2Count.remove(subClass); - } - - - EvaluatedDescription evalDesc; - //firstly, create disjoint classexpressions which not occur and give score of 1 - if(reasoner.isPrepared()){ - SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); - } - for(NamedClass cls : completeDisjointclasses){ - if(useClassPopularity && ( - (ks instanceof SparqlEndpointKS && ((SparqlEndpointKS) ks).supportsSPARQL_1_1()) || !(ks instanceof SparqlEndpointKS))){ - int popularity = reasoner.getIndividualsCount(cls); - //we skip classes with no instances - if(popularity == 0) continue; - double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(popularity, 0); - double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; - evalDesc = new EvaluatedDescription(cls, new AxiomScore(1- accuracy)); - } else { - evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); - } - - evalDescs.add(evalDesc); - } - - //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) - for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ -// evalDesc = new EvaluatedDescription(entry.getKey(), -// new AxiomScore(1 - (entry.getValue() / (double)all))); double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, entry.getValue()); double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; evalDesc = new EvaluatedDescription(entry.getKey(), @@ -385,6 +360,7 @@ return evalDescs; } + private void keepMostGeneralClasses(Set<NamedClass> classes){ ClassHierarchy h = reasoner.getClassHierarchy(); for(NamedClass nc : new HashSet<NamedClass>(classes)){ @@ -393,17 +369,16 @@ } public static void main(String[] args) throws Exception{ - LocalModelBasedSparqlEndpointKS ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); - DisjointClassesLearner l = new DisjointClassesLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), - Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()))); - l = new DisjointClassesLearner(ks); +// SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + SparqlEndpointKS ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); + DisjointClassesLearner l = new DisjointClassesLearner(ks); l.setClassToDescribe(new NamedClass("http://ns.softwiki.de/req/CustomerRequirement")); l.init(); - l.getReasoner().prepareSubsumptionHierarchy(); +// l.getReasoner().prepareSubsumptionHierarchy(); // System.out.println(l.getReasoner().getClassHierarchy().getSubClasses(new NamedClass("http://dbpedia.org/ontology/Athlete"), false));System.exit(0); l.start(); - for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.75)){ + for(EvaluatedAxiom e : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE, 0.2)){ System.out.println(e); } Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -45,6 +45,7 @@ import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.AxiomComparator; +import org.openrdf.model.vocabulary.OWL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -55,6 +56,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.util.iterator.Filter; /** * @author Lorenz Bühmann @@ -193,7 +195,7 @@ return new SPARQLTasks(((SparqlEndpointKS) ks).getEndpoint()).getAllClasses(); } else { Set<NamedClass> classes = new TreeSet<NamedClass>(); - for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().toList()){ + for(OntClass cls : ((LocalModelBasedSparqlEndpointKS)ks).getModel().listClasses().filterDrop(new OWLFilter()).toList()){ if(!cls.isAnon()){ classes.add(new NamedClass(cls.getURI())); } @@ -235,7 +237,7 @@ } protected ResultSet executeSelectQuery(String query, Model model) { - logger.info("Sending query\n{} ...", query); + logger.info("Sending query on local model\n{} ...", query); QueryExecution qexec = QueryExecutionFactory.create(query, model); ResultSet rs = qexec.execSelect();; @@ -317,6 +319,17 @@ return new AxiomScore(accuracy, confidence); } + class OWLFilter extends Filter<OntClass>{ + + @Override + public boolean accept(OntClass cls) { + if(!cls.isAnon()){ + return cls.getURI().startsWith(OWL.NAMESPACE); + } + return false; + } + + } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-21 14:38:40 UTC (rev 3513) +++ trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2011-12-27 10:36:53 UTC (rev 3514) @@ -35,7 +35,7 @@ // read the RDF/XML file baseModel.read(in, null); - model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, baseModel); + model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF, baseModel); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <km...@us...> - 2011-12-21 14:38:51
|
Revision: 3513 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3513&view=rev Author: kmpf Date: 2011-12-21 14:38:40 +0000 (Wed, 21 Dec 2011) Log Message: ----------- Changed a SPARQL query Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-12-21 10:15:12 UTC (rev 3512) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/AminoAcids.java 2011-12-21 14:38:40 UTC (rev 3513) @@ -31,6 +31,7 @@ public static final Resource TYR = ResourceFactory.createResource("http://bio2rdf.org/pdb:Tyrosine"); public static final Resource SEL = ResourceFactory.createResource("http://bio2rdf.org/pdb:Selenomethionine"); public static final Resource HYT = ResourceFactory.createResource("http://bio2rdf.org/pdb:2-hydroxy-tryptophan"); + public static final Resource SOC = ResourceFactory.createResource("http://bio2rdf.org/pdb:S-oxyCysteine"); public static HashMap<Resource, File> getAllConfFiles (String dir, String confFileName){ HashMap<Resource, File> aminoAcidsConfFiles = new HashMap<Resource, File>(30); @@ -56,6 +57,8 @@ aminoAcidsConfFiles.put(TYR, new File(dir + confFileName.replace(".conf", "." + TYR.getLocalName() + ".conf"))); aminoAcidsConfFiles.put(SEL, new File(dir + confFileName.replace(".conf", "." + SEL.getLocalName() + ".conf"))); aminoAcidsConfFiles.put(HYT, new File(dir + confFileName.replace(".conf", "." + HYT.getLocalName() + ".conf"))); + aminoAcidsConfFiles.put(SOC, new File(dir + confFileName.replace(".conf", "." + SOC.getLocalName() + ".conf"))); + return aminoAcidsConfFiles; } @@ -85,6 +88,8 @@ resprint.put(TYR, new PrintStream(allConfFiles.get(TYR))); resprint.put(SEL, new PrintStream(allConfFiles.get(SEL))); resprint.put(HYT, new PrintStream(allConfFiles.get(HYT))); + resprint.put(SOC, new PrintStream(allConfFiles.get(SOC))); + } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -116,6 +121,7 @@ resourceString.put(TYR, new StringBuffer(init)); resourceString.put(SEL, new StringBuffer(init)); resourceString.put(HYT, new StringBuffer(init)); + resourceString.put(SOC, new StringBuffer(init)); return resourceString; } Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-12-21 10:15:12 UTC (rev 3512) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/HelixRDFCreator.java 2011-12-21 14:38:40 UTC (rev 3513) @@ -103,15 +103,19 @@ Boolean dlLearn = false; Boolean wekaLearn = false; - int dataSet = 1; + int dataSet = 5; /* * data for test purpose */ - PDBProtein testProtein = new PDBProtein("1EDM","B"); -// PDBProtein testProtein = new PDBProtein("1LMB", "3"); -// PDBProtein testProtein = new PDBProtein("8ABP"); + /* +++ Problem IDs +++ + * Warum funktionieren die Abfragen mit den untenstehenden PDB IDs nicht??? + */ +// PDBProtein testProtein = new PDBProtein("1HTR","P"); +// PDBProtein testProtein = new PDBProtein("2W9Y","A"); + PDBProtein testProtein = new PDBProtein("3A4R","A"); + /* * create a training data set @@ -411,6 +415,7 @@ for (int i = 0 ; i < negatives.size() ; i++ ) { lp.append("\"" + negatives.get(i).getURI() + "\", "); try{ + _logger.info("Negative residue: " + negatives.get(i).getURI()); Statement spo = model.getModel().getProperty(negatives.get(i), type); resourceStringBuffer.get(spo.getResource()).append("\"" + negatives.get(i).getURI() + "\", "); } catch (NullPointerException e) { Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-12-21 10:15:12 UTC (rev 3512) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2011-12-21 14:38:40 UTC (rev 3513) @@ -7,11 +7,7 @@ import java.util.ArrayList; import java.util.HashMap; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; import org.xml.sax.InputSource; import com.dumontierlab.pdb2rdf.model.PdbRdfModel; @@ -22,7 +18,6 @@ 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.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -205,30 +200,36 @@ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> " + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + - "CONSTRUCT { ?x1 pdb:beginsAt ?x2 ." + - " ?x1 pdb:endsAt ?x3 ." + - " ?x5 dcterms:isPartOf ?x4 ." + - " ?x5 rdf:type ?x6 ." + - " ?x5 pdb:isImmediatelyBefore ?x7 ." + - " ?x5 pdb:hasChainPosition ?x8 ." + - " ?x8 rdfs:label ?residuePosition ." + - " ?x8 pdb:hasValue ?x9 ." + - " ?organism rdfs:label ?organismName ." + - " ?seq rdf:type pdb:PolymerSequence ." + - " ?seq pdb:hasValue ?sequence . } " + + "CONSTRUCT { " + + " ?x1 pdb:beginsAt ?x2 ." + + " ?x1 pdb:endsAt ?x3 ." + + " ?x5 dcterms:isPartOf ?x4 ." + + " ?x5 rdf:type ?x6 ." + + " ?x5 pdb:isImmediatelyBefore ?x7 ." + + " ?x5 pdb:hasChainPosition ?x8 ." + + " ?x8 pdb:hasValue ?x9 ." + + " ?organism rdfs:label ?organismName ." + + " ?seq rdf:type pdb:PolymerSequence ." + + " ?seq pdb:hasValue ?sequence . " + + "} " + "WHERE { " + - " OPTIONAL { ?x1 rdf:type pdb:Helix ." + - " ?x1 pdb:beginsAt ?x2 ." + - " ?x1 pdb:endsAt ?x3 . } . " + - " ?x3 dcterms:isPartOf ?x4 ." + - " ?x4 rdf:type <http://bio2rdf.org/pdb:Polypeptide(L)> ." + - " ?x5 dcterms:isPartOf ?x4 ." + - " ?x5 rdf:type ?x6 ." + + " OPTIONAL { ?x1 rdf:type pdb:Helix ." + + " ?x1 pdb:beginsAt ?x2 ." + + " ?x1 pdb:endsAt ?x3 . " + + "} . " + + " ?x3 dcterms:isPartOf ?x4 ." + + " ?x4 rdf:type <http://bio2rdf.org/pdb:Polypeptide(L)> ." + + //" <http://bio2rdf.org/pdb:3A4R/chemicalComponent_A0> dcterms:isPartOf ?x4 ." + + //" <http://bio2rdf.org/pdb:3A4R/chemicalComponent_A0> rdf:type ?x6 ." + + //" OPTIONAL { <http://bio2rdf.org/pdb:3A4R/chemicalComponent_A0> pdb:isImmediatelyBefore ?x7 . } ." + + //" <http://bio2rdf.org/pdb:3A4R/chemicalComponent_A0> pdb:hasChainPosition ?x8 ." + + " ?x5 dcterms:isPartOf ?x4 . " + + " ?x5 rdf:type ?x6 ." + // with the optional clause i get the information by which amino acid // a amino acid is followed - " OPTIONAL { ?x5 pdb:isImmediatelyBefore ?x7 . } . " + - " ?x5 pdb:hasChainPosition ?x8 ." + - " ?x8 pdb:hasValue ?x9 Filter (xsd:int(?x9)) ."; + " OPTIONAL { ?x5 pdb:isImmediatelyBefore ?x7 . } ." + + " ?x5 pdb:hasChainPosition ?x8 ." + + " ?x8 pdb:hasValue ?x9 Filter (datatype((?x9)) = xsd:integer) ."; if (chainID.length() == 1 && pdbID.length() == 4) { queryString += @@ -237,11 +238,13 @@ "/chain_" + chainID.toUpperCase() + "> ."; } queryString += - " ?x4 pdb:hasPolymerSequence ?seq . " + - " ?seq rdf:type pdb:PolymerSequence . " + - " ?seq pdb:hasValue ?sequence . " + - " OPTIONAL { ?organism rdfs:label ?organismName " + - "FILTER (str(?organism) = fn:concat(str(?x4), '/extraction/source/gene/organism')) . } . }"; + " ?x4 pdb:hasPolymerSequence ?seq . " + + " ?seq rdf:type pdb:PolymerSequence . " + + " ?seq pdb:hasValue ?sequence . " + + " OPTIONAL { ?organism rdfs:label ?organismName " + + "FILTER (str(?organism) = fn:concat(str(?x4), '/extraction/source/gene/organism')) . " + + "} . " + + "}"; _logger.debug(queryString); Query query = QueryFactory.create(queryString); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-21 10:15:23
|
Revision: 3512 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3512&view=rev Author: lorenz_b Date: 2011-12-21 10:15:12 +0000 (Wed, 21 Dec 2011) Log Message: ----------- Extended script to firstly handle the root unsatisfiable classes. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2011-12-20 11:43:21 UTC (rev 3511) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2011-12-21 10:15:12 UTC (rev 3512) @@ -1,6 +1,9 @@ package org.dllearner.utilities; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -11,8 +14,10 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.aksw.mole.ore.rootderived.StructureBasedRootClassFinder; import org.mindswap.pellet.RBox; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLEntity; @@ -20,6 +25,7 @@ import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.model.RemoveAxiom; import uk.ac.manchester.cs.owlapi.modularity.ModuleType; @@ -31,14 +37,14 @@ public class JustificationBasedCoherentOntologyExtractor implements CoherentOntologyExtractor{ - private static final int NUMBER_OF_JUSTIFICATIONS = 2; + private static final int NUMBER_OF_JUSTIFICATIONS = 5; // private PelletReasoner reasoner; private IncrementalClassifier reasoner; private OWLOntology incoherentOntology; private OWLOntology ontology; - private Map<OWLClass, OWLOntology> cls2ModuleMap; + private Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); static {PelletExplanation.setup();} @@ -54,49 +60,134 @@ OWLOntologyManager man = incoherentOntology.getOWLOntologyManager(); // man.addOntologyChangeListener(reasoner); + StructureBasedRootClassFinder rootFinder = new StructureBasedRootClassFinder(reasoner); + rootFinder.computeRootDerivedClasses(); + Set<OWLClass> unsatClasses = rootFinder.getRootUnsatisfiableClasses();//reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + int cnt = unsatClasses.size(); - Set<OWLClass> unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); - //if the ontology is not incoherent we return it here if(unsatClasses.isEmpty()){ return incoherentOntology; } - + //compute the logical modules for each unsatisfiable class cls2ModuleMap = extractModules(unsatClasses); + + //compute initial explanations for each unsatisfiable class + Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = getInitialExplanationsForUnsatClasses(unsatClasses); while(!unsatClasses.isEmpty()){ - //for each unsatisfiable class we compute n justifications here and count how often each axiom occurs globally - Map<OWLAxiom, Integer> axiom2CountMap = new HashMap<OWLAxiom, Integer>(); - for(OWLClass unsatClass : unsatClasses){ - Set<Set<OWLAxiom>> explanations = computeExplanations(unsatClass); - for(Set<OWLAxiom> explanation : explanations){ - for(OWLAxiom ax : explanation){ - Integer cnt = axiom2CountMap.get(ax); - if(cnt == null){ - cnt = 0; - } - cnt = cnt + 1; - axiom2CountMap.put(ax, cnt); - } - } - } + //get frequency for each axiom + Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(cls2Explanations); + //get a sorted list of entries with the highest axiom count first List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); for(Entry<OWLAxiom, Integer> entry : sortedEntries){ System.out.println(entry.getKey() + ":" + entry.getValue()); } - //we remove the most occuring axiom + //we remove the most frequent axiom from the ontology OWLAxiom toRemove = sortedEntries.get(0).getKey(); + System.out.println("Removing axiom " + toRemove); man.removeAxiom(incoherentOntology, toRemove); man.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); + removeFromExplanations(cls2Explanations, toRemove); + removeFromModules(toRemove); + + //recompute the unsatisfiable classes reasoner.classify(); - unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + rootFinder = new StructureBasedRootClassFinder(reasoner); + rootFinder.computeRootDerivedClasses(); + unsatClasses = rootFinder.getRootUnsatisfiableClasses();//reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); + System.out.println("Remaining unsatisfiable classes: " + unsatClasses.size()); + + //save + if(cnt - unsatClasses.size() >= 10){ + OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); + try { + toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_" + unsatClasses.size() + ".owl"))); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + cnt = unsatClasses.size(); + } + + //recompute explanations if necessary + refillExplanations(unsatClasses, cls2Explanations); + + System.gc(); } + try { + incoherentOntology.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_coherent.owl"))); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } System.out.println(incoherentOntology.getLogicalAxiomCount()); return getOntologyWithAnnotations(incoherentOntology); } + private void removeFromModules(OWLAxiom axiom){ + OWLOntology module; + for(Entry<OWLClass, OWLOntology> entry : cls2ModuleMap.entrySet()){ + module = entry.getValue(); + module.getOWLOntologyManager().removeAxiom(module, axiom); + } + } + + private void removeFromExplanations(Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations, OWLAxiom axiom){ + for(Entry<OWLClass, Set<Set<OWLAxiom>>> entry : cls2Explanations.entrySet()){ + for (Iterator<Set<OWLAxiom>> iterator = entry.getValue().iterator(); iterator.hasNext();) { + Set<OWLAxiom> explanation = iterator.next(); + if(explanation.contains(axiom)){ + iterator.remove(); + } + } + } + } + + private void refillExplanations(Set<OWLClass> unsatClasses, Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations){ + for(OWLClass unsatClass : unsatClasses){ + Set<Set<OWLAxiom>> precomputedExplanations = cls2Explanations.get(unsatClass); + if(precomputedExplanations == null || precomputedExplanations.size() < NUMBER_OF_JUSTIFICATIONS){ + Set<Set<OWLAxiom>> newExplanations = computeExplanations(unsatClass, NUMBER_OF_JUSTIFICATIONS); + cls2Explanations.put(unsatClass, newExplanations); + } + } + } + + private Map<OWLAxiom, Integer> getAxiomFrequency(Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations){ + Map<OWLAxiom, Integer> axiom2CountMap = new HashMap<OWLAxiom, Integer>(); + + for(Entry<OWLClass, Set<Set<OWLAxiom>>> entry : cls2Explanations.entrySet()){ + for(Set<OWLAxiom> explanation : entry.getValue()){ + for(OWLAxiom ax : explanation){ + Integer cnt = axiom2CountMap.get(ax); + if(cnt == null){ + cnt = 0; + } + cnt = cnt + 1; + axiom2CountMap.put(ax, cnt); + } + } + } + + return axiom2CountMap; + } + + private Map<OWLClass, Set<Set<OWLAxiom>>> getInitialExplanationsForUnsatClasses(Set<OWLClass> unsatClasses){ + Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = new HashMap<OWLClass, Set<Set<OWLAxiom>>>(); + + for(OWLClass unsatClass : unsatClasses){ + Set<Set<OWLAxiom>> explanations = computeExplanations(unsatClass); + cls2Explanations.put(unsatClass, explanations); + } + + return cls2Explanations; + } + private OWLOntology getOntologyWithoutAnnotations(OWLOntology ontology){ try { OWLOntologyManager man = ontology.getOWLOntologyManager(); @@ -124,15 +215,29 @@ } private Set<Set<OWLAxiom>> computeExplanations(OWLClass unsatClass){ - PelletExplanation expGen = new PelletExplanation(cls2ModuleMap.get(unsatClass)); + PelletExplanation expGen = new PelletExplanation(getModule(unsatClass)); return expGen.getUnsatisfiableExplanations(unsatClass, NUMBER_OF_JUSTIFICATIONS); } + private Set<Set<OWLAxiom>> computeExplanations(OWLClass unsatClass, int limit){ + PelletExplanation expGen = new PelletExplanation(getModule(unsatClass)); + return expGen.getUnsatisfiableExplanations(unsatClass, NUMBER_OF_JUSTIFICATIONS); + } + + private OWLOntology getModule(OWLClass cls){ + OWLOntology module = cls2ModuleMap.get(cls); + if(module == null){ + module = OntologyUtils.getOntologyFromAxioms( + ModularityUtils.extractModule(incoherentOntology, Collections.singleton((OWLEntity)cls), ModuleType.TOP_OF_BOT)); + cls2ModuleMap.put(cls, module); + } + return module; + } + private Map<OWLClass, OWLOntology> extractModules(Set<OWLClass> classes){ Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); for(OWLClass cls : classes){ - OWLOntology module = OntologyUtils.getOntologyFromAxioms( - ModularityUtils.extractModule(incoherentOntology, Collections.singleton((OWLEntity)cls), ModuleType.TOP_OF_BOT)); + OWLOntology module = getModule(cls); cls2ModuleMap.put(cls, module); } return cls2ModuleMap; @@ -144,6 +249,9 @@ // OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("../components-core/cohaerent.owl")); // System.out.println(schema.getLogicalAxiomCount()); OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("/home/lorenz/arbeit/dbpedia_0.75_no_datapropaxioms.owl")); +// System.out.println(schema.getLogicalAxiomCount()); +// OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("log/dbpedia_coherent.owl")); + System.out.println(schema.getLogicalAxiomCount()); JustificationBasedCoherentOntologyExtractor extractor = new JustificationBasedCoherentOntologyExtractor(); OWLOntology coherentOntology = extractor.getCoherentOntology(schema);System.out.println(coherentOntology.getLogicalAxiomCount()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2011-12-20 11:43:32
|
Revision: 3511 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3511&view=rev Author: christinaunger Date: 2011-12-20 11:43:21 +0000 (Tue, 20 Dec 2011) Log Message: ----------- [tbsl] revised BasicTemplator Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2011-12-19 16:07:11 UTC (rev 3510) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2011-12-20 11:43:21 UTC (rev 3511) @@ -33,6 +33,7 @@ List<Slot> slots; // BasicQueryTemplate query; List<Integer> usedInts; + List<Simple_DRS_Condition> unusedConditions; public DRS2BasicSPARQL_Converter() { // query = new BasicQueryTemplate(); @@ -54,7 +55,7 @@ // query = new BasicQueryTemplate(); slots = ls; - + return convert(drs, new BasicQueryTemplate(), false); } @@ -65,8 +66,10 @@ if (!restructureEmpty(drs)) { return null; } - System.out.println("--- DRS (after) : " + drs); // DEBUG - + System.out.println("DRS:\n" + drs); // DEBUG + + unusedConditions = new ArrayList<Simple_DRS_Condition>(); + for (DRS_Condition condition : drs.getConditions()) { convertCondition(condition,temp); if (negate) { @@ -77,6 +80,21 @@ } } } + + for (Simple_DRS_Condition c : unusedConditions) { + if (!temp.getVariablesInConditions().contains(c.getArguments().get(0))) { + String v = c.getArguments().get(0).getValue(); + for (Slot s : slots) { + if (s.getAnchor().equals(v) && !s.getSlotType().equals(SlotType.RESOURCE)) { + String fresh = v+createFresh(); + s.setAnchor(fresh); + temp.addConditions(new Path(v,"isA",fresh)); + temp.addSlot(s); + break; + } + } + } + } for (DiscourseReferent referent : drs.collectDRs()) { if (referent.isMarked()) { @@ -91,6 +109,7 @@ f.addNotBound(term); temp.addFilter(f); } + for (Slot s : slots) { if (s.getAnchor().equals(referent.getValue())) { temp.addSlot(s); // query @@ -311,15 +330,14 @@ new SPARQL_Term(simple.getArguments().get(1).getValue(),true), SPARQL_PairType.REGEX))); } - else if (predicate.equals("ISA")) { - temp.addConditions(new Path(simple.getArguments().get(0).getValue(),"isA",simple.getArguments().get(1).getValue())); + else { + if (simple.getArguments().size() == 1) { + unusedConditions.add((Simple_DRS_Condition) condition); + } } -// else { -// if (simple.getArguments().size() == 1) { -// temp.addConditions(new Path(simple.getArguments().get(0).getValue(),"rdf:type",simple.getPredicate())); -// } -// } + } + return temp; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java 2011-12-19 16:07:11 UTC (rev 3510) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/BasicQueryTemplate.java 2011-12-20 11:43:21 UTC (rev 3511) @@ -106,6 +106,16 @@ } return result; } + + public Set<String> getVariablesInConditions() { + Set<String> vars = new HashSet<String>(); + for (Path p : conditions) { + vars.add(p.start); + vars.add(p.via); + vars.add(p.target); + } + return vars; + } public Set<SPARQL_Term> getSelTerms() { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-19 16:07:11 UTC (rev 3510) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-20 11:43:21 UTC (rev 3511) @@ -59,19 +59,19 @@ /* DP */ String[] dpEntry1 = {token, "(DP (NP " + treetoken + "))", - "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; String[] dpEntry2 = {token, "(DP (NP " + treetoken + " DP[name]))", - "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(p), ISA(x,p), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; result.add(dpEntry1); result.add(dpEntry2); /* NP */ String[] npEntry1 = {token, "(NP " + treetoken + ")", - "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; String[] npEntry2 = {token, "(NP " + treetoken + " DP[name])", - "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; result.add(npEntry1); result.add(npEntry2); } @@ -89,13 +89,13 @@ else if (pos.equals("NPREP")) { String[] dpEntry1 = {token, "(DP (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; String[] dpEntry2 = {token, "(DP DET[det] (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>"}; String[] npEntry = {token, "(NP " + treetoken + " DP[pobj])", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; result.add(dpEntry1); result.add(dpEntry2); result.add(npEntry); @@ -104,13 +104,13 @@ slot = "SLOT_" + tokenfluent + "/UNSPEC/" + token; String[] dpEntry1 = {token, "(DP (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>" }; + "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>" }; String[] dpEntry2 = {token, "(DP DET[det] (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>" }; + "<x,l1,<<e,t>,t>,[ l1:[ p | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>" }; String[] npEntry = {token, "(NP " + treetoken + " DP[pobj])", - "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; result.add(dpEntry1); result.add(dpEntry2); result.add(npEntry); @@ -119,7 +119,7 @@ slot = "SLOT_" + tokenfluent + "/UNSPEC/" + token; String[] npEntry = {token, "(NP " + treetoken + " )", - "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; result.add(npEntry); } @@ -136,11 +136,11 @@ if (pos.equals("PASSIVE")) { String[] passEntry1 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; String[] passEntry2 = {token, "(S DP[wh] (VP DP[dp] V:'" + token + "'))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,x,wh,<<e,t>,t>),(l3,y,dp,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(y,x) ] ],[(l2,x,wh,<<e,t>,t>),(l3,y,dp,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,wh,<<e,t>,t>),(l3,y,dp,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(passEntry1); result.add(passEntry2); @@ -148,35 +148,35 @@ else if (pos.equals("PASSPART")) { String[] passpartEntry = {token, "(NP NP* (VP V:'" + token + "' DP[dp]))", - "<x,l1,t,[ l1:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + + "<x,l1,t,[ l1:[ p | SLOT_" + token + "(y,x) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[ | empty(y,x) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[]>"}; result.add(passpartEntry); } else if (pos.equals("VPASS")) { String[] passEntry = {token, "(S DP[subj] (VP V:'" + token + "'))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(passEntry); } else if (pos.equals("VPASSIN")) { String[] passEntry1 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; String[] passEntry2 = {token, "(S DP[dp] (VP V:'" + token + "' NUM[num]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,z) ] ],[(l2,x,dp,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(y,z) ] ],[(l2,x,dp,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; result.add(passEntry1); result.add(passEntry2); } else if (pos.equals("GERUNDIN")) { String[] gerundinEntry1 = {token, "(NP NP* V:'" + token + "' DP[obj]))", - "<x,l1,t,[ l1:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + + "<x,l1,t,[ l1:[ p | SLOT_" + token + "(y,x) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[ | empty(x,y) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[]>"}; String[] gerundinEntry2 = {token, "(ADJ V:'" + token + "' DP[obj]))", - "<x,l1,<e,t>,[ l1:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + + "<x,l1,<e,t>,[ l1:[ p | SLOT_" + token + "(y,x) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + " ;; <x,l1,<e,t>,[ l1:[ | empty(x,y) ] ],[(l2,y,obj,<<e,t>,t>)],[ l2=l1 ],[]>"}; result.add(gerundinEntry1); result.add(gerundinEntry2); @@ -184,14 +184,14 @@ else if (pos.equals("VPREP")) { String[] passEntry1 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; String[] passEntry2 = {token, "(S DP[subj] (VP V:'" + token + "' NUM[num]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y), DATE(y,z) ] ],[(l2,x,subj,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(x,y), DATE(y,z) ] ],[(l2,x,subj,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; String[] whEntry = {token, "(S DP[obj] (VP DP[subj] V:'" + token + "'))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(passEntry1); result.add(passEntry2); @@ -200,7 +200,7 @@ else if (pos.equals("VBD") || pos.equals("VBZ") || pos.equals("VBP")) { String[] vEntry = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(vEntry); @@ -208,18 +208,18 @@ else if (pos.equals("VB")) { String[] whEntry = {token, "(S DP[obj] (VP DP[subj] V:'" + token + "'))", - "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; result.add(whEntry); } else if (pos.equals("VBG") || pos.equals("VBN")) { String[] gerEntry = {token, "(NP NP* (VP V:'" + token + "' DP[dp]))", - "<x,l1,t,[ l1:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + + "<x,l1,t,[ l1:[ p | SLOT_" + token + "(x,y) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[" + slot + "]>" + ";; <x,l1,t,[ l1:[ | empty(x,y) ] ],[(l2,y,dp,<<e,t>,t>)],[ l2=l1 ],[]>"}; String[] wasGerEntry = {token, "(S DP[comp] (VP V:'was' DP[subject] V:'" + token + "'))", - "<y,l1,t,[ l1:[ | SLOT_" + token + "(p), p(y,z) ] ],[(l2,y,comp,<<e,t>,t>), (l3,z,subject,<<e,t>,t>) ],[ l2=l1, l3=l1 ],[" + slot + "]>"}; + "<y,l1,t,[ l1:[ | SLOT_" + token + "(y,z) ] ],[(l2,y,comp,<<e,t>,t>), (l3,z,subject,<<e,t>,t>) ],[ l2=l1, l3=l1 ],[" + slot + "]>"}; result.add(wasGerEntry); result.add(gerEntry); } @@ -227,14 +227,14 @@ slot = "SLOT_" + token + "/PROPERTY/" + token + "_date"; String[] whenEntry = {token, "(S DP[subj] (VP V:'" + token + "'))", - "<x,l1,t,[ l1:[ ?y,p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>)],[ l2=l1 ],[ " + slot + " ]>"}; + "<x,l1,t,[ l1:[ ?y,p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>)],[ l2=l1 ],[ " + slot + " ]>"}; result.add(whenEntry); } else if (pos.equals("WHERE")) { slot = "SLOT_" + token + "/PROPERTY/" + token + "_place"; String[] whereEntry = {token, "(S DP[subj] (VP V:'" + token + "'))", - "<x,l1,t,[ l1:[ ?y,p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>)],[ l2=l1 ],[ " + slot + " ]>"}; + "<x,l1,t,[ l1:[ ?y,p | SLOT_" + token + "(x,y) ] ],[(l2,x,subj,<<e,t>,t>)],[ l2=l1 ],[ " + slot + " ]>"}; result.add(whereEntry); } @@ -247,13 +247,13 @@ if (pos.equals("JJ")) { String[] adjEntry = {token, "(NP ADJ:'" + token.toLowerCase() + "' NP*)", - "<x,l1,<e,t>,[ l1:[ j | SLOT_" + token + "(p), p(x,j) ] ],[],[],["+slot+"]>"}; + "<x,l1,<e,t>,[ l1:[ j | SLOT_" + token + "(x,j) ] ],[],[],["+slot+"]>"}; result.add(adjEntry); } if (pos.equals("JJH")) { String[] howEntry = {"how "+token, "(DP ADJ:'" + token.toLowerCase() + "')", - "<x,l1,<<e,t>,t>,[ l1:[ ?j,x,p | SLOT_" + token + "(p), p(x,j) ] ],[],[],["+slot+"]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ ?j,x,p | SLOT_" + token + "(x,j) ] ],[],[],["+slot+"]>"}; result.add(howEntry); } /* COMPARATIVE */ @@ -266,11 +266,11 @@ String[] compEntry1 = {token, "(ADJ ADJ:'" + token.toLowerCase() + "' P:'than' DP[compobj])", - "<x,l1,<e,t>,[ l1:[ p,j,i | SLOT_" + token + "(p), p(x,i), p(y,j), " + comp + "(i,j) ] ],[ (l2,y,compobj,<<e,t>,t>) ],[l1=l2],["+slot+"]>"}; + "<x,l1,<e,t>,[ l1:[ p,j,i | SLOT_" + token + "(x,i), SLOT_" + token + "(y,j), " + comp + "(i,j) ] ],[ (l2,y,compobj,<<e,t>,t>) ],[l1=l2],["+slot+"]>"}; result.add(compEntry1); String[] compEntry2 = {token, "(NP NP* (ADJ ADJ:'" + token.toLowerCase() + "' P:'than' DP[compobj]))", - "<x,l1,<e,t>,[ l1:[ p,j,i | SLOT_" + token + "(p), p(x,i), p(y,j), " + comp + "(i,j) ] ],[ (l2,y,compobj,<<e,t>,t>) ],[l1=l2],["+slot+"]>"}; + "<x,l1,<e,t>,[ l1:[ p,j,i | SLOT_" + token + "(x,i), SLOT_" + token + "(y,j), " + comp + "(i,j) ] ],[ (l2,y,compobj,<<e,t>,t>) ],[l1=l2],["+slot+"]>"}; result.add(compEntry2); } /* SUPERLATIVE */ @@ -283,28 +283,29 @@ String[] superEntry1 = {token, "(DET DET:'the' ADJ:'" + token.toLowerCase() + "')", - "<x,l1,e,[ l1:[ p,x,j | SLOT_" + token + "(p), p(x,j), " + comp + "(j) ] ],[],[],["+slot+"]>"}; + "<x,l1,e,[ l1:[ p,x,j | SLOT_" + token + "(x,j), " + comp + "(j) ] ],[],[],["+slot+"]>"}; result.add(superEntry1); String[] superEntry2 = {token, "(DP (NP DET:'the' ADJ:'" + token.toLowerCase() + "'))", - "<x,l1,<<e,t>,t>,[ l1:[ p,x,j | SLOT_" + token + "(p), p(x,j), " + comp + "(j) ] ],[],[],["+slot+"]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ p,x,j | SLOT_" + token + "(x,j), " + comp + "(j) ] ],[],[],["+slot+"]>"}; result.add(superEntry2); String[] superEntry3 = {token, "(DP (NP DET:'the' ADJ:'" + token.toLowerCase() + "' NP[noun]))", - "<x,l1,<<e,t>,t>,[ l1:[ p,x,j | SLOT_" + token + "(p), p(x,j), " + comp + "(j) ] ],[ (l2,x,noun,<e,t>) ],[l2=l1],["+slot+"]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ p,x,j | SLOT_" + token + "(x,j), " + comp + "(j) ] ],[ (l2,x,noun,<e,t>) ],[l2=l1],["+slot+"]>"}; result.add(superEntry3); } } /* PREPOSITIONS */ else if (equalsOneOf(pos,preps)) { + slot = "SLOT_" + token + "/PROPERTY/"; String[] npAdjunct = {token, "(NP NP* (PP P:'" + token.toLowerCase() + "' DP[pobj]))", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + token + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>" + - " ;; <x,l1,<e,t>,[ l1:[ | empty(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>"}; + // "<x,l1,<e,t>,[ l1:[ | SLOT_" + token + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],["+slot+"]>" + + "<x,l1,<e,t>,[ l1:[ | empty(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>"}; String[] vpAdjunct = {token, "(VP VP* (PP P:'" + token.toLowerCase() + "' DP[pobj]))", - "<x,l1,t,[ l1:[ | SLOT_" + token + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>" + - " ;; <x,l1,t,[ l1:[ | empty(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>"}; + // "<x,l1,t,[ l1:[ | SLOT_" + token + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],["+slot+"]>" + + "<x,l1,t,[ l1:[ | empty(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[]>"}; result.add(npAdjunct); result.add(vpAdjunct); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2011-12-19 16:07:22
|
Revision: 3510 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3510&view=rev Author: christinaunger Date: 2011-12-19 16:07:11 +0000 (Mon, 19 Dec 2011) Log Message: ----------- [tbsl] corrections in BasicTemplate building Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Path.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2011-12-19 14:55:37 UTC (rev 3509) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2BasicSPARQL_Converter.java 2011-12-19 16:07:11 UTC (rev 3510) @@ -19,9 +19,11 @@ import org.dllearner.algorithm.tbsl.sparql.SPARQL_OrderBy; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Prefix; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; @@ -120,6 +122,14 @@ for (DRS_Condition cond : scope.getConditions()) { temp = convertCondition(cond,temp); } + // preserve marked referents from restrictor and scope + Set<DiscourseReferent> tokeep = restrictor.collectDRs(); + tokeep.addAll(scope.collectDRs()); + for (DiscourseReferent dr : tokeep) { + if (dr.isMarked()) { + temp.addSelTerm(new SPARQL_Term(dr.getValue())); + } + } // add the quantifier at last DiscourseReferent ref = complex.getReferent(); String sref = ref.getValue(); @@ -165,7 +175,7 @@ } else { Simple_DRS_Condition simple = (Simple_DRS_Condition) condition; - + String predicate = simple.getPredicate(); if (predicate.startsWith("SLOT")) { for (Slot s : slots) { @@ -287,6 +297,28 @@ SPARQL_PairType.EQ))); return temp; } + else if (predicate.equals("DATE")) { + temp.addFilter(new SPARQL_Filter( + new SPARQL_Pair( + new SPARQL_Term(simple.getArguments().get(0).getValue(),false), + new SPARQL_Term("'^"+simple.getArguments().get(1).getValue()+"'",true), + SPARQL_PairType.REGEX))); + } + else if (predicate.equals("regex")) { + temp.addFilter(new SPARQL_Filter( + new SPARQL_Pair( + new SPARQL_Term(simple.getArguments().get(0).getValue(),false), + new SPARQL_Term(simple.getArguments().get(1).getValue(),true), + SPARQL_PairType.REGEX))); + } + else if (predicate.equals("ISA")) { + temp.addConditions(new Path(simple.getArguments().get(0).getValue(),"isA",simple.getArguments().get(1).getValue())); + } +// else { +// if (simple.getArguments().size() == 1) { +// temp.addConditions(new Path(simple.getArguments().get(0).getValue(),"rdf:type",simple.getPredicate())); +// } +// } } return temp; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2011-12-19 14:55:37 UTC (rev 3509) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2011-12-19 16:07:11 UTC (rev 3510) @@ -63,6 +63,7 @@ * x/RBR adj/JJ > adj/JJR, x/RBS adj/JJ > adj/JJS, x/WRB adj/JJ > x/JJH * nn/RBR of/IN > nn/NPREP * usw. + * Note: Matching these patterns is order-dependent! * */ String condensedstring = taggedstring.replaceAll("``/``","").replaceAll("''/''","").replaceAll(" "," "); Matcher m; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Path.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Path.java 2011-12-19 14:55:37 UTC (rev 3509) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Path.java 2011-12-19 16:07:11 UTC (rev 3510) @@ -28,11 +28,14 @@ } public String toString() { + String v; + if (via.equals("isA")) v = via; else v = "?"+via; + if (via.isEmpty()) { return "?" + start + " -- " + "?" + target; } else { - return "?" + start + " -- ?" + via + " -- ?" + target; + return "?" + start + " -- " + v + " -- ?" + target; } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-19 14:55:37 UTC (rev 3509) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-19 16:07:11 UTC (rev 3510) @@ -59,19 +59,19 @@ /* DP */ String[] dpEntry1 = {token, "(DP (NP " + treetoken + "))", - "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; String[] dpEntry2 = {token, "(DP (NP " + treetoken + " DP[name]))", - "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x,p | SLOT_" + tokenfluent + "(p), ISA(x,p), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; result.add(dpEntry1); result.add(dpEntry2); /* NP */ String[] npEntry1 = {token, "(NP " + treetoken + ")", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; String[] npEntry2 = {token, "(NP " + treetoken + " DP[name])", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p), equal(x,y) ] ],[ (l2,y,name,<<e,t>,t>) ],[l2=l1],[" + slot + "]>"}; result.add(npEntry1); result.add(npEntry2); } @@ -89,13 +89,13 @@ else if (pos.equals("NPREP")) { String[] dpEntry1 = {token, "(DP (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ x | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; String[] dpEntry2 = {token, "(DP DET[det] (NP " + treetoken + " DP[pobj]))", - "<x,l1,<<e,t>,t>,[ l1:[ | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>),(l3,x,det,e)],[l2=l1,l3=l1],[" + slot + "]>"}; String[] npEntry = {token, "(NP " + treetoken + " DP[pobj])", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(p), p(x,y) ] ],[(l2,y,pobj,<<e,t>,t>)],[l2=l1],[" + slot + "]>"}; result.add(dpEntry1); result.add(dpEntry2); result.add(npEntry); @@ -116,10 +116,10 @@ result.add(npEntry); } else if(pos.equals("JJNN") && token.contains("_")) { - slot = "SLOT_" + tokenfluent + "/USNPEC/" + token; + slot = "SLOT_" + tokenfluent + "/UNSPEC/" + token; String[] npEntry = {token, "(NP " + treetoken + " )", - "<x,l1,<e,t>,[ l1:[ | SLOT_" + tokenfluent + "(x) ] ],[],[],[" + slot + "]>"}; + "<x,l1,<e,t>,[ l1:[ p | SLOT_" + tokenfluent + "(p), ISA(x,p) ] ],[],[],[" + slot + "]>"}; result.add(npEntry); } @@ -160,10 +160,14 @@ result.add(passEntry); } else if (pos.equals("VPASSIN")) { - String[] passEntry = {token, + String[] passEntry1 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,x) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; - result.add(passEntry); + String[] passEntry2 = {token, + "(S DP[dp] (VP V:'" + token + "' NUM[num]))", + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(y,z) ] ],[(l2,x,dp,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; + result.add(passEntry1); + result.add(passEntry2); } else if (pos.equals("GERUNDIN")) { String[] gerundinEntry1 = {token, @@ -178,15 +182,19 @@ result.add(gerundinEntry2); } else if (pos.equals("VPREP")) { - String[] passEntry = {token, + String[] passEntry1 = {token, "(S DP[subj] (VP V:'" + token + "' DP[obj]))", "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; + String[] passEntry2 = {token, + "(S DP[subj] (VP V:'" + token + "' NUM[num]))", + "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y), DATE(y,z) ] ],[(l2,x,subj,<<e,t>,t>),(l3,z,num,e)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>"}; String[] whEntry = {token, "(S DP[obj] (VP DP[subj] V:'" + token + "'))", "<x,l1,t,[ l1:[|], l4:[ p | SLOT_" + token + "(p), p(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[" + slot + "]>" + " ;; <x,l1,t,[ l1:[|], l4:[ | empty(x,y) ] ],[(l2,x,subj,<<e,t>,t>),(l3,y,obj,<<e,t>,t>)],[ l2<l1,l3<l1,l4<scope(l2),l4<scope(l3) ],[]>"}; - result.add(passEntry); + result.add(passEntry1); + result.add(passEntry2); result.add(whEntry); } else if (pos.equals("VBD") || pos.equals("VBZ") || pos.equals("VBP")) { @@ -239,13 +247,13 @@ if (pos.equals("JJ")) { String[] adjEntry = {token, "(NP ADJ:'" + token.toLowerCase() + "' NP*)", - "<x,l1,<e,t>,[ l1:[ j | SLOT_" + token + "(j) ] ],[],[],["+slot+"]>"}; + "<x,l1,<e,t>,[ l1:[ j | SLOT_" + token + "(p), p(x,j) ] ],[],[],["+slot+"]>"}; result.add(adjEntry); } if (pos.equals("JJH")) { String[] howEntry = {"how "+token, "(DP ADJ:'" + token.toLowerCase() + "')", - "<x,l1,<<e,t>,t>,[ l1:[ ?j,x | SLOT_" + token + "(j) ] ],[],[],["+slot+"]>"}; + "<x,l1,<<e,t>,t>,[ l1:[ ?j,x,p | SLOT_" + token + "(p), p(x,j) ] ],[],[],["+slot+"]>"}; result.add(howEntry); } /* COMPARATIVE */ 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 2011-12-19 14:55:37 UTC (rev 3509) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2011-12-19 16:07:11 UTC (rev 3510) @@ -29,6 +29,21 @@ if (s.equals(":q")) { System.exit(0); } + if (s.equals(":mode")) { + if (BASIC_MODE) System.out.println("Mode: BASIC"); + else System.out.println("Current mode is: LEIPZIG"); + continue; + } + if (s.equals(":mode BASIC")) { + BASIC_MODE = true; + System.out.println("Current mode is switched to BASIC."); + continue; + } + else if (s.equals(":mode LEIPZIG")) { + BASIC_MODE = false; + System.out.println("Current mode is switched to LEIPZIG."); + continue; + } if (BASIC_MODE) { for (BasicQueryTemplate temp : handler.buildBasicTemplates(s)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2011-12-19 14:55:46
|
Revision: 3509 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3509&view=rev Author: christinaunger Date: 2011-12-19 14:55:37 +0000 (Mon, 19 Dec 2011) Log Message: ----------- [tbsl] corrected small (but important) error in BasicSlotBuilder Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-19 14:20:34 UTC (rev 3508) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicSlotBuilder.java 2011-12-19 14:55:37 UTC (rev 3509) @@ -244,7 +244,7 @@ } if (pos.equals("JJH")) { String[] howEntry = {"how "+token, - "(DP WH:'how' ADJ:'" + token.toLowerCase() + "')", + "(DP ADJ:'" + token.toLowerCase() + "')", "<x,l1,<<e,t>,t>,[ l1:[ ?j,x | SLOT_" + token + "(j) ] ],[],[],["+slot+"]>"}; result.add(howEntry); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2011-12-19 14:20:40
|
Revision: 3508 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3508&view=rev Author: christinaunger Date: 2011-12-19 14:20:34 +0000 (Mon, 19 Dec 2011) Log Message: ----------- [tbsl] parts of the user input enclosed in double quotes is treated as named entity (jetzt aber wirklich!) Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2011-12-19 13:18:28 UTC (rev 3507) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2011-12-19 14:20:34 UTC (rev 3508) @@ -226,9 +226,21 @@ String flat = s; Matcher m; - Pattern nnpPattern = Pattern.compile("\\s?((\\w+)/NNP[S]?\\s(\\w+))/NNP[S]?(\\W|$)"); - Pattern nnPattern = Pattern.compile("\\s?((\\w+)/NN[S]?\\s(\\w+))/NN[S]?(\\W|$)"); - Pattern nnnnpPattern = Pattern.compile("\\s?((\\w+)/NNP[S]?)\\s(\\w+)/NN[S]?(\\W|$)"); + Pattern quotePattern1 = Pattern.compile("``/``(\\s)?(\\w+(/\\w+\\s)).*''/''"); + Pattern quotePattern2 = Pattern.compile("(``/``((.*)_)''/'')"); + Pattern nnpPattern = Pattern.compile("\\s?((\\w+)/NNP[S]?\\s(\\w+))/NNP[S]?(\\W|$)"); + Pattern nnPattern = Pattern.compile("\\s?((\\w+)/NN[S]?\\s(\\w+))/NN[S]?(\\W|$)"); + Pattern nnnnpPattern = Pattern.compile("\\s?((\\w+)/NNP[S]?)\\s(\\w+)/NN[S]?(\\W|$)"); + + m = quotePattern1.matcher(flat); + while (m.find()) { + flat = flat.replaceFirst(m.group(3),"_"); + m = quotePattern1.matcher(flat); + } + m = quotePattern2.matcher(flat); + while (m.find()) { + flat = flat.replaceFirst(m.group(2),m.group(3)+"/NNP"); + } m = nnpPattern.matcher(flat); while (m.find()) { 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 2011-12-19 13:18:28 UTC (rev 3507) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/BasicTemplator.java 2011-12-19 14:20:34 UTC (rev 3508) @@ -14,6 +14,7 @@ import org.dllearner.algorithm.tbsl.ltag.parser.Preprocessor; import org.dllearner.algorithm.tbsl.nlp.ApachePartOfSpeechTagger; import org.dllearner.algorithm.tbsl.nlp.PartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.StanfordPartOfSpeechTagger; import org.dllearner.algorithm.tbsl.sem.drs.DRS; import org.dllearner.algorithm.tbsl.sem.drs.UDRS; import org.dllearner.algorithm.tbsl.sem.dudes.data.Dude; @@ -31,6 +32,9 @@ Parser p; Preprocessor pp; + DUDE2UDRS_Converter d2u; + DRS2BasicSPARQL_Converter d2s; + boolean ONE_SCOPE_ONLY = true; public boolean UNTAGGED_INPUT = true; @@ -42,8 +46,8 @@ g = LTAG_Constructor.construct(grammarFiles); -// tagger = new StanfordPartOfSpeechTagger(); - tagger = new ApachePartOfSpeechTagger(); + tagger = new StanfordPartOfSpeechTagger(); +// tagger = new ApachePartOfSpeechTagger(); p = new Parser(); p.SHOW_GRAMMAR = true; @@ -52,6 +56,9 @@ p.MODE = "BASIC"; pp = new Preprocessor(false); + + d2u = new DUDE2UDRS_Converter(); + d2s = new DRS2BasicSPARQL_Converter(); } public void setUNTAGGED_INPUT(boolean b) { @@ -59,9 +66,7 @@ } public Set<BasicQueryTemplate> buildBasicQueries(String s) { - - DUDE2UDRS_Converter d2u = new DUDE2UDRS_Converter(); - DRS2BasicSPARQL_Converter d2s = new DRS2BasicSPARQL_Converter(); + boolean clearAgain = true; String tagged; 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 2011-12-19 13:18:28 UTC (rev 3507) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/TestFrontend.java 2011-12-19 14:20:34 UTC (rev 3508) @@ -12,7 +12,7 @@ public class TestFrontend { static String[] GRAMMAR_FILES = {"src/main/resources/lexicon/english.lex"}; - static boolean BASIC_MODE = false; // true for BASIC mode, false for LEIPZIG mode + static boolean BASIC_MODE = true; // true for BASIC mode, false for LEIPZIG mode public static void main(String[] args) { @@ -32,7 +32,13 @@ if (BASIC_MODE) { for (BasicQueryTemplate temp : handler.buildBasicTemplates(s)) { - System.out.println(temp.toString()); + try { + System.out.println(temp.toString()); + } + catch (NullPointerException e) { + System.err.println("NullPointer in BasicQueryTemplate!"); + continue; + } } } else { for (Template temp : handler.buildTemplates(s)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |