From: <jen...@us...> - 2008-03-03 12:46:25
|
Revision: 675 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=675&view=rev Author: jenslehmann Date: 2008-03-03 04:46:23 -0800 (Mon, 03 Mar 2008) Log Message: ----------- continued refinement operator implementation Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/Reasoner.java trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Modified: trunk/src/dl-learner/org/dllearner/core/Reasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/core/Reasoner.java 2008-03-03 12:46:23 UTC (rev 675) @@ -112,13 +112,13 @@ // currently, we do not require that datatype properties can be returned; // the main reason is that DIG does not distinguish between datatype and // object properties (of course one could implement it but it is not easy) - public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException; - public Set<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException; - public Set<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException; - public Set<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException; + public SortedSet<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException; public SortedSet<Individual> getIndividuals(); Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-03 12:46:23 UTC (rev 675) @@ -219,19 +219,19 @@ throw new ReasoningMethodUnsupportedException(); } - public Set<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { + public SortedSet<DatatypeProperty> getDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public Set<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException { + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public Set<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException { + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } - public Set<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException { + public SortedSet<DatatypeProperty> getIntDatatypeProperties() throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); } Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2008-03-03 12:46:23 UTC (rev 675) @@ -467,7 +467,7 @@ return reasoner.getAtomicRoles(); } - public Set<DatatypeProperty> getDatatypeProperties() { + public SortedSet<DatatypeProperty> getDatatypeProperties() { try { return reasoner.getDatatypeProperties(); } catch (ReasoningMethodUnsupportedException e) { @@ -476,7 +476,7 @@ } } - public Set<DatatypeProperty> getBooleanDatatypeProperties() { + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { try { return reasoner.getBooleanDatatypeProperties(); } catch (ReasoningMethodUnsupportedException e) { @@ -485,7 +485,7 @@ } } - public Set<DatatypeProperty> getIntDatatypeProperties() { + public SortedSet<DatatypeProperty> getIntDatatypeProperties() { try { return reasoner.getIntDatatypeProperties(); } catch (ReasoningMethodUnsupportedException e) { @@ -494,7 +494,7 @@ } } - public Set<DatatypeProperty> getDoubleDatatypeProperties() { + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { try { return reasoner.getDoubleDatatypeProperties(); } catch (ReasoningMethodUnsupportedException e) { Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 12:46:23 UTC (rev 675) @@ -78,10 +78,10 @@ private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; - private Set<DatatypeProperty> datatypeProperties; - private Set<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - private Set<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - private Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); + private SortedSet<DatatypeProperty> datatypeProperties; + private SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + private SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + private SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); private SortedSet<Individual> individuals; private ReasoningService rs; @@ -298,22 +298,22 @@ } @Override - public Set<DatatypeProperty> getDatatypeProperties() { + public SortedSet<DatatypeProperty> getDatatypeProperties() { return datatypeProperties; } @Override - public Set<DatatypeProperty> getBooleanDatatypeProperties() { + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { return booleanDatatypeProperties; } @Override - public Set<DatatypeProperty> getDoubleDatatypeProperties() { + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { return doubleDatatypeProperties; } @Override - public Set<DatatypeProperty> getIntDatatypeProperties() { + public SortedSet<DatatypeProperty> getIntDatatypeProperties() { return intDatatypeProperties; } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-03 12:46:23 UTC (rev 675) @@ -136,10 +136,10 @@ // primitives Set<NamedClass> atomicConcepts = new TreeSet<NamedClass>(conceptComparator); Set<ObjectProperty> atomicRoles = new TreeSet<ObjectProperty>(roleComparator); - Set<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); - Set<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); - Set<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); - Set<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> datatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> booleanDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> doubleDatatypeProperties = new TreeSet<DatatypeProperty>(); + SortedSet<DatatypeProperty> intDatatypeProperties = new TreeSet<DatatypeProperty>(); SortedSet<Individual> individuals = new TreeSet<Individual>(); // namespaces @@ -334,7 +334,7 @@ } @Override - public Set<DatatypeProperty> getDatatypeProperties() { + public SortedSet<DatatypeProperty> getDatatypeProperties() { return datatypeProperties; } @@ -960,7 +960,7 @@ * @return the booleanDatatypeProperties */ @Override - public Set<DatatypeProperty> getBooleanDatatypeProperties() { + public SortedSet<DatatypeProperty> getBooleanDatatypeProperties() { return booleanDatatypeProperties; } @@ -968,7 +968,7 @@ * @return the doubleDatatypeProperties */ @Override - public Set<DatatypeProperty> getDoubleDatatypeProperties() { + public SortedSet<DatatypeProperty> getDoubleDatatypeProperties() { return doubleDatatypeProperties; } @@ -976,7 +976,7 @@ * @return the intDatatypeProperties */ @Override - public Set<DatatypeProperty> getIntDatatypeProperties() { + public SortedSet<DatatypeProperty> getIntDatatypeProperties() { return intDatatypeProperties; } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/MathOperations.java 2008-03-03 12:46:23 UTC (rev 675) @@ -23,9 +23,13 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Union; +import org.dllearner.utilities.ConceptComparator; /** * Math operations related to refinement operators. @@ -114,20 +118,44 @@ return combosTmp; } + /** + * @see #getCombos(int) + * @param length Length of construct. + * @param maxValue Maximum value which can occur in sum. + * @return + */ + public static List<List<Integer>> getCombos(int length, int maxValue) { + LinkedList<List<Integer>> combosTmp = new LinkedList<List<Integer>>(); + decompose(length, maxValue, new LinkedList<Integer>(), combosTmp); + return combosTmp; + } + @SuppressWarnings("unchecked") private static LinkedList<Integer> cloneList(LinkedList<Integer> list) { return (LinkedList<Integer>) list.clone(); - } - - public static void main(String args[]) { - System.out.println(getCombos(7)); } - // neue Implementierung, die nicht mehr zur incompleteness führen soll, - // da die Konzepte in einer MultiDisjunction als Liste gespeichert werden - public static Set<Union> incCrossProduct(Set<Union> baseSet, Set<Description> newSet) { - Set<Union> retSet = new HashSet<Union>(); - + /** + * Implements a cross product in the sense that each union description in the + * base set is extended by each description in the new set. + * + * Example: + * baseSet = {A1 OR A2, A1 or A3} + * newSet = {A1, EXISTS r.A3} + * + * Returns: + * {A1 OR A2 OR A1, A1 OR A2 OR EXISTS r.A3, A1 OR A3 OR A1, A1 OR A3 OR EXISTS r.A3} + * + * If the base set is empty, then the return value are union class descriptions + * for each value in newSet (a union with only one concept). + * + * @param baseSet A set of union class descriptions. + * @param newSet The descriptions to add to each union class descriptions. + * @return The "cross product" of baseSet and newSet. + */ + public static SortedSet<Union> incCrossProduct(Set<Union> baseSet, Set<Description> newSet) { + SortedSet<Union> retSet = new TreeSet<Union>(new ConceptComparator()); + if(baseSet.isEmpty()) { for(Description c : newSet) { Union md = new Union(); @@ -148,4 +176,26 @@ return retSet; } + /** + * Returns true if the same property is used twice in an object some + * restriction, e.g. (EXISTS r.A1 AND A2 AND EXISTS r.A3) returns true, + * while (A1 OR A2) and (EXISTS r.A1 AND A2 AND EXISTS s.A3) return false. + * Note that the method does not work recursively, e.g. it return false + * for EXISTS r.(EXISTS r.A1 AND A2 AND EXISTS r.A3). + * + * @param d Description to test. + * @return See description. + */ + public static boolean containsDoubleObjectSomeRestriction(Description d) { + Set<String> roles = new TreeSet<String>(); + for(Description c : d.getChildren()) { + if(c instanceof ObjectSomeRestriction) { + String role = ((ObjectSomeRestriction)c).getRole().getName(); + boolean roleExists = !roles.add(role); + if(roleExists) + return true; + } + } + return false; + } } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 07:45:57 UTC (rev 674) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 12:46:23 UTC (rev 675) @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; @@ -45,6 +46,7 @@ import org.dllearner.core.owl.Union; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; +import org.dllearner.utilities.Helper; /** * A downward refinement operator, which makes use of domains @@ -81,17 +83,19 @@ // for refinements of \rho_\top(\top), the second one for \rho_A(\top) private int topRefinementsLength = 0; private Map<NamedClass, Integer> topARefinementsLength = new TreeMap<NamedClass, Integer>(); + // M is finite and this value is the maximum length of any value in M + private static int mMaxLength = 3; // the sets M_\top and M_A - private Map<Integer,Set<Description>> m = new TreeMap<Integer,Set<Description>>(); - private Map<NamedClass,Map<Integer,Set<Description>>> mA = new TreeMap<NamedClass,Map<Integer,Set<Description>>>(); + private Map<Integer,SortedSet<Description>> m = new TreeMap<Integer,SortedSet<Description>>(); + private Map<NamedClass,Map<Integer,SortedSet<Description>>> mA = new TreeMap<NamedClass,Map<Integer,SortedSet<Description>>>(); // @see MathOperations.getCombos private Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); // refinements of the top concept ordered by length - private Map<Integer, TreeSet<Description>> topRefinements = new TreeMap<Integer, TreeSet<Description>>(); - private Map<NamedClass,Map<Integer, TreeSet<Description>>> topARefinements = new TreeMap<NamedClass,Map<Integer, TreeSet<Description>>>(); + private Map<Integer, SortedSet<? extends Description>> topRefinements = new TreeMap<Integer, SortedSet<? extends Description>>(); + private Map<NamedClass,Map<Integer, SortedSet<? extends Description>>> topARefinements = new TreeMap<NamedClass,Map<Integer, SortedSet<? extends Description>>>(); // cumulated refinements of top (all from length one to the specified length) private Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); @@ -105,6 +109,8 @@ // 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>>(); // comparator für Konzepte private ConceptComparator conceptComparator = new ConceptComparator(); @@ -154,7 +160,7 @@ */ public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements) { - return refine(description, maxLength, knownRefinements, new Thing()); + return refine(description, maxLength, knownRefinements, startClass); } @SuppressWarnings({"unchecked"}) @@ -198,89 +204,84 @@ private void computeTopRefinements(int maxLength, NamedClass domain) { long topComputationTimeStartNs = System.nanoTime(); - // M erweiteren - computeM(maxLength); + if(domain == null && m.size() == 0) + computeM(); - // berechnen aller möglichen Kombinationen für Disjunktion, - for(int i = topRefinementsLength+1; i <= maxLength; i++) { - combos.put(i,MathOperations.getCombos(i)); - topRefinements.put(i, new TreeSet<Description>(conceptComparator)); - // topRefinements.put(i, new HashSet<Concept>()); + if(domain != null && !mA.containsKey(domain)) + computeM(domain); + + // compute all possible combinations of the disjunction + int refinementsLength = (domain == null) ? topRefinementsLength : topARefinementsLength.get(domain); + for(int i = refinementsLength+1; i <= maxLength; i++) { + combos.put(i,MathOperations.getCombos(i, mMaxLength)); +// topRefinements.put(i, new TreeSet<Description>(conceptComparator)); for(List<Integer> combo : combos.get(i)) { - // Kombination besteht aus nur einer Zahl => einfach M benutzen - // if(combo.getNumbers().size()==1) { + // combination is a single number => try to use M if(combo.size()==1) { - topRefinements.get(i).addAll(m.get(i)); - // Kombination besteht aus mehreren Zahlen => Disjunktion erzeugen + if(domain == null) + topRefinements.put(i,m.get(i)); + else + topARefinements.get(domain).put(i,mA.get(domain).get(i)); + // combinations has several numbers => generate disjunct } else { - Set<Union> baseSet = new HashSet<Union>(); - for(Integer j : combo) { // combo.getNumbers()) { + SortedSet<Union> baseSet = new TreeSet<Union>(conceptComparator); + for(Integer j : combo) { baseSet = MathOperations.incCrossProduct(baseSet, m.get(j)); } - // Umwandlung aller Konzepte in Negationsnormalform + // convert all concepts in ordered negation normal form for(Description concept : baseSet) { ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); } + // apply the exists filter (throwing out all refinements with + // double \exists r for any r) + // TODO: similar filtering can be done for boolean datatype + // properties if(applyExistsFilter) { - Iterator<Union> it = baseSet.iterator(); - while(it.hasNext()) { - Union md = it.next(); - boolean remove = false; - // falls Exists r für gleiche Rolle zweimal vorkommt, - // dann rausschmeißen - // Map<AtomicRole,Boolean> roleOccured = new HashMap<AtomicRole,Boolean>(); - Set<String> roles = new TreeSet<String>(); - for(Description c : md.getChildren()) { - if(c instanceof ObjectSomeRestriction) { - String role = ((ObjectSomeRestriction)c).getRole().getName(); - boolean roleExists = !roles.add(role); - // falls Rolle schon vorkommt, dann kann ganzes - // Refinement ignoriert werden (man könnte dann auch - // gleich abbrechen, aber das hat nur minimalste - // Auswirkungen auf Effizienz) - if(roleExists) - remove = true; - } + Iterator<Union> it = baseSet.iterator(); + while(it.hasNext()) { + if(MathOperations.containsDoubleObjectSomeRestriction(it.next())) + it.remove(); } - if(remove) - it.remove(); + } - } - } - - topRefinements.get(i).addAll(baseSet); + // add computed refinements + if(domain == null) + topRefinements.put(new Integer(i), baseSet); + else + topARefinements.get(domain).put(new Integer(i), baseSet); } } - // neu berechnete Refinements kumulieren, damit sie schneller abgefragt werden können - // computeCumulativeTopRefinements(i); + // create cumulative versions of refinements such that they can + // be accessed easily TreeSet<Description> cumulativeRefinements = new TreeSet<Description>(conceptComparator); - // Set<Concept> cumulativeRefinements = new HashSet<Concept>(); for(int j=1; j<=i; j++) { - cumulativeRefinements.addAll(topRefinements.get(j)); + if(domain == null) + cumulativeRefinements.addAll(topRefinements.get(j)); + else + cumulativeRefinements.addAll(topARefinements.get(domain).get(j)); } - topRefinementsCumulative.put(i, cumulativeRefinements); + if(domain == null) + topRefinementsCumulative.put(i, cumulativeRefinements); + else + topARefinementsCumulative.get(domain).put(i, cumulativeRefinements); } - // neue Maximallänge eintragen - topRefinementsLength = maxLength; + // register new top refinements length + if(domain == null) + topRefinementsLength = maxLength; + else + topARefinementsLength.put(domain,maxLength); topComputationTimeNs += System.nanoTime() - topComputationTimeStartNs; } // compute M_\top - private void computeM(int maxLength) { - computeM(maxLength, null); - } - - // computation of the set M_A - // a major difference compared to the ILP 2007 \rho operator is that - // M is finite and contains elements of length (currently) at most 3 - private void computeM(int maxLength, NamedClass domain) { + private void computeM() { long mComputationTimeStartNs = System.nanoTime(); // initialise all possible lengths (1 to 3) @@ -288,19 +289,19 @@ m.put(i, new TreeSet<Description>(conceptComparator)); } - Set<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); + SortedSet<Description> m1 = rs.getMoreSpecialConcepts(new Thing()); m.put(1,m1); if(useNegation) { Set<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); - Set<Description> m2 = new TreeSet<Description>(conceptComparator); + SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); for(Description c : m2tmp) { m2.add(new Negation(c)); } m.put(2,m2); } - Set<Description> m3 = new TreeSet<Description>(conceptComparator); + SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); if(useExistsConstructor) { // only uses most general roles for(ObjectProperty r : rs.getMostGeneralRoles()) { @@ -330,13 +331,89 @@ mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } + + // computation of the set M_A + // a major difference compared to the ILP 2007 \rho operator is that + // M is finite and contains elements of length (currently) at most 3 + private void computeM(NamedClass nc) { + long mComputationTimeStartNs = System.nanoTime(); + + mA.put(nc, new TreeMap<Integer,SortedSet<Description>>()); + // initialise all possible lengths (1 to 3) + for(int i=1; i<=3; i++) { + mA.get(nc).put(i, new TreeSet<Description>(conceptComparator)); + } - private void computeMgr(NamedClass domain) { + SortedSet<Description> m1 = rs.getMoreSpecialConcepts(nc); + m.put(1,m1); + + if(useNegation) { + // the definition in the paper is more complex, but acutally + // we only have to insert the most specific concepts satisfying + // the mentioned restrictions; there is no need to implement a + // recursive method because for A subClassOf A' we have not A' + // subClassOf A and thus: if A and B are disjoint then also A' + // and B; if not A AND B = B then also not A' AND B = B + SortedSet<Description> m2tmp = rs.getMoreGeneralConcepts(new Nothing()); + SortedSet<Description> m2 = new TreeSet<Description>(conceptComparator); + for(Description c : m2tmp) { + if(c instanceof Thing) + m2.add(c); + else { + NamedClass a = (NamedClass) c; + if(!isNotADisjoint(a, nc) && !isNotAMeaningFul(a, nc)) + m2.add(new Negation(a)); + } + } + m.put(2,m2); + } + + // compute applicable properties + computeMg(nc); + + SortedSet<Description> m3 = new TreeSet<Description>(conceptComparator); + if(useExistsConstructor) { + for(ObjectProperty r : mgr.get(nc)) { + m3.add(new ObjectSomeRestriction(r, new Thing())); + } + } + + if(useAllConstructor) { + // we allow \forall r.\top here because otherwise the operator + // becomes too difficult to manage due to dependencies between + // M_A and M_A' where A'=ran(r) + for(ObjectProperty r : mgr.get(nc)) { + m3.add(new ObjectAllRestriction(r, new Thing())); + } + } + + // boolean datatypes, e.g. testPositive = true + if(useBooleanDatatypes) { + Set<DatatypeProperty> booleanDPs = mgbd.get(nc); + for(DatatypeProperty dp : booleanDPs) { + m3.add(new BooleanValueRestriction(dp,true)); + m3.add(new BooleanValueRestriction(dp,false)); + } + } + + m.put(3,m3); + + mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; + } + + private void computeMg(NamedClass domain) { // compute the applicable properties if this has not been done yet if(appOP.get(domain) == null) - computeApp(domain); - Set<ObjectProperty> mostGeneral = rs.getMostGeneralRoles(); + computeApp(domain); + SortedSet<ObjectProperty> mostGeneral = rs.getMostGeneralRoles(); computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); + SortedSet<DatatypeProperty> mostGeneralDP = rs.getMostGeneralDatatypeProperties(); + // we make the (reasonable) assumption here that all sub and super + // datatype properties have the same type (e.g. boolean, integer, double) + Set<DatatypeProperty> mostGeneralBDP = Helper.intersection(mostGeneralDP, rs.getBooleanDatatypeProperties()); + Set<DatatypeProperty> mostGeneralDDP = Helper.intersection(mostGeneralDP, rs.getDoubleDatatypeProperties()); + computeMgbdRecursive(domain, mostGeneralBDP, mgbd.get(domain)); + computeMgddRecursive(domain, mostGeneralDDP, mgdd.get(domain)); } private void computeMgrRecursive(NamedClass domain, Set<ObjectProperty> currProperties, Set<ObjectProperty> mgrTmp) { @@ -348,9 +425,27 @@ } } + private void computeMgbdRecursive(NamedClass domain, Set<DatatypeProperty> currProperties, Set<DatatypeProperty> mgbdTmp) { + for(DatatypeProperty prop : currProperties) { + if(appBD.get(domain).contains(prop)) + mgbdTmp.add(prop); + else + computeMgbdRecursive(domain, rs.getMoreSpecialDatatypeProperties(prop), mgbdTmp); + } + } + + private void computeMgddRecursive(NamedClass domain, Set<DatatypeProperty> currProperties, Set<DatatypeProperty> mgddTmp) { + for(DatatypeProperty prop : currProperties) { + if(appDD.get(domain).contains(prop)) + mgddTmp.add(prop); + else + computeMgddRecursive(domain, rs.getMoreSpecialDatatypeProperties(prop), mgddTmp); + } + } + // computes the set of applicable properties for a given class private void computeApp(NamedClass domain) { - // TODO: also implement this for boolean/double datatype properties + // object properties Set<ObjectProperty> mostGeneral = rs.getAtomicRoles(); Set<ObjectProperty> applicableRoles = new TreeSet<ObjectProperty>(); for(ObjectProperty role : mostGeneral) { @@ -361,14 +456,52 @@ applicableRoles.add(role); } appOP.put(domain, applicableRoles); + + // boolean datatype properties + Set<DatatypeProperty> mostGeneralBDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> applicableBDPs = new TreeSet<DatatypeProperty>(); + for(DatatypeProperty role : mostGeneralBDPs) { + NamedClass nc = (NamedClass) rs.getDomain(role); + if(!isDisjoint(domain,nc)) + applicableBDPs.add(role); + } + appBD.put(domain, applicableBDPs); + + // double datatype properties + Set<DatatypeProperty> mostGeneralDDPs = rs.getBooleanDatatypeProperties(); + Set<DatatypeProperty> applicableDDPs = new TreeSet<DatatypeProperty>(); + for(DatatypeProperty role : mostGeneralDDPs) { + NamedClass nc = (NamedClass) rs.getDomain(role); + if(!isDisjoint(domain,nc)) + applicableDDPs.add(role); + } + appDD.put(domain, applicableDDPs); } // computes whether two classes are disjoint; this should be computed // by the reasoner only ones and otherwise taken from a matrix - private boolean isDisjoint(NamedClass class1, NamedClass class2) { + // => this has low importance in the long run, because M is cached anyway, + // but avoids many duplicate queries when computing M + private boolean isDisjoint(NamedClass a, NamedClass b) { // we need to test whether A AND B is equivalent to BOTTOM - Description d = new Intersection(class1, class2); + Description d = new Intersection(a, b); return rs.subsumes(new Nothing(), d); } + // we need to test whether NOT A AND B is equivalent to BOTTOM + private boolean isNotADisjoint(NamedClass a, NamedClass b) { + Description notA = new Negation(a); + Description d = new Intersection(notA, b); + return rs.subsumes(new Nothing(), d); + } + + // we need to test whether NOT A AND B = B + // (if not then NOT A is not meaningful in the sense that it does + // not semantically add anything to B) + private boolean isNotAMeaningFul(NamedClass a, NamedClass b) { + Description notA = new Negation(a); + Description d = new Intersection(notA, b); + return !rs.subsumes(b, d); + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |