From: <jen...@us...> - 2008-03-10 17:54:15
|
Revision: 700 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=700&view=rev Author: jenslehmann Date: 2008-03-10 10:53:52 -0700 (Mon, 10 Mar 2008) Log Message: ----------- double datatype learning support Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.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/refinementoperators/RhoDRDown.java trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/SimpleDoubleDataRange.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-10 17:53:52 UTC (rev 700) @@ -100,6 +100,12 @@ private boolean useOverlyGeneralList = true; private boolean useShortConceptConstruction = true; + // if set to false we do not test properness; this may seem wrong + // but the disadvantage of properness testing are additional reasoner + // queries and a search bias towards ALL r.something because + // ALL r.TOP is improper and automatically expanded further + private boolean testProperness = false; + // setting to true gracefully stops the algorithm private boolean stop = false; @@ -431,11 +437,13 @@ Set<Description> improperConcepts = null; if(toEvaluateConcepts.size()>0) { // Test aller Konzepte auf properness (mit DIG in nur einer Anfrage) - long propCalcReasoningStart = System.nanoTime(); - improperConcepts = rs.subsumes(toEvaluateConcepts, concept); - propernessTestsReasoner+=toEvaluateConcepts.size(); - // boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); - propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; + if(testProperness) { + long propCalcReasoningStart = System.nanoTime(); + improperConcepts = rs.subsumes(toEvaluateConcepts, concept); + propernessTestsReasoner+=toEvaluateConcepts.size(); + // boolean isProper = !learningProblem.getReasoningService().subsumes(refinement, concept); + propernessCalcReasoningTimeNs += System.nanoTime() - propCalcReasoningStart; + } } long improperConceptsRemovalTimeNsStart = System.nanoTime(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/MultiHeuristic.java 2008-03-10 17:53:52 UTC (rev 700) @@ -77,7 +77,7 @@ private double expansionPenaltyFactor; private double gainBonusFactor; private double nodeChildPenalty = 0.0001; - private double startNodeBonus = 0.8; + private double startNodeBonus = 0.1; // examples private int nrOfNegativeExamples; Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-10 17:53:52 UTC (rev 700) @@ -79,6 +79,12 @@ public Map<Individual, SortedSet<Constant>> getDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + // some convenience methods + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public Map<Individual, SortedSet<Boolean>> getBooleanDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException; + public boolean instanceCheck(Description concept, Individual individual) throws ReasoningMethodUnsupportedException; // mehrere instance checks für ein Konzept - spart bei DIG Anfragen Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-10 17:53:52 UTC (rev 700) @@ -459,6 +459,42 @@ return result; } + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return reasoner.getDoubleDatatypeMembers(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Double>> getIntDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return reasoner.getDoubleDatatypeMembers(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Double>> getTrueDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return reasoner.getDoubleDatatypeMembers(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + public Map<Individual, SortedSet<Double>> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) { + try { + return reasoner.getDoubleDatatypeMembers(datatypeProperty); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + public Set<NamedClass> getAtomicConcepts() { return reasoner.getAtomicConcepts(); } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/core/owl/DatatypeSomeRestriction.java 2008-03-10 17:53:52 UTC (rev 700) @@ -32,11 +32,14 @@ */ public class DatatypeSomeRestriction extends DatatypeQuantorRestriction { + DataRange dataRange; + /** * @param datatypeProperty */ - public DatatypeSomeRestriction(DatatypeProperty datatypeProperty) { + public DatatypeSomeRestriction(DatatypeProperty datatypeProperty, DataRange dataRange) { super(datatypeProperty); + this.dataRange = dataRange; } /* (non-Javadoc) @@ -44,7 +47,6 @@ */ @Override public int getArity() { - // TODO Auto-generated method stub return 0; } @@ -52,16 +54,14 @@ * @see org.dllearner.core.owl.KBElement#getLength() */ public int getLength() { - // TODO Auto-generated method stub - return 0; + return 1 + dataRange.getLength(); } /* (non-Javadoc) * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return restrictedPropertyExpression.toString(baseURI, prefixes) + dataRange.toString(baseURI, prefixes); } /* (non-Javadoc) @@ -83,5 +83,12 @@ public String toManchesterSyntaxString(String baseURI, Map<String,String> prefixes) { // TODO Auto-generated method stub return null; + } + + /** + * @return the dataRange + */ + public DataRange getDataRange() { + return dataRange; } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/core/owl/DoubleMaxValue.java 2008-03-10 17:53:52 UTC (rev 700) @@ -28,7 +28,7 @@ * @author Jens Lehmann * */ -public class DoubleMaxValue implements DoubleDataRange { +public class DoubleMaxValue implements SimpleDoubleDataRange { private double value; @@ -54,8 +54,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return " <= " + value; } public void accept(KBElementVisitor visitor) { Modified: trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/core/owl/DoubleMinValue.java 2008-03-10 17:53:52 UTC (rev 700) @@ -22,13 +22,13 @@ import java.util.Map; /** - * Double data range restricted by a maximum value, e.g. + * Double data range restricted by a minimum value, e.g. * hasAge >= 18. * * @author Jens Lehmann * */ -public class DoubleMinValue implements DoubleDataRange { +public class DoubleMinValue implements SimpleDoubleDataRange { private double value; @@ -54,8 +54,7 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return " >= " + value; } public void accept(KBElementVisitor visitor) { Added: trunk/src/dl-learner/org/dllearner/core/owl/SimpleDoubleDataRange.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/SimpleDoubleDataRange.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/SimpleDoubleDataRange.java 2008-03-10 17:53:52 UTC (rev 700) @@ -0,0 +1,33 @@ +/** + * 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 double data range with a single value used for restrictions, + * e.g. hasAge >= 18 (but not 65 >= hasAge >= 18). + * + * @author Jens Lehmann + * + */ +public interface SimpleDoubleDataRange extends DoubleDataRange { + + public double getValue(); + +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-10 17:53:52 UTC (rev 700) @@ -37,9 +37,13 @@ import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.InvalidConfigOptionValueException; import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DoubleMaxValue; +import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -206,6 +210,9 @@ @Override public boolean instanceCheck(Description description, Individual individual) throws ReasoningMethodUnsupportedException { + +// System.out.println(description + " " + individual); + if (description instanceof NamedClass) { return classInstancesPos.get((NamedClass) description).contains(individual); } else if (description instanceof Negation) { @@ -294,6 +301,28 @@ } else { return bdNeg.get(dp).contains(individual); } + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DataRange dr = dsr.getDataRange(); + SortedSet<Double> values = dd.get(dp).get(individual); + + // if there is no filler for this individual and property we + // need to return false + if(values == null) + return false; + + if(dr instanceof DoubleMaxValue) { + if(values.first() <= ((DoubleMaxValue)dr).getValue()) + return true; + else + return false; + } else if(dr instanceof DoubleMinValue) { + if(values.last() >= ((DoubleMinValue)dr).getValue()) + return true; + else + return false; + } } throw new ReasoningMethodUnsupportedException("Instance check for description " @@ -325,6 +354,11 @@ return atomicConcepts; } + @Override + public Map<Individual, SortedSet<Double>> getDoubleDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + return rc.getDoubleDatatypeMembers(datatypeProperty); + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-03-10 17:53:52 UTC (rev 700) @@ -35,6 +35,7 @@ import org.dllearner.core.owl.DatatypeValueRestriction; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DescriptionVisitor; +import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; @@ -45,6 +46,7 @@ import org.dllearner.core.owl.ObjectMinCardinalityRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; +import org.dllearner.core.owl.SimpleDoubleDataRange; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.TypedConstant; import org.dllearner.core.owl.Union; @@ -55,9 +57,13 @@ import org.semanticweb.owl.model.OWLConstant; import org.semanticweb.owl.model.OWLDataFactory; import org.semanticweb.owl.model.OWLDataProperty; +import org.semanticweb.owl.model.OWLDataRange; import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLObjectProperty; +import org.semanticweb.owl.model.OWLTypedConstant; +import org.semanticweb.owl.vocab.OWLRestrictedDataRangeFacetVocabulary; +import org.semanticweb.owl.vocab.XSDVocabulary; /** * Converter from DL-Learner descriptions to OWL API descriptions based @@ -212,7 +218,8 @@ public void visit(DatatypeValueRestriction description) { // convert OWL constant to OWL API constant Constant c = description.getValue(); - OWLConstant constant; + OWLConstant constant = convertConstant(c); + /* if(c instanceof TypedConstant) { Datatype dt = ((TypedConstant)c).getDatatype(); OWLDataType odt = convertDatatype(dt); @@ -225,6 +232,7 @@ constant = factory.getOWLUntypedConstant(uc.getLiteral()); } } + */ // get datatype property DatatypeProperty dtp = description.getRestrictedPropertyExpresssion(); @@ -276,8 +284,28 @@ * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.DatatypeSomeRestriction) */ public void visit(DatatypeSomeRestriction description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); + + // TODO: currently works only for double min/max + + DatatypeProperty dp = (DatatypeProperty) description.getRestrictedPropertyExpression(); + // currently only double restrictions implemented + SimpleDoubleDataRange dr = (SimpleDoubleDataRange) description.getDataRange(); + Double value = dr.getValue(); + + OWLDataType doubleDataType = factory.getOWLDataType(XSDVocabulary.DOUBLE.getURI()); + OWLTypedConstant constant = factory.getOWLTypedConstant(value.toString(), doubleDataType); + + OWLRestrictedDataRangeFacetVocabulary facet; + if(dr instanceof DoubleMinValue) + facet = OWLRestrictedDataRangeFacetVocabulary.MIN_INCLUSIVE; + else + facet = OWLRestrictedDataRangeFacetVocabulary.MAX_INCLUSIVE; + + OWLDataRange owlDataRange = factory.getOWLDataRangeRestriction(doubleDataType, facet, constant); + OWLDataProperty odp = factory.getOWLDataProperty(URI.create(dp.getName())); + OWLDescription d = factory.getOWLDataSomeRestriction(odp, owlDataRange); + + stack.push(d); } public OWLDataType convertDatatype(Datatype datatype) { @@ -291,4 +319,20 @@ throw new Error("OWLAPIDescriptionConverter: datatype not implemented"); } + private OWLConstant convertConstant(Constant constant) { + OWLConstant owlConstant; + if(constant instanceof TypedConstant) { + Datatype dt = ((TypedConstant)constant).getDatatype(); + OWLDataType odt = convertDatatype(dt); + owlConstant = factory.getOWLTypedConstant(constant.getLiteral(), odt); + } else { + UntypedConstant uc = (UntypedConstant) constant; + if(uc.hasLang()) { + owlConstant = factory.getOWLUntypedConstant(uc.getLiteral(), uc.getLang()); + } else { + owlConstant = factory.getOWLUntypedConstant(uc.getLiteral()); + } + } + return owlConstant; + } } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-10 17:53:52 UTC (rev 700) @@ -19,6 +19,7 @@ */ package org.dllearner.refinementoperators; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -29,12 +30,17 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.Map.Entry; import org.dllearner.algorithms.refinement.RefinementOperator; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DoubleMaxValue; +import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; @@ -119,7 +125,11 @@ // concept comparator private ConceptComparator conceptComparator = new ConceptComparator(); - // Statistik + // splits for double datatype properties in ascening order + private Map<DatatypeProperty,List<Double>> splits = new TreeMap<DatatypeProperty,List<Double>>(); + private int maxNrOfSplits = 20; + + // staistics public long mComputationTimeNs = 0; public long topComputationTimeNs = 0; @@ -129,6 +139,7 @@ private boolean useExistsConstructor = true; private boolean useNegation = true; private boolean useBooleanDatatypes = true; + private boolean useDoubleDatatypes = true; private boolean disjointChecks = true; private boolean instanceBasedDisjoints = true; @@ -165,38 +176,29 @@ dpDomains.put(dp, rs.getDomain(dp)); } + // compute splits for double datatype properties + for(DatatypeProperty dp : rs.getDoubleDatatypeProperties()) { + computeSplits(dp); + } + /* - NamedClass struc = new NamedClass("http://dl-learner.org/carcinogenesis#Compound"); + NamedClass struc = new NamedClass("http://dl-learner.org/carcinogenesis#Atom"); ObjectProperty op = new ObjectProperty("http://dl-learner.org/carcinogenesis#hasAtom"); - ObjectAllRestriction oar = new ObjectAllRestriction(op,struc); - String str = "((\"http://dl-learner.org/carcinogenesis#amesTestPositive\" IS FALSE) OR ALL \"http://dl-learner.org/carcinogenesis#hasAtom\".TOP)"; - Description desc = null; - try { - desc = KBParser.parseConcept(str); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// System.out.println(oar.getLength()); -// computeTopRefinements(3,struc); -// for(Description d : topARefinements.get(struc).get(1)) { - // bei 3 ist noch alles OK, bei 4 seltsamer Fehler mit Union - Set<Description> ds = refine(struc,10,null,struc); - Set<Description> improper = new HashSet<Description>(); + ObjectSomeRestriction oar = new ObjectSomeRestriction(op,Thing.instance); + + Set<Description> ds = refine(Thing.instance,3,null,struc); +// Set<Description> improper = new HashSet<Description>(); for(Description d : ds) { -// if(d instanceof Union) - if(rs.subsumes(d, struc)) { - improper.add(d); +// if(rs.subsumes(d, struc)) { +// improper.add(d); System.out.println(d); - } +// } } -// System.out.println(refine(Thing.instance,7,null,struc).size()); System.out.println(ds.size()); - System.out.println(improper.size()); +// System.out.println(improper.size()); System.exit(0); */ - - + if(startClass != null) this.startClass = startClass; } @@ -356,6 +358,36 @@ refinements.add(new ObjectAllRestriction(moreSpecialRole, description.getChild(0))); } + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DataRange dr = dsr.getDataRange(); + if(dr instanceof DoubleMaxValue) { + double value = ((DoubleMaxValue)dr).getValue(); + // find out which split value was used + int splitIndex = splits.get(dp).lastIndexOf(value); + if(splitIndex == -1) + throw new Error("split error"); + int newSplitIndex = splitIndex - 1; + if(newSplitIndex >= 0) { + DoubleMaxValue max = new DoubleMaxValue(splits.get(dp).get(newSplitIndex)); + DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,max); + refinements.add(newDSR); +// System.out.println(description + " => " + newDSR); + } + } else if(dr instanceof DoubleMinValue) { + double value = ((DoubleMinValue)dr).getValue(); + // find out which split value was used + int splitIndex = splits.get(dp).lastIndexOf(value); + if(splitIndex == -1) + throw new Error("split error"); + int newSplitIndex = splitIndex + 1; + if(newSplitIndex < splits.get(dp).size()) { + DoubleMinValue min = new DoubleMinValue(splits.get(dp).get(newSplitIndex)); + DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,min); + refinements.add(newDSR); + } + } } // if a refinement is not Bottom, Top, ALL r.Bottom a refinement of top can be appended @@ -606,6 +638,16 @@ } } + if(useDoubleDatatypes) { + Set<DatatypeProperty> doubleDPs = rs.getDoubleDatatypeProperties(); + for(DatatypeProperty dp : doubleDPs) { + DoubleMaxValue max = new DoubleMaxValue(splits.get(dp).get(splits.get(dp).size()-1)); + DoubleMinValue min = new DoubleMinValue(splits.get(dp).get(0)); + m3.add(new DatatypeSomeRestriction(dp,max)); + m3.add(new DatatypeSomeRestriction(dp,min)); + } + } + m.put(3,m3); mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; @@ -677,6 +719,24 @@ } } + if(useDoubleDatatypes) { + Set<DatatypeProperty> doubleDPs = mgdd.get(nc); +// System.out.println("cached disjoints " + cachedDisjoints); +// System.out.println("appOP " + appOP); +// System.out.println("appBD " + appBD); +// System.out.println("appDD " + appDD); +// System.out.println("mgr " + mgr); +// System.out.println("mgbd " + mgbd); +// System.out.println("mgdd " + mgdd); + + for(DatatypeProperty dp : doubleDPs) { + DoubleMaxValue max = new DoubleMaxValue(splits.get(dp).get(splits.get(dp).size()-1)); + DoubleMinValue min = new DoubleMinValue(splits.get(dp).get(0)); + m3.add(new DatatypeSomeRestriction(dp,max)); + m3.add(new DatatypeSomeRestriction(dp,min)); + } + } + mA.get(nc).put(3,m3); mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; @@ -755,10 +815,11 @@ appBD.put(domain, applicableBDPs); // double datatype properties - Set<DatatypeProperty> mostGeneralDDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> mostGeneralDDPs = rs.getDoubleDatatypeProperties(); Set<DatatypeProperty> applicableDDPs = new TreeSet<DatatypeProperty>(); for(DatatypeProperty role : mostGeneralDDPs) { Description d = (NamedClass) rs.getDomain(role); +// System.out.println("domain: " + d); if(!isDisjoint(domain,d)) applicableDDPs.add(role); } @@ -788,16 +849,18 @@ } private boolean isDisjoint(Description d1, Description d2) { - // equal concepts are not disjoint (unless equivalent to bottom) -// if(conceptComparator.compare(d1, d2)==0) -// return false; +// System.out.println("| " + d1 + " " + d2); +// System.out.println("| " + cachedDisjoints); + // check whether we have cached this query Map<Description,Boolean> tmp = cachedDisjoints.get(d1); Boolean tmp2 = null; if(tmp != null) tmp2 = tmp.get(d2); +// System.out.println("| " + tmp + " " + tmp2); + if(tmp2==null) { Boolean result; if(instanceBasedDisjoints) { @@ -809,24 +872,33 @@ // add the result to the cache (we add it twice such that // the order of access does not matter) +// System.out.println("| result: " + result); + // create new entries if necessary - Map<Description,Boolean> map = new TreeMap<Description,Boolean>(conceptComparator); + Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator); + Map<Description,Boolean> map2 = new TreeMap<Description,Boolean>(conceptComparator); if(tmp == null) - cachedDisjoints.put(d1, map); + cachedDisjoints.put(d1, map1); if(!cachedDisjoints.containsKey(d2)) - cachedDisjoints.put(d2, map); + cachedDisjoints.put(d2, map2); // add result symmetrically in the description matrix cachedDisjoints.get(d1).put(d2, result); cachedDisjoints.get(d2).put(d1, result); +// System.out.println("---"); return result; - } else + } else { +// System.out.println("==="); return tmp2; + } } private boolean isDisjointInstanceBased(Description d1, Description d2) { - Set<Individual> d1Instances = rs.retrieval(d1); - Set<Individual> d2Instances = rs.retrieval(d2); + SortedSet<Individual> d1Instances = rs.retrieval(d1); + SortedSet<Individual> d2Instances = rs.retrieval(d2); +// System.out.println(d1 + " " + d2); +// System.out.println(d1 + " " + d1Instances); +// System.out.println(d2 + " " + d2Instances); for(Individual d1Instance : d1Instances) { if(d2Instances.contains(d1Instance)) return false; @@ -870,4 +942,34 @@ return !rs.subsumes(d, b); } + private void computeSplits(DatatypeProperty dp) { + Set<Double> valuesSet = new TreeSet<Double>(); +// Set<Individual> individuals = rs.getIndividuals(); + Map<Individual,SortedSet<Double>> valueMap = rs.getDoubleDatatypeMembers(dp); + // add all values to the set (duplicates will be remove automatically) + for(Entry<Individual,SortedSet<Double>> e : valueMap.entrySet()) + valuesSet.addAll(e.getValue()); + // convert set to a list where values are sorted + List<Double> values = new LinkedList<Double>(valuesSet); + Collections.sort(values); + + int nrOfValues = values.size(); + // create split set + List<Double> splitsDP = new LinkedList<Double>(); + for(int splitNr=0; splitNr < maxNrOfSplits; splitNr++) { + int index; + if(nrOfValues<=maxNrOfSplits) + index = splitNr; + else + index = (int) Math.floor(splitNr * (double)nrOfValues/(maxNrOfSplits+1)); + + double value = 0.5*(values.get(index)+values.get(index+1)); + splitsDP.add(value); + } + splits.put(dp, splitsDP); + +// System.out.println(values); +// System.out.println(splits); +// System.exit(0); + } } \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-03-09 19:25:46 UTC (rev 699) +++ trunk/src/dl-learner/org/dllearner/utilities/ConceptComparator.java 2008-03-10 17:53:52 UTC (rev 700) @@ -4,12 +4,17 @@ import java.util.Set; import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypeSomeRestriction; +import org.dllearner.core.owl.DoubleMaxValue; +import org.dllearner.core.owl.DoubleMinValue; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.SimpleDoubleDataRange; import org.dllearner.core.owl.Union; import org.dllearner.core.owl.Negation; import org.dllearner.core.owl.ObjectQuantorRestriction; @@ -94,8 +99,44 @@ return cmp; } else return -1; + } else if(concept1 instanceof DatatypeSomeRestriction) { + if(concept2 instanceof Nothing || concept2 instanceof NamedClass || concept2 instanceof BooleanValueRestriction) { + return 1; + } else if(concept2 instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) concept1; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DatatypeSomeRestriction dsr2 = (DatatypeSomeRestriction) concept2; + DatatypeProperty dp2 = (DatatypeProperty) dsr2.getRestrictedPropertyExpression(); + + // first criterion: name of the properties + int cmp = rc.compare(dp, dp2); + + if(cmp == 0) { + SimpleDoubleDataRange dr = (SimpleDoubleDataRange) dsr.getDataRange(); + SimpleDoubleDataRange dr2 = (SimpleDoubleDataRange) dsr2.getDataRange(); + + // equal classes + if((dr instanceof DoubleMaxValue && dr2 instanceof DoubleMaxValue) + || (dr instanceof DoubleMinValue && dr2 instanceof DoubleMinValue)) { + double val1 = dr.getValue(); + double val2 = dr2.getValue(); + if(val1 > val2) + return 1; + else if(val1 == val2) + return 0; + else + return -1; + + } else if(dr instanceof DoubleMaxValue) + return 1; + else + return -1; + } else + return cmp; + } else + return -1; } else if(concept1 instanceof Thing) { - if(concept2 instanceof Nothing || concept2 instanceof NamedClass || concept2 instanceof BooleanValueRestriction) + if(concept2 instanceof Nothing || concept2 instanceof NamedClass || concept2 instanceof BooleanValueRestriction || concept2 instanceof DatatypeSomeRestriction) return 1; else if(concept2 instanceof Thing) return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |