From: <ki...@us...> - 2013-11-27 14:41:08
|
Revision: 4176 http://sourceforge.net/p/dl-learner/code/4176 Author: kirdie Date: 2013-11-27 14:41:05 +0000 (Wed, 27 Nov 2013) Log Message: ----------- changed index from interface to abstract class, thus removing much redundant code. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-11-25 14:20:13 UTC (rev 4175) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-11-27 14:41:05 UTC (rev 4176) @@ -331,8 +331,8 @@ return dataPropertyPopularityMap.get(dp); } else { String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}"; - - ResultSet rs = executeSelectQuery(String.format(queryTemplate, dp.getName())); +String query = String.format(queryTemplate, dp.getName()); + ResultSet rs = executeSelectQuery(query); int cnt = rs.next().getLiteral("cnt").getInt(); dataPropertyPopularityMap.put(dp, cnt); return cnt; Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java 2013-11-25 14:20:13 UTC (rev 4175) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java 2013-11-27 14:41:05 UTC (rev 4176) @@ -3,11 +3,9 @@ import java.util.ArrayList; import java.util.List; -public class HierarchicalIndex implements Index{ +public class HierarchicalIndex extends Index +{ - private static final int DEFAULT_LIMIT = 10; - private static final int DEFAULT_OFFSET = 0; - private Index primaryIndex; private Index secondaryIndex; @@ -23,18 +21,8 @@ public Index getSecondaryIndex() { return secondaryIndex; } - - @Override - public List<String> getResources(String queryString) { - return getResources(queryString, DEFAULT_LIMIT); - } @Override - public List<String> getResources(String queryString, int limit) { - return getResources(queryString, limit, DEFAULT_OFFSET); - } - - @Override public List<String> getResources(String queryString, int limit, int offset) { List<String> resources = new ArrayList<String>(); resources = primaryIndex.getResources(queryString, limit, offset); @@ -50,11 +38,6 @@ } @Override - public IndexResultSet getResourcesWithScores(String queryString, int limit) { - return getResourcesWithScores(queryString, limit, DEFAULT_OFFSET); - } - - @Override public IndexResultSet getResourcesWithScores(String queryString, int limit, int offset) { IndexResultSet rs = primaryIndex.getResourcesWithScores(queryString, limit, offset); if(rs.getItems().size() < limit){ @@ -63,4 +46,4 @@ return rs; } -} +} \ No newline at end of file Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2013-11-25 14:20:13 UTC (rev 4175) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2013-11-27 14:41:05 UTC (rev 4176) @@ -1,13 +1,16 @@ package org.dllearner.common.index; import java.util.List; -import java.util.Map; -public interface Index { - List<String> getResources(String queryString); - List<String> getResources(String queryString, int limit); - List<String> getResources(String queryString, int limit, int offset); - IndexResultSet getResourcesWithScores(String queryString); - IndexResultSet getResourcesWithScores(String queryString, int limit); - IndexResultSet getResourcesWithScores(String queryString, int limit, int offset); -} +public abstract class Index +{ + static final int DEFAULT_LIMIT = 10; + + public List<String> getResources(String queryString) {return getResources(queryString,DEFAULT_LIMIT);} + public List<String> getResources(String queryString, int limit) {return getResources(queryString,DEFAULT_LIMIT,0);} + abstract public List<String> getResources(String queryString, int limit, int offset); + + public IndexResultSet getResourcesWithScores(String queryString) {return getResourcesWithScores(queryString,DEFAULT_LIMIT);} + public IndexResultSet getResourcesWithScores(String queryString, int limit) {return getResourcesWithScores(queryString,DEFAULT_LIMIT,0);} + abstract public IndexResultSet getResourcesWithScores(String queryString, int limit, int offset); +} \ No newline at end of file Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-11-25 14:20:13 UTC (rev 4175) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-11-27 14:41:05 UTC (rev 4176) @@ -13,13 +13,10 @@ import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.params.ModifiableSolrParams; -public class SOLRIndex implements Index{ +public class SOLRIndex extends Index{ private HttpSolrServer server; - private static final int DEFAULT_LIMIT = 10; - private static final int DEFAULT_OFFSET = 0; - private String primarySearchField; private String secondarySearchField; @@ -52,16 +49,6 @@ } @Override - public List<String> getResources(String queryString) { - return getResources(queryString, DEFAULT_LIMIT); - } - - @Override - public List<String> getResources(String queryString, int limit) { - return getResources(queryString, limit, DEFAULT_OFFSET); - } - - @Override public List<String> getResources(String queryString, int limit, int offset) { List<String> resources = new ArrayList<String>(); QueryResponse response; @@ -82,16 +69,6 @@ } @Override - public IndexResultSet getResourcesWithScores(String queryString) { - return getResourcesWithScores(queryString, DEFAULT_LIMIT); - } - - @Override - public IndexResultSet getResourcesWithScores(String queryString, int limit) { - return getResourcesWithScores(queryString, limit, DEFAULT_OFFSET); - } - - @Override public IndexResultSet getResourcesWithScores(String queryString, int limit, int offset) { IndexResultSet rs = new IndexResultSet(); @@ -148,4 +125,4 @@ this.sortField = sortField; } -} +} \ No newline at end of file Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2013-11-25 14:20:13 UTC (rev 4175) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2013-11-27 14:41:05 UTC (rev 4176) @@ -16,11 +16,8 @@ import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -public class SPARQLIndex implements Index{ +public class SPARQLIndex extends Index{ - private static final int DEFAULT_LIMIT = 10; - private static final int DEFAULT_OFFSET = 0; - private SparqlEndpoint endpoint; private ExtractionDBCache cache; @@ -65,16 +62,6 @@ } @Override - public List<String> getResources(String searchTerm) { - return getResources(searchTerm, DEFAULT_LIMIT); - } - - @Override - public List<String> getResources(String searchTerm, int limit) { - return getResources(searchTerm, limit, DEFAULT_OFFSET); - } - - @Override public List<String> getResources(String searchTerm, int limit, int offset) { List<String> resources = new ArrayList<String>(); @@ -92,18 +79,8 @@ } return resources; } - - @Override - public IndexResultSet getResourcesWithScores(String searchTerm) { - return getResourcesWithScores(searchTerm, DEFAULT_LIMIT); - } @Override - public IndexResultSet getResourcesWithScores(String searchTerm, int limit) { - return getResourcesWithScores(searchTerm, limit, DEFAULT_OFFSET); - } - - @Override public IndexResultSet getResourcesWithScores(String searchTerm, int limit, int offset) { IndexResultSet irs = new IndexResultSet(); @@ -151,4 +128,4 @@ return model; } -} +} \ 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: <lor...@us...> - 2014-01-29 14:25:23
|
Revision: 4215 http://sourceforge.net/p/dl-learner/code/4215 Author: lorenz_b Date: 2014-01-29 14:25:19 +0000 (Wed, 29 Jan 2014) Log Message: ----------- Some modifications due to refactoring of neg. examples finder. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java trunk/test/isle/swore/ontology_with_comments.owl Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -205,7 +205,7 @@ cli.setContext(context); cli.setConfFile(file); cli.run(); - } catch (Exception e) { + } catch (Exception e) {e.printStackTrace(); String stacktraceFileName = "log/error.log"; // e.printStackTrace(); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -879,7 +879,7 @@ } private void filter(Model model) { - // filter out triples with String literals, as there often occur + // filter out triples with String literals, as therein often occur // some syntax errors and they are not relevant for learning List<Statement> statementsToRemove = new ArrayList<Statement>(); List<Statement> statementsToAdd = new ArrayList<Statement>(); Modified: trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/interfaces/src/main/java/org/dllearner/server/EnrichmentServlet.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -436,12 +436,10 @@ long startTime = System.currentTimeMillis(); System.out.print("finding negatives ... "); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); long runTime = System.currentTimeMillis() - startTime; - System.out.println("done (" + negExStr.size()+ " examples fround in " + runTime + " ms)"); + System.out.println("done (" + negExamples.size()+ " examples fround in " + runTime + " ms)"); SparqlKnowledgeSource ks2; AbstractReasonerComponent rc; Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -639,18 +639,14 @@ // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); - SortedSet<String> posExStr = Helper.getStringSet(posExamples); // get negative examples via various strategies System.out.print("finding negatives ... "); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + System.out.println("done (" + negExamples.size()+ ")"); - System.out.println("done (" + negExStr.size()+ ")"); - ComponentManager cm = ComponentManager.getInstance(); SparqlKnowledgeSource ks2 = cm.knowledgeSource(SparqlKnowledgeSource.class); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java 2014-01-29 14:25:19 UTC (rev 4215) @@ -645,20 +645,16 @@ private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, NamedClass nc, boolean equivalence) throws ComponentInitException { // get instances of class as positive examples - SPARQLReasoner sr = new SPARQLReasoner(ks); - SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); - SortedSet<String> posExStr = Helper.getStringSet(posExamples); + SPARQLReasoner sr = new SPARQLReasoner(ks); + SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + + // get negative examples via various strategies + System.out.print("finding negatives ... "); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); + SortedSet<Individual> negExamples = finder.getNegativeExamples(nc, posExamples, 20); + SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + System.out.println("done (" + negExamples.size()+ ")"); - // get negative examples via various strategies - System.out.print("finding negatives ... "); - AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); - SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); - SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); - - System.out.println("done (" + negExStr.size()+ ")"); - ComponentManager cm = ComponentManager.getInstance(); SparqlKnowledgeSource ks2 = cm.knowledgeSource(SparqlKnowledgeSource.class); Modified: trunk/test/isle/swore/ontology_with_comments.owl =================================================================== --- trunk/test/isle/swore/ontology_with_comments.owl 2014-01-29 14:24:16 UTC (rev 4214) +++ trunk/test/isle/swore/ontology_with_comments.owl 2014-01-29 14:25:19 UTC (rev 4215) @@ -430,11 +430,20 @@ <!-- http://purl.org/dc/elements/1.1/description --> - <owl:ObjectProperty rdf:about="&dc;description"> + <owl:DatatypeProperty rdf:about="&dc;description"> + <rdf:type rdf:resource="&owl;FunctionalProperty"/> <rdfs:label rdf:datatype="&xsd;string">description</rdfs:label> <rdfs:label xml:lang="de">Beschreibung</rdfs:label> <rdfs:range rdf:resource="&xsd;string"/> - </owl:ObjectProperty> + <rdfs:domain> + <owl:Class> + <owl:unionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&req;Goal"/> + <rdf:Description rdf:about="&req;Requirement"/> + </owl:unionOf> + </owl:Class> + </rdfs:domain> + </owl:DatatypeProperty> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <far...@us...> - 2014-02-17 23:35:27
|
Revision: 4230 http://sourceforge.net/p/dl-learner/code/4230 Author: farshadbadie Date: 2014-02-17 23:35:23 +0000 (Mon, 17 Feb 2014) Log Message: ----------- FuzzyCELOE extension test Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/pom.xml Added Paths: ----------- trunk/test/fuzzydll/FuzzyDL.jar trunk/test/fuzzydll/fuzzy_trains.conf trunk/test/fuzzydll/gurobi-5.0.1.jar Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2014-02-17 23:35:23 UTC (rev 4230) @@ -26,6 +26,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -448,6 +449,8 @@ // chose best node according to heuristics nextNode = getNextNodeToExpand(); + if(nextNode == null) + break; int horizExp = nextNode.getHorizontalExpansion(); // apply operator @@ -561,7 +564,15 @@ // 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 nodes.last(); + // *** patch start *** + FuzzyOENode last; + try { + last = nodes.last(); + } catch (NoSuchElementException e) { + return null; + } + return last; + // *** patch end *** } // expand node horizontically Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/interfaces/pom.xml 2014-02-17 23:35:23 UTC (rev 4230) @@ -606,6 +606,10 @@ <version>2.8.0</version> </dependency> + <dependency> + <groupId>gurobi</groupId> + <artifactId>gurobi</artifactId> + </dependency> </dependencies> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2014-02-17 23:35:23 UTC (rev 4230) @@ -215,7 +215,7 @@ // Get the Root Error Message logger.error("An Error Has Occurred During Processing."); - logger.error(primaryCause.getMessage()); +// logger.error(primaryCause.getMessage()); logger.debug("Stack Trace: ", e); logger.error("Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); FileOutputStream fos = new FileOutputStream(stacktraceFileName); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/pom.xml 2014-02-17 23:35:23 UTC (rev 4230) @@ -508,8 +508,13 @@ <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> - - </dependencies> + + <dependency> + <groupId>gurobi</groupId> + <artifactId>gurobi</artifactId> + <version>5.0.1</version> + </dependency> + </dependencies> </dependencyManagement> <repositories> Added: trunk/test/fuzzydll/FuzzyDL.jar =================================================================== (Binary files differ) Index: trunk/test/fuzzydll/FuzzyDL.jar =================================================================== --- trunk/test/fuzzydll/FuzzyDL.jar 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/test/fuzzydll/FuzzyDL.jar 2014-02-17 23:35:23 UTC (rev 4230) Property changes on: trunk/test/fuzzydll/FuzzyDL.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Added: trunk/test/fuzzydll/fuzzy_trains.conf =================================================================== --- trunk/test/fuzzydll/fuzzy_trains.conf (rev 0) +++ trunk/test/fuzzydll/fuzzy_trains.conf 2014-02-17 23:35:23 UTC (rev 4230) @@ -0,0 +1,22 @@ + +// declare some prefixes to use as abbreviations +prefixes = [ ("ex","http://www.example.com/fuzzyTrains.owl#") ] + +// knowledge source definition +ks.type = "OWL File" +ks.fileName = "fuzzyTrains_v5.0.owl" + +// reasoner +reasoner.type = "Fuzzy OWL API Reasoner" +reasoner.sources = { ks } + +// learning problem +problem.type = "fuzzyPosNeg" +problem.positiveExamples = { } +problem.negativeExamples = { } +problem.fuzzyEx = [("ex:east1",0.7),("ex:east2",0.5),("ex:west8",0.3),("ex:west9",0.1)] +problem.reasoner = reasoner + +// algorithm +algorithm.type = "Fuzzy CELOE" +algorithm.reasoner = reasoner \ No newline at end of file Added: trunk/test/fuzzydll/gurobi-5.0.1.jar =================================================================== (Binary files differ) Index: trunk/test/fuzzydll/gurobi-5.0.1.jar =================================================================== --- trunk/test/fuzzydll/gurobi-5.0.1.jar 2014-02-17 15:51:37 UTC (rev 4229) +++ trunk/test/fuzzydll/gurobi-5.0.1.jar 2014-02-17 23:35:23 UTC (rev 4230) Property changes on: trunk/test/fuzzydll/gurobi-5.0.1.jar ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2014-02-25 12:01:18
|
Revision: 4241 http://sourceforge.net/p/dl-learner/code/4241 Author: jenslehmann Date: 2014-02-25 12:01:14 +0000 (Tue, 25 Feb 2014) Log Message: ----------- some fixes; added accuracy method for class learning problem Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java trunk/examples/family/father_oe.conf Added Paths: ----------- trunk/test/thanh/ Removed Paths: ------------- trunk/examples/thanh/ 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 2014-02-25 11:30:53 UTC (rev 4240) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-02-25 12:01:14 UTC (rev 4241) @@ -593,7 +593,7 @@ // System.out.println("refining: " + node); int horizExp = node.getHorizontalExpansion(); TreeSet<Description> refinements = (TreeSet<Description>) operator.refine(node.getDescription(), horizExp+1); - System.out.println(refinements); +// System.out.println(refinements); node.incHorizontalExpansion(); node.setRefinementCount(refinements.size()); nodes.add(node); Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2014-02-25 11:30:53 UTC (rev 4240) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2014-02-25 12:01:14 UTC (rev 4241) @@ -924,4 +924,12 @@ public void setCheckConsistency(boolean checkConsistency) { this.checkConsistency = checkConsistency; } + + public String getAccuracyMethod() { + return accuracyMethod; + } + + public void setAccuracyMethod(String accuracyMethod) { + this.accuracyMethod = accuracyMethod; + } } Modified: trunk/examples/family/father_oe.conf =================================================================== --- trunk/examples/family/father_oe.conf 2014-02-25 11:30:53 UTC (rev 4240) +++ trunk/examples/family/father_oe.conf 2014-02-25 12:01:14 UTC (rev 4241) @@ -12,6 +12,7 @@ // learning problem lp.type = "clp" lp.classToDescribe = "ex:father" +lp.accuracyMethod = "fmeasure" // create learning algorithm to run alg.type = "celoe" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2014-02-25 12:08:26
|
Revision: 4242 http://sourceforge.net/p/dl-learner/code/4242 Author: kirdie Date: 2014-02-25 12:08:21 +0000 (Tue, 25 Feb 2014) Log Message: ----------- added quoting in index and others stuff i forgot. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-ext/pom.xml trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-core/pom.xml 2014-02-25 12:08:21 UTC (rev 4242) @@ -20,6 +20,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.3</version> <configuration> <!-- Uncomment this when the junits are independent of a runtime directory --> <!--<includes> --> @@ -58,7 +59,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> - <version>2.8</version> + <version>2.9</version> <configuration> <show>public</show> <nohelp>true</nohelp> Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -563,12 +563,10 @@ if(values == null){ try { values = (T) value.getClass().newInstance(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); + values.add(value); } - values.add(value); + catch (InstantiationException e) {e.printStackTrace();return;} + catch (IllegalAccessException e) {e.printStackTrace();return;} } values.add(value); } Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/pom.xml 2014-02-25 12:08:21 UTC (rev 4242) @@ -133,6 +133,36 @@ </dependencies> <build> <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9</version> + <configuration> + <show>public</show> + <nohelp>true</nohelp> + <destDir>doc/javadoc</destDir> + <doctitle>DL-Learner Javadoc</doctitle> + <author>true</author> + <nodeprecated>false</nodeprecated> + <nodeprecatedlist>false</nodeprecatedlist> + <noindex>false</noindex> + <nonavbar>false</nonavbar> + <notree>false</notree> + <overview>src/etc/overview.html</overview> + <source>1.6</source> + <sourcepath>src/main/java</sourcepath> + <splitindex>true</splitindex> + <stylesheetfile>src/etc/javadoc.css</stylesheetfile> + <use>true</use> + <version>true</version> + <linksource>true</linksource> + <bottom><img style='float:right' src='http://sflogo.sourceforge.net/sflogo.php?group_id=203619&type=1' width='88' height='31' border='0' alt='SourceForge.net Logo' /> DL-Learner is licenced under the terms of the GNU General Public License.<br />Copyright &#169; 2007-2011 Jens Lehmann</bottom> + <encoding>ISO-8859-1</encoding> + <windowtitle>DL-Learner Javadoc</windowtitle> + </configuration> + </plugin> + <!-- <plugin> <groupId>org.codehaus.mojo</groupId> @@ -151,6 +181,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> + <version>2.4.3</version> <configuration> <excludes> <exclude>org/dllearner/algorithm/tbsl/*</exclude> @@ -161,7 +192,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> - <version>1.2</version> + <version>1.2.1</version> <executions> <execution> Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/Index.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -5,9 +5,11 @@ public abstract class Index { static final int DEFAULT_LIMIT = 10; - + + String enquote(String s) {if(!s.startsWith("(")) s='('+s+')'; return s;} + public List<String> getResources(String queryString) {return getResources(queryString,DEFAULT_LIMIT);} - public List<String> getResources(String queryString, int limit) {return getResources(queryString,DEFAULT_LIMIT,0);} + public List<String> getResources(String queryString, int limit) {return getResources(enquote(queryString),DEFAULT_LIMIT,0);} abstract public List<String> getResources(String queryString, int limit, int offset); public IndexResultSet getResourcesWithScores(String queryString) {return getResourcesWithScores(queryString,DEFAULT_LIMIT);} Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java 2014-02-25 12:01:14 UTC (rev 4241) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/MappingBasedIndex.java 2014-02-25 12:08:21 UTC (rev 4242) @@ -5,6 +5,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -12,101 +14,43 @@ import java.util.Map.Entry; public class MappingBasedIndex { - - private Map<String, List<String>> classUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> resourceUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> datatypePropertyUri2TokensMap = new HashMap<String, List<String>>(); - private Map<String, List<String>> objectPropertyUri2TokensMap = new HashMap<String, List<String>>(); - - public MappingBasedIndex(String classMappingsFile, String resourceMappingsFile, - String dataPropertyMappingsFile, String objectPropertyMappingsFile) { - BufferedReader br = null; - String line = null; - try { - //load class mappings - if(classMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(classMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - classUri2TokensMap.put(uri, tokens); - } + + private final Map<String, List<String>> classUri2TokensMap; + private final Map<String, List<String>> resourceUri2TokensMap; + private final Map<String, List<String>> datatypePropertyUri2TokensMap; + private final Map<String, List<String>> objectPropertyUri2TokensMap; + + Map<String,List<String>> uriToTokens(InputStream mapping) throws IOException + { + Map<String, List<String>> uriToTokens = new HashMap<>(); + try(BufferedReader in = new BufferedReader(new InputStreamReader(mapping))) + { + String line = null; + while((line = in.readLine()) != null) + { + int split = line.indexOf("|"); + //get the URI + String uri = line.substring(0, split); + //get the list of tokens + List<String> tokens = new ArrayList<String>(); + String tokenString = line.substring(split + 1); + String[] tokenArray = tokenString.split(","); + for(String token : tokenArray){tokens.add(token.trim());} + uriToTokens.put(uri, tokens); } - - //load resource mappings - if(resourceMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(resourceMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - resourceUri2TokensMap.put(uri, tokens); - } - } - - //load object property mappings - if(objectPropertyMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(objectPropertyMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - objectPropertyUri2TokensMap.put(uri, tokens); - } - } - - //load datatype property mappings - if(dataPropertyMappingsFile != null){ - br = new BufferedReader(new FileReader(new File(dataPropertyMappingsFile))); - while((line = br.readLine()) != null){ - int split = line.indexOf("|"); - //get the URI - String uri = line.substring(0, split); - //get the list of tokens - List<String> tokens = new ArrayList<String>(); - String tokenString = line.substring(split + 1); - String[] tokenArray = tokenString.split(","); - for(String token : tokenArray){ - tokens.add(token.trim()); - } - - datatypePropertyUri2TokensMap.put(uri, tokens); - } - } - - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + return uriToTokens; + } } - + + public MappingBasedIndex(InputStream classMappingsFile, InputStream resourceMappingsFile, + InputStream dataPropertyMappingsFile, InputStream objectPropertyMappingsFile) throws IOException + { + classUri2TokensMap=uriToTokens(classMappingsFile); + resourceUri2TokensMap=uriToTokens(resourceMappingsFile); + datatypePropertyUri2TokensMap=uriToTokens(dataPropertyMappingsFile); + objectPropertyUri2TokensMap=uriToTokens(objectPropertyMappingsFile); + } + public List<String> getClasses(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : classUri2TokensMap.entrySet()){ @@ -116,8 +60,8 @@ } return uris; } - - public List<String> getResources(String token){ + + public List<String> getResourceAsStreams(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : resourceUri2TokensMap.entrySet()){ if(entry.getValue().contains(token)){ @@ -126,7 +70,7 @@ } return uris; } - + public List<String> getObjectProperties(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : objectPropertyUri2TokensMap.entrySet()){ @@ -136,7 +80,7 @@ } return uris; } - + public List<String> getDatatypeProperties(String token){ List<String> uris = new ArrayList<String>(); for(Entry<String, List<String>> entry : datatypePropertyUri2TokensMap.entrySet()){ @@ -146,14 +90,14 @@ } return uris; } - + public List<String> getProperties(String token){ List<String> uris = new ArrayList<String>(); uris.addAll(getObjectProperties(token)); uris.addAll(getDatatypeProperties(token)); return uris; } - + public IndexResultSet getClassesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getClasses(token)){ @@ -161,15 +105,15 @@ } return rs; } - - public IndexResultSet getResourcesWithScores(String token){ + + public IndexResultSet getResourceAsStreamsWithScores(String token){ IndexResultSet rs = new IndexResultSet(); - for(String uri : getResources(token)){ + for(String uri : getResourceAsStreams(token)){ rs.addItem(new IndexResultItem(uri, token, 1f)); } return rs; } - + public IndexResultSet getObjectPropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getObjectProperties(token)){ @@ -177,7 +121,7 @@ } return rs; } - + public IndexResultSet getDatatypePropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getDatatypeProperties(token)){ @@ -185,7 +129,7 @@ } return rs; } - + public IndexResultSet getPropertiesWithScores(String token){ IndexResultSet rs = new IndexResultSet(); for(String uri : getProperties(token)){ @@ -193,7 +137,7 @@ } return rs; } - + public Boolean isDataProperty(String uri){ if(datatypePropertyUri2TokensMap.containsKey(uri)) { return true; @@ -202,9 +146,9 @@ } return null; } - - public static void main(String[] args) { - MappingBasedIndex index = new MappingBasedIndex(MappingBasedIndex.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), null, null, null); + + public static void main(String[] args) throws IOException { + MappingBasedIndex index = new MappingBasedIndex(MappingBasedIndex.class.getClassLoader().getResourceAsStream("tbsl/oxford_class_mappings.txt"),null, null, null); System.out.println(index.getClasses("flat")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <far...@us...> - 2014-03-21 19:21:56
|
Revision: 4250 http://sourceforge.net/p/dl-learner/code/4250 Author: farshadbadie Date: 2014-03-21 19:21:47 +0000 (Fri, 21 Mar 2014) Log Message: ----------- All FuzzyDL issues fixed. Modified Paths: -------------- trunk/test/fuzzydll/fuzzy_trains.conf Added Paths: ----------- trunk/README-FuzzyDL trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl.owl trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl.pprj trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl.repository trunk/test/fuzzydll/EvKnowledge/EvKnowledge.pprj trunk/test/fuzzydll/EvKnowledge/People.owl trunk/test/fuzzydll/EvKnowledge/People.pprj trunk/test/fuzzydll/EvKnowledge/catalog-v001.xml trunk/test/fuzzydll/EvKnowledge/gurobi.txt trunk/test/fuzzydll/fuzzyOWL2fuzzyDLparserOutput.fuzzyDL.txt Added: trunk/README-FuzzyDL =================================================================== --- trunk/README-FuzzyDL (rev 0) +++ trunk/README-FuzzyDL 2014-03-21 19:21:47 UTC (rev 4250) @@ -0,0 +1,67 @@ +Instructions: +============= + +Instruction of first installation of Fuzzy DL + + 1. Download from http://gaia.isti.cnr.it/~straccia/software/fuzzyDL/fuzzyDL.html + + 2. Unzip the folder + + 3. the "FuzzyDL" folder is the main folder + + 4. Locating the SolverLinux dynamic libraries at |/usr/lib|, |lib| or |/usr/local/lib| directories, + 4.1. But you can add the path of the binary file to the library path by modifying the variable |LD_LIBRARY_PATH|. + For instance, if the libraries are in the same directory as the binary file, you can write in a terminal: export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH + + 5. Must be ready for the execution as follow + 5.a. java -jar FuzzyDL.jar filename + 5.b. To read in the file. Some parameters are taken from the CONFIG file + 5.c. To select the semantics, change the 'solver' parameter in the CONFIG file z (for Zadeh) / l (for Luaksiewicz)/ c (for Classical) + + 6. Alternatively, leave the dynamic libraries in solverLinux and define: + export LD_LIBRARY_PATH=$HOME/Linux/FuzzyDL/solverLinux + +---------------------------------------------------------------------------- + +Instruction of first installation of Gurobi Optimizer + +1. To Register and download from +http://pages.gurobi.com/DownloadRegistration.html?/download/gurobi-optimizer + +Note: Maybe it only works with an older release like 5.0.2. Still needs to be verified. + +2. Choose a destination directory. Actually, /opt is used for installation. + +3. To copy the Gurobi distribution to that directory and extract the contents. + Extraction will create a sub-directory gurobi560/linux64 . Also, The <installdir> would be /opt/gurobi560/linux64. + +4. In order to allow executable files to be found when needed, you have to modify a few environment variables: + • GUROBI_HOME should point to the <installdir>. + • PATH should be extended to include <installdir>/bin. + • LD_LIBRARY_PATH should be extended to include <installdir>/lib. + +5. In the case of using bash shell, need to add the following lines to the .bashrc files as follow: + • export GUROBI_HOME="/opt/gurobi560/linux64" + • export PATH="${PATH}:${GUROBI_HOME}/bin" + • export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib" + +6. If LD_LIBRARY_PATH is not already set, you would use the following instead: + export LD_LIBRARY_PATH="${GUROBI_HOME}/lib" (for Eclipse projects, this path has to be added to the environment variables). + +7. Ready to proceed to Obtain and Install the Gurobi License. +7.1. see the Licenses page: http://www.gurobi.com/de/download/licenses/current + +7.2. Free Academic tab -> Accept Agreement -> Request License -> clicking on the License ID +7.3. Run the grbgetkey command like: grbgetkey 253e22f3-... + +7.4. In order to save the license key, recommended to accept the default location (hitting Enter) + +8. When you run the Gurobi Optimizer, it will look for the gurobi.lic key file in /opt/gurobi and /opt/gurobi560. + +9. If you choose to put the license key file in a non-default location, you should add a line like the following to you .bashrc file + (For setting the environment variable) + + export GRB_LICENSE_FILE=/usr/home/jones/gurobi.lic + + + Added: trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl =================================================================== --- trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl (rev 0) +++ trunk/test/fuzzydll/EvKnowledge/EvKnowledge.owl 2014-03-21 19:21:47 UTC (rev 4250) @@ -0,0 +1,4239 @@ +<?xml version="1.0"?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:ace_lexicon="http://attempto.ifi.uzh.ch/ace_lexicon#" + xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#" + xmlns:foaf="http://xmlns.com/foaf/0.1/" + xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns="http://example.com/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:swrl="http://www.w3.org/2003/11/swrl#" + xmlns:swrlb="http://www.w3.org/2003/11/swrlb#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xml:base="http://example.com/"> + <owl:Ontology rdf:about="http://www.example.com/EvKnowledge.owl"/> + <rdfs:Datatype rdf:about="http://xmlns.com/foaf/0.1/"/> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Rectangle"> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Load"/> + </rdfs:subClassOf> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Rectangle</ace_lexicon:CN_sg> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Rectangles</ace_lexicon:CN_pl> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#UnsuccessfulUser"> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#User"/> + </rdfs:subClassOf> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >UnsuccessfulUsers</ace_lexicon:CN_pl> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >UnsuccessfulUser</ace_lexicon:CN_sg> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#SuccessfulUser"> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >SuccessfulUser</ace_lexicon:CN_sg> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >SuccessfulUsers</ace_lexicon:CN_pl> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#User"/> + </rdfs:subClassOf> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#RShoulder"> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >RShoulder</ace_lexicon:CN_sg> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >RShoulders</ace_lexicon:CN_pl> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Load"/> + </rdfs:subClassOf> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Triangle"> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Triangles</ace_lexicon:CN_pl> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Triangle</ace_lexicon:CN_sg> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Load"/> + </rdfs:subClassOf> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#MediumSuccessfulUser"> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#User"/> + </rdfs:subClassOf> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >MediumSuccessfulUsers</ace_lexicon:CN_pl> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >MediumSuccessfulUser</ace_lexicon:CN_sg> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#LShoulder"> + <rdfs:subClassOf> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Load"/> + </rdfs:subClassOf> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >LShoulder</ace_lexicon:CN_sg> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >LShoulders</ace_lexicon:CN_pl> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Load"> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Loads</ace_lexicon:CN_pl> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Load</ace_lexicon:CN_sg> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#User"> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >User</ace_lexicon:CN_sg> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Users</ace_lexicon:CN_pl> + </owl:Class> + <owl:Class rdf:about="http://www.example.com/EvKnowledge.owl#Train"> + <ace_lexicon:CN_pl rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Trains</ace_lexicon:CN_pl> + <ace_lexicon:CN_sg rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >Train</ace_lexicon:CN_sg> + </owl:Class> + <owl:ObjectProperty rdf:about="http://example.com/objectProperty_1"/> + <rdf:Description rdf:about="http://example.org/Ev#Success82"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER83</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.62</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.315</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success237"> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.83</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.4</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.36</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.66</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER238</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.56</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success119"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.46</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.61</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.81</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER120</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.325</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success145"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.76</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.46</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER146</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.2</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.95</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.65</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success96"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.77</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.295</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER97</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.19</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.73</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success256"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.75</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.61</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER257</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.5</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.81</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success32"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.256</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.76</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER33</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.16</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.7</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success105"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER106</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.56</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.67</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success247"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER248</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success76"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER77</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.265</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.75</ExamPerformanceAll> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.57</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success12"> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.34</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</StudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</ExamPerformanceAll> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.52</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER13</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success131"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER132</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.4</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.67</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</DegreeRepitition> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success227"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER228</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.348</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success187"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.61</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.57</ExamPerformanceGoal> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.69</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.44</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER188</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success255"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.71</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.77</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.82</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.54</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER256</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success197"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.72</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.2</DegreeRepitition> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.07</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.73</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER198</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success42"> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.14</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.49</DegreeRepitition> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.55</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER43</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success146"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.24</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER147</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.243</DegreeRepitition> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.35</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.365</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.19</DegreeStudyTime> + </rdf:Description> + <owl:AnnotationProperty rdf:about="http://example.com/DegreeRepitition"/> + <rdf:Description rdf:about="http://example.org/Ev#Success217"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.87</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER218</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success62"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.79</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER63</foaf:name> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.51</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.15</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success22"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER23</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.65</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.27</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success236"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER237</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.55</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.523</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.41</DegreeRepitition> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.22</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success81"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.295</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.12</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER82</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.67</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success144"> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.48</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER145</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.42</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.87</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.21</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.56</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <owl:AnnotationProperty rdf:about="http://example.com/StudyTime"/> + <rdf:Description rdf:about="http://example.org/Ev#Success95"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.86</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.255</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.15</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER96</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.305</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.62</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success257"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.66</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.76</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER258</foaf:name> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.87</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.9</DegreeRepitition> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.74</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success246"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.62</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.39</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.66</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER247</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.67</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success106"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.59</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.28</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER107</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success11"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.51</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.41</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER12</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success75"> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.5</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER76</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.4</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.255</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success130"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.02</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER131</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.05</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.34</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.39</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success159"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER160</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.54</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.79</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.475</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success226"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.475</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.23</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.59</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER227</foaf:name> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.13</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.71</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success31"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER32</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.295</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.75</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.24</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.15</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.65</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success186"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.01</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.82</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.495</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER187</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.67</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.93</ExamPerformanceGoal> + </rdf:Description> + <owl:AnnotationProperty rdf:about="http://example.com/DegreeStudyTime"/> + <rdf:Description rdf:about="http://example.org/Ev#Success41"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.2</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.49</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER42</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.2</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success196"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</ExamPerformanceGoal> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.19</DegreeRepitition> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.19</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.68</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER197</foaf:name> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.48</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success21"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.37</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER22</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.66</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.12</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success61"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.77</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER62</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.56</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.72</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.19</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success216"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.52</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.5</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER217</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.288</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success171"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.62</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.38</DegreeRepitition> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.49</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER172</foaf:name> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.33</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.43</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success44"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.115</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.27</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.04</ExamPerformanceGoal> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.35</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER45</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.65</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success84"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.7</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER85</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.27</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success117"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.8</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER118</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.315</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.7</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.28</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.69</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success235"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.35</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER236</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.51</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.27</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success107"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER108</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.255</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.305</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.54</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.63</DegreeStudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.4</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success249"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.45</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.72</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER250</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.79</ExamPerformanceAll> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.45</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success94"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.89</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.8</ExamPerformanceGoal> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.323</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.32</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER95</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success158"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER159</foaf:name> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.465</StudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.258</DegreeRepitition> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.59</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.73</DegreeStudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success30"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.245</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.31</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.12</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.75</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.59</ExamPerformanceGoal> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER31</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success253"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.61</StudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER254</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.92</ExamPerformanceAll> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.69</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success74"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.69</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</ExamPerformanceGoal> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.28</StudyTime> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.33</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER75</foaf:name> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.16</DegreeRepitition> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success229"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.69</ExamPerformanceGoal> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.49</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.7</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.99</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.07</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER230</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success10"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.55</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER11</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.81</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.18</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success185"> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.78</ExamPerformanceAll> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER186</foaf:name> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.21</ExamPerformanceGoal> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.34</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.64</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.49</StudyTime> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success8"> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER9</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.14</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.72</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.2</StudyTime> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.35</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success24"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.35</DegreeStudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER25</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</DegreeRepitition> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.06</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.76</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success64"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.76</DegreeStudyTime> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER65</foaf:name> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.58</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.8</ExamPerformanceAll> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.24</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.28</ExamPerformanceGoal> + </rdf:Description> + <owl:AnnotationProperty rdf:about="http://example.com/ExamPerformanceGoal"/> + <rdf:Description rdf:about="http://example.org/Ev#Success215"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.6</StudyTime> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER216</foaf:name> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.39</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.251</DegreeRepitition> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceGoal> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success199"> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.34</DegreeStudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER200</foaf:name> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.55</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.3</ExamPerformanceAll> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success148"> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.345</StudyTime> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.299</DegreeRepitition> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.1</DegreeStudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.13</ExamPerformanceGoal> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.64</ExamPerformanceAll> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER149</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success83"> + <DegreeStudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.15</DegreeStudyTime> + <StudyTime rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.25</StudyTime> + <ExamPerformanceGoal rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.26</ExamPerformanceGoal> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.0</KnowledgeLevel> + <ExamPerformanceAll rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.48</ExamPerformanceAll> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.29</DegreeRepitition> + <foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string" + >USER84</foaf:name> + </rdf:Description> + <rdf:Description rdf:about="http://example.org/Ev#Success43"> + <DegreeRepitition rdf:datatype="http://www.w3.org/2001/XMLSchema#float" + >0.33</DegreeRepitition> + <KnowledgeLevel rdf:datatype="http://www.w3.org/2001/XMLSchem... [truncated message content] |
From: <lor...@us...> - 2014-05-07 13:43:59
|
Revision: 4262 http://sourceforge.net/p/dl-learner/code/4262 Author: lorenz_b Date: 2014-05-07 13:43:54 +0000 (Wed, 07 May 2014) Log Message: ----------- Updated libs. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/SearchTreeNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceMetric.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/kb/OWLAPIOntology.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/AutomaticNegativeExampleFinderSPARQL2.java trunk/components-core/src/main/resources/log4j.properties trunk/components-core/src/test/java/org/dllearner/algorithms/isle/DBpediaExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QALDExperiment.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QTLTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/TreeSubsumptionTest.java trunk/examples/family-benchmark/Brother.conf trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java trunk/interfaces/src/main/java/org/dllearner/cli/SPARQLCrossValidation.java trunk/pom.xml trunk/protege/src/main/resources/META-INF/MANIFEST.MF trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DefaultRelevanceWeightings.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightedStableHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightings.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/EntityFrequencyCache.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java Removed Paths: ------------- trunk/test/fuzzydll/fuzzyOWL2fuzzyDLparserOutput.fuzzyDL.txt Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/pom.xml 2014-05-07 13:43:54 UTC (rev 4262) @@ -232,10 +232,10 @@ <artifactId>commons-pool</artifactId> </dependency> <dependency> - <groupId>org.semanticweb.elk</groupId> - <artifactId>elk-owlapi</artifactId> - <version>0.3.0</version> - </dependency> + <groupId>org.semanticweb.elk</groupId> + <artifactId>elk-owlapi</artifactId> + <version>0.4.1</version> +</dependency> <dependency> <groupId>de.tudresden.inf.lat.cel</groupId> <artifactId>reasoner</artifactId> @@ -281,7 +281,7 @@ <dependency> <groupId>org.aksw.jena-sparql-api</groupId> <artifactId>jena-sparql-api-core</artifactId> - <version>2.10.0-5-SNAPSHOT</version> + <version>2.10.0-8</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DefaultRelevanceWeightings.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DefaultRelevanceWeightings.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/DefaultRelevanceWeightings.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,31 @@ +/** + * + */ +package org.dllearner.algorithms.elcopy; + +import org.dllearner.algorithms.isle.metrics.ChiSquareRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.DiceRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.JaccardRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.LLRRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.PMIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.SCIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.SignificantPMIRelevanceMetric; +import org.dllearner.algorithms.isle.metrics.TTestRelevanceMetric; + +/** + * @author Lorenz Buehmann + * + */ +public class DefaultRelevanceWeightings extends RelevanceWeightings{ + + public DefaultRelevanceWeightings() { + put(PMIRelevanceMetric.class, 1.0); + put(SignificantPMIRelevanceMetric.class, 1.0); + put(ChiSquareRelevanceMetric.class, 1.0); + put(TTestRelevanceMetric.class, 1.0); + put(JaccardRelevanceMetric.class, 1.0); + put(DiceRelevanceMetric.class, 1.0); + put(SCIRelevanceMetric.class, 1.0); + put(LLRRelevanceMetric.class, 1.0); + } +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -45,6 +45,7 @@ import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.ScorePosNeg; +import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.refinementoperators.ELDown3; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.EvaluatedDescriptionSet; @@ -148,7 +149,10 @@ @Override public void init() throws ComponentInitException { // currently we use the stable heuristic - heuristic = new StableHeuristic(); + if(heuristic == null){ + heuristic = new StableHeuristic(); + } + candidates = new TreeSet<SearchTreeNode>(heuristic); if(ignoredConcepts != null) { @@ -167,6 +171,13 @@ bestEvaluatedDescriptions = new EvaluatedDescriptionSet(maxNrOfResults); } + /** + * @param heuristic the heuristic to set + */ + public void setHeuristic(ELHeuristic heuristic) { + this.heuristic = heuristic; + } + @Override public void start() { stop = false; @@ -237,7 +248,13 @@ } else { node.setCoveredNegatives(negCovers); } - node.setScore(accuracy); + node.setAccuracy(accuracy); + if(heuristic instanceof RelevanceWeightedStableHeuristic){ + node.setScore(((RelevanceWeightedStableHeuristic)heuristic).getNodeScore(node)); + } else { + node.setScore(accuracy); + } + // System.out.println(description + ":" + accuracy); // link to parent (unless start node) if(parentNode == null) { @@ -259,6 +276,7 @@ // for fully computing the evaluated description if(bestEvaluatedDescriptions.size() == 0 || ((EvaluatedDescriptionPosNeg)bestEvaluatedDescriptions.getWorst()).getCoveredNegatives().size() >= node.getCoveredNegatives()) { ScorePosNeg score = (ScorePosNeg) learningProblem.computeScore(description); + ((ScoreTwoValued)score).setAccuracy(node.getScore()); EvaluatedDescriptionPosNeg ed = new EvaluatedDescriptionPosNeg(description, score); bestEvaluatedDescriptions.add(ed); } @@ -329,7 +347,9 @@ //non of the equivalent classes must occur on the first level TreeSet<Description> toTest = new TreeSet<Description>(descriptionComparator); - toTest.add(classToDescribe); + if(classToDescribe != null){ + toTest.add(classToDescribe); + } while(!toTest.isEmpty()) { Description d = toTest.pollFirst(); if(occursOnFirstLevel(description, d)) { @@ -341,7 +361,9 @@ // 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); + if(classToDescribe != null){ + toTest.add(classToDescribe); + } while(!toTest.isEmpty()) { Description d = toTest.pollFirst(); if(occursOnFirstLevel(description, d)) { Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightedStableHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightedStableHeuristic.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightedStableHeuristic.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,124 @@ +/** + * 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.elcopy; + +import java.util.Arrays; +import java.util.List; + +import org.dllearner.algorithms.isle.metrics.RelevanceMetric; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.NamedClass; + + +/** + * A stable comparator for search tree nodes. Stable means that the order + * of nodes will not change during the run of the learning algorithm. In + * this implementation, this is ensured by using only covered examples + * and tree size as criteria. + * + * @author Jens Lehmann + * + */ +public class RelevanceWeightedStableHeuristic implements ELHeuristic { + + private ELDescriptionTreeComparator cmp = new ELDescriptionTreeComparator(); + private RelevanceWeightings weightings; + private List<RelevanceMetric> relevanceMetrics; + private NamedClass classToDescribe; + + + public RelevanceWeightedStableHeuristic(NamedClass classToDescribe, RelevanceWeightings weightings, RelevanceMetric... relevanceMetrics) { + this.classToDescribe = classToDescribe; + this.weightings = weightings; + this.relevanceMetrics = Arrays.asList(relevanceMetrics); + } + + public RelevanceWeightedStableHeuristic(NamedClass classToDescribe, RelevanceWeightings weightings, List<RelevanceMetric> relevanceMetrics) { + this.classToDescribe = classToDescribe; + this.weightings = weightings; + this.relevanceMetrics = relevanceMetrics; + } + + public RelevanceWeightedStableHeuristic(NamedClass classToDescribe, RelevanceMetric... relevanceMetrics) { + this(classToDescribe, new DefaultRelevanceWeightings(), relevanceMetrics); + } + + public RelevanceWeightedStableHeuristic(NamedClass classToDescribe, List<RelevanceMetric> relevanceMetrics) { + this(classToDescribe, new DefaultRelevanceWeightings(), relevanceMetrics); + } + + /** + * @param weightings the weightings to set + */ + public void setWeightings(RelevanceWeightings weightings) { + this.weightings = weightings; + } + + /** + * @param relevanceMetrics the relevanceMetrics to set + */ + public void setRelevanceMetrics(List<RelevanceMetric> relevanceMetrics) { + this.relevanceMetrics = relevanceMetrics; + } + + /** + * @param classToDescribe the classToDescribe to set + */ + public void setClassToDescribe(NamedClass classToDescribe) { + this.classToDescribe = classToDescribe; + } + + public double getNodeScore(SearchTreeNode node){ + double score = node.getAccuracy(); + Description d = node.getDescriptionTree().transformToDescription(); + for (RelevanceMetric metric : relevanceMetrics) { + score += weightings.getWeight(metric.getClass()) * metric.getRelevance(classToDescribe, d); + } + return score; + } + + @Override + public int compare(SearchTreeNode o1, SearchTreeNode o2) { + +// int diff = o2.getCoveredNegatives() - o1.getCoveredNegatives(); + double score1 = o1.getScore(); + double score2 = o2.getScore(); + int diff = Double.compare(score1, score2); + if(diff>0) { + return 1; + } else if(diff<0) { + return -1; + } else { + + double sizeDiff = o2.getDescriptionTree().size - o1.getDescriptionTree().size; + + if(sizeDiff == 0) { + return cmp.compare(o1.getDescriptionTree(), o2.getDescriptionTree()); + } else if(sizeDiff>0) { + return 1; + } else { + return -1; + } + + } + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightings.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightings.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/RelevanceWeightings.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,24 @@ +/** + * + */ +package org.dllearner.algorithms.elcopy; + +import java.util.HashMap; + +import org.dllearner.algorithms.isle.metrics.RelevanceMetric; + +/** + * @author Lorenz Buehmann + * + */ +public class RelevanceWeightings extends HashMap<Class<? extends RelevanceMetric>, Double>{ + + public double getWeight(RelevanceMetric metric){ + return get(metric.getClass()); + } + + public double getWeight(Class<? extends RelevanceMetric> metricClass){ + return get(metricClass); + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/SearchTreeNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/SearchTreeNode.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/SearchTreeNode.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -38,6 +38,7 @@ private boolean tooWeak = false; private double score; + protected double accuracy; public SearchTreeNode(ELDescriptionTree descriptionTree) { this.descriptionTree = descriptionTree; @@ -127,4 +128,18 @@ this.score = score; } + /** + * @return the accuracy + */ + public double getAccuracy() { + return accuracy; + } + + /** + * @param accuracy the accuracy to set + */ + public void setAccuracy(double accuracy) { + this.accuracy = accuracy; + } + } Added: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/EntityFrequencyCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/EntityFrequencyCache.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/index/syntactic/EntityFrequencyCache.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,17 @@ +/** + * + */ +package org.dllearner.algorithms.isle.index.syntactic; + +import java.util.HashMap; +import java.util.Set; + +import org.dllearner.core.owl.Entity; + +/** + * @author Lorenz Buehmann + * + */ +public class EntityFrequencyCache extends HashMap<Set<Entity>, Long>{ + +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/AbstractRelevanceMetric.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -5,8 +5,10 @@ import java.util.HashMap; import java.util.Map; +import java.util.Set; import org.dllearner.algorithms.isle.index.Index; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; /** @@ -16,9 +18,12 @@ public abstract class AbstractRelevanceMetric implements RelevanceMetric { protected Index index; + protected String name; public AbstractRelevanceMetric(Index index) { this.index = index; + + name = getClass().getSimpleName().replace("RelevanceMetric", ""); } public static Map<Entity, Double> normalizeMinMax(Map<Entity, Double> hmEntity2Score) { @@ -53,5 +58,47 @@ } return hmEntity2Norm; } + + public String getName() { + return name; + } + + public double getRelevance(Entity entity, Description desc){ + Set<Entity> entities = desc.getSignature(); + double score = 0; + for (Entity otherEntity : entities) { + double relevance = getRelevance(entity, otherEntity); + if(!Double.isInfinite(relevance)){ + score += relevance/entities.size(); + } + } + return score; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractRelevanceMetric other = (AbstractRelevanceMetric) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceMetric.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceMetric.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/metrics/RelevanceMetric.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -20,6 +20,7 @@ package org.dllearner.algorithms.isle.metrics; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Entity; @@ -38,4 +39,6 @@ * @return */ double getNormalizedRelevance(Entity entity1, Entity entity2); + + double getRelevance(Entity entity, Description desc); } \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -1,5 +1,6 @@ package org.dllearner.algorithms.qtl; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -28,14 +29,19 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.Score; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Union; +import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.Heuristics; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.QueryTreeScore; +import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIConverter; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -51,12 +57,12 @@ import com.jamonapi.MonitorFactory; @ComponentAnn(name="query tree learner with noise (disjunctive)", shortName="qtl2dis", version=0.8) -public class QTL2Disjunctive extends AbstractCELA { +public class QTL2Disjunctive extends AbstractCELA implements Cloneable{ private static final Logger logger = Logger.getLogger(QTL2Disjunctive.class.getName()); - private LGGGenerator<String> lggGenerator = new LGGGeneratorImpl<String>(); + private LGGGenerator<String> lggGenerator; private Queue<EvaluatedQueryTree<String>> todoList; private SortedSet<EvaluatedQueryTree<String>> currentPartialSolutions; @@ -69,9 +75,6 @@ private Set<Individual> currentNegExamples; private Map<QueryTree<String>, Individual> tree2Individual; - - private double coverageWeight = 0.8; - private double specifityWeight = 0.2; private QueryTreeCache treeCache; @@ -79,8 +82,6 @@ private Model model; - private AbstractReasonerComponent reasoner; - private volatile boolean stop; private boolean isRunning; @@ -89,16 +90,39 @@ private List<EvaluatedQueryTree<String>> partialSolutions; + private EvaluatedDescription currentBestSolution; + + + + //Parameters + @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") + private double noisePercentage = 0.0; + @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") + private int maxExecutionTimeInSeconds = 10; + private double minimumTreeScore = 0.2; + private double coverageWeight = 0.8; + private double specifityWeight = 0.1; + private double noise = 0.3; + private double coverageBeta = 0.7; + + private double posExampleWeight = 1; + public QTL2Disjunctive() {} public QTL2Disjunctive(PosNegLP learningProblem, AbstractReasonerComponent reasoner) throws LearningProblemUnsupportedException{ - this.lp = learningProblem; - this.reasoner = reasoner; + super(learningProblem, reasoner); + loadModel(); } - public QTL2Disjunctive(PosNegLP lp, Model model) { - this.lp = lp; - this.model = model; +// public QTL2Disjunctive(PosNegLP lp, Model model) { +// this.learningProblem = lp; +// this.model = model; +// } + + public QTL2Disjunctive(QTL2Disjunctive qtl) { + super(qtl.getLearningProblem(), qtl.getReasoner()); + this.model = ModelFactory.createDefaultModel(); + this.model.add(qtl.model); } public EvaluatedQueryTree<String> getBestSolution(){ @@ -110,6 +134,14 @@ */ @Override public void init() throws ComponentInitException { + + if(!(learningProblem instanceof PosNegLP)){ + throw new IllegalArgumentException("Only PosNeg learning problems are supported"); + } + lp = (PosNegLP) learningProblem; + + lggGenerator = new LGGGeneratorImpl<String>(); + logger.info("Initializing..."); treeCache = new QueryTreeCache(model); tree2Individual = new HashMap<QueryTree<String>, Individual>(lp.getPositiveExamples().size()+lp.getNegativeExamples().size()); @@ -120,6 +152,18 @@ currentNegExamples = new TreeSet<Individual>(lp.getNegativeExamples()); //get the query trees + generateTrees(); + + //some logging + subMon = MonitorFactory.getTimeMonitor("subsumption-mon"); + lggMon = MonitorFactory.getTimeMonitor("lgg-mon"); + + //console rendering of class expressions + ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); + ToStringRenderer.getInstance().setShortFormProvider(new SimpleShortFormProvider()); + } + + private void generateTrees(){ QueryTree<String> queryTree; for (Individual ind : lp.getPositiveExamples()) { queryTree = treeCache.getQueryTree(ind.getName()); @@ -131,14 +175,6 @@ tree2Individual.put(queryTree, ind); currentNegExampleTrees.add(queryTree); } - - //some logging - subMon = MonitorFactory.getTimeMonitor("subsumption-mon"); - lggMon = MonitorFactory.getTimeMonitor("lgg-mon"); - - //console rendering of class expressions - ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); - ToStringRenderer.getInstance().setShortFormProvider(new SimpleShortFormProvider()); } /* (non-Javadoc) @@ -146,6 +182,11 @@ */ @Override public void start() { + String setup = "Setup:"; + setup += "#Pos. examples:" + currentPosExamples.size(); + setup += "#Neg. examples:" + currentNegExamples.size(); + setup += "Coverage beta:" + coverageBeta; + logger.info(setup); logger.info("Running..."); long startTime = System.currentTimeMillis(); @@ -180,6 +221,7 @@ currentNegExamples.remove(tree2Individual.get(tree)); } } + currentBestSolution = buildCombinedSolution(); } while (!(stop || currentPosExampleTrees.isEmpty())); isRunning = false; @@ -187,22 +229,53 @@ long endTime = System.currentTimeMillis(); logger.info("Finished in " + (endTime-startTime) + "ms."); - EvaluatedDescription combinedSolution = buildCombinedSolution(); - System.out.println(OWLAPIConverter.getOWLAPIDescription(combinedSolution.getDescription())); + logger.info("Combined solution:\n" + OWLAPIConverter.getOWLAPIDescription(currentBestSolution.getDescription())); + logger.info(currentBestSolution.getScore()); } private EvaluatedDescription buildCombinedSolution(){ + if(partialSolutions.size() == 1){ + EvaluatedDescription combinedSolution = partialSolutions.get(0).asEvaluatedDescription(); + double accuracy = lp.getAccuracy(combinedSolution.getDescription()); + System.out.println(accuracy); + return combinedSolution; + } List<Description> disjuncts = new ArrayList<Description>(); + + Set<Individual> posCovered = new HashSet<Individual>(); + Set<Individual> negCovered = new HashSet<Individual>(); + + //build the union of all class expressions Description partialDescription; for (EvaluatedQueryTree<String> partialSolution : partialSolutions) { partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( partialSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)); disjuncts.add(partialDescription); + posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives()); + negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives()); } Description unionDescription = new Union(disjuncts); - return new EvaluatedDescription(unionDescription, null); + Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered); + Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered); + + double accuracy = lp.getAccuracy(unionDescription); + System.out.println(accuracy); + + //compute the coverage + double recall = posCovered.size() / (double)lp.getPositiveExamples().size(); + double precision = (posCovered.size() + negCovered.size() == 0) + ? 0 + : posCovered.size() / (double)(posCovered.size() + negCovered.size()); + + double coverageScore = Heuristics.getFScore(recall, precision, coverageBeta); + +// ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered); +// score.setAccuracy(coverageScore); + QueryTreeScore score = new QueryTreeScore(coverageScore, coverageScore, posCovered, posNotCovered, negCovered, negNotCovered, -1, -1); + + return new EvaluatedDescription(unionDescription, score); } private void reset(){ @@ -216,6 +289,7 @@ } private void computeLGG(){ + logger.info("Computing best partial solution..."); currentlyBestScore = 0d; initTodoList(currentPosExampleTrees, currentNegExampleTrees); @@ -246,16 +320,17 @@ } currentlyBestScore = solution.getScore(); } + currentPartialSolutions.add(currentElement); } currentPartialSolutions.add(currentElement); // todoList.remove(currentElement); } while(!terminationCriteriaSatisfied()); long endTime = System.currentTimeMillis(); - logger.info("Finished in " + (endTime-startTime) + "ms."); - EvaluatedDescription bestSolution = getCurrentlyBestEvaluatedDescription(); + logger.info("...finished in " + (endTime-startTime) + "ms."); + EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription(); - logger.info("Best solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestSolution.getDescription()) + "\n(" + bestSolution.getScore() + ")"); + logger.info("Best partial solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()) + "\n(" + bestPartialSolution.getScore() + ")"); logger.trace("LGG time: " + lggMon.getTotal() + "ms"); logger.trace("Avg. LGG time: " + lggMon.getAvg() + "ms"); @@ -278,7 +353,7 @@ */ @Override public Description getCurrentlyBestDescription() { - return getCurrentlyBestEvaluatedDescription().getDescription(); + return currentBestSolution.getDescription(); } /* (non-Javadoc) @@ -286,8 +361,7 @@ */ @Override public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { - EvaluatedQueryTree<String> bestSolution = currentPartialSolutions.first(); - return bestSolution.asEvaluatedDescription(); + return currentBestSolution; } /* (non-Javadoc) @@ -298,14 +372,18 @@ return isRunning; } +// @Autowired +// public void setLearningProblem(PosNegLP learningProblem) { +// this.lp = learningProblem; +// } + @Autowired - public void setLearningProblem(PosNegLP learningProblem) { - this.lp = learningProblem; + public void setReasoner(AbstractReasonerComponent reasoner){ + super.setReasoner(reasoner); + loadModel(); } - @Autowired - public void setReasoner(AbstractReasonerComponent reasoner){ - this.reasoner = reasoner; + private void loadModel(){ model = ModelFactory.createDefaultModel(); for (KnowledgeSource ks : reasoner.getSources()) { if(ks instanceof OWLFile){ @@ -314,6 +392,14 @@ } catch (IOException e) { e.printStackTrace(); } + } else if(ks instanceof OWLAPIOntology){ + ByteArrayInputStream bais = new ByteArrayInputStream(((OWLAPIOntology) ks).getConverter().convert(((OWLAPIOntology) ks).getOntology())); + model.read(bais, null); + try { + bais.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } } @@ -328,14 +414,14 @@ private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ //1. get a score for the coverage = recall oriented //compute positive examples which are not covered by LGG - Set<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); - Set<Individual> uncoveredPosExamples = new HashSet<Individual>(); + List<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); + Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(); for (QueryTree<String> queryTree : uncoveredPositiveExampleTrees) { uncoveredPosExamples.add(tree2Individual.get(queryTree)); } //compute negative examples which are covered by LGG Collection<QueryTree<String>> coveredNegativeExampleTrees = getCoveredTrees(tree, currentNegExampleTrees); - Set<Individual> coveredNegExamples = new HashSet<Individual>(); + Set<Individual> coveredNegExamples = new TreeSet<Individual>(); for (QueryTree<String> queryTree : coveredNegativeExampleTrees) { coveredNegExamples.add(tree2Individual.get(queryTree)); } @@ -346,7 +432,8 @@ ? 0 : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); - double coverageScore = Heuristics.getFScore(recall, precision); + double beta = 0.5; + double coverageScore = Heuristics.getFScore(recall, precision, beta); //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented int nrOfSpecificNodes = 0; @@ -364,8 +451,8 @@ double score = coverageWeight * coverageScore + specifityWeight * specifityScore; QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, - Sets.difference(currentPosExamples, uncoveredPosExamples), uncoveredPosExamples, - coveredNegExamples, Sets.difference(currentNegExamples, coveredNegExamples), + new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, + coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), specifityScore, nrOfSpecificNodes); // QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, @@ -400,8 +487,8 @@ * @param allTrees * @return */ - private Set<QueryTree<String>> getUncoveredTrees(QueryTree<String> tree, List<QueryTree<String>> allTrees){ - Set<QueryTree<String>> uncoveredTrees = new LinkedHashSet<QueryTree<String>>(); + private List<QueryTree<String>> getUncoveredTrees(QueryTree<String> tree, List<QueryTree<String>> allTrees){ + List<QueryTree<String>> uncoveredTrees = new ArrayList<QueryTree<String>>(); for (QueryTree<String> queryTree : allTrees) { boolean subsumed = queryTree.isSubsumedBy(tree); if(!subsumed){ @@ -470,4 +557,33 @@ } todoList.add(solution); } + + /** + * @param noisePercentage the noisePercentage to set + */ + public void setNoisePercentage(double noisePercentage) { + this.noisePercentage = noisePercentage; + } + + /** + * @param maxExecutionTimeInSeconds the maxExecutionTimeInSeconds to set + */ + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds) { + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + } + + /** + * @param coverageBeta the coverageBeta to set + */ + public void setCoverageBeta(double coverageBeta) { + this.coverageBeta = coverageBeta; + } + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return new QTL2Disjunctive(this); + } } Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,559 @@ +package org.dllearner.algorithms.qtl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.PriorityBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.qtl.cache.QueryTreeCache; +import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy; +import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree; +import org.dllearner.algorithms.qtl.operations.lgg.LGGGenerator; +import org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorImpl; +import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.QueryTreeScore; +import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.semanticweb.owlapi.io.ToStringRenderer; +import org.semanticweb.owlapi.util.SimpleShortFormProvider; +import org.springframework.beans.factory.annotation.Autowired; + +import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxOWLObjectRendererImpl; + +import com.google.common.collect.Sets; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + +@ComponentAnn(name="query tree learner with noise (disjunctive)", shortName="qtl2dis", version=0.8) +public class QTL2DisjunctiveMT extends AbstractCELA { + + + private static final Logger logger = Logger.getLogger(QTL2DisjunctiveMT.class.getName()); + + private LGGGenerator<String> lggGenerator = new LGGGeneratorImpl<String>(); + + private BlockingQueue<EvaluatedQueryTree<String>> todoList; + private SortedSet<EvaluatedQueryTree<String>> solutions; + + private double currentlyBestScore = 0d; + + private List<QueryTree<String>> currentPosExampleTrees; + private List<QueryTree<String>> currentNegExampleTrees; + + private Map<QueryTree<String>, Individual> tree2Indivual; + + private double coverageWeight = 0.8; + private double specifityWeight = 0.2; + + private QueryTreeCache treeCache; + + private PosNegLP lp; + + private Model model; + + private AbstractReasonerComponent reasoner; + + private volatile boolean stop; + private boolean isRunning; + + private Monitor subMon; + private Monitor lggMon; + + private final EvaluatedQueryTree<String> STOP_ELEMENT = new EvaluatedQueryTree<String>(new QueryTreeImpl<String>("STOP"), null, null, null); + + + public QTL2DisjunctiveMT() {} + + public QTL2DisjunctiveMT(PosNegLP learningProblem, AbstractReasonerComponent reasoner) throws LearningProblemUnsupportedException{ + this.lp = learningProblem; + this.reasoner = reasoner; + + } + + public QTL2DisjunctiveMT(PosNegLP lp, Model model) { + this.lp = lp; + this.model = model; + } + + public EvaluatedQueryTree<String> getBestSolution(){ + return solutions.first(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() throws ComponentInitException { + logger.info("Initializing..."); + treeCache = new QueryTreeCache(model); + tree2Indivual = new HashMap<QueryTree<String>, Individual>(lp.getPositiveExamples().size()+lp.getNegativeExamples().size()); + + currentPosExampleTrees = new ArrayList<QueryTree<String>>(lp.getPositiveExamples().size()); + currentNegExampleTrees = new ArrayList<QueryTree<String>>(lp.getNegativeExamples().size()); + + //get the query trees + QueryTree<String> queryTree; + for (Individual ind : lp.getPositiveExamples()) { + queryTree = treeCache.getQueryTree(ind.getName()); + tree2Indivual.put(queryTree, ind); + currentPosExampleTrees.add(queryTree); + } + for (Individual ind : lp.getNegativeExamples()) { + queryTree = treeCache.getQueryTree(ind.getName()); + tree2Indivual.put(queryTree, ind); + currentNegExampleTrees.add(treeCache.getQueryTree(ind.getName())); + } + + //some logging + subMon = MonitorFactory.getTimeMonitor("subsumption-mon"); + lggMon = MonitorFactory.getTimeMonitor("lgg-mon"); + + //console rendering of class expressions + ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); + ToStringRenderer.getInstance().setShortFormProvider(new SimpleShortFormProvider()); + } + + /* (non-Javadoc) + * @see org.dllearner.core.LearningAlgorithm#start() + */ + @Override + public void start() { + logger.info("Running..."); + stop = false; + isRunning = true; + long startTime = System.currentTimeMillis(); + + subMon = MonitorFactory.getTimeMonitor("subsumption-mon"); + lggMon = MonitorFactory.getTimeMonitor("lgg-mon"); + + + //outer loop: compute LGG, pick best solution and remove all covered positive and negative examples + List<EvaluatedQueryTree<String>> unionSolutions = new ArrayList<EvaluatedQueryTree<String>>(); + do { + //compute LGG + computeLGG(); + + //pick best solution computed so far + EvaluatedQueryTree<String> bestSolution = solutions.first(); + unionSolutions.add(bestSolution); + logger.info("#Uncovered pos. examples:" + bestSolution.getFalseNegatives().size()); + + //remove all covered examples + QueryTree<String> tree; + for (Iterator<QueryTree<String>> iterator = currentPosExampleTrees.iterator(); iterator.hasNext();) { + tree = iterator.next(); + if(tree.isSubsumedBy(bestSolution.getTree())){ + iterator.remove(); + } + } + for (Iterator<QueryTree<String>> iterator = currentNegExampleTrees.iterator(); iterator.hasNext();) { + tree = iterator.next(); + if(tree.isSubsumedBy(bestSolution.getTree())){ + iterator.remove(); + } + } + } while (!(stop || currentPosExampleTrees.isEmpty())); + + + } + + private void computeLGG(){ + currentlyBestScore = 0d; + initTodoList(currentPosExampleTrees, currentNegExampleTrees); + long startTime = System.currentTimeMillis(); + int nrOfThreads = Runtime.getRuntime().availableProcessors() - 1; + nrOfThreads = 2; + ExecutorService es = Executors.newFixedThreadPool(nrOfThreads); + for(int i = 0; i < nrOfThreads; i++){ + es.submit(new QueryTreeProcessor()); + } + es.shutdown(); + try { + es.awaitTermination(1, TimeUnit.HOURS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + long endTime = System.currentTimeMillis(); + logger.info("Finished in " + (endTime-startTime) + "ms."); + EvaluatedDescription bestSolution = getCurrentlyBestEvaluatedDescription(); + ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); + ToStringRenderer.getInstance().setShortFormProvider(new SimpleShortFormProvider()); +// solutions.first().getTree().dump(); + logger.info("Best solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestSolution.getDescription()) + "\n(" + bestSolution.getScore() + ")"); + + logger.trace("LGG time: " + lggMon.getTotal() + "ms"); + logger.trace("Avg. LGG time: " + lggMon.getAvg() + "ms"); + logger.trace("#LGG computations: " + lggMon.getHits()); + logger.trace("Subsumption test time: " + subMon.getTotal() + "ms"); + logger.trace("Avg. subsumption test time: " + subMon.getAvg() + "ms"); + logger.trace("#Subsumption tests: " + subMon.getHits()); + } + + /* (non-Javadoc) + * @see org.dllearner.core.StoppableLearningAlgorithm#stop() + */ + @Override + public void stop() { + stop = true; + } + + /* (non-Javadoc) + * @see org.dllearner.core.AbstractCELA#getCurrentlyBestDescription() + */ + @Override + public Description getCurrentlyBestDescription() { + return getCurrentlyBestEvaluatedDescription().getDescription(); + } + + /* (non-Javadoc) + * @see org.dllearner.core.AbstractCELA#getCurrentlyBestEvaluatedDescription() + */ + @Override + public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { + EvaluatedQueryTree<String> bestSolution = solutions.first(); + Description description = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( + bestSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)); + return new EvaluatedDescription(description, bestSolution.getTreeScore()); + } + + /* (non-Javadoc) + * @see org.dllearner.core.StoppableLearningAlgorithm#isRunning() + */ + @Override + public boolean isRunning() { + return isRunning; + } + + @Autowired + public void setLearningProblem(PosNegLP learningProblem) { + this.lp = learningProblem; + } + + @Autowired + public void setReasoner(AbstractReasonerComponent reasoner){ + this.reasoner = reasoner; + model = ModelFactory.createDefaultModel(); + for (KnowledgeSource ks : reasoner.getSources()) { + if(ks instanceof OWLFile){ + try { + model.read(((OWLFile) ks).getURL().openStream(), null); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * @return the treeCache + */ + public QueryTreeCache getTreeCache() { + return treeCache; + } + + private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ + //1. get a score for the coverage = recall oriented + //compute positive examples which are not covered by LGG + Collection<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); + Set<Individual> uncoveredPosExamples = new HashSet<Individual>(); + for (QueryTree<String> queryTree : uncoveredPositiveExampleTrees) { + uncoveredPosExamples.add(tree2Indivual.get(queryTree)); + } + //compute negative examples which are covered by LGG + Collection<QueryTree<String>> coveredNegativeExampleTrees = getCoveredTrees(tree, currentNegExampleTrees); + Set<Individual> coveredNegExamples = new HashSet<Individual>(); + for (QueryTree<String> queryTree : coveredNegativeExampleTrees) { + coveredNegExamples.add(tree2Indivual.get(queryTree)); + } + //compute score + int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size(); + double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size(); + double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0) + ? 0 + : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); + + double coverageScore = recall;//Heuristics.getFScore(recall, precision); + + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int nrOfSpecificNodes = 0; + for (QueryTree<String> childNode : tree.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + nrOfSpecificNodes++; + } + } + double specifityScore = Math.log(nrOfSpecificNodes); + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + + QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, + uncoveredPosExamples, Sets.difference(lp.getPositiveExamples(), uncoveredPosExamples), + coveredNegExamples, Sets.difference(lp.getNegativeExamples(), coveredNegExamples), + specifityScore, nrOfSpecificNodes); + + EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore); + + return evaluatedTree; + } + + /** + * Initializes the todo list with all distinct trees contained in the given list {@code trees}. + * Firstly, distinct trees are computed and afterwards, for each tree a score is computed. + * @param trees + */ + private void initTodoList(List<QueryTree<String>> posExamples, List<QueryTree<String>> negExamples){ + todoList = new PriorityBlockingQueue<EvaluatedQueryTree<String>>(); + solutions = new TreeSet<EvaluatedQueryTree<String>>(); +// EvaluatedQueryTree<String> dummy = new EvaluatedQueryTree<String>(new QueryTreeImpl<String>((N)"TOP"), trees, 0d); +// todoList.add(dummy); + //compute distinct trees + Collection<QueryTree<String>> distinctTrees = new ArrayList<QueryTree<String>>(); + for (QueryTree<String> queryTree : posExamples) { + boolean distinct = true; + for (QueryTree<String> otherTree : distinctTrees) { + if(!queryTree.equals(otherTree)){ + if(queryTree.isSameTreeAs(otherTree)){ + distinct = false; + break; + } + } + } + if(distinct){ + distinctTrees.add(queryTree); + } + } + for (QueryTree<String> queryTree : distinctTrees) {//System.out.println(queryTree.getStringRepresentation()); + EvaluatedQueryTree<String> evaluatedQueryTree = evaluate(queryTree, false); + todoList.add(evaluatedQueryTree); + } + } + + /** + * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. + * @param tree + * @param allTrees + * @return + */ + private Collection<QueryTree<String>> getCoveredTrees(QueryTree<String> tree, List<QueryTree<String>> trees){ + Collection<QueryTree<String>> coveredTrees = new ArrayList<QueryTree<String>>(); + for (QueryTree<String> queryTree : trees) { + boolean subsumed = queryTree.isSubsumedBy(tree); + if(subsumed){ + coveredTrees.add(queryTree); + } + } + return coveredTrees; + } + + /** + * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. + * @param tree + * @param allTrees + * @return + */ + private Collection<QueryTree<String>> getUncoveredTrees(QueryTree<String> tree, List<QueryTree<String>> allTrees){ + Collection<QueryTree<String>> uncoveredTrees = new ArrayList<QueryTree<String>>(); + for (QueryTree<String> queryTree : allTrees) { + boolean subsumed = queryTree.isSubsumedBy(tree); + if(!subsumed){ + uncoveredTrees.add(queryTree); + } + } + return uncoveredTrees; + } + + private boolean sameTrees(QueryTree<String> tree1, QueryTree<String> tree2){ + return tree1.isSubsumedBy(tree2) && tree2.isSubsumedBy(tree1); + } + + private synchronized boolean terminationCriteriaSatisfied(){ + return stop || todoList.isEmpty() || currentPosExampleTrees.isEmpty(); + } + + /** + * Add tree to todo list if not already contained in that list or the solutions. + * @param solution + */ + private void todo(EvaluatedQueryTree<String> solution){ + //check if not already contained in todo list + for (EvaluatedQueryTree<String> evTree : todoList) { + if(sameTrees(solution.getTree(), evTree.getTree())){ + return; + } + } + //check if not already contained in solutions + for (EvaluatedQueryTree<String> evTree : solutions) { + if(sameTrees(solution.getTree(), evTree.getTree())){ + return; + } + } + try { + todoList.put(solution); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + class QueryTreeProcessor implements Runnable { + + volatile boolean isRunning; + LGGGenerator<String> lggGenerator = new LGGGeneratorImpl<String>(); + + /** + * + */ + public QueryTreeProcessor() { + } + + /* (non-Javadoc) + * @see java.lang.Runnable#run() + */ + @Override + public void run() { + long startTime = System.currentTimeMillis(); + while(!terminationCriteriaSatisfied()){ + double currentlyBestScore = 0d; + try { + long t1 = System.currentTimeMillis(); + EvaluatedQueryTree<String> evaluatedQueryTree = todoList.take(); + long t2 = System.currentTimeMillis(); + System.out.println(Thread.currentThread().getId() + "\t waiting time:" + (t2-t1)); + for (QueryTree<String> example : evaluatedQueryTree.getFalseNegatives()) { + //compute the LGG +// lggMon.start(); + QueryTree<String> lgg = lggGenerator.getLGG(evaluatedQueryTree.getTree(), example); +// lggMon.stop(); + + //evaluate the LGG + EvaluatedQueryTree<String> solution = evaluate(lgg, true); + + if(solution.getScore() >= currentlyBestScore){ + //add to todo list, if not already contained in todo list or solution list + todo(solution); + if(solution.getScore() > currentlyBestScore){ + logger.info("Got better solution:" + solution.getTreeScore()); + } + currentlyBestScore = solution.getScore(); + } + } + long t3 = System.currentTimeMillis(); + System.out.println(Thread.currentThread().getId() + "\t processing time:" + (t3-t2)); + // add currently processed tree to solutions + solutions.add(evaluatedQueryTree); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + System.out.println(System.currentTimeMillis() + ":" + Thread.currentThread().getId() + " finished"); + } + + private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ + //1. get a score for the coverage = recall oriented + //compute positive examples which are not covered by LGG + Collection<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); + Set<Individual> uncoveredPosExamples = new HashSet<Individual>(); + for (QueryTree<String> queryTree : uncoveredPositiveExampleTrees) { + uncoveredPosExamples.add(tree2Indivual.get(queryTree)); + } + //compute negative examples which are covered by LGG + Collection<QueryTree<String>> coveredNegativeExampleTrees = getCoveredTrees(tree, currentNegExampleTrees); + Set<Individual> coveredNegExamples = new HashSet<Individual>(); + for (QueryTree<String> queryTree : coveredNegativeExampleTrees) { + coveredNegExamples.add(tree2Indivual.get(queryTree)); + } + //compute score + int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size(); + double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size(); + double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0) + ? 0 + : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); + + double coverageScore = recall;//Heuristics.getFScore(recall, precision); + + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int nrOfSpecificNodes = 0; + for (QueryTree<String> childNode : tree.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + nrOfSpecificNodes++; + } + } + double specifityScore = Math.log(nrOfSpecificNodes); + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + + QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, + uncoveredPosExamples, Sets.difference(lp.getPositiveExamples(), uncoveredPosExamples), + coveredNegExamples, Sets.difference(lp.getNegativeExamples(), coveredNegExamples), + specifityScore, nrOfSpecificNodes); + + EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore); + + return evaluatedTree; + } + + /** + * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. + * @param tree + * @param allTrees + * @return + */ + private Collection<QueryTree<String>> getCoveredTrees(QueryTree<String> tree, List<QueryTree<String>> trees){ + Collection<QueryTree<String>> coveredTrees = new ArrayList<QueryTree<String>>(); + for (QueryTree<String> queryTree : trees) { + boolean subsumed = queryTree.isSubsumedBy(tree); + if(subsumed){ + coveredTrees.add(queryTree); + } + } + return coveredTrees; + } + + /** + * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. + * @param tree + * @param allTrees + * @return + */ + private Collection<QueryTree<String>> getUncoveredTrees(QueryTree<String> tree, List<QueryTree<String>> allTrees){ + Collection<QueryTree<String>> uncoveredTrees = new ArrayList<QueryTree<String>>(); + for (QueryTree<String> queryTree : allTrees) { + boolean subsumed = queryTree.isSubsumedBy(tree); + if(!subsumed){ + uncoveredTrees.add(queryTree); + } + } + return uncoveredTrees; + } + + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -0,0 +1,79 @@ +/** + * + */ +package org.dllearner.algorithms.qtl; + +import java.util.Comparator; +import java.util.Set; + +import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree; +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.Heuristic; +import org.dllearner.core.owl.Individual; +import org.dllearner.learningproblems.Heuristics; +import org.dllearner.learningproblems.QueryTreeScore; +import org.dllearner.utilities.owl.ConceptComparator; + +/** + * @author Lorenz Buehmann + * + */ +@ComponentAnn(name = "QueryTreeHeuristic", shortName = "qtree_heuristic", version = 0.1) +public class QueryTreeHeuristic extends AbstractComponent implements Heuristic, Comparator<EvaluatedQueryTree<String>>{ + + // F score beta value + private double coverageBeta = 1; + + private double coverageWeight = 0.8; + + private double specifityWeight = 0.1; + + // syntactic comparison as final comparison criterion + private ConceptComparator conceptComparator = new ConceptComparator(); + + /* (non-Javadoc) + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() throws ComponentInitException { + } + + public double getScore(EvaluatedQueryTree<String> tree){ + QueryTreeScore treeScore = tree.getTreeScore(); + + //TODO + double score = treeScore.getScore(); + + return score; + } + + private double getPredictedAccuracy(EvaluatedQueryTree<String> tree){ + QueryTreeScore treeScore = tree.getTreeScore(); + + Set<Individual> truePositives = treeScore.getCoveredPositives(); + Set<Individual> trueNegatives = treeScore.getNotCoveredNegatives(); + Set<Individual> falsePositives = treeScore.getNotCoveredPositives(); + Set<Individual> falseNegatives = treeScore.getCoveredNegatives(); + return 0; + + } + + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @Override + public int compare(EvaluatedQueryTree<String> tree1, EvaluatedQueryTree<String> tree2) { + double diff = getScore(tree1) - getScore(tree2); + + if (diff > 0) { + return 1; + } else if (diff < 0) { + return -1; + } else { + return conceptComparator.compare(tree1.asEvaluatedDescription().getDescription(), tree2.asEvaluatedDescription().getDescription()); + } + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-07 11:25:54 UTC (rev 4261) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-07 13:43:54 UTC (rev 4262) @@ -1488,7 +1488,7 @@ private String prefixed(Map<String, String> prefixes, String uri){ if(uri.startsWith("http://")){ - for (Entry<String, String> entry : prefixes.entrySet()) {System.out.println(entry); + for (Entry<String, String> entry : prefixes.entrySet()) { String prefix = entry.getKey(); String ns = entry.getValue(); if(uri.startsWith(ns)){ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTre... [truncated message content] |
From: <lor...@us...> - 2014-05-08 11:45:49
|
Revision: 4263 http://sourceforge.net/p/dl-learner/code/4263 Author: lorenz_b Date: 2014-05-08 11:45:45 +0000 (Thu, 08 May 2014) Log Message: ----------- Added more termination criteria for QTL algorithm. Added heuristics for tree score. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java trunk/components-core/src/main/java/org/dllearner/learningproblems/QueryTreeScore.java trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -2,6 +2,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -61,6 +62,7 @@ private static final Logger logger = Logger.getLogger(QTL2Disjunctive.class.getName()); + private final DecimalFormat df = new DecimalFormat("0.00"); private LGGGenerator<String> lggGenerator; @@ -92,21 +94,31 @@ private EvaluatedDescription currentBestSolution; + private QueryTreeHeuristic heuristic; //Parameters @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") private double noisePercentage = 0.0; @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = 10; - private double minimumTreeScore = 0.2; + private int maxExecutionTimeInSeconds = -1; + private double coverageWeight = 0.8; private double specifityWeight = 0.1; - private double noise = 0.3; - private double coverageBeta = 0.7; + private double coverageBeta = 0.5; - private double posExampleWeight = 1; + private double minCoveredPosExamplesFraction = 0.2; + // maximum execution time to compute a part of the solution + private double maxTreeComputationTimeInSeconds = 60; + // how important not to cover negatives + private double posWeight = 2; + // minimum score a query tree must have to be part of the solution + private double minimumTreeScore = 0.2; + private long startTime; + + private long partialSolutionStartTime; + public QTL2Disjunctive() {} public QTL2Disjunctive(PosNegLP learningProblem, AbstractReasonerComponent reasoner) throws LearningProblemUnsupportedException{ @@ -142,6 +154,11 @@ lggGenerator = new LGGGeneratorImpl<String>(); + if(heuristic == null){ + heuristic = new QueryTreeHeuristic(); + heuristic.setPosExamplesWeight(2); + } + logger.info("Initializing..."); treeCache = new QueryTreeCache(model); tree2Individual = new HashMap<QueryTree<String>, Individual>(lp.getPositiveExamples().size()+lp.getNegativeExamples().size()); @@ -164,6 +181,7 @@ } private void generateTrees(){ + logger.info("Generating trees..."); QueryTree<String> queryTree; for (Individual ind : lp.getPositiveExamples()) { queryTree = treeCache.getQueryTree(ind.getName()); @@ -175,6 +193,7 @@ tree2Individual.put(queryTree, ind); currentNegExampleTrees.add(queryTree); } + logger.info("...done."); } /* (non-Javadoc) @@ -183,46 +202,59 @@ @Override public void start() { String setup = "Setup:"; - setup += "#Pos. examples:" + currentPosExamples.size(); - setup += "#Neg. examples:" + currentNegExamples.size(); - setup += "Coverage beta:" + coverageBeta; + setup += "\n#Pos. examples:" + currentPosExamples.size(); + setup += "\n#Neg. examples:" + currentNegExamples.size(); + setup += "\nCoverage beta:" + coverageBeta; logger.info(setup); logger.info("Running..."); - long startTime = System.currentTimeMillis(); + startTime = System.currentTimeMillis(); reset(); int i = 1; - do { + while(!terminationCriteriaSatisfied()){ logger.info(i++ + ". iteration..."); logger.info("#Remaining pos. examples:" + currentPosExampleTrees.size()); logger.info("#Remaining neg. examples:" + currentNegExampleTrees.size()); - //compute LGG - computeLGG(); + //compute a (partial) solution + computeNextPartialSolution(); //pick best (partial) solution computed so far EvaluatedQueryTree<String> bestPartialSolution = currentPartialSolutions.first(); - partialSolutions.add(bestPartialSolution); - //remove all covered examples - QueryTree<String> tree; - for (Iterator<QueryTree<String>> iterator = currentPosExampleTrees.iterator(); iterator.hasNext();) { - tree = iterator.next(); - if(tree.isSubsumedBy(bestPartialSolution.getTree())){ - iterator.remove(); - currentPosExamples.remove(tree2Individual.get(tree)); + //add if some criteria are satisfied + if(bestPartialSolution.getScore() >= minimumTreeScore){ + + partialSolutions.add(bestPartialSolution); + + //remove all covered examples + QueryTree<String> tree; + for (Iterator<QueryTree<String>> iterator = currentPosExampleTrees.iterator(); iterator.hasNext();) { + tree = iterator.next(); + if(tree.isSubsumedBy(bestPartialSolution.getTree())){ + iterator.remove(); + currentPosExamples.remove(tree2Individual.get(tree)); + } } - } - for (Iterator<QueryTree<String>> iterator = currentNegExampleTrees.iterator(); iterator.hasNext();) { - tree = iterator.next(); - if(tree.isSubsumedBy(bestPartialSolution.getTree())){ - iterator.remove(); - currentNegExamples.remove(tree2Individual.get(tree)); + for (Iterator<QueryTree<String>> iterator = currentNegExampleTrees.iterator(); iterator.hasNext();) { + tree = iterator.next(); + if(tree.isSubsumedBy(bestPartialSolution.getTree())){ + iterator.remove(); + currentNegExamples.remove(tree2Individual.get(tree)); + } } + //build the current combined solution + currentBestSolution = buildCombinedSolution(); + + logger.info("combined accuracy: " + df.format(currentBestSolution.getAccuracy())); + } else { + logger.info("no tree found, which satisfies the minimum criteria - the best was: " + + currentBestSolution.getDescription().toManchesterSyntaxString(baseURI, prefixes) + + " with score " + currentBestSolution.getScore()); } - currentBestSolution = buildCombinedSolution(); - } while (!(stop || currentPosExampleTrees.isEmpty())); + + }; isRunning = false; @@ -234,6 +266,119 @@ } + private void computeNextPartialSolution(){ + logger.info("Computing best partial solution..."); + currentlyBestScore = 0d; + partialSolutionStartTime = System.currentTimeMillis(); + initTodoList(currentPosExampleTrees, currentNegExampleTrees); + + EvaluatedQueryTree<String> currentElement; + while(!partialSolutionTerminationCriteriaSatisfied()){ + logger.trace("TODO list size: " + todoList.size()); + //pick best element from todo list + currentElement = todoList.poll(); + //generate the LGG between the chosen tree and each uncovered positive example + for (QueryTree<String> example : currentElement.getFalseNegatives()) { + QueryTree<String> tree = currentElement.getTree(); + + //compute the LGG + lggMon.start(); + QueryTree<String> lgg = lggGenerator.getLGG(tree, example); + lggMon.stop(); + + //evaluate the LGG + EvaluatedQueryTree<String> solution = evaluate(lgg, true); + double score = solution.getScore(); + double mas = heuristic.getMaximumAchievableScore(solution); + + if(score >= currentlyBestScore){ + //add to todo list, if not already contained in todo list or solution list + todo(solution); + if(solution.getScore() > currentlyBestScore){ + logger.info("Got better solution:" + solution.getTreeScore()); + } + currentlyBestScore = solution.getScore(); + } else if(mas < currentlyBestScore){ + todo(solution); + } else { + System.out.println("Too general"); + } + currentPartialSolutions.add(currentElement); + + } + currentPartialSolutions.add(currentElement); + } + long endTime = System.currentTimeMillis(); + logger.info("...finished in " + (endTime-partialSolutionStartTime) + "ms."); + EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription(); + + logger.info("Best partial solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()) + "\n(" + bestPartialSolution.getScore() + ")"); + + logger.trace("LGG time: " + lggMon.getTotal() + "ms"); + logger.trace("Avg. LGG time: " + lggMon.getAvg() + "ms"); + logger.info("#LGG computations: " + lggMon.getHits()); + logger.trace("Subsumption test time: " + subMon.getTotal() + "ms"); + logger.trace("Avg. subsumption test time: " + subMon.getAvg() + "ms"); + logger.trace("#Subsumption tests: " + subMon.getHits()); + } + + private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ + //1. get a score for the coverage = recall oriented + //compute positive examples which are not covered by LGG + List<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); + Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(); + for (QueryTree<String> queryTree : uncoveredPositiveExampleTrees) { + uncoveredPosExamples.add(tree2Individual.get(queryTree)); + } + //compute negative examples which are covered by LGG + Collection<QueryTree<String>> coveredNegativeExampleTrees = getCoveredTrees(tree, currentNegExampleTrees); + Set<Individual> coveredNegExamples = new TreeSet<Individual>(); + for (QueryTree<String> queryTree : coveredNegativeExampleTrees) { + coveredNegExamples.add(tree2Individual.get(queryTree)); + } + //compute score + int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size(); + double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size(); + double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0) + ? 0 + : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); + + double coverageScore = Heuristics.getFScore(recall, precision, coverageBeta); + + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int nrOfSpecificNodes = 0; + for (QueryTree<String> childNode : tree.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + nrOfSpecificNodes++; + } + } + double specifityScore = 0d; + if(useSpecifity){ + specifityScore = Math.log(nrOfSpecificNodes); + } + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + + QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, + new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, + coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), + specifityScore, nrOfSpecificNodes); + +// QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, +// null,null,null,null, +// specifityScore, nrOfSpecificNodes); + + EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore); + + //TODO use only the heuristic to compute the score + score = heuristic.getScore(evaluatedTree); + queryTreeScore.setScore(score); + queryTreeScore.setAccuracy(score); + + return evaluatedTree; + } + private EvaluatedDescription buildCombinedSolution(){ if(partialSolutions.size() == 1){ EvaluatedDescription combinedSolution = partialSolutions.get(0).asEvaluatedDescription(); @@ -288,58 +433,8 @@ lggMon.reset(); } - private void computeLGG(){ - logger.info("Computing best partial solution..."); - currentlyBestScore = 0d; - - initTodoList(currentPosExampleTrees, currentNegExampleTrees); - - long startTime = System.currentTimeMillis(); - EvaluatedQueryTree<String> currentElement; - do{ - logger.trace("TODO list size: " + todoList.size()); - //pick best element from todo list - currentElement = todoList.poll(); - //generate the LGG between the chosen tree and each uncovered positive example - for (QueryTree<String> example : currentElement.getFalseNegatives()) { - QueryTree<String> tree = currentElement.getTree(); - - //compute the LGG - lggMon.start(); - QueryTree<String> lgg = lggGenerator.getLGG(tree, example); - lggMon.stop(); - - //evaluate the LGG - EvaluatedQueryTree<String> solution = evaluate(lgg, true); - - if(solution.getScore() >= currentlyBestScore){ - //add to todo list, if not already contained in todo list or solution list - todo(solution); - if(solution.getScore() > currentlyBestScore){ - logger.info("Got better solution:" + solution.getTreeScore()); - } - currentlyBestScore = solution.getScore(); - } - currentPartialSolutions.add(currentElement); - - } - currentPartialSolutions.add(currentElement); -// todoList.remove(currentElement); - } while(!terminationCriteriaSatisfied()); - long endTime = System.currentTimeMillis(); - logger.info("...finished in " + (endTime-startTime) + "ms."); - EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription(); - - logger.info("Best partial solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()) + "\n(" + bestPartialSolution.getScore() + ")"); - - logger.trace("LGG time: " + lggMon.getTotal() + "ms"); - logger.trace("Avg. LGG time: " + lggMon.getAvg() + "ms"); - logger.trace("#LGG computations: " + lggMon.getHits()); - logger.trace("Subsumption test time: " + subMon.getTotal() + "ms"); - logger.trace("Avg. subsumption test time: " + subMon.getAvg() + "ms"); - logger.trace("#Subsumption tests: " + subMon.getHits()); - } + /* (non-Javadoc) * @see org.dllearner.core.StoppableLearningAlgorithm#stop() */ @@ -411,58 +506,7 @@ return treeCache; } - private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ - //1. get a score for the coverage = recall oriented - //compute positive examples which are not covered by LGG - List<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); - Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(); - for (QueryTree<String> queryTree : uncoveredPositiveExampleTrees) { - uncoveredPosExamples.add(tree2Individual.get(queryTree)); - } - //compute negative examples which are covered by LGG - Collection<QueryTree<String>> coveredNegativeExampleTrees = getCoveredTrees(tree, currentNegExampleTrees); - Set<Individual> coveredNegExamples = new TreeSet<Individual>(); - for (QueryTree<String> queryTree : coveredNegativeExampleTrees) { - coveredNegExamples.add(tree2Individual.get(queryTree)); - } - //compute score - int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size(); - double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size(); - double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0) - ? 0 - : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); - - double beta = 0.5; - double coverageScore = Heuristics.getFScore(recall, precision, beta); - - //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented - int nrOfSpecificNodes = 0; - for (QueryTree<String> childNode : tree.getChildrenClosure()) { - if(!childNode.getUserObject().equals("?")){ - nrOfSpecificNodes++; - } - } - double specifityScore = 0d; - if(useSpecifity){ - specifityScore = Math.log(nrOfSpecificNodes); - } - - //3.compute the total score - double score = coverageWeight * coverageScore + specifityWeight * specifityScore; - - QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, - new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, - coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), - specifityScore, nrOfSpecificNodes); - -// QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, -// null,null,null,null, -// specifityScore, nrOfSpecificNodes); - - EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore); - - return evaluatedTree; - } + /** * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. @@ -535,9 +579,21 @@ } private boolean terminationCriteriaSatisfied(){ - return stop || todoList.isEmpty() || currentPosExampleTrees.isEmpty(); + return stop || isTimeExpired() || currentPosExampleTrees.isEmpty(); } + private boolean partialSolutionTerminationCriteriaSatisfied(){ + return stop || todoList.isEmpty() || currentPosExampleTrees.isEmpty() || isPartialSolutionTimeExpired() || isTimeExpired(); + } + + private boolean isTimeExpired(){ + return maxExecutionTimeInSeconds <= 0 ? false : (System.currentTimeMillis() - startTime)/1000d >= maxExecutionTimeInSeconds; + } + + private boolean isPartialSolutionTimeExpired(){ + return maxTreeComputationTimeInSeconds <= 0 ? false : (System.currentTimeMillis() - partialSolutionStartTime)/1000d >= maxTreeComputationTimeInSeconds; + } + /** * Add tree to todo list if not already contained in that list or the solutions. * @param solution Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -13,6 +13,7 @@ import org.dllearner.core.Heuristic; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics; +import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.learningproblems.QueryTreeScore; import org.dllearner.utilities.owl.ConceptComparator; @@ -23,6 +24,8 @@ @ComponentAnn(name = "QueryTreeHeuristic", shortName = "qtree_heuristic", version = 0.1) public class QueryTreeHeuristic extends AbstractComponent implements Heuristic, Comparator<EvaluatedQueryTree<String>>{ + private HeuristicType heuristicType = HeuristicType.PRED_ACC; + // F score beta value private double coverageBeta = 1; @@ -30,6 +33,8 @@ private double specifityWeight = 0.1; + private double posExamplesWeight = 1; + // syntactic comparison as final comparison criterion private ConceptComparator conceptComparator = new ConceptComparator(); @@ -43,23 +48,88 @@ public double getScore(EvaluatedQueryTree<String> tree){ QueryTreeScore treeScore = tree.getTreeScore(); - //TODO - double score = treeScore.getScore(); + Set<Individual> truePositives = treeScore.getCoveredPositives(); + Set<Individual> trueNegatives = treeScore.getNotCoveredNegatives(); + Set<Individual> falsePositives = treeScore.getNotCoveredPositives(); + Set<Individual> falseNegatives = treeScore.getCoveredNegatives(); + double tp = truePositives.size(); + double tn = trueNegatives.size(); + double fp = falsePositives.size(); + double fn = falseNegatives.size(); + + double score = 0; + switch(heuristicType){ + case FMEASURE : + score = Heuristics.getFScore(tp/(tp+fn), tp/(tp+fp), posExamplesWeight);break; + case PRED_ACC : + score = (posExamplesWeight * tp + tn) / (posExamplesWeight * (tp + fn) + tn + fp);break; + case ENTROPY :{ + double total = tp + fn; + double pp = tp / total; + double pn = fn / total; + score = pp * Math.log(pp) + pn * Math.log(pn); + break;} + case MATTHEWS_CORRELATION : + score = (tp * tn - fp * fn) / Math.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn));break; + case YOUDEN_INDEX : score = tp / (tp + fn) + tn / (fp + tn) - 1;break; + default: + break; + + } + return score; } - private double getPredictedAccuracy(EvaluatedQueryTree<String> tree){ + /** + * Returns the maximum achievable score according to the used score function. + * @return + */ + public double getMaximumAchievableScore(EvaluatedQueryTree<String> tree) { QueryTreeScore treeScore = tree.getTreeScore(); Set<Individual> truePositives = treeScore.getCoveredPositives(); Set<Individual> trueNegatives = treeScore.getNotCoveredNegatives(); Set<Individual> falsePositives = treeScore.getNotCoveredPositives(); Set<Individual> falseNegatives = treeScore.getCoveredNegatives(); - return 0; + double tp = truePositives.size(); + double tn = trueNegatives.size(); + double fp = falsePositives.size(); + double fn = falseNegatives.size(); + + return getMaximumAchievableScore(tp, tn, fp, fn); } + + /** + * Returns the maximum achievable score according to the used score function. + * @param tp + * @param tn + * @param fp + * @param fn + * @return + */ + private double getMaximumAchievableScore(double tp, double tn, double fp, double fn) { + double mas = 0d; + switch (heuristicType) { + case FMEASURE: + break; + case PRED_ACC: + mas = (posExamplesWeight * tp + tn - fp) / (posExamplesWeight * (tp + fn) + tn + fp); + break; + case ENTROPY: + break; + case MATTHEWS_CORRELATION: + break; + case YOUDEN_INDEX: + break; + default: + break; + } + return mas; + } + /* (non-Javadoc) * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ @@ -75,5 +145,19 @@ return conceptComparator.compare(tree1.asEvaluatedDescription().getDescription(), tree2.asEvaluatedDescription().getDescription()); } } + + /** + * @param heuristicType the heuristicType to set + */ + public void setHeuristicType(HeuristicType heuristicType) { + this.heuristicType = heuristicType; + } + + /** + * @param posExamplesWeight the posExamplesWeight to set + */ + public void setPosExamplesWeight(double posExamplesWeight) { + this.posExamplesWeight = posExamplesWeight; + } } Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/Heuristics.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -29,7 +29,7 @@ */ public class Heuristics { - public static enum HeuristicType { PRED_ACC, AMEASURE, JACCARD, FMEASURE, GEN_FMEASURE }; + public static enum HeuristicType { PRED_ACC, AMEASURE, JACCARD, FMEASURE, GEN_FMEASURE, ENTROPY, MATTHEWS_CORRELATION, YOUDEN_INDEX }; /** * Computes F1-Score. Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/QueryTreeScore.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/QueryTreeScore.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/QueryTreeScore.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -16,7 +16,7 @@ private double score; - private double coverageScore; + private double accuracy; private double specifityScore; private int nrOfSpecificNodes; @@ -26,12 +26,12 @@ private Set<Individual> negAsPos; private Set<Individual> negAsNeg; - public QueryTreeScore(double score, double coverageScore, + public QueryTreeScore(double score, double accuracy, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg, double specifityScore, int nrOfSpecificNodes) { super(); this.score = score; - this.coverageScore = coverageScore; + this.accuracy = accuracy; this.posAsPos = posAsPos; this.posAsNeg = posAsNeg; this.negAsPos = negAsPos; @@ -46,15 +46,29 @@ public double getScore() { return score; } + + /** + * @param score the score to set + */ + public void setScore(double score) { + this.score = score; + } /* (non-Javadoc) * @see org.dllearner.core.Score#getAccuracy() */ @Override public double getAccuracy() { - return score; + return accuracy; } + /** + * @param accuracy the accuracy to set + */ + public void setAccuracy(double accuracy) { + this.accuracy = accuracy; + } + public Set<Individual> getCoveredNegatives() { return negAsPos; } @@ -77,7 +91,7 @@ @Override public String toString() { return score - + "(coverage=" + coverageScore + + "(accuracy=" + accuracy + "(+" + posAsPos.size() + "/" + (posAsPos.size() + posAsNeg.size()) + "|-" + negAsPos.size() + "/" + (negAsPos.size() + negAsNeg.size()) + ")|" + "specifity=" + specifityScore + "(" + nrOfSpecificNodes + "))"; Modified: trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -19,44 +19,49 @@ */ package org.dllearner.scripts; +import static java.util.Arrays.asList; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Random; import java.util.Set; import java.util.TreeSet; -import java.util.Map.Entry; +import joptsimple.OptionParser; +import joptsimple.OptionSet; + +import org.apache.commons.beanutils.PropertyUtils; 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.dllearner.cli.Start; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; +import org.dllearner.cli.CLI; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.parser.ParseException; import org.dllearner.utilities.Helper; -import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.datastructures.TrainTestList; import org.dllearner.utilities.statistics.Stat; -import joptsimple.OptionParser; -import joptsimple.OptionSet; +import com.google.common.base.Charsets; +import com.google.common.io.Files; -import static java.util.Arrays.*; - /** * Performs nested cross validation for the given problem. A k fold outer and l * fold inner cross validation is used. Parameters: @@ -93,6 +98,8 @@ * */ public class NestedCrossValidation { + + private File outputFile = new File("log/nested-cv.log"); /** * Entry method, which uses JOptSimple to parse parameters. @@ -115,6 +122,7 @@ parser.acceptsAll(asList( "i", "innerfolds"), "Number of inner folds.").withRequiredArg().ofType(Integer.class).describedAs("#folds"); parser.acceptsAll(asList( "p", "parameter"), "Parameter to vary.").withRequiredArg(); parser.acceptsAll(asList( "r", "pvalues", "range"), "Values of parameter. $x-$y can be used for integer ranges.").withRequiredArg(); + parser.acceptsAll(asList( "s", "stepsize", "steps"), "Step size of range.").withOptionalArg().ofType(Double.class).defaultsTo(1d); // parse options and display a message for the user in case of problems OptionSet options = null; @@ -137,8 +145,9 @@ String parameter = (String) options.valueOf("p"); String range = (String) options.valueOf("r"); String[] rangeSplit = range.split("-"); - int rangeStart = new Integer(rangeSplit[0]); - int rangeEnd = new Integer(rangeSplit[1]); + double rangeStart = Double.valueOf(rangeSplit[0]); + double rangeEnd = Double.valueOf(rangeSplit[1]); + double stepsize = (Double) options.valueOf("s"); boolean verbose = options.has("v"); // create logger (a simple logger which outputs @@ -149,11 +158,13 @@ logger.removeAllAppenders(); logger.addAppender(consoleAppender); logger.setLevel(Level.WARN); + Logger.getLogger("org.dllearner.algorithms").setLevel(Level.INFO); +// logger.addAppender(new FileAppender(layout, "nested-cv.log", false)); // disable OWL API info output java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING); System.out.println("Warning: The script is not well tested yet. (No known bugs, but needs more testing.)"); - new NestedCrossValidation(confFile, outerFolds, innerFolds, parameter, rangeStart, rangeEnd, verbose); + new NestedCrossValidation(confFile, outerFolds, innerFolds, parameter, rangeStart, rangeEnd, stepsize, verbose); // an option is missing => print help screen and message } else { @@ -163,14 +174,24 @@ } - public NestedCrossValidation(File confFile, int outerFolds, int innerFolds, String parameter, int startValue, int endValue, boolean verbose) throws FileNotFoundException, ComponentInitException, ParseException, org.dllearner.confparser.ParseException { + private void print(String s){ + try { + Files.append(s + "\n", outputFile , Charsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println(s); + } + + public NestedCrossValidation(File confFile, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { DecimalFormat df = new DecimalFormat(); ComponentManager cm = ComponentManager.getInstance(); - Start start = new Start(confFile); + CLI start = new CLI(confFile); + start.init(); AbstractLearningProblem lp = start.getLearningProblem(); - + System.out.println(lp); if(!(lp instanceof PosNegLP)) { System.out.println("Positive only learning not supported yet."); System.exit(0); @@ -196,16 +217,16 @@ for(int currOuterFold=0; currOuterFold<outerFolds; currOuterFold++) { - System.out.println("Outer fold " + currOuterFold); + print("Outer fold " + currOuterFold); TrainTestList posList = posLists.get(currOuterFold); TrainTestList negList = negLists.get(currOuterFold); // measure relevant criterion (accuracy, F-measure) over different parameter values - Map<Integer,Stat> paraStats = new HashMap<Integer,Stat>(); + Map<Double,Stat> paraStats = new HashMap<Double,Stat>(); - for(int currParaValue=startValue; currParaValue<=endValue; currParaValue++) { + for(double currParaValue=startValue; currParaValue<=endValue; currParaValue+=stepsize) { - System.out.println(" Parameter value " + currParaValue + ":"); + print(" Parameter value " + currParaValue + ":"); // split train folds again (computation of inner folds for each parameter // value is redundant, but not a big problem) List<Individual> trainPosList = posList.getTrainList(); @@ -219,19 +240,24 @@ for(int currInnerFold=0; currInnerFold<innerFolds; currInnerFold++) { - System.out.println(" Inner fold " + currInnerFold + ":"); + print(" Inner fold " + currInnerFold + ":"); // get positive & negative examples for training run Set<Individual> posEx = new TreeSet<Individual>(innerPosLists.get(currInnerFold).getTrainList()); Set<Individual> negEx = new TreeSet<Individual>(innerNegLists.get(currInnerFold).getTrainList()); // read conf file and exchange options for pos/neg examples // and parameter to optimise - start = new Start(confFile); + start = new CLI(confFile); + start.init(); AbstractLearningProblem lpIn = start.getLearningProblem(); - cm.applyConfigEntry(lpIn, "positiveExamples", Datastructures.individualSetToStringSet(posEx)); - cm.applyConfigEntry(lpIn, "negativeExamples", Datastructures.individualSetToStringSet(negEx)); + ((PosNegLP)lpIn).setPositiveExamples(posEx); + ((PosNegLP)lpIn).setNegativeExamples(negEx); AbstractCELA laIn = start.getLearningAlgorithm(); - cm.applyConfigEntry(laIn, parameter, (double)currParaValue); + try { + PropertyUtils.setSimpleProperty(laIn, parameter, currParaValue); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } lpIn.init(); laIn.init(); @@ -263,15 +289,15 @@ paraCriterionStat.addNumber(accuracy); - System.out.println(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); - System.out.println(" accuracy: " + df.format(accuracy) + "%"); - System.out.println(" precision: " + df.format(precision) + "%"); - System.out.println(" recall: " + df.format(recall) + "%"); - System.out.println(" F measure: " + df.format(fmeasure) + "%"); + print(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); + print(" accuracy: " + df.format(accuracy) + "%"); + print(" precision: " + df.format(precision) + "%"); + print(" recall: " + df.format(recall) + "%"); + print(" F measure: " + df.format(fmeasure) + "%"); if(verbose) { - System.out.println(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); - System.out.println(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); + print(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); + print(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); } // free memory @@ -284,28 +310,33 @@ } // decide for the best parameter - System.out.println(" Summary over parameter values:"); - int bestPara = startValue; + print(" Summary over parameter values:"); + double bestPara = startValue; double bestValue = Double.NEGATIVE_INFINITY; - for(Entry<Integer,Stat> entry : paraStats.entrySet()) { - int para = entry.getKey(); + for(Entry<Double,Stat> entry : paraStats.entrySet()) { + double para = entry.getKey(); Stat stat = entry.getValue(); - System.out.println(" value " + para + ": " + stat.prettyPrint("%")); + print(" value " + para + ": " + stat.prettyPrint("%")); if(stat.getMean() > bestValue) { bestPara = para; bestValue = stat.getMean(); } } - System.out.println(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); - System.out.println(" Learn on Outer fold:"); + print(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); + print(" Learn on Outer fold:"); // start a learning process with this parameter and evaluate it on the outer fold - start = new Start(confFile); + start = new CLI(confFile); + start.init(); AbstractLearningProblem lpOut = start.getLearningProblem(); - cm.applyConfigEntry(lpOut, "positiveExamples", Datastructures.individualListToStringSet(posLists.get(currOuterFold).getTrainList())); - cm.applyConfigEntry(lpOut, "negativeExamples", Datastructures.individualListToStringSet(negLists.get(currOuterFold).getTrainList())); + ((PosNegLP)lpOut).setPositiveExamples(new TreeSet<Individual>(posLists.get(currOuterFold).getTrainList())); + ((PosNegLP)lpOut).setNegativeExamples(new TreeSet<Individual>(negLists.get(currOuterFold).getTrainList())); AbstractCELA laOut = start.getLearningAlgorithm(); - cm.applyConfigEntry(laOut, parameter, (double)bestPara); + try { + PropertyUtils.setSimpleProperty(laOut, parameter, bestPara); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } lpOut.init(); laOut.init(); @@ -332,15 +363,15 @@ double recall = 100 * (double) posCorrect.size() / (posCorrect.size() + posError.size()); double fmeasure = 2 * (precision * recall) / (precision + recall); - System.out.println(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); - System.out.println(" accuracy: " + df.format(accuracy) + "%"); - System.out.println(" precision: " + df.format(precision) + "%"); - System.out.println(" recall: " + df.format(recall) + "%"); - System.out.println(" F measure: " + df.format(fmeasure) + "%"); + print(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); + print(" accuracy: " + df.format(accuracy) + "%"); + print(" precision: " + df.format(precision) + "%"); + print(" recall: " + df.format(recall) + "%"); + print(" F measure: " + df.format(fmeasure) + "%"); if(verbose) { - System.out.println(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); - System.out.println(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); + print(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); + print(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); } // update overall statistics @@ -355,14 +386,13 @@ } // overall statistics - System.out.println(); - System.out.println("*******************"); - System.out.println("* Overall Results *"); - System.out.println("*******************"); - System.out.println("accuracy: " + accOverall.prettyPrint("%")); - System.out.println("F measure: " + fOverall.prettyPrint("%")); - System.out.println("precision: " + precisionOverall.prettyPrint("%")); - System.out.println("recall: " + recallOverall.prettyPrint("%")); + print("*******************"); + print("* Overall Results *"); + print("*******************"); + print("accuracy: " + accOverall.prettyPrint("%")); + print("F measure: " + fOverall.prettyPrint("%")); + print("precision: " + precisionOverall.prettyPrint("%")); + print("recall: " + recallOverall.prettyPrint("%")); } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-07 13:43:54 UTC (rev 4262) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-08 11:45:45 UTC (rev 4263) @@ -53,8 +53,8 @@ public class QTLEvaluation { int nrOfFolds = 10; - private int nrOfPosExamples = 100; - private int nrOfNegExamples = 100; + private int nrOfPosExamples = 300; + private int nrOfNegExamples = 300; List<String> posExamples = Lists.newArrayList( "http://dl-learner.org/carcinogenesis#d1", @@ -496,13 +496,13 @@ lp.setReasoner(reasoner); lp.init(); QTL2Disjunctive la = new QTL2Disjunctive(lp, reasoner); -// la.init(); -// la.start(); + la.init(); + la.start(); CrossValidation.outputFile = new File("log/qtl-cv.log"); CrossValidation.writeToFile = true; CrossValidation.multiThreaded = multiThreaded; - CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); +// CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); long endTime = System.currentTimeMillis(); System.err.println((endTime - startTime) + "ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-05-08 14:40:17
|
Revision: 4265 http://sourceforge.net/p/dl-learner/code/4265 Author: lorenz_b Date: 2014-05-08 14:40:15 +0000 (Thu, 08 May 2014) Log Message: ----------- Extended CV script. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-core/src/main/java/org/dllearner/utilities/statistics/Stat.java trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -17,6 +17,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.collections.ListUtils; import org.apache.log4j.Logger; import org.dllearner.algorithms.qtl.cache.QueryTreeCache; import org.dllearner.algorithms.qtl.datastructures.QueryTree; @@ -69,7 +70,7 @@ private Queue<EvaluatedQueryTree<String>> todoList; private SortedSet<EvaluatedQueryTree<String>> currentPartialSolutions; - private double currentlyBestScore = 0d; + private double bestCurrentScore = 0d; private List<QueryTree<String>> currentPosExampleTrees; private List<QueryTree<String>> currentNegExampleTrees; @@ -114,11 +115,17 @@ private double posWeight = 2; // minimum score a query tree must have to be part of the solution private double minimumTreeScore = 0.2; + //If yes, then the algorithm tries to cover all positive examples. Note that while this improves accuracy on the testing set, + //it may lead to overfitting + private boolean tryFullCoverage; + //algorithm will terminate immediately when a correct definition is found + private boolean stopOnFirstDefinition; private long startTime; - private long partialSolutionStartTime; + private double startPosExamplesSize; + public QTL2Disjunctive() {} public QTL2Disjunctive(PosNegLP learningProblem, AbstractReasonerComponent reasoner) throws LearningProblemUnsupportedException{ @@ -156,7 +163,7 @@ if(heuristic == null){ heuristic = new QueryTreeHeuristic(); - heuristic.setPosExamplesWeight(2); + heuristic.setPosExamplesWeight(posWeight); } logger.info("Initializing..."); @@ -168,6 +175,8 @@ currentPosExamples = new TreeSet<Individual>(lp.getPositiveExamples()); currentNegExamples = new TreeSet<Individual>(lp.getNegativeExamples()); + startPosExamplesSize = currentPosExamples.size(); + //get the query trees generateTrees(); @@ -178,6 +187,15 @@ //console rendering of class expressions ToStringRenderer.getInstance().setRenderer(new ManchesterOWLSyntaxOWLObjectRendererImpl()); ToStringRenderer.getInstance().setShortFormProvider(new SimpleShortFormProvider()); + + //compute the LGG for all examples + //this allows us to prune all other trees because we can omit paths in trees which are contained in all positive + //as well as negative examples +// List<QueryTree<String>> allExamplesTrees = new ArrayList<QueryTree<String>>(); +// allExamplesTrees.addAll(currentPosExampleTrees); +// allExamplesTrees.addAll(currentNegExampleTrees); +// QueryTree<String> lgg = lggGenerator.getLGG(allExamplesTrees); +// lgg.dump(); } private void generateTrees(){ @@ -204,7 +222,7 @@ String setup = "Setup:"; setup += "\n#Pos. examples:" + currentPosExamples.size(); setup += "\n#Neg. examples:" + currentNegExamples.size(); - setup += "\nCoverage beta:" + coverageBeta; + setup += "\nPos. weight(beta):" + posWeight; logger.info(setup); logger.info("Running..."); startTime = System.currentTimeMillis(); @@ -268,7 +286,7 @@ private void computeNextPartialSolution(){ logger.info("Computing best partial solution..."); - currentlyBestScore = 0d; + bestCurrentScore = Double.NEGATIVE_INFINITY; partialSolutionStartTime = System.currentTimeMillis(); initTodoList(currentPosExampleTrees, currentNegExampleTrees); @@ -291,14 +309,14 @@ double score = solution.getScore(); double mas = heuristic.getMaximumAchievableScore(solution); - if(score >= currentlyBestScore){ + if(score >= bestCurrentScore){ //add to todo list, if not already contained in todo list or solution list todo(solution); - if(solution.getScore() > currentlyBestScore){ + if(solution.getScore() > bestCurrentScore){ logger.info("Got better solution:" + solution.getTreeScore()); } - currentlyBestScore = solution.getScore(); - } else if(mas < currentlyBestScore){ + bestCurrentScore = solution.getScore(); + } else if(mas < bestCurrentScore){ todo(solution); } else { System.out.println("Too general"); @@ -431,6 +449,8 @@ subMon.reset(); lggMon.reset(); + + bestCurrentScore = minimumTreeScore; } @@ -578,8 +598,31 @@ return tree1.isSubsumedBy(tree2) && tree2.isSubsumedBy(tree1); } - private boolean terminationCriteriaSatisfied(){ - return stop || isTimeExpired() || currentPosExampleTrees.isEmpty(); + private boolean terminationCriteriaSatisfied() { + //stop was called or time expired + if(stop || isTimeExpired()){ + return true; + } + + // stop if there are no more positive examples to cover + if (stopOnFirstDefinition && currentPosExamples.isEmpty()) { + return true; + } + + // we stop when the score of the last tree added is too low + // (indicating that the algorithm could not find anything appropriate + // in the timeframe set) + if (bestCurrentScore < minimumTreeScore) { + return true; + } + + // stop when almost all positive examples have been covered + if (tryFullCoverage) { + return false; + } else { + int maxPosRemaining = (int) Math.ceil(startPosExamplesSize * 0.05d); + return (currentPosExamples.size() <= maxPosRemaining); + } } private boolean partialSolutionTerminationCriteriaSatisfied(){ @@ -635,6 +678,13 @@ this.coverageBeta = coverageBeta; } + /** + * @param posWeight the posWeight to set + */ + public void setPosWeight(double posWeight) { + this.posWeight = posWeight; + } + /* (non-Javadoc) * @see java.lang.Object#clone() */ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -63,7 +63,7 @@ case FMEASURE : score = Heuristics.getFScore(tp/(tp+fn), tp/(tp+fp), posExamplesWeight);break; case PRED_ACC : - score = (posExamplesWeight * tp + tn) / (posExamplesWeight * (tp + fn) + tn + fp);break; + score = (tp + posExamplesWeight * tn) / ((tp + fn) + posExamplesWeight * (tn + fp));break; case ENTROPY :{ double total = tp + fn; double pp = tp / total; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -161,7 +161,7 @@ label += "Values: " + object.getLiterals(); } } - label += object.isResourceNode() + "," + object.isLiteralNode(); +// label += object.isResourceNode() + "," + object.isLiteralNode(); return label; } }; @@ -801,13 +801,16 @@ writer.println(ren); for (QueryTree<N> child : getChildren()) { Object edge = getEdge(child); - if (edge != null) { + boolean meaningful = !edge.equals(RDF.type.getURI()) || meaningful(child); + if (edge != null && meaningful) { writer.print(sb.toString()); writer.print("--- "); writer.print(edge); writer.print(" ---\n"); } - child.dump(writer, indent); + if(meaningful){ + child.dump(writer, indent); + } } writer.flush(); // int depth = getPathToRoot().size(); @@ -832,6 +835,23 @@ // writer.flush(); } + private boolean meaningful(QueryTree<N> tree){ + if(tree.isResourceNode() || tree.isLiteralNode()){ + return true; + } else { + for (QueryTree<N> child : tree.getChildren()) { + Object edge = tree.getEdge(child); + if(!edge.equals(RDFS.subClassOf.getURI())){ + return true; + } else if(child.isResourceNode()){ + return true; + } else if(meaningful(child)){ + return true; + } + } + } + return false; + } public List<N> fillDepthFirst() { List<N> results = new ArrayList<N>(); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/statistics/Stat.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/statistics/Stat.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/components-core/src/main/java/org/dllearner/utilities/statistics/Stat.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -75,6 +75,14 @@ } } + public void add(Stat stat){ + count += stat.count; + sum += stat.sum; + squareSum += stat.squareSum; + min = Math.min(min, stat.min); + max = Math.max(max, stat.max); + } + /** * Add a number to this object. * Modified: trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -26,6 +26,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -60,6 +61,7 @@ import org.dllearner.utilities.statistics.Stat; import com.google.common.base.Charsets; +import com.google.common.collect.Lists; import com.google.common.io.Files; /** @@ -100,6 +102,15 @@ public class NestedCrossValidation { private File outputFile = new File("log/nested-cv.log"); + DecimalFormat df = new DecimalFormat(); + + // overall statistics + Stat globalAcc = new Stat(); + Stat globalF = new Stat(); + Stat globalRecall = new Stat(); + Stat globalPrecision = new Stat(); + + Map<Double,Stat> globalParaStats = new HashMap<Double,Stat>(); /** * Entry method, which uses JOptSimple to parse parameters. @@ -115,8 +126,7 @@ OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); - parser.acceptsAll(asList("c", "conf"), "Conf file to use.").withRequiredArg().ofType( - File.class); + parser.acceptsAll(asList("c", "conf"), "The comma separated list of conffiles to be used.").withRequiredArg().describedAs("file1, file2, ..."); parser.acceptsAll(asList( "v", "verbose"), "Be more verbose."); parser.acceptsAll(asList( "o", "outerfolds"), "Number of outer folds.").withRequiredArg().ofType(Integer.class).describedAs("#folds"); parser.acceptsAll(asList( "i", "innerfolds"), "Number of inner folds.").withRequiredArg().ofType(Integer.class).describedAs("#folds"); @@ -139,7 +149,12 @@ // all options present => start nested cross validation } else if(options.has("c") && options.has("o") && options.has("i") && options.has("p") && options.has("r")) { // read all options in variables and parse option values - File confFile = (File) options.valueOf("c"); + String confFilesString = (String) options.valueOf("c"); + List<File> confFiles = new ArrayList<File>(); + for (String fileString : confFilesString.split(",")) { + confFiles.add(new File(fileString.trim())); + } + int outerFolds = (Integer) options.valueOf("o"); int innerFolds = (Integer) options.valueOf("i"); String parameter = (String) options.valueOf("p"); @@ -164,7 +179,7 @@ java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING); System.out.println("Warning: The script is not well tested yet. (No known bugs, but needs more testing.)"); - new NestedCrossValidation(confFile, outerFolds, innerFolds, parameter, rangeStart, rangeEnd, stepsize, verbose); + new NestedCrossValidation(confFiles, outerFolds, innerFolds, parameter, rangeStart, rangeEnd, stepsize, verbose); // an option is missing => print help screen and message } else { @@ -182,16 +197,52 @@ } System.out.println(s); } + + public NestedCrossValidation(File confFile, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { + this(Lists.newArrayList(confFile), outerFolds, innerFolds, parameter, startValue, endValue, stepsize, verbose); + } - public NestedCrossValidation(File confFile, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { + public NestedCrossValidation(List<File> confFiles, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { - DecimalFormat df = new DecimalFormat(); - ComponentManager cm = ComponentManager.getInstance(); + for (File confFile : confFiles) { + print(confFile.getPath()); + validate(confFile, outerFolds, innerFolds, parameter, startValue, endValue, stepsize, verbose); + } + print("********************************************"); + print("********************************************"); + print("********************************************"); + + // decide for the best parameter + print(" Summary over parameter values:"); + double bestPara = startValue; + double bestValue = Double.NEGATIVE_INFINITY; + for (Entry<Double, Stat> entry : globalParaStats.entrySet()) { + double para = entry.getKey(); + Stat stat = entry.getValue(); + print(" value " + para + ": " + stat.prettyPrint("%")); + if (stat.getMean() > bestValue) { + bestPara = para; + bestValue = stat.getMean(); + } + } + print(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); + + // overall statistics + print("*******************"); + print("* Overall Results *"); + print("*******************"); + print("accuracy: " + globalAcc.prettyPrint("%")); + print("F measure: " + globalF.prettyPrint("%")); + print("precision: " + globalPrecision.prettyPrint("%")); + print("recall: " + globalRecall.prettyPrint("%")); + + } + + private void validate(File confFile, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws IOException, ComponentInitException{ CLI start = new CLI(confFile); start.init(); AbstractLearningProblem lp = start.getLearningProblem(); - System.out.println(lp); if(!(lp instanceof PosNegLP)) { System.out.println("Positive only learning not supported yet."); System.exit(0); @@ -213,7 +264,7 @@ Stat accOverall = new Stat(); Stat fOverall = new Stat(); Stat recallOverall = new Stat(); - Stat precisionOverall = new Stat(); + Stat precisionOverall = new Stat(); for(int currOuterFold=0; currOuterFold<outerFolds; currOuterFold++) { @@ -302,11 +353,15 @@ // free memory rs.releaseKB(); - cm.freeAllComponents(); } paraStats.put(currParaValue, paraCriterionStat); - + Stat globalParaStat = globalParaStats.get(currParaValue); + if(globalParaStat == null){ + globalParaStat = new Stat(); + globalParaStats.put(currParaValue, globalParaStat); + } + globalParaStat.add(paraCriterionStat); } // decide for the best parameter @@ -382,9 +437,13 @@ // free memory rs.releaseKB(); - cm.freeAllComponents(); } + globalAcc.add(accOverall); + globalF.add(fOverall); + globalPrecision.add(precisionOverall); + globalRecall.add(recallOverall); + // overall statistics print("*******************"); print("* Overall Results *"); @@ -393,7 +452,6 @@ print("F measure: " + fOverall.prettyPrint("%")); print("precision: " + precisionOverall.prettyPrint("%")); print("recall: " + recallOverall.prettyPrint("%")); - } // convenience methods, which takes a list of examples and divides them in Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-08 14:39:43 UTC (rev 4264) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-08 14:40:15 UTC (rev 4265) @@ -496,13 +496,13 @@ lp.setReasoner(reasoner); lp.init(); QTL2Disjunctive la = new QTL2Disjunctive(lp, reasoner); - la.init(); - la.start(); +// la.init(); +// la.start(); CrossValidation.outputFile = new File("log/qtl-cv.log"); CrossValidation.writeToFile = true; CrossValidation.multiThreaded = multiThreaded; -// CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); + CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); long endTime = System.currentTimeMillis(); System.err.println((endTime - startTime) + "ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-05-08 18:19:35
|
Revision: 4266 http://sourceforge.net/p/dl-learner/code/4266 Author: lorenz_b Date: 2014-05-08 18:19:32 +0000 (Thu, 08 May 2014) Log Message: ----------- Extended CV script. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 14:40:15 UTC (rev 4265) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 18:19:32 UTC (rev 4266) @@ -110,7 +110,7 @@ private double minCoveredPosExamplesFraction = 0.2; // maximum execution time to compute a part of the solution - private double maxTreeComputationTimeInSeconds = 60; + private double maxTreeComputationTimeInSeconds = 10; // how important not to cover negatives private double posWeight = 2; // minimum score a query tree must have to be part of the solution Modified: trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 14:40:15 UTC (rev 4265) +++ trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 18:19:32 UTC (rev 4266) @@ -334,9 +334,9 @@ // double negErrorRate = 100*(negError.size()/posTest.size()); double accuracy = 100*((double)(posCorrect.size()+negCorrect.size())/(posTest.size()+negTest.size())); - double precision = 100 * (double) posCorrect.size() / (posCorrect.size() + negError.size()); - double recall = 100 * (double) posCorrect.size() / (posCorrect.size() + posError.size()); - double fmeasure = 2 * (precision * recall) / (precision + recall); + double precision = 100 * (double) posCorrect.size() / (posCorrect.size() + negError.size()) == 0 ? 0 : (posCorrect.size() + negError.size()); + double recall = 100 * (double) posCorrect.size() / (posCorrect.size() + posError.size()) == 0 ? 0 : (posCorrect.size() + posError.size()); + double fmeasure = 2 * (precision * recall) / (precision + recall) == 0 ? 0 : (precision + recall); paraCriterionStat.addNumber(accuracy); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-05-09 18:13:07
|
Revision: 4267 http://sourceforge.net/p/dl-learner/code/4267 Author: lorenz_b Date: 2014-05-09 18:13:04 +0000 (Fri, 09 May 2014) Log Message: ----------- Modified CV script. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java trunk/test/qtl/breasttissue/train1.conf trunk/test/qtl/carcinogenesis/train.conf trunk/test/qtl/mutagenesis/train1.conf trunk/test/qtl/parkinsons/train.conf trunk/test/qtl/suramin/train.conf Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-09 18:13:04 UTC (rev 4267) @@ -102,19 +102,18 @@ @ConfigOption(name = "noisePercentage", defaultValue="0.0", description="the (approximated) percentage of noise within the examples") private double noisePercentage = 0.0; @ConfigOption(defaultValue = "10", name = "maxExecutionTimeInSeconds", description = "maximum execution of the algorithm in seconds") - private int maxExecutionTimeInSeconds = -1; + private int maxExecutionTimeInSeconds = 60; private double coverageWeight = 0.8; private double specifityWeight = 0.1; - private double coverageBeta = 0.5; private double minCoveredPosExamplesFraction = 0.2; // maximum execution time to compute a part of the solution private double maxTreeComputationTimeInSeconds = 10; // how important not to cover negatives - private double posWeight = 2; + private double beta = 1; // minimum score a query tree must have to be part of the solution - private double minimumTreeScore = 0.2; + private double minimumTreeScore = 0.3; //If yes, then the algorithm tries to cover all positive examples. Note that while this improves accuracy on the testing set, //it may lead to overfitting private boolean tryFullCoverage; @@ -161,10 +160,10 @@ lggGenerator = new LGGGeneratorImpl<String>(); - if(heuristic == null){ +// if(heuristic == null){ heuristic = new QueryTreeHeuristic(); - heuristic.setPosExamplesWeight(posWeight); - } + heuristic.setPosExamplesWeight(beta); +// } logger.info("Initializing..."); treeCache = new QueryTreeCache(model); @@ -222,7 +221,8 @@ String setup = "Setup:"; setup += "\n#Pos. examples:" + currentPosExamples.size(); setup += "\n#Neg. examples:" + currentNegExamples.size(); - setup += "\nPos. weight(beta):" + posWeight; + setup += "Heuristic:" + heuristic.getHeuristicType().name(); + setup += "\nbeta=" + beta; logger.info(setup); logger.info("Running..."); startTime = System.currentTimeMillis(); @@ -236,7 +236,7 @@ logger.info("#Remaining neg. examples:" + currentNegExampleTrees.size()); //compute a (partial) solution - computeNextPartialSolution(); + computeBestPartialSolution(); //pick best (partial) solution computed so far EvaluatedQueryTree<String> bestPartialSolution = currentPartialSolutions.first(); @@ -279,29 +279,31 @@ long endTime = System.currentTimeMillis(); logger.info("Finished in " + (endTime-startTime) + "ms."); - logger.info("Combined solution:\n" + OWLAPIConverter.getOWLAPIDescription(currentBestSolution.getDescription())); + logger.info("Combined solution:" + OWLAPIConverter.getOWLAPIDescription(currentBestSolution.getDescription()).toString().replace("\n", "")); logger.info(currentBestSolution.getScore()); } - private void computeNextPartialSolution(){ + private void computeBestPartialSolution(){ logger.info("Computing best partial solution..."); bestCurrentScore = Double.NEGATIVE_INFINITY; partialSolutionStartTime = System.currentTimeMillis(); initTodoList(currentPosExampleTrees, currentNegExampleTrees); EvaluatedQueryTree<String> currentElement; + QueryTree<String> currentTree; while(!partialSolutionTerminationCriteriaSatisfied()){ logger.trace("TODO list size: " + todoList.size()); //pick best element from todo list currentElement = todoList.poll(); + currentTree = currentElement.getTree(); //generate the LGG between the chosen tree and each uncovered positive example - for (QueryTree<String> example : currentElement.getFalseNegatives()) { - QueryTree<String> tree = currentElement.getTree(); - + Iterator<QueryTree<String>> it = currentElement.getFalseNegatives().iterator(); + while (it.hasNext() && !isPartialSolutionTimeExpired() && !isTimeExpired()) { + QueryTree<String> uncoveredTree = it.next(); //compute the LGG lggMon.start(); - QueryTree<String> lgg = lggGenerator.getLGG(tree, example); + QueryTree<String> lgg = lggGenerator.getLGG(currentTree, uncoveredTree); lggMon.stop(); //evaluate the LGG @@ -312,8 +314,8 @@ if(score >= bestCurrentScore){ //add to todo list, if not already contained in todo list or solution list todo(solution); - if(solution.getScore() > bestCurrentScore){ - logger.info("Got better solution:" + solution.getTreeScore()); + if(score > bestCurrentScore){ + logger.info("\tGot better solution:" + solution.getTreeScore()); } bestCurrentScore = solution.getScore(); } else if(mas < bestCurrentScore){ @@ -330,7 +332,7 @@ logger.info("...finished in " + (endTime-partialSolutionStartTime) + "ms."); EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription(); - logger.info("Best partial solution:\n" + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()) + "\n(" + bestPartialSolution.getScore() + ")"); + logger.info("Best partial solution: " + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()).toString().replace("\n", "") + "\n(" + bestPartialSolution.getScore() + ")"); logger.trace("LGG time: " + lggMon.getTotal() + "ms"); logger.trace("Avg. LGG time: " + lggMon.getAvg() + "ms"); @@ -361,7 +363,7 @@ ? 0 : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); - double coverageScore = Heuristics.getFScore(recall, precision, coverageBeta); + double coverageScore = Heuristics.getFScore(recall, precision, beta); //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented int nrOfSpecificNodes = 0; @@ -400,8 +402,6 @@ private EvaluatedDescription buildCombinedSolution(){ if(partialSolutions.size() == 1){ EvaluatedDescription combinedSolution = partialSolutions.get(0).asEvaluatedDescription(); - double accuracy = lp.getAccuracy(combinedSolution.getDescription()); - System.out.println(accuracy); return combinedSolution; } List<Description> disjuncts = new ArrayList<Description>(); @@ -423,16 +423,13 @@ Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered); Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered); - double accuracy = lp.getAccuracy(unionDescription); - System.out.println(accuracy); - //compute the coverage double recall = posCovered.size() / (double)lp.getPositiveExamples().size(); double precision = (posCovered.size() + negCovered.size() == 0) ? 0 : posCovered.size() / (double)(posCovered.size() + negCovered.size()); - double coverageScore = Heuristics.getFScore(recall, precision, coverageBeta); + double coverageScore = Heuristics.getFScore(recall, precision, beta); // ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered); // score.setAccuracy(coverageScore); @@ -442,6 +439,7 @@ } private void reset(){ + currentBestSolution = null; partialSolutions = new ArrayList<EvaluatedQueryTree<String>>(); stop = false; @@ -672,17 +670,18 @@ } /** - * @param coverageBeta the coverageBeta to set + * Default value is 1. Lower values force importance of covering positive examples. + * @param beta the beta to set */ - public void setCoverageBeta(double coverageBeta) { - this.coverageBeta = coverageBeta; + public void setBeta(double beta) { + this.beta = beta; } /** - * @param posWeight the posWeight to set + * @param maxTreeComputationTimeInSeconds the maxTreeComputationTimeInSeconds to set */ - public void setPosWeight(double posWeight) { - this.posWeight = posWeight; + public void setMaxTreeComputationTimeInSeconds(double maxTreeComputationTimeInSeconds) { + this.maxTreeComputationTimeInSeconds = maxTreeComputationTimeInSeconds; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-09 18:13:04 UTC (rev 4267) @@ -26,13 +26,6 @@ private HeuristicType heuristicType = HeuristicType.PRED_ACC; - // F score beta value - private double coverageBeta = 1; - - private double coverageWeight = 0.8; - - private double specifityWeight = 0.1; - private double posExamplesWeight = 1; // syntactic comparison as final comparison criterion @@ -63,7 +56,7 @@ case FMEASURE : score = Heuristics.getFScore(tp/(tp+fn), tp/(tp+fp), posExamplesWeight);break; case PRED_ACC : - score = (tp + posExamplesWeight * tn) / ((tp + fn) + posExamplesWeight * (tn + fp));break; + score = (1/posExamplesWeight * tp + tn) / (1/posExamplesWeight * (tp + fn) + (tn + fp));break; case ENTROPY :{ double total = tp + fn; double pp = tp / total; @@ -154,6 +147,13 @@ } /** + * @return the heuristicType + */ + public HeuristicType getHeuristicType() { + return heuristicType; + } + + /** * @param posExamplesWeight the posExamplesWeight to set */ public void setPosExamplesWeight(double posExamplesWeight) { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java 2014-05-09 18:13:04 UTC (rev 4267) @@ -65,11 +65,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " [>= " + minValue + " <= " + maxValue + "]"; + return " double[>= " + minValue + " <= " + maxValue + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " [>= " + minValue + " <= " + maxValue + "]"; + return " double[>= " + minValue + " <= " + maxValue + "]"; } public void accept(KBElementVisitor visitor) { @@ -81,7 +81,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " [>= " + minValue + " <= " + maxValue + "]"; + return " double[>= " + minValue + " <= " + maxValue + "]"; } /* (non-Javadoc) Modified: trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/scripts/src/main/java/org/dllearner/scripts/NestedCrossValidation.java 2014-05-09 18:13:04 UTC (rev 4267) @@ -22,7 +22,6 @@ import static java.util.Arrays.asList; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; @@ -43,15 +42,17 @@ import org.apache.commons.beanutils.PropertyUtils; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; +import org.apache.log4j.Layout; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.Priority; import org.apache.log4j.SimpleLayout; import org.dllearner.cli.CLI; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.PosNegLP; @@ -101,7 +102,10 @@ */ public class NestedCrossValidation { - private File outputFile = new File("log/nested-cv.log"); + + private static final Logger logger = Logger.getLogger(NestedCrossValidation.class.getName()); + + private static File logFile = new File("log/nested-cv.log"); DecimalFormat df = new DecimalFormat(); // overall statistics @@ -126,7 +130,7 @@ OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); - parser.acceptsAll(asList("c", "conf"), "The comma separated list of conffiles to be used.").withRequiredArg().describedAs("file1, file2, ..."); + parser.acceptsAll(asList("c", "conf"), "The comma separated list of config files to be used.").withRequiredArg().describedAs("file1, file2, ..."); parser.acceptsAll(asList( "v", "verbose"), "Be more verbose."); parser.acceptsAll(asList( "o", "outerfolds"), "Number of outer folds.").withRequiredArg().ofType(Integer.class).describedAs("#folds"); parser.acceptsAll(asList( "i", "innerfolds"), "Number of inner folds.").withRequiredArg().ofType(Integer.class).describedAs("#folds"); @@ -167,13 +171,18 @@ // create logger (a simple logger which outputs // its messages to the console) - SimpleLayout layout = new SimpleLayout(); + Layout layout = new PatternLayout("%m%n"); ConsoleAppender consoleAppender = new ConsoleAppender(layout); Logger logger = Logger.getRootLogger(); logger.removeAllAppenders(); logger.addAppender(consoleAppender); - logger.setLevel(Level.WARN); + logger.setLevel(Level.ERROR); Logger.getLogger("org.dllearner.algorithms").setLevel(Level.INFO); + Logger.getLogger("org.dllearner.scripts").setLevel(Level.INFO); + + FileAppender fileAppender = new FileAppender(layout, logFile.getPath(), false); + logger.addAppender(fileAppender); + fileAppender.setThreshold(Level.INFO); // logger.addAppender(new FileAppender(layout, "nested-cv.log", false)); // disable OWL API info output java.util.logging.Logger.getLogger("").setLevel(java.util.logging.Level.WARNING); @@ -188,15 +197,6 @@ } } - - private void print(String s){ - try { - Files.append(s + "\n", outputFile , Charsets.UTF_8); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println(s); - } public NestedCrossValidation(File confFile, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { this(Lists.newArrayList(confFile), outerFolds, innerFolds, parameter, startValue, endValue, stepsize, verbose); @@ -205,37 +205,38 @@ public NestedCrossValidation(List<File> confFiles, int outerFolds, int innerFolds, String parameter, double startValue, double endValue, double stepsize, boolean verbose) throws ComponentInitException, ParseException, org.dllearner.confparser.ParseException, IOException { for (File confFile : confFiles) { - print(confFile.getPath()); + logger.info("++++++++++++++++++++++++++++++++++++++++++++++"); + logger.info(confFile.getPath()); + logger.info("++++++++++++++++++++++++++++++++++++++++++++++"); validate(confFile, outerFolds, innerFolds, parameter, startValue, endValue, stepsize, verbose); } - print("********************************************"); - print("********************************************"); - print("********************************************"); + logger.info("############################################"); + logger.info("############################################"); // decide for the best parameter - print(" Summary over parameter values:"); + logger.info(" Overall summary over parameter values:"); double bestPara = startValue; double bestValue = Double.NEGATIVE_INFINITY; for (Entry<Double, Stat> entry : globalParaStats.entrySet()) { double para = entry.getKey(); Stat stat = entry.getValue(); - print(" value " + para + ": " + stat.prettyPrint("%")); + logger.info(" value " + para + ": " + stat.prettyPrint("%")); if (stat.getMean() > bestValue) { bestPara = para; bestValue = stat.getMean(); } } - print(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); + logger.info(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); // overall statistics - print("*******************"); - print("* Overall Results *"); - print("*******************"); - print("accuracy: " + globalAcc.prettyPrint("%")); - print("F measure: " + globalF.prettyPrint("%")); - print("precision: " + globalPrecision.prettyPrint("%")); - print("recall: " + globalRecall.prettyPrint("%")); + logger.info("*******************"); + logger.info("* Overall Results *"); + logger.info("*******************"); + logger.info("accuracy: " + globalAcc.prettyPrint("%")); + logger.info("F measure: " + globalF.prettyPrint("%")); + logger.info("precision: " + globalPrecision.prettyPrint("%")); + logger.info("recall: " + globalRecall.prettyPrint("%")); } @@ -255,6 +256,7 @@ Collections.shuffle(negExamples, new Random(2)); AbstractReasonerComponent rc = start.getReasonerComponent(); + rc.init(); String baseURI = rc.getBaseURI(); List<TrainTestList> posLists = getFolds(posExamples, outerFolds); @@ -268,7 +270,7 @@ for(int currOuterFold=0; currOuterFold<outerFolds; currOuterFold++) { - print("Outer fold " + currOuterFold); + logger.info("Outer fold " + currOuterFold); TrainTestList posList = posLists.get(currOuterFold); TrainTestList negList = negLists.get(currOuterFold); @@ -277,7 +279,7 @@ for(double currParaValue=startValue; currParaValue<=endValue; currParaValue+=stepsize) { - print(" Parameter value " + currParaValue + ":"); + logger.info(" Parameter value " + currParaValue + ":"); // split train folds again (computation of inner folds for each parameter // value is redundant, but not a big problem) List<Individual> trainPosList = posList.getTrainList(); @@ -291,7 +293,7 @@ for(int currInnerFold=0; currInnerFold<innerFolds; currInnerFold++) { - print(" Inner fold " + currInnerFold + ":"); + logger.info(" Inner fold " + currInnerFold + ":"); // get positive & negative examples for training run Set<Individual> posEx = new TreeSet<Individual>(innerPosLists.get(currInnerFold).getTrainList()); Set<Individual> negEx = new TreeSet<Individual>(innerNegLists.get(currInnerFold).getTrainList()); @@ -320,13 +322,12 @@ TreeSet<Individual> posTest = new TreeSet<Individual>(innerPosLists.get(currInnerFold).getTestList()); TreeSet<Individual> negTest = new TreeSet<Individual>(innerNegLists.get(currInnerFold).getTestList()); - AbstractReasonerComponent rs = start.getReasonerComponent(); // true positive - Set<Individual> posCorrect = rs.hasType(concept, posTest); + Set<Individual> posCorrect = rc.hasType(concept, posTest); // false negative Set<Individual> posError = Helper.difference(posTest, posCorrect); // false positive - Set<Individual> negError = rs.hasType(concept, negTest); + Set<Individual> negError = rc.hasType(concept, negTest); // true negative Set<Individual> negCorrect = Helper.difference(negTest, negError); @@ -340,19 +341,16 @@ paraCriterionStat.addNumber(accuracy); - print(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); - print(" accuracy: " + df.format(accuracy) + "%"); - print(" precision: " + df.format(precision) + "%"); - print(" recall: " + df.format(recall) + "%"); - print(" F measure: " + df.format(fmeasure) + "%"); + logger.info(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); + logger.info(" accuracy: " + df.format(accuracy) + "%"); + logger.info(" precision: " + df.format(precision) + "%"); + logger.info(" recall: " + df.format(recall) + "%"); + logger.info(" F measure: " + df.format(fmeasure) + "%"); if(verbose) { - print(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); - print(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); + logger.info(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); + logger.info(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); } - - // free memory - rs.releaseKB(); } paraStats.put(currParaValue, paraCriterionStat); @@ -365,20 +363,20 @@ } // decide for the best parameter - print(" Summary over parameter values:"); + logger.info(" Summary over parameter values:"); double bestPara = startValue; double bestValue = Double.NEGATIVE_INFINITY; for(Entry<Double,Stat> entry : paraStats.entrySet()) { double para = entry.getKey(); Stat stat = entry.getValue(); - print(" value " + para + ": " + stat.prettyPrint("%")); + logger.info(" value " + para + ": " + stat.prettyPrint("%")); if(stat.getMean() > bestValue) { bestPara = para; bestValue = stat.getMean(); } } - print(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); - print(" Learn on Outer fold:"); + logger.info(" selected " + bestPara + " as best parameter value (criterion value " + df.format(bestValue) + "%)"); + logger.info(" Learn on Outer fold:"); // start a learning process with this parameter and evaluate it on the outer fold start = new CLI(confFile); @@ -418,15 +416,15 @@ double recall = 100 * (double) posCorrect.size() / (posCorrect.size() + posError.size()); double fmeasure = 2 * (precision * recall) / (precision + recall); - print(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); - print(" accuracy: " + df.format(accuracy) + "%"); - print(" precision: " + df.format(precision) + "%"); - print(" recall: " + df.format(recall) + "%"); - print(" F measure: " + df.format(fmeasure) + "%"); + logger.info(" hypothesis: " + concept.toManchesterSyntaxString(baseURI, null)); + logger.info(" accuracy: " + df.format(accuracy) + "%"); + logger.info(" precision: " + df.format(precision) + "%"); + logger.info(" recall: " + df.format(recall) + "%"); + logger.info(" F measure: " + df.format(fmeasure) + "%"); if(verbose) { - print(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); - print(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); + logger.info(" false positives (neg. examples classified as pos.): " + formatIndividualSet(posError, baseURI)); + logger.info(" false negatives (pos. examples classified as neg.): " + formatIndividualSet(negError, baseURI)); } // update overall statistics @@ -445,13 +443,13 @@ globalRecall.add(recallOverall); // overall statistics - print("*******************"); - print("* Overall Results *"); - print("*******************"); - print("accuracy: " + accOverall.prettyPrint("%")); - print("F measure: " + fOverall.prettyPrint("%")); - print("precision: " + precisionOverall.prettyPrint("%")); - print("recall: " + recallOverall.prettyPrint("%")); + logger.info("*******************"); + logger.info("* Overall Results *"); + logger.info("*******************"); + logger.info("accuracy: " + accOverall.prettyPrint("%")); + logger.info("F measure: " + fOverall.prettyPrint("%")); + logger.info("precision: " + precisionOverall.prettyPrint("%")); + logger.info("recall: " + recallOverall.prettyPrint("%")); } // convenience methods, which takes a list of examples and divides them in Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-09 18:13:04 UTC (rev 4267) @@ -6,43 +6,39 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.algorithms.qtl.QTL2; import org.dllearner.algorithms.qtl.QTL2Disjunctive; import org.dllearner.algorithms.qtl.QueryTreeFactory; import org.dllearner.algorithms.qtl.datastructures.QueryTree; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; import org.dllearner.algorithms.qtl.impl.QueryTreeFactoryImpl; +import org.dllearner.cli.CLI; import org.dllearner.cli.CrossValidation; -import org.dllearner.cli.SPARQLCrossValidation; +import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.owl.Individual; -import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.scripts.NestedCrossValidation; import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyChange; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.reasoner.OWLReasoner; -import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; -import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -52,363 +48,20 @@ */ public class QTLEvaluation { - int nrOfFolds = 10; + int nrOfFolds = 3; private int nrOfPosExamples = 300; private int nrOfNegExamples = 300; - List<String> posExamples = Lists.newArrayList( - "http://dl-learner.org/carcinogenesis#d1", - "http://dl-learner.org/carcinogenesis#d10", - "http://dl-learner.org/carcinogenesis#d101", - "http://dl-learner.org/carcinogenesis#d102", - "http://dl-learner.org/carcinogenesis#d103", - "http://dl-learner.org/carcinogenesis#d106", - "http://dl-learner.org/carcinogenesis#d107", - "http://dl-learner.org/carcinogenesis#d108", - "http://dl-learner.org/carcinogenesis#d11", - "http://dl-learner.org/carcinogenesis#d12", - "http://dl-learner.org/carcinogenesis#d13", - "http://dl-learner.org/carcinogenesis#d134", - "http://dl-learner.org/carcinogenesis#d135", - "http://dl-learner.org/carcinogenesis#d136", - "http://dl-learner.org/carcinogenesis#d138", - "http://dl-learner.org/carcinogenesis#d140", - "http://dl-learner.org/carcinogenesis#d141", - "http://dl-learner.org/carcinogenesis#d144", - "http://dl-learner.org/carcinogenesis#d145", - "http://dl-learner.org/carcinogenesis#d146", - "http://dl-learner.org/carcinogenesis#d147", - "http://dl-learner.org/carcinogenesis#d15", - "http://dl-learner.org/carcinogenesis#d17", - "http://dl-learner.org/carcinogenesis#d19", - "http://dl-learner.org/carcinogenesis#d192", - "http://dl-learner.org/carcinogenesis#d193", - "http://dl-learner.org/carcinogenesis#d195", - "http://dl-learner.org/carcinogenesis#d196", - "http://dl-learner.org/carcinogenesis#d197", - "http://dl-learner.org/carcinogenesis#d198", - "http://dl-learner.org/carcinogenesis#d199", - "http://dl-learner.org/carcinogenesis#d2", - "http://dl-learner.org/carcinogenesis#d20", - "http://dl-learner.org/carcinogenesis#d200", - "http://dl-learner.org/carcinogenesis#d201", - "http://dl-learner.org/carcinogenesis#d202", - "http://dl-learner.org/carcinogenesis#d203", - "http://dl-learner.org/carcinogenesis#d204", - "http://dl-learner.org/carcinogenesis#d205", - "http://dl-learner.org/carcinogenesis#d21", - "http://dl-learner.org/carcinogenesis#d22", - "http://dl-learner.org/carcinogenesis#d226", - "http://dl-learner.org/carcinogenesis#d227", - "http://dl-learner.org/carcinogenesis#d228", - "http://dl-learner.org/carcinogenesis#d229", - "http://dl-learner.org/carcinogenesis#d231", - "http://dl-learner.org/carcinogenesis#d232", - "http://dl-learner.org/carcinogenesis#d234", - "http://dl-learner.org/carcinogenesis#d236", - "http://dl-learner.org/carcinogenesis#d239", - "http://dl-learner.org/carcinogenesis#d23_2", - "http://dl-learner.org/carcinogenesis#d242", - "http://dl-learner.org/carcinogenesis#d245", - "http://dl-learner.org/carcinogenesis#d247", - "http://dl-learner.org/carcinogenesis#d249", - "http://dl-learner.org/carcinogenesis#d25", - "http://dl-learner.org/carcinogenesis#d252", - "http://dl-learner.org/carcinogenesis#d253", - "http://dl-learner.org/carcinogenesis#d254", - "http://dl-learner.org/carcinogenesis#d255", - "http://dl-learner.org/carcinogenesis#d26", - "http://dl-learner.org/carcinogenesis#d272", - "http://dl-learner.org/carcinogenesis#d275", - "http://dl-learner.org/carcinogenesis#d277", - "http://dl-learner.org/carcinogenesis#d279", - "http://dl-learner.org/carcinogenesis#d28", - "http://dl-learner.org/carcinogenesis#d281", - "http://dl-learner.org/carcinogenesis#d283", - "http://dl-learner.org/carcinogenesis#d284", - "http://dl-learner.org/carcinogenesis#d288", - "http://dl-learner.org/carcinogenesis#d29", - "http://dl-learner.org/carcinogenesis#d290", - "http://dl-learner.org/carcinogenesis#d291", - "http://dl-learner.org/carcinogenesis#d292", - "http://dl-learner.org/carcinogenesis#d30", - "http://dl-learner.org/carcinogenesis#d31", - "http://dl-learner.org/carcinogenesis#d32", - "http://dl-learner.org/carcinogenesis#d33", - "http://dl-learner.org/carcinogenesis#d34", - "http://dl-learner.org/carcinogenesis#d35", - "http://dl-learner.org/carcinogenesis#d36", - "http://dl-learner.org/carcinogenesis#d37", - "http://dl-learner.org/carcinogenesis#d38", - "http://dl-learner.org/carcinogenesis#d42", - "http://dl-learner.org/carcinogenesis#d43", - "http://dl-learner.org/carcinogenesis#d44", - "http://dl-learner.org/carcinogenesis#d45", - "http://dl-learner.org/carcinogenesis#d46", - "http://dl-learner.org/carcinogenesis#d47", - "http://dl-learner.org/carcinogenesis#d48", - "http://dl-learner.org/carcinogenesis#d49", - "http://dl-learner.org/carcinogenesis#d5", - "http://dl-learner.org/carcinogenesis#d51", - "http://dl-learner.org/carcinogenesis#d52", - "http://dl-learner.org/carcinogenesis#d53", - "http://dl-learner.org/carcinogenesis#d55", - "http://dl-learner.org/carcinogenesis#d58", - "http://dl-learner.org/carcinogenesis#d6", - "http://dl-learner.org/carcinogenesis#d7", - "http://dl-learner.org/carcinogenesis#d84", - "http://dl-learner.org/carcinogenesis#d85_2", - "http://dl-learner.org/carcinogenesis#d86", - "http://dl-learner.org/carcinogenesis#d87", - "http://dl-learner.org/carcinogenesis#d88", - "http://dl-learner.org/carcinogenesis#d89", - "http://dl-learner.org/carcinogenesis#d9", - "http://dl-learner.org/carcinogenesis#d91", - "http://dl-learner.org/carcinogenesis#d92", - "http://dl-learner.org/carcinogenesis#d93", - "http://dl-learner.org/carcinogenesis#d95", - "http://dl-learner.org/carcinogenesis#d96", - "http://dl-learner.org/carcinogenesis#d98", - "http://dl-learner.org/carcinogenesis#d99", - "http://dl-learner.org/carcinogenesis#d100", - "http://dl-learner.org/carcinogenesis#d104", - "http://dl-learner.org/carcinogenesis#d105", - "http://dl-learner.org/carcinogenesis#d109", - "http://dl-learner.org/carcinogenesis#d137", - "http://dl-learner.org/carcinogenesis#d139", - "http://dl-learner.org/carcinogenesis#d14", - "http://dl-learner.org/carcinogenesis#d142", - "http://dl-learner.org/carcinogenesis#d143", - "http://dl-learner.org/carcinogenesis#d148", - "http://dl-learner.org/carcinogenesis#d16", - "http://dl-learner.org/carcinogenesis#d18", - "http://dl-learner.org/carcinogenesis#d191", - "http://dl-learner.org/carcinogenesis#d206", - "http://dl-learner.org/carcinogenesis#d230", - "http://dl-learner.org/carcinogenesis#d233", - "http://dl-learner.org/carcinogenesis#d235", - "http://dl-learner.org/carcinogenesis#d237", - "http://dl-learner.org/carcinogenesis#d238", - "http://dl-learner.org/carcinogenesis#d23_1", - "http://dl-learner.org/carcinogenesis#d24", - "http://dl-learner.org/carcinogenesis#d240", - "http://dl-learner.org/carcinogenesis#d241", - "http://dl-learner.org/carcinogenesis#d243", - "http://dl-learner.org/carcinogenesis#d244", - "http://dl-learner.org/carcinogenesis#d246", - "http://dl-learner.org/carcinogenesis#d248", - "http://dl-learner.org/carcinogenesis#d250", - "http://dl-learner.org/carcinogenesis#d251", - "http://dl-learner.org/carcinogenesis#d27", - "http://dl-learner.org/carcinogenesis#d273", - "http://dl-learner.org/carcinogenesis#d274", - "http://dl-learner.org/carcinogenesis#d278", - "http://dl-learner.org/carcinogenesis#d286", - "http://dl-learner.org/carcinogenesis#d289", - "http://dl-learner.org/carcinogenesis#d3", - "http://dl-learner.org/carcinogenesis#d39", - "http://dl-learner.org/carcinogenesis#d4", - "http://dl-learner.org/carcinogenesis#d40", - "http://dl-learner.org/carcinogenesis#d41", - "http://dl-learner.org/carcinogenesis#d50", - "http://dl-learner.org/carcinogenesis#d54", - "http://dl-learner.org/carcinogenesis#d56", - "http://dl-learner.org/carcinogenesis#d57", - "http://dl-learner.org/carcinogenesis#d8", - "http://dl-learner.org/carcinogenesis#d85_1", - "http://dl-learner.org/carcinogenesis#d90", - "http://dl-learner.org/carcinogenesis#d94", - "http://dl-learner.org/carcinogenesis#d97", - "http://dl-learner.org/carcinogenesis#d296", - "http://dl-learner.org/carcinogenesis#d305", - "http://dl-learner.org/carcinogenesis#d306", - "http://dl-learner.org/carcinogenesis#d307", - "http://dl-learner.org/carcinogenesis#d308", - "http://dl-learner.org/carcinogenesis#d311", - "http://dl-learner.org/carcinogenesis#d314", - "http://dl-learner.org/carcinogenesis#d315", - "http://dl-learner.org/carcinogenesis#d316", - "http://dl-learner.org/carcinogenesis#d320", - "http://dl-learner.org/carcinogenesis#d322", - "http://dl-learner.org/carcinogenesis#d323", - "http://dl-learner.org/carcinogenesis#d325", - "http://dl-learner.org/carcinogenesis#d329", - "http://dl-learner.org/carcinogenesis#d330", - "http://dl-learner.org/carcinogenesis#d331", - "http://dl-learner.org/carcinogenesis#d332", - "http://dl-learner.org/carcinogenesis#d333", - "http://dl-learner.org/carcinogenesis#d336", - "http://dl-learner.org/carcinogenesis#d337" - ); + CLI cli = new CLI(new File("../test/qtl/carcinogenesis/train.conf")); - List<String> negExamples = Lists.newArrayList( - "http://dl-learner.org/carcinogenesis#d110", - "http://dl-learner.org/carcinogenesis#d111", - "http://dl-learner.org/carcinogenesis#d114", - "http://dl-learner.org/carcinogenesis#d116", - "http://dl-learner.org/carcinogenesis#d117", - "http://dl-learner.org/carcinogenesis#d119", - "http://dl-learner.org/carcinogenesis#d121", - "http://dl-learner.org/carcinogenesis#d123", - "http://dl-learner.org/carcinogenesis#d124", - "http://dl-learner.org/carcinogenesis#d125", - "http://dl-learner.org/carcinogenesis#d127", - "http://dl-learner.org/carcinogenesis#d128", - "http://dl-learner.org/carcinogenesis#d130", - "http://dl-learner.org/carcinogenesis#d133", - "http://dl-learner.org/carcinogenesis#d150", - "http://dl-learner.org/carcinogenesis#d151", - "http://dl-learner.org/carcinogenesis#d154", - "http://dl-learner.org/carcinogenesis#d155", - "http://dl-learner.org/carcinogenesis#d156", - "http://dl-learner.org/carcinogenesis#d159", - "http://dl-learner.org/carcinogenesis#d160", - "http://dl-learner.org/carcinogenesis#d161", - "http://dl-learner.org/carcinogenesis#d162", - "http://dl-learner.org/carcinogenesis#d163", - "http://dl-learner.org/carcinogenesis#d164", - "http://dl-learner.org/carcinogenesis#d165", - "http://dl-learner.org/carcinogenesis#d166", - "http://dl-learner.org/carcinogenesis#d169", - "http://dl-learner.org/carcinogenesis#d170", - "http://dl-learner.org/carcinogenesis#d171", - "http://dl-learner.org/carcinogenesis#d172", - "http://dl-learner.org/carcinogenesis#d173", - "http://dl-learner.org/carcinogenesis#d174", - "http://dl-learner.org/carcinogenesis#d178", - "http://dl-learner.org/carcinogenesis#d179", - "http://dl-learner.org/carcinogenesis#d180", - "http://dl-learner.org/carcinogenesis#d181", - "http://dl-learner.org/carcinogenesis#d183", - "http://dl-learner.org/carcinogenesis#d184", - "http://dl-learner.org/carcinogenesis#d185", - "http://dl-learner.org/carcinogenesis#d186", - "http://dl-learner.org/carcinogenesis#d188", - "http://dl-learner.org/carcinogenesis#d190", - "http://dl-learner.org/carcinogenesis#d194", - "http://dl-learner.org/carcinogenesis#d207", - "http://dl-learner.org/carcinogenesis#d208_1", - "http://dl-learner.org/carcinogenesis#d209", - "http://dl-learner.org/carcinogenesis#d210", - "http://dl-learner.org/carcinogenesis#d211", - "http://dl-learner.org/carcinogenesis#d212", - "http://dl-learner.org/carcinogenesis#d213", - "http://dl-learner.org/carcinogenesis#d214", - "http://dl-learner.org/carcinogenesis#d215", - "http://dl-learner.org/carcinogenesis#d217", - "http://dl-learner.org/carcinogenesis#d218", - "http://dl-learner.org/carcinogenesis#d219", - "http://dl-learner.org/carcinogenesis#d220", - "http://dl-learner.org/carcinogenesis#d224", - "http://dl-learner.org/carcinogenesis#d256", - "http://dl-learner.org/carcinogenesis#d257", - "http://dl-learner.org/carcinogenesis#d258", - "http://dl-learner.org/carcinogenesis#d261", - "http://dl-learner.org/carcinogenesis#d262", - "http://dl-learner.org/carcinogenesis#d263", - "http://dl-learner.org/carcinogenesis#d264", - "http://dl-learner.org/carcinogenesis#d265", - "http://dl-learner.org/carcinogenesis#d266", - "http://dl-learner.org/carcinogenesis#d267", - "http://dl-learner.org/carcinogenesis#d269", - "http://dl-learner.org/carcinogenesis#d271", - "http://dl-learner.org/carcinogenesis#d276", - "http://dl-learner.org/carcinogenesis#d280", - "http://dl-learner.org/carcinogenesis#d285", - "http://dl-learner.org/carcinogenesis#d287", - "http://dl-learner.org/carcinogenesis#d293", - "http://dl-learner.org/carcinogenesis#d294", - "http://dl-learner.org/carcinogenesis#d59", - "http://dl-learner.org/carcinogenesis#d60", - "http://dl-learner.org/carcinogenesis#d61", - "http://dl-learner.org/carcinogenesis#d63", - "http://dl-learner.org/carcinogenesis#d64", - "http://dl-learner.org/carcinogenesis#d65", - "http://dl-learner.org/carcinogenesis#d69", - "http://dl-learner.org/carcinogenesis#d70", - "http://dl-learner.org/carcinogenesis#d71", - "http://dl-learner.org/carcinogenesis#d72", - "http://dl-learner.org/carcinogenesis#d73", - "http://dl-learner.org/carcinogenesis#d74", - "http://dl-learner.org/carcinogenesis#d75", - "http://dl-learner.org/carcinogenesis#d76", - "http://dl-learner.org/carcinogenesis#d77", - "http://dl-learner.org/carcinogenesis#d78", - "http://dl-learner.org/carcinogenesis#d79", - "http://dl-learner.org/carcinogenesis#d80", - "http://dl-learner.org/carcinogenesis#d81", - "http://dl-learner.org/carcinogenesis#d82", - "http://dl-learner.org/carcinogenesis#d112", - "http://dl-learner.org/carcinogenesis#d113", - "http://dl-learner.org/carcinogenesis#d115", - "http://dl-learner.org/carcinogenesis#d118", - "http://dl-learner.org/carcinogenesis#d120", - "http://dl-learner.org/carcinogenesis#d122", - "http://dl-learner.org/carcinogenesis#d126", - "http://dl-learner.org/carcinogenesis#d129", - "http://dl-learner.org/carcinogenesis#d131", - "http://dl-learner.org/carcinogenesis#d132", - "http://dl-learner.org/carcinogenesis#d149", - "http://dl-learner.org/carcinogenesis#d152", - "http://dl-learner.org/carcinogenesis#d153", - "http://dl-learner.org/carcinogenesis#d157", - "http://dl-learner.org/carcinogenesis#d158", - "http://dl-learner.org/carcinogenesis#d167", - "http://dl-learner.org/carcinogenesis#d168", - "http://dl-learner.org/carcinogenesis#d175", - "http://dl-learner.org/carcinogenesis#d176", - "http://dl-learner.org/carcinogenesis#d177", - "http://dl-learner.org/carcinogenesis#d182", - "http://dl-learner.org/carcinogenesis#d187", - "http://dl-learner.org/carcinogenesis#d189", - "http://dl-learner.org/carcinogenesis#d208_2", - "http://dl-learner.org/carcinogenesis#d216", - "http://dl-learner.org/carcinogenesis#d221", - "http://dl-learner.org/carcinogenesis#d222", - "http://dl-learner.org/carcinogenesis#d223", - "http://dl-learner.org/carcinogenesis#d225", - "http://dl-learner.org/carcinogenesis#d259", - "http://dl-learner.org/carcinogenesis#d260", - "http://dl-learner.org/carcinogenesis#d268", - "http://dl-learner.org/carcinogenesis#d270", - "http://dl-learner.org/carcinogenesis#d282", - "http://dl-learner.org/carcinogenesis#d295", - "http://dl-learner.org/carcinogenesis#d62", - "http://dl-learner.org/carcinogenesis#d66", - "http://dl-learner.org/carcinogenesis#d67", - "http://dl-learner.org/carcinogenesis#d68", - "http://dl-learner.org/carcinogenesis#d83", - "http://dl-learner.org/carcinogenesis#d297", - "http://dl-learner.org/carcinogenesis#d298", - "http://dl-learner.org/carcinogenesis#d299", - "http://dl-learner.org/carcinogenesis#d300", - "http://dl-learner.org/carcinogenesis#d302", - "http://dl-learner.org/carcinogenesis#d303", - "http://dl-learner.org/carcinogenesis#d304", - "http://dl-learner.org/carcinogenesis#d309", - "http://dl-learner.org/carcinogenesis#d312", - "http://dl-learner.org/carcinogenesis#d313", - "http://dl-learner.org/carcinogenesis#d317", - "http://dl-learner.org/carcinogenesis#d318", - "http://dl-learner.org/carcinogenesis#d319", - "http://dl-learner.org/carcinogenesis#d324", - "http://dl-learner.org/carcinogenesis#d326", - "http://dl-learner.org/carcinogenesis#d327", - "http://dl-learner.org/carcinogenesis#d328", - "http://dl-learner.org/carcinogenesis#d334", - "http://dl-learner.org/carcinogenesis#d335" - ); - private Model model; private OWLOntology ontology; private QueryTreeFactory<String> queryTreeFactory; - private List<QueryTree<String>> posExampleTrees; - private List<QueryTree<String>> negExampleTrees; private PosNegLP lp; - public QTLEvaluation() throws ComponentInitException { + public QTLEvaluation() throws ComponentInitException, IOException { queryTreeFactory = new QueryTreeFactoryImpl(); queryTreeFactory.setMaxDepth(3); @@ -434,59 +87,29 @@ } } - private void loadExamples() throws ComponentInitException{ + private void loadExamples() throws ComponentInitException, IOException{ - Collections.shuffle(posExamples, new Random(1)); - Collections.shuffle(negExamples, new Random(2)); + cli.init(); + lp = (PosNegLP) cli.getLearningProblem(); + + // get examples and shuffle them + List<Individual> posExamples = new LinkedList<Individual>(((PosNegLP)lp).getPositiveExamples()); + Collections.shuffle(posExamples, new Random(1)); + List<Individual> negExamples = new LinkedList<Individual>(((PosNegLP)lp).getNegativeExamples()); + Collections.shuffle(negExamples, new Random(2)); posExamples = posExamples.subList(0, Math.min(posExamples.size(), nrOfPosExamples)); negExamples = negExamples.subList(0, Math.min(negExamples.size(), nrOfNegExamples)); -// posExamples.clear(); -// String string = "http://dl-learner.org/carcinogenesis#d101, http://dl-learner.org/carcinogenesis#d103, http://dl-learner.org/carcinogenesis#d107, http://dl-learner.org/carcinogenesis#d108, http://dl-learner.org/carcinogenesis#d135, http://dl-learner.org/carcinogenesis#d139, http://dl-learner.org/carcinogenesis#d14, http://dl-learner.org/carcinogenesis#d141, http://dl-learner.org/carcinogenesis#d143, http://dl-learner.org/carcinogenesis#d147, http://dl-learner.org/carcinogenesis#d17, http://dl-learner.org/carcinogenesis#d19, http://dl-learner.org/carcinogenesis#d193, http://dl-learner.org/carcinogenesis#d198, http://dl-learner.org/carcinogenesis#d228, http://dl-learner.org/carcinogenesis#d236, http://dl-learner.org/carcinogenesis#d242, http://dl-learner.org/carcinogenesis#d244, http://dl-learner.org/carcinogenesis#d273, http://dl-learner.org/carcinogenesis#d275, http://dl-learner.org/carcinogenesis#d28, http://dl-learner.org/carcinogenesis#d283, http://dl-learner.org/carcinogenesis#d286, http://dl-learner.org/carcinogenesis#d291, http://dl-learner.org/carcinogenesis#d292, http://dl-learner.org/carcinogenesis#d307, http://dl-learner.org/carcinogenesis#d31, http://dl-learner.org/carcinogenesis#d325, http://dl-learner.org/carcinogenesis#d33, http://dl-learner.org/carcinogenesis#d333, http://dl-learner.org/carcinogenesis#d34, http://dl-learner.org/carcinogenesis#d36, http://dl-learner.org/carcinogenesis#d38, http://dl-learner.org/carcinogenesis#d4, http://dl-learner.org/carcinogenesis#d40, http://dl-learner.org/carcinogenesis#d44, http://dl-learner.org/carcinogenesis#d51, http://dl-learner.org/carcinogenesis#d85_2, http://dl-learner.org/carcinogenesis#d98, http://dl-learner.org/carcinogenesis#d99"; -// String[] split = string.split(","); -// for (String s : split) { -// posExamples.add(s.trim()); -// } -// negExamples.clear(); -// string = "http://dl-learner.org/carcinogenesis#d112, http://dl-learner.org/carcinogenesis#d116, http://dl-learner.org/carcinogenesis#d117, http://dl-learner.org/carcinogenesis#d119, http://dl-learner.org/carcinogenesis#d157, http://dl-learner.org/carcinogenesis#d160, http://dl-learner.org/carcinogenesis#d161, http://dl-learner.org/carcinogenesis#d162, http://dl-learner.org/carcinogenesis#d163, http://dl-learner.org/carcinogenesis#d167, http://dl-learner.org/carcinogenesis#d169, http://dl-learner.org/carcinogenesis#d175, http://dl-learner.org/carcinogenesis#d177, http://dl-learner.org/carcinogenesis#d184, http://dl-learner.org/carcinogenesis#d194, http://dl-learner.org/carcinogenesis#d208_2, http://dl-learner.org/carcinogenesis#d209, http://dl-learner.org/carcinogenesis#d217, http://dl-learner.org/carcinogenesis#d256, http://dl-learner.org/carcinogenesis#d257, http://dl-learner.org/carcinogenesis#d260, http://dl-learner.org/carcinogenesis#d271, http://dl-learner.org/carcinogenesis#d276, http://dl-learner.org/carcinogenesis#d282, http://dl-learner.org/carcinogenesis#d287, http://dl-learner.org/carcinogenesis#d294, http://dl-learner.org/carcinogenesis#d298, http://dl-learner.org/carcinogenesis#d300, http://dl-learner.org/carcinogenesis#d309, http://dl-learner.org/carcinogenesis#d319, http://dl-learner.org/carcinogenesis#d326, http://dl-learner.org/carcinogenesis#d328, http://dl-learner.org/carcinogenesis#d334, http://dl-learner.org/carcinogenesis#d60, http://dl-learner.org/carcinogenesis#d61, http://dl-learner.org/carcinogenesis#d66, http://dl-learner.org/carcinogenesis#d75, http://dl-learner.org/carcinogenesis#d79, http://dl-learner.org/carcinogenesis#d80, http://dl-learner.org/carcinogenesis#d83"; -// split = string.split(","); -// for (String s : split) { -// negExamples.add(s.trim()); -// } + Set<Individual> posSet = new TreeSet<Individual>( + NestedCrossValidation.getFolds(NestedCrossValidation.getFolds(posExamples, 3).get(0).getTrainList(), 3).get(0).getTrainList()); + Set<Individual> negSet = new TreeSet<Individual>( + NestedCrossValidation.getFolds(NestedCrossValidation.getFolds(negExamples, 3).get(0).getTrainList(), 3).get(0).getTrainList()); - posExampleTrees = new ArrayList<QueryTree<String>>(); - for (String ex : posExamples) { - QueryTreeImpl<String> tree = queryTreeFactory.getQueryTree(ex, model); - posExampleTrees.add(tree); - } - negExampleTrees = new ArrayList<QueryTree<String>>(); - for (String ex : negExamples) { - QueryTreeImpl<String> tree = queryTreeFactory.getQueryTree(ex, model); - negExampleTrees.add(tree); - } - int cnt = 1; - for(QueryTree<String> tree : posExampleTrees){ -// System.out.println("TREE " + cnt); -// tree.dump(); -// -// System.out.println("-----------------------------"); - cnt++; -// System.out.println(((QueryTreeImpl<String>)tree).toQuery()); - } - - SortedSet<Individual> pos = new TreeSet<Individual>(); - for (String ex : posExamples) { - pos.add(new Individual(ex)); - } - SortedSet<Individual> neg = new TreeSet<Individual>(); - for (String ex : negExamples) { - neg.add(new Individual(ex)); - } - lp = new PosNegLPStandard(); - lp.setPositiveExamples(pos); - lp.setNegativeExamples(neg); + this.lp = new PosNegLPStandard(); + this.lp.setPositiveExamples(posSet); + this.lp.setNegativeExamples(negSet); } public void run(boolean multiThreaded) throws ComponentInitException, LearningProblemUnsupportedException{ @@ -496,13 +119,14 @@ lp.setReasoner(reasoner); lp.init(); QTL2Disjunctive la = new QTL2Disjunctive(lp, reasoner); -// la.init(); -// la.start(); + la.setBeta(0.5); + la.init(); + la.start(); CrossValidation.outputFile = new File("log/qtl-cv.log"); CrossValidation.writeToFile = true; CrossValidation.multiThreaded = multiThreaded; - CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); +// CrossValidation cv = new CrossValidation(la, lp, reasoner, nrOfFolds, false); long endTime = System.currentTimeMillis(); System.err.println((endTime - startTime) + "ms"); } Modified: trunk/test/qtl/breasttissue/train1.conf =================================================================== --- trunk/test/qtl/breasttissue/train1.conf 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/test/qtl/breasttissue/train1.conf 2014-05-09 18:13:04 UTC (rev 4267) @@ -8,6 +8,8 @@ // QTL configuration alg.type = "qtl2dis" +alg.maxExecutionTimeInSeconds = 60 +alg.maxTreeComputationTimeInSeconds = 10 // learning problem lp.type = "posNegStandard" Modified: trunk/test/qtl/carcinogenesis/train.conf =================================================================== --- trunk/test/qtl/carcinogenesis/train.conf 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/test/qtl/carcinogenesis/train.conf 2014-05-09 18:13:04 UTC (rev 4267) @@ -8,6 +8,11 @@ reasoner.type = "fast instance checker" reasoner.sources = { ks } +// QTL configuration +alg.type = "qtl2dis" +alg.maxExecutionTimeInSeconds = 60 +alg.maxTreeComputationTimeInSeconds = 10 + // learning problem lp.type = "posNegStandard" lp.positiveExamples = { @@ -352,5 +357,3 @@ "kb:d335" } -// QTL configuration -alg.type = "qtl2dis" Modified: trunk/test/qtl/mutagenesis/train1.conf =================================================================== --- trunk/test/qtl/mutagenesis/train1.conf 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/test/qtl/mutagenesis/train1.conf 2014-05-09 18:13:04 UTC (rev 4267) @@ -11,6 +11,8 @@ // QTL configuration alg.type = "qtl2dis" +alg.maxExecutionTimeInSeconds = 60 +alg.maxTreeComputationTimeInSeconds = 10 // learning problem lp.type = "posNegStandard" Modified: trunk/test/qtl/parkinsons/train.conf =================================================================== --- trunk/test/qtl/parkinsons/train.conf 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/test/qtl/parkinsons/train.conf 2014-05-09 18:13:04 UTC (rev 4267) @@ -7,6 +7,8 @@ // QTL configuration alg.type = "qtl2dis" +alg.maxExecutionTimeInSeconds = 60 +alg.maxTreeComputationTimeInSeconds = 10 // learning problem lp.type = "posNegStandard" Modified: trunk/test/qtl/suramin/train.conf =================================================================== --- trunk/test/qtl/suramin/train.conf 2014-05-08 18:19:32 UTC (rev 4266) +++ trunk/test/qtl/suramin/train.conf 2014-05-09 18:13:04 UTC (rev 4267) @@ -30,4 +30,6 @@ } // QTL configuration -alg.type = "qtl2dis" \ No newline at end of file +alg.type = "qtl2dis" +alg.maxExecutionTimeInSeconds = 60 +alg.maxTreeComputationTimeInSeconds = 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: <lor...@us...> - 2014-05-22 02:22:20
|
Revision: 4269 http://sourceforge.net/p/dl-learner/code/4269 Author: lorenz_b Date: 2014-05-22 02:22:16 +0000 (Thu, 22 May 2014) Log Message: ----------- Updated Maven libs. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java trunk/examples/mutagenesis/train1.conf trunk/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java trunk/test/qtl/alzheimer/train1.conf Added Paths: ----------- trunk/dllearner-parent.iml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/pom.xml 2014-05-22 02:22:16 UTC (rev 4269) @@ -115,12 +115,15 @@ <artifactId>log4j</artifactId> </dependency> - <!-- Latest JENA ARQ - we have to exclude XercesImpl and use an older version here because use version bei JENA leads to some errors --> <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-arq</artifactId> - </dependency> + + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-core</artifactId> + </dependency> <!--JSON is in Central --> <dependency> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/elcopy/ELLearningAlgorithm.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -118,7 +118,6 @@ public ELLearningAlgorithm(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { super(problem, reasoner); // configurator = new ELLearningAlgorithmConfigurator(this); - timeMonitor = MonitorFactory.getTimeMonitor("time"); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -8,7 +8,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.PriorityQueue; @@ -17,11 +16,12 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.apache.commons.collections.ListUtils; import org.apache.log4j.Logger; import org.dllearner.algorithms.qtl.cache.QueryTreeCache; import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeSubsumptionStrategy; import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree; import org.dllearner.algorithms.qtl.operations.lgg.LGGGenerator; import org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorImpl; @@ -31,9 +31,7 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningProblem; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.Score; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -43,7 +41,6 @@ import org.dllearner.learningproblems.Heuristics; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.QueryTreeScore; -import org.dllearner.learningproblems.ScoreTwoValued; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; import org.dllearner.utilities.owl.OWLAPIConverter; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -141,6 +138,11 @@ super(qtl.getLearningProblem(), qtl.getReasoner()); this.model = ModelFactory.createDefaultModel(); this.model.add(qtl.model); + this.beta = qtl.beta; + this.maxExecutionTimeInSeconds = qtl.maxExecutionTimeInSeconds; + this.maxTreeComputationTimeInSeconds = qtl.maxTreeComputationTimeInSeconds; + this.tryFullCoverage = qtl.tryFullCoverage; + this.stopOnFirstDefinition = qtl.stopOnFirstDefinition; } public EvaluatedQueryTree<String> getBestSolution(){ @@ -160,10 +162,10 @@ lggGenerator = new LGGGeneratorImpl<String>(); -// if(heuristic == null){ + if(heuristic == null){ heuristic = new QueryTreeHeuristic(); heuristic.setPosExamplesWeight(beta); -// } + } logger.info("Initializing..."); treeCache = new QueryTreeCache(model); @@ -218,12 +220,7 @@ */ @Override public void start() { - String setup = "Setup:"; - setup += "\n#Pos. examples:" + currentPosExamples.size(); - setup += "\n#Neg. examples:" + currentNegExamples.size(); - setup += "Heuristic:" + heuristic.getHeuristicType().name(); - setup += "\nbeta=" + beta; - logger.info(setup); + showSetup(); logger.info("Running..."); startTime = System.currentTimeMillis(); @@ -235,12 +232,9 @@ logger.info("#Remaining pos. examples:" + currentPosExampleTrees.size()); logger.info("#Remaining neg. examples:" + currentNegExampleTrees.size()); - //compute a (partial) solution - computeBestPartialSolution(); + //compute best (partial) solution computed so far + EvaluatedQueryTree<String> bestPartialSolution = computeBestPartialSolution(); - //pick best (partial) solution computed so far - EvaluatedQueryTree<String> bestPartialSolution = currentPartialSolutions.first(); - //add if some criteria are satisfied if(bestPartialSolution.getScore() >= minimumTreeScore){ @@ -284,12 +278,13 @@ } - private void computeBestPartialSolution(){ + private EvaluatedQueryTree<String> computeBestPartialSolution(){ logger.info("Computing best partial solution..."); bestCurrentScore = Double.NEGATIVE_INFINITY; partialSolutionStartTime = System.currentTimeMillis(); initTodoList(currentPosExampleTrees, currentNegExampleTrees); + EvaluatedQueryTree<String> bestPartialSolutionTree = null; EvaluatedQueryTree<String> currentElement; QueryTree<String> currentTree; while(!partialSolutionTerminationCriteriaSatisfied()){ @@ -307,30 +302,34 @@ lggMon.stop(); //evaluate the LGG - EvaluatedQueryTree<String> solution = evaluate(lgg, true); - double score = solution.getScore(); - double mas = heuristic.getMaximumAchievableScore(solution); - - if(score >= bestCurrentScore){ - //add to todo list, if not already contained in todo list or solution list - todo(solution); - if(score > bestCurrentScore){ - logger.info("\tGot better solution:" + solution.getTreeScore()); + Set<EvaluatedQueryTree<String>> solutions = evaluate(lgg, true); + for (EvaluatedQueryTree<String> solution : solutions) { + double score = solution.getScore(); + double mas = heuristic.getMaximumAchievableScore(solution); + + if(score >= bestCurrentScore){ + //add to todo list, if not already contained in todo list or solution list + todo(solution); + if(score > bestCurrentScore){ + logger.info("\tGot better solution:" + solution.getTreeScore()); + bestCurrentScore = score; + bestPartialSolutionTree = solution; + } + + } else if(mas >= bestCurrentScore){ + todo(solution); + } else { +// System.out.println("Too general"); +// System.out.println("MAS=" + mas + "\nBest=" + bestCurrentScore); } - bestCurrentScore = solution.getScore(); - } else if(mas < bestCurrentScore){ - todo(solution); - } else { - System.out.println("Too general"); + currentPartialSolutions.add(currentElement); } - currentPartialSolutions.add(currentElement); - } currentPartialSolutions.add(currentElement); } long endTime = System.currentTimeMillis(); logger.info("...finished in " + (endTime-partialSolutionStartTime) + "ms."); - EvaluatedDescription bestPartialSolution = currentPartialSolutions.first().asEvaluatedDescription(); + EvaluatedDescription bestPartialSolution = bestPartialSolutionTree.asEvaluatedDescription(LiteralNodeConversionStrategy.SOME_VALUES_FROM); logger.info("Best partial solution: " + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()).toString().replace("\n", "") + "\n(" + bestPartialSolution.getScore() + ")"); @@ -340,9 +339,11 @@ logger.trace("Subsumption test time: " + subMon.getTotal() + "ms"); logger.trace("Avg. subsumption test time: " + subMon.getAvg() + "ms"); logger.trace("#Subsumption tests: " + subMon.getHits()); + + return bestPartialSolutionTree; } - private EvaluatedQueryTree<String> evaluate(QueryTree<String> tree, boolean useSpecifity){ + private EvaluatedQueryTree<String> evaluateSimple(QueryTree<String> tree, boolean useSpecifity){ //1. get a score for the coverage = recall oriented //compute positive examples which are not covered by LGG List<QueryTree<String>> uncoveredPositiveExampleTrees = getUncoveredTrees(tree, currentPosExampleTrees); @@ -399,45 +400,191 @@ return evaluatedTree; } - private EvaluatedDescription buildCombinedSolution(){ - if(partialSolutions.size() == 1){ - EvaluatedDescription combinedSolution = partialSolutions.get(0).asEvaluatedDescription(); - return combinedSolution; + /** + * Returns a set of evaluated query trees. A set is returned because there are several ways how to convert literal nodes. + * @param tree + * @param useSpecifity + * @return + */ + private Set<EvaluatedQueryTree<String>> evaluate(QueryTree<String> tree, boolean useSpecifity){ + Set<EvaluatedQueryTree<String>> evaluatedTrees = new TreeSet<EvaluatedQueryTree<String>>(); + + LiteralNodeSubsumptionStrategy[] strategies = LiteralNodeSubsumptionStrategy.values(); + strategies = new LiteralNodeSubsumptionStrategy[]{LiteralNodeSubsumptionStrategy.DATATYPE, LiteralNodeSubsumptionStrategy.INTERVAL}; + for (LiteralNodeSubsumptionStrategy strategy : strategies) { + //1. get a score for the coverage = recall oriented + List<QueryTree<String>> uncoveredPositiveExampleTrees = new ArrayList<QueryTree<String>>(); + List<QueryTree<String>> coveredNegativeExampleTrees = new ArrayList<QueryTree<String>>(); + + //compute positive examples which are not covered by LGG + for (QueryTree<String> posTree : currentPosExampleTrees) { + if(!posTree.isSubsumedBy(tree, strategy)){ + uncoveredPositiveExampleTrees.add(posTree); + } + } + //compute negative examples which are covered by LGG + for (QueryTree<String> negTree : currentNegExampleTrees) { + if(negTree.isSubsumedBy(tree, strategy)){ + coveredNegativeExampleTrees.add(negTree); + } + } + //convert to individuals + Set<Individual> uncoveredPosExamples = asIndividuals(uncoveredPositiveExampleTrees); + Set<Individual> coveredNegExamples = asIndividuals(coveredNegativeExampleTrees); + + //compute score + int coveredPositiveExamples = currentPosExampleTrees.size() - uncoveredPositiveExampleTrees.size(); + double recall = coveredPositiveExamples / (double)currentPosExampleTrees.size(); + double precision = (coveredNegativeExampleTrees.size() + coveredPositiveExamples == 0) + ? 0 + : coveredPositiveExamples / (double)(coveredPositiveExamples + coveredNegativeExampleTrees.size()); + + double coverageScore = Heuristics.getFScore(recall, precision, beta); + + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int nrOfSpecificNodes = 0; + for (QueryTree<String> childNode : tree.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + nrOfSpecificNodes++; + } + } + double specifityScore = 0d; + if(useSpecifity){ + specifityScore = Math.log(nrOfSpecificNodes); + } + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + + QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, + new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, + coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), + specifityScore, nrOfSpecificNodes); + + EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, uncoveredPositiveExampleTrees, coveredNegativeExampleTrees, queryTreeScore); + + //TODO use only the heuristic to compute the score + score = heuristic.getScore(evaluatedTree); + queryTreeScore.setScore(score); + queryTreeScore.setAccuracy(score); + + evaluatedTrees.add(evaluatedTree); } - List<Description> disjuncts = new ArrayList<Description>(); - Set<Individual> posCovered = new HashSet<Individual>(); - Set<Individual> negCovered = new HashSet<Individual>(); + return evaluatedTrees; + } + + /** + * Returns a set of evaluated query trees. A set is returned because there are several ways how to convert literal nodes. + * @param tree + * @param useSpecifity + * @return + */ + private Set<EvaluatedDescription> evaluate2(QueryTree<String> tree, boolean useSpecifity){ + Set<EvaluatedDescription> evaluatedDescriptions = new TreeSet<EvaluatedDescription>(); - //build the union of all class expressions - Description partialDescription; - for (EvaluatedQueryTree<String> partialSolution : partialSolutions) { - partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( - partialSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)); - disjuncts.add(partialDescription); - posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives()); - negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives()); + LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values(); + strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM, LiteralNodeConversionStrategy.FACET_RESTRICTION}; + for (LiteralNodeConversionStrategy strategy : strategies) { + Description d = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(tree.asOWLClassExpression(strategy)); + //convert to individuals + SortedSet<Individual> coveredExamples = reasoner.getIndividuals(d); + Set<Individual> coveredPosExamples = new TreeSet<Individual>(Sets.intersection(currentPosExamples, coveredExamples)); + Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(Sets.difference(currentPosExamples, coveredExamples)); + Set<Individual> coveredNegExamples = new TreeSet<Individual>(Sets.intersection(currentNegExamples, coveredExamples)); + + //compute score + double recall = coveredPosExamples.size() / (double)currentPosExamples.size(); + double precision = (coveredNegExamples.size() + coveredPosExamples.size() == 0) + ? 0 + : coveredPosExamples.size() / (double)(coveredPosExamples.size() + coveredNegExamples.size()); + + double coverageScore = Heuristics.getFScore(recall, precision, beta); + + //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + int nrOfSpecificNodes = 0; + for (QueryTree<String> childNode : tree.getChildrenClosure()) { + if(!childNode.getUserObject().equals("?")){ + nrOfSpecificNodes++; + } + } + double specifityScore = 0d; + if(useSpecifity){ + specifityScore = Math.log(nrOfSpecificNodes); + } + + //3.compute the total score + double score = coverageWeight * coverageScore + specifityWeight * specifityScore; + + QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, + new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, + coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), + specifityScore, nrOfSpecificNodes); + + //TODO use only the heuristic to compute the score +// score = heuristic.getScore(evaluatedTree); +// queryTreeScore.setScore(score); +// queryTreeScore.setAccuracy(score); +// +// EvaluatedDescription evaluatedDescription = new EvaluatedDescription(d, queryTreeScore); +// +// evaluatedDescriptions.add(evaluatedDescription); } - Description unionDescription = new Union(disjuncts); - Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered); - Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered); - - //compute the coverage - double recall = posCovered.size() / (double)lp.getPositiveExamples().size(); - double precision = (posCovered.size() + negCovered.size() == 0) - ? 0 - : posCovered.size() / (double)(posCovered.size() + negCovered.size()); - - double coverageScore = Heuristics.getFScore(recall, precision, beta); - -// ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered); -// score.setAccuracy(coverageScore); - QueryTreeScore score = new QueryTreeScore(coverageScore, coverageScore, posCovered, posNotCovered, negCovered, negNotCovered, -1, -1); - - return new EvaluatedDescription(unionDescription, score); + return evaluatedDescriptions; } + private EvaluatedDescription buildCombinedSolution(){ + EvaluatedDescription bestCombinedSolution = null; + double bestScore = Double.NEGATIVE_INFINITY; + LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values(); + strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM}; + for (LiteralNodeConversionStrategy strategy : strategies) { + EvaluatedDescription combinedSolution; + if(partialSolutions.size() == 1){ + combinedSolution = partialSolutions.get(0).asEvaluatedDescription(strategy); + } else { + List<Description> disjuncts = new ArrayList<Description>(); + + Set<Individual> posCovered = new HashSet<Individual>(); + Set<Individual> negCovered = new HashSet<Individual>(); + + //build the union of all class expressions + Description partialDescription; + for (EvaluatedQueryTree<String> partialSolution : partialSolutions) { + partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( + partialSolution.getTree().asOWLClassExpression(strategy)); + disjuncts.add(partialDescription); + posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives()); + negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives()); + } + Description unionDescription = new Union(disjuncts); + + Set<Individual> posNotCovered = Sets.difference(lp.getPositiveExamples(), posCovered); + Set<Individual> negNotCovered = Sets.difference(lp.getNegativeExamples(), negCovered); + + //compute the coverage + double recall = posCovered.size() / (double)lp.getPositiveExamples().size(); + double precision = (posCovered.size() + negCovered.size() == 0) + ? 0 + : posCovered.size() / (double)(posCovered.size() + negCovered.size()); + + double coverageScore = Heuristics.getFScore(recall, precision, beta); + +// ScoreTwoValued score = new ScoreTwoValued(posCovered, posNotCovered, negCovered, negNotCovered); +// score.setAccuracy(coverageScore); + QueryTreeScore score = new QueryTreeScore(coverageScore, coverageScore, posCovered, posNotCovered, negCovered, negNotCovered, -1, -1); + + combinedSolution = new EvaluatedDescription(unionDescription, score); + } + if(combinedSolution.getAccuracy() > bestScore){ + bestCombinedSolution = combinedSolution; + bestCurrentScore = combinedSolution.getAccuracy(); + } + } + return bestCombinedSolution; + } + private void reset(){ currentBestSolution = null; partialSolutions = new ArrayList<EvaluatedQueryTree<String>>(); @@ -524,7 +671,20 @@ return treeCache; } + private Set<Individual> asIndividuals(Collection<QueryTree<String>> trees){ + Set<Individual> individuals = new HashSet<Individual>(trees.size()); + for (QueryTree<String> queryTree : trees) { + individuals.add(tree2Individual.get(queryTree)); + } + return individuals; + } + private void asTree(Description d){ + QueryTree<String> tree = new QueryTreeImpl<String>(""); + for (Description child : d.getChildren()) { + + } + } /** * Return all trees from the given list {@code allTrees} which are not already subsumed by {@code tree}. @@ -587,7 +747,7 @@ } } for (QueryTree<String> queryTree : distinctTrees) {//System.out.println(queryTree.getStringRepresentation()); - EvaluatedQueryTree<String> evaluatedQueryTree = evaluate(queryTree, false); + EvaluatedQueryTree<String> evaluatedQueryTree = evaluateSimple(queryTree, false); todoList.add(evaluatedQueryTree); } } @@ -656,6 +816,18 @@ } /** + * Shows the current setup of the algorithm. + */ + private void showSetup(){ + String setup = "Setup:"; + setup += "\n#Pos. examples:" + currentPosExamples.size(); + setup += "\n#Neg. examples:" + currentNegExamples.size(); + setup += "\nHeuristic:" + heuristic.getHeuristicType().name(); + setup += "\nbeta=" + beta; + logger.info(setup); + } + + /** * @param noisePercentage the noisePercentage to set */ public void setNoisePercentage(double noisePercentage) { @@ -684,6 +856,20 @@ this.maxTreeComputationTimeInSeconds = maxTreeComputationTimeInSeconds; } + /** + * @return the heuristic + */ + public QueryTreeHeuristic getHeuristic() { + return heuristic; + } + + /** + * @param heuristic the heuristic to set + */ + public void setHeuristic(QueryTreeHeuristic heuristic) { + this.heuristic = heuristic; + } + /* (non-Javadoc) * @see java.lang.Object#clone() */ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeHeuristic.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -106,15 +106,19 @@ double mas = 0d; switch (heuristicType) { case FMEASURE: + mas = Double.POSITIVE_INFINITY; break; case PRED_ACC: mas = (posExamplesWeight * tp + tn - fp) / (posExamplesWeight * (tp + fn) + tn + fp); break; case ENTROPY: + mas = Double.POSITIVE_INFINITY; break; case MATTHEWS_CORRELATION: + mas = Double.POSITIVE_INFINITY; break; case YOUDEN_INDEX: + mas = Double.POSITIVE_INFINITY; break; default: break; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -87,6 +87,8 @@ void addChild(QueryTreeImpl<N> child, Object edge); + void addChild(QueryTree<N> child, Object edge); + void addChild(QueryTreeImpl<N> child, Object edge, int position); int removeChild(QueryTreeImpl<N> child); @@ -150,6 +152,8 @@ RDFDatatype getDatatype(); Set<Literal> getLiterals(); + + void setParent(QueryTree<N> parent); /** * @param edge Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -53,6 +53,9 @@ import org.jgrapht.ext.GraphMLExporter; import org.jgrapht.ext.VertexNameProvider; import org.jgrapht.graph.DefaultDirectedGraph; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.model.OWLDataFactory; @@ -101,6 +104,8 @@ public enum LiteralNodeSubsumptionStrategy { DATATYPE, INTERVAL, + MIN, + MAX, ENUMERATION, OFF } @@ -117,7 +122,11 @@ /** * Literals as datatype, e.g. xsd:integer */ - SOME_VALUES_FROM + SOME_VALUES_FROM, + + MIN, + + MAX, } private N userObject; @@ -169,7 +178,12 @@ } public QueryTreeImpl(N userObject, NodeType nodeType) { + this(userObject, nodeType, 0); + } + + public QueryTreeImpl(N userObject, NodeType nodeType, int id) { this.userObject = userObject; + this.id = id; children = new ArrayList<QueryTreeImpl<N>>(); child2EdgeMap = new HashMap<QueryTree<N>, Object>(); edge2ChildrenMap = new HashMap<String, List<QueryTree<N>>>(); @@ -305,13 +319,33 @@ this.parent = parent; this.parent.children.add(this); } + + /* (non-Javadoc) + * @see org.dllearner.algorithms.qtl.datastructures.QueryTree#setParent(org.dllearner.algorithms.qtl.datastructures.QueryTree) + */ + @Override + public void setParent(QueryTree<N> parent) { + setParent((QueryTreeImpl<N>)parent); + } - public void addChild(QueryTreeImpl<N> child) { children.add(child); child.parent = this; } + public void addChild(QueryTree<N> child) { + children.add((QueryTreeImpl<N>) child); + child.setParent(this); + } + + /* (non-Javadoc) + * @see org.dllearner.algorithms.qtl.datastructures.QueryTree#addChild(org.dllearner.algorithms.qtl.datastructures.QueryTree, java.lang.Object) + */ + @Override + public void addChild(QueryTree<N> child, Object edge) { + addChild((QueryTreeImpl<N>)child, edge); + } + @Override public void addChild(QueryTreeImpl<N> child, int position) { children.add(position, child); @@ -516,10 +550,13 @@ private boolean subsumes(Set<Literal> subsumer, Set<Literal> subsumee, LiteralNodeSubsumptionStrategy strategy){ if(strategy == LiteralNodeSubsumptionStrategy.DATATYPE){ - + //check if both datatypes are the same + RDFDatatype subsumerDatatype = getDatatype(subsumer); + RDFDatatype subsumeeDatatype = getDatatype(subsumee); + return subsumerDatatype.equals(subsumeeDatatype); } else if(strategy == LiteralNodeSubsumptionStrategy.ENUMERATION){ return subsumer.containsAll(subsumee); - } else if(strategy == LiteralNodeSubsumptionStrategy.INTERVAL){ + } else { //check if both datatypes are the same RDFDatatype subsumerDatatype = getDatatype(subsumer); RDFDatatype subsumeeDatatype = getDatatype(subsumee); @@ -532,19 +569,35 @@ return true; } - //check if subsumee interval is contained in subsumer interval - Literal subsumerMin = getMin(subsumer); - Literal subsumerMax = getMax(subsumer); + if(strategy == LiteralNodeSubsumptionStrategy.INTERVAL){ + //check if subsumee interval is contained in subsumer interval + Literal subsumerMin = getMin(subsumer); + Literal subsumerMax = getMax(subsumer); + + Literal subsumeeMin = getMin(subsumee); + Literal subsumeeMax = getMax(subsumee); + + boolean leftMoreGeneral = isLessOrEqual(subsumerMin, subsumeeMin); + boolean rightMoreGeneral = isGreaterOrEqual(subsumerMax, subsumeeMax); + + if(!(leftMoreGeneral && rightMoreGeneral)){ + // System.out.println("[" + subsumeeMin + "," + subsumeeMax + "] not in interval " + "[" + subsumerMin + "," + subsumerMax + "]"); + return false; + } + } else if(strategy == LiteralNodeSubsumptionStrategy.MIN){ - Literal subsumeeMin = getMin(subsumee); - Literal subsumeeMax = getMax(subsumee); + //check if subsumee min is greater than subsumer min + Literal subsumerMin = getMin(subsumer); + Literal subsumeeMin = getMin(subsumee); + + return isGreaterOrEqual(subsumeeMin, subsumerMin); + } else if(strategy == LiteralNodeSubsumptionStrategy.MAX){ - boolean leftMoreGeneral = isLessOrEqual(subsumerMin, subsumeeMin); - boolean rightMoreGeneral = isGreaterOrEqual(subsumerMax, subsumeeMax); - - if(!(leftMoreGeneral && rightMoreGeneral)){ -// System.out.println("[" + subsumeeMin + "," + subsumeeMax + "] not in interval " + "[" + subsumerMin + "," + subsumerMax + "]"); - return false; + //check if subsumee min is greater than subsumer min + Literal subsumerMax = getMax(subsumer); + Literal subsumeeMax = getMax(subsumee); + + return isGreaterOrEqual(subsumerMax, subsumeeMax); } } return true; @@ -1417,6 +1470,10 @@ dataRange = asDataOneOf(df, literals); } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.FACET_RESTRICTION){ dataRange = asFacet(df, literals); + } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MIN){ + dataRange = asMinFacet(df, literals); + } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MAX){ + dataRange = asMaxFacet(df, literals); } } classExpressions.add(df.getOWLDataSomeValuesFrom(p, dataRange)); @@ -1462,6 +1519,30 @@ return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction, maxRestriction); } + private OWLDataRange asMinFacet(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a facet of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + Literal min = getMin(literals); + + OWLFacetRestriction minRestriction = df.getOWLFacetRestriction(OWLFacet.MIN_INCLUSIVE, asOWLLiteral(df, min)); + + return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction); + } + + private OWLDataRange asMaxFacet(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a facet of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + Literal max = getMax(literals); + + OWLFacetRestriction maxRestriction = df.getOWLFacetRestriction(OWLFacet.MAX_INCLUSIVE, asOWLLiteral(df, max)); + + return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), maxRestriction); + } + private OWLDataRange asDataOneOf(OWLDataFactory df, Set<Literal> literals){ //return Boolean datatype because it doesn't make sense to return a enumeration of Boolean values if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ @@ -1506,6 +1587,45 @@ } } + public String asJSON(){ + + PrefixCCMap prefixes = PrefixCCMap.getInstance(); + JSONObject json = null; + try { + json = buildJSON(this, prefixes); + JSONArray array = new JSONArray(); + buildJSON2(array, this, prefixes); + System.out.println(array); + } catch (JSONException e) { + e.printStackTrace(); + } + + + return json.toString(); + } + + private JSONObject buildJSON(QueryTree<N> tree, PrefixCCMap prefixes) throws JSONException{ + JSONObject json = new JSONObject(); + json.put("name", prefixed(prefixes, tree.getUserObject().toString())); + JSONArray children = new JSONArray(); + for (QueryTree<N> child : tree.getChildren()) { + children.put(buildJSON(child, prefixes)); + } + json.put("children", children); + return json; + } + + private void buildJSON2(JSONArray array, QueryTree<N> tree, PrefixCCMap prefixes) throws JSONException{ + for (QueryTree<N> child : tree.getChildren()) { + JSONObject json = new JSONObject(); + json.put("source", tree.getId()); + json.put("target", child.getId()); + json.put("type", prefixed(prefixes, tree.getEdge(child).toString())); + array.put(json); + buildJSON2(array, child, prefixes); + } + } + private String prefixed(Map<String, String> prefixes, String uri){ if(uri.startsWith("http://")){ for (Entry<String, String> entry : prefixes.entrySet()) { @@ -1561,5 +1681,9 @@ e.printStackTrace(); } } + + + + } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -8,6 +8,9 @@ import org.dllearner.learningproblems.QueryTreeScore; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; +import com.google.common.collect.ComparisonChain; +import com.google.common.collect.Ordering; + public class EvaluatedQueryTree<N> implements Comparable<EvaluatedQueryTree<N>>{ private QueryTree<N> tree; @@ -57,14 +60,17 @@ @Override public int compareTo(EvaluatedQueryTree<N> other) { - double diff = getScore() - other.getScore(); - if(diff == 0){ - return -1; - } else if(diff > 0){ - return -1; - } else { - return 1; - } + return ComparisonChain.start() + .compare(this.getScore(), other.getScore()) + .result(); +// double diff = getScore() - other.getScore(); +// if(diff == 0){ +// return -1; +// } else if(diff > 0){ +// return -1; +// } else { +// return 1; +// } } public EvaluatedDescription asEvaluatedDescription(){ @@ -72,6 +78,11 @@ getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)), score); } + public EvaluatedDescription asEvaluatedDescription(LiteralNodeConversionStrategy strategy){ + return new EvaluatedDescription(DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( + getTree().asOWLClassExpression(strategy)), score); + } + /* (non-Javadoc) * @see java.lang.Object#toString() */ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -4,16 +4,65 @@ package org.dllearner.algorithms.qtl.util; import java.util.Collection; +import java.util.Stack; import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.NodeType; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.ToStringRenderer; +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.OWLDataComplementOf; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataIntersectionOf; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataRangeVisitor; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLDataUnionOf; +import org.semanticweb.owlapi.model.OWLDatatype; +import org.semanticweb.owlapi.model.OWLDatatypeRestriction; +import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; +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.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectUnionOf; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyChange; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.PrefixManager; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; +import org.semanticweb.owlapi.util.DefaultPrefixManager; +import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; + +import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +import com.hp.hpl.jena.vocabulary.RDF; + /** * Converts query trees into OWL class expressions and vice versa. * @author Lorenz Buehmann * */ -public class QueryTreeConverter { +public class QueryTreeConverter implements OWLClassExpressionVisitor, OWLDataRangeVisitor{ + Stack<QueryTree<String>> stack = new Stack<QueryTree<String>>(); + int id = 0; + /** * Returns a OWL class expression of the union of the given query trees. * @param queryTrees @@ -23,5 +72,246 @@ //check for common paths } + + public QueryTree<String> asQueryTree(OWLClassExpression expression){ +// stack.push(new QueryTreeImpl<String>("?")); + reset(); + expression.accept(this); + return stack.pop(); + } + + private void reset(){ + id = 0; + stack.clear(); + } + private void fireUnsupportedFeatureException(OWLClassExpression expression) { + throw new IllegalArgumentException("Conversion of " + expression.getClass().getSimpleName() + " is not supported."); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLClass) + */ + @Override + public void visit(OWLClass cls) { + stack.peek().addChild(new QueryTreeImpl<String>(cls.toStringID(), NodeType.RESOURCE, id++), RDF.type.getURI()); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectIntersectionOf) + */ + @Override + public void visit(OWLObjectIntersectionOf expr) { + boolean root = stack.isEmpty(); + stack.push(new QueryTreeImpl<String>("?", NodeType.VARIABLE, id++)); + for (OWLClassExpression op : expr.getOperandsAsList()) { + op.accept(this); + } +// if(!root) +// stack.pop(); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectUnionOf) + */ + @Override + public void visit(OWLObjectUnionOf expr) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectComplementOf) + */ + @Override + public void visit(OWLObjectComplementOf expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom) + */ + @Override + public void visit(OWLObjectSomeValuesFrom expr) { + QueryTree<String> parent = stack.peek(); + QueryTree<String> child; + OWLClassExpression filler = expr.getFiller(); + if(filler.isAnonymous()){ + if(!(filler instanceof OWLObjectIntersectionOf)){ + stack.push(new QueryTreeImpl<String>("?", NodeType.VARIABLE, id++)); + } + expr.getFiller().accept(this); + child = stack.pop(); + } else { + child = new QueryTreeImpl<String>(filler.asOWLClass().toStringID(), NodeType.RESOURCE, id++); + } + parent.addChild(child, expr.getProperty().asOWLObjectProperty().toStringID()); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectAllValuesFrom) + */ + @Override + public void visit(OWLObjectAllValuesFrom expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasValue) + */ + @Override + public void visit(OWLObjectHasValue expr) { + QueryTree<String> tree = stack.peek(); + tree.addChild(new QueryTreeImpl<String>(expr.getValue().asOWLNamedIndividual().toStringID(), NodeType.RESOURCE, id++), expr.getProperty().asOWLObjectProperty().toStringID()); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMinCardinality) + */ + @Override + public void visit(OWLObjectMinCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectExactCardinality) + */ + @Override + public void visit(OWLObjectExactCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectMaxCardinality) + */ + @Override + public void visit(OWLObjectMaxCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectHasSelf) + */ + @Override + public void visit(OWLObjectHasSelf expr) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLObjectOneOf) + */ + @Override + public void visit(OWLObjectOneOf expr) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataSomeValuesFrom) + */ + @Override + public void visit(OWLDataSomeValuesFrom expr) { + QueryTree<String> tree = stack.peek(); + expr.getFiller().accept(this); + QueryTree<String> child = stack.pop(); + tree.addChild(child, expr.getProperty().asOWLDataProperty().toStringID()); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataAllValuesFrom) + */ + @Override + public void visit(OWLDataAllValuesFrom expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataHasValue) + */ + @Override + public void visit(OWLDataHasValue expr) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMinCardinality) + */ + @Override + public void visit(OWLDataMinCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataExactCardinality) + */ + @Override + public void visit(OWLDataExactCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLClassExpressionVisitor#visit(org.semanticweb.owlapi.model.OWLDataMaxCardinality) + */ + @Override + public void visit(OWLDataMaxCardinality expr) { + fireUnsupportedFeatureException(expr); + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDatatype) + */ + @Override + public void visit(OWLDatatype arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataOneOf) + */ + @Override + public void visit(OWLDataOneOf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataComplementOf) + */ + @Override + public void visit(OWLDataComplementOf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataIntersectionOf) + */ + @Override + public void visit(OWLDataIntersectionOf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDataUnionOf) + */ + @Override + public void visit(OWLDataUnionOf arg0) { + } + + /* (non-Javadoc) + * @see org.semanticweb.owlapi.model.OWLDataRangeVisitor#visit(org.semanticweb.owlapi.model.OWLDatatypeRestriction) + */ + @Override + public void visit(OWLDatatypeRestriction arg0) { + } + + public static void main(String[] args) throws Exception { + ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLDataFactory df = man.getOWLDataFactory(); + PrefixManager pm = new DefaultPrefixManager("http://example.org/"); + OWLClassExpression ce = df.getOWLObjectIntersectionOf( + df.getOWLClass("A", pm), + df.getOWLObjectSomeValuesFrom( + df.getOWLObjectProperty("p", pm), + df.getOWLObjectSomeValuesFrom( + df.getOWLObjectProperty("r", pm), + df.getOWLObjectIntersectionOf( + df.getOWLClass("A", pm), + df.getOWLClass("B", pm)))) + ); + System.out.println(ce); + QueryTreeConverter converter = new QueryTreeConverter(); + QueryTree<String> tree = converter.asQueryTree(ce); + tree.dump(); + } + } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return " double[<= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return " double[<= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " <= " + value; + return " double[<= " + value + "]"; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return " double[>= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return " double[>= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " >= " + value; + return " double[>= " + value + "]"; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLDataRangeConverter.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -97,13 +97,16 @@ max = OWLAPIConverter.convertConstant(value); } } - double minValue = Double.parseDouble(min.getLiteral()); - double maxValue = Double.parseDouble(max.getLiteral()); + if(min != null && max != null){ + double minValue = Double.parseDouble(min.getLiteral()); + double maxValue = Double.parseDouble(max.getLiteral()); dataRange = new DoubleMinMaxRange(minValue, maxValue); } else if(min != null && max == null){ + double minValue = Double.parseDouble(min.getLiteral()); dataRange = new DoubleMinValue(minValue); } else if(max != null && min == null){ + double maxValue = Double.parseDouble(max.getLiteral()); dataRange = new DoubleMaxValue(maxValue); } else { Modified: trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -67,7 +67,7 @@ tree.dump(); System.out.println("-----------------------------"); cnt++; - System.out.println(((QueryTreeImpl<String>)tree).toQuery()); +// System.out.println(((QueryTreeImpl<String>)tree).toQuery()); } @@ -76,6 +76,7 @@ System.out.println("LGG"); lgg.dump(); + System.out.println(((QueryTreeImpl<String>)lgg).asJSON()); QueryTreeImpl<String> tree = factory.getQueryTree("?"); QueryTreeImpl<String> subTree1 = new QueryTreeImpl<String>("?"); Added: trunk/dllearner-parent.iml =================================================================== --- trunk/dllearner-parent.iml (rev 0) +++ trunk/dllearner-parent.iml 2014-05-22 02:22:16 UTC (rev 4269) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="false"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> + Modified: trunk/examples/mutagenesis/train1.conf =================================================================== --- trunk/examples/mutagenesis/train1.conf 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/examples/mutagenesis/train1.conf 2014-05-22 02:22:16 UTC (rev 4269) @@ -246,10 +246,11 @@ "kb:f6" } -alg.type = "ocel" +alg.type = "celoe" alg.noisePercentage = 30 alg.writeSearchTree = false alg.startClass = "kb:Compound" +alg.maxExecutionTimeInSeconds = 60 alg.searchTreeFile = "log/mutagenesis/searchTree.log" Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/pom.xml 2014-05-22 02:22:16 UTC (rev 4269) @@ -195,7 +195,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-core</artifactId> - <version>2.7.2</version> + <version>2.11.1</version> </dependency> <!--SwingX is in central --> <dependency> Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EProcurementUseCase.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -63,12 +63,12 @@ private static final Logger logger = Logger.getLogger(EProcurementUseCase.class.getName()); - static final int maxNrOfPositiveExamples = 100; - static final int maxNrOfNegativeExamples = 200; + static final int maxNrOfPositiveExamples = 10000; + static final int maxNrOfNegativeExamples = 10000; static boolean posOnly = false; - static int maxCBDDepth = 2; + static int maxCBDDepth = 3; static int maxNrOfResults = 100; - static int maxExecutionTimeInSeconds = 200; + static int maxExecutionTimeInSeconds = 500; static double noiseInPercentage = 50; static boolean useNegation = false; static boolean useAllConstructor = false; @@ -117,10 +117,10 @@ // schema.read(new URL("http://opendata.cz/pco/public-contracts.ttl").openStream(), null, "TURTLE"); model.add(schema); // get positive examples - SortedSet<Individual> positiveExamples = getExamples(model, posClass); + SortedSet<Individual> positiveExamples = getExamples(model, posClass, maxNrOfPositiveExamples); // get negative examples // SortedSet<Individual> negativeExamples = getNegativeExamples(model, cls, positiveExamples); - SortedSet<Individual> negativeExamples = getExamples(model, negClass); + SortedSet<Individual> negativeExamples = getExamples(model, negClass, maxNrOfNegativeExamples); //get the lgg of the pos. examples // showLGG(model, positiveExamples); // build a sample of the kb @@ -205,14 +205,14 @@ ((QueryTreeImpl<String>) lgg).asGraph(); } - private static SortedSet<Individual> getExamples(Model model, NamedClass cls){ + private static SortedSet<Individual> getExamples(Model model, NamedClass cls, int limit){ logger.info("Generating examples..."); - SortedSet<Individual> individuals = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(model)).getIndividuals(cls, 1000); + SortedSet<Individual> individuals = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(model)).getIndividuals(cls, limit); List<Individual> individualsList = new ArrayList<>(individuals); // Collections.shuffle(individualsList, new Random(1234)); individuals.clear(); individuals.addAll(individualsList.subList(0, Math.min(maxNrOfPositiveExamples, individualsList.size()))); - logger.info("Done. Got " + individuals.size() + ": " + individuals); + logger.info("Done. Got " + individuals.size()); return individuals; } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-12 09:53:57 UTC (rev 4268) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java 2014-05-22 02:22:16 UTC (rev 4269) @@ -8,37 +8,30 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.FileAppender; +import org.apache.log4j.Layout; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; import org.dllearner.algorithms.qtl.QTL2Disjunctive; import org.dllearner.algorithms.qtl.QueryTreeFactory; -import org.dllearner.algorithms.qtl.datastructures.QueryTree; -import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.dllearner.algorithms.qtl.QueryTreeHeuristic; import org.dllearner.algorithms.qtl.impl.QueryTreeFactoryImpl; import org.dllearner.cli.CLI; import org.dllearner.cli.CrossValidation; -import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.owl.Individual; -import org.dllearner.kb.OWLAPIOntology; +import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.learningproblems.PosNegLP; -import org.dllearner.learningproblems.PosNegLPStandard; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.scripts.NestedCrossValidation; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -48,11 +41,17 @@ */ public class QTLEvaluation { - int nrOfFolds = 3; + int nrOfFolds = 10; private int nrOfPosExamples = 300; private int nrOfNegExamples = 300; - CLI cli = new CLI(new File("../test/qtl/carcinogenesis/train.conf")); + CLI carcinogenesis = new CLI(new File("../test/qtl/carcinogenesis/train.conf")); + CLI mammographic = new CLI(new File("../test/qtl/mammographic/train.conf")); + CLI suramin = new CLI(new File("../test/qtl/suramin/train.conf")); + CLI heart = new CLI(new File("../test/qtl/heart/train.conf")); + CLI breasttissue = new CLI(new File("../test/qtl/breasttissue/train1.conf")); + CLI parkinsons = new CLI(new File("../test/qtl/parkinsons/train.conf")); + CLI mutagenesis = new CLI(new File("../test/qtl/mutagenesis/train1.conf")); private Model model; private OWLOntology ontology; @@ -65,7 +64,7 @@ queryTreeFactory = new QueryTreeFactoryImpl(); queryTreeFactory.setMaxDepth(3); - loadDataset(); +// loadDataset(); loadExamples(); } @@ -89,46 +88,100 @@ private void loadExamples() throws ComponentInitException, IOException{ - cli.init(); - lp = (PosNegLP) cli.getLearningProblem(); +// cli.init(); +// lp = (PosNegLP) cli.getLearningProblem(); // get examples and shuffle them - List<Individual> posExamples = new LinkedList<Individual>(((PosNegLP)lp).getPositiveExamples()); - Collections.shuffle(posExamples, new Random(1)); - List<Individual> negExamples = new LinkedList<Individual>(((PosNegLP)lp).getNegativeExamples()); - Collections.shuffle(negExamples, new Random(2)); - posExamples = posExamples.subList(0, Math.min(posExamples.size(), nrOfPosExamples)); - neg... [truncated message content] |
From: <ki...@us...> - 2014-06-23 12:57:30
|
Revision: 4276 http://sourceforge.net/p/dl-learner/code/4276 Author: kirdie Date: 2014-06-23 12:57:22 +0000 (Mon, 23 Jun 2014) Log Message: ----------- made components-core and -ext compile again by removing version number of maven exec plugin. also fixed some warnings in the poms about duplicate info which is already contained in the parent. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-ext/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-05-27 13:03:09 UTC (rev 4275) +++ trunk/components-core/pom.xml 2014-06-23 12:57:22 UTC (rev 4276) @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.dllearner</groupId> + <!-- <groupId>org.dllearner</groupId> --> <artifactId>components-core</artifactId> <name>DL Learner Core Components</name> Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2014-05-27 13:03:09 UTC (rev 4275) +++ trunk/components-ext/pom.xml 2014-06-23 12:57:22 UTC (rev 4276) @@ -2,12 +2,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.dllearner</groupId> + <!-- <groupId>org.dllearner</groupId> --> <artifactId>components-ext</artifactId> <packaging>jar</packaging> <name>components-ext</name> - <version>1.0-SNAPSHOT</version> + <!-- <version>1.0-SNAPSHOT</version> --> <url>http://aksw.org/Projects/DLLearner</url> <parent> @@ -192,7 +192,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> + <!-- <version>1.2.1</version> --> <executions> <execution> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2014-07-29 13:53:27
|
Revision: 4280 http://sourceforge.net/p/dl-learner/code/4280 Author: lorenz_b Date: 2014-07-29 13:53:19 +0000 (Tue, 29 Jul 2014) Log Message: ----------- Added punning test. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OENode.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java trunk/components-core/src/main/java/org/dllearner/core/owl/Constant.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java trunk/components-core/src/main/java/org/dllearner/reasoning/ExistentialRestrictionMaterialization.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/ConceptComparator.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIDescriptionConvertVisitor.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/RoleComparator.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETestCorpus.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/ISLETestNoCorpus.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/PMIRelevanceMetricTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/isle/metrics/RelevanceMetricsTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/pattern/OWLPatternDetectionTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/GeneralisationTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/LGGTest.java trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/QTLTest.java trunk/components-core/src/test/java/org/dllearner/test/junit/SomeOnlyReasonerTest.java trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/pom.xml trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/RAChallenge.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/QTLEvaluation.java trunk/scripts/src/main/java/org/dllearner/scripts/pattern/OWLAxiomPatternUsageEvaluation.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/pom.xml 2014-07-29 13:53:19 UTC (rev 4280) @@ -100,10 +100,10 @@ <artifactId>mysql-connector-java</artifactId> </dependency> - <dependency> + <!-- <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> - </dependency> + </dependency> --> <dependency> <groupId>com.clarkparsia</groupId> @@ -152,10 +152,6 @@ <artifactId>hermit</artifactId> </dependency> - <dependency> - <groupId>eu.trowl</groupId> - <artifactId>trowl-core</artifactId> - </dependency> <dependency> <groupId>com.jamonapi</groupId> @@ -249,6 +245,11 @@ <artifactId>jsexp</artifactId> <version>0.1.0</version> </dependency> + <dependency> + <groupId>eu.trowl</groupId> + <artifactId>trowl-core</artifactId> + <version>1.4.0</version> + </dependency> <dependency> <groupId>xerces</groupId> @@ -334,6 +335,16 @@ <artifactId>solr-solrj</artifactId> <version>4.4.0</version> </dependency> + <dependency> + <groupId>nz.ac.waikato.cms.weka</groupId> + <artifactId>weka-dev</artifactId> + <version>3.7.11</version> +</dependency> + <!-- <dependency> + <groupId>nz.ac.waikato.cms.weka</groupId> + <artifactId>weka-stable</artifactId> + <version>3.6.9</version> + </dependency> --> </dependencies> <dependencyManagement> <dependencies> 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 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -32,7 +32,6 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.algorithms.elcopy.ELLearningAlgorithm; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractHeuristic; import org.dllearner.core.AbstractKnowledgeSource; @@ -50,7 +49,6 @@ import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; import org.dllearner.kb.OWLAPIOntology; -import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyLP; @@ -92,7 +90,7 @@ * */ @ComponentAnn(name="CELOE", shortName="celoe", 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 CELOE extends AbstractCELA { +public class CELOE extends AbstractCELA implements Cloneable{ private static Logger logger = Logger.getLogger(CELOE.class); // private CELOEConfigurator configurator; @@ -224,6 +222,39 @@ } + public CELOE(CELOE celoe){ + setReasoner(celoe.reasoner); + setLearningProblem(celoe.learningProblem); + setAllowedConcepts(celoe.getAllowedConcepts()); + setExpandAccuracy100Nodes(celoe.expandAccuracy100Nodes); + setFilterDescriptionsFollowingFromKB(celoe.filterDescriptionsFollowingFromKB); + setHeuristic(celoe.heuristic); + setIgnoredConcepts(celoe.ignoredConcepts); + setLearningProblem(celoe.learningProblem); + setMaxClassExpressionTests(celoe.maxClassExpressionTests); + setMaxClassExpressionTestsAfterImprovement(celoe.maxClassExpressionTestsAfterImprovement); + setMaxDepth(celoe.maxDepth); + setMaxExecutionTimeInSeconds(celoe.maxExecutionTimeInSeconds); + setMaxExecutionTimeInSecondsAfterImprovement(celoe.maxExecutionTimeInSecondsAfterImprovement); + setMaxNrOfResults(celoe.maxNrOfResults); + setNoisePercentage(celoe.noisePercentage); + RhoDRDown op = new RhoDRDown((RhoDRDown)celoe.operator); + try { + op.init(); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + setOperator(op); + setReplaceSearchTree(celoe.replaceSearchTree); + setReuseExistingDescription(celoe.reuseExistingDescription); + setSingleSuggestionMode(celoe.singleSuggestionMode); + setStartClass(celoe.startClass); + setStopOnFirstDefinition(celoe.stopOnFirstDefinition); + setTerminateOnNoiseReached(celoe.terminateOnNoiseReached); + setUseMinimizer(celoe.useMinimizer); + setWriteSearchTree(celoe.writeSearchTree); + } + public CELOE(AbstractLearningProblem problem, AbstractReasonerComponent reasoner) { super(problem, reasoner); // configurator = new CELOEConfigurator(this); @@ -529,7 +560,7 @@ treeString += " " + n + "\n"; } } - treeString += startNode.toTreeString(baseURI); + treeString += startNode.toTreeString(baseURI, prefixes); treeString += "\n"; if (replaceSearchTree) @@ -1134,6 +1165,14 @@ public void setExpandAccuracy100Nodes(boolean expandAccuracy100Nodes) { this.expandAccuracy100Nodes = expandAccuracy100Nodes; } + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return new CELOE(this); + } public static void main(String[] args) throws Exception{ String cls = "http://purl.org/procurement/public-contracts#Tender"; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OENode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OENode.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/OENode.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -22,6 +22,7 @@ import java.text.DecimalFormat; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.dllearner.algorithms.SearchTreeNode; import org.dllearner.algorithms.isle.NLPHeuristic; @@ -119,7 +120,11 @@ } public String getShortDescription(String baseURI) { - String ret = description.toString(baseURI,null) + " ["; + return getShortDescription(baseURI, null); + } + + public String getShortDescription(String baseURI, Map<String, String> prefixes) { + String ret = description.toString(baseURI,prefixes) + " ["; // ret += "score" + NLPHeuristic.getNodeScore(this) + ","; ret += "acc:" + dfPercent.format(accuracy) + ", "; ret += "he:" + horizontalExpansion + ", "; @@ -141,6 +146,10 @@ return toTreeString(0, baseURI).toString(); } + public String toTreeString(String baseURI, Map<String, String> prefixes) { + return toTreeString(0, baseURI, prefixes).toString(); + } + private StringBuilder toTreeString(int depth, String baseURI) { StringBuilder treeString = new StringBuilder(); for(int i=0; i<depth-1; i++) @@ -153,6 +162,19 @@ } return treeString; } + + private StringBuilder toTreeString(int depth, String baseURI, Map<String, String> prefixes) { + StringBuilder treeString = new StringBuilder(); + for(int i=0; i<depth-1; i++) + treeString.append(" "); + if(depth!=0) + treeString.append("|--> "); + treeString.append(getShortDescription(baseURI, prefixes)+"\n"); + for(OENode child : children) { + treeString.append(child.toTreeString(depth+1,baseURI,prefixes)); + } + return treeString; + } /** * @return the refinementCount @@ -166,5 +188,5 @@ */ public void setRefinementCount(int refinementCount) { this.refinementCount = refinementCount; - } + } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -202,7 +202,7 @@ public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { EvaluatedQueryTree<String> bestSolution = solutions.first(); Description description = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( - bestSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)); + bestSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.MIN_MAX)); return new EvaluatedDescription(description, new AxiomScore(bestSolution.getScore())); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2Disjunctive.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -19,7 +19,6 @@ import org.apache.log4j.Logger; import org.dllearner.algorithms.qtl.cache.QueryTreeCache; import org.dllearner.algorithms.qtl.datastructures.QueryTree; -import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeSubsumptionStrategy; import org.dllearner.algorithms.qtl.operations.lgg.EvaluatedQueryTree; @@ -42,8 +41,10 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.QueryTreeScore; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; +import org.dllearner.utilities.owl.DLSyntaxObjectRenderer; import org.dllearner.utilities.owl.OWLAPIConverter; import org.semanticweb.owlapi.io.ToStringRenderer; +import org.semanticweb.owlapi.model.OWLClassExpression; import org.semanticweb.owlapi.util.SimpleShortFormProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -75,6 +76,7 @@ private Set<Individual> currentNegExamples; private Map<QueryTree<String>, Individual> tree2Individual; + private Map<Individual, QueryTree<String>> individual2Tree; private QueryTreeCache treeCache; @@ -121,7 +123,15 @@ private long partialSolutionStartTime; private double startPosExamplesSize; + private int expressionTests = 0; + LiteralNodeConversionStrategy[] strategies = new LiteralNodeConversionStrategy[]{ + LiteralNodeConversionStrategy.MIN, + LiteralNodeConversionStrategy.MAX, + LiteralNodeConversionStrategy.MIN_MAX, + LiteralNodeConversionStrategy.DATATYPE + }; + public QTL2Disjunctive() {} public QTL2Disjunctive(PosNegLP learningProblem, AbstractReasonerComponent reasoner) throws LearningProblemUnsupportedException{ @@ -154,7 +164,7 @@ */ @Override public void init() throws ComponentInitException { - + ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); if(!(learningProblem instanceof PosNegLP)){ throw new IllegalArgumentException("Only PosNeg learning problems are supported"); } @@ -170,6 +180,7 @@ logger.info("Initializing..."); treeCache = new QueryTreeCache(model); tree2Individual = new HashMap<QueryTree<String>, Individual>(lp.getPositiveExamples().size()+lp.getNegativeExamples().size()); + individual2Tree = new HashMap<Individual, QueryTree<String>>(lp.getPositiveExamples().size()+lp.getNegativeExamples().size()); currentPosExampleTrees = new ArrayList<QueryTree<String>>(lp.getPositiveExamples().size()); currentNegExampleTrees = new ArrayList<QueryTree<String>>(lp.getNegativeExamples().size()); @@ -205,11 +216,13 @@ for (Individual ind : lp.getPositiveExamples()) { queryTree = treeCache.getQueryTree(ind.getName()); tree2Individual.put(queryTree, ind); + individual2Tree.put(ind, queryTree); currentPosExampleTrees.add(queryTree); } for (Individual ind : lp.getNegativeExamples()) { queryTree = treeCache.getQueryTree(ind.getName()); tree2Individual.put(queryTree, ind); + individual2Tree.put(ind, queryTree); currentNegExampleTrees.add(queryTree); } logger.info("...done."); @@ -235,7 +248,7 @@ //compute best (partial) solution computed so far EvaluatedQueryTree<String> bestPartialSolution = computeBestPartialSolution(); - //add if some criteria are satisfied + //add to partial solutions if criteria are satisfied if(bestPartialSolution.getScore() >= minimumTreeScore){ partialSolutions.add(bestPartialSolution); @@ -244,14 +257,14 @@ QueryTree<String> tree; for (Iterator<QueryTree<String>> iterator = currentPosExampleTrees.iterator(); iterator.hasNext();) { tree = iterator.next(); - if(tree.isSubsumedBy(bestPartialSolution.getTree())){ + if(!bestPartialSolution.getFalseNegatives().contains(tree)){//a pos tree that is not covered iterator.remove(); currentPosExamples.remove(tree2Individual.get(tree)); } } for (Iterator<QueryTree<String>> iterator = currentNegExampleTrees.iterator(); iterator.hasNext();) { tree = iterator.next(); - if(tree.isSubsumedBy(bestPartialSolution.getTree())){ + if(bestPartialSolution.getFalsePositives().contains(tree)){//a neg example that is covered iterator.remove(); currentNegExamples.remove(tree2Individual.get(tree)); } @@ -272,8 +285,9 @@ long endTime = System.currentTimeMillis(); logger.info("Finished in " + (endTime-startTime) + "ms."); + logger.info(expressionTests +" descriptions tested"); + logger.info("Combined solution:" + OWLAPIConverter.getOWLAPIDescription(currentBestSolution.getDescription()).toString().replace("\n", "")); - logger.info("Combined solution:" + OWLAPIConverter.getOWLAPIDescription(currentBestSolution.getDescription()).toString().replace("\n", "")); logger.info(currentBestSolution.getScore()); } @@ -291,7 +305,9 @@ logger.trace("TODO list size: " + todoList.size()); //pick best element from todo list currentElement = todoList.poll(); + currentTree = currentElement.getTree(); + logger.info("Next tree: " + currentElement.getTreeScore() + "\n" + OWLAPIConverter.getOWLAPIDescription(currentElement.getEvaluatedDescription().getDescription())); //generate the LGG between the chosen tree and each uncovered positive example Iterator<QueryTree<String>> it = currentElement.getFalseNegatives().iterator(); while (it.hasNext() && !isPartialSolutionTimeExpired() && !isTimeExpired()) { @@ -302,26 +318,29 @@ lggMon.stop(); //evaluate the LGG - Set<EvaluatedQueryTree<String>> solutions = evaluate(lgg, true); + Set<EvaluatedQueryTree<String>> solutions = evaluate2(lgg, true); for (EvaluatedQueryTree<String> solution : solutions) { + expressionTests++; double score = solution.getScore(); double mas = heuristic.getMaximumAchievableScore(solution); if(score >= bestCurrentScore){ - //add to todo list, if not already contained in todo list or solution list - todo(solution); if(score > bestCurrentScore){ logger.info("\tGot better solution:" + solution.getTreeScore()); + logger.info(OWLAPIConverter.getOWLAPIDescription(solution.getEvaluatedDescription().getDescription())); bestCurrentScore = score; bestPartialSolutionTree = solution; } - + //add to todo list, if not already contained in todo list or solution list + todo(solution); } else if(mas >= bestCurrentScore){ todo(solution); } else { + logger.info("Too weak:" + solution.getTreeScore()); // System.out.println("Too general"); // System.out.println("MAS=" + mas + "\nBest=" + bestCurrentScore); } + currentPartialSolutions.add(currentElement); } } @@ -329,7 +348,7 @@ } long endTime = System.currentTimeMillis(); logger.info("...finished in " + (endTime-partialSolutionStartTime) + "ms."); - EvaluatedDescription bestPartialSolution = bestPartialSolutionTree.asEvaluatedDescription(LiteralNodeConversionStrategy.SOME_VALUES_FROM); + EvaluatedDescription bestPartialSolution = bestPartialSolutionTree.getEvaluatedDescription(); logger.info("Best partial solution: " + OWLAPIConverter.getOWLAPIDescription(bestPartialSolution.getDescription()).toString().replace("\n", "") + "\n(" + bestPartialSolution.getScore() + ")"); @@ -410,7 +429,12 @@ Set<EvaluatedQueryTree<String>> evaluatedTrees = new TreeSet<EvaluatedQueryTree<String>>(); LiteralNodeSubsumptionStrategy[] strategies = LiteralNodeSubsumptionStrategy.values(); - strategies = new LiteralNodeSubsumptionStrategy[]{LiteralNodeSubsumptionStrategy.DATATYPE, LiteralNodeSubsumptionStrategy.INTERVAL}; + strategies = new LiteralNodeSubsumptionStrategy[]{ + LiteralNodeSubsumptionStrategy.DATATYPE, + LiteralNodeSubsumptionStrategy.INTERVAL, + LiteralNodeSubsumptionStrategy.MIN, + LiteralNodeSubsumptionStrategy.MAX, + }; for (LiteralNodeSubsumptionStrategy strategy : strategies) { //1. get a score for the coverage = recall oriented List<QueryTree<String>> uncoveredPositiveExampleTrees = new ArrayList<QueryTree<String>>(); @@ -480,18 +504,27 @@ * @param useSpecifity * @return */ - private Set<EvaluatedDescription> evaluate2(QueryTree<String> tree, boolean useSpecifity){ - Set<EvaluatedDescription> evaluatedDescriptions = new TreeSet<EvaluatedDescription>(); + private Set<EvaluatedQueryTree<String>> evaluate2(QueryTree<String> tree, boolean useSpecifity){ + Set<EvaluatedQueryTree<String>> evaluatedTrees = new TreeSet<EvaluatedQueryTree<String>>(); - LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values(); - strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM, LiteralNodeConversionStrategy.FACET_RESTRICTION}; + //test different strategies on the conversion of literal nodes + Set<OWLClassExpression> combinations = new HashSet<OWLClassExpression>(); + for (LiteralNodeConversionStrategy strategy : strategies) { - Description d = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(tree.asOWLClassExpression(strategy)); + OWLClassExpression ce = tree.asOWLClassExpression(strategy); + combinations.add(ce); + } + //compute all combinations of different types of facets +// OWLClassExpression ce = tree.asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION); +// combinations = ce.accept(new ClassExpressionLiteralCombination()); + for (OWLClassExpression c : combinations) { + Description d = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription(c); //convert to individuals SortedSet<Individual> coveredExamples = reasoner.getIndividuals(d); Set<Individual> coveredPosExamples = new TreeSet<Individual>(Sets.intersection(currentPosExamples, coveredExamples)); Set<Individual> uncoveredPosExamples = new TreeSet<Individual>(Sets.difference(currentPosExamples, coveredExamples)); Set<Individual> coveredNegExamples = new TreeSet<Individual>(Sets.intersection(currentNegExamples, coveredExamples)); + Set<Individual> uncoveredNegExamples = new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredExamples)); //compute score double recall = coveredPosExamples.size() / (double)currentPosExamples.size(); @@ -501,7 +534,7 @@ double coverageScore = Heuristics.getFScore(recall, precision, beta); - //2. get a score for the specifity of the query, i.e. how many edges/nodes = precision oriented + //2. get a score for the specificity of the query, i.e. how many edges/nodes = precision oriented int nrOfSpecificNodes = 0; for (QueryTree<String> childNode : tree.getChildrenClosure()) { if(!childNode.getUserObject().equals("?")){ @@ -516,33 +549,38 @@ //3.compute the total score double score = coverageWeight * coverageScore + specifityWeight * specifityScore; - QueryTreeScore queryTreeScore = new QueryTreeScore(score, coverageScore, - new TreeSet<Individual>(Sets.difference(currentPosExamples, uncoveredPosExamples)), uncoveredPosExamples, - coveredNegExamples, new TreeSet<Individual>(Sets.difference(currentNegExamples, coveredNegExamples)), + QueryTreeScore queryTreeScore = new QueryTreeScore( + score, coverageScore, + coveredPosExamples, uncoveredPosExamples, + coveredNegExamples, uncoveredNegExamples, specifityScore, nrOfSpecificNodes); //TODO use only the heuristic to compute the score -// score = heuristic.getScore(evaluatedTree); -// queryTreeScore.setScore(score); -// queryTreeScore.setAccuracy(score); -// -// EvaluatedDescription evaluatedDescription = new EvaluatedDescription(d, queryTreeScore); -// -// evaluatedDescriptions.add(evaluatedDescription); + EvaluatedQueryTree<String> evaluatedTree = new EvaluatedQueryTree<String>(tree, + asQueryTrees(uncoveredPosExamples), asQueryTrees(coveredNegExamples), queryTreeScore); + score = heuristic.getScore(evaluatedTree); + queryTreeScore.setScore(score); + queryTreeScore.setAccuracy(score); + + + EvaluatedDescription evaluatedDescription = new EvaluatedDescription(d, queryTreeScore); + + evaluatedTree.setDescription(evaluatedDescription); + + evaluatedTrees.add(evaluatedTree); } - - return evaluatedDescriptions; + return evaluatedTrees; } private EvaluatedDescription buildCombinedSolution(){ EvaluatedDescription bestCombinedSolution = null; double bestScore = Double.NEGATIVE_INFINITY; LiteralNodeConversionStrategy[] strategies = LiteralNodeConversionStrategy.values(); - strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.SOME_VALUES_FROM}; + strategies = new LiteralNodeConversionStrategy[]{LiteralNodeConversionStrategy.DATATYPE}; for (LiteralNodeConversionStrategy strategy : strategies) { EvaluatedDescription combinedSolution; if(partialSolutions.size() == 1){ - combinedSolution = partialSolutions.get(0).asEvaluatedDescription(strategy); + combinedSolution = partialSolutions.get(0).getEvaluatedDescription(); } else { List<Description> disjuncts = new ArrayList<Description>(); @@ -552,8 +590,7 @@ //build the union of all class expressions Description partialDescription; for (EvaluatedQueryTree<String> partialSolution : partialSolutions) { - partialDescription = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( - partialSolution.getTree().asOWLClassExpression(strategy)); + partialDescription = partialSolution.getEvaluatedDescription().getDescription(); disjuncts.add(partialDescription); posCovered.addAll(partialSolution.getTreeScore().getCoveredPositives()); negCovered.addAll(partialSolution.getTreeScore().getCoveredNegatives()); @@ -679,11 +716,12 @@ return individuals; } - private void asTree(Description d){ - QueryTree<String> tree = new QueryTreeImpl<String>(""); - for (Description child : d.getChildren()) { - + private Set<QueryTree<String>> asQueryTrees(Collection<Individual> individuals){ + Set<QueryTree<String>> trees = new HashSet<QueryTree<String>>(individuals.size()); + for (Individual ind : individuals) { + trees.add(individual2Tree.get(ind)); } + return trees; } /** @@ -802,16 +840,23 @@ private void todo(EvaluatedQueryTree<String> solution){ //check if not already contained in todo list for (EvaluatedQueryTree<String> evTree : todoList) { - if(sameTrees(solution.getTree(), evTree.getTree())){ + //this is a workaround as we have currently no equals method for trees based on the literal conversion strategy +// boolean sameTree = sameTrees(solution.getTree(), evTree.getTree()); + boolean sameTree = OWLAPIConverter.getOWLAPIDescription(evTree.getEvaluatedDescription().getDescription()).toString() + .equals(OWLAPIConverter.getOWLAPIDescription(solution.getEvaluatedDescription().getDescription()).toString()); + if(sameTree){ + logger.warn("Not added to TODO list: Already contained in."); return; } } //check if not already contained in solutions for (EvaluatedQueryTree<String> evTree : currentPartialSolutions) { if(sameTrees(solution.getTree(), evTree.getTree())){ + logger.warn("Not added to partial solutions list: Already contained in."); return; } } + logger.info("Added to TODO list."); todoList.add(solution); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL2DisjunctiveMT.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -240,7 +240,7 @@ public EvaluatedDescription getCurrentlyBestEvaluatedDescription() { EvaluatedQueryTree<String> bestSolution = solutions.first(); Description description = DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( - bestSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)); + bestSolution.getTree().asOWLClassExpression(LiteralNodeConversionStrategy.MIN_MAX)); return new EvaluatedDescription(description, bestSolution.getTreeScore()); } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -118,11 +118,11 @@ /** * Literals as an interval on the datatype, e.g. [>= 5 <=10] */ - FACET_RESTRICTION, + MIN_MAX, /** * Literals as datatype, e.g. xsd:integer */ - SOME_VALUES_FROM, + DATATYPE, MIN, @@ -207,7 +207,7 @@ if(nodeType == NodeType.RESOURCE){ isResourceNode = true; } else if(nodeType == NodeType.LITERAL){ - isResourceNode = true; + isLiteralNode = true; } } @@ -1405,7 +1405,7 @@ * are transformed into existential restrictions. */ public OWLClassExpression asOWLClassExpression(){ - return asOWLClassExpression(LiteralNodeConversionStrategy.SOME_VALUES_FROM); + return asOWLClassExpression(LiteralNodeConversionStrategy.DATATYPE); } /** @@ -1430,7 +1430,7 @@ for(QueryTree<N> child : children){ String childLabel = (String) child.getUserObject(); String predicateString = (String) tree.getEdge(child); - if(predicateString.equals(RDF.type.getURI())){ + if(predicateString.equals(RDF.type.getURI()) || predicateString.equals(RDFS.subClassOf.getURI())){//A if(child.isVarNode()){ classExpressions.addAll(buildOWLClassExpressions(df, child, literalNodeConversionStrategy)); } else { @@ -1438,25 +1438,17 @@ classExpressions.add(df.getOWLClass(IRI.create(childLabel))); } } - } else if(predicateString.equals(RDFS.subClassOf.getURI())){ - if(child.isVarNode()){ - classExpressions.addAll(buildOWLClassExpressions(df, child, literalNodeConversionStrategy)); - } else { - if(!childLabel.equals(OWL.Thing.getURI())){//avoid trivial owl:Thing statements - classExpressions.add(df.getOWLClass(IRI.create(childLabel))); - } - } } else { if(child.isLiteralNode()){ OWLDataProperty p = df.getOWLDataProperty(IRI.create((String) tree.getEdge(child))); - if(childLabel.equals("?")){ + if(childLabel.equals("?")){//p some int Set<Literal> literals = child.getLiterals(); OWLDataRange dataRange = null; if(literals.isEmpty()){//happens if there are heterogeneous datatypes String datatypeURI = OWL2Datatype.RDFS_LITERAL.getURI().toString(); dataRange = df.getOWLDatatype(IRI.create(datatypeURI)); } else { - if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.SOME_VALUES_FROM){ + if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.DATATYPE){ Literal lit = literals.iterator().next(); RDFDatatype datatype = lit.getDatatype(); String datatypeURI; @@ -1468,7 +1460,7 @@ dataRange = df.getOWLDatatype(IRI.create(datatypeURI)); } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.DATA_ONE_OF){ dataRange = asDataOneOf(df, literals); - } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.FACET_RESTRICTION){ + } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MIN_MAX){ dataRange = asFacet(df, literals); } else if(literalNodeConversionStrategy == LiteralNodeConversionStrategy.MIN){ dataRange = asMinFacet(df, literals); @@ -1477,7 +1469,7 @@ } } classExpressions.add(df.getOWLDataSomeValuesFrom(p, dataRange)); - } else { + } else {//p value 1.2 Set<Literal> literals = child.getLiterals(); Literal lit = literals.iterator().next(); OWLLiteral owlLiteral = asOWLLiteral(df, lit); @@ -1486,7 +1478,7 @@ } else { OWLObjectProperty p = df.getOWLObjectProperty(IRI.create((String) tree.getEdge(child))); OWLClassExpression filler; - if(child.isVarNode()){ + if(child.isVarNode()){//p some C Set<OWLClassExpression> fillerClassExpressions = buildOWLClassExpressions(df, child, literalNodeConversionStrategy); if(fillerClassExpressions.isEmpty()){ filler = df.getOWLThing(); @@ -1496,7 +1488,7 @@ filler = df.getOWLObjectIntersectionOf(fillerClassExpressions); } classExpressions.add(df.getOWLObjectSomeValuesFrom(p, filler)); - } else { + } else {//p value {a} classExpressions.add(df.getOWLObjectHasValue(p, df.getOWLNamedIndividual(IRI.create(childLabel)))); } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/EvaluatedQueryTree.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -5,6 +5,7 @@ import org.dllearner.algorithms.qtl.datastructures.QueryTree; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Description; import org.dllearner.learningproblems.QueryTreeScore; import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; @@ -18,6 +19,8 @@ private Collection<QueryTree<N>> falsePositives; private QueryTreeScore score; // private ScoreTwoValued score; + + private EvaluatedDescription description; public EvaluatedQueryTree(QueryTree<N> tree, Collection<QueryTree<N>> falseNegatives, Collection<QueryTree<N>> falsePositives, QueryTreeScore score) { @@ -61,7 +64,8 @@ @Override public int compareTo(EvaluatedQueryTree<N> other) { return ComparisonChain.start() - .compare(this.getScore(), other.getScore()) +// .compare(this.getScore(), other.getScore()) + .compare(other.getScore(), this.getScore()) .result(); // double diff = getScore() - other.getScore(); // if(diff == 0){ @@ -73,9 +77,26 @@ // } } + + /** + * @return the description + */ + public EvaluatedDescription getEvaluatedDescription() { + return asEvaluatedDescription(); + } + /** + * @param description the description to set + */ + public void setDescription(EvaluatedDescription description) { + this.description = description; + } + public EvaluatedDescription asEvaluatedDescription(){ - return new EvaluatedDescription(DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( - getTree().asOWLClassExpression(LiteralNodeConversionStrategy.FACET_RESTRICTION)), score); + if(description == null){ + description = new EvaluatedDescription(DLLearnerDescriptionConvertVisitor.getDLLearnerDescription( + getTree().asOWLClassExpression(LiteralNodeConversionStrategy.MIN_MAX)), score); + } + return description; } public EvaluatedDescription asEvaluatedDescription(LiteralNodeConversionStrategy strategy){ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/QueryTreeConverter.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -4,10 +4,17 @@ package org.dllearner.algorithms.qtl.util; import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import java.util.Stack; +import javax.xml.bind.DatatypeConverter; + import org.dllearner.algorithms.qtl.datastructures.QueryTree; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.LiteralNodeConversionStrategy; import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl.NodeType; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.ToStringRenderer; @@ -24,11 +31,15 @@ import org.semanticweb.owlapi.model.OWLDataMaxCardinality; import org.semanticweb.owlapi.model.OWLDataMinCardinality; import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataRange; import org.semanticweb.owlapi.model.OWLDataRangeVisitor; import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; import org.semanticweb.owlapi.model.OWLDataUnionOf; import org.semanticweb.owlapi.model.OWLDatatype; import org.semanticweb.owlapi.model.OWLDatatypeRestriction; +import org.semanticweb.owlapi.model.OWLFacetRestriction; +import org.semanticweb.owlapi.model.OWLLiteral; import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; import org.semanticweb.owlapi.model.OWLObjectComplementOf; import org.semanticweb.owlapi.model.OWLObjectExactCardinality; @@ -38,20 +49,24 @@ import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; import org.semanticweb.owlapi.model.OWLObjectMinCardinality; import org.semanticweb.owlapi.model.OWLObjectOneOf; +import org.semanticweb.owlapi.model.OWLObjectProperty; 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.OWLOntologyManager; import org.semanticweb.owlapi.model.PrefixManager; -import org.semanticweb.owlapi.reasoner.OWLReasoner; -import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; import org.semanticweb.owlapi.util.DefaultPrefixManager; +import org.semanticweb.owlapi.vocab.OWL2Datatype; +import org.semanticweb.owlapi.vocab.OWLFacet; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import uk.ac.manchester.cs.owlapi.dlsyntax.DLSyntaxObjectRenderer; -import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +import com.hp.hpl.jena.datatypes.RDFDatatype; +import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.vocabulary.OWL; import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; /** * Converts query trees into OWL class expressions and vice versa. @@ -60,6 +75,8 @@ */ public class QueryTreeConverter implements OWLClassExpressionVisitor, OWLDataRangeVisitor{ + OWLDataFactory df = new OWLDataFactoryImpl(); + Stack<QueryTree<String>> stack = new Stack<QueryTree<String>>(); int id = 0; @@ -67,12 +84,213 @@ * Returns a OWL class expression of the union of the given query trees. * @param queryTrees */ - public void asOWLClassExpression(Collection<QueryTree<String>> queryTrees){ - - //check for common paths - + public OWLClassExpression asOWLClassExpression(QueryTree<String> tree){ + Set<OWLClassExpression> classExpressions = asOWLClassExpressions(tree); + OWLClassExpression expression; + if(classExpressions.isEmpty()){ + expression = df.getOWLThing(); + } else if(classExpressions.size() == 1){ + expression = classExpressions.iterator().next(); + } else { + expression = df.getOWLObjectIntersectionOf(classExpressions); + } + return expression; } + /** + * Returns a OWL class expression representation of the given query tree. + * @param queryTrees + */ + public Set<OWLClassExpression> asOWLClassExpressions(QueryTree<String> tree){ + Set<OWLClassExpression> classExpressions = new HashSet<OWLClassExpression>(); + + List<QueryTree<String>> children = tree.getChildren(); + for(QueryTree<String> child : children){ + String childLabel = (String) child.getUserObject(); + String predicateString = (String) tree.getEdge(child); + if(predicateString.equals(RDF.type.getURI()) || predicateString.equals(RDFS.subClassOf.getURI())){//A + if(child.isVarNode()){ + classExpressions.addAll(asOWLClassExpressions(child)); + } else { + if(!childLabel.equals(OWL.Thing.getURI())){//avoid trivial owl:Thing statements + classExpressions.add(df.getOWLClass(IRI.create(childLabel))); + } + } + } else { + if(child.isLiteralNode()){ + OWLDataProperty p = df.getOWLDataProperty(IRI.create((String) tree.getEdge(child))); + if(childLabel.equals("?")){//p some int + Set<Literal> literals = child.getLiterals(); + OWLDataRange dataRange = null; + if(literals.isEmpty()){//happens if there are heterogeneous datatypes + String datatypeURI = OWL2Datatype.RDFS_LITERAL.getURI().toString(); + dataRange = df.getOWLDatatype(IRI.create(datatypeURI)); + } else { + for (LiteralNodeConversionStrategy strategy : LiteralNodeConversionStrategy.values()) { + if(strategy == LiteralNodeConversionStrategy.DATATYPE){ + Literal lit = literals.iterator().next(); + RDFDatatype datatype = lit.getDatatype(); + String datatypeURI; + if(datatype == null){ + datatypeURI = OWL2Datatype.RDF_PLAIN_LITERAL.getURI().toString(); + } else { + datatypeURI = datatype.getURI(); + } + dataRange = df.getOWLDatatype(IRI.create(datatypeURI)); + } else if(strategy == LiteralNodeConversionStrategy.DATA_ONE_OF){ + dataRange = asDataOneOf(df, literals); + } else if(strategy == LiteralNodeConversionStrategy.MIN_MAX){ + dataRange = asFacet(df, literals); + } else if(strategy == LiteralNodeConversionStrategy.MIN){ + dataRange = asMinFacet(df, literals); + } else if(strategy == LiteralNodeConversionStrategy.MAX){ + dataRange = asMaxFacet(df, literals); + } + } + } + classExpressions.add(df.getOWLDataSomeValuesFrom(p, dataRange)); + } else {//p value 1.2 + Set<Literal> literals = child.getLiterals(); + Literal lit = literals.iterator().next(); + OWLLiteral owlLiteral = asOWLLiteral(df, lit); + classExpressions.add(df.getOWLDataHasValue(p, owlLiteral)); + } + } else { + OWLObjectProperty p = df.getOWLObjectProperty(IRI.create((String) tree.getEdge(child))); + OWLClassExpression filler; + if(child.isVarNode()){//p some C + Set<OWLClassExpression> fillerClassExpressions = asOWLClassExpressions(child); + if(fillerClassExpressions.isEmpty()){ + filler = df.getOWLThing(); + } else if(fillerClassExpressions.size() == 1){ + filler = fillerClassExpressions.iterator().next(); + } else { + filler = df.getOWLObjectIntersectionOf(fillerClassExpressions); + } + classExpressions.add(df.getOWLObjectSomeValuesFrom(p, filler)); + } else {//p value {a} + classExpressions.add(df.getOWLObjectHasValue(p, df.getOWLNamedIndividual(IRI.create(childLabel)))); + } + } + } + } + return classExpressions; + } + + private OWLDataRange asFacet(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a facet of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + Literal min = getMin(literals); + Literal max = getMax(literals); + + OWLFacetRestriction minRestriction = df.getOWLFacetRestriction(OWLFacet.MIN_INCLUSIVE, asOWLLiteral(df, min)); + OWLFacetRestriction maxRestriction = df.getOWLFacetRestriction(OWLFacet.MAX_INCLUSIVE, asOWLLiteral(df, max)); + + return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction, maxRestriction); + } + + private OWLDataRange asMinFacet(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a facet of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + Literal min = getMin(literals); + + OWLFacetRestriction minRestriction = df.getOWLFacetRestriction(OWLFacet.MIN_INCLUSIVE, asOWLLiteral(df, min)); + + return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), minRestriction); + } + + private OWLDataRange asMaxFacet(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a facet of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + Literal max = getMax(literals); + + OWLFacetRestriction maxRestriction = df.getOWLFacetRestriction(OWLFacet.MAX_INCLUSIVE, asOWLLiteral(df, max)); + + return df.getOWLDatatypeRestriction(getOWLDatatype(df, literals), maxRestriction); + } + + private OWLDataRange asDataOneOf(OWLDataFactory df, Set<Literal> literals){ + //return Boolean datatype because it doesn't make sense to return a enumeration of Boolean values + if(getOWLDatatype(df, literals).equals(df.getBooleanOWLDatatype())){ + return df.getBooleanOWLDatatype(); + } + return df.getOWLDataOneOf(asOWLLiterals(df, literals)); + } + + private Set<OWLLiteral> asOWLLiterals(OWLDataFactory df, Set<Literal> literals){ + Set<OWLLiteral> owlLiterals = new HashSet<OWLLiteral>(literals.size()); + for (Literal literal : literals) { + owlLiterals.add(asOWLLiteral(df, literal)); + } + return owlLiterals; + } + + private OWLLiteral asOWLLiteral(OWLDataFactory df, Literal literal){ + OWLLiteral owlLiteral; + if(literal.getDatatypeURI() == null){ + owlLiteral = df.getOWLLiteral(literal.getLexicalForm(), literal.getLanguage()); + } else { + owlLiteral = df.getOWLLiteral(literal.getLexicalForm(), df.getOWLDatatype(IRI.create(literal.getDatatypeURI()))); + } + return owlLiteral; + } + + private Literal getMin(Set<Literal> literals){ + Iterator<Literal> iter = literals.iterator(); + Literal min = iter.next(); + Literal l; + while(iter.hasNext()){ + l = iter.next(); + if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ + min = (l.getInt() < min.getInt()) ? l : min; + } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ + min = (l.getDouble() < min.getDouble()) ? l : min; + } else if(l.getDatatype() == XSDDatatype.XSDfloat){ + min = (l.getFloat() < min.getFloat()) ? l : min; + } else if(l.getDatatype() == XSDDatatype.XSDdate){ + min = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(min.getLexicalForm())) == -1) ? l : min; + } + } + return min; + } + + private Literal getMax(Set<Literal> literals){ + Iterator<Literal> iter = literals.iterator(); + Literal max = iter.next(); + Literal l; + while(iter.hasNext()){ + l = iter.next(); + if(l.getDatatype() == XSDDatatype.XSDinteger || l.getDatatype() == XSDDatatype.XSDint){ + max = (l.getInt() > max.getInt()) ? l : max; + } else if(l.getDatatype() == XSDDatatype.XSDdouble || l.getDatatype() == XSDDatatype.XSDdecimal){ + max = (l.getDouble() > max.getDouble()) ? l : max; + } else if(l.getDatatype() == XSDDatatype.XSDfloat){ + max = (l.getFloat() > max.getFloat()) ? l : max; + } else if(l.getDatatype() == XSDDatatype.XSDdate){ + max = (DatatypeConverter.parseDate(l.getLexicalForm()).compareTo(DatatypeConverter.parseDate(max.getLexicalForm())) == 1) ? l : max; + } + } + return max; + } + + private OWLDatatype getOWLDatatype(OWLDataFactory df, Set<Literal> literals){ + return df.getOWLDatatype(IRI.create(literals.iterator().next().getDatatypeURI())); + } + + + /** + * Converts a OWL class expression into a query tree, if possible. Note that this is not possible + * for all OWL constructs, e.g. universal restrictions are not allowed. An exceptions is thrown if the conversion + * fails. + * @param expression + * @return + */ public QueryTree<String> asQueryTree(OWLClassExpression expression){ // stack.push(new QueryTreeImpl<String>("?")); reset(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractCELA.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -52,7 +52,7 @@ * @author Jens Lehmann * */ -public abstract class AbstractCELA extends AbstractComponent implements ClassExpressionLearningAlgorithm, StoppableLearningAlgorithm, Cloneable { +public abstract class AbstractCELA extends AbstractComponent implements ClassExpressionLearningAlgorithm, StoppableLearningAlgorithm { protected EvaluatedDescriptionSet bestEvaluatedDescriptions = new EvaluatedDescriptionSet(AbstractCELA.MAX_NR_OF_RESULTS); protected DecimalFormat dfPercent = new DecimalFormat("0.00%"); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Constant.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Constant.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Constant.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -19,17 +19,16 @@ package org.dllearner.core.owl; +import java.io.Serializable; + /** * A constant value. * * @author Jens Lehmann * */ -public abstract class Constant implements KBElement, Comparable<Constant> { +public abstract class Constant implements KBElement, Comparable<Constant>, Serializable { - /** - * - */ private static final long serialVersionUID = 2331790456049452753L; String literal; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -31,9 +31,6 @@ */ public class DatatypeProperty implements Comparable<DatatypeProperty>, Property, NamedKBElement, Serializable { - /** - * - */ private static final long serialVersionUID = 8452865438915671952L; protected String name; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMaxValue.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " double[<= " + value + "]"; + return "double[<= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[<= " + value + "]"; + return "double[<= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[<= " + value + "]"; + return "double[<= " + value + "]"; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinMaxRange.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -65,11 +65,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + minValue + " <= " + maxValue + "]"; + return "double[>= " + minValue + ", <= " + maxValue + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + minValue + " <= " + maxValue + "]"; + return "double[>= " + minValue + ", <= " + maxValue + "]"; } public void accept(KBElementVisitor visitor) { @@ -81,7 +81,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + minValue + " <= " + maxValue + "]"; + return "double[>= " + minValue + ", <= " + maxValue + "]"; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DoubleMinValue.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -58,11 +58,11 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + value + "]"; + return "double[>= " + value + "]"; } public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + value + "]"; + return "double[>= " + value + "]"; } public void accept(KBElementVisitor visitor) { @@ -74,7 +74,7 @@ */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - return " double[>= " + value + "]"; + return "double[>= " + value + "]"; } /* (non-Javadoc) Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -19,6 +19,7 @@ package org.dllearner.core.owl; +import java.io.Serializable; import java.net.URI; import java.util.Map; @@ -31,7 +32,7 @@ * @author Jens Lehmann * */ -public class ObjectProperty extends ObjectPropertyExpression implements Property, Comparable<ObjectProperty>{ +public class ObjectProperty extends ObjectPropertyExpression implements Property, Comparable<ObjectProperty>, Serializable{ private static final long serialVersionUID = -3343070247923446690L; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -29,9 +29,6 @@ */ public class TypedConstant extends Constant { - /** - * - */ private static final long serialVersionUID = -9135242138291085300L; private Datatype datatype; Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ExistentialRestrictionMaterialization.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ExistentialRestrictionMaterialization.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ExistentialRestrictionMaterialization.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.Stack; @@ -81,27 +82,55 @@ private Map<OWLClass, Set<OWLClassExpression>> map = new HashMap<>(); Stack<Set<OWLClassExpression>> stack = new Stack<Set<OWLClassExpression>>(); OWLDataFactory df; + boolean onlyIfExistentialOnPath = true; + + int indent = 0; public SuperClassFinder() { df = ontology.getOWLOntologyManager().getOWLDataFactory(); } public Set<OWLClassExpression> getSuperClasses(OWLClass cls){ +// System.out.println("#################"); map.clear(); computeSuperClasses(cls); Set<OWLClassExpression> superClasses = map.get(cls); superClasses.remove(cls); + + //filter out non existential superclasses + if(onlyIfExistentialOnPath){ + for (Iterator<OWLClassExpression> iterator = superClasses.iterator(); iterator.hasNext();) { + OWLClassExpression sup = iterator.next(); + if (!(sup instanceof OWLObjectSomeValuesFrom || sup instanceof OWLDataAllValuesFrom)) { + iterator.remove(); + } + } + } return superClasses; } private void computeSuperClasses(OWLClass cls){ + String s = ""; + for(int i = 0; i < indent; i++){ + s += " "; + } +// System.out.println(s + cls); + indent++; Set<OWLClassExpression> superClasses = new HashSet<OWLClassExpression>(); superClasses.add(cls); + + //get the directly asserted super classes Set<OWLClassExpression> superClassExpressions = cls.getSuperClasses(ontology); + + //omit trivial super class + superClassExpressions.remove(cls); + + //go subsumption hierarchy up for each directly asserted super class for (OWLClassExpression sup : superClassExpressions) { sup.accept(this); superClasses.addAll(stack.pop()); } + stack.push(superClasses); map.put(cls, superClasses); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-07-02 06:31:52 UTC (rev 4279) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-07-29 13:53:19 UTC (rev 4280) @@ -59,6 +59,7 @@ import ... [truncated message content] |
From: <lor...@us...> - 2014-08-06 11:41:31
|
Revision: 4283 http://sourceforge.net/p/dl-learner/code/4283 Author: lorenz_b Date: 2014-08-06 11:41:26 +0000 (Wed, 06 Aug 2014) Log Message: ----------- Updated OWL API. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java trunk/components-core/src/test/resources/punning_example.ttl trunk/pom.xml 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 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -346,6 +346,9 @@ if(writeSearchTree) { File f = new File(searchTreeFile ); + if(f.getParentFile() != null){ + f.getParentFile().mkdirs(); + } Files.clearFile(f); } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -52,6 +52,14 @@ public URI getURI() { return URI.create(name); } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.PropertyExpression#isAnonymous() + */ + @Override + public boolean isAnonymous() { + return false; + } @Override public String toString() { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -25,6 +25,8 @@ import java.util.Map; import java.util.Set; +import org.semanticweb.owlapi.model.OWLRuntimeException; + /** * A class description is sometimes also called "complex class" or "concept". * @@ -216,8 +218,20 @@ return this instanceof NamedClass; } + /** + * Determines whether or not this expression represents an anonymous class + * expression. + * + * @return {@code true} if this is an anonymous class expression, or + * {@code false} if this is a named class ( {@code OWLClass}) + */ + public boolean isAnonymous(){ + return true; + }; + public NamedClass asNamedClass(){ - return (NamedClass)this; + throw new OWLRuntimeException( + "Not an OWLClass. This method should only be called if the isAnonymous method returns false!"); } /** Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -56,6 +56,22 @@ return URI.create(name); } + /* (non-Javadoc) + * @see org.dllearner.core.owl.Description#isAnonymous() + */ + @Override + public boolean isAnonymous() { + return false; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.Description#asNamedClass() + */ + @Override + public NamedClass asNamedClass() { + return this; + } + public int getLength() { return 1; } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -46,7 +46,23 @@ public URI getURI() { return URI.create(name); - } + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.ObjectPropertyExpression#asObjectProperty() + */ + @Override + public ObjectProperty asObjectProperty() { + return this; + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.PropertyExpression#isAnonymous() + */ + @Override + public boolean isAnonymous() { + return false; + } @Override public String toString() { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -21,6 +21,8 @@ import java.io.Serializable; +import org.semanticweb.owlapi.model.OWLRuntimeException; + /** * An object property expression is an object property construct, which * can be used in axioms, e.g. complex class descriptions. It can be @@ -52,7 +54,21 @@ result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } - + + /** + * If the property is a named object property then this method will obtain + * the property as such. The general pattern of use is that the + * {@code isAnonymous} method should first be used to determine if the + * property is named (i.e. not an object property expression such as + * inv(p)). If the property is named then this method may be used to obtain + * the property as a named property without casting. + * + * @return The property as an {@code ObjectProperty} if possible. + * @throws OWLRuntimeException + * if the property is not a named property. + */ + public abstract ObjectProperty asObjectProperty(); + @Override public boolean equals(Object obj) { if (this == obj) Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -22,6 +22,7 @@ import java.util.Map; import org.dllearner.utilities.Helper; +import org.semanticweb.owlapi.model.OWLRuntimeException; /** * Represents the inverse of a property expression. It can be used @@ -49,6 +50,23 @@ public int getLength() { return 2; } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.ObjectPropertyExpression#asObjectProperty() + */ + @Override + public ObjectProperty asObjectProperty() { + throw new OWLRuntimeException( + "Property is not a named property. Check using the isAnonymous method before calling this method!"); + } + + /* (non-Javadoc) + * @see org.dllearner.core.owl.PropertyExpression#isAnonymous() + */ + @Override + public boolean isAnonymous() { + return true; + } public String toString(String baseURI, Map<String,String> prefixes) { return Helper.getAbbreviatedString(name, baseURI, prefixes) + "-"; Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -19,6 +19,7 @@ package org.dllearner.core.owl; + /** * * @author Jens Lehmann @@ -26,9 +27,6 @@ */ public abstract class ObjectQuantorRestriction extends QuantorRestriction { - /** - * - */ private static final long serialVersionUID = -5482730659805823042L; public ObjectQuantorRestriction(ObjectPropertyExpression role, Description c) { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -29,9 +29,6 @@ */ public class ObjectSomeRestriction extends ObjectQuantorRestriction { - /** - * - */ private static final long serialVersionUID = 858960420513908151L; public ObjectSomeRestriction(ObjectPropertyExpression role, Description c) { Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -24,5 +24,14 @@ * */ public interface PropertyExpression extends KBElement { + + /** + * Determines if this property expression is anonymous. + * + * @return {@code true} if the property expression is anonymous (because it + * is the inverse of a property). {@code false} if this property is + * a named object property or named data property. + */ + boolean isAnonymous(); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -26,6 +26,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -153,7 +154,7 @@ private boolean materializeExistentialRestrictions = false; private boolean useCaching = true; - + private boolean handlePunning = true; public enum ForallSemantics { Standard, // standard all quantor @@ -271,6 +272,7 @@ HashFunction hf = Hashing.md5(); Hasher hasher = hf.newHasher(); hasher.putBoolean(materializeExistentialRestrictions); + hasher.putBoolean(handlePunning); for (OWLOntology ont : rc.getOWLAPIOntologies()) { hasher.putInt(ont.getLogicalAxioms().hashCode()); hasher.putInt(ont.getAxioms().hashCode()); @@ -373,6 +375,7 @@ sd.put(dp, rc.getStringDatatypeMembers(dp)); } + if(materializeExistentialRestrictions){ ExistentialRestrictionMaterialization materialization = new ExistentialRestrictionMaterialization(rc.getReasoner().getRootOntology()); for (NamedClass cls : atomicConcepts) { @@ -384,6 +387,42 @@ } } + //materialize facts based on OWL punning, i.e.: + //for each A in N_C + if(handlePunning){ + OWLOntology ontology = rc.getReasoner().getRootOntology(); + + Individual genericIndividual = new Individual("http://dl-learner.org/punning#genInd"); + Map<Individual, SortedSet<Individual>> map = new HashMap<Individual, SortedSet<Individual>>(); + for (Individual individual : individuals) { + SortedSet<Individual> objects = new TreeSet<Individual>(); + objects.add(genericIndividual); + map.put(individual, objects); + } + for (NamedClass cls : atomicConcepts) { + classInstancesNeg.get(cls).add(genericIndividual); + if(OWLPunningDetector.hasPunning(ontology, cls)){ + Individual clsAsInd = new Individual(cls.getName()); + //for each x \in N_I with A(x) we add relatedTo(x,A) + SortedSet<Individual> individuals = classInstancesPos.get(cls); + for (Individual individual : individuals) { + SortedSet<Individual> objects = map.get(individual); + if(objects == null){ + objects = new TreeSet<Individual>(); + map.put(individual, objects); + } + objects.add(clsAsInd); + + } + } + } + opPos.put(OWLPunningDetector.punningProperty, map); + atomicRoles = new TreeSet<ObjectProperty>(atomicRoles); + atomicRoles.add(OWLPunningDetector.punningProperty); + atomicRoles = Collections.unmodifiableSet(atomicRoles); +// individuals.add(genericIndividual); + } + long dematDuration = System.currentTimeMillis() - dematStartTime; logger.debug("TBox dematerialised in " + dematDuration + " ms"); } @@ -482,6 +521,9 @@ } ObjectProperty op = (ObjectProperty) ope; Description child = description.getChild(0); + if(handlePunning && op == OWLPunningDetector.punningProperty && child.equals(new NamedClass(Thing.uri.toString()))){ + return true; + } Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); if (mapping == null) { @@ -489,7 +531,8 @@ + ")."); return false; } - SortedSet<Individual> roleFillers = opPos.get(op).get(individual); + + SortedSet<Individual> roleFillers = mapping.get(individual); if (roleFillers == null) { return false; } @@ -565,7 +608,9 @@ return true; } // return false if there are none or not enough role fillers - if (roleFillers == null || roleFillers.size() < number) { + if (roleFillers == null + || (roleFillers.size() < number && op != OWLPunningDetector.punningProperty) + ) { return false; } @@ -574,7 +619,9 @@ index++; if (hasTypeImpl(child, roleFiller)) { nrOfFillers++; - if (nrOfFillers == number) { + if (nrOfFillers == number + || (handlePunning && op == OWLPunningDetector.punningProperty) + ) { return true; } // early abort: e.g. >= 10 hasStructure.Methyl; @@ -763,7 +810,7 @@ + description + " unsupported. Inverse object properties not supported."); } ObjectProperty op = (ObjectProperty) ope; - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); // each individual is connected to a set of individuals via the property; // we loop through the complete mapping @@ -1265,4 +1312,18 @@ public void setMaterializeExistentialRestrictions(boolean materializeExistentialRestrictions) { this.materializeExistentialRestrictions = materializeExistentialRestrictions; } + + /** + * @param handlePunning the handlePunning to set + */ + public void setHandlePunning(boolean handlePunning) { + this.handlePunning = handlePunning; + } + + /** + * @param useCaching the useCaching to set + */ + public void setUseMaterializationCaching(boolean useCaching) { + this.useCaching = useCaching; + } } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -75,6 +75,7 @@ import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.collect.Sets; @@ -499,15 +500,17 @@ } } else if (description instanceof Intersection) { - + + System.out.println("REFINING: " + OWLAPIDescriptionConvertVisitor.getOWLClassExpression(description)); // refine one of the elements for(Description child : description.getChildren()) { - + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(child)); + System.out.println(maxLength - description.getLength()+child.getLength()); // refine the child; the new max length is the current max length minus // the currently considered concept plus the length of the child // TODO: add better explanation tmp = refine(child, maxLength - description.getLength()+child.getLength(),null,currDomain); - + System.out.println(tmp); // create new intersection for(Description c : tmp) { List<Description> newChildren = (List<Description>)((LinkedList<Description>)description.getChildren()).clone(); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -254,6 +254,12 @@ @Override public void visit(OWLAsymmetricObjectPropertyAxiom axiom) { + axiom.getProperty().accept(this); + writeSpace(); + write(DISJOINT_WITH); + writeSpace(); + axiom.getProperty().accept(this); + write(INVERSE); } @Override Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -22,6 +22,10 @@ import java.util.Comparator; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.reasoning.OWLPunningDetector; /** * Comparator for evaluated descriptions, which orders them by @@ -47,8 +51,12 @@ else if(acc1 < acc2) return -1; else { - int length1 = ed1.getDescriptionLength(); - int length2 = ed2.getDescriptionLength(); + int length1 = + getLength(ed1); +// ed1.getDescriptionLength(); + int length2 = + getLength(ed2); +// ed2.getDescriptionLength(); if(length1 < length2) return 1; else if(length1 > length2) @@ -57,5 +65,20 @@ return cc.compare(ed1.getDescription(), ed2.getDescription()); } } + + private int getLength(EvaluatedDescription ed){ + int length = 0; + Description d = ed.getDescription(); + if(d instanceof Intersection){ + for (Description child : d.getChildren()) { + if(child instanceof ObjectSomeRestriction && ((ObjectSomeRestriction) child).getRole().asObjectProperty() == OWLPunningDetector.punningProperty){ + length += child.getChild(0).getLength(); + } else { + length += child.getLength(); + } + } + } + return length; + } } \ No newline at end of file Modified: trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java 2014-08-06 11:41:26 UTC (rev 4283) @@ -3,37 +3,48 @@ */ package org.dllearner.test; -import java.io.ByteArrayInputStream; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.SortedSet; import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.celoe.OEHeuristicRuntime; import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; +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.ObjectProperty; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.learningproblems.PosNegLPStandard; -import org.dllearner.reasoning.FastInstanceChecker; -import org.dllearner.utilities.owl.OWLAPIConverter; +import org.dllearner.reasoning.MaterializableFastInstanceChecker; +import org.dllearner.reasoning.OWLPunningDetector; +import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.utilities.owl.DLSyntaxObjectRenderer; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.junit.Assert; import org.junit.Test; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.ToStringRenderer; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; -import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLNamedIndividual; -import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.owllink.parser.OWLlinkDescriptionElementHandler; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import com.google.common.collect.Sets; +import com.google.common.collect.Sets.SetView; /** * @author Lorenz Buehmann @@ -41,87 +52,35 @@ */ public class PunningTest { - - public OWLOntology makeExampleKB() throws OWLOntologyCreationException{ - String kb = "@prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix :<http://foo.org/> ."; - kb += ":p a owl:ObjectProperty ."; - - for (int i = 1; i <= 5; i++) { - kb += ":r" + i + " a owl:ObjectProperty ."; - } - - kb += ":A a owl:Class; :r1 :o1; :r2 :o2 ."; - kb += ":B a owl:Class; :r1 :o3; :r3 :o2 ."; - - for (int i = 1; i <= 10; i++) { - kb += ":x" + i + " a owl:NamedIndividual ."; - } - - int m = 5; - int n = 5; - - //m instances of A - for (int i = 1; i <= m; i++) { - kb += ":x" + i + " a :A ."; - } - - //n instances of B - for (int i = 1; i <= n; i++) { - kb += ":x" + i + " a :A ."; - } - - OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(kb.getBytes())); - return ontology; - } - public OWLOntology loadExample() throws OWLOntologyCreationException{ OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getClassLoader().getResourceAsStream("punning_example.ttl")); return ontology; } @Test - public void testPunning() throws OWLOntologyCreationException, ComponentInitException{ - OWLOntology ontology = makeExampleKB(); - OWLDataFactory df = new OWLDataFactoryImpl(); + public void testPunningExists() throws OWLOntologyCreationException, ComponentInitException{ + OWLOntology ontology = loadExample(); - //check that A and B are both, individual and class - OWLClass clsA = df.getOWLClass(IRI.create("http://foo.org/A")); - OWLClass clsB = df.getOWLClass(IRI.create("http://foo.org/B")); - OWLIndividual indA = df.getOWLNamedIndividual(IRI.create("http://foo.org/A")); - OWLIndividual indB = df.getOWLNamedIndividual(IRI.create("http://foo.org/B")); - + Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); Set<OWLClass> classes = ontology.getClassesInSignature(); - Set<OWLObjectProperty> properties = ontology.getObjectPropertiesInSignature(); - Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); - System.out.println("Classes:" + classes); - System.out.println("Properties:" + properties); - System.out.println("Individuals:" + individuals); + SetView<IRI> intersection = Sets.intersection(toIRI(individuals), toIRI(classes)); + System.out.println("Entities that are class and individual:\n" + intersection); + Assert.assertTrue(!intersection.isEmpty()); - Assert.assertTrue( - ontology.getClassesInSignature().contains(clsA) && - ontology.getClassesInSignature().contains(clsB) && - ontology.getIndividualsInSignature().contains(indA) && - ontology.getIndividualsInSignature().contains(indB) - ); - - KnowledgeSource ks = new OWLAPIOntology(ontology); - ks.init(); - - AbstractReasonerComponent rc = new FastInstanceChecker(ks); - rc.init(); - - AbstractLearningProblem lp = new PosNegLPStandard(rc); - lp.init(); - - AbstractCELA la = new CELOE(lp, rc); - la.init(); - - la.start(); } + private Set<IRI> toIRI(Set<? extends OWLEntity> entities){ + Set<IRI> iris = new HashSet<IRI>(); + for (OWLEntity e : entities) { + iris.add(e.getIRI()); + } + return iris; + } + @Test - public void testPunning2() throws OWLOntologyCreationException, ComponentInitException{ + public void testPunning() throws OWLOntologyCreationException, ComponentInitException{ + ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer()); OWLOntology ontology = loadExample(); OWLDataFactory df = new OWLDataFactoryImpl(); @@ -138,18 +97,83 @@ KnowledgeSource ks = new OWLAPIOntology(ontology); ks.init(); - AbstractReasonerComponent rc = new FastInstanceChecker(ks); + MaterializableFastInstanceChecker rc = new MaterializableFastInstanceChecker(ks); +// rc.setUseMaterializationCaching(false); + rc.setHandlePunning(true); + rc.setUseMaterializationCaching(false); rc.init(); + rc.setBaseURI("http://ex.org/"); PosNegLPStandard lp = new PosNegLPStandard(rc); lp.setPositiveExamples(posExamples); lp.setNegativeExamples(negExamples); lp.init(); - AbstractCELA la = new CELOE(lp, rc); + CELOE la = new CELOE(lp, rc); + la.setWriteSearchTree(true); + la.setSearchTreeFile("log/punning_search_tree.txt"); + la.setReplaceSearchTree(true); + la.setMaxNrOfResults(50); + la.setMaxExecutionTimeInSeconds(20); + la.setExpandAccuracy100Nodes(true); + OEHeuristicRuntime heuristic = new OEHeuristicRuntime(); +// heuristic.setExpansionPenaltyFactor(0.001); +// la.setHeuristic(heuristic); la.init(); + ((RhoDRDown)la.getOperator()).setUseNegation(false); +// la.start(); - la.start(); + System.out.println("Classes: " + ontology.getClassesInSignature()); + System.out.println("Individuals: " + ontology.getIndividualsInSignature()); + + Description d = new Intersection(new NamedClass("http://ex.org/Fahrzeug")); + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d)); + SortedSet<Individual> individuals = rc.getIndividuals(d); + System.out.println(individuals); + + d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction( + OWLPunningDetector.punningProperty, Thing.instance)); + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d)); + individuals = rc.getIndividuals(d); + System.out.println(individuals); + + d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction( + OWLPunningDetector.punningProperty, new ObjectSomeRestriction(new ObjectProperty( + "http://ex.org/bereifung"), Thing.instance))); + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d)); + individuals = rc.getIndividuals(d); + System.out.println(individuals); + + d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction( + OWLPunningDetector.punningProperty, +// new ObjectSomeRestriction(new ObjectProperty("http://ex.org/bereifung"), + Thing.instance)); + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d)); + individuals = rc.getIndividuals(d); + System.out.println(individuals); + + //get some refinements + System.out.println("###############"); + System.out.println("Refinements:"); + Set<Description> refinements = la.getOperator().refine(d, d.getLength() + 4); + for (Description ref : refinements) { + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(ref)); + System.out.println(lp.getAccuracyOrTooWeak(ref, 0d)); + } + System.out.println("###############"); + + + d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction( + OWLPunningDetector.punningProperty, new ObjectSomeRestriction(new ObjectProperty( + "http://ex.org/bereifung"), new ObjectSomeRestriction(OWLPunningDetector.punningProperty, + Thing.instance)))); + System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d)); + individuals = rc.getIndividuals(d); + System.out.println(individuals); +// List<? extends EvaluatedDescription> currentlyBestEvaluatedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(100); +// for (EvaluatedDescription ed : currentlyBestEvaluatedDescriptions) { +// System.out.println(ed); +// } } } Modified: trunk/components-core/src/test/resources/punning_example.ttl =================================================================== --- trunk/components-core/src/test/resources/punning_example.ttl 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/components-core/src/test/resources/punning_example.ttl 2014-08-06 11:41:26 UTC (rev 4283) @@ -57,11 +57,7 @@ <http://ex.org/SIEMENS425#567> a ex:Bahn . <http://ex.org/TATRAT3#678> a ex:Tram . -# punning workaround -ex:p a owl:ObjectProperty . -<http://ex.org/TRABANT601#1234> ex:p ex:Auto . -<http://ex.org/S51#2345> ex:p ex:Moped . -<http://ex.org/MIFA23#3456> ex:p ex:Fahrrad . -<http://ex.org/CLIPSO90MG#4567> ex:p ex:Schubkarre . -<http://ex.org/SIEMENS425#567> ex:p ex:Bahn . -<http://ex.org/TATRAT3#678> ex:p ex:Tram . \ No newline at end of file +# punning of ex:Gummireifen +ex:bestehtAus a owl:ObjectProperty . +ex:Gummireifen ex:bestehtAus ex:GUMMI . +ex:GUMMI a ex:Werkstoff . Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-07-29 13:56:03 UTC (rev 4282) +++ trunk/pom.xml 2014-08-06 11:41:26 UTC (rev 4283) @@ -123,7 +123,7 @@ <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> - <version>3.4.5</version> + <version>3.5.1</version> </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |