|
From: <lor...@us...> - 2014-08-06 11:41:31
|
Revision: 4283
http://sourceforge.net/p/dl-learner/code/4283
Author: lorenz_b
Date: 2014-08-06 11:41:26 +0000 (Wed, 06 Aug 2014)
Log Message:
-----------
Updated OWL API.
Modified Paths:
--------------
trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java
trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java
trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java
trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java
trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java
trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java
trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java
trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java
trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java
trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java
trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java
trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java
trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java
trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java
trunk/components-core/src/test/resources/punning_example.ttl
trunk/pom.xml
Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -346,6 +346,9 @@
if(writeSearchTree) {
File f = new File(searchTreeFile );
+ if(f.getParentFile() != null){
+ f.getParentFile().mkdirs();
+ }
Files.clearFile(f);
}
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/DatatypeProperty.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -52,6 +52,14 @@
public URI getURI() {
return URI.create(name);
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.PropertyExpression#isAnonymous()
+ */
+ @Override
+ public boolean isAnonymous() {
+ return false;
+ }
@Override
public String toString() {
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/Description.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -25,6 +25,8 @@
import java.util.Map;
import java.util.Set;
+import org.semanticweb.owlapi.model.OWLRuntimeException;
+
/**
* A class description is sometimes also called "complex class" or "concept".
*
@@ -216,8 +218,20 @@
return this instanceof NamedClass;
}
+ /**
+ * Determines whether or not this expression represents an anonymous class
+ * expression.
+ *
+ * @return {@code true} if this is an anonymous class expression, or
+ * {@code false} if this is a named class ( {@code OWLClass})
+ */
+ public boolean isAnonymous(){
+ return true;
+ };
+
public NamedClass asNamedClass(){
- return (NamedClass)this;
+ throw new OWLRuntimeException(
+ "Not an OWLClass. This method should only be called if the isAnonymous method returns false!");
}
/**
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/NamedClass.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -56,6 +56,22 @@
return URI.create(name);
}
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.Description#isAnonymous()
+ */
+ @Override
+ public boolean isAnonymous() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.Description#asNamedClass()
+ */
+ @Override
+ public NamedClass asNamedClass() {
+ return this;
+ }
+
public int getLength() {
return 1;
}
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectProperty.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -46,7 +46,23 @@
public URI getURI() {
return URI.create(name);
- }
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.ObjectPropertyExpression#asObjectProperty()
+ */
+ @Override
+ public ObjectProperty asObjectProperty() {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.PropertyExpression#isAnonymous()
+ */
+ @Override
+ public boolean isAnonymous() {
+ return false;
+ }
@Override
public String toString() {
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyExpression.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -21,6 +21,8 @@
import java.io.Serializable;
+import org.semanticweb.owlapi.model.OWLRuntimeException;
+
/**
* An object property expression is an object property construct, which
* can be used in axioms, e.g. complex class descriptions. It can be
@@ -52,7 +54,21 @@
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
-
+
+ /**
+ * If the property is a named object property then this method will obtain
+ * the property as such. The general pattern of use is that the
+ * {@code isAnonymous} method should first be used to determine if the
+ * property is named (i.e. not an object property expression such as
+ * inv(p)). If the property is named then this method may be used to obtain
+ * the property as a named property without casting.
+ *
+ * @return The property as an {@code ObjectProperty} if possible.
+ * @throws OWLRuntimeException
+ * if the property is not a named property.
+ */
+ public abstract ObjectProperty asObjectProperty();
+
@Override
public boolean equals(Object obj) {
if (this == obj)
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectPropertyInverse.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -22,6 +22,7 @@
import java.util.Map;
import org.dllearner.utilities.Helper;
+import org.semanticweb.owlapi.model.OWLRuntimeException;
/**
* Represents the inverse of a property expression. It can be used
@@ -49,6 +50,23 @@
public int getLength() {
return 2;
}
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.ObjectPropertyExpression#asObjectProperty()
+ */
+ @Override
+ public ObjectProperty asObjectProperty() {
+ throw new OWLRuntimeException(
+ "Property is not a named property. Check using the isAnonymous method before calling this method!");
+ }
+
+ /* (non-Javadoc)
+ * @see org.dllearner.core.owl.PropertyExpression#isAnonymous()
+ */
+ @Override
+ public boolean isAnonymous() {
+ return true;
+ }
public String toString(String baseURI, Map<String,String> prefixes) {
return Helper.getAbbreviatedString(name, baseURI, prefixes) + "-";
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectQuantorRestriction.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -19,6 +19,7 @@
package org.dllearner.core.owl;
+
/**
*
* @author Jens Lehmann
@@ -26,9 +27,6 @@
*/
public abstract class ObjectQuantorRestriction extends QuantorRestriction {
- /**
- *
- */
private static final long serialVersionUID = -5482730659805823042L;
public ObjectQuantorRestriction(ObjectPropertyExpression role, Description c) {
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/ObjectSomeRestriction.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -29,9 +29,6 @@
*/
public class ObjectSomeRestriction extends ObjectQuantorRestriction {
- /**
- *
- */
private static final long serialVersionUID = 858960420513908151L;
public ObjectSomeRestriction(ObjectPropertyExpression role, Description c) {
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/PropertyExpression.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -24,5 +24,14 @@
*
*/
public interface PropertyExpression extends KBElement {
+
+ /**
+ * Determines if this property expression is anonymous.
+ *
+ * @return {@code true} if the property expression is anonymous (because it
+ * is the inverse of a property). {@code false} if this property is
+ * a named object property or named data property.
+ */
+ boolean isAnonymous();
}
Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/reasoning/MaterializableFastInstanceChecker.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -26,6 +26,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -153,7 +154,7 @@
private boolean materializeExistentialRestrictions = false;
private boolean useCaching = true;
-
+ private boolean handlePunning = true;
public enum ForallSemantics {
Standard, // standard all quantor
@@ -271,6 +272,7 @@
HashFunction hf = Hashing.md5();
Hasher hasher = hf.newHasher();
hasher.putBoolean(materializeExistentialRestrictions);
+ hasher.putBoolean(handlePunning);
for (OWLOntology ont : rc.getOWLAPIOntologies()) {
hasher.putInt(ont.getLogicalAxioms().hashCode());
hasher.putInt(ont.getAxioms().hashCode());
@@ -373,6 +375,7 @@
sd.put(dp, rc.getStringDatatypeMembers(dp));
}
+
if(materializeExistentialRestrictions){
ExistentialRestrictionMaterialization materialization = new ExistentialRestrictionMaterialization(rc.getReasoner().getRootOntology());
for (NamedClass cls : atomicConcepts) {
@@ -384,6 +387,42 @@
}
}
+ //materialize facts based on OWL punning, i.e.:
+ //for each A in N_C
+ if(handlePunning){
+ OWLOntology ontology = rc.getReasoner().getRootOntology();
+
+ Individual genericIndividual = new Individual("http://dl-learner.org/punning#genInd");
+ Map<Individual, SortedSet<Individual>> map = new HashMap<Individual, SortedSet<Individual>>();
+ for (Individual individual : individuals) {
+ SortedSet<Individual> objects = new TreeSet<Individual>();
+ objects.add(genericIndividual);
+ map.put(individual, objects);
+ }
+ for (NamedClass cls : atomicConcepts) {
+ classInstancesNeg.get(cls).add(genericIndividual);
+ if(OWLPunningDetector.hasPunning(ontology, cls)){
+ Individual clsAsInd = new Individual(cls.getName());
+ //for each x \in N_I with A(x) we add relatedTo(x,A)
+ SortedSet<Individual> individuals = classInstancesPos.get(cls);
+ for (Individual individual : individuals) {
+ SortedSet<Individual> objects = map.get(individual);
+ if(objects == null){
+ objects = new TreeSet<Individual>();
+ map.put(individual, objects);
+ }
+ objects.add(clsAsInd);
+
+ }
+ }
+ }
+ opPos.put(OWLPunningDetector.punningProperty, map);
+ atomicRoles = new TreeSet<ObjectProperty>(atomicRoles);
+ atomicRoles.add(OWLPunningDetector.punningProperty);
+ atomicRoles = Collections.unmodifiableSet(atomicRoles);
+// individuals.add(genericIndividual);
+ }
+
long dematDuration = System.currentTimeMillis() - dematStartTime;
logger.debug("TBox dematerialised in " + dematDuration + " ms");
}
@@ -482,6 +521,9 @@
}
ObjectProperty op = (ObjectProperty) ope;
Description child = description.getChild(0);
+ if(handlePunning && op == OWLPunningDetector.punningProperty && child.equals(new NamedClass(Thing.uri.toString()))){
+ return true;
+ }
Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
if (mapping == null) {
@@ -489,7 +531,8 @@
+ ").");
return false;
}
- SortedSet<Individual> roleFillers = opPos.get(op).get(individual);
+
+ SortedSet<Individual> roleFillers = mapping.get(individual);
if (roleFillers == null) {
return false;
}
@@ -565,7 +608,9 @@
return true;
}
// return false if there are none or not enough role fillers
- if (roleFillers == null || roleFillers.size() < number) {
+ if (roleFillers == null
+ || (roleFillers.size() < number && op != OWLPunningDetector.punningProperty)
+ ) {
return false;
}
@@ -574,7 +619,9 @@
index++;
if (hasTypeImpl(child, roleFiller)) {
nrOfFillers++;
- if (nrOfFillers == number) {
+ if (nrOfFillers == number
+ || (handlePunning && op == OWLPunningDetector.punningProperty)
+ ) {
return true;
}
// early abort: e.g. >= 10 hasStructure.Methyl;
@@ -763,7 +810,7 @@
+ description + " unsupported. Inverse object properties not supported.");
}
ObjectProperty op = (ObjectProperty) ope;
- Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
+ Map<Individual, SortedSet<Individual>> mapping = opPos.get(op);
// each individual is connected to a set of individuals via the property;
// we loop through the complete mapping
@@ -1265,4 +1312,18 @@
public void setMaterializeExistentialRestrictions(boolean materializeExistentialRestrictions) {
this.materializeExistentialRestrictions = materializeExistentialRestrictions;
}
+
+ /**
+ * @param handlePunning the handlePunning to set
+ */
+ public void setHandlePunning(boolean handlePunning) {
+ this.handlePunning = handlePunning;
+ }
+
+ /**
+ * @param useCaching the useCaching to set
+ */
+ public void setUseMaterializationCaching(boolean useCaching) {
+ this.useCaching = useCaching;
+ }
}
Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -75,6 +75,7 @@
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptComparator;
import org.dllearner.utilities.owl.ConceptTransformation;
+import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Sets;
@@ -499,15 +500,17 @@
}
} else if (description instanceof Intersection) {
-
+
+ System.out.println("REFINING: " + OWLAPIDescriptionConvertVisitor.getOWLClassExpression(description));
// refine one of the elements
for(Description child : description.getChildren()) {
-
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(child));
+ System.out.println(maxLength - description.getLength()+child.getLength());
// refine the child; the new max length is the current max length minus
// the currently considered concept plus the length of the child
// TODO: add better explanation
tmp = refine(child, maxLength - description.getLength()+child.getLength(),null,currDomain);
-
+ System.out.println(tmp);
// create new intersection
for(Description c : tmp) {
List<Description> newChildren = (List<Description>)((LinkedList<Description>)description.getChildren()).clone();
Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DLSyntaxObjectRenderer.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -254,6 +254,12 @@
@Override
public void visit(OWLAsymmetricObjectPropertyAxiom axiom) {
+ axiom.getProperty().accept(this);
+ writeSpace();
+ write(DISJOINT_WITH);
+ writeSpace();
+ axiom.getProperty().accept(this);
+ write(INVERSE);
}
@Override
Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionComparator.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -22,6 +22,10 @@
import java.util.Comparator;
import org.dllearner.core.EvaluatedDescription;
+import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.reasoning.OWLPunningDetector;
/**
* Comparator for evaluated descriptions, which orders them by
@@ -47,8 +51,12 @@
else if(acc1 < acc2)
return -1;
else {
- int length1 = ed1.getDescriptionLength();
- int length2 = ed2.getDescriptionLength();
+ int length1 =
+ getLength(ed1);
+// ed1.getDescriptionLength();
+ int length2 =
+ getLength(ed2);
+// ed2.getDescriptionLength();
if(length1 < length2)
return 1;
else if(length1 > length2)
@@ -57,5 +65,20 @@
return cc.compare(ed1.getDescription(), ed2.getDescription());
}
}
+
+ private int getLength(EvaluatedDescription ed){
+ int length = 0;
+ Description d = ed.getDescription();
+ if(d instanceof Intersection){
+ for (Description child : d.getChildren()) {
+ if(child instanceof ObjectSomeRestriction && ((ObjectSomeRestriction) child).getRole().asObjectProperty() == OWLPunningDetector.punningProperty){
+ length += child.getChild(0).getLength();
+ } else {
+ length += child.getLength();
+ }
+ }
+ }
+ return length;
+ }
}
\ No newline at end of file
Modified: trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java
===================================================================
--- trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/test/java/org/dllearner/test/PunningTest.java 2014-08-06 11:41:26 UTC (rev 4283)
@@ -3,37 +3,48 @@
*/
package org.dllearner.test;
-import java.io.ByteArrayInputStream;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import java.util.SortedSet;
import org.dllearner.algorithms.celoe.CELOE;
+import org.dllearner.algorithms.celoe.OEHeuristicRuntime;
import org.dllearner.core.AbstractCELA;
-import org.dllearner.core.AbstractLearningProblem;
-import org.dllearner.core.AbstractReasonerComponent;
import org.dllearner.core.ComponentInitException;
+import org.dllearner.core.EvaluatedDescription;
import org.dllearner.core.KnowledgeSource;
+import org.dllearner.core.owl.Description;
import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.Intersection;
+import org.dllearner.core.owl.NamedClass;
+import org.dllearner.core.owl.ObjectProperty;
+import org.dllearner.core.owl.ObjectSomeRestriction;
+import org.dllearner.core.owl.Thing;
import org.dllearner.kb.OWLAPIOntology;
import org.dllearner.learningproblems.PosNegLPStandard;
-import org.dllearner.reasoning.FastInstanceChecker;
-import org.dllearner.utilities.owl.OWLAPIConverter;
+import org.dllearner.reasoning.MaterializableFastInstanceChecker;
+import org.dllearner.reasoning.OWLPunningDetector;
+import org.dllearner.refinementoperators.RhoDRDown;
+import org.dllearner.utilities.owl.DLSyntaxObjectRenderer;
import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor;
import org.junit.Assert;
import org.junit.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
+import org.semanticweb.owlapi.io.ToStringRenderer;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataFactory;
-import org.semanticweb.owlapi.model.OWLIndividual;
+import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
-import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
+import org.semanticweb.owlapi.owllink.parser.OWLlinkDescriptionElementHandler;
import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl;
import com.google.common.collect.Sets;
+import com.google.common.collect.Sets.SetView;
/**
* @author Lorenz Buehmann
@@ -41,87 +52,35 @@
*/
public class PunningTest {
-
- public OWLOntology makeExampleKB() throws OWLOntologyCreationException{
- String kb = "@prefix owl:<http://www.w3.org/2002/07/owl#> . @prefix :<http://foo.org/> .";
- kb += ":p a owl:ObjectProperty .";
-
- for (int i = 1; i <= 5; i++) {
- kb += ":r" + i + " a owl:ObjectProperty .";
- }
-
- kb += ":A a owl:Class; :r1 :o1; :r2 :o2 .";
- kb += ":B a owl:Class; :r1 :o3; :r3 :o2 .";
-
- for (int i = 1; i <= 10; i++) {
- kb += ":x" + i + " a owl:NamedIndividual .";
- }
-
- int m = 5;
- int n = 5;
-
- //m instances of A
- for (int i = 1; i <= m; i++) {
- kb += ":x" + i + " a :A .";
- }
-
- //n instances of B
- for (int i = 1; i <= n; i++) {
- kb += ":x" + i + " a :A .";
- }
-
- OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new ByteArrayInputStream(kb.getBytes()));
- return ontology;
- }
-
public OWLOntology loadExample() throws OWLOntologyCreationException{
OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getClassLoader().getResourceAsStream("punning_example.ttl"));
return ontology;
}
@Test
- public void testPunning() throws OWLOntologyCreationException, ComponentInitException{
- OWLOntology ontology = makeExampleKB();
- OWLDataFactory df = new OWLDataFactoryImpl();
+ public void testPunningExists() throws OWLOntologyCreationException, ComponentInitException{
+ OWLOntology ontology = loadExample();
- //check that A and B are both, individual and class
- OWLClass clsA = df.getOWLClass(IRI.create("http://foo.org/A"));
- OWLClass clsB = df.getOWLClass(IRI.create("http://foo.org/B"));
- OWLIndividual indA = df.getOWLNamedIndividual(IRI.create("http://foo.org/A"));
- OWLIndividual indB = df.getOWLNamedIndividual(IRI.create("http://foo.org/B"));
-
+ Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
Set<OWLClass> classes = ontology.getClassesInSignature();
- Set<OWLObjectProperty> properties = ontology.getObjectPropertiesInSignature();
- Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature();
- System.out.println("Classes:" + classes);
- System.out.println("Properties:" + properties);
- System.out.println("Individuals:" + individuals);
+ SetView<IRI> intersection = Sets.intersection(toIRI(individuals), toIRI(classes));
+ System.out.println("Entities that are class and individual:\n" + intersection);
+ Assert.assertTrue(!intersection.isEmpty());
- Assert.assertTrue(
- ontology.getClassesInSignature().contains(clsA) &&
- ontology.getClassesInSignature().contains(clsB) &&
- ontology.getIndividualsInSignature().contains(indA) &&
- ontology.getIndividualsInSignature().contains(indB)
- );
-
- KnowledgeSource ks = new OWLAPIOntology(ontology);
- ks.init();
-
- AbstractReasonerComponent rc = new FastInstanceChecker(ks);
- rc.init();
-
- AbstractLearningProblem lp = new PosNegLPStandard(rc);
- lp.init();
-
- AbstractCELA la = new CELOE(lp, rc);
- la.init();
-
- la.start();
}
+ private Set<IRI> toIRI(Set<? extends OWLEntity> entities){
+ Set<IRI> iris = new HashSet<IRI>();
+ for (OWLEntity e : entities) {
+ iris.add(e.getIRI());
+ }
+ return iris;
+ }
+
@Test
- public void testPunning2() throws OWLOntologyCreationException, ComponentInitException{
+ public void testPunning() throws OWLOntologyCreationException, ComponentInitException{
+ ToStringRenderer.getInstance().setRenderer(new DLSyntaxObjectRenderer());
OWLOntology ontology = loadExample();
OWLDataFactory df = new OWLDataFactoryImpl();
@@ -138,18 +97,83 @@
KnowledgeSource ks = new OWLAPIOntology(ontology);
ks.init();
- AbstractReasonerComponent rc = new FastInstanceChecker(ks);
+ MaterializableFastInstanceChecker rc = new MaterializableFastInstanceChecker(ks);
+// rc.setUseMaterializationCaching(false);
+ rc.setHandlePunning(true);
+ rc.setUseMaterializationCaching(false);
rc.init();
+ rc.setBaseURI("http://ex.org/");
PosNegLPStandard lp = new PosNegLPStandard(rc);
lp.setPositiveExamples(posExamples);
lp.setNegativeExamples(negExamples);
lp.init();
- AbstractCELA la = new CELOE(lp, rc);
+ CELOE la = new CELOE(lp, rc);
+ la.setWriteSearchTree(true);
+ la.setSearchTreeFile("log/punning_search_tree.txt");
+ la.setReplaceSearchTree(true);
+ la.setMaxNrOfResults(50);
+ la.setMaxExecutionTimeInSeconds(20);
+ la.setExpandAccuracy100Nodes(true);
+ OEHeuristicRuntime heuristic = new OEHeuristicRuntime();
+// heuristic.setExpansionPenaltyFactor(0.001);
+// la.setHeuristic(heuristic);
la.init();
+ ((RhoDRDown)la.getOperator()).setUseNegation(false);
+// la.start();
- la.start();
+ System.out.println("Classes: " + ontology.getClassesInSignature());
+ System.out.println("Individuals: " + ontology.getIndividualsInSignature());
+
+ Description d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"));
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d));
+ SortedSet<Individual> individuals = rc.getIndividuals(d);
+ System.out.println(individuals);
+
+ d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction(
+ OWLPunningDetector.punningProperty, Thing.instance));
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d));
+ individuals = rc.getIndividuals(d);
+ System.out.println(individuals);
+
+ d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction(
+ OWLPunningDetector.punningProperty, new ObjectSomeRestriction(new ObjectProperty(
+ "http://ex.org/bereifung"), Thing.instance)));
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d));
+ individuals = rc.getIndividuals(d);
+ System.out.println(individuals);
+
+ d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction(
+ OWLPunningDetector.punningProperty,
+// new ObjectSomeRestriction(new ObjectProperty("http://ex.org/bereifung"),
+ Thing.instance));
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d));
+ individuals = rc.getIndividuals(d);
+ System.out.println(individuals);
+
+ //get some refinements
+ System.out.println("###############");
+ System.out.println("Refinements:");
+ Set<Description> refinements = la.getOperator().refine(d, d.getLength() + 4);
+ for (Description ref : refinements) {
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(ref));
+ System.out.println(lp.getAccuracyOrTooWeak(ref, 0d));
+ }
+ System.out.println("###############");
+
+
+ d = new Intersection(new NamedClass("http://ex.org/Fahrzeug"), new ObjectSomeRestriction(
+ OWLPunningDetector.punningProperty, new ObjectSomeRestriction(new ObjectProperty(
+ "http://ex.org/bereifung"), new ObjectSomeRestriction(OWLPunningDetector.punningProperty,
+ Thing.instance))));
+ System.out.println(OWLAPIDescriptionConvertVisitor.getOWLClassExpression(d));
+ individuals = rc.getIndividuals(d);
+ System.out.println(individuals);
+// List<? extends EvaluatedDescription> currentlyBestEvaluatedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(100);
+// for (EvaluatedDescription ed : currentlyBestEvaluatedDescriptions) {
+// System.out.println(ed);
+// }
}
}
Modified: trunk/components-core/src/test/resources/punning_example.ttl
===================================================================
--- trunk/components-core/src/test/resources/punning_example.ttl 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/components-core/src/test/resources/punning_example.ttl 2014-08-06 11:41:26 UTC (rev 4283)
@@ -57,11 +57,7 @@
<http://ex.org/SIEMENS425#567> a ex:Bahn .
<http://ex.org/TATRAT3#678> a ex:Tram .
-# punning workaround
-ex:p a owl:ObjectProperty .
-<http://ex.org/TRABANT601#1234> ex:p ex:Auto .
-<http://ex.org/S51#2345> ex:p ex:Moped .
-<http://ex.org/MIFA23#3456> ex:p ex:Fahrrad .
-<http://ex.org/CLIPSO90MG#4567> ex:p ex:Schubkarre .
-<http://ex.org/SIEMENS425#567> ex:p ex:Bahn .
-<http://ex.org/TATRAT3#678> ex:p ex:Tram .
\ No newline at end of file
+# punning of ex:Gummireifen
+ex:bestehtAus a owl:ObjectProperty .
+ex:Gummireifen ex:bestehtAus ex:GUMMI .
+ex:GUMMI a ex:Werkstoff .
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2014-07-29 13:56:03 UTC (rev 4282)
+++ trunk/pom.xml 2014-08-06 11:41:26 UTC (rev 4283)
@@ -123,7 +123,7 @@
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
- <version>3.4.5</version>
+ <version>3.5.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|