You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <lor...@us...> - 2013-01-22 11:28:04
|
Revision: 3885 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3885&view=rev Author: lorenz_b Date: 2013-01-22 11:27:57 +0000 (Tue, 22 Jan 2013) Log Message: ----------- Updated dependencies for OWL-API. Modified Paths: -------------- trunk/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-01-22 09:47:20 UTC (rev 3884) +++ trunk/pom.xml 2013-01-22 11:27:57 UTC (rev 3885) @@ -120,10 +120,20 @@ in Maven. --> <dependencies> <dependency> - <groupId>net.sourceforge.owlapi</groupId> - <artifactId>owlapi</artifactId> - <version>3.2.4</version> - </dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-distribution</artifactId> + <version>3.4</version> + </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-reasoner</artifactId> + <version>3.3</version> + </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-util</artifactId> + <version>3.3</version> + </dependency> <dependency> <groupId>com.owldl</groupId> @@ -137,6 +147,12 @@ </exclusion> </exclusions> </dependency> + + <dependency> + <groupId>eu.trowl</groupId> + <artifactId>trowl-core</artifactId> + <version>1.0</version> + </dependency> <dependency> <groupId>org.semanticweb.hermit</groupId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-01-22 09:47:32
|
Revision: 3884 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3884&view=rev Author: lorenz_b Date: 2013-01-22 09:47:20 +0000 (Tue, 22 Jan 2013) Log Message: ----------- Moving QTL algorithm to core module. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/cache/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/cache/QueryTreeCache.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/NodeRenderer.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/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/GeneralisedQueryTree.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeChange.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/examples/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/examples/DBpediaExample.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/examples/LinkedGeoDataExample.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/EmptyLGGException.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/NBRException.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/NegativeTreeCoverageExecption.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/QTLException.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/exception/TimeOutException.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/ExactMatchFilter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/Filter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/Filters.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/I_Sub.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QueryTreeFilter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QuestionBasedQueryTreeFilter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QuestionBasedQueryTreeFilterAggressive.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QuestionBasedStatementFilter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QuestionBasedStatementFilter2.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/QuestionBasedStatementSelector.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/filters/ZeroFilter.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/impl/QueryTreeFactoryImpl2.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/FilterVisitor.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/Generalisation.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/NBR.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/PostLGG.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGenerator.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/lgg/LGGGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/NBRGenerator.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/NBRGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/strategy/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/strategy/BruteForceNBRStrategy.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/strategy/GreedyNBRStrategy.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/strategy/NBRStrategy.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/operations/nbr/strategy/TagNonSubsumingPartsNBRStrategy.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/Prefixes.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/SPARQLEndpointEx.java trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/util/TreeHelper.java trunk/components-core/src/test/java/org/dllearner/algorithms/ trunk/components-core/src/test/java/org/dllearner/algorithms/qtl/ 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/NBRTest.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 Property Changed: ---------------- trunk/components-core/ Property changes on: trunk/components-core ___________________________________________________________________ Modified: svn:ignore - components-core.iml target log .classpath .project .settings + components-core.iml target log .classpath .project .settings cache Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2013-01-22 09:43:25 UTC (rev 3883) +++ trunk/components-core/pom.xml 2013-01-22 09:47:20 UTC (rev 3884) @@ -113,11 +113,18 @@ </exclusions> </dependency> - <!-- THIS IS FROM THE UNIBAS REPO --> <dependency> <groupId>net.sourceforge.owlapi</groupId> - <artifactId>owlapi</artifactId> + <artifactId>owlapi-distribution</artifactId> </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-reasoner</artifactId> +</dependency> +<dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-util</artifactId> + </dependency> <!-- THIS IS FROM THE UNIBAS REPO --> <dependency> @@ -253,6 +260,12 @@ <artifactId>xercesImpl</artifactId> <version>2.8.0</version> </dependency> + + <dependency> + <groupId>uk.ac.shef.wit</groupId> + <artifactId>simmetrics</artifactId> + <version>1.6.2</version> + </dependency> </dependencies> <dependencyManagement> <dependencies> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-01-22 09:43:25 UTC (rev 3883) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -178,12 +178,12 @@ class2Overlap.put(cls, cnt); } //for each property in knowledge base - for(NamedClass cls : allClasses){ + for(NamedClass cls : allClasses){if(!cls.toString().equals("http://dbpedia.org/ontology/MotorcycleRider"))continue; //get the popularity int otherPopularity = reasoner.getPopularity(cls); if(otherPopularity == 0){//skip empty properties continue; - } + }System.out.println(cls); //get the overlap int overlap = class2Overlap.containsKey(cls) ? class2Overlap.get(cls) : 0; //compute the estimated precision @@ -455,7 +455,8 @@ ks = new LocalModelBasedSparqlEndpointKS(new URL("http://dl-learner.svn.sourceforge.net/viewvc/dl-learner/trunk/examples/swore/swore.rdf?revision=2217")); ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); DisjointClassesLearner l = new DisjointClassesLearner(ks); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Book")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Agent")); + l.setMaxExecutionTimeInSeconds(60); l.init(); l.getReasoner().prepareSubsumptionHierarchy(); l.getReasoner().precomputeClassPopularity(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2013-01-22 09:43:25 UTC (rev 3883) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -164,7 +164,7 @@ public static void main(String[] args) throws Exception{ FunctionalObjectPropertyAxiomLearner l = new FunctionalObjectPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/league")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/currency")); l.setMaxExecutionTimeInSeconds(20); l.setForceSPARQL_1_0_Mode(true); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2013-01-22 09:43:25 UTC (rev 3883) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -206,14 +206,14 @@ ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); l.setReasoner(reasoner); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/grammyAward")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/anthem")); l.setMaxExecutionTimeInSeconds(40); - l.addFilterNamespace("http://dbpedia.org/ontology/"); +// l.addFilterNamespace("http://dbpedia.org/ontology/"); // l.setReturnOnlyNewAxioms(true); l.init(); l.start(); - System.out.println(l.getCurrentlyBestEvaluatedAxioms(10, 0.3)); + System.out.println(l.getCurrentlyBestEvaluatedAxioms()); } } Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,387 @@ +/** + * 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.qtl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.commons.collections15.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.exception.EmptyLGGException; +import org.dllearner.algorithms.qtl.exception.NegativeTreeCoverageExecption; +import org.dllearner.algorithms.qtl.exception.TimeOutException; +import org.dllearner.algorithms.qtl.filters.QueryTreeFilter; +import org.dllearner.algorithms.qtl.operations.NBR; +import org.dllearner.algorithms.qtl.operations.lgg.LGGGenerator; +import org.dllearner.algorithms.qtl.operations.lgg.LGGGeneratorImpl; +import org.dllearner.algorithms.qtl.util.SPARQLEndpointEx; +import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.options.ConfigOption; +import org.dllearner.core.options.IntegerConfigOption; +import org.dllearner.core.owl.Individual; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.CachingConciseBoundedDescriptionGenerator; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.utilities.Helper; +import org.springframework.beans.factory.annotation.Autowired; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSetRewindable; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.Statement; +import com.hp.hpl.jena.util.iterator.Filter; + +/** + * + * Learning algorithm for SPARQL queries based on so called query trees. + * + * @author Lorenz Bühmann + * @author Jens Lehmann + * + * + */ +@ComponentAnn(name="query tree learner", shortName="qtl", version=0.8) +public class QTL extends AbstractComponent implements SparqlQueryLearningAlgorithm { + + private static final Logger logger = Logger.getLogger(QTL.class); + + private LearningProblem learningProblem; + private SparqlEndpointKS endpointKS; +// private QTLConfigurator configurator; + + private SparqlEndpoint endpoint; + private ExtractionDBCache cache; + + private QueryTreeCache treeCache; + + private LGGGenerator<String> lggGenerator; + private NBR<String> nbr; + + private List<String> posExamples; + private List<String> negExamples; + + private List<QueryTree<String>> posExampleTrees; + private List<QueryTree<String>> negExampleTrees; + + private QueryTreeFilter queryTreeFilter; + + private ConciseBoundedDescriptionGenerator cbdGenerator; + + private int maxExecutionTimeInSeconds = 60; + private int maxQueryTreeDepth = 2; + + private QueryTree<String> lgg; + private SortedSet<String> lggInstances; + + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(CommonConfigOptions.maxExecutionTimeInSeconds(10)); + options.add(new IntegerConfigOption("maxQueryTreeDepth", "recursion depth of query tree extraction", 2)); + return options; + } + + public QTL() { + + } + + public QTL(AbstractLearningProblem learningProblem, SparqlEndpointKS endpointKS) throws LearningProblemUnsupportedException{ + if(!(learningProblem instanceof PosOnlyLP || learningProblem instanceof PosNegLP)){ + throw new LearningProblemUnsupportedException(learningProblem.getClass(), getClass()); + } + this.learningProblem = learningProblem; + this.endpointKS = endpointKS; + +// this.configurator = new QTLConfigurator(this); + } + + public QTL(SPARQLEndpointEx endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + + treeCache = new QueryTreeCache(); + cbdGenerator = new CachingConciseBoundedDescriptionGenerator(new ConciseBoundedDescriptionGeneratorImpl(endpoint, cache)); + cbdGenerator.setRecursionDepth(maxQueryTreeDepth); + + lggGenerator = new LGGGeneratorImpl<String>(); + nbr = new NBR<String>(endpoint, cache); + nbr.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + + posExampleTrees = new ArrayList<QueryTree<String>>(); + negExampleTrees = new ArrayList<QueryTree<String>>(); + } + + public String getQuestion(List<String> posExamples, List<String> negExamples) throws EmptyLGGException, NegativeTreeCoverageExecption, TimeOutException { + this.posExamples = posExamples; + this.negExamples = negExamples; + + generatePositiveExampleTrees(); + generateNegativeExampleTrees(); + + if(negExamples.isEmpty()){ + QueryTree<String> dummyNegTree = new QueryTreeImpl<String>("?"); + dummyNegTree.addChild(new QueryTreeImpl<String>("?"), "dummy"); + negExampleTrees.add(dummyNegTree); + } + + lgg = lggGenerator.getLGG(posExampleTrees); + + if(queryTreeFilter != null){ + lgg = queryTreeFilter.getFilteredQueryTree(lgg); + } + if(logger.isDebugEnabled()){ + logger.debug("LGG: \n" + lgg.getStringRepresentation()); + } + if(lgg.isEmpty()){ + throw new EmptyLGGException(); + } + + int index = coversNegativeQueryTree(lgg); + if(index != -1){ + throw new NegativeTreeCoverageExecption(negExamples.get(index)); + } + + lggInstances = getResources(lgg); + nbr.setLGGInstances(lggInstances); + + String question = nbr.getQuestion(lgg, negExampleTrees, getKnownResources()); + + return question; + } + + public void setExamples(List<String> posExamples, List<String> negExamples){ + this.posExamples = posExamples; + this.negExamples = negExamples; + } + + public void addStatementFilter(Filter<Statement> filter){ + treeCache.setStatementFilter(filter); + } + + public void addQueryTreeFilter(QueryTreeFilter queryTreeFilter){ + this.queryTreeFilter = queryTreeFilter; + } + + public void setMaxExecutionTimeInSeconds(int maxExecutionTimeInSeconds){ + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + nbr.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + } + + public void setMaxQueryTreeDepth(int maxQueryTreeDepth){ + this.maxQueryTreeDepth = maxQueryTreeDepth; + cbdGenerator.setRecursionDepth(maxQueryTreeDepth); + } + + public String getSPARQLQuery(){ + if(lgg == null){ + lgg = lggGenerator.getLGG(getQueryTrees(posExamples)); + } + return lgg.toSPARQLQueryString(); + } + + public void setRestrictToNamespaces(List<String> namespaces){ + cbdGenerator.setRestrictToNamespaces(namespaces); + } + + private void generatePositiveExampleTrees(){ + posExampleTrees.clear(); + posExampleTrees.addAll(getQueryTrees(posExamples)); + } + + private void generateNegativeExampleTrees(){ + negExampleTrees.clear(); + negExampleTrees.addAll(getQueryTrees(negExamples)); + } + + private List<QueryTree<String>> getQueryTrees(List<String> resources){ + List<QueryTree<String>> trees = new ArrayList<QueryTree<String>>(); + Model model; + QueryTree<String> tree; + for(String resource : resources){ + if(logger.isDebugEnabled()){ + logger.debug("Tree for resource " + resource); + } + model = cbdGenerator.getConciseBoundedDescription(resource); + tree = treeCache.getQueryTree(resource, model); + if(logger.isDebugEnabled()){ + logger.debug(tree.getStringRepresentation()); + } + trees.add(tree); + } + return trees; + } + + private List<String> getKnownResources(){ + return ListUtils.union(posExamples, negExamples); + } + +// private boolean coversNegativeQueryTree(QueryTree<String> tree){ +// for(QueryTree<String> negTree : negExampleTrees){ +// if(negTree.isSubsumedBy(tree)){ +// return true; +// } +// } +// return false; +// } + + private int coversNegativeQueryTree(QueryTree<String> tree){ + for(int i = 0; i < negExampleTrees.size(); i++){ + if(negExampleTrees.get(i).isSubsumedBy(tree)){ + return i; + } + } + return -1; + } + + private SortedSet<String> getResources(QueryTree<String> tree){ + SortedSet<String> resources = new TreeSet<String>(); + String query = getDistinctSPARQLQuery(tree); + String result = cache.executeSelectQuery(endpoint, query); + ResultSetRewindable rs = SparqlQuery.convertJSONtoResultSet(result); + String uri; + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + uri = qs.getResource("x0").getURI(); + resources.add(uri); + } + return resources; + } + + private String getDistinctSPARQLQuery(QueryTree<String> tree){ + String query = tree.toSPARQLQueryString(); +// query = "SELECT DISTINCT " + query.substring(7); + return query; + } + + @Override + public void start(){ + generatePositiveExampleTrees(); + + lgg = lggGenerator.getLGG(posExampleTrees); + + if(queryTreeFilter != null){ + lgg = queryTreeFilter.getFilteredQueryTree(lgg); + } + if(logger.isDebugEnabled()){ + logger.debug("LGG: \n" + lgg.getStringRepresentation()); + } + + } + + @Override + public List<String> getCurrentlyBestSPARQLQueries(int nrOfSPARQLQueries) { + return Collections.singletonList(getBestSPARQLQuery()); + } + + @Override + public String getBestSPARQLQuery() { + return lgg.toSPARQLQueryString(); + } + + public void init() { + if(learningProblem instanceof PosOnlyLP){ + this.posExamples = convert(((PosOnlyLP)learningProblem).getPositiveExamples()); + } else if(learningProblem instanceof PosNegLP){ + this.posExamples = convert(((PosNegLP)learningProblem).getPositiveExamples()); + this.negExamples = convert(((PosNegLP)learningProblem).getNegativeExamples()); + } + endpoint = endpointKS.getEndpoint(); + + treeCache = new QueryTreeCache(); + cbdGenerator = new CachingConciseBoundedDescriptionGenerator(new ConciseBoundedDescriptionGeneratorImpl(endpoint, cache)); + cbdGenerator.setRecursionDepth(maxQueryTreeDepth); + + lggGenerator = new LGGGeneratorImpl<String>(); + nbr = new NBR<String>(endpoint); + nbr.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + + posExampleTrees = new ArrayList<QueryTree<String>>(); + negExampleTrees = new ArrayList<QueryTree<String>>(); + } + + private List<String> convert(Set<Individual> individuals){ + List<String> list = new ArrayList<String>(); + for(Individual ind : individuals){ + list.add(ind.toString()); + } + return list; + } + + public static void main(String[] args) throws Exception { + Set<String> positiveExamples = new HashSet<String>(); + positiveExamples.add("http://dbpedia.org/resource/Liverpool_F.C."); + positiveExamples.add("http://dbpedia.org/resource/Chelsea_F.C."); + + ComponentManager cm = ComponentManager.getInstance(); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + ks.init(); + PosOnlyLP lp = new PosOnlyLP(); + cm.getPool().registerComponent(lp); + lp.setPositiveExamples(Helper.getIndividualSet(positiveExamples)); + QTL qtl = new QTL(lp, ks); + qtl.init(); + qtl.start(); + String query = qtl.getBestSPARQLQuery(); + System.out.println(query); + } + + public LearningProblem getLearningProblem() { + return learningProblem; + } + + @Autowired + public void setLearningProblem(LearningProblem learningProblem) { + this.learningProblem = learningProblem; + } + + public SparqlEndpointKS getEndpointKS() { + return endpointKS; + } + + @Autowired + public void setEndpointKS(SparqlEndpointKS endpointKS) { + this.endpointKS = endpointKS; + } + + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QueryTreeFactory.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,53 @@ +/** + * Copyright (C) 2007-2010, 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.qtl; + +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; +import org.dllearner.algorithms.qtl.filters.Filter; + +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Selector; +import com.hp.hpl.jena.rdf.model.Statement; + +/** + * + * @author Lorenz Bühmann + * + */ +public interface QueryTreeFactory<N> { + + QueryTreeImpl<N> getQueryTree(String example, Model model); + + QueryTreeImpl<N> getQueryTree(String example, Model model, int maxEdges); + + QueryTreeImpl<N> getQueryTree(Resource example, Model model); + + QueryTreeImpl<N> getQueryTree(String example); + + void setPredicateFilter(Filter filter); + + void setObjectFilter(Filter filter); + + void setStatementSelector(Selector selector); + + void setStatementFilter(com.hp.hpl.jena.util.iterator.Filter<Statement> filter); + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/cache/QueryTreeCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/cache/QueryTreeCache.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/cache/QueryTreeCache.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,65 @@ +package org.dllearner.algorithms.qtl.cache; + +import java.util.HashMap; +import java.util.Map; + +import org.dllearner.algorithms.qtl.QueryTreeFactory; +import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.filters.Filter; +import org.dllearner.algorithms.qtl.impl.QueryTreeFactoryImpl; + +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Selector; +import com.hp.hpl.jena.rdf.model.Statement; + +public class QueryTreeCache { + + private Map<Model, QueryTree<String>> cache; + private QueryTreeFactory<String> factory; + + public QueryTreeCache(){ + cache = new HashMap<Model, QueryTree<String>>(); + factory = new QueryTreeFactoryImpl(); + } + + public QueryTree<String> getQueryTree(String root, Model model){ + QueryTree<String> tree = cache.get(model); + if(tree == null){ + tree = factory.getQueryTree(root, model); + } + return tree; + } + + public QueryTree<String> getQueryTree(Resource root, Model model){ + QueryTree<String> tree = cache.get(model); + if(tree == null){ + tree = factory.getQueryTree(root, model); + } + return tree; + } + + public void setPredicateFilter(Filter filter){ + factory.setPredicateFilter(filter); + } + + public void setObjectFilter(Filter filter){ + factory.setObjectFilter(filter); + } + + public void setStatementFilter(com.hp.hpl.jena.util.iterator.Filter<Statement> filter){ + factory.setStatementFilter(filter); + } + + public void setStatementSelector(Selector selector){ + factory.setStatementSelector(selector); + } + + public void clear(){ + cache.clear(); + } + + public void dispose(){ + cache = null; + } +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/NodeRenderer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/NodeRenderer.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/NodeRenderer.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2007-2010, 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.qtl.datastructures; + + +/** + * + * @author Lorenz Bühmann + * + */ +public interface NodeRenderer<N> { + + String render(QueryTree<N> node); + +} Added: 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 (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/QueryTree.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,144 @@ +/** + * Copyright (C) 2007-2010, 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.qtl.datastructures; + +import java.io.PrintWriter; +import java.util.Comparator; +import java.util.List; +import java.util.Set; + +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeImpl; + +import com.hp.hpl.jena.datatypes.RDFDatatype; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.rdf.model.Literal; + +/** + * + * @author Lorenz Bühmann + * + */ +public interface QueryTree<N> { + + /** + * Gets the "content" of this tree node. + * @return The user content of this node. + */ + N getUserObject(); + + void setUserObject(N userObject); + + void setId(int id); + + int getId(); + + boolean isEmpty(); + + QueryTree<N> getNodeById(int nodeId); + + boolean isLiteralNode(); + + void setLiteralNode(boolean isLiteralNode); + + boolean isResourceNode(); + + void setResourceNode(boolean isResourceNode); + + boolean isVarNode(); + + void setVarNode(boolean isVarNode); + + QueryTree<N> getParent(); + + List<QueryTree<N>> getChildren(); + + List<QueryTree<N>> getChildren(Object edge); + + List<QueryTree<N>> getChildrenClosure(); + + Object getEdge(QueryTree<N> child); + + void addChild(QueryTreeImpl<N> child); + + void addChild(QueryTreeImpl<N> child, int position); + + void addChild(QueryTreeImpl<N> child, Object edge); + + void addChild(QueryTreeImpl<N> child, Object edge, int position); + + int removeChild(QueryTreeImpl<N> child); + + Set<Object> getEdges(); + + void sortChildren(Comparator<QueryTree<N>> comparator); + + int getChildCount(); + + int getMaxDepth(); + + boolean isRoot(); + + boolean isLeaf(); + + boolean isSubsumedBy(QueryTree<N> tree); + + boolean isSubsumedBy(QueryTree<N> tree, boolean stopAfterError); + + boolean isSameTreeAs(QueryTree<N> tree); + + void tag(); + + boolean isTagged(); + + QueryTree<N> getRoot(); + + List<QueryTree<N>> getLeafs(); + + List<QueryTree<N>> getPathToRoot(); + + List<N> getUserObjectPathToRoot(); + + void dump(); + + public String getStringRepresentation(); + + void dump(PrintWriter writer); + + void dump(PrintWriter writer, int indent); + + Set<N> getUserObjectClosure(); + + List<N> fillDepthFirst(); + + String toSPARQLQueryString(); + + String toSPARQLQueryString(boolean filtered); + + Query toSPARQLQuery(); + + int getTriplePatternCount(); + + Query toQuery(); + + RDFDatatype getDatatype(); + + List<Literal> getLiterals(); + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/GeneralisedQueryTree.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/GeneralisedQueryTree.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/GeneralisedQueryTree.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,51 @@ +package org.dllearner.algorithms.qtl.datastructures.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.datastructures.impl.QueryTreeChange.ChangeType; + +public class GeneralisedQueryTree<N> { + + private QueryTree<N> tree; + private List<QueryTreeChange> changes; + + public GeneralisedQueryTree(QueryTree<N> tree){ + this.tree = tree; + changes = new ArrayList<QueryTreeChange>(); + } + + public GeneralisedQueryTree(QueryTree<N> tree, List<QueryTreeChange> changes){ + this.tree = tree; + this.changes = changes; + } + + public void setQueryTree(QueryTree<N> tree){ + this.tree = tree; + } + + public QueryTree<N> getQueryTree(){ + return tree; + } + + public void addChange(QueryTreeChange change){ + changes.add(change); + } + + public void addChanges(List<QueryTreeChange> changes){ + this.changes.addAll(changes); + } + + public List<QueryTreeChange> getChanges(){ + return changes; + } + + public QueryTreeChange getLastChange(){ + if(changes.isEmpty()){ + return new QueryTreeChange(0, ChangeType.REPLACE_LABEL); + } + return changes.get(changes.size()-1); + } + +} Added: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeChange.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeChange.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeChange.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,72 @@ +package org.dllearner.algorithms.qtl.datastructures.impl; + + + +public class QueryTreeChange { + + public enum ChangeType{ + REPLACE_LABEL, + REMOVE_NODE; + } + + private int nodeId; + + private ChangeType type; + + private String object; + private String edge; + + public QueryTreeChange(int nodeId, ChangeType type){ + this.nodeId = nodeId; + this.type = type; + } + + public int getNodeId() { + return nodeId; + } + + public ChangeType getType() { + return type; + } + + public String getObject() { + return object; + } + + public void setObject(String object) { + this.object = object; + } + + public String getEdge() { + return edge; + } + + public void setEdge(String edge) { + this.edge = edge; + } + + @Override + public String toString() { +// return "nodeId" + (type==ChangeType.REPLACE_LABEL ? "Replace" : "Remove"); + return nodeId + (type==ChangeType.REPLACE_LABEL ? "a" : "b"); + } + + @Override + public boolean equals(Object obj) { + if(obj == this){ + return true; + } + if(obj == null || !(obj instanceof QueryTreeChange)){ + return false; + } + QueryTreeChange other = (QueryTreeChange)obj; + return nodeId == other.getNodeId() && type == other.getType(); + } + + @Override + public int hashCode() { + return nodeId + type.hashCode() + 37; + } + + +} Added: 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 (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/datastructures/impl/QueryTreeImpl.java 2013-01-22 09:47:20 UTC (rev 3884) @@ -0,0 +1,905 @@ +/** + * Copyright (C) 2007-2010, 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.qtl.datastructures.impl; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.regex.Pattern; + +import javax.xml.bind.DatatypeConverter; + +import org.dllearner.algorithms.qtl.datastructures.NodeRenderer; +import org.dllearner.algorithms.qtl.datastructures.QueryTree; +import org.dllearner.algorithms.qtl.filters.Filters; + +import com.hp.hpl.jena.datatypes.BaseDatatype; +import com.hp.hpl.jena.datatypes.RDFDatatype; +import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.graph.Node; +import com.hp.hpl.jena.graph.Triple; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.sparql.syntax.ElementGroup; +import com.hp.hpl.jena.sparql.syntax.ElementTriplesBlock; + +/** + * + * @author Lorenz Bühmann + * + */ +public class QueryTreeImpl<N> implements QueryTree<N>{ + + private N userObject; + + private QueryTreeImpl<N> parent; + + private List<QueryTreeImpl<N>> children; + + private Map<QueryTree<N>, Object> child2EdgeMap; + private Map<String, List<QueryTree<N>>> edge2ChildrenMap; + + private NodeRenderer<N> toStringRenderer; + + private boolean tagged = false; + + private int cnt; + + private int id; + + private boolean isLiteralNode = false; + private boolean isResourceNode = false; + + private List<Literal> literals = new ArrayList<Literal>(); + + + public QueryTreeImpl(N userObject) { + this.userObject = userObject; + children = new ArrayList<QueryTreeImpl<N>>(); + child2EdgeMap = new HashMap<QueryTree<N>, Object>(); + edge2ChildrenMap = new HashMap<String, List<QueryTree<N>>>(); + toStringRenderer = new NodeRenderer<N>() { + public String render(QueryTree<N> object) { + String label = object.toString() + "(" + object.getId() + ")"; + if(object.isLiteralNode()){ + if(!object.getLiterals().isEmpty()){ + label += "Values: " + object.getLiterals(); + } + } + return label; + } + }; + } + + public QueryTreeImpl(QueryTree<N> tree){ + this(tree.getUserObject()); + setId(tree.getId()); + QueryTreeImpl<N> subTree; + for(QueryTree<N> child : tree.getChildren()){ + subTree = new QueryTreeImpl<N>(child); + subTree.setId(child.getId()); + subTree.setLiteralNode(child.isLiteralNode()); + subTree.setResourceNode(child.isResourceNode()); + addChild(subTree, tree.getEdge(child)); + } + } + + public N getUserObject() { + return userObject; + } + + public void setUserObject(N userObject) { + this.userObject = userObject; + } + + @Override + public void setId(int id) { + this.id = id; + } + + @Override + public int getId() { + return id; + } + + @Override + public boolean isEmpty(){ + return this.children.isEmpty(); + } + + public QueryTree<N> getNodeById(int nodeId){ + QueryTree<N> node = null; + if(this.id == nodeId){ + node = this; + } else { + for(QueryTree<N> child : children){ + node = child.getNodeById(nodeId); + if(node != null){ + return node; + } + } + } + return node; + } + + @Override + public boolean isLiteralNode() { + return isLiteralNode; + } + + @Override + public void setLiteralNode(boolean isLiteralNode) { + this.isLiteralNode = isLiteralNode; + } + + @Override + public boolean isResourceNode() { + return isResourceNode; + } + + @Override + public void setResourceNode(boolean isResourceNode) { + this.isResourceNode = isResourceNode; + } + + @Override + public boolean isVarNode() { + return !isLiteralNode && !isResourceNode; + } + + @Override + public void setVarNode(boolean isVarNode) { + isLiteralNode = false; + isResourceNode = false; + } + + + public void setParent(QueryTreeImpl<N> parent) { + if (this.parent != null) { + this.parent.children.remove(this); + } + this.parent = parent; + this.parent.children.add(this); + } + + + public void addChild(QueryTreeImpl<N> child) { + children.add(child); + child.parent = this; + } + + @Override + public void addChild(QueryTreeImpl<N> child, int position) { + children.add(position, child); + child.parent = this; + } + + public void addChild(QueryTreeImpl<N> child, Object edge) { + addChild(child); + child2EdgeMap.put(child, edge); + + List<QueryTree<N>> children = edge2ChildrenMap.get(edge); + if(children == null){ + children = new ArrayList<QueryTree<N>>(); + edge2ChildrenMap.put((String)edge, children); + } + children.add(child); + } + + @Override + public void addChild(QueryTreeImpl<N> child, Object edge, int position) { + addChild(child, position); + child2EdgeMap.put(child, edge); + + List<QueryTree<N>> children = edge2ChildrenMap.get(edge); + if(children == null){ + children = new ArrayList<QueryTree<N>>(); + edge2ChildrenMap.put((String)edge, children); + } + children.add(child); + + } + + + public int removeChild(QueryTreeImpl<N> child) { + int pos = children.indexOf(child); + children.remove(child); + edge2ChildrenMap.get(child2EdgeMap.get(child)).remove(child); + child.parent = null; + return pos; + } + + public void removeChildren(Set<QueryTreeImpl<N>> children) { + for(QueryTreeImpl<N> child : children){ + this.children.remove(child); + child.parent = null; + } + } + + + public Object getEdge(QueryTree<N> child) { + return child2EdgeMap.get(child); + } + + public Set<Object> getEdges(){ + return new TreeSet<Object>(child2EdgeMap.values()); + } + + + public void sortChildren(Comparator<QueryTree<N>> comparator) { + Collections.sort(children, comparator); + } + + + public void clearChildren() { + for (QueryTreeImpl<N> child : new ArrayList<QueryTreeImpl<N>>(children)) { + removeChild(child); + } + } + + + public QueryTree<N> getParent() { + return parent; + } + + + public List<QueryTree<N>> getChildren() { + return new ArrayList<QueryTree<N>>(children); + } + + public List<QueryTree<N>> getChildren(Object edge) { +// List<QueryTree<N>> children = new ArrayList<QueryTree<N>>(); +// for(Entry<QueryTree<N>, Object> entry : child2EdgeMap.entrySet()){ +// if(entry.getValue().equals(edge)){ +// children.add(entry.getKey()); +// } +// } +// return children; + List<QueryTree<N>> children = edge2ChildrenMap.get(edge); + if(children == null){ + children = new ArrayList<QueryTree<N>>(); + } + return new ArrayList<QueryTree<N>>(children); + } + + public int getChildCount() { + return children.size(); + } + + + public boolean isRoot() { + return parent == null; + } + + + public boolean isLeaf() { + return children.isEmpty(); + } + + @Override + public boolean isSubsumedBy(QueryTree<N> tree) { + if(!(tree.getUserObject().equals("?") || tree.getUserObject().equals(this.userObject))){ + return false; + } + + Object edge; + for(QueryTree<N> child : tree.getChildren()){ + boolean isSubsumed = false; + edge = tree.getEdge(child); + for(QueryTree<N> child2 : this.getChildren(edge)){ + if(child2.isSubsumedBy(child)){ + isSubsumed = true; + break; + } + } + if(!isSubsumed){ + return false; + } + } + return true; + } + + @Override + public boolean isSubsumedBy(QueryTree<N> tree, boolean stopAfterError) { + if(!(tree.getUserObject().equals("?") || tree.getUserObject().equals(this.userObject))){ + return false; + } + + Object edge; + for(QueryTree<N> child : tree.getChildren()){ + boolean isSubsumed = false; + edge = tree.getEdge(child); + for(QueryTree<N> child2 : this.getChildren(edge)){ + if(child2.isSubsumedBy(child, true)){ + isSubsumed = true; + break; + } + } + if(!isSubsumed){ + child.tag(); + return false; + } + } + return true; + } + + public void tag(){ + tagged = true; + } + + public boolean isTagged(){ + return tagged; + } + + + public QueryTree<N> getRoot() { + if (parent == null) { + return this; + } + return parent.getRoot(); + } + + public List<QueryTree<N>> getLeafs(){ + List<QueryTree<N>> leafs = new LinkedList<QueryTree<N>>(); + if(isLeaf()){ + leafs.add(this); + } else { + for(QueryTree<N> child : children){ + leafs.addAll(child.getLeafs()); + } + } + return leafs; + } + + + public List<QueryTree<N>> getPathToRoot() { + List<QueryTree<N>> path = new ArrayList<QueryTree<N>>(); + path.add(0, this); + QueryTree<N> par = parent; + while (par != null) { + path.add(0, par); + par = par.getParent(); + } + return path; + } + + + + + public List<N> getUserObjectPathToRoot() { + List<N> path = new ArrayList<N>(); + path.add(0, this.getUserObject()); + QueryTree<N> par = parent; + while (par != null) { + path.add(0, par.getUserObject()); + par = par.getParent(); + } + return path; + } + + public List<QueryTree<N>> getChildrenClosure() { + List<QueryTree<N>> children = new ArrayList<QueryTree<N>>(); + getChildrenClosure(this, children); + return children; + } + + private void getChildrenClosure(QueryTree<N> tree, List<QueryTree<N>> bin) { + bin.add(tree); + for (QueryTree<N> child : tree.getChildren()) { + getChildrenClosure(child, bin); + } + } + + + public Set<N> getUserObjectClosure() { + Set<N> objects = new HashSet<N>(); + getUserObjectClosure(this, objects); + return objects; + } + + public int getTriplePatternCount(){ + return countTriplePattern(this); + } + + private int countTriplePattern(QueryTree<N> tree){ + int cnt = 0; + Object object; + if(!tree.isLeaf()){ + for(QueryTree<N> child : tree.getChildren()){ + object = child.getUserObject(); + boolean objectIsResource = !object.equals("?"); + cnt++; + if(!objectIsResource){ + cnt+=countTriplePattern(child); + } + } + } + return cnt; + } + + public QueryTree<N> getSPARQLQueryTree(){ + return createSPARQLQueryTree(this); + } + + private QueryTree<N> createSPARQLQueryTree(QueryTree<N> tree){ + QueryTree<N> copy = new QueryTreeImpl<N>(tree.getUserObject()); + if(tree.getUserObject().equals("?")){ + for(QueryTree<N> child : tree.getChildren()){ + copy.addChild((QueryTreeImpl<N>) createSPARQLQueryTree(child), tree.getEdge(child)); + } + } +// for(QueryTree<N> child : tree.getChildren()){ +// if(child.getUserObject().equals("?")){ +// copy.addChild((QueryTreeImpl<N>) createSPARQLQueryTree(child), tree.getEdge(child)); +// } else { +// copy.addChild((QueryTreeImpl<N>) child, tree.getEdge(child)); +// } +// +// } + + return copy; + } + + private void getUserObjectClosure(QueryTree<N> tree, Set<N> bin) { + bin.add(tree.getUserObject()); + for (QueryTree<N> child : tree.getChildren()) { + getUserObjectClosure(child, bin); + } + } + + public String getStringRepresentation(){ + int depth = getPathToRoot().size(); + StringBuilder sb = new StringBuilder(); + if(isRoot()){ + sb.append("TREE\n\n"); + } + String ren = toStringRenderer.render(this); + ren = ren.replace("\n", "\n" + sb); + sb.append(ren); + sb.append("\n"); + for (QueryTree<N> child : getChildren()) { + for (int i = 0; i < depth; i++) { + sb.append("\t"); + } + Object edge = getEdge(child); + if (edge != null) { + sb.append(" "); + sb.append(edge); + sb.append(" ---> "); + } + sb.append(((QueryTreeImpl<N>)child).getStringRepresentation()); + } + return sb.toString(); + } + + public String getStringRepresentation(int indent){ + int depth = getPathToRoot().size(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < depth + indent; i++) { + sb.append("\t"); + } + String ren = toStringRenderer.render(this); + ren = ren.replace("\n", "\n" + sb); + sb.append(ren); + sb.append("\n"); + for (QueryTree<N> child : getChildren()) { + Object edge = getEdge(child); + if (edge != null) { + sb.append("--- "); + sb.append(edge); + sb.append(" ---\n"); + } + sb.append(((QueryTreeImpl<N>)child).getStringRepresentation(indent)); + } + return sb.toString(); + } + + public void dump() { + dump(new PrintWriter(System.out), 0); + } + + public void dump(PrintWriter writer) { + dump(writer, 0); + } + + public void dump(PrintWriter writer, int indent) { + int depth = getPathToRoot().size(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < depth + indent; i++) { + sb.append("\t"); + } + writer.print(sb.toString()); + String ren = toStringRenderer.render(this); + ren = ren.replace("\n", "\n" + sb); + writer.println(ren); + for (QueryTree<N> child : getChildren()) { + Object edge = getEdge(child); + if (edge != null) { + writer.print(sb.toString()); + writer.print("--- "); + writer.print(edge); + writer.print(" ---\n"); + } + child.dump(writer, indent); + } + writer.flush(); +// int depth = getPathToRoot().size(); +// StringBuilder sb = new StringBuilder(); +// for (int i = 0; i < depth + indent; i++) { +// sb.append("\t"); +// } +// writer.print(sb.toString()); +// String ren = toStringRenderer.render(this); +// ren = ren.replace("\n", "\n" + sb); +// writer.println(ren); +// for (QueryTree<N> child : getChildren()) { +// Object edge = getEdge(child); +// if (edge != null) { +// writer.print(sb.toString()); +// writer.print("--- "); +// writer.print(edge); +// writer.print(" ---\n"); +// } +// child.dump(writer, indent); +// } +// writer.flush(); + } + + + public List<N> fillDepthFirst() { + List<N> results = new ArrayList<N>(); + fillDepthFirst(this, results); + return results; + } + + private void fillDepthFirst(QueryTree<N> tree, List<N> bin) { + bin.add(tree.getUserObject()); + for (QueryTree<N> child : tree.getChildren()) { + fillDepthFirst(child, bin); + } + } + + public void replace(QueryTreeImpl<N> tree) { + parent.children.remove(this); + parent.children.add(tree); + parent = null; + tree.children.clear(); + tree.children.addAll(children); + children.clear(); + } + + public String toString() { + if (userObject != null) { + return userObject.toString(); + } else { + return ""; + } + } + + + public int getSize() { + return getUserObjectClosure().size(); + } + + + + public int getMaxDepth() { + return getMaxDepth(this); + } + + private int getMaxDepth(QueryTree<N> tree) { + int maxChildDepth = tree.getPathToRoot().size(); + for (QueryTree<N> child : tree.getChildren()) { + int childDepth = getMaxDepth(child); + if(childDepth > maxChildDepth) { + maxChildDepth = childDepth; + } + } + return maxChildDepth; + } + + @Override + public Object clone() throws CloneNotSupportedException { + QueryTreeImpl<N> copy = new QueryTreeImpl<N>(this.userObject); + for(QueryTreeImpl<N> child : children){ + copy.addChild((QueryTreeImpl<N>)child.clone(), getEdge(child)); + } + + return copy; + } + +// @Override +// public boolean equals(Object obj) { +// if(obj == this){ +// return true; +// } +// if(!(obj instanceof QueryTreeImpl<?>)){ +// return false; +// } +// QueryTreeImpl<N> other = (QueryTreeImpl<N>)obj; +// if(!this.userObject.equals(other.getUserObject())){ +// return false; +// } +// Object edge; +// for(QueryTreeImpl<N> child : this.children){ +// boolean existsEqualChild = false; +// edge = child2EdgeMap.get(child); +// for(QueryTree<N> child2 : other.getChildren(edge)){ +// if(child.equals(child2)){ +// existsEqualChild = true; +// break; +// } +// } +// if(!existsEqualChild){ +// return false; +// } +// } +// return true; +// } + + public boolean isSameTreeAs(QueryTree<N> tree){ + if(!this.userObject.equals(tree.getUserObject())){ + return false; + } + Object edge; + for(QueryTreeImpl<N> child : this.children){ + boolean existsEqualChild = false; + edge = child2EdgeMap.get(child); + for(QueryTree<N> child2 : tree.getChildren(edge)){ + if(child.isSameTreeAs(child2)){ + existsEqualChild = true; + break; + } + } + if(!existsEqualChild){ + return false; + } + } + return true; + } + + @Override + public Query toSPARQLQuery() { + return QueryFactory.create(toSPARQLQueryString(), Syntax.syntaxARQ); + } + + @Override + public String toSPARQLQueryString() { + if(children.isEmpty()){ + return "SELECT ?x0 WHERE {?x0 ?y ?z.}"; + } + cnt = 0; + StringBuilder sb = new StringBuilder(); + sb.append("SELECT DISTINCT ?x0 WHERE {\n"); + List<String> filters = new ArrayList<String>(); + buildSPARQLQueryString(this, sb, false, filters); + for(String filter : filters){ + sb.append(filter).append("\n"); + } + sb.append("}"); + return sb.toString(); + } + + @Override + public String toSPARQLQueryString(boolean filtered) { + if(children.isEmpty()){ + return "SELECT ?x0 WHERE {?x0 ?y ?z.}"; + } + cnt = 0; + StringBuilder sb = new StringBuilder(); + List<String> filters = new ArrayList<String>(); + sb.append("SELECT DISTINCT ?x0 WHERE {\n"); + buildSPARQLQueryString(this, sb, filtered, filters); + for(String filter : filters){ + sb.append(filter).append("\n"); + } + sb.append("}"); + return sb.toString(); + } + + private void buildSPARQLQueryString(QueryTree<N> tree, StringBuilder sb, boolean filtered, List<String> filters){ + Object subject = null; + if(tree.getUserObject().equals("?")){ + subject = "?x" + cnt++; + if(tree.isLiteralNode() && !tree.getLiterals().isEmpty()){ + filters.add(getFilter(subject.toString(), tree.getLiterals())); + } + } else { + subject = "<" + tree.getUserObject() + ">"; + } + Object predicate; + Object object; + if(!tree.isLeaf()){ + for(QueryTree<N> child : tree.getChildren()){ + predicate = tree.getEdge(child); + if(filtered){ + if(Filters.getAllFilterProperties().contains(predicate.toString())){ + continue; + } + } + object = child.getUserObject(); + boolean objectIsResource = !object.equals("?"); + if(!objectIsResource){ + object = "?x" + cnt; + } else if(((String)object).startsWith("http://")){ + object = "<" + object + ">"; + ... [truncated message content] |
From: <lor...@us...> - 2013-01-22 09:43:32
|
Revision: 3883 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3883&view=rev Author: lorenz_b Date: 2013-01-22 09:43:25 +0000 (Tue, 22 Jan 2013) Log Message: ----------- Moving QTL algorithm to core module. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Similarity.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Similarity.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Similarity.java 2013-01-22 09:40:58 UTC (rev 3882) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Similarity.java 2013-01-22 09:43:25 UTC (rev 3883) @@ -1,6 +1,6 @@ package org.dllearner.algorithm.tbsl.util; -import org.dllearner.algorithm.qtl.filters.I_Sub; +import org.dllearner.algorithms.qtl.filters.I_Sub; import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric; import uk.ac.shef.wit.simmetrics.similaritymetrics.Levenshtein; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-01-22 09:41:05
|
Revision: 3882 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3882&view=rev Author: lorenz_b Date: 2013-01-22 09:40:58 +0000 (Tue, 22 Jan 2013) Log Message: ----------- Moving QTL algorithm to core module. Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/ trunk/components-ext/src/test/java/org/dllearner/algorithm/qtl/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-12-25 13:19:20
|
Revision: 3881 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3881&view=rev Author: lorenz_b Date: 2012-12-25 13:19:09 +0000 (Tue, 25 Dec 2012) Log Message: ----------- Added equals+hashcode for literals. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/pom.xml 2012-12-25 13:19:09 UTC (rev 3881) @@ -169,6 +169,11 @@ <groupId>org.semanticweb.hermit</groupId> <artifactId>hermit</artifactId> </dependency> + + <dependency> + <groupId>eu.trowl</groupId> + <artifactId>trowl-core</artifactId> + </dependency> <dependency> <groupId>com.jamonapi</groupId> Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/Datatype.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -22,6 +22,9 @@ import java.net.URI; import java.util.Map; +import org.semanticweb.owlapi.model.IRI; + + /** * @author Jens Lehmann * 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 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/TypedConstant.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -120,6 +120,35 @@ String str = literal + datatype; String str2 = o.literal + ((TypedConstant)o).datatype; return str.compareTo(str2); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((datatype == null) ? 0 : datatype.hashCode()); + result = prime * result + ((getLiteral() == null) ? 0 : getLiteral().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; + TypedConstant other = (TypedConstant) obj; + if (datatype == null) { + if (other.datatype != null) + return false; + } else if (!datatype.equals(other.datatype)) + return false; + if(!getLiteral().equals(other.getLiteral())){ + return false; + } + return true; } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/UntypedConstant.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -124,4 +124,36 @@ return str.compareTo(str2); } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (hasLang ? 1231 : 1237); + result = prime * result + ((lang == null) ? 0 : lang.hashCode()); + result = prime * result + ((getLiteral() == null) ? 0 : getLiteral().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; + UntypedConstant other = (UntypedConstant) obj; + if (hasLang != other.hasLang) + return false; + if (lang == null) { + if (other.lang != null) + return false; + } else if (!lang.equals(other.lang)) + return false; + if(!getLiteral().equals(other.getLiteral())){ + return false; + } + return true; + } + } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ConciseBoundedDescriptionGeneratorImpl.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -2,28 +2,22 @@ import java.io.UnsupportedEncodingException; import java.sql.SQLException; -import java.util.Arrays; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.vocabulary.RDF; -import com.hp.hpl.jena.vocabulary.RDFS; public class ConciseBoundedDescriptionGeneratorImpl implements ConciseBoundedDescriptionGenerator{ private static final Logger logger = Logger.getLogger(ConciseBoundedDescriptionGeneratorImpl.class); - private static final int CHUNK_SIZE = 1000; + private int chunkSize = 0; private ExtractionDBCache cache; private SparqlEndpoint endpoint; @@ -37,6 +31,12 @@ this.cache = cache; } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint, ExtractionDBCache cache, int maxRecursionDepth) { + this.endpoint = endpoint; + this.cache = cache; + this.maxRecursionDepth = maxRecursionDepth; + } + public ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint endpoint) { this(endpoint, null); } @@ -53,8 +53,12 @@ return getModelChunked(resourceURI, depth); } + public void setChunkSize(int chunkSize) { + this.chunkSize = chunkSize; + } + private Model getModelChunked(String resource, int depth){ - String query = makeConstructQueryOptional(resource, CHUNK_SIZE, 0, depth); + String query = makeConstructQueryOptional(resource, chunkSize, 0, depth); Model all = ModelFactory.createDefaultModel(); try { Model model; @@ -65,9 +69,9 @@ } all.add(model); int i = 1; - while(model.size() != 0){ + do{ // while(model.size() == CHUNK_SIZE){ - query = makeConstructQueryOptional(resource, CHUNK_SIZE, i * CHUNK_SIZE, depth); + query = makeConstructQueryOptional(resource, chunkSize, i * chunkSize, depth); if(cache == null){ model = getModel(query); } else { @@ -75,7 +79,7 @@ } all.add(model); i++; - } + } while(chunkSize > 0 && model.size() != 0); } catch (UnsupportedEncodingException e) { logger.error(e); } catch (SQLException e) { @@ -124,8 +128,10 @@ sb.append("}"); } sb.append("}\n"); - sb.append("LIMIT ").append(limit).append("\n"); - sb.append("OFFSET ").append(offset); + if(chunkSize > 0){ + sb.append("LIMIT ").append(limit).append("\n"); + sb.append("OFFSET ").append(offset); + } return sb.toString(); } @@ -179,8 +185,8 @@ Logger.getRootLogger().setLevel(Level.DEBUG); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(SparqlEndpoint.getEndpointDBpedia()); cbdGen = new CachingConciseBoundedDescriptionGenerator(cbdGen); - cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); - Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 2); +// cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); + Model cbd = cbdGen.getConciseBoundedDescription("http://dbpedia.org/resource/Leipzig", 3); System.out.println(cbd.size()); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-12-11 19:34:37 UTC (rev 3880) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-12-25 13:19:09 UTC (rev 3881) @@ -23,6 +23,7 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -99,7 +100,9 @@ import org.semanticweb.owlapi.model.UnknownOWLOntologyException; import org.semanticweb.owlapi.owllink.OWLlinkHTTPXMLReasonerFactory; import org.semanticweb.owlapi.owllink.OWLlinkReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.FreshEntitiesException; import org.semanticweb.owlapi.reasoner.FreshEntityPolicy; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.Node; @@ -107,8 +110,10 @@ import org.semanticweb.owlapi.reasoner.NullReasonerProgressMonitor; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; import org.semanticweb.owlapi.reasoner.ReasonerProgressMonitor; import org.semanticweb.owlapi.reasoner.SimpleConfiguration; +import org.semanticweb.owlapi.reasoner.TimeOutException; import org.semanticweb.owlapi.util.SimpleIRIMapper; import org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat; import org.springframework.beans.propertyeditors.StringTrimmerEditor; @@ -119,1103 +124,1000 @@ import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import de.tudresden.inf.lat.cel.owlapi.CelReasoner; +import eu.trowl.owlapi3.rel.reasoner.dl.RELReasonerFactory; /** - * Mapping to OWL API reasoner interface. The OWL API currently supports three - * reasoners: FaCT++, HermiT and Pellet. FaCT++ is connected using JNI and - * native libraries, while HermiT and Pellet are pure Java libraries. - * + * Mapping to OWL API reasoner interface. The OWL API currently + * supports three reasoners: FaCT++, HermiT and Pellet. FaCT++ is connected + * using JNI and native libraries, while HermiT and Pellet are pure Java + * libraries. + * * @author Jens Lehmann */ @ComponentAnn(name = "OWL API Reasoner", shortName = "oar", version = 0.8) public class OWLAPIReasoner extends AbstractReasonerComponent { - // private static Logger logger = Logger - // .getLogger(OWLAPIReasoner.class); +// private static Logger logger = Logger +// .getLogger(OWLAPIReasoner.class); - // private String reasonerType = "pellet"; - private OWLReasoner reasoner; - private OWLOntologyManager manager; + //private String reasonerType = "pellet"; + private OWLReasoner reasoner; + private OWLOntologyManager manager; - private OWLOntology ontology; - // the data factory is used to generate OWL API objects - private OWLDataFactory factory; - // static factory - // private static OWLDataFactory staticFactory = - // OWLManager.createOWLOntologyManager().getOWLDataFactory(); + private OWLOntology ontology; + // the data factory is used to generate OWL API objects + private OWLDataFactory factory; + // static factory +// private static OWLDataFactory staticFactory = OWLManager.createOWLOntologyManager().getOWLDataFactory(); - private ConceptComparator conceptComparator = new ConceptComparator(); - private RoleComparator roleComparator = new RoleComparator(); - // private ClassHierarchy subsumptionHierarchy; - // private ObjectPropertyHierarchy roleHierarchy; - // private DatatypePropertyHierarchy datatypePropertyHierarchy; - // private Set<Description> allowedConceptsInSubsumptionHierarchy; + private ConceptComparator conceptComparator = new ConceptComparator(); + private RoleComparator roleComparator = new RoleComparator(); +// private ClassHierarchy subsumptionHierarchy; +// private ObjectPropertyHierarchy roleHierarchy; +// private DatatypePropertyHierarchy datatypePropertyHierarchy; +// private Set<Description> allowedConceptsInSubsumptionHierarchy; - // primitives - Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); - Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); - SortedSet<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<DatatypeProperty> stringDatatypeProperties = new TreeSet<DatatypeProperty>(); - SortedSet<Individual> individuals = new TreeSet<Individual>(); + // primitives + Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); + Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + SortedSet<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> stringDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<Individual> individuals = new TreeSet<Individual>(); - // namespaces - private Map<String, String> prefixes = new TreeMap<String, String>(); - private String baseURI; + // namespaces + private Map<String, String> prefixes = new TreeMap<String, String>(); + private String baseURI; - // references to OWL API ontologies - private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); - @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\", \"elk\", \"cel\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) - private String reasonerTypeString = "pellet"; - @ConfigOption(name = "owlLinkURL", description = "The URL to the owl server", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) - private String owlLinkURL; + // references to OWL API ontologies + private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); + @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\", \"elk\", \"cel\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String reasonerTypeString = "pellet"; + @ConfigOption(name = "owlLinkURL", description = "The URL to the owl server", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) + private String owlLinkURL; - public OWLAPIReasoner() { - } + public OWLAPIReasoner() { - public OWLAPIReasoner(Set<KnowledgeSource> sources) { - super(sources); - } + } + + public OWLAPIReasoner(KnowledgeSource... sources) { + super(new HashSet<KnowledgeSource>(Arrays.asList(sources))); + } - public static String getName() { - return "OWL API reasoner"; - } + public OWLAPIReasoner(Set<KnowledgeSource> sources) { + super(sources); + } - @Override - public void init() throws ComponentInitException { - // reset variables (otherwise subsequent initialisation with - // different knowledge sources will merge both) - atomicConcepts = new TreeSet<NamedClass>(conceptComparator); - atomicRoles = new TreeSet<ObjectProperty>(roleComparator); - datatypeProperties = new TreeSet<DatatypeProperty>(); - booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - intDatatypeProperties = new TreeSet<DatatypeProperty>(); - stringDatatypeProperties = new TreeSet<DatatypeProperty>(); - individuals = new TreeSet<Individual>(); + public static String getName() { + return "OWL API reasoner"; + } - // create OWL API ontology manager - make sure we use a new data factory - // so that we don't default to the static one which can cause problems - // in a multi threaded environment. - manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + @Override + public void init() throws ComponentInitException { + // reset variables (otherwise subsequent initialisation with + // different knowledge sources will merge both) + atomicConcepts = new TreeSet<NamedClass>(conceptComparator); + atomicRoles = new TreeSet<ObjectProperty>(roleComparator); + datatypeProperties = new TreeSet<DatatypeProperty>(); + booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + intDatatypeProperties = new TreeSet<DatatypeProperty>(); + stringDatatypeProperties = new TreeSet<DatatypeProperty>(); + individuals = new TreeSet<Individual>(); - // it is a bit cumbersome to obtain all classes, because there - // are no reasoner queries to obtain them => hence we query them - // for each ontology and add them to a set; a comparator avoids - // duplicates by checking URIs - Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { - public int compare(OWLNamedObject o1, OWLNamedObject o2) { - return o1.getIRI().compareTo(o2.getIRI()); - } - }; - Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); - Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>( - namedObjectComparator); - Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>( - namedObjectComparator); - Set<OWLNamedIndividual> owlIndividuals = new TreeSet<OWLNamedIndividual>( - namedObjectComparator); + // create OWL API ontology manager - make sure we use a new data factory so that we don't default to the static one which can cause problems in a multi threaded environment. + manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); - Set<OWLOntology> allImports = new HashSet<OWLOntology>(); - prefixes = new TreeMap<String, String>(); + // it is a bit cumbersome to obtain all classes, because there + // are no reasoner queries to obtain them => hence we query them + // for each ontology and add them to a set; a comparator avoids + // duplicates by checking URIs + Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { + public int compare(OWLNamedObject o1, OWLNamedObject o2) { + return o1.getIRI().compareTo(o2.getIRI()); + } + }; + Set<OWLClass> classes = new TreeSet<OWLClass>(namedObjectComparator); + Set<OWLObjectProperty> owlObjectProperties = new TreeSet<OWLObjectProperty>(namedObjectComparator); + Set<OWLDataProperty> owlDatatypeProperties = new TreeSet<OWLDataProperty>(namedObjectComparator); + Set<OWLNamedIndividual> owlIndividuals = new TreeSet<OWLNamedIndividual>(namedObjectComparator); - Set<OWLImportsDeclaration> directImports = new HashSet<OWLImportsDeclaration>(); + Set<OWLOntology> allImports = new HashSet<OWLOntology>(); + prefixes = new TreeMap<String, String>(); - for (KnowledgeSource source : sources) { + Set<OWLImportsDeclaration> directImports = new HashSet<OWLImportsDeclaration>(); - if (source instanceof OWLOntologyKnowledgeSource) { - ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); - owlAPIOntologies.add(ontology); - } else { - // This reasoner requires an ontology to process - throw new ComponentInitException( - "OWL API Reasoner Requires an OWLKnowledgeSource. Received a KS of type: " - + source.getClass().getName()); - } + for (KnowledgeSource source : sources) { - directImports.addAll(ontology.getImportsDeclarations()); + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + }else{ + //This reasoner requires an ontology to process + throw new ComponentInitException("OWL API Reasoner Requires an OWLKnowledgeSource. Received a KS of type: " + source.getClass().getName()); + } - try { - // imports includes the ontology itself - // FIXME this line throws the strange error - Set<OWLOntology> imports = manager.getImportsClosure(ontology); - allImports.addAll(imports); + directImports.addAll(ontology.getImportsDeclarations()); - // System.out.println(imports); - for (OWLOntology ont : imports) { - classes.addAll(ont.getClassesInSignature()); - owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); - owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); - owlIndividuals.addAll(ont.getIndividualsInSignature()); - } + try { + // imports includes the ontology itself + //FIXME this line throws the strange error + Set<OWLOntology> imports = manager.getImportsClosure(ontology); + allImports.addAll(imports); - } catch (UnknownOWLOntologyException uooe) { - logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); - } +// System.out.println(imports); + for (OWLOntology ont : imports) { + classes.addAll(ont.getClassesInSignature()); + owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); + owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); + owlIndividuals.addAll(ont.getIndividualsInSignature()); + } - // if several knowledge sources are included, then we can only - // guarantee that the base URI is from one of those sources (there - // can't be more than one); but we will take care that all prefixes - // are - // correctly imported - OWLOntologyFormat format = manager.getOntologyFormat(ontology); - if (format instanceof PrefixOWLOntologyFormat) { - prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); - baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); - prefixes.remove(""); - } + } catch (UnknownOWLOntologyException uooe) { + logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); + } - } + // if several knowledge sources are included, then we can only + // guarantee that the base URI is from one of those sources (there + // can't be more than one); but we will take care that all prefixes are + // correctly imported + OWLOntologyFormat format = manager.getOntologyFormat(ontology); + if (format instanceof PrefixOWLOntologyFormat) { + prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); + baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); + prefixes.remove(""); + } - // Now merge all of the knowledge sources into one ontology instance. - try { - // The following line illustrates a problem with using different - // OWLOntologyManagers. This can manifest itself if we have multiple - // sources who were created with different manager instances. - // ontology = - // OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner/all"), - // new HashSet<OWLOntology>(owlAPIOntologies)); - ontology = manager.createOntology(IRI.create("http://dl-learner/all"), - new HashSet<OWLOntology>(owlAPIOntologies)); - // we have to add all import declarations manually here, because - // this are no axioms - List<OWLOntologyChange> addImports = new ArrayList<OWLOntologyChange>(); - for (OWLImportsDeclaration i : directImports) { - addImports.add(new AddImport(ontology, i)); - } - manager.applyChanges(addImports); - } catch (OWLOntologyCreationException e1) { - e1.printStackTrace(); - } + } - // configure reasoner - ReasonerProgressMonitor progressMonitor = new NullReasonerProgressMonitor(); - FreshEntityPolicy freshEntityPolicy = FreshEntityPolicy.ALLOW; - long timeOut = Integer.MAX_VALUE; - IndividualNodeSetPolicy individualNodeSetPolicy = IndividualNodeSetPolicy.BY_NAME; - OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor, freshEntityPolicy, - timeOut, individualNodeSetPolicy); + //Now merge all of the knowledge sources into one ontology instance. + try { + //The following line illustrates a problem with using different OWLOntologyManagers. This can manifest itself if we have multiple sources who were created with different manager instances. + //ontology = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); + ontology = manager.createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); + //we have to add all import declarations manually here, because this are no axioms + List<OWLOntologyChange> addImports = new ArrayList<OWLOntologyChange>(); + for (OWLImportsDeclaration i : directImports) { + addImports.add(new AddImport(ontology, i)); + } + manager.applyChanges(addImports); + } catch (OWLOntologyCreationException e1) { + e1.printStackTrace(); + } - // create actual reasoner - if (getReasonerTypeString().equals("fact")) { - try { - reasoner = new FaCTPlusPlusReasonerFactory().createNonBufferingReasoner(ontology, - conf); + //configure reasoner + ReasonerProgressMonitor progressMonitor = new NullReasonerProgressMonitor(); + FreshEntityPolicy freshEntityPolicy = FreshEntityPolicy.ALLOW; + long timeOut = Integer.MAX_VALUE; + IndividualNodeSetPolicy individualNodeSetPolicy = IndividualNodeSetPolicy.BY_NAME; + OWLReasonerConfiguration conf = new SimpleConfiguration(progressMonitor, freshEntityPolicy, timeOut, individualNodeSetPolicy); - } catch (Exception e) { - throw new RuntimeException(e); - } - System.out.println("Using FaCT++."); - } else if (getReasonerTypeString().equals("hermit")) { - // instantiate HermiT reasoner - reasoner = new ReasonerFactory().createNonBufferingReasoner(ontology, conf); - } else if (getReasonerTypeString().equals("pellet")) { - // instantiate Pellet reasoner - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology, - conf); - // change log level to WARN for Pellet, because otherwise log - // output will be very large - Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); - pelletLogger.setLevel(Level.WARN); - } else if (getReasonerTypeString().equals("elk")) { - // instantiate ELK reasoner - reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology, conf); - // reasoner = new - // MyElkReasonerFactory().createNonBufferingReasoner(ontology, - // conf); - } else if (getReasonerTypeString().equals("cel")) { - // instantiate CEL reasoner - reasoner = new CelReasoner(ontology, conf); - } else { - try { - OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); - URL url = new URL(getOwlLinkURL());// Configure the server - // end-point - OWLlinkReasonerConfiguration config = new OWLlinkReasonerConfiguration(url); - reasoner = factory.createNonBufferingReasoner(ontology, config); - System.out.println(reasoner.getReasonerName()); - } catch (Exception e) { - // e.printStackTrace(); - throw new ComponentInitException(e); - } - } + // create actual reasoner + if (getReasonerTypeString().equals("fact")) { + try { + reasoner = new FaCTPlusPlusReasonerFactory().createNonBufferingReasoner(ontology, conf); + } catch (Exception e) { + throw new RuntimeException(e); + } + System.out.println("Using FaCT++."); + } else if (getReasonerTypeString().equals("hermit")) { + // instantiate HermiT reasoner + reasoner = new ReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("pellet")) { + // instantiate Pellet reasoner + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology, conf); + // change log level to WARN for Pellet, because otherwise log + // output will be very large + Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); + pelletLogger.setLevel(Level.WARN); + } else if (getReasonerTypeString().equals("elk")) { + // instantiate ELK reasoner + reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("cel")) { + // instantiate CEL reasoner + reasoner = new CelReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("trowl")) { + // instantiate TrOWL reasoner + reasoner = new RELReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else { + try { + OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); + URL url = new URL(getOwlLinkURL());//Configure the server end-point + OWLlinkReasonerConfiguration config = new OWLlinkReasonerConfiguration(url); + reasoner = factory.createNonBufferingReasoner(ontology, config); + System.out.println(reasoner.getReasonerName()); + } catch (Exception e) { +// e.printStackTrace(); + throw new ComponentInitException(e); + } + } - /* - * Set<OWLOntology> importsClosure = - * manager.getImportsClosure(ontology); - * System.out.println("imports closure : " + importsClosure); try { - * reasoner.loadOntologies(importsClosure); } catch - * (OWLReasonerException e1) { // TODO Auto-generated catch block - * e1.printStackTrace(); } - */ + /* + Set<OWLOntology> importsClosure = manager.getImportsClosure(ontology); + System.out.println("imports closure : " + importsClosure); + try { + reasoner.loadOntologies(importsClosure); + } catch (OWLReasonerException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ - // System.out.println(classes); - // System.out.println(properties); - // System.out.println(individuals); +// System.out.println(classes); +// System.out.println(properties); +// System.out.println(individuals); - // compute class hierarchy and types of individuals - // (done here to speed up later reasoner calls) - boolean inconsistentOntology = !reasoner.isConsistent(); + // compute class hierarchy and types of individuals + // (done here to speed up later reasoner calls) + boolean inconsistentOntology = !reasoner.isConsistent(); - if (!inconsistentOntology) { - reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY, - InferenceType.CLASS_ASSERTIONS); - } else { - throw new ComponentInitException("Inconsistent ontologies."); - } + if (!inconsistentOntology) { + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY, InferenceType.CLASS_ASSERTIONS); + } else { + throw new ComponentInitException("Inconsistent ontologies."); + } - factory = manager.getOWLDataFactory(); + factory = manager.getOWLDataFactory(); - // try { - // if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) - // System.out.println("DEFINED."); - // else - // System.out.println("NOT DEFINED."); - // } catch (OWLReasonerException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } +// try { +// if(reasoner.isDefined(factory.getOWLIndividual(URI.create("http://example.com/father#female")))) +// System.out.println("DEFINED."); +// else +// System.out.println("NOT DEFINED."); +// } catch (OWLReasonerException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } - // read in primitives - for (OWLClass owlClass : classes) - atomicConcepts.add(new NamedClass(owlClass.toStringID())); - for (OWLObjectProperty owlProperty : owlObjectProperties) - atomicRoles.add(new ObjectProperty(owlProperty.toStringID())); - for (OWLDataProperty owlProperty : owlDatatypeProperties) { - DatatypeProperty dtp = new DatatypeProperty(owlProperty.toStringID()); - Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); - Iterator<OWLDataRange> it = ranges.iterator(); - if (it.hasNext()) { - OWLDataRange range = it.next(); - if (range.isDatatype()) { - URI uri = ((OWLDatatype) range).getIRI().toURI(); - if (uri.equals(OWL2Datatype.BOOLEAN.getURI())) - booleanDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.DOUBLE.getURI())) - doubleDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.INT.getURI())) - intDatatypeProperties.add(dtp); - else if (uri.equals(OWL2Datatype.STRING.getURI())) - stringDatatypeProperties.add(dtp); - } - } else { - stringDatatypeProperties.add(dtp); - } - datatypeProperties.add(dtp); - } - for (OWLNamedIndividual owlIndividual : owlIndividuals) { - individuals.add(new Individual(owlIndividual.toStringID())); - } + // read in primitives + for (OWLClass owlClass : classes) + atomicConcepts.add(new NamedClass(owlClass.toStringID())); + for (OWLObjectProperty owlProperty : owlObjectProperties) + atomicRoles.add(new ObjectProperty(owlProperty.toStringID())); + for (OWLDataProperty owlProperty : owlDatatypeProperties) { + DatatypeProperty dtp = new DatatypeProperty(owlProperty.toStringID()); + Set<OWLDataRange> ranges = owlProperty.getRanges(allImports); + Iterator<OWLDataRange> it = ranges.iterator(); + if (it.hasNext()) { + OWLDataRange range = it.next(); + if (range.isDatatype()) { + URI uri = ((OWLDatatype) range).getIRI().toURI(); + if (uri.equals(OWL2Datatype.BOOLEAN.getURI())) booleanDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.DOUBLE.getURI())) doubleDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.INT.getURI())) intDatatypeProperties.add(dtp); + else if (uri.equals(OWL2Datatype.STRING.getURI())) stringDatatypeProperties.add(dtp); + } + } else { + stringDatatypeProperties.add(dtp); + } + datatypeProperties.add(dtp); + } + for (OWLNamedIndividual owlIndividual : owlIndividuals) { + individuals.add(new Individual(owlIndividual.toStringID())); + } - // remove top and bottom properties (for backwards compatibility) - // atomicRoles.remove(new - // ObjectProperty("http://www.w3.org/2002/07/owl#bottomObjectProperty")); - // atomicRoles.remove(new - // ObjectProperty("http://www.w3.org/2002/07/owl#topObjectProperty")); - } + // remove top and bottom properties (for backwards compatibility) +// atomicRoles.remove(new ObjectProperty("http://www.w3.org/2002/07/owl#bottomObjectProperty")); +// atomicRoles.remove(new ObjectProperty("http://www.w3.org/2002/07/owl#topObjectProperty")); + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getAtomicConcepts() - */ - public Set<NamedClass> getNamedClasses() { - return Collections.unmodifiableSet(atomicConcepts); - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicConcepts() + */ + public Set<NamedClass> getNamedClasses() { + return Collections.unmodifiableSet(atomicConcepts); + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getAtomicRoles() - */ - public Set<ObjectProperty> getObjectProperties() { - return Collections.unmodifiableSet(atomicRoles); - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getAtomicRoles() + */ + public Set<ObjectProperty> getObjectProperties() { + return Collections.unmodifiableSet(atomicRoles); + } - @Override - public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { - return datatypeProperties; - } + @Override + public SortedSet<DatatypeProperty> getDatatypePropertiesImpl() { + return datatypeProperties; + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getIndividuals() - */ - public SortedSet<Individual> getIndividuals() { - return individuals; - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getIndividuals() + */ + public SortedSet<Individual> getIndividuals() { + return individuals; + } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#getReasonerType() - */ - @Override - public ReasonerType getReasonerType() { - if (getReasonerTypeString().equals("fact")) { - return ReasonerType.OWLAPI_FACT; - } else if (getReasonerTypeString().equals("hermit")) { - return ReasonerType.OWLAPI_HERMIT; - } else { - return ReasonerType.OWLAPI_PELLET; - } - } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#getReasonerType() + */ + @Override + public ReasonerType getReasonerType() { + if (getReasonerTypeString().equals("fact")) { + return ReasonerType.OWLAPI_FACT; + } else if (getReasonerTypeString().equals("hermit")) { + return ReasonerType.OWLAPI_HERMIT; + } else { + return ReasonerType.OWLAPI_PELLET; + } + } - // @Override - // public ObjectPropertyHierarchy prepareRoleHierarchy() { - // // code copied from DIG reasoner - // - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (ObjectProperty role : atomicRoles) { - // roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); - // roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); - // } - // - // roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, - // roleHierarchyDown); - // return roleHierarchy; - // } +// @Override +// public ObjectPropertyHierarchy prepareRoleHierarchy() { +// // code copied from DIG reasoner +// +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (ObjectProperty role : atomicRoles) { +// roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); +// roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); +// } +// +// roleHierarchy = new ObjectPropertyHierarchy(atomicRoles, roleHierarchyUp, +// roleHierarchyDown); +// return roleHierarchy; +// } - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) - */ - // public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { - // // code copied from DIG reasoner - // - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new - // TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (ObjectProperty role : atomicRoles) { - // roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); - // roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); - // } - // - // roleHierarchy = new ObjectPropertyHierarchy(allowedRoles, - // roleHierarchyUp, - // roleHierarchyDown); - // } + /* (non-Javadoc) + * @see org.dllearner.core.Reasoner#prepareRoleHierarchy(java.util.Set) + */ +// public void prepareRoleHierarchy(Set<ObjectProperty> allowedRoles) { +// // code copied from DIG reasoner +// +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyUp = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// TreeMap<ObjectProperty, TreeSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, TreeSet<ObjectProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (ObjectProperty role : atomicRoles) { +// roleHierarchyDown.put(role, getMoreSpecialRolesImpl(role)); +// roleHierarchyUp.put(role, getMoreGeneralRolesImpl(role)); +// } +// +// roleHierarchy = new ObjectPropertyHierarchy(allowedRoles, roleHierarchyUp, +// roleHierarchyDown); +// } - // @Override - // public ObjectPropertyHierarchy getRoleHierarchy() { - // return roleHierarchy; - // } +// @Override +// public ObjectPropertyHierarchy getRoleHierarchy() { +// return roleHierarchy; +// } - // public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> - // allowedRoles) { - // // code copied from DIG reasoner - // - // TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> - // datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, - // TreeSet<DatatypeProperty>>( - // roleComparator); - // TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> - // datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, - // TreeSet<DatatypeProperty>>( - // roleComparator); - // - // // refinement of atomic concepts - // for (DatatypeProperty role : datatypeProperties) { - // datatypePropertyHierarchyDown.put(role, - // getMoreSpecialDatatypePropertiesImpl(role)); - // datatypePropertyHierarchyUp.put(role, - // getMoreGeneralDatatypePropertiesImpl(role)); - // } - // - // datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, - // datatypePropertyHierarchyUp, - // datatypePropertyHierarchyDown); - // } +// public void prepareDatatypePropertyHierarchyImpl(Set<DatatypeProperty> allowedRoles) { +// // code copied from DIG reasoner +// +// TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( +// roleComparator); +// TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>> datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, TreeSet<DatatypeProperty>>( +// roleComparator); +// +// // refinement of atomic concepts +// for (DatatypeProperty role : datatypeProperties) { +// datatypePropertyHierarchyDown.put(role, getMoreSpecialDatatypePropertiesImpl(role)); +// datatypePropertyHierarchyUp.put(role, getMoreGeneralDatatypePropertiesImpl(role)); +// } +// +// datatypePropertyHierarchy = new DatatypePropertyHierarchy(allowedRoles, datatypePropertyHierarchyUp, +// datatypePropertyHierarchyDown); +// } - // @Override - // public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { - // return datatypePropertyHierarchy; - // } +// @Override +// public DatatypePropertyHierarchy getDatatypePropertyHierarchy() { +// return datatypePropertyHierarchy; +// } - @Override - public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) { - return reasoner.isEntailed(factory.getOWLSubClassOfAxiom( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(subConcept), - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(superConcept))); - } + @Override + public boolean isSuperClassOfImpl(Description superConcept, Description subConcept) { + return reasoner.isEntailed(factory.getOWLSubClassOfAxiom(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(subConcept), OWLAPIDescriptionConvertVisitor.getOWLClassExpression(superConcept))); + } - @Override - protected boolean isEquivalentClassImpl(Description class1, Description class2) { - return reasoner.isEntailed(factory.getOWLEquivalentClassesAxiom( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class1), - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class2))); - } + @Override + protected boolean isEquivalentClassImpl(Description class1, Description class2) { + return reasoner.isEntailed(factory.getOWLEquivalentClassesAxiom(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class1), OWLAPIDescriptionConvertVisitor.getOWLClassExpression(class2))); + } - @Override - protected TreeSet<Description> getSuperClassesImpl(Description concept) { - NodeSet<OWLClass> classes = null; + @Override + protected TreeSet<Description> getSuperClassesImpl(Description concept) { + NodeSet<OWLClass> classes = null; - classes = reasoner.getSuperClasses( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); + classes = reasoner.getSuperClasses(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); - return getFirstClasses(classes); - } + return getFirstClasses(classes); + } - @Override - protected TreeSet<Description> getSubClassesImpl(Description concept) { - NodeSet<OWLClass> classes = null; + @Override + protected TreeSet<Description> getSubClassesImpl(Description concept) { + NodeSet<OWLClass> classes = null; - classes = reasoner.getSubClasses( - OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); + classes = reasoner.getSubClasses(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept), true); - return getFirstClasses(classes); - } + return getFirstClasses(classes); + } - @Override - protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { - NodeSet<OWLObjectPropertyExpression> properties = null; + @Override + protected TreeSet<ObjectProperty> getSuperPropertiesImpl(ObjectProperty role) { + NodeSet<OWLObjectPropertyExpression> properties = null; - try { - properties = reasoner.getSuperObjectProperties( - OWLAPIConverter.getOWLAPIObjectProperty(role), true); - return getFirstObjectProperties(properties); - } catch (Exception e) { - TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); - return roles; - } - } + properties = reasoner.getSuperObjectProperties(OWLAPIConverter.getOWLAPIObjectProperty(role), true); - @Override - protected TreeSet<ObjectProperty> getSubPropertiesImpl(ObjectProperty role) { - NodeSet<OWLObjectPropertyExpression> properties = null; + return getFirstObjectProperties(properties); + } - try { - properties = reasoner.getSubObjectProperties( - OWLAPIConverter.getOWLAPIObjectProperty(role), true); - return getFirstObjectProperties(properties); - } catch (Exception e) { - TreeSet<ObjectProperty> roles = new TreeSet<ObjectProperty>(roleComparator); - return roles; - } + @Override + protected TreeSet<ObjectProperty> getSubPropertiesImpl(ObjectProperty role) { + NodeSet<OWLObjectPropertyExpression> properties = null; - } + properties = reasoner.getSubObjectProperties(OWLAPIConverter.getOWLAPIObjectProperty(role), true); - @Override - protected TreeSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) { - NodeSet<OWLDataProperty> properties = null; + return getFirstObjectProperties(properties); + } - properties = reasoner.getSuperDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), - true); + @Override + protected TreeSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) { + NodeSet<OWLDataProperty> properties = null; - return getFirstDatatypeProperties(properties); - } + properties = reasoner.getSuperDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), true); - @Override - protected TreeSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) { - NodeSet<OWLDataProperty> properties = null; + return getFirstDatatypeProperties(properties); + } - properties = reasoner.getSubDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), - true); + @Override + protected TreeSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) { + NodeSet<OWLDataProperty> properties = null; - return getFirstDatatypeProperties(properties); - } + properties = reasoner.getSubDataProperties(OWLAPIConverter.getOWLAPIDataProperty(role), true); - @Override - public boolean hasTypeImpl(Description concept, Individual individual) { - boolean test = false; - OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); - OWLNamedIndividual i = factory.getOWLNamedIndividual(IRI.create(individual.getName())); -// try { -// test = reasoner.isEntailed(factory.getOWLClassAssertionAxiom(d, i)); -// } catch (Exception e) { -// test = true; -// } - if(d.isAnonymous()){ - throw new UnsupportedOperationException("Can not do type checking for complex class expressions."); - } - for(OWLClass type : reasoner.getTypes(i, false).getFlattened()){ - if(type.equals(d.asOWLClass())){ - return true; - } - } - return test; - } + return getFirstDatatypeProperties(properties); + } - @Override - public SortedSet<Individual> getIndividualsImpl(Description concept) { - // OWLDescription d = getOWLAPIDescription(concept); - OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); - Set<OWLNamedIndividual> individuals = reasoner.getInstances(d, false).getFlattened(); - SortedSet<Individual> inds = new TreeSet<Individual>(); - for (OWLNamedIndividual ind : individuals) - // ugly code - if (ind != null) - inds.add(new Individual(ind.toStringID())); - return inds; - } + @Override + public boolean hasTypeImpl(Description concept, Individual individual) { + OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); + OWLIndividual i = factory.getOWLNamedIndividual(IRI.create(individual.getName())); + if(concept instanceof Thing) return true; + if(concept instanceof NamedClass && ((NamedClass)concept).getName().contains("Error"))return false; + return reasoner.isEntailed(factory.getOWLClassAssertionAxiom(d, i)); + } - @Override - public Set<NamedClass> getTypesImpl(Individual individual) { - Set<Node<OWLClass>> result = null; + @Override + public SortedSet<Individual> getIndividualsImpl(Description concept) { +// OWLDescription d = getOWLAPIDescription(concept); + OWLClassExpression d = OWLAPIDescriptionConvertVisitor.getOWLClassExpression(concept); + Set<OWLNamedIndividual> individuals = reasoner.getInstances(d, false).getFlattened(); + SortedSet<Individual> inds = new TreeSet<Individual>(); + for (OWLNamedIndividual ind : individuals) + //ugly code + if (ind != null) inds.add(new Individual(ind.toStringID())); + return inds; + } - result = reasoner.getTypes(factory.getOWLNamedIndividual(IRI.create(individual.getName())), - false).getNodes(); + @Override + public Set<NamedClass> getTypesImpl(Individual individual) { + Set<Node<OWLClass>> result = null; - return getFirstClassesNoTopBottom(result); - } + result = reasoner.getTypes(factory.getOWLNamedIndividual(IRI.create(individual.getName())), false).getNodes(); - @Override - public boolean isSatisfiableImpl() { - return reasoner.isSatisfiable(factory.getOWLThing()); - } + return getFirstClassesNoTopBottom(result); + } - @Override - public Description getDomainImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + @Override + public boolean isSatisfiableImpl() { + return reasoner.isSatisfiable(factory.getOWLThing()); + } - // Pellet returns a set of nodes of named classes, which are more - // general than the actual domain/range - NodeSet<OWLClass> set; + @Override + public Description getDomainImpl(ObjectProperty objectProperty) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + + // Pellet returns a set of nodes of named classes, which are more + // general than the actual domain/range + NodeSet<OWLClass> set; try { set = reasoner.getObjectPropertyDomains(prop, false); return getDescriptionFromReturnedDomain(set); - } catch (Exception e) { - return getDescriptionFromReturnedDomain(null); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (FreshEntitiesException e) { + e.printStackTrace(); + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch(de.tudresden.inf.lat.cel.owlapi.UnsupportedReasonerOperationInCelException e){ + e.printStackTrace(); } - } + return Thing.instance; - @Override - public Description getDomainImpl(DatatypeProperty datatypeProperty) { - OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); + } - NodeSet<OWLClass> set = reasoner.getDataPropertyDomains(prop, true); - return getDescriptionFromReturnedDomain(set); + @Override + public Description getDomainImpl(DatatypeProperty datatypeProperty) { + OWLDataProperty prop = OWLAPIConverter.getOWLAPIDataProperty(datatypeProperty); - } + NodeSet<OWLClass> set = reasoner.getDataPropertyDomains(prop, true); + return getDescriptionFromReturnedDomain(set); - @Override - public Description getRangeImpl(ObjectProperty objectProperty) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + } - NodeSet<OWLClass> set; + @Override + public Description getRangeImpl(ObjectProperty objectProperty) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(objectProperty); + + NodeSet<OWLClass> set; try { set = reasoner.getObjectPropertyRanges(prop, true); - if (set.isEmpty()) - return new Thing(); - OWLClass oc = set.iterator().next().getRepresentativeElement(); - if (oc.isOWLThing()) { - return Thing.instance; - } - return new NamedClass(oc.toStringID()); - } catch (Exception e) { - return Thing.instance; + if (set.isEmpty()) return new Thing(); + OWLClass oc = set.iterator().next().getRepresentativeElement(); + if (oc.isOWLThing()) { + return Thing.instance; + } + return new NamedClass(oc.toStringID()); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (FreshEntitiesException e) { + e.printStackTrace(); + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch(de.tudresden.inf.lat.cel.owlapi.UnsupportedReasonerOperationInCelException e){ + e.printStackTrace(); } - } + return Thing.instance; - private Description getDescriptionFromReturnedDomain(NodeSet<OWLClass> set) { - if (set.isEmpty()) - return new Thing(); + } - Set<OWLClassExpression> union = new HashSet<OWLClassExpression>(); - Set<OWLClassExpression> domains = new HashSet<OWLClassExpression>(); + private Description getDescriptionFromReturnedDomain(NodeSet<OWLClass> set) { + if (set.isEmpty()) return new Thing(); - for (Node<OWLClass> descs : set) { - for (OWLClassExpression desc : descs) { - union.add(desc); - } - } - for (OWLClassExpression desc : union) { - boolean isSuperClass = false; - for (Description d : getClassHierarchy().getSubClasses( - OWLAPIConverter.convertClass(desc.asOWLClass()))) { - if (union.contains(OWLAPIConverter.getOWLAPIDescription(d))) { - isSuperClass = true; - break; - } - } - if (!isSuperClass) { - domains.add(desc); - } - } + Set<OWLClassExpression> union = new HashSet<OWLClassExpression>(); + Set<OWLClassExpression> domains = new HashSet<OWLClassExpression>(); - OWLClass oc = (OWLClass) domains.iterator().next(); - if (oc.isOWLThing()) { - return new Thing(); - } else { - return new NamedClass(oc.toStringID()); - } - } + for (Node<OWLClass> descs : set) { + for (OWLClassExpression desc : descs) { + union.add(desc); + } + } + for (OWLClassExpression desc : union) { + boolean isSuperClass = false; + for (Description d : getClassHierarchy().getSubClasses(OWLAPIConverter.convertClass(desc.asOWLClass()))) { + if (union.contains(OWLAPIConverter.getOWLAPIDescription(d))) { + isSuperClass = true; + break; + } + } + if (!isSuperClass) { + domains.add(desc); + } + } - @Override - public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { - OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole); - Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); - for (Individual i : individuals) { - OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(i.getName())); + OWLClass oc = (OWLClass) domains.iterator().next(); + if (oc.isOWLThing()) { + return new Thing(); + } else { + return new NamedClass(oc.toStringID()); + } + } - // get all related individuals via OWL API - Set<OWLNamedIndividual> inds; - try { - inds = reasoner.getObjectPropertyValues(ind, prop).getFlattened(); - } catch (Exception e) { - inds = null; - } + @Override + public Map<Individual, SortedSet<Individual>> getPropertyMembersImpl(ObjectProperty atomicRole) { + OWLObjectProperty prop = OWLAPIConverter.getOWLAPIObjectProperty(atomicRole); + Map<Individual, SortedSet<Individual>> map = new TreeMap<Individual, SortedSet<Individual>>(); + for (Individual i : individuals) { + OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(i.getName())); - // convert data back to DL-Learner structures - SortedSet<Individual> is = new TreeSet<Individual>(); - try { - for (OWLNamedIndividual oi : inds) - is.add(new Individual(oi.toStringID())); - map.put(i, is); - } catch (Exception e) { - map = null; - } - } - return map; - } + // get all related individuals via OWL API + Set<OWLNamedIndividual> inds = reasoner.getObjectPropertyValues(ind, prop).getFlattened(); - @Override - protected Map<ObjectProperty, Set<Individual>> getObjectPropertyRelationshipsImpl( - Individual individual) { - OWLNamedIndividual ind = factory.getOWLNamedIndividual(IRI.create(individual.getName())); - Map<OWLObjectPropertyExpression, Set<OWLNamedIndividual>> mapAPI = new HashMap<OWLObjectPropertyExpression, Set<OWLNamedIndividual>>(); + // convert data back to DL-Learner structures + SortedSet<Individual> is = new TreeSet<Individual>(); + for (OWLNamedIndividual oi : inds) + ... [truncated message content] |
From: <lor...@us...> - 2012-12-11 19:34:46
|
Revision: 3880 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3880&view=rev Author: lorenz_b Date: 2012-12-11 19:34:37 +0000 (Tue, 11 Dec 2012) Log Message: ----------- Set default log level to INFO in log4j.properties file. Added config option logLevel(String value) for cli to set the log level via config file. Modified Paths: -------------- trunk/interfaces/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java trunk/interfaces/src/main/resources/log4j.properties Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2012-11-29 15:21:42 UTC (rev 3879) +++ trunk/interfaces/pom.xml 2012-12-11 19:34:37 UTC (rev 3880) @@ -383,6 +383,12 @@ <dependency> <groupId>org.dllearner</groupId> <artifactId>components-core</artifactId> + <exclusions> + <exclusion> + <artifactId>jena</artifactId> + <groupId>com.hp.hpl.jena</groupId> + </exclusion> + </exclusions> </dependency> <!--dependency> <groupId>org.dllearner</groupId> <artifactId>components-ext</artifactId> </dependency --> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-11-29 15:21:42 UTC (rev 3879) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-12-11 19:34:37 UTC (rev 3880) @@ -29,6 +29,7 @@ import org.apache.commons.lang.exception.ExceptionUtils; +import org.apache.log4j.Level; import org.apache.xmlbeans.XmlObject; import org.dllearner.algorithms.ParCEL.ParCELPosNegLP; import org.dllearner.configuration.IConfiguration; @@ -70,6 +71,8 @@ private boolean performCrossValidation = false; private int nrOfFolds = 10; private int noOfRuns = 1; + + private String logLevel = "INFO"; public CLI() { @@ -97,6 +100,11 @@ } public void run() throws IOException { + try { + org.apache.log4j.Logger.getLogger("org.dllearner").setLevel(Level.toLevel(logLevel.toUpperCase())); + } catch (Exception e) { + logger.warn("Error setting log level to " + logLevel); + } if (writeSpringConfiguration) { SpringConfigurationXMLBeanConverter converter = new SpringConfigurationXMLBeanConverter(); @@ -272,6 +280,14 @@ this.nrOfFolds = nrOfFolds; } + public void setLogLevel(String logLevel) { + this.logLevel = logLevel; + } + + public String getLogLevel() { + return logLevel; + } + public LearningAlgorithm getLearningAlgorithm() { return algorithm; } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-11-29 15:21:42 UTC (rev 3879) +++ trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-12-11 19:34:37 UTC (rev 3880) @@ -111,6 +111,8 @@ public static void main(String[] args) throws MalformedURLException, IllegalArgumentException, SecurityException, ComponentInitException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, FileNotFoundException { new File(baseDir).mkdirs(); + new File(baseDir).mkdirs(); + SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); Logger.getRootLogger().setLevel(Level.WARN); Modified: trunk/interfaces/src/main/resources/log4j.properties =================================================================== --- trunk/interfaces/src/main/resources/log4j.properties 2012-11-29 15:21:42 UTC (rev 3879) +++ trunk/interfaces/src/main/resources/log4j.properties 2012-12-11 19:34:37 UTC (rev 3880) @@ -13,9 +13,9 @@ log4j.appender.file.Threshold=DEBUG # DL-Learner Logs -log4j.logger.org.dllearner=DEBUG +log4j.logger.org.dllearner=INFO # Turn this to Debug if you wish to dump stack traces to the appenders (console, file) -log4j.logger.org.dllearner.cli=DEBUG +log4j.logger.org.dllearner.cli=INFO log4j.logger.org.dllearner.server.nke.LogicalRelationStrategy=DEBUG log4j.category.org.dllearner.kb.simple=DEBUG This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-11-29 15:21:53
|
Revision: 3879 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3879&view=rev Author: jenslehmann Date: 2012-11-29 15:21:42 +0000 (Thu, 29 Nov 2012) Log Message: ----------- documentation update Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/examples/father.conf trunk/interfaces/doc/configOptions.html Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2012-11-29 15:21:42 UTC (rev 3879) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2011, Jens Lehmann + * Copyright (C) 2007-2012, Jens Lehmann * * This file is part of DL-Learner. * @@ -19,7 +19,6 @@ package org.dllearner.learningproblems; -import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; @@ -34,12 +33,7 @@ import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.CommonConfigOptions; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.DoubleConfigOption; -import org.dllearner.core.options.StringConfigOption; -import org.dllearner.core.options.URLConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; @@ -64,22 +58,26 @@ private long nanoStartTime; private int maxExecutionTimeInSeconds = 10; - // TODO: config option + @ConfigOption(name = "classToDescribe", description="class of which a description should be learned", required=true) private NamedClass classToDescribe; private List<Individual> classInstances; private TreeSet<Individual> classInstancesSet; private boolean equivalence = true; -// private ClassLearningProblemConfigurator configurator; - // approximation of accuracy + + @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false) private boolean useApproximations; // factor for higher weight on recall (needed for subclass learning) private double coverageFactor; + @ConfigOption(name = "betaSC", description="beta index for F-measure in super class learning", required=false, defaultValue="3.0") private double betaSC = 3.0; + + @ConfigOption(name = "betaEq", description="beta index for F-measure in definition learning", required=false, defaultValue="1.0") private double betaEq = 1.0; // instances of super classes excluding instances of the class itself @@ -89,8 +87,12 @@ // specific variables for generalised F-measure private TreeSet<Individual> negatedClassInstances; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy. Available measues are \"pred_acc\" (predictive accuracy), \"fmeasure\" (F measure), \"generalised_fmeasure\" (generalised F-Measure according to Fanizzi and d'Amato).",defaultValue = "pred_acc") + private String accuracyMethod = "pred_acc"; + private HeuristicType heuristic = HeuristicType.AMEASURE; + @ConfigOption(name = "checkConsistency", description = "whether to check for consistency of suggestions (when added to ontology)", required=false, defaultValue="true") private boolean checkConsistency = true; public ClassLearningProblem() { @@ -106,6 +108,7 @@ // configurator = new ClassLearningProblemConfigurator(this); } + /* public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); URLConfigOption classToDescribeOption = new URLConfigOption("classToDescribe", "class of which a description should be learned", null, true, false); @@ -130,6 +133,7 @@ options.add(betaEq); return options; } + */ public static String getName() { return "class learning problem"; @@ -140,18 +144,18 @@ // classToDescribe = new NamedClass(configurator.getClassToDescribe().toString()); // useApproximations = configurator.getUseApproximations(); -// String accM = configurator.getAccuracyMethod(); -// if(accM.equals("standard")) { -// heuristic = HeuristicType.AMEASURE; -// } else if(accM.equals("fmeasure")) { -// heuristic = HeuristicType.FMEASURE; -// } else if(accM.equals("generalised_fmeasure")) { -// heuristic = HeuristicType.GEN_FMEASURE; -// } else if(accM.equals("jaccard")) { -// heuristic = HeuristicType.JACCARD; -// } else if(accM.equals("pred_acc")) { -// heuristic = HeuristicType.PRED_ACC; -// } + String accM = accuracyMethod; + if(accM.equals("standard")) { + heuristic = HeuristicType.AMEASURE; + } else if(accM.equals("fmeasure")) { + heuristic = HeuristicType.FMEASURE; + } else if(accM.equals("generalised_fmeasure")) { + heuristic = HeuristicType.GEN_FMEASURE; + } else if(accM.equals("jaccard")) { + heuristic = HeuristicType.JACCARD; + } else if(accM.equals("pred_acc")) { + heuristic = HeuristicType.PRED_ACC; + } if(useApproximations && heuristic.equals(HeuristicType.PRED_ACC)) { System.err.println("Approximating predictive accuracy is an experimental feature. USE IT AT YOUR OWN RISK. If you consider to use it for anything serious, please extend the unit tests at org.dllearner.test.junit.HeuristicTests first to verify that it works."); Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2012-11-29 15:21:42 UTC (rev 3879) @@ -66,9 +66,9 @@ @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false) private boolean useApproximations; - @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) - private String accuracyMethod = "predacc"; - + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy. Available measues are \"pred_acc\" (predictive accuracy), \"fmeasure\" (F measure), \"generalised_fmeasure\" (generalised F-Measure according to Fanizzi and d'Amato).",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) + private String accuracyMethod = "pred_acc"; + // private boolean useFMeasure; private boolean useOldDIGOptions = false; Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/examples/father.conf 2012-11-29 15:21:42 UTC (rev 3879) @@ -24,5 +24,6 @@ lp.negativeExamples = { "ex:heinz", "ex:anna", "ex:michelle" } // create learning algorithm to run -alg1.type = "celoe" -alg2.type = "pceloe" +alg.type = "celoe" +alg.maxExecutionTimeInSeconds = 1 + Modified: trunk/interfaces/doc/configOptions.html =================================================================== --- trunk/interfaces/doc/configOptions.html 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/interfaces/doc/configOptions.html 2012-11-29 15:21:42 UTC (rev 3879) @@ -65,27 +65,36 @@ <p>short name: bruteForce<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.CELOE"><h2>CELOE</h2></a> <p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />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.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> <tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> -<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> <tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.ClassLearningProblem"><h2>ClassLearningProblem</h2></a> -<p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy. Available measues are "pred_acc" (predictive accuracy), "fmeasure" (F measure), "generalised_fmeasure" (generalised F-Measure according to Fanizzi and d'Amato).</td><td> String</td><td>pred_acc</td><td> false</td></tr> +<tr><td>classToDescribe</td><td>class of which a description should be learned</td><td> NamedClass</td><td></td><td> true</td></tr> +<tr><td>checkConsistency</td><td>whether to check for consistency of suggestions (when added to ontology)</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> +<tr><td>betaSC</td><td>beta index for F-measure in super class learning</td><td> double</td><td>3.0</td><td> false</td></tr> +<tr><td>betaEq</td><td>beta index for F-measure in definition learning</td><td> double</td><td>1.0</td><td> false</td></tr> +<tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive"><h2>Disjunctive ELTL</h2></a> <p>short name: deltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: Disjunctive ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf with support for disjunctions.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>tryFullCoverage</td><td>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.</td><td> boolean</td><td>false</td><td> false</td></tr> @@ -105,8 +114,8 @@ <p>short name: fuzzyPosNeg<br />version: 0.2<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB File</h2></a> <p>short name: kbfile<br />version: 0.8<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> <tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> -<tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="OtherComponent"><a name="org.dllearner.algorithms.celoe.OEHeuristicRuntime"><h2>OEHeuristicRuntime</h2></a> @@ -116,8 +125,8 @@ </div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.OWLAPIReasoner"><h2>OWL API Reasoner</h2></a> <p>short name: oar<br />version: 0.8<br />implements: ReasonerComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> <tr><td>owlLinkURL</td><td>The URL to the owl server</td><td> String</td><td></td><td> false</td></tr> -<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.ocel.OCEL"><h2>OWL Class Expression Learner</h2></a> @@ -126,45 +135,45 @@ <p>short name: owlfile<br />version: 0.9<br />implements: KnowledgeSource<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.PCELOE"><h2>PCELOE</h2></a> <p>short name: pceloe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />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.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> <tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> -<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>nrOfThreads</td><td>number of threads running in parallel</td><td> int</td><td>2</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> <tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStandard"><h2>PosNegLPStandard</h2></a> <p>short name: posNegStandard<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> -<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy.</td><td> String</td><td>predacc</td><td> false</td></tr> +<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy. Available measues are "pred_acc" (predictive accuracy), "fmeasure" (F measure), "generalised_fmeasure" (generalised F-Measure according to Fanizzi and d'Amato).</td><td> String</td><td>predacc</td><td> false</td></tr> <tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStrict"><h2>PosNegLPStrict</h2></a> <p>short name: posNegStrict<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> <tr><td>accuracyPenalty</td><td>penalty for incorrectness (example belongs neither to concept nor its negation)</td><td> double</td><td>1</td><td> false</td></tr> -<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.RandomGuesser"><h2>Random Guesser</h2></a> <p>short name: randomGuesser<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.SparqlEndpointKS"><h2>SPARQL endpoint</h2></a> <p>short name: sparql<br />version: 0.2<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> <tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> -<tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> </tbody></table> </div> <div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.SparqlKnowledgeSource"><h2>SPARQL endpoint fragment</h2></a> @@ -201,14 +210,14 @@ </div> <div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.simple.SparqlSimpleExtractor"><h2>efficient SPARQL fragment extractor</h2></a> <p>short name: sparqls<br />version: 0.1<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> +<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> +<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> +<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> <tr><td>tboxfilter</td><td>Filter for the tbox, can use variable ?example and ?class</td><td> String</td><td></td><td> false</td></tr> +<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> <tr><td>endpointURL</td><td>URL of the SPARQL endpoint</td><td> String</td><td></td><td> true</td></tr> -<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> -<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> <tr><td>instances</td><td>List of the instances to use</td><td> List</td><td></td><td> true</td></tr> -<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> -<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> -<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner"><h2>equivalent dataproperty axiom learner</h2></a> @@ -245,10 +254,10 @@ <div class="OtherComponent"><a name="org.dllearner.algorithms.ocel.MultiHeuristic"><h2>multiple criteria heuristic</h2></a> <p>short name: multiheuristic<br />version: 0.7<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> -<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> +<tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> <tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> <tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> +<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> <tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> </tbody></table> </div> @@ -271,19 +280,19 @@ <p>short name: posonlylp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.RhoDRDown"><h2>rho refinement operator</h2></a> <p>short name: rho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.SimpleSubclassLearner"><h2>simple subclass learner</h2></a> @@ -298,19 +307,19 @@ </div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.SynchronizedRhoDRDown"><h2>synchronized rho refinement operator</h2></a> <p>short name: syncrho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner"><h2>transitive objectproperty axiom learner</h2></a> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-11-29 14:57:46
|
Revision: 3878 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3878&view=rev Author: jenslehmann Date: 2012-11-29 14:57:34 +0000 (Thu, 29 Nov 2012) Log Message: ----------- documentation update Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/interfaces/doc/configOptions.html Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -174,6 +174,7 @@ @Override public void start() { +// System.out.println("starting disjunctive ELTL algorithm"); stop = false; isRunning = true; reset(); @@ -196,7 +197,9 @@ // System.out.println("best: " + best); // apply operator + System.out.print("applying operator ..."); List<ELDescriptionTree> refinements = operator.refine(best.getDescriptionTree()); + System.out.println("done " + refinements.size() + " refinements"); // add all refinements to search tree, candidates, best descriptions for(ELDescriptionTree refinement : refinements) { addDescriptionTree(refinement, best); Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -81,6 +81,7 @@ "org.dllearner.kb.sparql.SparqlKnowledgeSource", "org.dllearner.kb.sparql.simple.SparqlSimpleExtractor", "org.dllearner.learningproblems.PosNegLPStandard", + "org.dllearner.learningproblems.PosNegLPStrict", "org.dllearner.learningproblems.FuzzyPosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.learningproblems.ClassLearningProblem", Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -25,11 +25,12 @@ import java.util.TreeSet; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.DoubleConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; @@ -40,17 +41,27 @@ import org.dllearner.utilities.datastructures.SortedSetTuple; /** + * + * A strict learning problem means that for negative examples, it is required that a negative example + * should be instance of (NOT C) for a hypothesis C. + * * @author Jens Lehmann * */ +@ComponentAnn(name = "PosNegLPStrict", shortName = "posNegStrict", version = 0.8) public class PosNegLPStrict extends PosNegLP { private Set<Individual> neutralExamples; private boolean penaliseNeutralExamples = false; private static final double defaultAccuracyPenalty = 1; + + @ConfigOption(name = "accuracyPenalty", description = "penalty for incorrectness (example belongs neither to concept nor its negation)", defaultValue = "1", required = false) private double accuracyPenalty = defaultAccuracyPenalty; + private static final double defaultErrorPenalty = 3; + + @ConfigOption(name = "errorPenalty", description = "penalty for errors (example can be inferred to belong to the negated concept class)", defaultValue = "3", required = false) private double errorPenalty = defaultErrorPenalty; @@ -65,13 +76,14 @@ return "three valued definition learning problem"; } + /* public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = PosNegLP.createConfigOptions(); options.add(new BooleanConfigOption("penaliseNeutralExamples", "if set to true neutral examples are penalised")); options.add(new DoubleConfigOption("accuracyPenalty", "penalty for pos/neg examples which are classified as neutral", defaultAccuracyPenalty)); options.add(new DoubleConfigOption("errorPenalty", "penalty for pos. examples classified as negative or vice versa", defaultErrorPenalty)); return options; - } + } */ /* * (non-Javadoc) Modified: trunk/interfaces/doc/configOptions.html =================================================================== --- trunk/interfaces/doc/configOptions.html 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/interfaces/doc/configOptions.html 2012-11-29 14:57:34 UTC (rev 3878) @@ -21,14 +21,19 @@ <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.BruteForceLearner">Brute Force Learner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.celoe.CELOE">CELOE</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.ClassLearningProblem">ClassLearningProblem</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive">Disjunctive ELTL</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.el.ELLearningAlgorithm">ELTL</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.fuzzydll.FuzzyCELOE">Fuzzy CELOE</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner">Fuzzy OWL API Reasoner</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.FuzzyPosNegLPStandard">FuzzyPosNegLPStandard</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.KBFile">KB File</a></li></div> +<div class="OtherComponent"><li><a href="#org.dllearner.algorithms.celoe.OEHeuristicRuntime">OEHeuristicRuntime</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.OWLAPIReasoner">OWL API Reasoner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.ocel.OCEL">OWL Class Expression Learner</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.OWLFile">OWL File</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.celoe.PCELOE">PCELOE</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosNegLPStandard">PosNegLPStandard</a></li></div> +<div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosNegLPStrict">PosNegLPStrict</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.RandomGuesser">Random Guesser</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.SparqlEndpointKS">SPARQL endpoint</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.sparql.SparqlKnowledgeSource">SPARQL endpoint fragment</a></li></div> @@ -38,6 +43,7 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.DisjointClassesLearner">disjoint classes learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner">disjoint dataproperty axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner">disjoint objectproperty axiom learner</a></li></div> +<div class="KnowledgeSource"><li><a href="#org.dllearner.kb.sparql.simple.SparqlSimpleExtractor">efficient SPARQL fragment extractor</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner">equivalent dataproperty axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner">equivalent objectproperty axiom learner</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.FastInstanceChecker">fast instance checker</a></li></div> @@ -49,34 +55,48 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner">objectproperty domain axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner">objectproperty range learner</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosOnlyLP">positive only learning problem</a></li></div> -<div class="LearningAlgorithm"><li><a href="#org.dllearner.algorithm.qtl.QTL">query tree learner</a></li></div> <div class="RefinementOperator"><li><a href="#org.dllearner.refinementoperators.RhoDRDown">rho refinement operator</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.SimpleSubclassLearner">simple subclass learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner">symmetric objectproperty axiom learner</a></li></div> +<div class="RefinementOperator"><li><a href="#org.dllearner.refinementoperators.SynchronizedRhoDRDown">synchronized rho refinement operator</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner">transitive objectproperty axiom learner</a></li></div> </ul> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.BruteForceLearner"><h2>Brute Force Learner</h2></a> <p>short name: bruteForce<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.CELOE"><h2>CELOE</h2></a> <p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />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.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>maxClassDescriptionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> <tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.ClassLearningProblem"><h2>ClassLearningProblem</h2></a> <p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive"><h2>Disjunctive ELTL</h2></a> +<p>short name: deltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: Disjunctive ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf with support for disjunctions.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>tryFullCoverage</td><td>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.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>treeSearchTimeSeconds</td><td>Specifies how long the algorithm should search for a partial solution (a tree).</td><td> double</td><td>1.0</td><td> false</td></tr> +</tbody></table> +</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithm"><h2>ELTL</h2></a> +<p>short name: eltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator.</td><td> boolean</td><td>true</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.fuzzydll.FuzzyCELOE"><h2>Fuzzy CELOE</h2></a> <p>short name: fceloe<br />version: 0.2<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: See Fuzzy DL-Learner paper published at ISDA 2011.<br /></p>This component does not have configuration options.</div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner"><h2>Fuzzy OWL API Reasoner</h2></a> @@ -85,33 +105,65 @@ <p>short name: fuzzyPosNeg<br />version: 0.2<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB File</h2></a> <p>short name: kbfile<br />version: 0.8<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> <tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> -<tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="OtherComponent"><a name="org.dllearner.algorithms.celoe.OEHeuristicRuntime"><h2>OEHeuristicRuntime</h2></a> +<p>short name: celoe_heuristic<br />version: 0.5<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> +</tbody></table> +</div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.OWLAPIReasoner"><h2>OWL API Reasoner</h2></a> <p>short name: oar<br />version: 0.8<br />implements: ReasonerComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>owlLinkURL</td><td>The URL to the owl server</td><td> String</td><td></td><td> false</td></tr> -<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet"}</td><td> String</td><td>pellet</td><td> false</td></tr> +<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.ocel.OCEL"><h2>OWL Class Expression Learner</h2></a> <p>short name: ocel<br />version: 1.2<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.OWLFile"><h2>OWL File</h2></a> <p>short name: owlfile<br />version: 0.9<br />implements: KnowledgeSource<br /></p>This component does not have configuration options.</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.PCELOE"><h2>PCELOE</h2></a> +<p>short name: pceloe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />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.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>nrOfThreads</td><td>number of threads running in parallel</td><td> int</td><td>2</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> +<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStandard"><h2>PosNegLPStandard</h2></a> <p>short name: posNegStandard<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> <tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy.</td><td> String</td><td>predacc</td><td> false</td></tr> <tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> </tbody></table> </div> +<div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStrict"><h2>PosNegLPStrict</h2></a> +<p>short name: posNegStrict<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>accuracyPenalty</td><td>penalty for incorrectness (example belongs neither to concept nor its negation)</td><td> double</td><td>1</td><td> false</td></tr> +<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.RandomGuesser"><h2>Random Guesser</h2></a> <p>short name: randomGuesser<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.SparqlEndpointKS"><h2>SPARQL endpoint</h2></a> <p>short name: sparql<br />version: 0.2<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> -<tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> </tbody></table> </div> @@ -147,6 +199,18 @@ <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.simple.SparqlSimpleExtractor"><h2>efficient SPARQL fragment extractor</h2></a> +<p>short name: sparqls<br />version: 0.1<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>tboxfilter</td><td>Filter for the tbox, can use variable ?example and ?class</td><td> String</td><td></td><td> false</td></tr> +<tr><td>endpointURL</td><td>URL of the SPARQL endpoint</td><td> String</td><td></td><td> true</td></tr> +<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> +<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> +<tr><td>instances</td><td>List of the instances to use</td><td> List</td><td></td><td> true</td></tr> +<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> +<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> +<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner"><h2>equivalent dataproperty axiom learner</h2></a> <p>short name: dplequiv<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> @@ -180,12 +244,12 @@ </div> <div class="OtherComponent"><a name="org.dllearner.algorithms.ocel.MultiHeuristic"><h2>multiple criteria heuristic</h2></a> <p>short name: multiheuristic<br />version: 0.7<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> +<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> +<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> <tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> <tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> -<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> <tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> -<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner"><h2>object subPropertyOf axiom learner</h2></a> @@ -205,22 +269,20 @@ </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosOnlyLP"><h2>positive only learning problem</h2></a> <p>short name: posonlylp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> -<div class="LearningAlgorithm"><a name="org.dllearner.algorithm.qtl.QTL"><h2>query tree learner</h2></a> -<p>short name: qtl<br />version: 0.8<br />implements: LearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.RhoDRDown"><h2>rho refinement operator</h2></a> <p>short name: rho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> @@ -234,6 +296,23 @@ <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="RefinementOperator"><a name="org.dllearner.refinementoperators.SynchronizedRhoDRDown"><h2>synchronized rho refinement operator</h2></a> +<p>short name: syncrho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner"><h2>transitive objectproperty axiom learner</h2></a> <p>short name: opltrans<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2012-11-23 09:58:04
|
Revision: 3877 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3877&view=rev Author: edka Date: 2012-11-23 09:57:51 +0000 (Fri, 23 Nov 2012) Log Message: ----------- phaenotype-examples with conf-file Modified Paths: -------------- trunk/test/phaenotype/mp-equivalence-axioms-subq.owl Added Paths: ----------- trunk/test/phaenotype/beispiele_conf.txt trunk/test/phaenotype/test2_exp.owl trunk/test/phaenotype/test_exp.owl trunk/test/phaenotype/train.conf trunk/test/phaenotype/vergleich.owl Copied: trunk/test/phaenotype/beispiele_conf.txt (from rev 3856, trunk/test/phaenotype/auswertung.txt) =================================================================== --- trunk/test/phaenotype/beispiele_conf.txt (rev 0) +++ trunk/test/phaenotype/beispiele_conf.txt 2012-11-23 09:57:51 UTC (rev 3877) @@ -0,0 +1,404 @@ +lp.positiveExamples = { +"kb:MGI_1855930", +"kb:MGI_1855933", +"kb:MGI_1855937", +"kb:MGI_1855968", +"kb:MGI_1855969", +"kb:MGI_1855971", +"kb:MGI_1855979", +"kb:MGI_1855985", +"kb:MGI_1855995", +"kb:MGI_1856008", +"kb:MGI_1856009", +"kb:MGI_1856012", +"kb:MGI_1856013", +"kb:MGI_1856016", +"kb:MGI_1856022", +"kb:MGI_1856026", +"kb:MGI_1856027", +"kb:MGI_1856041", +"kb:MGI_1856044", +"kb:MGI_1856047", +"kb:MGI_1856056", +"kb:MGI_1856064", +"kb:MGI_1856066", +"kb:MGI_1856067", +"kb:MGI_1856083", +"kb:MGI_1856085", +"kb:MGI_1856088", +"kb:MGI_1856094", +"kb:MGI_1856096", +"kb:MGI_1856098", +"kb:MGI_1856100", +"kb:MGI_1856106", +"kb:MGI_1856108", +"kb:MGI_1856136", +"kb:MGI_1856144", +"kb:MGI_1856145", +"kb:MGI_1856146", +"kb:MGI_1856147", +"kb:MGI_1856149", +"kb:MGI_1856155", +"kb:MGI_1856158", +"kb:MGI_1856178", +"kb:MGI_1856179", +"kb:MGI_1856180", +"kb:MGI_1856181", +"kb:MGI_1856197", +"kb:MGI_1856202", +"kb:MGI_1856217", +"kb:MGI_1856218", +"kb:MGI_1856220", +"kb:MGI_1856221", +"kb:MGI_1856226", +"kb:MGI_1856227", +"kb:MGI_1856228", +"kb:MGI_1856276", +"kb:MGI_1856298", +"kb:MGI_1856317", +"kb:MGI_1856318", +"kb:MGI_1856319", +"kb:MGI_1856327", +"kb:MGI_1856328", +"kb:MGI_1856330", +"kb:MGI_1856333", +"kb:MGI_1856335", +"kb:MGI_1856362", +"kb:MGI_1856363", +"kb:MGI_1856373", +"kb:MGI_1856377", +"kb:MGI_1856378", +"kb:MGI_1856384", +"kb:MGI_1856392", +"kb:MGI_1856393", +"kb:MGI_1856394", +"kb:MGI_1856395", +"kb:MGI_1856397", +"kb:MGI_1856399", +"kb:MGI_1856410", +"kb:MGI_1856412", +"kb:MGI_1856424", +"kb:MGI_1856464", +"kb:MGI_1856465", +"kb:MGI_1856492", +"kb:MGI_1856502", +"kb:MGI_1856506", +"kb:MGI_1856523", +"kb:MGI_1856544", +"kb:MGI_1856555", +"kb:MGI_1856581", +"kb:MGI_1856585", +"kb:MGI_1856586", +"kb:MGI_1856587", +"kb:MGI_1856588", +"kb:MGI_1856595", +"kb:MGI_1856596", +"kb:MGI_1856605", +"kb:MGI_1856608", +"kb:MGI_1856628", +"kb:MGI_1856631", +"kb:MGI_1856649", +"kb:MGI_1856656", +"kb:MGI_1856662", +"kb:MGI_1856664", +"kb:MGI_1856666", +"kb:MGI_1856667", +"kb:MGI_1856671", +"kb:MGI_1856679", +"kb:MGI_1856681", +"kb:MGI_1856685", +"kb:MGI_1856688", +"kb:MGI_1856691", +"kb:MGI_1856692", +"kb:MGI_1856693", +"kb:MGI_1856694", +"kb:MGI_1856699", +"kb:MGI_1856702", +"kb:MGI_1856703", +"kb:MGI_1856704", +"kb:MGI_1856707", +"kb:MGI_1856709", +"kb:MGI_1856710", +"kb:MGI_1856712", +"kb:MGI_1856716", +"kb:MGI_1856829", +"kb:MGI_1856830", +"kb:MGI_1856831", +"kb:MGI_1856842", +"kb:MGI_1856845", +"kb:MGI_1856851", +"kb:MGI_1856852", +"kb:MGI_1856885", +"kb:MGI_1856897", +"kb:MGI_1856903", +"kb:MGI_1856905", +"kb:MGI_1856913", +"kb:MGI_1856915", +"kb:MGI_1856919", +"kb:MGI_1856920", +"kb:MGI_1856926", +"kb:MGI_1856929", +"kb:MGI_1856931", +"kb:MGI_1856946", +"kb:MGI_1856953", +"kb:MGI_1856959", +"kb:MGI_1856960", +"kb:MGI_1856965", +"kb:MGI_1856973", +"kb:MGI_1856982", +"kb:MGI_1856987", +"kb:MGI_1856989", +"kb:MGI_1856996", +"kb:MGI_1857021", +"kb:MGI_1857025", +"kb:MGI_1857042", +"kb:MGI_1857043", +"kb:MGI_1857051", +"kb:MGI_1857061", +"kb:MGI_1857079", +"kb:MGI_1857090", +"kb:MGI_1857091", +"kb:MGI_1857104", +"kb:MGI_1857105", +"kb:MGI_1857113", +"kb:MGI_1857117", +"kb:MGI_1857124", +"kb:MGI_1857129", +"kb:MGI_1857131", +"kb:MGI_1857132", +"kb:MGI_1857137", +"kb:MGI_1857138", +"kb:MGI_1857139", +"kb:MGI_1857140", +"kb:MGI_1857141", +"kb:MGI_1857151", +"kb:MGI_1857160", +"kb:MGI_1857161", +"kb:MGI_1857162", +"kb:MGI_1857164", +"kb:MGI_1857166", +"kb:MGI_1857169", +"kb:MGI_1857174", +"kb:MGI_1857175", +"kb:MGI_1857179", +"kb:MGI_1857181", +"kb:MGI_1857184", +"kb:MGI_1857194", +"kb:MGI_1857199", +"kb:MGI_1857208", +"kb:MGI_1857212", +"kb:MGI_1857229", +"kb:MGI_1857235", +"kb:MGI_1857236", +"kb:MGI_1857258", +"kb:MGI_1857263", +"kb:MGI_1857265", +"kb:MGI_1857266", +"kb:MGI_1857267", +"kb:MGI_1857272", +"kb:MGI_1857273", +"kb:MGI_1857274", +"kb:MGI_1857276", +"kb:MGI_1857278", +"kb:MGI_1857284", +"kb:MGI_1857289", +"kb:MGI_1857291", +"kb:MGI_1857299", +"kb:MGI_1857300", +"kb:MGI_1857304", +"kb:MGI_1857310", +"kb:MGI_1857312", +"kb:MGI_1857336", +"kb:MGI_1857342", +"kb:MGI_1857344", +"kb:MGI_1857347", +"kb:MGI_1857352", +"kb:MGI_1857386", +"kb:MGI_1857388", +"kb:MGI_1857397", +"kb:MGI_1857401", +"kb:MGI_1857409", +"kb:MGI_1857424", +"kb:MGI_1857431", +"kb:MGI_1857432", +"kb:MGI_1857438", +"kb:MGI_1857439", +"kb:MGI_1857441", +"kb:MGI_1857442", +"kb:MGI_1857444", +"kb:MGI_1857446", +"kb:MGI_1857447", +"kb:MGI_1857467", +"kb:MGI_1857469", +"kb:MGI_1857473", +"kb:MGI_1857497", +"kb:MGI_1857499", +"kb:MGI_1857515", +"kb:MGI_1857519", +"kb:MGI_1857520", +"kb:MGI_1857528", +"kb:MGI_1857539", +"kb:MGI_1857540", +"kb:MGI_1857544", +"kb:MGI_1857545", +"kb:MGI_1857556", +"kb:MGI_1857562", +"kb:MGI_1857572", +"kb:MGI_1857595", +"kb:MGI_1857597", +"kb:MGI_1857598", +"kb:MGI_1857599", +"kb:MGI_1857617", +"kb:MGI_1857629", +"kb:MGI_1857644", +"kb:MGI_1857648", +"kb:MGI_1857673", +"kb:MGI_1857695", +"kb:MGI_1857697", +"kb:MGI_1857702", +"kb:MGI_1857708", +"kb:MGI_1857709", +"kb:MGI_1857718", +"kb:MGI_1857729", +"kb:MGI_1857740", +"kb:MGI_1857751", +"kb:MGI_1857766", +"kb:MGI_1857776", +"kb:MGI_1857793", +"kb:MGI_1857796", +"kb:MGI_1857803", +"kb:MGI_1857811", +"kb:MGI_1857813", +"kb:MGI_1857832", +"kb:MGI_1857844", +"kb:MGI_1857846", +"kb:MGI_1857860", +"kb:MGI_1857868", +"kb:MGI_1857869", +"kb:MGI_1857871", +"kb:MGI_1857873", +"kb:MGI_1857880", +"kb:MGI_1857881", +"kb:MGI_1857883", +"kb:MGI_1857887", +"kb:MGI_1857890", +"kb:MGI_1857891", +"kb:MGI_1857896", +"kb:MGI_1857897", +"kb:MGI_1857898", +"kb:MGI_1857927", +"kb:MGI_1857935", +"kb:MGI_1857936", +"kb:MGI_1857937", +"kb:MGI_1857938", +"kb:MGI_1857950", +"kb:MGI_1857951", +"kb:MGI_1857957", +"kb:MGI_1857966", +"kb:MGI_1857969", +"kb:MGI_1857974", +"kb:MGI_1857981", +"kb:MGI_1857990" +} + +lp.negativeExamples = { +"kb:MGI_1857133", +"kb:MGI_1857143", +"kb:MGI_1857145", +"kb:MGI_1857180", +"kb:MGI_1857192", +"kb:MGI_1857204", +"kb:MGI_1857271", +"kb:MGI_1857468", +"kb:MGI_1857713", +"kb:MGI_1857722", +"kb:MGI_1857765", +"kb:MGI_1857941", +"kb:MGI_1860087", +"kb:MGI_1861699", +"kb:MGI_1861928", +"kb:MGI_1861947", +"kb:MGI_1888773", +"kb:MGI_1888964", +"kb:MGI_1931521", +"kb:MGI_1933757", +"kb:MGI_1934272", +"kb:MGI_1934274", +"kb:MGI_1935123", +"kb:MGI_2138030", +"kb:MGI_2149629", +"kb:MGI_2149838", +"kb:MGI_2155738", +"kb:MGI_2155771", +"kb:MGI_2176524", +"kb:MGI_2176526", +"kb:MGI_2178675", +"kb:MGI_2178778", +"kb:MGI_2179728", +"kb:MGI_2180787", +"kb:MGI_2181877", +"kb:MGI_2182733", +"kb:MGI_2182942", +"kb:MGI_2183547", +"kb:MGI_2386271", +"kb:MGI_2386677", +"kb:MGI_2388392", +"kb:MGI_2429736", +"kb:MGI_2653065", +"kb:MGI_2667262", +"kb:MGI_2668436", +"kb:MGI_2670598", +"kb:MGI_3028639", +"kb:MGI_3033929", +"kb:MGI_3033931", +"kb:MGI_3043815", +"kb:MGI_3050095", +"kb:MGI_3052865", +"kb:MGI_3053604", +"kb:MGI_3055296", +"kb:MGI_3514020", +"kb:MGI_3522476", +"kb:MGI_3525361", +"kb:MGI_3528497", +"kb:MGI_3530465", +"kb:MGI_3577049", +"kb:MGI_3605162", +"kb:MGI_3605480", +"kb:MGI_3612537", +"kb:MGI_3612978", +"kb:MGI_3621812", +"kb:MGI_3623589", +"kb:MGI_3624862", +"kb:MGI_3628756", +"kb:MGI_3664558", +"kb:MGI_3664756", +"kb:MGI_3664792", +"kb:MGI_3664793", +"kb:MGI_3694813", +"kb:MGI_3697454", +"kb:MGI_3697714", +"kb:MGI_3697905", +"kb:MGI_3697906", +"kb:MGI_3712964", +"kb:MGI_3722875", +"kb:MGI_3763820", +"kb:MGI_3771547", +"kb:MGI_3774128", +"kb:MGI_3778822", +"kb:MGI_3784965", +"kb:MGI_3807480", +"kb:MGI_3810287", +"kb:MGI_3812434", +"kb:MGI_3813273", +"kb:MGI_3817496", +"kb:MGI_3840831", +"kb:MGI_3849598", +"kb:MGI_3849599", +"kb:MGI_3851593", +"kb:MGI_4418212", +"kb:MGI_4438451", +"kb:MGI_4457607", +"kb:MGI_4868581", +"kb:MGI_5293442", +"kb:MGI_5309003" +} \ No newline at end of file Modified: trunk/test/phaenotype/mp-equivalence-axioms-subq.owl =================================================================== --- trunk/test/phaenotype/mp-equivalence-axioms-subq.owl 2012-11-19 12:05:59 UTC (rev 3876) +++ trunk/test/phaenotype/mp-equivalence-axioms-subq.owl 2012-11-23 09:57:51 UTC (rev 3877) @@ -9,24 +9,23 @@ <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > <!ENTITY oboInOwl "http://www.geneontology.org/formats/oboInOwl#" > - <!ENTITY mp-logical-definitions-subq "http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#" > + <!ENTITY mp-equivalent-axioms-subq "http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#" > ]> -<rdf:RDF xmlns="&obo;mp/mp-logical-definitions-subq.owl#" - xml:base="&obo;mp/mp-logical-definitions-subq.owl" +<rdf:RDF xmlns="&obo;mp/mp-equivalent-axioms-subq.owl#" + xml:base="&obo;mp/mp-equivalent-axioms-subq.owl" xmlns:obo="http://purl.obolibrary.org/obo/" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" - xmlns:mp-logical-definitions-subq="&obo;mp/mp-logical-definitions-subq#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:_="&obo;_#" - xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#"> - <owl:Ontology rdf:about="&obo;mp/mp-logical-definitions-subq.owl"> + xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#" + xmlns:mp-equivalent-axioms-subq="&obo;mp/mp-equivalent-axioms-subq#"> + <owl:Ontology rdf:about="&obo;mp/mp-equivalent-axioms-subq.owl"> <oboInOwl:date rdf:datatype="&xsd;string">27:07:2007 00:13</oboInOwl:date> <oboInOwl:saved-by rdf:datatype="&xsd;string">George Gkoutos</oboInOwl:saved-by> - <oboInOwl:remark rdf:datatype="&xsd;string">Status: ALPHA TESTING</oboInOwl:remark> <oboInOwl:remark rdf:datatype="&xsd;string">TODO - fix has_central_participant defs</oboInOwl:remark> <oboInOwl:remark rdf:datatype="&xsd;string">TODO - fix inheres_in_part_of defs</oboInOwl:remark> <oboInOwl:remark rdf:datatype="&xsd;string">TODO - physiology</oboInOwl:remark> @@ -73,11 +72,17 @@ <!-- http://purl.obolibrary.org/obo/BFO_0000052 --> <owl:ObjectProperty rdf:about="&obo;BFO_0000052"> - <rdfs:subPropertyOf rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <rdfs:subPropertyOf rdf:resource="&obo;RO_0002314"/> </owl:ObjectProperty> + <!-- http://purl.obolibrary.org/obo/BFO_0000057 --> + + <owl:ObjectProperty rdf:about="&obo;BFO_0000057"/> + + + <!-- http://purl.obolibrary.org/obo/BFO_0000070 --> <owl:ObjectProperty rdf:about="&obo;BFO_0000070"/> @@ -106,113 +111,107 @@ - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#after --> + <!-- http://purl.obolibrary.org/obo/RO_0002314 --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#after"/> + <owl:ObjectProperty rdf:about="&obo;RO_0002314"> + <owl:propertyChainAxiom rdf:parseType="Collection"> + <rdf:Description rdf:about="&obo;BFO_0000052"/> + <rdf:Description rdf:about="&obo;BFO_0000050"/> + </owl:propertyChainAxiom> + </owl:ObjectProperty> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#contained_in --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#after --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#contained_in"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#after"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#during --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#contained_in --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#during"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#contained_in"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#exists_during --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#during --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#exists_during"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#during"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_central_participant --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#exists_during --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#has_central_participant"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#exists_during"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_output --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#has_central_participant --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#has_output"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#has_central_participant"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_participant --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#has_output --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#has_participant"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#has_output"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_quality --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#has_quality --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#has_quality"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#has_quality"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#increases_population_size_of --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#increases_population_size_of --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#increases_population_size_of"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#increases_population_size_of"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#inheres_in_part_of --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#occurs_in --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"> - <owl:propertyChainAxiom rdf:parseType="Collection"> - <rdf:Description rdf:about="&obo;BFO_0000052"/> - <rdf:Description rdf:about="&obo;BFO_0000050"/> - </owl:propertyChainAxiom> - </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#occurs_in"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#occurs_in --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#preceded_by --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#occurs_in"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#preceded_by"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#preceded_by --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#results_from --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#preceded_by"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#results_from"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#results_from --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#results_in_change_to --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#results_from"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#results_in_change_to"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#results_in_change_to --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#results_in_complete_development_of --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#results_in_change_to"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#results_in_complete_development_of"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#results_in_complete_development_of --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#results_in_death_of --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#results_in_complete_development_of"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#results_in_death_of"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#results_in_death_of --> + <!-- http://purl.obolibrary.org/obo/mp/mp-equivalent-axioms-subq#results_in_directed_movement_of --> - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#results_in_death_of"/> + <owl:ObjectProperty rdf:about="&obo;mp/mp-equivalent-axioms-subq#results_in_directed_movement_of"/> - <!-- http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#results_in_directed_movement_of --> - - <owl:ObjectProperty rdf:about="&obo;mp/mp-logical-definitions-subq#results_in_directed_movement_of"/> - - - <!-- http://sourceforge.net/tracker/index.php?func=detail&aid=1825041&group_id=76834&atid=947684 --> <owl:ObjectProperty rdf:about="http://sourceforge.net/tracker/index.php?func=detail&aid=1825041&group_id=76834&atid=947684"/> @@ -230,6 +229,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_12777 --> + + <owl:Class rdf:about="&obo;CHEBI_12777"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_15035 --> <owl:Class rdf:about="&obo;CHEBI_15035"/> @@ -362,6 +367,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_16973 --> + + <owl:Class rdf:about="&obo;CHEBI_16973"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_16978 --> <owl:Class rdf:about="&obo;CHEBI_16978"/> @@ -404,6 +415,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_17544 --> + + <owl:Class rdf:about="&obo;CHEBI_17544"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_17636 --> <owl:Class rdf:about="&obo;CHEBI_17636"/> @@ -446,6 +463,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_18085 --> + + <owl:Class rdf:about="&obo;CHEBI_18085"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_18237 --> <owl:Class rdf:about="&obo;CHEBI_18237"/> @@ -620,6 +643,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_26948 --> + + <owl:Class rdf:about="&obo;CHEBI_26948"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_26995 --> <owl:Class rdf:about="&obo;CHEBI_26995"/> @@ -638,27 +667,39 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_27300 --> + + <owl:Class rdf:about="&obo;CHEBI_27300"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_27363 --> <owl:Class rdf:about="&obo;CHEBI_27363"/> + <!-- http://purl.obolibrary.org/obo/CHEBI_27470 --> + + <owl:Class rdf:about="&obo;CHEBI_27470"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_27568 --> <owl:Class rdf:about="&obo;CHEBI_27568"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_27584 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_27570 --> - <owl:Class rdf:about="&obo;CHEBI_27584"/> + <owl:Class rdf:about="&obo;CHEBI_27570"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_27958 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_27584 --> - <owl:Class rdf:about="&obo;CHEBI_27958"/> + <owl:Class rdf:about="&obo;CHEBI_27584"/> @@ -698,33 +739,33 @@ - <!-- http://purl.obolibrary.org/obo/CHEBI_30052 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_29073 --> - <owl:Class rdf:about="&obo;CHEBI_30052"/> + <owl:Class rdf:about="&obo;CHEBI_29073"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_30660 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_29429 --> - <owl:Class rdf:about="&obo;CHEBI_30660"/> + <owl:Class rdf:about="&obo;CHEBI_29429"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_30879 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_30052 --> - <owl:Class rdf:about="&obo;CHEBI_30879"/> + <owl:Class rdf:about="&obo;CHEBI_30052"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_3165 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_30660 --> - <owl:Class rdf:about="&obo;CHEBI_3165"/> + <owl:Class rdf:about="&obo;CHEBI_30660"/> - <!-- http://purl.obolibrary.org/obo/CHEBI_32111 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_3165 --> - <owl:Class rdf:about="&obo;CHEBI_32111"/> + <owl:Class rdf:about="&obo;CHEBI_3165"/> @@ -734,12 +775,18 @@ - <!-- http://purl.obolibrary.org/obo/CHEBI_33290 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_33234 --> - <owl:Class rdf:about="&obo;CHEBI_33290"/> + <owl:Class rdf:about="&obo;CHEBI_33234"/> + <!-- http://purl.obolibrary.org/obo/CHEBI_33567 --> + + <owl:Class rdf:about="&obo;CHEBI_33567"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_33568 --> <owl:Class rdf:about="&obo;CHEBI_33568"/> @@ -758,6 +805,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_33838 --> + + <owl:Class rdf:about="&obo;CHEBI_33838"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_35143 --> <owl:Class rdf:about="&obo;CHEBI_35143"/> @@ -788,6 +841,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_36976 --> + + <owl:Class rdf:about="&obo;CHEBI_36976"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_37527 --> <owl:Class rdf:about="&obo;CHEBI_37527"/> @@ -812,6 +871,12 @@ + <!-- http://purl.obolibrary.org/obo/CHEBI_46819 --> + + <owl:Class rdf:about="&obo;CHEBI_46819"/> + + + <!-- http://purl.obolibrary.org/obo/CHEBI_47773 --> <owl:Class rdf:about="&obo;CHEBI_47773"/> @@ -848,9 +913,9 @@ - <!-- http://purl.obolibrary.org/obo/CHEBI_52999 --> + <!-- http://purl.obolibrary.org/obo/CHEBI_50211 --> - <owl:Class rdf:about="&obo;CHEBI_52999"/> + <owl:Class rdf:about="&obo;CHEBI_50211"/> @@ -1526,6 +1591,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0000525 --> + + <owl:Class rdf:about="&obo;CL_0000525"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0000540 --> <owl:Class rdf:about="&obo;CL_0000540"/> @@ -1766,6 +1837,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0000648 --> + + <owl:Class rdf:about="&obo;CL_0000648"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0000649 --> <owl:Class rdf:about="&obo;CL_0000649"/> @@ -2348,6 +2425,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002173 --> + + <owl:Class rdf:about="&obo;CL_0002173"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002303 --> <owl:Class rdf:about="&obo;CL_0002303"/> @@ -2360,12 +2443,36 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002353 --> + + <owl:Class rdf:about="&obo;CL_0002353"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002354 --> + + <owl:Class rdf:about="&obo;CL_0002354"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002355 --> <owl:Class rdf:about="&obo;CL_0002355"/> + <!-- http://purl.obolibrary.org/obo/CL_0002357 --> + + <owl:Class rdf:about="&obo;CL_0002357"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002370 --> + + <owl:Class rdf:about="&obo;CL_0002370"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002372 --> <owl:Class rdf:about="&obo;CL_0002372"/> @@ -2402,6 +2509,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002486 --> + + <owl:Class rdf:about="&obo;CL_0002486"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002487 --> <owl:Class rdf:about="&obo;CL_0002487"/> @@ -2414,6 +2527,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002489 --> + + <owl:Class rdf:about="&obo;CL_0002489"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002490 --> <owl:Class rdf:about="&obo;CL_0002490"/> @@ -2450,6 +2569,12 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002608 --> + + <owl:Class rdf:about="&obo;CL_0002608"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0002633 --> <owl:Class rdf:about="&obo;CL_0002633"/> @@ -2462,6 +2587,36 @@ + <!-- http://purl.obolibrary.org/obo/CL_0002666 --> + + <owl:Class rdf:about="&obo;CL_0002666"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002668 --> + + <owl:Class rdf:about="&obo;CL_0002668"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002669 --> + + <owl:Class rdf:about="&obo;CL_0002669"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002670 --> + + <owl:Class rdf:about="&obo;CL_0002670"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_0002672 --> + + <owl:Class rdf:about="&obo;CL_0002672"/> + + + <!-- http://purl.obolibrary.org/obo/CL_0005019 --> <owl:Class rdf:about="&obo;CL_0005019"/> @@ -2486,6 +2641,150 @@ + <!-- http://purl.obolibrary.org/obo/CL_1001436 --> + + <owl:Class rdf:about="&obo;CL_1001436"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001437 --> + + <owl:Class rdf:about="&obo;CL_1001437"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001451 --> + + <owl:Class rdf:about="&obo;CL_1001451"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001474 --> + + <owl:Class rdf:about="&obo;CL_1001474"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001501 --> + + <owl:Class rdf:about="&obo;CL_1001501"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001502 --> + + <owl:Class rdf:about="&obo;CL_1001502"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001503 --> + + <owl:Class rdf:about="&obo;CL_1001503"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001505 --> + + <owl:Class rdf:about="&obo;CL_1001505"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001509 --> + + <owl:Class rdf:about="&obo;CL_1001509"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001516 --> + + <owl:Class rdf:about="&obo;CL_1001516"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001517 --> + + <owl:Class rdf:about="&obo;CL_1001517"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001561 --> + + <owl:Class rdf:about="&obo;CL_1001561"/> + + + + <!-- http://purl.obolibrary.org/obo/CL_1001566 --> + + <owl:Class rdf:about="&obo;CL_1001566"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_1040 --> + + <owl:Class rdf:about="&obo;DOID_1040"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_3277 --> + + <owl:Class rdf:about="&obo;DOID_3277"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_3892 --> + + <owl:Class rdf:about="&obo;DOID_3892"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_3963 --> + + <owl:Class rdf:about="&obo;DOID_3963"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_4015 --> + + <owl:Class rdf:about="&obo;DOID_4015"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_5394 --> + + <owl:Class rdf:about="&obo;DOID_5394"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_5742 --> + + <owl:Class rdf:about="&obo;DOID_5742"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_684 --> + + <owl:Class rdf:about="&obo;DOID_684"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_718 --> + + <owl:Class rdf:about="&obo;DOID_718"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_8857 --> + + <owl:Class rdf:about="&obo;DOID_8857"/> + + + + <!-- http://purl.obolibrary.org/obo/DOID_8923 --> + + <owl:Class rdf:about="&obo;DOID_8923"/> + + + <!-- http://purl.obolibrary.org/obo/FMA_52901 --> <owl:Class rdf:about="&obo;FMA_52901"/> @@ -2522,6 +2821,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0000262 --> + + <owl:Class rdf:about="&obo;GO_0000262"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0000266 --> <owl:Class rdf:about="&obo;GO_0000266"/> @@ -2666,6 +2971,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0001763 --> + + <owl:Class rdf:about="&obo;GO_0001763"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0001764 --> <owl:Class rdf:about="&obo;GO_0001764"/> @@ -2984,6 +3295,24 @@ + <!-- http://purl.obolibrary.org/obo/GO_0003091 --> + + <owl:Class rdf:about="&obo;GO_0003091"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0003096 --> + + <owl:Class rdf:about="&obo;GO_0003096"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0003097 --> + + <owl:Class rdf:about="&obo;GO_0003097"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0003309 --> <owl:Class rdf:about="&obo;GO_0003309"/> @@ -2996,6 +3325,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0003311 --> + + <owl:Class rdf:about="&obo;GO_0003311"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0003312 --> <owl:Class rdf:about="&obo;GO_0003312"/> @@ -3020,6 +3355,18 @@ + <!-- http://purl.obolibrary.org/obo/GO_0004035 --> + + <owl:Class rdf:about="&obo;GO_0004035"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004096 --> + + <owl:Class rdf:about="&obo;GO_0004096"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0004195 --> <owl:Class rdf:about="&obo;GO_0004195"/> @@ -3032,6 +3379,66 @@ + <!-- http://purl.obolibrary.org/obo/GO_0004340 --> + + <owl:Class rdf:about="&obo;GO_0004340"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004352 --> + + <owl:Class rdf:about="&obo;GO_0004352"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004365 --> + + <owl:Class rdf:about="&obo;GO_0004365"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004465 --> + + <owl:Class rdf:about="&obo;GO_0004465"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004585 --> + + <owl:Class rdf:about="&obo;GO_0004585"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004602 --> + + <owl:Class rdf:about="&obo;GO_0004602"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004607 --> + + <owl:Class rdf:about="&obo;GO_0004607"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004731 --> + + <owl:Class rdf:about="&obo;GO_0004731"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0004806 --> + + <owl:Class rdf:about="&obo;GO_0004806"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0005143 --> + + <owl:Class rdf:about="&obo;GO_0005143"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0005577 --> <owl:Class rdf:about="&obo;GO_0005577"/> @@ -3104,6 +3511,18 @@ + <!-- http://purl.obolibrary.org/obo/GO_0005743 --> + + <owl:Class rdf:about="&obo;GO_0005743"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0005759 --> + + <owl:Class rdf:about="&obo;GO_0005759"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0005764 --> <owl:Class rdf:about="&obo;GO_0005764"/> @@ -3266,6 +3685,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0006776 --> + + <owl:Class rdf:about="&obo;GO_0006776"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0006874 --> <owl:Class rdf:about="&obo;GO_0006874"/> @@ -3284,6 +3709,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0006882 --> + + <owl:Class rdf:about="&obo;GO_0006882"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0006885 --> <owl:Class rdf:about="&obo;GO_0006885"/> @@ -3812,6 +4243,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0010761 --> + + <owl:Class rdf:about="&obo;GO_0010761"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0010934 --> <owl:Class rdf:about="&obo;GO_0010934"/> @@ -3890,6 +4327,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0016322 --> + + <owl:Class rdf:about="&obo;GO_0016322"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0016446 --> <owl:Class rdf:about="&obo;GO_0016446"/> @@ -4070,6 +4513,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0030061 --> + + <owl:Class rdf:about="&obo;GO_0030061"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0030073 --> <owl:Class rdf:about="&obo;GO_0030073"/> @@ -4478,6 +4927,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0033878 --> + + <owl:Class rdf:about="&obo;GO_0033878"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0034102 --> <owl:Class rdf:about="&obo;GO_0034102"/> @@ -4508,12 +4963,6 @@ - <!-- http://purl.obolibrary.org/obo/GO_0035095 --> - - <owl:Class rdf:about="&obo;GO_0035095"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0035162 --> <owl:Class rdf:about="&obo;GO_0035162"/> @@ -4538,18 +4987,48 @@ + <!-- http://purl.obolibrary.org/obo/GO_0035502 --> + + <owl:Class rdf:about="&obo;GO_0035502"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0035503 --> + + <owl:Class rdf:about="&obo;GO_0035503"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0035546 --> <owl:Class rdf:about="&obo;GO_0035546"/> + <!-- http://purl.obolibrary.org/obo/GO_0035623 --> + + <owl:Class rdf:about="&obo;GO_0035623"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0035630 --> + + <owl:Class rdf:about="&obo;GO_0035630"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0036045 --> <owl:Class rdf:about="&obo;GO_0036045"/> + <!-- http://purl.obolibrary.org/obo/GO_0036053 --> + + <owl:Class rdf:about="&obo;GO_0036053"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0040007 --> <owl:Class rdf:about="&obo;GO_0040007"/> @@ -4682,12 +5161,6 @@ - <!-- http://purl.obolibrary.org/obo/GO_0042600 --> - - <owl:Class rdf:about="&obo;GO_0042600"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0042603 --> <owl:Class rdf:about="&obo;GO_0042603"/> @@ -4718,6 +5191,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0042638 --> + + <owl:Class rdf:about="&obo;GO_0042638"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0042639 --> <owl:Class rdf:about="&obo;GO_0042639"/> @@ -4766,12 +5245,6 @@ - <!-- http://purl.obolibrary.org/obo/GO_0042747 --> - - <owl:Class rdf:about="&obo;GO_0042747"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0042775 --> <owl:Class rdf:about="&obo;GO_0042775"/> @@ -4904,6 +5377,18 @@ + <!-- http://purl.obolibrary.org/obo/GO_0043931 --> + + <owl:Class rdf:about="&obo;GO_0043931"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0043932 --> + + <owl:Class rdf:about="&obo;GO_0043932"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0044224 --> <owl:Class rdf:about="&obo;GO_0044224"/> @@ -4976,9 +5461,9 @@ - <!-- http://purl.obolibrary.org/obo/GO_0045471 --> + <!-- http://purl.obolibrary.org/obo/GO_0045519 --> - <owl:Class rdf:about="&obo;GO_0045471"/> + <owl:Class rdf:about="&obo;GO_0045519"/> @@ -5012,15 +5497,33 @@ + <!-- http://purl.obolibrary.org/obo/GO_0046958 --> + + <owl:Class rdf:about="&obo;GO_0046958"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0046959 --> + + <owl:Class rdf:about="&obo;GO_0046959"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0046960 --> + + <owl:Class rdf:about="&obo;GO_0046960"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0048003 --> <owl:Class rdf:about="&obo;GO_0048003"/> - <!-- http://purl.obolibrary.org/obo/GO_0048148 --> + <!-- http://purl.obolibrary.org/obo/GO_0048144 --> - <owl:Class rdf:about="&obo;GO_0048148"/> + <owl:Class rdf:about="&obo;GO_0048144"/> @@ -5060,12 +5563,6 @@ - <!-- http://purl.obolibrary.org/obo/GO_0048265 --> - - <owl:Class rdf:about="&obo;GO_0048265"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0048286 --> <owl:Class rdf:about="&obo;GO_0048286"/> @@ -5282,48 +5779,18 @@ - <!-- http://purl.obolibrary.org/obo/GO_0050907 --> - - <owl:Class rdf:about="&obo;GO_0050907"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0050909 --> <owl:Class rdf:about="&obo;GO_0050909"/> - <!-- http://purl.obolibrary.org/obo/GO_0050951 --> - - <owl:Class rdf:about="&obo;GO_0050951"/> - - - - <!-- http://purl.obolibrary.org/obo/GO_0050954 --> - - <owl:Class rdf:about="&obo;GO_0050954"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0050955 --> <owl:Class rdf:about="&obo;GO_0050955"/> - <!-- http://purl.obolibrary.org/obo/GO_0050975 --> - - <owl:Class rdf:about="&obo;GO_0050975"/> - - - - <!-- http://purl.obolibrary.org/obo/GO_0050976 --> - - <owl:Class rdf:about="&obo;GO_0050976"/> - - - <!-- http://purl.obolibrary.org/obo/GO_0051216 --> <owl:Class rdf:about="&obo;GO_0051216"/> @@ -5420,6 +5887,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0060041 --> + + <owl:Class rdf:about="&obo;GO_0060041"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0060047 --> <owl:Class rdf:about="&obo;GO_0060047"/> @@ -5516,12 +5989,30 @@ + <!-- http://purl.obolibrary.org/obo/GO_0060291 --> + + <owl:Class rdf:about="&obo;GO_0060291"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0060292 --> + + <owl:Class rdf:about="&obo;GO_0060292"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0060317 --> <owl:Class rdf:about="&obo;GO_0060317"/> + <!-- http://purl.obolibrary.org/obo/GO_0060326 --> + + <owl:Class rdf:about="&obo;GO_0060326"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0060374 --> <owl:Class rdf:about="&obo;GO_0060374"/> @@ -5534,12 +6025,36 @@ + <!-- http://purl.obolibrary.org/obo/GO_0060425 --> + + <owl:Class rdf:about="&obo;GO_0060425"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0060434 --> + + <owl:Class rdf:about="&obo;GO_0060434"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0060439 --> + + <owl:Class rdf:about="&obo;GO_0060439"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0060442 --> <owl:Class rdf:about="&obo;GO_0060442"/> + <!-- http://purl.obolibrary.org/obo/GO_0060463 --> + + <owl:Class rdf:about="&obo;GO_0060463"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0060484 --> <owl:Class rdf:about="&obo;GO_0060484"/> @@ -5714,6 +6229,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0072105 --> + + <owl:Class rdf:about="&obo;GO_0072105"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0072134 --> <owl:Class rdf:about="&obo;GO_0072134"/> @@ -5726,6 +6247,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0072574 --> + + <owl:Class rdf:about="&obo;GO_0072574"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0072601 --> <owl:Class rdf:about="&obo;GO_0072601"/> @@ -5756,6 +6283,12 @@ + <!-- http://purl.obolibrary.org/obo/GO_0072606 --> + + <owl:Class rdf:about="&obo;GO_0072606"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0072607 --> <owl:Class rdf:about="&obo;GO_0072607"/> @@ -5858,12 +6391,72 @@ + <!-- http://purl.obolibrary.org/obo/GO_0097017 --> + + <owl:Class rdf:about="&obo;GO_0097017"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097018 --> + + <owl:Class rdf:about="&obo;GO_0097018"/> + + + <!-- http://purl.obolibrary.org/obo/GO_0097028 --> <owl:Class rdf:about="&obo;GO_0097028"/> + <!-- http://purl.obolibrary.org/obo/GO_0097208 --> + + <owl:Class rdf:about="&obo;GO_0097208"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097224 --> + + <owl:Class rdf:about="&obo;GO_0097224"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097225 --> + + <owl:Class rdf:about="&obo;GO_0097225"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097226 --> + + <owl:Class rdf:about="&obo;GO_0097226"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097227 --> + + <owl:Class rdf:about="&obo;GO_0097227"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097228 --> + + <owl:Class rdf:about="&obo;GO_0097228"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097229 --> + + <owl:Class rdf:about="&obo;GO_0097229"/> + + + + <!-- http://purl.obolibrary.org/obo/GO_0097252 --> + + <owl:Class rdf:about="&obo;GO_0097252"/> + + + <!-- http://purl.obolibrary.org/obo/IMR_0000006 --> <owl:Class rdf:about="&obo;IMR_0000006"/> @@ -7346,6 +7939,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0000298 --> + + <owl:Class rdf:about="&obo;MA_0000298"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0000302 --> <owl:Class rdf:about="&obo;MA_0000302"/> @@ -7664,6 +8263,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0000370 --> + + <owl:Class rdf:about="&obo;MA_0000370"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0000371 --> <owl:Class rdf:about="&obo;MA_0000371"/> @@ -8180,12 +8785,6 @@ - <!-- http://purl.obolibrary.org/obo/MA_0000728 --> - - <owl:Class rdf:about="&obo;MA_0000728"/> - - - <!-- http://purl.obolibrary.org/obo/MA_0000731 --> <owl:Class rdf:about="&obo;MA_0000731"/> @@ -10388,12 +10987,24 @@ + <!-- http://purl.obolibrary.org/obo/MA_0001646 --> + + <owl:Class rdf:about="&obo;MA_0001646"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0001652 --> <owl:Class rdf:about="&obo;MA_0001652"/> + <!-- http://purl.obolibrary.org/obo/MA_0001653 --> + + <owl:Class rdf:about="&obo;MA_0001653"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0001654 --> <owl:Class rdf:about="&obo;MA_0001654"/> @@ -10406,6 +11017,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0001658 --> + + <owl:Class rdf:about="&obo;MA_0001658"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0001660 --> <owl:Class rdf:about="&obo;MA_0001660"/> @@ -10430,6 +11047,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0001678 --> + + <owl:Class rdf:about="&obo;MA_0001678"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0001681 --> <owl:Class rdf:about="&obo;MA_0001681"/> @@ -10442,6 +11065,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0001687 --> + + <owl:Class rdf:about="&obo;MA_0001687"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0001692 --> <owl:Class rdf:about="&obo;MA_0001692"/> @@ -10832,12 +11461,6 @@ - <!-- http://purl.obolibrary.org/obo/MA_0002010 --> - - <owl:Class rdf:about="&obo;MA_0002010"/> - - - <!-- http://purl.obolibrary.org/obo/MA_0002031 --> <owl:Class rdf:about="&obo;MA_0002031"/> @@ -10850,6 +11473,24 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002035 --> + + <owl:Class rdf:about="&obo;MA_0002035"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002036 --> + + <owl:Class rdf:about="&obo;MA_0002036"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002037 --> + + <owl:Class rdf:about="&obo;MA_0002037"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002044 --> <owl:Class rdf:about="&obo;MA_0002044"/> @@ -10880,6 +11521,18 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002077 --> + + <owl:Class rdf:about="&obo;MA_0002077"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002085 --> + + <owl:Class rdf:about="&obo;MA_0002085"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002111 --> <owl:Class rdf:about="&obo;MA_0002111"/> @@ -10898,6 +11551,24 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002210 --> + + <owl:Class rdf:about="&obo;MA_0002210"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002211 --> + + <owl:Class rdf:about="&obo;MA_0002211"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002212 --> + + <owl:Class rdf:about="&obo;MA_0002212"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002249 --> <owl:Class rdf:about="&obo;MA_0002249"/> @@ -11516,12 +12187,138 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002577 --> + + <owl:Class rdf:about="&obo;MA_0002577"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002578 --> + + <owl:Class rdf:about="&obo;MA_0002578"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002582 --> + + <owl:Class rdf:about="&obo;MA_0002582"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002583 --> + + <owl:Class rdf:about="&obo;MA_0002583"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002584 --> + + <owl:Class rdf:about="&obo;MA_0002584"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002586 --> + + <owl:Class rdf:about="&obo;MA_0002586"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002587 --> + + <owl:Class rdf:about="&obo;MA_0002587"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002588 --> + + <owl:Class rdf:about="&obo;MA_0002588"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002591 --> + + <owl:Class rdf:about="&obo;MA_0002591"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002592 --> + + <owl:Class rdf:about="&obo;MA_0002592"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002593 --> + + <owl:Class rdf:about="&obo;MA_0002593"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002594 --> + + <owl:Class rdf:about="&obo;MA_0002594"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002596 --> + + <owl:Class rdf:about="&obo;MA_0002596"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002597 --> + + <owl:Class rdf:about="&obo;MA_0002597"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002602 --> + + <owl:Class rdf:about="&obo;MA_0002602"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002603 --> + + <owl:Class rdf:about="&obo;MA_0002603"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002606 --> + + <owl:Class rdf:about="&obo;MA_0002606"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002616 --> <owl:Class rdf:about="&obo;MA_0002616"/> + <!-- http://purl.obolibrary.org/obo/MA_0002618 --> + + <owl:Class rdf:about="&obo;MA_0002618"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002631 --> + + <owl:Class rdf:about="&obo;MA_0002631"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002632 --> + + <owl:Class rdf:about="&obo;MA_0002632"/> + + + + <!-- http://purl.obolibrary.org/obo/MA_0002655 --> + + <owl:Class rdf:about="&obo;MA_0002655"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002656 --> <owl:Class rdf:about="&obo;MA_0002656"/> @@ -11654,6 +12451,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002713 --> + + <owl:Class rdf:about="&obo;MA_0002713"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002714 --> <owl:Class rdf:about="&obo;MA_0002714"/> @@ -11984,6 +12787,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002810 --> + + <owl:Class rdf:about="&obo;MA_0002810"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002813 --> <owl:Class rdf:about="&obo;MA_0002813"/> @@ -12248,6 +13057,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002888 --> + + <owl:Class rdf:about="&obo;MA_0002888"/> + + + <!-- http://purl.obolibrary.org/obo/MA_0002897 --> <owl:Class rdf:about="&obo;MA_0002897"/> @@ -12464,6 +13279,12 @@ + <!-- http://purl.obolibrary.org/obo/MA_0002996 --> + + <owl:Class rdf:about="&obo;MA_0002996"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_119 --> <owl:Class rdf:about="&obo;MPATH_119"/> @@ -12506,6 +13327,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_160 --> + + <owl:Class rdf:about="&obo;MPATH_160"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_164 --> <owl:Class rdf:about="&obo;MPATH_164"/> @@ -12614,6 +13441,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_249 --> + + <owl:Class rdf:about="&obo;MPATH_249"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_25 --> <owl:Class rdf:about="&obo;MPATH_25"/> @@ -12626,6 +13459,18 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_251 --> + + <owl:Class rdf:about="&obo;MPATH_251"/> + + + + <!-- http://purl.obolibrary.org/obo/MPATH_252 --> + + <owl:Class rdf:about="&obo;MPATH_252"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_266 --> <owl:Class rdf:about="&obo;MPATH_266"/> @@ -12662,12 +13507,24 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_308 --> + + <owl:Class rdf:about="&obo;MPATH_308"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_31 --> <owl:Class rdf:about="&obo;MPATH_31"/> + <!-- http://purl.obolibrary.org/obo/MPATH_321 --> + + <owl:Class rdf:about="&obo;MPATH_321"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_322 --> <owl:Class rdf:about="&obo;MPATH_322"/> @@ -12698,6 +13555,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_354 --> + + <owl:Class rdf:about="&obo;MPATH_354"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_356 --> <owl:Class rdf:about="&obo;MPATH_356"/> @@ -12722,6 +13585,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_365 --> + + <owl:Class rdf:about="&obo;MPATH_365"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_375 --> <owl:Class rdf:about="&obo;MPATH_375"/> @@ -12746,6 +13615,18 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_387 --> + + <owl:Class rdf:about="&obo;MPATH_387"/> + + + + <!-- http://purl.obolibrary.org/obo/MPATH_396 --> + + <owl:Class rdf:about="&obo;MPATH_396"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_397 --> <owl:Class rdf:about="&obo;MPATH_397"/> @@ -12758,6 +13639,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_407 --> + + <owl:Class rdf:about="&obo;MPATH_407"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_408 --> <owl:Class rdf:about="&obo;MPATH_408"/> @@ -12794,12 +13681,24 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_435 --> + + <owl:Class rdf:about="&obo;MPATH_435"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_437 --> <owl:Class rdf:about="&obo;MPATH_437"/> + <!-- http://purl.obolibrary.org/obo/MPATH_438 --> + + <owl:Class rdf:about="&obo;MPATH_438"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_445 --> <owl:Class rdf:about="&obo;MPATH_445"/> @@ -12818,6 +13717,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_506 --> + + <owl:Class rdf:about="&obo;MPATH_506"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_516 --> <owl:Class rdf:about="&obo;MPATH_516"/> @@ -12848,6 +13753,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_564 --> + + <owl:Class rdf:about="&obo;MPATH_564"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_571 --> <owl:Class rdf:about="&obo;MPATH_571"/> @@ -12914,6 +13825,12 @@ + <!-- http://purl.obolibrary.org/obo/MPATH_723 --> + + <owl:Class rdf:about="&obo;MPATH_723"/> + + + <!-- http://purl.obolibrary.org/obo/MPATH_74 --> <owl:Class rdf:about="&obo;MPATH_74"/> @@ -13994,7 +14911,7 @@ <owl:someValuesFrom rdf:resource="&obo;PATO_0000460"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;GO_0001503"/> </owl:Restriction> </owl:intersectionOf> @@ -14434,7 +15351,7 @@ <rdf:Description rdf:about="&obo;PATO_0002166"/> <owl:Restriction> <owl:onProperty rdf:resource="&obo;BFO_0000052"/> - <owl:someValuesFrom rdf:resource="&obo;UBERON_0000969"/> + <owl:someValuesFrom rdf:resource="&obo;MA_0001475"/> </owl:Restriction> </owl:intersectionOf> </owl:Class> @@ -14487,7 +15404,7 @@ <owl:someValuesFrom rdf:resource="&obo;GO_0035265"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#has_central_participant"/> + <owl:onProperty rdf:resource="&obo;mp/mp-equivalent-axioms-subq#has_central_participant"/> <owl:someValuesFrom rdf:resource="&obo;MA_0000316"/> </owl:Restriction> </owl:intersectionOf> @@ -14893,13 +15810,9 @@ <owl:someValuesFrom> <owl:Class> <owl:intersectionOf rdf:parseType="Collection"> - <rdf:Description rdf:about="&obo;PATO_0001570"/> + <rdf:Description rdf:about="&obo;PATO_0000911"/> <owl:Restriction> <owl:onProperty rdf:resource="&obo;BFO_0000052"/> - <owl:someValuesFrom rdf:resource="&obo;MA_0001463"/> - </owl:Restriction> - <owl:Restriction> - <owl:onProperty rdf:resource="&obo;BFO_0000070"/> <owl:someValuesFrom rdf:resource="&obo;_#_basisphenoid_bone_ossification"/> </owl:Restriction> </owl:intersectionOf> @@ -15854,7 +16767,7 @@ <owl:someValuesFrom rdf:resource="&obo;PATO_0001869"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;MA_0002416"/> </owl:Restriction> </owl:intersectionOf> @@ -16930,7 +17843,7 @@ <owl:someValuesFrom rdf:resource="&obo;PATO_0000460"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;MA_0000060"/> </owl:Restriction> </owl:intersectionOf> @@ -16961,7 +17874,7 @@ <owl:someValuesFrom rdf:resource="&obo;PATO_0001863"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;MA_0002719"/> </owl:Restriction> </owl:intersectionOf> @@ -17109,9 +18022,9 @@ <owl:someValuesFrom> <owl:Class> <owl:intersectionOf rdf:parseType="Collection"> - <rdf:Description rdf:about="&obo;PATO_0001558"/> + <rdf:Description rdf:about="&obo;PATO_0000911"/> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;BFO_0000070"/> + <owl:onProperty rdf:resource="&obo;BFO_0000052"/> <owl:someValuesFrom rdf:resource="&obo;GO_0009566"/> </owl:Restriction> </owl:intersectionOf> @@ -17123,29 +18036,6 @@ - <!-- http://purl.obolibrary.org/obo/MP_0000243 --> - - <owl:Class rdf:about="&obo;MP_0000243"> - <owl:equivalentClass> - <owl:Restriction> - <owl:onProperty rdf:resource="&obo;BFO_0000051"/> - <owl:someValuesFrom> - <owl:Class> - <owl:intersectionOf rdf:parseType="Collection"> - <rdf:Description rdf:about="&obo;PATO_0001561"/> - <owl:Restriction> - <owl:onProperty rdf:resource="&obo;BFO_0000070"/> - <owl:someValuesFrom rdf:resource="&obo;NBO_0000671"/> - </owl:Restriction> - </owl:intersectionOf> - </owl:Class> - </owl:someValuesFrom> - </owl:Restriction> - </owl:equivalentClass> - </owl:Class> - - - <!-- http://purl.obolibrary.org/obo/MP_0000245 --> <owl:Class rdf:about="&obo;MP_0000245"> @@ -17569,7 +18459,7 @@ <owl:someValuesFrom rdf:resource="&obo;PATO_0000460"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;UBERON_0004141"/> </owl:Restriction> </owl:intersectionOf> @@ -17696,7 +18586,7 @@ <owl:someValuesFrom rdf:resource="&obo;MA_0002791"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> <owl:someValuesFrom rdf:resource="&obo;MA_0000093"/> </owl:Restriction> </owl:intersectionOf> @@ -18815,7 +19705,7 @@ <owl:someValuesFrom rdf:resource="&obo;IMR_0000304"/> </owl:Restriction> <owl:Restriction> - <owl:onProperty rdf:resource="&obo;mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:onProperty rdf:resource="&obo;RO_0002314"/> ... [truncated message content] |
From: <ki...@us...> - 2012-11-19 12:06:06
|
Revision: 3876 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3876&view=rev Author: kirdie Date: 2012-11-19 12:05:59 +0000 (Mon, 19 Nov 2012) Log Message: ----------- SPARQL indices now ignore case. SPARQLClassesIndex now counts all instances as a class that are instances of owl:Class or have at least one instance (some classes are not modelled as owl:Class). Added a test class for the SPARQLClassesIndex. SPARQLTemplatedBasedLearner2 now uses the SPARQLClassesIndex for Classes instead of the normal SPARQL index. The benchmark results should now be better because this applies to many of the 'near' or 'close to' questions. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLClassesIndex.java branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Added Paths: ----------- branches/hmm/components-ext/src/test/java/org/dllearner/common/ branches/hmm/components-ext/src/test/java/org/dllearner/common/index/ branches/hmm/components-ext/src/test/java/org/dllearner/common/index/SPARQLClassesIndexTest.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-19 11:15:47 UTC (rev 3875) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-19 12:05:59 UTC (rev 3876) @@ -6,14 +6,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; @@ -55,6 +53,7 @@ import org.dllearner.common.index.IndexResultItem; import org.dllearner.common.index.IndexResultSet; import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.common.index.SPARQLClassesIndex; import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; import org.dllearner.common.index.SPARQLIndex; import org.dllearner.common.index.SPARQLObjectPropertiesIndex; @@ -65,10 +64,6 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.Thing; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; @@ -76,7 +71,6 @@ import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.reasoning.SPARQLReasoner; import org.ini4j.Options; -import org.openjena.atlas.logging.Log; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider; import com.hp.hpl.jena.ontology.OntModelSpec; @@ -255,7 +249,7 @@ public SPARQLTemplateBasedLearner2(Model model, MappingBasedIndex mappingBasedIndex, PartOfSpeechTagger posTagger) { - this(model, new SPARQLIndex(model),new SPARQLIndex(model),new SPARQLIndex(model),posTagger); + this(model, new SPARQLIndex(model),new SPARQLClassesIndex(model),new SPARQLIndex(model),posTagger); setMappingIndex(mappingBasedIndex); } @@ -674,7 +668,9 @@ // get candidates for slot if(!slot2Allocations.containsKey(slot)) { - slot2Allocations.put(slot,new SlotProcessor(slot).computeAllocations(slot)); + SortedSet<Allocation> allocations = new SlotProcessor(slot).computeAllocations(slot); + logger.info("allocations for slot "+slot+": "+allocations); + slot2Allocations.put(slot,allocations); } } } @@ -717,6 +713,7 @@ { try { SortedSet<Allocation> result = future.get(); + logger.debug("allocations: "+result); slot2Allocations.put(futureToSlot.get(future), result); } catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();throw new RuntimeException(e);} } Modified: branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLClassesIndex.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLClassesIndex.java 2012-11-19 11:15:47 UTC (rev 3875) +++ branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLClassesIndex.java 2012-11-19 12:05:59 UTC (rev 3876) @@ -2,8 +2,8 @@ import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; - import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.vocabulary.OWL; public class SPARQLClassesIndex extends SPARQLIndex{ @@ -26,13 +26,13 @@ super.queryTemplate = "SELECT DISTINCT ?uri WHERE {\n" + "?s a ?uri.\n" + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + - "FILTER(REGEX(STR(?label), '%s'))}\n" + + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; - super.queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + - "?s a ?uri.\n" + + super.queryWithLabelTemplate = "SELECT DISTINCT ?uri ?label WHERE {\n" + + "{?uri a <"+ OWL.Class.getURI() + ">.} UNION {?s a ?uri.}\n"+ "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + - "FILTER(REGEX(STR(?label), '%s'))}\n" + + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; } } Modified: branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-11-19 11:15:47 UTC (rev 3875) +++ branches/hmm/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-11-19 12:05:59 UTC (rev 3876) @@ -30,13 +30,13 @@ protected String queryTemplate = "SELECT DISTINCT ?uri WHERE {\n" + "?uri a ?type.\n" + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + - "FILTER(REGEX(STR(?label), '%s'))}\n" + + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; protected String queryWithLabelTemplate = "SELECT DISTINCT * WHERE {\n" + "?uri a ?type.\n" + "?uri <http://www.w3.org/2000/01/rdf-schema#label> ?label\n" + - "FILTER(REGEX(STR(?label), '%s'))}\n" + + "FILTER(REGEX(STR(?label), '%s', 'i'))}\n" + "LIMIT %d OFFSET %d"; @@ -108,8 +108,7 @@ public IndexResultSet getResourcesWithScores(String searchTerm, int limit, int offset) { IndexResultSet irs = new IndexResultSet(); - String query = String.format(queryWithLabelTemplate, searchTerm, limit, offset); - + String query = String.format(queryWithLabelTemplate, searchTerm, limit, offset); ResultSet rs = executeSelect(query); QuerySolution qs; Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-19 11:15:47 UTC (rev 3875) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-19 12:05:59 UTC (rev 3876) @@ -132,8 +132,8 @@ protected static final int QUESTION_OFFSET = 0; protected static final int QUESTION_LIMIT = Integer.MAX_VALUE; - protected static final boolean WHITELIST_ONLY = false; - protected static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); + protected static final boolean WHITELIST_ONLY = true; + protected static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {24}))); protected static final boolean GENERATE_HTML_ONLY = false; protected static final int MAX_THREADS = 4; @@ -364,13 +364,15 @@ /**more will be left out of the xml file */ List<String> questions = new LinkedList<String>(); BufferedReader in = new BufferedReader((new InputStreamReader(getClass().getClassLoader().getResourceAsStream("tbsl/oxford_eval_queries_parsed.txt")))); - int count=0; + int count=-1; for(String line;count<(QUESTION_LIMIT+QUESTION_OFFSET)&&(line=in.readLine())!=null;) { + count++; + if(WHITELIST_ONLY&&!WHITELIST.contains(Integer.valueOf(count))) {continue;} logger.info(count+": "+line); - if(count<QUESTION_OFFSET) {count++;continue;} + if(count<QUESTION_OFFSET) {continue;} String question = line.replace("question: ", "").trim(); - if(!line.trim().isEmpty()) {questions.add(question);count++;} + if(!line.trim().isEmpty()) {questions.add(question);} } in.close(); Model model = loadOxfordModel(); Added: branches/hmm/components-ext/src/test/java/org/dllearner/common/index/SPARQLClassesIndexTest.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/common/index/SPARQLClassesIndexTest.java (rev 0) +++ branches/hmm/components-ext/src/test/java/org/dllearner/common/index/SPARQLClassesIndexTest.java 2012-11-19 12:05:59 UTC (rev 3876) @@ -0,0 +1,24 @@ +/** **/ +package org.dllearner.common.index; + +import static org.junit.Assert.*; +import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner3; +import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner3Test; +import org.junit.Test; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; + +/** @author konrad + * */ +public class SPARQLClassesIndexTest +{ + + @Test public void test() + { + Model m = ModelFactory.createDefaultModel(); + m.read(SPARQLTemplateBasedLearner3Test.class.getClassLoader().getResourceAsStream("oxford/schema/LGD-Dump-110406-Ontology.nt"),null, "TURTLE"); + SPARQLClassesIndex index = new SPARQLClassesIndex(m); + assertFalse(index.getResourcesWithScores("pharmacy").getItems().isEmpty()); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-19 11:15:58
|
Revision: 3875 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3875&view=rev Author: kirdie Date: 2012-11-19 11:15:47 +0000 (Mon, 19 Nov 2012) Log Message: ----------- evaluation Modified Paths: -------------- branches/hmm/components-ext/eval/analyze branches/hmm/components-ext/eval/eval2.xml Modified: branches/hmm/components-ext/eval/analyze =================================================================== --- branches/hmm/components-ext/eval/analyze 2012-11-14 16:56:18 UTC (rev 3874) +++ branches/hmm/components-ext/eval/analyze 2012-11-19 11:15:47 UTC (rev 3875) @@ -1,2 +1,3 @@ #!/bin/bash -grep "<evaluation>" | sort | uniq -c +grep -E "(<evaluation>)|(<type>)" | sort | uniq -c + Modified: branches/hmm/components-ext/eval/eval2.xml =================================================================== --- branches/hmm/components-ext/eval/eval2.xml 2012-11-14 16:56:18 UTC (rev 3874) +++ branches/hmm/components-ext/eval/eval2.xml 2012-11-19 11:15:47 UTC (rev 3875) @@ -392,6 +392,7 @@ <question answertype="resource" id="23"> <string>houses/NNS close/RB to/TO an/DT Italian/JJ restaurant/NN</string> <queryStatus> +<evaluation>incorrect</correct> <type>OK</type> </queryStatus> <query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> @@ -425,9 +426,9 @@ <question answertype="resource" id="25"> <string>houses/NNS at/IN walking/VBG distance/NN from/IN Tesco/NNP or/CC Sainsburys/NNP shops/NNS</string> <queryStatus> +<evaluation>incorrect</correct> <type>OK</type> </queryStatus> -<evaluation>incorrect</correct> <query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> @@ -511,6 +512,7 @@ <string>houses/NNS with/IN many/JJ reception/NN rooms/NNS</string> <queryStatus> <type>OK</type> +<evaluation>partlycorrect</correct> </queryStatus> <query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-14 16:56:32
|
Revision: 3874 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3874&view=rev Author: kirdie Date: 2012-11-14 16:56:18 +0000 (Wed, 14 Nov 2012) Log Message: ----------- improved oxford benchmarking. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java branches/hmm/components-ext/src/main/resources/tbsl/oxford_eval_queries.txt branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/QueryTestData.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Added Paths: ----------- branches/hmm/components-ext/eval/ branches/hmm/components-ext/eval/analyze branches/hmm/components-ext/eval/eval2.xml branches/hmm/components-ext/src/main/resources/tbsl/oxford_eval_queries_parsed.txt branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/LearnStatus.java branches/hmm/components-ext/src/test/resources/oxford/links/lgd_labels.ttl branches/hmm/components-ext/src/test/resources/oxford/links/lgd_nodes.txt Added: branches/hmm/components-ext/eval/analyze =================================================================== --- branches/hmm/components-ext/eval/analyze (rev 0) +++ branches/hmm/components-ext/eval/analyze 2012-11-14 16:56:18 UTC (rev 3874) @@ -0,0 +1,2 @@ +#!/bin/bash +grep "<evaluation>" | sort | uniq -c Property changes on: branches/hmm/components-ext/eval/analyze ___________________________________________________________________ Added: svn:executable + * Added: branches/hmm/components-ext/eval/eval2.xml =================================================================== --- branches/hmm/components-ext/eval/eval2.xml (rev 0) +++ branches/hmm/components-ext/eval/eval2.xml 2012-11-14 16:56:18 UTC (rev 3874) @@ -0,0 +1,1358 @@ +<dataset> +<question answertype="resource" id="0"> +<string>houses/NNS in/IN Headington/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Headington','i')). +} +]]></query> +</question> +<question answertype="resource" id="1"> +<string>houses/NNS in/IN Abingdon/NNP with/IN more/JJR than/IN 2/CD bedrooms/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 (COUNT(?y0) AS ?c) WHERE { + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedrooms> ?y0. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Abingdon','i')). + FILTER(?c > 2). +} +GROUP BY ?x0 +]]></query> +</question> +<question answertype="resource" id="2"> +<string>houses/NNS with/IN garden/NN in/IN Wheatley/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?z,'garden','i')). + FILTER(regex(?y0,'Wheatley','i')). +} +]]></query> +</question> +<question answertype="resource" id="3"> +<string>detached/JJ houses/NNS in/IN Oxford/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + FILTER(regex(?y0,'Oxford','i')). + FILTER(regex(?y,'detached','i')). +} +]]></query> +</question> +<question answertype="resource" id="4"> +<string>Victorian/JJ houses/NNS in/IN Oxfordshire/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + FILTER(regex(?y0,'Oxfordshire','i')). + FILTER(regex(?y,'Victorian','i')). +} +]]></query> +</question> +<question answertype="resource" id="5"> +<string>Edwardian/JJ house/NN in/IN Oxfordshire/NNP for/IN less/JJR than/IN 1000000/CD</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#hasPrice> ?y0. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y1. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + FILTER(?y0 < 1000000). + FILTER(regex(?y,'Edwardian','i')). + FILTER(regex(?y1,'Oxfordshire','i')). +} +]]></query> +</question> +<question answertype="resource" id="6"> +<string>houses/NNS with/IN double/JJ garage/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#garage> ?y. + ?y <http://purl.org/goodrelations/v1#description> ?y0. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y0,'double','i')). +} +]]></query> +</question> +<question answertype="resource" id="7"> +<string>houses/NNS with/IN large/JJ garden/NN and/CC equipped/JJ kitchen/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y1 WHERE { + ?y1 <http://purl.org/goodrelations/v1#description> ?y0. + ?y1 rdf:type ?p2. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?y0,'equipped','i')). + FILTER(regex(?z,'large garden','i')). +} +]]></query> +</question> +<question answertype="resource" id="8"> +<string>houses/NNS with/IN more/JJR than/IN 1/CD reception/NN room/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#receptions> ?y. + FILTER(?y > 1). +} +]]></query> +</question> +<question answertype="resource" id="9"> +<string>houses/NNS with/IN conservatory/NN room/NN and/CC less/JJR than/IN 900000/CD pounds/NNS</string> +<queryStatus> +<evaluation>incorrect</correct> +<notes><note>templateproblem</note></note> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y0 (COUNT(?y0) AS ?c) WHERE { + ?x ?p1 ?y. + ?y0 rdf:type <http://linkedgeodata.org/triplify/node260063131>. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(?c < 900000). +} +GROUP BY ?x ?y0 +]]></query> +</question> +<question answertype="resource" id="10"> +<string>houses/NNS in/IN Old/NNP Marston/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Old Marston','i')). +} +]]></query> +</question> +<question answertype="resource" id="11"> +<string>family/NN houses/NNS with/IN more/JJR than/IN 2/CD bathrooms/NNS and/CC more/JJR than/IN 4/CD bedrooms/NNS</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x (COUNT(?y) AS ?c) (COUNT(?y0) AS ?c0) WHERE { + ?y0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedroom>. + ?x <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bathrooms> ?y. + ?x rdf:type ?p0. + FILTER(?c > 2). + FILTER(?c0 > 4). +} +GROUP BY ?x +]]></query> +</question> +<question answertype="resource" id="12"> +<string>houses/NNS close/RB to/TO Iffley/NNP Sport/NNP Centre/NNP</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="13"> +<string>houses/NNS in/IN Oxford/NNP close/RB to/TO the/DT train/NN station/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y0 ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 <http://dbpedia.org/property/near> ?y0. + ?y0 rdf:type ?p0. + FILTER(regex(?y,'Oxford','i')). +} +]]></query> +</question> +<question answertype="resource" id="14"> +<string>houses/NNS in/IN Summertown/NNP for/IN less/JJR than/IN 400000/CD pounds/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#hasPrice> ?y0. + FILTER(?y0 < 400000). + FILTER(regex(?y,'Summertown','i')). +} +]]></query> +</question> +<question answertype="resource" id="15"> +<string>two/CD floors/NNS houses/NNS in/IN East/NNP Oxford/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +ASK WHERE { + 2 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?2 rdf:type ?p0. + FILTER(regex(?y,'East Oxford','i')). +} +]]></query> +</question> +<question answertype="resource" id="16"> +<string>brand/NN new/JJ houses/NNS in/IN Oxford/NNP for/IN less/JJR than/IN 500000/CD pounds/NNS</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y ?y0 WHERE { + ?y <http://purl.org/goodrelations/v1#description> ?y2. + ?y rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?y1 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#hasPrice> ?y0. + ?y <http://www.w3.org/2006/vcard/ns#street-address> ?y1. + ?y rdf:type <http://purl.org/goodrelations/v1#hasBrand>. + FILTER(?y0 < 500000). + FILTER(regex(?y1,'Oxford','i')). + FILTER(regex(?y2,'new','i')). +} +]]></query> +</question> +<question answertype="resource" id="17"> +<string>houses/NNS close/RB to/TO Brookes/NNP University/NNP</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="18"> +<string>houses/NNS in/IN Jericho/NNP area/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y,'Jericho area','i')). +} +]]></query> +</question> +<question answertype="resource" id="19"> +<string>house/NN close/RB to/TO Headington/NNP hospitals/NNS</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="20"> +<string>modern/JJ houses/NNS with/IN gas/NN central/JJ heating/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 ?p0 ?y0. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + ?x0 <http://linkedgeodata.org/ontology/Shop> ?y0. + FILTER(regex(?y,'modern','i')). +} +]]></query> +</question> +<question answertype="resource" id="21"> +<string>houses/NNS with/IN electric/JJ heating/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'electric heating','i')). +} +]]></query> +</question> +<question answertype="resource" id="22"> +<string>houses/NNS less/JJR than/IN 500000/CD within/IN area/NN OX16/CD</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>61</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="23"> +<string>houses/NNS close/RB to/TO an/DT Italian/JJ restaurant/NN</string> +<queryStatus> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y ?x0 WHERE { + ?y <http://purl.org/goodrelations/v1#description> ?y0. + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?y rdf:type ?p1. + FILTER(regex(?y0,'Italian','i')). +} +]]></query> +</question> +<question answertype="resource" id="24"> +<string>houses/NNS at/IN walking/VBG distance/NN from/IN a/DT pharmacy/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?y rdf:type ?p0. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="25"> +<string>houses/NNS at/IN walking/VBG distance/NN from/IN Tesco/NNP or/CC Sainsburys/NNP shops/NNS</string> +<queryStatus> +<type>OK</type> +</queryStatus> +<evaluation>incorrect</correct> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +ASK WHERE { +{ ?y ?p1 ?y0.?y rdf:type ?p0. } UNION {} +} +]]></query> +</question> +<question answertype="resource" id="26"> +<string>houses/NNS nearby/JJ Sheldonian/NNP Theatre/NNP</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="27"> +<string>houses/NNS with/IN underfloor/JJ heating/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'underfloor heating','i')). +} +]]></query> +</question> +<question answertype="resource" id="28"> +<string>houses/NNS with/IN wood/NN floor/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'wood floor','i')). +} +]]></query> +</question> +<question answertype="resource" id="29"> +<string>houses/NNS close/RB to/TO The/DT King/NN 's/POS Arms/NNS pub/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x WHERE { + ?x ?p1 ?y0. + ?x <http://dbpedia.org/property/near> ?y. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?y rdf:type <http://linkedgeodata.org/ontology/Parking>. +} +]]></query> +</question> +<question answertype="resource" id="30"> +<string>houses/NNS with/IN a/DT garden/NN that/WDT is/VBZ at/IN least/JJS 2/CD acres/NNS big/JJ</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>184</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="31"> +<string>houses/NNS with/IN many/JJ reception/NN rooms/NNS</string> +<queryStatus> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#receptions> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="32"> +<string>houses/NNS built/VBN around/IN 1950/CD</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>76</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="33"> +<string>houses/NNS with/IN balcony/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'balcony','i')). +} +]]></query> +</question> +<question answertype="resource" id="34"> +<string>houses/NNS with/IN double/JJ glazed/JJ windows/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'double glazed windows','i')). +} +]]></query> +</question> +<question answertype="resource" id="35"> +<string>2/CD bedroom/NN houses/NNS near/IN Oxford/NNP train/NN station/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 (COUNT(?x0) AS ?v0) WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type ?p1. +} +GROUP BY ?x0 +HAVING (?v0 = 2) +]]></query> +</question> +<question answertype="resource" id="36"> +<string>4/CD bedroom/NN detached/VBD houses/NNS in/IN Oxford/NNP</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y (COUNT(?x) AS ?v2) WHERE { + ?y <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?y <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedroom> ?x. + ?y rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y0,'Oxford','i')). +} +GROUP BY ?y +HAVING (?v2 = 4) +]]></query> +</question> +<question answertype="resource" id="37"> +<string>studio/NN apartments/NNS in/IN Summertown/NNP ,/, Oxford/NNP</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>38</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="38"> +<string>freehold/NN houses/NNS with/IN 2/CD bedrooms/NNS and/CC a/DT living/NN room/NN in/IN Banbury/NNP</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y1 (COUNT(?y) AS ?v2) WHERE { + ?y1 rdf:type ?p1. + ?y1 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?x rdf:type ?p4. + ?y <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedrooms> ?x. + FILTER(regex(?y0,'Banbury','i')). +} +GROUP BY ?x ?y1 +HAVING (?v2 = 2) +]]></query> +</question> +<question answertype="resource" id="39"> +<string>houses/NNS in/IN Oxford/NNP city/NN center/NN with/IN at/IN most/JJS 2/CD bedrooms/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x1 (COUNT(?y0) AS ?c) WHERE { + ?x1 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedrooms> ?y0. + ?x1 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x1 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Oxford city center','i')). + FILTER(?c <= 2). +} +GROUP BY ?x1 +]]></query> +</question> +<question answertype="resource" id="40"> +<string>victorian/JJ town/NN houses/NNS in/IN north/JJ Oxford/NNP</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?y0 ?p2 ?j. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + FILTER(regex(?y0,'Oxford','i')). + FILTER(regex(?y,'victoriantown','i')). +} +]]></query> +</question> +<question answertype="resource" id="41"> +<string>terrace/NN houses/NNS with/IN west/NN facing/VBG garden/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y1 ?x0 WHERE { + ?x0 rdf:type ?p2. + ?y1 <http://purl.org/goodrelations/v1#description> ?y0. + ?x0 <http://linkedgeodata.org/triplify/node338797397> ?y1. + ?x0 ?p1 ?y1. + FILTER(regex(?y0,'facing','i')). +} +]]></query> +</question> +<question answertype="resource" id="42"> +<string>modernized/JJ end/NN terrace/NN houses/NNS with/IN private/JJ parking/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y1 ?x0 WHERE { + ?y1 <http://purl.org/goodrelations/v1#description> ?y0. + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#ParkingType> ?y1. + ?x0 <http://purl.org/goodrelations/v1#description> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y0,'private','i')). + FILTER(regex(?y,'modernizedendterrace','i')). +} +]]></query> +</question> +<question answertype="resource" id="43"> +<string>three/CD bedroom/NN houses/NNS with/IN open/JJ fireplace/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 (COUNT(?x0) AS ?v0) WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type ?p1. + FILTER(regex(?z,'fireplace open','i')). +} +GROUP BY ?x0 +HAVING (?v0 = 3) +]]></query> +</question> +<question answertype="resource" id="44"> +<string>houses/NNS available/JJ from/IN June/NNP 15th/CD ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>80</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="45"> +<string>houses/NNS on/IN Rawlinson/NNP Road/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y,'Rawlinson Road','i')). +} +]]></query> +</question> +<question answertype="resource" id="46"> +<string>flats/NNS near/IN supermarket/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?y rdf:type ?p1. +} +]]></query> +</question> +<question answertype="resource" id="47"> +<string>give/VB me/PRP flats/NNS in/IN central/JJ Oxford/NNP with/IN at/IN least/JJS one/CD bedroom/NN below/IN 1000/CD pounds/NNS a/DT month/NN ?/.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>1652</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="48"> +<string>find/VB 2/CD bedroom/NN flats/NNS in/IN walking/VBG distance/NN from/IN the/DT computer/NN science/NN departement/NN !/.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>52</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="49"> +<string>find/VB a/DT property/NN with/IN 2/CD bedrooms/NNS close/RB to/TO some/DT park/NN ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>51</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="50"> +<string>find/VB a/DT flat/NN in/IN the/DT area/NN around/IN Cowley/NNP Road/NNP with/IN 2/CD bedrooms/NNS ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>1489</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="51"> +<string>find/VB a/DT furnished/JJ place/NN with/IN one/CD bedroom/NN close/RB to/TO the/DT Radcliffe/NNP Camera/NNP ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>89</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="52"> +<string>find/VB an/DT unfurnished/JJ house/NN with/IN at/IN least/JJS 2/CD bedrooms/NNS in/IN Summertown/NNP ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>70</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="53"> +<string>find/VB a/DT furnished/VBN flat/JJ with/IN one/CD bedroom/NN for/IN smokers/NNS ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>1993</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="54"> +<string>find/VB a/DT flat/NN with/IN parking/NN in/IN central/JJ Oxford/NNP ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>86</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="55"> +<string>find/VB a/DT representative/JJ house/NN in/IN Summertown/NNP ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>69</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="56"> +<string>which/WDT places/NNS are/VBP offered/VBN close/RB to/TO the/DT train/NN station/NN ?/.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>245</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="57"> +<string>show/VB me/PRP the/DT retirement/NN houses/NNS for/IN sale/NN near/IN Oxford/NNP ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>70</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="58"> +<string>give/VB me/PRP a/DT flat/NN with/IN at/IN least/JJS two/CD bathrooms/NNS for/IN less/JJR than/IN 1000/CD pounds/NNS ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>2176</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="59"> +<string>show/VB me/PRP a/DT flat/NN which/WDT is/VBZ close/RB to/TO 3/CD bars/NNS ./.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>84</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="60"> +<string>what/WP is/VBZ the/DT average/JJ price/NN of/IN furnished/VBN 1/CD bedroom/NN apartments/NNS in/IN Heddington/NNP ?/.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>179</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="61"> +<string>how/WRB many/JJ flats/NNS are/VBP offered/VBN in/IN central/JJ Oxford/NNP below/IN 1000/CD pounds/NNS a/DT month/NN ?/.</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>113</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="62"> +<string>houses/NNS close/RB to/TO The/DT Ashmolean/NNP Museum/NNP ,/, with/IN more/JJR than/IN one/CD bedroom/NN</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>88</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="63"> +<string>houses/NNS in/IN Botley/NNP Road/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y,'Botley Road','i')). +} +]]></query> +</question> +<question answertype="resource" id="64"> +<string>houses/NNS in/IN Littlemore/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Littlemore','i')). +} +]]></query> +</question> +<question answertype="resource" id="65"> +<string>houses/NNS that/WDT cost/VBP between/IN 600000/CD and/CC 800000/CD pounds/NNS</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>147</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="66"> +<string>houses/NNS with/IN 3/CD bedrooms/NNS in/IN Florence/NNP Park/NNP Road/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 (COUNT(?y) AS ?v2) WHERE { + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#bedrooms> ?y. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y0,'Florence Park Road','i')). +} +GROUP BY ?x0 +HAVING (?v2 = 3) +]]></query> +</question> +<question answertype="resource" id="67"> +<string>houses/NNS with/IN front/JJ garden/NN and/CC rear/NN garden/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y0 WHERE { + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x <http://purl.org/goodrelations/v1#description> ?z. + ?y0 rdf:type ?p0. + FILTER(regex(?z,'front garden','i')). +} +]]></query> +</question> +<question answertype="resource" id="68"> +<string>houses/NNS in/IN Oxford/NNP ,/, close/RB to/TO Railway/NNP Station/NNP</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>40</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="69"> +<string>houses/NNS with/IN ample/JJ parking/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://diadem.cs.ox.ac.uk/ontologies/real-estate#ParkingType> ?y. + ?y <http://purl.org/goodrelations/v1#description> ?y0. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?y0,'ample','i')). +} +]]></query> +</question> +<question answertype="resource" id="70"> +<string>house/NN with/IN electric/JJ central/JJ heating/NN system/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'electric central heating system','i')). +} +]]></query> +</question> +<question answertype="resource" id="71"> +<string>houses/NNS with/IN three/CD en/IN suites/NNS near/IN Oxford/NNP</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>37</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="72"> +<string>houses/NNS with/IN countryside/NN views/NNS</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 ?p1 ?y. +} +]]></query> +</question> +<question answertype="resource" id="73"> +<string>houses/NNS with/IN farmland/NN views/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'farmland views','i')). +} +]]></query> +</question> +<question answertype="resource" id="74"> +<string>houses/NNS nearby/JJ River/NNP Thames/NNPS</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +<question answertype="resource" id="75"> +<string>houses/NNS having/VBG one/CD utility/NN room/NN or/CC cloakroom/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?y0 WHERE { + ?1 rdf:type ?p3. + 1 <http://purl.org/goodrelations/v1#description> ?y0. +{ ?1 rdf:type ?p0. } UNION {?1 rdf:type ?p1.} + FILTER(regex(?y0,'having','i')). +} +]]></query> +</question> +<question answertype="resource" id="76"> +<string>houses/NNS in/IN Oxfordshire/NNP with/IN fireplaces/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?y,'Oxfordshire','i')). + FILTER(regex(?z,'fireplaces','i')). +} +]]></query> +</question> +<question answertype="resource" id="77"> +<string>houses/NNS with/IN open/JJ plan/NN kitchen/NN near/IN Oxford/NNP</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://dbpedia.org/property/near> <http://linkedgeodata.org/triplify/node1257810975>. + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?z,'kitchen open plan','i')). +} +]]></query> +</question> +<question answertype="resource" id="78"> +<string>houses/NNS with/IN walled/JJ garden/NN near/IN Oxford/NNP</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://dbpedia.org/property/near> <http://linkedgeodata.org/triplify/node1257810975>. + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?z,'garden walled','i')). +} +]]></query> +</question> +<question answertype="resource" id="79"> +<string>houses/NNS with/IN river/NN views/NNS</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'river views','i')). +} +]]></query> +</question> +<question answertype="resource" id="80"> +<string>houses/NNS with/IN gated/JJ entrance/NN or/CC in/IN a/DT gated/JJ community/NN</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>67</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="81"> +<string>recently/RB refurbished/VBN houses/NNS with/IN lift/NN</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>84</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="82"> +<string>house/NN with/IN balcony/NN and/CC vaulted/VBD ceiling/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y1 WHERE { + ?y1 <http://purl.org/goodrelations/v1#description> ?y0. + ?y1 rdf:type ?p2. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x <http://purl.org/goodrelations/v1#description> ?z. + FILTER(regex(?z,'balcony','i')). + FILTER(regex(?y0,'vaulted','i')). +} +]]></query> +</question> +<question answertype="resource" id="83"> +<string>house/NN that/WDT is/VBZ a/DT maisonette/NN and/CC on/IN Gloucester/NNP Green/NNP</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>366</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="84"> +<string>house/NN in/IN a/DT corner/NN or/CC end/NN of/IN terrace/NN plot/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y1. +{ ?y1 rdf:type ?p1. } UNION {?y1 ?p4 ?y0.?y1 rdf:type ?p2.?y0 rdf:type ?p3.} +} +]]></query> +</question> +<question answertype="resource" id="85"> +<string>house/NN with/IN 3/CD bedrooms/NNS ,/, but/CC cheaper/JJR than/IN 150000/CD pounds/NNS</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>269</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="86"> +<string>house/NN with/IN at/IN least/JJS 2/CD reception/NN rooms/NNS and/CC a/DT garden/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x WHERE { + ?x <http://diadem.cs.ox.ac.uk/ontologies/real-estate#receptions> ?y. + ?y0 rdf:type ?p1. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(?y >= 2). +} +]]></query> +</question> +<question answertype="resource" id="87"> +<string>house/NN with/IN a/DT courtyard/NN</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://purl.org/goodrelations/v1#description> ?z. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + FILTER(regex(?z,'courtyard','i')). +} +]]></query> +</question> +<question answertype="resource" id="88"> +<string>house/NN with/IN a/DT fireplace/NN and/CC a/DT garden/NN that/WDT is/VBZ not/RB communal/JJ</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>1676</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="89"> +<string>house/NN with/IN parking/NN but/CC not/RB Victorian/JJ</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>33</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="90"> +<string>house/NN with/IN 3/CD bathrooms/NNS ,/, but/CC not/RB en/IN suite/NN</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>163</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="91"> +<string>house/NN in/IN a/DT retirement/NN complex/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://nwalsh.com/rdf/vCard#postal-code> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?y rdf:type ?p1. +} +]]></query> +</question> +<question answertype="resource" id="92"> +<string>house/NN with/IN double/JJ glazing/NN and/CC central/JJ heating/NN</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x ?y0 WHERE { + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x <http://purl.org/goodrelations/v1#description> ?z. + ?y0 rdf:type ?p0. + FILTER(regex(?z,'double glazing','i')). +} +]]></query> +</question> +<question answertype="resource" id="93"> +<string>house/NN with/IN immediately/RB available/JJ</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>40</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="94"> +<string>house/NN listed/VBD Grade/NNP I/NNP or/CC Grade/NNP II/NNP</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x WHERE { + ?x <http://nwalsh.com/rdf/vCard#n> ?y0. + ?x rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +{ } UNION {} +} +]]></query> +</question> +<question answertype="resource" id="95"> +<string>house/NN that/WDT has/VBZ been/VBN recently/RB replumbed/VBN</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>99</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="96"> +<string>house/NN in/IN Witney/NNP or/CC Wolvercote/NNP</string> +<queryStatus> +<evaluation>partlycorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y0. +{ } UNION {} + FILTER(regex(?y0,'Wolvercote','i')). +} +]]></query> +</question> +<question answertype="resource" id="97"> +<string>house/NN with/IN more/JJR than/IN 2/CD bedrooms/NNS ,/, but/CC not/RB in/IN Marston/NNP</string> +<queryStatus> +<type>NO_TEMPLATE_FOUND</type> +<timeMs>292</timeMs> +</queryStatus> +</question> +<question answertype="resource" id="98"> +<string>house/NN in/IN Banbury/NNP Road/NNP</string> +<queryStatus> +<evaluation>correct</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. + ?x0 <http://www.w3.org/2006/vcard/ns#street-address> ?y. + FILTER(regex(?y,'Banbury Road','i')). +} +]]></query> +</question> +<question answertype="resource" id="99"> +<string>house/NN in/IN the/DT area/NN of/IN John/NNP Radcliffe/NNP hospital/NN</string> +<queryStatus> +<evaluation>incorrect</correct> +<type>OK</type> +</queryStatus> +<query><![CDATA[PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> + +SELECT ?x0 WHERE { + ?x0 <http://dbpedia.org/property/near> ?y. + ?x0 rdf:type <http://diadem.cs.ox.ac.uk/ontologies/real-estate#House>. +} +]]></query> +</question> +</dataset> Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-14 14:37:16 UTC (rev 3873) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-14 16:56:18 UTC (rev 3874) @@ -100,7 +100,7 @@ /** The minimum score of items that are accepted from the Sindice search BOA index. **/ private static final Double BOA_THRESHOLD = 0.5; enum Mode {BEST_QUERY, BEST_NON_EMPTY_QUERY} - private Mode mode = Mode.BEST_NON_EMPTY_QUERY; + public static final Mode mode = Mode.BEST_QUERY; /** used to create a label out of the URI when there is no label available in the SPARQL endpoint.*/ private static SimpleIRIShortFormProvider sfp = new SimpleIRIShortFormProvider(); @@ -399,6 +399,10 @@ learnSPARQLQueries(false); } + /** generates SPARQL queries out of the questions + * @param useHMM use a hidden markov model resource disambiguation (experimental, slow) + * @throws NoTemplateFoundException if non of the templates apply to the query + */ public void learnSPARQLQueries(boolean useHMM) throws NoTemplateFoundException { reset(); @@ -414,10 +418,10 @@ logger.debug("Done in " + templateMon.getLastValue() + "ms."); relevantKeywords.addAll(templateGenerator.getUnknownWords()); if(templates.isEmpty()){throw new NoTemplateFoundException();} -// logger.debug("Templates:"); -// for(Template t : templates){ -// logger.debug(t); -// } + logger.debug("Templates:"); + for(Template t : templates){ + logger.debug(t); + } //get the weighted query candidates generatedQueries = getWeightedSPARQLQueries(templates,useHMM); @@ -684,21 +688,7 @@ logger.debug("Generating SPARQL query candidates..."); SortedMap<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(); -// new Comparator<Slot>() { -// -// @Override -// public int compare(Slot o1, Slot o2) { -// if(o1.equals(o2)) return 0; -// return -1; -//// if(o1.getSlotType() == o2.getSlotType()){ -//// return o1.getToken().compareTo(o2.getToken()); -//// } else { -//// return -1; -//// } -// } -// }); slot2Allocations = Collections.synchronizedSortedMap(slot2Allocations); - SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); @@ -708,30 +698,31 @@ // Set<Allocation> allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); - ExecutorService executor = Executors.newSingleThreadExecutor();//Executors.newFixedThreadPool(t.getSlots().size()); +// ExecutorService executor = Executors.newSingleThreadExecutor(); + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); long startTime = System.currentTimeMillis(); - Map<Future,Slot> futureToSlot = new HashMap<Future,Slot>(); + Map<Future<SortedSet<Allocation>>,Slot> futureToSlot = new HashMap<Future<SortedSet<Allocation>>,Slot>(); + // start calculating candidates for each slot for (Slot slot : t.getSlots()) { if(!slot2Allocations.containsKey(slot)){ Callable<SortedSet<Allocation>> worker = new SlotProcessor(slot); Future<SortedSet<Allocation>> submit = executor.submit(worker); futureToSlot.put(submit, slot); - } + } } - + // get the candidates for (Future<SortedSet<Allocation>> future : futureToSlot.keySet()) { try { - SortedSet<Allocation> result = future.get(); + SortedSet<Allocation> result = future.get(); slot2Allocations.put(futureToSlot.get(future), result); } catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();throw new RuntimeException(e);} } executor.shutdown(); - /*for(Slot slot : t.getSlots()){ allocations = slot2Allocations2.get(slot); if(allocations == null){ @@ -753,25 +744,27 @@ } allocations.addAll(tmp); }*/ - logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + logger.debug("Time needed for generating allocation candidates for all slots of the template: " + (System.currentTimeMillis() - startTime) + "ms"); Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); Query cleanQuery = t.getQuery(); queries.add(new WeightedQuery(cleanQuery)); - Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); Set<Slot> classSlots = new HashSet<Slot>(); - // TODO: can this be optimized to be in just one loop? (but I guess it won't give a noticable performance benefit anyways...) + + // property slots first because they determine if the objects in another slots are resources or literals for(Slot slot : t.getSlots()){ - if(slot.getSlotType() == SlotType.CLASS){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ sortedSlots.add(slot); - classSlots.add(slot); } } + for(Slot slot : t.getSlots()){ - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ + if(slot.getSlotType() == SlotType.CLASS){ sortedSlots.add(slot); + classSlots.add(slot); } } for(Slot slot : t.getSlots()){ @@ -779,26 +772,35 @@ sortedSlots.add(slot); } } + //add for each SYMPROPERTY Slot the reversed query + { + Set<WeightedQuery> normalAndReversedQueries = new TreeSet<WeightedQuery>(); for(Slot slot : sortedSlots){ for(WeightedQuery wQ : queries){ if(slot.getSlotType() == SlotType.SYMPROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY){ Query reversedQuery = new Query(wQ.getQuery()); - reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); - tmp.add(new WeightedQuery(reversedQuery)); + + // why only the first? temporarily comment this out and do it with all +// reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + for(SPARQL_Triple triple: reversedQuery.getTriplesWithVar(slot.getAnchor())) + { + triple.reverse(); + } + normalAndReversedQueries.add(new WeightedQuery(reversedQuery)); } - tmp.add(wQ); + normalAndReversedQueries.add(wQ); } queries.clear(); - queries.addAll(tmp); - tmp.clear(); + queries.addAll(normalAndReversedQueries); } - + } Set<Slot> unhandledSlots = new HashSet<Slot>(sortedSlots); unhandledSlots.removeAll(slot2Allocations.keySet()); if(!unhandledSlots.isEmpty()) { logger.error("the following slots are unhandled: "+unhandledSlots); + System.exit(1); } for(Slot slot : sortedSlots) { @@ -809,6 +811,7 @@ } if(!slot2Allocations.get(slot).isEmpty()){ + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ Query q = new Query(query.getQuery()); @@ -892,25 +895,28 @@ // } // } +// je nach propertykandidaten und prädikatpositionen: zuerst prädikate füllen, weil man dann weiß, ob es objektproperty oder datatypeproperty ist und damit kann man dann sachen rausfiltern + + // TODO: ist hier schon gefüllt if(!drop){ if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); +// q.replaceVarWithURI(slot.getAnchor(), a.getUri()); for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ SPARQL_Value object = triple.getValue(); if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position -// SPARQL_Property predicate = triple.getProperty(); -// if(!predicate.isVariable()){//only consider triple where predicate is URI -// String predicateURI = predicate.getName().replace("<", "").replace(">", ""); -// if(isDatatypeProperty(predicateURI)){//if data property -// q.addFilter(new SPARQL_Filter(new SPARQL_Pair( -// object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); -// } else { -// q.replaceVarWithURI(slot.getAnchor(), a.getUri()); -// } -// } else { -// q.replaceVarWithURI(slot.getAnchor(), a.getUri()); -// } -// } else { + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { // } } Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-11-14 14:37:16 UTC (rev 3873) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-11-14 16:56:18 UTC (rev 3874) @@ -15,7 +15,7 @@ import com.jamonapi.MonitorFactory; public class Parser { - + private static final Logger logger = Logger.getLogger(Parser.class); public boolean CONSTRUCT_SEMANTICS = false; @@ -32,15 +32,15 @@ private List<Dude> dudes = new ArrayList<Dude>(); private ParseGrammar parseGrammar = null; private List<Integer> temporaryEntries = new ArrayList<Integer>(); - + private GrammarFilter grammarFilter = new GrammarFilter(); @SuppressWarnings("unchecked") private final Class[] operations = { Scanner.class, MoveDotDown.class, - MoveDotUp.class, LeftPredictor.class, LeftCompletor.class, - RightPredictor.class, RightCompletor.class, SubstPredictor.class, - SubstCompletor.class }; - + MoveDotUp.class, LeftPredictor.class, LeftCompletor.class, + RightPredictor.class, RightCompletor.class, SubstPredictor.class, + SubstCompletor.class }; + /** * parses given input string by using the given grammar. Behaviour of the * Parser is controlled by USE_DPS_AS_INITTREES, USE_LESS_MEMORY, @@ -58,7 +58,7 @@ derivedTrees.clear(); dudes.clear(); temporaryEntries.clear(); - + if (!VERBOSE) GrammarFilter.VERBOSE = false; /* @@ -76,8 +76,8 @@ this.input = ("# ".concat(inputNoTags.replaceAll("'","").trim())).split(" "); int n = this.input.length; - - + + if (SHOW_GRAMMAR) { logger.debug(parseGrammar); } @@ -87,7 +87,7 @@ } List<Pair<TreeNode, Short>> initTrees = parseGrammar.getInitTrees(); - + internalParse(initTrees, n); if (USE_DPS_AS_INITTREES && derivationTrees.isEmpty()) { @@ -98,18 +98,18 @@ return derivationTrees; } - + public List<String> getUnknownWords(){ return grammarFilter.getUnknownWords(); } - + public List<DerivationTree> parseMultiThreaded(String taggeduserinput, LTAGLexicon grammar) { derivationTrees.clear(); derivedTrees.clear(); dudes.clear(); temporaryEntries.clear(); - + if (!VERBOSE) GrammarFilter.VERBOSE = false; /* @@ -127,8 +127,8 @@ this.input = ("# ".concat(inputNoTags.replaceAll("'","").trim())).split(" "); int n = this.input.length; - - + + if (SHOW_GRAMMAR) {... [truncated message content] |
From: <Chr...@us...> - 2012-11-14 14:37:27
|
Revision: 3873 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3873&view=rev Author: ChristinaUnger Date: 2012-11-14 14:37:16 +0000 (Wed, 14 Nov 2012) Log Message: ----------- at walking distance -> near Modified Paths: -------------- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex Modified: trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex =================================================================== --- trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-11-09 17:15:06 UTC (rev 3872) +++ trunk/components-ext/src/main/resources/tbsl/lexicon/english_oxford.lex 2012-11-14 14:37:16 UTC (rev 3873) @@ -7,14 +7,14 @@ near || (PP P:'near' DP[dp]) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> nearby || (NP NP* (PP P:'nearby' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_nearby(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_nearby/OBJECTPROPERTY/near ]> nearby || (PP P:'nearby' DP[dp]) || <x,l1,<e,t>, [ l1:[ | SLOT_nearby(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_nearby/OBJECTPROPERTY/near ]> - within walking distance from || (NP NP* (PP P:'within' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - within walking distance from || (PP P:'within' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - within minutes of || (NP NP* (PP P:'within' (NP N:'minutes' P:'of' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - within minutes of || (PP P:'within' (NP N:'minutes' P:'of' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - in walking distance from || (NP NP* (PP P:'in' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - in walking distance from || (PP P:'in' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - at walking distance from || (NP NP* (PP P:'at' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> - at walking distance from || (PP P:'at' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/at_walking_distance ]> + within walking distance from || (NP NP* (PP P:'within' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + within walking distance from || (PP P:'within' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + within minutes of || (NP NP* (PP P:'within' (NP N:'minutes' P:'of' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + within minutes of || (PP P:'within' (NP N:'minutes' P:'of' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + in walking distance from || (NP NP* (PP P:'in' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + in walking distance from || (PP P:'in' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + at walking distance from || (NP NP* (PP P:'at' (NP N:'walking' N:'distance' P:'from' DP[dp]))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> + at walking distance from || (PP P:'at' (NP N:'walking' N:'distance' P:'from' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near ]> in the area || (NP NP* (PP P:'in' (DP DET:'the' (NP N:'area' DP[dp])))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near]> in the area of || (NP NP* (PP P:'in' (DP DET:'the' (NP N:'area' (PP P:'of' DP[dp]))))) || <x,l1,<e,t>, [ l1:[ | SLOT_near(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_near/OBJECTPROPERTY/near]> in || (NP NP* (PP P:'in' DP[dp])) || <x,l1,<e,t>, [ l1:[ | SLOT_location(x,y) ] ], [ (l2,y,dp,<<e,t>,t>) ], [ l2=l1 ],[ SLOT_location/PROPERTY/location^city^postal_code^address^street ]> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-09 17:15:13
|
Revision: 3872 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3872&view=rev Author: kirdie Date: 2012-11-09 17:15:06 +0000 (Fri, 09 Nov 2012) Log Message: ----------- new test data is now in and benchmark bug fixed but there is still a timeout issue when creating the benchmark xml file out of the oxford evaluation queries. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Property Changed: ---------------- branches/hmm/ Property changes on: branches/hmm ___________________________________________________________________ Modified: svn:mergeinfo - /trunk:3846-3863 + /trunk:3845-3871 Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-09 15:06:31 UTC (rev 3871) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-09 17:15:06 UTC (rev 3872) @@ -1174,7 +1174,7 @@ learnedPos++; List<String> results; try { - logger.debug("Testing query:\n" + query); + logger.trace("Testing query:\n" + query); com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); q.setLimit(1); ResultSet rs = executeSelect(q.toString()); @@ -1217,7 +1217,7 @@ } else if(queryType == SPARQL_QueryType.ASK){ for(WeightedQuery query : queries){ learnedPos++; - logger.debug("Testing query:\n" + query); + logger.trace("Testing query:\n" + query); boolean result = executeAskQuery(query.getQuery().toString()); learnedSPARQLQueries.add(query); // if(stopIfQueryResultNotEmpty && result){ Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-09 15:06:31 UTC (rev 3871) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-09 17:15:06 UTC (rev 3872) @@ -115,15 +115,15 @@ // problem mit "In/IN which/WDT films/NNS did/VBD Julia/NNP Roberts/NNP as/RB well/RB as/IN Richard/NNP Gere/NNP play/NN" public class SPARQLTemplateBasedLearner3Test { - protected static final boolean USE_HMM = true; + protected static final boolean USE_HMM = false; protected static final File evaluationFolder = new File("cache/evaluation"); protected static final boolean DBPEDIA_PRETAGGED = true; protected static final boolean OXFORD_PRETAGGED = false; - protected static final int MAX_NUMBER_OF_QUESTIONS = 100; + protected static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; protected static final boolean WHITELIST_ONLY = false; protected static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); protected static final boolean GENERATE_HTML_ONLY = false; - protected static final int MAX_THREADS = 10; + protected static final int MAX_THREADS = 1; /*@Test*/ public void testDBpedia() throws Exception { @@ -252,7 +252,7 @@ out.close(); } - @Test public void testOxford() throws Exception + /*@Test*/ public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex(),OXFORD_PRETAGGED); @@ -318,19 +318,16 @@ logger.info("learned query: "+testData.id2Query.get(0)); } - /*@Test*/ @SuppressWarnings("null") public void generateXMLOxford() throws IOException - { + @Test @SuppressWarnings("null") public void generateXMLOxford() throws IOException + { boolean ADD_POS_TAGS = true; PartOfSpeechTagger posTagger = null; if(ADD_POS_TAGS) {posTagger=new StanfordPartOfSpeechTagger();} Model model = loadOxfordModel(); List<String> questions = new LinkedList<String>(); BufferedReader in = new BufferedReader((new InputStreamReader(getClass().getClassLoader().getResourceAsStream("tbsl/oxford_eval_queries.txt")))); - int j=0; for(String line;(line=in.readLine())!=null;) { - j++; - if(j>5) break; // TODO: remove later String question = line.replace("question: ", "").trim(); if(ADD_POS_TAGS&&!OXFORD_PRETAGGED) {question = posTagger.tag(question);} if(!line.trim().isEmpty()) {questions.add(question);} @@ -340,9 +337,13 @@ Iterator<String> it = questions.iterator(); for(int i=0;i<questions.size();i++) {id2Question.put(i, it.next());} MappingBasedIndex mappingIndex= getOxfordMappingIndex(); + logger.info("generating sparql queries for questions"); QueryTestData testData = generateTestDataMultiThreaded(id2Question, null,model,mappingIndex,ADD_POS_TAGS||OXFORD_PRETAGGED); + logger.info("generating answers for sparql queries"); testData.generateAnswers(null, null, model); + logger.info("writing test data to benchmark file"); testData.writeQaldXml(new File("log/test.xml")); + logger.info("finished generating oxford benchmark file, "+testData.id2Question.values().size()+"questions, "+testData.id2Query.size()+" SPARQL queries, "+testData.id2Answers.size()+" answers."); } public static MappingBasedIndex getOxfordMappingIndex() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-09 15:06:38
|
Revision: 3871 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3871&view=rev Author: kirdie Date: 2012-11-09 15:06:31 +0000 (Fri, 09 Nov 2012) Log Message: ----------- Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-09 11:46:34 UTC (rev 3870) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-09 15:06:31 UTC (rev 3871) @@ -96,7 +96,7 @@ public class SPARQLTemplateBasedLearner2 implements SparqlQueryLearningAlgorithm { /** synonyms are great but are not used yet by the HMM algorithm. **/ - private static final boolean HMM_USE_SYNONYMS = true; + private static final boolean HMM_USE_SYNONYMS = false; /** The minimum score of items that are accepted from the Sindice search BOA index. **/ private static final Double BOA_THRESHOLD = 0.5; enum Mode {BEST_QUERY, BEST_NON_EMPTY_QUERY} Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java 2012-11-09 11:46:34 UTC (rev 3870) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java 2012-11-09 15:06:31 UTC (rev 3871) @@ -196,5 +196,4 @@ // } } - } Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-09 11:46:34 UTC (rev 3870) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-09 15:06:31 UTC (rev 3871) @@ -115,17 +115,17 @@ // problem mit "In/IN which/WDT films/NNS did/VBD Julia/NNP Roberts/NNP as/RB well/RB as/IN Richard/NNP Gere/NNP play/NN" public class SPARQLTemplateBasedLearner3Test { - protected static final boolean USE_HMM = false; + protected static final boolean USE_HMM = true; protected static final File evaluationFolder = new File("cache/evaluation"); protected static final boolean DBPEDIA_PRETAGGED = true; protected static final boolean OXFORD_PRETAGGED = false; - protected static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; + protected static final int MAX_NUMBER_OF_QUESTIONS = 100; protected static final boolean WHITELIST_ONLY = false; protected static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); protected static final boolean GENERATE_HTML_ONLY = false; protected static final int MAX_THREADS = 10; - @Test public void testDBpedia() throws Exception + /*@Test*/ public void testDBpedia() throws Exception { File file = generateTestDataIfNecessary( new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml").getFile()), @@ -244,10 +244,6 @@ // "<td><ul>"+getAnswerHTMLList(evaluation.referenceData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ // "<td>"+evaluation.testData.id2LearnStatus.get(id)+"</td></tr>"); - - - - logger.info(questionsOnlyCorrectWithHMM.size()+" questions only correct with hmm, "+ questionsOnlyCorrectWithoutHMM.size()+" questions only correct without hmm"); @@ -256,7 +252,7 @@ out.close(); } - /*@Test*/ public void testOxford() throws Exception + @Test public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex(),OXFORD_PRETAGGED); @@ -362,39 +358,37 @@ public static Model loadOxfordModel() { // load it into a model because we can and it's faster and doesn't rely on endpoint availability - // the files are located in the paper svn under question-answering-iswc-2012/data + // the files are located in the paper svn under http://diadem.cs.ox.ac.uk/svn/papers/oxpath/question-answering-iswc-2012/data/ and data_v2 // ls *ttl | xargs -I @ echo \"@\", + //find -type f | sed -r "s|\./(.*)|\"\1\",|" final String[] rdf = { - "abbeys-sales-triple.ttl", - "andrewsonline-sales-triple.ttl", - "anker-sales-triple.ttl", - "bairstoweves-sales-triple.ttl", - "ballards-sales-triple.ttl", - "breckon-sales-triple.ttl", - "buckellandballard-sales-triple.ttl", - "carterjonas-sales.ttl", - "churchgribben-salse-triple.ttl", - "findaproperty-sales-triple.ttl", - "johnwood-sales-triple.ttl", - "martinco-letting-triples.ttl", - "scottfraser-letting-triples.ttl", - "scottfraser-sales-triples.ttl", - "scottsymonds-sales-triple.ttl", - "scrivenerandreinger-sales-triple.ttl", - "sequencehome-sales-triple.ttl", - "teampro-sales.ttl", - "thomasmerrifield-sales-triples.ttl", - "wwagency-letting-triple_with-XSD.ttl", - "wwagency-sales-triple_with-XSD.ttl", - // ls links/*ttl | xargs -I @ echo \"@\", - "links/allNear.ttl", - "links/all_walking_distance.ttl", - "links/lgd_data.ttl", - // ls schema/* | xargs -I @ echo \"@\", - "schema/goodRelations.owl", - "schema/LGD-Dump-110406-Ontology.nt", - "schema/ontology.ttl", - "schema/vCard.owl" + "andrewsonline-sales-triple.ttl", + "johnwood-sales-triple.ttl", + "wwagency.ttl", + "findaproperty-sales-triple.ttl", + "carterjonas-sales.ttl", + "breckon.ttl", + "sequencehome.ttl", + "schema/ontology.ttl", + "schema/goodRelations.owl", + "schema/vCard.owl", + "schema/LGD-Dump-110406-Ontology.nt", + "hodson.ttl", + "thomasmerrifield.ttl", + "churchgribben.ttl", + "bairstoweves-sales-triple.ttl", + "anker.ttl", + "martinco-letting-triples.ttl", + "scrivenerandreinger.ttl", + "ballards.ttl", + "teamprop.ttl", + "abbeys-sales-triple.ttl", + "links/ontology.ttl", + "links/lgd_data.ttl", + "links/allNear.ttl", + "links/all_walking_distance.ttl", + "scottsymonds.ttl", + "scottfraser.ttl" }; Model m = ModelFactory.createDefaultModel(); for(final String s:rdf) @@ -810,7 +804,7 @@ String question = id2Question.get(i); try { - testData.id2LearnStatus.put(i,futures.get(i).get(30, TimeUnit.SECONDS)); + testData.id2LearnStatus.put(i,futures.get(i).get(USE_HMM?120:30, TimeUnit.SECONDS)); } catch (InterruptedException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-08 18:25:55
|
Revision: 3869 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3869&view=rev Author: kirdie Date: 2012-11-08 18:25:48 +0000 (Thu, 08 Nov 2012) Log Message: ----------- improvement of new learner. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-07 18:13:41 UTC (rev 3868) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-08 18:25:48 UTC (rev 3869) @@ -76,6 +76,7 @@ import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.reasoning.SPARQLReasoner; import org.ini4j.Options; +import org.openjena.atlas.logging.Log; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.util.SimpleIRIShortFormProvider; import com.hp.hpl.jena.ontology.OntModelSpec; @@ -654,27 +655,9 @@ if(templates.isEmpty()) throw new AssertionError("no templates"); templates = goodTemplates(templates); if(templates.isEmpty()) throw new AssertionError("no good templates"); - - Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { + logger.debug(templates.size()+" good templates found."); + Map<Slot, Set<Allocation>> slot2Allocations = Collections.synchronizedSortedMap(new TreeMap<Slot, Set<Allocation>>()); - @Override - public int compare(Slot o1, Slot o2) { - System.err.println(o1.getToken()); - System.err.println(o2.getToken()); - if(o1.getToken().equalsIgnoreCase("river")||o2.getToken().equalsIgnoreCase("river")) - { - int nop = 5; - System.err.println(nop); - } - if(o1.getSlotType() == o2.getSlotType()){ - return o1.getToken().compareTo(o2.getToken()); - } else { - return -1; - } - } - }); -// slot2Allocations = Collections.synchronizedMap(slot2Allocations); - SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); @@ -725,31 +708,25 @@ // Set<Allocation> allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); - ExecutorService executor = Executors.newSingleThreadExecutor();//Executors.newFixedThreadPool(t.getSlots().size()); - List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); + ExecutorService executor = Executors.newSingleThreadExecutor();//Executors.newFixedThreadPool(t.getSlots().size()); long startTime = System.currentTimeMillis(); - + Map<Future,Slot> futureToSlot = new HashMap<Future,Slot>(); + for (Slot slot : t.getSlots()) { if(!slot2Allocations.containsKey(slot)){ - Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); - Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); - list.add(submit); + Callable<SortedSet<Allocation>> worker = new SlotProcessor(slot); + Future<SortedSet<Allocation>> submit = executor.submit(worker); + futureToSlot.put(submit, slot); } } - for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { + for (Future<SortedSet<Allocation>> future : futureToSlot.keySet()) + { try { - Map<Slot, SortedSet<Allocation>> result = future.get(); - - Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); - slot2Allocations.put(item.getKey(), item.getValue()); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { -// e.printStackTrace(); - throw new RuntimeException(e); - } + SortedSet<Allocation> result = future.get(); + slot2Allocations.put(futureToSlot.get(future), result); + } catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();throw new RuntimeException(e);} } executor.shutdown(); @@ -1393,19 +1370,18 @@ } /** Computes candidates for a slot by using an index. * */ - class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ + class SlotProcessor implements Callable<SortedSet<Allocation>> + { + public final Slot slot; - private Slot slot; - public SlotProcessor(Slot slot) { this.slot = slot; } @Override - public Map<Slot, SortedSet<Allocation>> call() throws Exception { - Map<Slot, SortedSet<Allocation>> result = new HashMap<Slot, SortedSet<Allocation>>(); - result.put(slot, computeAllocations(slot)); - return result; + public SortedSet<Allocation> call() throws Exception + { + return computeAllocations(slot); } private SortedSet<Allocation> computeAllocations(Slot slot){ Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-07 18:13:41 UTC (rev 3868) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-08 18:25:48 UTC (rev 3869) @@ -115,31 +115,32 @@ // problem mit "In/IN which/WDT films/NNS did/VBD Julia/NNP Roberts/NNP as/RB well/RB as/IN Richard/NNP Gere/NNP play/NN" public class SPARQLTemplateBasedLearner3Test { - private static final boolean USE_HMM = false; - private static final File evaluationFolder = new File("cache/evaluation"); - private static final boolean DBPEDIA_PRETAGGED = true; - private static final boolean OXFORD_PRETAGGED = false; - private static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; - private static final boolean WHITELIST_ONLY = false; - private static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); - private static final boolean GENERATE_HTML_ONLY = false; + protected static final boolean USE_HMM = false; + protected static final File evaluationFolder = new File("cache/evaluation"); + protected static final boolean DBPEDIA_PRETAGGED = true; + protected static final boolean OXFORD_PRETAGGED = false; + protected static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; + protected static final boolean WHITELIST_ONLY = false; + protected static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); + protected static final boolean GENERATE_HTML_ONLY = false; + protected static final int MAX_THREADS = 10; @Test public void testDBpedia() throws Exception { File file = generateTestDataIfNecessary( new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml").getFile()), - SparqlEndpoint.getEndpointDBpedia(), + SparqlEndpoint.getEndpointDBpediaLiveAKSW(), dbpediaLiveCache); test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null,DBPEDIA_PRETAGGED); } - // private char[] hmmHtmlRow(String question, String string, String string2, String string3, Set<String> set, Set<String> set2, + // protected char[] hmmHtmlRow(String question, String string, String string2, String string3, Set<String> set, Set<String> set2, // Set<String> set3, LearnStatus learnStatus, LearnStatus learnStatus2) // { // return null; // } - private static boolean probablySparqlSelectQuery(String s) + protected static boolean probablySparqlSelectQuery(String s) { s=s.toLowerCase(); return s.contains("select")&&s.contains("{")&&s.contains("}"); @@ -149,7 +150,7 @@ * transformed by escaping HTML characters, setting fixed width on SPARQL queries and shortening and linking of dbpedia resource URIs. */ // unescaped form from the top: <tr><td>t(o_1)</td>...<td>t(o_n)</td></tr> - private static String htmlTableTr(Object... tds) + protected static String htmlTableTr(Object... tds) { System.out.println(); StringBuilder sb = new StringBuilder(); @@ -461,7 +462,7 @@ learnedTestData.write();*/ } - private File generateTestDataIfNecessary(final File referenceXML,final SparqlEndpoint endpoint,ExtractionDBCache cache) throws ParserConfigurationException, SAXException, IOException, TransformerException + protected File generateTestDataIfNecessary(final File referenceXML,final SparqlEndpoint endpoint,ExtractionDBCache cache) throws ParserConfigurationException, SAXException, IOException, TransformerException { String dir = "cache/"+getClass().getSimpleName()+"/"; new File(dir).mkdirs(); @@ -475,7 +476,7 @@ return updatedReferenceXML; } - private void evaluateAndWrite(String title,final File updatedReferenceXML, final SparqlEndpoint endpoint,ExtractionDBCache cache, + protected void evaluateAndWrite(String title,final File updatedReferenceXML, final SparqlEndpoint endpoint,ExtractionDBCache cache, Knowledgebase kb, Model model, MappingBasedIndex index,boolean pretagged) { @@ -498,7 +499,7 @@ * @param reference the test data assumed to be correct. needs to contain the answers for all queries. * @param suspect the test data to compare with the reference. * if a query for a question does not match and the answers are not provided or don't match as well then the question is marked as incorrectly answered.*/ - private static Evaluation evaluate(QueryTestData reference, QueryTestData suspect) + protected static Evaluation evaluate(QueryTestData reference, QueryTestData suspect) { // Diff d = diffTestData(reference,testData); Evaluation evaluation = new Evaluation(suspect,reference); @@ -560,7 +561,7 @@ static class Evaluation implements Serializable { - private static final long serialVersionUID = 6L; + protected static final long serialVersionUID = 6L; final QueryTestData testData; final QueryTestData referenceData; int numberOfQuestions = 0; @@ -640,7 +641,7 @@ return evaluations; } - private static Evaluation read(File file) + protected static Evaluation read(File file) { try { @@ -739,7 +740,7 @@ public final Type type; - private static final long serialVersionUID = 1L; + protected static final long serialVersionUID = 1L; public static final LearnStatus OK = new LearnStatus(Type.OK,null); public static final LearnStatus TIMEOUT = new LearnStatus(Type.TIMEOUT,null); public static final LearnStatus NO_TEMPLATE_FOUND = new LearnStatus(Type.NO_TEMPLATE_FOUND,null); @@ -748,7 +749,7 @@ public final Exception exception; - private LearnStatus(Type type, Exception exception) {this.type=type;this.exception = exception;} + protected LearnStatus(Type type, Exception exception) {this.type=type;this.exception = exception;} public static LearnStatus exceptionStatus(Exception cause) { @@ -782,7 +783,7 @@ * @throws MalformedURLException * @throws ComponentInitException */ - private QueryTestData generateTestDataMultiThreaded(SortedMap<Integer, String> id2Question,Knowledgebase kb,Model model, MappingBasedIndex index,boolean pretagged) + protected QueryTestData generateTestDataMultiThreaded(SortedMap<Integer, String> id2Question,Knowledgebase kb,Model model, MappingBasedIndex index,boolean pretagged) { QueryTestData testData = new QueryTestData(); testData.hmm = USE_HMM; @@ -797,7 +798,7 @@ Map<Integer,Future<LearnStatus>> futures = new HashMap<Integer,Future<LearnStatus>>(); // List<FutureTask> todo = new ArrayList<FutureTask>(id2Question.size()); - ExecutorService service = Executors.newCachedThreadPool();// newFixedThreadPool(1); + ExecutorService service = Executors.newFixedThreadPool(MAX_THREADS); for(int i: id2Question.keySet()) {//if(i != 78)continue; @@ -809,7 +810,7 @@ String question = id2Question.get(i); try { - testData.id2LearnStatus.put(i,futures.get(i).get(30, TimeUnit.MINUTES)); + testData.id2LearnStatus.put(i,futures.get(i).get(30, TimeUnit.SECONDS)); } catch (InterruptedException e) { @@ -868,7 +869,7 @@ * @throws SAXException * @throws TransformerException */ - private void generateUpdatedXML(File originalFile, File updatedFile,SparqlEndpoint endpoint, ExtractionDBCache cache,Model model) throws ParserConfigurationException, SAXException, IOException, TransformerException + protected void generateUpdatedXML(File originalFile, File updatedFile,SparqlEndpoint endpoint, ExtractionDBCache cache,Model model) throws ParserConfigurationException, SAXException, IOException, TransformerException { logger.info(String.format("Updating question file \"%s\" by removing questions without nonempty resource list answer and adding answers.\n" + " Saving the result to file \"%s\"",originalFile.getPath(),updatedFile.getPath())); @@ -951,31 +952,30 @@ // } } - int correctMatches = 0; int numberOfNoTemplateFoundExceptions = 0; int numberOfOtherExceptions = 0; // int successfullTestThreadRuns = 0; /** */ - // private static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; + // protected static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; private static final Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); - // private SPARQLTemplateBasedLearner2 oxfordLearner; - // private SPARQLTemplateBasedLearner2 dbpediaLiveLearner; + // protected SPARQLTemplateBasedLearner2 oxfordLearner; + // protected SPARQLTemplateBasedLearner2 dbpediaLiveLearner; - // private final ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); - private final static ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); + // protected final ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); + protected final static ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); - private final Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); + protected final Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); static final SparqlEndpoint dbpediaLiveEndpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); //static SparqlEndpoint oxfordEndpoint; - // private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} + // protected ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} - private static boolean httpResponseOK(String url) throws MalformedURLException, IOException + protected static boolean httpResponseOK(String url) throws MalformedURLException, IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("HEAD"); @@ -1041,7 +1041,7 @@ testIndex(dbpedia.getPropertyIndex(),new String[][] {{"born in","http://dbpedia.org/ontology/birthPlace"}}); } - private static Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) + protected static Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) { // for(String url : new String[] {resourcesURL,classesURL,propertiesURL,boaPropertiesURL}) @@ -1138,7 +1138,7 @@ return uris; } - private static String urlDecode(String url){ + protected static String urlDecode(String url){ String decodedURL = null; try { decodedURL = URLDecoder.decode(url, "UTF-8"); @@ -1150,7 +1150,7 @@ } - // private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} + // protected ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} // @Test public void benchmarkCreateOxfordKnowledgeBase() // { @@ -1164,7 +1164,7 @@ // System.out.println(diff+" millis as a whole, "+diff/1000.0+" millis per run"); // } - // private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) + // protected Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) // { // URL url; // try{url = new URL("http://lgd.aksw.org:8900/sparql");} catch(Exception e) {throw new RuntimeException(e);} @@ -1186,19 +1186,19 @@ // } /** @author konrad * Learns a query for a question and puts it into the given testData object. * */ - private static class LearnQueryCallable implements Callable<LearnStatus> + protected static class LearnQueryCallable implements Callable<LearnStatus> { - private final String question; - // private final String endpoint; - private final int id; - private final QueryTestData testData; + protected final String question; + // protected final String endpoint; + protected final int id; + protected final QueryTestData testData; - static private class POSTaggerHolder + static protected class POSTaggerHolder {static public final PartOfSpeechTagger posTagger = new SynchronizedStanfordPartOfSpeechTagger();} - static private final WordNet wordnet = new WordNet(); - static private final Options options = new Options(); - private final SPARQLTemplateBasedLearner2 learner; + static protected final WordNet wordnet = new WordNet(); + static protected final Options options = new Options(); + protected final SPARQLTemplateBasedLearner2 learner; public LearnQueryCallable(String question, int id, QueryTestData testData, Knowledgebase knowledgeBase,boolean pretagged) { @@ -1294,9 +1294,9 @@ return sb.toString(); } - private static String escapePre(String s) {return s.replace("<", "<").replace(">", ">");} + protected static String escapePre(String s) {return s.replace("<", "<").replace(">", ">");} - private static String getAnswerHTMLList(String[] answers) + protected static String getAnswerHTMLList(String[] answers) { StringBuilder sbAnswers = new StringBuilder(); final int MAX = 10; @@ -1327,7 +1327,7 @@ /** Generates the HTML string content for one of the 4 colored bars which represent the correctly, incorrectly and unanswered question. * Also creates and links to a file which contains the questions.*/ - private static String createColoredColumn(/*@NonNull*/ File link,/*@NonNull*/ String title,/*@NonNull*/ String color,/*@NonNull*/ Collection<String> questions, int numberOfQuestionsTotal, boolean queriesAvailable,boolean jaccard, Evaluation evaluation) + protected static String createColoredColumn(/*@NonNull*/ File link,/*@NonNull*/ String title,/*@NonNull*/ String color,/*@NonNull*/ Collection<String> questions, int numberOfQuestionsTotal, boolean queriesAvailable,boolean jaccard, Evaluation evaluation) { final StringBuilder sb = new StringBuilder(); sb.append("<a href='"+link.getAbsolutePath()+"' title='"+title+" ("+questions.size()+"/"+(numberOfQuestionsTotal==0?"":numberOfQuestionsTotal)+")'>"); @@ -1465,13 +1465,13 @@ } catch (Exception e){throw new RuntimeException(e);} } - // private void updateFile(File originalFile, File updatedFile, String endpoint) + // protected void updateFile(File originalFile, File updatedFile, String endpoint) // { // // // } - // private void test(File file) throws MalformedURLException, InterruptedException + // protected void test(File file) throws MalformedURLException, InterruptedException // { // SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); // SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); @@ -1547,5 +1547,5 @@ // //fail("Not yet implemented"); // } - private static ResultSet executeSelect(SparqlEndpoint endpoint, String query, ExtractionDBCache cache){return SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query));} + protected static ResultSet executeSelect(SparqlEndpoint endpoint, String query, ExtractionDBCache cache){return SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query));} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-07 18:13:53
|
Revision: 3868 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3868&view=rev Author: kirdie Date: 2012-11-07 18:13:41 +0000 (Wed, 07 Nov 2012) Log Message: ----------- fixed a bug with a comparator used for a treeset with slots and integrated this comparator into the Slot class. Also started a new version of the getWeightedSPARQLQueries(). Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-02 17:47:38 UTC (rev 3867) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-07 18:13:41 UTC (rev 3868) @@ -15,6 +15,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; @@ -98,7 +99,7 @@ /** The minimum score of items that are accepted from the Sindice search BOA index. **/ private static final Double BOA_THRESHOLD = 0.5; enum Mode {BEST_QUERY, BEST_NON_EMPTY_QUERY} - private Mode mode = Mode.BEST_QUERY; + private Mode mode = Mode.BEST_NON_EMPTY_QUERY; /** used to create a label out of the URI when there is no label available in the SPARQL endpoint.*/ private static SimpleIRIShortFormProvider sfp = new SimpleIRIShortFormProvider(); @@ -521,6 +522,7 @@ private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates, boolean hmm) { +// return getWeightedSPARQLQueriesNew(templates); return hmm?getWeightedSPARQLQueriesWithHMM(templates):getWeightedSPARQLQueriesWithoutHMM(templates); } @@ -628,14 +630,42 @@ // return queries; } - - @SuppressWarnings("unused") private SortedSet<WeightedQuery> getWeightedSPARQLQueriesWithoutHMM(Set<Template> templates){ - logger.debug("Generating SPARQL query candidates..."); - + + /** removes templates which have empty slots */ + protected Set<Template> goodTemplates(Set<Template> templates) + { + Set<Template> remainingTemplates = new HashSet<Template>(); + templates: + for(Template t: templates) + { + for (Slot slot : t.getSlots()) {if(slot.getWords().isEmpty()) {continue templates;} } + remainingTemplates.add(t); + } + return remainingTemplates; + } + + /** There seems to be a bug in the other getWeightedSPARQLQueries... functions, so this is a new implementation + */ + protected SortedSet<WeightedQuery> getWeightedSPARQLQueriesNew(Set<Template> templates) + { + logger.debug("Generating SPARQL query candidates (new implementation)..."); + + List<String> vars = new LinkedList<String>(); + if(templates.isEmpty()) throw new AssertionError("no templates"); + templates = goodTemplates(templates); + if(templates.isEmpty()) throw new AssertionError("no good templates"); + Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { @Override public int compare(Slot o1, Slot o2) { + System.err.println(o1.getToken()); + System.err.println(o2.getToken()); + if(o1.getToken().equalsIgnoreCase("river")||o2.getToken().equalsIgnoreCase("river")) + { + int nop = 5; + System.err.println(nop); + } if(o1.getSlotType() == o2.getSlotType()){ return o1.getToken().compareTo(o2.getToken()); } else { @@ -643,18 +673,59 @@ } } }); - slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); +// slot2Allocations = Collections.synchronizedMap(slot2Allocations); + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); + + SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); + + for(Template t : templates) + { +// logger.debug("Processing template:\n" + t.toString()); + for (Slot slot : t.getSlots()) + { + // get candidates for slot + if(!slot2Allocations.containsKey(slot)) + { + slot2Allocations.put(slot,new SlotProcessor(slot).computeAllocations(slot)); + } + } + } + logger.info(slot2Allocations.size()+" allocations: "+slot2Allocations); + + if(1==1) System.exit(1); + return queries; + } + @SuppressWarnings("unused") private SortedSet<WeightedQuery> getWeightedSPARQLQueriesWithoutHMM(Set<Template> templates){ + logger.debug("Generating SPARQL query candidates..."); + + SortedMap<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(); +// new Comparator<Slot>() { +// +// @Override +// public int compare(Slot o1, Slot o2) { +// if(o1.equals(o2)) return 0; +// return -1; +//// if(o1.getSlotType() == o2.getSlotType()){ +//// return o1.getToken().compareTo(o2.getToken()); +//// } else { +//// return -1; +//// } +// } +// }); + slot2Allocations = Collections.synchronizedSortedMap(slot2Allocations); + + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); for(Template t : templates) { - logger.info("Processing template:\n" + t.toString()); + logger.debug("Processing template:\n" + t.toString()); // Set<Allocation> allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); - ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); + ExecutorService executor = Executors.newSingleThreadExecutor();//Executors.newFixedThreadPool(t.getSlots().size()); List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); long startTime = System.currentTimeMillis(); @@ -670,7 +741,8 @@ for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { try { Map<Slot, SortedSet<Allocation>> result = future.get(); - Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); + + Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); slot2Allocations.put(item.getKey(), item.getValue()); } catch (InterruptedException e) { e.printStackTrace(); @@ -743,9 +815,22 @@ queries.clear(); queries.addAll(tmp); tmp.clear(); - } + } - for(Slot slot : sortedSlots){ + Set<Slot> unhandledSlots = new HashSet<Slot>(sortedSlots); + unhandledSlots.removeAll(slot2Allocations.keySet()); + if(!unhandledSlots.isEmpty()) + { + logger.error("the following slots are unhandled: "+unhandledSlots); + } + for(Slot slot : sortedSlots) + { + Set<Allocation> allocations = slot2Allocations.get(slot); + if(allocations==null) + { + System.err.println("no allocations for slot "+slot); + + } if(!slot2Allocations.get(slot).isEmpty()){ for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ @@ -832,9 +917,10 @@ if(!drop){ if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ SPARQL_Value object = triple.getValue(); -// if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position // SPARQL_Property predicate = triple.getProperty(); // if(!predicate.isVariable()){//only consider triple where predicate is URI // String predicateURI = predicate.getName().replace("<", "").replace(">", ""); @@ -849,7 +935,7 @@ // } // } else { // -// } + } } } else { q.replaceVarWithURI(slot.getAnchor(), a.getUri()); @@ -1306,6 +1392,7 @@ return indexResultItems; } + /** Computes candidates for a slot by using an index. * */ class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ private Slot slot; @@ -1322,7 +1409,7 @@ } private SortedSet<Allocation> computeAllocations(Slot slot){ - logger.debug("Computing allocations for slot: " + slot); + logger.trace("Computing allocations for slot: " + slot); SortedSet<Allocation> allocations = new TreeSet<Allocation>(); Index index = getIndexBySlotType(slot); @@ -1378,7 +1465,7 @@ normProminenceValues(allocations); computeScore(allocations); - logger.debug("Found " + allocations.size() + " allocations for slot " + slot); + logger.trace(allocations.size() + " allocations for slot " + slot); return new TreeSet<Allocation>(allocations); } Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-11-02 17:47:38 UTC (rev 3867) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-11-07 18:13:41 UTC (rev 3868) @@ -762,7 +762,7 @@ learnedPos++; List<String> results; try { - logger.info("Testing query:\n" + query); + logger.debug("Testing query:\n" + query); com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); q.setLimit(1); ResultSet rs = executeSelect(q.toString()); @@ -805,7 +805,7 @@ } else if(queryType == SPARQL_QueryType.ASK){ for(WeightedQuery query : queries){ learnedPos++; - logger.info("Testing query:\n" + query); + logger.debug("Testing query:\n" + query); boolean result = executeAskQuery(query.getQuery().toString()); learnedSPARQLQueries.add(query); // if(stopIfQueryResultNotEmpty && result){ Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java 2012-11-02 17:47:38 UTC (rev 3867) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Slot.java 2012-11-07 18:13:41 UTC (rev 3868) @@ -5,7 +5,7 @@ import java.util.Iterator; import java.util.List; -public class Slot implements Serializable{ +public class Slot implements Serializable, Comparable<Slot> { private static final long serialVersionUID = 8672756914248710435L; @@ -164,7 +164,7 @@ if (getClass() != obj.getClass()) return false; Slot other = (Slot) obj; - if(other.type == type && other.token == token){ + if(other.type == type && other.token.equals(token)){ return true; } return false; @@ -178,6 +178,23 @@ result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } + + @Override + public int compareTo(Slot o) + { + if(this.equals(o)) return 0; + // sort by slot type + int t = type.compareTo(o.type); + if(t!=0) return t; + return token.compareTo(o.token); + // sort by + +// if(o1.getSlotType() == o2.getSlotType()){ +// return o1.getToken().compareTo(o2.getToken()); +// } else { +// return -1; +// } + } } Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-02 17:47:38 UTC (rev 3867) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-07 18:13:41 UTC (rev 3868) @@ -1,6 +1,6 @@ package org.dllearner.algorithm.tbsl.learning; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.BufferedReader; import java.io.File; @@ -11,7 +11,6 @@ import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.OutputStream; import java.io.PrintWriter; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -24,6 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -31,8 +31,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; +import java.util.SortedSet; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; @@ -117,9 +119,10 @@ private static final File evaluationFolder = new File("cache/evaluation"); private static final boolean DBPEDIA_PRETAGGED = true; private static final boolean OXFORD_PRETAGGED = false; - private static final int MAX_NUMBER_OF_QUESTIONS = 20; - private static final boolean WHITELIST_ONLY = true; + private static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; + private static final boolean WHITELIST_ONLY = false; private static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); + private static final boolean GENERATE_HTML_ONLY = false; @Test public void testDBpedia() throws Exception { @@ -430,7 +433,7 @@ public void test(String title, final File referenceXML,final SparqlEndpoint endpoint,ExtractionDBCache cache,Knowledgebase kb, Model model, MappingBasedIndex index,boolean pretagged) throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException { - evaluateAndWrite(title,referenceXML,endpoint,cache,kb,model,index,pretagged); + if(!GENERATE_HTML_ONLY) {evaluateAndWrite(title,referenceXML,endpoint,cache,kb,model,index,pretagged);} generateHTML(title); // if(evaluation.numberOfCorrectAnswers<3) {fail("only " + evaluation.numberOfCorrectAnswers+" correct answers.");} @@ -529,12 +532,27 @@ { evaluation.correctlyAnsweredQuestions.add(question); evaluation.numberOfCorrectAnswers++; + evaluation.question2JaccardOfAnswers.put(question,1.0); } else { - evaluation.incorrectlyAnsweredQuestions.add(question); - logger.debug("learned queries differing. reference query:\n"+referenceQuery+"\nsuspect query:\n"+suspectQuery); - logger.debug("learned answers differing: reference answers:\n"+reference.id2Answers.get(i)+"\nsuspect answers:\n"+suspect.id2Answers.get(i)); + Set<String> intersection = new HashSet<String>(reference.id2Answers.get(i)); + intersection.retainAll(suspect.id2Answers.get(i)); + if(!intersection.isEmpty()) + { + evaluation.partlyCorrectlyAnsweredQuestions.add(question); + evaluation.numberOfPartlyCorrectAnswers++; + Set<String> union = new HashSet<String>(reference.id2Answers.get(i)); + union.addAll(suspect.id2Answers.get(i)); + evaluation.question2JaccardOfAnswers.put(question,((double)intersection.size())/union.size()); + } else + { + evaluation.incorrectlyAnsweredQuestions.add(question); + evaluation.question2JaccardOfAnswers.put(question,0.0); + logger.debug("learned queries differing. reference query:\n"+referenceQuery+"\nsuspect query:\n"+suspectQuery); + logger.debug("learned answers differing: reference answers:\n"+reference.id2Answers.get(i)+"\nsuspect answers:\n"+suspect.id2Answers.get(i)); + } + } } return evaluation; @@ -542,18 +560,22 @@ static class Evaluation implements Serializable { - private static final long serialVersionUID = 5L; + private static final long serialVersionUID = 6L; final QueryTestData testData; final QueryTestData referenceData; int numberOfQuestions = 0; - int numberOfAnsweredQuestions = 0; + int numberOfAnsweredQuestions = 0; int numberOfCorrectAnswers = 0; + int numberOfPartlyCorrectAnswers = 0; double precision = 0; double recall = 0; final Set<String> unansweredQuestions = new HashSet<String>(); final Set<String> incorrectlyAnsweredQuestions = new HashSet<String>(); - final Set<String> correctlyAnsweredQuestions = new HashSet<String>(); + final Set<String> correctlyAnsweredQuestions = new HashSet<String>(); + final Set<String> partlyCorrectlyAnsweredQuestions = new HashSet<String>(); + final Map<String,Double> question2JaccardOfAnswers = new HashMap<String,Double>(); + public Evaluation(QueryTestData testData,QueryTestData referenceData) {this.testData = testData;this.referenceData = referenceData;} void computePrecisionAndRecall() // we have at maximum one answer set per question @@ -566,7 +588,7 @@ { StringBuffer sb = new StringBuffer(); sb.append(numberOfAnsweredQuestions+" of "+numberOfQuestions+" questions answered, "); - sb.append(numberOfCorrectAnswers+" correct answers."); + sb.append(numberOfCorrectAnswers+" exactly correct answers, "+numberOfPartlyCorrectAnswers+" partly correct answers."); sb.append("precision: "+precision+", recall: "+recall+"\n"); sb.append("Detailed List: "); sb.append(toHTML()); @@ -578,6 +600,7 @@ StringBuffer sb = new StringBuffer(); sb.append(htmlDetailsList("Unanswered Questions",unansweredQuestions)); sb.append(htmlDetailsList("Wrongly Answered Questions",incorrectlyAnsweredQuestions)); + sb.append(htmlDetailsList("Partly correctly Answered Questions",partlyCorrectlyAnsweredQuestions)); sb.append(htmlDetailsList("Correctly Answered Questions",correctlyAnsweredQuestions)); return sb.toString(); } @@ -640,6 +663,13 @@ if (other.correctlyAnsweredQuestions != null) return false; } else if (!correctlyAnsweredQuestions.equals(other.correctlyAnsweredQuestions)) return false; + + if (partlyCorrectlyAnsweredQuestions == null) + { + if (other.partlyCorrectlyAnsweredQuestions != null) return false; + } + else if (!partlyCorrectlyAnsweredQuestions.equals(other.partlyCorrectlyAnsweredQuestions)) return false; + if (incorrectlyAnsweredQuestions == null) { if (other.incorrectlyAnsweredQuestions != null) return false; @@ -1000,14 +1030,14 @@ assertTrue(entities[i][1]+"!="+uri+" "+items,entities[i][1].equals(uri)||entities[i][1].equals(secondUri)); } } - + /*@Test*/ public void testSolrGoodResults() { Knowledgebase dbpedia = createDBpediaLiveKnowledgebase(dbpediaLiveCache); - + testIndex(dbpedia.getResourceIndex(),new String[][] {{"Brooklyn Bridge","http://dbpedia.org/resource/Brooklyn_Bridge"},{"Estonia","http://dbpedia.org/resource/Estonia"}, - {"Germany","http://dbpedia.org/resource/Germany"}}); + {"Germany","http://dbpedia.org/resource/Germany"}}); testIndex(dbpedia.getPropertyIndex(),new String[][] {{"born in","http://dbpedia.org/ontology/birthPlace"}}); } @@ -1282,16 +1312,38 @@ return sbAnswers.toString(); } - /** Generates the HTML string content for one of the 3 colored bars which represent the correctly, incorrectly and unanswered question. + static <K,V extends Comparable<? super V>> SortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map) { + SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>( + new Comparator<Map.Entry<K,V>>() { + @Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) { + int res = e1.getValue().compareTo(e2.getValue()); + return res != 0 ? res : 1; // Special fix to preserve items with equal values + } + } + ); + sortedEntries.addAll(map.entrySet()); + return sortedEntries; + } + + /** Generates the HTML string content for one of the 4 colored bars which represent the correctly, incorrectly and unanswered question. * Also creates and links to a file which contains the questions.*/ - private static String createColoredColumn(/*@NonNull*/ File link,/*@NonNull*/ String title,/*@NonNull*/ String color,/*@NonNull*/ Collection<String> questions, int numberOfQuestionsTotal, boolean queriesAvailable, Evaluation evaluation) + private static String createColoredColumn(/*@NonNull*/ File link,/*@NonNull*/ String title,/*@NonNull*/ String color,/*@NonNull*/ Collection<String> questions, int numberOfQuestionsTotal, boolean queriesAvailable,boolean jaccard, Evaluation evaluation) { final StringBuilder sb = new StringBuilder(); - sb.append("<a href='"+link.getAbsolutePath()+"' title='"+title+"'>"); + sb.append("<a href='"+link.getAbsolutePath()+"' title='"+title+" ("+questions.size()+"/"+(numberOfQuestionsTotal==0?"":numberOfQuestionsTotal)+")'>"); sb.append("<div style='float:left;width:"+100.0*questions.size()/numberOfQuestionsTotal+"%;height:1em;background-color:"+color+";'></div>"); sb.append("</a>"); + // link.getParentFile().mkdirs(); + Collection<String> sortedQuestions; + if(jaccard) // sort by jaccard descending + { + sortedQuestions = new LinkedList<String>(); + SortedMap<String,Double> map = new TreeMap<String,Double>(); + for(String question : questions) {map.put(question, 1-evaluation.question2JaccardOfAnswers.get(question));} - // link.getParentFile().mkdirs(); + for(Entry<String,Double> e: entriesSortedByValues(map)) {sortedQuestions.add(e.getKey());} + } else sortedQuestions = questions; + try { PrintWriter out = new PrintWriter(link); @@ -1301,8 +1353,9 @@ out.println("<!DOCTYPE html><html>\n<head><title>"+title+"</title></head>\n<body>\n<table border='1'>"); if(queriesAvailable) { - out.println("<tr><th>Question</th><th>Learned Query</th><th>Reference Query</th><th>Learned Answers</th><th>Reference Answers</th><th>Error Type</th></tr>"); - for(String question: questions) + out.println("<tr><th>Question</th><th>Learned Query</th><th>Reference Query</th><th>Learned Answers</th><th>Reference Answers</th><th>Error Type</th>"+ + (jaccard?"<th>jaccard</th>":"")+"</tr>"); + for(String question: sortedQuestions) { Integer id = question2Id.get(question); if(evaluation.testData.id2Answers.get(id)==null) {System.err.println(question);continue;} @@ -1312,12 +1365,13 @@ "<td><code><pre>"+escapePre(evaluation.referenceData.id2Query.get(id))+"</pre></code></td>"+ "<td><ul>"+getAnswerHTMLList(evaluation.testData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ "<td><ul>"+getAnswerHTMLList(evaluation.referenceData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ - "<td>"+evaluation.testData.id2LearnStatus.get(id)+"</td></tr>"); + "<td>"+evaluation.testData.id2LearnStatus.get(id)+"</td>"+ + "<td>"+(jaccard?evaluation.question2JaccardOfAnswers.get(question):"")+"</td></tr>"); } } else - { + { out.println("<tr><th>Question</th><th>Error Type</th></tr>"); - for(String question: questions) + for(String question: sortedQuestions) { Integer id = question2Id.get(question); if(id==null) {System.err.println(question);continue;} @@ -1350,6 +1404,7 @@ out.println("</style></head>"); out.println("<body>"); out.println(diffHTML("Correctly Answered Questions (precision and recall = 1)", from.correctlyAnsweredQuestions, to.correctlyAnsweredQuestions)); + out.println(diffHTML("Partly correctly Answered Questions", from.partlyCorrectlyAnsweredQuestions, to.partlyCorrectlyAnsweredQuestions)); out.println(diffHTML("Incorrectly Answered Questions", from.incorrectlyAnsweredQuestions, to.incorrectlyAnsweredQuestions)); out.println(diffHTML("Unanswered Questions", from.unansweredQuestions, to.unansweredQuestions)); out.println("</body>\n</html>"); @@ -1390,9 +1445,10 @@ } sb2.append("</td><td width='100%'>"); sb2.append("<div style='width:100%;height:1em;border:solid 1px;'>"); - sb2.append(createColoredColumn(new File(folder,"correctly_answered.html"), "Correctly Answered Questions", "green", e.correctlyAnsweredQuestions, e.numberOfQuestions,true,e)); - sb2.append(createColoredColumn(new File(folder,"incorrectly_answered.html"), "Incorrectly Answered Questions", "orange", e.incorrectlyAnsweredQuestions, e.numberOfQuestions,true,e)); - sb2.append(createColoredColumn(new File(folder,"unanswered.html"), "Unanswered Questions", "red", e.unansweredQuestions, e.numberOfQuestions,false,e)); + sb2.append(createColoredColumn(new File(folder,"correctly_answered.html"), "Correctly Answered Questions", "green", e.correctlyAnsweredQuestions, e.numberOfQuestions,true,false,e)); + sb2.append(createColoredColumn(new File(folder,"partly_correctly_answered.html"), "Partly Correctly Answered Questions", "gold", e.partlyCorrectlyAnsweredQuestions, e.numberOfQuestions,true,true,e)); + sb2.append(createColoredColumn(new File(folder,"incorrectly_answered.html"), "Incorrectly Answered Questions", "darkorange", e.incorrectlyAnsweredQuestions, e.numberOfQuestions,true,false,e)); + sb2.append(createColoredColumn(new File(folder,"unanswered.html"), "Unanswered Questions", "red", e.unansweredQuestions, e.numberOfQuestions,false,false,e)); sb2.append("<span style='width:1000px;'></span>"); sb2.append("</td></tr>\n"); last = e; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-02 17:47:45
|
Revision: 3867 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3867&view=rev Author: kirdie Date: 2012-11-02 17:47:38 +0000 (Fri, 02 Nov 2012) Log Message: ----------- began bugfixing learner 2. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-02 14:52:52 UTC (rev 3866) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-02 17:47:38 UTC (rev 3867) @@ -713,6 +713,7 @@ Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); List<Slot> sortedSlots = new ArrayList<Slot>(); Set<Slot> classSlots = new HashSet<Slot>(); + // TODO: can this be optimized to be in just one loop? (but I guess it won't give a noticable performance benefit anyways...) for(Slot slot : t.getSlots()){ if(slot.getSlotType() == SlotType.CLASS){ sortedSlots.add(slot); Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-02 14:52:52 UTC (rev 3866) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-02 17:47:38 UTC (rev 3867) @@ -117,11 +117,11 @@ private static final File evaluationFolder = new File("cache/evaluation"); private static final boolean DBPEDIA_PRETAGGED = true; private static final boolean OXFORD_PRETAGGED = false; - private static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; - private static final boolean WHITELIST_ONLY = false; + private static final int MAX_NUMBER_OF_QUESTIONS = 20; + private static final boolean WHITELIST_ONLY = true; private static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); - /*@Test*/ public void testDBpedia() throws Exception + @Test public void testDBpedia() throws Exception { File file = generateTestDataIfNecessary( new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml").getFile()), @@ -767,7 +767,7 @@ Map<Integer,Future<LearnStatus>> futures = new HashMap<Integer,Future<LearnStatus>>(); // List<FutureTask> todo = new ArrayList<FutureTask>(id2Question.size()); - ExecutorService service = Executors.newFixedThreadPool(1); + ExecutorService service = Executors.newCachedThreadPool();// newFixedThreadPool(1); for(int i: id2Question.keySet()) {//if(i != 78)continue; @@ -1001,7 +1001,7 @@ } } - @Test public void testSolrGoodResults() + /*@Test*/ public void testSolrGoodResults() { Knowledgebase dbpedia = createDBpediaLiveKnowledgebase(dbpediaLiveCache); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-02 14:53:03
|
Revision: 3866 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3866&view=rev Author: kirdie Date: 2012-11-02 14:52:52 +0000 (Fri, 02 Nov 2012) Log Message: ----------- merged with trunk Modified Paths: -------------- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalDataPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/IrreflexiveObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner2.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexiveObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/SubDataPropertyOfAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/SubObjectPropertyOfAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java branches/hmm/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java branches/hmm/components-core/src/main/java/org/dllearner/core/ComponentManager.java branches/hmm/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java branches/hmm/components-core/src/main/java/org/dllearner/core/owl/EquivalentObjectPropertiesAxiom.java branches/hmm/components-core/src/main/java/org/dllearner/core/owl/Thing.java branches/hmm/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java branches/hmm/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java branches/hmm/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java branches/hmm/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java branches/hmm/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java branches/hmm/scripts/pom.xml branches/hmm/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java branches/hmm/scripts/src/main/resources/log4j.properties branches/hmm/test/newcomponent/AristotlePosNeg.conf branches/hmm/test/phaenotype/mp-equivalence-axioms-subq.owl Added Paths: ----------- branches/hmm/components-core/src/main/java/org/dllearner/core/owl/GenericDatatypePropertyAssertion.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluationMultithreaded.java Removed Paths: ------------- branches/hmm/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java Property Changed: ---------------- branches/hmm/ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel/ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java branches/hmm/components-core/src/main/java/org/dllearner/kb/aquisitors/LinkedDataTupleAquisitor.java branches/hmm/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java branches/hmm/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java branches/hmm/components-core/src/main/java/org/dllearner/kb/aquisitors/TupleAquisitor.java branches/hmm/components-core/src/main/java/org/dllearner/kb/extraction/ObjectPropertyNode.java branches/hmm/components-core/src/main/java/org/dllearner/kb/manipulator/Manipulator.java branches/hmm/components-core/src/main/java/org/dllearner/kb/manipulator/Rule.java branches/hmm/components-core/src/main/java/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java branches/hmm/components-core/src/main/java/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java branches/hmm/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionClass.java branches/hmm/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java branches/hmm/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java branches/hmm/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java branches/hmm/components-core/src/main/java/org/dllearner/learningproblems/ScorePosNeg.java branches/hmm/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/matching/LGDPoint.java branches/hmm/scripts/src/main/java/org/dllearner/scripts/package-info.java Property changes on: branches/hmm ___________________________________________________________________ Added: svn:mergeinfo + /trunk:3846-3863 Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -47,7 +47,6 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; -import org.dllearner.learningproblems.Heuristics; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -157,7 +156,8 @@ } if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ - runSPARQL1_1_Mode(); +// runSPARQL1_1_Mode(); + runSingleQueryMode(); } else { runSPARQL1_0_Mode(); } @@ -165,6 +165,38 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSingleQueryMode(){ + //compute the overlap if exist + Map<NamedClass, Integer> class2Overlap = new HashMap<NamedClass, Integer>(); + String query = String.format("SELECT ?type (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s a ?type.} GROUP BY ?type", classToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + NamedClass cls = new NamedClass(qs.getResource("type").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + class2Overlap.put(cls, cnt); + } + //for each property in knowledge base + for(NamedClass cls : allClasses){ + //get the popularity + int otherPopularity = reasoner.getPopularity(cls); + if(otherPopularity == 0){//skip empty properties + continue; + } + //get the overlap + int overlap = class2Overlap.containsKey(cls) ? class2Overlap.get(cls) : 0; + //compute the estimated precision + double precision = accuracy(otherPopularity, overlap); + //compute the estimated recall + double recall = accuracy(popularity, overlap); + //compute the final score + double score = 1 - fMEasure(precision, recall); + + currentlyBestEvaluatedDescriptions.add(new EvaluatedDescription(cls, new AxiomScore(score))); + } + } + private void runSPARQL1_0_Mode(){ Model model = ModelFactory.createDefaultModel(); int limit = 1000; Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -19,9 +19,7 @@ package org.dllearner.algorithms; -import java.net.URL; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -109,11 +107,11 @@ @Override public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { - List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); + currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); for(EvaluatedDescription ed : getCurrentlyBestEvaluatedDescriptions(nrOfAxioms)){ - axioms.add(new EvaluatedAxiom(new SubClassAxiom(classToDescribe, ed.getDescription()), new AxiomScore(ed.getAccuracy()))); + currentlyBestAxioms.add(new EvaluatedAxiom(new SubClassAxiom(classToDescribe, ed.getDescription()), new AxiomScore(ed.getAccuracy()))); } - return axioms; + return currentlyBestAxioms; } @Override @@ -145,6 +143,16 @@ } } + if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ + runSingleQueryMode(); + } else { + runSPARQL1_0_Mode(); + } + + logger.info("...finished in {}ms. (Got {} rows)", (System.currentTimeMillis()-startTime), fetchedRows); + } + + private void runSPARQL1_0_Mode(){ Map<Individual, SortedSet<Description>> ind2Types = new HashMap<Individual, SortedSet<Description>>(); int limit = 1000; boolean repeat = true; @@ -153,9 +161,26 @@ createEvaluatedDescriptions(ind2Types); fetchedRows += 1000; } - + } + + private void runSingleQueryMode(){ + int total = reasoner.getPopularity(classToDescribe); - logger.info("...finished in {}ms. (Got {} rows)", (System.currentTimeMillis()-startTime), fetchedRows); + if(total > 0){ + String query = String.format("SELECT ?type (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a <%s>. ?s a ?type} GROUP BY ?type ORDER BY DESC(?cnt)", classToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(!qs.get("type").isAnon()){ + NamedClass sup = new NamedClass(qs.getResource("type").getURI()); + int overlap = qs.get("cnt").asLiteral().getInt(); + if(!sup.getURI().equals(Thing.uri) && ! classToDescribe.equals(sup)){//omit owl:Thing and the class to describe itself + currentlyBestEvaluatedDescriptions.add(new EvaluatedDescription(sup, computeScore(total, overlap))); + } + } + } + } } public NamedClass getClassToDescribe() { @@ -234,8 +259,7 @@ } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), - Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); SPARQLReasoner reasoner = new SPARQLReasoner(ks); reasoner.prepareSubsumptionHierarchy(); @@ -244,7 +268,7 @@ l.setReasoner(reasoner); l.setReturnOnlyNewAxioms(true); - ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 10); + ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 50); l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); l.init(); l.start(); Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -21,6 +21,7 @@ import java.io.File; import java.text.DecimalFormat; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -218,11 +219,11 @@ // configurator = new CELOEConfigurator(this); } -// public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { -// Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); -// problems.add(AbstractLearningProblem.class); -// return problems; -// } + public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { + Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); + problems.add(AbstractLearningProblem.class); + return problems; + } public static String getName() { return "CELOE"; Property changes on: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -22,6 +22,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collections; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -29,12 +31,15 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.owl.AsymmetricObjectPropertyAxiom; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -53,6 +58,9 @@ public AsymmetricObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s ?p ?o. FILTER NOT EXISTS{?o ?p ?s}}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s ?p ?o. ?o ?p ?s}"); + } public ObjectProperty getPropertyToDescribe() { @@ -88,18 +96,18 @@ } private void runSPARQL1_0_Mode(){ - Model model = ModelFactory.createDefaultModel(); + workingModel = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; String baseQuery = "CONSTRUCT {?s <%s> ?o.} WHERE {?s <%s> ?o} LIMIT %d OFFSET %d"; String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); Model newModel = executeConstructQuery(query); while(!terminationCriteriaSatisfied() && newModel.size() != 0){ - model.add(newModel); + workingModel.add(newModel); // get number of instances of s with <s p o> query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); - ResultSet rs = executeSelectQuery(query, model); + ResultSet rs = executeSelectQuery(query, workingModel); QuerySolution qs; int total = 0; while(rs.hasNext()){ @@ -108,7 +116,7 @@ } query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeSelectQuery(query, model); + rs = executeSelectQuery(query, workingModel); int symmetric = 0; while(rs.hasNext()){ qs = rs.next(); @@ -127,26 +135,57 @@ } } - private void runSPARQL1_1_Mode(){ - String query = "SELECT (COUNT(*) AS ?total) WHERE {?s <%s> ?o.}"; - query = query.replace("%s", propertyToDescribe.getURI().toString()); - ResultSet rs = executeSelectQuery(query); - QuerySolution qs; - int total = 0; - while(rs.hasNext()){ - qs = rs.next(); - total = qs.getLiteral("total").getInt(); + @Override + public SortedSet<KBElement> getPositiveExamples(EvaluatedAxiom axiom) { + if(workingModel != null){ + SortedSet<KBElement> allExamples = new TreeSet<KBElement>(); + ParameterizedSparqlString query = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s ?p ?o.}"); + query.setIri("p", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query.toString(), workingModel); + while(rs.hasNext()){ + allExamples.add(new Individual(rs.next().get("s").asResource().getURI())); + } + SortedSet<KBElement> negExamples = getNegativeExamples(axiom); + + SortedSet<KBElement> posExamples = new TreeSet<KBElement>(allExamples); + posExamples.removeAll(negExamples); + + + return posExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); } - query = "SELECT (COUNT(*) AS ?symmetric) WHERE {?s <%s> ?o. ?o <%s> ?s.}"; - query = query.replace("%s", propertyToDescribe.getURI().toString()); - rs = executeSelectQuery(query); - int symmetric = 0; - while(rs.hasNext()){ - qs = rs.next(); - symmetric = qs.getLiteral("symmetric").getInt(); + } + + @Override + public SortedSet<KBElement> getNegativeExamples(EvaluatedAxiom axiom) { + if(workingModel != null){ + SortedSet<KBElement> negExamples = new TreeSet<KBElement>(); + ParameterizedSparqlString query = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s ?p ?o.?o ?p ?s}"); + query.setIri("p", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query.toString(), workingModel); + while(rs.hasNext()){ + negExamples.add(new Individual(rs.next().get("s").asResource().getURI())); + } + + return negExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); } - int asymmetric = total - symmetric; + } + + private void runSPARQL1_1_Mode(){ + int total = reasoner.getPopularity(propertyToDescribe); + if(total > 0){ + int asymmetric = 0; + String query = "SELECT (COUNT(*) AS ?asymmetric) WHERE {?s <%s> ?o. FILTER NOT EXISTS{?o <%s> ?s.}}"; + query = query.replace("%s", propertyToDescribe.getURI().toString()); + ResultSet rs = executeSelectQuery(query); + if(rs.hasNext()){ + asymmetric = rs.next().getLiteral("asymmetric").getInt(); + } + currentlyBestAxioms.add(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), computeScore(total, asymmetric), declaredAsymmetric)); } Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -20,14 +20,7 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; @@ -40,19 +33,26 @@ import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; -import org.semanticweb.owlapi.model.IRI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.Statement; +import com.hp.hpl.jena.rdf.model.StmtIterator; +import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; @ComponentAnn(name="dataproperty domain axiom learner", shortName="dpldomain", version=0.1) public class DataPropertyDomainAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -62,14 +62,10 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; - private static final ParameterizedSparqlString singleQueryTemplate = new ParameterizedSparqlString("SELECT ?type (COUNT(DISTINCT ?ind) AS ?cnt) WHERE {?ind <%s> ?o. ?ind a ?type.}"); - - private Map<Individual, SortedSet<Description>> individual2Types; - public DataPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; - super.iterativeQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?ind ?type WHERE {?ind ?p ?o. ?ind a ?type.}"); - + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s a ?type}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s WHERE {?s ?p ?o. FILTER NOT EXISTS{?s a ?type}}"); } public DatatypeProperty getPropertyToDescribe() { @@ -82,7 +78,6 @@ @Override public void start() { - iterativeQueryTemplate.setIri("p", propertyToDescribe.getName()); logger.info("Start learning..."); startTime = System.currentTimeMillis(); fetchedRows = 0; @@ -104,81 +99,108 @@ } } } - - runIterativeQueryMode(); + if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ + runSingleQueryMode(); + } else { + runSPARQL1_0_Mode(); + } logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } private void runSingleQueryMode(){ - } - - private void runIterativeQueryMode(){ - individual2Types = new HashMap<Individual, SortedSet<Description>>(); - while(!terminationCriteriaSatisfied() && !fullDataLoaded){ - ResultSet rs = fetchData(); - processData(rs); - buildEvaluatedAxioms(); + String query = String.format("SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + int nrOfSubjects = rs.next().getLiteral("cnt").getInt(); + + query = String.format("SELECT ?type (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s <%s> ?o. ?s a ?type.} GROUP BY ?type", propertyToDescribe.getName()); + rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + NamedClass domain = new NamedClass(qs.getResource("type").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + if(!domain.getURI().equals(Thing.uri)){ + currentlyBestAxioms.add(new EvaluatedAxiom(new DatatypePropertyDomainAxiom(propertyToDescribe, domain), computeScore(nrOfSubjects, cnt))); + } } } - private void processData(ResultSet rs){ - QuerySolution qs; - Individual ind; - Description type; - SortedSet<Description> types; - int cnt = 0; - while(rs.hasNext()){ - cnt++; - qs = rs.next(); - if(qs.get("type").isURIResource()){ - types = new TreeSet<Description>(); - ind = new Individual(qs.getResource("ind").getURI()); - type = new NamedClass(qs.getResource("type").getURI()); - types.add(type); - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(type)){ - types.addAll(reasoner.getClassHierarchy().getSuperClasses(type)); + private void runSPARQL1_0_Mode() { + workingModel = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s a ?type.} WHERE {?s <%s> ?o. ?s a ?type.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + workingModel.add(newModel); + // get number of distinct subjects + query = "SELECT (COUNT(DISTINCT ?s) AS ?all) WHERE {?s a ?type.}"; + ResultSet rs = executeSelectQuery(query, workingModel); + QuerySolution qs; + int all = 1; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + + // get class and number of instances + query = "SELECT ?type (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.} GROUP BY ?type ORDER BY DESC(?cnt)"; + rs = executeSelectQuery(query, workingModel); + + if (all > 0) { + currentlyBestAxioms.clear(); + while(rs.hasNext()){ + qs = rs.next(); + Resource type = qs.get("type").asResource(); + //omit owl:Thing as trivial domain + if(type.equals(OWL.Thing)){ + continue; } + currentlyBestAxioms.add(new EvaluatedAxiom( + new DatatypePropertyDomainAxiom(propertyToDescribe, new NamedClass(type.getURI())), + computeScore(all, qs.get("cnt").asLiteral().getInt()))); } - addToMap(individual2Types, ind, types); + } + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); + fillWithInference(newModel); } - lastRowCount = cnt; } - - private void buildEvaluatedAxioms(){ - List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Map<Description, Integer> result = new HashMap<Description, Integer>(); - for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ - for(Description nc : entry.getValue()){ - Integer cnt = result.get(nc); - if(cnt == null){ - cnt = Integer.valueOf(1); - } else { - cnt = Integer.valueOf(cnt + 1); + + private void fillWithInference(Model model){ + Model additionalModel = ModelFactory.createDefaultModel(); + if(reasoner.isPrepared()){ + for(StmtIterator iter = model.listStatements(null, RDF.type, (RDFNode)null); iter.hasNext();){ + Statement st = iter.next(); + Description cls = new NamedClass(st.getObject().asResource().getURI()); + if(reasoner.getClassHierarchy().contains(cls)){ + for(Description sup : reasoner.getClassHierarchy().getSuperClasses(cls)){ + additionalModel.add(st.getSubject(), st.getPredicate(), model.createResource(sup.toString())); + } } - result.put(nc, cnt); } } - - //omit owl:Thing - result.remove(new NamedClass(Thing.instance.getURI())); - - EvaluatedAxiom evalAxiom; - int total = individual2Types.keySet().size(); - for(Entry<Description, Integer> entry : sortByValues(result)){ - evalAxiom = new EvaluatedAxiom(new DatatypePropertyDomainAxiom(propertyToDescribe, entry.getKey()), - computeScore(total, entry.getValue())); - if(existingAxioms.contains(evalAxiom.getAxiom())){ - evalAxiom.setAsserted(true); - } - axioms.add(evalAxiom); - } - - currentlyBestAxioms = axioms; + model.add(additionalModel); } + @Override + public Set<KBElement> getPositiveExamples(EvaluatedAxiom evAxiom) { + DatatypePropertyDomainAxiom axiom = (DatatypePropertyDomainAxiom) evAxiom.getAxiom(); + posExamplesQueryTemplate.setIri("type", axiom.getDomain().toString()); + return super.getPositiveExamples(evAxiom); + } + + @Override + public Set<KBElement> getNegativeExamples(EvaluatedAxiom evAxiom) { + DatatypePropertyDomainAxiom axiom = (DatatypePropertyDomainAxiom) evAxiom.getAxiom(); + negExamplesQueryTemplate.setIri("type", axiom.getDomain().toString()); + return super.getNegativeExamples(evAxiom); + } + public static void main(String[] args) throws Exception{ org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyRangeAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -20,12 +20,7 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.Set; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -36,15 +31,19 @@ import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyRangeAxiom; -import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Resource; @ComponentAnn(name="dataproperty range learner", shortName="dblrange", version=0.1) public class DataPropertyRangeAxiomLearner extends AbstractAxiomLearningAlgorithm { @@ -56,6 +55,9 @@ public DataPropertyRangeAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT ?s WHERE {?o ?p ?s. FILTER (DATATYPE(?s) = ?dt)}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT ?s WHERE {?o ?p ?s. FILTER (DATATYPE(?s) != ?dt)}"); + } public DatatypeProperty getPropertyToDescribe() { @@ -72,84 +74,103 @@ startTime = System.currentTimeMillis(); fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //get existing range - DataRange existingRange = reasoner.getRange(propertyToDescribe); - if(existingRange != null){ - existingAxioms.add(new DatatypePropertyRangeAxiom(propertyToDescribe, existingRange)); - logger.debug("Existing range: " + existingRange); - } - //get objects with datatypes - Map<Individual, SortedSet<Datatype>> individual2Datatypes = new HashMap<Individual, SortedSet<Datatype>>(); - boolean repeat = true; - int limit = 1000; - while(!terminationCriteriaSatisfied() && repeat){ - int ret = addIndividualsWithTypes(individual2Datatypes, limit, fetchedRows); - currentlyBestAxioms = buildEvaluatedAxioms(individual2Datatypes); - fetchedRows += 1000; - repeat = (ret == limit); - } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); - } - - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Datatype>> individual2Types){ - List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Map<Datatype, Integer> result = new HashMap<Datatype, Integer>(); - for(Entry<Individual, SortedSet<Datatype>> entry : individual2Types.entrySet()){ - for(Datatype nc : entry.getValue()){ - Integer cnt = result.get(nc); - if(cnt == null){ - cnt = Integer.valueOf(1); - } else { - cnt = Integer.valueOf(cnt + 1); - } - result.put(nc, cnt); + if(returnOnlyNewAxioms){ + //get existing ranges + DataRange existingRange = reasoner.getRange(propertyToDescribe); + if(existingRange != null){ + existingAxioms.add(new DatatypePropertyRangeAxiom(propertyToDescribe, existingRange)); } } - EvaluatedAxiom evalAxiom; - int total = individual2Types.keySet().size(); - for(Entry<Datatype, Integer> entry : sortByValues(result)){ - evalAxiom = new EvaluatedAxiom(new DatatypePropertyRangeAxiom(propertyToDescribe, entry.getKey()), - computeScore(total, entry.getValue())); - if(existingAxioms.contains(evalAxiom.getAxiom())){ - evalAxiom.setAsserted(true); - } - axioms.add(evalAxiom); + if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ + runSingleQueryMode(); + } else { + runSPARQL1_0_Mode(); } - - return axioms; + logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - - private int addIndividualsWithTypes(Map<Individual, SortedSet<Datatype>> ind2Datatypes, int limit, int offset){ - String query = String.format("SELECT ?ind (DATATYPE(?val) AS ?datatype) WHERE {?ind <%s> ?val.} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + private void runSingleQueryMode(){ + String query = String.format("SELECT (COUNT(DISTINCT ?o) AS ?cnt) WHERE {?s <%s> ?o.}", propertyToDescribe.getName()); ResultSet rs = executeSelectQuery(query); - Individual ind; - Datatype newType; + int nrOfSubjects = rs.next().getLiteral("cnt").getInt(); + + query = String.format("SELECT (DATATYPE(?o) AS ?type) (COUNT(DISTINCT ?o) AS ?cnt) WHERE {?s <%s> ?o.} GROUP BY DATATYPE(?o)", propertyToDescribe.getName()); + rs = executeSelectQuery(query); QuerySolution qs; - SortedSet<Datatype> types; - int cnt = 0; while(rs.hasNext()){ - cnt++; - newType = null; qs = rs.next(); - ind = new Individual(qs.getResource("ind").getURI()); - if(qs.getResource("datatype") != null){ - newType = new Datatype(qs.getResource("datatype").getURI()); - types = ind2Datatypes.get(ind); - if(types == null){ - types = new TreeSet<Datatype>(); - ind2Datatypes.put(ind, types); + if(qs.get("type") != null){ + DataRange range = new Datatype(qs.get("type").asLiteral().getLexicalForm()); + int cnt = qs.getLiteral("cnt").getInt(); + currentlyBestAxioms.add(new EvaluatedAxiom(new DatatypePropertyRangeAxiom(propertyToDescribe, range), computeScore(nrOfSubjects, cnt))); + } + } + } + + private void runSPARQL1_0_Mode() { + workingModel = ModelFactory.createDefaultModel(); + int limit = 1000; + int offset = 0; + String baseQuery = "CONSTRUCT {?s <%s> ?o} WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d"; + String query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + Model newModel = executeConstructQuery(query); + while(!terminationCriteriaSatisfied() && newModel.size() != 0){ + workingModel.add(newModel); + // get number of distinct subjects + query = "SELECT (COUNT(?o) AS ?all) WHERE {?s ?p ?o.}"; + ResultSet rs = executeSelectQuery(query, workingModel); + QuerySolution qs; + int all = 1; + while (rs.hasNext()) { + qs = rs.next(); + all = qs.getLiteral("all").getInt(); + } + + // get class and number of instances +// query = "SELECT (DATATYPE(?o) AS ?dt) (COUNT(?o) AS ?cnt) WHERE{?s ?p ?o} GROUP BY DATATYPE(?o) ORDER BY DESC(?cnt)"; + query = "SELECT ?dt (COUNT(?o) AS ?cnt) " + + "WHERE {" + + "{" + + "SELECT (DATATYPE(?o) AS ?dt) ?o WHERE{?s ?p ?o}" + + "}" + + "}" + + "GROUP BY ?dt"; + rs = executeSelectQuery(query, workingModel); + + if (all > 0) { + currentlyBestAxioms.clear(); + while(rs.hasNext()){ + qs = rs.next(); + Resource type = qs.get("dt").asResource(); + currentlyBestAxioms.add(new EvaluatedAxiom( + new DatatypePropertyRangeAxiom(propertyToDescribe, new Datatype(type.getURI())), + computeScore(all, qs.get("cnt").asLiteral().getInt()))); } - types.add(newType); + } - + offset += limit; + query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + newModel = executeConstructQuery(query); } - return cnt; } + @Override + public Set<KBElement> getPositiveExamples(EvaluatedAxiom evAxiom) { + DatatypePropertyRangeAxiom axiom = (DatatypePropertyRangeAxiom) evAxiom.getAxiom(); + posExamplesQueryTemplate.setIri("dt", axiom.getRange().toString()); + return super.getPositiveExamples(evAxiom); + } + + @Override + public Set<KBElement> getNegativeExamples(EvaluatedAxiom evAxiom) { + DatatypePropertyRangeAxiom axiom = (DatatypePropertyRangeAxiom) evAxiom.getAxiom(); + negExamplesQueryTemplate.setIri("dt", axiom.getRange().toString()); + return super.getNegativeExamples(evAxiom); + } + public static void main(String[] args) throws Exception{ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -32,8 +33,13 @@ import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DisjointDatatypePropertyAxiom; +import org.dllearner.core.owl.GenericDatatypePropertyAssertion; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; @@ -42,8 +48,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -64,6 +72,9 @@ public DisjointDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p1 ?o. FILTER NOT EXISTS{?s ?p ?o}}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p ?o. }"); } public DatatypeProperty getPropertyToDescribe() { @@ -94,7 +105,8 @@ allDataProperties.remove(propertyToDescribe); if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ - runSPARQL1_1_Mode(); +// runSPARQL1_1_Mode(); + runSingleQueryMode(); } else { runSPARQL1_0_Mode(); } @@ -102,21 +114,52 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSingleQueryMode(){ + //compute the overlap if exist + Map<ObjectProperty, Integer> property2Overlap = new HashMap<ObjectProperty, Integer>(); + String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?s ?p ?o.} GROUP BY ?p", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + ObjectProperty prop = new ObjectProperty(qs.getResource("p").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + property2Overlap.put(prop, cnt); + } + //for each property in knowledge base + for(DatatypeProperty p : allDataProperties){ + //get the popularity + int otherPopularity = reasoner.getPopularity(p); + if(otherPopularity == 0){//skip empty properties + continue; + } + //get the overlap + int overlap = property2Overlap.containsKey(p) ? property2Overlap.get(p) : 0; + //compute the estimated precision + double precision = accuracy(otherPopularity, overlap); + //compute the estimated recall + double recall = accuracy(popularity, overlap); + //compute the final score + double score = 1 - fMEasure(precision, recall); + + currentlyBestAxioms.add(new EvaluatedAxiom(new DisjointDatatypePropertyAxiom(propertyToDescribe, p), new AxiomScore(score))); + } + } + private void runSPARQL1_0_Mode() { - Model model = ModelFactory.createDefaultModel(); + workingModel = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String countQuery = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); Model newModel = executeConstructQuery(query); Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); while(!terminationCriteriaSatisfied() && newModel.size() != 0){ - model.add(newModel); - query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; - + workingModel.add(newModel); DatatypeProperty prop; Integer oldCnt; - ResultSet rs = executeSelectQuery(query, model); + ResultSet rs = executeSelectQuery(countQuery, workingModel); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); @@ -135,7 +178,7 @@ offset += limit; - query = String.format(baseQuery, propertyToDescribe.getName(), propertyToDescribe.getName(), limit, offset); + query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); } @@ -253,6 +296,56 @@ return axioms; } + @Override + public Set<KBElement> getPositiveExamples(EvaluatedAxiom evAxiom) { + DisjointDatatypePropertyAxiom axiom = (DisjointDatatypePropertyAxiom) evAxiom.getAxiom(); + posExamplesQueryTemplate.setIri("p", axiom.getDisjointRole().getName()); + if(workingModel != null){ + Set<KBElement> posExamples = new HashSet<KBElement>(); + + ResultSet rs = executeSelectQuery(posExamplesQueryTemplate.toString(), workingModel); + Individual subject; + Literal object; + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + subject = new Individual(qs.getResource("s").getURI()); + object = qs.getLiteral("o"); + posExamples.add(new GenericDatatypePropertyAssertion( + propertyToDescribe, subject, object.getLexicalForm(), new Datatype(object.getDatatypeURI()))); + } + + return posExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); + } + } + + @Override + public Set<KBElement> getNegativeExamples(EvaluatedAxiom evAxiom) { + DisjointDatatypePropertyAxiom axiom = (DisjointDatatypePropertyAxiom) evAxiom.getAxiom(); + negExamplesQueryTemplate.setIri("p", axiom.getDisjointRole().getName()); + if(workingModel != null){ + Set<KBElement> negExamples = new TreeSet<KBElement>(); + + ResultSet rs = executeSelectQuery(negExamplesQueryTemplate.toString(), workingModel); + Individual subject; + Literal object; + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + subject = new Individual(qs.getResource("s").getURI()); + object = qs.getLiteral("o"); + negExamples.add(new GenericDatatypePropertyAssertion( + propertyToDescribe, subject, object.getLexicalForm(), new Datatype(object.getDatatypeURI()))); + } + + return negExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); + } + } + public static void main(String[] args) throws Exception{ DisjointDataPropertyAxiomLearner l = new DisjointDataPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/accessDate")); Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -33,7 +34,10 @@ import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.ObjectPropertyEditor; import org.dllearner.core.owl.DisjointObjectPropertyAxiom; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyAssertion; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; @@ -42,6 +46,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; @@ -64,6 +69,9 @@ public DisjointObjectPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p1 ?o. FILTER NOT EXISTS{?s ?p ?o}}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p ?o. }"); } public ObjectProperty getPropertyToDescribe() { @@ -95,7 +103,8 @@ allObjectProperties.remove(propertyToDescribe); if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ - runSPARQL1_1_Mode(); +// runSPARQL1_1_Mode(); + runSingleQueryMode(); } else { runSPARQL1_0_Mode(); } @@ -103,21 +112,53 @@ logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSingleQueryMode(){ + //compute the overlap if exist + Map<ObjectProperty, Integer> property2Overlap = new HashMap<ObjectProperty, Integer>(); + String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?s ?p ?o.} GROUP BY ?p", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + ObjectProperty prop = new ObjectProperty(qs.getResource("p").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + property2Overlap.put(prop, cnt); + } + //for each property in knowledge base + for(ObjectProperty p : allObjectProperties){ + //get the popularity + int otherPopularity = reasoner.getPopularity(p); + if(otherPopularity == 0){//skip empty properties + continue; + } + //get the overlap + int overlap = property2Overlap.containsKey(p) ? property2Overlap.get(p) : 0; + //compute the estimated precision + double precision = accuracy(otherPopularity, overlap); + //compute the estimated recall + double recall = accuracy(popularity, overlap); + //compute the final score + double score = 1 - fMEasure(precision, recall); + + currentlyBestAxioms.add(new EvaluatedAxiom(new DisjointObjectPropertyAxiom(propertyToDescribe, p), new AxiomScore(score))); + } + } + private void runSPARQL1_0_Mode() { - Model model = ModelFactory.createDefaultModel(); + workingModel = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; + String countQuery = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); Model newModel = executeConstructQuery(query); Map<ObjectProperty, Integer> result = new HashMap<ObjectProperty, Integer>(); while(!terminationCriteriaSatisfied() && newModel.size() != 0){ - model.add(newModel); - query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + workingModel.add(newModel); ObjectProperty prop; Integer oldCnt; - ResultSet rs = executeSelectQuery(query, model); + ResultSet rs = executeSelectQuery(countQuery, workingModel); QuerySolution qs; while(rs.hasNext()){ qs = rs.next(); @@ -134,7 +175,6 @@ currentlyBestAxioms = buildAxioms(result, allObjectProperties); } - offset += limit; query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); @@ -247,6 +287,54 @@ return axioms; } + @Override + public Set<KBElement> getPositiveExamples(EvaluatedAxiom evAxiom) { + DisjointObjectPropertyAxiom axiom = (DisjointObjectPropertyAxiom) evAxiom.getAxiom(); + posExamplesQueryTemplate.setIri("p", axiom.getDisjointRole().getName()); + if(workingModel != null){ + Set<KBElement> posExamples = new HashSet<KBElement>(); + + ResultSet rs = executeSelectQuery(posExamplesQueryTemplate.toString(), workingModel); + Individual subject; + Individual object; + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + subject = new Individual(qs.getResource("s").getURI()); + object = new Individual(qs.getResource("o").getURI()); + posExamples.add(new ObjectPropertyAssertion(propertyToDescribe, subject, object)); + } + + return posExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); + } + } + + @Override + public Set<KBElement> getNegativeExamples(EvaluatedAxiom evAxiom) { + DisjointObjectPropertyAxiom axiom = (DisjointObjectPropertyAxiom) evAxiom.getAxiom(); + negExamplesQueryTemplate.setIri("p", axiom.getDisjointRole().getName()); + if(workingModel != null){ + Set<KBElement> negExamples = new TreeSet<KBElement>(); + + ResultSet rs = executeSelectQuery(negExamplesQueryTemplate.toString(), workingModel); + Individual subject; + Individual object; + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + subject = new Individual(qs.getResource("s").getURI()); + object = new Individual(qs.getResource("o").getURI()); + negExamples.add(new ObjectPropertyAssertion(propertyToDescribe, subject, object)); + } + + return negExamples; + } else { + throw new UnsupportedOperationException("Getting positive examples is not possible."); + } + } + public static void main(String[] args) throws Exception{ SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); // endpoint = new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); Modified: branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java =================================================================== --- branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2012-11-02 14:25:26 UTC (rev 3865) +++ branches/hmm/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentDataPropertyAxiomLearner.java 2012-11-02 14:52:52 UTC (rev 3866) @@ -20,10 +20,8 @@ package org.dllearner.algorithms.properties; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; +import java.util.HashSet; +import java.util.Set; import java.util.SortedSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; @@ -31,16 +29,21 @@ import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.DataPropertyEditor; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.EquivalentDatatypePropertiesAxiom; +import org.dllearner.core.owl.GenericDatatypePropertyAssertion; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KBElement; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.learningproblems.AxiomScore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -54,6 +57,9 @@ public EquivalentDataPropertyAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + super.posExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p ?o}"); + super.negExamplesQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?s ?o WHERE {?s ?p1 ?o. FILTER NOT EXISTS{?s ?p ?o}}"); + } public DatatypeProperty getPropertyToDescribe() { @@ -70,115 +76,131 @@ startTime = System.currentTimeMillis(); fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - //get existing super properties - SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getSuperProperties(propertyToDescribe); - logger.debug("Existing super properties: " + existingSuperProperties); + if(returnOnlyNewAxioms){ + //get existing domains + SortedSet<DatatypeProperty> existingSuperProperties = reasoner.getEquivalentProperties(propertyToDescribe); + if(existingSuperProperties != null && !existingSuperProperties.isEmpty()){ + for(DatatypeProperty supProp : existingSuperProperties){ + existingAxioms.add(new EquivalentDatatypePropertiesAxiom(propertyToDescribe, supProp)); + } + } + } + if(!forceSPARQL_1_0_Mode && ks.supportsSPARQL_1_1()){ - runSPARQL1_1_Mode(); + runSingleQueryMode(); } else { runSPARQL1_0_Mode(); } - logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + private void runSingleQueryMode(){ + int total = reasoner.getPopularity(propertyToDescribe); + + if(total > 0){ + String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?s ?p ?o.} GROUP BY ?p", propertyToDescribe.getName()); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + DatatypeProperty prop = new DatatypeProperty(qs.getResource("p").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + if(!prop.equals(propertyToDescribe)){ + currentlyBestAxioms.add(new EvaluatedAxiom(new EquivalentDatatypePropertiesAxiom(propertyToDescribe, prop), computeScore(total, cnt))); + + } + } + } + } + private void runSPARQL1_0_Mode() { - Model model = ModelFactory.createDefaultModel(); + workingModel = ModelFactory.createDefaultModel(); int limit = 1000; int offset = 0; String baseQuery = "CONSTRUCT {?s ?p ?o.} WHERE {?s <%s> ?o. ?s ?p ?o.} LIMIT %d OFFSET %d"; String query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); Model newModel = executeConstructQuery(query); - Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); while(!terminationCriteriaSatisfied() && newModel.size() != 0){ - model.add(newModel); - query = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o.} GROUP BY ?p"; + workingModel.add(newModel); + // get number of triples + int all = (int)workingModel.size(); - DatatypeProperty prop; - Integer oldCnt; - ResultSet rs = executeSelectQuery(query, model); - QuerySolution qs; - while(rs.hasNext()){ - qs = rs.next(); - prop = new DatatypeProperty(qs.getResource("p").getURI()); - int newCnt = qs.getLiteral("count").getInt(); - oldCnt = result.get(prop); - if(oldCnt == null){ - oldCnt = Integer.valueOf(newCnt); + if (all > 0) { + // get class and number of instances + query = "SELECT ?p (COUNT(*) AS ?cnt) WHERE {?s ?p ?o.} GROUP BY ?p ORDER BY DESC(?cnt)"; + ResultSet rs = executeSelectQuery(query, workingModel); + + currentlyBestAxioms.clear(); + QuerySolution qs; + DatatypeProperty prop; + while(rs.hasNext()){ + qs = rs.next(); + prop = new DatatypeProperty(qs.get("p").asResource().getURI()); + //omit property to describe as it is trivial + if(prop.equals(propertyToDescribe)){ + continue; + } + currentlyBestAxioms.add(new EvaluatedAxiom( + new EquivalentDatatypePropertiesAxiom(propertyToDescribe, prop), + computeScore(all, qs.get("cnt").asLiteral().getInt()))); } - result.put(prop, oldCnt); - qs.getLiteral("count").getInt(); + } - if(!result.isEmpty()){ - currentlyBestAxioms = buildAxioms(result); - } - - offset += limit; query = String.format(baseQuery, propertyToDescribe.getName(), limit, offset); newModel = executeConstructQuery(query); } - } - private void runSPARQL1_1_Mode() { - // get subjects with types - int limit = 1000; - int offset = 0; - String queryTemplate = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o.?p a owl:DatatypeProperty." - + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + "}"; - String query; - Map<DatatypeProperty, Integer> result = new HashMap<DatatypeProperty, Integer>(); - DatatypeProperty prop; - Integer oldCnt; - boolean repeat = true; - - while (!terminationCriteriaSatisfied() && repeat) { - query = String.format(queryTemplate, propertyToDescribe, limit, - offset); - ResultSet rs = executeSelectQuery(query); + @Override + public Set<KBElement> getPositiveExamples(EvaluatedAxiom e... [truncated message content] |
From: <ki...@us...> - 2012-11-02 14:25:35
|
Revision: 3865 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3865&view=rev Author: kirdie Date: 2012-11-02 14:25:26 +0000 (Fri, 02 Nov 2012) Log Message: ----------- added a test if the solr indices are online and working. Modified Paths: -------------- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-02 14:24:44 UTC (rev 3864) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-02 14:25:26 UTC (rev 3865) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.learning; +import static org.junit.Assert.*; import static org.junit.Assert.fail; import java.io.BufferedReader; import java.io.File; @@ -10,6 +11,7 @@ import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.io.PrintWriter; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -18,6 +20,7 @@ import java.net.URL; import java.net.URLDecoder; import java.text.DateFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -32,6 +35,7 @@ import java.util.SortedMap; import java.util.Stack; import java.util.TreeMap; +import java.util.TreeSet; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ExecutionException; @@ -64,6 +68,8 @@ import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.common.index.Index; +import org.dllearner.common.index.IndexResultItem; +import org.dllearner.common.index.IndexResultSet; import org.dllearner.common.index.MappingBasedIndex; import org.dllearner.common.index.SOLRIndex; import org.dllearner.core.ComponentInitException; @@ -111,7 +117,7 @@ private static final File evaluationFolder = new File("cache/evaluation"); private static final boolean DBPEDIA_PRETAGGED = true; private static final boolean OXFORD_PRETAGGED = false; - private static final int MAX_NUMBER_OF_QUESTIONS = 20; + private static final int MAX_NUMBER_OF_QUESTIONS = Integer.MAX_VALUE; private static final boolean WHITELIST_ONLY = false; private static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); @@ -246,7 +252,7 @@ out.close(); } - @Test public void testOxford() throws Exception + /*@Test*/ public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex(),OXFORD_PRETAGGED); @@ -518,7 +524,7 @@ logger.warn("no suspect answers for question "+i+" ("+question+")"); continue; } - + if(referenceQuery.equals(suspectQuery)||reference.id2Answers.get(i).equals(suspect.id2Answers.get(i))) { evaluation.correctlyAnsweredQuestions.add(question); @@ -941,24 +947,78 @@ private static boolean httpResponseOK(String url) throws MalformedURLException, IOException { - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); - connection.setRequestMethod("HEAD"); - int responseCode = connection.getResponseCode(); - return responseCode == 200; + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("HEAD"); + int responseCode = connection.getResponseCode(); + return responseCode == 200; } + static final String resourcesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_resources"; + static final String classesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_classes"; + static final String propertiesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_properties"; + static final String boaPropertiesURL = "http://139.18.2.173:8080/solr/boa_fact_detail"; + + public boolean isOnline(String url) + { + try + { + URL u = new URL (url ); + HttpURLConnection huc = ( HttpURLConnection ) u.openConnection (); + huc.setRequestMethod ("GET"); + huc.connect () ; + // OutputStream os = huc.getOutputStream ( ) ; + int code = huc.getResponseCode ( ) ; + if(code!=404) logger.warn("Response code "+code+" for url "+url); + return code==404; + } + catch(Throwable t) {logger.warn("Exception when checking availability of url "+url,t);return false;} + } + + // gets called by setup() + /*@Test*/ public void testSolrOnline() + { + String[] solrServerUrls = {resourcesURL,classesURL,propertiesURL,boaPropertiesURL}; + String suffix = "/admin"; + for(String url : solrServerUrls) + { + url+=suffix; + if(!isOnline(url)) fail(); + } + } + + protected void testIndex(Index index, String[][] entities) + { + for(int i=0;i<entities.length;i++) + { + IndexResultSet rs = index.getResourcesWithScores(entities[i][0]); + Set<IndexResultItem> items = new TreeSet<IndexResultItem>(rs.getItems()); + ArrayList<IndexResultItem> itemList = new ArrayList<IndexResultItem>(items); + // the right resource should have the top or second from the top score + String uri = items.iterator().next().getUri(); + IndexResultItem secondItem = itemList.size()<2?null:itemList.get(1); + String secondUri = secondItem==null?null:secondItem.getUri(); + assertTrue(entities[i][1]+"!="+uri+" "+items,entities[i][1].equals(uri)||entities[i][1].equals(secondUri)); + } + } + + @Test public void testSolrGoodResults() + { + Knowledgebase dbpedia = createDBpediaLiveKnowledgebase(dbpediaLiveCache); + + testIndex(dbpedia.getResourceIndex(),new String[][] + {{"Brooklyn Bridge","http://dbpedia.org/resource/Brooklyn_Bridge"},{"Estonia","http://dbpedia.org/resource/Estonia"}, + {"Germany","http://dbpedia.org/resource/Germany"}}); + testIndex(dbpedia.getPropertyIndex(),new String[][] {{"born in","http://dbpedia.org/ontology/birthPlace"}}); + } + private static Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) { - String resourcesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_resources123"; - String classesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_classes"; - String propertiesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_properties"; - String boaPropertiesURL = "http://139.18.2.173:8080/solr/boa_fact_detail"; - -// for(String url : new String[] {resourcesURL,classesURL,propertiesURL,boaPropertiesURL}) -// { -// try{if(!httpResponseOK(url)) throw new RuntimeException("Http response not 200 for url "+url);} catch(Exception e) {throw new RuntimeException(e);} -// } - + + // for(String url : new String[] {resourcesURL,classesURL,propertiesURL,boaPropertiesURL}) + // { + // try{if(!httpResponseOK(url)) throw new RuntimeException("Http response not 200 for url "+url);} catch(Exception e) {throw new RuntimeException(e);} + // } + SOLRIndex resourcesIndex = new SOLRIndex(resourcesURL); resourcesIndex.setPrimarySearchField("label"); // resourcesIndex.setSortField("pagerank"); @@ -988,7 +1048,7 @@ // Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.INFO); logger.setLevel(Level.INFO); // TODO: remove when finishing implementation of this class logger.addAppender(new FileAppender(new SimpleLayout(), "log/"+this.getClass().getSimpleName()+".log", false)); - + testSolrOnline(); // Logger.getRootLogger().removeAllAppenders(); // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-02 14:24:51
|
Revision: 3864 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3864&view=rev Author: kirdie Date: 2012-11-02 14:24:44 +0000 (Fri, 02 Nov 2012) Log Message: ----------- added Comparable interface, equals and hashcode. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/common/index/IndexResultItem.java Modified: branches/hmm/components-ext/src/main/java/org/dllearner/common/index/IndexResultItem.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/common/index/IndexResultItem.java 2012-11-01 10:22:25 UTC (rev 3863) +++ branches/hmm/components-ext/src/main/java/org/dllearner/common/index/IndexResultItem.java 2012-11-02 14:24:44 UTC (rev 3864) @@ -3,7 +3,10 @@ import java.util.Collections; import java.util.Map; -public class IndexResultItem { +/** Natural ordering is negated natural order of scores (highest to lowest score) if score is different, else lexical order of urls if urls are equal else lexical ordering of labels. + * This keeps the ordering consistent with equals and hashCode because those ignore the fields too. **/ +public class IndexResultItem implements Comparable<IndexResultItem> +{ private final String uri; private final String label; private final float score; @@ -26,9 +29,52 @@ public float getScore() {return score;} public Map<String,? extends Object> getFields() {return fields;} - @Override public String toString() + @Override public String toString() {return "label:" + label + "--uri:" + uri + "--fields:" + fields;} + + @Override public int compareTo(IndexResultItem item) { - // TODO Auto-generated method stub - return "label:" + label + "--uri:" + uri + "--fields:" + fields; + int i; + i = -Float.compare(this.score, item.score); + if(i!=0) return i; + i = this.uri.compareTo(item.uri); + if(i!=0) return i; + i = this.label.compareTo(item.label); + return i; } -} + + @Override public int hashCode() + { + final int prime = 31; + int result = 1; +// result = prime * result + ((fields == null) ? 0 : fields.hashCode()); + result = prime * result + ((label == null) ? 0 : label.hashCode()); + result = prime * result + Float.floatToIntBits(score); + result = prime * result + ((uri == null) ? 0 : uri.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; + IndexResultItem other = (IndexResultItem) obj; +// if (fields == null) +// { +// if (other.fields != null) return false; +// } +// else if (!fields.equals(other.fields)) return false; + if (label == null) + { + if (other.label != null) return false; + } + else if (!label.equals(other.label)) return false; + if (Float.floatToIntBits(score) != Float.floatToIntBits(other.score)) return false; + if (uri == null) + { + if (other.uri != null) return false; + } + else if (!uri.equals(other.uri)) return false; + return true; + } +} \ 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: <ki...@us...> - 2012-11-01 10:22:40
|
Revision: 3863 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3863&view=rev Author: kirdie Date: 2012-11-01 10:22:25 +0000 (Thu, 01 Nov 2012) Log Message: ----------- undo bad commit Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Property Changed: ---------------- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/LinkedDataTupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/TupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/extraction/ObjectPropertyNode.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Manipulator.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Rule.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionClass.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ScorePosNeg.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/matching/LGDPoint.java trunk/scripts/src/main/java/org/dllearner/scripts/package-info.java Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/LinkedDataTupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/TupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/extraction/ObjectPropertyNode.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Manipulator.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Rule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionClass.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/ScorePosNeg.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -1,19 +1,27 @@ package org.dllearner.algorithm.tbsl.learning; -import hmm.HiddenMarkovModel; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; -import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import org.apache.commons.collections15.MultiMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.apache.log4j.Logger; import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; @@ -23,7 +31,13 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.Allocation; import org.dllearner.algorithm.tbsl.sparql.Query; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -32,10 +46,13 @@ import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; +import org.dllearner.algorithm.tbsl.util.Similarity; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; import org.dllearner.common.index.Index; import org.dllearner.common.index.IndexResultItem; import org.dllearner.common.index.IndexResultSet; import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.common.index.SOLRIndex; import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; import org.dllearner.common.index.SPARQLIndex; import org.dllearner.common.index.SPARQLObjectPropertiesIndex; @@ -46,13 +63,19 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.reasoning.SPARQLReasoner; +import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; + import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; @@ -62,6 +85,10 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.sparql.expr.ExprAggregator; +import com.hp.hpl.jena.sparql.expr.ExprVar; +import com.hp.hpl.jena.sparql.expr.aggregate.AggCount; +import com.hp.hpl.jena.sparql.expr.aggregate.Aggregator; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -489,88 +516,358 @@ return relevantKeywords; } - // just for testing the HMM integration, getWeightedSPARQLQueriesOld is the original one - private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates) - { - // for testing - for(Template template: templates) - { - { - ArrayList<String> keywords = new ArrayList<String>(); - for(Slot slot: template.getSlots()) - { - keywords.add(slot.getWords().get(0)); + private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + logger.debug("Generating SPARQL query candidates..."); + + Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { + + @Override + public int compare(Slot o1, Slot o2) { + if(o1.getSlotType() == o2.getSlotType()){ + return o1.getToken().compareTo(o2.getToken()); + } else { + return -1; } - if(template.getSlots().size()!=3) {continue;} - if(!keywords.contains("Mean Hamster Software")) {continue;} - if(!keywords.contains("published")) {continue;} - System.out.println("\"keywords\": "+keywords); } - System.out.println(template); - SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); - Query query = template.getQuery(); - double score = 0; - - Map<List<String>,Collection<String>> segmentToURIs = new HashMap<List<String>,Collection<String>>(); - for(Slot slot: template.getSlots()) - { - List<String> segment = new LinkedList<String>(); - segment.add(slot.getWords().get(0)); // TODO: split it up? - - Set<String> uris = new HashSet<String>(); - - for(IndexResultItem item : getIndexResultItems(slot)) - { - uris.add(item.getUri()); + }); + slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); + + + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); + + Set<Allocation> allocations; + + for(Template t : templates){ + logger.info("Processing template:\n" + t.toString()); + allocations = new TreeSet<Allocation>(); + boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); + + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); + List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); + + long startTime = System.currentTimeMillis(); + + for (Slot slot : t.getSlots()) { + if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); + Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); + Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); + list.add(submit); + } + } + + for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { + try { + Map<Slot, SortedSet<Allocation>> result = future.get(); + Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); + slot2Allocations.put(item.getKey(), item.getValue()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); } - segmentToURIs.put(segment,uris); } - HiddenMarkovModel hmm = new HiddenMarkovModel(); - hmm.initialization(); - hmm.startMarkovModel(segmentToURIs,true); - MultiMap<Double,List<String>> paths = hmm.getPaths(); - // System.out.println(hmm.getPaths()); - // die keywords jetzt in sadeehs algorithmus reinwerfen - // da kommen jetzt pfade raus mit unterschiedlichen wahrscheinlichkeiten - // HiddenMarkovModel HMM = new HiddenMarkovModel(); - // HMM.StartMarkovModel(); - // jetzt die variablen aus der query ersetzen mit den kandidaten - // ranked list der pfade, die die observation sequence generieren + executor.shutdown(); - for(Double d : paths.keySet()) - { - for(List<String> path : paths.get(d)) - { - Query q = new Query(query); - // TODO: which variable stands for which resource? do it randomly now to check if the replacement works and then correct the order later - System.out.println(q.getVariablesAsStringList()); - System.out.println(); - int i = 0; - for(String var : q.getVariablesAsStringList()) - { - q.replaceVarWithURI(var, path.get(i)); - i++; + + /*for(Slot slot : t.getSlots()){ + allocations = slot2Allocations2.get(slot); + if(allocations == null){ + allocations = computeAllocations(slot, 10); + slot2Allocations2.put(slot, allocations); + } + slot2Allocations.put(slot, allocations); + + //for tests add the property URI with http://dbpedia.org/property/ namespace + //TODO should be replaced by usage of a separate SOLR index + Set<Allocation> tmp = new HashSet<Allocation>(); + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(Allocation a : allocations){ + String uri = "http://dbpedia.org/property/" + a.getUri().substring(a.getUri().lastIndexOf("/")+1); + Allocation newA = new Allocation(uri, a.getSimilarity(), a.getProminence()); + newA.setScore(a.getScore()-0.000001); + tmp.add(newA); } - System.out.println(q); + } + allocations.addAll(tmp); + }*/ + logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); + Query cleanQuery = t.getQuery(); + queries.add(new WeightedQuery(cleanQuery)); - WeightedQuery wQuery = new WeightedQuery(q, score); - queries.add(wQuery); + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); + Set<Slot> classSlots = new HashSet<Slot>(); + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.CLASS){ + sortedSlots.add(slot); + classSlots.add(slot); } } - //System.exit(0); - return queries; - // >> SLOTS: - // y0: RESOURCE {Mean Hamster Software} - // p0: OBJECTPROPERTY {published,print} - // p1: CLASS {video games} + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ + sortedSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(!sortedSlots.contains(slot)){ + sortedSlots.add(slot); + } + } + //add for each SYMPROPERTY Slot the reversed query + for(Slot slot : sortedSlots){ + for(WeightedQuery wQ : queries){ + if(slot.getSlotType() == SlotType.SYMPROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY){ + Query reversedQuery = new Query(wQ.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + tmp.add(new WeightedQuery(reversedQuery)); + } + tmp.add(wQ); + } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); + } + for(Slot slot : sortedSlots){ + if(!slot2Allocations.get(slot).isEmpty()){ + for(Allocation a : slot2Allocations.get(slot)){ + for(WeightedQuery query : queries){ + Query q = new Query(query.getQuery()); - // System.out.println(template); + boolean drop = false; + if(useDomainRangeRestriction){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + String objectVar = triple.getValue().getName(); + String subjectVar = triple.getVariable().getName(); + // System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ + // System.out.println(typeTriple); + if(true){//reasoner.isObjectProperty(a.getUri())){ + Description range = reasoner.getRange(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(range != null){ + Set<Description> allRanges = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(range instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(range); + allRanges.addAll(superClasses); + } else { + for(Description nc : range.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allRanges.addAll(superClasses); + } + } + allRanges.add(range); + allRanges.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } + } + } else { + drop = true; + } + + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ + Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(domain != null){ + Set<Description> allDomains = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(domain instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(domain); + allDomains.addAll(superClasses); + } else { + for(Description nc : domain.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allDomains.addAll(superClasses); + } + } + allDomains.add(domain); + allDomains.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + + } + } + } + } + } + } + + if(!drop){ + if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + WeightedQuery w = new WeightedQuery(q); + double newScore = query.getScore() + a.getScore(); + w.setScore(newScore); + w.addAllocations(query.getAllocations()); + w.addAllocation(a); + tmp.add(w); + } + + + } + } + //lower queries with FILTER-REGEX + if(containsRegex){ + for(WeightedQuery wQ : tmp){ + wQ.setScore(wQ.getScore() - 0.01); + } + } + + queries.clear(); + queries.addAll(tmp);//System.out.println(tmp); + tmp.clear(); + } else {//Add REGEX FILTER if resource slot is empty and predicate is datatype property + if(slot.getSlotType() == SlotType.RESOURCE){ + for(WeightedQuery query : queries){ + Query q = query.getQuery(); + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } + } + } + } + + } + + } else { + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + for(WeightedQuery wQ : queries){ + List<SPARQL_Triple> triples = wQ.getQuery().getTriplesWithVar(slot.getAnchor()); + for(SPARQL_Triple triple : triples){ + String typeVar; + String resourceURI; + SymPropertyDirection direction; + if(triple.getValue().isVariable()){ + direction = SymPropertyDirection.VAR_RIGHT; + typeVar = triple.getValue().getName(); + resourceURI = triple.getVariable().getName(); + } else { + direction = SymPropertyDirection.VAR_LEFT; + typeVar = triple.getVariable().getName(); + resourceURI = triple.getValue().getName(); + } + resourceURI = resourceURI.replace("<", "").replace(">", ""); + List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); + for(SPARQL_Triple typeTriple : typeTriples){ + String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); + // List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); + // for(Entry<String, Integer> property : mostFrequentProperties){ + // wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); + // wQ.setScore(wQ.getScore() + 0.1); + // } + } + + } + } + } + } + // else if(slot.getSlotType() == SlotType.CLASS){ + // String token = slot.getWords().get(0); + // if(slot.getToken().contains("house")){ + // String regexToken = token.replace("houses", "").replace("house", "").trim(); + // try { + // Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); + // SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); + // if(alloc != null && !alloc.isEmpty()){ + // String uri = alloc.first().getUri(); + // for(WeightedQuery query : queries){ + // Query q = query.getQuery(); + // for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + // SPARQL_Term subject = triple.getVariable(); + // SPARQL_Term object = new SPARQL_Term("desc"); + // object.setIsVariable(true); + // object.setIsURI(false); + // q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); + // q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + // object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); + // } + // q.replaceVarWithURI(slot.getAnchor(), uri); + // + // } + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + // } + + + } + + } + for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { + WeightedQuery wQ = iterator.next(); + if(dropZeroScoredQueries){ + if(wQ.getScore() <= 0){ + iterator.remove(); + } + } else { + if(t.getSlots().size()==0) throw new AssertionError("no slots for query "+wQ); + wQ.setScore(wQ.getScore()/t.getSlots().size()); + } + + } + allQueries.addAll(queries); + List<Query> qList = new ArrayList<Query>(); + for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); + qList.add(wQ.getQuery()); + } + template2Queries.put(t, qList); } - // - return null; + logger.debug("...done in "); + return allQueries; } private double getProminenceValue(String uri, SlotType type){ @@ -845,51 +1142,101 @@ } - private Set<IndexResultItem> getIndexResultItems(Slot slot) - { -// List<String> uris = new LinkedList<String>(); - Set<IndexResultItem> indexResultItems = new HashSet<IndexResultItem>(); - - Index index = getIndexBySlotType(slot); - - for(String word : slot.getWords()) - { - IndexResultSet rs = new IndexResultSet(); - if(mappingIndex != null){ - SlotType type = slot.getSlotType(); - if(type == SlotType.CLASS){ - rs.add(mappingIndex.getClassesWithScores(word)); - } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ - rs.add(mappingIndex.getPropertiesWithScores(word)); - } else if(type == SlotType.DATATYPEPROPERTY){ - rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); - } else if(type == SlotType.OBJECTPROPERTY){ - rs.add(mappingIndex.getObjectPropertiesWithScores(word)); - } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ - rs.add(mappingIndex.getResourcesWithScores(word)); + class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ + + private Slot slot; + + public SlotProcessor(Slot slot) { + this.slot = slot; + } + + @Override + public Map<Slot, SortedSet<Allocation>> call() throws Exception { + Map<Slot, SortedSet<Allocation>> result = new HashMap<Slot, SortedSet<Allocation>>(); + result.put(slot, computeAllocations(slot)); + return result; + } + + private SortedSet<Allocation> computeAllocations(Slot slot){ + logger.debug("Computing allocations for slot: " + slot); + SortedSet<Allocation> allocations = new TreeSet<Allocation>(); + + Index index = getIndexBySlotType(slot); + + IndexResultSet rs; + for(String word : slot.getWords()){ + rs = new IndexResultSet(); + if(mappingIndex != null){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + rs.add(mappingIndex.getClassesWithScores(word)); + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + rs.add(mappingIndex.getPropertiesWithScores(word)); + } else if(type == SlotType.DATATYPEPROPERTY){ + rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); + } else if(type == SlotType.OBJECTPROPERTY){ + rs.add(mappingIndex.getObjectPropertiesWithScores(word)); + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + rs.add(mappingIndex.getResourcesWithScores(word)); + } } - } - //use the non manual indexes only if mapping based resultset is not empty and option is set - if(!useManualMappingsIfExistOnly || rs.isEmpty()){ - if(slot.getSlotType() == SlotType.RESOURCE){ - rs.add(index.getResourcesWithScores(word, 20)); - } else { - if(slot.getSlotType() == SlotType.CLASS){ - word = PlingStemmer.stem(word); + //use the non manual indexes only if mapping based resultset is not empty and option is set + if(!useManualMappingsIfExistOnly || rs.isEmpty()){ + if(slot.getSlotType() == SlotType.RESOURCE){ + rs.add(index.getResourcesWithScores(word, 20)); + } else { + if(slot.getSlotType() == SlotType.CLASS){ + word = PlingStemmer.stem(word); + } + rs.add(index.getResourcesWithScores(word, 20)); } - rs.add(index.getResourcesWithScores(word, 20)); } + + + for(IndexResultItem item : rs.getItems()){ + double similarity = Similarity.getSimilarity(word, item.getLabel()); + // //get the labels of the redirects and compute the highest similarity + // if(slot.getSlotType() == SlotType.RESOURCE){ + // Set<String> labels = getRedirectLabels(item.getUri()); + // for(String label : labels){ + // double tmp = Similarity.getSimilarity(word, label); + // if(tmp > similarity){ + // similarity = tmp; + // } + // } + // } + double prominence = getProminenceValue(item.getUri(), slot.getSlotType()); + allocations.add(new Allocation(item.getUri(), prominence, similarity)); + } + } -// for(IndexResultItem item: rs.getItems()) -// { -// uris.add(item.getUri()); -// } - indexResultItems.addAll(rs.getItems()); + + normProminenceValues(allocations); + + computeScore(allocations); + logger.debug("Found " + allocations.size() + " allocations for slot " + slot); + return new TreeSet<Allocation>(allocations); } - return indexResultItems; + + private Index getIndexBySlotType(Slot slot){ + Index index = null; + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + index = classesIndex; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + index = propertiesIndex; + } else if(type == SlotType.DATATYPEPROPERTY){ + index = datatypePropertiesIndex; + } else if(type == SlotType.OBJECTPROPERTY){ + index = objectPropertiesIndex; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + index = resourcesIndex; + } + return index; + } + } - public String getTaggedInput() { if(templateGenerator==null) {throw new AssertionError("Learner not initialized. Please call init();");} @@ -908,33 +1255,33 @@ return isDatatypeProperty; } - // /** - // * @param args - // * @throws NoTemplateFoundException - // * @throws IOException - // * @throws FileNotFoundException - // * @throws InvalidFileFormatException - // */ - // public static void main(String[] args) throws Exception { - // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), - // Collections.<String>singletonList(""), Collections.<String>emptyList()); - // Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); - // Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); - // Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); - // - // SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); - // learner.init(); - // - // String question = "What is the highest mountain?"; - // - // learner.setQuestion(question); - // learner.learnSPARQLQueries(); - // System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); - // System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); - // System.out.println(learner.getLearnedPosition()); - // - // } + /** + * @param args + * @throws NoTemplateFoundException + * @throws IOException + * @throws FileNotFoundException + * @throws InvalidFileFormatException + */ + public static void main(String[] args) throws Exception { + SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), + Collections.<String>singletonList(""), Collections.<String>emptyList()); + Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); + Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); + Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); + SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.init(); + String question = "What is the highest mountain?"; + learner.setQuestion(question); + learner.learnSPARQLQueries(); + System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + System.out.println(learner.getLearnedPosition()); + + } + + + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -58,7 +58,7 @@ unions = new HashSet<SPARQL_Union>(); } - /** copy constructor*/ + //copy constructor public Query(Query query){ this.qt = query.getQt(); Set<SPARQL_Term> selTerms = new HashSet<SPARQL_Term>(); Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -114,7 +114,7 @@ test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null); } - /*@Test*/ public void testOxford() throws Exception + @Test public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex()); @@ -160,26 +160,6 @@ logger.info("learned query: "+testData.id2Query.get(0)); } - /** For debugging one question in particular. - */ - @Test public void testSingleQueryDBpedia() - { -// Logger.getLogger(Templator.class).setLevel(Level.DEBUG); -// Logger.getLogger(Parser.class).setLevel(Level.DEBUG); -// Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.DEBUG); - // String question = "houses for less than 900000 pounds"; - String question = "Give/VB me/PRP all/DT video/JJ games/NNS published/VBN by/IN Mean/NNP Hamster/NNP Software/NNP"; -// String question = "give me all video games published by mean hamster software"; -// String question = "Give me all video games published by Mean Hamster Software"; -// question = new StanfordPartOfSpeechTagger().tag(question); -// System.out.println(question); - -// Model model = loadOxfordModel(); - QueryTestData testData = new QueryTestData(); - new LearnQueryCallable(question, 0, testData, dbpediaLiveKnowledgebase, true).call(); - logger.info("learned query: "+testData.id2Query.get(0)); - } - /*@Test*/ public void generateXMLOxford() throws IOException { boolean ADD_POS_TAGS = true; @@ -955,7 +935,6 @@ learner = new SPARQLTemplateBasedLearner2(knowledgeBase,pretagged?null:POSTaggerHolder.posTagger,wordnet,options); try {learner.init();} catch (ComponentInitException e) {throw new RuntimeException(e);} learner.setUseIdealTagger(pretagged); - learner.setGrammarFiles(new String[]{"tbsl/lexicon/english.lex"}); } public LearnQueryCallable(String question, int id, QueryTestData testData, Model model,MappingBasedIndex index,boolean pretagged) Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/matching/LGDPoint.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/package-info.java ___________________________________________________________________ Deleted: svn:mergeinfo - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-10-30 16:32:53
|
Revision: 3862 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3862&view=rev Author: kirdie Date: 2012-10-30 16:32:40 +0000 (Tue, 30 Oct 2012) Log Message: ----------- fixed oxford testing. Modified Paths: -------------- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java branches/hmm/components-ext/src/main/resources/tbsl/evaluation/oxford_working_questions.xml branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/QueryTestData.java branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Added Paths: ----------- branches/hmm/components-ext/src/main/resources/tbsl/evaluation/oxford_working_questions_justquestions.xml Modified: branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 16:10:36 UTC (rev 3861) +++ branches/hmm/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 16:32:40 UTC (rev 3862) @@ -90,15 +90,13 @@ import com.jamonapi.MonitorFactory; /** The old learner taken over by Konrad Höffner for experiments with the Hidden Markov Algorithm by Saedeeh Shekarpur. - * * */ public class SPARQLTemplateBasedLearner2 implements SparqlQueryLearningAlgorithm { - private static final boolean USE_HMM = false; /** synonyms are great but are not used yet by the HMM algorithm. **/ - private static final boolean HMM_USE_SYNONYMS = false; + private static final boolean HMM_USE_SYNONYMS = true; /** The minimum score of items that are accepted from the Sindice search BOA index. **/ - private static final Double BOA_THRESHOLD = 0.9; + private static final Double BOA_THRESHOLD = 0.5; enum Mode {BEST_QUERY, BEST_NON_EMPTY_QUERY} private Mode mode = Mode.BEST_QUERY; @@ -394,35 +392,37 @@ // templateMon.reset(); // sparqlMon.reset(); } - - public void learnSPARQLQueries() throws NoTemplateFoundException{ + public void learnSPARQLQueries() throws NoTemplateFoundException + { + learnSPARQLQueries(false); + } + + public void learnSPARQLQueries(boolean useHMM) throws NoTemplateFoundException + { reset(); //generate SPARQL query templates logger.debug("Generating SPARQL query templates..."); templateMon.start(); if(multiThreaded){ - templates = templateGenerator.buildTemplatesMultiThreaded(question,!USE_HMM||HMM_USE_SYNONYMS); + templates = templateGenerator.buildTemplatesMultiThreaded(question,!useHMM||HMM_USE_SYNONYMS); } else { templates = templateGenerator.buildTemplates(question); } templateMon.stop(); logger.debug("Done in " + templateMon.getLastValue() + "ms."); relevantKeywords.addAll(templateGenerator.getUnknownWords()); - if(templates.isEmpty()){ - throw new NoTemplateFoundException(); + if(templates.isEmpty()){throw new NoTemplateFoundException();} +// logger.debug("Templates:"); +// for(Template t : templates){ +// logger.debug(t); +// } - } - logger.debug("Templates:"); - for(Template t : templates){ - logger.debug(t); - } - //get the weighted query candidates - generatedQueries = getWeightedSPARQLQueries(templates,USE_HMM); + generatedQueries = getWeightedSPARQLQueries(templates,useHMM); sparqlQueryCandidates = new ArrayList<WeightedQuery>(); int i = 0; for(WeightedQuery wQ : generatedQueries){ - logger.debug(wQ.explain()); + logger.trace(wQ.explain()); sparqlQueryCandidates.add(wQ); if(i == maxTestedQueries){ break; @@ -526,52 +526,61 @@ private SortedSet<WeightedQuery> getWeightedSPARQLQueriesWithHMM(Set<Template> templates) { - // for testing + List<String> vars = new LinkedList<String>(); + if(templates.isEmpty()) throw new AssertionError("no templates"); + SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); for(Template template: templates) { { ArrayList<String> keywords = new ArrayList<String>(); for(Slot slot: template.getSlots()) { - keywords.add(slot.getWords().get(0)); + if(!slot.getWords().isEmpty()) + { + // we don't have synonyms for hmm at the moment, so there should be just one word + if(slot.getWords().size()!=1) throw new AssertionError("more than one word with hmm for slot: "+slot.getWords()); + keywords.add(slot.getWords().get(0)); + vars.add(slot.getAnchor()); + } } - if(template.getSlots().size()!=3) {continue;} // if(!keywords.contains("Mean Hamster Software")) {continue;} // if(!keywords.contains("published")) {continue;} - System.out.println("\"keywords\": "+keywords); + logger.debug("\"keywords\": "+keywords); } - System.out.println(template); - SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); + System.out.println(template); Query query = template.getQuery(); double score = 0; Map<List<String>,List<ResourceInfo>> segmentToURIs = new HashMap<List<String>,List<ResourceInfo>>(); - Map<String,IndexResultItem> uriUniqueToResultItem = new HashMap<String,IndexResultItem>(); +// Map<String,IndexResultItem> uriUniqueToResultItem = new HashMap<String,IndexResultItem>(); for(Slot slot: template.getSlots()) { - List<String> segment = new LinkedList<String>(); - segment.addAll(Arrays.asList(slot.getWords().get(0).split("\\s"))); - List<ResourceInfo> resourceInfos = new LinkedList<ResourceInfo>(); + if(!slot.getWords().isEmpty()){ + List<String> segment = new LinkedList<String>(); + segment.addAll(Arrays.asList(slot.getWords().get(0).split("\\s"))); + List<ResourceInfo> resourceInfos = new LinkedList<ResourceInfo>(); - for(IndexResultItem item : getIndexResultItems(slot)) - { - // if this gets used at another place, create a function IndexResultItemToResourceInfo() - ResourceInfo info = new ResourceInfo(); - info.setUri(item.getUri()); - String label = item.getLabel(); - // in dbpedia, the last part of the uri is transformed from the english label, reverse the transformation (should almost always work for dbpedia article resources) - info.setLabel(label!=null?label:sfp.getShortForm(IRI.create(item.getUri()))); - // in saedeehs algorithm, the emission probabilty is formed by the string similarity - // but we use the lucene index score - double max = 0; - for(String word: slot.getWords()) {max = Math.max(max, Similarity.getSimilarity(word, info.getLabel()));} - if(max<0||max>1) throw new AssertionError("max is not in [0,1], max="+max); - info.setStringSimilarityScore(max); - if(!info.setTypeFromDBpediaURI()) throw new AssertionError("could not set type for info "+info); - System.err.println("info with type: "+info); - resourceInfos.add(info); + for(IndexResultItem item : getIndexResultItems(slot)) + { + // if this gets used at another place, create a function IndexResultItemToResourceInfo() + ResourceInfo info = new ResourceInfo(); + info.setUri(item.getUri()); + String label = item.getLabel(); + // in dbpedia, the last part of the uri is transformed from the english label, reverse the transformation (should almost always work for dbpedia article resources) + info.setLabel(label!=null?label:sfp.getShortForm(IRI.create(item.getUri()))); + // in saedeehs algorithm, the emission probabilty is formed by the string similarity + // but we use the lucene index score + double max = 0; + for(String word: slot.getWords()) {max = Math.max(max, Similarity.getSimilarity(word, info.getLabel()));} + if(max<0||max>1) throw new AssertionError("max is not in [0,1], max="+max); + info.setStringSimilarityScore(max); + if(!info.setTypeFromDBpediaURI()) throw new AssertionError("could not set type for info "+info); + System.err.println("info with type: "+info); + resourceInfos.add(info); + } + segmentToURIs.put(segment,resourceInfos); } - segmentToURIs.put(segment,resourceInfos); + } HiddenMarkovModel hmm = new HiddenMarkovModel(); hmm.initialization(); @@ -595,10 +604,10 @@ System.out.println(q.getVariablesAsStringList()); System.out.println(); int i = 0; - for(String var : q.getVariablesAsStringList()) - { - q.replaceVarWithURI(var, path.get(i)); - i++; + for(String uri : path){ + uri = uri.trim(); + String var = vars.get(path.indexOf(uri)); + q.replaceVarWithURI(var, uri); } System.out.println(q); @@ -607,8 +616,7 @@ queries.add(wQuery); } } - //System.exit(0); - return queries; + //System.exit(0); // >> SLOTS: // y0: RESOURCE {Mean Hamster Software} // p0: OBJECTPROPERTY {published,print} @@ -618,10 +626,10 @@ // System.out.println(template); } // - return null; + return queries; } - private SortedSet<WeightedQuery> getWeightedSPARQLQueriesWithoutHMM(Set<Template> templates){ + @SuppressWarnings("unused") private SortedSet<WeightedQuery> getWeightedSPARQLQueriesWithoutHMM(Set<Template> templates){ logger.debug("Generating SPARQL query candidates..."); Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { @@ -640,11 +648,10 @@ SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); - Set<Allocation> allocations; - - for(Template t : templates){ - logger.info("Processing template:\n" + t.toString()); - allocations = new TreeSet<Allocation>(); + for(Template t : templates) + { + logger.info("Processing template:\n" + t.toString()); +// Set<Allocation> allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); @@ -653,7 +660,7 @@ long startTime = System.currentTimeMillis(); for (Slot slot : t.getSlots()) { - if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); + if(!slot2Allocations.containsKey(slot)){ Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); list.add(submit); @@ -668,7 +675,8 @@ } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { - e.printStackTrace(); +// e.printStackTrace(); + throw new RuntimeException(e); } } @@ -734,7 +742,7 @@ queries.clear(); queries.addAll(tmp); tmp.clear(); - } + } for(Slot slot : sortedSlots){ if(!slot2Allocations.get(slot).isEmpty()){ @@ -743,104 +751,104 @@ Query q = new Query(query.getQuery()); boolean drop = false; - if(useDomainRangeRestriction){ - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - String objectVar = triple.getValue().getName(); - String subjectVar = triple.getVariable().getName(); - // System.out.println(triple); - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ - // System.out.println(typeTriple); - if(true){//reasoner.isObjectProperty(a.getUri())){ - Description range = reasoner.getRange(new ObjectProperty(a.getUri())); - // System.out.println(a); - if(range != null){ - Set<Description> allRanges = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(range instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(range); - allRanges.addAll(superClasses); - } else { - for(Description nc : range.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allRanges.addAll(superClasses); - } - } - allRanges.add(range); - allRanges.remove(new NamedClass(Thing.instance.getURI())); +// if(useDomainRangeRestriction){ +// if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ +// for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ +// String objectVar = triple.getValue().getName(); +// String subjectVar = triple.getVariable().getName(); +// +// for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ +// +// if(true){//reasoner.isObjectProperty(a.getUri())){ +// Description range = reasoner.getRange(new ObjectProperty(a.getUri())); +// +// if(range != null){ +// Set<Description> allRanges = new HashSet<Description>(); +// SortedSet<Description> superClasses; +// if(range instanceof NamedClass){ +// superClasses = reasoner.getSuperClasses(range); +// allRanges.addAll(superClasses); +// } else { +// for(Description nc : range.getChildren()){ +// superClasses = reasoner.getSuperClasses(nc); +// allRanges.addAll(superClasses); +// } +// } +// allRanges.add(range); +// allRanges.remove(new NamedClass(Thing.instance.getURI())); +// +// Set<Description> allTypes = new HashSet<Description>(); +// String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); +// Description type = new NamedClass(typeURI); +// superClasses = reasoner.getSuperClasses(type); +// allTypes.addAll(superClasses); +// allTypes.add(type); +// +// if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ +// drop = true; +// } +// } +// } else { +// drop = true; +// } +// +// } +// for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ +// Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); +// +// if(domain != null){ +// Set<Description> allDomains = new HashSet<Description>(); +// SortedSet<Description> superClasses; +// if(domain instanceof NamedClass){ +// superClasses = reasoner.getSuperClasses(domain); +// allDomains.addAll(superClasses); +// } else { +// for(Description nc : domain.getChildren()){ +// superClasses = reasoner.getSuperClasses(nc); +// allDomains.addAll(superClasses); +// } +// } +// allDomains.add(domain); +// allDomains.remove(new NamedClass(Thing.instance.getURI())); +// +// Set<Description> allTypes = new HashSet<Description>(); +// String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); +// Description type = new NamedClass(typeURI); +// superClasses = reasoner.getSuperClasses(type); +// allTypes.addAll(superClasses); +// allTypes.add(type); +// +// if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ +// drop = true; +// } else { +// +// } +// } +// } +// } +// } +// } - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ - drop = true; - } - } - } else { - drop = true; - } - - } - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ - Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); - // System.out.println(a); - if(domain != null){ - Set<Description> allDomains = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(domain instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(domain); - allDomains.addAll(superClasses); - } else { - for(Description nc : domain.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allDomains.addAll(superClasses); - } - } - allDomains.add(domain); - allDomains.remove(new NamedClass(Thing.instance.getURI())); - - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ - drop = true; - } else { - - } - } - } - } - } - } - if(!drop){ if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ SPARQL_Value object = triple.getValue(); - if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position - SPARQL_Property predicate = triple.getProperty(); - if(!predicate.isVariable()){//only consider triple where predicate is URI - String predicateURI = predicate.getName().replace("<", "").replace(">", ""); - if(isDatatypeProperty(predicateURI)){//if data property - q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } +// if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position +// SPARQL_Property predicate = triple.getProperty(); +// if(!predicate.isVariable()){//only consider triple where predicate is URI +// String predicateURI = predicate.getName().replace("<", "").replace(">", ""); +// if(isDatatypeProperty(predicateURI)){//if data property +// q.addFilter(new SPARQL_Filter(new SPARQL_Pair( +// object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); +// } else { +// q.replaceVarWithURI(slot.getAnchor(), a.getUri()); +// } +// } else { +// q.replaceVarWithURI(slot.getAnchor(), a.getUri()); +// } +// } else { +// +// } } } else { q.replaceVarWithURI(slot.getAnchor(), a.getUri()); @@ -864,7 +872,7 @@ } queries.clear(); - queries.addAll(tmp);//System.out.println(tmp); + queries.addAll(tmp); tmp.clear(); } else {//Add REGEX FILTER if resource slot is empty and predicate is datatype property if(slot.getSlotType() == SlotType.RESOURCE){ @@ -952,6 +960,7 @@ } } + for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { WeightedQuery wQ = iterator.next(); if(dropZeroScoredQueries){ @@ -966,11 +975,12 @@ } allQueries.addAll(queries); List<Query> qList = new ArrayList<Query>(); - for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); + for(WeightedQuery wQ : queries){ qList.add(wQ.getQuery()); } template2Queries.put(t, qList); } + logger.debug(allQueries); logger.debug("...done in "); return allQueries; } @@ -1011,14 +1021,13 @@ if(popularity == null){ popularity = Integer.valueOf(0); } - System.out.println(popularity); + logger.trace("popularity: "+popularity); - // if(cnt == 0){ // return 0; // } // return Math.log(cnt); - if(popularity!=popularity) {throw new AssertionError("prominence NaN for uri "+uri+", slot type "+type);} + if(Double.isNaN(popularity)) {throw new AssertionError("prominence NaN for uri "+uri+", slot type "+type);} return popularity; } Modified: branches/hmm/components-ext/src/main/resources/tbsl/evaluation/oxford_working_questions.xml =================================================================== (Binary files differ) Added: branches/hmm/components-ext/src/main/resources/tbsl/evaluation/oxford_working_questions_justquestions.xml =================================================================== (Binary files differ) Property changes on: branches/hmm/components-ext/src/main/resources/tbsl/evaluation/oxford_working_questions_justquestions.xml ___________________________________________________________________ Added: svn:mime-type + application/xml Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/QueryTestData.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/QueryTestData.java 2012-10-30 16:10:36 UTC (rev 3861) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/QueryTestData.java 2012-10-30 16:32:40 UTC (rev 3862) @@ -12,6 +12,7 @@ import java.io.PrintWriter; import java.io.Serializable; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.SortedMap; @@ -36,7 +37,8 @@ public class QueryTestData implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; + public boolean hmm = false; public SortedMap<Integer, String> id2Question = new ConcurrentSkipListMap<Integer, String>(); public SortedMap<Integer, String> id2Query = new ConcurrentSkipListMap<Integer, String>(); public SortedMap<Integer, Set<String>> id2Answers = new ConcurrentSkipListMap<Integer, Set<String>>(); @@ -73,138 +75,153 @@ if(!id2Answers.isEmpty()) {throw new AssertionError("Answers already existing.");} for(int i:id2Query.keySet()) { - Set<String> uris = SPARQLTemplateBasedLearner3Test.getUris(endpoint, id2Query.get(i),cache,model); - id2Answers.put(i, uris); // empty answer set better transfers intended meaning and doesn't cause NPEs in html generation :-) - if(!uris.isEmpty()) {/*id2Answers.put(i, uris);*/} - else {id2LearnStatus.put(i, LearnStatus.QUERY_RESULT_EMPTY);} - } - return this; + try + { + Set<String> uris = SPARQLTemplateBasedLearner3Test.getUris(endpoint, id2Query.get(i),cache,model); + // empty answer set better transfers intended meaning and doesn't cause NPEs in html generation :-) + id2Answers.put(i, uris); + if(!uris.isEmpty()) {/*id2Answers.put(i, uris);*/} + else {id2LearnStatus.put(i, LearnStatus.QUERY_RESULT_EMPTY);} + + } + catch(Exception e) + { + id2Answers.put(i, Collections.<String>emptySet()); + id2LearnStatus.put(i, LearnStatus.exceptionStatus(e)); + } } + return this; +} - /** reads test data from a QALD2 benchmark XML file, including questions, queries and answers. - * each question needs to have a query but not necessarily an answer. - * @param file a QALD benchmark XML file - * @param MAX_NUMBER_OF_QUESTIONS the maximum number of questions read from the file. - * @return the test data read from the XML file */ - public static QueryTestData readQaldXml(final File file, int MAX_NUMBER_OF_QUESTIONS) - { - QueryTestData testData = new QueryTestData(); - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(file); - doc.getDocumentElement().normalize(); - NodeList questionNodes = doc.getElementsByTagName("question"); - int id; +/** reads test data from a QALD2 benchmark XML file, including questions, queries and answers. + * each question needs to have a query but not necessarily an answer. + * @param file a QALD benchmark XML file + * @param MAX_NUMBER_OF_QUESTIONS the maximum number of questions read from the file. + * @return the test data read from the XML file */ +public static QueryTestData readQaldXml(final File file, final int MAX_NUMBER_OF_QUESTIONS, boolean whitelistOnly,Set<Integer> whitelist) +{ + QueryTestData testData = new QueryTestData(); + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(file); + doc.getDocumentElement().normalize(); + NodeList questionNodes = doc.getElementsByTagName("question"); + int id; - for(int i = 0; i < questionNodes.getLength(); i++) + for(int i = 0; i < questionNodes.getLength(); i++) + { + if(i>MAX_NUMBER_OF_QUESTIONS) break; + String question; + String query; + Set<String> answers = new HashSet<String>(); + Element questionNode = (Element) questionNodes.item(i); + //read question ID + id = Integer.valueOf(questionNode.getAttribute("id")); + if(whitelistOnly&&!whitelist.contains(id)) {continue;} + + //Read question + question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); + //Read SPARQL query + query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); + // //Read answers + // answers = new HashSet<String>(); + // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); + // for(int j = 0; j < aswersNodes.getLength(); j++){ + // Element answerNode = (Element) aswersNodes.item(j); + // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); + // } + + if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) { - if(i>MAX_NUMBER_OF_QUESTIONS) break; - String question; - String query; - Set<String> answers = new HashSet<String>(); - Element questionNode = (Element) questionNodes.item(i); - //read question ID - id = Integer.valueOf(questionNode.getAttribute("id")); - //Read question - question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); - //Read SPARQL query - query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); - // //Read answers - // answers = new HashSet<String>(); - // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); - // for(int j = 0; j < aswersNodes.getLength(); j++){ - // Element answerNode = (Element) aswersNodes.item(j); - // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); - // } - - if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) + testData.id2Question.put(id, question); + testData.id2Query.put(id, query); + Element answersElement = (Element) questionNode.getElementsByTagName("answers").item(0); + // some of our qald files were mistakenly created so that they have the "answer" elements directly under the question node + // with no answers element + if(answersElement==null) answersElement = (Element)questionNode; +// if(answersElement!=null) { - testData.id2Question.put(id, question); - testData.id2Query.put(id, query); - Element answersElement = (Element) questionNode.getElementsByTagName("answers").item(0); - if(answersElement!=null) + NodeList answerElements = answersElement.getElementsByTagName("answer"); + for(int j=0; j<answerElements.getLength();j++) { - NodeList answerElements = answersElement.getElementsByTagName("answer"); - for(int j=0; j<answerElements.getLength();j++) - { - String answer = ((Element)answerElements.item(j)).getTextContent(); - answers.add(answer); - } - testData.id2Answers.put(id, answers); + String answer = ((Element)answerElements.item(j)).getTextContent(); + answers.add(answer); } - } - // question2Answers.put(question, answers); + testData.id2Answers.put(id, answers); + } + } + // question2Answers.put(question, answers); - } - } catch (DOMException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return testData; - } + } + } catch (DOMException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return testData; +} - /** write the test data to a QALD2 benchmark XML file, including questions, queries and answers. - * each question needs to have a query but not necessarily an answer. - * @param file a QALD benchmark XML file **/ - public void writeQaldXml(final File file) - { - // see http://www.genedavis.com/library/xml/java_dom_xml_creation.jsp - try +/** write the test data to a QALD2 benchmark XML file, including questions, queries and answers. + * each question needs to have a query but not necessarily an answer. + * @param file a QALD benchmark XML file **/ +public void writeQaldXml(final File file) +{ + // see http://www.genedavis.com/library/xml/java_dom_xml_creation.jsp + try + { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.newDocument(); + Element root = doc.createElement("dataset"); + doc.appendChild(root); + + for(Integer i:id2Question.keySet()) { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.newDocument(); - Element root = doc.createElement("dataset"); - doc.appendChild(root); - - for(Integer i:id2Question.keySet()) + Element questionElement = doc.createElement("question"); + questionElement.setAttribute("id", i.toString()); + questionElement.setAttribute("answertype", "resource"); + root.appendChild(questionElement); + Element stringElement = doc.createElement("string"); + stringElement.setTextContent(id2Question.get(i)); + questionElement.appendChild(stringElement); + String query = id2Query.get(i); + if(query!=null) + { + Element queryElement = doc.createElement("query"); + // queryElement.setTextContent(query); + queryElement.appendChild(doc.createCDATASection(query)); + questionElement.appendChild(queryElement); + } + Collection<String> answers = id2Answers.get(i); + if(answers!=null) { - Element questionElement = doc.createElement("question"); - questionElement.setAttribute("id", i.toString()); - questionElement.setAttribute("answertype", "resource"); - root.appendChild(questionElement); - Element stringElement = doc.createElement("string"); - stringElement.setTextContent(id2Question.get(i)); - questionElement.appendChild(stringElement); - String query = id2Query.get(i); - if(query!=null) - { - Element queryElement = doc.createElement("query"); -// queryElement.setTextContent(query); - queryElement.appendChild(doc.createCDATASection(query)); - questionElement.appendChild(queryElement); - } - Collection<String> answers = id2Answers.get(i); - if(answers!=null) + for(String answer: answers) { - for(String answer: answers) - { - Element answerElement = doc.createElement("answer"); - answerElement.setTextContent(answer); - questionElement.appendChild(answerElement); - } + Element answerElement = doc.createElement("answer"); + answerElement.setTextContent(answer); + questionElement.appendChild(answerElement); } - } - //set up a transformer - TransformerFactory transfac = TransformerFactory.newInstance(); - Transformer trans = transfac.newTransformer(); - trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - trans.setOutputProperty(OutputKeys.INDENT, "yes"); + } + } + //set up a transformer + TransformerFactory transfac = TransformerFactory.newInstance(); + Transformer trans = transfac.newTransformer(); + trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); - - //create string from xml tree - PrintWriter sw = new PrintWriter(file); - StreamResult result = new StreamResult(sw); - DOMSource source = new DOMSource(doc); - trans.transform(source, result); - } - catch (Exception e) {throw new RuntimeException(e);} + + //create string from xml tree + PrintWriter sw = new PrintWriter(file); + StreamResult result = new StreamResult(sw); + DOMSource source = new DOMSource(doc); + trans.transform(source, result); } + catch (Exception e) {throw new RuntimeException(e);} +} } \ No newline at end of file Modified: branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 16:10:36 UTC (rev 3861) +++ branches/hmm/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 16:32:40 UTC (rev 3862) @@ -4,6 +4,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -12,9 +13,12 @@ import java.io.PrintWriter; import java.io.Serializable; import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.URL; import java.net.URLDecoder; import java.text.DateFormat; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -36,6 +40,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -44,6 +49,9 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.collections15.BidiMap; +import org.apache.commons.collections15.bidimap.DualHashBidiMap; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -69,7 +77,6 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import cern.colt.Arrays; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; @@ -99,25 +106,150 @@ // problem mit "In/IN which/WDT films/NNS did/VBD Julia/NNP Roberts/NNP as/RB well/RB as/IN Richard/NNP Gere/NNP play/NN" public class SPARQLTemplateBasedLearner3Test -{ +{ + private static final boolean USE_HMM = false; private static final File evaluationFolder = new File("cache/evaluation"); private static final boolean DBPEDIA_PRETAGGED = true; private static final boolean OXFORD_PRETAGGED = false; - private static final int MAX_NUMBER_OF_QUESTIONS = 10; + private static final int MAX_NUMBER_OF_QUESTIONS = 20; + private static final boolean WHITELIST_ONLY = false; + private static final Set<Integer> WHITELIST = Collections.unmodifiableSet(new HashSet<Integer>(Arrays.asList(new Integer[] {4}))); - @Test public void testDBpedia() throws Exception + /*@Test*/ public void testDBpedia() throws Exception { File file = generateTestDataIfNecessary( new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml").getFile()), SparqlEndpoint.getEndpointDBpedia(), dbpediaLiveCache); - test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null); + test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null,DBPEDIA_PRETAGGED); } - /*@Test*/ public void testOxford() throws Exception + // private char[] hmmHtmlRow(String question, String string, String string2, String string3, Set<String> set, Set<String> set2, + // Set<String> set3, LearnStatus learnStatus, LearnStatus learnStatus2) + // { + // return null; + // } + + private static boolean probablySparqlSelectQuery(String s) { + s=s.toLowerCase(); + return s.contains("select")&&s.contains("{")&&s.contains("}"); + } + + /** returns an html table row representation <tr><td>t(o_1)</td>...<td>t(o_n)</td></tr> of the string representation of objects, + * transformed by escaping HTML characters, setting fixed width on SPARQL queries and shortening and linking of dbpedia resource URIs. + */ + // unescaped form from the top: <tr><td>t(o_1)</td>...<td>t(o_n)</td></tr> + private static String htmlTableTr(Object... tds) + { + System.out.println(); + StringBuilder sb = new StringBuilder(); + // shorten and link dbpedia resource uris + Pattern p = Pattern.compile("http://dbpedia\\.org/resource/([\\w]*)"); + + for(Object td: tds) + { + if(td==null) {sb.append("<td></td>");continue;} + sb.append("<td>"); + + // probably a SPARQL query? use fixed font width. + String s = StringEscapeUtils.escapeHtml(td.toString()); + if(probablySparqlSelectQuery(s)) {s="<pre>"+s+"</pre>";} + else {s =(p.matcher(s).replaceAll("<a href=\"$0\">dbpedia:$1</a>"));} + + sb.append(s); + sb.append("</td>"); + } + return sb.toString(); + } + + @SuppressWarnings("unchecked") /*@Test*/ public void evaluateHMMAgainstNormalAndBenchmark() throws FileNotFoundException + { + // get the newest evaluations from both with and without hmm + SortedMap<Long,Evaluation> evaluations = new TreeMap<Long,Evaluation>(Collections.reverseOrder()); + evaluations.putAll(Evaluation.read()); + Evaluation newestWithHmm = null; + Evaluation newestWithoutHmm = null; + + for(Iterator<Long> it = evaluations.keySet().iterator();it.hasNext()&&(newestWithHmm==null||newestWithoutHmm==null);) + { + Evaluation e = evaluations.get(it.next()); + if(e.testData.hmm) + {if(newestWithHmm==null) {newestWithHmm=e;}} + else if(newestWithoutHmm==null) {newestWithoutHmm=e;} + } + if(newestWithHmm==null||newestWithoutHmm==null) {logger.warn("No pair of evaluations for Aborting.");return;} + + Set<String> intersectionOfQuestions = new HashSet<String>(newestWithHmm.testData.id2Question.values()); + intersectionOfQuestions.retainAll(newestWithoutHmm.testData.id2Question.values()); + if(intersectionOfQuestions.isEmpty()) {logger.warn("No common questions. Aborting.");return;} + + Set<String> questionsOnlyCorrectWithHMM = new HashSet<String> (intersectionOfQuestions); + questionsOnlyCorrectWithHMM.retainAll(newestWithHmm.correctlyAnsweredQuestions); + questionsOnlyCorrectWithHMM.removeAll(newestWithoutHmm.correctlyAnsweredQuestions); + + Set<String> questionsOnlyCorrectWithoutHMM = new HashSet<String> (intersectionOfQuestions); + questionsOnlyCorrectWithoutHMM.retainAll(newestWithoutHmm.correctlyAnsweredQuestions); + questionsOnlyCorrectWithoutHMM.removeAll(newestWithHmm.correctlyAnsweredQuestions); + + PrintWriter out = new PrintWriter("log/evaluatehmm.html"); + String title = "Evaluation of HMM vs the normal disambiguation."; + + out.println("<!DOCTYPE html><html>\n<head><title>"+title+"</title></head>\n<body>\n<table border='1'>"); + out.println("<tr><th>Question</th><th>Query with HMM</th><th>Query without HMM</th><th>Reference Query</th>" + + "<th>Answers with HMM</th><th>Answers without HMM</th><th>Reference Answers</th><th>Status with HMM</th><th>Status without HMM</th></tr>"); + + // most of the time it should be enough to assume that the keys are equal, but this could introduce subtle bugs + BidiMap<String,Integer> question2IdWithHmm = new DualHashBidiMap<Integer,String>(newestWithHmm.testData.id2Question).inverseBidiMap(); + BidiMap<String,Integer> question2IdWithoutHmm = new DualHashBidiMap<Integer,String>(newestWithoutHmm.testData.id2Question).inverseBidiMap(); + // if(newestWithHmm.correctlyAnsweredQuestions.contains(question)!=newestWithoutHmm.correctlyAnsweredQuestions.contains(question)) {..} + + for(Set<String> c : new Set[] {questionsOnlyCorrectWithHMM, questionsOnlyCorrectWithoutHMM}) + { + for(String question: c) + { + int idWithHmm = question2IdWithHmm.get(question); + int idWithoutHmm = question2IdWithoutHmm.get(question); + out.println(htmlTableTr( + question, + newestWithHmm.testData.id2Query.get(idWithHmm), + newestWithoutHmm.testData.id2Query.get(idWithoutHmm), + newestWithHmm.referenceData.id2Query.get(idWithHmm), + newestWithHmm.testData.id2Answers.get(idWithHmm), + newestWithoutHmm.testData.id2Answers.get(idWithoutHmm), + newestWithHmm.referenceData.id2Answers.get(idWithHmm), + newestWithHmm.testData.id2LearnStatus.get(idWithHmm), + newestWithoutHmm.testData.id2LearnStatus.get(idWithoutHmm) + )); + } + } + + // Integer id = question2Id.get(question); + // if(evaluation.testData.id2Answers.get(id)==null) {System.err.println(question);continue;} + // out.println( + // "<tr><td>"+question+"</td>"+ + // "<td><code><pre>"+escapePre(evaluation.testData.id2Query.get(id))+"</pre></code></td>"+ + // "<td><code><pre>"+escapePre(evaluation.referenceData.id2Query.get(id))+"</pre></code></td>"+ + // "<td><ul>"+getAnswerHTMLList(evaluation.testData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ + // "<td><ul>"+getAnswerHTMLList(evaluation.referenceData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ + // "<td>"+evaluation.testData.id2LearnStatus.get(id)+"</td></tr>"); + + + + + + logger.info(questionsOnlyCorrectWithHMM.size()+" questions only correct with hmm, "+ + questionsOnlyCorrectWithoutHMM.size()+" questions only correct without hmm"); + + // generate a html description of it + + out.close(); + } + + @Test public void testOxford() throws Exception + { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); - test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex()); + test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex(),OXFORD_PRETAGGED); } // /*@Test*/ public void testOxford() throws Exception @@ -180,7 +312,7 @@ logger.info("learned query: "+testData.id2Query.get(0)); } - /*@Test*/ public void generateXMLOxford() throws IOException + /*@Test*/ @SuppressWarnings("null") public void generateXMLOxford() throws IOException { boolean ADD_POS_TAGS = true; PartOfSpeechTagger posTagger = null; @@ -289,10 +421,10 @@ } } - public void test(String title, final File referenceXML,final SparqlEndpoint endpoint,ExtractionDBCache cache,Knowledgebase kb, Model model, MappingBasedIndex index) + public void test(String title, final File referenceXML,final SparqlEndpoint endpoint,ExtractionDBCache cache,Knowledgebase kb, Model model, MappingBasedIndex index,boolean pretagged) throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException { - evaluateAndWrite(title,referenceXML,endpoint,cache,kb,model,index); + evaluateAndWrite(title,referenceXML,endpoint,cache,kb,model,index,pretagged); generateHTML(title); // if(evaluation.numberOfCorrectAnswers<3) {fail("only " + evaluation.numberOfCorrectAnswers+" correct answers.");} @@ -335,14 +467,14 @@ } private void evaluateAndWrite(String title,final File updatedReferenceXML, final SparqlEndpoint endpoint,ExtractionDBCache cache, - Knowledgebase kb, Model model, MappingBasedIndex index) + Knowledgebase kb, Model model, MappingBasedIndex index,boolean pretagged) { - QueryTestData referenceTestData = QueryTestData.readQaldXml(updatedReferenceXML,MAX_NUMBER_OF_QUESTIONS); + QueryTestData referenceTestData = QueryTestData.readQaldXml(updatedReferenceXML,MAX_NUMBER_OF_QUESTIONS,WHITELIST_ONLY,WHITELIST); logger.info(title+" subset loaded with "+referenceTestData.id2Question.size()+" questions."); long startLearning = System.currentTimeMillis(); - QueryTestData learnedTestData = generateTestDataMultiThreaded(referenceTestData.id2Question, kb,model,index,DBPEDIA_PRETAGGED); + QueryTestData learnedTestData = generateTestDataMultiThreaded(referenceTestData.id2Question, kb,model,index,pretagged); long endLearning = System.currentTimeMillis(); logger.info("finished learning after "+(endLearning-startLearning)/1000.0+"s"); learnedTestData.generateAnswers(endpoint,cache,model); @@ -376,6 +508,17 @@ String referenceQuery = reference.id2Query.get(i); String suspectQuery = suspect.id2Query.get(i); // reference is required to contain answers for every key so we shouldn't get NPEs here (even though it could be the empty set but that shouldn't happen because only questions with nonempty answers are included in the updated reference) + if(reference.id2Answers.get(i)==null) + { + logger.warn("no reference answers for question "+i+" ("+question+")"); + continue; + } + if(suspect.id2Answers.get(i)==null) + { + logger.warn("no suspect answers for question "+i+" ("+question+")"); + continue; + } + if(referenceQuery.equals(suspectQuery)||reference.id2Answers.get(i).equals(suspect.id2Answers.get(i))) { evaluation.correctlyAnsweredQuestions.add(question); @@ -456,9 +599,12 @@ } catch(IOException e) {throw new RuntimeException(e);} } + /** + * @return the evaluations by timestamp, sorted ascending (from oldest to newest) + */ public static SortedMap<Long,Evaluation> read() { - SortedMap<Long,Evaluation> evaluations = new ConcurrentSkipListMap<Long,Evaluation>(); + SortedMap<Long,Evaluation> evaluations = new ConcurrentSkipListMap<Long,Evaluation>(); evaluationFolder.mkdirs(); File[] files = evaluationFolder.listFiles(); for(int i=0;i<files.length;i++) {evaluations.put(Long.valueOf(files[i].getName()),read(files[i]));} @@ -603,6 +749,7 @@ private QueryTestData generateTestDataMultiThreaded(SortedMap<Integer, String> id2Question,Knowledgebase kb,Model model, MappingBasedIndex index,boolean pretagged) { QueryTestData testData = new QueryTestData(); + testData.hmm = USE_HMM; // -- only create the learner parameters once to save time -- // PartOfSpeechTagger posTagger = new StanfordPartOfSpeechTagger(); // WordNet wordnet = new WordNet(); @@ -792,15 +939,32 @@ // private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} + private static boolean httpResponseOK(String url) throws MalformedURLException, IOException + { + HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + connection.setRequestMethod("HEAD"); + int responseCode = connection.getResponseCode(); + return responseCode == 200; + } private static Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) { - SOLRIndex resourcesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_resources"); + String resourcesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_resources123"; + String classesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_classes"; + String propertiesURL = "http://dbpedia.aksw.org:8080/solr/dbpedia_properties"; + String boaPropertiesURL = "http://139.18.2.173:8080/solr/boa_fact_detail"; + +// for(String url : new String[] {resourcesURL,classesURL,propertiesURL,boaPropertiesURL}) +// { +// try{if(!httpResponseOK(url)) throw new RuntimeException("Http response not 200 for url "+url);} catch(Exception e) {throw new RuntimeException(e);} +// } + + SOLRIndex resourcesIndex = new SOLRIndex(resourcesURL); resourcesIndex.setPrimarySearchField("label"); // resourcesIndex.setSortField("pagerank"); - Index classesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_classes"); - Index propertiesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_properties"); - SOLRIndex boa_propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/boa_fact_detail"); + Index classesIndex = new SOLRIndex(classesURL); + Index propertiesIndex = new SOLRIndex(propertiesURL); + SOLRIndex boa_propertiesIndex = new SOLRIndex(boaPropertiesURL); boa_propertiesIndex.setSortField("boa-score"); // propertiesIndex = new HierarchicalIndex(boa_propertiesIndex, propertiesIndex); MappingBasedIndex mappingIndex= new MappingBasedIndex( @@ -820,11 +984,13 @@ Logger.getRootLogger().setLevel(Level.WARN); Logger.getLogger(Templator.class).setLevel(Level.WARN); Logger.getLogger(Parser.class).setLevel(Level.WARN); - Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.WARN); + Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.DEBUG); // Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.INFO); logger.setLevel(Level.INFO); // TODO: remove when finishing implementation of this class logger.addAppender(new FileAppender(new SimpleLayout(), "log/"+this.getClass().getSimpleName()+".log", false)); + // Logger.getRootLogger().removeAllAppenders(); + // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); // oxfordLearner = new SPARQLTemplateBasedLearner2(createOxfordKnowledgebase(oxfordCache)); } @@ -846,8 +1012,9 @@ } catch(QueryExceptionHTTP e) { - logger.error("Error getting uris for query "+query+" at endpoint "+endpoint,e); - return Collections.<String>emptySet(); + throw new QueryExceptionHTTP("Error getting uris for query "+query+" at endpoint "+endpoint,e); + // logger.error("Error getting uris for query "+query+" at endpoint "+endpoint,e); + // return Collections.<String>emptySet(); } String variable = "?uri"; resultsetloop: @@ -976,14 +1143,13 @@ @Override public LearnStatus call() { - logger.trace("learning question: "+question); try { // learn query learner.setQuestion(question); - learner.learnSPARQLQueries(); + learner.learnSPARQLQueries(USE_HMM); String learnedQuery = learner.getBestSPARQLQuery(); testData.id2Question.put(id, question); if(learnedQuery!=null&&!learnedQuery.isEmpty()) @@ -995,6 +1161,11 @@ // Set<String> learnedURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); } + catch(AssertionError e ) + { + // this is the only exception that we want to halt on + throw new RuntimeException(e); + } catch(NoTemplateFoundException e) { logger.warn(String.format("no template found for question \"%s\"",question)); @@ -1070,7 +1241,7 @@ out.println("<!DOCTYPE html><html>\n<head><title>"+title+"</title></head>\n<body>\n<table border='1'>"); if(queriesAvailable) { - out.println("<tr><th>Question</th><th>Learned Query</th><th>Reference Query</th><th>Learned Answers</th><th>Reference Answers</th></tr>"); + out.println("<tr><th>Question</th><th>Learned Query</th><th>Reference Query</th><th>Learned Answers</th><th>Reference Answers</th><th>Error Type</th></tr>"); for(String question: questions) { Integer id = question2Id.get(question); @@ -1080,8 +1251,9 @@ "<td><code><pre>"+escapePre(evaluation.testData.id2Query.get(id))+"</pre></code></td>"+ "<td><code><pre>"+escapePre(evaluation.referenceData.id2Query.get(id))+"</pre></code></td>"+ "<td><ul>"+getAnswerHTMLList(evaluation.testData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ - "<td><ul>"+getAnswerHTMLList(evaluation.referenceData.id2Answers.get(id).toArray(new String[0]))+"</ul></td></tr>"); - } + "<td><ul>"+getAnswerHTMLList(evaluation.referenceData.id2Answers.get(id).toArray(new String[0]))+"</ul></td>"+ + "<td>"+evaluation.testData.id2LearnStatus.get(id)+"</td></tr>"); + } } else { out.println("<tr><th>Question</th><th>Error Type</th></tr>"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-10-30 16:10:51
|
Revision: 3861 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3861&view=rev Author: kirdie Date: 2012-10-30 16:10:36 +0000 (Tue, 30 Oct 2012) Log Message: ----------- corrected the oxford benchmarking. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 12:53:54 UTC (rev 3860) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 16:10:36 UTC (rev 3861) @@ -1,27 +1,19 @@ package org.dllearner.algorithm.tbsl.learning; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URL; +import hmm.HiddenMarkovModel; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import org.apache.commons.collections15.MultiMap; import org.apache.log4j.Logger; import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; @@ -31,13 +23,7 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.Allocation; import org.dllearner.algorithm.tbsl.sparql.Query; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -46,13 +32,10 @@ import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; -import org.dllearner.algorithm.tbsl.util.Similarity; -import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; import org.dllearner.common.index.Index; import org.dllearner.common.index.IndexResultItem; import org.dllearner.common.index.IndexResultSet; import org.dllearner.common.index.MappingBasedIndex; -import org.dllearner.common.index.SOLRIndex; import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; import org.dllearner.common.index.SPARQLIndex; import org.dllearner.common.index.SPARQLObjectPropertiesIndex; @@ -63,19 +46,13 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.Thing; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.reasoning.SPARQLReasoner; -import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; - import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; @@ -85,10 +62,6 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.sparql.expr.ExprAggregator; -import com.hp.hpl.jena.sparql.expr.ExprVar; -import com.hp.hpl.jena.sparql.expr.aggregate.AggCount; -import com.hp.hpl.jena.sparql.expr.aggregate.Aggregator; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -516,358 +489,88 @@ return relevantKeywords; } - private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ - logger.debug("Generating SPARQL query candidates..."); - - Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { - - @Override - public int compare(Slot o1, Slot o2) { - if(o1.getSlotType() == o2.getSlotType()){ - return o1.getToken().compareTo(o2.getToken()); - } else { - return -1; + // just for testing the HMM integration, getWeightedSPARQLQueriesOld is the original one + private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates) + { + // for testing + for(Template template: templates) + { + { + ArrayList<String> keywords = new ArrayList<String>(); + for(Slot slot: template.getSlots()) + { + keywords.add(slot.getWords().get(0)); } + if(template.getSlots().size()!=3) {continue;} + if(!keywords.contains("Mean Hamster Software")) {continue;} + if(!keywords.contains("published")) {continue;} + System.out.println("\"keywords\": "+keywords); } - }); - slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); - - - SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); - - Set<Allocation> allocations; - - for(Template t : templates){ - logger.info("Processing template:\n" + t.toString()); - allocations = new TreeSet<Allocation>(); - boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); - - ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); - List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); - - long startTime = System.currentTimeMillis(); - - for (Slot slot : t.getSlots()) { - if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); - Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); - Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); - list.add(submit); - } - } - - for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { - try { - Map<Slot, SortedSet<Allocation>> result = future.get(); - Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); - slot2Allocations.put(item.getKey(), item.getValue()); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); + System.out.println(template); + SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); + Query query = template.getQuery(); + double score = 0; + + Map<List<String>,Collection<String>> segmentToURIs = new HashMap<List<String>,Collection<String>>(); + for(Slot slot: template.getSlots()) + { + List<String> segment = new LinkedList<String>(); + segment.add(slot.getWords().get(0)); // TODO: split it up? + + Set<String> uris = new HashSet<String>(); + + for(IndexResultItem item : getIndexResultItems(slot)) + { + uris.add(item.getUri()); } + segmentToURIs.put(segment,uris); } + HiddenMarkovModel hmm = new HiddenMarkovModel(); + hmm.initialization(); + hmm.startMarkovModel(segmentToURIs,true); + MultiMap<Double,List<String>> paths = hmm.getPaths(); - executor.shutdown(); + // System.out.println(hmm.getPaths()); + // die keywords jetzt in sadeehs algorithmus reinwerfen + // da kommen jetzt pfade raus mit unterschiedlichen wahrscheinlichkeiten + // HiddenMarkovModel HMM = new HiddenMarkovModel(); + // HMM.StartMarkovModel(); + // jetzt die variablen aus der query ersetzen mit den kandidaten + // ranked list der pfade, die die observation sequence generieren - - /*for(Slot slot : t.getSlots()){ - allocations = slot2Allocations2.get(slot); - if(allocations == null){ - allocations = computeAllocations(slot, 10); - slot2Allocations2.put(slot, allocations); - } - slot2Allocations.put(slot, allocations); - - //for tests add the property URI with http://dbpedia.org/property/ namespace - //TODO should be replaced by usage of a separate SOLR index - Set<Allocation> tmp = new HashSet<Allocation>(); - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(Allocation a : allocations){ - String uri = "http://dbpedia.org/property/" + a.getUri().substring(a.getUri().lastIndexOf("/")+1); - Allocation newA = new Allocation(uri, a.getSimilarity(), a.getProminence()); - newA.setScore(a.getScore()-0.000001); - tmp.add(newA); + for(Double d : paths.keySet()) + { + for(List<String> path : paths.get(d)) + { + Query q = new Query(query); + // TODO: which variable stands for which resource? do it randomly now to check if the replacement works and then correct the order later + System.out.println(q.getVariablesAsStringList()); + System.out.println(); + int i = 0; + for(String var : q.getVariablesAsStringList()) + { + q.replaceVarWithURI(var, path.get(i)); + i++; } - } - allocations.addAll(tmp); - }*/ - logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + System.out.println(q); - Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); - Query cleanQuery = t.getQuery(); - queries.add(new WeightedQuery(cleanQuery)); - Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); - List<Slot> sortedSlots = new ArrayList<Slot>(); - Set<Slot> classSlots = new HashSet<Slot>(); - for(Slot slot : t.getSlots()){ - if(slot.getSlotType() == SlotType.CLASS){ - sortedSlots.add(slot); - classSlots.add(slot); + WeightedQuery wQuery = new WeightedQuery(q, score); + queries.add(wQuery); } } - for(Slot slot : t.getSlots()){ - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ - sortedSlots.add(slot); - } - } - for(Slot slot : t.getSlots()){ - if(!sortedSlots.contains(slot)){ - sortedSlots.add(slot); - } - } - //add for each SYMPROPERTY Slot the reversed query - for(Slot slot : sortedSlots){ - for(WeightedQuery wQ : queries){ - if(slot.getSlotType() == SlotType.SYMPROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY){ - Query reversedQuery = new Query(wQ.getQuery()); - reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); - tmp.add(new WeightedQuery(reversedQuery)); - } - tmp.add(wQ); - } - queries.clear(); - queries.addAll(tmp); - tmp.clear(); - } + //System.exit(0); + return queries; + // >> SLOTS: + // y0: RESOURCE {Mean Hamster Software} + // p0: OBJECTPROPERTY {published,print} + // p1: CLASS {video games} - for(Slot slot : sortedSlots){ - if(!slot2Allocations.get(slot).isEmpty()){ - for(Allocation a : slot2Allocations.get(slot)){ - for(WeightedQuery query : queries){ - Query q = new Query(query.getQuery()); - boolean drop = false; - if(useDomainRangeRestriction){ - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - String objectVar = triple.getValue().getName(); - String subjectVar = triple.getVariable().getName(); - // System.out.println(triple); - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ - // System.out.println(typeTriple); - if(true){//reasoner.isObjectProperty(a.getUri())){ - Description range = reasoner.getRange(new ObjectProperty(a.getUri())); - // System.out.println(a); - if(range != null){ - Set<Description> allRanges = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(range instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(range); - allRanges.addAll(superClasses); - } else { - for(Description nc : range.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allRanges.addAll(superClasses); - } - } - allRanges.add(range); - allRanges.remove(new NamedClass(Thing.instance.getURI())); - - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ - drop = true; - } - } - } else { - drop = true; - } - - } - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ - Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); - // System.out.println(a); - if(domain != null){ - Set<Description> allDomains = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(domain instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(domain); - allDomains.addAll(superClasses); - } else { - for(Description nc : domain.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allDomains.addAll(superClasses); - } - } - allDomains.add(domain); - allDomains.remove(new NamedClass(Thing.instance.getURI())); - - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ - drop = true; - } else { - - } - } - } - } - } - } - - if(!drop){ - if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - SPARQL_Value object = triple.getValue(); - if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position - SPARQL_Property predicate = triple.getProperty(); - if(!predicate.isVariable()){//only consider triple where predicate is URI - String predicateURI = predicate.getName().replace("<", "").replace(">", ""); - if(isDatatypeProperty(predicateURI)){//if data property - q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - WeightedQuery w = new WeightedQuery(q); - double newScore = query.getScore() + a.getScore(); - w.setScore(newScore); - w.addAllocations(query.getAllocations()); - w.addAllocation(a); - tmp.add(w); - } - - - } - } - //lower queries with FILTER-REGEX - if(containsRegex){ - for(WeightedQuery wQ : tmp){ - wQ.setScore(wQ.getScore() - 0.01); - } - } - - queries.clear(); - queries.addAll(tmp);//System.out.println(tmp); - tmp.clear(); - } else {//Add REGEX FILTER if resource slot is empty and predicate is datatype property - if(slot.getSlotType() == SlotType.RESOURCE){ - for(WeightedQuery query : queries){ - Query q = query.getQuery(); - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - SPARQL_Value object = triple.getValue(); - if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position - SPARQL_Property predicate = triple.getProperty(); - if(!predicate.isVariable()){//only consider triple where predicate is URI - String predicateURI = predicate.getName().replace("<", "").replace(">", ""); - if(isDatatypeProperty(predicateURI)){//if data property - q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); - } - } - } - } - - } - - } else { - if(slot.getSlotType() == SlotType.SYMPROPERTY){ - for(WeightedQuery wQ : queries){ - List<SPARQL_Triple> triples = wQ.getQuery().getTriplesWithVar(slot.getAnchor()); - for(SPARQL_Triple triple : triples){ - String typeVar; - String resourceURI; - SymPropertyDirection direction; - if(triple.getValue().isVariable()){ - direction = SymPropertyDirection.VAR_RIGHT; - typeVar = triple.getValue().getName(); - resourceURI = triple.getVariable().getName(); - } else { - direction = SymPropertyDirection.VAR_LEFT; - typeVar = triple.getVariable().getName(); - resourceURI = triple.getValue().getName(); - } - resourceURI = resourceURI.replace("<", "").replace(">", ""); - List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); - for(SPARQL_Triple typeTriple : typeTriples){ - String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); - // List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); - // for(Entry<String, Integer> property : mostFrequentProperties){ - // wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); - // wQ.setScore(wQ.getScore() + 0.1); - // } - } - - } - } - } - } - // else if(slot.getSlotType() == SlotType.CLASS){ - // String token = slot.getWords().get(0); - // if(slot.getToken().contains("house")){ - // String regexToken = token.replace("houses", "").replace("house", "").trim(); - // try { - // Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); - // SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); - // if(alloc != null && !alloc.isEmpty()){ - // String uri = alloc.first().getUri(); - // for(WeightedQuery query : queries){ - // Query q = query.getQuery(); - // for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - // SPARQL_Term subject = triple.getVariable(); - // SPARQL_Term object = new SPARQL_Term("desc"); - // object.setIsVariable(true); - // object.setIsURI(false); - // q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); - // q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - // object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); - // } - // q.replaceVarWithURI(slot.getAnchor(), uri); - // - // } - // } - // } catch (Exception e) { - // e.printStackTrace(); - // } - // } - // } - - - } - - } - for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { - WeightedQuery wQ = iterator.next(); - if(dropZeroScoredQueries){ - if(wQ.getScore() <= 0){ - iterator.remove(); - } - } else { - if(t.getSlots().size()==0) throw new AssertionError("no slots for query "+wQ); - wQ.setScore(wQ.getScore()/t.getSlots().size()); - } - - } - allQueries.addAll(queries); - List<Query> qList = new ArrayList<Query>(); - for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); - qList.add(wQ.getQuery()); - } - template2Queries.put(t, qList); + // System.out.println(template); } - logger.debug("...done in "); - return allQueries; + // + return null; } private double getProminenceValue(String uri, SlotType type){ @@ -1142,101 +845,51 @@ } - class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ - - private Slot slot; - - public SlotProcessor(Slot slot) { - this.slot = slot; - } - - @Override - public Map<Slot, SortedSet<Allocation>> call() throws Exception { - Map<Slot, SortedSet<Allocation>> result = new HashMap<Slot, SortedSet<Allocation>>(); - result.put(slot, computeAllocations(slot)); - return result; - } - - private SortedSet<Allocation> computeAllocations(Slot slot){ - logger.debug("Computing allocations for slot: " + slot); - SortedSet<Allocation> allocations = new TreeSet<Allocation>(); - - Index index = getIndexBySlotType(slot); - - IndexResultSet rs; - for(String word : slot.getWords()){ - rs = new IndexResultSet(); - if(mappingIndex != null){ - SlotType type = slot.getSlotType(); - if(type == SlotType.CLASS){ - rs.add(mappingIndex.getClassesWithScores(word)); - } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ - rs.add(mappingIndex.getPropertiesWithScores(word)); - } else if(type == SlotType.DATATYPEPROPERTY){ - rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); - } else if(type == SlotType.OBJECTPROPERTY){ - rs.add(mappingIndex.getObjectPropertiesWithScores(word)); - } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ - rs.add(mappingIndex.getResourcesWithScores(word)); - } + private Set<IndexResultItem> getIndexResultItems(Slot slot) + { +// List<String> uris = new LinkedList<String>(); + Set<IndexResultItem> indexResultItems = new HashSet<IndexResultItem>(); + + Index index = getIndexBySlotType(slot); + + for(String word : slot.getWords()) + { + IndexResultSet rs = new IndexResultSet(); + if(mappingIndex != null){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + rs.add(mappingIndex.getClassesWithScores(word)); + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + rs.add(mappingIndex.getPropertiesWithScores(word)); + } else if(type == SlotType.DATATYPEPROPERTY){ + rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); + } else if(type == SlotType.OBJECTPROPERTY){ + rs.add(mappingIndex.getObjectPropertiesWithScores(word)); + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + rs.add(mappingIndex.getResourcesWithScores(word)); } - //use the non manual indexes only if mapping based resultset is not empty and option is set - if(!useManualMappingsIfExistOnly || rs.isEmpty()){ - if(slot.getSlotType() == SlotType.RESOURCE){ - rs.add(index.getResourcesWithScores(word, 20)); - } else { - if(slot.getSlotType() == SlotType.CLASS){ - word = PlingStemmer.stem(word); - } - rs.add(index.getResourcesWithScores(word, 20)); + } + //use the non manual indexes only if mapping based resultset is not empty and option is set + if(!useManualMappingsIfExistOnly || rs.isEmpty()){ + if(slot.getSlotType() == SlotType.RESOURCE){ + rs.add(index.getResourcesWithScores(word, 20)); + } else { + if(slot.getSlotType() == SlotType.CLASS){ + word = PlingStemmer.stem(word); } + rs.add(index.getResourcesWithScores(word, 20)); } - - - for(IndexResultItem item : rs.getItems()){ - double similarity = Similarity.getSimilarity(word, item.getLabel()); - // //get the labels of the redirects and compute the highest similarity - // if(slot.getSlotType() == SlotType.RESOURCE){ - // Set<String> labels = getRedirectLabels(item.getUri()); - // for(String label : labels){ - // double tmp = Similarity.getSimilarity(word, label); - // if(tmp > similarity){ - // similarity = tmp; - // } - // } - // } - double prominence = getProminenceValue(item.getUri(), slot.getSlotType()); - allocations.add(new Allocation(item.getUri(), prominence, similarity)); - } - } - - normProminenceValues(allocations); - - computeScore(allocations); - logger.debug("Found " + allocations.size() + " allocations for slot " + slot); - return new TreeSet<Allocation>(allocations); +// for(IndexResultItem item: rs.getItems()) +// { +// uris.add(item.getUri()); +// } + indexResultItems.addAll(rs.getItems()); } - - private Index getIndexBySlotType(Slot slot){ - Index index = null; - SlotType type = slot.getSlotType(); - if(type == SlotType.CLASS){ - index = classesIndex; - } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ - index = propertiesIndex; - } else if(type == SlotType.DATATYPEPROPERTY){ - index = datatypePropertiesIndex; - } else if(type == SlotType.OBJECTPROPERTY){ - index = objectPropertiesIndex; - } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ - index = resourcesIndex; - } - return index; - } - + return indexResultItems; } + public String getTaggedInput() { if(templateGenerator==null) {throw new AssertionError("Learner not initialized. Please call init();");} @@ -1255,33 +908,33 @@ return isDatatypeProperty; } - /** - * @param args - * @throws NoTemplateFoundException - * @throws IOException - * @throws FileNotFoundException - * @throws InvalidFileFormatException - */ - public static void main(String[] args) throws Exception { - SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), - Collections.<String>singletonList(""), Collections.<String>emptyList()); - Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); - Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); - Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); + // /** + // * @param args + // * @throws NoTemplateFoundException + // * @throws IOException + // * @throws FileNotFoundException + // * @throws InvalidFileFormatException + // */ + // public static void main(String[] args) throws Exception { + // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), + // Collections.<String>singletonList(""), Collections.<String>emptyList()); + // Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); + // Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); + // Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); + // + // SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + // learner.init(); + // + // String question = "What is the highest mountain?"; + // + // learner.setQuestion(question); + // learner.learnSPARQLQueries(); + // System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + // System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + // System.out.println(learner.getLearnedPosition()); + // + // } - SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); - learner.init(); - String question = "What is the highest mountain?"; - learner.setQuestion(question); - learner.learnSPARQLQueries(); - System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); - System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); - System.out.println(learner.getLearnedPosition()); - - } - - - } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-10-30 12:53:54 UTC (rev 3860) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-10-30 16:10:36 UTC (rev 3861) @@ -58,7 +58,7 @@ unions = new HashSet<SPARQL_Union>(); } - //copy constructor + /** copy constructor*/ public Query(Query query){ this.qt = query.getQt(); Set<SPARQL_Term> selTerms = new HashSet<SPARQL_Term>(); Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 12:53:54 UTC (rev 3860) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 16:10:36 UTC (rev 3861) @@ -114,7 +114,7 @@ test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null); } - @Test public void testOxford() throws Exception + /*@Test*/ public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex()); @@ -160,6 +160,26 @@ logger.info("learned query: "+testData.id2Query.get(0)); } + /** For debugging one question in particular. + */ + @Test public void testSingleQueryDBpedia() + { +// Logger.getLogger(Templator.class).setLevel(Level.DEBUG); +// Logger.getLogger(Parser.class).setLevel(Level.DEBUG); +// Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.DEBUG); + // String question = "houses for less than 900000 pounds"; + String question = "Give/VB me/PRP all/DT video/JJ games/NNS published/VBN by/IN Mean/NNP Hamster/NNP Software/NNP"; +// String question = "give me all video games published by mean hamster software"; +// String question = "Give me all video games published by Mean Hamster Software"; +// question = new StanfordPartOfSpeechTagger().tag(question); +// System.out.println(question); + +// Model model = loadOxfordModel(); + QueryTestData testData = new QueryTestData(); + new LearnQueryCallable(question, 0, testData, dbpediaLiveKnowledgebase, true).call(); + logger.info("learned query: "+testData.id2Query.get(0)); + } + /*@Test*/ public void generateXMLOxford() throws IOException { boolean ADD_POS_TAGS = true; @@ -935,6 +955,7 @@ learner = new SPARQLTemplateBasedLearner2(knowledgeBase,pretagged?null:POSTaggerHolder.posTagger,wordnet,options); try {learner.init();} catch (ComponentInitException e) {throw new RuntimeException(e);} learner.setUseIdealTagger(pretagged); + learner.setGrammarFiles(new String[]{"tbsl/lexicon/english.lex"}); } public LearnQueryCallable(String question, int id, QueryTestData testData, Model model,MappingBasedIndex index,boolean pretagged) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-10-30 12:54:06
|
Revision: 3860 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3860&view=rev Author: dcherix Date: 2012-10-30 12:53:54 +0000 (Tue, 30 Oct 2012) Log Message: ----------- new conf Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java trunk/scripts/src/main/resources/log4j.properties trunk/test/newcomponent/AristotlePosNeg.conf Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -21,6 +21,7 @@ import java.io.File; import java.text.DecimalFormat; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -218,11 +219,11 @@ // configurator = new CELOEConfigurator(this); } -// public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { -// Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); -// problems.add(AbstractLearningProblem.class); -// return problems; -// } + public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { + Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); + problems.add(AbstractLearningProblem.class); + return problems; + } public static String getName() { return "CELOE"; Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -99,6 +99,7 @@ "org.dllearner.kb.OWLFile", "org.dllearner.kb.KBFile", "org.dllearner.kb.sparql.SparqlKnowledgeSource", + "org.dllearner.kb.sparql.simple.SparqlSimpleExtractor", "org.dllearner.kb.OWLAPIOntology", // "org.dllearner.kb.SparqlEndpointKS", //reasoners Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -225,6 +225,8 @@ return (String) entry.get(2); } + + /** * Adds an entry to the cache. @@ -328,7 +330,7 @@ totaltime.stop(); return result; } - + public boolean executeSparqlAskQuery(SparqlQuery query) { String str = getCacheEntry(query.getSparqlQueryString()); JamonMonitorLogger.increaseCount(Cache.class, "TotalQueries"); Deleted: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -1,50 +0,0 @@ -package org.dllearner.kb.sparql; - -import java.net.URL; - -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.kb.OWLOntologyKnowledgeSource; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyManager; - -@ComponentAnn(name="efficient SPARQL fragment extractor", shortName="sparqls", version=0.1) -public class SparqlSimpleExtractor implements KnowledgeSource, OWLOntologyKnowledgeSource { - - @ConfigOption(name="endpointURL", description="URL of the SPARQL endpoint", required=true) - private URL endpointURL = null; - - public SparqlSimpleExtractor() { - - } - - @Override - public void init() throws ComponentInitException { - // TODO Auto-generated method stub - - } - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - - public URL getEndpointURL() { - return endpointURL; - } - - public void setEndpointURL(URL endpointURL) { - this.endpointURL = endpointURL; - } - - @Override - public OWLOntology createOWLOntology(OWLOntologyManager manager) { - //TODO Update this to return an ontology representation of what the reasoners should work with. Build with the passed in manager instance. - return null; - } -} Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/pom.xml 2012-10-30 12:53:54 UTC (rev 3860) @@ -66,6 +66,28 @@ <dependency> <groupId>org.aksw.commons</groupId> <artifactId>sparql</artifactId> + <exclusions> + <exclusion> + <artifactId>slf4j-api</artifactId> + <groupId>org.slf4j</groupId> + </exclusion> + <exclusion> + <artifactId>arq</artifactId> + <groupId>com.hp.hpl.jena</groupId> + </exclusion> + <exclusion> + <artifactId>xercesImpl</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>any23-core</artifactId> + <groupId>org.deri.any23</groupId> + </exclusion> + <exclusion> + <artifactId>jena-core</artifactId> + <groupId>org.apache.jena</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>mysql</groupId> @@ -102,7 +124,7 @@ <executable>java</executable> <arguments> <argument>-Xms512m</argument> - <argument>-Xmx4000m</argument> + <argument>-Xmx3000m</argument> </arguments> </configuration> </plugin> Modified: trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -24,6 +24,10 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -47,8 +51,10 @@ import org.dllearner.core.owl.Thing; import org.dllearner.gui.Config; import org.dllearner.gui.ConfigSave; +import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.RhoDRDown; @@ -66,6 +72,7 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -89,6 +96,7 @@ .getLogger(DBpediaClassLearnerCELOE.class); SparqlEndpoint sparqlEndpoint = null; + private Cache cache; public DBpediaClassLearnerCELOE() { // OPTIONAL: if you want to do some case distinctions in the learnClass @@ -100,6 +108,7 @@ // TODO Auto-generated catch block e.printStackTrace(); } + cache = new Cache("basCache"); } public static void main(String args[]) @@ -110,20 +119,21 @@ Monitor mon = MonitorFactory.start("Learn DBpedia"); KB kb = dcl.learnAllClasses(classesToLearn); mon.stop(); - kb.export(new File("/home/dcherix/dllearner/old/result.owl"), + kb.export(new File("/home/dcherix/dllearner/old/result"+i+".owl"), OntologyFormat.RDF_XML); // Set<String> pos = // dcl.getPosEx("http://dbpedia.org/ontology/Person"); // dcl.getNegEx("http://dbpedia.org/ontology/Person", pos); - logger.info("Test " + i + ":\n" + logger.info("Test" + i + ":\n" + JamonMonitorLogger.getStringForAllSortedByLabel()); + System.gc(); } } public KB learnAllClasses(Set<String> classesToLearn) { KB kb = new KB(); for (String classToLearn : classesToLearn) { - logger.info("Leraning class: " + classToLearn); + logger.info("Leanring class: " + classToLearn); try { Description d = learnClass(classToLearn); if (d == null @@ -141,6 +151,7 @@ } catch (Exception e) { logger.warn("", e); } + this.dropCache(); } return kb; @@ -175,6 +186,7 @@ ks.setUrl(new URL(endpointurl)); ks.setUseLits(false); ks.setUseCacheDatabase(true); + ks.setUseCache(true); ks.setRecursionDepth(1); ks.setCloseAfterRecursion(true); ks.setSaveExtractedFragment(true); @@ -252,12 +264,18 @@ // } // public Set<String> getPosEx(String clazz) throws Exception { - SparqlTemplate st = SparqlTemplate.getInstance("instancesOfClass.vm"); - st.setLimit(0); - VelocityContext vc = st.getVelocityContext(); - vc.put("class", clazz); - String queryString = st.getQuery(); - return this.executeResourceQuery(queryString); +// SparqlTemplate st = SparqlTemplate.getInstance("instancesOfClass.vm"); +// st.setLimit(0); +// VelocityContext vc = st.getVelocityContext(); +// vc.put("class", clazz); +// String queryString = st.getQuery(); + StringBuilder queryString = new StringBuilder(); + queryString.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"); + queryString.append(" SELECT ?instances WHERE { ?instances rdf:type <"); + queryString.append(clazz); + queryString.append("> }"); + System.out.println(queryString); + return this.executeResourceQuery(queryString.toString()); } /** @@ -337,7 +355,7 @@ logger.info("using class for negatives: " + targetClass); if (targetClass != null) { SparqlTemplate st = SparqlTemplate - .getInstance("instancesOfClass.vm"); + .getInstance("instancesOfClass2.vm"); st.setLimit(0); VelocityContext vc = st.getVelocityContext(); vc.put("class", targetClass); @@ -386,10 +404,11 @@ } public Set<String> executeResourceQuery(String queryString) { - Query query = QueryFactory.create(queryString); - QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, - query); - ResultSet resultSet = qexec.execSelect(); +// Query query = QueryFactory.create(queryString); +// QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, +// query); +// ResultSet resultSet = qexec.execSelect(); + ResultSetRewindable resultSet = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(new SparqlQuery(queryString,sparqlEndpoint))); QuerySolution solution; Set<String> results = new HashSet<String>(); while (resultSet.hasNext()) { @@ -400,10 +419,11 @@ } public Set<String> executeClassQuery(String queryString) { - Query query = QueryFactory.create(queryString); - QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, - query); - ResultSet resultSet = qexec.execSelect(); +// Query query = QueryFactory.create(queryString); +// QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, +// query); +// ResultSet resultSet = qexec.execSelect(); + ResultSetRewindable resultSet = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(new SparqlQuery(queryString,sparqlEndpoint))); QuerySolution solution; Set<String> results = new HashSet<String>(); while (resultSet.hasNext()) { @@ -413,4 +433,24 @@ return results; } + private void dropCache(){ + try { + Class.forName("org.h2.Driver"); + String databaseName="extraction"; + String databaseDirectory="cache"; + Connection conn = DriverManager.getConnection("jdbc:h2:"+databaseDirectory+"/"+databaseName, "sa", ""); + Statement st = conn.createStatement(); + st.execute("DELETE FROM QUERY_CACHE"); + st.close(); + conn.close(); + System.gc(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -107,7 +107,7 @@ public static void main(String args[]) throws LearningProblemUnsupportedException, IOException, Exception { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 4; i++) { NewSparqlCompDBpediaClassLearnerCELOE dcl = new NewSparqlCompDBpediaClassLearnerCELOE(); Set<String> classesToLearn = dcl.getClasses(); @@ -129,8 +129,7 @@ public KB learnAllClasses(Set<String> classesToLearn) { KB kb = new KB(); for (String classToLearn : classesToLearn) { - logger.info(classToLearn); - System.out.println(classToLearn); + logger.info("learning "+classToLearn); try { Description d = learnClass(classToLearn); if (d == null @@ -148,6 +147,7 @@ } catch (Exception e) { logger.warn("", e); } + System.gc(); } return kb; @@ -254,10 +254,7 @@ for (OntClass ontClass : classes) { results.add(ontClass.getURI()); i++; - if (i == 100) - break; } - System.out.println(results.size()); return results; } Modified: trunk/scripts/src/main/resources/log4j.properties =================================================================== --- trunk/scripts/src/main/resources/log4j.properties 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/resources/log4j.properties 2012-10-30 12:53:54 UTC (rev 3860) @@ -1,9 +1,15 @@ log4j.appender.A1=org.apache.log4j.RollingFileAppender -log4j.appender.A1.File=log/errors.log +log4j.appender.A1.File=log/oldComp4.log log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c- %m%n -log4j.appender.A2=org.apache.log4j.RollingFileAppender -log4j.appender.A2.File=log/queries.log -log4j.appender.A2.layout=org.apache.log4j.PatternLayout +#log4j.appender.A2=org.apache.log4j.RollingFileAppender +#log4j.appender.A2.File=log/queries.log +#log4j.appender.A2.layout=org.apache.log4j.PatternLayout -log4j.rootLogger=ERROR,A1 \ No newline at end of file +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +log4j.rootLogger=INFO,A1,stdout + Modified: trunk/test/newcomponent/AristotlePosNeg.conf =================================================================== --- trunk/test/newcomponent/AristotlePosNeg.conf 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/test/newcomponent/AristotlePosNeg.conf 2012-10-30 12:53:54 UTC (rev 3860) @@ -13,9 +13,12 @@ sparql.type = "sparqls" sparql.endpointURL = "http://live.dbpedia.org/sparql" sparql.defaultGraphURI = "http://dbpedia.org" -sparql.recursionDepth = 1 -sparql.ontologyFile= "http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl" +sparql.recursionDepth = 2 +sparql.ontologySchemaUrls = {"http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl" } +sparql.aboxfilter = "FILTER ( !isLiteral(?o) && regex(str(?o), '^http://dbpedia.org/resource/') && ! regex(str(?o), '^http://dbpedia.org/resource/Category') && ! regex(str(?o), '^http://dbpedia.org/resource/Template') ) . " +sparql.tboxfilter = "FILTER ( regex(str(?class), '^http://dbpedia.org/ontology/') ) . " + sparql.instances = { "http://dbpedia.org/resource/Democritus", "http://dbpedia.org/resource/Zeno_of_Elea", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |