From: <jen...@us...> - 2009-01-05 12:35:32
|
Revision: 1567 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1567&view=rev Author: jenslehmann Date: 2009-01-05 12:35:24 +0000 (Mon, 05 Jan 2009) Log Message: ----------- EL operator benchmark started and a number of smaller changes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/KB.java trunk/src/dl-learner/org/dllearner/core/owl/Nothing.java trunk/src/dl-learner/org/dllearner/kb/KBFile.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/ContextDescription.java trunk/src/dl-learner/org/dllearner/scripts/evaluation/ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java trunk/src/dl-learner/org/dllearner/scripts/evaluation/package-info.java trunk/src/dl-learner/org/dllearner/scripts/package-info.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/scripts/package.html Added: trunk/src/dl-learner/org/dllearner/core/owl/ContextDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ContextDescription.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/ContextDescription.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2007-2008, 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.core.owl; + +/** + * A class description in its context, i.e. including a parent link (if any). + * For instance, there is only one description owl:Thing, but it can occur + * nested within different descriptions like "createdBy SOME owl:Thing". + * Depending on what you want to do, you either need a Description or a + * ContextDescription. + * + * @author Jens Lehmann + * + */ +public class ContextDescription { + + private Description description; + + private Description parent; + + public ContextDescription(Description description, Description parent) { + this.description = description; + this.parent = parent; + } + + /** + * @return the description + */ + public Description getDescription() { + return description; + } + + /** + * @return the parent + */ + public Description getParent() { + return parent; + } + +} Modified: trunk/src/dl-learner/org/dllearner/core/owl/KB.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KB.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/core/owl/KB.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -1,11 +1,22 @@ package org.dllearner.core.owl; +import java.io.File; +import java.net.URI; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyCreationException; +import org.semanticweb.owl.model.OWLOntologyManager; +import org.semanticweb.owl.model.OWLOntologyStorageException; +import org.semanticweb.owl.model.UnknownOWLOntologyException; +import org.semanticweb.owl.util.SimpleURIMapper; + public class KB implements KBElement { // private Set<Axiom> axioms = new HashSet<Axiom>(); @@ -273,4 +284,24 @@ return axioms; } + public void export(File file, org.dllearner.core.OntologyFormat format){ + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + URI ontologyURI = URI.create("http://example.com"); + URI physicalURI = file.toURI(); + SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); + manager.addURIMapper(mapper); + OWLOntology ontology; + try { + ontology = manager.createOntology(ontologyURI); + // OWLAPIReasoner.fillOWLAPIOntology(manager,ontology,kb); + OWLAPIAxiomConvertVisitor.fillOWLOntology(manager, ontology, this); + manager.saveOntology(ontology); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (UnknownOWLOntologyException e) { + e.printStackTrace(); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } + } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/Nothing.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Nothing.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/core/owl/Nothing.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -22,7 +22,7 @@ import java.util.Map; /** - * Implementation of owl:nothing/BOTTOM. + * Implementation of owl:Nothing/BOTTOM. * * @author Jens Lehmann * Modified: trunk/src/dl-learner/org/dllearner/kb/KBFile.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/kb/KBFile.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -38,14 +38,6 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.DIGConverter; -import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLOntologyCreationException; -import org.semanticweb.owl.model.OWLOntologyManager; -import org.semanticweb.owl.model.OWLOntologyStorageException; -import org.semanticweb.owl.model.UnknownOWLOntologyException; -import org.semanticweb.owl.util.SimpleURIMapper; /** * KB files are an internal convenience format used in DL-Learner. Their @@ -158,24 +150,25 @@ @Override public void export(File file, org.dllearner.core.OntologyFormat format){ - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - URI ontologyURI = URI.create("http://example.com"); - URI physicalURI = file.toURI(); - SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); - manager.addURIMapper(mapper); - OWLOntology ontology; - try { - ontology = manager.createOntology(ontologyURI); - // OWLAPIReasoner.fillOWLAPIOntology(manager,ontology,kb); - OWLAPIAxiomConvertVisitor.fillOWLOntology(manager, ontology, kb); - manager.saveOntology(ontology); - } catch (OWLOntologyCreationException e) { - e.printStackTrace(); - } catch (UnknownOWLOntologyException e) { - e.printStackTrace(); - } catch (OWLOntologyStorageException e) { - e.printStackTrace(); - } + kb.export(file, format); +// OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); +// URI ontologyURI = URI.create("http://example.com"); +// URI physicalURI = file.toURI(); +// SimpleURIMapper mapper = new SimpleURIMapper(ontologyURI, physicalURI); +// manager.addURIMapper(mapper); +// OWLOntology ontology; +// try { +// ontology = manager.createOntology(ontologyURI); +// // OWLAPIReasoner.fillOWLAPIOntology(manager,ontology,kb); +// OWLAPIAxiomConvertVisitor.fillOWLOntology(manager, ontology, kb); +// manager.saveOntology(ontology); +// } catch (OWLOntologyCreationException e) { +// e.printStackTrace(); +// } catch (UnknownOWLOntologyException e) { +// e.printStackTrace(); +// } catch (OWLOntologyStorageException e) { +// e.printStackTrace(); +// } } public URL getURL() { Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -71,7 +71,6 @@ import org.dllearner.parser.ParseException; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptTransformation; -import org.semanticweb.owl.inference.OWLReasonerException; /** * Reasoner for fast instance checks. It works by completely dematerialising the Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -393,7 +393,6 @@ List<ELDescriptionEdge> piVEdges = new LinkedList<ELDescriptionEdge>(); ELDescriptionNode tmp = v; while(!tmp.isRoot()) { -// System.out.println("blub"); piVEdges.add(tmp.getParentEdge()); tmp = tmp.getParent(); } @@ -446,9 +445,14 @@ i.addChild(opDomains.get(edge.getLabel())); } + int size = i.getChildren().size(); + // size = 0 means we have the top concept + if(size == 0) { + return Thing.instance; + } // if the intersection has just one element, we return // the element itself instead - if(i.getChildren().size() == 1) { + else if(size == 1) { return i.getChild(0); } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -176,6 +176,7 @@ public boolean isDisjoint(Description d1, Description d2) { // System.out.println("d1: " + d1); // System.out.println("d2: " + d2); +// System.out.println("cache: " + cachedDisjoints); // check whether we have cached this query Map<Description,Boolean> tmp = cachedDisjoints.get(d1); Added: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -0,0 +1,152 @@ +/** + * Copyright (C) 2007-2008, 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.scripts.evaluation; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Random; +import java.util.Set; + +import org.dllearner.algorithms.el.ELDescriptionTree; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.owl.Thing; +import org.dllearner.kb.OWLFile; +import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.refinementoperators.ELDown2; +import org.dllearner.utilities.statistics.Stat; + +/** + * An evaluation of the EL refinement operator {@link ELDown2}. It creates + * a set of artificial ontologies with varying complexity and performs + * refinement steps on them. + * + * @author Jens Lehmann + * + */ +public class ELOperatorBenchmark { + + private static Random rand = new Random(1); + + public static void main(String[] args) throws MalformedURLException, ComponentInitException { + String example = "/home/jl/promotion/ontologien/galen2.owl"; + testOntology(example); + System.exit(0); + + /* TEST ON ARTIFICIAL ONTOLOGIES + + + // number of concepts and roles + int[] conceptCounts = new int[] { 5, 10 }; + int[] roleCounts = new int[] { 5, 10}; + + // number of applications of operator + int opApplications = 10; + + // statistics directory + String statDir = "/log/stat/el/"; + String statFile = statDir + "stats.txt"; + String gnuPlotApplicationTimeFile = statDir + "application.gp"; + String gnuPlotRefinementTimeFile = statDir + "refinement.gp"; + boolean writeOntologies = true; + String ontologyDir = "/log/stat/el/ontologies/"; + + + + for(int conceptCount : conceptCounts) { + for(int roleCount : roleCounts) { + // code for ontology creation + KB kb = new KB(); + + // create class hierarchy (concept 0 is owl:Thing) + for(int i=1; i<=conceptCount; i++) { + // create class + NamedClass nc = new NamedClass("a" + i); + // pick an existing class as super class + int j = (i == 0) ? 0 : rand.nextInt(i); + Description superClass; + if(j==0) { + superClass = Thing.instance; + } else { + superClass = new NamedClass("a" + j); + } + kb.addAxiom(new SubClassAxiom(nc, superClass)); + // disjointness with siblings + } + + + // save ontology + File f = new File(ontologyDir + "c" + conceptCount + "r" + roleCount + ".owl"); + kb.export(f, OntologyFormat.RDF_XML); + + + } + } + */ +// ELDown2 operator = new ELDown2(); + } + + private static void testOntology(String ont) throws MalformedURLException, ComponentInitException { + System.out.print("Reading in " + ont + " ... "); + ComponentManager cm = ComponentManager.getInstance(); + // reading ontology into a reasoner + KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(source, "url", new File(ont).toURI().toURL()); + source.init(); + ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source); + reasoner.init(); + System.out.println("done."); + System.out.println(); + + int outerLoops = 10; + for(int loop = 0; loop < outerLoops; loop++) { + + // application of operator and statistics recording + int nrOfApplications = 10; + ELDescriptionTree currTree = new ELDescriptionTree(reasoner, Thing.instance); + ELDown2 operator = new ELDown2(reasoner); + Stat runtime = new Stat(); + Stat runtimePerRefinement = new Stat(); + + System.out.println("Testing operator (applying it " + nrOfApplications + " times):"); + for(int i=0; i < nrOfApplications; i++) { + System.out.print("current concept: " + currTree.transformToDescription().toString(reasoner.getBaseURI(), reasoner.getPrefixes())); + // apply operator on current description + long start = System.nanoTime(); + Set<ELDescriptionTree> refinements = operator.refine(currTree); + long time = System.nanoTime() - start; + runtime.addNumber(time/1000000d); + runtimePerRefinement.addNumber(time/1000000d/refinements.size()); + System.out.println(" [has " + refinements.size() + " refinements]"); + // pick a refinement randomly (which is kind of slow for a set, but + // this does not matter here) + int index = rand.nextInt(refinements.size()); + currTree = new ArrayList<ELDescriptionTree>(refinements).get(index); + } + System.out.println("operator time: " + runtime.prettyPrint("ms")); + System.out.println("operator time per refinement: " + runtimePerRefinement.prettyPrint("ms")); + System.out.println(); + + } + } +} Added: trunk/src/dl-learner/org/dllearner/scripts/evaluation/package-info.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/evaluation/package-info.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/package-info.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -0,0 +1,6 @@ +/** + * All scripts, which serve evaluation purposes, i.e. evaluation of + * learning algorithms, refinement operators, components etc. These + * are usually benchmarks testing accuracy, performance etc. of algorithms. + */ +package org.dllearner.scripts.evaluation; \ No newline at end of file Copied: trunk/src/dl-learner/org/dllearner/scripts/package-info.java (from rev 1566, trunk/src/dl-learner/org/dllearner/scripts/package.html) =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/package-info.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/scripts/package-info.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -0,0 +1,4 @@ +/** + * Runnable scripts, each for a different task or experiment. + */ +package org.dllearner.scripts; \ No newline at end of file Property changes on: trunk/src/dl-learner/org/dllearner/scripts/package-info.java ___________________________________________________________________ Added: svn:mergeinfo + Deleted: trunk/src/dl-learner/org/dllearner/scripts/package.html =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/package.html 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/scripts/package.html 2009-01-05 12:35:24 UTC (rev 1567) @@ -1,7 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> -<html> -<head></head> -<body bgcolor="white"> -<p>Runnable scripts, each for a different task or experiment.</p> -</body> -</html> Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -19,7 +19,7 @@ */ package org.dllearner.test.junit; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import java.io.File; import java.util.Set; @@ -30,7 +30,6 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.owl.Description; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.refinementoperators.ELDown2; @@ -38,7 +37,6 @@ import org.dllearner.test.junit.TestOntologies.TestOntology; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; -import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.owl.ConceptComparator; import org.dllearner.utilities.owl.ConceptTransformation; import org.dllearner.utilities.statistics.Stat; Modified: trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2008-12-22 13:50:14 UTC (rev 1566) +++ trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2009-01-05 12:35:24 UTC (rev 1567) @@ -24,7 +24,7 @@ /** * Utility class for calculating the mean and standard deviation of a given set - * of numbers. + * of numbers. The class also contains convenience methods for printing values. * * @author Jens Lehmann * @@ -144,4 +144,20 @@ return str; } + /** + * Pretty prints the results under the assumption that the input + * values are time spans measured in nano seconds. + * + * @see System#nanoTime() + * @return A string summarising statistical values. + */ +// public String prettyPrintNanoSeconds() { +// DecimalFormat df = new DecimalFormat(); +// String str = "av. " + df.format(getMean()) + unit; +// str += " (deviation " + df.format(getStandardDeviation()) + unit + "; "; +// str += "min " + df.format(getMin()) + unit + "; "; +// str += "max " + df.format(getMax()) + unit + ")"; +// return str; +// } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |