|
From: <lor...@us...> - 2014-05-23 12:03:42
|
Revision: 4271
http://sourceforge.net/p/dl-learner/code/4271
Author: lorenz_b
Date: 2014-05-23 12:03:39 +0000 (Fri, 23 May 2014)
Log Message:
-----------
Added support for inter min max datarange.
Modified Paths:
--------------
trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java
trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java
trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java
trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java
trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java 2014-05-22 11:04:32 UTC (rev 4270)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/IntMaxValue.java 2014-05-23 12:03:39 UTC (rev 4271)
@@ -58,11 +58,11 @@
* @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map)
*/
public String toString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return "integer[<= " + value + "]";
}
public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return "integer[<= " + value + "]";
}
public void accept(KBElementVisitor visitor) {
@@ -74,7 +74,7 @@
*/
@Override
public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " <= " + value;
+ return "integer[<= " + value + "]";
}
/* (non-Javadoc)
@@ -85,4 +85,12 @@
return false;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return toString(null, null);
+ }
+
}
Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java 2014-05-22 11:04:32 UTC (rev 4270)
+++ trunk/components-core/src/main/java/org/dllearner/core/owl/IntMinValue.java 2014-05-23 12:03:39 UTC (rev 4271)
@@ -58,11 +58,11 @@
* @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map)
*/
public String toString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return "integer[>= " + value + "]";
}
public String toKBSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return "integer[>= " + value + "]";
}
public void accept(KBElementVisitor visitor) {
@@ -74,7 +74,7 @@
*/
@Override
public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
- return " >= " + value;
+ return "integer[>= " + value + "]";
}
/* (non-Javadoc)
@@ -84,4 +84,12 @@
public boolean isDatatype() {
return false;
}
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return toString(null, null);
+ }
}
Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-05-22 11:04:32 UTC (rev 4270)
+++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2014-05-23 12:03:39 UTC (rev 4271)
@@ -53,6 +53,8 @@
import org.dllearner.core.owl.DoubleMinValue;
import org.dllearner.core.owl.Entity;
import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.IntMaxValue;
+import org.dllearner.core.owl.IntMinValue;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.Negation;
@@ -73,8 +75,6 @@
import org.dllearner.parser.ParseException;
import org.dllearner.utilities.Helper;
import org.dllearner.utilities.owl.ConceptTransformation;
-import org.semanticweb.owlapi.owllink.builtin.requests.IsDataPropertySatisfiable;
-import org.semanticweb.owlapi.vocab.OWL2Datatype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
@@ -563,22 +563,39 @@
} else {
return false;
}
- }
- SortedSet<Double> values = dd.get(dp).get(individual);
+ } else {
+ if(dr instanceof IntMaxValue || dr instanceof IntMinValue){
+ SortedSet<Integer> values = id.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 there is no filler for this individual and property we
+ // need to return false
+ if (values == null) {
+ return false;
+ }
+ if (dr instanceof IntMaxValue) {
+ return (values.first() <= ((IntMaxValue) dr).getValue());
+ } else if (dr instanceof IntMinValue) {
+ return (values.last() >= ((IntMinValue) dr).getValue());
+ }
+ } else {
+ SortedSet<Double> values = dd.get(dp).get(individual);
- if (dr instanceof DoubleMaxValue) {
- return (values.first() <= ((DoubleMaxValue) dr).getValue());
- } else if (dr instanceof DoubleMinValue) {
- return (values.last() >= ((DoubleMinValue) dr).getValue());
- } else if (dr instanceof DoubleMinMaxRange){
- return (values.first() <= ((DoubleMinMaxRange) dr).getMaxValue()) && (values.last() >= ((DoubleMinMaxRange) dr).getMinValue());
+ // if there is no filler for this individual and property we
+ // need to return false
+ if (values == null) {
+ return false;
+ }
+ if (dr instanceof DoubleMaxValue) {
+ return (values.first() <= ((DoubleMaxValue) dr).getValue());
+ } else if (dr instanceof DoubleMinValue) {
+ return (values.last() >= ((DoubleMinValue) dr).getValue());
+ } else if (dr instanceof DoubleMinMaxRange){
+ return (values.first() <= ((DoubleMinMaxRange) dr).getMaxValue()) && (values.last() >= ((DoubleMinMaxRange) dr).getMinValue());
+ }
+ }
+
}
+
} else if (description instanceof DatatypeValueRestriction) {
Constant value = ((DatatypeValueRestriction)description).getValue();
DatatypeProperty dp = ((DatatypeValueRestriction)description).getRestrictedPropertyExpression();
Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-05-22 11:04:32 UTC (rev 4270)
+++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2014-05-23 12:03:39 UTC (rev 4271)
@@ -53,6 +53,8 @@
import org.dllearner.core.owl.DoubleMaxValue;
import org.dllearner.core.owl.DoubleMinValue;
import org.dllearner.core.owl.Individual;
+import org.dllearner.core.owl.IntMaxValue;
+import org.dllearner.core.owl.IntMinValue;
import org.dllearner.core.owl.Intersection;
import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.Negation;
@@ -96,8 +98,10 @@
public class RhoDRDown extends RefinementOperatorAdapter implements Component, CustomHierarchyRefinementOperator, CustomStartRefinementOperator, ReasoningBasedRefinementOperator {
private static Logger logger = Logger
- .getLogger(RhoDRDown.class);
+ .getLogger(RhoDRDown.class);
+ private static final NamedClass OWL_THING = new NamedClass(Thing.uri);
+
private AbstractReasonerComponent reasoner;
// hierarchies
@@ -152,18 +156,21 @@
private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>();
private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>();
private Map<NamedClass, Set<DatatypeProperty>> appSD = new TreeMap<NamedClass, Set<DatatypeProperty>>();
+ private Map<NamedClass, Set<DatatypeProperty>> appID = new TreeMap<NamedClass, Set<DatatypeProperty>>();
// most general applicable properties
private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>();
private Map<NamedClass,Set<DatatypeProperty>> mgbd = new TreeMap<NamedClass,Set<DatatypeProperty>>();
private Map<NamedClass,Set<DatatypeProperty>> mgdd = new TreeMap<NamedClass,Set<DatatypeProperty>>();
private Map<NamedClass,Set<DatatypeProperty>> mgsd = new TreeMap<NamedClass,Set<DatatypeProperty>>();
+ private Map<NamedClass,Set<DatatypeProperty>> mgid = new TreeMap<NamedClass,Set<DatatypeProperty>>();
// concept comparator
private ConceptComparator conceptComparator = new ConceptComparator();
- // splits for double datatype properties in ascening order
+ // splits for double datatype properties in ascending order
private Map<DatatypeProperty,List<Double>> splits = new TreeMap<DatatypeProperty,List<Double>>();
+ private Map<DatatypeProperty,List<Integer>> splitsInt = new TreeMap<DatatypeProperty,List<Integer>>();
private int maxNrOfSplits = 10;
// data structure for a simple frequent pattern matching preprocessing phase
@@ -330,6 +337,11 @@
computeSplits(dp);
}
+ // compute splits for integer datatype properties
+ for (DatatypeProperty dp : reasoner.getIntDatatypeProperties()) {
+ computeSplitsInt(dp);
+ }
+
// determine the maximum number of fillers for each role
// (up to a specified cardinality maximum)
if(useCardinalityRestrictions) {
@@ -457,7 +469,7 @@
tmp = subHierarchy.getSuperClasses(description.getChild(0));
for(Description c : tmp) {
- if(!(c instanceof Thing))
+ if(!(c instanceof Thing) && !c.equals(OWL_THING))
refinements.add(new Negation(c));
}
@@ -674,6 +686,31 @@
DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,min);
refinements.add(newDSR);
}
+ } if(dr instanceof IntMaxValue) {
+ int value = ((IntMaxValue)dr).getValue();
+ // find out which split value was used
+ int splitIndex = splitsInt.get(dp).lastIndexOf(value);
+ if(splitIndex == -1)
+ throw new Error("split error");
+ int newSplitIndex = splitIndex - 1;
+ if(newSplitIndex >= 0) {
+ IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(newSplitIndex));
+ DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,max);
+ refinements.add(newDSR);
+// System.out.println(description + " => " + newDSR);
+ }
+ } else if(dr instanceof IntMinValue) {
+ int value = ((IntMinValue)dr).getValue();
+ // find out which split value was used
+ int splitIndex = splitsInt.get(dp).lastIndexOf(value);
+ if(splitIndex == -1)
+ throw new Error("split error");
+ int newSplitIndex = splitIndex + 1;
+ if(newSplitIndex < splitsInt.get(dp).size()) {
+ IntMinValue min = new IntMinValue(splitsInt.get(dp).get(newSplitIndex));
+ DatatypeSomeRestriction newDSR = new DatatypeSomeRestriction(dp,min);
+ refinements.add(newDSR);
+ }
}
} else if (description instanceof StringValueRestriction) {
StringValueRestriction svr = (StringValueRestriction) description;
@@ -786,6 +823,10 @@
TreeSet<DatatypeProperty> occuredDP = new TreeSet<DatatypeProperty>();
// rule 4: no double occurences of hasValue restrictions
TreeSet<ObjectProperty> occuredVR = new TreeSet<ObjectProperty>();
+ // rule 5: max. restrictions at most once
+ boolean maxIntOccurence = false;
+ // rule 6: min restrictions at most once
+ boolean minIntOccurence = false;
for(Description child : intersection.getChildren()) {
if(child instanceof DatatypeSomeRestriction) {
@@ -800,6 +841,16 @@
return false;
else
minDoubleOccurence = true;
+ } else if(dr instanceof IntMaxValue) {
+ if(maxIntOccurence)
+ return false;
+ else
+ maxIntOccurence = true;
+ } else if(dr instanceof IntMinValue) {
+ if(minIntOccurence)
+ return false;
+ else
+ minIntOccurence = true;
}
} else if(child instanceof BooleanValueRestriction) {
DatatypeProperty dp = (DatatypeProperty) ((BooleanValueRestriction)child).getRestrictedPropertyExpression();
@@ -978,7 +1029,7 @@
if(useNegation) {
Set<Description> m2tmp = subHierarchy.getSuperClasses(new Nothing());
for(Description c : m2tmp) {
- if(!(c instanceof Thing)) {
+ if(!(c instanceof Thing) && !c.equals(OWL_THING)) {
m2.add(new Negation(c));
}
}
@@ -1024,6 +1075,18 @@
}
}
+ if(useIntDatatypes) {
+ Set<DatatypeProperty> intDPs = reasoner.getIntDatatypeProperties();
+ for(DatatypeProperty dp : intDPs) {
+ if(splitsInt.get(dp).size() > 0) {
+ IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(splitsInt.get(dp).size()-1));
+ IntMinValue min = new IntMinValue(splitsInt.get(dp).get(0));
+ m3.add(new DatatypeSomeRestriction(dp,max));
+ m3.add(new DatatypeSomeRestriction(dp,min));
+ }
+ }
+ }
+
if(useDataHasValueConstructor) {
Set<DatatypeProperty> stringDPs = reasoner.getStringDatatypeProperties();
for(DatatypeProperty dp : stringDPs) {
@@ -1161,8 +1224,21 @@
m3.add(new DatatypeSomeRestriction(dp,min));
}
}
- }
+ }
+ if(useIntDatatypes) {
+ Set<DatatypeProperty> intDPs = mgid.get(nc);
+
+ for(DatatypeProperty dp : intDPs) {
+ if(splitsInt.get(dp).size() > 0) {
+ IntMaxValue max = new IntMaxValue(splitsInt.get(dp).get(splitsInt.get(dp).size()-1));
+ IntMinValue min = new IntMinValue(splitsInt.get(dp).get(0));
+ m3.add(new DatatypeSomeRestriction(dp,max));
+ m3.add(new DatatypeSomeRestriction(dp,min));
+ }
+ }
+ }
+
if(useDataHasValueConstructor) {
Set<DatatypeProperty> stringDPs = mgsd.get(nc);
for(DatatypeProperty dp : stringDPs) {
@@ -1257,7 +1333,7 @@
// System.out.println("index " + index + " lower class " + lowerClass);
for(Description candidate : subHierarchy.getSuperClasses(lowerClass)) {
- if(!(candidate instanceof Thing)) {
+ if(!(candidate instanceof Thing) && !candidate.equals(OWL_THING)) {
// System.out.println("candidate: " + candidate);
// check disjointness with index/range (should not be disjoint otherwise not useful)
if(!isDisjoint(new Negation(candidate),index)) {
@@ -1293,6 +1369,7 @@
mgbd.put(domain, new TreeSet<DatatypeProperty>());
mgdd.put(domain, new TreeSet<DatatypeProperty>());
mgsd.put(domain, new TreeSet<DatatypeProperty>());
+ mgid.put(domain, new TreeSet<DatatypeProperty>());
SortedSet<ObjectProperty> mostGeneral = reasoner.getMostGeneralProperties();
computeMgrRecursive(domain, mostGeneral, mgr.get(domain));
@@ -1302,9 +1379,11 @@
Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, reasoner.getBooleanDatatypeProperties());
Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, reasoner.getDoubleDatatypeProperties());
Set<DatatypeProperty> mostGeneralSDP = Helper.intersection(mostGeneralDP, reasoner.getStringDatatypeProperties());
+ Set<DatatypeProperty> mostGeneralIDP = Helper.intersection(mostGeneralDP, reasoner.getIntDatatypeProperties());
computeMgbdRecursive(domain, mostGeneralBDP, mgbd.get(domain));
computeMgddRecursive(domain, mostGeneralDDP, mgdd.get(domain));
computeMgsdRecursive(domain, mostGeneralSDP, mgsd.get(domain));
+ computeMgidRecursive(domain, mostGeneralIDP, mgid.get(domain));
}
private void computeMgrRecursive(NamedClass domain, Set<ObjectProperty> currProperties, Set<ObjectProperty> mgrTmp) {
@@ -1343,6 +1422,15 @@
}
}
+ private void computeMgidRecursive(NamedClass domain, Set<DatatypeProperty> currProperties, Set<DatatypeProperty> mgidTmp) {
+ for(DatatypeProperty prop : currProperties) {
+ if(appID.get(domain).contains(prop))
+ mgidTmp.add(prop);
+ else
+ computeMgidRecursive(domain, reasoner.getSubProperties(prop), mgidTmp);
+ }
+ }
+
// computes the set of applicable properties for a given class
private void computeApp(NamedClass domain) {
// object properties
@@ -1390,7 +1478,19 @@
if(!isDisjoint(domain,d))
applicableSDPs.add(role);
}
- appSD.put(domain, applicableSDPs);
+ appSD.put(domain, applicableSDPs);
+
+ // integer datatype properties
+ Set<DatatypeProperty> mostGeneralIDPs = reasoner.getIntDatatypeProperties();
+ Set<DatatypeProperty> applicableIDPs = new TreeSet<DatatypeProperty>();
+ for(DatatypeProperty role : mostGeneralIDPs) {
+// Description d = (NamedClass) rs.getDomain(role);
+ Description d = reasoner.getDomain(role);
+// System.out.println("domain: " + d);
+ if(!isDisjoint(domain,d))
+ applicableIDPs.add(role);
+ }
+ appID.put(domain, applicableIDPs);
}
// returns true of the intersection contains elements disjoint
@@ -1541,6 +1641,37 @@
// System.out.println(splits);
// System.exit(0);
}
+
+ private void computeSplitsInt(DatatypeProperty dp) {
+ Set<Integer> valuesSet = new TreeSet<Integer>();
+// Set<Individual> individuals = rs.getIndividuals();
+ Map<Individual,SortedSet<Integer>> valueMap = reasoner.getIntDatatypeMembers(dp);
+ // add all values to the set (duplicates will be remove automatically)
+ for(Entry<Individual,SortedSet<Integer>> e : valueMap.entrySet())
+ valuesSet.addAll(e.getValue());
+ // convert set to a list where values are sorted
+ List<Integer> values = new LinkedList<Integer>(valuesSet);
+ Collections.sort(values);
+
+ int nrOfValues = values.size();
+ // create split set
+ List<Integer> splitsDP = new LinkedList<Integer>();
+ for(int splitNr=0; splitNr < Math.min(maxNrOfSplits,nrOfValues-1); splitNr++) {
+ int index;
+ if(nrOfValues<=maxNrOfSplits)
+ index = splitNr;
+ else
+ index = (int) Math.floor(splitNr * (double)nrOfValues/(maxNrOfSplits+1));
+
+ int value = values.get(index);
+ splitsDP.add(value);
+ }
+ splitsInt.put(dp, splitsDP);
+
+// System.out.println(values);
+// System.out.println(splits);
+// System.exit(0);
+ }
public int getFrequencyThreshold() {
return frequencyThreshold;
Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java
===================================================================
--- trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java 2014-05-22 11:04:32 UTC (rev 4270)
+++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/DescriptionMinimizer.java 2014-05-23 12:03:39 UTC (rev 4271)
@@ -24,9 +24,12 @@
import java.util.TreeMap;
import org.dllearner.core.AbstractReasonerComponent;
+import org.dllearner.core.owl.DataRange;
+import org.dllearner.core.owl.DatatypeSomeRestriction;
import org.dllearner.core.owl.Description;
+import org.dllearner.core.owl.IntMaxValue;
+import org.dllearner.core.owl.IntMinValue;
import org.dllearner.core.owl.Intersection;
-import org.dllearner.core.owl.NamedClass;
import org.dllearner.core.owl.Negation;
import org.dllearner.core.owl.Nothing;
import org.dllearner.core.owl.ObjectAllRestriction;
@@ -59,7 +62,7 @@
}
/**
- * Method which minimzes the input description. The algorithm does not
+ * Method which minimizes the input description. The algorithm does not
* replace subdescriptions with named classes, e.g.
* if the description "male \sqcap \exists hasChild.\top" is passed to the
* algorithm and a class "father" is defined in the obvious way
@@ -241,6 +244,15 @@
}
private boolean isSubclassOf(Description d1, Description d2) {
+ if(beautify && (d1 instanceof DatatypeSomeRestriction) && (d2 instanceof DatatypeSomeRestriction)){
+ DataRange dr1 = ((DatatypeSomeRestriction)d1).getDataRange();
+ DataRange dr2 = ((DatatypeSomeRestriction)d2).getDataRange();
+ if(dr1 instanceof IntMinValue && dr2 instanceof IntMinValue){
+ return ((IntMinValue)dr1).getValue() >= ((IntMinValue)dr2).getValue();
+ } else if(dr1 instanceof IntMaxValue && dr2 instanceof IntMaxValue){
+ return ((IntMaxValue)dr1).getValue() <= ((IntMaxValue)dr2).getValue();
+ }
+ }
if(!(d1.isNamedClass() && d2.isNamedClass())) return false;
// check whether we have cached this query
Map<Description,Boolean> tmp = cachedSubclassOf.get(d1);
@@ -249,7 +261,8 @@
tmp2 = tmp.get(d2);
if(tmp2==null) {
- Boolean result = reasoner.isSuperClassOf(d2, d1);
+
+ Boolean result = reasoner.isSuperClassOf(d2, d1);
// create new entry if necessary
Map<Description,Boolean> map1 = new TreeMap<Description,Boolean>(conceptComparator);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|