From: <jen...@us...> - 2008-03-04 19:11:41
|
Revision: 687 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=687&view=rev Author: jenslehmann Date: 2008-03-04 11:10:55 -0800 (Tue, 04 Mar 2008) Log Message: ----------- reasoning bug fixes and extensions Modified Paths: -------------- trunk/examples/commandcollection.txt trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.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/RhoDRDown.java Modified: trunk/examples/commandcollection.txt =================================================================== --- trunk/examples/commandcollection.txt 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/examples/commandcollection.txt 2008-03-04 19:10:55 UTC (rev 687) @@ -66,3 +66,4 @@ import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL"); sparql.instances = {}; +posNegDefinition.percentPerLengthUnit = 0.10; \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/core/ReasonerComponent.java 2008-03-04 19:10:55 UTC (rev 687) @@ -149,6 +149,22 @@ return ret; } + // convenience method returning those values which have value "false" for this + // datatype property + public SortedSet<Individual> getFalseDatatypeMembers(DatatypeProperty datatypeProperty) throws ReasoningMethodUnsupportedException { + Map<Individual, SortedSet<Constant>> mapping = getDatatypeMembers(datatypeProperty); + SortedSet<Individual> ret = new TreeSet<Individual>(); + for(Entry<Individual, SortedSet<Constant>> e : mapping.entrySet()) { + SortedSet<Constant> values = e.getValue(); + for(Constant c : values) { + boolean v = Boolean.parseBoolean(c.getLiteral()); + if(v == false) + ret.add(e.getKey()); + } + } + return ret; + } + public boolean instanceCheck(Description concept, Individual individual) throws ReasoningMethodUnsupportedException { throw new ReasoningMethodUnsupportedException(); Modified: trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/core/owl/TypedConstant.java 2008-03-04 19:10:55 UTC (rev 687) @@ -27,7 +27,7 @@ * @author Jens Lehmann * */ -public class TypedConstant extends Constant { +public class TypedConstant extends Constant implements Comparable<TypedConstant> { private Datatype datatype; @@ -47,7 +47,8 @@ * @see org.dllearner.core.owl.KBElement#toString(java.lang.String, java.util.Map) */ public String toString(String baseURI, Map<String, String> prefixes) { - return literal + "^^" + datatype; + return literal; +// return literal + "^^" + datatype; } /** @@ -62,6 +63,19 @@ */ public void accept(KBElementVisitor visitor) { visitor.visit(this); + } + + /* (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(TypedConstant o) { + // the first criteria is the datatype + int datatypeComparision = datatype.getURI().compareTo(datatype.getURI()); + if(datatypeComparision == 0) { + // the second criterion is the literal value + return literal.compareTo(o.literal); + } else + return datatypeComparision; } } Modified: trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java =================================================================== --- trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/examples/Carcinogenesis.java 2008-03-04 19:10:55 UTC (rev 687) @@ -204,6 +204,10 @@ // and cannot parser its own generated file // DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(atomTypes); // kb.addAxiom(disjointAtomTypes); + String[] mainClasses = new String[] {"Compound", "Atom", "Bond", "Structure"}; + Set<String> mainClassesSet = new HashSet<String>(Arrays.asList(mainClasses)); + DisjointClassesAxiom disjointAtomTypes = getDisjointClassesAxiom(mainClassesSet); + kb.addAxiom(disjointAtomTypes); // all different axiom (UNA) // exporting differentIndividuals axioms is broken in OWL API @@ -230,9 +234,12 @@ String confHeader = "import(\"pte.owl\");\n\n"; confHeader += "reasoner = fastInstanceChecker;\n"; confHeader += "algorithm = refexamples;\n"; -// confHeader += "refinement.writeSearchTree = true;"; -// confHeader += "refinement.searchTreeFile = \"log/carcinogenesis/searchTree.log\""; - confHeader += "\n\n"; + confHeader += "refexamples.noisePercentage = 35;\n"; + confHeader += "refexamples.startClass = " + getURI2("Compound") + ";\n"; + confHeader += "refexamples.writeSearchTree = false;\n"; + confHeader += "refexamples.searchTreeFile = \"log/carcinogenesis/searchTree.log\";\n"; + confHeader += "posNegDefinition.percentPerLengthUnit = 0.10;\n"; + confHeader += "\n"; Files.appendFile(confTrainFile, confHeader); // generating training examples @@ -338,7 +345,9 @@ } else if (headName.equals("has_property")) { String compoundName = head.getArgument(0).toPLString(); String testName = head.getArgument(1).toPLString(); - boolean testResult = Boolean.parseBoolean(head.getArgument(2).toPLString()); + String resultStr = head.getArgument(2).toPLString(); + boolean testResult = (resultStr.equals("p")) ? true : false; + // create a new datatype property if it does not exist already if(!tests.contains(testName)) { String axiom1 = "DPDOMAIN(" + getURI2(testName) + ") = " + getURI2("Compound") + ".\n"; @@ -453,7 +462,7 @@ private static DisjointClassesAxiom getDisjointClassesAxiom(Set<String> classes) { Set<Description> descriptions = new HashSet<Description>(); for(String namedClass : classes) - descriptions.add(new NamedClass(namedClass)); + descriptions.add(new NamedClass(getURI(namedClass))); return new DisjointClassesAxiom(descriptions); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-04 19:10:55 UTC (rev 687) @@ -56,6 +56,7 @@ import org.dllearner.kb.OWLFile; import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; +import org.dllearner.utilities.Helper; /** * Reasoner for fast instance checks. It works by completely dematerialising the @@ -76,6 +77,8 @@ private static Logger logger = Logger.getLogger(FastInstanceChecker.class); + private boolean defaultNegation = true; + private Set<NamedClass> atomicConcepts; private Set<ObjectProperty> atomicRoles; private SortedSet<DatatypeProperty> datatypeProperties; @@ -96,10 +99,9 @@ // object property mappings private Map<ObjectProperty, Map<Individual, SortedSet<Individual>>> opPos = new TreeMap<ObjectProperty, Map<Individual, SortedSet<Individual>>>(); // datatype property mappings - // (for booleans we assume that just one mapping exists, e.g. - // hasValue(object,true) and hasValue(object,false) will - // lead to undefined behaviour (they are logical contradictions) - private Map<DatatypeProperty, SortedSet<Individual>> bd = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); + // we have one mapping for true and false for efficiency reasons + private Map<DatatypeProperty, SortedSet<Individual>> bdPos = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); + private Map<DatatypeProperty, SortedSet<Individual>> bdNeg = new TreeMap<DatatypeProperty, SortedSet<Individual>>(); // for int and double we assume that a property can have several values, // althoug this should be rare, // e.g. hasValue(object,2) and hasValue(object,3) @@ -151,20 +153,39 @@ // FastRetrievalReasoner later) long dematStartTime = System.currentTimeMillis(); - for (NamedClass atomicConcept : rs.getAtomicConcepts()) { - classInstancesPos.put(atomicConcept, rs.retrieval(atomicConcept)); - Negation negatedAtomicConcept = new Negation(atomicConcept); - classInstancesNeg.put(atomicConcept, rs.retrieval(negatedAtomicConcept)); + logger.debug("dematerialising concepts"); + + for (NamedClass atomicConcept : rs.getAtomicConcepts()) { + + SortedSet<Individual> pos = rs.retrieval(atomicConcept); + classInstancesPos.put(atomicConcept, pos); + + if(defaultNegation) { + classInstancesNeg.put(atomicConcept, Helper.difference(individuals,pos)); + } else { + // Pellet needs approximately infinite time to answer negated queries + // on the carcinogenesis data set (and probably others), so we have to + // be careful here + Negation negatedAtomicConcept = new Negation(atomicConcept); + classInstancesNeg.put(atomicConcept, rs.retrieval(negatedAtomicConcept)); + } + + } + logger.debug("dematerialising object properties"); + for (ObjectProperty atomicRole : atomicRoles) { opPos.put(atomicRole, rc.getRoleMembers(atomicRole)); } + logger.debug("dematerialising datatype properties"); + for (DatatypeProperty dp : booleanDatatypeProperties) { - bd.put(dp, rc.getTrueDatatypeMembers(dp)); + bdPos.put(dp, rc.getTrueDatatypeMembers(dp)); + bdNeg.put(dp, rc.getFalseDatatypeMembers(dp)); } - + for (DatatypeProperty dp : intDatatypeProperties) { id.put(dp, rc.getIntDatatypeMembers(dp)); } @@ -269,9 +290,9 @@ if(value) { // check whether the individual is in the set of individuals mapped // to true by this datatype property - return bd.get(dp).contains(individual); + return bdPos.get(dp).contains(individual); } else { - return !bd.get(dp).contains(individual); + return bdNeg.get(dp).contains(individual); } } Modified: trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/reasoning/OWLAPIReasoner.java 2008-03-04 19:10:55 UTC (rev 687) @@ -248,7 +248,8 @@ reasoner = new uk.ac.manchester.cs.factplusplus.owlapi.Reasoner(manager); } catch (Exception e) { e.printStackTrace(); - } + } + System.out.println("Using FaCT++."); } else { // instantiate Pellet reasoner reasoner = new org.mindswap.pellet.owlapi.Reasoner(manager); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-04 13:40:00 UTC (rev 686) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-04 19:10:55 UTC (rev 687) @@ -115,7 +115,7 @@ 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 + // concept comparator private ConceptComparator conceptComparator = new ConceptComparator(); // Statistik @@ -129,6 +129,11 @@ private boolean useNegation = true; private boolean useBooleanDatatypes = true; + // caches for reasoner queries +// private Map<NamedClass,Map<NamedClass,Boolean>> abDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + private Map<NamedClass,Map<NamedClass,Boolean>> notABDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); +// private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + public RhoDRDown(ReasoningService reasoningService) { this(reasoningService, true, true, true, true, true, true, null); } @@ -562,7 +567,7 @@ m2.add(c); else { NamedClass a = (NamedClass) c; - if(!isNotADisjoint(a, nc) && isNotAMeaningFul(a, nc)) + if(!isNotADisjoint(a, nc) && isNotAMeaningful(a, nc)) m2.add(new Negation(a)); } } @@ -697,19 +702,29 @@ // 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); + Map<NamedClass,Boolean> tmp = notABDisjoint.get(a); + Boolean tmp2 = null; + if(tmp != null) + tmp2 = tmp.get(b); + + if(tmp2==null) { + Description notA = new Negation(a); + Description d = new Intersection(notA, b); + Boolean result = rs.subsumes(new Nothing(), d); + // ... add to cache ... + return result; + } else + return tmp2; } // 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) { + private boolean isNotAMeaningful(NamedClass a, NamedClass b) { Description notA = new Negation(a); Description d = new Intersection(notA, b); // check b subClassOf b AND NOT A (if yes then it is not meaningful) return !rs.subsumes(d, b); - } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |