From: <lor...@us...> - 2011-09-21 21:49:17
|
Revision: 3281 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3281&view=rev Author: lorenz_b Date: 2011-09-21 21:49:10 +0000 (Wed, 21 Sep 2011) Log Message: ----------- Made some small changes for enrichment in ORE. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java Added Paths: ----------- trunk/components-core/src/test/java/org/dllearner/test/junit/DisjointClassesLearningTest.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -21,11 +21,11 @@ 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.dllearner.core.AbstractAxiomLearningAlgorithm; @@ -186,9 +186,9 @@ @Override public List<EvaluatedAxiom> getCurrentlyBestEvaluatedAxioms(int nrOfAxioms) { List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); - Set<Description> descriptions; + List<Description> descriptions; for(EvaluatedDescription ed : getCurrentlyBestEvaluatedDescriptions(nrOfAxioms)){ - descriptions = new HashSet<Description>(); + descriptions = new ArrayList<Description>(); descriptions.add(classToDescribe); descriptions.add(ed.getDescription()); axioms.add(new EvaluatedAxiom(new DisjointClassesAxiom(descriptions), new AxiomScore(ed.getAccuracy()))); @@ -209,6 +209,9 @@ EvaluatedDescription evalDesc; //firstly, create disjoint classexpressions which not occur and give score of 1 + if(reasoner.isPrepared()){ + SortedSet<Description> mostGeneralClasses = reasoner.getClassHierarchy().getMostGeneralClasses(); + } for(NamedClass cls : completeDisjointclasses){ evalDesc = new EvaluatedDescription(cls, new AxiomScore(1)); evalDescs.add(evalDesc); 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 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -208,7 +208,9 @@ SPARQLReasoner reasoner = new SPARQLReasoner(ks); reasoner.prepareSubsumptionHierarchy(); + System.out.println(reasoner.getClassHierarchy().getSubClasses(Thing.instance).size()); + ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); l.setReasoner(reasoner); l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/author")); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -356,4 +356,21 @@ } return depth; } + + public SortedSet<Description> getMostGeneralClasses(){ + SortedSet<Description> generalClasses = new TreeSet<Description>(conceptComparator); + boolean add = false; + SortedSet<Description> superClasses; + for(Description sub : getSubClasses(Thing.instance)){ + superClasses = getSuperClasses(sub); + superClasses = new TreeSet<Description>(conceptComparator);superClasses.remove(Thing.instance); + if(superClasses.isEmpty()){ + add = true; + } + if(add){ + generalClasses.add(sub); + } + } + return generalClasses; + } } Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/DisjointClassesAxiom.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -19,6 +19,7 @@ package org.dllearner.core.owl; +import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -33,9 +34,9 @@ * */ private static final long serialVersionUID = 7788863077013583508L; - private Set<Description> descriptions; + private Collection<Description> descriptions; - public DisjointClassesAxiom(Set<Description> descriptions) { + public DisjointClassesAxiom(Collection<Description> descriptions) { this.descriptions = descriptions; } @@ -94,7 +95,7 @@ /** * @return the descriptions */ - public Set<Description> getDescriptions() { + public Collection<Description> getDescriptions() { return descriptions; } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -106,13 +106,13 @@ // parents/children of top ... SortedSet<Description> tmp = getSubClasses(Thing.instance); - subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>()); + subsumptionHierarchyUp.put(Thing.instance, new TreeSet<Description>(conceptComparator)); subsumptionHierarchyDown.put(Thing.instance, tmp); // ... bottom ... tmp = getSuperClasses(Nothing.instance); subsumptionHierarchyUp.put(Nothing.instance, tmp); - subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>()); + subsumptionHierarchyDown.put(Nothing.instance, new TreeSet<Description>(conceptComparator)); // ... and named classes Set<NamedClass> atomicConcepts = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); @@ -813,6 +813,10 @@ return hierarchy != null; } + public void setCache(ExtractionDBCache cache) { + this.cache = cache; + } + private boolean executeAskQuery(String query){ QueryEngineHTTP queryExecution = new QueryEngineHTTP(ks.getEndpoint().getURL().toString(), query); for (String dgu : ks.getEndpoint().getDefaultGraphURIs()) { Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-09-20 09:55:53 UTC (rev 3280) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OWLAPIAxiomConvertVisitor.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -21,6 +21,7 @@ import static org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor.getOWLClassExpression; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -377,7 +378,7 @@ * @see org.dllearner.core.owl.TerminologicalAxiomVisitor#visit(org.dllearner.core.owl.DisjointClassesAxiom) */ public void visit(DisjointClassesAxiom axiom) { - Set<Description> descriptions = axiom.getDescriptions(); + Collection<Description> descriptions = axiom.getDescriptions(); Set<OWLClassExpression> owlAPIDescriptions = new HashSet<OWLClassExpression>(); for(Description description : descriptions) owlAPIDescriptions.add(getOWLClassExpression(description)); Added: trunk/components-core/src/test/java/org/dllearner/test/junit/DisjointClassesLearningTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/DisjointClassesLearningTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/DisjointClassesLearningTest.java 2011-09-21 21:49:10 UTC (rev 3281) @@ -0,0 +1,55 @@ +package org.dllearner.test.junit; + +import junit.framework.TestCase; + +import org.dllearner.algorithms.DisjointClassesLearner; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.reasoning.SPARQLReasoner; + +public class DisjointClassesLearningTest extends TestCase{ + + private SparqlEndpointKS ks; + private SPARQLReasoner reasoner; + + private static final int maxExecutionTimeInSeconds = 10; + + @Override + protected void setUp() throws Exception { + super.setUp(); + ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + + reasoner = new SPARQLReasoner(ks); + reasoner.prepareSubsumptionHierarchy(); + } + + public void testLearnSingleClass(){ + DisjointClassesLearner l = new DisjointClassesLearner(ks); + l.setReasoner(reasoner); + l.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Book")); + + l.start(); + + System.out.println(l.getCurrentlyBestAxioms(5)); + } + + public void testLearnForMostGeneralClasses(){ + DisjointClassesLearner l = new DisjointClassesLearner(ks); + l.setReasoner(reasoner); + l.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + + for(Description cls : reasoner.getClassHierarchy().getMostGeneralClasses()){ + l.setClassToDescribe((NamedClass)cls); + + l.start(); + + System.out.println(l.getCurrentlyBestAxioms(5)); + } + } + + + +} Property changes on: trunk/components-core/src/test/java/org/dllearner/test/junit/DisjointClassesLearningTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |