From: <jen...@us...> - 2008-09-26 17:25:57
|
Revision: 1273 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1273&view=rev Author: jenslehmann Date: 2008-09-26 17:25:48 +0000 (Fri, 26 Sep 2008) Log Message: ----------- implemented hasValue support including simple frequent pattern preprocessing (not working yet) Modified Paths: -------------- 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/owl/ConceptComparator.java Added Paths: ----------- trunk/examples/semantic_bible/hasvalue_example.conf Added: trunk/examples/semantic_bible/hasvalue_example.conf =================================================================== --- trunk/examples/semantic_bible/hasvalue_example.conf (rev 0) +++ trunk/examples/semantic_bible/hasvalue_example.conf 2008-09-26 17:25:48 UTC (rev 1273) @@ -0,0 +1,20 @@ +/** + * It should learn ethnicity hasValue Jewish, but does not work for some reason. + */ + +import("../NTNcombined.owl"); + +// reasoner = owlAPIReasoner; +owlAPIReasoner.reasonerType = pellet; + ++"http://semanticbible.org/ns/2006/NTNames#Hezron" ++"http://semanticbible.org/ns/2006/NTNames#Jehoshaphat" ++"http://semanticbible.org/ns/2006/NTNames#Judah" ++"http://semanticbible.org/ns/2006/NTNames#Jorim" ++"http://semanticbible.org/ns/2006/NTNames#Neri" + +-"http://semanticbible.org/ns/2006/NTNames#Hierapolis" +-"http://semanticbible.org/ns/2006/NTNames#Iconium" +-"http://semanticbible.org/ns/2006/NTNames#Joda" +-"http://semanticbible.org/ns/2006/NTNames#JohntheBaptist" +-"http://semanticbible.org/ns/2006/NTNames#Philip" Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-09-26 16:30:40 UTC (rev 1272) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-09-26 17:25:48 UTC (rev 1273) @@ -63,6 +63,7 @@ import org.dllearner.core.owl.ObjectPropertyExpression; import org.dllearner.core.owl.ObjectPropertyHierarchy; import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.ObjectValueRestriction; import org.dllearner.core.owl.SubsumptionHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; @@ -428,6 +429,11 @@ } } return true; + } else if (description instanceof ObjectValueRestriction) { + Individual i = ((ObjectValueRestriction)description).getIndividual(); + ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); + + return opPos.get(op).get(individual).contains(i); } else if (description instanceof BooleanValueRestriction) { DatatypeProperty dp = ((BooleanValueRestriction) description) .getRestrictedPropertyExpresssion(); Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-09-26 16:30:40 UTC (rev 1272) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIDescriptionConvertVisitor.java 2008-09-26 17:25:48 UTC (rev 1273) @@ -36,6 +36,7 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.DescriptionVisitor; import org.dllearner.core.owl.DoubleMinValue; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Negation; @@ -44,6 +45,7 @@ import org.dllearner.core.owl.ObjectExactCardinalityRestriction; import org.dllearner.core.owl.ObjectMaxCardinalityRestriction; import org.dllearner.core.owl.ObjectMinCardinalityRestriction; +import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.ObjectValueRestriction; import org.dllearner.core.owl.SimpleDoubleDataRange; @@ -60,6 +62,7 @@ import org.semanticweb.owl.model.OWLDataRange; import org.semanticweb.owl.model.OWLDataType; import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLTypedConstant; import org.semanticweb.owl.vocab.OWLRestrictedDataRangeFacetVocabulary; @@ -227,8 +230,10 @@ * @see org.dllearner.core.owl.DescriptionVisitor#visit(org.dllearner.core.owl.ObjectValueRestriction) */ public void visit(ObjectValueRestriction description) { - // TODO Auto-generated method stub - throw new Error("OWLAPIDescriptionConverter: not implemented"); + OWLObjectProperty role = factory.getOWLObjectProperty( + URI.create(((ObjectProperty)description.getRestrictedPropertyExpression()).getName())); + OWLIndividual i = factory.getOWLIndividual(URI.create(description.getIndividual().getName())); + stack.push(factory.getOWLObjectValueRestriction(role, i)); } /* (non-Javadoc) Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-09-26 16:30:40 UTC (rev 1272) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-09-26 17:25:48 UTC (rev 1273) @@ -19,6 +19,7 @@ */ package org.dllearner.refinementoperators; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -54,6 +55,7 @@ import org.dllearner.core.owl.ObjectPropertyExpression; import org.dllearner.core.owl.ObjectQuantorRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.ObjectValueRestriction; import org.dllearner.core.owl.SubsumptionHierarchy; import org.dllearner.core.owl.Thing; import org.dllearner.core.owl.Union; @@ -148,6 +150,14 @@ private Map<DatatypeProperty,List<Double>> splits = new TreeMap<DatatypeProperty,List<Double>>(); private int maxNrOfSplits = 10; + // experimental support for hasValue + private boolean useHasValue = false; + // data structure for a simple frequent pattern matching preprocessing phase + private int frequencyThreshold = 3; + 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>>(); + // staistics public long mComputationTimeNs = 0; public long topComputationTimeNs = 0; @@ -193,7 +203,46 @@ for(ObjectProperty op : rs.getObjectProperties()) { opDomains.put(op, rs.getDomain(op)); opRanges.put(op, rs.getRange(op)); + + if(useHasValue) { + // init + Map<Individual, Integer> opMap = new TreeMap<Individual, Integer>(); + valueFrequency.put(op, opMap); + + // sets ordered by corresponding individual (which we ignore) + Collection<SortedSet<Individual>> fillerSets = rs.getRoleMembers(op).values(); + for(SortedSet<Individual> fillerSet : fillerSets) { + for(Individual i : fillerSet) { +// System.out.println("op " + op + " i " + i); + Integer value = opMap.get(i); + + if(value != null) { + opMap.put(i, value+1); + } else { + opMap.put(i, 1); + } + } + } + + // keep only frequent patterns (TODO it would be slightly + // more efficient if we stop adding to valueFrequency + // after threshold is reached) + Set<Individual> frequentInds = new TreeSet<Individual>(); + for(Individual i : opMap.keySet()) { + if(opMap.get(i) > frequencyThreshold) { + frequentInds.add(i); + } + } + frequentValues.put(op, frequentInds); + + } + } + + // we do not need the temporary set anymore and let the + // garbage collector take care of it + valueFrequency = null; + for(DatatypeProperty dp : rs.getDatatypeProperties()) { dpDomains.put(dp, rs.getDomain(dp)); } @@ -405,6 +454,18 @@ } } + // rule 4: EXISTS r.TOP => EXISTS r.{value} + if(useHasValue && description.getChild(0) instanceof Thing) { + // watch out for frequent patterns + Set<Individual> frequentInds = frequentValues.get(role); + if(frequentInds != null) { + for(Individual ind : frequentInds) { + ObjectValueRestriction ovr = new ObjectValueRestriction(ar, ind); + refinements.add(ovr); + } + } + } + } else if (description instanceof ObjectAllRestriction) { ObjectPropertyExpression role = ((ObjectQuantorRestriction)description).getRole(); Description range = opRanges.get(role); Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptComparator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptComparator.java 2008-09-26 16:30:40 UTC (rev 1272) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/ConceptComparator.java 2008-09-26 17:25:48 UTC (rev 1273) @@ -8,6 +8,7 @@ import org.dllearner.core.owl.DatatypeSomeRestriction; import org.dllearner.core.owl.DoubleMaxValue; import org.dllearner.core.owl.DoubleMinValue; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.ObjectAllRestriction; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Nothing; @@ -17,6 +18,7 @@ import org.dllearner.core.owl.ObjectMinCardinalityRestriction; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.ObjectValueRestriction; import org.dllearner.core.owl.SimpleDoubleDataRange; import org.dllearner.core.owl.Union; import org.dllearner.core.owl.Negation; @@ -175,8 +177,23 @@ return roleCompare; } else return -1; + } else if(concept1 instanceof ObjectValueRestriction) { + if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectSomeRestriction || concept2 instanceof ObjectAllRestriction) + return 1; + else if(concept2 instanceof ObjectValueRestriction) { + int roleCompare = rc.compare(((ObjectValueRestriction)concept1).getRestrictedPropertyExpression(), ((ObjectQuantorRestriction)concept2).getRestrictedPropertyExpression()); + + if(roleCompare == 0) { + Individual value1 = ((ObjectValueRestriction)concept1).getIndividual(); + Individual value2 = ((ObjectValueRestriction)concept2).getIndividual(); + return value1.compareTo(value2); + } else { + return roleCompare; + } + } else + return -1; } else if(concept1 instanceof ObjectMinCardinalityRestriction) { - if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction) + if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction || concept2 instanceof ObjectValueRestriction) return 1; // first criterion: object property // second criterion: number @@ -196,7 +213,7 @@ } else return -1; } else if(concept1 instanceof ObjectMaxCardinalityRestriction) { - if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction || concept2 instanceof ObjectMinCardinalityRestriction) + if(concept2.getChildren().size()<1 || concept2 instanceof Negation || concept2 instanceof ObjectQuantorRestriction || concept2 instanceof ObjectValueRestriction || concept2 instanceof ObjectMinCardinalityRestriction) return 1; // first criterion: object property // second criterion: number This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |