From: <sha...@us...> - 2012-04-18 12:52:02
|
Revision: 3640 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3640&view=rev Author: shadowtm Date: 2012-04-18 12:51:51 +0000 (Wed, 18 Apr 2012) Log Message: ----------- Cleaned up poms in preparation for removing third party repositories - these mods will make a significant impact on build time. Modified Paths: -------------- trunk/components-ext/pom.xml trunk/pom.xml Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2012-04-18 03:45:36 UTC (rev 3639) +++ trunk/components-ext/pom.xml 2012-04-18 12:51:51 UTC (rev 3640) @@ -10,21 +10,6 @@ <version>1.0-SNAPSHOT</version> <url>http://aksw.org/Projects/DLLearner</url> - <repositories> - <repository> - <id>Simmetrics</id> - <url>http://maven.mse.jhu.edu/m2repository/</url> - </repository> - <!-- <repository> <id>Harvard Med</id> <url>http://repo.open.med.harvard.edu/nexus/content/repositories/public/</url> - </repository> --> - <repository> - <id>Annolab</id> - <url>http://annolab.org/m2/releases/</url> - </repository> - <!-- <repository> <id>Mirror for WSTX</id> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url> - </repository> --> - </repositories> - <parent> <groupId>org.dllearner</groupId> <artifactId>dllearner-parent</artifactId> @@ -124,24 +109,13 @@ <groupId>uk.ac.shef.wit</groupId> <artifactId>simmetrics</artifactId> <version>1.6.2</version> - <type>jar</type> - <scope>compile</scope> </dependency> <dependency> <groupId>stax</groupId> <artifactId>stax-api</artifactId> <version>1.0.1</version> - <type>jar</type> - <scope>compile</scope> </dependency> <dependency> - <groupId>woodstox</groupId> - <artifactId>wstx-api</artifactId> - <version>3.2.0</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> @@ -179,10 +153,8 @@ <dependency> <groupId>org.nlp2rdf</groupId> <artifactId>nif</artifactId> - <version>1.1-SNAPSHOT</version> + <version>1.1</version> </dependency> - - <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-18 03:45:36 UTC (rev 3639) +++ trunk/pom.xml 2012-04-18 12:51:51 UTC (rev 3640) @@ -16,7 +16,7 @@ <gwt.version>2.3.0</gwt.version> <!--Define the AKSW dependency version --> - <aksw.version>0.1</aksw.version> + <aksw.version>0.2-SNAPSHOT</aksw.version> <slf4j.version>1.6.4</slf4j.version> <log4j.version>1.2.16</log4j.version> @@ -81,11 +81,11 @@ <artifactId>maven-source-plugin</artifactId> <version>2.1.2</version> </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>gwt-maven-plugin</artifactId> - <version>${gwt.version}</version> - </plugin> + <plugin> + <groupId>com.mycila.maven-license-plugin</groupId> + <artifactId>maven-license-plugin</artifactId> + <version>1.9.0</version> + </plugin> </plugins> </pluginManagement> </build> @@ -117,12 +117,6 @@ <version>1.3.3</version> </dependency> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>0.9.3</version> - </dependency> - <!-- SOLR Dependency --> <dependency> <groupId>org.apache.solr</groupId> @@ -152,13 +146,6 @@ </exclusions> </dependency> - - <dependency> - <groupId>com.extjs</groupId> - <artifactId>gxt</artifactId> - <version>2.2.3</version> - </dependency> - <!--Available via central, we use the latest with minor mods to DL Learner source (IE Dig related code) --> <dependency> @@ -293,34 +280,26 @@ </dependency> <dependency> - <groupId>org.dllearner</groupId> - <artifactId>sparql-query-generator</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> <groupId>org.aksw.commons</groupId> <artifactId>sparql</artifactId> - <version>0.2-SNAPSHOT</version> + <version>${aksw.version}</version> </dependency> <dependency> <groupId>org.aksw.commons</groupId> <artifactId>model</artifactId> - <version>0.2-SNAPSHOT</version> + <version>${aksw.version}</version> </dependency> <dependency> <groupId>org.aksw.commons</groupId> <artifactId>collections</artifactId> - <version>0.2-SNAPSHOT</version> + <version>${aksw.version}</version> </dependency> - <dependency> <groupId>org.aksw.commons</groupId> <artifactId>util</artifactId> - <version>0.2-SNAPSHOT</version> + <version>${aksw.version}</version> </dependency> - <dependency> <groupId>net.sourceforge.secondstring</groupId> <artifactId>secondstring</artifactId> @@ -357,25 +336,8 @@ <version>5.1.13</version> </dependency> - <dependency> - <groupId>commons-configuration</groupId> - <artifactId>commons-configuration</artifactId> - <version>1.6</version> - </dependency> - <!--GWT Dependencies --> <dependency> - <groupId>com.google.gwt</groupId> - <artifactId>gwt-servlet</artifactId> - <version>${gwt.version}</version> - </dependency> - <dependency> - <groupId>com.google.gwt</groupId> - <artifactId>gwt-user</artifactId> - <version>${gwt.version}</version> - </dependency> - - <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>8.4-701.jdbc4</version> @@ -478,13 +440,6 @@ <artifactId>jcl-over-slf4j</artifactId> <version>${slf4j.version}</version> </dependency> - - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jdk14</artifactId> - <version>${slf4j.version}</version> - </dependency> <!--END Logging Dependencies--> </dependencies> @@ -518,13 +473,7 @@ <url>http://on.cs.unibas.ch/maven/repository/</url> </repository> - <!-- This repository contains the jars for the project lombok jars --> <repository> - <id>projectlombok.org</id> - <url>http://projectlombok.org/mavenrepo</url> - </repository> - - <repository> <id>GXT</id> <url>http://maven.jahia.org/maven2/</url> </repository> @@ -621,9 +570,11 @@ <artifactId>maven-source-plugin</artifactId> <executions> <execution> - <goals> - <goal>jar</goal> - </goals> + <id>attach-sources</id> + <phase>verify</phase> + <goals> + <goal>jar</goal> + </goals> </execution> </executions> </plugin> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-04-19 13:39:37
|
Revision: 3642 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3642&view=rev Author: lorenz_b Date: 2012-04-19 13:39:25 +0000 (Thu, 19 Apr 2012) Log Message: ----------- Started Protege plugin refactoring to be able to work with latest DL-Learner architecture and Protege 4.1. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java trunk/protege/src/main/resources/META-INF/MANIFEST.MF trunk/protege/src/main/resources/lib/components-core-1.0-SNAPSHOT.jar Added Paths: ----------- trunk/protege/src/main/resources/lib/jamon-2.0.jar trunk/protege/src/main/resources/lib/json-20090211.jar trunk/protege/src/main/resources/lib/log4j-1.2.16.jar Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -778,251 +778,254 @@ return inds; } -@SuppressWarnings("unchecked") -public SortedSet<Individual> getIndividualsImplFast(Description description) - throws ReasoningMethodUnsupportedException { - // policy: returned sets are clones, i.e. can be modified - // (of course we only have to clone the leafs of a class description tree) - if (description instanceof NamedClass) { - return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); - } else if (description instanceof Negation) { - if(description.getChild(0) instanceof NamedClass) { - return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone(); - } - // implement retrieval as default negation - return Helper.difference((TreeSet<Individual>) individuals.clone(), getIndividualsImpl(description.getChild(0))); - } else if (description instanceof Thing) { - return (TreeSet<Individual>) individuals.clone(); - } else if (description instanceof Nothing) { - return new TreeSet<Individual>(); - } else if (description instanceof Union) { - // copy instances of first element and then subtract all others - SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); - int childNr = 0; - for(Description child : description.getChildren()) { - if(childNr != 0) { - ret.addAll(getIndividualsImpl(child)); + @SuppressWarnings("unchecked") + public SortedSet<Individual> getIndividualsImplFast(Description description) + throws ReasoningMethodUnsupportedException { + // policy: returned sets are clones, i.e. can be modified + // (of course we only have to clone the leafs of a class description tree) + if (description instanceof NamedClass) { + if(((NamedClass) description).getName().equals("http://www.w3.org/2002/07/owl#Nothing")){ + return new TreeSet<Individual>(); } - childNr++; - } - return ret; - } else if (description instanceof Intersection) { - // copy instances of first element and then subtract all others - SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); - int childNr = 0; - for(Description child : description.getChildren()) { - if(childNr != 0) { - ret.retainAll(getIndividualsImpl(child)); + return (TreeSet<Individual>) classInstancesPos.get((NamedClass) description).clone(); + } else if (description instanceof Negation) { + if(description.getChild(0) instanceof NamedClass) { + return (TreeSet<Individual>) classInstancesNeg.get((NamedClass) description.getChild(0)).clone(); } - childNr++; - } - return ret; - } else if (description instanceof ObjectSomeRestriction) { - SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Retrieval for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - - // each individual is connected to a set of individuals via the property; - // we loop through the complete mapping - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - SortedSet<Individual> inds = entry.getValue(); - for(Individual ind : inds) { - if(targetSet.contains(ind)) { - returnSet.add(entry.getKey()); - // once we found an individual, we do not need to check the others - continue; + // implement retrieval as default negation + return Helper.difference((TreeSet<Individual>) individuals.clone(), getIndividualsImpl(description.getChild(0))); + } else if (description instanceof Thing) { + return (TreeSet<Individual>) individuals.clone(); + } else if (description instanceof Nothing) { + return new TreeSet<Individual>(); + } else if (description instanceof Union) { + // copy instances of first element and then subtract all others + SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); + int childNr = 0; + for(Description child : description.getChildren()) { + if(childNr != 0) { + ret.addAll(getIndividualsImpl(child)); } + childNr++; } - } - return returnSet; - } else if (description instanceof ObjectAllRestriction) { - // \forall restrictions are difficult to handle; assume we want to check - // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons - // this is satisfied trivially (all of their non-existing children are male) -// if(!configurator.getForallRetrievalSemantics().equals("standard")) { -// throw new Error("Only forallExists semantics currently implemented."); -// } - - // problem: we need to make sure that \neg \exists r.\top \equiv \forall r.\bot - // can still be reached in an algorithm (\forall r.\bot \equiv \bot under forallExists - // semantics) - - SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); - - ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); -// SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet()); - SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - - // each individual is connected to a set of individuals via the property; - // we loop through the complete mapping - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - SortedSet<Individual> inds = entry.getValue(); - for(Individual ind : inds) { - if(!targetSet.contains(ind)) { - returnSet.remove(entry.getKey()); - continue; + return ret; + } else if (description instanceof Intersection) { + // copy instances of first element and then subtract all others + SortedSet<Individual> ret = getIndividualsImpl(description.getChild(0)); + int childNr = 0; + for(Description child : description.getChildren()) { + if(childNr != 0) { + ret.retainAll(getIndividualsImpl(child)); } + childNr++; } - } - return returnSet; - } else if (description instanceof ObjectMinCardinalityRestriction) { - ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Description child = description.getChild(0); - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> targetSet = getIndividualsImpl(child); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - int number = ((ObjectCardinalityRestriction) description).getNumber(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - int nrOfFillers = 0; - int index = 0; - SortedSet<Individual> inds = entry.getValue(); + return ret; + } else if (description instanceof ObjectSomeRestriction) { + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - // we do not need to run tests if there are not sufficiently many fillers - if(inds.size() < number) { - continue; + ObjectPropertyExpression ope = ((ObjectSomeRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Retrieval for description " + + description + " unsupported. Inverse object properties not supported."); } + ObjectProperty op = (ObjectProperty) ope; + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - for(Individual ind : inds) { - // stop inner loop when nr of fillers is reached - if(nrOfFillers >= number) { - returnSet.add(entry.getKey()); - break; - } - // early abort when too many instance checks failed - if (inds.size() - index < number) { - break; - } - if(targetSet.contains(ind)) { - nrOfFillers++; + // each individual is connected to a set of individuals via the property; + // we loop through the complete mapping + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + SortedSet<Individual> inds = entry.getValue(); + for(Individual ind : inds) { + if(targetSet.contains(ind)) { + returnSet.add(entry.getKey()); + // once we found an individual, we do not need to check the others + continue; + } } - index++; } - } - - return returnSet; - } else if (description instanceof ObjectMaxCardinalityRestriction) { - ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); - if (!(ope instanceof ObjectProperty)) { - throw new ReasoningMethodUnsupportedException("Instance check for description " - + description + " unsupported. Inverse object properties not supported."); - } - ObjectProperty op = (ObjectProperty) ope; - Description child = description.getChild(0); - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> targetSet = getIndividualsImpl(child); - // initially all individuals are in the return set and we then remove those - // with too many fillers - SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - - int number = ((ObjectCardinalityRestriction) description).getNumber(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - int nrOfFillers = 0; - int index = 0; - SortedSet<Individual> inds = entry.getValue(); + return returnSet; + } else if (description instanceof ObjectAllRestriction) { + // \forall restrictions are difficult to handle; assume we want to check + // \forall hasChild.male with domain(hasChild)=Person; then for all non-persons + // this is satisfied trivially (all of their non-existing children are male) +// if(!configurator.getForallRetrievalSemantics().equals("standard")) { +// throw new Error("Only forallExists semantics currently implemented."); +// } - // we do not need to run tests if there are not sufficiently many fillers - if(number < inds.size()) { - returnSet.add(entry.getKey()); - continue; + // problem: we need to make sure that \neg \exists r.\top \equiv \forall r.\bot + // can still be reached in an algorithm (\forall r.\bot \equiv \bot under forallExists + // semantics) + + SortedSet<Individual> targetSet = getIndividualsImpl(description.getChild(0)); + + ObjectPropertyExpression ope = ((ObjectAllRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); } + ObjectProperty op = (ObjectProperty) ope; + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); +// SortedSet<Individual> returnSet = new TreeSet<Individual>(mapping.keySet()); + SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - for(Individual ind : inds) { - // stop inner loop when nr of fillers is reached - if(nrOfFillers >= number) { - break; - } - // early abort when too many instance are true already - if (inds.size() - index < number) { - returnSet.add(entry.getKey()); - break; - } - if(targetSet.contains(ind)) { - nrOfFillers++; + // each individual is connected to a set of individuals via the property; + // we loop through the complete mapping + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + SortedSet<Individual> inds = entry.getValue(); + for(Individual ind : inds) { + if(!targetSet.contains(ind)) { + returnSet.remove(entry.getKey()); + continue; + } } - index++; } - } - - return returnSet; - } else if (description instanceof ObjectValueRestriction) { - Individual i = ((ObjectValueRestriction)description).getIndividual(); - ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); - - Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); - - for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { - if(entry.getValue().contains(i)) { - returnSet.add(entry.getKey()); + return returnSet; + } else if (description instanceof ObjectMinCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); } - } - return returnSet; - } else if (description instanceof BooleanValueRestriction) { - DatatypeProperty dp = ((BooleanValueRestriction) description) - .getRestrictedPropertyExpression(); - boolean value = ((BooleanValueRestriction) description).getBooleanValue(); + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(child); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); - if (value) { - return (TreeSet<Individual>) bdPos.get(dp).clone(); - } else { - return (TreeSet<Individual>) bdNeg.get(dp).clone(); - } - } else if (description instanceof DatatypeSomeRestriction) { - DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; - DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); - DataRange dr = dsr.getDataRange(); + int number = ((ObjectCardinalityRestriction) description).getNumber(); - Map<Individual, SortedSet<Double>> mapping = dd.get(dp); - SortedSet<Individual> returnSet = new TreeSet<Individual>(); + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(inds.size() < number) { + continue; + } + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + returnSet.add(entry.getKey()); + break; + } + // early abort when too many instance checks failed + if (inds.size() - index < number) { + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectMaxCardinalityRestriction) { + ObjectPropertyExpression ope = ((ObjectCardinalityRestriction) description).getRole(); + if (!(ope instanceof ObjectProperty)) { + throw new ReasoningMethodUnsupportedException("Instance check for description " + + description + " unsupported. Inverse object properties not supported."); + } + ObjectProperty op = (ObjectProperty) ope; + Description child = description.getChild(0); + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> targetSet = getIndividualsImpl(child); + // initially all individuals are in the return set and we then remove those + // with too many fillers + SortedSet<Individual> returnSet = (SortedSet<Individual>) individuals.clone(); - if (dr instanceof DoubleMaxValue) { - for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { - if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) { + int number = ((ObjectCardinalityRestriction) description).getNumber(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + int nrOfFillers = 0; + int index = 0; + SortedSet<Individual> inds = entry.getValue(); + + // we do not need to run tests if there are not sufficiently many fillers + if(number < inds.size()) { returnSet.add(entry.getKey()); + continue; } - } - } else if (dr instanceof DoubleMinValue) { - for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { - if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) { + + for(Individual ind : inds) { + // stop inner loop when nr of fillers is reached + if(nrOfFillers >= number) { + break; + } + // early abort when too many instance are true already + if (inds.size() - index < number) { + returnSet.add(entry.getKey()); + break; + } + if(targetSet.contains(ind)) { + nrOfFillers++; + } + index++; + } + } + + return returnSet; + } else if (description instanceof ObjectValueRestriction) { + Individual i = ((ObjectValueRestriction)description).getIndividual(); + ObjectProperty op = (ObjectProperty) ((ObjectValueRestriction)description).getRestrictedPropertyExpression(); + + Map<Individual, SortedSet<Individual>> mapping = opPos.get(op); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + for(Entry<Individual, SortedSet<Individual>> entry : mapping.entrySet()) { + if(entry.getValue().contains(i)) { returnSet.add(entry.getKey()); } } + return returnSet; + } else if (description instanceof BooleanValueRestriction) { + DatatypeProperty dp = ((BooleanValueRestriction) description) + .getRestrictedPropertyExpression(); + boolean value = ((BooleanValueRestriction) description).getBooleanValue(); + + if (value) { + return (TreeSet<Individual>) bdPos.get(dp).clone(); + } else { + return (TreeSet<Individual>) bdNeg.get(dp).clone(); + } + } else if (description instanceof DatatypeSomeRestriction) { + DatatypeSomeRestriction dsr = (DatatypeSomeRestriction) description; + DatatypeProperty dp = (DatatypeProperty) dsr.getRestrictedPropertyExpression(); + DataRange dr = dsr.getDataRange(); + + Map<Individual, SortedSet<Double>> mapping = dd.get(dp); + SortedSet<Individual> returnSet = new TreeSet<Individual>(); + + if (dr instanceof DoubleMaxValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().first() <= ((DoubleMaxValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } else if (dr instanceof DoubleMinValue) { + for(Entry<Individual, SortedSet<Double>> entry : mapping.entrySet()) { + if(entry.getValue().last() >= ((DoubleMinValue)dr).getValue()) { + returnSet.add(entry.getKey()); + } + } + } } + + throw new ReasoningMethodUnsupportedException("Retrieval for description " + + description + " unsupported."); + + // return rs.retrieval(concept); +// SortedSet<Individual> inds = new TreeSet<Individual>(); +// for (Individual i : individuals) { +// if (hasType(concept, i)) { +// inds.add(i); +// } +// } +// return inds; } - - throw new ReasoningMethodUnsupportedException("Retrieval for description " - + description + " unsupported."); - - // return rs.retrieval(concept); -// SortedSet<Individual> inds = new TreeSet<Individual>(); -// for (Individual i : individuals) { -// if (hasType(concept, i)) { -// inds.add(i); -// } -// } -// return inds; -} @Override public Set<NamedClass> getTypesImpl(Individual individual) { Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/ActionHandler.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -99,6 +99,14 @@ // view.setLearningStarted(); // view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), // Manager.getInstance().getMaximumHorizontalExpansion()); +// try { +// Manager manager = Manager.getInstance(); +// manager.initLearningProblem(); +// manager.initLearningAlgorithm(); +// Manager.getInstance().startLearning(); +// } catch (Exception e) { +// e.printStackTrace(); +// } retriever = new SuggestionRetriever(); retriever.addPropertyChangeListener(view.getStatusBar()); @@ -181,30 +189,30 @@ manager.initLearningAlgorithm(); view.setBusyTaskEnded(); -// SwingUtilities.invokeLater(new Runnable() { -// @Override -// public void run() { -// view.setLearningStarted(); -// view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), -// Manager.getInstance().getMaximumHorizontalExpansion()); -// } -// }); -// -// timer = new Timer(); -// timer.schedule(new TimerTask(){ -// int progress = 0; -// List<? extends EvaluatedDescription> result; -// @Override -// public void run() { -// progress++; -// setProgress(progress); -// if(!isCancelled() && Manager.getInstance().isLearning()){ -// result = Manager.getInstance().getCurrentlyLearnedDescriptions(); -// publish(result); -// } -// } -// -// }, 1000, 500); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + view.setLearningStarted(); + view.showHorizontalExpansionMessage(Manager.getInstance().getMinimumHorizontalExpansion(), + Manager.getInstance().getMaximumHorizontalExpansion()); + } + }); + + timer = new Timer(); + timer.schedule(new TimerTask(){ + int progress = 0; + List<? extends EvaluatedDescription> result; + @Override + public void run() { + progress++; + setProgress(progress); + if(!isCancelled() && Manager.getInstance().isLearning()){ + result = Manager.getInstance().getCurrentlyLearnedDescriptions(); + publish(result); + } + } + + }, 1000, 500); Manager.getInstance().startLearning(); } catch (Exception e) { ErrorLogPanel.showErrorDialog(e); @@ -218,13 +226,13 @@ @Override public void done() { -// if(!isCancelled()){ -// timer.cancel(); -// List<? extends EvaluatedDescription> result = Manager.getInstance().getCurrentlyLearnedDescriptions(); -// updateList(result); -// setProgress(0); -// view.setLearningFinished(); -// } + if(!isCancelled()){ + timer.cancel(); + List<? extends EvaluatedDescription> result = Manager.getInstance().getCurrentlyLearnedDescriptions(); + updateList(result); + setProgress(0); + view.setLearningFinished(); + } ProtegeApplication.getBackgroundTaskManager().endTask(learningTask); } Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/META-INF/plugin.xml 2012-04-19 13:39:25 UTC (rev 3642) @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <plugin> <extension id="org.dllearner.tools.protege.ProtegePlugin" - point="org.protege.editor.owl.ui_editor_description"> + point="org.protege.editor.core.application.ViewComponent"> <label value="DL-Learner"/> <class value="org.dllearner.tools.protege.ProtegePlugin"/> <index value="E"/> Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/Manager.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -6,11 +6,8 @@ import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -18,6 +15,7 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.EvaluatedDescriptionClass; import org.dllearner.reasoning.ProtegeReasoner; +import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.owl.OWLAPIConverter; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.protege.editor.core.Disposable; @@ -37,14 +35,6 @@ public class Manager implements OWLModelManagerListener, OWLSelectionModelListener, Disposable{ - private final String[] components = { "org.dllearner.kb.OWLFile", - "org.dllearner.reasoning.OWLAPIReasoner", - "org.dllearner.reasoning.FastInstanceChecker", - "org.dllearner.reasoning.ProtegeReasoner", - "org.dllearner.reasoning.FastRetrievalReasoner", - "org.dllearner.algorithms.celoe.CELOE", - "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.ClassLearningProblem"}; - private static Manager instance; private OWLEditorKit editorKit; @@ -52,11 +42,10 @@ private boolean reinitNecessary = true; - private ComponentManager cm; - private AbstractLearningProblem lp; - private AbstractCELA la; + private ClassLearningProblem lp; + private CELOE la; private ProtegeReasoner reasoner; - private AbstractKnowledgeSource ks; + private KnowledgeSource ks; private LearningType learningType; private int maxExecutionTimeInSeconds; @@ -85,8 +74,6 @@ private Manager(OWLEditorKit editorKit){ this.editorKit = editorKit; - ComponentManager.setComponentClasses(components); - cm = ComponentManager.getInstance(); } public void setOWLEditorKit(OWLEditorKit editorKit){ @@ -110,20 +97,25 @@ public void initLearningAlgorithm() throws Exception { System.out.print("Initializing learning algorithm..."); long startTime = System.currentTimeMillis(); - la = cm.learningAlgorithm(CELOE.class, lp, reasoner); - cm.applyConfigEntry(la, "useAllConstructor", useAllConstructor); - cm.applyConfigEntry(la, "useExistsConstructor", useExistsConstructor); - cm.applyConfigEntry(la, "useHasValueConstructor", - useHasValueConstructor); - cm.applyConfigEntry(la, "useNegation", useNegation); - cm.applyConfigEntry(la, "useCardinalityRestrictions", - useCardinalityRestrictions); - if (useCardinalityRestrictions) { - cm.applyConfigEntry(la, "cardinalityLimit", cardinalityLimit); + la = new CELOE(lp, reasoner); + + RhoDRDown op = new RhoDRDown(); + op.setReasoner(reasoner); + op.setUseNegation(useNegation); + op.setUseHasValueConstructor(useAllConstructor); + op.setUseCardinalityRestrictions(useCardinalityRestrictions); + if(useCardinalityRestrictions){ + op.setCardinalityLimit(cardinalityLimit); } - cm.applyConfigEntry(la, "noisePercentage", noisePercentage); - cm.applyConfigEntry(la, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); + op.setUseExistsConstructor(useExistsConstructor); + op.setUseHasValueConstructor(useHasValueConstructor); + op.init(); + + la.setOperator(op); + + la.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + la.setNoisePercentage(noisePercentage); + la.setMaxNrOfResults(maxNrOfResults); la.init(); System.out.println("done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -133,16 +125,11 @@ public void initLearningProblem() throws Exception { System.out.print("Initializing learning problem..."); long startTime = System.currentTimeMillis(); - lp = cm.learningProblem(ClassLearningProblem.class, reasoner); - cm.applyConfigEntry(lp, "classToDescribe", editorKit.getOWLWorkspace() - .getOWLSelectionModel().getLastSelectedClass().getIRI().toURI() - .toURL()); - if (learningType == LearningType.EQUIVALENT) { - cm.applyConfigEntry(lp, "type", "equivalence"); - } else if (learningType == LearningType.SUPER) { - cm.applyConfigEntry(lp, "type", "superClass"); - } - cm.applyConfigEntry(lp, "checkConsistency", false); + lp = new ClassLearningProblem(reasoner); + lp.setClassToDescribe(new NamedClass(editorKit.getOWLWorkspace() + .getOWLSelectionModel().getLastSelectedClass().getIRI().toURI())); + lp.setEquivalence(learningType == LearningType.EQUIVALENT); + lp.setCheckConsistency(false); lp.init(); System.out.println("Done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -154,17 +141,16 @@ } public void initReasoner() throws Exception{ - System.out.print("Initializing reasoner..."); + System.out.print("Initializing DL-Learner internal reasoner..."); long startTime = System.currentTimeMillis(); - reasoner = cm.reasoner(ProtegeReasoner.class, ks); - reasoner.setOWLReasoner(editorKit.getOWLModelManager().getReasoner()); + reasoner = new ProtegeReasoner(Collections.singleton(ks), editorKit.getOWLModelManager().getReasoner()); reasoner.setProgressMonitor(progressMonitor); reasoner.init(); System.out.println("Done in " + (System.currentTimeMillis()-startTime) + "ms."); } public void initReasonerAsynchronously(){ - reasoner = cm.reasoner(ProtegeReasoner.class, ks); + reasoner = new ProtegeReasoner(Collections.singleton(ks), editorKit.getOWLModelManager().getReasoner()); reasoner.setOWLReasoner(editorKit.getOWLModelManager().getReasoner()); reasoner.setProgressMonitor(progressMonitor); @@ -372,7 +358,6 @@ @Override public void dispose() throws Exception { reasoner.releaseKB(); - cm.freeAllComponents(); editorKit.getOWLModelManager().removeListener(this); editorKit.getOWLWorkspace().getOWLSelectionModel().removeListener(this); Modified: trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java =================================================================== --- trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/java/org/dllearner/tools/protege/ProtegePlugin.java 2012-04-19 13:39:25 UTC (rev 3642) @@ -25,6 +25,10 @@ import javax.swing.JComponent; import org.protege.editor.core.ui.util.InputVerificationStatusChangedListener; +import org.protege.editor.owl.model.OWLModelManager; +import org.protege.editor.owl.model.event.EventType; +import org.protege.editor.owl.model.event.OWLModelManagerChangeEvent; +import org.protege.editor.owl.model.event.OWLModelManagerListener; import org.protege.editor.owl.model.inference.NoOpReasoner; import org.protege.editor.owl.ui.editor.AbstractOWLClassExpressionEditor; import org.semanticweb.owlapi.model.AxiomType; @@ -38,7 +42,7 @@ * @author Christian Koetteritzsch * */ -public class ProtegePlugin extends AbstractOWLClassExpressionEditor { +public class ProtegePlugin extends AbstractOWLClassExpressionEditor implements OWLModelManagerListener{ private static final long serialVersionUID = 728362819273927L; private DLLearnerView view; @@ -60,16 +64,22 @@ Manager.getInstance(getOWLEditorKit()).setLearningType(LearningType.SUPER); } view.reset(); + checkReasonerStatus(); + return true; + } + + private void checkReasonerStatus(){ OWLReasoner r = getOWLEditorKit().getModelManager().getReasoner(); if(r instanceof NoOpReasoner){ view.setHintMessage("<html><font size=\"3\" color=\"red\">You have to select a reasoner (click on menu \"Reasoner\"). We recommend to use Pellet. </font></html>"); view.setRunButtonEnabled(false); } else { + view.setHintMessage(""); + view.setRunButtonEnabled(true); if(!Manager.getInstance().isPreparing() && Manager.getInstance().isReinitNecessary()){ new ReadingOntologyThread(view).start(); } } - return true; } @Override @@ -105,6 +115,7 @@ } private void addListeners(){ + getOWLEditorKit().getOWLModelManager().addListener(this); getOWLEditorKit().getOWLModelManager().addListener(Manager.getInstance(getOWLEditorKit())); getOWLEditorKit().getOWLWorkspace().getOWLSelectionModel().addListener(Manager.getInstance(getOWLEditorKit())); } @@ -113,4 +124,11 @@ getOWLEditorKit().getOWLModelManager().removeListener(Manager.getInstance(getOWLEditorKit())); getOWLEditorKit().getOWLWorkspace().getOWLSelectionModel().removeListener(Manager.getInstance(getOWLEditorKit())); } + + @Override + public void handleChange(OWLModelManagerChangeEvent event) { + if(event.isType(EventType.REASONER_CHANGED) || event.isType(EventType.ACTIVE_ONTOLOGY_CHANGED)){ + checkReasonerStatus(); + } + } } Modified: trunk/protege/src/main/resources/META-INF/MANIFEST.MF =================================================================== --- trunk/protege/src/main/resources/META-INF/MANIFEST.MF 2012-04-18 14:01:32 UTC (rev 3641) +++ trunk/protege/src/main/resources/META-INF/MANIFEST.MF 2012-04-19 13:39:25 UTC (rev 3642) @@ -11,6 +11,9 @@ lib/junit-4.4.jar, lib/jamon-2.7.jar, lib/swingx-1.6.jar, + lib/json-20090211.jar, + lib/log4j-1.2.16.jar, + lib/jamon-2.0.jar, lib/jena/json.jar, lib/jena/commons-logging-1.1.1.jar, lib/components-core-1.0-SNAPSHOT.jar Modified: trunk/protege/src/main/resources/lib/components-core-1.0-SNAPSHOT.jar =================================================================== (Binary files differ) Added: trunk/protege/src/main/resources/lib/jamon-2.0.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/jamon-2.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/protege/src/main/resources/lib/json-20090211.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/json-20090211.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/protege/src/main/resources/lib/log4j-1.2.16.jar =================================================================== (Binary files differ) Property changes on: trunk/protege/src/main/resources/lib/log4j-1.2.16.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-04-20 02:59:20
|
Revision: 3646 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3646&view=rev Author: shadowtm Date: 2012-04-20 02:59:13 +0000 (Fri, 20 Apr 2012) Log Message: ----------- Removed references to repositories - we should put external dependencies in our archiva (either through upload or proxied repository). This way, we aren't dependent on third party repositories when we build - just our own. Modified Paths: -------------- trunk/components-core/pom.xml trunk/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-04-19 22:10:21 UTC (rev 3645) +++ trunk/components-core/pom.xml 2012-04-20 02:59:13 UTC (rev 3646) @@ -137,20 +137,15 @@ </dependency> <!-- Latest JENA ARQ - we have to exclude XercesImpl and use an older version here because use version bei JENA leads to some errors --> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-arq</artifactId> - <exclusions> - <exclusion> - <artifactId>xercesImpl</artifactId> - <groupId>xerces</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - <version>2.6.0</version> + <dependency> + <groupId>org.apache.jena</groupId> + <artifactId>jena-arq</artifactId> + <exclusions> + <exclusion> + <artifactId>xercesImpl</artifactId> + <groupId>xerces</groupId> + </exclusion> + </exclusions> </dependency> <!--JSON is in Central --> @@ -159,16 +154,7 @@ <artifactId>json</artifactId> </dependency> - <dependency> - <groupId>net.sf.jopt-simple</groupId> - <artifactId>jopt-simple</artifactId> - </dependency> - <dependency> - <groupId>org.ini4j</groupId> - <artifactId>ini4j</artifactId> - </dependency> - <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> @@ -208,11 +194,6 @@ </dependency> <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - </dependency> - - <dependency> <groupId>fuzzydll</groupId> <artifactId>fuzzydl</artifactId> <version>1.0</version> @@ -241,19 +222,10 @@ <artifactId>spring-beans</artifactId> </dependency> <dependency> - <groupId>org.aksw.commons</groupId> - <artifactId>collections</artifactId> - </dependency> - <dependency> - <groupId>net.didion.jwnl</groupId> - <artifactId>jwnl</artifactId> - <version>1.4.1.RC2</version> + <groupId>org.apache.lucene</groupId> + <artifactId>lucene-core</artifactId> </dependency> - <dependency> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-core</artifactId> - </dependency> - - - </dependencies> + + + </dependencies> </project> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-19 22:10:21 UTC (rev 3645) +++ trunk/pom.xml 2012-04-20 02:59:13 UTC (rev 3646) @@ -86,6 +86,26 @@ <artifactId>maven-license-plugin</artifactId> <version>1.9.0</version> </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>tomcat-maven-plugin</artifactId> + <version>1.0</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <version>2.5</version> + </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>maven-jetty-plugin</artifactId> + <version>6.1.26</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>2.4</version> + </plugin> </plugins> </pluginManagement> </build> @@ -109,6 +129,13 @@ <groupId>com.owldl</groupId> <artifactId>pellet</artifactId> <version>2.3.0</version> + <exclusions> + <!--Excluding this because it has the same classpath as the new Apache Jena and can cause problems--> + <exclusion> + <groupId>com.hp.hpl.jena</groupId> + <artifactId>jena</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> @@ -442,109 +469,31 @@ </dependency> <!--END Logging Dependencies--> + <!--It seems that later versions of this causes a lot of problems for some of the libraries we depend on--> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.6.0</version> + </dependency> + </dependencies> </dependencyManagement> <repositories> - - <repository> - <id>maven2-repository.dev.java.net</id> - <name>Java.net Repository for Maven</name> - <url>http://download.java.net/maven/2/</url> - <layout>default</layout> - </repository> - - <repository> <id>maven.aksw.internal</id> <name>University Leipzig, AKSW Maven2 Repository</name> <url>http://maven.aksw.org/archiva/repository/internal</url> + <releases/> </repository> - <repository> <id>maven.aksw.snapshots</id> <name>University Leipzig, AKSW Maven2 Repository</name> <url>http://maven.aksw.org/archiva/repository/snapshots</url> + <snapshots/> </repository> - - <!-- This repository contains the pellet jars --> - <repository> - <id>pellet_etc</id> - <url>http://on.cs.unibas.ch/maven/repository/</url> - </repository> - - <repository> - <id>GXT</id> - <url>http://maven.jahia.org/maven2/</url> - </repository> - - <!-- - This is so we can get the 1.3-SNAPSHOT of GWT Maven Plugin cause - 1.2 is broken on the hudson - - Here's a good place to browse the repository: - https://nexus.codehaus.org --> - <repository> - <id>maven.codehaus.snapshots</id> - <name>Codehaus repository Repository</name> - <url>https://nexus.codehaus.org/content/repositories/public</url> - </repository> - - <repository> - <id>google-maven-snapshot-repository</id> - <name>Google Maven Snapshot Repository</name> - <url>https://oss.sonatype.org/content/repositories/google-snapshots/</url> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - - <repository> - <id>apache-repo-releases</id> - <url>https://repository.apache.org/content/repositories/releases/</url> - <releases> - <enabled>true</enabled> - </releases> - </repository> - <repository> - <id>apache-repo-snapshots</id> - <url>https://repository.apache.org/content/repositories/snapshots/</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> </repositories> - <pluginRepositories> - <pluginRepository> - <id>maven.codehaus.plugin.snapshots</id> - <name>Codehaus plugin Repository</name> - <url>https://nexus.codehaus.org/content/repositories/public</url> - <snapshots> - <enabled>true</enabled> - </snapshots> - <releases> - <enabled>true</enabled> - </releases> - </pluginRepository> - <pluginRepository> - <id>evolvis-release-repository</id> - <name>evolvis.org release repository</name> - <url>http://maven-repo.evolvis.org/releases</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - </pluginRepository> - <pluginRepository> - <id>maven-latex-plugin-repo</id> - <url>http://akquinet.github.com/maven-latex-plugin/maven2/</url> - <releases> - <enabled>true</enabled> - </releases> - </pluginRepository> - </pluginRepositories> - - <distributionManagement> <repository> <id>archiva.internal</id> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2012-04-23 21:22:10
|
Revision: 3654 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3654&view=rev Author: kurzum Date: 2012-04-23 21:17:47 +0000 (Mon, 23 Apr 2012) Log Message: ----------- finished caching of ontologies for sparql component, changed log level for file to debug Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java trunk/interfaces/src/main/resources/log4j.properties Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-04-23 20:33:48 UTC (rev 3653) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-04-23 21:17:47 UTC (rev 3654) @@ -34,37 +34,28 @@ public synchronized void init() { for (String url : ontologySchemaUrls) { - if (!alreadyIndexed.add(url)) { + log.info("Testing, if indexed: " + url); + if (alreadyIndexed.add(url)) { + log.info("Ontology not found, start indexing"); try { Monitor m0 = MonitorFactory.start("Indexer parsing ontology"); model = ModelFactory.createOntologyModel(); model.read(url, null); classIndexer.index(model); m0.stop(); - log.debug("indexed " + url + " " + url); + log.info("indexed ontology in ms:" + m0.getTotal()); } catch (Exception e) { log.error(e.getMessage(), e); } + } else { + //not so important output + log.debug("Already indexed: " + url + " " + alreadyIndexed); } } } - - /*public void init() { - classIndexer = new ClassIndexer(); - model = ModelFactory.createOntologyModel(); - try { - Monitor m0 = MonitorFactory.start("Indexer parsing ontology"); - model.read(new FileInputStream(ontologySchema), null); - m0.stop(); - } catch (FileNotFoundException e) { - log.error(e.getMessage(), e); - } - classIndexer.index(model); - } */ - public OntModel getHierarchyForURI(String classUri) { if (classIndexer == null) { this.init(); Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-23 20:33:48 UTC (rev 3653) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-23 21:17:47 UTC (rev 3654) @@ -160,11 +160,10 @@ monIndexing.stop(); monComp.stop(); log.info("*******Simple SPARQL Extractor********"); - for (Monitor monitor : MonitorFactory.getRootMonitor().getMonitors()) { + /*for (Monitor monitor : MonitorFactory.getRootMonitor().getMonitors()) { log.info("* {} *", monitor); - log.info(JamonMonitorLogger.getStringForAllSortedByLabel()); - - } + }*/ + log.info(JamonMonitorLogger.getStringForAllSortedByLabel()); log.info("**************************************"); } Modified: trunk/interfaces/src/main/resources/log4j.properties =================================================================== --- trunk/interfaces/src/main/resources/log4j.properties 2012-04-23 20:33:48 UTC (rev 3653) +++ trunk/interfaces/src/main/resources/log4j.properties 2012-04-23 21:17:47 UTC (rev 3654) @@ -3,14 +3,15 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=log/interfaces.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern= %-4r [%t] %-5p %c %x - %m%n +log4j.appender.file.Threshold=DEBUG # DL-Learner Logs log4j.logger.org.dllearner=INFO - log4j.logger.org.dllearner.server.nke.LogicalRelationStrategy=DEBUG # Eliminate most of the Spring Context Loading noise This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2012-04-24 00:48:32
|
Revision: 3656 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3656&view=rev Author: kurzum Date: 2012-04-24 00:48:26 +0000 (Tue, 24 Apr 2012) Log Message: ----------- some fixes Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java trunk/examples/thanh/AristotlePosNeg.conf Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java 2012-04-23 22:19:40 UTC (rev 3655) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java 2012-04-24 00:48:26 UTC (rev 3656) @@ -15,103 +15,99 @@ * @author didierc */ public class ABoxQueryGenerator { - public String createQuery(List<String> individuals, OntModel model, List<String> filters) { + + public String createQuery(Set<String> individuals, String aboxfilter) { Monitor monABoxQueryGeneration = MonitorFactory.getTimeMonitor("ABox query generator").start(); StringBuilder builder = new StringBuilder(); - builder.append("CONSTRUCT {?s ?p ?o} "); - builder.append("{ ?s ?p ?o ."); - Set<String> curIndividuals; - if (model.isEmpty()) { - curIndividuals = new HashSet<String>(individuals); - } else { - curIndividuals = this.difference2(individuals, model); + builder.append("CONSTRUCT {?s ?p ?o } "); + builder.append("{ ?s ?p ?o . "); + builder.append(makeInFilter("?s", individuals)); + if (aboxfilter != null) { + builder.append(aboxfilter); } - builder.append(" FILTER (?s IN( "); - for (String individual : curIndividuals) { - builder.append("<"); - builder.append(individual); - builder.append(">"); - builder.append(", "); - } - builder.deleteCharAt(builder.length() - 2); - builder.append("))"); - if (filters != null) { - for (String filter : filters) { - builder.append("filter"); - } - } builder.append("}"); monABoxQueryGeneration.stop(); return builder.toString(); } - public String createLastQuery(List<String> individuals, OntModel model, List<String> filters) { - Monitor monABoxQueryGeneration = MonitorFactory.getTimeMonitor("ABox query generator") - .start(); + public static StringBuilder makeInFilter(String var, Set<String> uris) { StringBuilder builder = new StringBuilder(); - if (false) { - builder.append("CONSTRUCT {?s ?p ?o . ?o a ?class} "); - builder.append("{ ?s ?p ?o ."); - builder.append("?o a ?class"); - } else { - builder.append("CONSTRUCT {?s ?p ?o } "); - builder.append("{ ?s ?p ?o . "); - } - - Set<String> curIndividuals; - if (model.isEmpty()) { - curIndividuals = new HashSet<String>(individuals); - } else { - curIndividuals = this.difference2(individuals, model); - } - builder.append(" FILTER ( ?s IN( "); - for (String individual : curIndividuals) { + builder.append(" FILTER (" + var + " IN( "); + for (String uri : uris) { builder.append("<"); - builder.append(individual); + builder.append(uri); builder.append(">"); builder.append(", "); } builder.deleteCharAt(builder.length() - 2); - builder.append(")). "); - if (filters != null) { - for (String filter : filters) { - builder.append(filter); - builder.append(". "); - } - } - builder.append("}"); - monABoxQueryGeneration.stop(); - return builder.toString(); + builder.append(")) . "); + return builder; } - public Set<String> difference2 - (List<String> a, OntModel model) { - Set<String> inds = new HashSet<String>(a); - Set<String> result = new HashSet<String>(); - for (ExtendedIterator<Individual> it = model.listIndividuals(); it.hasNext(); ) { - String individual = it.next().getURI(); - if (!inds.contains(individual)) { - result.add(individual); - } - } - return result; + /** + * + * + * @param oldIndividuals + * @param model + * @return + */ + + + /*public String createLastQuery(List<String> individuals, OntModel model, List<String> filters) { + Monitor monABoxQueryGeneration = MonitorFactory.getTimeMonitor("ABox query generator") + .start(); + StringBuilder builder = new StringBuilder(); + if (false) { + builder.append("CONSTRUCT {?s ?p ?o . ?o a ?class} "); + builder.append("{ ?s ?p ?o ."); + builder.append("?o a ?class"); + } else { + builder.append("CONSTRUCT {?s ?p ?o } "); + builder.append("{ ?s ?p ?o . "); } - /*private List<String> getIndividualsFromModel - (OntModel - model) { - ExtendedIterator<Individual> iterator = model.listIndividuals(); - LinkedList<String> result = new LinkedList<String>(); - while (iterator.hasNext()) { - result.add(iterator.next().getURI()); + Set<String> curIndividuals; + if (model.isEmpty()) { + curIndividuals = new HashSet<String>(individuals); + } else { + curIndividuals = this.difference2(individuals, model); + } + builder.append(" FILTER ( ?s IN( "); + for (String individual : curIndividuals) { + builder.append("<"); + builder.append(individual); + builder.append(">"); + builder.append(", "); + } + builder.deleteCharAt(builder.length() - 2); + builder.append(")). "); + if (filters != null) { + for (String filter : filters) { + builder.append(filter); + builder.append(". "); } - return result; } + builder.append("}"); + monABoxQueryGeneration.stop(); + return builder.toString(); +} */ - public List<String> difference - (List<String> a, List<String> b) { - ArrayList<String> result = new ArrayList<String>(b); - result.removeAll(a); - return result; - } */ + + /*private List<String> getIndividualsFromModel + (OntModel + model) { + ExtendedIterator<Individual> iterator = model.listIndividuals(); + LinkedList<String> result = new LinkedList<String>(); + while (iterator.hasNext()) { + result.add(iterator.next().getURI()); + } + return result; + } + + public List<String> difference + (List<String> a, List<String> b) { + ArrayList<String> result = new ArrayList<String>(b); + result.removeAll(a); + return result; + } */ } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java 2012-04-23 22:19:40 UTC (rev 3655) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java 2012-04-24 00:48:26 UTC (rev 3656) @@ -3,16 +3,13 @@ */ package org.dllearner.kb.sparql.simple; +import com.hp.hpl.jena.query.*; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryExecutionFactory; -import com.hp.hpl.jena.query.QueryFactory; /** * @author didierc @@ -21,23 +18,26 @@ private static Logger log = LoggerFactory.getLogger(QueryExecutor.class); - public OntModel executeQuery(String queryString, String endpoint, OntModel model) { - Monitor monQueryingTotal = MonitorFactory.start("Query time total").start(); - Query query = QueryFactory.create(queryString); - log.debug("Jena Query: ", query); - QueryExecution qExec = QueryExecutionFactory.sparqlService(endpoint, query); - qExec.execConstruct(model); - monQueryingTotal.stop(); - return model; - } + public OntModel executeQuery(String queryString, String endpoint, OntModel model, String defaultGraphURI) { Monitor monQueryingTotal = MonitorFactory.start("Query time total").start(); + try{ Query query = QueryFactory.create(queryString); log.debug("Jena Query: ", query); - QueryExecution qExec = QueryExecutionFactory.sparqlService(endpoint, query, defaultGraphURI); + QueryExecution qExec; + if (defaultGraphURI == null) { + qExec = QueryExecutionFactory.sparqlService(endpoint, query); + + } else { + qExec = QueryExecutionFactory.sparqlService(endpoint, query, defaultGraphURI); + + } log.debug("Qexec: {}", qExec); qExec.execConstruct(model); + }catch (QueryParseException e ){ + log.warn("Query failed (skipping):\n" + queryString, e); + } monQueryingTotal.stop(); return model; } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-23 22:19:40 UTC (rev 3655) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-24 00:48:26 UTC (rev 3656) @@ -1,27 +1,21 @@ package org.dllearner.kb.sparql.simple; -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.query.QueryParseException; +import com.hp.hpl.jena.rdf.model.*; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.config.ConfigOption; import org.dllearner.utilities.JamonMonitorLogger; -import org.dllearner.utilities.experiments.Jamon; import org.semanticweb.owlapi.model.OWLOntology; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.hp.hpl.jena.ontology.OntClass; -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import com.jamonapi.Monitor; -import com.jamonapi.MonitorFactory; +import java.util.*; @ComponentAnn(name = "efficient SPARQL fragment extractor", shortName = "sparqls", version = 0.1) public class SparqlSimpleExtractor implements KnowledgeSource { @@ -31,9 +25,8 @@ private OntModel model = null; @ConfigOption(name = "instances", description = "List of the instances to use", required = true) private List<String> instances = null; - @ConfigOption(name = "filters", description = "List of the filters to use", required = true) - private List<String> filters = null; - + @ConfigOption(name = "aboxfilter", description = "Filter for the tbox, can use variable ?s, ?p amd ?o", required = false) + private String aboxfilter = null; @ConfigOption(name = "tboxfilter", description = "Filter for the tbox, can use variable ?example and ?class", required = false) private String tboxfilter = null; @@ -83,8 +76,33 @@ // System.out.println(extractor.createQuery()); } + public Set<String> difference(Set<String> alreadyQueriedIndividuals, OntModel model) { + Set<String> candidates = new HashSet<String>(); + Set<String> result = new HashSet<String>(); + for (ResIterator it = model.listSubjects(); it.hasNext(); ) { + candidates.add(it.next().getURI()); + } + for (NodeIterator it = model.listObjects(); it.hasNext(); ) { + RDFNode cur = it.next(); + if (cur.isURIResource() && !cur.isAnon()) { + candidates.add(((Resource) cur).getURI()); + } + } + + for (String candidate : candidates) { + if (!alreadyQueriedIndividuals.contains(candidate)) { + System.out.println(candidate); + result.add(candidate); + } + } + + return result; + } + + @Override public void init() throws ComponentInitException { + if (endpointURL == null) { throw new ComponentInitException( "Parameter endpoint URL is required"); @@ -111,32 +129,43 @@ Monitor monQueryingABox; QueryExecutor executor = new QueryExecutor(); String queryString; + Set<String> instancesSet = new HashSet<String>(instances); + Set<String> alreadyQueried = new HashSet<String>(); if (sparqlQuery == null) { ABoxQueryGenerator aGenerator = new ABoxQueryGenerator(); - for (int i = 0; i < recursionDepth - 1; i++) { + for (int i = 0; i < recursionDepth; i++) { + if (instancesSet.isEmpty()) { + log.warn("no new instances found more recursions (recursion " + i + ") " + instancesSet.size() + " new instances"); - queryString = aGenerator.createQuery(instances, model, filters); + } + + log.info("processing (recursion " + i + ") " + instancesSet.size() + " new instances"); + queryString = aGenerator.createQuery(instancesSet, aboxfilter); log.debug("SPARQL: {}", queryString); monQueryingABox = MonitorFactory.start("ABox query time"); - executor.executeQuery(queryString, endpointURL, model, - defaultGraphURI); + executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); monQueryingABox.stop(); + + alreadyQueried.addAll(instancesSet); + instancesSet = difference(alreadyQueried, model); + + } - queryString = aGenerator.createLastQuery(instances, model, filters); - log.debug("SPARQL: {}", queryString); + //queryString = aGenerator.createLastQuery(instances, model, filters); + //log.debug("SPARQL: {}", queryString); - monQueryingABox = MonitorFactory.start("ABox query time"); - Monitor monQueryingABox2 = MonitorFactory.start("ABox query time last query"); - executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); - monQueryingABox.stop(); - monQueryingABox2.stop(); + //monQueryingABox = MonitorFactory.start("ABox query time"); + //Monitor monQueryingABox2 = MonitorFactory.start("ABox query time last query"); + //executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); + //monQueryingABox.stop(); + //monQueryingABox2.stop(); } else { monQueryingABox = MonitorFactory.getTimeMonitor("ABox query time").start(); - executor.executeQuery(sparqlQuery, endpointURL, model); + executor.executeQuery(sparqlQuery, endpointURL, model, null); monQueryingABox.stop(); } @@ -144,7 +173,7 @@ TBoxQueryGenerator tGenerator = new TBoxQueryGenerator(); //TODO check if all instances are queried. model.listIndividuals().toSet() - queryString = tGenerator.createQuery(model, tboxfilter, instances); + queryString = tGenerator.createQuery(alreadyQueried, tboxfilter); Monitor monQueryingTBox = MonitorFactory.start("TBox query time"); @@ -196,18 +225,12 @@ this.model = model; } - /** - * @return the filters - */ - public List<String> getFilters() { - return filters; + public String getAboxfilter() { + return aboxfilter; } - /** - * @param filters the filters to set - */ - public void setFilters(List<String> filters) { - this.filters = filters; + public void setAboxfilter(String aboxfilter) { + this.aboxfilter = aboxfilter; } /** Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java 2012-04-23 22:19:40 UTC (rev 3655) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java 2012-04-24 00:48:26 UTC (rev 3656) @@ -4,7 +4,9 @@ package org.dllearner.kb.sparql.simple; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.ModelFactory; @@ -15,8 +17,7 @@ * @author didierc */ public class TBoxQueryGenerator { - public String createQuery(OntModel model, String filter, - List<String> individuals) { + public String createQuery(Set<String> individuals, String filter) { Monitor monTquery = MonitorFactory.getTimeMonitor("TBox query generator") .start(); StringBuilder builder = new StringBuilder( @@ -42,7 +43,7 @@ public static void main(String... args) { TBoxQueryGenerator generator = new TBoxQueryGenerator(); OntModel model = ModelFactory.createOntologyModel(); - List<String> individuals = new ArrayList<String>(); + Set<String> individuals = new HashSet<String>(); individuals.add("http://dbpedia.org/resource/JB_Carlson"); @@ -1046,10 +1047,10 @@ individuals.add("http://dbpedia.org/resource/Percy_Jackson"); individuals.add("http://dbpedia.org/resource/Glynis_Barber"); - String queryString = generator.createQuery(model, null, individuals); + String queryString = generator.createQuery(individuals, null); System.out.println(queryString); QueryExecutor executor = new QueryExecutor(); - executor.executeQuery(queryString, "http://live.dbpedia.org/sparql", model); + executor.executeQuery(queryString, "http://live.dbpedia.org/sparql", model, null); model.write(System.out); } } Modified: trunk/examples/thanh/AristotlePosNeg.conf =================================================================== --- trunk/examples/thanh/AristotlePosNeg.conf 2012-04-23 22:19:40 UTC (rev 3655) +++ trunk/examples/thanh/AristotlePosNeg.conf 2012-04-24 00:48:26 UTC (rev 3656) @@ -13,10 +13,13 @@ sparql.type = "sparqls" sparql.endpointURL = "http://live.dbpedia.org/sparql" sparql.defaultGraphURI = "http://dbpedia.org" -sparql.recursionDepth = 1 +sparql.recursionDepth = 2 sparql.ontologySchemaUrls = {"http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl" } +sparql.aboxfilter = "FILTER ( !isLiteral(?o) ) " +// && regex(str(?o), '^http://dbpedia.org/resource/') && ! regex(str(?o), '^http://dbpedia.org/resource/Category') && ! regex(str(?o), '^http://dbpedia.org/resource/Template') ) . " +//|| regex(str(?p), '^http://dbpedia.org/property/') )) " sparql.tboxfilter = "FILTER ( regex(str(?class), '^http://dbpedia.org/ontology/') ) . " -//sparql.tboxfilter = "FILTER ( regex(str(?class), LIKE <http://dbpedia.org/ontology/%> ) . " +//sparql.tboxfilter = "FILTER ( ?class LIKE <http://dbpedia.org/ontology/%> ) . " sparql.instances = { "http://dbpedia.org/resource/Democritus", @@ -39,6 +42,7 @@ "http://dbpedia.org/resource/Pythagoras", "http://dbpedia.org/resource/Philolaus" } + lp.negativeExamples = { "http://dbpedia.org/resource/Democritus", "http://dbpedia.org/resource/Zeno_of_Elea", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2012-04-29 12:31:28
|
Revision: 3664 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3664&view=rev Author: kurzum Date: 2012-04-29 12:31:22 +0000 (Sun, 29 Apr 2012) Log Message: ----------- error log improvements Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java trunk/interfaces/src/main/java/org/dllearner/server/Rest.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-28 17:27:17 UTC (rev 3663) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-29 12:31:22 UTC (rev 3664) @@ -6,6 +6,7 @@ import java.util.List; import java.util.Set; +import com.hp.hpl.jena.ontology.OntModelSpec; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; @@ -57,7 +58,7 @@ private static Logger log = LoggerFactory.getLogger(SparqlSimpleExtractor.class); public SparqlSimpleExtractor() { - model = ModelFactory.createOntologyModel(); + model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); } /** Modified: trunk/interfaces/src/main/java/org/dllearner/server/Rest.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/server/Rest.java 2012-04-28 17:27:17 UTC (rev 3663) +++ trunk/interfaces/src/main/java/org/dllearner/server/Rest.java 2012-04-29 12:31:22 UTC (rev 3664) @@ -1,39 +1,31 @@ package org.dllearner.server; -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.apache.commons.lang.exception.ExceptionUtils; import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; import org.dllearner.confparser3.ConfParserConfiguration; import org.dllearner.core.ClassExpressionLearningAlgorithm; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.kb.sparql.SparqlQueryDescriptionConvertVisitor; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; import org.json.simple.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + public class Rest extends HttpServlet { private static Logger log = LoggerFactory.getLogger(Rest.class); @@ -66,8 +58,8 @@ throw new IllegalArgumentException("Missing parameter: conf is required. "); } else { conf = httpServletRequest.getParameter("conf"); - if(isSet("limit" , httpServletRequest)){ - limit = Integer.parseInt(httpServletRequest.getParameter("limit")) ; + if (isSet("limit", httpServletRequest)) { + limit = Integer.parseInt(httpServletRequest.getParameter("limit")); } } @@ -108,17 +100,17 @@ } catch (IllegalArgumentException e) { String msg = e.getMessage();// + printParameterMap(httpServletRequest); - log.error(msg); + log.error("", ExceptionUtils.getRootCause(e)); learningResult.put("success", "0"); learningResult.put("error", msg); - learningResult.put("stacktrace", ExceptionUtils.getFullStackTrace(e)); + learningResult.put("stacktrace", ExceptionUtils.getRootCause(e)); } catch (Exception e) { String msg = "An error occured: " + e.getMessage(); //+ printParameterMap(httpServletRequest); - log.error(msg, e); + log.error("", ExceptionUtils.getRootCause(e)); learningResult.put("success", "0"); learningResult.put("error", msg); - learningResult.put("stacktrace", ExceptionUtils.getFullStackTrace(e)); + learningResult.put("stacktrace", ExceptionUtils.getRootCause(e)); } result.put("learningresult", learningResult); @@ -136,26 +128,20 @@ * @param conf the content of a conf file * @return */ - public EvaluatedDescriptionPosNeg learn(String conf) { - try { - Resource confFile = new InputStreamResource(new ByteArrayInputStream(conf.getBytes())); - - IConfiguration configuration = new ConfParserConfiguration(confFile); + public EvaluatedDescriptionPosNeg learn(String conf) throws Exception { + Resource confFile = new InputStreamResource(new ByteArrayInputStream(conf.getBytes())); - ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); - ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); - - LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); - algorithm.start(); - if(algorithm instanceof ClassExpressionLearningAlgorithm){ - return (EvaluatedDescriptionPosNeg)((ClassExpressionLearningAlgorithm) algorithm).getCurrentlyBestEvaluatedDescriptions(1).iterator().next(); - } - } catch (BeansException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; + IConfiguration configuration = new ConfParserConfiguration(confFile); + + ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); + ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); + + LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); + algorithm.start(); + if (algorithm instanceof ClassExpressionLearningAlgorithm) { + return (EvaluatedDescriptionPosNeg) ((ClassExpressionLearningAlgorithm) algorithm).getCurrentlyBestEvaluatedDescriptions(1).iterator().next(); + } + throw new Exception("only ClassExpressionLearningAlgorithm implemented currently"); } @@ -174,26 +160,29 @@ } return ret; } - - public static void main(String[] args) throws Exception{ - String filePath = "../examples/father.conf"; - byte[] buffer = new byte[(int) new File(filePath).length()]; + + public static void main(String[] args) throws Exception { + String filePath = "../examples/father.conf"; + byte[] buffer = new byte[(int) new File(filePath).length()]; BufferedInputStream f = null; try { f = new BufferedInputStream(new FileInputStream(filePath)); f.read(buffer); } finally { - if (f != null) try { f.close(); } catch (IOException ignored) { } + if (f != null) try { + f.close(); + } catch (IOException ignored) { + } } String confString = new String(buffer); - + Resource confFile = new InputStreamResource(new ByteArrayInputStream(confString.getBytes())); - + IConfiguration configuration = new ConfParserConfiguration(confFile); ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); - ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); - + ApplicationContext context = builder.buildApplicationContext(configuration, new ArrayList<Resource>()); + LearningAlgorithm algorithm = context.getBean(LearningAlgorithm.class); algorithm.start(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-04-29 16:25:20
|
Revision: 3666 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3666&view=rev Author: shadowtm Date: 2012-04-29 16:25:14 +0000 (Sun, 29 Apr 2012) Log Message: ----------- Improved the way we were handling/outputting error messages to the console for the CLI interface. Modified Paths: -------------- trunk/components-core/pom.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java trunk/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/components-core/pom.xml 2012-04-29 16:25:14 UTC (rev 3666) @@ -225,6 +225,10 @@ <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> </dependencies> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -27,24 +27,16 @@ import java.util.List; import java.util.Map.Entry; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Layout; -import org.apache.log4j.Level; +import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; import org.apache.xmlbeans.XmlObject; -import org.dllearner.Info; import org.dllearner.configuration.IConfiguration; import org.dllearner.configuration.spring.ApplicationContextBuilder; import org.dllearner.configuration.spring.DefaultApplicationContextBuilder; import org.dllearner.configuration.util.SpringConfigurationXMLBeanConverter; import org.dllearner.confparser3.ConfParserConfiguration; import org.dllearner.confparser3.ParseException; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.LearningAlgorithm; -import org.dllearner.core.ReasoningMethodUnsupportedException; +import org.dllearner.core.*; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.utilities.Files; import org.springframework.context.ApplicationContext; @@ -170,10 +162,10 @@ List<Resource> springConfigResources = new ArrayList<Resource>(); - //DL-Learner Configuration Object - IConfiguration configuration = new ConfParserConfiguration(confFile); + try { + //DL-Learner Configuration Object + IConfiguration configuration = new ConfParserConfiguration(confFile); - try { ApplicationContextBuilder builder = new DefaultApplicationContextBuilder(); ApplicationContext context = builder.buildApplicationContext(configuration,springConfigResources); @@ -191,7 +183,15 @@ cli.run(); } catch (Exception e) { String stacktraceFileName = "log/error.log"; - logger.error("An Error Occurred During Processing. Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); + + //Find the primary cause of the exception. + Throwable primaryCause = findPrimaryCause(e); + + // Get the Root Error Message + logger.error("An Error Has Occurred During Processing."); + logger.error(primaryCause.getMessage()); + + logger.error("Terminating DL-Learner...and writing stacktrace to: " + stacktraceFileName); FileOutputStream fos = new FileOutputStream(stacktraceFileName); PrintStream ps = new PrintStream(fos); e.printStackTrace(ps); @@ -199,7 +199,30 @@ } - public void setContext(ApplicationContext context) { + /** + * Find the primary cause of the specified exception. + * + * @param e The exception to analyze + * @return The primary cause of the exception. + */ + private static Throwable findPrimaryCause(Exception e) { + // The throwables from the stack of the exception + Throwable[] throwables = ExceptionUtils.getThrowables(e); + + //Look For a Component Init Exception and use that as the primary cause of failure, if we find it + int componentInitExceptionIndex = ExceptionUtils.indexOfThrowable(e, ComponentInitException.class); + + Throwable primaryCause; + if(componentInitExceptionIndex > -1) { + primaryCause = throwables[componentInitExceptionIndex]; + }else { + //No Component Init Exception on the Stack Trace, so we'll use the root as the primary cause. + primaryCause = ExceptionUtils.getRootCause(e); + } + return primaryCause; + } + + public void setContext(ApplicationContext context) { this.context = context; } Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/ConfigurationBasedBeanDefinitionRegistryPostProcessor.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -14,7 +14,6 @@ import org.springframework.beans.factory.support.ManagedSet; import java.util.Collection; -import java.util.StringTokenizer; /** * Created by IntelliJ IDEA. Modified: trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/interfaces/src/main/java/org/dllearner/configuration/spring/DefaultApplicationContextBuilder.java 2012-04-29 16:25:14 UTC (rev 3666) @@ -59,7 +59,6 @@ try { context.refresh(); } catch (BeanCreationException e) { - logger.error("There was a problem creating the bean named \"" + e.getBeanName() + "\" - Check your configuration file and try again."); throw new RuntimeException(e); } catch (Exception e) { logger.error("There was a problem initializing the components...shutting down."); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-29 15:58:36 UTC (rev 3665) +++ trunk/pom.xml 2012-04-29 16:25:14 UTC (rev 3666) @@ -478,7 +478,13 @@ <version>2.6.0</version> </dependency> - </dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> + + </dependencies> </dependencyManagement> <repositories> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-08 11:53:40
|
Revision: 3697 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3697&view=rev Author: lorenz_b Date: 2012-05-08 11:53:28 +0000 (Tue, 08 May 2012) Log Message: ----------- Added REGEX filter option. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DataPropertyDomainAxiomLearner.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -28,6 +29,9 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.SimpleLayout; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.EvaluatedAxiom; @@ -42,9 +46,11 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; +import org.semanticweb.owlapi.model.IRI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -56,8 +62,14 @@ @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=DataPropertyEditor.class) private DatatypeProperty propertyToDescribe; + private static final ParameterizedSparqlString singleQueryTemplate = new ParameterizedSparqlString("SELECT ?type (COUNT(DISTINCT ?ind) AS ?cnt) WHERE {?ind <%s> ?o. ?ind a ?type.}"); + + private Map<Individual, SortedSet<Description>> individual2Types; + public DataPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + super.iterativeQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?ind ?type WHERE {?ind ?p ?o. ?ind a ?type.}"); + } public DatatypeProperty getPropertyToDescribe() { @@ -70,6 +82,7 @@ @Override public void start() { + iterativeQueryTemplate.setIri("p", propertyToDescribe.getName()); logger.info("Start learning..."); startTime = System.currentTimeMillis(); fetchedRows = 0; @@ -92,20 +105,49 @@ } } - //get subjects with types - Map<Individual, SortedSet<Description>> individual2Types = new HashMap<Individual, SortedSet<Description>>(); - boolean repeat = true; - int limit = 1000; - while(!terminationCriteriaSatisfied() && repeat){ - int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); - currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); - fetchedRows += 1000; - repeat = (ret == limit); - } + runIterativeQueryMode(); logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + + private void runSingleQueryMode(){ + + } + + private void runIterativeQueryMode(){ + individual2Types = new HashMap<Individual, SortedSet<Description>>(); + while(!terminationCriteriaSatisfied() && !fullDataLoaded){ + ResultSet rs = fetchData(); + processData(rs); + buildEvaluatedAxioms(); + } + } + + private void processData(ResultSet rs){ + QuerySolution qs; + Individual ind; + Description type; + SortedSet<Description> types; + int cnt = 0; + while(rs.hasNext()){ + cnt++; + qs = rs.next(); + if(qs.get("type").isURIResource()){ + types = new TreeSet<Description>(); + ind = new Individual(qs.getResource("ind").getURI()); + type = new NamedClass(qs.getResource("type").getURI()); + types.add(type); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(type)){ + types.addAll(reasoner.getClassHierarchy().getSuperClasses(type)); + } + } + addToMap(individual2Types, ind, types); + } + } + lastRowCount = cnt; + } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ + private void buildEvaluatedAxioms(){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Description, Integer> result = new HashMap<Description, Integer>(); for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ @@ -134,46 +176,14 @@ axioms.add(evalAxiom); } - return axioms; + currentlyBestAxioms = axioms; } - private int addIndividualsWithTypes(Map<Individual, SortedSet<Description>> ind2Types, int limit, int offset){ - String query = String.format("PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type. ?type a owl:Class} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + public static void main(String[] args) throws Exception{ + org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); + org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); + org.apache.log4j.Logger.getLogger(DataPropertyDomainAxiomLearner.class).setLevel(Level.INFO); -// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); - - ResultSet rs = executeSelectQuery(query); - Individual ind; - Description newType; - QuerySolution qs; - SortedSet<Description> types; - int cnt = 0; - while(rs.hasNext()){ - cnt++; - qs = rs.next(); - if(qs.get("type").isURIResource()){ - ind = new Individual(qs.getResource("ind").getURI()); - newType = new NamedClass(qs.getResource("type").getURI()); - types = ind2Types.get(ind); - if(types == null){ - types = new TreeSet<Description>(); - ind2Types.put(ind, types); - } - types.add(newType); - Set<Description> superClasses; - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(newType)){ - superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); - types.addAll(superClasses); - } - - } - } - } - return cnt; - } - - public static void main(String[] args) throws Exception{ SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); SPARQLReasoner reasoner = new SPARQLReasoner(ks); @@ -181,9 +191,10 @@ DataPropertyDomainAxiomLearner l = new DataPropertyDomainAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); l.setReasoner(reasoner); - l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/birthDate")); + l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/AutomobileEngine/height")); l.setMaxExecutionTimeInSeconds(10); - l.setReturnOnlyNewAxioms(true); + l.addFilterNamespace("http://dbpedia.org/ontology/"); +// l.setReturnOnlyNewAxioms(true); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(5)); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointDataPropertyAxiomLearner.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -255,8 +255,8 @@ public static void main(String[] args) throws Exception{ DisjointDataPropertyAxiomLearner l = new DisjointDataPropertyAxiomLearner(new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/position")); - l.setMaxExecutionTimeInSeconds(20); + l.setPropertyToDescribe(new DatatypeProperty("http://dbpedia.org/ontology/accessDate")); + l.setMaxExecutionTimeInSeconds(10); l.init(); l.getReasoner().precomputeDataPropertyPopularity(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -19,7 +19,6 @@ package org.dllearner.algorithms.properties; -import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,11 +28,15 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.SimpleLayout; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.config.ObjectPropertyEditor; +import org.dllearner.core.owl.DatatypePropertyDomainAxiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; @@ -41,11 +44,13 @@ import org.dllearner.core.owl.ObjectPropertyDomainAxiom; import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.reasoning.SPARQLReasoner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.query.ParameterizedSparqlString; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -54,11 +59,15 @@ private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyDomainAxiomLearner.class); + private Map<Individual, SortedSet<Description>> individual2Types; + + @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; public ObjectPropertyDomainAxiomLearner(SparqlEndpointKS ks){ this.ks = ks; + super.iterativeQueryTemplate = new ParameterizedSparqlString("SELECT DISTINCT ?ind ?type WHERE {?ind ?p ?o. ?ind a ?type.}"); } public ObjectProperty getPropertyToDescribe() { @@ -71,12 +80,13 @@ @Override public void start() { + iterativeQueryTemplate.setIri("p", propertyToDescribe.getName()); logger.info("Start learning..."); startTime = System.currentTimeMillis(); fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - if(reasoner.isPrepared()){ + if(returnOnlyNewAxioms){ //get existing domains Description existingDomain = reasoner.getDomain(propertyToDescribe); if(existingDomain != null){ @@ -93,20 +103,49 @@ } } - //get subjects with types - Map<Individual, SortedSet<Description>> individual2Types = new HashMap<Individual, SortedSet<Description>>(); - boolean repeat = true; - int limit = 1000; - while(!terminationCriteriaSatisfied() && repeat){ - int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); - currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); - fetchedRows += 1000; - repeat = (ret == limit); - } + runIterativeQueryMode(); logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } + + private void runSingleQueryMode(){ + + } + + private void runIterativeQueryMode(){ + individual2Types = new HashMap<Individual, SortedSet<Description>>(); + while(!terminationCriteriaSatisfied() && !fullDataLoaded){ + ResultSet rs = fetchData(); + processData(rs); + buildEvaluatedAxioms(); + } + } + + private void processData(ResultSet rs){ + QuerySolution qs; + Individual ind; + Description type; + SortedSet<Description> types; + int cnt = 0; + while(rs.hasNext()){ + cnt++; + qs = rs.next(); + if(qs.get("type").isURIResource()){ + types = new TreeSet<Description>(); + ind = new Individual(qs.getResource("ind").getURI()); + type = new NamedClass(qs.getResource("type").getURI()); + types.add(type); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(type)){ + types.addAll(reasoner.getClassHierarchy().getSuperClasses(type)); + } + } + addToMap(individual2Types, ind, types); + } + } + lastRowCount = cnt; + } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ + private void buildEvaluatedAxioms(){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Description, Integer> result = new HashMap<Description, Integer>(); for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ @@ -135,57 +174,25 @@ axioms.add(evalAxiom); } - return axioms; + currentlyBestAxioms = axioms; } - private int addIndividualsWithTypes(Map<Individual, SortedSet<Description>> ind2Types, int limit, int offset){ - String query = String.format("PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?ind ?type WHERE {?ind <%s> ?o. ?ind a ?type. ?type a owl:Class} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); + public static void main(String[] args) throws Exception{ + org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); + org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO); + org.apache.log4j.Logger.getLogger(DataPropertyDomainAxiomLearner.class).setLevel(Level.INFO); -// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); - ResultSet rs = executeSelectQuery(query); - Individual ind; - Description newType; - QuerySolution qs; - SortedSet<Description> types; - int cnt = 0; - while(rs.hasNext()){ - cnt++; - qs = rs.next(); - if(qs.get("type").isURIResource()){ - ind = new Individual(qs.getResource("ind").getURI()); - newType = new NamedClass(qs.getResource("type").getURI()); - types = ind2Types.get(ind); - if(types == null){ - types = new TreeSet<Description>(); - ind2Types.put(ind, types); - } - types.add(newType); - Set<Description> superClasses; - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(newType)){ - superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); - types.addAll(superClasses); - } - - } - } - - } - return cnt; - } - - public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); - SPARQLReasoner reasoner = new SPARQLReasoner(ks); reasoner.prepareSubsumptionHierarchy(); ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); l.setReasoner(reasoner); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/Automobile/fuelCapacity")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/currency")); l.setMaxExecutionTimeInSeconds(10); + l.addFilterNamespace("http://dbpedia.org/ontology/"); // l.setReturnOnlyNewAxioms(true); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyRangeAxiomLearner.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -52,6 +51,7 @@ public class ObjectPropertyRangeAxiomLearner extends AbstractAxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ObjectPropertyRangeAxiomLearner.class); + private Map<Individual, SortedSet<Description>> individual2Types; @ConfigOption(name="propertyToDescribe", description="", propertyEditorClass=ObjectPropertyEditor.class) private ObjectProperty propertyToDescribe; @@ -70,12 +70,13 @@ @Override public void start() { + iterativeQueryTemplate.setIri("p", propertyToDescribe.getName()); logger.info("Start learning..."); startTime = System.currentTimeMillis(); fetchedRows = 0; currentlyBestAxioms = new ArrayList<EvaluatedAxiom>(); - if(reasoner.isPrepared()){ + if(returnOnlyNewAxioms){ //get existing ranges Description existingRange = reasoner.getRange(propertyToDescribe); if(existingRange != null){ @@ -92,20 +93,49 @@ } } - //get objects with types - Map<Individual, SortedSet<Description>> individual2Types = new HashMap<Individual, SortedSet<Description>>(); - boolean repeat = true; - int limit = 1000; - while(!terminationCriteriaSatisfied() && repeat){ - int ret = addIndividualsWithTypes(individual2Types, limit, fetchedRows); - currentlyBestAxioms = buildEvaluatedAxioms(individual2Types); - fetchedRows += 1000; - repeat = (ret == limit); - } + runIterativeQueryMode(); logger.info("...finished in {}ms.", (System.currentTimeMillis()-startTime)); } - private List<EvaluatedAxiom> buildEvaluatedAxioms(Map<Individual, SortedSet<Description>> individual2Types){ + private void runSingleQueryMode(){ + + } + + private void runIterativeQueryMode(){ + individual2Types = new HashMap<Individual, SortedSet<Description>>(); + while(!terminationCriteriaSatisfied() && !fullDataLoaded){ + ResultSet rs = fetchData(); + processData(rs); + buildEvaluatedAxioms(); + } + } + + private void processData(ResultSet rs){ + QuerySolution qs; + Individual ind; + Description type; + SortedSet<Description> types; + int cnt = 0; + while(rs.hasNext()){ + cnt++; + qs = rs.next(); + if(qs.get("type").isURIResource()){ + types = new TreeSet<Description>(); + ind = new Individual(qs.getResource("ind").getURI()); + type = new NamedClass(qs.getResource("type").getURI()); + types.add(type); + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(type)){ + types.addAll(reasoner.getClassHierarchy().getSuperClasses(type)); + } + } + addToMap(individual2Types, ind, types); + } + } + lastRowCount = cnt; + } + + private void buildEvaluatedAxioms(){ List<EvaluatedAxiom> axioms = new ArrayList<EvaluatedAxiom>(); Map<Description, Integer> result = new HashMap<Description, Integer>(); for(Entry<Individual, SortedSet<Description>> entry : individual2Types.entrySet()){ @@ -134,52 +164,18 @@ axioms.add(evalAxiom); } - return axioms; + currentlyBestAxioms = axioms; } - private int addIndividualsWithTypes(Map<Individual, SortedSet<Description>> ind2Types, int limit, int offset){ - String query = String.format("PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT DISTINCT ?ind ?type WHERE {?s <%s> ?ind. ?ind a ?type. ?type a owl:Class} LIMIT %d OFFSET %d", propertyToDescribe.getName(), limit, offset); - -// String query = String.format("SELECT DISTINCT ?ind ?type WHERE {?ind a ?type. {SELECT ?ind {?ind <%s> ?o.} LIMIT %d OFFSET %d}}", propertyToDescribe.getName(), limit, offset); - - ResultSet rs = executeSelectQuery(query); - Individual ind; - Description newType; - QuerySolution qs; - SortedSet<Description> types; - int cnt = 0; - while(rs.hasNext()){ - cnt++; - qs = rs.next(); - ind = new Individual(qs.getResource("ind").getURI()); - newType = new NamedClass(qs.getResource("type").getURI()); - types = ind2Types.get(ind); - if(types == null){ - types = new TreeSet<Description>(); - ind2Types.put(ind, types); - } - types.add(newType); - Set<Description> superClasses; - if(reasoner.isPrepared()){ - if(reasoner.getClassHierarchy().contains(newType)){ - superClasses = reasoner.getClassHierarchy().getSuperClasses(newType); - types.addAll(superClasses); - } - - } - } - return cnt; - } - public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); SPARQLReasoner reasoner = new SPARQLReasoner(ks); reasoner.prepareSubsumptionHierarchy(); ObjectPropertyRangeAxiomLearner l = new ObjectPropertyRangeAxiomLearner(ks); l.setReasoner(reasoner); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/routeTypeAbbreviation")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/ideology")); l.setMaxExecutionTimeInSeconds(10); // l.setReturnOnlyNewAxioms(true); l.init(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -21,6 +21,7 @@ import java.net.SocketTimeoutException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -49,7 +50,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.query.ParameterizedSparqlString; +import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.ResultSet; @@ -57,7 +61,15 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; +import com.hp.hpl.jena.sparql.expr.E_Equals; +import com.hp.hpl.jena.sparql.expr.E_Regex; +import com.hp.hpl.jena.sparql.expr.E_Str; +import com.hp.hpl.jena.sparql.expr.ExprVar; +import com.hp.hpl.jena.sparql.expr.NodeValue; import com.hp.hpl.jena.sparql.resultset.ResultSetMem; +import com.hp.hpl.jena.sparql.syntax.ElementFilter; +import com.hp.hpl.jena.sparql.syntax.ElementGroup; +import com.hp.hpl.jena.sparql.util.NodeFactory; import com.hp.hpl.jena.util.iterator.Filter; import com.hp.hpl.jena.vocabulary.OWL2; import com.hp.hpl.jena.vocabulary.RDF; @@ -93,6 +105,17 @@ protected boolean forceSPARQL_1_0_Mode = false; + protected int chunkCount = 0; + protected int chunkSize = 1000; + protected int offset = 0; + protected int lastRowCount = 0; + + protected boolean fullDataLoaded = false; + + private List<String> filterNamespaces = new ArrayList<String>(); + + protected ParameterizedSparqlString iterativeQueryTemplate; + public AbstractAxiomLearningAlgorithm() { existingAxioms = new TreeSet<Axiom>(new AxiomComparator()); } @@ -259,7 +282,7 @@ } } - protected ResultSet executeSelectQuery(String query) { + protected ResultSet executeSelectQuery(String query) {System.out.println(query); logger.debug("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); @@ -274,7 +297,12 @@ return rs; } catch (QueryExceptionHTTP e) { if(e.getCause() instanceof SocketTimeoutException){ - logger.warn("Got timeout"); + if(timeout){ + logger.warn("Got timeout"); + } else { + logger.trace("Got local timeout"); + } + } else { logger.error("Exception executing query", e); } @@ -381,6 +409,87 @@ return 2 * precision * recall / (precision + recall); } + protected ResultSet fetchData(){ + setChunkConditions(); + if(!fullDataLoaded){ + Query query = buildQuery(); + offset += chunkSize; + ResultSet rs = executeSelectQuery(query.toString()); + chunkCount++; + return rs; + } + return new ResultSetMem(); + } + + private void setChunkConditions() { + // adapt chunk size if needed + if (chunkCount == 1 && lastRowCount < chunkSize) { + logger.info("Adapting chunk size from " + chunkSize + " to " + lastRowCount); + chunkSize = lastRowCount; + offset = lastRowCount; + } + + // check if full data was loaded + if(chunkCount != 0){ + fullDataLoaded = (lastRowCount == 0) || (lastRowCount < chunkSize); + if (fullDataLoaded) { + logger.info("Loaded whole data. Early termination."); + } + } + } + + private Query buildQuery(){ + Query query = iterativeQueryTemplate.asQuery(); + for(String ns : filterNamespaces){ + ((ElementGroup)query.getQueryPattern()).addElementFilter( + new ElementFilter( + new E_Regex( + new E_Str(new ExprVar(Node.createVariable("type"))), + ns, ""))); + } + query.setLimit(chunkSize); + query.setOffset(offset); + return query; + } + + public void addFilterNamespace(String namespace){ + filterNamespaces.add(namespace); + } + + protected <K,T extends Set<V>, V> void addToMap(Map<K, T> map, K key, V value ){ + T values = map.get(key); + if(values == null){ + try { + values = (T) values.getClass().newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + values.add(value); + } + values.add(value); + } + + protected <K,T extends Set<V>, V> void addToMap(Map<K, T> map, K key, Collection<V> newValues ){ + T values = map.get(key); + if(values == null){ + try { + values = (T) newValues.getClass().newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + map.put(key, values); + } + values.addAll(newValues); + } + + private void adaptChunkCount(){ + + } + class OWLFilter extends Filter<OntClass>{ @Override Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-07 14:28:49 UTC (rev 3696) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-08 11:53:28 UTC (rev 3697) @@ -219,6 +219,8 @@ private OWLReasoner reasoner; private OWLDataFactory factory = new OWLDataFactoryImpl(); + private static final String NAMESPACE = "http://dbpedia.org/ontology"; + private SPARQLReasoner sparqlReasoner; public EnrichmentEvaluation(SparqlEndpoint endpoint) { @@ -370,6 +372,7 @@ AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); ((AbstractAxiomLearningAlgorithm)learner).setReasoner(sparqlReasoner); + ((AbstractAxiomLearningAlgorithm)learner).addFilterNamespace(NAMESPACE); ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); @@ -459,6 +462,7 @@ AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); ((AbstractAxiomLearningAlgorithm)learner).setReasoner(sparqlReasoner); + ((AbstractAxiomLearningAlgorithm)learner).addFilterNamespace(NAMESPACE); ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-05-11 07:40:45
|
Revision: 3704 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3704&view=rev Author: jenslehmann Date: 2012-05-11 07:40:34 +0000 (Fri, 11 May 2012) Log Message: ----------- moved class Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java trunk/interfaces/src/main/resources/log4j.properties Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ClassIndexer.java Removed Paths: ------------- trunk/components-core/src/main/java/org/nlp2rdf/ Copied: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ClassIndexer.java (from rev 3703, trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java) =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ClassIndexer.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ClassIndexer.java 2012-05-11 07:40:34 UTC (rev 3704) @@ -0,0 +1,258 @@ +/***************************************************************************/ +/* Copyright (C) 2010-2011, Sebastian Hellmann */ +/* Note: If you need parts of NLP2RDF in another licence due to licence */ +/* incompatibility, please mail hel...@in... */ +/* */ +/* This file is part of NLP2RDF. */ +/* */ +/* NLP2RDF is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* NLP2RDF is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/***************************************************************************/ + +package org.dllearner.kb.sparql.simple; + +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.util.iterator.ExtendedIterator; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.naming.ldap.ExtendedRequest; +import java.util.*; + + +/** + * Indexes an Ontology + * skips complex classes per default, this does not affect the hierarchy outcome + */ +public class ClassIndexer { + private static Logger log = LoggerFactory.getLogger(ClassIndexer.class); + + //Options + private boolean copyLabels = true; + private boolean copyComments = true; + private String language = null; + + //Not implemented + private Map<String, String> transform = new HashMap<String, String>(); + //Not implemented + private Set<String> remove = new HashSet<String>(); + + //internal variables + private Map<String, OntModel> classUriToClassHierarchy = new HashMap<String, OntModel>(); + + public ClassIndexer() { + } + + public void index(OntModel from) { + + // Set<OntClass> classes = from.listClasses(); + int i = 0; + OntClass cl; + for (ExtendedIterator<OntClass> it = from.listClasses(); it.hasNext(); ) { + Monitor m0 = MonitorFactory.start("Indexer listClasses"); + cl = it.next(); + m0.stop(); + //for (OntClass cl : classes) { + Monitor m1 = MonitorFactory.start("Indexer generating tree"); + Tree t = new Tree(cl); + m1.stop(); + Monitor m2 = MonitorFactory.start("Indexer generating model"); + OntModel m = t.toModel(); + m2.stop(); + Monitor m3 = MonitorFactory.start("Indexer generating hashmap"); + classUriToClassHierarchy.put(cl.getURI(), m); + m3.stop(); + } + + } + + /** + * @param classUri + * @return a filled OntModel with all superclasses of classUri or null, if no class is found + */ + public OntModel getHierarchyForClassURI(String classUri) { + return classUriToClassHierarchy.get(classUri); + } + + /** + * transforms namespaces + * + * @param in + * @return + */ + private String transformNamespace(String in) { + String ret = in; + for (String s : transform.keySet()) { + if (in.startsWith(s)) { + return in.replace(s, transform.get(s)); + + } + } + return ret; + } + + /** + * filters out certain namespaces + * + * @param s + * @return + */ + private boolean filterNamespace(String s) { + for (String prefix : remove) { + if (s.startsWith(prefix)) { + return true; + } + } + return false; + } + + + public boolean isCopyLabels() { + return copyLabels; + } + + public void setCopyLabels(boolean copyLabels) { + this.copyLabels = copyLabels; + } + + public boolean isCopyComments() { + return copyComments; + } + + public void setCopyComments(boolean copyComments) { + this.copyComments = copyComments; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + /** + * A simple Helper Class to convert the hierarchy + */ + private class Tree { + final String uri; + List<Tree> parents; + final String label; + final String comment; + + public Tree(OntClass me) { + this.uri = me.getURI(); + label = me.getLabel(language); + comment = me.getComment(language); + parents = new ArrayList<Tree>(); + + Set<OntClass> superClasses = me.listSuperClasses(true).toSet(); + for (OntClass s : superClasses) { + //this is were complex classes are skipped + if (s.isAnon()) { + continue; + } + log.trace(s.toString()); + parents.add(new Tree(s)); + } + } + + public OntModel toModel() { + OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, ModelFactory.createDefaultModel()); + OntClass me = model.createClass(uri); + //TODO test this for <&> + if (copyLabels && label != null) { + me.addLabel(label, language); + } + if (copyComments && comment != null) { + me.addComment(comment, language); + } + for (Tree p : parents) { + OntClass superClass = model.createClass(p.uri); + me.addSuperClass(superClass); + model.add(p.toModel()); + } + return model; + } + } + +} + +/** + public void expandSuperAndCopy(String originalClassUri) { + + String newClassUri = transform(originalClassUri); + if (isRemove(originalClassUri) || isRemove(newClassUri)) { + return; + } + + + // create initial classes + OntClass toClass = toModel.createClass(newClassUri); + OntClass fromClass = fromModel.getOntClass(originalClassUri); + + if(toClass==null || fromClass == null){ + logger.error("null occured in fromClass "+originalClassUri+" but retrieving yielded: "+fromClass ); + return; + } + + //System.out.println("begin"); + //for(OntClass cltest: fromModel.listClasses().toSet()){ + // System.out.println(cltest.getURI()); + // System.out.println(cltest.getClass().getSimpleName()); + //} + //System.out.println("end"); + + if (copyLabelsAndComments ) { + String tmp = null; + + if((tmp=fromClass.getLabel(null))!=null) {toClass.setLabel(tmp, null);} + // System.out.println(fromClass.getURI()+"has label "+tmp); + + if((tmp=fromClass.getComment(null))!=null) {toClass.setComment(tmp, null);} + // System.out.println(fromClass.getURI()+"has comment "+tmp); + } + + // get the superclasses + Set<OntClass> fromSuperclasses = fromClass.listSuperClasses(true).toSet(); + + for (OntClass fromSuperclass : fromSuperclasses) { + String newFromSuperclassUri = transform(fromSuperclass.getURI()); + if (isRemove(fromSuperclass.getURI()) || isRemove(newFromSuperclassUri)) { + continue; + } + if(fromSuperclass.isAnon()){ + continue; + } + + OntClass toSuperclass = toModel.createClass(newFromSuperclassUri); + toClass.addSuperClass(toSuperclass); + + if (copyLabelsAndComments) { + String tmp = null; + if((tmp=fromSuperclass.getLabel(null))!=null) {toSuperclass.setLabel(tmp, null);} + // System.out.println(fromSuperclass.getURI()+"has label "+tmp); + + if((tmp=fromSuperclass.getComment(null))!=null) {toSuperclass.setComment(tmp, null);} + // System.out.println(fromSuperclass.getURI()+"has comment "+tmp); + } + // System.out.println(fromSuperclass); + expandSuperAndCopy(fromSuperclass.getURI()); + } + + } **/ \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-05-11 07:03:50 UTC (rev 3703) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-05-11 07:40:34 UTC (rev 3704) @@ -10,7 +10,6 @@ import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; -import org.nlp2rdf.ontology.ClassIndexer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; Modified: trunk/interfaces/src/main/resources/log4j.properties =================================================================== --- trunk/interfaces/src/main/resources/log4j.properties 2012-05-11 07:03:50 UTC (rev 3703) +++ trunk/interfaces/src/main/resources/log4j.properties 2012-05-11 07:40:34 UTC (rev 3704) @@ -13,9 +13,9 @@ log4j.appender.file.Threshold=DEBUG # DL-Learner Logs -log4j.logger.org.dllearner=INFO +log4j.logger.org.dllearner=DEBUG # Turn this to Debug if you wish to dump stack traces to the appenders (console, file) -log4j.logger.org.dllearner.cli=INFO +log4j.logger.org.dllearner.cli=DEBUG log4j.logger.org.dllearner.server.nke.LogicalRelationStrategy=DEBUG log4j.category.org.dllearner.kb.simple=DEBUG This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tc...@us...> - 2012-05-17 03:10:07
|
Revision: 3715 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3715&view=rev Author: tcanvn Date: 2012-05-17 03:09:57 +0000 (Thu, 17 May 2012) Log Message: ----------- change the PADCEL algorithm's name (PADCEL --> ParCEL). Package name, examples, CLI and test units have been updated Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown2008.java trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELComplenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCompletenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCorrectnessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCoverageGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELCoveredNegativeExampleComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefaultHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionGenerationTimeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionLengthComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELDefinitionLengthReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELEvaluationResult.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELExtraNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELGenerationTimeReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELImprovedCovegareGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELOntologyUtil.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELPosNegLP.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELScore.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELStringUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELTaskComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerThreadFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearnerMBean.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELearnerMat.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ParCELDoubleSplitterAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ParCELDoubleSplitterV1.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ValueCount.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/split/ValuesSet.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCELEx/ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCELEx/ParCELExAbstract.java trunk/examples/carcinogenesis/carcinogenesis_parcel.conf trunk/examples/family-benchmark/Aunt_parcel.conf trunk/examples/family-benchmark/Brother_parcel.conf trunk/examples/family-benchmark/Cousin_parcel.conf trunk/examples/family-benchmark/Daughter_parcel.conf trunk/examples/family-benchmark/Father_parcel.conf trunk/examples/family-benchmark/Grandson_parcel.conf trunk/examples/family-benchmark/Uncle_parcel.conf trunk/examples/forte/uncle_owl_large_parcel.conf trunk/examples/moral_reasoner/moral_all_examples_simple_owl_parcel.conf trunk/examples/poker/straight_owl_parcel.conf trunk/examples/showering-duration/uca1_150_parcel.conf trunk/examples/showering-duration/uca2_300_parcel.conf trunk/interfaces/src/main/java/org/dllearner/cli/ParCELCrossValidation.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELCLITestAbstract.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELCarcinoGenesisTest.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELFamilyBenchmarkTest.java trunk/interfaces/src/test/java/org/dllearner/cli/ParCELMultiExamplesTest.java Removed Paths: ------------- trunk/components-core/src/main/java/nz/ac/massey/abd/ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELReducer.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELRefinementOperatorFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELRefinementOperatorPool.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELScore.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELStringUtilities.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELTaskComparator.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELWorker.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELWorkerThreadFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELearnerMBean.java trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/split/ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCELEx/ trunk/examples/carcinogenesis/carcinogenesis_padcel.conf trunk/examples/family-benchmark/Aunt_padcel.conf trunk/examples/family-benchmark/Brother_padcel.conf trunk/examples/family-benchmark/Cousin_padcel.conf trunk/examples/family-benchmark/Daughter_padcel.conf trunk/examples/family-benchmark/Father_padcel.conf trunk/examples/family-benchmark/Grandson_padcel.conf trunk/examples/family-benchmark/Uncle_padcel.conf trunk/examples/forte/uncle_owl_large_padcel.conf trunk/examples/moral_reasoner/moral_all_examples_simple_owl_padcel.conf trunk/examples/poker/straight_owl_padcel.conf trunk/examples/showering-duration/uca1_150_padcel.conf trunk/examples/showering-duration/uca2_300_padcel.conf trunk/interfaces/src/main/java/org/dllearner/cli/PADCELCrossValidation.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCLITestAbstract.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELCarcinoGenesisTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELFamilyBenchmarkTest.java trunk/interfaces/src/test/java/org/dllearner/cli/PADCELMultiExamplesTest.java Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELAbstract.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,142 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Set; -import java.util.SortedSet; -import java.util.concurrent.ConcurrentSkipListSet; - -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.NamedClass; - -/** - * Abstract class for all PDL-Learner algorithms family - * - * @author An C. Tran - * - */ -public abstract class PADCELAbstract extends AbstractCELA { - - // ---------------------------------- - // configuration options - // ---------------------------------- - @ConfigOption(name = "numberOfWorkers", defaultValue = "2", description = "This option is used to set the number of workers will be created to serve the leaner. This should be = 2 * total number of cores of CPUs") - protected int numberOfWorkers = 4; // max number of workers will be created - - @ConfigOption(name = "maxExecutionTimeInSeconds", defaultValue = "0", description = "maximum execution of the algorithm in seconds") - protected int maxExecutionTimeInSeconds = 0; - - @ConfigOption(name = "noisePercentage", defaultValue = "0.0", description = "The percentage of noise within the examples") - protected double noisePercentage = 0.0; - - @ConfigOption(name = "maxNoOfSplits", defaultValue = "10", description = "Max number of splits will be applied for data properties with double range") - protected int maxNoOfSplits = 10; - - @ConfigOption(name = "ignoredConcepts", defaultValue = "", description = "set of concepts that will be ignored in learning the target concept") - protected Set<NamedClass> ignoredConcepts = null; - - - /** - * All generated descriptions thread-safe set is used to avoid concurrently - * accessing - */ - protected ConcurrentSkipListSet<Description> allDescriptions = null; - - /** - * Search tree. It hold all evaluated descriptions that are not correct and - * not weak ==> candidate for partial definitions Nodes in the search tree - * must be ordered using heuristic so that it can help the searching more - * efficiently (best search rather than 'blind' breadth first of depth - * first) NOTE: node = (description + accuracy/correctness/completeness/... - * value) - */ - protected ConcurrentSkipListSet<PADCELNode> searchTree = null; // thread safe - // set - - /** - * partial definitions (they should be sorted so that we can get the best - * partial definition at any time - */ - protected SortedSet<PADCELExtraNode> partialDefinitions = null; - - /** - * Default constructor - */ - public PADCELAbstract() { - super(); - } - - /** - * ======================================================================== - * Constructor for the learning algorithm - * - * @param learningProblem - * Must be a PDLLPosNegLP - * @param reasoningService - * A reasoner - */ - public PADCELAbstract(PADCELPosNegLP learningProblem, AbstractReasonerComponent reasoningService) { - super(learningProblem, reasoningService); - } - - public abstract Description getUnionCurrenlyBestDescription(); - - public abstract int getNoOfCompactedPartialDefinition(); - - public abstract Set<PADCELExtraNode> getPartialDefinitions(); - - public abstract double getCurrentlyOveralMaxCompleteness(); - - public long getNumberOfPartialDefinitions() { - return this.partialDefinitions.size(); - } - - - // ------------------------------------------------ - // setters and getters for configuration options - // ------------------------------------------------ - - public void setNumberOfWorkers(int numberOfWorkers) { - this.numberOfWorkers = numberOfWorkers; - } - - public int getNumberOfWorkers() { - return numberOfWorkers; - } - - public void setMaxExecutionTimeInSeconds(int maxExecutionTime) { - this.maxExecutionTimeInSeconds = maxExecutionTime; - } - - public int getMaxExecutionTimeInSeconds() { - return maxExecutionTimeInSeconds; - } - - public void setNoisePercentage(double noise) { - this.noisePercentage = noise; - } - - public double getNoisePercentage() { - return this.noisePercentage; - } - - - public int getMaxNoOfSplits() { - return maxNoOfSplits; - } - - public void setMaxNoOfSplits(int maxNoOfSplits) { - this.maxNoOfSplits = maxNoOfSplits; - } - - public Set<NamedClass> getIgnoredConcepts() { - return ignoredConcepts; - } - - public void setIgnoredConcepts(Set<NamedClass> ignoredConcepts) { - this.ignoredConcepts = ignoredConcepts; - } - - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELComplenessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,37 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Comparator for PDLLNode based on the completeness of the description If two - * nodes has the same completeness, description length will be taken into the - * consideration and finally the ConceptComparator - * - * @author An C. Tran - * - */ - -public class PADCELComplenessComparator implements Comparator<PADCELNode> { - - @Override - public int compare(PADCELNode node1, PADCELNode node2) { - int v1 = node1.getCoveredPositiveExamples().size(); - int v2 = node2.getCoveredPositiveExamples().size(); - if (v1 > v2) - return -1; - else if (v1 < v2) - return 1; - else { - if (node1.getDescription().getLength() < node2.getDescription().getLength()) - return -1; - else if (node1.getDescription().getLength() > node2.getDescription().getLength()) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCompletenessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on their completeness (coverage). The description - * length and ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCompletenessComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - - int v1 = node1.getCoveredPositiveExamples().size(); - int v2 = node2.getCoveredPositiveExamples().size(); - - if (v1 > v2) - return -1; - else if (v1 < v2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCorrectnessComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on their correctness. The description length and - * ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCorrectnessComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - double correctness1 = node1.getCorrectness(); - double correctness2 = node2.getCorrectness(); - - if (correctness1 > correctness2) - return -1; // smaller will be on the top - else if (correctness1 < correctness2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoverageGreedyReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,82 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * This class implements a simple strategy for compacting the partial definition set In this - * strategy, the partial definition will be chosen based on their accuracy. The partial definition - * with the best accuracy will be chosen first and the rests will not be re-calculated before the - * next reduction - * - * @author An C. Tran - * - */ -public class PADCELCoverageGreedyReducer implements PADCELReducer { - - /** - * Compact partial definitions - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover all positive examples - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover (positive examples \ uncovered positive - * examples) - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELCorrectnessComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = partialDefinitions.iterator(); - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELCoveredNegativeExampleComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,38 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Use to compare 2 ExtraPLOENode nodes based on the number of covered negative examples. The - * description length and ConceptComparator will be used it they have equal coverage - * - * @author An C. Tran - * - */ -public class PADCELCoveredNegativeExampleComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - int coveredNeg1 = node1.getCoveredNegativeExamples().size(); - int coveredNeg2 = node2.getCoveredPositiveExamples().size(); - - if (coveredNeg1 > coveredNeg2) - return -1; // smaller will be on the top - else if (coveredNeg1 < coveredNeg2) - return 1; - else { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefaultHeuristic.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,95 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Implements the heuristic used to expand the search tree. Dimensions used: <br> - * + correctness: main value<br> - * + horizontal expansion: penalty<br> - * + accuracy gained from the parent node: bonus<br> - * + refinement nodes: penalty<br> - * + concept type + name (org.dllearner.utilities.owl.ConceptComparator) - * - * @author An C. Tran - * - */ -public class PADCELDefaultHeuristic implements PADCELHeuristic { - - // penalty for long descriptions - protected double expansionPenaltyFactor = 0.1; - - // bonus for gained accuracy - protected double gainBonusFactor = 0.2; - - // penalty if a node description has very many refinements since exploring - // such a node is computationally very expensive - protected double nodeRefinementPenalty = 0.0001; - - // award for node with high accuracy - protected double accuracyAwardFactor = 0.01; - - // syntactic comparison as final comparison criterion - protected ConceptComparator conceptComparator = new ConceptComparator(); - - /** - * Compare two node - * - * @param node1 - * Node to compare - * @param node2 - * Node to compare - * - * @return 1 if node1 "greater" than node2 and vice versa - */ - public int compare(PADCELNode node1, PADCELNode node2) { - double diff = getNodeScore(node1) - getNodeScore(node2); - - if (diff > 0) { // node1 has better score than node2 - return 1; - } else if (diff < 0) { - return -1; - } else { - int comp = conceptComparator.compare(node1.getDescription(), node2.getDescription()); - - // this allows duplicate descriptions exists in the set - if (comp != 0) - return comp; - else - return -1; - - } - } - - /** - * Calculate score for a node which is used as the searching heuristic - * - * @param node - * Node to be scored - * - * @return Score of the node - */ - protected double getNodeScore(PADCELNode node) { - - // the scoring mainly bases on correctness - double score = node.getCorrectness(); - - // bonus for the accuracy gained - if (!node.isRoot()) { - double parentAccuracy = ((PADCELNode) (node.getParent())).getAccuracy(); - score += (parentAccuracy - node.getAccuracy()) * gainBonusFactor; - } - - // award node with high accuracy - score += node.getAccuracy() * accuracyAwardFactor; - - // penalty for horizontal expansion - score -= node.getHorizontalExpansion() * expansionPenaltyFactor; - // score -= node.getDescription().getLength() * expansionPenaltyFactor; - - return score; - } - - public double getScore(PADCELNode node) { - return this.getNodeScore(node); - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionGenerationTimeComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,37 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -/** - * Compare two node based on their generation time. - * This will be used in the Generation Time Greedy Compactness strategy - * GOLR - * - * @author An C. Tran - */ - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -public class PADCELDefinitionGenerationTimeComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - double genTime1 = node1.getGenerationTime(); - double genTime2 = node2.getGenerationTime(); - - if (genTime1 < genTime2) - return -1; - else if (genTime1 > genTime2) - return 1; - else { - if (node1.getDescription().getLength() < node2.getDescription().getLength()) - return -1; - else if (node1.getDescription().getLength() > node2.getDescription().getLength()) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), - node2.getDescription()); - } - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthComparator.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,29 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -import org.dllearner.utilities.owl.ConceptComparator; - -/** - * Compare two node based on their definition length. This will be used in the Definition Length - * Greedy Compactness strategy - * - * @author An C. Tran - * - */ - -public class PADCELDefinitionLengthComparator implements Comparator<PADCELExtraNode> { - - @Override - public int compare(PADCELExtraNode node1, PADCELExtraNode node2) { - int len1 = node1.getDescription().getLength(); - int len2 = node2.getDescription().getLength(); - if (len1 < len2) - return -1; - else if (len1 > len2) - return 1; - else - return new ConceptComparator().compare(node1.getDescription(), node2.getDescription()); - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELDefinitionLengthReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,59 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * Compact set of partial definitions using Definition Length Grredy Reduction strategy - * - * @author An C. Tran - * - */ -public class PADCELDefinitionLengthReducer implements PADCELReducer { - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> newSortedPartialDefinitions = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionLengthComparator()); - synchronized (partialDefinitions) { - newSortedPartialDefinitions.addAll(partialDefinitions); - } - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = newSortedPartialDefinitions.iterator(); - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELEvaluationResult.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,132 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Set; - -import org.dllearner.core.owl.Individual; - -/** - * This class represents the result of an evaluation result return from the PDLL learning problem - * (PDLLPosNegLP) <br> - * Information included in a PDLL evaluation includes: - * <ol> - * <li>- accuracy: double</li> - * <li>- correctness: double</li> - * <li>- completeness: double</li> - * <li>- covered positive examples: Set<Individual></li> - * <li>- covered negative examples: Set<Individual></li> - * </ol> - * - * @author An C. Tran - * - */ -public class PADCELEvaluationResult { - - protected double accuracy = -1; - protected double correctness = -1; - protected double completeness = -1; - protected Set<Individual> coveredPossitiveExamples = null; - protected Set<Individual> coveredNegativeExamples = null; - - /** - * Default constructor, use default value for all properties - */ - public PADCELEvaluationResult() { - - } - - /** - * This use to create an evaluation result that is not for a correct definition. So, we don't - * need to hold the set of covered positive examples - * - * @param accuracy - * @param correctness - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness) { - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - } - - /** - * Used to create an evaluation result for a correct definition.<br> - * Covered positive examples have to be kept to be used in the result compactness later on.<br> - * This is usually used in case of partial definition - * - * @param accuracy - * @param correctness - * @param completeness - * @param coveredPossitiveExamples - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness, - Set<Individual> coveredPossitiveExamples) { - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - this.coveredPossitiveExamples = coveredPossitiveExamples; - } - - /** - * Used to create an evaluation result for a correct definition.<br> - * Both covered positive examples and covered negative examples will be kept to be used in the - * result compactness later on. - * - * @param accuracy - * @param correctness - * @param completeness - * @param coveredPositiveExamples - * @param coveredNegativeExamples - */ - public PADCELEvaluationResult(double accuracy, double correctness, double completeness, - Set<Individual> coveredPositiveExamples, Set<Individual> coveredNegativeExamples) { - - this.accuracy = accuracy; - this.correctness = correctness; - this.completeness = completeness; - this.coveredPossitiveExamples = coveredPositiveExamples; - this.coveredNegativeExamples = coveredNegativeExamples; - } - - // --------------------------------------- - // Getters and setters - // --------------------------------------- - public double getAccuracy() { - return accuracy; - } - - public void setAccuracy(double accuracy) { - this.accuracy = accuracy; - } - - public double getCorrectness() { - return correctness; - } - - public void setCorrectness(double correctness) { - this.correctness = correctness; - } - - public double getCompleteness() { - return completeness; - } - - public void setCompleteness(double completeness) { - this.completeness = completeness; - } - - public Set<Individual> getCoveredPossitiveExamples() { - return coveredPossitiveExamples; - } - - public void setCoveredPossitiveExamples(Set<Individual> coveredPossitiveExamples) { - this.coveredPossitiveExamples = coveredPossitiveExamples; - } - - public Set<Individual> getCoveredNegativeExamples() { - return coveredNegativeExamples; - } - - public void setCoveredNegativeExamples(Set<Individual> coveredNegativeExamples) { - this.coveredNegativeExamples = coveredNegativeExamples; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELExtraNode.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,132 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.algorithms.celoe.OENode; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -/** - * Generation time and node type is added into PADCELNode. This information is necessary for some - * reduction algorithms - * - * @author An C. Tran - * - */ -public class PADCELExtraNode extends PADCELNode { - - private double generationTime = Double.MIN_VALUE; // time in ms that the node was generated - private int type = -1; - - Set<OENode> compositeNodes = new HashSet<OENode>(); - - /** - * ============================================================================================ - * Constructor with correctness of the description - * - * @param parentNode - * Parent node of this node - * @param description - * Description of the node - * @param accuracy - * Accuracy of the node - * @param distance - * Distance between the node and the learning problem - * @param correctness - * Correctness of the node - */ - public PADCELExtraNode(OENode parentNode, Description description, double accuracy, - double correctness) { - super(parentNode, description, accuracy, correctness); - } - - public PADCELExtraNode(OENode parentNode, Description description, double accuracy) { - super(parentNode, description, accuracy); - } - - public PADCELExtraNode(PADCELNode node) { - super(node.getParent(), node.getDescription(), node.getAccuracy(), node.getCorrectness()); - setCoveredPositiveExamples(node.getCoveredPositiveExamples()); - setCoveredNegativeExamples(node.getCoveredNegativeExamples()); - } - - public PADCELExtraNode(PADCELNode node, Set<Individual> cp, double generationTime) { - super(node.getParent(), node.getDescription(), node.getAccuracy(), node.getCorrectness()); - super.coveredPositiveExamples = cp; - this.generationTime = generationTime; - } - - /** - * ============================================================================================ - * Constructor with the correctness and the generation time of the description - * - * @param parentNode - * Parent node of this node - * @param description - * Description of the node - * @param accuracy - * Accuracy of the node - * @param distance - * Distance between the node and the learning problem - * @param correctness - * Correctness of the node - * @param genTime - * Time in ms that the work used to generate this node - */ - public PADCELExtraNode(PADCELNode parentNode, Description description, double accuracy, - double correctness, double genTime) { - super(parentNode, description, accuracy, correctness); - this.coveredPositiveExamples = null; - this.generationTime = genTime; - } - - /** - * ============================================================================================ - * Constructor with the set of positive examples covered by the description of the node - * - * @param parentNode - * @param description - * @param accuracy - * @param distance - * @param correctness - * @param cn - * Covered positive examples - */ - public PADCELExtraNode(PADCELNode parentNode, Description description, double accuracy, - double correctness, Set<Individual> cp) { - super(parentNode, description, accuracy, correctness); - super.setCoveredPositiveExamples(cp); - } - - // ------------------------- - // getters and setters - // ------------------------- - public void setCoveredPositiveExamples(Set<Individual> cpn) { - super.setCoveredPositiveExamples(cpn); - } - - public double getGenerationTime() { - return generationTime; - } - - public void setGenerationTime(double d) { - this.generationTime = d; - } - - public void setType(int t) { - this.type = t; - } - - public int getType() { - return this.type; - } - - public void setCompositeList(Set<PADCELExtraNode> compositeNodes) { - this.compositeNodes.addAll(compositeNodes); - } - - public Set<OENode> getCompositeNodes() { - return this.compositeNodes; - } -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELGenerationTimeReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,62 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.dllearner.core.owl.Individual; - -/** - * Compact two a partial definitions set using Generation Time Greedy strategy - * - * @author An C. Tran - * - */ - -public class PADCELGenerationTimeReducer implements PADCELReducer { - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return compact(partialDefinitions, positiveExamples, 0); - } - - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> newSortedPartialDefinitions = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - synchronized (partialDefinitions) { - newSortedPartialDefinitions.addAll(partialDefinitions); - } - - TreeSet<PADCELExtraNode> minimisedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELDefinitionGenerationTimeComparator()); - - Iterator<PADCELExtraNode> partialDefinitionIterator = newSortedPartialDefinitions.iterator(); - - while ((positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (partialDefinitionIterator.hasNext())) { - PADCELExtraNode node = partialDefinitionIterator.next(); - - int positiveExamplesRemoved = positiveExamplesTmp.size(); - positiveExamplesTmp.removeAll(node.getCoveredPositiveExamples()); - - positiveExamplesRemoved -= positiveExamplesTmp.size(); - - if (positiveExamplesRemoved > 0) { - node.setCorrectness(positiveExamplesRemoved); - minimisedPartialDefinition.add(node); - } - } - - return minimisedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELHeuristic.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,16 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.Comparator; - -/** - * Interface for heuristics used in PADCEL - * - * @author An C. Tran - * - */ -public interface PADCELHeuristic extends Comparator<PADCELNode> { - - public int compare(PADCELNode node1, PADCELNode node2); - - public double getScore(PADCELNode node); -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELImprovedCovegareGreedyReducer.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,115 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.util.HashSet; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.dllearner.core.owl.Individual; - -/** - * This class implements "wise" coverage greedy strategy for compacting the partial definitions In - * this strategy, the partial definitions will be chosen based on their coverage. When a partial - * definition has been chosen, coverage of other partial definition will be recalculated - * - * @author An C. Tran - * - */ - -public class PADCELImprovedCovegareGreedyReducer implements PADCELReducer { - - Logger logger = Logger.getLogger(this.getClass()); - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover all positive examples - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples) { - return this.compact(partialDefinitions, positiveExamples, 0); - } - - /** - * Compact partial definition with noise allowed - * - * @param partialDefinitions - * Set of partial definitions - * @param positiveExamples - * Set of positive examples (used to check whether partial definition is useful - * @param uncoveredPositiveExamples - * Number of uncovered positive examples allowed - * - * @return Subset of partial definitions that cover (positive examples \ uncovered positive - * examples) - */ - @Override - public SortedSet<PADCELExtraNode> compact(SortedSet<PADCELExtraNode> partialDefinitions, - Set<Individual> positiveExamples, int uncoveredPositiveExamples) { - Set<Individual> positiveExamplesTmp = new HashSet<Individual>(); - positiveExamplesTmp.addAll(positiveExamples); - - TreeSet<PADCELExtraNode> reducedPartialDefinition = new TreeSet<PADCELExtraNode>( - new PADCELCompletenessComparator()); - - if (partialDefinitions.size() == 0) - return reducedPartialDefinition; - - synchronized (partialDefinitions) { - Object[] partialDefs = partialDefinitions.toArray(); - - // the highest accurate partial definition - // reducedPartialDefinition.add((PDLLExtraNode)partialDefs[0]); - // positiveExamplesTmp.removeAll(((PDLLExtraNode)partialDefs[0]).getCoveredPositiveExamples()); - - for (int i = 0; (positiveExamplesTmp.size() > uncoveredPositiveExamples) - && (i < partialDefinitions.size()); i++) { - - // count the number of different positive examples covered - int counti = 0; - for (Individual indi : ((PADCELExtraNode) partialDefs[i]) - .getCoveredPositiveExamples()) { - if (positiveExamplesTmp.contains(indi)) - counti++; - } // count the number of different covered positive examples by - // i - - for (int j = i + 1; j < partialDefinitions.size(); j++) { - int countj = 0; - - for (Individual indj : ((PADCELExtraNode) partialDefs[j]) - .getCoveredPositiveExamples()) - if (positiveExamplesTmp.contains(indj)) - countj++; - - // TODO: revise this code: Swapping should be done only one - // time at the end - // swap the partial definition so that the "best" partial - // definition will be in the top - if (countj > counti) { - PADCELExtraNode tmp = (PADCELExtraNode) partialDefs[j]; - partialDefs[j] = partialDefs[i]; - partialDefs[i] = tmp; - counti = countj; - } - } - - reducedPartialDefinition.add((PADCELExtraNode) partialDefs[i]); - positiveExamplesTmp.removeAll(((PADCELExtraNode) partialDefs[i]) - .getCoveredPositiveExamples()); - } - } - - return reducedPartialDefinition; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELNode.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,113 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.text.DecimalFormat; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.algorithms.celoe.OENode; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -/** - * Represents a node in the search tree used in the PDLLeanring<br> - * A node includes description and its corresponding properties such as: correctness, accuracy, - * distance between the description the leaning problem, parent node of the description. It also - * contains a flag which indicates the node is processed or not. - * - * @author An C. Tran - * - */ -public class PADCELNode extends OENode { - - private double correctness = -1.0; - private double completeness = -1.0; - - protected Set<Individual> coveredPositiveExamples = new HashSet<Individual>(); - protected Set<Individual> coveredNegativeExamples = new HashSet<Individual>(); - - private DecimalFormat dfPercent = new DecimalFormat("0.00%"); - - public PADCELNode(OENode parentNode, Description description, double accuracy) { - super(parentNode, description, accuracy); - } - - public PADCELNode(OENode parentNode, Description description, double accuracy, double correctness) { - super(parentNode, description, accuracy); - this.correctness = correctness; - } - - public PADCELNode(OENode parentNode, Description description, double accuracy, - double correctness, double completeness) { - super(parentNode, description, accuracy); - this.correctness = correctness; - this.completeness = completeness; - } - - public PADCELNode(OENode parentNode, Description description) { - super(parentNode, description, 0); - } - - public PADCELNode(OENode parentNode, Description description, - Set<Individual> coveredPositiveExamples, Set<Individual> coveredNegativeExamples) { - super(parentNode, description, 0); - this.coveredPositiveExamples.addAll(coveredPositiveExamples); - this.coveredNegativeExamples.addAll(coveredNegativeExamples); - } - - public void setCorrectness(double cor) { - this.correctness = cor; - } - - public double getCorrectness() { - return this.correctness; - } - - public void setCompleteness(double comp) { - this.completeness = comp; - } - - public double getCompleteness() { - return this.completeness; - } - - public void setAccuracy(double acc) { - this.accuracy = acc; - } - - public Set<Individual> getCoveredPositiveExamples() { - return this.coveredPositiveExamples; - } - - public Set<Individual> getCoveredNegativeExamples() { - return this.coveredNegativeExamples; - } - - public void setCoveredPositiveExamples(Set<Individual> coveredPositiveExamples) { - if (coveredPositiveExamples != null) - this.coveredPositiveExamples.addAll(coveredPositiveExamples); - else - this.coveredPositiveExamples.clear(); - } - - public void setCoveredNegativeExamples(Set<Individual> coveredNegativeExamples) { - if (coveredNegativeExamples != null) - this.coveredNegativeExamples.addAll(coveredNegativeExamples); - else - this.coveredNegativeExamples.clear(); - } - - @Override - public String toString() { - String ret = this.getDescription().toString(null, null) + " ["; - ret += "acc:" + dfPercent.format(this.getAccuracy()) + ", "; - ret += "cor:" + dfPercent.format(this.getCorrectness()) + ", "; - ret += "comp:" + dfPercent.format(this.completeness) + "]"; - return ret; - - } - - public void setDescription(Description newDescription) { - this.description = newDescription; - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELOntologyUtil.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,87 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.IRI; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyCreationException; -import org.semanticweb.owlapi.model.OWLOntologyManager; -import org.semanticweb.owlapi.model.OWLOntologyStorageException; - -/** - * Some utility functions for ontology manipulation - * - * @author An C. Tran - * - */ - -public class PADCELOntologyUtil { - - /** - * ========================================================================================== - * Get ontology given its file path - * - * @param ontologyFilePath - * - * @return Opened ontology - * @throws OWLOntologyCreationException - */ - public static OWLOntology loadOntology(String ontologyFilePath) - throws OWLOntologyCreationException { - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology ontology; - - String flash = (System.getProperty("os.name").contains("Windows")) ? "/" : ""; - - File f = new File(ontologyFilePath); - - if (!ontologyFilePath.contains("file:")) - ontologyFilePath = "file:" + flash + f.getAbsolutePath(); - - ontologyFilePath = ontologyFilePath.replace('\\', '/'); - - ontology = manager.loadOntology(IRI.create(ontologyFilePath)); - - return ontology; - } - - /** - * ============================================================================================ - * Persist the ontology - * - * @param ontology - * Ontology which need to be persisted - * - * @throws OWLOntologyStorageException - */ - public static void persistOntology(OWLOntology ontology) throws OWLOntologyStorageException { - OWLOntologyManager manager = ontology.getOWLOntologyManager(); - manager.saveOntology(ontology); - } - - /** - * ============================================================================================ - * Persist ontology to another ontology - * - * @param ontology - * Ontology contains changes - * @param newFilePath - * Path to the new ontology file - * - * @throws OWLOntologyStorageException - * @throws IOException - */ - public static void persistOntology(OWLOntology ontology, String newFilePath) - throws OWLOntologyStorageException, IOException { - OWLOntologyManager manager = ontology.getOWLOntologyManager(); - - File f = new File(newFilePath); - FileOutputStream fo = new FileOutputStream(f); - - manager.saveOntology(ontology, fo); - fo.close(); - } - -} Deleted: trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java 2012-05-15 07:20:52 UTC (rev 3714) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/PADCEL/PADCELPosNegLP.java 2012-05-17 03:09:57 UTC (rev 3715) @@ -1,493 +0,0 @@ -package org.dllearner.algorithms.PADCEL; - -/** - * PDLL Learning problem: provides correctness, completeness, and accuracy calculation. - * Predictive accuracy calculation is used. - * - * @author An C. Tran - */ - -import java.util.Set; - -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedList; - -import org.apache.log4j.Logger; -import org.dllearner.core.AbstractLearningProblem; -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.AbstractReasonerComponent; -import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.StringSetConfigOption; -import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Individual; - -@ComponentAnn(name = "PDLLPosNegLP", shortName = "pdllPosNegLP", version = 0.1, description = "PDLL positive negative learning problem") -public class PADCELPosNegLP extends AbstractLearningProblem { - - protected Set<Individual> positiveExamples; - protected Set<Individual> negativeExamples; - - protected Set<Individual> uncoveredPositiveExamples; - - private Logger logger = Logger.getLogger(this.getClass()); - - // reasoner component is declared in AbstractLearningProblem class - - /** - * Constructor, used in case that positive and negative examples are provided when this - * component is initialized - * - * @param reasoningService - * Reasoner, provides reasoning service. Used to checking the instance type - * @param positiveExamples - * Positive examples - * @param negativeExamples - * Negative examples - */ - public PADCELPosNegLP(AbstractReasonerComponent reasoningService, - Set<Individual> positiveExamples, Set<Individual> negativeExamples) { - super(reasoningService); - this.positiveExamples = positiveExamples; - this.negativeExamples = negativeExamples; - this.uncoveredPositiveExamples = this.positiveExamples; - } - - /** - * This constructor is used when the learning configuration file is used - * - * @param reasoningService - */ - public PADCELPosNegLP(AbstractReasonerComponent reasoningService) { - super(reasoningService); - } - - /** - * This constructor can be used by SpringDefinition to create bean object Properties of new bean - * may be initialised later using setters - */ - public PADCELPosNegLP() { - super(); - - if (logger.isDebugEnabled()) - logger.debug("Learning problem created: " + this); - } - - /** - * Get list of positive examples covered by a description - * - * @param description - * Description - * - * @return Set of positive examples covered by the description - */ - protected Set<Individual> coveredPositiveExamples(Description description) { - Set<Individual> coveredPositiveExamples = new HashSet<Individual>(); - - for (Individual example : positiveExamples) - if (reasoner.hasType(description, example)) - coveredPositiveExamples.add(example); - - return coveredPositiveExamples; - } - - /** - * Get number of positive examples covered by a description - * - * @param description - * Description - * @return Number if positive examples covered by the description - */ - protected int getNumberCoveredPositiveExamples(Description description) { - int coveredPos = 0; - - for (Individual example : positiveExamples) - if (reasoner.hasType(description, example)) - coveredPos++; - - return coveredPos; - } - - /** - * Get number of negative examples covered by a description - * - * @param description - * Description to test - * - * @return Number of negative examples covered by the description - */ - protected int getNumberOfCoveredNegativeExamples(Description description) { - int coveredNeg = 0; - for (Individual example : negativeExamples) { - if (reasoner.hasType(description, example)) { - coveredNeg++; - } - } - - return coveredNeg; - } - - /** - * Calculate predictive accuracy of a description pred-accuracy(D) = - * (covered-positive-examples(D) + uncovered-negative-examples(D)) / all-examples - * -... [truncated message content] |
From: <jen...@us...> - 2012-05-18 11:10:24
|
Revision: 3722 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3722&view=rev Author: jenslehmann Date: 2012-05-18 11:10:14 +0000 (Fri, 18 May 2012) Log Message: ----------- changed comment Modified Paths: -------------- trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java trunk/interfaces/src/main/java/org/dllearner/cli/Start.java Modified: trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java 2012-05-18 11:07:51 UTC (rev 3721) +++ trunk/components-core/src/test/java/org/dllearner/core/AnnComponentManagerTest.java 2012-05-18 11:10:14 UTC (rev 3722) @@ -20,6 +20,7 @@ public void testGetComponentsOfType() { Collection<Class<? extends Component>> components = AnnComponentManager.getInstance().getComponentsOfType(ReasonerComponent.class); +// System.out.println(components); Assert.assertEquals(3,components.size()); } } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Start.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2012-05-18 11:07:51 UTC (rev 3721) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Start.java 2012-05-18 11:10:14 UTC (rev 3722) @@ -116,9 +116,9 @@ */ public static void main(String[] args) { - System.out.println("********************************************************************************"); - System.out.println("* Caution: The command line interface is currently unlikely to work correctly. *"); - System.out.println("********************************************************************************"); + System.out.println("************************************************************************************************************"); + System.out.println("* Please use the new CLI interfach: org.dllearner.cli.CLI - this interface is unlikely to work as expected *"); + System.out.println("************************************************************************************************************"); System.out.println("DL-Learner " + Info.build + " command line interface"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-11 12:57:09
|
Revision: 3777 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3777&view=rev Author: lorenz_b Date: 2012-07-11 12:56:58 +0000 (Wed, 11 Jul 2012) Log Message: ----------- Added option to use ELK and CEL reasoner. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/pom.xml Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-07-07 11:36:11 UTC (rev 3776) +++ trunk/components-core/pom.xml 2012-07-11 12:56:58 UTC (rev 3777) @@ -227,6 +227,22 @@ <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> </dependency> + <dependency> + <groupId>org.semanticweb.elk</groupId> + <artifactId>elk-owlapi</artifactId> + <version>0.2.0</version> + </dependency> + <dependency> + <groupId>de.tudresden.inf.lat.cel</groupId> + <artifactId>reasoner</artifactId> + <version>0.5.1</version> + </dependency> + <dependency> + <groupId>de.tudresden.inf.lat.cel</groupId> + <artifactId>jsexp</artifactId> + <version>0.1.0</version> + </dependency> + </dependencies> <dependencyManagement> <dependencies> Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-07-07 11:36:11 UTC (rev 3776) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-07-11 12:56:58 UTC (rev 3777) @@ -72,6 +72,7 @@ import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.RoleComparator; import org.semanticweb.HermiT.Reasoner.ReasonerFactory; +import org.semanticweb.elk.owlapi.ElkReasonerFactory; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AddAxiom; import org.semanticweb.owlapi.model.AddImport; @@ -122,6 +123,8 @@ import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +import de.tudresden.inf.lat.cel.owlapi.CelReasoner; + /** * Mapping to OWL API reasoner interface. The OWL API currently * supports three reasoners: FaCT++, HermiT and Pellet. FaCT++ is connected @@ -169,7 +172,7 @@ // references to OWL API ontologies private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); - @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) + @ConfigOption(name = "reasonerType", description = "The name of the OWL APIReasoner to use {\"fact\", \"hermit\", \"owllink\", \"pellet\", \"elk\", \"cel\"}", defaultValue = "pellet", required = false, propertyEditorClass = StringTrimmerEditor.class) private String reasonerTypeString = "pellet"; @ConfigOption(name = "owlLinkURL", description = "The URL to the owl server", defaultValue = "", required = false, propertyEditorClass = StringTrimmerEditor.class) private String owlLinkURL; @@ -305,6 +308,12 @@ // output will be very large Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); pelletLogger.setLevel(Level.WARN); + } else if (getReasonerTypeString().equals("elk")) { + // instantiate ELK reasoner + reasoner = new ElkReasonerFactory().createNonBufferingReasoner(ontology, conf); + } else if (getReasonerTypeString().equals("cel")) { + // instantiate CEL reasoner + reasoner = new CelReasoner(ontology, conf); } else { try { OWLlinkHTTPXMLReasonerFactory factory = new OWLlinkHTTPXMLReasonerFactory(); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-07-07 11:36:11 UTC (rev 3776) +++ trunk/pom.xml 2012-07-11 12:56:58 UTC (rev 3777) @@ -119,11 +119,6 @@ as version is retrieved from the parent. - - Remember, default scope is compile in Maven. --> <dependencies> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-iri</artifactId> - <version>0.9.1-incubating-20120305.120450-12</version> - </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi</artifactId> @@ -505,6 +500,12 @@ <url>http://maven.aksw.org/archiva/repository/snapshots</url> <snapshots/> </repository> + <repository> + <id>elk.reasoner</id> + <name>ELK Reasoner Repository</name> + <url>http://elk-reasoner.googlecode.com/svn/m2/releases</url> + <releases/> + </repository> </repositories> <distributionManagement> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-07-12 11:14:59
|
Revision: 3782 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3782&view=rev Author: jenslehmann Date: 2012-07-12 11:14:47 +0000 (Thu, 12 Jul 2012) Log Message: ----------- - abstracted hard dependency of CELOE on rho refinement operator - split up refinement operators into multiple interfaces describing their capabilities Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/OperatorInverter.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperator.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperatorAdapter.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomHierarchyRefinementOperator.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomStartRefinementOperator.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ExampleOperator.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/LengthLimitedRefinementOperator.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/ReasoningBasedRefinementOperator.java Removed Paths: ------------- trunk/components-core/src/main/java/nz/ac/ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorFactory.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -15,10 +15,11 @@ import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown2008; -public class ParCELRefinementOperatorFactory extends BasePoolableObjectFactory<RefinementOperator> { +public class ParCELRefinementOperatorFactory extends BasePoolableObjectFactory<LengthLimitedRefinementOperator> { private AbstractReasonerComponent reasoner; private ClassHierarchy classHierarchy; @@ -63,7 +64,7 @@ } @Override - public RefinementOperator makeObject() throws Exception { + public LengthLimitedRefinementOperator makeObject() throws Exception { //clone a new class heirarchy to avoid the competition between refinement operators ClassHierarchy clonedClassHierarchy = this.classHierarchy.clone(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELRefinementOperatorPool.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -9,6 +9,7 @@ import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.Description; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; /** @@ -17,7 +18,7 @@ * @author An C. Tran * */ -public class ParCELRefinementOperatorPool extends StackObjectPool<RefinementOperator> { +public class ParCELRefinementOperatorPool extends StackObjectPool<LengthLimitedRefinementOperator> { /** * Create refinement operator pool given max number of idle object without splitter Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorker.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -7,6 +7,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.owl.Description; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; /** @@ -23,7 +24,7 @@ // refinement operator used in refinement private ParCELRefinementOperatorPool refinementOperatorPool; - private RefinementOperator refinementOperator; + private LengthLimitedRefinementOperator refinementOperator; // reducer, used to make the callback to pass the result and get the next description for // processing @@ -93,7 +94,7 @@ * @param name * Name of the worker, assigned by reduce (for tracing purpose only) */ - public ParCELWorker(ParCELearner learner, RefinementOperator refinementOperator, + public ParCELWorker(ParCELearner learner, LengthLimitedRefinementOperator refinementOperator, ParCELPosNegLP learningProblem, ParCELNode nodeToProcess, String name) { super(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/ParCEL/ParCELWorkerMat.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -8,6 +8,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.owl.Description; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; /** @@ -24,7 +25,7 @@ // refinement operator used in refinement private ParCELRefinementOperatorPool refinementOperatorPool; - private RefinementOperator refinementOperator; + private LengthLimitedRefinementOperator refinementOperator; // reducer, used to make the callback to pass the result and get the next description for // processing @@ -96,7 +97,7 @@ * @param name * Name of the worker, assigned by reduce (for tracing purpose only) */ - public ParCELWorkerMat(ParCELearnerMat learner, RefinementOperator refinementOperator, + public ParCELWorkerMat(ParCELearnerMat learner, LengthLimitedRefinementOperator refinementOperator, ParCELPosNegLP learningProblem, ParCELNode nodeToProcess, String name) { super(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -51,7 +51,11 @@ import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.refinementoperators.CustomHierarchyRefinementOperator; +import org.dllearner.refinementoperators.CustomStartRefinementOperator; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; +import org.dllearner.refinementoperators.ReasoningBasedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.utilities.Files; @@ -86,7 +90,7 @@ // private OEHeuristicStable heuristicStable = new OEHeuristicStable(); // private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); - private RefinementOperator operator; + private LengthLimitedRefinementOperator operator; private DescriptionMinimizer minimizer; @ConfigOption(name="useMinimizer", defaultValue="true", description="Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.") private boolean useMinimizer = true; @@ -282,16 +286,20 @@ if(operator == null) { // we use a default operator and inject the class hierarchy for now operator = new RhoDRDown(); - ((RhoDRDown)operator).setStartClass(startClass); - ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); + if(operator instanceof CustomStartRefinementOperator) { + ((CustomStartRefinementOperator)operator).setStartClass(startClass); + } + if(operator instanceof ReasoningBasedRefinementOperator) { + ((ReasoningBasedRefinementOperator)operator).setReasoner(reasoner); + } + operator.init(); } - // TODO: find a better solution as this is quite difficult to debug - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); - ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); - ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + if(operator instanceof CustomHierarchyRefinementOperator) { + ((CustomHierarchyRefinementOperator)operator).setClassHierarchy(classHierarchy); + ((CustomHierarchyRefinementOperator)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((CustomHierarchyRefinementOperator)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + } - // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); @@ -347,8 +355,11 @@ LinkedList<Description> startClassCandidates = new LinkedList<Description>(); startClassCandidates.add(existingDefinition); - ((RhoDRDown)operator).setDropDisjuncts(true); - RefinementOperator upwardOperator = new OperatorInverter(operator); + // hack for RhoDRDown + if(operator instanceof RhoDRDown) { + ((RhoDRDown)operator).setDropDisjuncts(true); + } + LengthLimitedRefinementOperator upwardOperator = (LengthLimitedRefinementOperator) new OperatorInverter(operator); // use upward refinement until we find an appropriate start class boolean startClassFound = false; @@ -380,7 +391,9 @@ // System.out.println("existing def: " + existingDefinition); // System.out.println(reasoner.getIndividuals(existingDefinition)); - ((RhoDRDown)operator).setDropDisjuncts(false); + if(operator instanceof RhoDRDown) { + ((RhoDRDown)operator).setDropDisjuncts(false); + } } else { Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); @@ -898,12 +911,12 @@ return expressionTests; } - public RefinementOperator getOperator() { + public LengthLimitedRefinementOperator getOperator() { return operator; } @Autowired(required=false) - public void setOperator(RefinementOperator operator) { + public void setOperator(LengthLimitedRefinementOperator operator) { this.operator = operator; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -63,7 +63,11 @@ import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.refinementoperators.CustomHierarchyRefinementOperator; +import org.dllearner.refinementoperators.CustomStartRefinementOperator; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; +import org.dllearner.refinementoperators.ReasoningBasedRefinementOperator; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; import org.dllearner.refinementoperators.SynchronizedRhoDRDown; @@ -99,7 +103,7 @@ // private OEHeuristicStable heuristicStable = new OEHeuristicStable(); // private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); - private RefinementOperator operator; + private LengthLimitedRefinementOperator operator; private DescriptionMinimizer minimizer; @ConfigOption(name="useMinimizer", defaultValue="true", description="Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.") private boolean useMinimizer = true; @@ -297,16 +301,20 @@ if(operator == null) { // we use a default operator and inject the class hierarchy for now operator = new SynchronizedRhoDRDown(); - ((SynchronizedRhoDRDown)operator).setStartClass(startClass); - ((SynchronizedRhoDRDown)operator).setReasoner(reasoner); - ((SynchronizedRhoDRDown)operator).init(); + if(operator instanceof CustomStartRefinementOperator) { + ((CustomStartRefinementOperator)operator).setStartClass(startClass); + } + if(operator instanceof ReasoningBasedRefinementOperator) { + ((ReasoningBasedRefinementOperator)operator).setReasoner(reasoner); + } + operator.init(); } - // TODO: find a better solution as this is quite difficult to debug - ((SynchronizedRhoDRDown)operator).setSubHierarchy(classHierarchy); - ((SynchronizedRhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); - ((SynchronizedRhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + if(operator instanceof CustomHierarchyRefinementOperator) { + ((CustomHierarchyRefinementOperator)operator).setClassHierarchy(classHierarchy); + ((CustomHierarchyRefinementOperator)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((CustomHierarchyRefinementOperator)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + } - // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); baseURI = reasoner.getBaseURI(); prefixes = reasoner.getPrefixes(); @@ -362,8 +370,10 @@ LinkedList<Description> startClassCandidates = new LinkedList<Description>(); startClassCandidates.add(existingDefinition); - ((RhoDRDown)operator).setDropDisjuncts(true); - RefinementOperator upwardOperator = new OperatorInverter(operator); + if(operator instanceof RhoDRDown) { + ((RhoDRDown)operator).setDropDisjuncts(true); + } + LengthLimitedRefinementOperator upwardOperator = (LengthLimitedRefinementOperator) new OperatorInverter(operator); // use upward refinement until we find an appropriate start class boolean startClassFound = false; @@ -395,7 +405,9 @@ // System.out.println("existing def: " + existingDefinition); // System.out.println(reasoner.getIndividuals(existingDefinition)); - ((RhoDRDown)operator).setDropDisjuncts(false); + if(operator instanceof RhoDRDown) { + ((RhoDRDown)operator).setDropDisjuncts(false); + } } else { Set<Description> superClasses = reasoner.getClassHierarchy().getSuperClasses(classToDescribe); @@ -877,7 +889,7 @@ } @Autowired(required=false) - public void setOperator(RefinementOperator operator) { + public void setOperator(LengthLimitedRefinementOperator operator) { this.operator = operator; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/fuzzydll/FuzzyCELOE.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -56,6 +56,7 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; @@ -91,7 +92,7 @@ // private OEHeuristicStable heuristicStable = new OEHeuristicStable(); // private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); - private RefinementOperator operator; + private LengthLimitedRefinementOperator operator; private DescriptionMinimizer minimizer; // all nodes in the search tree (used for selecting most promising node) @@ -332,7 +333,7 @@ LinkedList<Description> startClassCandidates = new LinkedList<Description>(); startClassCandidates.add(existingDefinition); ((RhoDRDown)operator).setDropDisjuncts(true); - RefinementOperator upwardOperator = new OperatorInverter(operator); + LengthLimitedRefinementOperator upwardOperator = (LengthLimitedRefinementOperator) new OperatorInverter(operator); // use upward refinement until we find an appropriate start class boolean startClassFound = false; @@ -926,7 +927,7 @@ } @Autowired(required=false) - public void setOperator(RefinementOperator operator) { + public void setOperator(LengthLimitedRefinementOperator operator) { this.operator = operator; } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/isle/ISLE.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -51,6 +51,7 @@ import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; @@ -80,7 +81,7 @@ // private OEHeuristicStable heuristicStable = new OEHeuristicStable(); // private OEHeuristicRuntime heuristicRuntime = new OEHeuristicRuntime(); - private RefinementOperator operator; + private LengthLimitedRefinementOperator operator; private DescriptionMinimizer minimizer; // all nodes in the search tree (used for selecting most promising node) @@ -246,7 +247,7 @@ LinkedList<Description> startClassCandidates = new LinkedList<Description>(); startClassCandidates.add(existingDefinition); ((RhoDRDown)operator).setDropDisjuncts(true); - RefinementOperator upwardOperator = new OperatorInverter(operator); + LengthLimitedRefinementOperator upwardOperator = (LengthLimitedRefinementOperator) new OperatorInverter(operator); // use upward refinement until we find an appropriate start class boolean startClassFound = false; Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -92,6 +92,8 @@ "org.dllearner.algorithms.celoe.OEHeuristicRuntime", "org.dllearner.refinementoperators.RhoDRDown", "org.dllearner.refinementoperators.SynchronizedRhoDRDown", + // just for testing + "org.dllearner.refinementoperators.ExampleOperator", } )); private static Collection<Class<? extends Component>> components; private static BidiMap<Class<? extends Component>, String> componentNames; Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomHierarchyRefinementOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomHierarchyRefinementOperator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomHierarchyRefinementOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -0,0 +1,43 @@ +/** + * Copyright (C) 2007-2012, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.dllearner.refinementoperators; + +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.ObjectPropertyHierarchy; + + +/** + * + * A refinement operator for which hierarchies other those of the + * reasoner can be injected. Using those hierarchies means that only classes + * from the hierarchies should occur in refinements. + * + * @author Jens Lehmann + * + */ +public interface CustomHierarchyRefinementOperator extends RefinementOperator { + + public void setClassHierarchy(ClassHierarchy classHierarchy); + + public void setObjectPropertyHierarchy(ObjectPropertyHierarchy objectPropertyHierarchy); + + public void setDataPropertyHierarchy(DatatypePropertyHierarchy dataPropertyHierarchy); + +} Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomStartRefinementOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomStartRefinementOperator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/CustomStartRefinementOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2007-2012, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.dllearner.refinementoperators; + +import org.dllearner.core.owl.Description; + +/** + * A refinement operator, which allows to set a start class. + * + * @author Jens Lehmann + * + */ +public interface CustomStartRefinementOperator extends RefinementOperator { + + public void setStartClass(Description description); + +} Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/ExampleOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/ExampleOperator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/ExampleOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -0,0 +1,40 @@ +package org.dllearner.refinementoperators; + +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.owl.Description; + +/** + * Example refinement operator. + * + * @author Jens Lehmann + * + */ +@ComponentAnn(name = "example refinement operator", shortName = "exop", version = 0.8) +public class ExampleOperator implements LengthLimitedRefinementOperator { + + @Override + public void init() throws ComponentInitException { + } + + @Override + public Set<Description> refine(Description description) { + return new TreeSet<Description>(); + } + + @Override + public Set<Description> refine(Description description, int maxLength) { + return refine(description); + } + + @Override + public Set<Description> refine(Description description, int maxLength, + List<Description> knownRefinements) { + return refine(description); + } + +} Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/LengthLimitedRefinementOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/LengthLimitedRefinementOperator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/LengthLimitedRefinementOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -0,0 +1,57 @@ +/** + * Copyright (C) 2007-2012, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.dllearner.refinementoperators; + +import java.util.List; +import java.util.Set; + +import org.dllearner.core.owl.Description; + +/** + * A refinement operator for which the syntactic length of the generated + * refinements can be limited. + * + * @author Jens Lehmann + * + */ +public interface LengthLimitedRefinementOperator extends RefinementOperator { + + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength); + + /** + * Optional refinement operation, where the learning algorithm can + * specify an additional bound on the length of descriptions and + * a list of known refinements, which do not need to be returned. + * + * @param description The description, which will be refined. + * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. + * @param knownRefinements A collection of known refinements, which do not need to be returned. + * @return A set of refinements obeying the above restrictions. + */ + public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements); + +} Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/OperatorInverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/OperatorInverter.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/OperatorInverter.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -37,14 +37,14 @@ * @author Jens Lehmann * */ -public class OperatorInverter implements RefinementOperator { +public class OperatorInverter implements LengthLimitedRefinementOperator { - private RefinementOperator operator; + private LengthLimitedRefinementOperator operator; private ConceptComparator cc = new ConceptComparator(); private boolean useNegationNormalForm = true; private boolean guaranteeLength = true; - public OperatorInverter(RefinementOperator operator) { + public OperatorInverter(LengthLimitedRefinementOperator operator) { this.operator = operator; } Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/ReasoningBasedRefinementOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/ReasoningBasedRefinementOperator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/ReasoningBasedRefinementOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2007-2012, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +package org.dllearner.refinementoperators; + +import org.dllearner.core.Reasoner; + +/** + * A refinement operator, which uses an underlying reasoner, which is a typical + * scenario. + * + * @author Jens Lehmann + * + */ +public interface ReasoningBasedRefinementOperator extends RefinementOperator { + + public void setReasoner(Reasoner reasoner); + +} Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperator.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperator.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -44,26 +44,4 @@ */ public Set<Description> refine(Description description); - /** - * Optional refinement operation, where the learning algorithm can - * specify an additional bound on the length of descriptions. - * - * @param description The description, which will be refined. - * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. - * @return A set of refinements obeying the above restrictions. - */ - public Set<Description> refine(Description description, int maxLength); - - /** - * Optional refinement operation, where the learning algorithm can - * specify an additional bound on the length of descriptions and - * a list of known refinements, which do not need to be returned. - * - * @param description The description, which will be refined. - * @param maxLength The maximum length of returned description, where length is defined by {@link Description#getLength()}. - * @param knownRefinements A collection of known refinements, which do not need to be returned. - * @return A set of refinements obeying the above restrictions. - */ - public Set<Description> refine(Description description, int maxLength, List<Description> knownRefinements); - } Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperatorAdapter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperatorAdapter.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RefinementOperatorAdapter.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -30,7 +30,7 @@ * @author Jens Lehmann * */ -public abstract class RefinementOperatorAdapter implements RefinementOperator { +public abstract class RefinementOperatorAdapter implements LengthLimitedRefinementOperator { /* (non-Javadoc) * @see org.dllearner.refinementoperators.RefinementOperator#refine(org.dllearner.core.owl.Description) Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -38,6 +38,7 @@ import org.dllearner.core.Component; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.Reasoner; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.CommonConfigOptions; @@ -92,7 +93,7 @@ * */ @ComponentAnn(name = "rho refinement operator", shortName = "rho", version = 0.8) -public class RhoDRDown extends RefinementOperatorAdapter implements Component { +public class RhoDRDown extends RefinementOperatorAdapter implements Component, CustomHierarchyRefinementOperator, CustomStartRefinementOperator, ReasoningBasedRefinementOperator { private static Logger logger = Logger .getLogger(RhoDRDown.class); @@ -1710,4 +1711,14 @@ public void setDataPropertyHierarchy(DatatypePropertyHierarchy dataPropertyHierarchy) { this.dataPropertyHierarchy = dataPropertyHierarchy; } + + @Override + public void setReasoner(Reasoner reasoner) { + this.reasoner = (AbstractReasonerComponent) reasoner; + } + + @Override + public void setClassHierarchy(ClassHierarchy classHierarchy) { + subHierarchy = classHierarchy; + } } \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -38,6 +38,7 @@ import org.dllearner.core.Component; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.Reasoner; import org.dllearner.core.config.BooleanEditor; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.CommonConfigOptions; @@ -92,7 +93,7 @@ * */ @ComponentAnn(name = "synchronized rho refinement operator", shortName = "syncrho", version = 0.8) -public class SynchronizedRhoDRDown extends RefinementOperatorAdapter implements Component { +public class SynchronizedRhoDRDown extends RefinementOperatorAdapter implements Component, CustomHierarchyRefinementOperator, CustomStartRefinementOperator, ReasoningBasedRefinementOperator { private static Logger logger = Logger .getLogger(SynchronizedRhoDRDown.class); @@ -1710,4 +1711,15 @@ public void setDataPropertyHierarchy(DatatypePropertyHierarchy dataPropertyHierarchy) { this.dataPropertyHierarchy = dataPropertyHierarchy; } + + @Override + public void setReasoner(Reasoner reasoner) { + this.reasoner = (AbstractReasonerComponent) reasoner; + } + + @Override + public void setClassHierarchy(ClassHierarchy classHierarchy) { + subHierarchy = classHierarchy; + } + } \ No newline at end of file Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -42,6 +42,7 @@ import org.dllearner.parser.KBParser; import org.dllearner.parser.ParseException; import org.dllearner.reasoning.OWLAPIReasoner; +import org.dllearner.refinementoperators.LengthLimitedRefinementOperator; import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; @@ -247,7 +248,7 @@ op.setDropDisjuncts(true); op.init(); - RefinementOperator operator = new OperatorInverter(op); + LengthLimitedRefinementOperator operator = new OperatorInverter(op); Description concept = KBParser.parseConcept("(limo AND EXISTS hasOwner.man)"); Set<Description> refinements = operator.refine(concept, 6); for(Description refinement : refinements) { Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-07-12 10:19:48 UTC (rev 3781) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-07-12 11:14:47 UTC (rev 3782) @@ -198,6 +198,8 @@ } catch (Exception e) { String stacktraceFileName = "log/error.log"; +// e.printStackTrace(); + //Find the primary cause of the exception. Throwable primaryCause = findPrimaryCause(e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 08:19:59
|
Revision: 3786 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3786&view=rev Author: lorenz_b Date: 2012-07-13 08:19:48 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Updated JENA dependencies. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java trunk/components-core/src/main/java/org/dllearner/utilities/Files.java trunk/pom.xml Modified: trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java 2012-07-13 08:19:48 UTC (rev 3786) @@ -25,8 +25,8 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; +import java.util.StringTokenizer; -import com.ibm.icu.util.StringTokenizer; /** * @author Jens Lehmann Modified: trunk/components-core/src/main/java/org/dllearner/utilities/Files.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/Files.java 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/components-core/src/main/java/org/dllearner/utilities/Files.java 2012-07-13 08:19:48 UTC (rev 3786) @@ -34,8 +34,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.StringTokenizer; -import com.ibm.icu.util.StringTokenizer; /** * @author Jens Lehmann Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/pom.xml 2012-07-13 08:19:48 UTC (rev 3786) @@ -180,7 +180,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-core</artifactId> - <version>2.7.1-incubating-SNAPSHOT</version> + <version>2.7.2</version> </dependency> <!--SwingX is in central --> <dependency> @@ -240,7 +240,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-arq</artifactId> - <version>2.9.1-incubating-SNAPSHOT</version> + <version>2.9.2</version> </dependency> <!--Junits --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-08-23 12:50:07
|
Revision: 3831 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3831&view=rev Author: kirdie Date: 2012-08-23 12:49:55 +0000 (Thu, 23 Aug 2012) Log Message: ----------- more oxford test code. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-08-23 08:40:43 UTC (rev 3830) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-08-23 12:49:55 UTC (rev 3831) @@ -460,7 +460,7 @@ T values = map.get(key); if(values == null){ try { - values = (T) values.getClass().newInstance(); + values = (T) value.getClass().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-08-23 08:40:43 UTC (rev 3830) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-08-23 12:49:55 UTC (rev 3831) @@ -93,119 +93,119 @@ import com.jamonapi.MonitorFactory; public class SPARQLTemplateBasedLearner2 implements SparqlQueryLearningAlgorithm{ - + enum Mode{ BEST_QUERY, BEST_NON_EMPTY_QUERY } - + private Mode mode = Mode.BEST_QUERY; - + private static final Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner2.class); private Monitor templateMon = MonitorFactory.getTimeMonitor("template"); private Monitor sparqlMon = MonitorFactory.getTimeMonitor("sparql"); - + private boolean useRemoteEndpointValidation; private boolean stopIfQueryResultNotEmpty; private int maxTestedQueriesPerTemplate = 50; private int maxQueryExecutionTimeInSeconds; private int maxTestedQueries = 200; private int maxIndexResults; - - private SparqlEndpoint endpoint; - private Model model; - + + private SparqlEndpoint endpoint = null; + private Model model = null; + private ExtractionDBCache cache = new ExtractionDBCache("cache"); - + private Index resourcesIndex; private Index classesIndex; private Index propertiesIndex; - + private Index datatypePropertiesIndex; private Index objectPropertiesIndex; - + private MappingBasedIndex mappingIndex; - - private Templator templateGenerator; + + private Templator templateGenerator = null; private Lemmatizer lemmatizer; private PartOfSpeechTagger posTagger; private WordNet wordNet; - + private String question; private int learnedPos = -1; - + private Set<Template> templates; private Map<Template, Collection<? extends Query>> template2Queries; private Map<Slot, List<String>> slot2URI; - + private Collection<WeightedQuery> sparqlQueryCandidates; private SortedSet<WeightedQuery> learnedSPARQLQueries; private SortedSet<WeightedQuery> generatedQueries; - + private SPARQLReasoner reasoner; - + private String currentlyExecutedQuery; - + private boolean dropZeroScoredQueries = true; private boolean useManualMappingsIfExistOnly = true; - + private boolean multiThreaded = true; - + private String [] grammarFiles = new String[]{"tbsl/lexicon/english.lex"}; - + private PopularityMap popularityMap; - + private Set<String> relevantKeywords; - + private boolean useDomainRangeRestriction = true; - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger()); } - + public SPARQLTemplateBasedLearner2(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options); } - + public SPARQLTemplateBasedLearner2(Knowledgebase knowledgebase){ this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index){ this(endpoint, index, new StanfordPartOfSpeechTagger()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, new WordNet(), new Options()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger){ this(endpoint, index, posTagger, new WordNet(), new Options()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, WordNet wordNet){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger(), wordNet, new Options()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index, WordNet wordNet){ this(endpoint, index, new StanfordPartOfSpeechTagger(), wordNet, new Options()); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, new Options(), new ExtractionDBCache("cache")); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger, WordNet wordNet){ this(endpoint, index, index, index, posTagger, wordNet, new Options(), new ExtractionDBCache("cache")); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ this(endpoint, index, index, index, posTagger, wordNet, options, new ExtractionDBCache("cache")); } - + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ this.endpoint = endpoint; this.resourcesIndex = resourcesIndex; @@ -214,9 +214,9 @@ this.posTagger = posTagger; this.wordNet = wordNet; this.cache = cache; - + setOptions(options); - + if(propertiesIndex instanceof SPARQLPropertiesIndex){ if(propertiesIndex instanceof VirtuosoPropertiesIndex){ datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); @@ -231,29 +231,29 @@ } reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cache); } - + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ this(model, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger()); } - + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger){ this(model, resourcesIndex, classesIndex, propertiesIndex, posTagger, new WordNet(), new Options()); } - + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, WordNet wordNet){ this(model, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger(), wordNet, new Options()); } - + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ this(model, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); } - + public SPARQLTemplateBasedLearner2(Model model, MappingBasedIndex mappingBasedIndex, PartOfSpeechTagger posTagger) { this(model, new SPARQLIndex(model),new SPARQLIndex(model),new SPARQLIndex(model),posTagger); setMappingIndex(mappingBasedIndex); } - + public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ this.model = model; this.resourcesIndex = resourcesIndex; @@ -262,9 +262,9 @@ this.posTagger = posTagger; this.wordNet = wordNet; this.cache = cache; - + setOptions(options); - + if(propertiesIndex instanceof SPARQLPropertiesIndex){ if(propertiesIndex instanceof VirtuosoPropertiesIndex){ datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); @@ -279,25 +279,27 @@ } reasoner = new SPARQLReasoner(new LocalModelBasedSparqlEndpointKS(ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM, model)), cache); } - - public void setGrammarFiles(String[] grammarFiles){ + + public void setGrammarFiles(String[] grammarFiles) + { + if(templateGenerator==null) {throw new AssertionError("Learner not initialized. Please call init();");} templateGenerator.setGrammarFiles(grammarFiles); } - + @Override public void init() throws ComponentInitException { - templateGenerator = new Templator(posTagger, wordNet, grammarFiles); - lemmatizer = new LingPipeLemmatizer(); + templateGenerator = new Templator(posTagger, wordNet, grammarFiles); + lemmatizer = new LingPipeLemmatizer(); } - + public void setMappingIndex(MappingBasedIndex mappingIndex) { this.mappingIndex = mappingIndex; } - + public void setCache(ExtractionDBCache cache) { this.cache = cache; } - + public void setKnowledgebase(Knowledgebase knowledgebase){ this.endpoint = knowledgebase.getEndpoint(); this.resourcesIndex = knowledgebase.getResourceIndex(); @@ -318,28 +320,28 @@ } reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); } - + public void setUseDomainRangeRestriction(boolean useDomainRangeRestriction) { this.useDomainRangeRestriction = useDomainRangeRestriction; } - + /* * Only for Evaluation useful. */ public void setUseIdealTagger(boolean value){ templateGenerator.setUNTAGGED_INPUT(!value); } - + private void setOptions(Options options){ maxIndexResults = Integer.parseInt(options.get("solr.query.limit", "10")); - + maxQueryExecutionTimeInSeconds = Integer.parseInt(options.get("sparql.query.maxExecutionTimeInSeconds", "20")); cache.setMaxExecutionTimeInSeconds(maxQueryExecutionTimeInSeconds); - + useRemoteEndpointValidation = options.get("learning.validationType", "remote").equals("remote") ? true : false; stopIfQueryResultNotEmpty = Boolean.parseBoolean(options.get("learning.stopAfterFirstNonEmptyQueryResult", "true")); maxTestedQueriesPerTemplate = Integer.parseInt(options.get("learning.maxTestedQueriesPerTemplate", "20")); - + String wordnetPath = options.get("wordnet.dictionary", "tbsl/dict"); wordnetPath = this.getClass().getClassLoader().getResource(wordnetPath).getPath(); System.setProperty("wordnet.database.dir", wordnetPath); @@ -347,20 +349,20 @@ public void setEndpoint(SparqlEndpoint endpoint){ this.endpoint = endpoint; - + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); reasoner.setCache(cache); reasoner.prepareSubsumptionHierarchy(); } - + public void setQuestion(String question){ this.question = question; } - + public void setUseRemoteEndpointValidation(boolean useRemoteEndpointValidation){ this.useRemoteEndpointValidation = useRemoteEndpointValidation; } - + public int getMaxQueryExecutionTimeInSeconds() { return maxQueryExecutionTimeInSeconds; } @@ -383,11 +385,11 @@ slot2URI = new HashMap<Slot, List<String>>(); relevantKeywords = new HashSet<String>(); currentlyExecutedQuery = null; - -// templateMon.reset(); -// sparqlMon.reset(); + + // templateMon.reset(); + // sparqlMon.reset(); } - + public void learnSPARQLQueries() throws NoTemplateFoundException{ reset(); //generate SPARQL query templates @@ -403,13 +405,13 @@ relevantKeywords.addAll(templateGenerator.getUnknownWords()); if(templates.isEmpty()){ throw new NoTemplateFoundException(); - + } logger.debug("Templates:"); for(Template t : templates){ logger.debug(t); } - + //get the weighted query candidates generatedQueries = getWeightedSPARQLQueries(templates); sparqlQueryCandidates = new ArrayList<WeightedQuery>(); @@ -422,7 +424,7 @@ } i++; } - + if(mode == Mode.BEST_QUERY){ double bestScore = -1; for(WeightedQuery candidate : generatedQueries){ @@ -439,15 +441,15 @@ if(useRemoteEndpointValidation){ //on remote endpoint validateAgainstRemoteEndpoint(sparqlQueryCandidates); } else {//on local model - + } } } - + public SortedSet<WeightedQuery> getGeneratedQueries() { return generatedQueries; } - + public SortedSet<WeightedQuery> getGeneratedQueries(int topN) { SortedSet<WeightedQuery> topNQueries = new TreeSet<WeightedQuery>(); int max = Math.min(topN, generatedQueries.size()); @@ -459,28 +461,28 @@ } return topNQueries; } - + public Set<Template> getTemplates(){ return templates; } - + public List<String> getGeneratedSPARQLQueries(){ List<String> queries = new ArrayList<String>(); for(WeightedQuery wQ : sparqlQueryCandidates){ queries.add(wQ.getQuery().toString()); } - + return queries; } - + public Map<Template, Collection<? extends Query>> getTemplates2SPARQLQueries(){ return template2Queries; } - + public Map<Slot, List<String>> getSlot2URIs(){ return slot2URI; } - + private void normProminenceValues(Set<Allocation> allocations){ double min = 0; double max = 0; @@ -497,25 +499,25 @@ a.setProminence(prominence); } } - + private void computeScore(Set<Allocation> allocations){ double alpha = 0.8; double beta = 1 - alpha; - + for(Allocation a : allocations){ double score = alpha * a.getSimilarity() + beta * a.getProminence(); a.setScore(score); } - + } - + public Set<String> getRelevantKeywords(){ return relevantKeywords; } - + private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ logger.debug("Generating SPARQL query candidates..."); - + Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { @Override @@ -528,23 +530,22 @@ } }); slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); - - + + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); - + Set<Allocation> allocations; - + for(Template t : templates){ - logger.info("Processing template:\n" + t.toString()); - System.err.println(QueryFactory.create(t.getQuery().toString(), Syntax.syntaxSPARQL_11)); + logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); - + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); - + long startTime = System.currentTimeMillis(); - + for (Slot slot : t.getSlots()) { if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); @@ -552,7 +553,7 @@ list.add(submit); } } - + for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { try { Map<Slot, SortedSet<Allocation>> result = future.get(); @@ -564,10 +565,10 @@ e.printStackTrace(); } } - + executor.shutdown(); - - + + /*for(Slot slot : t.getSlots()){ allocations = slot2Allocations2.get(slot); if(allocations == null){ @@ -575,7 +576,7 @@ slot2Allocations2.put(slot, allocations); } slot2Allocations.put(slot, allocations); - + //for tests add the property URI with http://dbpedia.org/property/ namespace //TODO should be replaced by usage of a separate SOLR index Set<Allocation> tmp = new HashSet<Allocation>(); @@ -590,11 +591,11 @@ allocations.addAll(tmp); }*/ logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); - + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); Query cleanQuery = t.getQuery(); queries.add(new WeightedQuery(cleanQuery)); - + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); List<Slot> sortedSlots = new ArrayList<Slot>(); Set<Slot> classSlots = new HashSet<Slot>(); @@ -628,125 +629,125 @@ queries.addAll(tmp); tmp.clear(); } - + for(Slot slot : sortedSlots){ if(!slot2Allocations.get(slot).isEmpty()){ for(Allocation a : slot2Allocations.get(slot)){ for(WeightedQuery query : queries){ - Query q = new Query(query.getQuery()); - - boolean drop = false; - if(useDomainRangeRestriction){ - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - String objectVar = triple.getValue().getName(); - String subjectVar = triple.getVariable().getName(); -// System.out.println(triple); - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ -// System.out.println(typeTriple); - if(true){//reasoner.isObjectProperty(a.getUri())){ - Description range = reasoner.getRange(new ObjectProperty(a.getUri())); -// System.out.println(a); - if(range != null){ - Set<Description> allRanges = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(range instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(range); - allRanges.addAll(superClasses); - } else { - for(Description nc : range.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allRanges.addAll(superClasses); - } - } - allRanges.add(range); - allRanges.remove(new NamedClass(Thing.instance.getURI())); - - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ - drop = true; - } - } - } else { - drop = true; - } - - } - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ - Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); -// System.out.println(a); - if(domain != null){ - Set<Description> allDomains = new HashSet<Description>(); + Query q = new Query(query.getQuery()); + + boolean drop = false; + if(useDomainRangeRestriction){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + String objectVar = triple.getValue().getName(); + String subjectVar = triple.getVariable().getName(); + // System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ + // System.out.println(typeTriple); + if(true){//reasoner.isObjectProperty(a.getUri())){ + Description range = reasoner.getRange(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(range != null){ + Set<Description> allRanges = new HashSet<Description>(); SortedSet<Description> superClasses; - if(domain instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(domain); - allDomains.addAll(superClasses); + if(range instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(range); + allRanges.addAll(superClasses); } else { - for(Description nc : domain.getChildren()){ + for(Description nc : range.getChildren()){ superClasses = reasoner.getSuperClasses(nc); - allDomains.addAll(superClasses); + allRanges.addAll(superClasses); } } - allDomains.add(domain); - allDomains.remove(new NamedClass(Thing.instance.getURI())); - + allRanges.add(range); + allRanges.remove(new NamedClass(Thing.instance.getURI())); + Set<Description> allTypes = new HashSet<Description>(); String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); Description type = new NamedClass(typeURI); superClasses = reasoner.getSuperClasses(type); allTypes.addAll(superClasses); allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ - drop = true; - } else { - + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } + } + } else { + drop = true; + } + + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ + Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(domain != null){ + Set<Description> allDomains = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(domain instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(domain); + allDomains.addAll(superClasses); + } else { + for(Description nc : domain.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allDomains.addAll(superClasses); } } + allDomains.add(domain); + allDomains.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + + } } } } } - - if(!drop){ - if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - SPARQL_Value object = triple.getValue(); - if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position - SPARQL_Property predicate = triple.getProperty(); - if(!predicate.isVariable()){//only consider triple where predicate is URI - String predicateURI = predicate.getName().replace("<", "").replace(">", ""); - if(isDatatypeProperty(predicateURI)){//if data property - q.addFilter(new SPARQL_Filter(new SPARQL_Pair( - object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); - } + } + + if(!drop){ + if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); } else { q.replaceVarWithURI(slot.getAnchor(), a.getUri()); } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); } - } else { - q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } } - WeightedQuery w = new WeightedQuery(q); - double newScore = query.getScore() + a.getScore(); - w.setScore(newScore); - w.addAllocations(query.getAllocations()); - w.addAllocation(a); - tmp.add(w); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); } - - + WeightedQuery w = new WeightedQuery(q); + double newScore = query.getScore() + a.getScore(); + w.setScore(newScore); + w.addAllocations(query.getAllocations()); + w.addAllocation(a); + tmp.add(w); + } + + } } //lower queries with FILTER-REGEX @@ -755,7 +756,7 @@ wQ.setScore(wQ.getScore() - 0.01); } } - + queries.clear(); queries.addAll(tmp);//System.out.println(tmp); tmp.clear(); @@ -776,9 +777,9 @@ } } } - + } - + } else { if(slot.getSlotType() == SlotType.SYMPROPERTY){ for(WeightedQuery wQ : queries){ @@ -800,50 +801,50 @@ List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); for(SPARQL_Triple typeTriple : typeTriples){ String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); -// List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); -// for(Entry<String, Integer> property : mostFrequentProperties){ -// wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); -// wQ.setScore(wQ.getScore() + 0.1); -// } + // List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); + // for(Entry<String, Integer> property : mostFrequentProperties){ + // wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); + // wQ.setScore(wQ.getScore() + 0.1); + // } } - + } } } } -// else if(slot.getSlotType() == SlotType.CLASS){ -// String token = slot.getWords().get(0); -// if(slot.getToken().contains("house")){ -// String regexToken = token.replace("houses", "").replace("house", "").trim(); -// try { -// Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); -// SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); -// if(alloc != null && !alloc.isEmpty()){ -// String uri = alloc.first().getUri(); -// for(WeightedQuery query : queries){ -// Query q = query.getQuery(); -// for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ -// SPARQL_Term subject = triple.getVariable(); -// SPARQL_Term object = new SPARQL_Term("desc"); -// object.setIsVariable(true); -// object.setIsURI(false); -// q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); -// q.addFilter(new SPARQL_Filter(new SPARQL_Pair( -// object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); -// } -// q.replaceVarWithURI(slot.getAnchor(), uri); -// -// } -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } -// } - - + // else if(slot.getSlotType() == SlotType.CLASS){ + // String token = slot.getWords().get(0); + // if(slot.getToken().contains("house")){ + // String regexToken = token.replace("houses", "").replace("house", "").trim(); + // try { + // Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); + // SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); + // if(alloc != null && !alloc.isEmpty()){ + // String uri = alloc.first().getUri(); + // for(WeightedQuery query : queries){ + // Query q = query.getQuery(); + // for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + // SPARQL_Term subject = triple.getVariable(); + // SPARQL_Term object = new SPARQL_Term("desc"); + // object.setIsVariable(true); + // object.setIsURI(false); + // q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); + // q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + // object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); + // } + // q.replaceVarWithURI(slot.getAnchor(), uri); + // + // } + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + // } + + } - + } for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { WeightedQuery wQ = iterator.next(); @@ -852,9 +853,10 @@ iterator.remove(); } } else { + if(t.getSlots().size()==0) throw new AssertionError("no slots for query "+wQ); wQ.setScore(wQ.getScore()/t.getSlots().size()); } - + } allQueries.addAll(queries); List<Query> qList = new ArrayList<Query>(); @@ -866,7 +868,7 @@ logger.debug("...done in "); return allQueries; } - + private double getProminenceValue(String uri, SlotType type){ Integer popularity = null; if(popularityMap != null){ @@ -890,7 +892,7 @@ query = "SELECT COUNT(*) WHERE {?s ?p <%s>}"; } query = String.format(query, uri); - + ResultSet rs = executeSelect(query); QuerySolution qs; String projectionVar; @@ -903,20 +905,20 @@ if(popularity == null){ popularity = Integer.valueOf(0); } - - -// if(cnt == 0){ -// return 0; -// } -// return Math.log(cnt); + + + // if(cnt == 0){ + // return 0; + // } + // return Math.log(cnt); return popularity; } - + public void setPopularityMap(PopularityMap popularityMap) { this.popularityMap = popularityMap; } - - + + private List<String> pruneList(List<String> words){ List<String> prunedList = new ArrayList<String>(); for(String w1 : words){ @@ -934,13 +936,13 @@ } } logger.info("Pruned list: " + prunedList); -// return getLemmatizedWords(words); + // return getLemmatizedWords(words); return prunedList; } - + private List<String> getLemmatizedWords(List<String> words){ logger.info("Pruning word list " + words + "..."); -// mon.start(); + // mon.start(); List<String> pruned = new ArrayList<String>(); for(String word : words){ //currently only stem single words @@ -952,15 +954,15 @@ pruned.add(lemWord); } } - + } -// mon.stop(); -// logger.info("Done in " + mon.getLastValue() + "ms."); + // mon.stop(); + // logger.info("Done in " + mon.getLastValue() + "ms."); logger.info("Pruned list: " + pruned); return pruned; } - - + + private Index getIndexBySlotType(Slot slot){ Index index = null; SlotType type = slot.getSlotType(); @@ -977,12 +979,12 @@ } return index; } - + private void validateAgainstRemoteEndpoint(Collection<WeightedQuery> queries){ SPARQL_QueryType queryType = queries.iterator().next().getQuery().getQt(); validate(queries, queryType); } - + private void validate(Collection<WeightedQuery> queries, SPARQL_QueryType queryType){ logger.debug("Testing candidate SPARQL queries on remote endpoint..."); sparqlMon.start(); @@ -995,7 +997,7 @@ com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); q.setLimit(1); ResultSet rs = executeSelect(q.toString()); - + results = new ArrayList<String>(); QuerySolution qs; String projectionVar; @@ -1007,7 +1009,7 @@ } else if(qs.get(projectionVar).isURIResource()){ results.add(qs.get(projectionVar).asResource().getURI()); } - + } if(!results.isEmpty()){ try{ @@ -1029,7 +1031,7 @@ } catch (Exception e) { e.printStackTrace(); } - + } } else if(queryType == SPARQL_QueryType.ASK){ for(WeightedQuery query : queries){ @@ -1037,31 +1039,39 @@ logger.debug("Testing query:\n" + query); boolean result = executeAskQuery(query.getQuery().toString()); learnedSPARQLQueries.add(query); -// if(stopIfQueryResultNotEmpty && result){ -// return; -// } + // if(stopIfQueryResultNotEmpty && result){ + // return; + // } if(stopIfQueryResultNotEmpty){ return; } logger.debug("Result: " + result); } } - + sparqlMon.stop(); logger.debug("Done in " + sparqlMon.getLastValue() + "ms."); } - - private boolean executeAskQuery(String query){ - currentlyExecutedQuery = query; - QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), query); - for(String uri : endpoint.getDefaultGraphURIs()){ - qe.addDefaultGraph(uri); + + private boolean executeAskQuery(String query) + { + if(query==null) throw new NullPointerException("Parameter query == null"); + currentlyExecutedQuery = query; + + boolean ret; + if (model == null) + { + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), query); + qe.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + ret = qe.execAsk(); } - boolean ret = qe.execAsk(); + else {ret = QueryExecutionFactory.create(QueryFactory.create(query, Syntax.syntaxARQ), model).execAsk();} return ret; } - - private ResultSet executeSelect(String query) { + + private ResultSet executeSelect(String query) + { + if(query==null) throw new NullPointerException("Parameter query == null"); currentlyExecutedQuery = query; ResultSet rs; if (model == null) { @@ -1076,14 +1086,14 @@ rs = QueryExecutionFactory.create(QueryFactory.create(query, Syntax.syntaxARQ), model) .execSelect(); } - + return rs; } - + public String getCurrentlyExecutedQuery() { return currentlyExecutedQuery; } - + public int getLearnedPosition() { if(learnedPos >= 0){ return learnedPos+1; @@ -1112,7 +1122,7 @@ return null; } } - + public SortedSet<WeightedQuery> getLearnedSPARQLQueries() { return learnedSPARQLQueries; } @@ -1126,13 +1136,13 @@ @Override public void setLearningProblem(LearningProblem learningProblem) { // TODO Auto-generated method stub - + } - + class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ - + private Slot slot; - + public SlotProcessor(Slot slot) { this.slot = slot; } @@ -1143,13 +1153,13 @@ result.put(slot, computeAllocations(slot)); return result; } - + private SortedSet<Allocation> computeAllocations(Slot slot){ logger.debug("Computing allocations for slot: " + slot); SortedSet<Allocation> allocations = new TreeSet<Allocation>(); - + Index index = getIndexBySlotType(slot); - + IndexResultSet rs; for(String word : slot.getWords()){ rs = new IndexResultSet(); @@ -1178,33 +1188,33 @@ rs.add(index.getResourcesWithScores(word, 20)); } } - - + + for(IndexResultItem item : rs.getItems()){ double similarity = Similarity.getSimilarity(word, item.getLabel()); -// //get the labels of the redirects and compute the highest similarity -// if(slot.getSlotType() == SlotType.RESOURCE){ -// Set<String> labels = getRedirectLabels(item.getUri()); -// for(String label : labels){ -// double tmp = Similarity.getSimilarity(word, label); -// if(tmp > similarity){ -// similarity = tmp; -// } -// } -// } + // //get the labels of the redirects and compute the highest similarity + // if(slot.getSlotType() == SlotType.RESOURCE){ + // Set<String> labels = getRedirectLabels(item.getUri()); + // for(String label : labels){ + // double tmp = Similarity.getSimilarity(word, label); + // if(tmp > similarity){ + // similarity = tmp; + // } + // } + // } double prominence = getProminenceValue(item.getUri(), slot.getSlotType()); allocations.add(new Allocation(item.getUri(), prominence, similarity)); } - + } - + normProminenceValues(allocations); - + computeScore(allocations); logger.debug("Found " + allocations.size() + " allocations for slot " + slot); return new TreeSet<Allocation>(allocations); } - + private Index getIndexBySlotType(Slot slot){ Index index = null; SlotType type = slot.getSlotType(); @@ -1221,13 +1231,15 @@ } return index; } - + } - - public String getTaggedInput(){ + + public String getTaggedInput() + { + if(templateGenerator==null) {throw new AssertionError("Learner not initialized. Please call init();");} return templateGenerator.getTaggedInput(); } - + private boolean isDatatypeProperty(String uri){ Boolean isDatatypeProperty = null; if(mappingIndex != null){ @@ -1239,7 +1251,7 @@ } return isDatatypeProperty; } - + /** * @param args * @throws NoTemplateFoundException @@ -1253,20 +1265,20 @@ Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); - + SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); learner.init(); - + String question = "What is the highest mountain?"; - + learner.setQuestion(question); learner.learnSPARQLQueries(); System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); System.out.println(learner.getLearnedPosition()); - + } - + } Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-08-23 08:40:43 UTC (rev 3830) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SPARQLIndex.java 2012-08-23 12:49:55 UTC (rev 3831) @@ -127,7 +127,7 @@ return irs; } - private ResultSet executeSelect(String query){System.out.println(query); + private ResultSet executeSelect(String query){ ResultSet rs; if(model == null){ if(cache == null){ Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-08-23 08:40:43 UTC (rev 3830) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-08-23 12:49:55 UTC (rev 3831) @@ -4,10 +4,8 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -15,7 +13,6 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; -import java.net.URL; import java.net.URLDecoder; import java.text.DateFormat; import java.util.Collection; @@ -61,17 +58,13 @@ import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; import org.dllearner.common.index.SOLRIndex; -import org.dllearner.common.index.SPARQLClassesIndex; -import org.dllearner.common.index.SPARQLIndex; -import org.dllearner.common.index.VirtuosoClassesIndex; -import org.dllearner.common.index.VirtuosoResourcesIndex; import org.dllearner.core.ComponentInitException; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.ini4j.Options; -import org.junit.*; -import org.w3c.dom.DOMException; +import org.junit.Before; +import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -111,16 +104,16 @@ {test("QALD 2 Benchmark ideally tagged", new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml").getFile()), SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache);} - @Test public void testOxford() throws IOException + @Test public void generateXMLOxford() throws IOException { Model m = loadOxfordModel(); List<String> questions = new LinkedList<String>(); BufferedReader in = new BufferedReader((new InputStreamReader(getClass().getClassLoader().getResourceAsStream("tbsl/oxford_eval_queries.txt")))); int j=0; - for(String line=in.readLine();line!=null;) + for(String line;(line=in.readLine())!=null;) { j++; - if(j>5) break; + if(j>1) break; if(!line.isEmpty()) {questions.add(line.replace("question: ", ""));} } in.close(); @@ -133,7 +126,8 @@ SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() ); - generateTestDataMultiThreaded(id2Question, null,m,mappingIndex,OXFORD_PRETAGGED); + QueryTestData testData = generateTestDataMultiThreaded(id2Question, null,m,mappingIndex,OXFORD_PRETAGGED); + testData.writeQaldXml(new File("log/test.xml")); } private Model loadOxfordModel() @@ -250,7 +244,7 @@ generateUpdatedXML(referenceXML,updatedReferenceXML,endpoint,cache); } - QueryTestData referenceTestData = readQueries(updatedReferenceXML); + QueryTestData referenceTestData = QueryTestData.readQaldXml(updatedReferenceXML); logger.info(title+" subset loaded with "+referenceTestData.id2Question.size()+" questions."); long startLearning = System.currentTimeMillis(); @@ -463,7 +457,7 @@ } } - private static class LearnStatus implements Serializable + public static class LearnStatus implements Serializable { public enum Type {OK, TIMEOUT, NO_TEMPLATE_FOUND,QUERY_RESULT_EMPTY,NO_QUERY_LEARNED,EXCEPTION} @@ -693,14 +687,13 @@ // private SPARQLTemplateBasedLearner2 oxfordLearner; // private SPARQLTemplateBasedLearner2 dbpediaLiveLearner; - private final ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); +// private final ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); private final static ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); private final Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); static final SparqlEndpoint dbpediaLiveEndpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); //static SparqlEndpoint oxfordEndpoint; - private static final int MAXIMUM_QUESTIONS = Integer.MAX_VALUE; // private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} @@ -732,7 +725,7 @@ Logger.getRootLogger().setLevel(Level.WARN); Logger.getLogger(Templator.class).setLevel(Level.WARN); Logger.getLogger(Parser.class).setLevel(Level.WARN); - Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.WARN); + Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.INFO); // Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.INFO); logger.setLevel(Level.INFO); // TODO: remove when finishing implementation of this class logger.addAppender(new FileAppender(new SimpleLayout(), "log/"+this.getClass().getSimpleName()+".log", false)); @@ -741,131 +734,7 @@ // oxfordLearner = new SPARQLTemplateBasedLearner2(createOxfordKnowledgebase(oxfordCache)); } - private static class QueryTestData implements Serializable - { - public SortedMap<Integer, String> id2Question = new ConcurrentSkipListMap<Integer, String>(); - public SortedMap<Integer, String> id2Query = new ConcurrentSkipListMap<Integer, String>(); - public SortedMap<Integer, Set<String>> id2Answers = new ConcurrentSkipListMap<Integer, Set<String>>(); - public SortedMap<Integer, LearnStatus> id2LearnStatus = new ConcurrentSkipListMap<Integer, LearnStatus>(); - - private static final String persistancePath = "cache/"+SPARQLTemplateBasedLearner3Test.class.getSimpleName()+'/'+QueryTestData.class.getSimpleName(); - - public synchronized void write() - { - try - { - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(persistancePath))); - oos.writeObject(this); - oos.close(); - } catch(IOException e) {throw new RuntimeException(e);} - } - - public static QueryTestData read() throws FileNotFoundException, IOException - { - try - { - ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(persistancePath))); - QueryTestData testData = (QueryTestData) ois.readObject(); - ois.close(); - return testData; - } - catch (ClassNotFoundException e){throw new RuntimeException(e);} - } - - public QueryTestData generateAnswers(SparqlEndpoint endpoint, ExtractionDBCache cache) - { - if(!id2Answers.isEmpty()) {throw new AssertionError("Answers already existing.");} - for(int i:id2Query.keySet()) - { - Set<String> uris = getUris(endpoint, id2Query.get(i),cache); - id2Answers.put(i, uris); // empty answer set better transfers intended meaning and doesn't cause NPEs in html generation :-) - if(!uris.isEmpty()) {/*id2Answers.put(i, uris);*/} - else {id2LearnStatus.put(i, LearnStatus.QUERY_RESULT_EMPTY);} - } - return this; - } - - - } - - private QueryTestData readQueries(final File file) - { - QueryTestData testData = new QueryTestData(); - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(file); - doc.getDocumentElement().normalize(); - NodeList questionNodes = doc.getElementsByTagName("question"); - int id; - - for(int i = 0; i < questionNodes.getLength(); i++) - { - if(i>=MAXIMUM_QUESTIONS) break; // TODO: remove - String question; - String query; - Set<String> answers = new HashSet<String>(); - Element questionNode = (Element) questionNodes.item(i); - //read question ID - id = Integer.valueOf(questionNode.getAttribute("id")); - //Read question - question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); - //Read SPARQL query - query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); - // //Read answers - // answers = new HashSet<String>(); - // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); - // for(int j = 0; j < aswersNodes.getLength(); j++){ - // Element answerNode = (Element) aswersNodes.item(j); - // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); - // } - - if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) - { - testData.id2Question.put(id, question); - testData.id2Query.put(id, query); - Element answersElement = (Element) questionNode.getElementsByTagName("answers").item(0); - if(answersElement!=null) - { - NodeList answerElements = answersElement.getElementsByTagName("answer"); - for(int j=0; j<answerElements.getLength();j++) - { - String answer = ((Element)answerElements.item(j)).getTextContent(); - answers.add(answer); - } - testData.id2Answers.put(id, answers); - } - } - // question2Answers.put(question, answers); - - } - } catch (DOMException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - // StringBuilder sb = new StringBuilder(); - // for(Entry<Integer, String> e : id2Question.entrySet()){ - // sb.append(e.getKey()+ ": " + extractSentence(e.getValue()) + "\n"); - // } - // try { - // BufferedWriter out = new BufferedWriter(new FileWriter("questions.txt")); - // out.write(sb.toString()); - // out.close(); - // } - // catch (IOException e) - // { - // System.out.println("Exception "); - // - // } - return testData; - } - - protected static Set<String> getUris(final SparqlEndpoint endpoint, final String query, ExtractionDBCache cache) + public static Set<String> getUris(final SparqlEndpoint endpoint, final String query, ExtractionDBCache cache) { if(query==null) {throw new AssertionError("query is null");} if(endpoint==null) {throw new AssertionError("endpoint is null");} @@ -969,8 +838,7 @@ {static public final PartOfSpeechTagger posTagger = new SynchronizedStanfordPartOfSpeechTagger();} static private final WordNet wordnet = new WordNet(); - static private final Options options = new Options(); - private final boolean pretagged; + static private final Options options = new Options(); private final SPARQLTemplateBasedLearner2 learner; public LearnQueryCallable(String question, int id, QueryTestData testData, Knowledgebase knowledgeBase,boolean pretagged) @@ -978,8 +846,8 @@ this.question=question; this.id=id; this.testData=testData; - this.pretagged=pretagged; learner = new SPARQLTemplateBasedLearner2(knowledgeBase,pretagged?null:POSTaggerHolder.posTagger,wordnet,options); + try {learner.init();} catch (ComponentInitException e) {throw new RuntimeException(e);} } public LearnQueryCallable(String question, int id, QueryTestData testData, Model model,MappingBasedIndex index,boolean pretagged) @@ -987,20 +855,15 @@ this.question=question; this.id=id; this.testData=testData; - this.pretagged=pretagged; MappingBasedIndex mappingIndex= new MappingBasedIndex( SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() ); - + learner = new SPARQLTemplateBasedLearner2(model,mappingIndex,pretagged?null:POSTaggerHolder.posTagger); - try { - learner.init(); - } catch (ComponentInitException e) { - e.printStackTrace(); - } + try {learner.init();} catch (ComponentInitException e) {throw new RuntimeException(e);} } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-10-30 12:54:06
|
Revision: 3860 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3860&view=rev Author: dcherix Date: 2012-10-30 12:53:54 +0000 (Tue, 30 Oct 2012) Log Message: ----------- new conf Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java trunk/scripts/src/main/resources/log4j.properties trunk/test/newcomponent/AristotlePosNeg.conf Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -21,6 +21,7 @@ import java.io.File; import java.text.DecimalFormat; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -218,11 +219,11 @@ // configurator = new CELOEConfigurator(this); } -// public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { -// Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); -// problems.add(AbstractLearningProblem.class); -// return problems; -// } + public static Collection<Class<? extends AbstractLearningProblem>> supportedLearningProblems() { + Collection<Class<? extends AbstractLearningProblem>> problems = new LinkedList<Class<? extends AbstractLearningProblem>>(); + problems.add(AbstractLearningProblem.class); + return problems; + } public static String getName() { return "CELOE"; Modified: trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/core/ComponentManager.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -99,6 +99,7 @@ "org.dllearner.kb.OWLFile", "org.dllearner.kb.KBFile", "org.dllearner.kb.sparql.SparqlKnowledgeSource", + "org.dllearner.kb.sparql.simple.SparqlSimpleExtractor", "org.dllearner.kb.OWLAPIOntology", // "org.dllearner.kb.SparqlEndpointKS", //reasoners Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/Cache.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -225,6 +225,8 @@ return (String) entry.get(2); } + + /** * Adds an entry to the cache. @@ -328,7 +330,7 @@ totaltime.stop(); return result; } - + public boolean executeSparqlAskQuery(SparqlQuery query) { String str = getCacheEntry(query.getSparqlQueryString()); JamonMonitorLogger.increaseCount(Cache.class, "TotalQueries"); Deleted: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -1,50 +0,0 @@ -package org.dllearner.kb.sparql; - -import java.net.URL; - -import org.dllearner.core.ComponentAnn; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.kb.OWLOntologyKnowledgeSource; -import org.semanticweb.owlapi.model.OWLOntology; -import org.semanticweb.owlapi.model.OWLOntologyManager; - -@ComponentAnn(name="efficient SPARQL fragment extractor", shortName="sparqls", version=0.1) -public class SparqlSimpleExtractor implements KnowledgeSource, OWLOntologyKnowledgeSource { - - @ConfigOption(name="endpointURL", description="URL of the SPARQL endpoint", required=true) - private URL endpointURL = null; - - public SparqlSimpleExtractor() { - - } - - @Override - public void init() throws ComponentInitException { - // TODO Auto-generated method stub - - } - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - - public URL getEndpointURL() { - return endpointURL; - } - - public void setEndpointURL(URL endpointURL) { - this.endpointURL = endpointURL; - } - - @Override - public OWLOntology createOWLOntology(OWLOntologyManager manager) { - //TODO Update this to return an ontology representation of what the reasoners should work with. Build with the passed in manager instance. - return null; - } -} Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/pom.xml 2012-10-30 12:53:54 UTC (rev 3860) @@ -66,6 +66,28 @@ <dependency> <groupId>org.aksw.commons</groupId> <artifactId>sparql</artifactId> + <exclusions> + <exclusion> + <artifactId>slf4j-api</artifactId> + <groupId>org.slf4j</groupId> + </exclusion> + <exclusion> + <artifactId>arq</artifactId> + <groupId>com.hp.hpl.jena</groupId> + </exclusion> + <exclusion> + <artifactId>xercesImpl</artifactId> + <groupId>xerces</groupId> + </exclusion> + <exclusion> + <artifactId>any23-core</artifactId> + <groupId>org.deri.any23</groupId> + </exclusion> + <exclusion> + <artifactId>jena-core</artifactId> + <groupId>org.apache.jena</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>mysql</groupId> @@ -102,7 +124,7 @@ <executable>java</executable> <arguments> <argument>-Xms512m</argument> - <argument>-Xmx4000m</argument> + <argument>-Xmx3000m</argument> </arguments> </configuration> </plugin> Modified: trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/DBpediaClassLearnerCELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -24,6 +24,10 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -47,8 +51,10 @@ import org.dllearner.core.owl.Thing; import org.dllearner.gui.Config; import org.dllearner.gui.ConfigSave; +import org.dllearner.kb.sparql.Cache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.RhoDRDown; @@ -66,6 +72,7 @@ import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -89,6 +96,7 @@ .getLogger(DBpediaClassLearnerCELOE.class); SparqlEndpoint sparqlEndpoint = null; + private Cache cache; public DBpediaClassLearnerCELOE() { // OPTIONAL: if you want to do some case distinctions in the learnClass @@ -100,6 +108,7 @@ // TODO Auto-generated catch block e.printStackTrace(); } + cache = new Cache("basCache"); } public static void main(String args[]) @@ -110,20 +119,21 @@ Monitor mon = MonitorFactory.start("Learn DBpedia"); KB kb = dcl.learnAllClasses(classesToLearn); mon.stop(); - kb.export(new File("/home/dcherix/dllearner/old/result.owl"), + kb.export(new File("/home/dcherix/dllearner/old/result"+i+".owl"), OntologyFormat.RDF_XML); // Set<String> pos = // dcl.getPosEx("http://dbpedia.org/ontology/Person"); // dcl.getNegEx("http://dbpedia.org/ontology/Person", pos); - logger.info("Test " + i + ":\n" + logger.info("Test" + i + ":\n" + JamonMonitorLogger.getStringForAllSortedByLabel()); + System.gc(); } } public KB learnAllClasses(Set<String> classesToLearn) { KB kb = new KB(); for (String classToLearn : classesToLearn) { - logger.info("Leraning class: " + classToLearn); + logger.info("Leanring class: " + classToLearn); try { Description d = learnClass(classToLearn); if (d == null @@ -141,6 +151,7 @@ } catch (Exception e) { logger.warn("", e); } + this.dropCache(); } return kb; @@ -175,6 +186,7 @@ ks.setUrl(new URL(endpointurl)); ks.setUseLits(false); ks.setUseCacheDatabase(true); + ks.setUseCache(true); ks.setRecursionDepth(1); ks.setCloseAfterRecursion(true); ks.setSaveExtractedFragment(true); @@ -252,12 +264,18 @@ // } // public Set<String> getPosEx(String clazz) throws Exception { - SparqlTemplate st = SparqlTemplate.getInstance("instancesOfClass.vm"); - st.setLimit(0); - VelocityContext vc = st.getVelocityContext(); - vc.put("class", clazz); - String queryString = st.getQuery(); - return this.executeResourceQuery(queryString); +// SparqlTemplate st = SparqlTemplate.getInstance("instancesOfClass.vm"); +// st.setLimit(0); +// VelocityContext vc = st.getVelocityContext(); +// vc.put("class", clazz); +// String queryString = st.getQuery(); + StringBuilder queryString = new StringBuilder(); + queryString.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"); + queryString.append(" SELECT ?instances WHERE { ?instances rdf:type <"); + queryString.append(clazz); + queryString.append("> }"); + System.out.println(queryString); + return this.executeResourceQuery(queryString.toString()); } /** @@ -337,7 +355,7 @@ logger.info("using class for negatives: " + targetClass); if (targetClass != null) { SparqlTemplate st = SparqlTemplate - .getInstance("instancesOfClass.vm"); + .getInstance("instancesOfClass2.vm"); st.setLimit(0); VelocityContext vc = st.getVelocityContext(); vc.put("class", targetClass); @@ -386,10 +404,11 @@ } public Set<String> executeResourceQuery(String queryString) { - Query query = QueryFactory.create(queryString); - QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, - query); - ResultSet resultSet = qexec.execSelect(); +// Query query = QueryFactory.create(queryString); +// QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, +// query); +// ResultSet resultSet = qexec.execSelect(); + ResultSetRewindable resultSet = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(new SparqlQuery(queryString,sparqlEndpoint))); QuerySolution solution; Set<String> results = new HashSet<String>(); while (resultSet.hasNext()) { @@ -400,10 +419,11 @@ } public Set<String> executeClassQuery(String queryString) { - Query query = QueryFactory.create(queryString); - QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, - query); - ResultSet resultSet = qexec.execSelect(); +// Query query = QueryFactory.create(queryString); +// QueryExecution qexec = QueryExecutionFactory.sparqlService(endpointurl, +// query); +// ResultSet resultSet = qexec.execSelect(); + ResultSetRewindable resultSet = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(new SparqlQuery(queryString,sparqlEndpoint))); QuerySolution solution; Set<String> results = new HashSet<String>(); while (resultSet.hasNext()) { @@ -413,4 +433,24 @@ return results; } + private void dropCache(){ + try { + Class.forName("org.h2.Driver"); + String databaseName="extraction"; + String databaseDirectory="cache"; + Connection conn = DriverManager.getConnection("jdbc:h2:"+databaseDirectory+"/"+databaseName, "sa", ""); + Statement st = conn.createStatement(); + st.execute("DELETE FROM QUERY_CACHE"); + st.close(); + conn.close(); + System.gc(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/java/org/dllearner/scripts/improveWikipedia/NewSparqlCompDBpediaClassLearnerCELOE.java 2012-10-30 12:53:54 UTC (rev 3860) @@ -107,7 +107,7 @@ public static void main(String args[]) throws LearningProblemUnsupportedException, IOException, Exception { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 4; i++) { NewSparqlCompDBpediaClassLearnerCELOE dcl = new NewSparqlCompDBpediaClassLearnerCELOE(); Set<String> classesToLearn = dcl.getClasses(); @@ -129,8 +129,7 @@ public KB learnAllClasses(Set<String> classesToLearn) { KB kb = new KB(); for (String classToLearn : classesToLearn) { - logger.info(classToLearn); - System.out.println(classToLearn); + logger.info("learning "+classToLearn); try { Description d = learnClass(classToLearn); if (d == null @@ -148,6 +147,7 @@ } catch (Exception e) { logger.warn("", e); } + System.gc(); } return kb; @@ -254,10 +254,7 @@ for (OntClass ontClass : classes) { results.add(ontClass.getURI()); i++; - if (i == 100) - break; } - System.out.println(results.size()); return results; } Modified: trunk/scripts/src/main/resources/log4j.properties =================================================================== --- trunk/scripts/src/main/resources/log4j.properties 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/scripts/src/main/resources/log4j.properties 2012-10-30 12:53:54 UTC (rev 3860) @@ -1,9 +1,15 @@ log4j.appender.A1=org.apache.log4j.RollingFileAppender -log4j.appender.A1.File=log/errors.log +log4j.appender.A1.File=log/oldComp4.log log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c- %m%n -log4j.appender.A2=org.apache.log4j.RollingFileAppender -log4j.appender.A2.File=log/queries.log -log4j.appender.A2.layout=org.apache.log4j.PatternLayout +#log4j.appender.A2=org.apache.log4j.RollingFileAppender +#log4j.appender.A2.File=log/queries.log +#log4j.appender.A2.layout=org.apache.log4j.PatternLayout -log4j.rootLogger=ERROR,A1 \ No newline at end of file +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n + +log4j.rootLogger=INFO,A1,stdout + Modified: trunk/test/newcomponent/AristotlePosNeg.conf =================================================================== --- trunk/test/newcomponent/AristotlePosNeg.conf 2012-10-30 12:41:05 UTC (rev 3859) +++ trunk/test/newcomponent/AristotlePosNeg.conf 2012-10-30 12:53:54 UTC (rev 3860) @@ -13,9 +13,12 @@ sparql.type = "sparqls" sparql.endpointURL = "http://live.dbpedia.org/sparql" sparql.defaultGraphURI = "http://dbpedia.org" -sparql.recursionDepth = 1 -sparql.ontologyFile= "http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl" +sparql.recursionDepth = 2 +sparql.ontologySchemaUrls = {"http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl" } +sparql.aboxfilter = "FILTER ( !isLiteral(?o) && regex(str(?o), '^http://dbpedia.org/resource/') && ! regex(str(?o), '^http://dbpedia.org/resource/Category') && ! regex(str(?o), '^http://dbpedia.org/resource/Template') ) . " +sparql.tboxfilter = "FILTER ( regex(str(?class), '^http://dbpedia.org/ontology/') ) . " + sparql.instances = { "http://dbpedia.org/resource/Democritus", "http://dbpedia.org/resource/Zeno_of_Elea", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-11-01 10:22:40
|
Revision: 3863 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3863&view=rev Author: kirdie Date: 2012-11-01 10:22:25 +0000 (Thu, 01 Nov 2012) Log Message: ----------- undo bad commit Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Property Changed: ---------------- trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/LinkedDataTupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/TupleAquisitor.java trunk/components-core/src/main/java/org/dllearner/kb/extraction/ObjectPropertyNode.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Manipulator.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Rule.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionClass.java trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/components-core/src/main/java/org/dllearner/learningproblems/ScorePosNeg.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/matching/LGDPoint.java trunk/scripts/src/main/java/org/dllearner/scripts/package-info.java Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/OCEL.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/algorithms/ocel/ROLearner2.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/LinkedDataTupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/SparqlTupleAquisitorImproved.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/aquisitors/TupleAquisitor.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/extraction/ObjectPropertyNode.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Manipulator.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/Rule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionClass.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/EvaluatedDescriptionPosNeg.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/learningproblems/ScorePosNeg.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/components-core/src/main/java/org/dllearner/utilities/owl/EvaluatedDescriptionPosNegComparator.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -1,19 +1,27 @@ package org.dllearner.algorithm.tbsl.learning; -import hmm.HiddenMarkovModel; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; -import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import org.apache.commons.collections15.MultiMap; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.apache.log4j.Logger; import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; @@ -23,7 +31,13 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.Allocation; import org.dllearner.algorithm.tbsl.sparql.Query; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.SlotType; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -32,10 +46,13 @@ import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; +import org.dllearner.algorithm.tbsl.util.Similarity; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; import org.dllearner.common.index.Index; import org.dllearner.common.index.IndexResultItem; import org.dllearner.common.index.IndexResultSet; import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.common.index.SOLRIndex; import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; import org.dllearner.common.index.SPARQLIndex; import org.dllearner.common.index.SPARQLObjectPropertiesIndex; @@ -46,13 +63,19 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.reasoning.SPARQLReasoner; +import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; + import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; @@ -62,6 +85,10 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.sparql.expr.ExprAggregator; +import com.hp.hpl.jena.sparql.expr.ExprVar; +import com.hp.hpl.jena.sparql.expr.aggregate.AggCount; +import com.hp.hpl.jena.sparql.expr.aggregate.Aggregator; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -489,88 +516,358 @@ return relevantKeywords; } - // just for testing the HMM integration, getWeightedSPARQLQueriesOld is the original one - private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates) - { - // for testing - for(Template template: templates) - { - { - ArrayList<String> keywords = new ArrayList<String>(); - for(Slot slot: template.getSlots()) - { - keywords.add(slot.getWords().get(0)); + private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + logger.debug("Generating SPARQL query candidates..."); + + Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { + + @Override + public int compare(Slot o1, Slot o2) { + if(o1.getSlotType() == o2.getSlotType()){ + return o1.getToken().compareTo(o2.getToken()); + } else { + return -1; } - if(template.getSlots().size()!=3) {continue;} - if(!keywords.contains("Mean Hamster Software")) {continue;} - if(!keywords.contains("published")) {continue;} - System.out.println("\"keywords\": "+keywords); } - System.out.println(template); - SortedSet<WeightedQuery> queries = new TreeSet<WeightedQuery>(); - Query query = template.getQuery(); - double score = 0; - - Map<List<String>,Collection<String>> segmentToURIs = new HashMap<List<String>,Collection<String>>(); - for(Slot slot: template.getSlots()) - { - List<String> segment = new LinkedList<String>(); - segment.add(slot.getWords().get(0)); // TODO: split it up? - - Set<String> uris = new HashSet<String>(); - - for(IndexResultItem item : getIndexResultItems(slot)) - { - uris.add(item.getUri()); + }); + slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); + + + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); + + Set<Allocation> allocations; + + for(Template t : templates){ + logger.info("Processing template:\n" + t.toString()); + allocations = new TreeSet<Allocation>(); + boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); + + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); + List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); + + long startTime = System.currentTimeMillis(); + + for (Slot slot : t.getSlots()) { + if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); + Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); + Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); + list.add(submit); + } + } + + for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { + try { + Map<Slot, SortedSet<Allocation>> result = future.get(); + Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); + slot2Allocations.put(item.getKey(), item.getValue()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); } - segmentToURIs.put(segment,uris); } - HiddenMarkovModel hmm = new HiddenMarkovModel(); - hmm.initialization(); - hmm.startMarkovModel(segmentToURIs,true); - MultiMap<Double,List<String>> paths = hmm.getPaths(); - // System.out.println(hmm.getPaths()); - // die keywords jetzt in sadeehs algorithmus reinwerfen - // da kommen jetzt pfade raus mit unterschiedlichen wahrscheinlichkeiten - // HiddenMarkovModel HMM = new HiddenMarkovModel(); - // HMM.StartMarkovModel(); - // jetzt die variablen aus der query ersetzen mit den kandidaten - // ranked list der pfade, die die observation sequence generieren + executor.shutdown(); - for(Double d : paths.keySet()) - { - for(List<String> path : paths.get(d)) - { - Query q = new Query(query); - // TODO: which variable stands for which resource? do it randomly now to check if the replacement works and then correct the order later - System.out.println(q.getVariablesAsStringList()); - System.out.println(); - int i = 0; - for(String var : q.getVariablesAsStringList()) - { - q.replaceVarWithURI(var, path.get(i)); - i++; + + /*for(Slot slot : t.getSlots()){ + allocations = slot2Allocations2.get(slot); + if(allocations == null){ + allocations = computeAllocations(slot, 10); + slot2Allocations2.put(slot, allocations); + } + slot2Allocations.put(slot, allocations); + + //for tests add the property URI with http://dbpedia.org/property/ namespace + //TODO should be replaced by usage of a separate SOLR index + Set<Allocation> tmp = new HashSet<Allocation>(); + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(Allocation a : allocations){ + String uri = "http://dbpedia.org/property/" + a.getUri().substring(a.getUri().lastIndexOf("/")+1); + Allocation newA = new Allocation(uri, a.getSimilarity(), a.getProminence()); + newA.setScore(a.getScore()-0.000001); + tmp.add(newA); } - System.out.println(q); + } + allocations.addAll(tmp); + }*/ + logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); + Query cleanQuery = t.getQuery(); + queries.add(new WeightedQuery(cleanQuery)); - WeightedQuery wQuery = new WeightedQuery(q, score); - queries.add(wQuery); + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); + Set<Slot> classSlots = new HashSet<Slot>(); + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.CLASS){ + sortedSlots.add(slot); + classSlots.add(slot); } } - //System.exit(0); - return queries; - // >> SLOTS: - // y0: RESOURCE {Mean Hamster Software} - // p0: OBJECTPROPERTY {published,print} - // p1: CLASS {video games} + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ + sortedSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(!sortedSlots.contains(slot)){ + sortedSlots.add(slot); + } + } + //add for each SYMPROPERTY Slot the reversed query + for(Slot slot : sortedSlots){ + for(WeightedQuery wQ : queries){ + if(slot.getSlotType() == SlotType.SYMPROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY){ + Query reversedQuery = new Query(wQ.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + tmp.add(new WeightedQuery(reversedQuery)); + } + tmp.add(wQ); + } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); + } + for(Slot slot : sortedSlots){ + if(!slot2Allocations.get(slot).isEmpty()){ + for(Allocation a : slot2Allocations.get(slot)){ + for(WeightedQuery query : queries){ + Query q = new Query(query.getQuery()); - // System.out.println(template); + boolean drop = false; + if(useDomainRangeRestriction){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + String objectVar = triple.getValue().getName(); + String subjectVar = triple.getVariable().getName(); + // System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ + // System.out.println(typeTriple); + if(true){//reasoner.isObjectProperty(a.getUri())){ + Description range = reasoner.getRange(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(range != null){ + Set<Description> allRanges = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(range instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(range); + allRanges.addAll(superClasses); + } else { + for(Description nc : range.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allRanges.addAll(superClasses); + } + } + allRanges.add(range); + allRanges.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } + } + } else { + drop = true; + } + + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ + Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); + // System.out.println(a); + if(domain != null){ + Set<Description> allDomains = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(domain instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(domain); + allDomains.addAll(superClasses); + } else { + for(Description nc : domain.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allDomains.addAll(superClasses); + } + } + allDomains.add(domain); + allDomains.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ + drop = true; + } else { + + } + } + } + } + } + } + + if(!drop){ + if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + } + } else { + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + } + WeightedQuery w = new WeightedQuery(q); + double newScore = query.getScore() + a.getScore(); + w.setScore(newScore); + w.addAllocations(query.getAllocations()); + w.addAllocation(a); + tmp.add(w); + } + + + } + } + //lower queries with FILTER-REGEX + if(containsRegex){ + for(WeightedQuery wQ : tmp){ + wQ.setScore(wQ.getScore() - 0.01); + } + } + + queries.clear(); + queries.addAll(tmp);//System.out.println(tmp); + tmp.clear(); + } else {//Add REGEX FILTER if resource slot is empty and predicate is datatype property + if(slot.getSlotType() == SlotType.RESOURCE){ + for(WeightedQuery query : queries){ + Query q = query.getQuery(); + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + SPARQL_Value object = triple.getValue(); + if(object.isVariable() && object.getName().equals(slot.getAnchor())){//only consider triple where SLOT is in object position + SPARQL_Property predicate = triple.getProperty(); + if(!predicate.isVariable()){//only consider triple where predicate is URI + String predicateURI = predicate.getName().replace("<", "").replace(">", ""); + if(isDatatypeProperty(predicateURI)){//if data property + q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + object, "'" + slot.getWords().get(0) + "'", SPARQL_PairType.REGEX))); + } + } + } + } + + } + + } else { + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + for(WeightedQuery wQ : queries){ + List<SPARQL_Triple> triples = wQ.getQuery().getTriplesWithVar(slot.getAnchor()); + for(SPARQL_Triple triple : triples){ + String typeVar; + String resourceURI; + SymPropertyDirection direction; + if(triple.getValue().isVariable()){ + direction = SymPropertyDirection.VAR_RIGHT; + typeVar = triple.getValue().getName(); + resourceURI = triple.getVariable().getName(); + } else { + direction = SymPropertyDirection.VAR_LEFT; + typeVar = triple.getVariable().getName(); + resourceURI = triple.getValue().getName(); + } + resourceURI = resourceURI.replace("<", "").replace(">", ""); + List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); + for(SPARQL_Triple typeTriple : typeTriples){ + String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); + // List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); + // for(Entry<String, Integer> property : mostFrequentProperties){ + // wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); + // wQ.setScore(wQ.getScore() + 0.1); + // } + } + + } + } + } + } + // else if(slot.getSlotType() == SlotType.CLASS){ + // String token = slot.getWords().get(0); + // if(slot.getToken().contains("house")){ + // String regexToken = token.replace("houses", "").replace("house", "").trim(); + // try { + // Map<Slot, SortedSet<Allocation>> ret = new SlotProcessor(new Slot(null, SlotType.CLASS, Collections.singletonList("house"))).call(); + // SortedSet<Allocation> alloc = ret.entrySet().iterator().next().getValue(); + // if(alloc != null && !alloc.isEmpty()){ + // String uri = alloc.first().getUri(); + // for(WeightedQuery query : queries){ + // Query q = query.getQuery(); + // for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + // SPARQL_Term subject = triple.getVariable(); + // SPARQL_Term object = new SPARQL_Term("desc"); + // object.setIsVariable(true); + // object.setIsURI(false); + // q.addCondition(new SPARQL_Triple(subject, new SPARQL_Property("<http://purl.org/goodrelations/v1#description>"), object)); + // q.addFilter(new SPARQL_Filter(new SPARQL_Pair( + // object, "'" + regexToken + "'", SPARQL_PairType.REGEX))); + // } + // q.replaceVarWithURI(slot.getAnchor(), uri); + // + // } + // } + // } catch (Exception e) { + // e.printStackTrace(); + // } + // } + // } + + + } + + } + for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { + WeightedQuery wQ = iterator.next(); + if(dropZeroScoredQueries){ + if(wQ.getScore() <= 0){ + iterator.remove(); + } + } else { + if(t.getSlots().size()==0) throw new AssertionError("no slots for query "+wQ); + wQ.setScore(wQ.getScore()/t.getSlots().size()); + } + + } + allQueries.addAll(queries); + List<Query> qList = new ArrayList<Query>(); + for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); + qList.add(wQ.getQuery()); + } + template2Queries.put(t, qList); } - // - return null; + logger.debug("...done in "); + return allQueries; } private double getProminenceValue(String uri, SlotType type){ @@ -845,51 +1142,101 @@ } - private Set<IndexResultItem> getIndexResultItems(Slot slot) - { -// List<String> uris = new LinkedList<String>(); - Set<IndexResultItem> indexResultItems = new HashSet<IndexResultItem>(); - - Index index = getIndexBySlotType(slot); - - for(String word : slot.getWords()) - { - IndexResultSet rs = new IndexResultSet(); - if(mappingIndex != null){ - SlotType type = slot.getSlotType(); - if(type == SlotType.CLASS){ - rs.add(mappingIndex.getClassesWithScores(word)); - } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ - rs.add(mappingIndex.getPropertiesWithScores(word)); - } else if(type == SlotType.DATATYPEPROPERTY){ - rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); - } else if(type == SlotType.OBJECTPROPERTY){ - rs.add(mappingIndex.getObjectPropertiesWithScores(word)); - } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ - rs.add(mappingIndex.getResourcesWithScores(word)); + class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ + + private Slot slot; + + public SlotProcessor(Slot slot) { + this.slot = slot; + } + + @Override + public Map<Slot, SortedSet<Allocation>> call() throws Exception { + Map<Slot, SortedSet<Allocation>> result = new HashMap<Slot, SortedSet<Allocation>>(); + result.put(slot, computeAllocations(slot)); + return result; + } + + private SortedSet<Allocation> computeAllocations(Slot slot){ + logger.debug("Computing allocations for slot: " + slot); + SortedSet<Allocation> allocations = new TreeSet<Allocation>(); + + Index index = getIndexBySlotType(slot); + + IndexResultSet rs; + for(String word : slot.getWords()){ + rs = new IndexResultSet(); + if(mappingIndex != null){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + rs.add(mappingIndex.getClassesWithScores(word)); + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + rs.add(mappingIndex.getPropertiesWithScores(word)); + } else if(type == SlotType.DATATYPEPROPERTY){ + rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); + } else if(type == SlotType.OBJECTPROPERTY){ + rs.add(mappingIndex.getObjectPropertiesWithScores(word)); + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + rs.add(mappingIndex.getResourcesWithScores(word)); + } } - } - //use the non manual indexes only if mapping based resultset is not empty and option is set - if(!useManualMappingsIfExistOnly || rs.isEmpty()){ - if(slot.getSlotType() == SlotType.RESOURCE){ - rs.add(index.getResourcesWithScores(word, 20)); - } else { - if(slot.getSlotType() == SlotType.CLASS){ - word = PlingStemmer.stem(word); + //use the non manual indexes only if mapping based resultset is not empty and option is set + if(!useManualMappingsIfExistOnly || rs.isEmpty()){ + if(slot.getSlotType() == SlotType.RESOURCE){ + rs.add(index.getResourcesWithScores(word, 20)); + } else { + if(slot.getSlotType() == SlotType.CLASS){ + word = PlingStemmer.stem(word); + } + rs.add(index.getResourcesWithScores(word, 20)); } - rs.add(index.getResourcesWithScores(word, 20)); } + + + for(IndexResultItem item : rs.getItems()){ + double similarity = Similarity.getSimilarity(word, item.getLabel()); + // //get the labels of the redirects and compute the highest similarity + // if(slot.getSlotType() == SlotType.RESOURCE){ + // Set<String> labels = getRedirectLabels(item.getUri()); + // for(String label : labels){ + // double tmp = Similarity.getSimilarity(word, label); + // if(tmp > similarity){ + // similarity = tmp; + // } + // } + // } + double prominence = getProminenceValue(item.getUri(), slot.getSlotType()); + allocations.add(new Allocation(item.getUri(), prominence, similarity)); + } + } -// for(IndexResultItem item: rs.getItems()) -// { -// uris.add(item.getUri()); -// } - indexResultItems.addAll(rs.getItems()); + + normProminenceValues(allocations); + + computeScore(allocations); + logger.debug("Found " + allocations.size() + " allocations for slot " + slot); + return new TreeSet<Allocation>(allocations); } - return indexResultItems; + + private Index getIndexBySlotType(Slot slot){ + Index index = null; + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + index = classesIndex; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + index = propertiesIndex; + } else if(type == SlotType.DATATYPEPROPERTY){ + index = datatypePropertiesIndex; + } else if(type == SlotType.OBJECTPROPERTY){ + index = objectPropertiesIndex; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + index = resourcesIndex; + } + return index; + } + } - public String getTaggedInput() { if(templateGenerator==null) {throw new AssertionError("Learner not initialized. Please call init();");} @@ -908,33 +1255,33 @@ return isDatatypeProperty; } - // /** - // * @param args - // * @throws NoTemplateFoundException - // * @throws IOException - // * @throws FileNotFoundException - // * @throws InvalidFileFormatException - // */ - // public static void main(String[] args) throws Exception { - // SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), - // Collections.<String>singletonList(""), Collections.<String>emptyList()); - // Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); - // Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); - // Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); - // - // SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); - // learner.init(); - // - // String question = "What is the highest mountain?"; - // - // learner.setQuestion(question); - // learner.learnSPARQLQueries(); - // System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); - // System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); - // System.out.println(learner.getLearnedPosition()); - // - // } + /** + * @param args + * @throws NoTemplateFoundException + * @throws IOException + * @throws FileNotFoundException + * @throws InvalidFileFormatException + */ + public static void main(String[] args) throws Exception { + SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://greententacle.techfak.uni-bielefeld.de:5171/sparql"), + Collections.<String>singletonList(""), Collections.<String>emptyList()); + Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); + Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); + Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); + SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.init(); + String question = "What is the highest mountain?"; + learner.setQuestion(question); + learner.learnSPARQLQueries(); + System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + System.out.println(learner.getLearnedPosition()); + + } + + + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -58,7 +58,7 @@ unions = new HashSet<SPARQL_Union>(); } - /** copy constructor*/ + //copy constructor public Query(Query query){ this.qt = query.getQt(); Set<SPARQL_Term> selTerms = new HashSet<SPARQL_Term>(); Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-10-30 16:32:40 UTC (rev 3862) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-11-01 10:22:25 UTC (rev 3863) @@ -114,7 +114,7 @@ test("QALD 2 Benchmark ideally tagged", file,SparqlEndpoint.getEndpointDBpedia(),dbpediaLiveCache,dbpediaLiveKnowledgebase,null,null); } - /*@Test*/ public void testOxford() throws Exception + @Test public void testOxford() throws Exception { File file = new File(getClass().getClassLoader().getResource("tbsl/evaluation/oxford_working_questions.xml").getFile()); test("Oxford 19 working questions", file,null,null,null,loadOxfordModel(),getOxfordMappingIndex()); @@ -160,26 +160,6 @@ logger.info("learned query: "+testData.id2Query.get(0)); } - /** For debugging one question in particular. - */ - @Test public void testSingleQueryDBpedia() - { -// Logger.getLogger(Templator.class).setLevel(Level.DEBUG); -// Logger.getLogger(Parser.class).setLevel(Level.DEBUG); -// Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.DEBUG); - // String question = "houses for less than 900000 pounds"; - String question = "Give/VB me/PRP all/DT video/JJ games/NNS published/VBN by/IN Mean/NNP Hamster/NNP Software/NNP"; -// String question = "give me all video games published by mean hamster software"; -// String question = "Give me all video games published by Mean Hamster Software"; -// question = new StanfordPartOfSpeechTagger().tag(question); -// System.out.println(question); - -// Model model = loadOxfordModel(); - QueryTestData testData = new QueryTestData(); - new LearnQueryCallable(question, 0, testData, dbpediaLiveKnowledgebase, true).call(); - logger.info("learned query: "+testData.id2Query.get(0)); - } - /*@Test*/ public void generateXMLOxford() throws IOException { boolean ADD_POS_TAGS = true; @@ -955,7 +935,6 @@ learner = new SPARQLTemplateBasedLearner2(knowledgeBase,pretagged?null:POSTaggerHolder.posTagger,wordnet,options); try {learner.init();} catch (ComponentInitException e) {throw new RuntimeException(e);} learner.setUseIdealTagger(pretagged); - learner.setGrammarFiles(new String[]{"tbsl/lexicon/english.lex"}); } public LearnQueryCallable(String question, int id, QueryTestData testData, Model model,MappingBasedIndex index,boolean pretagged) Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/matching/LGDPoint.java ___________________________________________________________________ Deleted: svn:mergeinfo - Property changes on: trunk/scripts/src/main/java/org/dllearner/scripts/package-info.java ___________________________________________________________________ Deleted: svn:mergeinfo - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-11-29 14:57:46
|
Revision: 3878 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3878&view=rev Author: jenslehmann Date: 2012-11-29 14:57:34 +0000 (Thu, 29 Nov 2012) Log Message: ----------- documentation update Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java trunk/interfaces/doc/configOptions.html Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/el/ELLearningAlgorithmDisjunctive.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -174,6 +174,7 @@ @Override public void start() { +// System.out.println("starting disjunctive ELTL algorithm"); stop = false; isRunning = true; reset(); @@ -196,7 +197,9 @@ // System.out.println("best: " + best); // apply operator + System.out.print("applying operator ..."); List<ELDescriptionTree> refinements = operator.refine(best.getDescriptionTree()); + System.out.println("done " + refinements.size() + " refinements"); // add all refinements to search tree, candidates, best descriptions for(ELDescriptionTree refinement : refinements) { addDescriptionTree(refinement, best); Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -81,6 +81,7 @@ "org.dllearner.kb.sparql.SparqlKnowledgeSource", "org.dllearner.kb.sparql.simple.SparqlSimpleExtractor", "org.dllearner.learningproblems.PosNegLPStandard", + "org.dllearner.learningproblems.PosNegLPStrict", "org.dllearner.learningproblems.FuzzyPosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", "org.dllearner.learningproblems.ClassLearningProblem", Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStrict.java 2012-11-29 14:57:34 UTC (rev 3878) @@ -25,11 +25,12 @@ import java.util.TreeSet; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigEntry; -import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.DoubleConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.Description; @@ -40,17 +41,27 @@ import org.dllearner.utilities.datastructures.SortedSetTuple; /** + * + * A strict learning problem means that for negative examples, it is required that a negative example + * should be instance of (NOT C) for a hypothesis C. + * * @author Jens Lehmann * */ +@ComponentAnn(name = "PosNegLPStrict", shortName = "posNegStrict", version = 0.8) public class PosNegLPStrict extends PosNegLP { private Set<Individual> neutralExamples; private boolean penaliseNeutralExamples = false; private static final double defaultAccuracyPenalty = 1; + + @ConfigOption(name = "accuracyPenalty", description = "penalty for incorrectness (example belongs neither to concept nor its negation)", defaultValue = "1", required = false) private double accuracyPenalty = defaultAccuracyPenalty; + private static final double defaultErrorPenalty = 3; + + @ConfigOption(name = "errorPenalty", description = "penalty for errors (example can be inferred to belong to the negated concept class)", defaultValue = "3", required = false) private double errorPenalty = defaultErrorPenalty; @@ -65,13 +76,14 @@ return "three valued definition learning problem"; } + /* public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = PosNegLP.createConfigOptions(); options.add(new BooleanConfigOption("penaliseNeutralExamples", "if set to true neutral examples are penalised")); options.add(new DoubleConfigOption("accuracyPenalty", "penalty for pos/neg examples which are classified as neutral", defaultAccuracyPenalty)); options.add(new DoubleConfigOption("errorPenalty", "penalty for pos. examples classified as negative or vice versa", defaultErrorPenalty)); return options; - } + } */ /* * (non-Javadoc) Modified: trunk/interfaces/doc/configOptions.html =================================================================== --- trunk/interfaces/doc/configOptions.html 2012-11-23 09:57:51 UTC (rev 3877) +++ trunk/interfaces/doc/configOptions.html 2012-11-29 14:57:34 UTC (rev 3878) @@ -21,14 +21,19 @@ <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.BruteForceLearner">Brute Force Learner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.celoe.CELOE">CELOE</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.ClassLearningProblem">ClassLearningProblem</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive">Disjunctive ELTL</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.el.ELLearningAlgorithm">ELTL</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.fuzzydll.FuzzyCELOE">Fuzzy CELOE</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner">Fuzzy OWL API Reasoner</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.FuzzyPosNegLPStandard">FuzzyPosNegLPStandard</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.KBFile">KB File</a></li></div> +<div class="OtherComponent"><li><a href="#org.dllearner.algorithms.celoe.OEHeuristicRuntime">OEHeuristicRuntime</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.OWLAPIReasoner">OWL API Reasoner</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.ocel.OCEL">OWL Class Expression Learner</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.OWLFile">OWL File</a></li></div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.celoe.PCELOE">PCELOE</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosNegLPStandard">PosNegLPStandard</a></li></div> +<div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosNegLPStrict">PosNegLPStrict</a></li></div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.RandomGuesser">Random Guesser</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.SparqlEndpointKS">SPARQL endpoint</a></li></div> <div class="KnowledgeSource"><li><a href="#org.dllearner.kb.sparql.SparqlKnowledgeSource">SPARQL endpoint fragment</a></li></div> @@ -38,6 +43,7 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.DisjointClassesLearner">disjoint classes learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner">disjoint dataproperty axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner">disjoint objectproperty axiom learner</a></li></div> +<div class="KnowledgeSource"><li><a href="#org.dllearner.kb.sparql.simple.SparqlSimpleExtractor">efficient SPARQL fragment extractor</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner">equivalent dataproperty axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner">equivalent objectproperty axiom learner</a></li></div> <div class="ReasonerComponent"><li><a href="#org.dllearner.reasoning.FastInstanceChecker">fast instance checker</a></li></div> @@ -49,34 +55,48 @@ <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner">objectproperty domain axiom learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner">objectproperty range learner</a></li></div> <div class="LearningProblem"><li><a href="#org.dllearner.learningproblems.PosOnlyLP">positive only learning problem</a></li></div> -<div class="LearningAlgorithm"><li><a href="#org.dllearner.algorithm.qtl.QTL">query tree learner</a></li></div> <div class="RefinementOperator"><li><a href="#org.dllearner.refinementoperators.RhoDRDown">rho refinement operator</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><li><a href="#org.dllearner.algorithms.SimpleSubclassLearner">simple subclass learner</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner">symmetric objectproperty axiom learner</a></li></div> +<div class="RefinementOperator"><li><a href="#org.dllearner.refinementoperators.SynchronizedRhoDRDown">synchronized rho refinement operator</a></li></div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><li><a href="#org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner">transitive objectproperty axiom learner</a></li></div> </ul> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.BruteForceLearner"><h2>Brute Force Learner</h2></a> <p>short name: bruteForce<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.CELOE"><h2>CELOE</h2></a> <p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>maxClassDescriptionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> <tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.ClassLearningProblem"><h2>ClassLearningProblem</h2></a> <p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive"><h2>Disjunctive ELTL</h2></a> +<p>short name: deltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: Disjunctive ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf with support for disjunctions.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>tryFullCoverage</td><td>If yes, then the algorithm tries to cover all positive examples. Note that while this improves accuracy on the testing set, it may lead to overfitting.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>treeSearchTimeSeconds</td><td>Specifies how long the algorithm should search for a partial solution (a tree).</td><td> double</td><td>1.0</td><td> false</td></tr> +</tbody></table> +</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithm"><h2>ELTL</h2></a> +<p>short name: eltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>Specifies whether to use real disjointness checks or instance based ones (no common instances) in the refinement operator.</td><td> boolean</td><td>true</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.fuzzydll.FuzzyCELOE"><h2>Fuzzy CELOE</h2></a> <p>short name: fceloe<br />version: 0.2<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: See Fuzzy DL-Learner paper published at ISDA 2011.<br /></p>This component does not have configuration options.</div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.fuzzydll.FuzzyOWLAPIReasoner"><h2>Fuzzy OWL API Reasoner</h2></a> @@ -85,33 +105,65 @@ <p>short name: fuzzyPosNeg<br />version: 0.2<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB File</h2></a> <p>short name: kbfile<br />version: 0.8<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> <tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> -<tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="OtherComponent"><a name="org.dllearner.algorithms.celoe.OEHeuristicRuntime"><h2>OEHeuristicRuntime</h2></a> +<p>short name: celoe_heuristic<br />version: 0.5<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> +</tbody></table> +</div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.OWLAPIReasoner"><h2>OWL API Reasoner</h2></a> <p>short name: oar<br />version: 0.8<br />implements: ReasonerComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>owlLinkURL</td><td>The URL to the owl server</td><td> String</td><td></td><td> false</td></tr> -<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet"}</td><td> String</td><td>pellet</td><td> false</td></tr> +<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.ocel.OCEL"><h2>OWL Class Expression Learner</h2></a> <p>short name: ocel<br />version: 1.2<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.OWLFile"><h2>OWL File</h2></a> <p>short name: owlfile<br />version: 0.9<br />implements: KnowledgeSource<br /></p>This component does not have configuration options.</div> +<div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.PCELOE"><h2>PCELOE</h2></a> +<p>short name: pceloe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>nrOfThreads</td><td>number of threads running in parallel</td><td> int</td><td>2</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> +<tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> +<tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStandard"><h2>PosNegLPStandard</h2></a> <p>short name: posNegStandard<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> <tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy.</td><td> String</td><td>predacc</td><td> false</td></tr> <tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> </tbody></table> </div> +<div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStrict"><h2>PosNegLPStrict</h2></a> +<p>short name: posNegStrict<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>accuracyPenalty</td><td>penalty for incorrectness (example belongs neither to concept nor its negation)</td><td> double</td><td>1</td><td> false</td></tr> +<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.RandomGuesser"><h2>Random Guesser</h2></a> <p>short name: randomGuesser<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.SparqlEndpointKS"><h2>SPARQL endpoint</h2></a> <p>short name: sparql<br />version: 0.2<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> -<tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> </tbody></table> </div> @@ -147,6 +199,18 @@ <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.simple.SparqlSimpleExtractor"><h2>efficient SPARQL fragment extractor</h2></a> +<p>short name: sparqls<br />version: 0.1<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>tboxfilter</td><td>Filter for the tbox, can use variable ?example and ?class</td><td> String</td><td></td><td> false</td></tr> +<tr><td>endpointURL</td><td>URL of the SPARQL endpoint</td><td> String</td><td></td><td> true</td></tr> +<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> +<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> +<tr><td>instances</td><td>List of the instances to use</td><td> List</td><td></td><td> true</td></tr> +<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> +<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> +<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner"><h2>equivalent dataproperty axiom learner</h2></a> <p>short name: dplequiv<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> DatatypeProperty</td><td></td><td> false</td></tr> @@ -180,12 +244,12 @@ </div> <div class="OtherComponent"><a name="org.dllearner.algorithms.ocel.MultiHeuristic"><h2>multiple criteria heuristic</h2></a> <p>short name: multiheuristic<br />version: 0.7<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> +<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> +<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> <tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> <tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> -<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> <tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> -<tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner"><h2>object subPropertyOf axiom learner</h2></a> @@ -205,22 +269,20 @@ </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosOnlyLP"><h2>positive only learning problem</h2></a> <p>short name: posonlylp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> -<div class="LearningAlgorithm"><a name="org.dllearner.algorithm.qtl.QTL"><h2>query tree learner</h2></a> -<p>short name: qtl<br />version: 0.8<br />implements: LearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.RhoDRDown"><h2>rho refinement operator</h2></a> <p>short name: rho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> @@ -234,6 +296,23 @@ <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> </tbody></table> </div> +<div class="RefinementOperator"><a name="org.dllearner.refinementoperators.SynchronizedRhoDRDown"><h2>synchronized rho refinement operator</h2></a> +<p>short name: syncrho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner"><h2>transitive objectproperty axiom learner</h2></a> <p>short name: opltrans<br />version: 0.1<br />implements: LearningAlgorithm, AxiomLearningAlgorithm<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>propertyToDescribe</td><td></td><td> ObjectProperty</td><td></td><td> false</td></tr> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-11-29 15:21:53
|
Revision: 3879 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3879&view=rev Author: jenslehmann Date: 2012-11-29 15:21:42 +0000 (Thu, 29 Nov 2012) Log Message: ----------- documentation update Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java trunk/examples/father.conf trunk/interfaces/doc/configOptions.html Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/ClassLearningProblem.java 2012-11-29 15:21:42 UTC (rev 3879) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2011, Jens Lehmann + * Copyright (C) 2007-2012, Jens Lehmann * * This file is part of DL-Learner. * @@ -19,7 +19,6 @@ package org.dllearner.learningproblems; -import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; @@ -34,12 +33,7 @@ import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.options.BooleanConfigOption; -import org.dllearner.core.options.CommonConfigOptions; -import org.dllearner.core.options.ConfigOption; -import org.dllearner.core.options.DoubleConfigOption; -import org.dllearner.core.options.StringConfigOption; -import org.dllearner.core.options.URLConfigOption; +import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; @@ -64,22 +58,26 @@ private long nanoStartTime; private int maxExecutionTimeInSeconds = 10; - // TODO: config option + @ConfigOption(name = "classToDescribe", description="class of which a description should be learned", required=true) private NamedClass classToDescribe; private List<Individual> classInstances; private TreeSet<Individual> classInstancesSet; private boolean equivalence = true; -// private ClassLearningProblemConfigurator configurator; - // approximation of accuracy + + @ConfigOption(name = "approxDelta", description = "The Approximate Delta", defaultValue = "0.05", required = false) private double approxDelta = 0.05; + @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false) private boolean useApproximations; // factor for higher weight on recall (needed for subclass learning) private double coverageFactor; + @ConfigOption(name = "betaSC", description="beta index for F-measure in super class learning", required=false, defaultValue="3.0") private double betaSC = 3.0; + + @ConfigOption(name = "betaEq", description="beta index for F-measure in definition learning", required=false, defaultValue="1.0") private double betaEq = 1.0; // instances of super classes excluding instances of the class itself @@ -89,8 +87,12 @@ // specific variables for generalised F-measure private TreeSet<Individual> negatedClassInstances; + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy. Available measues are \"pred_acc\" (predictive accuracy), \"fmeasure\" (F measure), \"generalised_fmeasure\" (generalised F-Measure according to Fanizzi and d'Amato).",defaultValue = "pred_acc") + private String accuracyMethod = "pred_acc"; + private HeuristicType heuristic = HeuristicType.AMEASURE; + @ConfigOption(name = "checkConsistency", description = "whether to check for consistency of suggestions (when added to ontology)", required=false, defaultValue="true") private boolean checkConsistency = true; public ClassLearningProblem() { @@ -106,6 +108,7 @@ // configurator = new ClassLearningProblemConfigurator(this); } + /* public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); URLConfigOption classToDescribeOption = new URLConfigOption("classToDescribe", "class of which a description should be learned", null, true, false); @@ -130,6 +133,7 @@ options.add(betaEq); return options; } + */ public static String getName() { return "class learning problem"; @@ -140,18 +144,18 @@ // classToDescribe = new NamedClass(configurator.getClassToDescribe().toString()); // useApproximations = configurator.getUseApproximations(); -// String accM = configurator.getAccuracyMethod(); -// if(accM.equals("standard")) { -// heuristic = HeuristicType.AMEASURE; -// } else if(accM.equals("fmeasure")) { -// heuristic = HeuristicType.FMEASURE; -// } else if(accM.equals("generalised_fmeasure")) { -// heuristic = HeuristicType.GEN_FMEASURE; -// } else if(accM.equals("jaccard")) { -// heuristic = HeuristicType.JACCARD; -// } else if(accM.equals("pred_acc")) { -// heuristic = HeuristicType.PRED_ACC; -// } + String accM = accuracyMethod; + if(accM.equals("standard")) { + heuristic = HeuristicType.AMEASURE; + } else if(accM.equals("fmeasure")) { + heuristic = HeuristicType.FMEASURE; + } else if(accM.equals("generalised_fmeasure")) { + heuristic = HeuristicType.GEN_FMEASURE; + } else if(accM.equals("jaccard")) { + heuristic = HeuristicType.JACCARD; + } else if(accM.equals("pred_acc")) { + heuristic = HeuristicType.PRED_ACC; + } if(useApproximations && heuristic.equals(HeuristicType.PRED_ACC)) { System.err.println("Approximating predictive accuracy is an experimental feature. USE IT AT YOUR OWN RISK. If you consider to use it for anything serious, please extend the unit tests at org.dllearner.test.junit.HeuristicTests first to verify that it works."); Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosNegLPStandard.java 2012-11-29 15:21:42 UTC (rev 3879) @@ -66,9 +66,9 @@ @ConfigOption(name = "useApproximations", description = "Use Approximations", defaultValue = "false", required = false) private boolean useApproximations; - @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy.",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) - private String accuracyMethod = "predacc"; - + @ConfigOption(name = "accuracyMethod", description = "Specifies, which method/function to use for computing accuracy. Available measues are \"pred_acc\" (predictive accuracy), \"fmeasure\" (F measure), \"generalised_fmeasure\" (generalised F-Measure according to Fanizzi and d'Amato).",defaultValue = "predacc", propertyEditorClass = StringTrimmerEditor.class) + private String accuracyMethod = "pred_acc"; + // private boolean useFMeasure; private boolean useOldDIGOptions = false; Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/examples/father.conf 2012-11-29 15:21:42 UTC (rev 3879) @@ -24,5 +24,6 @@ lp.negativeExamples = { "ex:heinz", "ex:anna", "ex:michelle" } // create learning algorithm to run -alg1.type = "celoe" -alg2.type = "pceloe" +alg.type = "celoe" +alg.maxExecutionTimeInSeconds = 1 + Modified: trunk/interfaces/doc/configOptions.html =================================================================== --- trunk/interfaces/doc/configOptions.html 2012-11-29 14:57:34 UTC (rev 3878) +++ trunk/interfaces/doc/configOptions.html 2012-11-29 15:21:42 UTC (rev 3879) @@ -65,27 +65,36 @@ <p>short name: bruteForce<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.CELOE"><h2>CELOE</h2></a> <p>short name: celoe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> <tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> -<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> <tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>stopOnFirstDefinition</td><td>algorithm will terminate immediately when a correct definition is found</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.ClassLearningProblem"><h2>ClassLearningProblem</h2></a> -<p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> +<p>short name: clp<br />version: 0.6<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy. Available measues are "pred_acc" (predictive accuracy), "fmeasure" (F measure), "generalised_fmeasure" (generalised F-Measure according to Fanizzi and d'Amato).</td><td> String</td><td>pred_acc</td><td> false</td></tr> +<tr><td>classToDescribe</td><td>class of which a description should be learned</td><td> NamedClass</td><td></td><td> true</td></tr> +<tr><td>checkConsistency</td><td>whether to check for consistency of suggestions (when added to ontology)</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> +<tr><td>betaSC</td><td>beta index for F-measure in super class learning</td><td> double</td><td>3.0</td><td> false</td></tr> +<tr><td>betaEq</td><td>beta index for F-measure in definition learning</td><td> double</td><td>1.0</td><td> false</td></tr> +<tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> +</tbody></table> +</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive"><h2>Disjunctive ELTL</h2></a> <p>short name: deltl<br />version: 0.5<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: Disjunctive ELTL is an algorithm based on the refinement operator in http://jens-lehmann.org/files/2009/el_ilp.pdf with support for disjunctions.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>tryFullCoverage</td><td>If yes, then the algorithm tries to cover all positive examples. Note that while this improves accuracy on the testing set, it may lead to overfitting.</td><td> boolean</td><td>false</td><td> false</td></tr> @@ -105,8 +114,8 @@ <p>short name: fuzzyPosNeg<br />version: 0.2<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.KBFile"><h2>KB File</h2></a> <p>short name: kbfile<br />version: 0.8<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> <tr><td>fileName</td><td>relative or absolute path to KB file</td><td> String</td><td></td><td> false</td></tr> -<tr><td>url</td><td>URL pointer to the KB file</td><td> String</td><td></td><td> false</td></tr> </tbody></table> </div> <div class="OtherComponent"><a name="org.dllearner.algorithms.celoe.OEHeuristicRuntime"><h2>OEHeuristicRuntime</h2></a> @@ -116,8 +125,8 @@ </div> <div class="ReasonerComponent"><a name="org.dllearner.reasoning.OWLAPIReasoner"><h2>OWL API Reasoner</h2></a> <p>short name: oar<br />version: 0.8<br />implements: ReasonerComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> <tr><td>owlLinkURL</td><td>The URL to the owl server</td><td> String</td><td></td><td> false</td></tr> -<tr><td>reasonerType</td><td>The name of the OWL APIReasoner to use {"fact", "hermit", "owllink", "pellet", "elk", "cel"}</td><td> String</td><td>pellet</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.ocel.OCEL"><h2>OWL Class Expression Learner</h2></a> @@ -126,45 +135,45 @@ <p>short name: owlfile<br />version: 0.9<br />implements: KnowledgeSource<br /></p>This component does not have configuration options.</div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.celoe.PCELOE"><h2>PCELOE</h2></a> <p>short name: pceloe<br />version: 1.0<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br />description: CELOE is an adapted and extended version of the OCEL algorithm applied for the ontology engineering use case. See http://jens-lehmann.org/files/2011/celoe.pdf for reference.<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> <tr><td>startClass</td><td>You can specify a start class for the algorithm. To do this, you have to use Manchester OWL syntax without using prefixes.</td><td> Description</td><td>owl:Thing</td><td> false</td></tr> -<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>maxExecutionTimeInSecondsAfterImprovement</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> <tr><td>nrOfThreads</td><td>number of threads running in parallel</td><td> int</td><td>2</td><td> false</td></tr> -<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>terminateOnNoiseReached</td><td>specifies whether to terminate when noise criterion is met</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>noisePercentage</td><td>the (approximated) percentage of noise within the examples</td><td> double</td><td>0.0</td><td> false</td></tr> +<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>filterDescriptionsFollowingFromKB</td><td>If true, then the results will not contain suggestions, which already follow logically from the knowledge base. Be careful, since this requires a potentially expensive consistency check for candidate solutions.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxDepth</td><td>maximum depth of description</td><td> double</td><td>7</td><td> false</td></tr> <tr><td>searchTreeFile</td><td>file to use for the search tree</td><td> String</td><td>log/searchTree.txt</td><td> false</td></tr> <tr><td>maxExecutionTimeInSeconds</td><td>maximum execution of the algorithm in seconds</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>writeSearchTree</td><td>specifies whether to write a search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useMinimizer</td><td>Specifies whether returned expressions should be minimised by removing those parts, which are not needed. (Basically the minimiser tries to find the shortest expression which is equivalent to the learned expression). Turning this feature off may improve performance.</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>maxClassExpressionTestsAfterImprovement</td><td>The maximum number of candidate hypothesis the algorithm is allowed after an improvement in accuracy (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>reuseExistingDescription</td><td>If true, the algorithm tries to find a good starting point close to an existing definition/super class of the given class in the knowledge base.</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>replaceSearchTree</td><td>specifies whether to replace the search tree in the log file after each run or append the new search tree</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>maxClassExpressionTests</td><td>The maximum number of candidate hypothesis the algorithm is allowed to test (0 = no limit). The algorithm will stop afterwards. (The real number of tests can be slightly higher, because this criterion usually won't be checked after each single test.)</td><td> int</td><td>0</td><td> false</td></tr> +<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>maxNrOfResults</td><td>Sets the maximum number of results one is interested in. (Setting this to a lower value may increase performance as the learning algorithm has to store/evaluate/beautify less descriptions).</td><td> int</td><td>10</td><td> false</td></tr> -<tr><td>singleSuggestionMode</td><td>Use this if you are interested in only one suggestion and your learning problem has many (more than 1000) examples.</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStandard"><h2>PosNegLPStandard</h2></a> <p>short name: posNegStandard<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>approxDelta</td><td>The Approximate Delta</td><td> double</td><td>0.05</td><td> false</td></tr> -<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy.</td><td> String</td><td>predacc</td><td> false</td></tr> +<tr><td>accuracyMethod</td><td>Specifies, which method/function to use for computing accuracy. Available measues are "pred_acc" (predictive accuracy), "fmeasure" (F measure), "generalised_fmeasure" (generalised F-Measure according to Fanizzi and d'Amato).</td><td> String</td><td>predacc</td><td> false</td></tr> <tr><td>useApproximations</td><td>Use Approximations</td><td> boolean</td><td>false</td><td> false</td></tr> </tbody></table> </div> <div class="LearningProblem"><a name="org.dllearner.learningproblems.PosNegLPStrict"><h2>PosNegLPStrict</h2></a> <p>short name: posNegStrict<br />version: 0.8<br />implements: LearningProblem<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> <tr><td>accuracyPenalty</td><td>penalty for incorrectness (example belongs neither to concept nor its negation)</td><td> double</td><td>1</td><td> false</td></tr> -<tr><td>errorPenalty</td><td>penalty for errors (example can be inferred to belong to the negated concept class)</td><td> double</td><td>3</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.RandomGuesser"><h2>Random Guesser</h2></a> <p>short name: randomGuesser<br />version: 0.8<br />implements: LearningAlgorithm, ClassExpressionLearningAlgorithm<br /></p>This component does not have configuration options.</div> <div class="KnowledgeSource"><a name="org.dllearner.kb.SparqlEndpointKS"><h2>SPARQL endpoint</h2></a> <p>short name: sparql<br />version: 0.2<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> <tr><td>namedGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> <tr><td>defaultGraphs</td><td>no description available</td><td> List</td><td>[]</td><td> false</td></tr> -<tr><td>url</td><td>no description available</td><td> URL</td><td></td><td> true</td></tr> </tbody></table> </div> <div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.SparqlKnowledgeSource"><h2>SPARQL endpoint fragment</h2></a> @@ -201,14 +210,14 @@ </div> <div class="KnowledgeSource"><a name="org.dllearner.kb.sparql.simple.SparqlSimpleExtractor"><h2>efficient SPARQL fragment extractor</h2></a> <p>short name: sparqls<br />version: 0.1<br />implements: KnowledgeSource<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> +<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> +<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> +<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> <tr><td>tboxfilter</td><td>Filter for the tbox, can use variable ?example and ?class</td><td> String</td><td></td><td> false</td></tr> +<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> <tr><td>endpointURL</td><td>URL of the SPARQL endpoint</td><td> String</td><td></td><td> true</td></tr> -<tr><td>ontologySchemaUrls</td><td>List of Ontology Schema URLs</td><td> List</td><td></td><td> true</td></tr> -<tr><td>aboxfilter</td><td>Filter for the tbox, can use variable ?s, ?p amd ?o</td><td> String</td><td></td><td> false</td></tr> <tr><td>instances</td><td>List of the instances to use</td><td> List</td><td></td><td> true</td></tr> -<tr><td>sparqlQuery</td><td>Sparql Query</td><td> String</td><td></td><td> false</td></tr> -<tr><td>defaultGraphURI</td><td>default graph URI</td><td> String</td><td></td><td> true</td></tr> -<tr><td>recursionDepth</td><td>recursion depth</td><td> int</td><td></td><td> true</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner"><h2>equivalent dataproperty axiom learner</h2></a> @@ -245,10 +254,10 @@ <div class="OtherComponent"><a name="org.dllearner.algorithms.ocel.MultiHeuristic"><h2>multiple criteria heuristic</h2></a> <p>short name: multiheuristic<br />version: 0.7<br />implements: OtherComponent<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> <tr><td>expansionPenaltyFactor</td><td>no description available</td><td> double</td><td>0.02</td><td> false</td></tr> -<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> +<tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> <tr><td>startNodeBonus</td><td>no description available</td><td> double</td><td>0.1</td><td> false</td></tr> <tr><td>negationPenalty</td><td>no description available</td><td> int</td><td>0</td><td> false</td></tr> -<tr><td>negativeWeight</td><td>no description available</td><td> double</td><td>1.0</td><td> false</td></tr> +<tr><td>gainBonusFactor</td><td>no description available</td><td> double</td><td>0.5</td><td> false</td></tr> <tr><td>nodeChildPenalty</td><td>no description available</td><td> double</td><td>0.0001</td><td> false</td></tr> </tbody></table> </div> @@ -271,19 +280,19 @@ <p>short name: posonlylp<br />version: 0.6<br />implements: LearningProblem<br /></p>This component does not have configuration options.</div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.RhoDRDown"><h2>rho refinement operator</h2></a> <p>short name: rho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm ClassExpressionLearningAlgorithm"><a name="org.dllearner.algorithms.SimpleSubclassLearner"><h2>simple subclass learner</h2></a> @@ -298,19 +307,19 @@ </div> <div class="RefinementOperator"><a name="org.dllearner.refinementoperators.SynchronizedRhoDRDown"><h2>synchronized rho refinement operator</h2></a> <p>short name: syncrho<br />version: 0.8<br />implements: RefinementOperator<br /></p><table id="hor-minimalist-a"><thead><tr><th>option name</th><th>description</th><th>type</th><th>default value</th><th>required?</th></tr></thead><tbody> +<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> +<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useAllConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useHasValueConstructor</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>instanceBasedDisjoints</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> +<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>dropDisjuncts</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> <tr><td>applyAllFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useDoubleDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useNegation</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useStringDatatypes</td><td>no description available</td><td> boolean</td><td>false</td><td> false</td></tr> -<tr><td>useBooleanDatatypes</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>useExistsConstructor</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> <tr><td>useCardinalityRestrictions</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>applyExistsFilter</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> -<tr><td>disjointChecks</td><td>no description available</td><td> boolean</td><td>true</td><td> false</td></tr> </tbody></table> </div> <div class="LearningAlgorithm AxiomLearningAlgorithm"><a name="org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner"><h2>transitive objectproperty axiom learner</h2></a> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-01-25 12:02:22
|
Revision: 3891 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3891&view=rev Author: lorenz_b Date: 2013-01-25 12:02:10 +0000 (Fri, 25 Jan 2013) Log Message: ----------- Started script for instance based matching of 2 SPARQL knowledge bases. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/matching/GeneralMatcher.java trunk/test/qtl/dbpedia_simple.conf Added Paths: ----------- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2013-01-23 13:30:14 UTC (rev 3890) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SPARQLTasks.java 2013-01-25 12:02:10 UTC (rev 3891) @@ -701,7 +701,7 @@ public Set<NamedClass> getAllClasses() { Set<NamedClass> classes = new TreeSet<NamedClass>(); - String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?c WHERE {?c a owl:Class} LIMIT 1000"; + String query = "SELECT ?c WHERE {?c a <http://www.w3.org/2002/07/owl#Class>} LIMIT 1000"; /* * String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " + "SELECT ?c WHERE {{?c a owl:Class} UNION {?c rdfs:subClassOf ?d} UNION {?d rdfs:subClassOf ?c}} LIMIT 1000"; Modified: trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2013-01-23 13:30:14 UTC (rev 3890) +++ trunk/components-core/src/main/java/org/dllearner/learningproblems/PosOnlyLP.java 2013-01-25 12:02:10 UTC (rev 3891) @@ -64,6 +64,11 @@ public PosOnlyLP(AbstractReasonerComponent reasoningService) { super(reasoningService); } + + public PosOnlyLP(AbstractReasonerComponent reasoningService, SortedSet<Individual> positiveExamples) { + super(reasoningService); + this.positiveExamples = positiveExamples; + } /* * (non-Javadoc) Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2013-01-23 13:30:14 UTC (rev 3890) +++ trunk/scripts/pom.xml 2013-01-25 12:02:10 UTC (rev 3891) @@ -25,6 +25,10 @@ <artifactId>jena</artifactId> <groupId>com.hp.hpl.jena</groupId> </exclusion> + <exclusion> + <artifactId>owlapi</artifactId> + <groupId>net.sourceforge.owlapi</groupId> + </exclusion> </exclusions> </dependency> <dependency> @@ -40,6 +44,12 @@ <dependency> <groupId>org.dllearner</groupId> <artifactId>interfaces</artifactId> + <exclusions> + <exclusion> + <artifactId>owlapi</artifactId> + <groupId>net.sourceforge.owlapi</groupId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>net.sourceforge.secondstring</groupId> @@ -49,12 +59,12 @@ <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> - <dependency> - <groupId>com.dumontierlab</groupId> - <artifactId>pdb2rdf-parser</artifactId> - </dependency> <dependency> <groupId>com.dumontierlab</groupId> + <artifactId>pdb2rdf-parser</artifactId> + </dependency> + <dependency> + <groupId>com.dumontierlab</groupId> <artifactId>pdb2rdf-cli</artifactId> <exclusions> <exclusion> @@ -84,8 +94,8 @@ <groupId>org.deri.any23</groupId> </exclusion> <exclusion> - <artifactId>jena-core</artifactId> - <groupId>org.apache.jena</groupId> + <artifactId>jena-core</artifactId> + <groupId>org.apache.jena</groupId> </exclusion> </exclusions> </dependency> @@ -103,6 +113,30 @@ <artifactId>weka</artifactId> <version>3.6.5</version> </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-distribution</artifactId> + </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-reasoner</artifactId> + <exclusions> + <exclusion> + <artifactId>owlapi-api</artifactId> + <groupId>net.sourceforge.owlapi</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>net.sourceforge.owlapi</groupId> + <artifactId>owlapi-util</artifactId> + <exclusions> + <exclusion> + <artifactId>owlapi-api</artifactId> + <groupId>net.sourceforge.owlapi</groupId> + </exclusion> + </exclusions> + </dependency> </dependencies> Added: trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java 2013-01-25 12:02:10 UTC (rev 3891) @@ -0,0 +1,291 @@ +package org.dllearner.scripts; + +import java.net.URL; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.OWL; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + +public class OntologyMatching { + + + private static final Logger logger = Logger.getLogger(OntologyMatching.class.getName()); + + private final ObjectProperty sameAs = new ObjectProperty(OWL.sameAs.getURI()); + private final Monitor mon; + + //KB1 + private KnowledgeBase kb1; + //KB2 + private KnowledgeBase kb2; + + public OntologyMatching(KnowledgeBase kb1, KnowledgeBase kb2) { + this.kb1 = kb1; + this.kb2 = kb2; + + mon = MonitorFactory.getTimeMonitor("time"); + } + + public OntologyMatching(SparqlEndpoint endpoint1, SparqlEndpoint endpoint2) { + this(new KnowledgeBase(endpoint1), new KnowledgeBase(endpoint2)); + } + + public void start(){ + computeMatching(kb1, kb2); + computeMatching(kb2, kb1); + } + + private void computeMatching(KnowledgeBase source, KnowledgeBase target) { + // get all classes in SOURCE + Set<NamedClass> sourceClasses = getClasses(source); + + // for each class of KB1 + for (NamedClass nc : sourceClasses) { + logger.info(nc); + // get all via owl:sameAs related individuals + SortedSet<Individual> individuals = getRelatedIndividualsNamespaceAware(source, nc, target.getNamespace()); + logger.info(individuals); + //learn concept in KB2 based on the examples + if(individuals.size() >= 3){ + learnClassExpression(target, individuals); + } + } + } + + private void learnClassExpression(KnowledgeBase kb, SortedSet<Individual> posExamples){ + learnClassExpression(kb, posExamples, false); + } + + private void learnClassExpression(KnowledgeBase kb, SortedSet<Individual> positiveExamples, boolean posNeg){ + try { + SortedSet<Individual> negativeExamples = new TreeSet<Individual>(); + if(posNeg){ + //find negative examples + mon.start(); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(kb.getEndpoint()); + //TODO find negative examples + mon.stop(); + logger.info("Found " + negativeExamples.size() + " negative examples in " + mon.getLastValue() + "ms."); + } + + SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(positiveExamples, negativeExamples); + + SparqlKnowledgeSource ks = new SparqlKnowledgeSource(); + ks.setInstances(Datastructures.individualSetToStringSet(examples.getCompleteSet())); + ks.setUrl(kb.getEndpoint().getURL()); + ks.setDefaultGraphURIs(new TreeSet<String>(kb.getEndpoint().getDefaultGraphURIs())); + ks.setUseLits(false); + ks.setUseCacheDatabase(true); + ks.setCacheDir("cache"); + ks.setRecursionDepth(2); + ks.setCloseAfterRecursion(true); + ks.setDissolveBlankNodes(false); + ks.setSaveExtractedFragment(false); + ks.init(); + + AbstractReasonerComponent rc = new FastInstanceChecker(ks); + rc.init(); + + AbstractLearningProblem lp; + if(posNeg){ + lp = new PosNegLPStandard(rc, positiveExamples, negativeExamples); + } else { + lp = new PosOnlyLP(rc, positiveExamples); + + } + lp.init(); + + CELOE la = new CELOE(lp, rc); + la.setMaxExecutionTimeInSeconds(10); + la.setNoisePercentage(25); + la.init(); + la.start(); + + logger.info(la.getCurrentlyBestEvaluatedDescription()); + } catch (ComponentInitException e) { + e.printStackTrace(); + } + } + + private Set<NamedClass> getClasses(KnowledgeBase kb){ + Set<NamedClass> classes = kb.getSparqlHelper().getAllClasses(); + //fallback: check for ?s a ?type where ?type is not asserted to owl:Class + if(classes.isEmpty()){ + String query = "SELECT ?type WHERE {?s a ?type.}"; + ResultSet rs = executeSelect(kb, query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + if(qs.get("type").isURIResource()){ + classes.add(new NamedClass(qs.get("type").asResource().getURI())); + } + } + } + return classes; + } + + private SortedSet<Individual> getRelatedIndividualsNaive(KnowledgeBase kb, NamedClass nc){ + SortedSet<Individual> relatedIndividuals = new TreeSet<Individual>(); + //get all individuals in given class nc + Set<Individual> individuals = kb.getReasoner().getIndividuals(nc); + //for each individual in class nc + for(Individual ind : individuals){ + //get all individuals related via owl:sameAs + Set<Individual> sameIndividuals = kb.getReasoner().getRelatedIndividuals(ind, sameAs); + relatedIndividuals.addAll(sameIndividuals); + } + return relatedIndividuals; + } + + private SortedSet<Individual> getRelatedIndividuals(KnowledgeBase kb, NamedClass nc){ + SortedSet<Individual> relatedIndividuals = new TreeSet<Individual>(); + //get all individuals o which are connected to individuals s belonging to class nc + String query = String.format("SELECT ?o WHERE {?s a <%s>. ?s <http://www.w3.org/2002/07/owl#sameAs> ?o.}", nc.getName()); + ResultSet rs = executeSelect(kb, query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + RDFNode object = qs.get("o"); + if(object.isURIResource()){ + relatedIndividuals.add(new Individual(object.asResource().getURI())); + } + } + return relatedIndividuals; + } + + private SortedSet<Individual> getRelatedIndividualsNamespaceAware(KnowledgeBase kb, NamedClass nc, String targetNamespace){ + SortedSet<Individual> relatedIndividuals = new TreeSet<Individual>(); + //get all individuals o which are connected to individuals s belonging to class nc + String query = String.format("SELECT ?o WHERE {?s a <%s>. ?s <http://www.w3.org/2002/07/owl#sameAs> ?o. FILTER(REGEX(STR(?o),'%s'))}", nc.getName(), targetNamespace); + ResultSet rs = executeSelect(kb, query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + RDFNode object = qs.get("o"); + if(object.isURIResource()){ + relatedIndividuals.add(new Individual(object.asResource().getURI())); + } + } + return relatedIndividuals; + } + + protected ResultSet executeSelect(KnowledgeBase kb, String query){ + return executeSelect(kb, QueryFactory.create(query, Syntax.syntaxARQ)); + } + + protected ResultSet executeSelect(KnowledgeBase kb, Query query){ + ExtractionDBCache cache = kb.getCache(); + SparqlEndpoint endpoint = kb.getEndpoint(); + ResultSet rs = null; + if(cache != null){ + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query.toString())); + } else { + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), query); + for(String uri : endpoint.getDefaultGraphURIs()){ + qe.addDefaultGraph(uri); + } + rs = qe.execSelect(); + } + return rs; + } + + public static class KnowledgeBase{ + private SparqlEndpoint endpoint; + private SPARQLReasoner reasoner; + private SPARQLTasks sparqlHelper; + private String namespace; + private ExtractionDBCache cache; + + public KnowledgeBase(SparqlEndpoint endpoint, ExtractionDBCache cache, String namespace) { + this.endpoint = endpoint; + this.namespace = namespace; + this.cache = cache; + + this.reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + this.sparqlHelper = new SPARQLTasks(endpoint); + } + + public KnowledgeBase(SparqlEndpoint endpoint) { + this.endpoint = endpoint; + + this.reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + this.sparqlHelper = new SPARQLTasks(endpoint); + } + + public SparqlEndpoint getEndpoint() { + return endpoint; + } + + public SPARQLReasoner getReasoner() { + return reasoner; + } + + public SPARQLTasks getSparqlHelper() { + return sparqlHelper; + } + + public String getNamespace() { + return namespace; + } + + public ExtractionDBCache getCache() { + return cache; + } + + + + } + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + // KB2 + SparqlEndpoint endpoint1 = SparqlEndpoint.getEndpointDBpedia(); + ExtractionDBCache cache1 = new ExtractionDBCache("cache"); + String namespace1 = "http://dbpedia.org/resource/"; + KnowledgeBase kb1 = new KnowledgeBase(endpoint1, cache1, namespace1); + // KB2 + SparqlEndpoint endpoint2 = new SparqlEndpoint(new URL("http://wifo5-03.informatik.uni-mannheim.de/factbook/sparql")); + ExtractionDBCache cache2 = new ExtractionDBCache("cache"); + String namespace2 = "http://www4.wiwiss.fu-berlin.de/factbook/resource/"; + KnowledgeBase kb2 = new KnowledgeBase(endpoint2, cache2, namespace2); + + OntologyMatching matcher = new OntologyMatching(kb1, kb2); + matcher.start(); + + } + +} Modified: trunk/scripts/src/main/java/org/dllearner/scripts/matching/GeneralMatcher.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/matching/GeneralMatcher.java 2013-01-23 13:30:14 UTC (rev 3890) +++ trunk/scripts/src/main/java/org/dllearner/scripts/matching/GeneralMatcher.java 2013-01-25 12:02:10 UTC (rev 3891) @@ -24,7 +24,7 @@ import java.util.LinkedList; import java.util.Set; -import org.dllearner.algorithm.qtl.QTL; +import org.dllearner.algorithms.qtl.QTL; import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.kb.SparqlEndpointKS; Modified: trunk/test/qtl/dbpedia_simple.conf =================================================================== --- trunk/test/qtl/dbpedia_simple.conf 2013-01-23 13:30:14 UTC (rev 3890) +++ trunk/test/qtl/dbpedia_simple.conf 2013-01-25 12:02:10 UTC (rev 3891) @@ -2,7 +2,7 @@ prefixes = [ ("dbr","http://dbpedia.org/resource/") ] ks.type = "SPARQL" -ks.url = "http://live.dbpedia.org/sparql" +ks.url = "http://dbpedia.org/sparql" ks.defaultGraphURIs = { "http://dbpedia.org" } // learning problem @@ -10,3 +10,4 @@ lp.positiveExamples = { "dbr:Bob_Dylan", "dbr:The_Beatles", "dbr:Aerosmith" } alg.type = "qtl" +alg.maxQueryTreeDepth = 1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-02-16 13:03:08
|
Revision: 3899 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3899&view=rev Author: lorenz_b Date: 2013-02-16 13:03:00 +0000 (Sat, 16 Feb 2013) Log Message: ----------- Added option to work on JENA model. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/cli/CLI.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Knowledgebase.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PopularityMap.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LocalKnowledgebase.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/RemoteKnowledgebase.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/qtl/QTL.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -68,7 +68,9 @@ import org.dllearner.utilities.Helper; import org.springframework.beans.factory.annotation.Autowired; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Statement; @@ -94,6 +96,7 @@ // private QTLConfigurator configurator; private SparqlEndpoint endpoint; + private Model model; private ExtractionDBCache cache; private QueryTreeCache treeCache; @@ -157,6 +160,21 @@ negExampleTrees = new ArrayList<QueryTree<String>>(); } + public QTL(Model model) { + this.model = model; + + treeCache = new QueryTreeCache(); + cbdGenerator = new CachingConciseBoundedDescriptionGenerator(new ConciseBoundedDescriptionGeneratorImpl(model)); + cbdGenerator.setRecursionDepth(maxQueryTreeDepth); + + lggGenerator = new LGGGeneratorImpl<String>(); + nbr = new NBR<String>(model); + nbr.setMaxExecutionTimeInSeconds(maxExecutionTimeInSeconds); + + posExampleTrees = new ArrayList<QueryTree<String>>(); + negExampleTrees = new ArrayList<QueryTree<String>>(); + } + public String getQuestion(List<String> posExamples, List<String> negExamples) throws EmptyLGGException, NegativeTreeCoverageExecption, TimeOutException { this.posExamples = posExamples; this.negExamples = negExamples; @@ -312,8 +330,13 @@ private SortedSet<String> getResources(QueryTree<String> tree){ SortedSet<String> resources = new TreeSet<String>(); String query = getDistinctSPARQLQuery(tree); - String result = cache.executeSelectQuery(endpoint, query); - ResultSetRewindable rs = SparqlQuery.convertJSONtoResultSet(result); + ResultSet rs; + if(endpoint != null){ + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + } else { + rs = QueryExecutionFactory.create(query, model).execSelect(); + } + String uri; QuerySolution qs; while(rs.hasNext()){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/cli/CLI.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/cli/CLI.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/cli/CLI.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -10,6 +10,7 @@ import org.dllearner.algorithm.tbsl.learning.NoTemplateFoundException; import org.dllearner.algorithm.tbsl.learning.SPARQLTemplateBasedLearner2; import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.algorithm.tbsl.util.RemoteKnowledgebase; import org.dllearner.common.index.Index; import org.dllearner.common.index.SOLRIndex; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -30,7 +31,7 @@ Index propertiesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_properties"); - Knowledgebase kb = new Knowledgebase(endpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, null); + Knowledgebase kb = new RemoteKnowledgebase(endpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, null); SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(kb); System.out.println("======= TBSL v0.1 ============="); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -44,7 +44,9 @@ import org.dllearner.algorithm.tbsl.sparql.WeightedQuery; import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.algorithm.tbsl.util.LocalKnowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap; +import org.dllearner.algorithm.tbsl.util.RemoteKnowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; import org.dllearner.algorithm.tbsl.util.Similarity; import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; @@ -163,12 +165,44 @@ } public SPARQLTemplateBasedLearner2(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ - this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options); + this(knowledgebase, posTagger, wordNet, options, null); } public SPARQLTemplateBasedLearner2(Knowledgebase knowledgebase){ - this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); + this(knowledgebase, new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); } + + public SPARQLTemplateBasedLearner2(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ + if(knowledgebase instanceof LocalKnowledgebase){ + this.model = ((LocalKnowledgebase) knowledgebase).getModel(); + } else { + this.endpoint = ((RemoteKnowledgebase) knowledgebase).getEndpoint(); + } + this.resourcesIndex = knowledgebase.getResourceIndex(); + this.classesIndex = knowledgebase.getClassIndex(); + this.propertiesIndex = knowledgebase.getPropertyIndex(); + this.mappingIndex = knowledgebase.getMappingIndex(); + if(propertiesIndex instanceof SPARQLPropertiesIndex){ + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } + } else { + datatypePropertiesIndex = propertiesIndex; + objectPropertiesIndex = propertiesIndex; + } + this.posTagger = posTagger; + this.wordNet = wordNet; + this.cache = cache; + + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + setOptions(options); + + setMappingIndex(knowledgebase.getMappingIndex()); + } public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index index){ this(endpoint, index, new StanfordPartOfSpeechTagger()); @@ -301,7 +335,11 @@ } public void setKnowledgebase(Knowledgebase knowledgebase){ - this.endpoint = knowledgebase.getEndpoint(); + if(knowledgebase instanceof LocalKnowledgebase){ + this.model = ((LocalKnowledgebase) knowledgebase).getModel(); + } else { + this.endpoint = ((RemoteKnowledgebase) knowledgebase).getEndpoint(); + } this.resourcesIndex = knowledgebase.getResourceIndex(); this.classesIndex = knowledgebase.getClassIndex(); this.propertiesIndex = knowledgebase.getPropertyIndex(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -46,7 +46,9 @@ import org.dllearner.algorithm.tbsl.sparql.WeightedQuery; import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.algorithm.tbsl.util.LocalKnowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap; +import org.dllearner.algorithm.tbsl.util.RemoteKnowledgebase; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; import org.dllearner.algorithm.tbsl.util.SPARQLEndpointMetrics; import org.dllearner.algorithm.tbsl.util.Similarity; @@ -171,17 +173,44 @@ } public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ - this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options); + this(knowledgebase, posTagger, wordNet, options, null); setMappingIndex(knowledgebase.getMappingIndex()); } public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ - this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options, cache); + if(knowledgebase instanceof LocalKnowledgebase){ + this.model = ((LocalKnowledgebase) knowledgebase).getModel(); + } else { + this.endpoint = ((RemoteKnowledgebase) knowledgebase).getEndpoint(); + } + this.resourcesIndex = knowledgebase.getResourceIndex(); + this.classesIndex = knowledgebase.getClassIndex(); + this.propertiesIndex = knowledgebase.getPropertyIndex(); + this.mappingIndex = knowledgebase.getMappingIndex(); + if(propertiesIndex instanceof SPARQLPropertiesIndex){ + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } + } else { + datatypePropertiesIndex = propertiesIndex; + objectPropertiesIndex = propertiesIndex; + } + this.posTagger = posTagger; + this.wordNet = wordNet; + this.cache = cache; + + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + setOptions(options); + setMappingIndex(knowledgebase.getMappingIndex()); } public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase){ - this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); + this(knowledgebase, new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); setMappingIndex(knowledgebase.getMappingIndex()); } @@ -303,7 +332,11 @@ } public void setKnowledgebase(Knowledgebase knowledgebase){ - this.endpoint = knowledgebase.getEndpoint(); + if(knowledgebase instanceof LocalKnowledgebase){ + this.model = ((LocalKnowledgebase) knowledgebase).getModel(); + } else { + this.endpoint = ((RemoteKnowledgebase) knowledgebase).getEndpoint(); + } this.resourcesIndex = knowledgebase.getResourceIndex(); this.classesIndex = knowledgebase.getClassIndex(); this.propertiesIndex = knowledgebase.getPropertyIndex(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Knowledgebase.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Knowledgebase.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/Knowledgebase.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -2,12 +2,10 @@ import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; -import org.dllearner.kb.sparql.SparqlEndpoint; -public class Knowledgebase { +public abstract class Knowledgebase { private String label; - private SparqlEndpoint endpoint; private String description; private Index resourceIndex; @@ -16,30 +14,25 @@ private MappingBasedIndex mappingIndex; - public Knowledgebase(SparqlEndpoint endpoint, String label, String description, + public Knowledgebase(String label, String description, Index resourceIndex, Index propertyIndex, Index classIndex) { - this(endpoint, label, description, resourceIndex, propertyIndex, classIndex, null); + this(label, description, resourceIndex, propertyIndex, classIndex, null); } - public Knowledgebase(SparqlEndpoint endpoint, String label, String description, + public Knowledgebase(String label, String description, Index resourceIndex, Index propertyIndex, Index classIndex, MappingBasedIndex mappingIndex) { this.label = label; - this.endpoint = endpoint; this.description = description; this.resourceIndex = resourceIndex; this.propertyIndex = propertyIndex; this.classIndex = classIndex; this.mappingIndex = mappingIndex; } - + public String getLabel() { return label; } - public SparqlEndpoint getEndpoint() { - return endpoint; - } - public String getDescription() { return description; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LocalKnowledgebase.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LocalKnowledgebase.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/LocalKnowledgebase.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -0,0 +1,22 @@ +package org.dllearner.algorithm.tbsl.util; + +import org.dllearner.common.index.Index; +import org.dllearner.common.index.MappingBasedIndex; + +import com.hp.hpl.jena.rdf.model.Model; + +public class LocalKnowledgebase extends Knowledgebase{ + + private Model model; + + public LocalKnowledgebase(Model model, String label, String description, Index resourceIndex, Index propertyIndex, + Index classIndex, MappingBasedIndex mappingIndex) { + super(label, description, resourceIndex, propertyIndex, classIndex, mappingIndex); + this.model = model; + } + + public Model getModel() { + return model; + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PopularityMap.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PopularityMap.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PopularityMap.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -20,8 +20,10 @@ import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; public class PopularityMap { @@ -30,6 +32,7 @@ } private SparqlEndpoint endpoint; + private Model model; private ExtractionDBCache cache; private String file; @@ -41,9 +44,13 @@ this.file = file; this.endpoint = endpoint; this.cache = cache; - } + public PopularityMap(String file, Model model) { + this.file = file; + this.model = model; + } + public void init() { boolean deserialized = deserialize(); if(!deserialized){ @@ -137,7 +144,12 @@ query = String.format("SELECT COUNT(*) WHERE {?s ?p <%s>}", uri); } int pop = 0; - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + ResultSet rs; + if(endpoint != null){ + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + } else { + rs = QueryExecutionFactory.create(query, model).execSelect(); + } QuerySolution qs; String projectionVar; while(rs.hasNext()){ Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/RemoteKnowledgebase.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/RemoteKnowledgebase.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/RemoteKnowledgebase.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -0,0 +1,22 @@ +package org.dllearner.algorithm.tbsl.util; + +import org.dllearner.common.index.Index; +import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.kb.sparql.SparqlEndpoint; + +public class RemoteKnowledgebase extends Knowledgebase{ + + private SparqlEndpoint endpoint; + + public RemoteKnowledgebase(SparqlEndpoint endpoint, String label, String description, Index resourceIndex, Index propertyIndex, + Index classIndex, MappingBasedIndex mappingIndex) { + super(label, description, resourceIndex, propertyIndex, classIndex, mappingIndex); + this.endpoint = endpoint; + } + + public SparqlEndpoint getEndpoint() { + return endpoint; + } + + +} Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -42,6 +42,7 @@ import org.dllearner.algorithm.tbsl.sparql.WeightedQuery; import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.algorithm.tbsl.util.LatexWriter; +import org.dllearner.algorithm.tbsl.util.RemoteKnowledgebase; import org.dllearner.common.index.Index; import org.dllearner.common.index.SOLRIndex; import org.dllearner.kb.sparql.ExtractionDBCache; @@ -99,7 +100,7 @@ Index propertiesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_properties"); - Knowledgebase kb = new Knowledgebase(endpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, null); + Knowledgebase kb = new RemoteKnowledgebase(endpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, null); stbl = new SPARQLTemplateBasedLearner2(kb); stbl.setUseIdealTagger(USE_IDEAL_TAGGER); Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2013-02-11 12:18:04 UTC (rev 3898) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2013-02-16 13:03:00 UTC (rev 3899) @@ -55,6 +55,7 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.algorithm.tbsl.util.RemoteKnowledgebase; import org.dllearner.common.index.HierarchicalIndex; import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; @@ -794,7 +795,7 @@ SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("test/dbpedia_objectproperty_mappings.txt").getPath() ); - Knowledgebase kb = new Knowledgebase(dbpediaLiveEndpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); + Knowledgebase kb = new RemoteKnowledgebase(dbpediaLiveEndpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); return kb; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-02-27 13:49:04
|
Revision: 3906 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3906&view=rev Author: lorenz_b Date: 2013-02-27 13:48:57 +0000 (Wed, 27 Feb 2013) Log Message: ----------- Added cross validation to matching tests. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java trunk/scripts/src/test/java/org/dllearner/junit/OntologyMatchingTest.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java 2013-02-25 12:24:29 UTC (rev 3905) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlEndpoint.java 2013-02-27 13:48:57 UTC (rev 3906) @@ -210,6 +210,18 @@ return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); } + public static SparqlEndpoint getEndpointLOD2Cloud() { + URL u = null; + try { + u = new URL("http://lod.openlinksw.com/sparql/"); + } catch (Exception e) { + e.printStackTrace(); + } + LinkedList<String> defaultGraphURIs=new LinkedList<String>(); +// defaultGraphURIs.add("http://dbpedia.org"); + return new SparqlEndpoint(u, defaultGraphURIs, new LinkedList<String>()); + } + public static SparqlEndpoint getEndpointLinkedGeoData() { URL u = null; try { Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2013-02-25 12:24:29 UTC (rev 3905) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CrossValidation.java 2013-02-27 13:48:57 UTC (rev 3906) @@ -27,7 +27,9 @@ import java.util.List; import java.util.Random; import java.util.Set; +import java.util.TreeSet; +import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractReasonerComponent; @@ -35,6 +37,7 @@ import org.dllearner.core.owl.Individual; import org.dllearner.learningproblems.Heuristics; import org.dllearner.learningproblems.PosNegLP; +import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.statistics.Stat; @@ -70,7 +73,7 @@ } - public CrossValidation(AbstractCELA la, PosNegLP lp, AbstractReasonerComponent rs, int folds, boolean leaveOneOut) { + public CrossValidation(AbstractCELA la, AbstractLearningProblem lp, AbstractReasonerComponent rs, int folds, boolean leaveOneOut) { DecimalFormat df = new DecimalFormat(); @@ -81,11 +84,20 @@ List<Set<Individual>> testSetsNeg = new LinkedList<Set<Individual>>(); // get examples and shuffle them too - Set<Individual> posExamples = ((PosNegLP)lp).getPositiveExamples(); + Set<Individual> posExamples; + Set<Individual> negExamples; + if(lp instanceof PosNegLP){ + posExamples = ((PosNegLP)lp).getPositiveExamples(); + negExamples = ((PosNegLP)lp).getNegativeExamples(); + } else if(lp instanceof PosOnlyLP){ + posExamples = ((PosNegLP)lp).getPositiveExamples(); + negExamples = new HashSet<Individual>(); + } else { + throw new IllegalArgumentException("Only PosNeg and PosOnly learning problems are supported"); + } List<Individual> posExamplesList = new LinkedList<Individual>(posExamples); + List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); Collections.shuffle(posExamplesList, new Random(1)); - Set<Individual> negExamples = ((PosNegLP)lp).getNegativeExamples(); - List<Individual> negExamplesList = new LinkedList<Individual>(negExamples); Collections.shuffle(negExamplesList, new Random(2)); // sanity check whether nr. of folds makes sense for this benchmark @@ -137,8 +149,13 @@ Set<String> pos = Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); Set<String> neg = Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); - lp.setPositiveExamples(trainingSetsPos.get(currFold)); - lp.setNegativeExamples(trainingSetsNeg.get(currFold)); + if(lp instanceof PosNegLP){ + ((PosNegLP)lp).setPositiveExamples(trainingSetsPos.get(currFold)); + ((PosNegLP)lp).setNegativeExamples(trainingSetsNeg.get(currFold)); + } else if(lp instanceof PosOnlyLP){ + ((PosOnlyLP)lp).setPositiveExamples(new TreeSet<Individual>(trainingSetsPos.get(currFold))); + } + try { lp.init(); Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2013-02-25 12:24:29 UTC (rev 3905) +++ trunk/scripts/pom.xml 2013-02-27 13:48:57 UTC (rev 3906) @@ -116,7 +116,7 @@ <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> - <version>3.4</version> + <version>3.4.4-SNAPSHOT</version> </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> Modified: trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java 2013-02-25 12:24:29 UTC (rev 3905) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMatching.java 2013-02-27 13:48:57 UTC (rev 3906) @@ -44,6 +44,7 @@ import org.dllearner.learningproblems.PosOnlyLP; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.SPARQLReasoner; +import org.dllearner.utilities.CrossValidation; import org.dllearner.utilities.LabelShortFormProvider; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.datastructures.SetManipulation; @@ -75,6 +76,8 @@ import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; @@ -95,6 +98,8 @@ private Map<Description, List<? extends EvaluatedDescription>> mappingKB2KB1; private boolean posNegLearning = true; + private final boolean performCrossValidation = true; + private int fragmentDepth = 2; /** * The maximum number of positive examples, used for the SPARQL extraction and learning algorithm @@ -118,6 +123,10 @@ this(new KnowledgeBase(endpoint1), new KnowledgeBase(endpoint2)); } + public void setFragmentDepth(int fragmentDepth) { + this.fragmentDepth = fragmentDepth; + } + public void start(){ mappingKB1KB2 = computeAlignment(kb1, kb2); printMappingPretty(mappingKB1KB2); @@ -283,14 +292,16 @@ fullFragment.add(positiveFragment); fullFragment.add(negativeFragment); - //here is the most difficult task, i.e. find a 'good' fragment of the KB on which we can learn KnowledgeSource ks = convert(fullFragment); //initialize the reasoner + logger.info("Initializing reasoner..."); AbstractReasonerComponent rc = new FastInstanceChecker(ks); rc.init(); + logger.info("Done."); //initialize the learning problem + logger.info("Initializing learning problem..."); AbstractLearningProblem lp; if(posNeg){ lp = new PosNegLPStandard(rc, positiveExamplesSample, negativeExamplesSample); @@ -298,26 +309,34 @@ lp = new PosOnlyLP(rc, positiveExamplesSample); } lp.init(); + logger.info("Done."); - //apply the learning algorithm - logger.info("Running learning algorithm..."); + //initialize the learning algorithm + logger.info("Initializing learning algorithm..."); CELOE la = new CELOE(lp, rc); la.setMaxExecutionTimeInSeconds(10); la.setNoisePercentage(25); la.init(); - la.start(); + logger.info("Done."); - try { - QTL qtl = new QTL(lp, new LocalModelBasedSparqlEndpointKS(fullFragment)); - qtl.init(); - qtl.start(); - System.out.println(qtl.getSPARQLQuery()); - } catch (LearningProblemUnsupportedException e) { - e.printStackTrace(); + if(performCrossValidation){ + CrossValidation cv = new CrossValidation(la, lp, rc, 5, false); + } else { + //apply the learning algorithm + logger.info("Running learning algorithm..."); + la.start(); + logger.info(la.getCurrentlyBestEvaluatedDescription()); } - - logger.info(la.getCurrentlyBestEvaluatedDescription()); +// try { +// QTL qtl = new QTL(lp, new LocalModelBasedSparqlEndpointKS(fullFragment)); +// qtl.init(); +// qtl.start(); +// System.out.println(qtl.getSPARQLQuery()); +// } catch (LearningProblemUnsupportedException e) { +// e.printStackTrace(); +// } + return la.getCurrentlyBestEvaluatedDescriptions(10); } catch (ComponentInitException e) { e.printStackTrace(); @@ -382,21 +401,32 @@ logger.info(i++ + "/" + size); fullFragment.add(getFragment(ind, kb)); } - //filter out triples with String literals, as there often occur are some syntax errors and they are not relevant for learning + filter(fullFragment); + return fullFragment; + } + + private void filter(Model model) { + // filter out triples with String literals, as there often occur are + // some syntax errors and they are not relevant for learning List<Statement> statementsToRemove = new ArrayList<Statement>(); - for(Iterator<Statement> iter = fullFragment.listStatements().toList().iterator(); iter.hasNext();){ + for (Iterator<Statement> iter = model.listStatements().toList().iterator(); iter.hasNext();) { Statement st = iter.next(); RDFNode object = st.getObject(); - if(object.isLiteral()){ -// statementsToRemove.add(st); + if (object.isLiteral()) { + // statementsToRemove.add(st); Literal lit = object.asLiteral(); - if(lit.getDatatype() == null || lit.getDatatype().equals(XSD.STRING)){ + if (lit.getDatatype() == null || lit.getDatatype().equals(XSD.STRING)) { st.changeObject("shortened", "en"); - } + } } + //remove statements like <x a owl:Class> + if(st.getPredicate().equals(RDF.type)){ + if(object.equals(RDFS.Class.asNode()) || object.equals(OWL.Class.asNode()) || object.equals(RDFS.Literal.asNode())){ + statementsToRemove.add(st); + } + } } - fullFragment.remove(statementsToRemove); - return fullFragment; + model.remove(statementsToRemove); } /** @@ -414,7 +444,7 @@ private Model getFragment(Individual ind, KnowledgeBase kb){ logger.debug("Loading fragment for " + ind.getName()); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(kb.getEndpoint(), kb.getCache()); - Model cbd = cbdGen.getConciseBoundedDescription(ind.getName(), 2); + Model cbd = cbdGen.getConciseBoundedDescription(ind.getName(), fragmentDepth); logger.debug("Got " + cbd.size() + " triples."); return cbd; } Modified: trunk/scripts/src/test/java/org/dllearner/junit/OntologyMatchingTest.java =================================================================== --- trunk/scripts/src/test/java/org/dllearner/junit/OntologyMatchingTest.java 2013-02-25 12:24:29 UTC (rev 3905) +++ trunk/scripts/src/test/java/org/dllearner/junit/OntologyMatchingTest.java 2013-02-27 13:48:57 UTC (rev 3906) @@ -33,6 +33,8 @@ private KnowledgeBase worldFactBook; private KnowledgeBase openCyc; private KnowledgeBase linkedGeoData; + + private final int fragmentDepth = 3; @Before public void setUp() throws Exception { @@ -112,6 +114,7 @@ @Test public void testSingleClassLinkedGeoDataToDBpedia() { OntologyMatching matcher = new OntologyMatching(linkedGeoData, dbpedia); + matcher.setFragmentDepth(fragmentDepth); NamedClass nc = new NamedClass("http://linkedgeodata.org/ontology/Aerodrome"); List<? extends EvaluatedDescription> mapping = matcher.computeMapping(nc, linkedGeoData, dbpedia); Map<Description, List<? extends EvaluatedDescription>> alignment = new HashMap<Description, List<? extends EvaluatedDescription>>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-03-04 10:49:01
|
Revision: 3909 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3909&view=rev Author: lorenz_b Date: 2013-03-04 10:48:54 +0000 (Mon, 04 Mar 2013) Log Message: ----------- Updated SOLR lib. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java trunk/pom.xml Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-03-02 09:41:31 UTC (rev 3908) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-03-04 10:48:54 UTC (rev 3909) @@ -1,6 +1,5 @@ package org.dllearner.common.index; -import java.net.MalformedURLException; import java.util.ArrayList; import java.util.List; @@ -8,7 +7,7 @@ import org.apache.solr.client.solrj.SolrQuery.ORDER; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.impl.BinaryRequestWriter; -import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; +import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; @@ -16,7 +15,7 @@ public class SOLRIndex implements Index{ -private CommonsHttpSolrServer server; +private HttpSolrServer server; private static final int DEFAULT_LIMIT = 10; private static final int DEFAULT_OFFSET = 0; @@ -29,12 +28,8 @@ private boolean restrictiveSearch = true; public SOLRIndex(String solrServerURL){ - try { - server = new CommonsHttpSolrServer(solrServerURL); - server.setRequestWriter(new BinaryRequestWriter()); - } catch (MalformedURLException e) { - e.printStackTrace(); - } + server = new HttpSolrServer(solrServerURL); + server.setRequestWriter(new BinaryRequestWriter()); } public void setSearchFields(String primarySearchField, String secondarySearchField){ Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-03-02 09:41:31 UTC (rev 3908) +++ trunk/pom.xml 2013-03-04 10:48:54 UTC (rev 3909) @@ -20,6 +20,7 @@ <slf4j.version>1.6.4</slf4j.version> <log4j.version>1.2.16</log4j.version> + <solr.version>4.1.0</solr.version> </properties> <modules> @@ -164,7 +165,7 @@ <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> - <version>3.5.0</version> + <version>${solr.version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2013-03-19 13:41:06
|
Revision: 3913 http://sourceforge.net/p/dl-learner/code/3913 Author: lorenz_b Date: 2013-03-19 13:40:46 +0000 (Tue, 19 Mar 2013) Log Message: ----------- Changed SPARQL kb constructors. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/pom.xml trunk/scripts/pom.xml Modified: trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/components-core/src/main/java/org/dllearner/kb/LocalModelBasedSparqlEndpointKS.java 2013-03-19 13:40:46 UTC (rev 3913) @@ -37,6 +37,10 @@ this.model = model; } + public LocalModelBasedSparqlEndpointKS(Model model) { + this.model = ModelFactory.createOntologyModel(enableReasoning ? OntModelSpec.OWL_MEM : OntModelSpec.OWL_MEM_RDFS_INF, model); + } + @Override public void init() throws ComponentInitException { Model baseModel = ModelFactory.createDefaultModel(); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2013-03-19 13:40:46 UTC (rev 3913) @@ -439,7 +439,7 @@ @Override public Set<NamedClass> getTypes(Individual individual) { Set<NamedClass> types = new HashSet<NamedClass>(); - String query = String.format("SELECT ?class WHERE {<%s> a ?class.}", individual.getName()); + String query = String.format("SELECT DISTINCT ?class WHERE {<%s> a ?class.}", individual.getName()); ResultSet rs = executeSelectQuery(query); QuerySolution qs; while(rs.hasNext()){ @@ -448,6 +448,18 @@ } return types; } + + public Set<NamedClass> getTypes() { + Set<NamedClass> types = new HashSet<NamedClass>(); + String query = String.format("SELECT ?class WHERE {[] a ?class.}"); + ResultSet rs = executeSelectQuery(query); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + types.add(new NamedClass(qs.getResource("class").getURI())); + } + return types; + } @Override public boolean hasType(Description description, Individual individual) { Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/HierarchicalIndex.java 2013-03-19 13:40:46 UTC (rev 3913) @@ -15,6 +15,14 @@ this.primaryIndex = primaryIndex; this.secondaryIndex = secondaryIndex; } + + public Index getPrimaryIndex() { + return primaryIndex; + } + + public Index getSecondaryIndex() { + return secondaryIndex; + } @Override public List<String> getResources(String queryString) { Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2013-03-19 13:40:46 UTC (rev 3913) @@ -115,6 +115,7 @@ SolrQuery query = new SolrQuery(solrString); query.setRows(limit); query.setStart(offset); + query.addField("uri"); if(sortField != null){ query.addSortField(sortField, ORDER.desc); } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2013-03-19 13:40:46 UTC (rev 3913) @@ -25,6 +25,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -32,7 +33,9 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; +import java.net.Authenticator; import java.net.MalformedURLException; +import java.net.PasswordAuthentication; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; @@ -41,19 +44,21 @@ import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; -import java.util.TreeSet; import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; +import joptsimple.OptionSpec; import org.aksw.commons.jena_owlapi.Conversion; import org.apache.log4j.ConsoleAppender; @@ -61,8 +66,6 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat; -import org.dllearner.algorithms.DisjointClassesLearner; -import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.AsymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; @@ -91,9 +94,9 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.OntologyFormat; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.config.ConfigOption; @@ -105,11 +108,13 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubClassAxiom; +import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.kb.sparql.SparqlQuery; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.Heuristics.HeuristicType; @@ -118,14 +123,10 @@ import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.Helper; import org.dllearner.utilities.PrefixCCMap; -import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; -import org.dllearner.utilities.owl.DLLearnerAxiomConvertVisitor; import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; -import org.dllearner.utilities.owl.OWLAPIConverter; -import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.io.SystemOutDocumentTarget; @@ -144,10 +145,18 @@ import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; +import com.clarkparsia.owlapiv3.XSD; +import com.google.common.collect.Sets; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; +import com.hp.hpl.jena.vocabulary.OWL; +import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; /** * Command Line Interface for Enrichment. @@ -210,6 +219,7 @@ private double threshold = 0.7; private int chunksize = 1000; private boolean omitExistingAxioms; + private List<String> allowedNamespaces = new ArrayList<String>(); private boolean useInference; private SPARQLReasoner reasoner; @@ -227,13 +237,15 @@ // private CommonPrefixMap prefixes = new CommonPrefixMap(); // cache for SparqKnowledgeSource - SparqlKnowledgeSource ksCached; + KnowledgeSource ksCached; AbstractReasonerComponent rcCached; private Set<OWLAxiom> learnedOWLAxioms; private Set<EvaluatedAxiom> learnedEvaluatedAxioms; - public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose, int chunksize, int maxExecutionTimeInSeconds, boolean omitExistingAxioms) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, + boolean useInference, boolean verbose, int chunksize, + int maxExecutionTimeInSeconds, boolean omitExistingAxioms) { this.se = se; this.resource = resource; this.verbose = verbose; @@ -276,8 +288,8 @@ dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); - classAlgorithms.add(DisjointClassesLearner.class); - classAlgorithms.add(SimpleSubclassLearner.class); +// classAlgorithms.add(DisjointClassesLearner.class); +// classAlgorithms.add(SimpleSubclassLearner.class); classAlgorithms.add(CELOE.class); algorithmRuns = new LinkedList<AlgorithmRun>(); @@ -286,6 +298,10 @@ learnedEvaluatedAxioms = new HashSet<EvaluatedAxiom>(); } + public void setAllowedNamespaces(List<String> allowedNamespaces) { + this.allowedNamespaces = allowedNamespaces; + } + public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { // instantiate SPARQL endpoint wrapper component @@ -310,7 +326,9 @@ if(resource == null) { // loop over all entities and call appropriate algorithms - Set<NamedClass> classes = st.getAllClasses(); + + Set<NamedClass> classes = reasoner.getTypes();//st.getAllClasses(); + filterByNamespaces(classes); int entities = 0; for(NamedClass nc : classes) { try { @@ -323,24 +341,26 @@ break; } } - entities = 0; - Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); - for(ObjectProperty property : objectProperties) { - runObjectPropertyAlgorithms(ks, property); - entities++; - if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { - break; - } - } - entities = 0; - Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); - for(DatatypeProperty property : dataProperties) { - runDataPropertyAlgorithms(ks, property); - entities++; - if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { - break; - } - } +// entities = 0; +// Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); +// filterByNamespaces(objectProperties); +// for(ObjectProperty property : objectProperties) { +// runObjectPropertyAlgorithms(ks, property); +// entities++; +// if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { +// break; +// } +// } +// entities = 0; +// Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); +// filterByNamespaces(dataProperties); +// for(DatatypeProperty property : dataProperties) { +// runDataPropertyAlgorithms(ks, property); +// entities++; +// if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { +// break; +// } +// } } else { if(resource instanceof ObjectProperty) { System.out.println(resource + " appears to be an object property. Running appropriate algorithms.\n"); @@ -363,13 +383,32 @@ } } + private <T extends Entity> void filterByNamespaces(Collection<T> entities){ + if(allowedNamespaces != null && !allowedNamespaces.isEmpty()){ + for (Iterator<T> iterator = entities.iterator(); iterator.hasNext();) { + T entity = iterator.next();System.out.println(entity.getName()); + boolean startsWithAllowedNamespace = false; + for (String ns : allowedNamespaces) { + if(entity.getName().startsWith(ns)){ + startsWithAllowedNamespace = true; + break; + } + } + if(!startsWithAllowedNamespace){ + iterator.remove(); + } + } + } + } + @SuppressWarnings("unchecked") private void runClassLearningAlgorithms(SparqlEndpointKS ks, NamedClass nc) throws ComponentInitException { -// System.out.println("Running algorithms for class " + nc); + System.out.println("Running algorithms for class " + nc); for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { if(algorithmClass == CELOE.class) { - applyCELOE(ks, nc, false, false); - applyCELOE(ks, nc, true, true); +// applyCELOE(ks, nc, false, false); +// applyCELOE(ks, nc, true, true); + applyCELOE(ks, nc, true, false); } else { applyLearningAlgorithm((Class<AxiomLearningAlgorithm>)algorithmClass, ks, nc); } @@ -377,14 +416,14 @@ } private void runObjectPropertyAlgorithms(SparqlEndpointKS ks, ObjectProperty property) throws ComponentInitException { -// System.out.println("Running algorithms for object property " + property); + System.out.println("Running algorithms for object property " + property); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks, property); } } private void runDataPropertyAlgorithms(SparqlEndpointKS ks, DatatypeProperty property) throws ComponentInitException { -// System.out.println("Running algorithms for data property " + property); + System.out.println("Running algorithms for data property " + property); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks, property); } @@ -394,24 +433,55 @@ // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); + System.out.print("finding positives ... "); + long startTime = System.currentTimeMillis(); SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + long runTime = System.currentTimeMillis() - startTime; if(posExamples.isEmpty()){ System.out.println("Skipping CELOE because class " + nc.toString() + " is empty."); return Collections.emptyList(); } SortedSet<String> posExStr = Helper.getStringSet(posExamples); + System.out.println("done (" + posExStr.size()+ " examples found in " + runTime + " ms)"); // use own implementation of negative example finder - long startTime = System.currentTimeMillis(); System.out.print("finding negatives ... "); + startTime = System.currentTimeMillis(); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); - negExStr = SetManipulation.fuzzyShrink(negExStr, 20); + negExStr = SetManipulation.stableShrink(negExStr, 20); SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); - long runTime = System.currentTimeMillis() - startTime; - System.out.println("done (" + negExStr.size()+ " examples fround in " + runTime + " ms)"); + runTime = System.currentTimeMillis() - startTime; + System.out.println("done (" + negExStr.size()+ " examples found in " + runTime + " ms)"); + AbstractReasonerComponent rc; + KnowledgeSource ksFragment; + if(reuseKnowledgeSource){ + ksFragment = ksCached; + rc = rcCached; + } else { + System.out.print("extracting fragment ... "); + startTime = System.currentTimeMillis(); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getEndpoint(), cache, 2); + Model model = ModelFactory.createDefaultModel(); + for(Individual example : Sets.union(posExamples, negExamples)){ + Model cbd = cbdGen.getConciseBoundedDescription(example.getName()); + model.add(cbd); + } + filter(model); + runTime = System.currentTimeMillis() - startTime; + System.out.println("done (" + model.size()+ " triples found in " + runTime + " ms)"); + OWLOntology ontology = asOWLOntology(model); + ksFragment = new OWLAPIOntology(ontology); +// ksFragment.init(); + rc = new FastInstanceChecker(ksFragment); + rc.init(); + ksCached = ksFragment; + rcCached = rc; + } + + /*//old way to get SPARQL fragment SparqlKnowledgeSource ks2; AbstractReasonerComponent rc; if(reuseKnowledgeSource) { @@ -439,7 +509,7 @@ rc.init(); ksCached = ks2; rcCached = rc; - } + }*/ ClassLearningProblem lp = new ClassLearningProblem(rc); lp.setClassToDescribe(nc); @@ -684,6 +754,50 @@ // return model; // } + private OWLOntology asOWLOntology(Model model) { + try { + FileOutputStream fos = null; + try { + fos = new FileOutputStream("bug.ttl"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + model.write(baos, "TURTLE", null); + model.write(fos, "TURTLE", null); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = man.loadOntologyFromOntologyDocument(new ByteArrayInputStream(baos.toByteArray())); + return ontology; + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + return null; + } + + private void filter(Model model) { + // filter out triples with String literals, as there often occur are + // some syntax errors and they are not relevant for learning + List<Statement> statementsToRemove = new ArrayList<Statement>(); + for (Iterator<Statement> iter = model.listStatements().toList().iterator(); iter.hasNext();) { + Statement st = iter.next(); + RDFNode object = st.getObject(); + if (object.isLiteral()) { + // statementsToRemove.add(st); + Literal lit = object.asLiteral(); + if (lit.getDatatype() == null || lit.getDatatype().equals(XSD.STRING)) { + st.changeObject("shortened", "en"); + } + } + //remove statements like <x a owl:Class> + if(st.getPredicate().equals(RDF.type)){ + if(object.equals(RDFS.Class.asNode()) || object.equals(OWL.Class.asNode()) || object.equals(RDFS.Literal.asNode())){ + statementsToRemove.add(st); + } + } + } + model.remove(statementsToRemove); + } + Model getModel(List<OWLAxiom> axioms) { Model model = ModelFactory.createDefaultModel(); try { @@ -793,7 +907,7 @@ "The resource for which enrichment axioms should be suggested.").withOptionalArg().ofType(URI.class); parser.acceptsAll(asList("o", "output"), "Specify a file where the output can be written.") .withOptionalArg().ofType(File.class); - // TODO: other interestig formats: html, manchester, sparul + // TODO: other interesting formats: html, manchester, sparul parser.acceptsAll(asList("f", "format"), "Format of the generated output (plain, rdf/xml, turtle, n-triples).").withOptionalArg() .ofType(String.class).defaultsTo("plain"); @@ -815,7 +929,16 @@ "Specifies the max execution time for each algorithm run and each entity.").withRequiredArg().ofType(Integer.class).defaultsTo(10); parser.acceptsAll(asList("omitExistingAxioms"), "Specifies whether return only axioms which not already exist in the knowlegde base.").withOptionalArg().ofType(Boolean.class).defaultsTo(false); + OptionSpec<String> allowedNamespacesOption = parser.accepts( "ns" ).withRequiredArg().ofType( String.class ) + .withValuesSeparatedBy( ',' ); + + //username and password if endpoint is protected + parser.acceptsAll(asList("u", "username"), "Specify the username.") + .withOptionalArg().ofType(String.class); + parser.acceptsAll(asList("pw", "password"), "Specify the password.") + .withOptionalArg().ofType(String.class); + // parse options and display a message for the user in case of problems OptionSet options = null; try { @@ -865,6 +988,19 @@ System.out.println("The specified resource appears not be a proper URI."); System.exit(0); } + //set credentials if needed + if(options.has("username") && options.has("password")){ + final String username = (String) options.valueOf("username"); + final String password = (String) options.valueOf("password"); + Authenticator.setDefault (new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password.toCharArray()); + } + }); + } + + LinkedList<String> defaultGraphURIs = new LinkedList<String>(); if(graph != null) { defaultGraphURIs.add(graph.toString()); @@ -912,9 +1048,13 @@ if(options.has("o") && (!options.has("f") || options.valueOf("f").equals("plain"))) { PrintStream printStream = new PrintStream(new FileOutputStream(f)); System.setOut(printStream); - } + } + //extract namespaces to which the analyzed entities will be restricted + List<String> allowedNamespaces = options.valuesOf(allowedNamespacesOption); + Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false, chunksize, maxExecutionTimeInSeconds, omitExistingAxioms); + e.setAllowedNamespaces(allowedNamespaces); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); @@ -927,6 +1067,8 @@ axioms.addAll(e.toRDF(run.getAxioms(), run.getAlgorithm(), run.getParameters(), ks)); } Model model = e.getModel(axioms); + OutputStream os = options.has("o") ? new FileOutputStream((File)options.valueOf("o")) : System.out; + if(options.valueOf("f").equals("turtle")) { if(options.has("o")) { model.write(new FileOutputStream(f), "TURTLE"); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/pom.xml 2013-03-19 13:40:46 UTC (rev 3913) @@ -123,7 +123,7 @@ <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> - <version>3.4</version> + <version>3.4.4</version> </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2013-03-18 12:24:44 UTC (rev 3912) +++ trunk/scripts/pom.xml 2013-03-19 13:40:46 UTC (rev 3913) @@ -116,7 +116,6 @@ <dependency> <groupId>net.sourceforge.owlapi</groupId> <artifactId>owlapi-distribution</artifactId> -<!-- <version>3.4.4-SNAPSHOT</version> --> </dependency> <dependency> <groupId>net.sourceforge.owlapi</groupId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |