From: <jen...@us...> - 2008-03-03 19:40:24
|
Revision: 677 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=677&view=rev Author: jenslehmann Date: 2008-03-03 11:38:48 -0800 (Mon, 03 Mar 2008) Log Message: ----------- several bugfixes and first succesful run of new refinement operator on arch example Modified Paths: -------------- trunk/examples/arch/arch.conf trunk/examples/arch/arch.kb trunk/examples/arch/arch.owl trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java Modified: trunk/examples/arch/arch.conf =================================================================== --- trunk/examples/arch/arch.conf 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/examples/arch/arch.conf 2008-03-03 19:38:48 UTC (rev 677) @@ -16,13 +16,12 @@ * Copyright (C) 2007, Sebastian Hellmann */ +algorithm = refexamples; +reasoner = fastInstanceChecker; -//export("arch.owl"); - -/** background knowledge **/ +// export("arch.owl"); import("arch.kb"); - /** examples **/ +c1 +c4 Modified: trunk/examples/arch/arch.kb =================================================================== --- trunk/examples/arch/arch.kb 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/examples/arch/arch.kb 2008-03-03 19:38:48 UTC (rev 677) @@ -1,6 +1,11 @@ parallelpipe = (brick OR wedge). -freeStandingPillar = (pillar AND NOT EXISTS touches.TOP ) . +freeStandingPillar = (pillar AND NOT EXISTS touches.TOP ). +// disjoint classes +(parallelpipe AND pillar) = BOTTOM. +(construction AND pillar) = BOTTOM. +(parallelpipe AND construction) = BOTTOM. + construction(c1). construction(c2). construction(c3). @@ -24,6 +29,8 @@ wedge(d). wedge(e). +OPDOMAIN(hasPillar) = construction. +OPRANGE(hasPillar) = pillar. hasPillar(c1,p1). hasPillar(c1,p2). hasPillar(c2,p3). @@ -34,12 +41,16 @@ hasPillar(c4,p8). hasPillar(c5,p9). +OPDOMAIN(hasParallelpipe) = construction. +OPRANGE(hasParallelpipe) = parallelpipe. hasParallelpipe(c1,a). hasParallelpipe(c2,b). hasParallelpipe(c3,c). hasParallelpipe(c4,d). hasParallelpipe(c5,e). +OPDOMAIN(supports) = pillar. +OPRANGE(supports) = parallelpipe. supports(p1,a). supports(p2,a). supports(p5,c). @@ -48,11 +59,15 @@ supports(p8,d). supports(p9,e). +OPDOMAIN(leftof) = pillar. +OPRANGE(leftof) = pillar. leftof(p1,p2). leftof(p3,p4). leftof(p5,p6). leftof(p7,p8). +OPDOMAIN(touches) = pillar. +OPRANGE(touches) = pillar. touches(p5,p6). freeStandingPillar(p1). Modified: trunk/examples/arch/arch.owl =================================================================== --- trunk/examples/arch/arch.owl 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/examples/arch/arch.owl 2008-03-03 19:38:48 UTC (rev 677) @@ -1,115 +1,362 @@ -<?xml version="1.0"?> -<!DOCTYPE rdf:RDF [ - <!ENTITY owl 'http://www.w3.org/2002/07/owl#'> -]> -<rdf:RDF xml:base="http://localhost/foo" -xmlns:a="http://localhost/foo#" -xmlns:owl="http://www.w3.org/2002/07/owl#" -xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" -xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" -xmlns:prefix1="http://localhost/foo#"> - <owl:Ontology rdf:about=""/> - <owl:Class rdf:ID="freeStandingPillar"> - <owl:equivalentClass> - <owl:Class> - <owl:intersectionOf rdf:parseType="Collection"> - <owl:Class rdf:about="#pillar"/> - <owl:Class> - <owl:complementOf> - <owl:Restriction> - <owl:onProperty rdf:resource="#touches"/> - <owl:someValuesFrom rdf:resource="&owl;Thing"/> - </owl:Restriction> - </owl:complementOf> - </owl:Class> - </owl:intersectionOf> - </owl:Class> - </owl:equivalentClass> - </owl:Class> - <owl:Class rdf:ID="parallelpipe"> - <owl:equivalentClass> - <owl:Class> - <owl:unionOf rdf:parseType="Collection"> - <owl:Class rdf:about="#brick"/> - <owl:Class rdf:about="#wedge"/> - </owl:unionOf> - </owl:Class> - </owl:equivalentClass> - </owl:Class> - <prefix1:brick rdf:ID="a"/> - <prefix1:brick rdf:ID="b"/> - <prefix1:brick rdf:ID="c"/> - <prefix1:construction rdf:ID="c1"> - <prefix1:hasParallelpipe rdf:resource="#a"/> - <prefix1:hasPillar rdf:resource="#p1"/> - <prefix1:hasPillar rdf:resource="#p2"/> - </prefix1:construction> - <prefix1:construction rdf:ID="c2"> - <prefix1:hasParallelpipe rdf:resource="#b"/> - <prefix1:hasPillar rdf:resource="#p3"/> - <prefix1:hasPillar rdf:resource="#p4"/> - </prefix1:construction> - <prefix1:construction rdf:ID="c3"> - <prefix1:hasParallelpipe rdf:resource="#c"/> - <prefix1:hasPillar rdf:resource="#p5"/> - <prefix1:hasPillar rdf:resource="#p6"/> - </prefix1:construction> - <prefix1:construction rdf:ID="c4"> - <prefix1:hasParallelpipe rdf:resource="#d"/> - <prefix1:hasPillar rdf:resource="#p7"/> - <prefix1:hasPillar rdf:resource="#p8"/> - </prefix1:construction> - <prefix1:construction rdf:ID="c5"> - <prefix1:hasParallelpipe rdf:resource="#e"/> - <prefix1:hasPillar rdf:resource="#p9"/> - </prefix1:construction> - <prefix1:wedge rdf:ID="d"/> - <prefix1:wedge rdf:ID="e"/> - <prefix1:freeStandingPillar rdf:ID="p1"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:leftof rdf:resource="#p2"/> - <prefix1:supports rdf:resource="#a"/> - </prefix1:freeStandingPillar> - <prefix1:freeStandingPillar rdf:ID="p2"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:supports rdf:resource="#a"/> - </prefix1:freeStandingPillar> - <prefix1:freeStandingPillar rdf:ID="p3"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:leftof rdf:resource="#p4"/> - </prefix1:freeStandingPillar> - <prefix1:freeStandingPillar rdf:ID="p4"> - <rdf:type rdf:resource="#pillar"/> - </prefix1:freeStandingPillar> - <prefix1:pillar rdf:ID="p5"> - <prefix1:leftof rdf:resource="#p6"/> - <prefix1:supports rdf:resource="#c"/> - <prefix1:touches rdf:resource="#p6"/> - </prefix1:pillar> - <prefix1:pillar rdf:ID="p6"> - <prefix1:supports rdf:resource="#c"/> - </prefix1:pillar> - <prefix1:freeStandingPillar rdf:ID="p7"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:leftof rdf:resource="#p8"/> - <prefix1:supports rdf:resource="#d"/> - </prefix1:freeStandingPillar> - <prefix1:freeStandingPillar rdf:ID="p8"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:supports rdf:resource="#d"/> - </prefix1:freeStandingPillar> - <prefix1:freeStandingPillar rdf:ID="p9"> - <rdf:type rdf:resource="#pillar"/> - <prefix1:supports rdf:resource="#e"/> - </prefix1:freeStandingPillar> - <owl:Class rdf:ID="brick"/> - <owl:Class rdf:ID="construction"/> - <owl:Class rdf:ID="pillar"/> - <owl:Class rdf:ID="wedge"/> - <owl:Class rdf:about="http://www.w3.org/2002/07/owl#Thing"/> - <owl:ObjectProperty rdf:ID="hasParallelpipe"/> - <owl:ObjectProperty rdf:ID="hasPillar"/> - <owl:ObjectProperty rdf:ID="leftof"/> - <owl:ObjectProperty rdf:ID="supports"/> - <owl:ObjectProperty rdf:ID="touches"/> -</rdf:RDF> +<?xml version="1.0"?> + + +<!DOCTYPE rdf:RDF [ + <!ENTITY foo "http://localhost/foo#" > + <!ENTITY owl "http://www.w3.org/2002/07/owl#" > + <!ENTITY owl11 "http://www.w3.org/2006/12/owl11#" > + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" > + <!ENTITY owl11xml "http://www.w3.org/2006/12/owl11-xml#" > + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" > + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > +]> + + +<rdf:RDF xmlns="http://example.com#" + xml:base="http://example.com" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl11="http://www.w3.org/2006/12/owl11#" + xmlns:owl11xml="http://www.w3.org/2006/12/owl11-xml#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:foo="http://localhost/foo#"> + <owl:Ontology rdf:about=""/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Object Properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://localhost/foo#hasParallelpipe --> + + <owl:ObjectProperty rdf:about="&foo;hasParallelpipe"> + <rdfs:range rdf:resource="&foo;parallelpipe"/> + <rdfs:domain rdf:resource="&foo;construction"/> + </owl:ObjectProperty> + + + + <!-- http://localhost/foo#hasPillar --> + + <owl:ObjectProperty rdf:about="&foo;hasPillar"> + <rdfs:domain rdf:resource="&foo;construction"/> + <rdfs:range rdf:resource="&foo;pillar"/> + </owl:ObjectProperty> + + + + <!-- http://localhost/foo#leftof --> + + <owl:ObjectProperty rdf:about="&foo;leftof"> + <rdfs:domain rdf:resource="&foo;pillar"/> + <rdfs:range rdf:resource="&foo;pillar"/> + </owl:ObjectProperty> + + + + <!-- http://localhost/foo#supports --> + + <owl:ObjectProperty rdf:about="&foo;supports"> + <rdfs:range rdf:resource="&foo;parallelpipe"/> + <rdfs:domain rdf:resource="&foo;pillar"/> + </owl:ObjectProperty> + + + + <!-- http://localhost/foo#touches --> + + <owl:ObjectProperty rdf:about="&foo;touches"> + <rdfs:domain rdf:resource="&foo;pillar"/> + <rdfs:range rdf:resource="&foo;pillar"/> + </owl:ObjectProperty> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://localhost/foo#brick --> + + <owl:Class rdf:about="&foo;brick"/> + + + + <!-- http://localhost/foo#construction --> + + <owl:Class rdf:about="&foo;construction"/> + + + + <!-- http://localhost/foo#freeStandingPillar --> + + <owl:Class rdf:about="&foo;freeStandingPillar"> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&foo;pillar"/> + <owl:Class> + <owl:complementOf> + <owl:Restriction> + <owl:onProperty rdf:resource="&foo;touches"/> + <owl:someValuesFrom rdf:resource="&owl;Thing"/> + </owl:Restriction> + </owl:complementOf> + </owl:Class> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + + + + <!-- http://localhost/foo#parallelpipe --> + + <owl:Class rdf:about="&foo;parallelpipe"> + <owl:equivalentClass> + <owl:Class> + <owl:unionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&foo;wedge"/> + <rdf:Description rdf:about="&foo;brick"/> + </owl:unionOf> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + + + + <!-- http://localhost/foo#pillar --> + + <owl:Class rdf:about="&foo;pillar"/> + + + + <!-- http://localhost/foo#wedge --> + + <owl:Class rdf:about="&foo;wedge"/> + + + + <!-- http://www.w3.org/2002/07/owl#Nothing --> + + <owl:Class rdf:about="&owl;Nothing"> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&foo;pillar"/> + <rdf:Description rdf:about="&foo;parallelpipe"/> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&foo;construction"/> + <rdf:Description rdf:about="&foo;parallelpipe"/> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> + <owl:equivalentClass> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="&foo;construction"/> + <rdf:Description rdf:about="&foo;pillar"/> + </owl:intersectionOf> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + + + + <!-- http://www.w3.org/2002/07/owl#Thing --> + + <owl:Class rdf:about="&owl;Thing"/> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Individuals + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://localhost/foo#a --> + + <foo:brick rdf:about="&foo;a"/> + + + + <!-- http://localhost/foo#b --> + + <foo:brick rdf:about="&foo;b"/> + + + + <!-- http://localhost/foo#c --> + + <foo:brick rdf:about="&foo;c"/> + + + + <!-- http://localhost/foo#c1 --> + + <foo:construction rdf:about="&foo;c1"> + <foo:hasParallelpipe rdf:resource="&foo;a"/> + <foo:hasPillar rdf:resource="&foo;p2"/> + <foo:hasPillar rdf:resource="&foo;p1"/> + </foo:construction> + + + + <!-- http://localhost/foo#c2 --> + + <foo:construction rdf:about="&foo;c2"> + <foo:hasPillar rdf:resource="&foo;p3"/> + <foo:hasParallelpipe rdf:resource="&foo;b"/> + <foo:hasPillar rdf:resource="&foo;p4"/> + </foo:construction> + + + + <!-- http://localhost/foo#c3 --> + + <foo:construction rdf:about="&foo;c3"> + <foo:hasPillar rdf:resource="&foo;p5"/> + <foo:hasParallelpipe rdf:resource="&foo;c"/> + <foo:hasPillar rdf:resource="&foo;p6"/> + </foo:construction> + + + + <!-- http://localhost/foo#c4 --> + + <foo:construction rdf:about="&foo;c4"> + <foo:hasParallelpipe rdf:resource="&foo;d"/> + <foo:hasPillar rdf:resource="&foo;p8"/> + <foo:hasPillar rdf:resource="&foo;p7"/> + </foo:construction> + + + + <!-- http://localhost/foo#c5 --> + + <foo:construction rdf:about="&foo;c5"> + <foo:hasPillar rdf:resource="&foo;p9"/> + <foo:hasParallelpipe rdf:resource="&foo;e"/> + </foo:construction> + + + + <!-- http://localhost/foo#d --> + + <foo:wedge rdf:about="&foo;d"/> + + + + <!-- http://localhost/foo#e --> + + <foo:wedge rdf:about="&foo;e"/> + + + + <!-- http://localhost/foo#p1 --> + + <foo:pillar rdf:about="&foo;p1"> + <rdf:type rdf:resource="&foo;freeStandingPillar"/> + <foo:supports rdf:resource="&foo;a"/> + <foo:leftof rdf:resource="&foo;p2"/> + </foo:pillar> + + + + <!-- http://localhost/foo#p2 --> + + <foo:pillar rdf:about="&foo;p2"> + <rdf:type rdf:resource="&foo;freeStandingPillar"/> + <foo:supports rdf:resource="&foo;a"/> + </foo:pillar> + + + + <!-- http://localhost/foo#p3 --> + + <foo:freeStandingPillar rdf:about="&foo;p3"> + <rdf:type rdf:resource="&foo;pillar"/> + <foo:leftof rdf:resource="&foo;p4"/> + </foo:freeStandingPillar> + + + + <!-- http://localhost/foo#p4 --> + + <foo:freeStandingPillar rdf:about="&foo;p4"> + <rdf:type rdf:resource="&foo;pillar"/> + </foo:freeStandingPillar> + + + + <!-- http://localhost/foo#p5 --> + + <foo:pillar rdf:about="&foo;p5"> + <foo:supports rdf:resource="&foo;c"/> + <foo:touches rdf:resource="&foo;p6"/> + <foo:leftof rdf:resource="&foo;p6"/> + </foo:pillar> + + + + <!-- http://localhost/foo#p6 --> + + <foo:pillar rdf:about="&foo;p6"> + <foo:supports rdf:resource="&foo;c"/> + </foo:pillar> + + + + <!-- http://localhost/foo#p7 --> + + <foo:freeStandingPillar rdf:about="&foo;p7"> + <rdf:type rdf:resource="&foo;pillar"/> + <foo:leftof rdf:resource="&foo;p8"/> + <foo:supports rdf:resource="&foo;d"/> + </foo:freeStandingPillar> + + + + <!-- http://localhost/foo#p8 --> + + <foo:freeStandingPillar rdf:about="&foo;p8"> + <rdf:type rdf:resource="&foo;pillar"/> + <foo:supports rdf:resource="&foo;d"/> + </foo:freeStandingPillar> + + + + <!-- http://localhost/foo#p9 --> + + <foo:freeStandingPillar rdf:about="&foo;p9"> + <rdf:type rdf:resource="&foo;pillar"/> + <foo:supports rdf:resource="&foo;e"/> + </foo:freeStandingPillar> +</rdf:RDF> Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLComponent.java 2008-03-03 19:38:48 UTC (rev 677) @@ -43,7 +43,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.refinementoperators.RhoDown; +import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; @@ -54,8 +54,6 @@ * passes them to the actual refinement operator, heuristic, and * learning algorithm implementations. * - * Note: The component is not working yet. - * * Note: The options supported by the ROLearner component and this * one are not equal. Options that have been dropped for now: * - horizontal expansion factor: The goal of the algorithm will @@ -106,6 +104,7 @@ private boolean useNegation = true; private boolean useBooleanDatatypes = true; private double noisePercentage = 0.0; + private NamedClass startClass = null; // Variablen zur Einstellung der Protokollierung // boolean quiet = false; @@ -167,6 +166,7 @@ noisePercentage.setLowerLimit(0); noisePercentage.setUpperLimit(100); options.add(noisePercentage); + options.add(new StringConfigOption("startClass", "the named class which should be used to start the algorithm (GUI: needs a widget for selecting a class)")); return options; } @@ -219,8 +219,9 @@ noisePercentage = (Double) entry.getValue(); } else if(name.equals("useBooleanDatatypes")) { useBooleanDatatypes = (Boolean) entry.getValue(); + } else if(name.equals("startClass")) { + startClass = new NamedClass((String)entry.getValue()); } - } /* (non-Javadoc) @@ -276,19 +277,21 @@ if(improveSubsumptionHierarchy) rs.getSubsumptionHierarchy().improveSubsumptionHierarchy(); rs.prepareRoleHierarchy(usedRoles); + rs.prepareDatatypePropertyHierarchy(); // create a refinement operator and pass all configuration // variables to it - RhoDown operator = new RhoDown( - rs, - applyAllFilter, - applyExistsFilter, - useAllConstructor, - useExistsConstructor, - useNegation, - useBooleanDatatypes - ); - + RhoDRDown operator = new RhoDRDown( + rs, + applyAllFilter, + applyExistsFilter, + useAllConstructor, + useExistsConstructor, + useNegation, + useBooleanDatatypes, + startClass + ); + // create an algorithm object and pass all configuration // options to it algorithm = new ExampleBasedROLearner( Modified: trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/src/dl-learner/org/dllearner/algorithms/refexamples/ExampleBasedROLearner.java 2008-03-03 19:38:48 UTC (rev 677) @@ -42,7 +42,7 @@ import org.dllearner.core.owl.Thing; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; -import org.dllearner.refinementoperators.RhoDown; +import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.ConceptComparator; import org.dllearner.utilities.ConceptTransformation; import org.dllearner.utilities.Files; @@ -107,7 +107,8 @@ private List<Description> solutions = new LinkedList<Description>(); // used refinement operator and heuristic (exchangeable) - private RhoDown operator; + private RhoDRDown operator; +// private RefinementOperator operator; // private ExampleBasedHeuristic heuristic; // specifies whether to compute and log benchmark information @@ -195,7 +196,7 @@ } nrOfExamples = nrOfPositiveExamples + nrOfNegativeExamples; this.rs = rs; - this.operator = (RhoDown) operator; + this.operator = (RhoDRDown) operator; // initialise candidate set with heuristic as ordering candidates = new TreeSet<ExampleBasedNode>(heuristic); this.noise = noise; @@ -568,7 +569,7 @@ tooWeakList.add(refinement); } else { // Lösung gefunden - if(quality >= 0 && quality<allowedMisclassifications) { + if(quality >= 0 && quality<=allowedMisclassifications) { solutionFound = true; solutions.add(refinement); } Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastInstanceChecker.java 2008-03-03 19:38:48 UTC (rev 677) @@ -279,6 +279,11 @@ + description + " unsupported."); } + @Override + public SortedSet<Individual> retrieval(Description concept) { + return rs.retrieval(concept); + } + /* * (non-Javadoc) * Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 15:49:03 UTC (rev 676) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/RhoDRDown.java 2008-03-03 19:38:48 UTC (rev 677) @@ -97,8 +97,8 @@ private Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); // refinements of the top concept ordered by length - 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>>>(); + private Map<Integer, SortedSet<Description>> topRefinements = new TreeMap<Integer, SortedSet<Description>>(); + private Map<NamedClass,Map<Integer, SortedSet<Description>>> topARefinements = new TreeMap<NamedClass,Map<Integer, SortedSet<Description>>>(); // cumulated refinements of top (all from length one to the specified length) private Map<Integer, TreeSet<Description>> topRefinementsCumulative = new HashMap<Integer, TreeSet<Description>>(); @@ -119,8 +119,8 @@ private ConceptComparator conceptComparator = new ConceptComparator(); // Statistik - private long mComputationTimeNs = 0; - private long topComputationTimeNs = 0; + public long mComputationTimeNs = 0; + public long topComputationTimeNs = 0; private boolean applyAllFilter = true; private boolean applyExistsFilter = true; @@ -129,12 +129,20 @@ private boolean useNegation = true; private boolean useBooleanDatatypes = true; - public RhoDRDown(ReasoningService rs) { - this(rs, null); + public RhoDRDown(ReasoningService reasoningService) { + this(reasoningService, true, true, true, true, true, true, null); } - public RhoDRDown(ReasoningService rs, NamedClass startClass) { - this.rs = rs; + public RhoDRDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + boolean useExistsConstructor, boolean useNegation, boolean useBooleanDatatypes, NamedClass startClass) { + this.rs = reasoningService; + this.applyAllFilter = applyAllFilter; + this.applyExistsFilter = applyExistsFilter; + this.useAllConstructor = useAllConstructor; + this.useExistsConstructor = useExistsConstructor; + this.useNegation = useNegation; + this.useBooleanDatatypes = useBooleanDatatypes; + subHierarchy = rs.getSubsumptionHierarchy(); // query reasoner for domains and ranges @@ -169,6 +177,14 @@ @SuppressWarnings({"unchecked"}) public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements, Description currDomain) { + +// System.out.println(description + " " + currDomain); + + // actions needing to be performed if this is the first time the + // current domain is used + if(!(currDomain instanceof Thing) && !topARefinementsLength.containsKey(currDomain)) + topARefinementsLength.put((NamedClass)currDomain, 0); + // TODO: check whether using list or set makes more sense // here; and whether HashSet or TreeSet should be used Set<Description> refinements = new TreeSet<Description>(conceptComparator); @@ -184,8 +200,8 @@ refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); } else { if(maxLength>topARefinementsLength.get(currDomain)) - computeTopRefinements(maxLength); - refinements = (TreeSet<Description>) topRefinementsCumulative.get(maxLength).clone(); + computeTopRefinements(maxLength, (NamedClass) currDomain); + refinements = (TreeSet<Description>) topARefinementsCumulative.get(currDomain).get(maxLength).clone(); } // refinements.addAll(subHierarchy.getMoreSpecialConcepts(description)); @@ -303,9 +319,10 @@ int topRefLength = maxLength - description.getLength() - 1; // maybe we have to compute new top refinements here - if(currDomain instanceof Thing && topRefLength > topRefinementsLength) - computeTopRefinements(topRefLength); - else if(topRefLength > topARefinementsLength.get(currDomain)) + if(currDomain instanceof Thing) { + if(topRefLength > topRefinementsLength) + computeTopRefinements(topRefLength); + } else if(topRefLength > topARefinementsLength.get(currDomain)) computeTopRefinements(topRefLength,(NamedClass)currDomain); if(topRefLength>0) { @@ -366,24 +383,48 @@ if(domain != null && !mA.containsKey(domain)) computeM(domain); + int refinementsLength; + + if(domain == null) { + refinementsLength = topRefinementsLength; + } else { + if(!topARefinementsLength.containsKey(domain)) + topARefinementsLength.put(domain,0); + + refinementsLength = topARefinementsLength.get(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)); + // initialise the refinements with empty sets + if(domain == null) { + topRefinements.put(i, new TreeSet<Description>(conceptComparator)); + } else { + if(!topARefinements.containsKey(domain)) + topARefinements.put(domain, new TreeMap<Integer,SortedSet<Description>>()); + topARefinements.get(domain).put(i, new TreeSet<Description>(conceptComparator)); + } + for(List<Integer> combo : combos.get(i)) { // combination is a single number => try to use M if(combo.size()==1) { + // note we cannot use "put" instead of "addAll" because there + // can be several combos for one length if(domain == null) - topRefinements.put(i,m.get(i)); + topRefinements.get(i).addAll(m.get(i)); else - topARefinements.get(domain).put(i,mA.get(domain).get(i)); + topARefinements.get(domain).get(i).addAll(mA.get(domain).get(i)); // combinations has several numbers => generate disjunct } else { SortedSet<Union> baseSet = new TreeSet<Union>(conceptComparator); for(Integer j : combo) { - baseSet = MathOperations.incCrossProduct(baseSet, m.get(j)); + if(domain == null) + baseSet = MathOperations.incCrossProduct(baseSet, m.get(j)); + else + baseSet = MathOperations.incCrossProduct(baseSet, mA.get(domain).get(j)); } // convert all concepts in ordered negation normal form @@ -405,9 +446,9 @@ // add computed refinements if(domain == null) - topRefinements.put(new Integer(i), baseSet); + topRefinements.get(i).addAll(baseSet); else - topARefinements.get(domain).put(new Integer(i), baseSet); + topARefinements.get(domain).get(i).addAll(baseSet); } } @@ -415,15 +456,20 @@ // be accessed easily TreeSet<Description> cumulativeRefinements = new TreeSet<Description>(conceptComparator); for(int j=1; j<=i; j++) { - if(domain == null) + if(domain == null) { cumulativeRefinements.addAll(topRefinements.get(j)); - else + } else { cumulativeRefinements.addAll(topARefinements.get(domain).get(j)); + } } - if(domain == null) + + if(domain == null) { topRefinementsCumulative.put(i, cumulativeRefinements); - else + } else { + if(!topARefinementsCumulative.containsKey(domain)) + topARefinementsCumulative.put(domain, new TreeMap<Integer, TreeSet<Description>>()); topARefinementsCumulative.get(domain).put(i, cumulativeRefinements); + } } // register new top refinements length @@ -495,12 +541,12 @@ mA.put(nc, new TreeMap<Integer,SortedSet<Description>>()); // initialise all possible lengths (1 to 3) - for(int i=1; i<=3; i++) { + for(int i=1; i<=mMaxLength; i++) { mA.get(nc).put(i, new TreeSet<Description>(conceptComparator)); } SortedSet<Description> m1 = rs.getMoreSpecialConcepts(nc); - m.put(1,m1); + mA.get(nc).put(1,m1); if(useNegation) { // the definition in the paper is more complex, but acutally @@ -516,11 +562,11 @@ 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)); } } - m.put(2,m2); + mA.get(nc).put(2,m2); } // compute applicable properties @@ -551,7 +597,7 @@ } } - m.put(3,m3); + mA.get(nc).put(3,m3); mComputationTimeNs += System.nanoTime() - mComputationTimeStartNs; } @@ -560,6 +606,12 @@ // compute the applicable properties if this has not been done yet if(appOP.get(domain) == null) computeApp(domain); + + // initialise mgr, mgbd, mgdd + mgr.put(domain, new TreeSet<ObjectProperty>()); + mgbd.put(domain, new TreeSet<DatatypeProperty>()); + mgdd.put(domain, new TreeSet<DatatypeProperty>()); + SortedSet<ObjectProperty> mostGeneral = rs.getMostGeneralRoles(); computeMgrRecursive(domain, mostGeneral, mgr.get(domain)); SortedSet<DatatypeProperty> mostGeneralDP = rs.getMostGeneralDatatypeProperties(); @@ -606,8 +658,8 @@ for(ObjectProperty role : mostGeneral) { // TODO: currently we just rely on named classes as roles, // instead of computing dom(r) and ran(r) - NamedClass nc = (NamedClass) rs.getDomain(role); - if(!isDisjoint(domain,nc)) + Description d = rs.getDomain(role); + if(!isDisjoint(domain,d)) applicableRoles.add(role); } appOP.put(domain, applicableRoles); @@ -616,8 +668,8 @@ 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)) + Description d = (NamedClass) rs.getDomain(role); + if(!isDisjoint(domain,d)) applicableBDPs.add(role); } appBD.put(domain, applicableBDPs); @@ -626,8 +678,8 @@ 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)) + Description d = (NamedClass) rs.getDomain(role); + if(!isDisjoint(domain,d)) applicableDDPs.add(role); } appDD.put(domain, applicableDDPs); @@ -637,10 +689,10 @@ // by the reasoner only ones and otherwise taken from a matrix // => 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) { + private boolean isDisjoint(NamedClass a, Description d) { // we need to test whether A AND B is equivalent to BOTTOM - Description d = new Intersection(a, b); - return rs.subsumes(new Nothing(), d); + Description d2 = new Intersection(a, d); + return rs.subsumes(new Nothing(), d2); } // we need to test whether NOT A AND B is equivalent to BOTTOM @@ -656,7 +708,8 @@ private boolean isNotAMeaningFul(NamedClass a, NamedClass b) { Description notA = new Negation(a); Description d = new Intersection(notA, b); - return !rs.subsumes(b, d); + // 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. |