From: <jen...@us...> - 2010-02-02 09:16:55
|
Revision: 1988 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1988&view=rev Author: jenslehmann Date: 2010-02-02 09:16:38 +0000 (Tue, 02 Feb 2010) Log Message: ----------- preliminary/untested support for hasValue with datatypes (currently strings only) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/owl/StringValueRestriction.java Modified: trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2010-02-01 16:58:22 UTC (rev 1987) +++ trunk/src/dl-learner/org/dllearner/core/BaseReasoner.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -102,6 +102,15 @@ public SortedSet<DatatypeProperty> getIntDatatypeProperties(); /** + * Gets all data properties with range xsd:string. + * TODO We could extend this to all types, which can be parsed into + * strings and even include the properties without any specified datatype. + * @see org.dllearner.core.owl.Datatype#String + * @return String data properties in KB. + */ + public SortedSet<DatatypeProperty> getStringDatatypeProperties(); + + /** * Gets all individuals in the knowledge base, e.g. Eric, London, Car829. * @return All individuals in KB. */ Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2010-02-01 16:58:22 UTC (rev 1987) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -771,6 +771,21 @@ } @Override + public final SortedSet<DatatypeProperty> getStringDatatypeProperties() { + try { + return getStringDatatypePropertiesImpl(); + } catch (ReasoningMethodUnsupportedException e) { + handleExceptions(e); + return null; + } + } + + protected SortedSet<DatatypeProperty> getStringDatatypePropertiesImpl() + throws ReasoningMethodUnsupportedException { + throw new ReasoningMethodUnsupportedException(); + } + + @Override public final Description getDomain(ObjectProperty objectProperty) { try { return getDomainImpl(objectProperty); Modified: trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2010-02-01 16:58:22 UTC (rev 1987) +++ trunk/src/dl-learner/org/dllearner/core/owl/Datatype.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -30,7 +30,8 @@ DOUBLE ("http://www.w3.org/2001/XMLSchema#double"), INT ("http://www.w3.org/2001/XMLSchema#int"), - BOOLEAN ("http://www.w3.org/2001/XMLSchema#boolean"); + BOOLEAN ("http://www.w3.org/2001/XMLSchema#boolean"), + STRING ("http://www.w3.org/2001/XMLSchema#string"); private URI uri; @@ -51,6 +52,10 @@ return 1; } + public void accept(KBElementVisitor visitor) { + visitor.visit(this); + } + public String toString(String baseURI, Map<String, String> prefixes) { return uri.toString(); } @@ -59,16 +64,11 @@ return uri.toString(); } - public void accept(KBElementVisitor visitor) { - visitor.visit(this); - } - /* (non-Javadoc) * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map) */ @Override public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) { - // TODO Auto-generated method stub - return null; + return uri.toString(); } } Added: trunk/src/dl-learner/org/dllearner/core/owl/StringValueRestriction.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/StringValueRestriction.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/owl/StringValueRestriction.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2007-2010, 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; + +/** + * + * String value restriction, e.g. \exists description hasValue "interesting item". + * + * @author Jens Lehmann + * + */ +public class StringValueRestriction extends DatatypeValueRestriction { + + public StringValueRestriction(DatatypeProperty restrictedPropertyExpression, String value) { + super(restrictedPropertyExpression, new TypedConstant(value.toString(), Datatype.STRING)); + } + + private static final long serialVersionUID = 5651982376457935975L; + + @Override + public int getLength() { + return 3; + } + +} Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2010-02-01 16:58:22 UTC (rev 1987) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -145,6 +145,7 @@ SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> stringDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); // namespaces @@ -192,6 +193,7 @@ booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); intDatatypeProperties = new TreeSet<DatatypeProperty>(); + stringDatatypeProperties = new TreeSet<DatatypeProperty>(); individuals = new TreeSet<Individual>(); // create OWL API ontology manager @@ -377,7 +379,9 @@ else if(uri.equals(Datatype.DOUBLE.getURI())) doubleDatatypeProperties.add(dtp); else if(uri.equals(Datatype.INT.getURI())) - intDatatypeProperties.add(dtp); + intDatatypeProperties.add(dtp); + else if(uri.equals(Datatype.STRING.getURI())) + intDatatypeProperties.add(dtp); } } datatypeProperties.add(dtp); @@ -976,6 +980,14 @@ public SortedSet<DatatypeProperty> getIntDatatypePropertiesImpl() { return intDatatypeProperties; } + + /** + * @return the intDatatypeProperties + */ + @Override + public SortedSet<DatatypeProperty> getStringDatatypePropertiesImpl() { + return stringDatatypeProperties; + } /* (non-Javadoc) * @see org.dllearner.core.Reasoner#getBaseURI() Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2010-02-01 16:58:22 UTC (rev 1987) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2010-02-02 09:16:38 UTC (rev 1988) @@ -40,6 +40,7 @@ import org.dllearner.core.options.CommonConfigOptions; import org.dllearner.core.owl.BooleanValueRestriction; import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Constant; import org.dllearner.core.owl.DataRange; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DatatypeSomeRestriction; @@ -60,6 +61,7 @@ import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; +import org.dllearner.core.owl.StringValueRestriction; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; import org.dllearner.utilities.Helper; @@ -158,6 +160,10 @@ private Map<ObjectProperty, Map<Individual, Integer>> valueFrequency = new HashMap<ObjectProperty, Map<Individual, Integer>>(); // data structure with identified frequent values private Map<ObjectProperty, Set<Individual>> frequentValues = new HashMap<ObjectProperty, Set<Individual>>(); + // frequent data values + private Map<DatatypeProperty, Set<Constant>> frequentDataValues = new HashMap<DatatypeProperty, Set<Constant>>(); + private Map<DatatypeProperty, Map<Constant, Integer>> dataValueFrequency = new HashMap<DatatypeProperty, Map<Constant, Integer>>(); + private boolean useDataHasValueConstructor = false; // staistics public long mComputationTimeNs = 0; @@ -263,13 +269,12 @@ } } - // keep only frequent patterns (TODO it would be slightly - // more efficient if we stop adding to valueFrequency - // after threshold is reached) + // keep only frequent patterns Set<Individual> frequentInds = new TreeSet<Individual>(); for(Individual i : opMap.keySet()) { if(opMap.get(i) >= frequencyThreshold) { frequentInds.add(i); + break; } } frequentValues.put(op, frequentInds); @@ -278,14 +283,45 @@ } + for(DatatypeProperty dp : rs.getDatatypeProperties()) { + dpDomains.put(dp, rs.getDomain(dp)); + + if(useDataHasValueConstructor) { + Map<Constant, Integer> dpMap = new TreeMap<Constant, Integer>(); + dataValueFrequency.put(dp, dpMap); + + // sets ordered by corresponding individual (which we ignore) + Collection<SortedSet<Constant>> fillerSets = rs.getDatatypeMembers(dp).values(); + for(SortedSet<Constant> fillerSet : fillerSets) { + for(Constant i : fillerSet) { +// System.out.println("op " + op + " i " + i); + Integer value = dpMap.get(i); + + if(value != null) { + dpMap.put(i, value+1); + } else { + dpMap.put(i, 1); + } + } + } + + // keep only frequent patterns + Set<Constant> frequentInds = new TreeSet<Constant>(); + for(Constant i : dpMap.keySet()) { + if(dpMap.get(i) >= frequencyThreshold) { + frequentInds.add(i); + break; + } + } + frequentDataValues.put(dp, frequentInds); + } + } + // we do not need the temporary set anymore and let the // garbage collector take care of it valueFrequency = null; + dataValueFrequency = null; - for(DatatypeProperty dp : rs.getDatatypeProperties()) { - dpDomains.put(dp, rs.getDomain(dp)); - } - // compute splits for double datatype properties for(DatatypeProperty dp : rs.getDoubleDatatypeProperties()) { computeSplits(dp); @@ -930,6 +966,17 @@ } } + if(useDataHasValueConstructor) { + Set<DatatypeProperty> stringDPs = rs.getStringDatatypeProperties(); + for(DatatypeProperty dp : stringDPs) { + // loop over frequent values + Set<Constant> freqValues = frequentDataValues.get(dp); + for(Constant c : freqValues) { + m3.add(new StringValueRestriction(dp, c.getLiteral())); + } + } + } + m.put(3,m3); SortedSet<Description> m4 = new TreeSet<Description>(conceptComparator); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |