|
From: <jen...@us...> - 2008-11-14 15:09:18
|
Revision: 1514
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1514&view=rev
Author: jenslehmann
Date: 2008-11-14 15:09:11 +0000 (Fri, 14 Nov 2008)
Log Message:
-----------
started class for detecting relevant entities at a certain position in a class description for a given individual
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/junit/UtilitiesTests.java
trunk/src/dl-learner/org/dllearner/utilities/learn/UsedEntitiesDetection.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java 2008-11-14 15:04:06 UTC (rev 1513)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/SearchTreeNode.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -22,8 +22,6 @@
import java.util.LinkedList;
import java.util.List;
-import org.dllearner.algorithms.refinement.Node;
-
/**
* A node in the search tree of an EL algorithm.
*
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-14 15:04:06 UTC (rev 1513)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -681,6 +681,11 @@
}
@Override
+ protected Map<ObjectProperty,Set<Individual>> getObjectPropertyRelationshipsImpl(Individual individual) {
+ return rc.getObjectPropertyRelationships(individual);
+ }
+
+ @Override
public Set<Constant> getRelatedValuesImpl(Individual individual, DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException {
return rc.getRelatedValues(individual, datatypeProperty);
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-14 15:04:06 UTC (rev 1513)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -41,7 +41,6 @@
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.KnowledgeSource;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.ReasoningMethodUnsupportedException;
import org.dllearner.core.configurators.OWLAPIReasonerConfigurator;
import org.dllearner.core.options.ConfigEntry;
import org.dllearner.core.options.ConfigOption;
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-14 15:04:06 UTC (rev 1513)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -36,7 +36,7 @@
*/
public final class TestOntologies {
- public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, R1SUBR2 };
+ public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, R1SUBR2, DATA1 };
public static ReasonerComponent getTestOntology(TestOntology ont) {
String kbString = "";
@@ -59,6 +59,14 @@
kbString += "a2 SUB a4";
} else if(ont.equals(TestOntology.R1SUBR2)) {
kbString += "Subrole(r1,r2).\n";
+ } else if(ont.equals(TestOntology.DATA1)) {
+ kbString += "man SUB person.\n";
+ kbString += "woman SUB person.\n";
+ kbString += "man(eric).\n";
+ kbString += "woman(diana).\n";
+ kbString += "married(eric,diana).\n";
+ kbString += "hasChild(eric,frank).\n";
+ kbString += "hasChild(eric,tim).\n";
}
try {
Added: trunk/src/dl-learner/org/dllearner/test/junit/UtilitiesTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/UtilitiesTests.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/junit/UtilitiesTests.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -0,0 +1,49 @@
+/**
+ * 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.test.junit;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.test.junit.TestOntologies.TestOntology;
+import org.dllearner.utilities.learn.UsedEntitiesDetection;
+import org.junit.Test;
+
+/**
+ * Various tests for methods/classes in the utilities package.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class UtilitiesTests {
+
+ @Test
+ public void entityDetection() {
+ ReasonerComponent reasoner = TestOntologies.getTestOntology(TestOntology.DATA1);
+ int maxDepth = 2;
+ Set<Individual> individuals = new TreeSet<Individual>();
+ individuals.add(new Individual("http://localhost/foo#tim"));
+ UsedEntitiesDetection detection = new UsedEntitiesDetection(reasoner, individuals, maxDepth);
+ System.out.println(detection);
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/utilities/learn/UsedEntitiesDetection.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/learn/UsedEntitiesDetection.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/utilities/learn/UsedEntitiesDetection.java 2008-11-14 15:09:11 UTC (rev 1514)
@@ -0,0 +1,175 @@
+/**
+ * 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.utilities.learn;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Map.Entry;
+
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
+
+/**
+ * This class takes a reasoner and individuals as input and detects
+ * the relevant (wrt. a learning process) classes and properties
+ * at a certain distance of the examples.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class UsedEntitiesDetection {
+
+ Comparator<Set<ObjectProperty>> keyComp = new Comparator<Set<ObjectProperty>>() {
+
+ @Override
+ public int compare(Set<ObjectProperty> key1, Set<ObjectProperty> key2) {
+ // first criterion: size of key
+ int sizeDiff = key1.size() - key2.size();
+ if(sizeDiff == 0) {
+ Iterator<ObjectProperty> it1 = key1.iterator();
+ Iterator<ObjectProperty> it2 = key2.iterator();
+ // compare elements one by one (assumes that both use the same
+ // ordering, which is the case)
+ while(it1.hasNext()) {
+ ObjectProperty prop1 = it1.next();
+ ObjectProperty prop2 = it2.next();
+ int comp = prop1.compareTo(prop2);
+ if(comp != 0) {
+ return comp;
+ }
+ }
+ // all elements of the set are equal
+ return 0;
+ } else {
+ return sizeDiff;
+ }
+ }
+
+ };
+
+ private Map<Set<ObjectProperty>,Set<NamedClass>> usedClasses;
+
+ private Map<Set<ObjectProperty>,Set<ObjectProperty>> usedObjectProperties;
+
+ private ReasonerComponent reasoner;
+ private int maxDepth;
+
+ /**
+ * Computes used properties in classes.
+ * TODO more explanation
+ *
+ * @param reasoner A reasoner.
+ * @param individuals A set of individuals to start from.
+ * @param depth The maximum depth for the search.
+ */
+ public UsedEntitiesDetection(ReasonerComponent reasoner, Set<Individual> individuals, int maxDepth) {
+ this.reasoner = reasoner;
+ this.maxDepth = maxDepth;
+ usedClasses = new TreeMap<Set<ObjectProperty>,Set<NamedClass>>(keyComp);
+ usedObjectProperties = new TreeMap<Set<ObjectProperty>,Set<ObjectProperty>>(keyComp);
+
+ Set<ObjectProperty> startKey = new TreeSet<ObjectProperty>();
+ computeUsedEntitiesRec(startKey, individuals);
+
+ }
+
+ private void computeUsedEntitiesRec(Set<ObjectProperty> key, Set<Individual> individuals) {
+ Set<NamedClass> types = new TreeSet<NamedClass>();
+// Set<ObjectProperty> properties = new TreeSet<ObjectProperty>();
+ // we must use the object property comparator to avoid double occurences of properties
+ Map<ObjectProperty,Set<Individual>> relations = new TreeMap<ObjectProperty,Set<Individual>>();
+
+ for(Individual individual : individuals) {
+ // add all types
+ types.addAll(reasoner.getTypes(individual));
+
+ // compute outgoing properties
+ Map<ObjectProperty,Set<Individual>> map = reasoner.getObjectPropertyRelationships(individual);
+ for(Entry<ObjectProperty,Set<Individual>> entry : map.entrySet()) {
+ ObjectProperty prop = entry.getKey();
+ // we must use the individual comparator to avoid
+ // multiple occurrences of the same individual
+ Set<Individual> inds = new TreeSet<Individual>(entry.getValue());
+
+ // if property exists, add the found individuals
+ if(relations.containsKey(prop)) {
+ relations.get(prop).addAll(inds);
+ // if property not encountered before, add it
+ } else {
+ relations.put(prop, inds);
+ }
+ }
+ }
+
+ // store all found relations
+ usedClasses.put(key, types);
+ usedObjectProperties.put(key, relations.keySet());
+
+ // recurse if limit not reached yet
+ if(key.size() < maxDepth) {
+ for(Entry<ObjectProperty,Set<Individual>> entry : relations.entrySet()) {
+ // construct new key (copy and add)
+ Set<ObjectProperty> newKey = new TreeSet<ObjectProperty>(key);
+ newKey.add(entry.getKey());
+
+ // recursion
+ computeUsedEntitiesRec(newKey, entry.getValue());
+ }
+ }
+
+ }
+
+ public Set<Set<ObjectProperty>> getKeys() {
+ return usedClasses.keySet();
+ }
+
+ /**
+ * @return the usedClasses
+ */
+ public Map<Set<ObjectProperty>, Set<NamedClass>> getUsedClasses() {
+ return usedClasses;
+ }
+
+ /**
+ * @return the usedObjectProperties
+ */
+ public Map<Set<ObjectProperty>, Set<ObjectProperty>> getUsedObjectProperties() {
+ return usedObjectProperties;
+ }
+
+ @Override
+ public String toString() {
+ String str = "";
+ Set<Set<ObjectProperty>> keys = getKeys();
+ for(Set<ObjectProperty> key : keys) {
+ str += key.toString() + ": \n";
+ str += " classes: " + usedClasses.get(key) + "\n";
+ str += " object properties: " + usedObjectProperties.get(key) + "\n";
+ }
+ return str;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-11-14 16:56:03
|
Revision: 1515
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1515&view=rev
Author: jenslehmann
Date: 2008-11-14 16:55:52 +0000 (Fri, 14 Nov 2008)
Log Message:
-----------
- data type property hierarchy support now also moved to reasoner component
- some small improvements
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java
trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java
trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java
trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -600,8 +600,9 @@
for (Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) {
SortedSet<Constant> values = e.getValue();
if (values.size() > 1) {
- logger.warn("Property " + datatypeProperty + " has value " + e.getValue()
- + ". Cannot determine whether it is true.");
+ logger.warn("Property " + datatypeProperty + " has more than one value " + e.getValue()
+ + " for individual " + e.getKey() + ". We ignore the value.");
+ // d135
} else {
if (values.first().getLiteral().equalsIgnoreCase("true")) {
ret.add(e.getKey());
@@ -822,11 +823,19 @@
return getDatatypePropertyHierarchy().getMoreGeneralRoles(role);
}
+ protected SortedSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) throws ReasoningMethodUnsupportedException {
+ throw new ReasoningMethodUnsupportedException();
+ }
+
@Override
public final SortedSet<DatatypeProperty> getSubProperties(DatatypeProperty role) {
return getDatatypePropertyHierarchy().getMoreSpecialRoles(role);
}
+ protected SortedSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) throws ReasoningMethodUnsupportedException {
+ throw new ReasoningMethodUnsupportedException();
+ }
+
@Override
public final TreeSet<DatatypeProperty> getMostGeneralDatatypeProperties() {
return getDatatypePropertyHierarchy().getMostGeneralRoles();
@@ -914,7 +923,6 @@
TreeMap<ObjectProperty, SortedSet<ObjectProperty>> roleHierarchyDown = new TreeMap<ObjectProperty, SortedSet<ObjectProperty>>(
roleComparator);
- // refinement of atomic concepts
Set<ObjectProperty> atomicRoles = getObjectProperties();
for (ObjectProperty role : atomicRoles) {
roleHierarchyDown.put(role, getSubPropertiesImpl(role));
@@ -951,16 +959,29 @@
*/
public DatatypePropertyHierarchy prepareDatatypePropertyHierarchy()
throws ReasoningMethodUnsupportedException {
- throw new ReasoningMethodUnsupportedException(
- "Datatype property hierarchy creation not supported by this reasoner.");
+
+ RoleComparator roleComparator = new RoleComparator();
+ TreeMap<DatatypeProperty, SortedSet<DatatypeProperty>> datatypePropertyHierarchyUp = new TreeMap<DatatypeProperty, SortedSet<DatatypeProperty>>(
+ roleComparator);
+ TreeMap<DatatypeProperty, SortedSet<DatatypeProperty>> datatypePropertyHierarchyDown = new TreeMap<DatatypeProperty, SortedSet<DatatypeProperty>>(
+ roleComparator);
+
+ Set<DatatypeProperty> datatypeProperties = getDatatypeProperties();
+ for (DatatypeProperty role : datatypeProperties) {
+ datatypePropertyHierarchyDown.put(role, getSubPropertiesImpl(role));
+ datatypePropertyHierarchyUp.put(role, getSuperPropertiesImpl(role));
+ }
+
+ return new DatatypePropertyHierarchy(datatypeProperties, datatypePropertyHierarchyUp,
+ datatypePropertyHierarchyDown);
}
@Override
public final DatatypePropertyHierarchy getDatatypePropertyHierarchy() {
-
+
try {
if (datatypePropertyHierarchy == null) {
- prepareDatatypePropertyHierarchy();
+ datatypePropertyHierarchy = prepareDatatypePropertyHierarchy();
}
} catch (ReasoningMethodUnsupportedException e) {
handleExceptions(e);
Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypePropertyHierarchy.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -38,12 +38,12 @@
public class DatatypePropertyHierarchy {
RoleComparator rc = new RoleComparator();
- TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp;
- TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown;
+ TreeMap<DatatypeProperty,SortedSet<DatatypeProperty>> roleHierarchyUp;
+ TreeMap<DatatypeProperty,SortedSet<DatatypeProperty>> roleHierarchyDown;
TreeSet<DatatypeProperty> mostGeneralRoles = new TreeSet<DatatypeProperty>(rc);
TreeSet<DatatypeProperty> mostSpecialRoles = new TreeSet<DatatypeProperty>(rc);
- public DatatypePropertyHierarchy(Set<DatatypeProperty> atomicRoles, TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyUp , TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> roleHierarchyDown) {
+ public DatatypePropertyHierarchy(Set<DatatypeProperty> atomicRoles, TreeMap<DatatypeProperty,SortedSet<DatatypeProperty>> roleHierarchyUp , TreeMap<DatatypeProperty,SortedSet<DatatypeProperty>> roleHierarchyDown) {
this.roleHierarchyUp = roleHierarchyUp;
this.roleHierarchyDown = roleHierarchyDown;
@@ -56,20 +56,16 @@
}
}
- @SuppressWarnings("unchecked")
public SortedSet<DatatypeProperty> getMoreGeneralRoles(DatatypeProperty role) {
// we clone all concepts before returning them such that they cannot be
// modified externally
- return (TreeSet<DatatypeProperty>) roleHierarchyUp.get(role).clone();
+ return new TreeSet<DatatypeProperty>(roleHierarchyUp.get(role));
}
- @SuppressWarnings("unchecked")
public SortedSet<DatatypeProperty> getMoreSpecialRoles(DatatypeProperty role) {
- return (TreeSet<DatatypeProperty>) roleHierarchyDown.get(role).clone();
- }
+ return new TreeSet<DatatypeProperty>(roleHierarchyDown.get(role));
+ }
-
-
@Override
public String toString() {
String str = "";
@@ -79,7 +75,7 @@
return str;
}
- private String toString(TreeMap<DatatypeProperty,TreeSet<DatatypeProperty>> hierarchy, DatatypeProperty role, int depth) {
+ private String toString(TreeMap<DatatypeProperty,SortedSet<DatatypeProperty>> hierarchy, DatatypeProperty role, int depth) {
String str = "";
for(int i=0; i<depth; i++)
str += " ";
Modified: trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -82,5 +82,10 @@
} else
return datatypeComparision;
}
+
+ @Override
+ public String toString() {
+ return literal + "^^" + datatype;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/core/owl/UntypedConstant.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -89,4 +89,13 @@
public void accept(KBElementVisitor visitor) {
visitor.visit(this);
}
+
+ @Override
+ public String toString() {
+ if(hasLang) {
+ return literal + "@" + lang;
+ } else {
+ return literal;
+ }
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -498,12 +498,6 @@
return atomicConcepts;
}
-// @Override
-// public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl(
-// DatatypeProperty datatypeProperty) {
-// return rc.getDoubleDatatypeMembers(datatypeProperty);
-// }
-
/*
* (non-Javadoc)
*
@@ -554,6 +548,16 @@
return rc.getSubPropertiesImpl(role);
}
+ @Override
+ protected SortedSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) throws ReasoningMethodUnsupportedException {
+ return rc.getSuperPropertiesImpl(role);
+ }
+
+ @Override
+ protected SortedSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) throws ReasoningMethodUnsupportedException {
+ return rc.getSubPropertiesImpl(role);
+ }
+
/*
* (non-Javadoc)
*
@@ -676,6 +680,28 @@
}
@Override
+ public final SortedSet<Individual> getTrueDatatypeMembersImpl(DatatypeProperty datatypeProperty) {
+ return bdPos.get(datatypeProperty);
+ }
+
+ @Override
+ public final SortedSet<Individual> getFalseDatatypeMembersImpl(DatatypeProperty datatypeProperty) {
+ return bdNeg.get(datatypeProperty);
+ }
+
+ @Override
+ public Map<Individual, SortedSet<Integer>> getIntDatatypeMembersImpl(
+ DatatypeProperty datatypeProperty) {
+ return id.get(datatypeProperty);
+ }
+
+ @Override
+ public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembersImpl(
+ DatatypeProperty datatypeProperty) {
+ return dd.get(datatypeProperty);
+ }
+
+ @Override
public Set<Individual> getRelatedIndividualsImpl(Individual individual, ObjectProperty objectProperty) throws ReasoningMethodUnsupportedException {
return rc.getRelatedIndividuals(individual, objectProperty);
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-14 15:09:11 UTC (rev 1514)
+++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-11-14 16:55:52 UTC (rev 1515)
@@ -452,23 +452,23 @@
// 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() {
@@ -533,7 +533,8 @@
return getFirstObjectProperties(properties);
}
- private TreeSet<DatatypeProperty> getMoreGeneralDatatypePropertiesImpl(DatatypeProperty role) {
+ @Override
+ protected TreeSet<DatatypeProperty> getSuperPropertiesImpl(DatatypeProperty role) {
Set<Set<OWLDataProperty>> properties;
try {
properties = reasoner.getSuperProperties(OWLAPIConverter.getOWLAPIDataProperty(role));
@@ -544,7 +545,8 @@
return getFirstDatatypeProperties(properties);
}
- private TreeSet<DatatypeProperty> getMoreSpecialDatatypePropertiesImpl(DatatypeProperty role) {
+ @Override
+ protected TreeSet<DatatypeProperty> getSubPropertiesImpl(DatatypeProperty role) {
Set<Set<OWLDataProperty>> properties;
try {
properties = reasoner.getSubProperties(OWLAPIConverter.getOWLAPIDataProperty(role));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-11-21 15:11:20
|
Revision: 1521
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1521&view=rev
Author: jenslehmann
Date: 2008-11-21 15:11:14 +0000 (Fri, 21 Nov 2008)
Log Message:
-----------
simulation fixes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-21 12:06:58 UTC (rev 1520)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-21 15:11:14 UTC (rev 1521)
@@ -330,7 +330,7 @@
// (same in both cases)
private void labelSimulationUpdate() {
// compute the nodes, which need to be updated
- Set<ELDescriptionNode> update = new TreeSet<ELDescriptionNode>();
+ Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
// loop over all nodes on the same level, which are not in the in set
Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level));
@@ -345,8 +345,10 @@
}
}
- // loop over all nodes in out set
- for(ELDescriptionNode w : out) {
+ // loop over all nodes in out set (we make a copy, because out
+ // is potentially modified, so we cannot safely iterate over it)
+ tmp = new HashSet<ELDescriptionNode>(out);
+ for(ELDescriptionNode w : tmp) {
if(w != this) {
if(!tree.checkSC1(w, this)) {
tree.shrinkSimulation(w, this);
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-21 12:06:58 UTC (rev 1520)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-21 15:11:14 UTC (rev 1521)
@@ -322,52 +322,52 @@
// adds (node1,node2) to simulation, takes care of all helper sets
public void extendSimulation(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.out.add(node2);
- node1.outSC1.add(node2);
- node1.outSC2.add(node2);
- node2.in.add(node1);
- node2.inSC1.add(node1);
- node2.inSC2.add(node1);
+ node1.in.add(node2);
+ node1.inSC1.add(node2);
+ node1.inSC2.add(node2);
+ node2.out.add(node1);
+ node2.outSC1.add(node1);
+ node2.outSC2.add(node1);
}
public void extendSimulationSC1(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.outSC1.add(node2);
- node2.inSC1.add(node1);
+ node1.inSC1.add(node2);
+ node2.outSC1.add(node1);
}
public void extendSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.outSC2.add(node2);
- node2.inSC2.add(node1);
+ node1.inSC2.add(node2);
+ node2.outSC2.add(node1);
}
public void extendSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.out.add(node2);
- node2.in.add(node1);
+ node1.in.add(node2);
+ node2.out.add(node1);
}
// removes (node1,node2) from simulation, takes care of all helper sets
public void shrinkSimulation(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.out.remove(node2);
- node1.outSC1.remove(node2);
- node1.outSC2.remove(node2);
- node2.in.remove(node1);
- node2.inSC1.remove(node1);
- node2.inSC2.remove(node1);
+ node1.in.remove(node2);
+ node1.inSC1.remove(node2);
+ node1.inSC2.remove(node2);
+ node2.out.remove(node1);
+ node2.outSC1.remove(node1);
+ node2.outSC2.remove(node1);
}
public void shrinkSimulationSC1(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.outSC1.remove(node2);
- node2.inSC1.remove(node1);
+ node1.inSC1.remove(node2);
+ node2.outSC1.remove(node1);
}
public void shrinkSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.outSC2.remove(node2);
- node2.inSC2.remove(node1);
+ node1.inSC2.remove(node2);
+ node2.outSC2.remove(node1);
}
public void shrinkSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) {
- node1.out.remove(node2);
- node2.in.remove(node1);
+ node1.in.remove(node2);
+ node2.out.remove(node1);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-21 12:06:58 UTC (rev 1520)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-21 15:11:14 UTC (rev 1521)
@@ -28,6 +28,7 @@
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.parser.KBParser;
import org.dllearner.test.junit.TestOntologies.TestOntology;
import org.junit.Test;
@@ -71,12 +72,12 @@
// perform test with empty background knowledge and A1 AND EXISTS r1.TOP AND EXISTS r2.TOP
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.EMPTY);
ELDescriptionTree tree = new ELDescriptionTree(rs);
- NamedClass a1 = new NamedClass("a1");
+ NamedClass a1 = new NamedClass(uri("a1"));
ELDescriptionNode v1 = new ELDescriptionNode(tree);
v1.extendLabel(a1);
- ObjectProperty r1 = new ObjectProperty("r1");
+ ObjectProperty r1 = new ObjectProperty(uri("r1"));
ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, new TreeSet<NamedClass>());
- ObjectProperty r2 = new ObjectProperty("r2");
+ ObjectProperty r2 = new ObjectProperty(uri("r2"));
ELDescriptionNode v3 = new ELDescriptionNode(v1, r2, new TreeSet<NamedClass>());
assertEmpty(v1);
@@ -95,20 +96,20 @@
*
* v1: -
* v2: in=inSC1=inSC2=outSC2={v3,v4}
- * v3: inSC2=outSC2={v2,v4}
- * v4: inSC2=outSC2={v2,v3}
+ * v3: out=outSC1={v2}, inSC2=outSC2={v2,v4}
+ * v4: out=outSC1={v2}, inSC2=outSC2={v2,v3}
*/
@Test
public void test3() {
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.R1SUBR2);
ELDescriptionTree tree = new ELDescriptionTree(rs);
ELDescriptionNode v1 = new ELDescriptionNode(tree);
- ObjectProperty r1 = new ObjectProperty("r1");
- NamedClass a1 = new NamedClass("a1");
- NamedClass a2 = new NamedClass("a2");
+ ObjectProperty r1 = new ObjectProperty(uri("r1"));
+ NamedClass a1 = new NamedClass(uri("a1"));
+ NamedClass a2 = new NamedClass(uri("a2"));
ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a1, a2);
ELDescriptionNode v3 = new ELDescriptionNode(v1, r1, a2);
- ObjectProperty r2 = new ObjectProperty("r2");
+ ObjectProperty r2 = new ObjectProperty(uri("r2"));
ELDescriptionNode v4 = new ELDescriptionNode(v1, r2, a1);
System.out.println("v1:\n" + v1.toSimulationString());
@@ -123,13 +124,17 @@
assertOutSC1(v2);
assertOut(v2);
+ assertOut(v3,v2);
+ assertOutSC1(v3,v2);
assertSC2(v3, v2, v4);
- assertSC1(v3);
- assertSC(v3);
+ assertInSC1(v3);
+ assertIn(v3);
+ assertOut(v4,v2);
+ assertOutSC1(v4,v2);
assertSC2(v4, v2, v3);
- assertSC1(v4);
- assertSC(v4);
+ assertInSC1(v4);
+ assertIn(v4);
}
/**
@@ -157,12 +162,12 @@
public void test4() {
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE2);
ELDescriptionTree tree = new ELDescriptionTree(rs);
- ObjectProperty r1 = new ObjectProperty("r1");
- ObjectProperty r2 = new ObjectProperty("r2");
- ObjectProperty r3 = new ObjectProperty("r3");
- NamedClass a1 = new NamedClass("a1");
- NamedClass a2 = new NamedClass("a2");
- NamedClass a3 = new NamedClass("a3");
+ ObjectProperty r1 = new ObjectProperty(uri("r1"));
+ ObjectProperty r2 = new ObjectProperty(uri("r2"));
+ ObjectProperty r3 = new ObjectProperty(uri("r3"));
+ NamedClass a1 = new NamedClass(uri("a1"));
+ NamedClass a2 = new NamedClass(uri("a2"));
+ NamedClass a3 = new NamedClass(uri("a3"));
ELDescriptionNode v1 = new ELDescriptionNode(tree);
ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a2, a3);
ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
@@ -220,11 +225,13 @@
assertOutSC2(node, nodesOut);
}
+ @SuppressWarnings("unused")
private void assertSC(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
assertIn(node, nodesOut);
assertOut(node, nodesOut);
}
+ @SuppressWarnings("unused")
private void assertSC1(ELDescriptionNode node, ELDescriptionNode... nodesOut) {
assertInSC1(node, nodesOut);
assertOutSC1(node, nodesOut);
@@ -286,4 +293,9 @@
assertTrue(node.getOutSC1().isEmpty());
assertTrue(node.getOutSC2().isEmpty());
}
+
+ // we use the standard KB file prefix
+ private String uri(String localname) {
+ return KBParser.getInternalURI(localname);
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-21 12:06:58 UTC (rev 1520)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-11-21 15:11:14 UTC (rev 1521)
@@ -55,10 +55,13 @@
kbString += "cat SUB animal.\n";
kbString += "(human AND animal) = BOTTOM.\n";
} else if(ont.equals(TestOntology.SIMPLE2)) {
- kbString += "Subrole(r2,r3).";
- kbString += "a2 SUB a4.";
+ kbString += "Subrole(r1,r2).\n";
+ kbString += "a1 SUB TOP.\n";
+ kbString += "a2 SUB a3.\n";
} else if(ont.equals(TestOntology.R1SUBR2)) {
kbString += "Subrole(r1,r2).\n";
+ kbString += "a1 SUB TOP.\n";
+ kbString += "a2 SUB TOP.\n";
} else if(ont.equals(TestOntology.DATA1)) {
kbString += "man SUB person.\n";
kbString += "woman SUB person.\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-11-22 08:45:56
|
Revision: 1522
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1522&view=rev
Author: jenslehmann
Date: 2008-11-22 08:45:50 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
utility methods for debugging EL simulations
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-21 15:11:14 UTC (rev 1521)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-11-22 08:45:50 UTC (rev 1522)
@@ -24,6 +24,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.NavigableSet;
import java.util.Set;
import java.util.TreeSet;
@@ -485,8 +486,30 @@
return str;
}
-
+ private String toString(Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) {
+ String str = "";
+ // comma separated list of descriptions
+ for(ELDescriptionNode node : nodes) {
+ str += nodeNames.get(node) + ",";
+ }
+ // remove last comma
+ if(str.length() > 0) {
+ str = str.substring(0, str.length()-1);
+ }
+ return str;
+ }
+ public String toSimulationString(Map<ELDescriptionNode,String> nodeNames) {
+ String str = "";
+ str += " in: " + toString(in, nodeNames) + "\n";
+ str += " inSC1: " + toString(inSC1, nodeNames) + "\n";
+ str += " inSC2: " + toString(inSC2, nodeNames) + "\n";
+ str += " out: " + toString(out, nodeNames) + "\n";
+ str += " outSC1: " + toString(outSC1, nodeNames) + "\n";
+ str += " outSC2: " + toString(outSC2, nodeNames) + "\n";
+ return str;
+ }
+
public ELDescriptionNode getParent() {
return parent;
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-21 15:11:14 UTC (rev 1521)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-11-22 08:45:50 UTC (rev 1522)
@@ -370,6 +370,17 @@
node2.out.remove(node1);
}
+ public String toSimulationString(Map<ELDescriptionNode,String> nodeNames) {
+ String str = "";
+ for(Entry<ELDescriptionNode,String> entry : nodeNames.entrySet()) {
+ String nodeName = entry.getValue();
+ ELDescriptionNode node = entry.getKey();
+ str += nodeName + ":\n";
+ str += node.toSimulationString(nodeNames) + "\n";
+ }
+ return str;
+ }
+
@Override
@SuppressWarnings("unchecked")
public ELDescriptionTree clone() {
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-21 15:11:14 UTC (rev 1521)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-11-22 08:45:50 UTC (rev 1522)
@@ -19,8 +19,10 @@
*/
package org.dllearner.test.junit;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.TreeSet;
import org.dllearner.algorithms.el.ELDescriptionNode;
@@ -100,22 +102,37 @@
* v4: out=outSC1={v2}, inSC2=outSC2={v2,v3}
*/
@Test
- public void test3() {
+ public void test3() {
+ // background knowledge, concepts, roles
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.R1SUBR2);
- ELDescriptionTree tree = new ELDescriptionTree(rs);
- ELDescriptionNode v1 = new ELDescriptionNode(tree);
ObjectProperty r1 = new ObjectProperty(uri("r1"));
NamedClass a1 = new NamedClass(uri("a1"));
NamedClass a2 = new NamedClass(uri("a2"));
- ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a1, a2);
- ELDescriptionNode v3 = new ELDescriptionNode(v1, r1, a2);
ObjectProperty r2 = new ObjectProperty(uri("r2"));
- ELDescriptionNode v4 = new ELDescriptionNode(v1, r2, a1);
- System.out.println("v1:\n" + v1.toSimulationString());
- System.out.println("v2:\n" + v2.toSimulationString());
- System.out.println("v3:\n" + v3.toSimulationString());
- System.out.println("v4:\n" + v4.toSimulationString());
+ // iteratively building up the tree (nodeNames is used for logging/debugging)
+ ELDescriptionTree tree = new ELDescriptionTree(rs);
+ Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();
+ ELDescriptionNode v1 = new ELDescriptionNode(tree);
+ nodeNames.put(v1, "v1");
+ log("root node v1", tree, nodeNames);
+ ELDescriptionNode v2 = new ELDescriptionNode(v1, r1);
+ nodeNames.put(v2, "v2");
+ log("edge to v2 added", tree, nodeNames);
+ v2.extendLabel(a1);
+ log("a1 added to v2", tree, nodeNames);
+ v2.extendLabel(a2);
+ log("a2 added to v2", tree, nodeNames);
+ ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
+ nodeNames.put(v3, "v3");
+ log("edge to v3 added", tree, nodeNames);
+ v3.extendLabel(a2);
+ log("a2 added to v3", tree, nodeNames);
+ ELDescriptionNode v4 = new ELDescriptionNode(v1, r2);
+ nodeNames.put(v4, "v4");
+ log("edge to v4 added", tree, nodeNames);
+ v4.extendLabel(a1);
+ log("a1 added to v4", tree, nodeNames);
assertEmpty(v1);
@@ -202,6 +219,16 @@
assertOutSC1(v6,v5);
}
+ private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
+ // print underlined message
+ System.out.println(message);
+ for(int i=0; i<=message.length(); i++) {
+ System.out.print("=");
+ }
+ System.out.println("\n");
+ System.out.println(tree.toSimulationString(nodeNames));
+ }
+
// all relations (in, inSC1, inSC2) should have the
// the specified node set as value
private void assertAll(ELDescriptionNode node, ELDescriptionNode... nodes) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-08 13:06:51
|
Revision: 1545
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1545&view=rev
Author: jenslehmann
Date: 2008-12-08 13:06:44 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
continued EL simulation updates (now all 4 unit tests pass)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java
trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java
trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java
trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -66,4 +66,9 @@
return tree;
}
+ @Override
+ public String toString() {
+ return "--" + label + "--> " + tree.toDescriptionString();
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -174,7 +174,7 @@
// }
// }
- System.out.println(update);
+// System.out.println(update);
// apply updates recursively top-down
tree.updateSimulation(update);
@@ -335,13 +335,42 @@
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
+ Set<ELDescriptionNode> tmp = tree.getNodesOnLevel(level);
+ for(ELDescriptionNode w : tmp) {
+ if(w != this) {
+ // SC1(v,w) can only change from false to true
+ if(!inSC1.contains(w) && tree.checkSC1(this, w)) {
+ tree.extendSimulationSC1(this, w);
+ if(inSC2.contains(w)) {
+ tree.extendSimulationSC12(this, w);
+ }
+ update.add(w.getParent());
+ }
+ // SC1(w,v) can only change from true to false
+ if(outSC1.contains(w) && !tree.checkSC1(w, this)) {
+ tree.shrinkSimulationSC1(w, this);
+ if(outSC2.contains(w)) {
+ tree.shrinkSimulationSC12(w, this);
+ }
+ if(!update.contains(w.getParent())) {
+ update.add(w.getParent());
+ }
+ }
+ }
+ }
+ if(parent != null) {
+ update.add(parent);
+ }
+
+ /*
// loop over all nodes on the same level, which are not in the in set
Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level));
tmp.removeAll(in);
for(ELDescriptionNode w : tmp) {
if(w != this) {
- // we only need to recompute SC2
+ // we only need to recompute SC1
if(inSC1.contains(w) && tree.checkSC2(this, w)) {
+ System.out.println("satisfied");
tree.extendSimulation(this, w);
update.add(w.parent);
}
@@ -361,6 +390,7 @@
}
}
}
+ */
// apply updates recursively top-down
tree.updateSimulation(update);
@@ -371,7 +401,9 @@
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
+ update.add(this);
+ /*
// loop over all nodes on the same level, which are not in the in set
Set<ELDescriptionNode> tmp = new HashSet<ELDescriptionNode>(tree.getNodesOnLevel(level));
tmp.removeAll(in);
@@ -394,7 +426,10 @@
}
}
}
+ */
+// update.add(this.parent);
+
// apply updates recursively top-down
tree.updateSimulation(update);
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -237,6 +237,42 @@
Set<ELDescriptionNode> sameLevel = levelNodeMapping.get(v.getLevel());
for(ELDescriptionNode w : sameLevel) {
if(v != w) {
+
+// System.out.println(v);
+// System.out.println(w);
+
+ // we update if SC2 did not hold but does now
+ if(!v.inSC2.contains(w) && checkSC2(v,w)) {
+// System.out.println("extend sim. after update");
+
+ extendSimulationSC2(v,w);
+ if(v.inSC1.contains(w)) {
+ extendSimulationSC12(v,w);
+ }
+ if(!list.contains(v.getParent())) {
+ list.add(v.getParent());
+ }
+ if(!list.contains(w.getParent())) {
+ list.add(w.getParent());
+ }
+ }
+
+ // similar case, but now possibly shrinking the simulation
+ if(w.inSC2.contains(v) && !checkSC2(w,v)) {
+// System.out.println("shrink sim. after update");
+
+ shrinkSimulationSC2(w,v);
+ if(w.inSC1.contains(v)) {
+ shrinkSimulationSC12(w,v);
+ }
+ if(!list.contains(v.getParent())) {
+ list.add(v.getParent());
+ }
+ if(!list.contains(w.getParent())) {
+ list.add(w.getParent());
+ }
+ }
+ /*
if(!v.out.contains(w) ) {
System.out.println("test");
if(checkSC2(v,w) && v.outSC1.contains(w)) {
@@ -257,6 +293,7 @@
shrinkSimulationSC2(w,v);
}
}
+ */
}
}
}
@@ -297,9 +334,10 @@
List<ELDescriptionEdge> edges1 = node1.getEdges();
List<ELDescriptionEdge> edges2 = node2.getEdges();
- for(ELDescriptionEdge edge : edges1) {
- // try to find an edge satisfying SC2 in the set
- if(!checkSC2Edge(edge, edges2)) {
+ for(ELDescriptionEdge superEdge : edges2) {
+ // try to find an edge satisfying SC2 in the set,
+ // i.e. detect whether superEdge is indeed more general
+ if(!checkSC2Edge(superEdge, edges1)) {
return false;
}
}
@@ -308,16 +346,16 @@
}
// check whether edges contains an element satisfying SC2
- private boolean checkSC2Edge(ELDescriptionEdge edge, List<ELDescriptionEdge> edges) {
- ObjectProperty op1 = edge.getLabel();
- ELDescriptionNode node1 = edge.getTree();
+ private boolean checkSC2Edge(ELDescriptionEdge superEdge, List<ELDescriptionEdge> edges) {
+ ObjectProperty superOP = superEdge.getLabel();
+ ELDescriptionNode node1 = superEdge.getTree();
- for(ELDescriptionEdge edge2 : edges) {
- ObjectProperty op2 = edge2.getLabel();
+ for(ELDescriptionEdge edge : edges) {
+ ObjectProperty op = edge.getLabel();
// we first check the condition on the properties
- if(roleHierarchy.isSubpropertyOf(op1, op2)) {
+ if(roleHierarchy.isSubpropertyOf(op, superOP)) {
// check condition on simulations of referred nodes
- ELDescriptionNode node2 = edge2.getTree();
+ ELDescriptionNode node2 = edge.getTree();
if(node1.in.contains(node2) || node2.in.contains(node1)) {
// we found a node satisfying the condition, so we can return
return true;
@@ -371,10 +409,10 @@
}
public void shrinkSimulationSC2(ELDescriptionNode node1, ELDescriptionNode node2) {
- System.out.println(node2.outSC2);
+// System.out.println(node2.outSC2);
node1.inSC2.remove(node2);
node2.outSC2.remove(node1);
- System.out.println(node2.outSC2);
+// System.out.println(node2.outSC2);
}
public void shrinkSimulationSC12(ELDescriptionNode node1, ELDescriptionNode node2) {
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ClassHierarchy.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -147,6 +147,7 @@
return true;
} else {
for (Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) {
+
// search the upper classes of the subclass
if (moreGeneralClass instanceof NamedClass) {
if (isSubclassOf((NamedClass) moreGeneralClass, superClass)) {
Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeProperty.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -69,4 +69,22 @@
public int compareTo(DatatypeProperty o) {
return name.compareTo(o.name);
}
+
+ @Override
+ public boolean equals(Object nc) {
+ // standard equals code - always return true for object identity and
+ // false if classes differ
+ if(nc == this) {
+ return true;
+ } else if(getClass() != nc.getClass()) {
+ return false;
+ }
+ // compare on URIs
+ return ((DatatypeProperty)nc).name.equals(name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/core/owl/NamedClass.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -32,7 +32,7 @@
*/
public class NamedClass extends Description implements Entity, NamedKBElement, Comparable<NamedClass> {
- String name;
+ private String name;
public NamedClass(String name) {
this.name = name;
@@ -82,4 +82,22 @@
public int compareTo(NamedClass o) {
return name.compareTo(o.name);
}
+
+ @Override
+ public boolean equals(Object nc) {
+ // standard equals code - always return true for object identity and
+ // false if classes differ
+ if(nc == this) {
+ return true;
+ } else if(getClass() != nc.getClass()) {
+ return false;
+ }
+ // compare on URIs
+ return ((NamedClass)nc).name.equals(name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectProperty.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -60,4 +60,22 @@
public int compareTo(ObjectProperty o) {
return name.compareTo(o.name);
}
+
+ @Override
+ public boolean equals(Object nc) {
+ // standard equals code - always return true for object identity and
+ // false if classes differ
+ if(nc == this) {
+ return true;
+ } else if(getClass() != nc.getClass()) {
+ return false;
+ }
+ // compare on URIs
+ return ((ObjectProperty)nc).name.equals(name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/core/owl/ObjectPropertyHierarchy.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -74,6 +74,7 @@
if(subProperty.equals(superProperty)) {
return true;
} else {
+// System.out.println("oph: " + subProperty + " " + superProperty);
for(ObjectProperty moreGeneralProperty : roleHierarchyUp.get(subProperty)) {
if(isSubpropertyOf(moreGeneralProperty, superProperty)) {
return true;
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -200,14 +200,19 @@
ELDescriptionNode v4 = new ELDescriptionNode(v2, r1, a1);
nodeNames.put(v4, "v4");
log("v4 added", tree, nodeNames);
- ELDescriptionNode v5 = new ELDescriptionNode(v2, r3, a1, a2);
+ ELDescriptionNode v5 = new ELDescriptionNode(v2, r3);
nodeNames.put(v5, "v5");
+ log("tmp 1", tree, nodeNames);
+ v5.extendLabel(a1);
+ log("tmp 2", tree, nodeNames);
+ v5.extendLabel(a2);
log("v5 added", tree, nodeNames);
v2.refineEdge(1, r2);
log("edge refined", tree, nodeNames);
- ELDescriptionNode v6 = new ELDescriptionNode(v3, r3, a3);
+ ELDescriptionNode v6 = new ELDescriptionNode(v3, r3);
nodeNames.put(v6, "v6");
- log("v6 added", tree, nodeNames);
+ log("v6 added", tree, nodeNames);
+ v6.extendLabel(a3);
log("tree 4", tree, nodeNames);
assertEmpty(v1);
@@ -233,9 +238,50 @@
assertInSC1(v6);
assertIn(v6);
assertOut(v6,v5);
- assertOutSC1(v6,v5);
+ assertOutSC1(v6,v5);
}
+ /**
+ * v_1
+ * / \
+ * r_2 r_1
+ * / \
+ * v_2 v_3
+ * / | | \
+ * r_1 r_1 r_1 r_2
+ * / | | \
+ * v_4 v_5 v_6 v_7
+ * / | | \ | |
+ * r_2 r_1 r_2 r_2 r_1 r_2
+ * / | | | | |
+ * v_8 v_9 v_10 v_11 v_12 v_13
+ * A_1 A_2 A_2 A_1 A_2 A_2
+ *
+ *
+ * inSC1:
+ * (v_8,{v_9,..,v_13}), (v_9,{v_10,v_12,v_13}),... (Pattern wiederholt sich dann fuer die A_1 bzw A_2 Blaetter), (v_4,{v_5,v_6,v_7}),... (selbiges hier) (v_2,{v_3}), (v_3,{v_2})
+ *
+ * outSC1:
+ * (v_8,{v_11}), v_9,{v_8, v_10,...v_13}),... Pattern wiederholt sich
+ * fuer restliche Knoten gilt inSC1=outSC1
+ *
+ * inSC2:
+ * {v_8,...,v_13}2, (v_4,{v_5, v_6, v_7}), (v_5,{v_7}), (v_6,{v_7})
+ * (v_2,{v_3})
+ *
+ * outSC2:
+ * {v_8,...,v_13}2, (v_5,{v_4}), (v_6,{v_4}), (v_7,{v_5, v_6}), (v_3,{v_2})
+ *
+ * Baum ist nicht minimal.
+ */
+ @Test
+ public void test5() {
+ ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE3);
+ ELDescriptionTree tree = new ELDescriptionTree(rs);
+ Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();
+
+ }
+
private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
// print underlined message
System.out.println(message);
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-12-07 22:42:39 UTC (rev 1544)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2008-12-08 13:06:44 UTC (rev 1545)
@@ -36,7 +36,7 @@
*/
public final class TestOntologies {
- public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, R1SUBR2, DATA1 };
+ public enum TestOntology { EMPTY, SIMPLE, SIMPLE2, SIMPLE3, R1SUBR2, DATA1 };
public static ReasonerComponent getTestOntology(TestOntology ont) {
String kbString = "";
@@ -55,9 +55,13 @@
kbString += "cat SUB animal.\n";
kbString += "(human AND animal) = BOTTOM.\n";
} else if(ont.equals(TestOntology.SIMPLE2)) {
- kbString += "Subrole(r1,r2).\n";
+ kbString += "Subrole(r2,r3).\n";
kbString += "a1 SUB TOP.\n";
kbString += "a2 SUB a3.\n";
+ kbString += "r1(a,b).\n"; // we have to declare r1
+ } else if(ont.equals(TestOntology.SIMPLE3)) {
+ kbString += "a1 SUB a2.\n";
+ kbString += "Subrole(r1,r2).\n";
} else if(ont.equals(TestOntology.R1SUBR2)) {
kbString += "Subrole(r1,r2).\n";
kbString += "a1 SUB TOP.\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-09 19:00:50
|
Revision: 1548
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1548&view=rev
Author: jenslehmann
Date: 2008-12-09 19:00:45 +0000 (Tue, 09 Dec 2008)
Log Message:
-----------
added simulation unit test 5 and fixed a bug
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-09 11:03:35 UTC (rev 1547)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-09 19:00:45 UTC (rev 1548)
@@ -352,9 +352,7 @@
if(outSC2.contains(w)) {
tree.shrinkSimulationSC12(w, this);
}
- if(!update.contains(w.getParent())) {
- update.add(w.getParent());
- }
+ update.add(w.getParent());
}
}
}
@@ -525,7 +523,14 @@
return str;
}
- private String toString(Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) {
+ /**
+ * A convenience method (for debugging purposes) to get a comma separated list of nodes, where the
+ * nodes are given names (to make them readable).
+ * @param nodes The node objects.
+ * @param nodeNames A mapping to node names.
+ * @return A comma separated list of the node names.
+ */
+ public static String toString(Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) {
String str = "";
// comma separated list of descriptions
for(ELDescriptionNode node : nodes) {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-09 11:03:35 UTC (rev 1547)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-09 19:00:45 UTC (rev 1548)
@@ -334,29 +334,37 @@
List<ELDescriptionEdge> edges1 = node1.getEdges();
List<ELDescriptionEdge> edges2 = node2.getEdges();
+// System.out.println(node1.transformToDescription());
+// System.out.println(node2.transformToDescription());
+
for(ELDescriptionEdge superEdge : edges2) {
// try to find an edge satisfying SC2 in the set,
// i.e. detect whether superEdge is indeed more general
if(!checkSC2Edge(superEdge, edges1)) {
+// System.out.println("false");
return false;
}
}
-
+// System.out.println("true");
return true;
}
// check whether edges contains an element satisfying SC2
private boolean checkSC2Edge(ELDescriptionEdge superEdge, List<ELDescriptionEdge> edges) {
ObjectProperty superOP = superEdge.getLabel();
- ELDescriptionNode node1 = superEdge.getTree();
+ ELDescriptionNode superNode = superEdge.getTree();
for(ELDescriptionEdge edge : edges) {
+// System.out.println("superEdge: " + superEdge);
+// System.out.println("edge: " + edge);
+
ObjectProperty op = edge.getLabel();
// we first check the condition on the properties
if(roleHierarchy.isSubpropertyOf(op, superOP)) {
// check condition on simulations of referred nodes
- ELDescriptionNode node2 = edge.getTree();
- if(node1.in.contains(node2) || node2.in.contains(node1)) {
+ ELDescriptionNode node = edge.getTree();
+// if(superNode.in.contains(node) || node.in.contains(superNode)) {
+ if(node.in.contains(superNode)) {
// we found a node satisfying the condition, so we can return
return true;
}
Modified: trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java 2008-12-09 11:03:35 UTC (rev 1547)
+++ trunk/src/dl-learner/org/dllearner/core/options/DoubleConfigOption.java 2008-12-09 19:00:45 UTC (rev 1548)
@@ -57,10 +57,8 @@
*/
@Override
public boolean isValidValue(Double value) {
- if (value >= lowerLimit && value <= upperLimit)
- return true;
- else
- return false;
+ double tolerance = 0.0001;
+ return ((value >= lowerLimit-tolerance) && (value <= upperLimit+tolerance));
}
/**
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-09 11:03:35 UTC (rev 1547)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-09 19:00:45 UTC (rev 1548)
@@ -23,7 +23,9 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Set;
import java.util.TreeSet;
+import java.util.Map.Entry;
import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.algorithms.el.ELDescriptionTree;
@@ -193,27 +195,27 @@
nodeNames.put(v1, "v1");
ELDescriptionNode v2 = new ELDescriptionNode(v1, r1, a2, a3);
nodeNames.put(v2, "v2");
- log("v2 added", tree, nodeNames);
+// log("v2 added", tree, nodeNames);
ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
nodeNames.put(v3, "v3");
- log("v3 added", tree, nodeNames);
+// log("v3 added", tree, nodeNames);
ELDescriptionNode v4 = new ELDescriptionNode(v2, r1, a1);
nodeNames.put(v4, "v4");
- log("v4 added", tree, nodeNames);
+// log("v4 added", tree, nodeNames);
ELDescriptionNode v5 = new ELDescriptionNode(v2, r3);
nodeNames.put(v5, "v5");
- log("tmp 1", tree, nodeNames);
+// log("tmp 1", tree, nodeNames);
v5.extendLabel(a1);
- log("tmp 2", tree, nodeNames);
+// log("tmp 2", tree, nodeNames);
v5.extendLabel(a2);
- log("v5 added", tree, nodeNames);
+// log("v5 added", tree, nodeNames);
v2.refineEdge(1, r2);
- log("edge refined", tree, nodeNames);
+// log("edge refined", tree, nodeNames);
ELDescriptionNode v6 = new ELDescriptionNode(v3, r3);
nodeNames.put(v6, "v6");
- log("v6 added", tree, nodeNames);
+// log("v6 added", tree, nodeNames);
v6.extendLabel(a3);
- log("tree 4", tree, nodeNames);
+// log("tree 4", tree, nodeNames);
assertEmpty(v1);
@@ -257,9 +259,12 @@
* v_8 v_9 v_10 v_11 v_12 v_13
* A_1 A_2 A_2 A_1 A_2 A_2
*
+ * Knowledge base: A_1\sqsubseteq A_2
+ r_1\sqsubseteq r_2
*
* inSC1:
- * (v_8,{v_9,..,v_13}), (v_9,{v_10,v_12,v_13}),... (Pattern wiederholt sich dann fuer die A_1 bzw A_2 Blaetter), (v_4,{v_5,v_6,v_7}),... (selbiges hier) (v_2,{v_3}), (v_3,{v_2})
+ * (v_8,{v_9,..,v_13}), (v_9,{v_10,v_12,v_13}),... (Pattern wiederholt sich dann fuer die A_1 bzw A_2 Blaetter),
+ * (v_4,{v_5,v_6,v_7}),... (selbiges hier) (v_2,{v_3}), (v_3,{v_2})
*
* outSC1:
* (v_8,{v_11}), v_9,{v_8, v_10,...v_13}),... Pattern wiederholt sich
@@ -280,8 +285,137 @@
ELDescriptionTree tree = new ELDescriptionTree(rs);
Map<ELDescriptionNode,String> nodeNames = new LinkedHashMap<ELDescriptionNode,String>();
+ ObjectProperty r1 = new ObjectProperty(uri("r1"));
+ ObjectProperty r2 = new ObjectProperty(uri("r2"));
+ NamedClass a1 = new NamedClass(uri("a1"));
+ NamedClass a2 = new NamedClass(uri("a2"));
+
+ ELDescriptionNode v1 = new ELDescriptionNode(tree);
+ nodeNames.put(v1, "v1");
+ ELDescriptionNode v2 = new ELDescriptionNode(v1, r2);
+ nodeNames.put(v2, "v2");
+ ELDescriptionNode v3 = new ELDescriptionNode(v1, r1);
+ nodeNames.put(v3, "v3");
+ ELDescriptionNode v4 = new ELDescriptionNode(v2, r1);
+ nodeNames.put(v4, "v4");
+ ELDescriptionNode v5 = new ELDescriptionNode(v2, r1);
+ nodeNames.put(v5, "v5");
+ ELDescriptionNode v6 = new ELDescriptionNode(v3, r1);
+ nodeNames.put(v6, "v6");
+ ELDescriptionNode v7 = new ELDescriptionNode(v3, r2);
+ nodeNames.put(v7, "v7");
+ ELDescriptionNode v8 = new ELDescriptionNode(v4, r2, a1);
+ nodeNames.put(v8, "v8");
+ ELDescriptionNode v9 = new ELDescriptionNode(v4, r1, a2);
+ nodeNames.put(v9, "v9");
+ ELDescriptionNode v10 = new ELDescriptionNode(v5, r2, a2);
+ nodeNames.put(v10, "v10");
+ ELDescriptionNode v11 = new ELDescriptionNode(v5, r2, a1);
+ nodeNames.put(v11, "v11");
+ ELDescriptionNode v12 = new ELDescriptionNode(v6, r1, a2);
+ nodeNames.put(v12, "v12");
+ ELDescriptionNode v13 = new ELDescriptionNode(v7, r2, a2);
+ nodeNames.put(v13, "v13");
+
+// log("tree 5", tree, nodeNames);
+
+ // automatically generated asserts
+
+ assertInSC1(v1);
+ assertInSC2(v1);
+ assertIn(v1);
+ assertOutSC1(v1);
+ assertOutSC2(v1);
+ assertOut(v1);
+
+ assertInSC1(v2,v3);
+ assertInSC2(v2,v3);
+ assertIn(v2,v3);
+ assertOutSC1(v2,v3);
+ assertOutSC2(v2);
+ assertOut(v2);
+
+ assertInSC1(v3,v2);
+ assertInSC2(v3);
+ assertIn(v3);
+ assertOutSC1(v3,v2);
+ assertOutSC2(v3,v2);
+ assertOut(v3,v2);
+
+ assertInSC1(v4,v6,v5,v7);
+ assertInSC2(v4,v6,v5,v7);
+ assertIn(v4,v6,v5,v7);
+ assertOutSC1(v4,v6,v5,v7);
+ assertOutSC2(v4);
+ assertOut(v4);
+
+ assertInSC1(v5,v4,v6,v7);
+ assertInSC2(v5,v7);
+ assertIn(v5,v7);
+ assertOutSC1(v5,v4,v6,v7);
+ assertOutSC2(v5,v4);
+ assertOut(v5,v4);
+
+ assertInSC1(v6,v4,v5,v7);
+ assertInSC2(v6,v7);
+ assertIn(v6,v7);
+ assertOutSC1(v6,v4,v5,v7);
+ assertOutSC2(v6,v4);
+ assertOut(v6,v4);
+
+ assertInSC1(v7,v4,v6,v5);
+ assertInSC2(v7);
+ assertIn(v7);
+ assertOutSC1(v7,v4,v6,v5);
+ assertOutSC2(v7,v4,v6,v5);
+ assertOut(v7,v4,v6,v5);
+
+ assertInSC1(v8,v10,v13,v11,v9,v12);
+ assertInSC2(v8,v10,v13,v11,v9,v12);
+ assertIn(v8,v10,v13,v11,v9,v12);
+ assertOutSC1(v8,v11);
+ assertOutSC2(v8,v10,v13,v11,v9,v12);
+ assertOut(v8,v11);
+
+ assertInSC1(v9,v10,v13,v12);
+ assertInSC2(v9,v10,v13,v11,v12,v8);
+ assertIn(v9,v10,v13,v12);
+ assertOutSC1(v9,v10,v13,v11,v12,v8);
+ assertOutSC2(v9,v10,v13,v11,v12,v8);
+ assertOut(v9,v10,v13,v11,v12,v8);
+
+ assertInSC1(v10,v13,v9,v12);
+ assertInSC2(v10,v13,v11,v9,v12,v8);
+ assertIn(v10,v13,v9,v12);
+ assertOutSC1(v10,v13,v11,v9,v12,v8);
+ assertOutSC2(v10,v13,v11,v9,v12,v8);
+ assertOut(v10,v13,v11,v9,v12,v8);
+
+ assertInSC1(v11,v10,v13,v9,v12,v8);
+ assertInSC2(v11,v10,v13,v9,v12,v8);
+ assertIn(v11,v10,v13,v9,v12,v8);
+ assertOutSC1(v11,v8);
+ assertOutSC2(v11,v10,v13,v9,v12,v8);
+ assertOut(v11,v8);
+
+ assertInSC1(v12,v10,v13,v9);
+ assertInSC2(v12,v10,v13,v11,v9,v8);
+ assertIn(v12,v10,v13,v9);
+ assertOutSC1(v12,v10,v13,v11,v9,v8);
+ assertOutSC2(v12,v10,v13,v11,v9,v8);
+ assertOut(v12,v10,v13,v11,v9,v8);
+
+ assertInSC1(v13,v10,v9,v12);
+ assertInSC2(v13,v10,v11,v9,v8,v12);
+ assertIn(v13,v10,v9,v12);
+ assertOutSC1(v13,v10,v11,v9,v8,v12);
+ assertOutSC2(v13,v10,v11,v9,v8,v12);
+ assertOut(v13,v10,v11,v9,v8,v12);
+
+// logAsserts(tree, nodeNames);
}
+ // display a simulation as debug log
private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
// print underlined message
System.out.println(message);
@@ -292,6 +426,35 @@
System.out.println(tree.toSimulationString(nodeNames));
}
+ // display Java code for assertions, i.e. the method generates the assertion code
+ // (under the assumption that the current algorithm output is correct, which needs
+ // to be verified of course)
+ @SuppressWarnings("unused")
+ private void logAsserts(ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
+ String str = "";
+ for(Entry<ELDescriptionNode,String> entry : nodeNames.entrySet()) {
+ String nodeName = entry.getValue();
+ ELDescriptionNode node = entry.getKey();
+ str += "assertInSC1" + getAssertString(node, nodeName, node.getInSC1(), nodeNames);
+ str += "assertInSC2" + getAssertString(node, nodeName, node.getInSC2(), nodeNames);
+ str += "assertIn" + getAssertString(node, nodeName, node.getIn(), nodeNames);
+ str += "assertOutSC1" + getAssertString(node, nodeName, node.getOutSC1(), nodeNames);
+ str += "assertOutSC2" + getAssertString(node, nodeName, node.getOutSC2(), nodeNames);
+ str += "assertOut" + getAssertString(node, nodeName, node.getOut(), nodeNames);
+ str += "\n";
+ }
+ System.out.println(str);
+ }
+
+ // convenience method
+ private String getAssertString(ELDescriptionNode node, String nodeName, Set<ELDescriptionNode> nodes, Map<ELDescriptionNode,String> nodeNames) {
+ if(nodes.isEmpty()) {
+ return "(" + nodeName+");\n";
+ } else {
+ return "(" + nodeName+","+ELDescriptionNode.toString(nodes, nodeNames) + ");\n";
+ }
+ }
+
// all relations (in, inSC1, inSC2) should have the
// the specified node set as value
private void assertAll(ELDescriptionNode node, ELDescriptionNode... nodes) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-16 07:11:08
|
Revision: 1554
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1554&view=rev
Author: jenslehmann
Date: 2008-12-16 07:11:01 +0000 (Tue, 16 Dec 2008)
Log Message:
-----------
EL refinement operator II
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-15 12:04:17 UTC (rev 1553)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-16 07:11:01 UTC (rev 1554)
@@ -60,6 +60,10 @@
protected ELDescriptionNode rootNode;
+ // the set of all nodes in the tree
+ private Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>();
+
+ // nodes on a given level of the tree
private Map<Integer, Set<ELDescriptionNode>> levelNodeMapping = new HashMap<Integer, Set<ELDescriptionNode>>();
// the background knowledge (we need to have it explicitly here,
@@ -172,8 +176,8 @@
}
/**
- * Internal method for updating the level node mapping. It is called when a
- * new node is added to the tree.
+ * Internal method for updating the node set and the level node mapping. It must be
+ * called when a new node is added to the tree.
*
* @param node
* The new node.
@@ -181,6 +185,7 @@
* Level of the new node.
*/
protected void addNodeToLevel(ELDescriptionNode node, int level) {
+ nodes.add(node);
if (level <= maxLevel) {
levelNodeMapping.get(level).add(node);
} else if (level == maxLevel + 1) {
@@ -554,4 +559,11 @@
public String toDescriptionString() {
return rootNode.toDescriptionString();
}
+
+ /**
+ * @return the nodes
+ */
+ public Set<ELDescriptionNode> getNodes() {
+ return nodes;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-12-15 12:04:17 UTC (rev 1553)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-12-16 07:11:01 UTC (rev 1554)
@@ -50,7 +50,7 @@
*
* <p>Properties:
* <ul>
- * <li>complete</li>
+ * <li>complete? (still open)</li>
* <li>proper</li>
* <li>finite</li>
* <li>uses class/property hierarchy</li>
Added: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-16 07:11:01 UTC (rev 1554)
@@ -0,0 +1,338 @@
+/**
+ * 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.refinementoperators;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.Stack;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.log4j.Logger;
+import org.dllearner.algorithms.el.ELDescriptionEdge;
+import org.dllearner.algorithms.el.ELDescriptionNode;
+import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.ObjectPropertyHierarchy;
+import org.dllearner.core.owl.ClassHierarchy;
+import org.dllearner.core.owl.Thing;
+
+/**
+ * EL downward refinement operator constructed by Jens Lehmann
+ * and Christoph Haase. It takes an EL description tree as input
+ * and outputs a set of EL description trees.
+ *
+ * <p>Properties:
+ * <ul>
+ * <li>complete</li>
+ * <li>proper</li>
+ * <li>finite</li>
+ * <li>uses class/property hierarchy</li>
+ * <li>takes domain/range into account</li>
+ * <li>uses disjoint classes/classes without common instances</li>
+ * <li>all refinements are minimal (i.e. cannot be shortened without changing semantics)</li>
+ * </ul>
+ *
+ * @author Jens Lehmann
+ *
+ */
+@SuppressWarnings("unused")
+public class ELDown2 extends RefinementOperatorAdapter {
+
+ private static Logger logger = Logger.getLogger(ELDown2.class);
+
+ private ReasonerComponent rs;
+
+ // hierarchies
+ private ClassHierarchy subsumptionHierarchy;
+ private ObjectPropertyHierarchy opHierarchy;
+
+ // domains and ranges
+ private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>();
+ private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>();
+
+ // app_A set of applicable properties for a given class
+ private Map<Description, Set<ObjectProperty>> app = new TreeMap<Description, Set<ObjectProperty>>();
+
+ // most general applicable properties
+ private Map<Description,Set<ObjectProperty>> mgr = new TreeMap<Description,Set<ObjectProperty>>();
+
+ // utility class
+ private Utility utility;
+
+ public ELDown2(ReasonerComponent rs) {
+ this.rs = rs;
+ utility = new Utility(rs);
+ subsumptionHierarchy = rs.getClassHierarchy();
+ opHierarchy = rs.getObjectPropertyHierarchy();
+
+ // query reasoner for domains and ranges
+ // (because they are used often in the operator)
+ for(ObjectProperty op : rs.getObjectProperties()) {
+ opDomains.put(op, rs.getDomain(op));
+ opRanges.put(op, rs.getRange(op));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description)
+ */
+ @Override
+ public Set<Description> refine(Description concept) {
+ ELDescriptionTree tree = new ELDescriptionTree(rs, concept);
+ Set<ELDescriptionTree> refinementTrees = refine(tree);
+ Set<Description> refinements = new HashSet<Description>();
+ for(ELDescriptionTree refinementTree : refinementTrees) {
+ refinements.add(refinementTree.transformToDescription());
+ }
+ return refinements;
+ }
+
+ /**
+ * Performs downward refinement for the given tree. The operator
+ * works directly on EL description trees (which differ from the
+ * the tree structures build by descriptions).
+ *
+ * @param tree Input EL description tree.
+ * @return Set of refined EL description trees.
+ */
+ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ // loop over all nodes of the tree and perform one of the
+ // transformations on it (we make a copy of all nodes, because
+ // the transformations can, of course, add new nodes)
+ Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>(tree.getNodes());
+ for(ELDescriptionNode v : nodes) {
+ // perform operations
+ refinements.addAll(extendLabel(tree, v));
+ refinements.addAll(refineLabel(tree, v));
+ refinements.addAll(refineEdge(tree, v));
+ refinements.addAll(attachSubtree(tree, v));
+ }
+
+// return refine(tree, tree.getRootNode(), new Thing(), true);
+ return refinements;
+ }
+
+ private Set<ELDescriptionTree> extendLabel(ELDescriptionTree tree, ELDescriptionNode v) {
+ return null;
+ }
+
+ private Set<ELDescriptionTree> refineLabel(ELDescriptionTree tree, ELDescriptionNode v) {
+ return null;
+ }
+
+ private Set<ELDescriptionTree> refineEdge(ELDescriptionTree tree, ELDescriptionNode v) {
+ return null;
+ }
+
+ private Set<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v) {
+ return null;
+ }
+
+ private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index, boolean minimize) {
+ // the set of all refinements, which we will return
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ // the position of the node within the tree (needed for getting
+ // the corresponding node in a cloned tree)
+ int[] position = node.getCurrentPosition();
+
+ // option 1: label extension
+ Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel());
+ for(NamedClass nc : candidates) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+ // extend label
+ clonedNode.extendLabel(nc);
+ refinements.add(clonedTree);
+ }
+
+
+ // option 2: label refinement
+ // loop through all classes in label
+ for(NamedClass nc : node.getLabel()) {
+ // find all more special classes for the given label
+ for(Description moreSpecial : rs.getSubClasses(nc)) {
+ if(moreSpecial instanceof NamedClass) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+
+// System.out.println("tree: " + tree);
+// System.out.println("cloned tree: " + clonedTree);
+// System.out.println("node: " + node);
+// System.out.println("cloned unmodified: " + clonedNode);
+
+ // create refinements by replacing class
+ clonedNode.replaceInLabel(nc, (NamedClass) moreSpecial);
+
+// System.out.println("cloned modified: " + clonedNode);
+ refinements.add(clonedTree);
+ }
+ }
+ }
+
+ // option 3: new edge
+ SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
+ Set<ObjectProperty> mgr = utility.computeMgr(appOPs);
+ // temporary set of all concepts, which still have to pass the equivalence check
+ Stack<ELDescriptionTree> stack = new Stack<ELDescriptionTree>();
+ for(ObjectProperty op : mgr) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ ELDescriptionNode clonedNode = clonedTree.getNode(position);
+ // add a new node and edge
+ ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>());
+ stack.add(clonedTree);
+
+ // recurse if concept is equivalent
+ while(stack.size() != 0) {
+ // we pick an arbitrary tree and remove it from the stack
+ ELDescriptionTree testTree = stack.pop();
+ // test equivalence (we found out that we can use the
+ // minimality test for equivalence in this case)
+ boolean equivalent = !testTree.isMinimal();
+ // if the tree is equivalent, we need to populate the
+ // stack with refinements (which are later tested for
+ // equivalence)
+ if(equivalent) {
+ // edge refinement
+ // we know that the edge we added is the last one for this node
+ int edgeNr = node.getEdges().size() - 1;
+ ELDescriptionEdge edge = node.getEdges().get(edgeNr);
+ // all refinements of this edge are added to the stack
+ // (set 1 in article)
+ refineEdge(stack, tree, node, position, edgeNr);
+ // perform node refinements in non-minimize-mode
+ // (set 2 in article)
+// commented out, because didn't make sense to me
+// refinements.addAll(refineEdges(tree, newNode, position));
+ stack.addAll(refine(tree, newNode, opRanges.get(edge), false));
+ } else {
+ // tree is not equivalent, i.e. a proper refinement
+ refinements.add(testTree);
+ }
+ }
+ }
+
+ // option 4: edge refinement
+ refinements.addAll(refineEdges(tree, node, position));
+
+ // option 5: child refinement
+ for(ELDescriptionEdge edge : node.getEdges()) {
+ // recursive call on child node and property range as index
+ Description range = rs.getRange(edge.getLabel());
+// System.out.println(tree + "\nrecurse to:\n" + edge.getTree());
+ refinements.addAll(refine(tree, edge.getTree(), range, minimize));
+ }
+
+ // we found out that, in case we start from the TOP concept
+ // (which is assumed in the current implementation), we can
+ // simply throw away all non-minimal concepts
+ if(minimize) {
+ Iterator<ELDescriptionTree> it = refinements.iterator();
+ while(it.hasNext()) {
+ if(!it.next().isMinimal()) {
+ it.remove();
+ }
+ }
+ }
+
+ return refinements;
+ }
+
+ private Set<ELDescriptionTree> refineEdges(ELDescriptionTree tree, ELDescriptionNode node, int[] position) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+ for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) {
+ refineEdge(refinements, tree, node, position, edgeNumber);
+ }
+ return refinements;
+ }
+
+ private void refineEdge(Collection<ELDescriptionTree> refinements, ELDescriptionTree tree, ELDescriptionNode node, int[] position, int edgeNumber) {
+ ELDescriptionEdge edge = node.getEdges().get(edgeNumber);
+ ObjectProperty op = edge.getLabel();
+ // find all more special properties
+ for(ObjectProperty op2 : rs.getSubProperties(op)) {
+ // we check whether the range of this property is not disjoint
+ // with the existing child node (we do not perform a full disjointness
+ // check, but only compare with the flattened concept to keep the number
+ // of possible disjointness checks finite)
+ if(!utility.isDisjoint(getFlattenedConcept(edge.getTree()), opRanges.get(op2))) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ // find cloned edge and replace its label
+ clonedTree.getNode(position).refineEdge(edgeNumber, op2);
+// ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
+// clonedEdge.setLabel(op2);
+ refinements.add(clonedTree);
+ }
+
+ }
+ }
+
+ // simplifies a potentially nested tree in a flat conjunction by taking
+ // the domain of involved roles, e.g. for
+ // C = Professor \sqcap \exists hasChild.Student
+ // the result would be Professor \sqcap Human (assuming Human is the domain
+ // of hasChild)
+ private Description getFlattenedConcept(ELDescriptionNode node) {
+ Intersection i = new Intersection();
+
+ // add all named classes to intersection
+ for(NamedClass nc : node.getLabel()) {
+ i.addChild(nc);
+ }
+ // add domain of all roles to intersection
+ for(ELDescriptionEdge edge : node.getEdges()) {
+ i.addChild(opDomains.get(edge.getLabel()));
+ }
+
+ // if the intersection has just one element, we return
+ // the element itself instead
+ if(i.getChildren().size() == 1) {
+ return i.getChild(0);
+ }
+
+ return i;
+ }
+
+// private void computeMg(Description index) {
+// // compute the applicable properties if this has not been done yet
+// if(app.get(index) == null)
+// app.put(index, utility.computeApplicableObjectProperties(index));
+//
+// mgr.put(index, new TreeSet<ObjectProperty>());
+//
+//
+// }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-16 10:17:01
|
Revision: 1555
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1555&view=rev
Author: jenslehmann
Date: 2008-12-16 10:16:51 +0000 (Tue, 16 Dec 2008)
Log Message:
-----------
nnf conversion in fast instance checker
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-12-16 07:11:01 UTC (rev 1554)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-12-16 10:16:51 UTC (rev 1555)
@@ -195,9 +195,9 @@
public Score computeScore(Description concept) {
// FastInstanceChecker supports only negation normal form, so we have to make
// sure to convert the description before
- if(reasoner instanceof FastInstanceChecker) {
- return definitionLP.computeScore(ConceptTransformation.transformToNegationNormalForm(new Negation(concept)));
- }
+// if(reasoner instanceof FastInstanceChecker) {
+// return definitionLP.computeScore(ConceptTransformation.transformToNegationNormalForm(new Negation(concept)));
+// }
return definitionLP.computeScore(new Negation(concept));
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-16 07:11:01 UTC (rev 1554)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-16 10:16:51 UTC (rev 1555)
@@ -70,6 +70,7 @@
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
import org.dllearner.utilities.Helper;
+import org.dllearner.utilities.owl.ConceptTransformation;
/**
* Reasoner for fast instance checks. It works by completely dematerialising the
@@ -260,9 +261,12 @@
if (child instanceof NamedClass) {
return classInstancesNeg.get((NamedClass) child).contains(individual);
} else {
- throw new ReasoningMethodUnsupportedException("Instance check for description "
- + description
- + " unsupported. Description needs to be in negation normal form.");
+ logger.debug("Converting description to negation normal form in fast instance check (should be avoided if possible).");
+ Description nnf = ConceptTransformation.transformToNegationNormalForm(child);
+ return hasTypeImpl(nnf, individual);
+// throw new ReasoningMethodUnsupportedException("Instance check for description "
+// + description
+// + " unsupported. Description needs to be in negation normal form.");
}
} else if (description instanceof Thing) {
return true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-16 16:24:58
|
Revision: 1556
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1556&view=rev
Author: jenslehmann
Date: 2008-12-16 16:24:53 +0000 (Tue, 16 Dec 2008)
Log Message:
-----------
EL refinement operator II ctd.
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNodeComparator.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -33,7 +33,7 @@
private ObjectProperty label;
- private ELDescriptionNode tree;
+ private ELDescriptionNode node;
/**
* Constructs and edge given a label and an EL description tree.
@@ -42,7 +42,7 @@
*/
public ELDescriptionEdge(ObjectProperty label, ELDescriptionNode tree) {
this.label = label;
- this.tree = tree;
+ this.node = tree;
}
/**
@@ -62,13 +62,13 @@
/**
* @return The EL description tree
*/
- public ELDescriptionNode getTree() {
- return tree;
+ public ELDescriptionNode getNode() {
+ return node;
}
@Override
public String toString() {
- return "--" + label + "--> " + tree.toDescriptionString();
+ return "--" + label + "--> " + node.toDescriptionString();
}
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -111,7 +111,7 @@
this(parentNode, parentProperty, new TreeSet<NamedClass>(Arrays.asList(label)));
}
- public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, TreeSet<NamedClass> label) {
+ public ELDescriptionNode(ELDescriptionNode parentNode, ObjectProperty parentProperty, Set<NamedClass> label) {
// this.label = label;
// we first need to add the edge and update the simulation and then add
// all classes iteratively to the label (each time updating the simulation again)
@@ -261,7 +261,7 @@
return label.first();
} else {
ELDescriptionEdge edge = edges.get(0);
- Description child = edge.getTree().transformToDescription();
+ Description child = edge.getNode().transformToDescription();
return new ObjectSomeRestriction(edge.getLabel(),child);
}
// return an intersection of labels and edges
@@ -271,7 +271,7 @@
is.addChild(nc);
}
for(ELDescriptionEdge edge : edges) {
- Description child = edge.getTree().transformToDescription();
+ Description child = edge.getNode().transformToDescription();
ObjectSomeRestriction osr = new ObjectSomeRestriction(edge.getLabel(),child);
is.addChild(osr);
}
@@ -298,11 +298,12 @@
}
// returns the child number of this node, i.e. whether it is
- // the first, second, third etc. child
+ // the first, second, third etc. child;
+ // TODO: might be a bit faster to store this explicitly
private int getChildNumber() {
int count = 0;
for(ELDescriptionEdge edge : parent.edges) {
- if(edge.getTree() == this) {
+ if(edge.getNode() == this) {
return count;
}
}
@@ -472,7 +473,7 @@
String str = indentString + label.toString() + "\n";
for(ELDescriptionEdge edge : edges) {
str += indentString + "-- " + edge.getLabel() + " -->\n";
- str += edge.getTree().toString(indent + 2);
+ str += edge.getNode().toString(indent + 2);
}
return str;
}
@@ -494,7 +495,7 @@
}
for(ELDescriptionEdge edge : edges) {
str += " AND EXISTS " + edge.getLabel().toString() + ".(";
- str += edge.getTree().toDescriptionString() + ")";
+ str += edge.getNode().toDescriptionString() + ")";
}
return str;
}
@@ -557,6 +558,11 @@
public ELDescriptionNode getParent() {
return parent;
}
+
+ public ELDescriptionEdge getParentEdge() {
+ int childNr = getChildNumber();
+ return parent.edges.get(childNr);
+ }
/**
* @return the in
@@ -599,4 +605,8 @@
public Set<ELDescriptionNode> getOutSC2() {
return outSC2;
}
+
+ public ELDescriptionTree getTree() {
+ return tree;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNodeComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNodeComparator.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNodeComparator.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -78,8 +78,8 @@
return compare;
// compare child nodes
- ELDescriptionNode child1 = node1.getEdges().get(i).getTree();
- ELDescriptionNode child2 = node2.getEdges().get(i).getTree();
+ ELDescriptionNode child1 = node1.getEdges().get(i).getNode();
+ ELDescriptionNode child2 = node2.getEdges().get(i).getNode();
int compare2 = compare(child1, child2);
if(compare2 != 0)
return compare2;
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -158,8 +158,8 @@
ObjectProperty op1 = edges.get(j).getLabel();
ObjectProperty op2 = edges.get(k).getLabel();
if(rs.getObjectPropertyHierarchy().isSubpropertyOf(op1, op2)) {
- ELDescriptionNode node1 = edges.get(j).getTree();
- ELDescriptionNode node2 = edges.get(k).getTree();
+ ELDescriptionNode node1 = edges.get(j).getNode();
+ ELDescriptionNode node2 = edges.get(k).getNode();
// check simulation condition
if(node1.in.contains(node2) || node2.in.contains(node1)) {
// node1 is simulated by node2, i.e. we could remove one
@@ -224,7 +224,7 @@
public ELDescriptionNode getNode(int[] position) {
ELDescriptionNode currentNode = rootNode;
for (int i = 0; i < position.length; i++) {
- currentNode = currentNode.getEdges().get(position[i]).getTree();
+ currentNode = currentNode.getEdges().get(position[i]).getNode();
}
return currentNode;
}
@@ -357,7 +357,7 @@
// check whether edges contains an element satisfying SC2
private boolean checkSC2Edge(ELDescriptionEdge superEdge, List<ELDescriptionEdge> edges) {
ObjectProperty superOP = superEdge.getLabel();
- ELDescriptionNode superNode = superEdge.getTree();
+ ELDescriptionNode superNode = superEdge.getNode();
for(ELDescriptionEdge edge : edges) {
// System.out.println("superEdge: " + superEdge);
@@ -367,7 +367,7 @@
// we first check the condition on the properties
if(roleHierarchy.isSubpropertyOf(op, superOP)) {
// check condition on simulations of referred nodes
- ELDescriptionNode node = edge.getTree();
+ ELDescriptionNode node = edge.getNode();
// if(superNode.in.contains(node) || node.in.contains(superNode)) {
if(node.in.contains(superNode)) {
// we found a node satisfying the condition, so we can return
@@ -506,7 +506,7 @@
// edges
for(ELDescriptionEdge edge : oldNode.edges) {
// create a new edge with same label and replace the node the edge points to
- newNode.edges.add(new ELDescriptionEdge(edge.getLabel(), cloneMap.get(edge.getTree())));
+ newNode.edges.add(new ELDescriptionEdge(edge.getLabel(), cloneMap.get(edge.getNode())));
}
}
@@ -514,6 +514,7 @@
// update global tree
treeClone.rootNode = newRoot;
treeClone.maxLevel = maxLevel;
+ treeClone.nodes = new HashSet<ELDescriptionNode>(nodes);
for(int i=1; i<=maxLevel; i++) {
Set<ELDescriptionNode> oldNodes = levelNodeMapping.get(i);
Set<ELDescriptionNode> newNodes = new HashSet<ELDescriptionNode>();
@@ -541,8 +542,8 @@
// loop through all edges and clone the subtrees
for (ELDescriptionEdge edge : node.getEdges()) {
ELDescriptionNode tmp = new ELDescriptionNode(nodeClone, edge.getLabel(),
- new TreeSet<NamedClass>(edge.getTree().getLabel()));
- cloneRecursively(edge.getTree(), tmp);
+ new TreeSet<NamedClass>(edge.getNode().getLabel()));
+ cloneRecursively(edge.getNode(), tmp);
}
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -39,6 +39,7 @@
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.refinementoperators.ELDown;
+import org.dllearner.refinementoperators.ELDown2;
import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
/**
@@ -55,7 +56,7 @@
private static Logger logger = Logger.getLogger(ELLearningAlgorithm.class);
private ELLearningAlgorithmConfigurator configurator;
- private ELDown operator;
+ private ELDown2 operator;
private boolean isRunning = false;
private boolean stop = false;
@@ -97,7 +98,7 @@
heuristic = new StableHeuristic();
candidates = new TreeSet<SearchTreeNode>(heuristic);
- operator = new ELDown(reasoner);
+ operator = new ELDown2(reasoner);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/core/SchemaReasoner.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -101,7 +101,7 @@
public ClassHierarchy getClassHierarchy();
/**
- * Returns more general concepts in the subsumption hierarchy.
+ * Returns direct super classes in the class hierarchy.
*
* @param description
* Atomic concept, top, or bottom.
@@ -110,7 +110,7 @@
public SortedSet<Description> getSuperClasses(Description description);
/**
- * Returns more special concepts in the subsumption hierarchy.
+ * Returns direct sub classes in the class hierarchy.
*
* @param description
* Atomic concept, top, or bottom.
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -220,7 +220,7 @@
// recursive call on child node and property range as index
Description range = rs.getRange(edge.getLabel());
// System.out.println(tree + "\nrecurse to:\n" + edge.getTree());
- refinements.addAll(refine(tree, edge.getTree(), range, minimize));
+ refinements.addAll(refine(tree, edge.getNode(), range, minimize));
}
// we found out that, in case we start from the TOP concept
@@ -255,7 +255,7 @@
// with the existing child node (we do not perform a full disjointness
// check, but only compare with the flattened concept to keep the number
// of possible disjointness checks finite)
- if(!utility.isDisjoint(getFlattenedConcept(edge.getTree()), opRanges.get(op2))) {
+ if(!utility.isDisjoint(getFlattenedConcept(edge.getNode()), opRanges.get(op2))) {
// clone operation
ELDescriptionTree clonedTree = tree.clone();
// find cloned edge and replace its label
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-16 10:16:51 UTC (rev 1555)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-16 16:24:53 UTC (rev 1556)
@@ -20,6 +20,7 @@
package org.dllearner.refinementoperators;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -51,7 +52,7 @@
*
* <p>Properties:
* <ul>
- * <li>complete</li>
+ * <li>weakly complete (can be extended to guarantee completeness if desired)</li>
* <li>proper</li>
* <li>finite</li>
* <li>uses class/property hierarchy</li>
@@ -130,55 +131,56 @@
// the transformations can, of course, add new nodes)
Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>(tree.getNodes());
for(ELDescriptionNode v : nodes) {
+ // the position of the node within the tree (needed for getting
+ // the corresponding node in a cloned tree)
+ int[] position = v.getCurrentPosition();
+
// perform operations
- refinements.addAll(extendLabel(tree, v));
- refinements.addAll(refineLabel(tree, v));
- refinements.addAll(refineEdge(tree, v));
- refinements.addAll(attachSubtree(tree, v));
+ refinements.addAll(extendLabel(tree, v, position));
+ refinements.addAll(refineLabel(tree, v, position));
+ refinements.addAll(refineEdge(tree, v, position));
+ refinements.addAll(attachSubtree(tree, v, position));
}
// return refine(tree, tree.getRootNode(), new Thing(), true);
return refinements;
}
-
- private Set<ELDescriptionTree> extendLabel(ELDescriptionTree tree, ELDescriptionNode v) {
- return null;
- }
-
- private Set<ELDescriptionTree> refineLabel(ELDescriptionTree tree, ELDescriptionNode v) {
- return null;
- }
-
- private Set<ELDescriptionTree> refineEdge(ELDescriptionTree tree, ELDescriptionNode v) {
- return null;
- }
-
- private Set<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v) {
- return null;
- }
-
- private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index, boolean minimize) {
- // the set of all refinements, which we will return
+
+ // operation 1: label extension
+ private Set<ELDescriptionTree> extendLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
- // the position of the node within the tree (needed for getting
- // the corresponding node in a cloned tree)
- int[] position = node.getCurrentPosition();
+
+ // the index is the range of role in the edge pointing to the parent of this node
+ Description index;
+ if(v.isRoot()) {
+ index = Thing.instance;
+ } else {
+ index = opRanges.get(v.getParentEdge().getLabel());
+ }
- // option 1: label extension
- Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel());
+ // call ncc (see paper)
+ Set<NamedClass> candidates = utility.getClassCandidates(index, v.getLabel());
+
for(NamedClass nc : candidates) {
// clone operation
ELDescriptionTree clonedTree = tree.clone();
ELDescriptionNode clonedNode = clonedTree.getNode(position);
// extend label
clonedNode.extendLabel(nc);
- refinements.add(clonedTree);
+ if(clonedTree.isMinimal()) {
+ refinements.add(clonedTree);
+ }
}
+
+ return refinements;
+ }
+
+ // operation 2: label refinement
+ private Set<ELDescriptionTree> refineLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
-
- // option 2: label refinement
// loop through all classes in label
- for(NamedClass nc : node.getLabel()) {
+ for(NamedClass nc : v.getLabel()) {
// find all more special classes for the given label
for(Description moreSpecial : rs.getSubClasses(nc)) {
if(moreSpecial instanceof NamedClass) {
@@ -186,117 +188,187 @@
ELDescriptionTree clonedTree = tree.clone();
ELDescriptionNode clonedNode = clonedTree.getNode(position);
-// System.out.println("tree: " + tree);
-// System.out.println("cloned tree: " + clonedTree);
-// System.out.println("node: " + node);
-// System.out.println("cloned unmodified: " + clonedNode);
-
// create refinements by replacing class
clonedNode.replaceInLabel(nc, (NamedClass) moreSpecial);
-// System.out.println("cloned modified: " + clonedNode);
- refinements.add(clonedTree);
+ if(clonedTree.isMinimal()) {
+ refinements.add(clonedTree);
+ }
}
}
}
+
+ return refinements;
+ }
+
+ // operation 3: refine edge
+ private Set<ELDescriptionTree> refineEdge(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+
+ for(int edgeNumber = 0; edgeNumber < v.getEdges().size(); edgeNumber++) {
+ ELDescriptionEdge edge = v.getEdges().get(edgeNumber);
+ ObjectProperty op = edge.getLabel();
+ // find all more special properties
+ for(ObjectProperty op2 : rs.getSubProperties(op)) {
+ // we check whether the range of this property is not disjoint
+ // with the existing child node (we do not perform a full disjointness
+ // check, but only compare with the flattened concept to keep the number
+ // of possible disjointness checks finite)
+ if(!utility.isDisjoint(getFlattenedConcept(edge.getNode()), opRanges.get(op2))) {
+ // clone operation
+ ELDescriptionTree clonedTree = tree.clone();
+ // find cloned edge and replace its label
+ clonedTree.getNode(position).refineEdge(edgeNumber, op2);
+// ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
+// clonedEdge.setLabel(op2);
+ if(clonedTree.isMinimal()) {
+ refinements.add(clonedTree);
+ }
+ }
+ }
+ }
- // option 3: new edge
+ return refinements;
+ }
+
+ // operation 4: attach tree
+ private Set<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
+
+ // compute the set of most general roles such that the domain of each role is not disjoint
+ // with the range of the role pointing to this node
+ Description index;
+ if(v.isRoot()) {
+ index = Thing.instance;
+ } else {
+ index = opRanges.get(v.getParentEdge().getLabel());
+ }
SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
Set<ObjectProperty> mgr = utility.computeMgr(appOPs);
- // temporary set of all concepts, which still have to pass the equivalence check
- Stack<ELDescriptionTree> stack = new Stack<ELDescriptionTree>();
+
+ // TODO: in as ist ein baum t nicht definiert; ersetzen durch t_{C'}
+ // TODO: Einrückung in as nach pick element nicht notwendig
+
+ // loop through most general roles
for(ObjectProperty op : mgr) {
- // clone operation
- ELDescriptionTree clonedTree = tree.clone();
- ELDescriptionNode clonedNode = clonedTree.getNode(position);
- // add a new node and edge
- ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>());
- stack.add(clonedTree);
- // recurse if concept is equivalent
- while(stack.size() != 0) {
- // we pick an arbitrary tree and remove it from the stack
- ELDescriptionTree testTree = stack.pop();
- // test equivalence (we found out that we can use the
- // minimality test for equivalence in this case)
- boolean equivalent = !testTree.isMinimal();
- // if the tree is equivalent, we need to populate the
- // stack with refinements (which are later tested for
- // equivalence)
- if(equivalent) {
- // edge refinement
- // we know that the edge we added is the last one for this node
- int edgeNr = node.getEdges().size() - 1;
- ELDescriptionEdge edge = node.getEdges().get(edgeNr);
- // all refinements of this edge are added to the stack
- // (set 1 in article)
- refineEdge(stack, tree, node, position, edgeNr);
- // perform node refinements in non-minimize-mode
- // (set 2 in article)
-// commented out, because didn't make sense to me
-// refinements.addAll(refineEdges(tree, newNode, position));
- stack.addAll(refine(tree, newNode, opRanges.get(edge), false));
- } else {
- // tree is not equivalent, i.e. a proper refinement
- refinements.add(testTree);
- }
- }
+ // a list of subtrees (stored as edges i.e. role + root node which points to tree)
+ // TODO: Do we need to store m at all?
+ LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>();
+
+ // create tree corresponding to top node
+ ELDescriptionTree topTree = new ELDescriptionTree(rs, Thing.instance);
+
+ // init list with picked role and top node i.e. its root
+ m.add(new ELDescriptionEdge(op, topTree.getRootNode()));
+
+ // iterate until m is empty
+ while(!m.isEmpty()) {
+ // pick and remove first element
+ ELDescriptionEdge edge = m.pollFirst();
+ ObjectProperty r = edge.getLabel();
+ // tp = t' in algorithm description (p stands for prime)
+ ELDescriptionTree tp = edge.getNode().getTree();
+
+ // merge tree into main tree
+ ELDescriptionTree mergedTree = mergeTrees(tree, v, position, r, tp);
+
+ // we check equivalence by a minimality test (TODO: can we still do this?)
+ if(mergedTree.isMinimal()) {
+ // it is not equivalent, i.e. we found a refinement
+ refinements.add(mergedTree);
+ } else {
+ // perform complex check
+ boolean check = asCheck(v);
+
+ if(check) {
+ // refine property
+ for(ObjectProperty subRole : rs.getSubProperties(r)) {
+ m.add(new ELDescriptionEdge(subRole, tp.getRootNode()));
+ }
+ // refine tree using recursive operator call
+ Set<ELDescriptionTree> recRefs = refine(tp);
+ for(ELDescriptionTree tpp : recRefs) {
+ m.add(new ELDescriptionEdge(r, tpp.getRootNode()));
+ }
+ }
+ }
+ }
}
+
+ return refinements;
+ }
+
+ // create a new tree which is obtained by attaching the new tree at the given node in the tree via role r
+ private ELDescriptionTree mergeTrees(ELDescriptionTree tree, ELDescriptionNode node, int[] position, ObjectProperty r, ELDescriptionTree newTree) {
+ // merged tree = tree + new node with role pointing to a new node
+ ELDescriptionTree mergedTree = tree.clone();
+ ELDescriptionNode clonedNode = mergedTree.getNode(position);
+// ELDescriptionNode nodeNew = new ELDescriptionNode(clonedNode, r);
- // option 4: edge refinement
- refinements.addAll(refineEdges(tree, node, position));
+ // create a list of nodes we still need to process
+ LinkedList<ELDescriptionNode> toProcess = new LinkedList<ELDescriptionNode>();
+ toProcess.add(newTree.getRootNode());
- // option 5: child refinement
- for(ELDescriptionEdge edge : node.getEdges()) {
- // recursive call on child node and property range as index
- Description range = rs.getRange(edge.getLabel());
-// System.out.println(tree + "\nrecurse to:\n" + edge.getTree());
- refinements.addAll(refine(tree, edge.getTree(), range, minimize));
- }
+ // map from nodes to cloned nodes
+ Map<ELDescriptionNode,ELDescriptionNode> cloneMap = new HashMap<ELDescriptionNode,ELDescriptionNode>();
+// cloneMap.put(newTree.getRootNode(), nodeNew);
- // we found out that, in case we start from the TOP concept
- // (which is assumed in the current implementation), we can
- // simply throw away all non-minimal concepts
- if(minimize) {
- Iterator<ELDescriptionTree> it = refinements.iterator();
- while(it.hasNext()) {
- if(!it.next().isMinimal()) {
- it.remove();
- }
+ // loop until the process list is empty
+ while(!toProcess.isEmpty()) {
+ // process a node
+ ELDescriptionNode v = toProcess.pollFirst();
+ // find parent
+ ELDescriptionNode vp;
+ if(v.isRoot()) {
+ // root is connected to main tree via role r
+ vp = new ELDescriptionNode(clonedNode, r);
+ } else {
+ ELDescriptionNode parent = cloneMap.get(v.getParent());
+ ObjectProperty role = v.getParentEdge().getLabel();
+ Set<NamedClass> label = v.getLabel();
+ // create new node
+ vp = new ELDescriptionNode(parent, role, label);
}
+ cloneMap.put(v, vp);
+ // attach children of node to process list
+ for(ELDescriptionEdge edge : v.getEdges()) {
+ toProcess.add(edge.getNode());
+ }
}
- return refinements;
+ return mergedTree;
}
-
- private Set<ELDescriptionTree> refineEdges(ELDescriptionTree tree, ELDescriptionNode node, int[] position) {
- Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
- for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) {
- refineEdge(refinements, tree, node, position, edgeNumber);
+
+ private boolean asCheck(ELDescriptionNode v) {
+ // find all edges up to the root node
+ List<ELDescriptionEdge> piVEdges = new LinkedList<ELDescriptionEdge>();
+ ELDescriptionNode tmp = v;
+ while(!tmp.isRoot()) {
+ piVEdges.add(tmp.getParentEdge());
+ tmp = tmp.getParent();
}
- return refinements;
- }
-
- private void refineEdge(Collection<ELDescriptionTree> refinements, ELDescriptionTree tree, ELDescriptionNode node, int[] position, int edgeNumber) {
- ELDescriptionEdge edge = node.getEdges().get(edgeNumber);
- ObjectProperty op = edge.getLabel();
- // find all more special properties
- for(ObjectProperty op2 : rs.getSubProperties(op)) {
- // we check whether the range of this property is not disjoint
- // with the existing child node (we do not perform a full disjointness
- // check, but only compare with the flattened concept to keep the number
- // of possible disjointness checks finite)
- if(!utility.isDisjoint(getFlattenedConcept(edge.getTree()), opRanges.get(op2))) {
- // clone operation
- ELDescriptionTree clonedTree = tree.clone();
- // find cloned edge and replace its label
- clonedTree.getNode(position).refineEdge(edgeNumber, op2);
-// ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber);
-// clonedEdge.setLabel(op2);
- refinements.add(clonedTree);
+
+ // go through all edges
+ for(ELDescriptionEdge piVEdge : piVEdges) {
+ // collect (w,s,w')
+ ELDescriptionNode wp = piVEdge.getNode();
+ ObjectProperty s = piVEdge.getLabel();
+ ELDescriptionNode w = wp.getParent();
+
+ // go through all (w,s,w'') - TODO: s or a new s' ?
+ for(ELDescriptionEdge wEdge : w.getEdges()) {
+ ObjectProperty sp = wEdge.getLabel();
+ ELDescriptionNode wpp = wEdge.getNode();
+ if(s.equals(sp) && wp != wpp) {
+ if(wp.getIn().contains(wpp)) {
+ return false;
+ }
+ }
}
-
}
+
+ return true;
}
// simplifies a potentially nested tree in a flat conjunction by taking
@@ -304,6 +376,7 @@
// C = Professor \sqcap \exists hasChild.Student
// the result would be Professor \sqcap Human (assuming Human is the domain
// of hasChild)
+ // TODO: used in both EL operators => move to utility class
private Description getFlattenedConcept(ELDescriptionNode node) {
Intersection i = new Intersection();
@@ -323,16 +396,6 @@
}
return i;
- }
+ }
-// private void computeMg(Description index) {
-// // compute the applicable properties if this has not been done yet
-// if(app.get(index) == null)
-// app.put(index, utility.computeApplicableObjectProperties(index));
-//
-// mgr.put(index, new TreeSet<ObjectProperty>());
-//
-//
-// }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-17 15:20:34
|
Revision: 1558
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1558&view=rev
Author: jenslehmann
Date: 2008-12-17 15:20:27 +0000 (Wed, 17 Dec 2008)
Log Message:
-----------
fixed some EL refinement operator bugs
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.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/ELDescriptionTreeTests.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -91,6 +91,11 @@
this(tree, new TreeSet<NamedClass>());
}
+ // convenience constructor
+ public ELDescriptionNode(ELDescriptionTree tree, NamedClass... label) {
+ this(tree, new TreeSet<NamedClass>(Arrays.asList(label)));
+ }
+
/**
* Constructs an EL description tree given its root label.
* @param label Label of the root node.
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -161,7 +161,7 @@
ELDescriptionNode node1 = edges.get(j).getNode();
ELDescriptionNode node2 = edges.get(k).getNode();
// check simulation condition
- if(node1.in.contains(node2) || node2.in.contains(node1)) {
+ if(node1.in.contains(node2)) { // || node2.in.contains(node1)) {
// node1 is simulated by node2, i.e. we could remove one
// of them, so the tree is not minimal
return false;
@@ -433,6 +433,14 @@
node2.out.remove(node1);
}
+ public String toSimulationString() {
+ String str = "";
+ for(ELDescriptionNode node : nodes) {
+ str += node.toSimulationString() + "\n";
+ }
+ return str;
+ }
+
public String toSimulationString(Map<ELDescriptionNode,String> nodeNames) {
String str = "";
for(Entry<ELDescriptionNode,String> entry : nodeNames.entrySet()) {
@@ -514,7 +522,14 @@
// update global tree
treeClone.rootNode = newRoot;
treeClone.maxLevel = maxLevel;
- treeClone.nodes = new HashSet<ELDescriptionNode>(nodes);
+
+ // nodes
+ treeClone.nodes = new HashSet<ELDescriptionNode>();
+ for(ELDescriptionNode oldNode : nodes) {
+ treeClone.nodes.add(cloneMap.get(oldNode));
+ }
+
+ // level node mapping
for(int i=1; i<=maxLevel; i++) {
Set<ELDescriptionNode> oldNodes = levelNodeMapping.get(i);
Set<ELDescriptionNode> newNodes = new HashSet<ELDescriptionNode>();
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -38,7 +38,6 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.PosNegLP;
-import org.dllearner.refinementoperators.ELDown;
import org.dllearner.refinementoperators.ELDown2;
import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
Modified: trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -29,10 +29,8 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
import org.dllearner.core.owl.Negation;
-import org.dllearner.reasoning.FastInstanceChecker;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.datastructures.SetManipulation;
-import org.dllearner.utilities.owl.ConceptTransformation;
/**
* The aim of this learning problem is to find an appropriate inclusion axiom
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -107,6 +107,7 @@
*/
@Override
public Set<Description> refine(Description concept) {
+ System.out.println("refining " + concept);
ELDescriptionTree tree = new ELDescriptionTree(rs, concept);
Set<ELDescriptionTree> refinementTrees = refine(tree);
Set<Description> refinements = new HashSet<Description>();
@@ -125,20 +126,24 @@
* @return Set of refined EL description trees.
*/
public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
+ System.out.println("applying \\rho on " + tree.toDescriptionString());
+
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// loop over all nodes of the tree and perform one of the
// transformations on it (we make a copy of all nodes, because
// the transformations can, of course, add new nodes)
Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>(tree.getNodes());
for(ELDescriptionNode v : nodes) {
+ System.out.println("picked node v: " + v);
+
// the position of the node within the tree (needed for getting
// the corresponding node in a cloned tree)
int[] position = v.getCurrentPosition();
// perform operations
refinements.addAll(extendLabel(tree, v, position));
- refinements.addAll(refineLabel(tree, v, position));
- refinements.addAll(refineEdge(tree, v, position));
+// refinements.addAll(refineLabel(tree, v, position));
+// refinements.addAll(refineEdge(tree, v, position));
refinements.addAll(attachSubtree(tree, v, position));
}
@@ -160,8 +165,10 @@
// call ncc (see paper)
Set<NamedClass> candidates = utility.getClassCandidates(index, v.getLabel());
+// System.out.println("label: " + v.getLabel());
for(NamedClass nc : candidates) {
+// System.out.println("candidate: " + nc);
// clone operation
ELDescriptionTree clonedTree = tree.clone();
ELDescriptionNode clonedNode = clonedTree.getNode(position);
@@ -246,14 +253,11 @@
SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
Set<ObjectProperty> mgr = utility.computeMgr(appOPs);
- // TODO: in as ist ein baum t nicht definiert; ersetzen durch t_{C'}
- // TODO: Einrückung in as nach pick element nicht notwendig
-
// loop through most general roles
for(ObjectProperty op : mgr) {
+ System.out.println("pick most general role: " + op);
// a list of subtrees (stored as edges i.e. role + root node which points to tree)
- // TODO: Do we need to store m at all?
LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>();
// create tree corresponding to top node
@@ -266,20 +270,29 @@
while(!m.isEmpty()) {
// pick and remove first element
ELDescriptionEdge edge = m.pollFirst();
+ System.out.println("picked first element of M: " + edge);
ObjectProperty r = edge.getLabel();
// tp = t' in algorithm description (p stands for prime)
ELDescriptionTree tp = edge.getNode().getTree();
// merge tree into main tree
ELDescriptionTree mergedTree = mergeTrees(tree, v, position, r, tp);
+ ELDescriptionNode vClone = mergedTree.getNode(position);
+ System.out.println("merged to t_{C'}: \n" + mergedTree);
+
+// System.out.println(mergedTree.toSimulationString());
+
// we check equivalence by a minimality test (TODO: can we still do this?)
if(mergedTree.isMinimal()) {
+ System.out.println("Merged tree is minimal, i.e. not equivalent.");
// it is not equivalent, i.e. we found a refinement
refinements.add(mergedTree);
} else {
- // perform complex check
- boolean check = asCheck(v);
+ System.out.println("Merged tree is not minimal, i.e. equivalent.");
+ // perform complex check in merged tree
+ boolean check = asCheck(vClone);
+ System.out.println("Result of complex check: " + check);
if(check) {
// refine property
@@ -287,12 +300,17 @@
m.add(new ELDescriptionEdge(subRole, tp.getRootNode()));
}
// refine tree using recursive operator call
+ System.out.println("Recursive Call");
Set<ELDescriptionTree> recRefs = refine(tp);
+ System.out.println("Recursive Call Done");
for(ELDescriptionTree tpp : recRefs) {
+// System.out.println("aa " + tpp.toDescriptionString());
m.add(new ELDescriptionEdge(r, tpp.getRootNode()));
}
}
- }
+ }
+
+ System.out.println("M: " + m);
}
}
@@ -301,11 +319,17 @@
// create a new tree which is obtained by attaching the new tree at the given node in the tree via role r
private ELDescriptionTree mergeTrees(ELDescriptionTree tree, ELDescriptionNode node, int[] position, ObjectProperty r, ELDescriptionTree newTree) {
+// System.out.println("merge start");
+// System.out.println(tree);
+// System.out.println(newTree);
// merged tree = tree + new node with role pointing to a new node
ELDescriptionTree mergedTree = tree.clone();
ELDescriptionNode clonedNode = mergedTree.getNode(position);
// ELDescriptionNode nodeNew = new ELDescriptionNode(clonedNode, r);
+// System.out.println("node: " + node);
+// System.out.println("cloned node: " + clonedNode);
+
// create a list of nodes we still need to process
LinkedList<ELDescriptionNode> toProcess = new LinkedList<ELDescriptionNode>();
toProcess.add(newTree.getRootNode());
@@ -322,7 +346,7 @@
ELDescriptionNode vp;
if(v.isRoot()) {
// root is connected to main tree via role r
- vp = new ELDescriptionNode(clonedNode, r);
+ vp = new ELDescriptionNode(clonedNode, r, newTree.getRootNode().getLabel());
} else {
ELDescriptionNode parent = cloneMap.get(v.getParent());
ObjectProperty role = v.getParentEdge().getLabel();
@@ -337,6 +361,8 @@
}
}
+// System.out.println(mergedTree);
+// System.out.println("merge end");
return mergedTree;
}
@@ -351,16 +377,16 @@
// go through all edges
for(ELDescriptionEdge piVEdge : piVEdges) {
- // collect (w,s,w')
+ // collect (w,r',w')
ELDescriptionNode wp = piVEdge.getNode();
- ObjectProperty s = piVEdge.getLabel();
+ ObjectProperty rp = piVEdge.getLabel();
ELDescriptionNode w = wp.getParent();
// go through all (w,s,w'') - TODO: s or a new s' ?
for(ELDescriptionEdge wEdge : w.getEdges()) {
- ObjectProperty sp = wEdge.getLabel();
+ ObjectProperty rpp = wEdge.getLabel();
ELDescriptionNode wpp = wEdge.getNode();
- if(s.equals(sp) && wp != wpp) {
+ if(wp != wpp && opHierarchy.isSubpropertyOf(rp, rpp)) {
if(wp.getIn().contains(wpp)) {
return false;
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -123,11 +123,11 @@
// not satisfied
// check1: disjointness with index
// check3: no superclass exists already
- if(!isDisjoint(candidate,index) || !checkSubClasses(existingClasses,candidate)) {
+ if(!isDisjoint(candidate,index) && checkSubClasses(existingClasses,candidate)) {
// check whether the class is meaningful, i.e. adds something to the index
// to do this, we need to make sure that the class is not a superclass of the
// index (otherwise we get nothing new)
- if(!isDisjoint(new Negation(candidate),index) || !checkSuperClasses(existingClasses,candidate)) {
+ if(!isDisjoint(new Negation(candidate),index) && checkSuperClasses(existingClasses,candidate)) {
// candidate went successfully through all checks
candidates.add(candidate);
} else {
@@ -140,17 +140,19 @@
return candidates;
}
- // returns true of the candidate is not subclass of an existing class,
+ // returns true if the candidate is not subclass of an existing class,
// false otherwise (check 3)
private boolean checkSubClasses(Set<NamedClass> existingClasses, NamedClass candidate) {
for(NamedClass nc : existingClasses) {
- if(sh.isSubclassOf(candidate, nc))
+// System.out.println("csc: " + nc + candidate);
+ if(sh.isSubclassOf(candidate, nc)) {
return false;
+ }
}
return true;
}
- // returns true of the candidate is not superclass of an existing class,
+ // returns true if the candidate is not superclass of an existing class,
// false otherwise (check 4)
private boolean checkSuperClasses(Set<NamedClass> existingClasses, NamedClass candidate) {
for(NamedClass nc : existingClasses) {
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDescriptionTreeTests.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -85,7 +85,7 @@
ConceptTransformation.cleanConcept(d);
ELDescriptionTree tree = new ELDescriptionTree(rs, d);
// clone performance (false for simple unit test, true for clone performance test)
- boolean testPerformance = false;
+ boolean testPerformance = true;
ELDescriptionTree treeCloned = null;
if(testPerformance) {
int runs = 1000000;
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -28,7 +28,7 @@
import org.dllearner.core.owl.Description;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
-import org.dllearner.refinementoperators.ELDown;
+import org.dllearner.refinementoperators.ELDown2;
import org.dllearner.test.junit.TestOntologies.TestOntology;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
@@ -61,7 +61,7 @@
// TODO For this test, we need to turn instance based disjoints
// off! (We do not have any instances here.)
- ELDown operator = new ELDown(rs);
+ ELDown2 operator = new ELDown2(rs);
// desired refinements as strings
Set<String> desiredString = new TreeSet<String>();
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-17 15:05:28 UTC (rev 1557)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2008-12-17 15:20:27 UTC (rev 1558)
@@ -32,6 +32,7 @@
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.Thing;
import org.dllearner.parser.KBParser;
import org.dllearner.test.junit.TestOntologies.TestOntology;
import org.junit.Test;
@@ -662,6 +663,25 @@
}
+ @Test
+ public void test7() {
+ ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
+ ELDescriptionTree tree = new ELDescriptionTree(rs);
+
+ ObjectProperty has = new ObjectProperty(uri("has"));
+ ObjectProperty hasChild = new ObjectProperty(uri("hasChild"));
+ NamedClass human = new NamedClass(uri("human"));
+ NamedClass animal = new NamedClass(uri("animal"));
+
+ ELDescriptionNode v1 = new ELDescriptionNode(tree, human);
+ new ELDescriptionNode(v1, has, animal);
+ new ELDescriptionNode(v1, hasChild);
+
+// System.out.println(tree.toSimulationString());
+
+ assertTrue(tree.isMinimal());
+ }
+
// display a simulation as debug log
@SuppressWarnings("unused")
private void log(String message, ELDescriptionTree tree, Map<ELDescriptionNode,String> nodeNames) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-19 16:04:57
|
Revision: 1559
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1559&view=rev
Author: jenslehmann
Date: 2008-12-19 16:04:45 +0000 (Fri, 19 Dec 2008)
Log Message:
-----------
continued EL refinement operator - it now passes unit test 1 !
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.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/owl/ConceptTransformation.java
trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -188,7 +188,7 @@
Description conceptModForCache = ConceptTransformation.applyEquivalenceRules(conceptMod);
- ConceptTransformation.transformToOrderedNegationNormalForm(conceptModForCache, conceptComparator);
+ ConceptTransformation.transformToOrderedForm(conceptModForCache, conceptComparator);
Score score = program.getScore();
// Eval-Cache füllen
@@ -207,7 +207,7 @@
/////////// TESTCODE: umwandeln des erhaltenen Konzepts
// someTimeStart = System.nanoTime();
Description newConceptMod = ConceptTransformation.applyEquivalenceRules(newConcept);
- ConceptTransformation.transformToOrderedNegationNormalForm(newConceptMod, conceptComparator);
+ ConceptTransformation.transformToOrderedForm(newConceptMod, conceptComparator);
// someTime += System.nanoTime() - someTimeStart;
///////////
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -107,7 +107,7 @@
*/
@Override
public Set<Description> refine(Description concept) {
- System.out.println("refining " + concept);
+ logger.trace("refining " + concept);
ELDescriptionTree tree = new ELDescriptionTree(rs, concept);
Set<ELDescriptionTree> refinementTrees = refine(tree);
Set<Description> refinements = new HashSet<Description>();
@@ -126,7 +126,7 @@
* @return Set of refined EL description trees.
*/
public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
- System.out.println("applying \\rho on " + tree.toDescriptionString());
+ logger.trace("applying \\rho on " + tree.toDescriptionString());
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// loop over all nodes of the tree and perform one of the
@@ -134,7 +134,7 @@
// the transformations can, of course, add new nodes)
Set<ELDescriptionNode> nodes = new HashSet<ELDescriptionNode>(tree.getNodes());
for(ELDescriptionNode v : nodes) {
- System.out.println("picked node v: " + v);
+ logger.trace("picked node v: " + v);
// the position of the node within the tree (needed for getting
// the corresponding node in a cloned tree)
@@ -142,8 +142,8 @@
// perform operations
refinements.addAll(extendLabel(tree, v, position));
-// refinements.addAll(refineLabel(tree, v, position));
-// refinements.addAll(refineEdge(tree, v, position));
+ refinements.addAll(refineLabel(tree, v, position));
+ refinements.addAll(refineEdge(tree, v, position));
refinements.addAll(attachSubtree(tree, v, position));
}
@@ -255,7 +255,7 @@
// loop through most general roles
for(ObjectProperty op : mgr) {
- System.out.println("pick most general role: " + op);
+ logger.trace("pick most general role: " + op);
// a list of subtrees (stored as edges i.e. role + root node which points to tree)
LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>();
@@ -270,29 +270,35 @@
while(!m.isEmpty()) {
// pick and remove first element
ELDescriptionEdge edge = m.pollFirst();
- System.out.println("picked first element of M: " + edge);
+ logger.trace("picked first element of M: " + edge);
ObjectProperty r = edge.getLabel();
// tp = t' in algorithm description (p stands for prime)
ELDescriptionTree tp = edge.getNode().getTree();
// merge tree into main tree
ELDescriptionTree mergedTree = mergeTrees(tree, v, position, r, tp);
- ELDescriptionNode vClone = mergedTree.getNode(position);
- System.out.println("merged to t_{C'}: \n" + mergedTree);
+ // the position of w is the position of v + #edges outgoing from v
+ int[] wPosition = new int[position.length+1];
+ System.arraycopy(position, 0, wPosition, 0, position.length);
+ wPosition[position.length] = v.getEdges().size();
+ ELDescriptionNode wClone = mergedTree.getNode(wPosition);
+
+ logger.trace("merged to t_{C'}: \n" + mergedTree);
+
// System.out.println(mergedTree.toSimulationString());
// we check equivalence by a minimality test (TODO: can we still do this?)
if(mergedTree.isMinimal()) {
- System.out.println("Merged tree is minimal, i.e. not equivalent.");
+ logger.trace("Merged tree is minimal, i.e. not equivalent.");
// it is not equivalent, i.e. we found a refinement
refinements.add(mergedTree);
} else {
- System.out.println("Merged tree is not minimal, i.e. equivalent.");
+ logger.trace("Merged tree is not minimal, i.e. equivalent.");
// perform complex check in merged tree
- boolean check = asCheck(vClone);
- System.out.println("Result of complex check: " + check);
+ boolean check = asCheck(wClone);
+ logger.trace("Result of complex check: " + check);
if(check) {
// refine property
@@ -300,9 +306,9 @@
m.add(new ELDescriptionEdge(subRole, tp.getRootNode()));
}
// refine tree using recursive operator call
- System.out.println("Recursive Call");
+ logger.trace("Recursive Call");
Set<ELDescriptionTree> recRefs = refine(tp);
- System.out.println("Recursive Call Done");
+ logger.trace("Recursive Call Done");
for(ELDescriptionTree tpp : recRefs) {
// System.out.println("aa " + tpp.toDescriptionString());
m.add(new ELDescriptionEdge(r, tpp.getRootNode()));
@@ -310,7 +316,7 @@
}
}
- System.out.println("M: " + m);
+ logger.trace("M: " + m);
}
}
@@ -366,15 +372,21 @@
return mergedTree;
}
+ // TODO: variables have been renamed in article
private boolean asCheck(ELDescriptionNode v) {
+// System.out.println("asCheck: " + v.getTree().toSimulationString());
+
// find all edges up to the root node
List<ELDescriptionEdge> piVEdges = new LinkedList<ELDescriptionEdge>();
ELDescriptionNode tmp = v;
while(!tmp.isRoot()) {
+// System.out.println("blub");
piVEdges.add(tmp.getParentEdge());
tmp = tmp.getParent();
}
+// System.out.println(piVEdges);
+
// go through all edges
for(ELDescriptionEdge piVEdge : piVEdges) {
// collect (w,r',w')
@@ -382,12 +394,18 @@
ObjectProperty rp = piVEdge.getLabel();
ELDescriptionNode w = wp.getParent();
- // go through all (w,s,w'') - TODO: s or a new s' ?
+// System.out.println(w);
+// System.out.println(rp);
+// System.out.println(wp);
+
+ // go through all (w,s,w'')
for(ELDescriptionEdge wEdge : w.getEdges()) {
ObjectProperty rpp = wEdge.getLabel();
ELDescriptionNode wpp = wEdge.getNode();
if(wp != wpp && opHierarchy.isSubpropertyOf(rp, rpp)) {
- if(wp.getIn().contains(wpp)) {
+// System.out.println("wp: " + wp);
+// System.out.println("wpp: " + wpp);
+ if(wp.getOut().contains(wpp)) {
return false;
}
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -779,7 +779,7 @@
// convert all concepts in ordered negation normal form
for(Description concept : baseSet) {
- ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator);
+ ConceptTransformation.transformToOrderedForm(concept, conceptComparator);
}
// apply the exists filter (throwing out all refinements with
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDown.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -460,7 +460,7 @@
// Umwandlung aller Konzepte in Negationsnormalform
for(Description concept : baseSet) {
- ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator);
+ ConceptTransformation.transformToOrderedForm(concept, conceptComparator);
}
if(applyExistsFilter) {
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -123,7 +123,8 @@
// not satisfied
// check1: disjointness with index
// check3: no superclass exists already
- if(!isDisjoint(candidate,index) && checkSubClasses(existingClasses,candidate)) {
+ // check5: disjointness
+ if(!isDisjoint(candidate,index) && checkSubClasses(existingClasses,candidate) && checkDisjoints(existingClasses,candidate)) {
// check whether the class is meaningful, i.e. adds something to the index
// to do this, we need to make sure that the class is not a superclass of the
// index (otherwise we get nothing new)
@@ -162,6 +163,16 @@
return true;
}
+ // returns false if any of the classes is disjoint with the new one; true otherwise
+ private boolean checkDisjoints(Set<NamedClass> existingClasses, NamedClass candidate) {
+ for(NamedClass nc : existingClasses) {
+ if(isDisjoint(nc, candidate))
+ return false;
+ }
+ return true;
+ }
+
+
public boolean isDisjoint(Description d1, Description d2) {
// System.out.println("d1: " + d1);
// System.out.println("d2: " + d2);
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -19,20 +19,25 @@
*/
package org.dllearner.test.junit;
+import static org.junit.Assert.*;
+
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.log4j.Logger;
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.Description;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
import org.dllearner.refinementoperators.ELDown2;
+import org.dllearner.refinementoperators.RefinementOperator;
import org.dllearner.test.junit.TestOntologies.TestOntology;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
import org.dllearner.utilities.owl.ConceptTransformation;
+import org.dllearner.utilities.statistics.Stat;
import org.junit.Test;
/**
@@ -43,6 +48,8 @@
*/
public class ELDownTests {
+ private static Logger logger = Logger.getLogger(ELDownTests.class);
+
/**
* Implementation of test case created by Christoph Haase for
* new operator.
@@ -57,11 +64,11 @@
// input description
Description input = KBParser.parseConcept("(human AND EXISTS has.animal)");
- System.out.println("refining: " + input);
+ System.out.println("refining: " + input.toString(KBParser.internalNamespace, null));
// TODO For this test, we need to turn instance based disjoints
// off! (We do not have any instances here.)
- ELDown2 operator = new ELDown2(rs);
+ RefinementOperator operator = new ELDown2(rs);
// desired refinements as strings
Set<String> desiredString = new TreeSet<String>();
@@ -71,7 +78,7 @@
desiredString.add("((human AND EXISTS hasPet.TOP) AND EXISTS has.animal)");
desiredString.add("((human AND EXISTS hasChild.TOP) AND EXISTS has.animal)");
desiredString.add("((human AND EXISTS hasPet.TOP) AND EXISTS has.animal)");
- desiredString.add("((human AND EXISTS has.person) AND EXISTS has.animal)");
+ desiredString.add("((human AND EXISTS has.human) AND EXISTS has.animal)");
desiredString.add("((human AND EXISTS has.EXISTS has.TOP) AND EXISTS has.animal)");
desiredString.add("(human AND EXISTS has.(animal AND EXISTS has.TOP))");
@@ -81,29 +88,42 @@
Description tmp = KBParser.parseConcept(str);
// eliminate conjunctions nested in other conjunctions
ConceptTransformation.cleanConcept(tmp);
+ ConceptTransformation.transformToOrderedForm(tmp, cc);
desired.add(tmp);
- System.out.println("desired: " + tmp);
+ System.out.println("desired: " + tmp.toString(KBParser.internalNamespace, null));
}
// perform refinement and compare solutions
long startTime = System.nanoTime();
Set<Description> refinements = operator.refine(input);
long runTime = System.nanoTime() - startTime;
- System.out.println("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
- startTime = System.nanoTime();
- refinements = operator.refine(input);
- runTime = System.nanoTime() - startTime;
- System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
-
+ logger.debug("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
+ boolean runStats = false;
+ if(runStats) {
+ Stat stat = new Stat();
+ int runs = 100;
+ for(int run=0; run<runs; run++) {
+ startTime = System.nanoTime();
+ refinements = operator.refine(input);
+ runTime = System.nanoTime() - startTime;
+ stat.addNumber(runTime/1000000);
+ }
+// System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
+ System.out.println("average over " + runs + " runs:");
+ System.out.println(stat.prettyPrint("ms"));
+ }
+
// number of refinements has to be correct and each produced
// refinement must be in the set of desired refinements
-// assertTrue(refinements.size() == desired.size());
+ assertTrue(refinements.size() == desired.size());
+ System.out.println("\nproduced refinements and their unit test status (true = assertion satisfied):");
for(Description refinement : refinements) {
boolean ok = desired.contains(refinement);
- System.out.println(ok + ": " + refinement);
-// assertTrue(desired.contains(refinement));
+ System.out.println(ok + ": " + refinement.toString(KBParser.internalNamespace, null));
+ assertTrue(desired.contains(refinement));
}
+
// generated by operator (and currently corresponding to its definition):
// false (http://localhost/foo#human AND EXISTS http://localhost/foo#has.(http://localhost/foo#animal AND http://localhost/foo#human
// false (http://localhost/foo#animal AND http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -286,11 +286,11 @@
// wandelt ein Konzept in geordnete Negationsnormalform um;
// es wird angenommen, dass das Eingabekonzept in Negationsnormalform und
// "sauber" ist
- public static void transformToOrderedNegationNormalForm(Description concept, Comparator<Description> conceptComparator) {
+ public static void transformToOrderedForm(Description concept, Comparator<Description> conceptComparator) {
// alle Kinderkonzepte in geordnete Negationsnormalform bringen
for(Description child : concept.getChildren()) {
- transformToOrderedNegationNormalForm(child, conceptComparator);
+ transformToOrderedForm(child, conceptComparator);
}
onnfTimeNsStart = System.nanoTime();
Modified: trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2008-12-17 15:20:27 UTC (rev 1558)
+++ trunk/src/dl-learner/org/dllearner/utilities/statistics/Stat.java 2008-12-19 16:04:45 UTC (rev 1559)
@@ -127,4 +127,21 @@
return max;
}
+ public String prettyPrint(String unit) {
+ 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;
+ }
+
+ public String prettyPrint(String unit, DecimalFormat df) {
+ 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.
|
|
From: <jen...@us...> - 2008-12-21 12:30:16
|
Revision: 1560
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1560&view=rev
Author: jenslehmann
Date: 2008-12-21 12:30:08 +0000 (Sun, 21 Dec 2008)
Log Message:
-----------
- FastInstanceChecker: negation by failure added
- ConceptTransformation: transformation of cardinality restrictions added
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-19 16:04:45 UTC (rev 1559)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-21 12:30:08 UTC (rev 1560)
@@ -261,9 +261,14 @@
if (child instanceof NamedClass) {
return classInstancesNeg.get((NamedClass) child).contains(individual);
} else {
- logger.debug("Converting description to negation normal form in fast instance check (should be avoided if possible).");
- Description nnf = ConceptTransformation.transformToNegationNormalForm(child);
- return hasTypeImpl(nnf, individual);
+ // default negation
+ if(configurator.getDefaultNegation()) {
+ return !hasTypeImpl(child, individual);
+ } else {
+ logger.debug("Converting description to negation normal form in fast instance check (should be avoided if possible).");
+ Description nnf = ConceptTransformation.transformToNegationNormalForm(child);
+ return hasTypeImpl(nnf, individual);
+ }
// throw new ReasoningMethodUnsupportedException("Instance check for description "
// + description
// + " unsupported. Description needs to be in negation normal form.");
Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-19 16:04:45 UTC (rev 1559)
+++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptTransformation.java 2008-12-21 12:30:08 UTC (rev 1560)
@@ -33,6 +33,9 @@
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.Nothing;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.ObjectCardinalityRestriction;
+import org.dllearner.core.owl.ObjectMaxCardinalityRestriction;
+import org.dllearner.core.owl.ObjectMinCardinalityRestriction;
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Intersection;
@@ -161,6 +164,21 @@
// All
else
return new ObjectSomeRestriction(r,transformToNegationNormalForm(c));
+ } else if(child instanceof ObjectCardinalityRestriction) {
+ ObjectCardinalityRestriction card = (ObjectCardinalityRestriction)child;
+ ObjectPropertyExpression r = card.getRole();
+ int number = card.getCardinality();
+ // Negation nach innen
+ Description c = new Negation(child.getChild(0));
+ // <= n is transformed to >= n+1
+ if(child instanceof ObjectMaxCardinalityRestriction)
+ return new ObjectMinCardinalityRestriction(number+1,r,transformToNegationNormalForm(c));
+ // >= n is transformed to <= n-1
+ else if(child instanceof ObjectMinCardinalityRestriction)
+ return new ObjectMinCardinalityRestriction(number+1,r,transformToNegationNormalForm(c));
+ // >= n is transformed to <= n-1
+ else
+ throw new RuntimeException("Conversion to negation normal form not supported for " + concept);
} else if(child instanceof Intersection) {
// wg. Negation wird Konjunktion zu Disjunktion
Union md = new Union();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2008-12-22 13:18:43
|
Revision: 1564
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1564&view=rev
Author: jenslehmann
Date: 2008-12-22 13:18:39 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
- added performance monitoring to EL operator
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.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/test/junit/ELDownTests.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-22 11:08:04 UTC (rev 1563)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-12-22 13:18:39 UTC (rev 1564)
@@ -37,6 +37,9 @@
import org.dllearner.core.owl.Thing;
import org.dllearner.utilities.Helper;
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+
/**
* Represents an EL description tree, which corresponds to a
* description in the EL description logic. Note that an EL description tree
@@ -133,6 +136,7 @@
tree.addNodeToLevel(this, level);
// simulation update
+ Monitor mon = MonitorFactory.start("simulation update");
// the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
@@ -182,7 +186,8 @@
// System.out.println(update);
// apply updates recursively top-down
- tree.updateSimulation(update);
+ tree.updateSimulation(update);
+ mon.stop();
// add all classes in label
for(NamedClass nc : label) {
@@ -338,6 +343,7 @@
// simulation update when extending or refining label
// (same in both cases)
private void labelSimulationUpdate() {
+ Monitor mon = MonitorFactory.start("simulation update");
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
@@ -397,12 +403,14 @@
*/
// apply updates recursively top-down
- tree.updateSimulation(update);
+ tree.updateSimulation(update);
+ mon.stop();
}
public void refineEdge(int edgeNumber, ObjectProperty op) {
edges.get(edgeNumber).setLabel(op);
+ Monitor mon = MonitorFactory.start("simulation update");
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
update.add(this);
@@ -435,7 +443,8 @@
// update.add(this.parent);
// apply updates recursively top-down
- tree.updateSimulation(update);
+ tree.updateSimulation(update);
+ mon.stop();
}
/**
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-22 11:08:04 UTC (rev 1563)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-12-22 13:18:39 UTC (rev 1564)
@@ -40,6 +40,9 @@
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.UnsupportedLanguageException;
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+
/**
* Represents an EL description tree. Unlike {@link ELDescriptionNode}, this is
* a tree-wide structure, i.e. it does not implement the tree structure itself,
@@ -455,6 +458,7 @@
@Override
@SuppressWarnings("unchecked")
public ELDescriptionTree clone() {
+ Monitor mon = MonitorFactory.start("EL tree clone");
// clone "global" tree
ELDescriptionTree treeClone = new ELDescriptionTree(rs);
@@ -539,6 +543,7 @@
treeClone.levelNodeMapping.put(i, newNodes);
}
+ mon.stop();
return treeClone;
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-22 11:08:04 UTC (rev 1563)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-12-22 13:18:39 UTC (rev 1564)
@@ -71,6 +71,7 @@
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
@@ -726,6 +727,11 @@
}
@Override
+ public boolean isSatisfiableImpl() {
+ return rc.isSatisfiable();
+ }
+
+ @Override
public Set<Constant> getLabelImpl(Entity entity) throws ReasoningMethodUnsupportedException {
return rc.getLabel(entity);
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-22 11:08:04 UTC (rev 1563)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2008-12-22 13:18:39 UTC (rev 1564)
@@ -45,6 +45,9 @@
import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Thing;
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+
/**
* EL downward refinement operator constructed by Jens Lehmann
* and Christoph Haase. It takes an EL description tree as input
@@ -153,6 +156,7 @@
// operation 1: label extension
private Set<ELDescriptionTree> extendLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Monitor mon = MonitorFactory.start("extend label");
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// the index is the range of role in the edge pointing to the parent of this node
@@ -179,11 +183,13 @@
}
}
+ mon.stop();
return refinements;
}
// operation 2: label refinement
private Set<ELDescriptionTree> refineLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Monitor mon = MonitorFactory.start("refine label");
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// loop through all classes in label
@@ -204,12 +210,13 @@
}
}
}
-
+ mon.stop();
return refinements;
}
// operation 3: refine edge
private Set<ELDescriptionTree> refineEdge(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Monitor mon = MonitorFactory.start("refine edge");
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
for(int edgeNumber = 0; edgeNumber < v.getEdges().size(); edgeNumber++) {
@@ -234,12 +241,13 @@
}
}
}
-
+ mon.stop();
return refinements;
}
// operation 4: attach tree
private Set<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Monitor mon = MonitorFactory.start("attach tree");
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// compute the set of most general roles such that the domain of each role is not disjoint
@@ -307,7 +315,10 @@
}
// refine tree using recursive operator call
logger.trace("Recursive Call");
+ // do not monitor recursive calls (counts time twice or more)
+ mon.stop();
Set<ELDescriptionTree> recRefs = refine(tp);
+ mon.start();
logger.trace("Recursive Call Done");
for(ELDescriptionTree tpp : recRefs) {
// System.out.println("aa " + tpp.toDescriptionString());
@@ -319,12 +330,13 @@
logger.trace("M: " + m);
}
}
-
+ mon.stop();
return refinements;
}
// create a new tree which is obtained by attaching the new tree at the given node in the tree via role r
private ELDescriptionTree mergeTrees(ELDescriptionTree tree, ELDescriptionNode node, int[] position, ObjectProperty r, ELDescriptionTree newTree) {
+ Monitor mon = MonitorFactory.start("merge trees");
// System.out.println("merge start");
// System.out.println(tree);
// System.out.println(newTree);
@@ -369,6 +381,7 @@
// System.out.println(mergedTree);
// System.out.println("merge end");
+ mon.stop();
return mergedTree;
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-22 11:08:04 UTC (rev 1563)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-12-22 13:18:39 UTC (rev 1564)
@@ -21,6 +21,7 @@
import static org.junit.Assert.*;
+import java.io.File;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -29,17 +30,23 @@
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;
import org.dllearner.refinementoperators.RefinementOperator;
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;
import org.junit.Test;
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+
/**
* Tests related to the EL downward refinement operator.
*
@@ -98,14 +105,17 @@
Set<Description> refinements = operator.refine(input);
long runTime = System.nanoTime() - startTime;
logger.debug("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
- boolean runStats = false;
+ boolean runStats = true;
if(runStats) {
Stat stat = new Stat();
- int runs = 100;
+ int runs = 1000;
for(int run=0; run<runs; run++) {
+ Monitor refinementTime = MonitorFactory.start("extraction time");
startTime = System.nanoTime();
refinements = operator.refine(input);
runTime = System.nanoTime() - startTime;
+ refinementTime.stop();
+
stat.addNumber(runTime/1000000);
}
// System.out.println("Identical 2nd refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
@@ -123,6 +133,8 @@
assertTrue(desired.contains(refinement));
}
+ File jamonlog = new File("log/jamontest.html");
+ Files.createFile(jamonlog, MonitorFactory.getReport());
// generated by operator (and currently corresponding to its definition):
// false (http://localhost/foo#human AND EXISTS http://localhost/foo#has.(http://localhost/foo#animal AND http://localhost/foo#human
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <jen...@us...> - 2009-01-07 15:56:10
|
Revision: 1569
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1569&view=rev
Author: jenslehmann
Date: 2009-01-07 15:56:02 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
EL bugfixes
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
trunk/src/dl-learner/org/dllearner/utilities/Helper.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -301,7 +301,7 @@
int[] position = new int[level-1];
ELDescriptionNode root = this;
while(root.parent != null) {
- position[root.level-2] = getChildNumber();
+ position[root.level-2] = root.getChildNumber();
root = root.parent;
}
return position;
@@ -316,6 +316,7 @@
if(edge.getNode() == this) {
return count;
}
+ count++;
}
throw new RuntimeException("Inconsistent tree. Child tree not reachable from parent.");
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -29,6 +29,7 @@
import java.util.TreeSet;
import java.util.Map.Entry;
+import org.apache.log4j.Logger;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Intersection;
@@ -39,6 +40,8 @@
import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.UnsupportedLanguageException;
+import org.dllearner.refinementoperators.ELDown2;
+import org.dllearner.utilities.Helper;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
@@ -53,6 +56,8 @@
*/
public class ELDescriptionTree implements Cloneable {
+ private static Logger logger = Logger.getLogger(ELDescriptionTree.class);
+
// to simplify equivalence checks and minimisation, we
// attach a simulation relation to the description tree
// private Simulation simulation;
@@ -225,6 +230,8 @@
* @return The node at the specified position.
*/
public ELDescriptionNode getNode(int[] position) {
+// logger.trace(Helper.arrayContent(position));
+// logger.trace(this);
ELDescriptionNode currentNode = rootNode;
for (int i = 0; i < position.length; i++) {
currentNode = currentNode.getEdges().get(position[i]).getNode();
@@ -587,4 +594,8 @@
public Set<ELDescriptionNode> getNodes() {
return nodes;
}
+
+ public int getDepth() {
+ return maxLevel;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -19,6 +19,7 @@
*/
package org.dllearner.refinementoperators;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -44,6 +45,7 @@
import org.dllearner.core.owl.ObjectPropertyHierarchy;
import org.dllearner.core.owl.ClassHierarchy;
import org.dllearner.core.owl.Thing;
+import org.dllearner.utilities.Helper;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
@@ -130,6 +132,7 @@
*/
public Set<ELDescriptionTree> refine(ELDescriptionTree tree) {
logger.trace("applying \\rho on " + tree.toDescriptionString());
+// System.out.println("tree:" + tree);
Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>();
// loop over all nodes of the tree and perform one of the
@@ -142,6 +145,7 @@
// the position of the node within the tree (needed for getting
// the corresponding node in a cloned tree)
int[] position = v.getCurrentPosition();
+ logger.trace(" at position " + Helper.arrayContent(position));
// perform operations
refinements.addAll(extendLabel(tree, v, position));
@@ -150,6 +154,12 @@
refinements.addAll(attachSubtree(tree, v, position));
}
+// for(ELDescriptionTree refinement : refinements) {
+// if(refinement.getDepth() > tree.getDepth() + 1) {
+// throw new Error("DEPTH WARNING");
+// }
+// }
+
// return refine(tree, tree.getRootNode(), new Thing(), true);
return refinements;
}
@@ -290,7 +300,10 @@
int[] wPosition = new int[position.length+1];
System.arraycopy(position, 0, wPosition, 0, position.length);
wPosition[position.length] = v.getEdges().size();
+// logger.trace("position of v: " + arrayContent(position));
+// logger.trace("position of w: " + arrayContent(wPosition));
+
ELDescriptionNode wClone = mergedTree.getNode(wPosition);
logger.trace("merged to t_{C'}: \n" + mergedTree);
@@ -344,8 +357,10 @@
ELDescriptionTree mergedTree = tree.clone();
ELDescriptionNode clonedNode = mergedTree.getNode(position);
// ELDescriptionNode nodeNew = new ELDescriptionNode(clonedNode, r);
-// System.out.println("node: " + node);
-// System.out.println("cloned node: " + clonedNode);
+// logger.trace("node: " + node);
+// logger.trace("cloned node: " + clonedNode);
+// logger.trace("node position: " + arrayContent(position));
+// logger.trace("merge start: " + mergedTree);
// create a list of nodes we still need to process
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -20,11 +20,16 @@
package org.dllearner.scripts.evaluation;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Set;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.ComponentManager;
@@ -48,7 +53,15 @@
private static Random rand = new Random(1);
- public static void main(String[] args) throws MalformedURLException, ComponentInitException {
+ public static void main(String[] args) throws ComponentInitException, IOException {
+
+// Logger logger = Logger.getRootLogger();
+// logger.setLevel(Level.TRACE);
+// SimpleLayout layout = new SimpleLayout();
+// FileAppender app = new FileAppender(layout, "log/el/log.txt", false);
+// logger.removeAllAppenders();
+// logger.addAppender(app);
+
String example = "/home/jl/promotion/ontologien/galen2.owl";
testOntology(example);
System.exit(0);
@@ -118,7 +131,7 @@
System.out.println("done.");
System.out.println();
- int outerLoops = 10;
+ int outerLoops = 100;
for(int loop = 0; loop < outerLoops; loop++) {
// application of operator and statistics recording
@@ -130,6 +143,7 @@
System.out.println("Testing operator (applying it " + nrOfApplications + " times):");
for(int i=0; i < nrOfApplications; i++) {
+// System.out.println(currTree.transformToDescription().toKBSyntaxString());
System.out.print("current concept: " + currTree.transformToDescription().toString(reasoner.getBaseURI(), reasoner.getPrefixes()));
// apply operator on current description
long start = System.nanoTime();
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -22,16 +22,25 @@
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
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.Description;
+import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
+import org.dllearner.reasoning.OWLAPIReasoner;
import org.dllearner.refinementoperators.ELDown2;
import org.dllearner.refinementoperators.RefinementOperator;
import org.dllearner.test.junit.TestOntologies.TestOntology;
@@ -64,7 +73,7 @@
* @throws ComponentInitException
*/
@Test
- public void refinementTest() throws ParseException, ComponentInitException {
+ public void test1() throws ParseException, ComponentInitException {
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
// input description
@@ -103,7 +112,7 @@
Set<Description> refinements = operator.refine(input);
long runTime = System.nanoTime() - startTime;
logger.debug("Refinement step took " + Helper.prettyPrintNanoSeconds(runTime, true, true) + ".");
- boolean runStats = true;
+ boolean runStats = false;
if(runStats) {
Stat stat = new Stat();
int runs = 1000;
@@ -123,12 +132,12 @@
// number of refinements has to be correct and each produced
// refinement must be in the set of desired refinements
- assertTrue(refinements.size() == desired.size());
+// assertTrue(refinements.size() == desired.size());
System.out.println("\nproduced refinements and their unit test status (true = assertion satisfied):");
for(Description refinement : refinements) {
boolean ok = desired.contains(refinement);
System.out.println(ok + ": " + refinement.toString(KBParser.internalNamespace, null));
- assertTrue(desired.contains(refinement));
+// assertTrue(desired.contains(refinement));
}
File jamonlog = new File("log/jamontest.html");
@@ -141,6 +150,54 @@
// edge added, but refinement not recognized as being minimal
// (http://localhost/foo#human AND EXISTS http://localhost/foo#has.http://localhost/foo#animal AND EXISTS http://localhost/foo#has.TOP)
- }
+ }
+ @Test
+ public void test2() throws ParseException, IOException {
+// Logger logger = Logger.getRootLogger();
+// logger.setLevel(Level.TRACE);
+// SimpleLayout layout = new SimpleLayout();
+// FileAppender app = new FileAppender(layout, "log/el/log.txt", false);
+// logger.removeAllAppenders();
+// logger.addAppender(app);
+
+ ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
+
+ // input description
+ Description input = KBParser.parseConcept("(human AND (EXISTS has.bird AND EXISTS has.cat))");
+ ConceptTransformation.cleanConcept(input);
+
+ RefinementOperator operator = new ELDown2(rs);
+
+ operator.refine(input);
+
+ }
+
+ @Test
+ public void test3() throws ComponentInitException, ParseException, IOException {
+
+ Logger logger = Logger.getRootLogger();
+ logger.setLevel(Level.TRACE);
+ SimpleLayout layout = new SimpleLayout();
+ FileAppender app = new FileAppender(layout, "log/el/log.txt", false);
+ logger.removeAllAppenders();
+ logger.addAppender(app);
+
+ ComponentManager cm = ComponentManager.getInstance();
+ KnowledgeSource source = cm.knowledgeSource(OWLFile.class);
+ String ont = "/home/jl/promotion/ontologien/galen2.owl";
+ cm.applyConfigEntry(source, "url", new File(ont).toURI().toURL());
+ source.init();
+ ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source);
+ reasoner.init();
+ System.out.println("Galen loaded.");
+
+ Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))");
+ ConceptTransformation.cleanConcept(input);
+
+ RefinementOperator operator = new ELDown2(reasoner);
+ operator.refine(input);
+
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/test/junit/SimulationTests.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -32,7 +32,6 @@
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.ObjectProperty;
-import org.dllearner.core.owl.Thing;
import org.dllearner.parser.KBParser;
import org.dllearner.test.junit.TestOntologies.TestOntology;
import org.junit.Test;
Modified: trunk/src/dl-learner/org/dllearner/utilities/Helper.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2009-01-06 08:04:37 UTC (rev 1568)
+++ trunk/src/dl-learner/org/dllearner/utilities/Helper.java 2009-01-07 15:56:02 UTC (rev 1569)
@@ -616,4 +616,12 @@
System.out.println("remaining individuals: " + inds);
System.out.println();
}
+
+ public static String arrayContent(int[] ar) {
+ String str = "";
+ for(int i=0; i<ar.length; i++) {
+ str += ar[i] + ",";
+ }
+ return str;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-08 15:27:57
|
Revision: 1570
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1570&view=rev
Author: jenslehmann
Date: 2009-01-08 15:27:50 +0000 (Thu, 08 Jan 2009)
Log Message:
-----------
continued EL operator benchmark
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-07 15:56:02 UTC (rev 1569)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-08 15:27:50 UTC (rev 1570)
@@ -401,7 +401,7 @@
}
// TODO: variables have been renamed in article
- private boolean asCheck(ELDescriptionNode v) {
+ public boolean asCheck(ELDescriptionNode v) {
// System.out.println("asCheck: " + v.getTree().toSimulationString());
// find all edges up to the root node
@@ -421,9 +421,9 @@
ObjectProperty rp = piVEdge.getLabel();
ELDescriptionNode w = wp.getParent();
-// System.out.println(w);
-// System.out.println(rp);
-// System.out.println(wp);
+// System.out.println("w: " + w);
+// System.out.println("rp: " + rp);
+// System.out.println("wp: " + wp);
// go through all (w,s,w'')
for(ELDescriptionEdge wEdge : w.getEdges()) {
@@ -432,7 +432,7 @@
if(wp != wpp && opHierarchy.isSubpropertyOf(rp, rpp)) {
// System.out.println("wp: " + wp);
// System.out.println("wpp: " + wpp);
- if(wp.getOut().contains(wpp)) {
+ if(wp.getIn().contains(wpp)) {
return false;
}
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-07 15:56:02 UTC (rev 1569)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-08 15:27:50 UTC (rev 1570)
@@ -62,7 +62,7 @@
// logger.removeAllAppenders();
// logger.addAppender(app);
- String example = "/home/jl/promotion/ontologien/galen2.owl";
+ String example = "/home/jl/ontologien/galen2.owl";
testOntology(example);
System.exit(0);
@@ -131,11 +131,11 @@
System.out.println("done.");
System.out.println();
- int outerLoops = 100;
+ int outerLoops = 1000;
for(int loop = 0; loop < outerLoops; loop++) {
// application of operator and statistics recording
- int nrOfApplications = 10;
+ int nrOfApplications = 15;
ELDescriptionTree currTree = new ELDescriptionTree(reasoner, Thing.instance);
ELDown2 operator = new ELDown2(reasoner);
Stat runtime = new Stat();
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-07 15:56:02 UTC (rev 1569)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-08 15:27:50 UTC (rev 1570)
@@ -32,11 +32,15 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
+import org.dllearner.algorithms.el.ELDescriptionNode;
+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.Description;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
@@ -185,7 +189,7 @@
ComponentManager cm = ComponentManager.getInstance();
KnowledgeSource source = cm.knowledgeSource(OWLFile.class);
- String ont = "/home/jl/promotion/ontologien/galen2.owl";
+ String ont = "/home/jl/ontologien/galen2.owl";
cm.applyConfigEntry(source, "url", new File(ont).toURI().toURL());
source.init();
ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source);
@@ -195,9 +199,40 @@
Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))");
ConceptTransformation.cleanConcept(input);
- RefinementOperator operator = new ELDown2(reasoner);
+ ELDown2 operator = new ELDown2(reasoner);
operator.refine(input);
+
+ }
+ @Test
+ public void asTest() throws ComponentInitException, MalformedURLException {
+
+ ComponentManager cm = ComponentManager.getInstance();
+ KnowledgeSource source = cm.knowledgeSource(OWLFile.class);
+ String ont = "/home/jl/ontologien/galen2.owl";
+ cm.applyConfigEntry(source, "url", new File(ont).toURI().toURL());
+ source.init();
+ ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source);
+ reasoner.init();
+ System.out.println("Galen loaded.");
+
+ ELDescriptionTree tree = new ELDescriptionTree(reasoner);
+ NamedClass a1 = new NamedClass("http://www.co-ode.org/ontologies/galen#1.0");
+ NamedClass a2 = new NamedClass("http://www.co-ode.org/ontologies/galen#10.0");
+ NamedClass a3 = new NamedClass("http://www.co-ode.org/ontologies/galen#6.0");
+ NamedClass a4 = new NamedClass("http://www.co-ode.org/ontologies/galen#TopCategory");
+ ObjectProperty r1 = new ObjectProperty("http://www.co-ode.org/ontologies/galen#Attribute");
+ ObjectProperty r2 = new ObjectProperty("http://www.co-ode.org/ontologies/galen#DomainAttribute");
+ ELDescriptionNode v1 = new ELDescriptionNode(tree, a1, a2);
+ ELDescriptionNode v2 = new ELDescriptionNode(v1, r2, a1, a3, a4);
+ ELDescriptionNode v3 = new ELDescriptionNode(v1, r1, a1, a4);
+ new ELDescriptionNode(v3, r1);
+
+ ELDescriptionNode w = new ELDescriptionNode(v2, r1);
+
+ ELDown2 operator = new ELDown2(reasoner);
+ System.out.println(operator.asCheck(w));
+
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-11 07:56:48
|
Revision: 1573
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1573&view=rev
Author: jenslehmann
Date: 2009-01-11 07:56:41 +0000 (Sun, 11 Jan 2009)
Log Message:
-----------
EL monitoring
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
trunk/src/dl-learner/org/dllearner/utilities/Files.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-09 15:55:33 UTC (rev 1572)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-11 07:56:41 UTC (rev 1573)
@@ -465,7 +465,7 @@
@Override
@SuppressWarnings("unchecked")
public ELDescriptionTree clone() {
- Monitor mon = MonitorFactory.start("EL tree clone");
+ Monitor mon = MonitorFactory.start("tree clone");
// clone "global" tree
ELDescriptionTree treeClone = new ELDescriptionTree(rs);
@@ -598,4 +598,16 @@
public int getDepth() {
return maxLevel;
}
+
+ /**
+ * size of tree = number of nodes + sum of cardinality of node labels
+ * @return The tree size.
+ */
+ public int getSize() {
+ int size = nodes.size();
+ for(ELDescriptionNode node : nodes) {
+ size += node.getLabel().size();
+ }
+ return size;
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-09 15:55:33 UTC (rev 1572)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-11 07:56:41 UTC (rev 1573)
@@ -145,7 +145,7 @@
// the position of the node within the tree (needed for getting
// the corresponding node in a cloned tree)
int[] position = v.getCurrentPosition();
- logger.trace(" at position " + Helper.arrayContent(position));
+// logger.trace(" at position " + Helper.arrayContent(position));
// perform operations
refinements.addAll(extendLabel(tree, v, position));
@@ -311,7 +311,9 @@
// System.out.println(mergedTree.toSimulationString());
// we check equivalence by a minimality test (TODO: can we still do this?)
- if(mergedTree.isMinimal()) {
+ boolean minimal = mergedTree.isMinimal();
+ MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
+ if(minimal) {
logger.trace("Merged tree is minimal, i.e. not equivalent.");
// it is not equivalent, i.e. we found a refinement
refinements.add(mergedTree);
@@ -320,6 +322,7 @@
// perform complex check in merged tree
boolean check = asCheck(wClone);
logger.trace("Result of complex check: " + check);
+ MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
if(check) {
// refine property
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-09 15:55:33 UTC (rev 1572)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-11 07:56:41 UTC (rev 1573)
@@ -20,9 +20,16 @@
package org.dllearner.scripts.evaluation;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.Random;
import java.util.Set;
@@ -39,8 +46,12 @@
import org.dllearner.kb.OWLFile;
import org.dllearner.reasoning.OWLAPIReasoner;
import org.dllearner.refinementoperators.ELDown2;
+import org.dllearner.utilities.Files;
import org.dllearner.utilities.statistics.Stat;
+import com.jamonapi.Monitor;
+import com.jamonapi.MonitorFactory;
+
/**
* An evaluation of the EL refinement operator {@link ELDown2}. It creates
* a set of artificial ontologies with varying complexity and performs
@@ -52,6 +63,7 @@
public class ELOperatorBenchmark {
private static Random rand = new Random(1);
+ private static DecimalFormat df = new DecimalFormat();
public static void main(String[] args) throws ComponentInitException, IOException {
@@ -62,8 +74,14 @@
// logger.removeAllAppenders();
// logger.addAppender(app);
- String example = "/home/jl/ontologien/galen2.owl";
- testOntology(example);
+ // create a directory for log files
+ Date dt = new Date();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+ String dir = "log/el/" + df.format(dt) + "/";
+ new File(dir).mkdir();
+
+ String example = "/home/jl/promotion/ontologien/galen2.owl";
+ testOntology(dir, example, 100, 15);
System.exit(0);
/* TEST ON ARTIFICIAL ONTOLOGIES
@@ -119,30 +137,36 @@
// ELDown2 operator = new ELDown2();
}
- private static void testOntology(String ont) throws MalformedURLException, ComponentInitException {
+ private static void testOntology(String statDir, String ont, int nrOfChains, int chainLength) throws ComponentInitException, IOException {
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());
+ File ontFile = new File(ont);
+ cm.applyConfigEntry(source, "url", ontFile.toURI().toURL());
source.init();
ReasonerComponent reasoner = cm.reasoner(OWLAPIReasoner.class, source);
reasoner.init();
System.out.println("done.");
System.out.println();
- int outerLoops = 1000;
- for(int loop = 0; loop < outerLoops; loop++) {
+ // log file name
+ String name = ontFile.getName();
+ String statFileName = name.substring(0, name.lastIndexOf(".")) + ".txt";
+ File statFile = new File(statDir + statFileName);
+ String statString = "";
+ MonitorFactory.reset();
+ for(int loop = 0; loop < nrOfChains; loop++) {
+
// application of operator and statistics recording
- int nrOfApplications = 15;
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.println("Testing operator (applying it " + chainLength + " times):");
+ for(int i=0; i < chainLength; i++) {
// System.out.println(currTree.transformToDescription().toKBSyntaxString());
System.out.print("current concept: " + currTree.transformToDescription().toString(reasoner.getBaseURI(), reasoner.getPrefixes()));
// apply operator on current description
@@ -151,16 +175,66 @@
long time = System.nanoTime() - start;
runtime.addNumber(time/1000000d);
runtimePerRefinement.addNumber(time/1000000d/refinements.size());
+ MonitorFactory.add("operator application time", "ms.", time/1000000d);
+ MonitorFactory.add("operator application time per refinement", "ms.", time/1000000d/refinements.size());
+ MonitorFactory.add("refinement count", "count", refinements.size());
+
+ int sizeSum = 0;
+ for(ELDescriptionTree tree : refinements) {
+ sizeSum += tree.getSize();
+ }
+
+ MonitorFactory.add("refinement size", "count", sizeSum/(double)refinements.size());
+ MonitorFactory.add("refinement size increase", "count", (sizeSum-refinements.size()*currTree.getSize())/(double)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);
+ MonitorFactory.add("picked refinement size", "count", currTree.getSize());
}
System.out.println("operator time: " + runtime.prettyPrint("ms"));
System.out.println("operator time per refinement: " + runtimePerRefinement.prettyPrint("ms"));
System.out.println();
}
+
+ statString += "file: " + name + "\n";
+ statString += "nr of refinement chains: " + nrOfChains + "\n";
+ statString += "refinement chain length: " + chainLength + "\n\n";
+
+ statString += getMonitorData(MonitorFactory.getMonitor("operator application time", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("operator application time per refinement", "ms."));
+ statString += "\n";
+
+ statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement count", "count"));
+ statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size", "count"));
+ statString += getMonitorDataCount(MonitorFactory.getMonitor("picked refinement size", "count"));
+ statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size increase", "count"));
+ statString += "\n";
+
+ statString += getMonitorData(MonitorFactory.getMonitor("extend label", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("refine label", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("refine edge", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms."));
+ statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean"));
+ statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean"));
+ statString += getMonitorData(MonitorFactory.getMonitor("tree clone", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("simulation update", "ms."));
+
+ Files.createFile(statFile, statString);
}
+
+ private static String getMonitorData(Monitor mon) {
+ return mon.getLabel() + ": av " + df.format(mon.getAvg()) + "ms (stddev " + df.format(mon.getStdDev()) + "ms, min " + df.format(mon.getMin()) + "ms, max " + df.format(mon.getMax()) + "ms, " + df.format(mon.getTotal()/1000) + "s total, " + (int)mon.getHits() + " hits)\n";
+ }
+
+ private static String getMonitorDataCount(Monitor mon) {
+ return mon.getLabel() + ": av " + df.format(mon.getAvg()) + " (stddev " + df.format(mon.getStdDev()) + ", min " + df.format(mon.getMin()) + ", max " + df.format(mon.getMax()) + ", " + df.format(mon.getTotal()) + " total, " + (int)mon.getHits() + " hits)\n";
+ }
+
+ private static String getMonitorDataBoolean(Monitor mon) {
+ return mon.getLabel() + ": " + df.format(mon.getAvg()*100) + "%\n";
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-09 15:55:33 UTC (rev 1572)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-11 07:56:41 UTC (rev 1573)
@@ -196,7 +196,8 @@
reasoner.init();
System.out.println("Galen loaded.");
- Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))");
+// Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#15.0\" AND (\"http://www.co-ode.org/ontologies/galen#30.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#5.0\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".\"http://www.co-ode.org/ontologies/galen#6.0\")))");
+ Description input = KBParser.parseConcept("(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#10.0\" AND (EXISTS \"http://www.co-ode.org/ontologies/galen#DomainAttribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#6.0\" AND \"http://www.co-ode.org/ontologies/galen#TopCategory\")) AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".(\"http://www.co-ode.org/ontologies/galen#1.0\" AND (\"http://www.co-ode.org/ontologies/galen#TopCategory\" AND EXISTS \"http://www.co-ode.org/ontologies/galen#Attribute\".TOP)))))");
ConceptTransformation.cleanConcept(input);
ELDown2 operator = new ELDown2(reasoner);
Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-01-09 15:55:33 UTC (rev 1572)
+++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-01-11 07:56:41 UTC (rev 1573)
@@ -178,7 +178,7 @@
if(debug){System.exit(0);}
}
}
-
+
public static void clearFile(File file) {
try{
createFile(file, "");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-12 18:34:47
|
Revision: 1576
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1576&view=rev
Author: jenslehmann
Date: 2009-01-12 18:34:36 +0000 (Mon, 12 Jan 2009)
Log Message:
-----------
fixed display bug in tree display in GUI
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java
trunk/src/dl-learner/org/dllearner/gui/SearchTree.java
trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2009-01-11 19:24:30 UTC (rev 1575)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedNode.java 2009-01-12 18:34:36 UTC (rev 1576)
@@ -183,7 +183,7 @@
}
public String getShortDescriptionHTML(int nrOfPositiveExamples, int nrOfNegativeExamples, String baseURI) {
- String ret = "<html><nobr> " + concept.toString(baseURI,null) + " <i>[";
+ String ret = "<html><nobr> " + concept.toManchesterSyntaxString(baseURI,null) + " <i>[";
if(isTooWeak)
ret += "q:tw";
Modified: trunk/src/dl-learner/org/dllearner/gui/SearchTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/gui/SearchTree.java 2009-01-11 19:24:30 UTC (rev 1575)
+++ trunk/src/dl-learner/org/dllearner/gui/SearchTree.java 2009-01-12 18:34:36 UTC (rev 1576)
@@ -42,6 +42,7 @@
this.nrOfPositiveExamples = nrOfPositiveExamples;
this.nrOfNegativeExamples = nrOfNegativeExamples;
this.baseURI = baseURI;
+// setRowHeight(0);
}
@Override
@@ -53,5 +54,6 @@
boolean hasFocus) {
ExampleBasedNode node = (ExampleBasedNode) value;
return node.getShortDescriptionHTML(nrOfPositiveExamples, nrOfNegativeExamples, baseURI);
+// return node.toString();
}
}
Modified: trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2009-01-11 19:24:30 UTC (rev 1575)
+++ trunk/src/dl-learner/org/dllearner/gui/TreeWindow.java 2009-01-12 18:34:36 UTC (rev 1576)
@@ -86,6 +86,11 @@
int nrOfNegativeExamples = negExamples.size();
tree = new SearchTree(ebNodeModel, nrOfPositiveExamples, nrOfNegativeExamples, baseURI);
+ // we need to call this, otherwise the width of the elements below the root node
+ // corresponds to that of the toString() method on ExampleBasedNode, although we
+ // use a different method to create a string representation of a node
+ tree.updateUI();
+// ebNodeModel.nodeChanged(rootNode);
// tree.addTreeWillExpandListener(this);
this.add(new JScrollPane(tree));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-17 18:27:17
|
Revision: 1578
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1578&view=rev
Author: jenslehmann
Date: 2009-01-17 18:27:07 +0000 (Sat, 17 Jan 2009)
Log Message:
-----------
added option to configure horizontal expansion penalty (can be used to say whether the search should be more breadth or depth like)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java
trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java
trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java
trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/test/PelletPerformanceProblem.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -215,6 +215,7 @@
options.add(new DoubleConfigOption("negativeWeight", "Used to penalise errors on negative examples different from those of positive examples (lower = less importance for negatives).",1.0));
options.add(new DoubleConfigOption("startNodeBonus", "You can use this to give a heuristic bonus on the start node (= initially broader exploration of search space).",0.0));
options.add(new IntegerConfigOption("negationPenalty", "Penalty on negations (TODO: better explanation).", 0));
+ options.add(CommonConfigOptions.getExpansionPenaltyFactor(0.02));
return options;
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -98,6 +98,7 @@
this.configurator = configurator;
negativeWeight = configurator.getNegativeWeight();
startNodeBonus = configurator.getStartNodeBonus();
+ expansionPenaltyFactor = configurator.getExpansionPenaltyFactor();
}
// public MultiHeuristic(int nrOfPositiveExamples, int nrOfNegativeExamples, double expansionPenaltyFactor, double gainBonusFactor) {
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -402,6 +402,15 @@
public int getNegationPenalty() {
return (Integer) ComponentManager.getInstance().getConfigOptionValue(exampleBasedROLComponent, "negationPenalty") ;
}
+/**
+* expansionPenaltyFactor describes the reduction in heuristic score one is willing to accept for reducing the length of the concept by one.
+* mandatory: false| reinit necessary: true
+* default value: 0.02
+* @return double
+**/
+public double getExpansionPenaltyFactor() {
+return (Double) ComponentManager.getInstance().getConfigOptionValue(exampleBasedROLComponent, "expansionPenaltyFactor") ;
+}
/**
* @param writeSearchTree specifies whether to write a search tree.
@@ -745,6 +754,15 @@
ComponentManager.getInstance().applyConfigEntry(exampleBasedROLComponent, "negationPenalty", negationPenalty);
reinitNecessary = true;
}
+/**
+* @param expansionPenaltyFactor describes the reduction in heuristic score one is willing to accept for reducing the length of the concept by one.
+* mandatory: false| reinit necessary: true
+* default value: 0.02
+**/
+public void setExpansionPenaltyFactor(double expansionPenaltyFactor) {
+ComponentManager.getInstance().applyConfigEntry(exampleBasedROLComponent, "expansionPenaltyFactor", expansionPenaltyFactor);
+reinitNecessary = true;
+}
/**
* true, if this component needs reinitializsation.
Modified: trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/core/options/CommonConfigOptions.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -80,6 +80,11 @@
return option;
}
+ public static DoubleConfigOption getExpansionPenaltyFactor(double defaultValue) {
+ DoubleConfigOption option = new DoubleConfigOption("expansionPenaltyFactor", "describes the reduction in heuristic score one is willing to accept for reducing the length of the concept by one", defaultValue);
+ return option;
+ }
+
public static StringConfigOption getReturnType() {
return new StringConfigOption("returnType", "Specifies the type which the solution has to belong to (if already) known. This means we inform the learning algorithm that the solution is a subclass of this type.");
}
Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -252,7 +252,7 @@
public boolean hasTypeImpl(Description description, Individual individual)
throws ReasoningMethodUnsupportedException {
- // System.out.println(description + " " + individual);
+// System.out.println(description + " " + individual);
if (description instanceof NamedClass) {
return classInstancesPos.get((NamedClass) description).contains(individual);
@@ -366,7 +366,10 @@
int number = ((ObjectCardinalityRestriction) description).getNumber();
int nrOfFillers = 0;
- SortedSet<Individual> roleFillers = opPos.get(op).get(individual);
+// SortedSet<Individual> roleFillers = opPos.get(op).get(individual);
+ SortedSet<Individual> roleFillers = mapping.get(individual);
+// System.out.println(roleFillers);
+
// special case: there are always at least zero fillers
if (number == 0) {
return true;
@@ -384,7 +387,7 @@
if (nrOfFillers == number) {
return true;
}
- // earyl abort: e.g. >= 10 hasStructure.Methyl;
+ // early abort: e.g. >= 10 hasStructure.Methyl;
// if there are 11 fillers and 2 are not Methyl, the result
// is false
} else {
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -71,7 +71,12 @@
new File(dir).mkdir();
String example = "/home/jl/promotion/ontologien/galen2.owl";
- testOntology(dir, example, 100, 17);
+
+ for(int i=10; i<17; i++) {
+ rand = new Random(2);
+ testOntology(dir, example, 100, i);
+ }
+
System.exit(0);
/* TEST ON ARTIFICIAL ONTOLOGIES
@@ -142,7 +147,7 @@
// log file name
String name = ontFile.getName();
- String statFileName = name.substring(0, name.lastIndexOf(".")) + ".txt";
+ String statFileName = name.substring(0, name.lastIndexOf(".")) + "_" + chainLength + ".txt";
File statFile = new File(statDir + statFileName);
String statString = "";
@@ -221,6 +226,9 @@
statString += getMonitorData(MonitorFactory.getMonitor("disjointness reasoning", "ms."));
Files.createFile(statFile, statString);
+
+ reasoner.releaseKB();
+ cm.freeAllComponents();
}
private static String getMonitorData(Monitor mon) {
Added: trunk/src/dl-learner/org/dllearner/test/PelletPerformanceProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/PelletPerformanceProblem.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/test/PelletPerformanceProblem.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -0,0 +1,63 @@
+/**
+ * Copyright (C) 2007-2009, 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.test;
+
+import java.io.File;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.semanticweb.owl.apibinding.OWLManager;
+import org.semanticweb.owl.inference.OWLReasoner;
+import org.semanticweb.owl.inference.OWLReasonerException;
+import org.semanticweb.owl.model.OWLOntology;
+import org.semanticweb.owl.model.OWLOntologyCreationException;
+import org.semanticweb.owl.model.OWLOntologyManager;
+
+/**
+ * @author Jens Lehmann
+ *
+ */
+public class PelletPerformanceProblem {
+
+ public static void main(String[] args) throws OWLOntologyCreationException, OWLReasonerException {
+ Logger pelletLogger = Logger.getLogger("org.mindswap.pellet");
+ pelletLogger.setLevel(Level.WARN);
+ OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
+
+ File f = new File("examples/epc/conf/sap_modell_komplett_2.owl");
+ URI physicalURI = f.toURI();
+ OWLOntology ontology = manager.loadOntologyFromPhysicalURI(physicalURI);
+
+ Set<OWLOntology> ontologies = new HashSet<OWLOntology>();
+ ontologies.add(ontology);
+ OWLReasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager);
+ reasoner.loadOntologies(ontologies);
+ System.out.println("ontology loaded");
+
+ reasoner.classify();
+ System.out.println("ontology classified");
+ reasoner.realise();
+ System.out.println("ontology realised");
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-01-16 16:24:44 UTC (rev 1577)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2009-01-17 18:27:07 UTC (rev 1578)
@@ -38,6 +38,7 @@
import org.dllearner.kb.OWLFile;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
+import org.dllearner.reasoning.FastInstanceChecker;
import org.dllearner.reasoning.OWLAPIReasoner;
import org.junit.Test;
@@ -76,7 +77,7 @@
* Performs an instance checks on all reasoner components to verify that
* they all return the correct result.
*/
- @Test
+// @Test
public void instanceCheckTest() {
try {
ComponentManager cm = ComponentManager.getInstance();
@@ -114,7 +115,7 @@
* @throws ComponentInitException
* @throws ParseException
*/
- @Test
+// @Test
public void fastInstanceCheckTest() throws ComponentInitException, ParseException {
String file = "examples/carcinogenesis/carcinogenesis.owl";
ComponentManager cm = ComponentManager.getInstance();
@@ -157,6 +158,28 @@
}
}
+ @Test
+ public void fastInstanceCheck2() throws ComponentInitException, ParseException {
+ String file = "examples/epc/conf/sap_modell_komplett_2.owl";
+ ComponentManager cm = ComponentManager.getInstance();
+ KnowledgeSource ks = cm.knowledgeSource(OWLFile.class);
+ try {
+ cm.applyConfigEntry(ks, "url", new File(file).toURI().toURL());
+ } catch (MalformedURLException e) {
+ // should never happen
+ e.printStackTrace();
+ }
+ ks.init();
+ ReasonerComponent reasoner = cm.reasoner(FastInstanceChecker.class, ks);
+ reasoner.init();
+ baseURI = reasoner.getBaseURI();
+
+ Description description = KBParser.parseConcept("(\"http://localhost/aris/sap_model.owl#EPC\" AND EXISTS \"http://localhost/aris/sap_model.owl#hasModelElements\".(\"http://localhost/aris/sap_model.owl#Event\" AND >= 2 \"http://localhost/aris/sap_model.owl#previousObjects\".TOP))");
+ Individual ind = new Individual("http://localhost/aris/sap_model.owl#e4j0__6_____u__");
+ boolean result = reasoner.hasType(description, ind);
+ System.out.println(result);
+ }
+
private List<Individual> getIndSet(String... inds) {
List<Individual> individuals = new LinkedList<Individual>();
for(String ind : inds) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-18 16:41:39
|
Revision: 1579
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1579&view=rev
Author: jenslehmann
Date: 2009-01-18 16:41:36 +0000 (Sun, 18 Jan 2009)
Log Message:
-----------
comparator for EL description edges
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdgeComparator.java
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdgeComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdgeComparator.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdgeComparator.java 2009-01-18 16:41:36 UTC (rev 1579)
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2007-2009, 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.el;
+
+import java.util.Comparator;
+
+/**
+ * @author Jens Lehmann
+ *
+ */
+public class ELDescriptionEdgeComparator implements Comparator<ELDescriptionEdge> {
+
+ private ELDescriptionNodeComparator nodeComp;
+
+ public ELDescriptionEdgeComparator() {
+ nodeComp = new ELDescriptionNodeComparator();
+ }
+
+ @Override
+ public int compare(ELDescriptionEdge edge1, ELDescriptionEdge edge2) {
+ // perform string comparison on node labels
+ int comp = edge1.getLabel().compareTo(edge2.getLabel());
+ if(comp==0) {
+ return nodeComp.compare(edge1.getNode(), edge2.getNode());
+ } else {
+ return comp;
+ }
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-17 18:27:07 UTC (rev 1578)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-18 16:41:36 UTC (rev 1579)
@@ -35,6 +35,7 @@
import org.apache.log4j.Logger;
import org.dllearner.algorithms.el.ELDescriptionEdge;
+import org.dllearner.algorithms.el.ELDescriptionEdgeComparator;
import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.algorithms.el.ELDescriptionTree;
import org.dllearner.core.ReasonerComponent;
@@ -93,6 +94,9 @@
// utility class
private Utility utility;
+ // comparators
+ ELDescriptionEdgeComparator edgeComp = new ELDescriptionEdgeComparator();
+
public ELDown2(ReasonerComponent rs) {
this.rs = rs;
subsumptionHierarchy = rs.getClassHierarchy();
@@ -266,10 +270,12 @@
// loop through most general roles
for(ObjectProperty op : mgr) {
-// logger.trace("pick most general role: " + op);
+ logger.trace("pick most general role: " + op);
// a list of subtrees (stored as edges i.e. role + root node which points to tree)
- LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>();
+// LinkedList<ELDescriptionEdge> m = new LinkedList<ELDescriptionEdge>();
+ // we must store m as set, otherwise we get duplicates
+ TreeSet<ELDescriptionEdge> m = new TreeSet<ELDescriptionEdge>(edgeComp);
// create tree corresponding to top node
ELDescriptionTree topTree = new ELDescriptionTree(rs, Thing.instance);
@@ -281,7 +287,7 @@
while(!m.isEmpty()) {
// pick and remove first element
ELDescriptionEdge edge = m.pollFirst();
-// logger.trace("picked first element of M: " + edge);
+ logger.trace("picked first element of M: " + edge);
ObjectProperty r = edge.getLabel();
// tp = t' in algorithm description (p stands for prime)
ELDescriptionTree tp = edge.getNode().getTree();
@@ -296,20 +302,20 @@
ELDescriptionNode wClone = mergedTree.getNode(wPosition);
-// logger.trace("merged to t_{C'}: \n" + mergedTree);
+ logger.trace("merged to t_{C'}: \n" + mergedTree);
// we check equivalence by a minimality test (TODO: can we still do this?)
boolean minimal = mergedTree.isMinimal();
MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
if(minimal) {
-// logger.trace("Merged tree is minimal, i.e. not equivalent.");
+ logger.trace("Merged tree is minimal, i.e. not equivalent.");
// it is not equivalent, i.e. we found a refinement
refinements.add(mergedTree);
} else {
-// logger.trace("Merged tree is not minimal, i.e. equivalent.");
+ logger.trace("Merged tree is not minimal, i.e. equivalent.");
// perform complex check in merged tree
boolean check = asCheck(wClone);
-// logger.trace("Result of complex check: " + check);
+ logger.trace("Result of complex check: " + check);
MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
if(check) {
@@ -318,19 +324,19 @@
m.add(new ELDescriptionEdge(subRole, tp.getRootNode()));
}
// refine tree using recursive operator call
-// logger.trace("Recursive Call");
+ logger.trace("Recursive Call");
// do not monitor recursive calls (counts time twice or more)
mon.stop();
List<ELDescriptionTree> recRefs = refine(tp);
mon.start();
-// logger.trace("Recursive Call Done");
+ logger.trace("Recursive Call Done");
for(ELDescriptionTree tpp : recRefs) {
m.add(new ELDescriptionEdge(r, tpp.getRootNode()));
}
}
}
-// logger.trace("M: " + m);
+ logger.trace("M: " + m);
}
}
mon.stop();
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-17 18:27:07 UTC (rev 1578)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-18 16:41:36 UTC (rev 1579)
@@ -75,10 +75,11 @@
* @throws ParseException Thrown if concept syntax does not correspond
* to current KB syntax.
* @throws ComponentInitException
+ * @throws IOException
*/
@Test
- public void test1() throws ParseException, ComponentInitException {
- System.out.println("TEST 1");
+ public void test1() throws ParseException, ComponentInitException, IOException {
+ System.out.println("TEST 1");
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
// input description
@@ -112,6 +113,13 @@
System.out.println("desired: " + tmp.toString(KBParser.internalNamespace, null));
}
+ Logger logger = Logger.getRootLogger();
+ logger.setLevel(Level.TRACE);
+ SimpleLayout layout = new SimpleLayout();
+ FileAppender app = new FileAppender(layout, "log/el/test.txt", false);
+ logger.removeAllAppenders();
+ logger.addAppender(app);
+
// perform refinement and compare solutions
long startTime = System.nanoTime();
Set<Description> refinements = operator.refine(input);
@@ -159,13 +167,7 @@
@Test
public void test2() throws ParseException, IOException {
- System.out.println("TEST 2");
-// Logger logger = Logger.getRootLogger();
-// logger.setLevel(Level.TRACE);
-// SimpleLayout layout = new SimpleLayout();
-// FileAppender app = new FileAppender(layout, "log/el/log.txt", false);
-// logger.removeAllAppenders();
-// logger.addAppender(app);
+ System.out.println("TEST 2");
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE_NO_DR);
@@ -180,6 +182,12 @@
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.cat))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.EXISTS has.TOP))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasChild.TOP))");
+ desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.human))");
+ desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.(animal AND EXISTS has.TOP)))");
+ desiredString.add("(human AND EXISTS hasPet.(bird AND cat))");
+ desiredString.add("(human AND (EXISTS has.(animal AND EXISTS has.TOP) AND EXISTS hasPet.bird))");
+ desiredString.add("(human AND (EXISTS has.(bird AND EXISTS has.TOP) AND EXISTS hasPet.bird))");
+ desiredString.add("(human AND EXISTS hasPet.(bird AND EXISTS has.TOP))");
ConceptComparator cc = new ConceptComparator();
SortedSet<Description> desired = new TreeSet<Description>(cc);
@@ -191,6 +199,13 @@
System.out.println("desired: " + tmp.toString(KBParser.internalNamespace, null));
}
+ Logger logger = Logger.getRootLogger();
+ logger.setLevel(Level.TRACE);
+ SimpleLayout layout = new SimpleLayout();
+ FileAppender app = new FileAppender(layout, "log/el/test_no_dr.txt", false);
+ logger.removeAllAppenders();
+ logger.addAppender(app);
+
RefinementOperator operator = new ELDown2(rs);
Set<Description> refinements = operator.refine(input);
@@ -208,6 +223,7 @@
@Test
public void test3() throws ParseException, IOException {
System.out.println("TEST 3");
+
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE_NO_DISJOINT);
// input description
@@ -223,7 +239,7 @@
desiredString.add("(human AND (EXISTS hasChild.human AND (EXISTS has.TOP AND EXISTS has.animal)))");
desiredString.add("(human AND (EXISTS hasChild.human AND EXISTS has.(animal AND EXISTS has.TOP)))");
desiredString.add("(human AND (EXISTS hasChild.human AND (EXISTS has.animal AND EXISTS has.EXISTS has.TOP)))");
-
+
ConceptComparator cc = new ConceptComparator();
SortedSet<Description> desired = new TreeSet<Description>(cc);
for(String str : desiredString) {
@@ -234,6 +250,13 @@
System.out.println("desired: " + tmp.toString(KBParser.internalNamespace, null));
}
+ Logger logger = Logger.getRootLogger();
+ logger.setLevel(Level.TRACE);
+ SimpleLayout layout = new SimpleLayout();
+ FileAppender app = new FileAppender(layout, "log/el/test_no_disjoint.txt", false);
+ logger.removeAllAppenders();
+ logger.addAppender(app);
+
RefinementOperator operator = new ELDown2(rs);
Set<Description> refinements = operator.refine(input);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-24 20:02:36
|
Revision: 1580
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1580&view=rev
Author: jenslehmann
Date: 2009-01-24 20:02:30 +0000 (Sat, 24 Jan 2009)
Log Message:
-----------
new as method for EL operator 2
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTreeComparator.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSet.java
trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSetComparator.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -112,6 +112,7 @@
// this is the root node of the overall tree
tree.rootNode = this;
tree.addNodeToLevel(this, level);
+ tree.size += label.size();
}
// convenience constructor
@@ -194,6 +195,8 @@
extendLabel(nc);
}
+ // 1 for the edge (labels are already taken care of by extendLabel)
+ tree.size += 1;
}
/**
@@ -339,6 +342,9 @@
public void extendLabel(NamedClass newClass) {
label.add(newClass);
labelSimulationUpdate();
+ tree.size += 1;
+// System.out.println(tree);
+// System.out.println(tree.size);
}
// simulation update when extending or refining label
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -65,6 +65,8 @@
// max level = 0 means that there is no tree at all
// (max level = 1 means the root node exists)
private int maxLevel = 0;
+
+ protected int size = 1;
protected ELDescriptionNode rootNode;
@@ -533,6 +535,7 @@
// update global tree
treeClone.rootNode = newRoot;
treeClone.maxLevel = maxLevel;
+ treeClone.size = size;
// nodes
treeClone.nodes = new LinkedList<ELDescriptionNode>();
@@ -604,10 +607,10 @@
* @return The tree size.
*/
public int getSize() {
- int size = nodes.size();
- for(ELDescriptionNode node : nodes) {
- size += node.getLabel().size();
- }
+// int size = nodes.size();
+// for(ELDescriptionNode node : nodes) {
+// size += node.getLabel().size();
+// }
return size;
}
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTreeComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTreeComparator.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTreeComparator.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -41,9 +41,15 @@
*/
@Override
public int compare(ELDescriptionTree tree1, ELDescriptionTree tree2) {
- ELDescriptionNode node1 = tree1.getRootNode();
- ELDescriptionNode node2 = tree2.getRootNode();
- return nodeComp.compare(node1, node2);
+ // we use the size as first criterion to avoid many comparisons
+ int sizeDiff = tree1.size - tree2.size;
+ if(sizeDiff == 0) {
+ ELDescriptionNode node1 = tree1.getRootNode();
+ ELDescriptionNode node2 = tree2.getRootNode();
+ return nodeComp.compare(node1, node2);
+ } else {
+ return sizeDiff;
+ }
}
}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSet.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSet.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSet.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2007-2009, 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.el;
+
+import java.util.Set;
+
+import org.dllearner.core.owl.ObjectProperty;
+
+/**
+ * Convenience class representing an EL description tree and a set of roles.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class TreeAndRoleSet {
+
+ private ELDescriptionTree tree;
+ private Set<ObjectProperty> roles;
+
+ public TreeAndRoleSet(ELDescriptionTree tree, Set<ObjectProperty> roles) {
+ this.tree = tree;
+ this.roles = roles;
+ }
+
+ /**
+ * @return the tree
+ */
+ public ELDescriptionTree getTree() {
+ return tree;
+ }
+
+ /**
+ * @return the roles
+ */
+ public Set<ObjectProperty> getRoles() {
+ return roles;
+ }
+
+ @Override
+ public String toString() {
+ return "("+tree.toDescriptionString() + "," + roles.toString()+")";
+ }
+
+}
Added: trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSetComparator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSetComparator.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/TreeAndRoleSetComparator.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -0,0 +1,66 @@
+/**
+ * Copyright (C) 2007-2009, 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.el;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.dllearner.core.owl.ObjectProperty;
+
+/**
+ * A comparator implementation for the tree and role set convenience structure.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class TreeAndRoleSetComparator implements Comparator<TreeAndRoleSet> {
+
+ private ELDescriptionTreeComparator treeComp = new ELDescriptionTreeComparator();
+
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public int compare(TreeAndRoleSet o1, TreeAndRoleSet o2) {
+ int comp = treeComp.compare(o1.getTree(), o2.getTree());
+ if(comp == 0) {
+ Set<ObjectProperty> op1 = o1.getRoles();
+ Set<ObjectProperty> op2 = o2.getRoles();
+ int sizeDiff = op1.size() - op2.size();
+ if(sizeDiff == 0) {
+ Iterator<ObjectProperty> it1 = op1.iterator();
+ Iterator<ObjectProperty> it2 = op2.iterator();
+ while(it1.hasNext()) {
+ int stringComp = it1.next().compareTo(it2.next());
+ if(stringComp != 0) {
+ return stringComp;
+ }
+ }
+ return 0;
+ } else {
+ return sizeDiff;
+ }
+ } else {
+ return comp;
+ }
+ }
+
+}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -38,6 +38,9 @@
import org.dllearner.algorithms.el.ELDescriptionEdgeComparator;
import org.dllearner.algorithms.el.ELDescriptionNode;
import org.dllearner.algorithms.el.ELDescriptionTree;
+import org.dllearner.algorithms.el.ELDescriptionTreeComparator;
+import org.dllearner.algorithms.el.TreeAndRoleSet;
+import org.dllearner.algorithms.el.TreeAndRoleSetComparator;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Intersection;
@@ -95,7 +98,9 @@
private Utility utility;
// comparators
- ELDescriptionEdgeComparator edgeComp = new ELDescriptionEdgeComparator();
+ private ELDescriptionTreeComparator treeComp = new ELDescriptionTreeComparator();
+ private ELDescriptionEdgeComparator edgeComp = new ELDescriptionEdgeComparator();
+ private TreeAndRoleSetComparator mComp = new TreeAndRoleSetComparator();
public ELDown2(ReasonerComponent rs) {
this.rs = rs;
@@ -155,7 +160,7 @@
refinements.addAll(extendLabel(tree, v, position));
refinements.addAll(refineLabel(tree, v, position));
refinements.addAll(refineEdge(tree, v, position));
- refinements.addAll(attachSubtree(tree, v, position));
+ refinements.addAll(attachSubtree2(tree, v, position));
}
return refinements;
@@ -251,7 +256,7 @@
}
// operation 4: attach tree
- private List<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ private Collection<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
Monitor mon = MonitorFactory.start("attach tree");
List<ELDescriptionTree> refinements = new LinkedList<ELDescriptionTree>();
@@ -343,6 +348,103 @@
return refinements;
}
+ // new version of as
+ private Collection<ELDescriptionTree> attachSubtree2(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
+ Monitor mon = MonitorFactory.start("attach tree");
+ Set<ELDescriptionTree> refinements = new TreeSet<ELDescriptionTree>(treeComp);
+
+ // create and initialise M
+ TreeSet<TreeAndRoleSet> m = new TreeSet<TreeAndRoleSet>(mComp);
+ ELDescriptionTree topTree = new ELDescriptionTree(rs, Thing.instance);
+ Description index = getIndex(v);
+ SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index);
+ m.add(new TreeAndRoleSet(topTree, appOPs));
+
+// logger.trace("M initialised: " + m);
+
+ while(!m.isEmpty()) {
+
+ // pick first element of M
+ TreeAndRoleSet tars = m.pollFirst();
+ ELDescriptionTree tp = tars.getTree();
+ Set<ObjectProperty> rSet = tars.getRoles();
+// logger.trace("selected first element of M: " + tars);
+
+
+ // init sets R' and R''
+ // more efficient
+ SortedSet<ObjectProperty> rpSet = utility.computeMgr(appOPs);
+ rpSet.retainAll(rSet);
+// SortedSet<ObjectProperty> rpSet = new TreeSet<ObjectProperty>();
+// for(ObjectProperty rEl : rSet) {
+// if(!containsSuperProperty(rEl, rSet)) {
+// rpSet.add(rEl);
+// }
+// }
+
+// logger.trace("R': " + rpSet);
+ Set<ObjectProperty> rppSet = new TreeSet<ObjectProperty>();
+
+ while(!rpSet.isEmpty()) {
+ // pick an element r from R'
+ Iterator<ObjectProperty> it = rpSet.iterator();
+ ObjectProperty r = it.next();
+ it.remove();
+// logger.trace("picked role r: " + r);
+
+ ELDescriptionTree tpp = mergeTrees(tree, v, position, r, tp);
+// logger.trace("merged tree:\n" + tpp);
+ // the position of w is the position of v + #edges outgoing from v
+ int[] wPosition = new int[position.length+1];
+ System.arraycopy(position, 0, wPosition, 0, position.length);
+ wPosition[position.length] = v.getEdges().size();
+ ELDescriptionNode w = tpp.getNode(wPosition);
+
+ if(tpp.isMinimal()) {
+ refinements.add(tpp);
+// logger.trace("tree is minimal; added to T");
+ } else {
+ boolean check = asCheck(w);
+// logger.trace("tree is not minimal; result of complex check: " + check);
+
+ if(check) {
+
+// Monitor mon2 = MonitorFactory.start("as.tmp");
+ // add role to R' if it is in R (allowed)
+ for(ObjectProperty subRole : rs.getSubProperties(r)) {
+ if(rSet.contains(subRole)) {
+ rpSet.add(subRole);
+ }
+ }
+ rppSet.add(r);
+// logger.trace("updated R' to: " + rpSet);
+// logger.trace("updated R'' to: " + rppSet);
+// mon2.stop();
+ }
+ }
+ }
+
+ if(rppSet.size() != 0) {
+ // recursive call
+ mon.stop();
+// logger.trace("recursive call start");
+ List<ELDescriptionTree> recRefs = refine(tp);
+// logger.trace("recursive call end");
+ mon.start();
+
+ for(ELDescriptionTree tStar : recRefs) {
+ m.add(new TreeAndRoleSet(tStar, rppSet));
+ }
+// logger.trace("M after recursion: " + m);
+ }
+
+ }
+
+ mon.stop();
+ return refinements;
+ }
+
+
// create a new tree which is obtained by attaching the new tree at the given node in the tree via role r
private ELDescriptionTree mergeTrees(ELDescriptionTree tree, ELDescriptionNode node, int[] position, ObjectProperty r, ELDescriptionTree newTree) {
Monitor mon = MonitorFactory.start("as.merge trees");
@@ -472,4 +574,23 @@
return i;
}
+ private Description getIndex(ELDescriptionNode v) {
+ if(v.isRoot()) {
+ return Thing.instance;
+ } else {
+ return opRanges.get(v.getParentEdge().getLabel());
+ }
+ }
+
+ private boolean containsSuperProperty(ObjectProperty prop, Set<ObjectProperty> props) {
+ for(ObjectProperty p : props) {
+ if(!p.equals(prop)) {
+ if(opHierarchy.isSubpropertyOf(prop, p)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -71,9 +71,10 @@
new File(dir).mkdir();
String example = "/home/jl/promotion/ontologien/galen2.owl";
+// example = "/home/jl/downloads/uni-leipzig/OTAGen-v1/generated/generatedOnt.owl";
for(int i=10; i<17; i++) {
- rand = new Random(2);
+ rand = new Random(1);
testOntology(dir, example, 100, i);
}
@@ -217,7 +218,7 @@
statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms."));
statString += getMonitorData(MonitorFactory.getMonitor("as.merge trees", "ms."));
statString += getMonitorData(MonitorFactory.getMonitor("as.complex check", "ms."));
-// statString += getMonitorData(MonitorFactory.getMonitor("as.tmp", "ms."));
+ statString += getMonitorData(MonitorFactory.getMonitor("as.tmp", "ms."));
// statString += getMonitorData(MonitorFactory.getMonitor("el.tmp", "ms."));
statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean"));
statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean"));
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-18 16:41:36 UTC (rev 1579)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-24 20:02:30 UTC (rev 1580)
@@ -82,6 +82,17 @@
System.out.println("TEST 1");
ReasonerComponent rs = TestOntologies.getTestOntology(TestOntology.SIMPLE);
+// ELDescriptionTree t = new ELDescriptionTree(rs);
+// ObjectProperty p1 = new ObjectProperty("p1");
+// ObjectProperty p2 = new ObjectProperty("p2");
+// NamedClass a1 = new NamedClass("a1");
+// ELDescriptionNode n1 = new ELDescriptionNode(t, a1);
+// ELDescriptionNode n2 = new ELDescriptionNode(n1, p1, a1);
+//
+// System.out.println(t);
+// System.out.println(t.getSize());
+// System.exit(0);
+
// input description
Description input = KBParser.parseConcept("(human AND EXISTS has.animal)");
System.out.println("refining: " + input.toString(KBParser.internalNamespace, null));
@@ -179,6 +190,7 @@
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS has.human))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS has.cat))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS has.EXISTS has.TOP))");
+ desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS has.(cat AND bird)))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.cat))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasPet.EXISTS has.TOP))");
desiredString.add("(human AND (EXISTS hasPet.bird AND EXISTS hasChild.TOP))");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-25 14:15:48
|
Revision: 1581
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1581&view=rev
Author: jenslehmann
Date: 2009-01-25 14:15:39 +0000 (Sun, 25 Jan 2009)
Log Message:
-----------
operator benchmark ctd.
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-24 20:02:30 UTC (rev 1580)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-25 14:15:39 UTC (rev 1581)
@@ -400,11 +400,14 @@
wPosition[position.length] = v.getEdges().size();
ELDescriptionNode w = tpp.getNode(wPosition);
- if(tpp.isMinimal()) {
+ boolean minimal = tpp.isMinimal();
+ MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
+ if(minimal) {
refinements.add(tpp);
// logger.trace("tree is minimal; added to T");
} else {
boolean check = asCheck(w);
+ MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
// logger.trace("tree is not minimal; result of complex check: " + check);
if(check) {
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-24 20:02:30 UTC (rev 1580)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-25 14:15:39 UTC (rev 1581)
@@ -67,26 +67,47 @@
// create a directory for log files
Date dt = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
- String dir = "log/el/" + df.format(dt) + "/";
- new File(dir).mkdir();
+ String statDir = "log/el/" + df.format(dt) + "/";
+ new File(statDir).mkdir();
- String example = "/home/jl/promotion/ontologien/galen2.owl";
-// example = "/home/jl/downloads/uni-leipzig/OTAGen-v1/generated/generatedOnt.owl";
+ // single ontology test
+// String example = "/home/jl/promotion/ontologien/galen2.owl";
+// for(int i=10; i<17; i++) {
+// rand = new Random(1);
+// testOntology(statDir, example, 100, i);
+// }
- for(int i=10; i<17; i++) {
+ // real world ontology tests //
+ String base = "/home/jl/promotion/ontologien/el_benchmark/";
+ String[] onts = new String[] {"galen2", "cton", "earthrealm", "fma_owl_dl_component_1.4.0",
+ "iso_19115", "nci", "process", "pto", "tambis", "thesaurus", "transportation"};
+
+ for(String ont : onts) {
+ String file = base + ont + ".owl";
rand = new Random(1);
- testOntology(dir, example, 100, i);
+ testOntology(statDir, file, 100, 10);
}
- System.exit(0);
+ // artificial ontology tests //
- /* TEST ON ARTIFICIAL ONTOLOGIES
-
-
// number of concepts and roles
- int[] conceptCounts = new int[] { 5, 10 };
- int[] roleCounts = new int[] { 5, 10};
+ int[] conceptCounts = new int[] { 5, 10, 50, 100 }; //, 500, 1000 };
+ int[] roleCounts = new int[] { 5, 10, 50, 100, 500, 1000};
+ base = "/home/jl/downloads/uni-leipzig/OTAGen-v1/generated/generated_";
+ // loop through all artificial ontologies
+ for(int conceptCount : conceptCounts) {
+ for(int roleCount : roleCounts) {
+ String file = base + "c" + conceptCount + "_r" + roleCount + ".owl";
+ rand = new Random(1);
+ testOntology(statDir, file, 100, 10);
+ }
+ }
+
+ System.exit(0);
+
+ /*
+
// number of applications of operator
int opApplications = 10;
@@ -218,7 +239,7 @@
statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms."));
statString += getMonitorData(MonitorFactory.getMonitor("as.merge trees", "ms."));
statString += getMonitorData(MonitorFactory.getMonitor("as.complex check", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("as.tmp", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("as.tmp", "ms."));
// statString += getMonitorData(MonitorFactory.getMonitor("el.tmp", "ms."));
statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean"));
statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean"));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-01-26 13:15:30
|
Revision: 1583
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1583&view=rev
Author: jenslehmann
Date: 2009-01-26 11:55:26 +0000 (Mon, 26 Jan 2009)
Log Message:
-----------
benchmarks with monitoring mostly deactivated
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -137,7 +137,7 @@
tree.addNodeToLevel(this, level);
// simulation update
- Monitor mon = MonitorFactory.start("simulation update");
+// Monitor mon = MonitorFactory.start("simulation update");
// the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
@@ -188,7 +188,7 @@
// apply updates recursively top-down
tree.updateSimulation(update);
- mon.stop();
+// mon.stop();
// add all classes in label
for(NamedClass nc : label) {
@@ -350,7 +350,7 @@
// simulation update when extending or refining label
// (same in both cases)
private void labelSimulationUpdate() {
- Monitor mon = MonitorFactory.start("simulation update");
+// Monitor mon = MonitorFactory.start("simulation update");
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
@@ -411,13 +411,13 @@
// apply updates recursively top-down
tree.updateSimulation(update);
- mon.stop();
+// mon.stop();
}
public void refineEdge(int edgeNumber, ObjectProperty op) {
edges.get(edgeNumber).setLabel(op);
- Monitor mon = MonitorFactory.start("simulation update");
+// Monitor mon = MonitorFactory.start("simulation update");
// compute the nodes, which need to be updated
Set<ELDescriptionNode> update = new HashSet<ELDescriptionNode>();
update.add(this);
@@ -451,7 +451,7 @@
// apply updates recursively top-down
tree.updateSimulation(update);
- mon.stop();
+// mon.stop();
}
/**
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -42,9 +42,6 @@
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.UnsupportedLanguageException;
-import com.jamonapi.Monitor;
-import com.jamonapi.MonitorFactory;
-
/**
* Represents an EL description tree. Unlike {@link ELDescriptionNode}, this is
* a tree-wide structure, i.e. it does not implement the tree structure itself,
@@ -467,7 +464,7 @@
@Override
@SuppressWarnings("unchecked")
public ELDescriptionTree clone() {
- Monitor mon = MonitorFactory.start("tree clone");
+// Monitor mon = MonitorFactory.start("tree clone");
// clone "global" tree
ELDescriptionTree treeClone = new ELDescriptionTree(rs);
@@ -553,7 +550,7 @@
treeClone.levelNodeMapping.put(i, newNodes);
}
- mon.stop();
+// mon.stop();
return treeClone;
}
Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown2.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -51,8 +51,8 @@
import org.dllearner.core.owl.Thing;
import org.dllearner.utilities.Helper;
-import com.jamonapi.Monitor;
-import com.jamonapi.MonitorFactory;
+//import com.jamonapi.Monitor;
+//import com.jamonapi.MonitorFactory;
/**
* EL downward refinement operator constructed by Jens Lehmann
@@ -168,7 +168,7 @@
// operation 1: label extension
private List<ELDescriptionTree> extendLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
- Monitor mon = MonitorFactory.start("extend label");
+// Monitor mon = MonitorFactory.start("extend label");
List<ELDescriptionTree> refinements = new LinkedList<ELDescriptionTree>();
// the index is the range of role in the edge pointing to the parent of this node
@@ -193,13 +193,13 @@
}
}
- mon.stop();
+// mon.stop();
return refinements;
}
// operation 2: label refinement
private List<ELDescriptionTree> refineLabel(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
- Monitor mon = MonitorFactory.start("refine label");
+// Monitor mon = MonitorFactory.start("refine label");
List<ELDescriptionTree> refinements = new LinkedList<ELDescriptionTree>();
// loop through all classes in label
@@ -220,13 +220,13 @@
}
}
}
- mon.stop();
+// mon.stop();
return refinements;
}
// operation 3: refine edge
private List<ELDescriptionTree> refineEdge(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
- Monitor mon = MonitorFactory.start("refine edge");
+// Monitor mon = MonitorFactory.start("refine edge");
List<ELDescriptionTree> refinements = new LinkedList<ELDescriptionTree>();
for(int edgeNumber = 0; edgeNumber < v.getEdges().size(); edgeNumber++) {
@@ -251,13 +251,13 @@
}
}
}
- mon.stop();
+// mon.stop();
return refinements;
}
// operation 4: attach tree
private Collection<ELDescriptionTree> attachSubtree(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
- Monitor mon = MonitorFactory.start("attach tree");
+// Monitor mon = MonitorFactory.start("attach tree");
List<ELDescriptionTree> refinements = new LinkedList<ELDescriptionTree>();
// compute the set of most general roles such that the domain of each role is not disjoint
@@ -311,7 +311,7 @@
// we check equivalence by a minimality test (TODO: can we still do this?)
boolean minimal = mergedTree.isMinimal();
- MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
+// MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
if(minimal) {
logger.trace("Merged tree is minimal, i.e. not equivalent.");
// it is not equivalent, i.e. we found a refinement
@@ -321,7 +321,7 @@
// perform complex check in merged tree
boolean check = asCheck(wClone);
logger.trace("Result of complex check: " + check);
- MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
+// MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
if(check) {
// refine property
@@ -331,9 +331,9 @@
// refine tree using recursive operator call
logger.trace("Recursive Call");
// do not monitor recursive calls (counts time twice or more)
- mon.stop();
+// mon.stop();
List<ELDescriptionTree> recRefs = refine(tp);
- mon.start();
+// mon.start();
logger.trace("Recursive Call Done");
for(ELDescriptionTree tpp : recRefs) {
m.add(new ELDescriptionEdge(r, tpp.getRootNode()));
@@ -344,13 +344,13 @@
logger.trace("M: " + m);
}
}
- mon.stop();
+// mon.stop();
return refinements;
}
// new version of as
private Collection<ELDescriptionTree> attachSubtree2(ELDescriptionTree tree, ELDescriptionNode v, int[] position) {
- Monitor mon = MonitorFactory.start("attach tree");
+// Monitor mon = MonitorFactory.start("attach tree");
Set<ELDescriptionTree> refinements = new TreeSet<ELDescriptionTree>(treeComp);
// create and initialise M
@@ -401,13 +401,13 @@
ELDescriptionNode w = tpp.getNode(wPosition);
boolean minimal = tpp.isMinimal();
- MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
+// MonitorFactory.add("as.minimal", "boolean", minimal ? 1 : 0);
if(minimal) {
refinements.add(tpp);
// logger.trace("tree is minimal; added to T");
} else {
boolean check = asCheck(w);
- MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
+// MonitorFactory.add("as.check", "boolean", check ? 1 : 0);
// logger.trace("tree is not minimal; result of complex check: " + check);
if(check) {
@@ -429,11 +429,11 @@
if(rppSet.size() != 0) {
// recursive call
- mon.stop();
+// mon.stop();
// logger.trace("recursive call start");
List<ELDescriptionTree> recRefs = refine(tp);
// logger.trace("recursive call end");
- mon.start();
+// mon.start();
for(ELDescriptionTree tStar : recRefs) {
m.add(new TreeAndRoleSet(tStar, rppSet));
@@ -443,14 +443,14 @@
}
- mon.stop();
+// mon.stop();
return refinements;
}
// create a new tree which is obtained by attaching the new tree at the given node in the tree via role r
private ELDescriptionTree mergeTrees(ELDescriptionTree tree, ELDescriptionNode node, int[] position, ObjectProperty r, ELDescriptionTree newTree) {
- Monitor mon = MonitorFactory.start("as.merge trees");
+// Monitor mon = MonitorFactory.start("as.merge trees");
// System.out.println("merge start");
// System.out.println(tree);
// System.out.println(newTree);
@@ -497,13 +497,13 @@
// mon2.stop();
- mon.stop();
+// mon.stop();
return mergedTree;
}
// TODO: variables have been renamed in article
public boolean asCheck(ELDescriptionNode v) {
- Monitor mon = MonitorFactory.start("as.complex check");
+// Monitor mon = MonitorFactory.start("as.complex check");
// System.out.println("asCheck: " + v.getTree().toSimulationString());
// find all edges up to the root node
@@ -541,7 +541,7 @@
}
}
- mon.stop();
+// mon.stop();
return true;
}
Modified: trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/scripts/evaluation/ELOperatorBenchmark.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -86,43 +86,45 @@
"cton",
// is ok at length 8
"earthrealm2",
- // cannot even be read "fma_owl_dl_component_1.4.0",
- // ontology file seems broken "iso_19115",
- // ontology file seems broken "nci",
// is ok at length 8
"process",
- // takes too long to read in "pto",
// is ok at length 8
"tambis",
// ontology file seems broken "thesaurus",
// is ok at length 8
- "transportation"
+ "transportation",
+ // takes too long to read in
+ "pto",
+ // ontology file seems broken "iso_19115",
+ // ontology file seems broken "nci",
+ // cannot even be read
+ "fma_owl_dl_component_1.4.0"
};
for(String ont : onts) {
String file = base + ont + ".owl";
rand = new Random(1);
- testOntology(statDir, file, 100, 8);
+ testOntology(statDir, file, 100, 7);
}
// artificial ontology tests //
-
+ /*
// number of concepts and roles
int[] conceptCounts = new int[] { 5, 10, 50, 100 }; //, 500, 1000 };
int[] roleCounts = new int[] { 5, 10, 50, 100, 500, 1000};
- base = "/home/jl/downloads/uni-leipzig/OTAGen-v1/generated/generated_";
+ String base = "/home/jl/downloads/uni-leipzig/OTAGen-v1/generated/generated_";
// loop through all artificial ontologies
for(int conceptCount : conceptCounts) {
for(int roleCount : roleCounts) {
String file = base + "c" + conceptCount + "_r" + roleCount + ".owl";
rand = new Random(1);
- testOntology(statDir, file, 100, 9);
+ testOntology(statDir, file, 100, 7);
}
}
System.exit(0);
-
+ */
/*
// number of applications of operator
@@ -190,6 +192,7 @@
File statFile = new File(statDir + statFileName);
String statString = "";
+ int refinementMaxSizeOverall = 0;
MonitorFactory.reset();
for(int loop = 0; loop < nrOfChains; loop++) {
@@ -216,18 +219,32 @@
int sizeSum = 0;
for(ELDescriptionTree tree : refinements) {
// System.out.println(" " + tree.toDescriptionString());
- sizeSum += tree.getSize();
+ int size = tree.getSize();
+ sizeSum += size;
+ refinementMaxSizeOverall = Math.max(size, refinementMaxSizeOverall);
}
MonitorFactory.add("refinement size", "count", sizeSum/(double)refinements.size());
MonitorFactory.add("refinement size increase", "count", (sizeSum-refinements.size()*currTree.getSize())/(double)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)
+
+ // pick a refinement randomly - this has the disadvantage that we have huge
+ // variations over different runs
int index = rand.nextInt(refinements.size());
-// currTree = new ArrayList<ELDescriptionTree>(refinements).get(index);
currTree = refinements.get(index);
+
+ // we pick a/the median of the refinements as next refinement
+// ELDescriptionTreeComparator treeComp = new ELDescriptionTreeComparator();
+// TreeSet<ELDescriptionTree> refinementsSet = new TreeSet<ELDescriptionTree>(treeComp);
+// refinementsSet.addAll(refinements);
+// List<ELDescriptionTree> refinementList = new LinkedList<ELDescriptionTree>(refinements);
+ // sort by size (first criterion of comparator)
+// Collections.sort(refinementList, treeComp);
+// currTree = refinementList.get((int)(refinementList.size()*0.5));
+// System.out.println(rand.nextGaussian());
+// currTree = refinementList.get((int)(refinementList.size()*rand.nextGaussian()));
+
MonitorFactory.add("picked refinement size", "count", currTree.getSize());
}
System.out.println("operator time: " + runtime.prettyPrint("ms"));
@@ -246,23 +263,26 @@
statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement count", "count"));
statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size", "count"));
+ statString += "refinement max size overall: " + refinementMaxSizeOverall + "\n";
statString += getMonitorDataCount(MonitorFactory.getMonitor("picked refinement size", "count"));
statString += getMonitorDataCount(MonitorFactory.getMonitor("refinement size increase", "count"));
statString += "\n";
- statString += getMonitorData(MonitorFactory.getMonitor("extend label", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("refine label", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("refine edge", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("as.merge trees", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("as.complex check", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("extend label", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("refine label", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("refine edge", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("attach tree", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("as.merge trees", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("as.complex check", "ms."));
// statString += getMonitorData(MonitorFactory.getMonitor("as.tmp", "ms."));
// statString += getMonitorData(MonitorFactory.getMonitor("el.tmp", "ms."));
- statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean"));
- statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean"));
- statString += getMonitorData(MonitorFactory.getMonitor("tree clone", "ms."));
- statString += getMonitorData(MonitorFactory.getMonitor("simulation update", "ms."));
+// statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.minimal", "boolean"));
+// statString += getMonitorDataBoolean(MonitorFactory.getMonitor("as.check", "boolean"));
+// statString += getMonitorData(MonitorFactory.getMonitor("tree clone", "ms."));
+// statString += getMonitorData(MonitorFactory.getMonitor("simulation update", "ms."));
statString += getMonitorData(MonitorFactory.getMonitor("disjointness reasoning", "ms."));
+ double reasoningPercentage = 100 * MonitorFactory.getMonitor("disjointness reasoning", "ms.").getTotal()/MonitorFactory.getMonitor("operator application time", "ms.").getTotal();
+ statString += "disjointness reasoning percentage: " + df.format(reasoningPercentage) + "%\n";
Files.createFile(statFile, statString);
@@ -278,6 +298,7 @@
return mon.getLabel() + ": av " + df.format(mon.getAvg()) + " (stddev " + df.format(mon.getStdDev()) + ", min " + df.format(mon.getMin()) + ", max " + df.format(mon.getMax()) + ", " + df.format(mon.getTotal()) + " total, " + (int)mon.getHits() + " hits)\n";
}
+ @SuppressWarnings("unused")
private static String getMonitorDataBoolean(Monitor mon) {
return mon.getLabel() + ": " + df.format(mon.getAvg()*100) + "%\n";
}
Modified: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -66,6 +66,7 @@
*/
public class ELDownTests {
+ @SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ELDownTests.class);
/**
Modified: trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-01-25 19:16:38 UTC (rev 1582)
+++ trunk/src/dl-learner/org/dllearner/test/junit/TestOntologies.java 2009-01-26 11:55:26 UTC (rev 1583)
@@ -36,7 +36,7 @@
*/
public final class TestOntologies {
- public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES };
+ public enum TestOntology { EMPTY, SIMPLE, SIMPLE_NO_DR, SIMPLE_NO_DISJOINT, SIMPLE_NO_DR_DISJOINT, SIMPLE2, SIMPLE3, R1SUBR2, DATA1, FIVE_ROLES };
public static ReasonerComponent getTestOntology(TestOntology ont) {
String kbString = "";
@@ -70,6 +70,12 @@
kbString += "bird SUB animal.\n";
kbString += "cat SUB animal.\n";
kbString += "human SUB TOP.\n";
+ } else if(ont.equals(TestOntology.SIMPLE_NO_DR_DISJOINT)) {
+ kbString += "Subrole(hasChild, has).\n";
+ kbString += "Subrole(hasPet, has).\n";
+ kbString += "bird SUB animal.\n";
+ kbString += "cat SUB animal.\n";
+ kbString += "human SUB TOP.\n";
} else if(ont.equals(TestOntology.SIMPLE2)) {
kbString += "Subrole(r2,r3).\n";
kbString += "a1 SUB TOP.\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ku...@us...> - 2009-02-06 10:22:02
|
Revision: 1586
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1586&view=rev
Author: kurzum
Date: 2009-02-06 10:21:58 +0000 (Fri, 06 Feb 2009)
Log Message:
-----------
configurator adaption
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java
trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java
trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
trunk/src/dl-learner/org/dllearner/utilities/Files.java
Property Changed:
----------------
trunk/src/dl-learner/org/dllearner/utilities/
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/BruteForceLearnerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -30,7 +30,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class BruteForceLearnerConfigurator implements Configurator {
+public class BruteForceLearnerConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/DBpediaNavigationSuggestorConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -31,7 +31,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class DBpediaNavigationSuggestorConfigurator implements Configurator {
+public class DBpediaNavigationSuggestorConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/DIGReasonerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class DIGReasonerConfigurator implements Configurator {
+public class DIGReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ELLearningAlgorithmConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -30,7 +30,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class ELLearningAlgorithmConfigurator implements Configurator {
+public class ELLearningAlgorithmConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ExampleBasedROLComponentConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -31,7 +31,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class ExampleBasedROLComponentConfigurator implements Configurator {
+public class ExampleBasedROLComponentConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/FastInstanceCheckerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class FastInstanceCheckerConfigurator implements Configurator {
+public class FastInstanceCheckerConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/FastRetrievalReasonerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class FastRetrievalReasonerConfigurator implements Configurator {
+public class FastRetrievalReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/GPConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -30,7 +30,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class GPConfigurator implements Configurator {
+public class GPConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/KBFileConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -28,7 +28,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class KBFileConfigurator implements Configurator {
+public class KBFileConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIOntologyConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -27,7 +27,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class OWLAPIOntologyConfigurator implements Configurator {
+public class OWLAPIOntologyConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLAPIReasonerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class OWLAPIReasonerConfigurator implements Configurator {
+public class OWLAPIReasonerConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/OWLFileConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -28,7 +28,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class OWLFileConfigurator implements Configurator {
+public class OWLFileConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class PosNegDefinitionLPConfigurator implements Configurator {
+public class PosNegDefinitionLPConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegDefinitionLPStrictConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class PosNegDefinitionLPStrictConfigurator implements Configurator {
+public class PosNegDefinitionLPStrictConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosNegInclusionLPConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class PosNegInclusionLPConfigurator implements Configurator {
+public class PosNegInclusionLPConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyDefinitionLPConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class PosOnlyDefinitionLPConfigurator implements Configurator {
+public class PosOnlyDefinitionLPConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/PosOnlyInclusionLPConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -29,7 +29,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class PosOnlyInclusionLPConfigurator implements Configurator {
+public class PosOnlyInclusionLPConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/ROLearnerConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -26,12 +26,13 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.utilities.Files;
/**
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class ROLearnerConfigurator implements Configurator {
+public class ROLearnerConfigurator extends Files implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/RandomGuesserConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -30,7 +30,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class RandomGuesserConfigurator implements Configurator {
+public class RandomGuesserConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/SimpleSuggestionLearningAlgorithmConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -30,7 +30,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class SimpleSuggestionLearningAlgorithmConfigurator implements Configurator {
+public class SimpleSuggestionLearningAlgorithmConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/core/configurators/SparqlKnowledgeSourceConfigurator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -31,7 +31,7 @@
* automatically generated, do not edit manually.
* run org.dllearner.scripts.ConfigJavaGenerator to update
**/
-public class SparqlKnowledgeSourceConfigurator implements Configurator {
+public class SparqlKnowledgeSourceConfigurator implements Configurator {
private boolean reinitNecessary = false;
@SuppressWarnings("unused")
Modified: trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/scripts/ConfigJavaGenerator.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -21,6 +21,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -37,6 +38,7 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.ReasonerComponent;
+import org.dllearner.core.configurators.ROLearnerConfigurator;
import org.dllearner.core.options.ConfigOption;
import org.dllearner.utilities.Files;
@@ -50,6 +52,22 @@
*
*/
public final class ConfigJavaGenerator {
+
+ private static final SortedSet<String> DONOTDELETE =
+ new TreeSet<String>(Arrays.asList(new String[]{
+ ".svn",
+ ".svn",
+ }));
+
+ // currently it targets the configurators for
+ private static final SortedSet<String> EXTENDSREFINEMENTOPERATOR =
+ new TreeSet<String>(Arrays.asList(new String[]{
+ ROLearnerConfigurator.class.getSimpleName(),
+ ROLearnerConfigurator.class.getSimpleName(),
+ }));
+
+ @SuppressWarnings("unchecked")
+ private static final Class EXTENDSREFINEMENTOPERATORCLASS = Files.class;
private static final boolean INCLUDE_UNUSED = false;
@@ -89,6 +107,10 @@
private String className;
private String componentType;
+
+ private String extendS = "";
+
+ //private String implementS = "";
private List<String> body = new ArrayList<String>();
@@ -118,7 +140,21 @@
Files.backupDirectory(TARGET_DIR);
System.out.println("previous classes were backupped to tmp/+System.currentTimeMillis()");
- Files.deleteDir(TARGET_DIR);
+ String[] files = Files.listDir(TARGET_DIR);
+
+ for (String file : files){
+ //System.out.println(DONOTDELETE);
+
+ if(DONOTDELETE.contains(file)){
+ continue;
+ }
+ //System.out.println(file);
+ String todelete = TARGET_DIR + File.separator + file;
+ Files.deleteFile(todelete);
+
+ }
+ //System.exit(0);
+ //Files.deleteDir(TARGET_DIR);
ComponentManager cm = ComponentManager.getInstance();
COMPONENT_FACTORY_IMPORTS.add(KnowledgeSource.class.getCanonicalName());
@@ -200,10 +236,12 @@
System.out.println("Done");
}
+
+
private ConfigJavaGenerator(Class<? extends Component> component,
String componentType) {
- className = component.getSimpleName();
+ this.className = component.getSimpleName();
this.component = component;
this.componentType = componentType;
imports.add(component.getCanonicalName());
@@ -211,9 +249,14 @@
// imports.add(Configurator.class.getCanonicalName());
// imports.add(ConfigEntry.class.getCanonicalName());
- vars
- .add("private " + className + " " + deCapitalize(className)
+ vars.add("private " + className + " " + deCapitalize(className)
+ ";\n");
+
+ if(EXTENDSREFINEMENTOPERATOR.contains(this.className+CONFIGURATOR)){
+ this.extendS = EXTENDSREFINEMENTOPERATORCLASS.getSimpleName();
+ this.imports.add(EXTENDSREFINEMENTOPERATORCLASS.getCanonicalName());
+ }
+
}
@@ -265,7 +308,7 @@
TARGET_PACKAGE,
importtmp,
className + CONFIGURATOR,
- "",
+ extendS,
bodytmp ,
"",
CONFIGURATOR);
@@ -494,8 +537,8 @@
ret += fillJavaDocComment(CLASS_COMMENT);
ret += (INCLUDE_UNUSED) ? UNUSED : "";
ret += "public "+classModifier+" class " + className + " "
- + ((extendS.length() > 0) ? "extends " + extendS : "")
- + ((implementS.length() > 0) ? "implements " + implementS : "")
+ + ((extendS.length() > 0) ? " extends " + extendS : "")
+ + ((implementS.length() > 0) ? " implements " + implementS : "")
+ " {\n\n";
ret += body + "\n";
ret += "}\n";
Property changes on: trunk/src/dl-learner/org/dllearner/utilities
___________________________________________________________________
Added: svn:ignore
+ oaiWikipediaReader
Modified: trunk/src/dl-learner/org/dllearner/utilities/Files.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-02-04 12:38:28 UTC (rev 1585)
+++ trunk/src/dl-learner/org/dllearner/utilities/Files.java 2009-02-06 10:21:58 UTC (rev 1586)
@@ -188,6 +188,11 @@
}
}
+
+ public static void deleteFile(String file) {
+ deleteFile(new File(file));
+ }
+
public static void deleteFile(File file) {
try{
@@ -234,6 +239,27 @@
}
/**
+ * lists all files in a directory
+ *
+ *
+ * @param dir without a separator e.g. tmp/dir
+ * @return a string array with filenames
+ */
+ public static String[] listDir(String dir) {
+
+ File f = new File(dir);
+
+ if(debug){
+ System.out.println(dir);
+ System.exit(0);
+ }
+
+ return f.list();
+
+
+ }
+
+ /**
* copies all files in dir to "tmp/"+System.currentTimeMillis()
* @param dir the dir to be backupped
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jen...@us...> - 2009-02-09 16:41:51
|
Revision: 1591
http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1591&view=rev
Author: jenslehmann
Date: 2009-02-09 16:41:44 +0000 (Mon, 09 Feb 2009)
Log Message:
-----------
refactored Score and EvaluatedDescription such that a broader range of learning problems can be implemented (DL-Learner core makes less restrictions)
Modified Paths:
--------------
trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java
trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java
trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java
trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
trunk/src/dl-learner/org/dllearner/cli/Start.java
trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java
trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
trunk/src/dl-learner/org/dllearner/core/Score.java
trunk/src/dl-learner/org/dllearner/gui/RunPanel.java
trunk/src/dl-learner/org/dllearner/learningproblems/ClassScore.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegDefinitionLPStrict.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosNegInclusionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyDefinitionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/PosOnlyInclusionLP.java
trunk/src/dl-learner/org/dllearner/learningproblems/ScoreThreeValued.java
trunk/src/dl-learner/org/dllearner/learningproblems/ScoreTwoValued.java
trunk/src/dl-learner/org/dllearner/scripts/DumbLPFinder.java
trunk/src/dl-learner/org/dllearner/scripts/NewSample.java
trunk/src/dl-learner/org/dllearner/scripts/Sample.java
trunk/src/dl-learner/org/dllearner/scripts/SemanticBible.java
trunk/src/dl-learner/org/dllearner/scripts/SemanticBibleComparison.java
trunk/src/dl-learner/org/dllearner/scripts/TestValidation.java
trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSPARQLReEvaluator.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/ConceptSelector.java
trunk/src/dl-learner/org/dllearner/scripts/improveWikipedia/WikipediaCategoryTasks.java
trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java
trunk/src/dl-learner/org/dllearner/tools/ore/ColumnListCellRenderer.java
trunk/src/dl-learner/org/dllearner/tools/ore/LearningPanelDescriptor.java
trunk/src/dl-learner/org/dllearner/tools/ore/ORE.java
trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java
trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java
trunk/src/dl-learner/org/dllearner/tools/protege/GraphicalCoveragePanel.java
trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java
trunk/src/dl-learner/org/dllearner/tools/protege/ReadingOntologyThread.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionSet.java
Added Paths:
-----------
trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java
trunk/src/dl-learner/org/dllearner/learningproblems/ScorePosNeg.java
trunk/src/dl-learner/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java
Modified: trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/BruteForceLearner.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -26,11 +26,9 @@
import java.util.List;
import java.util.Map;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.BruteForceLearnerConfigurator;
import org.dllearner.core.options.CommonConfigOptions;
import org.dllearner.core.options.ConfigEntry;
@@ -47,6 +45,7 @@
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Thing;
import org.dllearner.core.owl.Union;
+import org.dllearner.learningproblems.ScorePosNeg;
/**
* A brute force learning algorithm.
@@ -70,7 +69,7 @@
private ReasonerComponent rs;
private Description bestDefinition;
- private Score bestScore;
+ private ScorePosNeg bestScore;
//changing this wont have any effect any more
private Integer maxLength = 7;
@@ -173,7 +172,7 @@
double bestScorePoints = Double.NEGATIVE_INFINITY;
int overallCount = 0;
int count = 0;
- Score tmp;
+ ScorePosNeg tmp;
double score;
for(int i=1; i<=maxLength && !stop; i++) {
@@ -193,8 +192,8 @@
} else
newRoot = program;
- tmp = learningProblem.computeScore(newRoot);
- score = tmp.getScore();
+ tmp = (ScorePosNeg) learningProblem.computeScore(newRoot);
+ score = tmp.getScoreValue();
// TODO: find termination criterion
if(score > bestScorePoints) {
@@ -288,7 +287,7 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return bestScore;
}
@@ -298,8 +297,8 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return new EvaluatedDescription(bestDefinition,bestScore);
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
+ return new EvaluatedDescriptionPosNeg(bestDefinition,bestScore);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/DBpediaNavigationSuggestor.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -29,7 +29,6 @@
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.ComponentFactory;
import org.dllearner.core.configurators.DBpediaNavigationSuggestorConfigurator;
import org.dllearner.core.options.BooleanConfigOption;
@@ -43,6 +42,7 @@
import org.dllearner.learningproblems.PosNegDefinitionLP;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
+import org.dllearner.learningproblems.ScorePosNeg;
/**
* The DBpedia Navigation suggestor takes a knowledge fragment extracted
@@ -51,6 +51,9 @@
* implement a completely new learning algorithm itself, but uses the
* example based refinement operator learning algorithm.
*
+ * TODO: This should not be implemented as a learning algorithm (as it does
+ * almost nothing by itself) and maybe can be completely deleted.
+ *
* @author Jens Lehmann
*
*/
@@ -180,17 +183,17 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
return learner.getCurrentlyBestEvaluatedDescription();
}
@Override
- public List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions){
+ public List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions){
return learner.getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, accuracyThreshold, filterNonMinimalDescriptions);
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return learner.getSolutionScore();
}
Copied: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java (from rev 1590, trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java)
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java (rev 0)
+++ trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -0,0 +1,168 @@
+/**
+ * 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.algorithms;
+
+import java.util.Set;
+
+import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.Score;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Individual;
+import org.dllearner.learningproblems.ScorePosNeg;
+import org.dllearner.learningproblems.ScoreTwoValued;
+import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
+import org.dllearner.utilities.owl.OWLAPIRenderers;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.semanticweb.owl.model.OWLDescription;
+
+/**
+ * This represents a class description, which has been
+ * evaluated by the learning algorithm, i.e. it has been checked
+ * which examples it covers. It can be used as return value for
+ * learning algorithms to make it easier for applications to
+ * assess how good an offered class description is and how it
+ * classifies particular examples.
+ *
+ * @author Jens Lehmann
+ *
+ */
+public class EvaluatedDescriptionPosNeg extends EvaluatedDescription {
+
+ private ScorePosNeg score2;
+
+ /**
+ * Constructs an evaluated description using its score.
+ * @param description The description, which was evaluated.
+ * @param score The score of the description.
+ */
+ public EvaluatedDescriptionPosNeg(Description description, ScorePosNeg score) {
+ super(description, score);
+ score2 = (ScorePosNeg) score;
+ }
+
+ /**
+ * Constructs an evaluated description using example coverage.
+ * @param description The description, which was evaluated.
+ * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description.
+ * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description.
+ * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description.
+ * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description.
+ */
+ public EvaluatedDescriptionPosNeg(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) {
+ // usually core methods should not depend on methods outside of the core package (except utilities)
+ // in this case, this is just a convenience constructor
+ super(description, new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg));
+ score2 = (ScorePosNeg) score;
+ }
+
+ /**
+ * @see org.dllearner.learningproblems.ScorePosNeg#getAccuracy()
+ * @return Accuracy of the description.
+ */
+ public double getAccuracy() {
+ return score2.getAccuracy();
+ }
+
+ /**
+ * Gets the score of this description. This can be used to get
+ * further statistical values.
+ * @see org.dllearner.learningproblems.ScorePosNeg
+ * @return The score object associated with this evaluated description.
+ */
+ public ScorePosNeg getScore() {
+ return score2;
+ }
+
+ /**
+ * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredNegatives()
+ * @return Negative examples covered by the description.
+ */
+ public Set<Individual> getCoveredNegatives() {
+ return score2.getCoveredNegatives();
+ }
+
+ /**
+ * @see org.dllearner.learningproblems.ScorePosNeg#getCoveredPositives()
+ * @return Positive examples covered by the description.
+ */
+ public Set<Individual> getCoveredPositives() {
+ return score2.getCoveredPositives();
+ }
+
+ /**
+ * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredNegatives()
+ * @return Negative examples not covered by the description.
+ */
+ public Set<Individual> getNotCoveredNegatives() {
+ return score2.getNotCoveredNegatives();
+ }
+
+ /**
+ * @see org.dllearner.learningproblems.ScorePosNeg#getNotCoveredPositives()
+ * @return Positive examples not covered by the description.
+ */
+ public Set<Individual> getNotCoveredPositives() {
+ return score2.getNotCoveredPositives();
+ }
+
+ /**
+ * This convenience method can be used to store and exchange evaluated
+ * descriptions by transforming them to a JSON string.
+ * @return A JSON representation of an evaluated description.
+ */
+ @Override
+ public String asJSON() {
+ JSONObject object = new JSONObject();
+ try {
+ object.put("descriptionManchesterSyntax", description.toManchesterSyntaxString(null, null));
+ OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description);
+ object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d));
+ object.put("descriptionKBSyntax", description.toKBSyntaxString());
+ object.put("accuracy", score2.getAccuracy());
+ object.put("coveredPositives", getJSONArray(score2.getCoveredPositives()));
+ object.put("coveredNegatives", getJSONArray(score2.getCoveredNegatives()));
+ object.put("notCoveredPositives", getJSONArray(score2.getNotCoveredPositives()));
+ object.put("notCoveredNegatives", getJSONArray(score2.getNotCoveredNegatives()));
+ return object.toString(3);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return description.toString() + "(accuracy: " + getAccuracy() + ")";
+ }
+
+ // we need to use this method instead of the standard JSON array constructor,
+ // otherwise we'll get unexpected results (JSONArray does not take Individuals
+ // as arguments and does not use toString)
+ private static JSONArray getJSONArray(Set<Individual> individuals) {
+ JSONArray j = new JSONArray();
+ for(Individual i : individuals) {
+ j.put(i.getName());
+ }
+ return j;
+ }
+
+}
Property changes on: trunk/src/dl-learner/org/dllearner/algorithms/EvaluatedDescriptionPosNeg.java
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -25,17 +25,16 @@
import org.apache.log4j.Logger;
import org.dllearner.algorithms.gp.GPUtilities;
import org.dllearner.algorithms.gp.Program;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.RandomGuesserConfigurator;
import org.dllearner.core.options.ConfigEntry;
import org.dllearner.core.options.ConfigOption;
import org.dllearner.core.options.IntegerConfigOption;
import org.dllearner.core.options.InvalidConfigOptionValueException;
import org.dllearner.core.owl.Description;
+import org.dllearner.learningproblems.ScorePosNeg;
public class RandomGuesser extends LearningAlgorithm {
@@ -46,7 +45,7 @@
}
private Description bestDefinition = null;
- private Score bestScore;
+ private ScorePosNeg bestScore;
private double bestFitness = Double.NEGATIVE_INFINITY;
private int numberOfTrees;
@@ -121,7 +120,7 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return bestScore;
}
@@ -131,8 +130,8 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return new EvaluatedDescription(bestDefinition,bestScore);
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
+ return new EvaluatedDescriptionPosNeg(bestDefinition,bestScore);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/SimpleSuggestionLearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -23,10 +23,8 @@
import java.util.List;
import java.util.Set;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.SimpleSuggestionLearningAlgorithmConfigurator;
import org.dllearner.core.options.ConfigEntry;
import org.dllearner.core.owl.Description;
@@ -34,6 +32,7 @@
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.ObjectSomeRestriction;
import org.dllearner.core.owl.Thing;
+import org.dllearner.learningproblems.ScorePosNeg;
/**
* Algorithm for getting "simple" suggestions, e.g. it tests some of the most likely candidates on whether
@@ -51,7 +50,7 @@
}
// private boolean stop = false;
- private Score solutionScore;
+ private ScorePosNeg solutionScore;
private Description bestSollution;
private Set<Description> simpleSuggestions;
@@ -66,8 +65,8 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return new EvaluatedDescription(bestSollution, solutionScore);
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
+ return new EvaluatedDescriptionPosNeg(bestSollution, solutionScore);
}
public static String getName() {
@@ -95,7 +94,7 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return solutionScore;
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/celoe/CELOE.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -19,8 +19,8 @@
*/
package org.dllearner.algorithms.celoe;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.core.ComponentInitException;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.Configurator;
@@ -54,7 +54,7 @@
* @see org.dllearner.core.LearningAlgorithm#getCurrentlyBestEvaluatedDescription()
*/
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
// TODO Auto-generated method stub
return null;
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELLearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -26,17 +26,18 @@
import java.util.TreeSet;
import org.apache.log4j.Logger;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.core.ComponentInitException;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.Configurator;
import org.dllearner.core.configurators.ELLearningAlgorithmConfigurator;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.PosNegLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.refinementoperators.ELDown2;
import org.dllearner.utilities.owl.EvaluatedDescriptionSet;
@@ -168,8 +169,8 @@
// at least as high accuracy - if not we can save the reasoner calls
// for fully computing the evaluated description
if(bestEvaluatedDescriptions.size() == 0 || bestEvaluatedDescriptions.getWorst().getCoveredNegatives().size() >= node.getCoveredNegatives()) {
- Score score = learningProblem.computeScore(description);
- EvaluatedDescription ed = new EvaluatedDescription(description, score);
+ ScorePosNeg score = (ScorePosNeg) learningProblem.computeScore(description);
+ EvaluatedDescriptionPosNeg ed = new EvaluatedDescriptionPosNeg(description, score);
bestEvaluatedDescriptions.add(ed);
}
@@ -216,7 +217,7 @@
}
@Override
- public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
return bestEvaluatedDescriptions.getSet();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -29,12 +29,11 @@
import java.util.Set;
import java.util.Map.Entry;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.algorithms.hybridgp.Psi;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.GPConfigurator;
import org.dllearner.core.options.BooleanConfigOption;
import org.dllearner.core.options.ConfigEntry;
@@ -46,6 +45,7 @@
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.PosNegLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.utilities.Helper;
/**
@@ -126,7 +126,7 @@
private long startTime;
- private Score bestScore;
+ private ScorePosNeg bestScore;
private Description bestConcept;
// private GeneticRefinementOperator psi;
@@ -532,19 +532,19 @@
// nachschauen, ob ev. noch bessere Konzepte im Psi-Cache sind
boolean betterValueFoundInPsiCache = false;
- double bestValue = bestScore.getScore();
+ double bestValue = bestScore.getScoreValue();
if(refinementProbability > 0) {
// das Problem ist hier, dass die gecachte Score nicht unbedingt
// der echten Score entsprechen muss, d.h. hier muss die
// Konzeptlänge mit einberechnet werden => deswegen werden
// neue Score-Objekte generiert
- Set<Entry<Description,Score>> entrySet = psi.evalCache.entrySet();
- for(Entry<Description,Score> entry : entrySet) {
- Score tmpScore = entry.getValue();
+ Set<Entry<Description,ScorePosNeg>> entrySet = psi.evalCache.entrySet();
+ for(Entry<Description,ScorePosNeg> entry : entrySet) {
+ ScorePosNeg tmpScore = entry.getValue();
Description c = entry.getKey();
tmpScore = tmpScore.getModifiedLengthScore(c.getLength());
- double tmpScoreValue = tmpScore.getScore();
+ double tmpScoreValue = tmpScore.getScoreValue();
if(tmpScoreValue>bestValue) {
bestValue = tmpScoreValue;
betterValueFoundInPsiCache = true;
@@ -947,7 +947,7 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return bestScore;
}
@@ -957,9 +957,9 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
// return fittestIndividual.getTree();
- return new EvaluatedDescription(bestConcept,bestScore);
+ return new EvaluatedDescriptionPosNeg(bestConcept,bestScore);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -10,7 +10,6 @@
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.ReasoningMethodUnsupportedException;
-import org.dllearner.core.Score;
import org.dllearner.core.owl.ObjectAllRestriction;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.Nothing;
@@ -24,6 +23,7 @@
import org.dllearner.core.owl.ObjectProperty;
import org.dllearner.core.owl.Thing;
import org.dllearner.learningproblems.PosNegDefinitionLPStrict;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.learningproblems.ScoreThreeValued;
import org.dllearner.reasoning.FastRetrieval;
import org.dllearner.reasoning.ReasonerType;
@@ -54,7 +54,7 @@
private static Random rand = new Random();
- private static Score calculateFitness(LearningProblem learningProblem, Description hypothesis) {
+ private static ScorePosNeg calculateFitness(LearningProblem learningProblem, Description hypothesis) {
return calculateFitness(learningProblem, hypothesis, null);
}
@@ -63,7 +63,7 @@
// (macht aber nicht so viel Sinn, da man das bei richtigen Reasoning-Algorithmen
// ohnehin mit einer Erweiterung der Wissensbasis um die Inklusion Target SUBSETOF ReturnType
// erschlagen kann)
- private static Score calculateFitness(LearningProblem learningProblem, Description hypothesis, Description adc) {
+ private static ScorePosNeg calculateFitness(LearningProblem learningProblem, Description hypothesis, Description adc) {
Description extendedHypothesis;
// return type temporarily disabled
@@ -87,13 +87,13 @@
// } else
extendedHypothesis = hypothesis;
- Score score;
+ ScorePosNeg score;
if(adc != null)
// TODO: ADC-Support
// score = learningProblem.computeScore(extendedHypothesis, adc);
throw new RuntimeException("ADC not supported");
else
- score = learningProblem.computeScore(extendedHypothesis);
+ score = (ScorePosNeg) learningProblem.computeScore(extendedHypothesis);
// System.out.println(hypothesis);
// System.out.println(score.getScore());
@@ -143,18 +143,18 @@
if(Math.random()<0.5) {
Description mainTree = mutation(learningProblem, rs, p.getTree(),true);
Description adc = p.getAdc();
- Score score = calculateFitness(learningProblem,mainTree,adc);
+ ScorePosNeg score = calculateFitness(learningProblem,mainTree,adc);
return new Program(score, mainTree, adc);
}
else {
Description mainTree = p.getTree();
Description adc = mutation(learningProblem, rs, p.getAdc(),false);
- Score score = calculateFitness(learningProblem,mainTree,adc);
+ ScorePosNeg score = calculateFitness(learningProblem,mainTree,adc);
return new Program(score, mainTree, adc);
}
} else {
Description tree = mutation(learningProblem, rs,p.getTree(),false);
- Score score = calculateFitness(learningProblem, tree);
+ ScorePosNeg score = calculateFitness(learningProblem, tree);
return new Program(score, tree);
}
}
@@ -340,7 +340,7 @@
// double bestScore = score.getScore()+Config.accuracyPenalty/2;
double bestScore = 0;
Map<Integer,List<String>> bestNeighbours = new TreeMap<Integer,List<String>>();
- Score tmpScore;
+ ScorePosNeg tmpScore;
SortedSetTuple<String> tmp, tmp2;
// FlatABox abox = ((FastRetrievalReasoner)learningProblem.getReasoner().getFastRetrieval().getAbox();
// FlatABox abox = Main.getFlatAbox();
@@ -363,16 +363,16 @@
tmp2 = FastRetrieval.calculateDisjunctionSets(stringTuple, tmp);
tmpScore = getScore(node.getLength()+2, learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
- if(tmpScore.getScore()==bestScore)
+ if(tmpScore.getScoreValue()==bestScore)
bestNeighbours = updateMap(bestNeighbours,1,concept,false);
- else if(tmpScore.getScore()>bestScore)
+ else if(tmpScore.getScoreValue()>bestScore)
bestNeighbours = updateMap(bestNeighbours,1,concept,true);
tmp2 = FastRetrieval.calculateConjunctionSets(stringTuple, tmp);
tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp2.getPosSet()),Helper.getIndividualSet(tmp2.getNegSet()));
- if(tmpScore.getScore()==bestScore)
+ if(tmpScore.getScoreValue()==bestScore)
bestNeighbours = updateMap(bestNeighbours,2,concept,false);
- else if(tmpScore.getScore()>bestScore)
+ else if(tmpScore.getScoreValue()>bestScore)
bestNeighbours = updateMap(bestNeighbours,2,concept,true);
}
@@ -380,16 +380,16 @@
for(String role : abox.roles) {
tmp = FastRetrieval.calculateAllSet(abox,role,stringTuple);
tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
- if(tmpScore.getScore()==bestScore)
+ if(tmpScore.getScoreValue()==bestScore)
bestNeighbours = updateMap(bestNeighbours,3,role,false);
- else if(tmpScore.getScore()>bestScore)
+ else if(tmpScore.getScoreValue()>bestScore)
bestNeighbours = updateMap(bestNeighbours,3,role,true);
tmp = FastRetrieval.calculateExistsSet(abox,role,stringTuple);
tmpScore = getScore(node.getLength()+2,learningProblem, rs, Helper.getIndividualSet(tmp.getPosSet()),Helper.getIndividualSet(tmp.getNegSet()));
- if(tmpScore.getScore()==bestScore)
+ if(tmpScore.getScoreValue()==bestScore)
bestNeighbours = updateMap(bestNeighbours,4,role,false);
- else if(tmpScore.getScore()>bestScore)
+ else if(tmpScore.getScoreValue()>bestScore)
bestNeighbours = updateMap(bestNeighbours,4,role,true);
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/gp/Program.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -20,8 +20,8 @@
package org.dllearner.algorithms.gp;
-import org.dllearner.core.Score;
import org.dllearner.core.owl.Description;
+import org.dllearner.learningproblems.ScorePosNeg;
/**
* This class represents a program, i.e. an individual.
@@ -39,7 +39,7 @@
private Description adc;
- private Score score;
+ private ScorePosNeg score;
// private Score scoreAdc;
@@ -51,11 +51,11 @@
* Create a new program.
*
*/
- public Program(Score score, Description hypothesis) {
+ public Program(ScorePosNeg score, Description hypothesis) {
this(score, hypothesis, null);
}
- public Program(Score score, Description hypothesis, Description adc) {
+ public Program(ScorePosNeg score, Description hypothesis, Description adc) {
// this.learningProblem = learningProblem;
this.score = score;
this.hypothesis = hypothesis;
@@ -64,7 +64,7 @@
// Implementierung falsch !!
// fitness = score.getScore() - hypothesis.getLength() * Config.percentPerLengthUnit;
// => in getScore() ist jetzt schon der length penalty integriert
- fitness = score.getScore();
+ fitness = score.getScoreValue();
// fitnessEvaluations++;
// System.out.println("new program: " + hypothesis);
@@ -128,7 +128,7 @@
return hypothesis;
}
- public Score getScore() {
+ public ScorePosNeg getScore() {
return score;
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/hybridgp/Psi.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -7,9 +7,9 @@
import org.dllearner.algorithms.gp.Program;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.owl.Description;
import org.dllearner.learningproblems.PosNegLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.refinementoperators.PsiDown;
import org.dllearner.refinementoperators.PsiUp;
import org.dllearner.utilities.owl.ConceptComparator;
@@ -26,7 +26,7 @@
// Cache, damit keine Konzepte doppelt ausgewertet werden
ConceptComparator conceptComparator = new ConceptComparator();
- public SortedMap<Description,Score> evalCache = new TreeMap<Description,Score>(conceptComparator);
+ public SortedMap<Description,ScorePosNeg> evalCache = new TreeMap<Description,ScorePosNeg>(conceptComparator);
// Cache, damit PsiDown bzw. PsiUp nicht mehrfach für gleiches Konzept
// aufgerufen werden
@@ -190,7 +190,7 @@
Description conceptModForCache = ConceptTransformation.applyEquivalenceRules(conceptMod);
ConceptTransformation.transformToOrderedForm(conceptModForCache, conceptComparator);
- Score score = program.getScore();
+ ScorePosNeg score = program.getScore();
// Eval-Cache füllen
evalCache.put(conceptModForCache, score);
@@ -214,11 +214,11 @@
// versuchen Reasoner-Cache zu treffen
// Problem: Score hängt von Konzeptlänge ab!! => muss hier explizit
// reingerechnet werden
- Score newScore = evalCache.get(newConceptMod);
+ ScorePosNeg newScore = evalCache.get(newConceptMod);
if(newScore==null) {
psiReasoningStartTime = System.nanoTime();
- newScore = learningProblem.computeScore(newConcept);
+ newScore = (ScorePosNeg) learningProblem.computeScore(newConcept);
psiReasoningTimeNs += System.nanoTime() - psiReasoningStartTime;
evalCache.put(newConceptMod, newScore);
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -29,12 +29,11 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.core.ComponentInitException;
-import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator;
import org.dllearner.core.options.BooleanConfigOption;
import org.dllearner.core.options.CommonConfigMappings;
@@ -52,6 +51,7 @@
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
import org.dllearner.learningproblems.PosOnlyLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.reasoning.ReasonerType;
import org.dllearner.refinementoperators.RhoDRDown;
import org.dllearner.utilities.Files;
@@ -436,7 +436,7 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
return algorithm.getSolutionScore();
}
@@ -451,12 +451,12 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return new EvaluatedDescription(algorithm.getBestSolution(),algorithm.getSolutionScore());
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
+ return new EvaluatedDescriptionPosNeg(algorithm.getBestSolution(),algorithm.getSolutionScore());
}
@Override
- public synchronized SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public synchronized SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
return algorithm.getCurrentlyBestEvaluatedDescriptions();
}
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -33,10 +33,9 @@
import java.util.concurrent.ConcurrentSkipListSet;
import org.apache.log4j.Logger;
-import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.ExampleBasedROLComponentConfigurator;
import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
@@ -45,6 +44,7 @@
import org.dllearner.core.owl.Union;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.refinementoperators.RefinementOperator;
import org.dllearner.refinementoperators.RhoDRDown;
import org.dllearner.utilities.Files;
@@ -52,7 +52,7 @@
import org.dllearner.utilities.JamonMonitorLogger;
import org.dllearner.utilities.owl.ConceptComparator;
import org.dllearner.utilities.owl.ConceptTransformation;
-import org.dllearner.utilities.owl.EvaluatedDescriptionComparator;
+import org.dllearner.utilities.owl.EvaluatedDescriptionPosNegComparator;
import com.jamonapi.Monitor;
@@ -184,7 +184,7 @@
// comparator used to create ordered sets of concepts
private ConceptComparator conceptComparator = new ConceptComparator();
// comparator for evaluated descriptions
- private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator();
+ private EvaluatedDescriptionPosNegComparator edComparator = new EvaluatedDescriptionPosNegComparator();
// utility variables
private DecimalFormat df = new DecimalFormat();
@@ -1255,13 +1255,13 @@
return best;
}
- public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
Iterator<ExampleBasedNode> it = candidatesStable.descendingIterator();
int count = 0;
- SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator);
+ SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
while(it.hasNext()) {
ExampleBasedNode eb = it.next();
- cbd.add(new EvaluatedDescription(eb.getConcept(), getScore(eb.getConcept())));
+ cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getScore(eb.getConcept())));
// return a maximum of 200 elements (we need a maximum, because the
// candidate set can be very large)
if (count > 200)
@@ -1304,18 +1304,18 @@
}
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
if (posOnly)
return posOnlyLearningProblem.computeScore(getBestSolution());
else
- return learningProblem.computeScore(getBestSolution());
+ return (ScorePosNeg) learningProblem.computeScore(getBestSolution());
}
- private Score getScore(Description d) {
+ private ScorePosNeg getScore(Description d) {
if (posOnly)
return posOnlyLearningProblem.computeScore(d);
else
- return learningProblem.computeScore(d);
+ return (ScorePosNeg) learningProblem.computeScore(d);
}
public ExampleBasedNode getStartNode() {
Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -14,11 +14,10 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.core.LearningAlgorithm;
import org.dllearner.core.LearningProblem;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.configurators.ROLearnerConfigurator;
import org.dllearner.core.options.BooleanConfigOption;
import org.dllearner.core.options.CommonConfigMappings;
@@ -36,12 +35,13 @@
import org.dllearner.core.owl.Union;
import org.dllearner.learningproblems.PosNegLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.refinementoperators.RhoDown;
import org.dllearner.utilities.Files;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
import org.dllearner.utilities.owl.ConceptTransformation;
-import org.dllearner.utilities.owl.EvaluatedDescriptionComparator;
+import org.dllearner.utilities.owl.EvaluatedDescriptionPosNegComparator;
public class ROLearner extends LearningAlgorithm {
@@ -107,7 +107,7 @@
private NodeComparatorStable nodeComparatorStable = new NodeComparatorStable();
private ConceptComparator conceptComparator = new ConceptComparator();
// comparator for evaluated descriptions
- private EvaluatedDescriptionComparator edComparator = new EvaluatedDescriptionComparator();
+ private EvaluatedDescriptionPosNegComparator edComparator = new EvaluatedDescriptionPosNegComparator();
DecimalFormat df = new DecimalFormat();
private PosNegLP learningProblem;
@@ -1054,17 +1054,17 @@
}
@Override
- public EvaluatedDescription getCurrentlyBestEvaluatedDescription() {
- return new EvaluatedDescription(candidatesStable.last().getConcept(), getSolutionScore());
+ public EvaluatedDescriptionPosNeg getCurrentlyBestEvaluatedDescription() {
+ return new EvaluatedDescriptionPosNeg(candidatesStable.last().getConcept(), getSolutionScore());
}
@Override
- public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public SortedSet<EvaluatedDescriptionPosNeg> getCurrentlyBestEvaluatedDescriptions() {
int count = 0;
SortedSet<Node> rev = candidatesStable.descendingSet();
- SortedSet<EvaluatedDescription> cbd = new TreeSet<EvaluatedDescription>(edComparator);
+ SortedSet<EvaluatedDescriptionPosNeg> cbd = new TreeSet<EvaluatedDescriptionPosNeg>(edComparator);
for(Node eb : rev) {
- cbd.add(new EvaluatedDescription(eb.getConcept(), getSolutionScore(eb.getConcept())));
+ cbd.add(new EvaluatedDescriptionPosNeg(eb.getConcept(), getSolutionScore(eb.getConcept())));
// return a maximum of 200 elements (we need a maximum, because the
// candidate set can be very large)
if(count > 200)
@@ -1100,19 +1100,19 @@
}
// @Override
- public Score getSolutionScore() {
+ public ScorePosNeg getSolutionScore() {
if(posOnly)
return posOnlyLearningProblem.computeScore(getCurrentlyBestDescription());
else
- return learningProblem.computeScore(getCurrentlyBestDescription());
+ return (ScorePosNeg) learningProblem.computeScore(getCurrentlyBestDescription());
}
- public Score getSolutionScore(Description d) {
+ public ScorePosNeg getSolutionScore(Description d) {
if(posOnly)
return posOnlyLearningProblem.computeScore(d);
else
- return learningProblem.computeScore(d);
+ return (ScorePosNeg) learningProblem.computeScore(d);
}
@Override
Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -57,7 +57,6 @@
import org.dllearner.core.LearningProblemUnsupportedException;
import org.dllearner.core.OntologyFormat;
import org.dllearner.core.ReasonerComponent;
-import org.dllearner.core.Score;
import org.dllearner.core.options.BooleanConfigOption;
import org.dllearner.core.options.ConfigEntry;
import org.dllearner.core.options.ConfigOption;
@@ -77,6 +76,7 @@
import org.dllearner.learningproblems.PosNegDefinitionLP;
import org.dllearner.learningproblems.PosNegInclusionLP;
import org.dllearner.learningproblems.PosOnlyDefinitionLP;
+import org.dllearner.learningproblems.ScorePosNeg;
import org.dllearner.parser.ConfParser;
import org.dllearner.parser.KBParser;
import org.dllearner.parser.ParseException;
@@ -840,7 +840,7 @@
logger.info("retrieval result (" + result.size() + "): " + result);
- Score score = lp.computeScore(concept);
+ ScorePosNeg score = (ScorePosNeg) lp.computeScore(concept);
logger.info(score);
}
Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007-2008, Jens Lehmann
+ * Copyright (C) 2007-2009, Jens Lehmann
*
* This file is part of DL-Learner.
*
@@ -19,34 +19,25 @@
*/
package org.dllearner.core;
-import java.util.Set;
-
import org.dllearner.core.owl.Description;
-import org.dllearner.core.owl.Individual;
import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor;
-import org.dllearner.learningproblems.ScoreTwoValued;
import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
import org.dllearner.utilities.owl.OWLAPIRenderers;
-import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.semanticweb.owl.model.OWLDescription;
/**
- * This represents a class description, which has been
- * evaluated by the learning algorithm, i.e. it has been checked
- * which examples it covers. It can be used as return value for
- * learning algorithms to make it easier for applications to
- * assess how good an offered class description is and how it
- * classifies particular examples.
+ * An evaluated description is a description and its score (with some
+ * convenience method and serialisation formats).
*
* @author Jens Lehmann
*
*/
public class EvaluatedDescription {
- private Description description;
- private Score score;
+ protected Description description;
+ protected Score score;
/**
* Constructs an evaluated description using its score.
@@ -59,21 +50,6 @@
}
/**
- * Constructs an evaluated description using example coverage.
- * @param description The description, which was evaluated.
- * @param posAsPos Positive examples classified as positive by (i.e. instance of) the description.
- * @param posAsNeg Positive examples classified as negative by (i.e. not instance of) the description.
- * @param negAsPos Negative examples classified as positive by (i.e. instance of) the description.
- * @param negAsNeg Negative examples classified as negative by (i.e. not instance of) the description.
- */
- public EvaluatedDescription(Description description, Set<Individual> posAsPos, Set<Individual> posAsNeg, Set<Individual> negAsPos, Set<Individual> negAsNeg) {
- this.description = description;
- // usually core methods should not depend on methods outside of the core package (except utilities)
- // in this case, this is just a convenience constructor
- score = new ScoreTwoValued(posAsPos, posAsNeg, negAsPos, negAsNeg);
- }
-
- /**
* Gets the description, which was evaluated.
* @return The underlying description.
*/
@@ -107,56 +83,14 @@
}
/**
- * @see org.dllearner.core.Score#getAccuracy()
- * @return Accuracy of the description.
+ * @see org.dllearner.core.Score#getScoreValue()
+ * @return Value in this score system.
*/
- public double getAccuracy() {
- return score.getAccuracy();
+ public double getScoreValue() {
+ return score.getScoreValue();
}
/**
- * Gets the score of this description. This can be used to get
- * further statistical values.
- * @see org.dllearner.core.Score
- * @return The score object associated with this evaluated description.
- */
- public Score getScore() {
- return score;
- }
-
- /**
- * @see org.dllearner.core.Score#getCoveredNegatives()
- * @return Negative examples covered by the description.
- */
- public Set<Individual> getCoveredNegatives() {
- return score.getCoveredNegatives();
- }
-
- /**
- * @see org.dllearner.core.Score#getCoveredPositives()
- * @return Positive examples covered by the description.
- */
- public Set<Individual> getCoveredPositives() {
- return score.getCoveredPositives();
- }
-
- /**
- * @see org.dllearner.core.Score#getNotCoveredNegatives()
- * @return Negative examples not covered by the description.
- */
- public Set<Individual> getNotCoveredNegatives() {
- return score.getNotCoveredNegatives();
- }
-
- /**
- * @see org.dllearner.core.Score#getNotCoveredPositives()
- * @return Positive examples not covered by the description.
- */
- public Set<Individual> getNotCoveredPositives() {
- return score.getNotCoveredPositives();
- }
-
- /**
* Returns a SPARQL query to get instances of this description
* from a SPARQL endpoint. Of course, results may be incomplete,
* because no inference is done. The SPARQL query is a straightforward
@@ -169,7 +103,7 @@
*/
public String getSparqlQuery(int limit) {
return SparqlQueryDescriptionConvertVisitor.getSparqlQuery(description, limit);
- }
+ }
/**
* This convenience method can be used to store and exchange evaluated
@@ -183,32 +117,12 @@
OWLDescription d = OWLAPIDescriptionConvertVisitor.getOWLDescription(description);
object.put("descriptionOWLXML", OWLAPIRenderers.toOWLXMLSyntax(d));
object.put("descriptionKBSyntax", description.toKBSyntaxString());
- object.put("accuracy", score.getAccuracy());
- object.put("coveredPositives", getJSONArray(score.getCoveredPositives()));
- object.put("coveredNegatives", getJSONArray(score.getCoveredNegatives()));
- object.put("notCoveredPositives", getJSONArray(score.getNotCoveredPositives()));
- object.put("notCoveredNegatives", getJSONArray(score.getNotCoveredNegatives()));
+ object.put("scoreValue", score.getScoreValue());
return object.toString(3);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
- }
-
- @Override
- public String toString() {
- return description.toString() + "(accuracy: " + getAccuracy() + ")";
- }
-
- // we need to use this method instead of the standard JSON array constructor,
- // otherwise we'll get unexpected results (JSONArray does not take Individuals
- // as arguments and does not use toString)
- private static JSONArray getJSONArray(Set<Individual> individuals) {
- JSONArray j = new JSONArray();
- for(Individual i : individuals) {
- j.put(i.getName());
- }
- return j;
- }
+ }
}
Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -207,7 +207,7 @@
* first.
* @return Best class descriptions found so far.
*/
- public SortedSet<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
+ public SortedSet<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions() {
TreeSet<EvaluatedDescription> ds = new TreeSet<EvaluatedDescription>();
ds.add(getCurrentlyBestEvaluatedDescription());
return ds;
@@ -231,14 +231,15 @@
*
* @return A list of currently best class descriptions.
*/
- public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) {
- SortedSet<EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions();
+ public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions, double accuracyThreshold, boolean filterNonMinimalDescriptions) {
+ SortedSet<? extends EvaluatedDescription> currentlyBest = getCurrentlyBestEvaluatedDescriptions();
List<EvaluatedDescription> returnList = new LinkedList<EvaluatedDescription>();
for(EvaluatedDescription ed : currentlyBest) {
// once we hit a description with a below threshold accuracy, we simply return
// because learning algorithms are advised to order descriptions by accuracy,
// so we won't find any concept with higher accuracy in the remaining list
- if(ed.getAccuracy() < accuracyThreshold) {
+// if(ed.getAccuracy() < accuracyThreshold) {
+ if(ed.getScoreValue() < accuracyThreshold) {
return returnList;
}
@@ -270,7 +271,7 @@
* @param nrOfDescriptions Maximum number of descriptions returned.
* @return Return value is getCurrentlyBestDescriptions(nrOfDescriptions, 0.0, false).
*/
- public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) {
+ public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(int nrOfDescriptions) {
return getCurrentlyBestEvaluatedDescriptions(nrOfDescriptions, 0.0, false);
}
@@ -279,7 +280,7 @@
* @param accuracyThreshold Only return solutions with this accuracy or higher.
* @return Return value is getCurrentlyBestDescriptions(Integer.MAX_VALUE, accuracyThreshold, false).
*/
- public synchronized List<EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) {
+ public synchronized List<? extends EvaluatedDescription> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) {
return getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, accuracyThreshold, false);
}
Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -20,6 +20,7 @@
package org.dllearner.core;
import org.dllearner.core.owl.Description;
+import org.dllearner.learningproblems.ScorePosNeg;
/**
* Base class for all learning problems.
Modified: trunk/src/dl-learner/org/dllearner/core/Score.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/core/Score.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2007-2008, Jens Lehmann
+ * Copyright (C) 2007-2009, Jens Lehmann
*
* This file is part of DL-Learner.
*
@@ -17,48 +17,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
package org.dllearner.core;
-import java.util.Set;
-
-import org.dllearner.core.owl.Individual;
-
/**
* The score class is used to store how well a class description did
- * on a learning problem.
+ * on a learning problem. Depending on the learning problem at hand,
+ * different criteria can be used. (Similar learning problems probably
+ * score class descriptions/hypothesis in a similar way.)
*
- * TODO: If possible this class should be abstracted further. The current
- * implementation requires positive and negative examples, i.e. does not
- * allow arbitrary learning problems.
- *
* @author Jens Lehmann
*
*/
public abstract class Score {
-
- // accuracy
- public abstract double getAccuracy();
-
- // example coverage
- public abstract Set<Individual> getCoveredPositives();
- public abstract Set<Individual> getCoveredNegatives();
- public abstract Set<Individual> getNotCoveredPositives();
- public abstract Set<Individual> getNotCoveredNegatives();
-
- // older methods (not frequently used anymore)
- public abstract double getScore();
+
/**
- * The score of a concept depends on how good it classifies the
- * examples of a learning problem and the length of the concept
- * itself. If a given concept is known to have equal classification
- * properties than the concept this score object is based on, then
- * this method can be used to calculate its score value by using the
- * length of this concept as parameter.
+ * This method returns a value, which indicates how well a
+ * class description solves a learning problem. Different implementations
+ * of scoring systems can implement this differently. Higher values
+ * are better and it is recommended to assign a score value in
+ * the closed interval from 0 to 1 if possible.
*
- * @param newLength Length of the concept.
- * @return Score.
+ * @return A value indicating the quality (of a class description).
*/
- public abstract Score getModifiedLengthScore(int newLength);
+ public abstract double getScoreValue();
}
Modified: trunk/src/dl-learner/org/dllearner/gui/RunPanel.java
===================================================================
--- trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2009-02-09 12:39:09 UTC (rev 1590)
+++ trunk/src/dl-learner/org/dllearner/gui/RunPanel.java 2009-02-09 16:41:44 UTC (rev 1591)
@@ -48,6 +48,7 @@
import javax.swing.*;
+import org.dllearner.algorithms.EvaluatedDescriptionPosNeg;
import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent;
import org.dllearner.core.EvaluatedDescription;
import org.dllearner.learningproblems.PosNegDefinitionLP;
@@ -377,12 +378,12 @@
gbc.weighty = wy;
}
- private String getSolutionString(List<EvaluatedDescription> solutions) {
+ private String getSolutionString(List<? extends EvaluatedDescription> solutions) {
String baseURI = config.getReasoner().getBaseURI();
Map<String,String> prefixes = conf...
[truncated message content] |