From: <jen...@us...> - 2008-02-26 18:13:32
|
Revision: 642 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=642&view=rev Author: jenslehmann Date: 2008-02-26 10:13:23 -0800 (Tue, 26 Feb 2008) Log Message: ----------- - datatype TBox reasoning using OWL API - description comparator updated to include boolean datatypes - refinement operator rho extended to include boolean datatypes Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2008-02-26 18:13:23 UTC (rev 642) @@ -30,6 +30,8 @@ import java.util.TreeSet; import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -538,8 +540,8 @@ if(topRefinementsLength<3 && maxLength>2) { // Konzepte der Länge 3: EXISTS r.TOP + Set<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { - Set<Description> m3 = new TreeSet<Description>(conceptComparator); // previous operator: uses all roles // for(AtomicRole r : Config.Refinement.allowedRoles) { // m3.add(new Exists(r, new Top())); @@ -548,17 +550,19 @@ for(ObjectProperty r : rs.getMostGeneralRoles()) { m3.add(new ObjectSomeRestriction(r, new Thing())); } - m.put(3,m3); + } // boolean datatypes, e.g. testPositive = true if(useBooleanDatatypes) { -// Set<Description> m3 = new TreeSet<Description>(conceptComparator); - // TODO: code for getting boolean datatypes -// m.put(3,m3); - // TODO: do not use put here because we overwrite the - // EXISTS quantor stuff + Set<DatatypeProperty> booleanDPs = rs.getBooleanDatatypeProperties(); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); + } } + + m.put(3,m3); } if(maxLength>2) { Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-02-26 18:13:23 UTC (rev 642) @@ -27,6 +27,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -405,6 +406,42 @@ return reasoner.getAtomicRoles(); } + public Set<DatatypeProperty> getDatatypeProperties() { + try { + return reasoner.getDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getBooleanDatatypeProperties() { + try { + return reasoner.getBooleanDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getIntDatatypeProperties() { + try { + return reasoner.getIntDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Set<DatatypeProperty> getDoubleDatatypeProperties() { + try { + return reasoner.getDoubleDatatypeProperties(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + public SortedSet<Individual> getIndividuals() { return reasoner.getIndividuals(); } Modified: trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/BooleanValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -27,6 +27,8 @@ */ public class BooleanValueRestriction extends DatatypeValueRestriction { + private boolean booleanValue; + /** * TODO: Internally a typed constant with datatype boolean and * strings "true" or "false" is created. This is a clean way to @@ -42,6 +44,11 @@ */ public BooleanValueRestriction(DatatypeProperty restrictedPropertyExpression, Boolean value) { super(restrictedPropertyExpression, new TypedConstant(value.toString(), Datatype.BOOLEAN)); + booleanValue = value; } + public boolean getBooleanValue() { + return booleanValue; + } + } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -49,8 +49,7 @@ */ @Override public int getArity() { - // TODO Auto-generated method stub - return 0; + return 2; } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/core/owl/ValueRestriction.java 2008-02-26 18:13:23 UTC (rev 642) @@ -31,6 +31,7 @@ public ValueRestriction(PropertyExpression propertyExpression, KBElement value) { super(propertyExpression); + this.value = value; } public KBElement getValue() { Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-02-26 18:13:23 UTC (rev 642) @@ -258,7 +258,16 @@ } return true; } else if (description instanceof BooleanValueRestriction) { - + DatatypeProperty dp = ((BooleanValueRestriction)description).getRestrictedPropertyExpresssion(); + boolean value = ((BooleanValueRestriction)description).getBooleanValue(); + + if(value) { + // check whether the individual is in the set of individuals mapped + // to true by this datatype property + return bd.get(dp).contains(individual); + } else { + return !bd.get(dp).contains(individual); + } } throw new ReasoningMethodUnsupportedException("Instance check for description " Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-02-26 18:13:23 UTC (rev 642) @@ -25,9 +25,12 @@ import java.util.Stack; import org.dllearner.algorithms.gp.ADC; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.Datatype; import org.dllearner.core.owl.DatatypeExactCardinalityRestriction; import org.dllearner.core.owl.DatatypeMaxCardinalityRestriction; import org.dllearner.core.owl.DatatypeMinCardinalityRestriction; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.DatatypeValueRestriction; import org.dllearner.core.owl.Description; @@ -43,11 +46,16 @@ import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.Union; +import org.dllearner.core.owl.UntypedConstant; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLConstant; import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDataProperty; +import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLObjectProperty; @@ -171,7 +179,7 @@ */ public void visit(ObjectMinCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -179,7 +187,7 @@ */ public void visit(ObjectExactCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -187,7 +195,7 @@ */ public void visit(ObjectMaxCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -195,15 +203,34 @@ */ public void visit(ObjectValueRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeValueRestriction) */ public void visit(DatatypeValueRestriction description) { - // TODO Auto-generated method stub - + // convert OWL constant to OWL API constant + Constant c = description.getValue(); + OWLConstant constant; + if(c instanceof TypedConstant) { + Datatype dt = ((TypedConstant)c).getDatatype(); + OWLDataType odt = convertDatatype(dt); + constant = factory.getOWLTypedConstant(c.getLiteral(), odt); + } else { + UntypedConstant uc = (UntypedConstant) c; + if(uc.hasLang()) { + constant = factory.getOWLUntypedConstant(uc.getLiteral(), uc.getLang()); + } else { + constant = factory.getOWLUntypedConstant(uc.getLiteral()); + } + } + + // get datatype property + DatatypeProperty dtp = description.getRestrictedPropertyExpresssion(); + OWLDataProperty prop = factory.getOWLDataProperty(URI.create(dtp.getName())); + + stack.push(factory.getOWLDataValueRestriction(prop, constant)); } /* (non-Javadoc) @@ -218,7 +245,7 @@ */ public void visit(ADC description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -226,7 +253,7 @@ */ public void visit(DatatypeMinCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -234,7 +261,7 @@ */ public void visit(DatatypeExactCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -242,7 +269,7 @@ */ public void visit(DatatypeMaxCardinalityRestriction description) { // TODO Auto-generated method stub - + throw new Error("OWLAPIDescriptionConverter: not implemented"); } /* (non-Javadoc) @@ -250,7 +277,18 @@ */ public void visit(DatatypeSomeRestriction description) { // TODO Auto-generated method stub + throw new Error("OWLAPIDescriptionConverter: not implemented"); + } + + public OWLDataType convertDatatype(Datatype datatype) { + if(datatype.equals(Datatype.BOOLEAN)) + return factory.getOWLDataType(Datatype.BOOLEAN.getURI()); + else if(datatype.equals(Datatype.INT)) + return factory.getOWLDataType(Datatype.INT.getURI()); + else if(datatype.equals(Datatype.DOUBLE)) + return factory.getOWLDataType(Datatype.DOUBLE.getURI()); + throw new Error("OWLAPIDescriptionConverter: datatype not implemented"); } - + } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-02-26 18:13:23 UTC (rev 642) @@ -419,7 +419,7 @@ @Override public boolean subsumes(Description superConcept, Description subConcept) { try { - return reasoner.isSubClassOf(getOWLAPIDescription(subConcept), getOWLAPIDescription(superConcept)); + return reasoner.isSubClassOf(OWLAPIDescriptionConvertVisitor.getOWLDescription(subConcept), OWLAPIDescriptionConvertVisitor.getOWLDescription(superConcept)); } catch (OWLReasonerException e) { e.printStackTrace(); throw new Error("Subsumption Error in OWL API."); Modified: trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-02-26 18:13:23 UTC (rev 642) @@ -3,6 +3,7 @@ import java.util.Comparator; import java.util.Set; +import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -51,6 +52,9 @@ // Ordnung für atomare Konzepte: Stringvergleich // Ordnung für atomare Rollen: Stringvergleich public int compare(Description concept1, Description concept2) { + // classes higher up are in the source code have lower value + // (they appear first in class descriptions, because sorted sets + // usually use an ascending order) if(concept1 instanceof Nothing) { if(concept2 instanceof Nothing) return 0; @@ -100,6 +104,17 @@ return roleCompare; } else return -1; + } else if(concept1 instanceof BooleanValueRestriction) { + if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction) { + return 1; + } else if(concept2 instanceof BooleanValueRestriction) { + int cmp = rc.compare(((BooleanValueRestriction)concept1).getRestrictedPropertyExpresssion(), ((BooleanValueRestriction)concept2).getRestrictedPropertyExpresssion()); + if(cmp == 0) + return compare(concept1.getChild(0), concept2.getChild(0)); + else + return cmp; + } else + return -1; } else if(concept1 instanceof Intersection) { if(concept2.getChildren().size()<2) return 1; Modified: trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-26 13:25:32 UTC (rev 641) +++ trunk/src/dl-learner/org/dllearner/utilities/RoleComparator.java 2008-02-26 18:13:23 UTC (rev 642) @@ -21,33 +21,47 @@ import java.util.Comparator; +import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectPropertyInverse; +import org.dllearner.core.owl.PropertyExpression; /** - * Compares two object properties. + * Compares two property expressions. The order is: + * datatype properties first, then inverse object properties, then + * object properties. For equal types, the URI or toString (inverses) + * is used to fix an order. * * @author Jens Lehmann * */ -public class RoleComparator implements Comparator<ObjectPropertyExpression> { +public class RoleComparator implements Comparator<PropertyExpression> { - public int compare(ObjectPropertyExpression r1, ObjectPropertyExpression r2) { + public int compare(PropertyExpression r1, PropertyExpression r2) { if(r1 instanceof ObjectProperty) { if(r2 instanceof ObjectProperty) { - return r1.getName().compareTo(r2.getName()); - // zweite Rolle ist invers + return ((ObjectProperty)r1).getName().compareTo(((ObjectProperty)r2).getName()); + // second role is inverse or datatype property } else { return -1; } - // 1. Rolle ist invers - } else { - if(r1 instanceof ObjectProperty) { + // first property is an inverse object property + } else if(r1 instanceof ObjectPropertyInverse){ + if(r2 instanceof ObjectProperty) { return 1; + } else if(r2 instanceof ObjectPropertyInverse){ + return r1.toString().compareTo(r2.toString()); } else { - return r1.getName().compareTo(r2.getName()); + return -1; } + // r1 is datatype property + } else { + if(r2 instanceof DatatypeProperty) { + return ((DatatypeProperty)r1).getName().compareTo(((DatatypeProperty)r2).getName()); + } else { + return 1; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |