You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <ku...@us...> - 2008-08-14 17:33:29
|
Revision: 1075 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1075&view=rev Author: kurzum Date: 2008-08-14 17:33:24 +0000 (Thu, 14 Aug 2008) Log Message: ----------- intermediate commit Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java trunk/src/dl-learner/org/dllearner/kb/old/ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java trunk/src/dl-learner/org/dllearner/kb/old/Scrap.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/old/TypedSparqlQueryInterface.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java Deleted: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,124 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.aquisitors; - -import java.net.URI; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.kb.extraction.Configuration; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.kb.sparql.SparqlQueryMaker; -import org.dllearner.utilities.datastructures.StringTuple; - -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class TypedSparqlQuery implements TypedSparqlQueryInterface { - - private static Logger logger = Logger.getLogger(KnowledgeSource.class); - - - boolean print_flag = false; - protected Configuration configuration; - private SparqlQueryMaker sparqlQueryMaker; - Cache cache; - - // boolean debug_no_cache = false;// true means no cache is used - // private SparqlHTTPRequest SparqlHTTPRequest; - // private SparqlQuery sparqlQuery; - // private CachedSparqlQuery cachedSparqlQuery; - - public TypedSparqlQuery(Configuration Configuration) { - this.configuration = Configuration; - this.sparqlQueryMaker =Configuration.getSparqlQueryMaker(); - - this.cache = new Cache(configuration.cacheDir); - // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); - // this.cachedSparqlQuery=new - // CachedSparqlQuery(this.sparqlQuery,this.cache); - } - - // standard query get a tupels (p,o) for subject s - /** - * uses a cache and gets the result tuples for a resource u - * - * @param uri - * the resource - * @param sparqlQueryString - * @param a - * the name of the first bound variable for xml parsing, normally - * predicate - * @param b - * the name of the second bound variable for xml parsing, - * normally object - * @return - */ - @SuppressWarnings({"unchecked"}) - public Set<StringTuple> getTupelForResource(URI uri) { - Set<StringTuple> s = new HashSet<StringTuple>(); - - String a = "predicate"; - String b = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); - -// CachedSparqlQuery csq = new CachedSparqlQuery(configuration -// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); - - SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); -// query.extraDebugInfo=uri.toString(); - String JSON = cache.executeSparqlQuery(query); - - ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON); - - List<ResultBinding> l = ResultSetFormatter.toList(rs); - - logger.trace(l.toString()); - for (ResultBinding resultBinding : l) { - - s.add(new StringTuple(resultBinding.get(a).toString(), - resultBinding.get(b).toString())); - } - return s; - } - - - - - - - - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,80 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.aquisitors; - -import java.net.URI; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.dllearner.kb.extraction.Configuration; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.utilities.datastructures.StringTuple; - -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class TypedSparqlQueryClasses extends TypedSparqlQuery implements - TypedSparqlQueryInterface { - - public TypedSparqlQueryClasses(Configuration configuration) { - super(configuration); - } - - /* - * Special TypedSparqlQuery which returns superclasses of classes - * (non-Javadoc) - * - * @see org.dllearner.kb.sparql.TypedSparqlQuery#getTupelForResource(java.net.URI) - */ - @Override - @SuppressWarnings({"unchecked"}) - public Set<StringTuple> getTupelForResource(URI uri) { - Set<StringTuple> s = new HashSet<StringTuple>(); - String a = "predicate"; - String b = "object"; - // getQuery for all super classes of classes only - String sparqlQueryString = "SELECT ?predicate ?object " + "WHERE {" - + "<" + uri.toString() + "> ?predicate ?object;" - + "a ?object . " - + " FILTER (!regex(str(?object),'http://xmlns.com/foaf/0.1/'))" - + "}"; - - SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); -// query.extraDebugInfo=uri.toString(); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(query)); - - List<ResultBinding> l = ResultSetFormatter.toList(rs); - for (ResultBinding resultBinding : l) { - - s.add(new StringTuple(resultBinding.get(a).toString(), - resultBinding.get(b).toString())); - } - return s; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.aquisitors; - -import java.net.URI; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * - * Typed SPARQL query interface. The typing means that they all have the same - * input and the same output: They are fn: resource -> ( a | b ) where a - * normally is a predicate and b an object - * - * @author Sebastian Hellmann - * - */ -public interface TypedSparqlQueryInterface { - - public Set<StringTuple> getTupelForResource(URI u); -} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -27,8 +27,8 @@ import java.util.TreeSet; import java.util.Vector; -import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -19,7 +19,7 @@ */ package org.dllearner.kb.extraction; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -24,9 +24,9 @@ import java.util.Vector; import org.apache.log4j.Logger; -import org.dllearner.kb.aquisitors.TypedSparqlQuery; -import org.dllearner.kb.aquisitors.TypedSparqlQueryClasses; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQuery; +import org.dllearner.kb.old.TypedSparqlQueryClasses; /** * This class is used to extract the information . Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -27,8 +27,8 @@ import java.util.TreeSet; import java.util.Vector; -import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -25,8 +25,8 @@ import java.util.TreeSet; import org.apache.log4j.Logger; -import org.dllearner.kb.aquisitors.TypedSparqlQuery; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQuery; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.statistics.Statistics; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,101 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.SortedSet; -import java.util.Vector; - -import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; -import org.dllearner.kb.manipulator.Manipulators; - - -/** - * Abstract class. defines functions to expand the nodes - * - * @author Sebastian Hellmann - * - */ -public abstract class Node implements Comparable<Node> { - - final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - final String rdftype = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - final String classns = "http://www.w3.org/2002/07/owl#Class"; - final String thing = "http://www.w3.org/2002/07/owl#Thing"; - - URI uri; - // protected String type; - protected boolean expanded = false; - - public Node(URI u) { - this.uri = u; - } - - /** - * Nodes are expanded with a certain context, given by the typedSparqlQuery - * and the manipulator - * - * @param typedSparqlQuery - * @param manipulator - * @return Vector<Node> all Nodes that are new because of expansion - */ - public abstract Vector<Node> expand( - TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); - - /** - * gets type defs for properties like rdf:type SymmetricProperties - * - * @param typedSparqlQuery - * @param manipulator - * @return Vector<Node> - */ - public abstract void expandProperties( - TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); - - /** - * output - * - * @return a set of n-triple - */ - public abstract SortedSet<String> toNTriple(); - - @Override - public String toString() { - return "Node: " + uri + ":" + this.getClass().getSimpleName(); - - } - - public URI getURI() { - return uri; - } - - public boolean equals(Node n) { - if (this.uri.equals(n.uri)) - return true; - else - return false; - } - - public int compareTo(Node n) { - return this.uri.toString().compareTo(n.uri.toString()); - } - -} Copied: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,101 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.extraction; + +import java.net.URI; +import java.util.SortedSet; +import java.util.Vector; + +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQueryInterface; + + +/** + * Abstract class. defines functions to expand the nodes + * + * @author Sebastian Hellmann + * + */ +public abstract class Node implements Comparable<Node> { + + final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + final String rdftype = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + URI uri; + // protected String type; + protected boolean expanded = false; + + public Node(URI u) { + this.uri = u; + } + + /** + * Nodes are expanded with a certain context, given by the typedSparqlQuery + * and the manipulator + * + * @param typedSparqlQuery + * @param manipulator + * @return Vector<Node> all Nodes that are new because of expansion + */ + public abstract Vector<Node> expand( + TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); + + /** + * gets type defs for properties like rdf:type SymmetricProperties + * + * @param typedSparqlQuery + * @param manipulator + * @return Vector<Node> + */ + public abstract void expandProperties( + TypedSparqlQueryInterface typedSparqlQuery, Manipulators manipulator); + + /** + * output + * + * @return a set of n-triple + */ + public abstract SortedSet<String> toNTriple(); + + @Override + public String toString() { + return "Node: " + uri + ":" + this.getClass().getSimpleName(); + + } + + public URI getURI() { + return uri; + } + + public boolean equals(Node n) { + if (this.uri.equals(n.uri)) + return true; + else + return false; + } + + public int compareTo(Node n) { + return this.uri.toString().compareTo(n.uri.toString()); + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -27,8 +27,8 @@ import java.util.TreeSet; import java.util.Vector; -import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; -import org.dllearner.kb.manipulator.Manipulators; +import org.dllearner.kb.old.Manipulators; +import org.dllearner.kb.old.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,112 +0,0 @@ -package org.dllearner.kb.extraction; - -/** - * this class collects old source code and will be removed after refactoring - * @author Sebastian Hellmann - * - */ -public class Scrap { - - /* - public String makeRoleQueryUsingFilters(String role) { - - String Filter = internalFilterAssemblyRole(); - String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role - + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter - + ").}"; - // System.out.println(ret); - - return ret; - } - */ - - /* - public String makeRoleQueryUsingFilters(String role, boolean domain) { - - String Filter = internalFilterAssemblyRole(); - String ret = ""; - if (domain) { - ret = "SELECT * WHERE { " + lineend + "?subject <" + role - + "> ?object; a []. " + lineend + "FILTER( " + lineend - + "(" + Filter + ").}"; - // "ORDER BY ?subject"; - // System.out.println(ret); - } else { - ret = "SELECT * WHERE { " + lineend + "?object a [] . " - + "?subject <" + role + "> ?object . " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; - // "ORDER BY ?object"; - - } - // System.out.println(ret); - - return ret; - }*/ - - - /* - * - private String internalFilterAssemblyRole() { - - String Filter = ""; - if (!this.sparqlQueryType.isLiterals()) - Filter += "!isLiteral(?object))"; - for (String s : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterSubject(s); - } - for (String o : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterObject(o); - } - return Filter; - }*/ - - - /* - * creates a query with the specified filters for all triples with subject - * - * @param subject - * the searched subject - * @param sf - * special object encapsulating all options - * @return sparql query - - /* - * public static String makeQueryFilter(String subject, oldSparqlFilter sf) { - * - * String Filter = ""; if (!sf.useLiterals) Filter += "!isLiteral(?object)"; - * for (String p : sf.getPredFilter()) { Filter += "\n" + - * filterPredicate(p); } for (String o : sf.getObjFilter()) { Filter += "\n" + - * filterObject(o); } - * - * String ret = "SELECT * WHERE { \n" + "<" + subject + "> ?predicate - * ?object.\n"; if (!(Filter.length() == 0)) ret += "FILTER( \n" + "(" + - * Filter + "))."; ret += "}"; // System.out.println(ret); return ret; } - */ - - /* - * moved to SparqlQuery remove here creates a query for subjects with - * the specified label @param label a phrase that is part of the label of a - * subject @param limit this limits the amount of results @return - * - * @Deprecated public static String makeLabelQuery(String label,int limit){ - * // maybe use http://xmlns:com/foaf/0.1/page return - * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject - * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object - * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; } - * - * - * creates a query for all subjects that are of the type concept @param - * concept the type that subjects are searched for @return - * - * - * moved to SparqlQuery remove here - * @Deprecated public static String makeConceptQuery(String concept){ return - * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a - * <"+concept+">}\n"; } moved to SparqlQuery remove here - * @Deprecated public static String makeArticleQuery(String subject){ return - * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+"> - * ?predicate ?object}\n"; } - */ - - -} Added: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBPediaNavigatorCityLocatorRule.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,51 @@ +package org.dllearner.kb.manipulator; + +import java.util.HashMap; +import java.util.Map; +import java.util.SortedSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +import com.hp.hpl.jena.rdf.model.impl.ResourceImpl; + +public class DBPediaNavigatorCityLocatorRule extends Rule{ + + Map<String,String> map=new HashMap<String,String>(); + + + public DBPediaNavigatorCityLocatorRule(Months month){ + super(month); + map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); + map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); + map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); + } + + + + @Override + public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ + + String uri; + if(( uri = map.get(subject.getURI().toString()) ) == null) { + return tuples; + }else { + tuples.add(new RDFNodeTuple(new ResourceImpl(OWLVocabulary.RDFS_SUBCLASS_OF), new ResourceImpl(uri))); + return tuples; + } + + + } + + + + + +} Deleted: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,58 +0,0 @@ -package org.dllearner.kb.manipulator; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -public class DBpediaNavigatorCityLocator { - - public static String getTypeToCoordinates(float lat, float lng){ - if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ - if (lat>50&&lat<52&&lng>12&&lng<13){ - return "http://dbpedia.org/class/custom/City_in_Saxony"; - } - else return "http://dbpedia.org/class/custom/City_in_Europe"; - } - else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ - if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ - return "http://dbpedia.org/class/custom/City_in_Egypt"; - } - else return "http://dbpedia.org/class/custom/City_in_Africa"; - } - else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ - return "http://dbpedia.org/class/custom/City_in_Asia"; - } - else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ - return "http://dbpedia.org/class/custom/City_in_Australia"; - } - else if (lng>-168.4&&lng<-19.7&&lat>6.6){ - return "http://dbpedia.org/class/custom/City_in_North_America"; - } - else if (lng>-81.56&&lng<-34.1&&lat<6.6){ - return "http://dbpedia.org/class/custom/City_in_South_America"; - } - else return "http://dbpedia.org/class/custom/City_in_World"; - } - - public static Set<StringTuple> getTuplesToAdd(String uri){ - String subClass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - - HashMap<String,String> map=new HashMap<String,String>(); - map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); - map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); - map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); - Set<StringTuple> toAdd = new HashSet<StringTuple>(); - if (map.containsKey(uri)){ - toAdd.add(new StringTuple(subClass,map.get(uri))); - } - return toAdd; - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,140 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.manipulator; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.kb.extraction.Node; -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Used to manipulate retrieved tupels, identify blanknodes, etc. - * - * @author Sebastian Hellmann - * - */ -public class DBpediaNavigatorManipulator implements Manipulators{ - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - final String classns = "http://www.w3.org/2002/07/owl#Class"; - final String thing = "http://www.w3.org/2002/07/owl#Thing"; - - public String blankNodeIdentifier = "bnode"; - public int breakSuperClassRetrievalAfter = 200; - public LinkedList<StringTuple> replacePredicate; - public LinkedList<StringTuple> replaceObject; - - // Set<String> classproperties; - - public DBpediaNavigatorManipulator(String blankNodeIdentifier, - int breakSuperClassRetrievalAfter, - LinkedList<StringTuple> replacePredicate, - LinkedList<StringTuple> replaceObject) { - this.blankNodeIdentifier = blankNodeIdentifier; - this.replaceObject = replaceObject; - this.replacePredicate = replacePredicate; - this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; - // Set<String> classproperties = new HashSet<String>(); - // classproperties.add(subclass); - - } - - /** - * this checks for consistency and manipulates the tuples, before they get - * triple - * - * @param tuples - * tuples for the node - * @param node - * @return - */ - public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { - //Set<StringTuple> toRemove = new HashSet<StringTuple>(); - Iterator<StringTuple> it = tuples.iterator(); - float lat=0; - float lng=0; - String clas=""; - StringTuple typeTupel=null; - tuples.addAll(DBpediaNavigatorCityLocator.getTuplesToAdd(node.getURI().toString())); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - - if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ - clas=t.b; - typeTupel=t; - } - - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) - lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) - lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - - /*replacePredicate(t); - replaceObject(t); - - - // remove <rdf:type, owl:class> - // this is done to avoid transformation to owl:subclassof - if (t.a.equals(type) && t.b.equals(classns) - && node instanceof ClassNode) { - toRemove.add(t); - } - - // all with type class - if (t.b.equals(classns) && node instanceof ClassNode) { - toRemove.add(t); - } - - // remove all instances with owl:type thing - if (t.a.equals(type) && t.b.equals(thing) - && node instanceof InstanceNode) { - toRemove.add(t); - }*/ - - } - if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ - String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); - tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); - tuples.remove(typeTupel); - } - //tuples.removeAll(toRemove); - - return tuples; - } - - /*private void replacePredicate(StringTuple t) { - for (StringTuple rep : replacePredicate) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - private void replaceObject(StringTuple t) { - for (StringTuple rep : replaceObject) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - }*/ -} Added: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorOtherRule.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,102 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.manipulator; + +import java.util.SortedSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.old.DBpediaNavigatorCityLocator; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.impl.ResourceImpl; + + +public class DBpediaNavigatorOtherRule extends Rule{ + + + public DBpediaNavigatorOtherRule(Months month){ + super(month); + } + // Set<String> classproperties; + + @Override + public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ + float lat=0; + float lng=0; + RDFNode clazz = null; + RDFNodeTuple typeTuple = null; + for (RDFNodeTuple tuple : tuples) { + + if (tuple.a.toString().equals(OWLVocabulary.RDF_TYPE)){ + clazz = tuple.b; + typeTuple = tuple; + } + + //TODO this doesn't work, because it is unclear what toString() method returns + + if (tuple.a.toString().equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")){ + lat=Float.parseFloat(tuple.b.toString().substring(0,tuple.b.toString().indexOf("^^"))); + } + if (tuple.a.toString().equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) { + lng=Float.parseFloat(tuple.b.toString().substring(0,tuple.b.toString().indexOf("^^"))); + } + + } + if (clazz.toString().equals("http://dbpedia.org/class/yago/City108524735")){ + String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); + tuples.add(new RDFNodeTuple(new ResourceImpl(OWLVocabulary.RDF_TYPE),new ResourceImpl(newType))); + //tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); + tuples.remove(typeTuple); + } + + return tuples; + } + + public static String getTypeToCoordinates(float lat, float lng){ + if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ + if (lat>50&&lat<52&&lng>12&&lng<13){ + return "http://dbpedia.org/class/custom/City_in_Saxony"; + } + else return "http://dbpedia.org/class/custom/City_in_Europe"; + } + else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ + if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ + return "http://dbpedia.org/class/custom/City_in_Egypt"; + } + else return "http://dbpedia.org/class/custom/City_in_Africa"; + } + else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ + return "http://dbpedia.org/class/custom/City_in_Asia"; + } + else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ + return "http://dbpedia.org/class/custom/City_in_Australia"; + } + else if (lng>-168.4&&lng<-19.7&&lat>6.6){ + return "http://dbpedia.org/class/custom/City_in_North_America"; + } + else if (lng>-81.56&&lng<-34.1&&lat<6.6){ + return "http://dbpedia.org/class/custom/City_in_South_America"; + } + else return "http://dbpedia.org/class/custom/City_in_World"; + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -107,12 +107,14 @@ public static Manipulator getDBpediaNavigatorManipulator(){ Manipulator m = new Manipulator(); + m.rules.add(new DBPediaNavigatorCityLocatorRule(Months.JANUARY)); + m.rules.add(new DBpediaNavigatorOtherRule(Months.DECEMBER)); return m; } public static Manipulator getDefaultManipulator(){ Manipulator m = new Manipulator(); - m.addDefaultRules(); + m.addDefaultRules(Months.DECEMBER); return m; } @@ -133,11 +135,11 @@ // } - private void addDefaultRules(){ + private void addDefaultRules(Months month){ - rules.add(new TypeFilterRule(Months.DECEMBER, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_CLASS,ClassNode.class.getCanonicalName() )) ; - rules.add(new TypeFilterRule(Months.DECEMBER,OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_THING,InstanceNode.class.getCanonicalName() )) ; - rules.add(new TypeFilterRule(Months.DECEMBER,"", OWLVocabulary.OWL_CLASS, ClassNode.class.getCanonicalName()) ) ; + rules.add(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_CLASS,ClassNode.class.getCanonicalName() )) ; + rules.add(new TypeFilterRule(month, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_THING,InstanceNode.class.getCanonicalName() )) ; + rules.add(new TypeFilterRule(month, "", OWLVocabulary.OWL_CLASS, ClassNode.class.getCanonicalName()) ) ; } Deleted: trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,23 +0,0 @@ -package org.dllearner.kb.manipulator; - -import java.util.LinkedList; - -import org.dllearner.utilities.datastructures.StringTuple; - - -/** - * Used to get the right manipulator - * - * @author Sebastian Knappe - * - */ -public class ManipulatorType { - - public static Manipulators getManipulatorByName(String predefinedManipulator,String blankNodeIdentifier, int breakSuperClassRetrievalAfter, LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) - { - if (predefinedManipulator.equals("DBPEDIA-NAVIGATOR")) return new DBpediaNavigatorManipulator(blankNodeIdentifier, - breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - else return new OldManipulator(blankNodeIdentifier, - breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,16 +0,0 @@ -package org.dllearner.kb.manipulator; - -import java.util.Set; - -import org.dllearner.kb.extraction.Node; -import org.dllearner.utilities.datastructures.StringTuple; - -public interface Manipulators { - - public int breakSuperClassRetrievalAfter = 200; - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - public String blankNodeIdentifier = "bnode"; - - public Set<StringTuple> check(Set<StringTuple> tuples, Node node); -} Deleted: trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java 2008-08-14 16:43:42 UTC (rev 1074) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -1,160 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.manipulator; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.kb.extraction.ClassNode; -import org.dllearner.kb.extraction.InstanceNode; -import org.dllearner.kb.extraction.Node; -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Used to manipulate retrieved tupels, identify blanknodes, etc. - * - * @author Sebastian Hellmann - * - */ -public class OldManipulator implements Manipulators{ - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - final String classns = "http://www.w3.org/2002/07/owl#Class"; - final String thing = "http://www.w3.org/2002/07/owl#Thing"; - - public String blankNodeIdentifier = "bnode"; - public int breakSuperClassRetrievalAfter = 200; - public LinkedList<StringTuple> replacePredicate; - public LinkedList<StringTuple> replaceObject; - - // Set<String> classproperties; - - public OldManipulator(String blankNodeIdentifier, - int breakSuperClassRetrievalAfter, - LinkedList<StringTuple> replacePredicate, - LinkedList<StringTuple> replaceObject) { - this.blankNodeIdentifier = blankNodeIdentifier; - this.replaceObject = replaceObject; - this.replacePredicate = replacePredicate; - this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; - // Set<String> classproperties = new HashSet<String>(); - // classproperties.add(subclass); - - } - - /** - * this checks for consistency and manipulates the tuples, before they get - * triple - * - * @param tuples - * tuples for the node - * @param node - * @return - */ - public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { - Set<StringTuple> toRemove = new HashSet<StringTuple>(); - Iterator<StringTuple> it = tuples.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - - //HACK -// if(t.a.equals("http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag")) { -// //hackGetLabel(t.b); -// -// } - - // GovTrack hack - // => we convert a string literal to a URI - // => TODO: introduce an option for converting literals for certain - // properties into URIs -// String sp = "http://purl.org/dc/elements/1.1/subject"; -// if(t.a.equals(sp)) { -// System.out.println(t); -// System.exit(0); -// } - - replacePredicate(t); - replaceObject(t); - - - // remove <rdf:type, owl:class> - // this is done to avoid transformation to owl:subclassof - if (t.a.equals(type) && t.b.equals(classns) - && node instanceof ClassNode) { - toRemove.add(t); - } - - // all with type class - if (t.b.equals(classns) && node instanceof ClassNode) { - toRemove.add(t); - } - - // remove all instances with owl:type thing - if (t.a.equals(type) && t.b.equals(thing) - && node instanceof InstanceNode) { - toRemove.add(t); - } - - } - tuples.removeAll(toRemove); - - return tuples; - } - - private void replacePredicate(StringTuple t) { - for (StringTuple rep : replacePredicate) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - private void replaceObject(StringTuple t) { - for (StringTuple rep : replaceObject) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - - /*private String hackGetLabel(String resname){ - String query="" + - "SELECT ?o \n" + - "WHERE { \n" + - "<"+resname+"> "+ " <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o " + - "}"; - - System.out.println(query); - //http://dbtune.org/musicbrainz/sparql?query= - //SELECT ?o WHERE { <http://dbtune.org/musicbrainz/resource/tag/1391> <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o } - SparqlQuery s=new SparqlQuery(query,SparqlEndpoint.EndpointMusicbrainz()); - ResultSet rs=s.send(); - while (rs.hasNext()){ - rs.nextBinding(); - } - //System.out.println("AAA"+s.getAsXMLString(s.send()) ); - return ""; - }*/ - -} Copied: trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorCityLocator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,58 @@ +package org.dllearner.kb.old; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import org.dllearner.utilities.datastructures.StringTuple; + +public class DBpediaNavigatorCityLocator { + + public static String getTypeToCoordinates(float lat, float lng){ + if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ + if (lat>50&&lat<52&&lng>12&&lng<13){ + return "http://dbpedia.org/class/custom/City_in_Saxony"; + } + else return "http://dbpedia.org/class/custom/City_in_Europe"; + } + else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ + if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ + return "http://dbpedia.org/class/custom/City_in_Egypt"; + } + else return "http://dbpedia.org/class/custom/City_in_Africa"; + } + else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ + return "http://dbpedia.org/class/custom/City_in_Asia"; + } + else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ + return "http://dbpedia.org/class/custom/City_in_Australia"; + } + else if (lng>-168.4&&lng<-19.7&&lat>6.6){ + return "http://dbpedia.org/class/custom/City_in_North_America"; + } + else if (lng>-81.56&&lng<-34.1&&lat<6.6){ + return "http://dbpedia.org/class/custom/City_in_South_America"; + } + else return "http://dbpedia.org/class/custom/City_in_World"; + } + + public static Set<StringTuple> getTuplesToAdd(String uri){ + String subClass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; + + HashMap<String,String> map=new HashMap<String,String>(); + map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); + map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); + map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); + Set<StringTuple> toAdd = new HashSet<StringTuple>(); + if (map.containsKey(uri)){ + toAdd.add(new StringTuple(subClass,map.get(uri))); + } + return toAdd; + } +} Copied: trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/DBpediaNavigatorManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,140 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.old; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Used to manipulate retrieved tupels, identify blanknodes, etc. + * + * @author Sebastian Hellmann + * + */ +public class DBpediaNavigatorManipulator implements Manipulators{ + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + public String blankNodeIdentifier = "bnode"; + public int breakSuperClassRetrievalAfter = 200; + public LinkedList<StringTuple> replacePredicate; + public LinkedList<StringTuple> replaceObject; + + // Set<String> classproperties; + + public DBpediaNavigatorManipulator(String blankNodeIdentifier, + int breakSuperClassRetrievalAfter, + LinkedList<StringTuple> replacePredicate, + LinkedList<StringTuple> replaceObject) { + this.blankNodeIdentifier = blankNodeIdentifier; + this.replaceObject = replaceObject; + this.replacePredicate = replacePredicate; + this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; + // Set<String> classproperties = new HashSet<String>(); + // classproperties.add(subclass); + + } + + /** + * this checks for consistency and manipulates the tuples, before they get + * triple + * + * @param tuples + * tuples for the node + * @param node + * @return + */ + public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { + //Set<StringTuple> toRemove = new HashSet<StringTuple>(); + Iterator<StringTuple> it = tuples.iterator(); + float lat=0; + float lng=0; + String clas=""; + StringTuple typeTupel=null; + tuples.addAll(DBpediaNavigatorCityLocator.getTuplesToAdd(node.getURI().toString())); + while (it.hasNext()) { + StringTuple t = (StringTuple) it.next(); + + if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ + clas=t.b; + typeTupel=t; + } + + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) + lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) + lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + + /*replacePredicate(t); + replaceObject(t); + + + // remove <rdf:type, owl:class> + // this is done to avoid transformation to owl:subclassof + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + }*/ + + } + if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ + String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); + tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); + tuples.remove(typeTupel); + } + //tuples.removeAll(toRemove); + + return tuples; + } + + /*private void replacePredicate(StringTuple t) { + for (StringTuple rep : replacePredicate) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } + + private void replaceObject(StringTuple t) { + for (StringTuple rep : replaceObject) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + }*/ +} Copied: trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/ManipulatorType.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,23 @@ +package org.dllearner.kb.old; + +import java.util.LinkedList; + +import org.dllearner.utilities.datastructures.StringTuple; + + +/** + * Used to get the right manipulator + * + * @author Sebastian Knappe + * + */ +public class ManipulatorType { + + public static Manipulators getManipulatorByName(String predefinedManipulator,String blankNodeIdentifier, int breakSuperClassRetrievalAfter, LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) + { + if (predefinedManipulator.equals("DBPEDIA-NAVIGATOR")) return new DBpediaNavigatorManipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + else return new OldManipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + } +} Copied: trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/Manipulators.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,16 @@ +package org.dllearner.kb.old; + +import java.util.Set; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.StringTuple; + +public interface Manipulators { + + public int breakSuperClassRetrievalAfter = 200; + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + public String blankNodeIdentifier = "bnode"; + + public Set<StringTuple> check(Set<StringTuple> tuples, Node node); +} Copied: trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java (from rev 1074, trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/old/OldManipulator.java 2008-08-14 17:33:24 UTC (rev 1075) @@ -0,0 +1,161 @@ +/** + * Copyri... [truncated message content] |
From: <ku...@us...> - 2008-08-14 16:43:48
|
Revision: 1074 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1074&view=rev Author: kurzum Date: 2008-08-14 16:43:42 +0000 (Thu, 14 Aug 2008) Log Message: ----------- intermediate commit Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/test/FilterTest.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/manipulator/ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorCityLocator.java trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java trunk/src/dl-learner/org/dllearner/test/rules/ Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -28,6 +28,7 @@ import java.util.Vector; import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -19,6 +19,7 @@ */ package org.dllearner.kb.extraction; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorCityLocator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorCityLocator.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorCityLocator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -1,58 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -public class DBpediaNavigatorCityLocator { - - public static String getTypeToCoordinates(float lat, float lng){ - if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ - if (lat>50&&lat<52&&lng>12&&lng<13){ - return "http://dbpedia.org/class/custom/City_in_Saxony"; - } - else return "http://dbpedia.org/class/custom/City_in_Europe"; - } - else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ - if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ - return "http://dbpedia.org/class/custom/City_in_Egypt"; - } - else return "http://dbpedia.org/class/custom/City_in_Africa"; - } - else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ - return "http://dbpedia.org/class/custom/City_in_Asia"; - } - else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ - return "http://dbpedia.org/class/custom/City_in_Australia"; - } - else if (lng>-168.4&&lng<-19.7&&lat>6.6){ - return "http://dbpedia.org/class/custom/City_in_North_America"; - } - else if (lng>-81.56&&lng<-34.1&&lat<6.6){ - return "http://dbpedia.org/class/custom/City_in_South_America"; - } - else return "http://dbpedia.org/class/custom/City_in_World"; - } - - public static Set<StringTuple> getTuplesToAdd(String uri){ - String subClass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - - HashMap<String,String> map=new HashMap<String,String>(); - map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); - map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); - map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); - map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); - Set<StringTuple> toAdd = new HashSet<StringTuple>(); - if (map.containsKey(uri)){ - toAdd.add(new StringTuple(subClass,map.get(uri))); - } - return toAdd; - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -1,139 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Used to manipulate retrieved tupels, identify blanknodes, etc. - * - * @author Sebastian Hellmann - * - */ -public class DBpediaNavigatorManipulator implements Manipulators{ - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - final String classns = "http://www.w3.org/2002/07/owl#Class"; - final String thing = "http://www.w3.org/2002/07/owl#Thing"; - - public String blankNodeIdentifier = "bnode"; - public int breakSuperClassRetrievalAfter = 200; - public LinkedList<StringTuple> replacePredicate; - public LinkedList<StringTuple> replaceObject; - - // Set<String> classproperties; - - public DBpediaNavigatorManipulator(String blankNodeIdentifier, - int breakSuperClassRetrievalAfter, - LinkedList<StringTuple> replacePredicate, - LinkedList<StringTuple> replaceObject) { - this.blankNodeIdentifier = blankNodeIdentifier; - this.replaceObject = replaceObject; - this.replacePredicate = replacePredicate; - this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; - // Set<String> classproperties = new HashSet<String>(); - // classproperties.add(subclass); - - } - - /** - * this checks for consistency and manipulates the tuples, before they get - * triple - * - * @param tuples - * tuples for the node - * @param node - * @return - */ - public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { - //Set<StringTuple> toRemove = new HashSet<StringTuple>(); - Iterator<StringTuple> it = tuples.iterator(); - float lat=0; - float lng=0; - String clas=""; - StringTuple typeTupel=null; - tuples.addAll(DBpediaNavigatorCityLocator.getTuplesToAdd(node.uri.toString())); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - - if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ - clas=t.b; - typeTupel=t; - } - - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) - lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) - lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); - - /*replacePredicate(t); - replaceObject(t); - - - // remove <rdf:type, owl:class> - // this is done to avoid transformation to owl:subclassof - if (t.a.equals(type) && t.b.equals(classns) - && node instanceof ClassNode) { - toRemove.add(t); - } - - // all with type class - if (t.b.equals(classns) && node instanceof ClassNode) { - toRemove.add(t); - } - - // remove all instances with owl:type thing - if (t.a.equals(type) && t.b.equals(thing) - && node instanceof InstanceNode) { - toRemove.add(t); - }*/ - - } - if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ - String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); - tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); - tuples.remove(typeTupel); - } - //tuples.removeAll(toRemove); - - return tuples; - } - - /*private void replacePredicate(StringTuple t) { - for (StringTuple rep : replacePredicate) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - private void replaceObject(StringTuple t) { - for (StringTuple rep : replaceObject) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - }*/ -} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -26,6 +26,7 @@ import org.apache.log4j.Logger; import org.dllearner.kb.aquisitors.TypedSparqlQuery; import org.dllearner.kb.aquisitors.TypedSparqlQueryClasses; +import org.dllearner.kb.manipulator.Manipulators; /** * This class is used to extract the information . Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -28,6 +28,7 @@ import java.util.Vector; import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -26,6 +26,7 @@ import org.apache.log4j.Logger; import org.dllearner.kb.aquisitors.TypedSparqlQuery; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.statistics.Statistics; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -1,157 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * Used to manipulate retrieved tupels, identify blanknodes, etc. - * - * @author Sebastian Hellmann - * - */ -public class Manipulator implements Manipulators{ - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; - final String classns = "http://www.w3.org/2002/07/owl#Class"; - final String thing = "http://www.w3.org/2002/07/owl#Thing"; - - public String blankNodeIdentifier = "bnode"; - public int breakSuperClassRetrievalAfter = 200; - public LinkedList<StringTuple> replacePredicate; - public LinkedList<StringTuple> replaceObject; - - // Set<String> classproperties; - - public Manipulator(String blankNodeIdentifier, - int breakSuperClassRetrievalAfter, - LinkedList<StringTuple> replacePredicate, - LinkedList<StringTuple> replaceObject) { - this.blankNodeIdentifier = blankNodeIdentifier; - this.replaceObject = replaceObject; - this.replacePredicate = replacePredicate; - this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; - // Set<String> classproperties = new HashSet<String>(); - // classproperties.add(subclass); - - } - - /** - * this checks for consistency and manipulates the tuples, before they get - * triple - * - * @param tuples - * tuples for the node - * @param node - * @return - */ - public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { - Set<StringTuple> toRemove = new HashSet<StringTuple>(); - Iterator<StringTuple> it = tuples.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - - //HACK -// if(t.a.equals("http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag")) { -// //hackGetLabel(t.b); -// -// } - - // GovTrack hack - // => we convert a string literal to a URI - // => TODO: introduce an option for converting literals for certain - // properties into URIs -// String sp = "http://purl.org/dc/elements/1.1/subject"; -// if(t.a.equals(sp)) { -// System.out.println(t); -// System.exit(0); -// } - - replacePredicate(t); - replaceObject(t); - - - // remove <rdf:type, owl:class> - // this is done to avoid transformation to owl:subclassof - if (t.a.equals(type) && t.b.equals(classns) - && node instanceof ClassNode) { - toRemove.add(t); - } - - // all with type class - if (t.b.equals(classns) && node instanceof ClassNode) { - toRemove.add(t); - } - - // remove all instances with owl:type thing - if (t.a.equals(type) && t.b.equals(thing) - && node instanceof InstanceNode) { - toRemove.add(t); - } - - } - tuples.removeAll(toRemove); - - return tuples; - } - - private void replacePredicate(StringTuple t) { - for (StringTuple rep : replacePredicate) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - private void replaceObject(StringTuple t) { - for (StringTuple rep : replaceObject) { - if (rep.a.equals(t.a)) { - t.a = rep.b; - } - } - } - - - /*private String hackGetLabel(String resname){ - String query="" + - "SELECT ?o \n" + - "WHERE { \n" + - "<"+resname+"> "+ " <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o " + - "}"; - - System.out.println(query); - //http://dbtune.org/musicbrainz/sparql?query= - //SELECT ?o WHERE { <http://dbtune.org/musicbrainz/resource/tag/1391> <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o } - SparqlQuery s=new SparqlQuery(query,SparqlEndpoint.EndpointMusicbrainz()); - ResultSet rs=s.send(); - while (rs.hasNext()){ - rs.nextBinding(); - } - //System.out.println("AAA"+s.getAsXMLString(s.send()) ); - return ""; - }*/ - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -1,23 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.LinkedList; - -import org.dllearner.utilities.datastructures.StringTuple; - - -/** - * Used to get the right manipulator - * - * @author Sebastian Knappe - * - */ -public class ManipulatorType { - - public static Manipulators getManipulatorByName(String predefinedManipulator,String blankNodeIdentifier, int breakSuperClassRetrievalAfter, LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) - { - if (predefinedManipulator.equals("DBPEDIA-NAVIGATOR")) return new DBpediaNavigatorManipulator(blankNodeIdentifier, - breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - else return new Manipulator(blankNodeIdentifier, - breakSuperClassRetrievalAfter, replacePredicate, replaceObject); - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -1,15 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -public interface Manipulators { - - public int breakSuperClassRetrievalAfter = 200; - public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - public String blankNodeIdentifier = "bnode"; - - public Set<StringTuple> check(Set<StringTuple> tuples, Node node); -} Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -24,6 +24,7 @@ import java.util.Vector; import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; +import org.dllearner.kb.manipulator.Manipulators; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -28,6 +28,7 @@ import java.util.Vector; import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.utilities.datastructures.StringTuple; /** Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorCityLocator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,58 @@ +package org.dllearner.kb.manipulator; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import org.dllearner.utilities.datastructures.StringTuple; + +public class DBpediaNavigatorCityLocator { + + public static String getTypeToCoordinates(float lat, float lng){ + if (lat<71.08&&lat>33.39&&lng>-24.01&&lng<50.8){ + if (lat>50&&lat<52&&lng>12&&lng<13){ + return "http://dbpedia.org/class/custom/City_in_Saxony"; + } + else return "http://dbpedia.org/class/custom/City_in_Europe"; + } + else if (lng>-17.5&&lng<52.04&&lat>-36&&lat<36.6){ + if (lat>21.45&&lat<31.51&&lng>24.7&&lng<37.26){ + return "http://dbpedia.org/class/custom/City_in_Egypt"; + } + else return "http://dbpedia.org/class/custom/City_in_Africa"; + } + else if (((lng>27.4&&lng<180)||(lng<-168.75))&&lat>-11.2){ + return "http://dbpedia.org/class/custom/City_in_Asia"; + } + else if (lng>113.9&&lng<179.65&&lat<-10.8&&lat>-47.04){ + return "http://dbpedia.org/class/custom/City_in_Australia"; + } + else if (lng>-168.4&&lng<-19.7&&lat>6.6){ + return "http://dbpedia.org/class/custom/City_in_North_America"; + } + else if (lng>-81.56&&lng<-34.1&&lat<6.6){ + return "http://dbpedia.org/class/custom/City_in_South_America"; + } + else return "http://dbpedia.org/class/custom/City_in_World"; + } + + public static Set<StringTuple> getTuplesToAdd(String uri){ + String subClass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; + + HashMap<String,String> map=new HashMap<String,String>(); + map.put("http://dbpedia.org/class/custom/City_in_Saxony", "http://dbpedia.org/class/custom/City_in_Europe"); + map.put("http://dbpedia.org/class/custom/City_in_Egypt", "http://dbpedia.org/class/custom/City_in_Africa"); + map.put("http://dbpedia.org/class/custom/City_in_Europe", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Asia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Australia", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_North_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_South_America", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_Africa", "http://dbpedia.org/class/yago/City108524735"); + map.put("http://dbpedia.org/class/custom/City_in_World", "http://dbpedia.org/class/yago/City108524735"); + Set<StringTuple> toAdd = new HashSet<StringTuple>(); + if (map.containsKey(uri)){ + toAdd.add(new StringTuple(subClass,map.get(uri))); + } + return toAdd; + } +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorCityLocator.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/DBpediaNavigatorManipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,140 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.manipulator; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Used to manipulate retrieved tupels, identify blanknodes, etc. + * + * @author Sebastian Hellmann + * + */ +public class DBpediaNavigatorManipulator implements Manipulators{ + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + public String blankNodeIdentifier = "bnode"; + public int breakSuperClassRetrievalAfter = 200; + public LinkedList<StringTuple> replacePredicate; + public LinkedList<StringTuple> replaceObject; + + // Set<String> classproperties; + + public DBpediaNavigatorManipulator(String blankNodeIdentifier, + int breakSuperClassRetrievalAfter, + LinkedList<StringTuple> replacePredicate, + LinkedList<StringTuple> replaceObject) { + this.blankNodeIdentifier = blankNodeIdentifier; + this.replaceObject = replaceObject; + this.replacePredicate = replacePredicate; + this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; + // Set<String> classproperties = new HashSet<String>(); + // classproperties.add(subclass); + + } + + /** + * this checks for consistency and manipulates the tuples, before they get + * triple + * + * @param tuples + * tuples for the node + * @param node + * @return + */ + public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { + //Set<StringTuple> toRemove = new HashSet<StringTuple>(); + Iterator<StringTuple> it = tuples.iterator(); + float lat=0; + float lng=0; + String clas=""; + StringTuple typeTupel=null; + tuples.addAll(DBpediaNavigatorCityLocator.getTuplesToAdd(node.getURI().toString())); + while (it.hasNext()) { + StringTuple t = (StringTuple) it.next(); + + if (t.a.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")){ + clas=t.b; + typeTupel=t; + } + + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#lat")) + lat=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + if (t.a.equals("http://www.w3.org/2003/01/geo/wgs84_pos#long")) + lng=Float.parseFloat(t.b.substring(0,t.b.indexOf("^^"))); + + /*replacePredicate(t); + replaceObject(t); + + + // remove <rdf:type, owl:class> + // this is done to avoid transformation to owl:subclassof + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + }*/ + + } + if (clas.equals("http://dbpedia.org/class/yago/City108524735")){ + String newType=DBpediaNavigatorCityLocator.getTypeToCoordinates(lat, lng); + tuples.add(new StringTuple("http://www.w3.org/1999/02/22-rdf-syntax-ns#type",newType)); + tuples.remove(typeTupel); + } + //tuples.removeAll(toRemove); + + return tuples; + } + + /*private void replacePredicate(StringTuple t) { + for (StringTuple rep : replacePredicate) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } + + private void replaceObject(StringTuple t) { + for (StringTuple rep : replaceObject) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + }*/ +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/DBpediaNavigatorManipulator.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,218 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.manipulator; + +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; + +import org.dllearner.kb.extraction.ClassNode; +import org.dllearner.kb.extraction.InstanceNode; +import org.dllearner.kb.extraction.Node; +import org.dllearner.kb.manipulator.Rule.Months; +import org.dllearner.utilities.datastructures.RDFNodeTuple; +import org.dllearner.utilities.owl.OWLVocabulary; + +/** + * Used to manipulate retrieved tupels, identify blanknodes, etc. + * + * @author Sebastian Hellmann + * + */ +public class Manipulator { + + List<Rule> rules = new ArrayList<Rule>(); + //List<ReplacementRule> replacementRules = new ArrayList<ReplacementRule>(); + + + //public int breakSuperClassRetrievalAfter = 200; + //public LinkedList<StringTuple> replacePredicate; + //public LinkedList<StringTuple> replaceObject; + + // Set<String> classproperties; + + private Manipulator() { + + //this.replaceObject = replaceObject; + //this.replacePredicate = replacePredicate; + //this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; + // Set<String> classproperties = new HashSet<String>(); + // classproperties.add(subclass); + + } + + /** + * this checks for consistency and manipulates the tuples, before they get + * triple + */ + public SortedSet<RDFNodeTuple> manipulate( Node node, SortedSet<RDFNodeTuple> tuples) { + + for (Months month : Rule.MONTHS) { + tuples = applyRulesOfTheMonth(month, node, tuples); + } + return tuples; + /*SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); + + for (RDFNodeTuple currentTuple : tuples) { + currentTuple = manipulateTuple(node.getURI().toString(), currentTuple); + if(keepTuple(node, currentTuple)) { + keep.add(currentTuple); + } + + } + return keep;*/ + } + + public SortedSet<RDFNodeTuple> applyRulesOfTheMonth(Months month, Node subject, SortedSet<RDFNodeTuple> tuples){ + for (Rule rule : rules) { + if(rule.month.equals(month)) { + tuples = rule.applyRule(subject, tuples); + } + } + return tuples; + } + + public static Manipulator getManipulatorByName(String predefinedManipulator) + { + if (predefinedManipulator.equalsIgnoreCase("DBPEDIA-NAVIGATOR")) { + return getDBpediaNavigatorManipulator(); +// return new DBpediaNavigatorManipulator(blankNodeIdentifier, + //breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + + } else if(predefinedManipulator.equalsIgnoreCase("DEFAULT")){ + return getDefaultManipulator(); + } + else { + //QUALITY maybe not the best, should be Default + return new Manipulator(); + } + } + + public static Manipulator getDBpediaNavigatorManipulator(){ + Manipulator m = new Manipulator(); + return m; + } + + public static Manipulator getDefaultManipulator(){ + Manipulator m = new Manipulator(); + m.addDefaultRules(); + return m; + } + + //HACK +// if(t.a.equals("http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag")) { +// //hackGetLabel(t.b); +// +// } + + // GovTrack hack + // => we convert a string literal to a URI + // => TODO: introduce an option for converting literals for certain + // properties into URIs +// String sp = "http://purl.org/dc/elements/1.1/subject"; +// if(t.a.equals(sp)) { +// System.out.println(t); +// System.exit(0); +// } + + + private void addDefaultRules(){ + + rules.add(new TypeFilterRule(Months.DECEMBER, OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_CLASS,ClassNode.class.getCanonicalName() )) ; + rules.add(new TypeFilterRule(Months.DECEMBER,OWLVocabulary.RDF_TYPE, OWLVocabulary.OWL_THING,InstanceNode.class.getCanonicalName() )) ; + rules.add(new TypeFilterRule(Months.DECEMBER,"", OWLVocabulary.OWL_CLASS, ClassNode.class.getCanonicalName()) ) ; + } + + + + /* + private RDFNodeTuple manipulateTuple(String subject, RDFNodeTuple tuple) { + + for (int i = 0; i < replacementRules.size(); i++) { + ReplacementRule replace = replacementRules.get(i); + tuple = replace.applyRule(subject, tuple); + } + return tuple; + }*/ + + /*private String hackGetLabel(String resname){ + String query="" + + "SELECT ?o \n" + + "WHERE { \n" + + "<"+resname+"> "+ " <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o " + + "}"; + + System.out.println(query); + //http://dbtune.org/musicbrainz/sparql?query= + //SELECT ?o WHERE { <http://dbtune.org/musicbrainz/resource/tag/1391> <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o } + SparqlQuery s=new SparqlQuery(query,SparqlEndpoint.EndpointMusicbrainz()); + ResultSet rs=s.send(); + while (rs.hasNext()){ + rs.nextBinding(); + } + //System.out.println("AAA"+s.getAsXMLString(s.send()) ); + return ""; + }*/ + + /*private void replacePredicate(StringTuple t) { + for (StringTuple rep : replacePredicate) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } +} + +private void replaceObject(StringTuple t) { + for (StringTuple rep : replaceObject) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } +}*/ + + + + /* + // remove <rdf:type, owl:class> + // this is done to avoid transformation to owl:subclassof + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + } + + } + tuples.removeAll(toRemove); + + return tuples; +} +*/ + +} Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/ManipulatorType.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,23 @@ +package org.dllearner.kb.manipulator; + +import java.util.LinkedList; + +import org.dllearner.utilities.datastructures.StringTuple; + + +/** + * Used to get the right manipulator + * + * @author Sebastian Knappe + * + */ +public class ManipulatorType { + + public static Manipulators getManipulatorByName(String predefinedManipulator,String blankNodeIdentifier, int breakSuperClassRetrievalAfter, LinkedList<StringTuple> replacePredicate,LinkedList<StringTuple> replaceObject) + { + if (predefinedManipulator.equals("DBPEDIA-NAVIGATOR")) return new DBpediaNavigatorManipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + else return new OldManipulator(blankNodeIdentifier, + breakSuperClassRetrievalAfter, replacePredicate, replaceObject); + } +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/ManipulatorType.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulators.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,16 @@ +package org.dllearner.kb.manipulator; + +import java.util.Set; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.StringTuple; + +public interface Manipulators { + + public int breakSuperClassRetrievalAfter = 200; + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + public String blankNodeIdentifier = "bnode"; + + public Set<StringTuple> check(Set<StringTuple> tuples, Node node); +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/Manipulators.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,160 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.manipulator; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.kb.extraction.ClassNode; +import org.dllearner.kb.extraction.InstanceNode; +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * Used to manipulate retrieved tupels, identify blanknodes, etc. + * + * @author Sebastian Hellmann + * + */ +public class OldManipulator implements Manipulators{ + public final String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public final String type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + final String objectProperty = "http://www.w3.org/2002/07/owl#ObjectProperty"; + final String classns = "http://www.w3.org/2002/07/owl#Class"; + final String thing = "http://www.w3.org/2002/07/owl#Thing"; + + public String blankNodeIdentifier = "bnode"; + public int breakSuperClassRetrievalAfter = 200; + public LinkedList<StringTuple> replacePredicate; + public LinkedList<StringTuple> replaceObject; + + // Set<String> classproperties; + + public OldManipulator(String blankNodeIdentifier, + int breakSuperClassRetrievalAfter, + LinkedList<StringTuple> replacePredicate, + LinkedList<StringTuple> replaceObject) { + this.blankNodeIdentifier = blankNodeIdentifier; + this.replaceObject = replaceObject; + this.replacePredicate = replacePredicate; + this.breakSuperClassRetrievalAfter = breakSuperClassRetrievalAfter; + // Set<String> classproperties = new HashSet<String>(); + // classproperties.add(subclass); + + } + + /** + * this checks for consistency and manipulates the tuples, before they get + * triple + * + * @param tuples + * tuples for the node + * @param node + * @return + */ + public Set<StringTuple> check(Set<StringTuple> tuples, Node node) { + Set<StringTuple> toRemove = new HashSet<StringTuple>(); + Iterator<StringTuple> it = tuples.iterator(); + while (it.hasNext()) { + StringTuple t = (StringTuple) it.next(); + + //HACK +// if(t.a.equals("http://www.holygoat.co.uk/owl/redwood/0.1/tags/taggedWithTag")) { +// //hackGetLabel(t.b); +// +// } + + // GovTrack hack + // => we convert a string literal to a URI + // => TODO: introduce an option for converting literals for certain + // properties into URIs +// String sp = "http://purl.org/dc/elements/1.1/subject"; +// if(t.a.equals(sp)) { +// System.out.println(t); +// System.exit(0); +// } + + replacePredicate(t); + replaceObject(t); + + + // remove <rdf:type, owl:class> + // this is done to avoid transformation to owl:subclassof + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + } + + } + tuples.removeAll(toRemove); + + return tuples; + } + + private void replacePredicate(StringTuple t) { + for (StringTuple rep : replacePredicate) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } + + private void replaceObject(StringTuple t) { + for (StringTuple rep : replaceObject) { + if (rep.a.equals(t.a)) { + t.a = rep.b; + } + } + } + + + /*private String hackGetLabel(String resname){ + String query="" + + "SELECT ?o \n" + + "WHERE { \n" + + "<"+resname+"> "+ " <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o " + + "}"; + + System.out.println(query); + //http://dbtune.org/musicbrainz/sparql?query= + //SELECT ?o WHERE { <http://dbtune.org/musicbrainz/resource/tag/1391> <http://www.holygoat.co.uk/owl/redwood/0.1/tags/tagName> ?o } + SparqlQuery s=new SparqlQuery(query,SparqlEndpoint.EndpointMusicbrainz()); + ResultSet rs=s.send(); + while (rs.hasNext()){ + rs.nextBinding(); + } + //System.out.println("AAA"+s.getAsXMLString(s.send()) ); + return ""; + }*/ + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/OldManipulator.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java (from rev 1072, trunk/src/dl-learner/org/dllearner/test/rules/FilterRule.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,43 @@ +package org.dllearner.kb.manipulator; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.SortedSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +public abstract class Rule { + + + public static final List<Months> MONTHS = new ArrayList<Months>(Arrays.asList(Months.values())); + + public enum Months { + JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, + AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER; + } + + Months month; + + + + + public Rule(Months month) { + this.month = month; + + } + + + public abstract SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples); + + + public static void main(String[] args) { + System.out.println(); + for (int i = 0; i < Months.values().length; i++) { + System.out.println(Months.values()[i]); + + } + System.out.println(Months.values()); + } +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/Rule.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java (from rev 1072, trunk/src/dl-learner/org/dllearner/test/rules/SimpleObjectFilterRule.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,44 @@ +package org.dllearner.kb.manipulator; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +public class SimpleObjectFilterRule extends Rule{ + + String objectFilter; + + public SimpleObjectFilterRule(Months month, String objectFilter) { + super(month); + this.objectFilter = objectFilter; + } + + + @Override + public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ + SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); + for (RDFNodeTuple tuple : tuples) { + if(!tuple.bPartContains(objectFilter)){ + keep.add(tuple); + } + } + return keep; + } + + /* + private boolean keepTuple(Node subject, RDFNodeTuple tuple) { + + for (int i = 0; i < filterRules.size(); i++) { + Rule fr = filterRules.get(i); + if (!(fr.keepTuple(subject, tuple))) { + return false; + } + } + return true; + }*/ + + + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimpleObjectFilterRule.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java (from rev 1072, trunk/src/dl-learner/org/dllearner/test/rules/SimplePredicateFilterRule.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,34 @@ +package org.dllearner.kb.manipulator; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +public class SimplePredicateFilterRule extends Rule{ + + String predicateFilter; + + + public SimplePredicateFilterRule(Months month, String predicateFilter) { + super(month); + this.predicateFilter = predicateFilter; + } + + + @Override + public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ + SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); + for (RDFNodeTuple tuple : tuples) { + if(!tuple.aPartContains(predicateFilter)){ + keep.add(tuple); + } + } + return keep; + } + + + + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/manipulator/SimplePredicateFilterRule.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/manipulator/TypeFilterRule.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -0,0 +1,58 @@ +package org.dllearner.kb.manipulator; + +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.kb.extraction.Node; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +public class TypeFilterRule extends Rule{ + + String predicateFilter; + String objectFilter; + String canonicalClassName; + + + public TypeFilterRule(Months month, String predicateFilter, String objectFilter, String canonicalClassName) { + super(month); + this.predicateFilter = predicateFilter; + this.objectFilter = objectFilter; + this.canonicalClassName = canonicalClassName; + } + + + + @Override + public SortedSet<RDFNodeTuple> applyRule(Node subject, SortedSet<RDFNodeTuple> tuples){ + SortedSet<RDFNodeTuple> keep = new TreeSet<RDFNodeTuple>(); + for (RDFNodeTuple tuple : tuples) { + boolean remove = (tuple.aPartContains(predicateFilter) && + tuple.bPartContains(objectFilter) && + subject.getClass().getCanonicalName().equals(canonicalClassName)); + if(!remove){ + keep.add(tuple); + } + } + return keep; + } + + + /* + if (t.a.equals(type) && t.b.equals(classns) + && node instanceof ClassNode) { + toRemove.add(t); + } + + // all with type class + if (t.b.equals(classns) && node instanceof ClassNode) { + toRemove.add(t); + } + + // remove all instances with owl:type thing + if (t.a.equals(type) && t.b.equals(thing) + && node instanceof InstanceNode) { + toRemove.add(t); + } + */ + +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -47,8 +47,8 @@ import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.owl.KB; import org.dllearner.kb.extraction.Manager; -import org.dllearner.kb.extraction.ManipulatorType; -import org.dllearner.kb.extraction.Manipulators; +import org.dllearner.kb.manipulator.ManipulatorType; +import org.dllearner.kb.manipulator.Manipulators; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; Modified: trunk/src/dl-learner/org/dllearner/test/FilterTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -5,9 +5,6 @@ import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.test.rules.RuleExecutor; -import org.dllearner.test.rules.SimpleObjectFilterRule; -import org.dllearner.test.rules.SimplePredicateFilterRule; import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.datastructures.StringTuple; import org.dllearner.utilities.statistics.SimpleClock; @@ -122,7 +119,7 @@ static void testShortWithFilter(){ SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>(); SortedSet<StringTuple> afterfilter= new TreeSet<StringTuple>(); - RuleExecutor re = new RuleExecutor(); + /*RuleExecutor re = new RuleExecutor(); re.addFilterRule(new SimplePredicateFilterRule( "http://dbpedia.org/property/relatedInstance" )); @@ -145,13 +142,13 @@ re.addFilterRule(new SimpleObjectFilterRule( "http://www.w3.org/2004/02/skos/core" )); re.addFilterRule(new SimpleObjectFilterRule("http://www.geonames.org")); + */ - sc.reset(); for (int i = 0; i < howmany; i++) { tupleset = st.queryAsTuple(subject, true); - afterfilter = re.filterTuples(subject,tupleset); + //afterfilter = re.filterTuples(subject,tupleset); } sc.printAndSet("SHORT with filter"); SetManipulation.printSet("before", tupleset); Modified: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -25,7 +25,7 @@ import java.util.LinkedList; import org.dllearner.kb.extraction.Manager; -import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.manipulator.OldManipulator; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.StringTuple; @@ -49,7 +49,7 @@ URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); m.useConfiguration(SparqlQueryMaker.getSparqlQueryMakerByName("DBPEDIA"),SparqlEndpoint.getEndpointByName("YAGO"), - new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), + new OldManipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), 1,true,true,"cache"); //, , //manipulator, recursiondepth, getAllSuperClasses, closeAfterRecursion) Modified: trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -51,5 +51,13 @@ return b.toString().compareTo(t.b.toString()); }else return comp; } + + public boolean aPartContains(String partOf) { + return !(a.toString().contains(partOf)); + } + + public boolean bPartContains(String partOf) { + return (b.toString().contains(partOf)); + } } Modified: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-14 14:18:37 UTC (rev 1073) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-14 16:43:42 UTC (rev 1074) @@ -8,6 +8,10 @@ public static final String OWL_SAME_AS = "http://www.w3.org/2002/07/owl#sameAs"; + public static final String OWL_OBJECTPROPERTY = "http://www.w3.org/2002/07/owl#ObjectProperty"; + public static final String OWL_CLASS = "http://www.w3.org/2002/07/owl#Class"; + public static final String OWL_THING = "http://www.w3.org/2002/07/owl#Thing"; + // public static final String RDF_TYPE = ""; // public static final String RDF_TYPE = ""; // public static final String RDF_TYPE = ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-14 14:18:47
|
Revision: 1073 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1073&view=rev Author: kurzum Date: 2008-08-14 14:18:37 +0000 (Thu, 14 Aug 2008) Log Message: ----------- intermediate commit Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/test/FilterTest.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/aquisitors/ trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java trunk/src/dl-learner/org/dllearner/test/TripleTypeTest.java trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryInterface.java Added: trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/LinkedDataTupelAquisitor.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import java.net.URI; +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class LinkedDataTupelAquisitor extends TupelAquisitor { + + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(LinkedDataTupelAquisitor.class); + + private Configuration configuration; + protected SparqlQueryMaker sparqlQueryMaker; + protected SPARQLTasks sparqlTasks; + + public LinkedDataTupelAquisitor(Configuration Configuration) { + this.configuration = Configuration; + this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); + this.sparqlTasks = configuration.sparqlTasks; + } + + // standard query get a tupels (p,o) for subject s + @Override + public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { + + + String pred = "predicate"; + String obj = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker + .makeSubjectQueryUsingFilters(uri.toString()); + + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + + } + + + + + +} Copied: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import java.net.URI; +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class SparqlTupelAquisitor extends TupelAquisitor { + + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); + + private Configuration configuration; + protected SparqlQueryMaker sparqlQueryMaker; + protected SPARQLTasks sparqlTasks; + + public SparqlTupelAquisitor(Configuration Configuration) { + this.configuration = Configuration; + this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); + this.sparqlTasks = configuration.sparqlTasks; + } + + // standard query get a tupels (p,o) for subject s + @Override + public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { + + + String pred = "predicate"; + String obj = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker + .makeSubjectQueryUsingFilters(uri.toString()); + + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + + } + + + + + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitor.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import java.net.URI; +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class SparqlTupelAquisitorClasses extends SparqlTupelAquisitor { + + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); + + public SparqlTupelAquisitorClasses(Configuration configuration) { + super(configuration); + } + + /* + * Special TypedSparqlQuery which returns superclasses of classes + * (non-Javadoc) + * + * @see org.dllearner.kb.sparql.TypedSparqlQuery#getTupelForResource(java.net.URI) + */ + @Override + @SuppressWarnings({"unchecked"}) + public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { + //Set<RDFNodeTuple> s = new TreeSet<RDFNodeTuple>(); + String pred = "predicate"; + String obj = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker.makeClassQueryUsingFilters(uri.toString()); + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorClasses.java ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/SparqlTupelAquisitorImproved.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,71 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import java.net.URI; +import java.util.SortedSet; + +import org.apache.log4j.Logger; +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class SparqlTupelAquisitorImproved extends TupelAquisitor { + + @SuppressWarnings("unused") + private static Logger logger = Logger.getLogger(SparqlTupelAquisitorImproved.class); + + private Configuration configuration; + protected SparqlQueryMaker sparqlQueryMaker; + protected SPARQLTasks sparqlTasks; + + public SparqlTupelAquisitorImproved(Configuration Configuration) { + this.configuration = Configuration; + this.sparqlQueryMaker = configuration.getSparqlQueryMaker(); + this.sparqlTasks = configuration.sparqlTasks; + } + + // standard query get a tupels (p,o) for subject s + @Override + public SortedSet<RDFNodeTuple> getTupelForResource(URI uri) { + + + String pred = "predicate"; + String obj = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker + .makeSubjectQueryUsingFilters(uri.toString()); + + return sparqlTasks.queryAsRDFNodeTuple(sparqlQueryString, pred, obj); + + } + + + + + +} Copied: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2007-2008, 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.kb.aquisitors; + +import java.net.URI; +import java.util.SortedSet; + +import org.dllearner.utilities.datastructures.RDFNodeTuple; + +/** + * + * Typed SPARQL query interface. The typing means that they all have the same + * input and the same output: They are fn: resource -> ( a | b ) where a + * normally is a predicate and b an object + * + * @author Sebastian Hellmann + * + */ +public abstract class TupelAquisitor { + + public abstract SortedSet<RDFNodeTuple> getTupelForResource(URI u); +} + + Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TupelAquisitor.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,124 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.aquisitors; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.log4j.Logger; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.utilities.datastructures.StringTuple; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.sparql.core.ResultBinding; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class TypedSparqlQuery implements TypedSparqlQueryInterface { + + private static Logger logger = Logger.getLogger(KnowledgeSource.class); + + + boolean print_flag = false; + protected Configuration configuration; + private SparqlQueryMaker sparqlQueryMaker; + Cache cache; + + // boolean debug_no_cache = false;// true means no cache is used + // private SparqlHTTPRequest SparqlHTTPRequest; + // private SparqlQuery sparqlQuery; + // private CachedSparqlQuery cachedSparqlQuery; + + public TypedSparqlQuery(Configuration Configuration) { + this.configuration = Configuration; + this.sparqlQueryMaker =Configuration.getSparqlQueryMaker(); + + this.cache = new Cache(configuration.cacheDir); + // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); + // this.cachedSparqlQuery=new + // CachedSparqlQuery(this.sparqlQuery,this.cache); + } + + // standard query get a tupels (p,o) for subject s + /** + * uses a cache and gets the result tuples for a resource u + * + * @param uri + * the resource + * @param sparqlQueryString + * @param a + * the name of the first bound variable for xml parsing, normally + * predicate + * @param b + * the name of the second bound variable for xml parsing, + * normally object + * @return + */ + @SuppressWarnings({"unchecked"}) + public Set<StringTuple> getTupelForResource(URI uri) { + Set<StringTuple> s = new HashSet<StringTuple>(); + + String a = "predicate"; + String b = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker + .makeSubjectQueryUsingFilters(uri.toString()); + +// CachedSparqlQuery csq = new CachedSparqlQuery(configuration +// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); + + SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); +// query.extraDebugInfo=uri.toString(); + String JSON = cache.executeSparqlQuery(query); + + ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON); + + List<ResultBinding> l = ResultSetFormatter.toList(rs); + + logger.trace(l.toString()); + for (ResultBinding resultBinding : l) { + + s.add(new StringTuple(resultBinding.get(a).toString(), + resultBinding.get(b).toString())); + } + return s; + } + + + + + + + + + + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQuery.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,80 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.aquisitors; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.utilities.datastructures.StringTuple; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.sparql.core.ResultBinding; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class TypedSparqlQueryClasses extends TypedSparqlQuery implements + TypedSparqlQueryInterface { + + public TypedSparqlQueryClasses(Configuration configuration) { + super(configuration); + } + + /* + * Special TypedSparqlQuery which returns superclasses of classes + * (non-Javadoc) + * + * @see org.dllearner.kb.sparql.TypedSparqlQuery#getTupelForResource(java.net.URI) + */ + @Override + @SuppressWarnings({"unchecked"}) + public Set<StringTuple> getTupelForResource(URI uri) { + Set<StringTuple> s = new HashSet<StringTuple>(); + String a = "predicate"; + String b = "object"; + // getQuery for all super classes of classes only + String sparqlQueryString = "SELECT ?predicate ?object " + "WHERE {" + + "<" + uri.toString() + "> ?predicate ?object;" + + "a ?object . " + + " FILTER (!regex(str(?object),'http://xmlns.com/foaf/0.1/'))" + + "}"; + + SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); +// query.extraDebugInfo=uri.toString(); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(query)); + + List<ResultBinding> l = ResultSetFormatter.toList(rs); + for (ResultBinding resultBinding : l) { + + s.add(new StringTuple(resultBinding.get(a).toString(), + resultBinding.get(b).toString())); + } + return s; + } + +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryClasses.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java (from rev 1072, trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryInterface.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,39 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.aquisitors; + +import java.net.URI; +import java.util.Set; + +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * + * Typed SPARQL query interface. The typing means that they all have the same + * input and the same output: They are fn: resource -> ( a | b ) where a + * normally is a predicate and b an object + * + * @author Sebastian Hellmann + * + */ +public interface TypedSparqlQueryInterface { + + public Set<StringTuple> getTupelForResource(URI u); +} Property changes on: trunk/src/dl-learner/org/dllearner/kb/aquisitors/TypedSparqlQueryInterface.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ClassNode.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -27,6 +27,7 @@ import java.util.TreeSet; import java.util.Vector; +import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -31,10 +31,11 @@ */ public class Configuration { - private SPARQLTasks sparqlTasks; + public SPARQLTasks sparqlTasks; private SparqlEndpoint endpoint; private SparqlQueryMaker sparqlQueryMaker; + private Manipulators manipulator; // the following needs to be moved to // class extraction algorithm or manipulator Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -24,6 +24,8 @@ import java.util.Vector; import org.apache.log4j.Logger; +import org.dllearner.kb.aquisitors.TypedSparqlQuery; +import org.dllearner.kb.aquisitors.TypedSparqlQueryClasses; /** * This class is used to extract the information . Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/InstanceNode.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -27,6 +27,7 @@ import java.util.TreeSet; import java.util.Vector; +import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -25,6 +25,7 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.kb.aquisitors.TypedSparqlQuery; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.statistics.Statistics; Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Node.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -23,7 +23,9 @@ import java.util.SortedSet; import java.util.Vector; +import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; + /** * Abstract class. defines functions to expand the nodes * Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/PropertyNode.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -27,6 +27,7 @@ import java.util.TreeSet; import java.util.Vector; +import org.dllearner.kb.aquisitors.TypedSparqlQueryInterface; import org.dllearner.utilities.datastructures.StringTuple; /** Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -1,124 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.log4j.Logger; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.kb.sparql.SparqlQueryMaker; -import org.dllearner.utilities.datastructures.StringTuple; - -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class SparqlTupelAquisitor extends TupelAquisitor { - - private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); - - - //boolean print_flag = false; - private Configuration configuration; - private SparqlQueryMaker sparqlQueryMaker; - Cache cache; - - // boolean debug_no_cache = false;// true means no cache is used - // private SparqlHTTPRequest SparqlHTTPRequest; - // private SparqlQuery sparqlQuery; - // private CachedSparqlQuery cachedSparqlQuery; - - public SparqlTupelAquisitor(Configuration Configuration) { - this.configuration = Configuration; - /*this.sparqlQueryMaker = new SparqlQueryMaker(Configuration - .getSparqlQueryType()); - */ - this.cache = new Cache(configuration.cacheDir); - // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); - // this.cachedSparqlQuery=new - // CachedSparqlQuery(this.sparqlQuery,this.cache); - } - - // standard query get a tupels (p,o) for subject s - /** - * uses a cache and gets the result tuples for a resource u - * - * @param uri - * the resource - * @param sparqlQueryString - * @param a - * the name of the first bound variable for xml parsing, normally - * predicate - * @param b - * the name of the second bound variable for xml parsing, - * normally object - * @return - */ - @Override - @SuppressWarnings({"unchecked"}) - public SortedSet<StringTuple> getTupelForResource(URI uri) { - SortedSet<StringTuple> s = new TreeSet<StringTuple>(); - - String a = "predicate"; - String b = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); - -// CachedSparqlQuery csq = new CachedSparqlQuery(configuration -// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); - - SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); -// query.extraDebugInfo=uri.toString(); - String JSON = cache.executeSparqlQuery(query); - - ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON); - - List<ResultBinding> l = ResultSetFormatter.toList(rs); - - logger.trace(l.toString()); - for (ResultBinding resultBinding : l) { - - s.add(new StringTuple(resultBinding.get(a).toString(), - resultBinding.get(b).toString())); - } - return s; - } - - - - - - - - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.SortedSet; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * - * Typed SPARQL query interface. The typing means that they all have the same - * input and the same output: They are fn: resource -> ( a | b ) where a - * normally is a predicate and b an object - * - * @author Sebastian Hellmann - * - */ -public abstract class TupelAquisitor { - - public abstract SortedSet<StringTuple> getTupelForResource(URI u); -} - - Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -1,123 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.dllearner.core.KnowledgeSource; -import org.dllearner.kb.sparql.Cache; -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.kb.sparql.SparqlQueryMaker; -import org.dllearner.utilities.datastructures.StringTuple; - -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class TypedSparqlQuery implements TypedSparqlQueryInterface { - - private static Logger logger = Logger.getLogger(KnowledgeSource.class); - - - boolean print_flag = false; - protected Configuration configuration; - private SparqlQueryMaker sparqlQueryMaker; - Cache cache; - - // boolean debug_no_cache = false;// true means no cache is used - // private SparqlHTTPRequest SparqlHTTPRequest; - // private SparqlQuery sparqlQuery; - // private CachedSparqlQuery cachedSparqlQuery; - - public TypedSparqlQuery(Configuration Configuration) { - this.configuration = Configuration; - this.sparqlQueryMaker =Configuration.getSparqlQueryMaker(); - - this.cache = new Cache(configuration.cacheDir); - // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); - // this.cachedSparqlQuery=new - // CachedSparqlQuery(this.sparqlQuery,this.cache); - } - - // standard query get a tupels (p,o) for subject s - /** - * uses a cache and gets the result tuples for a resource u - * - * @param uri - * the resource - * @param sparqlQueryString - * @param a - * the name of the first bound variable for xml parsing, normally - * predicate - * @param b - * the name of the second bound variable for xml parsing, - * normally object - * @return - */ - @SuppressWarnings({"unchecked"}) - public Set<StringTuple> getTupelForResource(URI uri) { - Set<StringTuple> s = new HashSet<StringTuple>(); - - String a = "predicate"; - String b = "object"; - // getQuery - String sparqlQueryString = sparqlQueryMaker - .makeSubjectQueryUsingFilters(uri.toString()); - -// CachedSparqlQuery csq = new CachedSparqlQuery(configuration -// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); - - SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); -// query.extraDebugInfo=uri.toString(); - String JSON = cache.executeSparqlQuery(query); - - ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON); - - List<ResultBinding> l = ResultSetFormatter.toList(rs); - - logger.trace(l.toString()); - for (ResultBinding resultBinding : l) { - - s.add(new StringTuple(resultBinding.get(a).toString(), - resultBinding.get(b).toString())); - } - return s; - } - - - - - - - - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryClasses.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -1,79 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.dllearner.kb.sparql.SparqlQuery; -import org.dllearner.utilities.datastructures.StringTuple; - -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFormatter; -import com.hp.hpl.jena.sparql.core.ResultBinding; - -/** - * Can execute different queries. - * - * @author Sebastian Hellmann - * - */ -public class TypedSparqlQueryClasses extends TypedSparqlQuery implements - TypedSparqlQueryInterface { - - public TypedSparqlQueryClasses(Configuration configuration) { - super(configuration); - } - - /* - * Special TypedSparqlQuery which returns superclasses of classes - * (non-Javadoc) - * - * @see org.dllearner.kb.sparql.TypedSparqlQuery#getTupelForResource(java.net.URI) - */ - @Override - @SuppressWarnings({"unchecked"}) - public Set<StringTuple> getTupelForResource(URI uri) { - Set<StringTuple> s = new HashSet<StringTuple>(); - String a = "predicate"; - String b = "object"; - // getQuery for all super classes of classes only - String sparqlQueryString = "SELECT ?predicate ?object " + "WHERE {" - + "<" + uri.toString() + "> ?predicate ?object;" - + "a ?object . " - + " FILTER (!regex(str(?object),'http://xmlns.com/foaf/0.1/'))" - + "}"; - - SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); -// query.extraDebugInfo=uri.toString(); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSparqlQuery(query)); - - List<ResultBinding> l = ResultSetFormatter.toList(rs); - for (ResultBinding resultBinding : l) { - - s.add(new StringTuple(resultBinding.get(a).toString(), - resultBinding.get(b).toString())); - } - return s; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryInterface.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryInterface.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQueryInterface.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -1,39 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.extraction; - -import java.net.URI; -import java.util.Set; - -import org.dllearner.utilities.datastructures.StringTuple; - -/** - * - * Typed SPARQL query interface. The typing means that they all have the same - * input and the same output: They are fn: resource -> ( a | b ) where a - * normally is a predicate and b an object - * - * @author Sebastian Hellmann - * - */ -public interface TypedSparqlQueryInterface { - - public Set<StringTuple> getTupelForResource(URI u); -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SPARQLTasks.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -24,6 +24,7 @@ import java.util.TreeSet; import org.apache.log4j.Logger; +import org.dllearner.utilities.datastructures.RDFNodeTuple; import org.dllearner.utilities.datastructures.StringTuple; import com.hp.hpl.jena.query.ResultSet; @@ -383,7 +384,7 @@ return queryAsSet(sparqlQueryString, variable); } - + @Deprecated public SortedSet<StringTuple> queryAsTuple(String subject, boolean filterLiterals) { ResultSetRewindable rs = null; String p = "predicate"; @@ -405,6 +406,47 @@ return getTuplesFromResultSet(rs, p, o); } + @Deprecated + public SortedSet<StringTuple> queryAsTuple(String sparqlQueryString, String var1, String var2) { + ResultSetRewindable rs = null; + try { + String jsonString = query(sparqlQueryString); + rs = SparqlQuery.convertJSONtoResultSet(jsonString); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + //SimpleClock sc = new SimpleClock(); + //rw = ResultSetFactory.makeRewindable(rs); + //sc.printAndSet("rewindable"); + return getTuplesFromResultSet(rs, var1, var2); + } + + @SuppressWarnings("unchecked") + public SortedSet<RDFNodeTuple> queryAsRDFNodeTuple(String sparqlQueryString, String var1, String var2) { + ResultSetRewindable rsw = null; + SortedSet<RDFNodeTuple> returnSet = new TreeSet<RDFNodeTuple>(); + + try { + String jsonString = query(sparqlQueryString); + rsw = SparqlQuery.convertJSONtoResultSet(jsonString); + + } catch (Exception e) { + logger.warn(e.getMessage()); + } + + List<ResultBinding> l = ResultSetFormatter.toList(rsw); + for (ResultBinding resultBinding : l) { + returnSet.add(new RDFNodeTuple(resultBinding.get(var1),resultBinding.get(var2))); + } + + rsw.reset(); + + return returnSet; + } + + /** * little higher level, executes query ,returns all resources for a * variable. Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -96,7 +96,23 @@ return returnString; } + + public String makeClassQueryUsingFilters(String subject) { + // String filter = internalFilterAssemblySubject(); + String tmpFilter = internalFilterAssemblySubject("predicate", "object"); + tmpFilter = (tmpFilter.length() > 0) ? "FILTER( " + lineend + tmpFilter + + "). " : " "; + + String returnString = "SELECT * WHERE {" +lineend + + "<" + subject + "> ?predicate ?object;" + + "a ?object . "+lineend+ + tmpFilter + "}"; + + + return returnString; + } + public String makeSubjectQueryLevel(String subject, int level) { // String filter = internalFilterAssemblySubject(); Modified: trunk/src/dl-learner/org/dllearner/test/FilterTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-14 12:09:10 UTC (rev 1072) +++ trunk/src/dl-learner/org/dllearner/test/FilterTest.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -36,6 +36,7 @@ /** * @param args */ + @SuppressWarnings("deprecation") public static void main(String[] args) { // System.out.println(qextralong); @@ -78,6 +79,7 @@ } + @SuppressWarnings("deprecation") static void testShort(){ SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>(); sc.reset(); @@ -116,6 +118,7 @@ sc.printAndSet("qextrashort "); } + @SuppressWarnings("deprecation") static void testShortWithFilter(){ SortedSet<StringTuple> tupleset = new TreeSet<StringTuple>(); SortedSet<StringTuple> afterfilter= new TreeSet<StringTuple>(); Added: trunk/src/dl-learner/org/dllearner/test/TripleTypeTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/TripleTypeTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/TripleTypeTest.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,44 @@ +package org.dllearner.test; + +import java.util.List; + +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SPARQLTasks; +import org.dllearner.kb.sparql.SparqlEndpoint; + +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.query.ResultSetRewindable; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.sparql.core.ResultBinding; + +public class TripleTypeTest { + + + public static void main(String[] args) { + String sparqlQueryString ="SELECT * WHERE { <http://dbpedia.org/resource/Angela_Merkel> ?predicate ?object. FILTER (isLiteral(?object))}"; + //sparqlQueryString ="SELECT * WHERE { <http://dbpedia.org/resource/Angela_Merkel> <http://dbpedia.org/property/hasPhotoCollection> ?object }"; + System.out.println(sparqlQueryString); + + SPARQLTasks st = new SPARQLTasks (Cache.getDefaultCache(), SparqlEndpoint.getEndpointDBpedia()); + + ResultSetRewindable rsw = st.queryAsResultSet(sparqlQueryString); + List<ResultBinding> l = ResultSetFormatter.toList(rsw); + + for (ResultBinding binding : l) { + //RDFNode pred = binding.get("predicate"); + RDFNode obj = binding.get("object"); + //System.out.println(pred.toString()); + //System.out.println(obj.toString()); + System.out.println(obj.isLiteral()); + System.out.println(obj.isAnon()); + System.out.println(obj.isResource()); + System.out.println(obj.isURIResource()); + Literal lit =(Literal) obj; + System.out.println(lit.toString()); + System.out.println(lit.getLanguage()); + } + + + } +} Added: trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/RDFNodeTuple.java 2008-08-14 14:18:37 UTC (rev 1073) @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2007, 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.utilities.datastructures; + +import com.hp.hpl.jena.rdf.model.RDFNode; + +/** + * A container which can hold two Strings, mainly used as a helper. + * Also used as pre form, if you want to create triple, that have the same subject + * @author Sebastian Hellmann + */ +public class RDFNodeTuple implements Comparable<RDFNodeTuple>{ + + public RDFNode a; + public RDFNode b; + + public RDFNodeTuple(RDFNode a, RDFNode b) { + this.a = a; + this.b = b; + } + + @Override + public String toString() { + return "<" + a.toString() + "|" + b.toString() + ">"; + } + + public boolean equals(RDFNodeTuple t) { + return ((b.toString().equals(t.b.toString())) && (a.toString().equals(t.a))); + } + + public int compareTo(RDFNodeTuple t){ + int comp = a.toString().compareTo(t.a.toString()); + if( comp == 0 ){ + return b.toString().compareTo(t.b.toString()); + }else return comp; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hee...@us...> - 2008-08-14 12:09:12
|
Revision: 1072 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1072&view=rev Author: heeroyuy Date: 2008-08-14 12:09:10 +0000 (Thu, 14 Aug 2008) Log Message: ----------- -small changes in protege build task Modified Paths: -------------- trunk/build.xml Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-08-14 12:08:46 UTC (rev 1071) +++ trunk/build.xml 2008-08-14 12:09:10 UTC (rev 1072) @@ -286,42 +286,46 @@ <!-- build protege plugin and copy it to the plugin folder --> <target name="protege"> - <property name="source" value="src/dl-learner/org/dllearner/tools/protege" /> - <property name="temp" value="${source}/temp" /> - - <mkdir dir="${temp}" /> - <mkdir dir="${temp}/META-INF" /> - <mkdir dir="${temp}/lib" /> - <mkdir dir="${temp}/lib/pellet" /> - <mkdir dir="${temp}/lib/jena" /> - <copy toDir="${temp}/META-INF" > - <fileset dir="${source}/META-INF" includes="MANIFEST.MF," /> - </copy> - <copy toDir="${temp}/lib" > - <fileset dir="${lib_dir}" includes="junit-4.4.jar" /> + <property name="source" value="src/dl-learner/org/dllearner/tools/protege" /> + <property name="temp" value="${source}/temp" /> + + <mkdir dir="${temp}" /> + <mkdir dir="${temp}/META-INF" /> + <mkdir dir="${temp}/lib" /> + <mkdir dir="${temp}/lib/pellet" /> + <mkdir dir="${temp}/lib/jena" /> + <mkdir dir="${temp}/lib/ore-tools" /> + <copy toDir="${temp}/META-INF" > + <fileset dir="${source}/META-INF" includes="MANIFEST.MF," /> + </copy> + <copy toDir="${temp}/lib/ore-tool" > + <fileset dir="${lib_dir}/ore-tool" includes="swingx-0.9.2.jar" /> + </copy> + <copy toDir="${temp}/lib" > + <fileset dir="${lib_dir}" includes="junit-4.4.jar,jamon-2.7.jar" /> + </copy> + <copy toDir="${temp}/lib/pellet" > + <fileset dir="${lib_dir}/pellet" includes="pellet.jar,aterm-java-1.6.jar,relaxngDatatype.jar,xsdlib.jar" /> + </copy> + <copy toDir="${temp}/lib/jena" > + <fileset dir="${lib_dir}/jena" includes="commons-logging-1.1.1.jar,json.jar" /> + </copy> + <copy toDir="${temp}" > + <fileset dir="${class_dir}" /> </copy> - <copy toDir="${temp}/lib/pellet" > - <fileset dir="${lib_dir}/pellet" includes="pellet.jar,aterm-java-1.6.jar,relaxngDatatype.jar,xsdlib.jar" /> - </copy> - <copy toDir="${temp}/lib/jena" > - <fileset dir="${lib_dir}/jena" includes="commons-logging-1.1.jar" /> - </copy> <copy toDir="${temp}" > - <fileset dir="${class_dir}" /> - </copy> - <copy toDir="${temp}" > - <fileset dir="${source}/META-INF" includes="**/*.xml," excludes="build.xml" /> - </copy> - <javac srcdir="${source}" - destdir="${temp}" - debug="on"> - <classpath refid="classpath"/> - </javac> - <jar destfile="${protege_dir}/dl-learner.jar" manifest="${temp}/META-INF/MANIFEST.MF"> - <fileset dir="${temp}" /> - </jar> - <delete dir="${temp}" /> - - </target> + <fileset dir="${source}/META-INF" includes="**/*.xml," excludes="build.xml" /> + </copy> + <javac srcdir="${source}" + destdir="${temp}" + debug="on"> + <classpath refid="classpath"/> + </javac> + <jar destfile="${protege_dir}/dl-learner.jar" manifest="${temp}/META-INF/MANIFEST.MF"> + <fileset dir="${temp}" /> + </jar> + <delete dir="${temp}" /> + + </target> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hee...@us...> - 2008-08-14 12:08:48
|
Revision: 1071 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1071&view=rev Author: heeroyuy Date: 2008-08-14 12:08:46 +0000 (Thu, 14 Aug 2008) Log Message: ----------- -add new necessary libraries to run the protege plugin Modified Paths: -------------- trunk/lib/protege/org.protege.editor.core.application.jar trunk/lib/protege/org.protege.editor.owl.jar This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <hee...@us...> - 2008-08-14 12:07:47
|
Revision: 1070 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1070&view=rev Author: heeroyuy Date: 2008-08-14 12:07:43 +0000 (Thu, 14 Aug 2008) Log Message: ----------- -added feature to get more details on the selected concept when doubleclick it -small change in detail panel -java doc Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/plugin.xml trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLClassDescriptionEditorWithDLLearnerTab.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLEquivalentClassesAxiomFrameSection.java trunk/src/dl-learner/org/dllearner/tools/protege/OWLSubClassAxiomFrameSection.java trunk/src/dl-learner/org/dllearner/tools/protege/PosAndNegSelectPanel.java trunk/src/dl-learner/org/dllearner/tools/protege/ProtegePlugin.java trunk/src/dl-learner/org/dllearner/tools/protege/SuggestClassPanel.java Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ActionHandler.java 2008-08-14 12:07:43 UTC (rev 1070) @@ -1,92 +1,120 @@ +/** + * Copyright (C) 2007-2008, 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.tools.protege; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.event.ActionEvent; -import java.awt.event.ItemEvent; -import java.awt.event.MouseEvent; +import java.util.Iterator; + +import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.event.ListSelectionEvent; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.owl.Description; +import org.protege.editor.owl.OWLEditorKit; /** + * This class processes input from the user. + * @author Christian Koetteritzsch * - * @author Heero Yuy - * */ -public class ActionHandler implements ActionListener, ItemListener, MouseListener, ListSelectionListener{ - /** - * This is the DLLearnerModel. - */ +public class ActionHandler implements ActionListener, ItemListener, + MouseListener, ListSelectionListener { + + // This is the DLLearnerModel. + private DLLearnerModel model; - /** - * This is the id that checks if the equivalent class or subclass button is - * pressed in protege - */ + private OWLEditorKit editorKit; + + // This is the id that checks if the equivalent class or subclass button is + // pressed in protege private String id; - /** - * this is a boolean that checked if the advanced button was pressed or not. - */ + // this is a boolean that checked if the advanced button was pressed or not. private boolean toggled; - /** - * This is the Tread of the DL-Learner - */ + // This is the Tread of the DL-Learner private Thread dlLearner; - /** - * This is the view of the DL-Learner tab. - */ + private EvaluatedDescription evaluatedDescription; + // This is the view of the DL-Learner tab. private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; + private int counter; + private EvaluatedDescription oldEvaluatedDescription; /** - * This is the constructor for the action handler - * @param a ActionHandler - * @param m DLLearnerModel - * @param view DLlearner tab - * @param i id if it is a subclass oran equivalent class + * This is the constructor for the action handler. + * + * @param a + * ActionHandler + * @param m + * DLLearnerModel + * @param view + * DLlearner tab + * @param i + * id if it is a subclass or an equivalent class + * @param editor OWLEditorKit */ - public ActionHandler(ActionHandler a,DLLearnerModel m,OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view ,String i) - { - this.view = view; - this.id=i; + public ActionHandler(ActionHandler a, DLLearnerModel m, + OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view, + String i, OWLEditorKit editor) { + this.editorKit = editor; + this.view = view; + this.id = i; + counter = 0; this.model = m; toggled = false; - - + } + /** - * + * When a Button is pressed this method select the right. + * @param z ActionEvent */ - public void actionPerformed(ActionEvent z){ - - if(z.getActionCommand().equals("Suggest "+id)) - { - if(model.getAlreadyLearned()==true) - { + public void actionPerformed(ActionEvent z) { + + if (z.getActionCommand().equals("Suggest " + id)) { + if (model.getAlreadyLearned()) { model.unsetListModel(); } - if(view.getPosAndNegSelectPanel().getPosAndNegSelectPanel().getComponentCount()<=2) - { - view.renderErrorMessage("Could not start learning. No Examples where available"); + if (view.getPosAndNegSelectPanel().getPosAndNegSelectPanel() + .getComponentCount() <= 2) { + view + .renderErrorMessage("Could not start learning. No Examples where available"); + } else { + model.setKnowledgeSource(); + model.setReasoner(); + model.setPositiveAndNegativeExamples(); + model.setLearningProblem(); + model.setLearningAlgorithm(); + this.dlLearner = new Thread(model); + dlLearner.start(); + view.getRunButton().setEnabled(false); + view.getCancelButton().setEnabled(true); + view.renderErrorMessage("Learning started"); + view.getPosAndNegSelectPanel().unsetCheckBoxes(); } - else{ - model.setKnowledgeSource(); - model.setReasoner(); - model.setPositiveAndNegativeExamples(); - model.setLearningProblem(); - model.setLearningAlgorithm(); - this.dlLearner = new Thread(model); - dlLearner.start(); - view.getRunButton().setEnabled(false); - view.getCancelButton().setEnabled(true); - view.renderErrorMessage("Learning started"); - view.getPosAndNegSelectPanel().unsetCheckBoxes(); - } } - - if(z.getActionCommand().equals("Cancel")) - { + + if (z.getActionCommand().equals("Cancel")) { view.getRunButton().setEnabled(true); view.getCancelButton().setEnabled(false); String error = "Learning aborted"; @@ -95,96 +123,89 @@ model.getLearningAlgorithm().stop(); model.setErrorMessage(error); } - - if(z.getActionCommand().equals("ADD")) - { - model.changeDLLearnerDescriptionsToOWLDescriptions((Description)view.getSuggestClassPanel().getSuggestList().getSelectedValue()); - String message ="Concept added"; + + if (z.getActionCommand().equals("ADD")) { + if (evaluatedDescription != null) { + model + .changeDLLearnerDescriptionsToOWLDescriptions(evaluatedDescription + .getDescription()); + } else { + model + .changeDLLearnerDescriptionsToOWLDescriptions((Description) view + .getSuggestClassPanel().getSuggestList() + .getSelectedValue()); + } + String message = "Concept added"; view.renderErrorMessage(message); } - - if(z.getActionCommand().equals("?")) - { - if(z.getSource().toString().contains("PosHelpButton")) - { - String hilfe="A Instance that follows from the classdescription.\nPer Default all that belongs to the class."; - view.getPosAndNegSelectPanel().renderHelpMessage(hilfe); + + if (z.getActionCommand().equals("?")) { + if (z.getSource().toString().contains("PosHelpButton")) { + String help = "A Instance that follows from the classdescription.\nPer Default all that belongs to the class."; + view.getPosAndNegSelectPanel().renderHelpMessage(help); } - - if(z.getSource().toString().contains("NegHelpButton")) - { - String hilfe="A Instance tht doesn't follow from the classdescription."; - view.getPosAndNegSelectPanel().renderHelpMessage(hilfe); + + if (z.getSource().toString().contains("NegHelpButton")) { + String help = "A Instance tht doesn't follow from the classdescription."; + view.getPosAndNegSelectPanel().renderHelpMessage(help); } - - + } - if(z.getActionCommand().equals("")) - { - if(!toggled==true) - { - toggled=true; + if (z.getActionCommand().equals("")) { + if (!toggled) { + toggled = true; view.setIconToggled(toggled); view.setExamplePanelVisible(toggled); - } - else - { - toggled=false; + } else { + toggled = false; view.setIconToggled(toggled); view.setExamplePanelVisible(toggled); } } - if(z.getActionCommand().equals("Why")) - { - view.getMoreDetailForSuggestedConceptsPanel().renderDetailPanel((Description)view.getSuggestClassPanel().getSuggestList().getSelectedValue()); + if (z.getActionCommand().equals("Why")) { + view.getMoreDetailForSuggestedConceptsPanel().renderDetailPanel( + evaluatedDescription); } } - - /** + + /** * - * @return + * @return id StringID if it is a Subclass or an equivalent class. */ - public String getID() - { + public String getID() { return id; } + + /** - * + * select/deselect the Check boxes. + * @param i ItemEvent */ - public void itemStateChanged(ItemEvent i) - { - if(i.getItem().toString().contains("Positive")) - { - for(int j = 0;j < model.getPosVector().size(); j++) - { - if(i.getItem().toString().contains(model.getPosVector().get(j).getText().toString())) - { - if(!model.getPosVector().get(j).isSelected()) - { + public void itemStateChanged(ItemEvent i) { + if (i.getItem().toString().contains("Positive")) { + for (int j = 0; j < model.getPosVector().size(); j++) { + if (i.getItem().toString().contains( + model.getPosVector().get(j).getText().toString())) { + if (!model.getPosVector().get(j).isSelected()) { model.getPosVector().get(j).setSelected(true); break; } - if(model.getPosVector().get(j).isSelected()) - { + if (model.getPosVector().get(j).isSelected()) { model.getPosVector().get(j).setSelected(false); break; } } } } - if(i.getItem().toString().contains("Negative")) - { - for(int j = 0;j < model.getNegVector().size(); j++) - { - if(i.getItem().toString().contains(model.getNegVector().get(j).getText().toString())) - { - if(!model.getNegVector().get(j).isSelected()) - { + if (i.getItem().toString().contains("Negative")) { + for (int j = 0; j < model.getNegVector().size(); j++) { + if (i.getItem().toString().contains( + model.getNegVector().get(j).getText().toString())) { + if (!model.getNegVector().get(j).isSelected()) { model.getNegVector().get(j).setSelected(true); break; } - if(model.getNegVector().get(j).isSelected()) - { + if (model.getNegVector().get(j).isSelected()) { model.getNegVector().get(j).setSelected(false); break; } @@ -193,61 +214,101 @@ } } - public void valueChanged(ListSelectionEvent e) - { - - } /** - * + * Nothing happens here. + * @param e ListSelectionEvent */ - public void mouseReleased(MouseEvent m) - { - + public void valueChanged(ListSelectionEvent e) { + } + /** - * + * Nothing happens here. + * @param m MouseEvent */ - public void mouseEntered(MouseEvent m) - { - + public void mouseReleased(MouseEvent m) { + } + + /** + * Nothing happens here. + * @param m MouseEvent + */ + public void mouseEntered(MouseEvent m) { + + } + /** - * + * Choses the right EvaluatedDescription object after a concept is chosen in the list. + * @param m MouseEvent */ - public void mouseClicked(MouseEvent m) - { - + public void mouseClicked(MouseEvent m) { + EvaluatedDescription eDescription = null; + oldEvaluatedDescription = evaluatedDescription; + String desc = view.getSuggestClassPanel().getSuggestList() + .getSelectedValue().toString(); + if (model.getEvaluatedDescriptionList() != null) { + for (Iterator<EvaluatedDescription> i = model + .getEvaluatedDescriptionList().iterator(); i.hasNext();) { + eDescription = i.next(); + if (desc.equals(eDescription.getDescription() + .toManchesterSyntaxString( + editorKit.getOWLModelManager() + .getActiveOntology().getURI() + + "#", null))) { + evaluatedDescription = eDescription; + break; + } + + } + } + System.out.println("old: " + oldEvaluatedDescription); + if (oldEvaluatedDescription != null) { + + if (oldEvaluatedDescription != evaluatedDescription) { + counter = 0; + } + counter++; + } else { + counter++; + } + if (counter == 2) { + counter = 0; + view.getMoreDetailForSuggestedConceptsPanel().renderDetailPanel( + evaluatedDescription); + } + System.out.println("Counter: " + counter); } + /** - * + * Nothing happens here. + * @param m MouseEvent */ - public void mouseExited(MouseEvent m) - { - + public void mouseExited(MouseEvent m) { + } + /** - * + * Sets the ADD button enable after a concept is chosen. + * @param m MouseEvent */ - public void mousePressed(MouseEvent m) - { - if(!view.getAddButton().isEnabled()) - { + public void mousePressed(MouseEvent m) { + if (!view.getAddButton().isEnabled()) { view.getAddButton().setEnabled(true); } } /** - * + * Destroys the Thread after the Pluigin is closed. */ - public void destroyDLLearnerThread() - { - dlLearner =null; + public void destroyDLLearnerThread() { + dlLearner = null; } + /** - * + * Resets the toggled Button after the plugin is closed. */ - public void resetToggled() - { + public void resetToggled() { toggled = false; } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/ButtonList.java 2008-08-14 12:07:43 UTC (rev 1070) @@ -1,3 +1,22 @@ +/** + * Copyright (C) 2007-2008, 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.tools.protege; import org.protege.editor.owl.ui.frame.AbstractOWLFrame; @@ -7,15 +26,32 @@ import org.semanticweb.owl.model.OWLClass; import org.protege.editor.owl.OWLEditorKit; -public class ButtonList extends AbstractOWLFrame<OWLClass>{ - - public ButtonList(OWLEditorKit editorKit) - { +/** + * This class manages the list of the lists for equivalent classes and so on. + * This is necessary to implement the dllearner plugin in the + * OWLClassDescriptionEditor. + * + * @author Christian Koetteritzsch + * + */ +public class ButtonList extends AbstractOWLFrame<OWLClass> { + /** + * Construktor of the Buttonlist. + * + * @param editorKit EditorKit from Protege + */ + public ButtonList(OWLEditorKit editorKit) { super(editorKit.getOWLModelManager().getOWLOntologyManager()); - addSection(new OWLEquivalentClassesAxiomFrameSection(editorKit, this)); - addSection(new OWLSubClassAxiomFrameSection(editorKit, this)); - addSection(new InheritedAnonymousClassesFrameSection(editorKit, this)); - addSection(new OWLClassAssertionAxiomIndividualSection(editorKit, this)); - addSection(new OWLDisjointClassesAxiomFrameSection(editorKit, this)); + // own OWLEquivalentClassesAxiomFrameSection to add the dllearner plugin + // to the + // OWLClassDescritpionEditor + addSection(new OWLEquivalentClassesAxiomFrameSection(editorKit, this)); + // own OWLEquivalentClassesAxiomFrameSection to add the dllearner plugin + // to the + // OWLClassDescritpionEditor + addSection(new OWLSubClassAxiomFrameSection(editorKit, this)); + addSection(new InheritedAnonymousClassesFrameSection(editorKit, this)); + addSection(new OWLClassAssertionAxiomIndividualSection(editorKit, this)); + addSection(new OWLDisjointClassesAxiomFrameSection(editorKit, this)); } } Modified: trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/DLLearnerModel.java 2008-08-14 12:07:43 UTC (rev 1070) @@ -1,197 +1,232 @@ +/** + * Copyright (C) 2007-2008, 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.tools.protege; +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Set; +import java.util.SortedSet; import java.util.TreeSet; -import java.util.List; import java.util.Vector; -import java.util.HashSet; -import java.util.Iterator; -import java.util.SortedSet; import javax.swing.DefaultListModel; import javax.swing.JCheckBox; -import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.algorithms.SimpleSuggestionLearningAlgorithm; - -import org.dllearner.core.owl.Description; +import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.ReasoningService; - +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; - import org.dllearner.kb.OWLAPIOntology; - +import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; -import org.dllearner.learningproblems.PosNegDefinitionLP; - import org.dllearner.reasoning.OWLAPIDescriptionConvertVisitor; import org.dllearner.reasoning.OWLAPIReasoner; - +import org.jdesktop.swingx.JXTaskPane; import org.protege.editor.owl.OWLEditorKit; import org.protege.editor.owl.ui.frame.OWLFrame; - import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.AddAxiom; import org.semanticweb.owl.model.OWLAxiom; +import org.semanticweb.owl.model.OWLClass; import org.semanticweb.owl.model.OWLDataFactory; +import org.semanticweb.owl.model.OWLDescription; import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyChangeException; import org.semanticweb.owl.model.OWLOntologyManager; -import org.semanticweb.owl.model.OWLDescription; +/** + * This Class provides the necessary methods to learn Concepts from the + * DL-Learner. + * + * @author Christian Koetteritzsch + * + */ +public class DLLearnerModel implements Runnable { + // The Sting is for components that are available in the DL-Learner + private String[] componenten = { "org.dllearner.kb.OWLFile", + "org.dllearner.reasoning.OWLAPIReasoner", + "org.dllearner.reasoning.DIGReasoner", + "org.dllearner.reasoning.FastRetrievalReasoner", + "org.dllearner.learningproblems.PosNegInclusionLP", + "org.dllearner.learningproblems.PosNegDefinitionLP", + "org.dllearner.algorithms.RandomGuesser", + "org.dllearner.algorithms.BruteForceLearner", + "org.dllearner.algorithms.refinement.ROLearner", + "org.dllearner.algorithms.refexamples.ExampleBasedROLComponent", + "org.dllearner.algorithms.gp.GP" }; + // This Vector stores the check boxes for the view. -/**2 - * This Class provides the necessary methods to learn Concepts from the DL-Learner. - * @author Heero Yuy - * - */ -public class DLLearnerModel implements Runnable{ - /** - * The Sting is for components that are available in the DL-Learner - */ - private String[] componenten={"org.dllearner.kb.OWLFile","org.dllearner.reasoning.OWLAPIReasoner", - "org.dllearner.reasoning.DIGReasoner","org.dllearner.reasoning.FastRetrievalReasoner","org.dllearner.learningproblems.PosNegInclusionLP" - ,"org.dllearner.learningproblems.PosNegDefinitionLP","org.dllearner.algorithms.RandomGuesser","org.dllearner.algorithms.BruteForceLearner","org.dllearner.algorithms.refinement.ROLearner","org.dllearner.algorithms.refexamples.ExampleBasedROLComponent","org.dllearner.algorithms.gp.GP"}; - /** - * This Vector stores the check boxes for the view. - */ private Vector<JCheckBox> positiv; - /** - * This Vector stores the negative Examples. - */ + + // This Vector stores the negative Examples. + private Vector<JCheckBox> negativ; - /** - * - */ + + // Component Manager that manages the components of the DL-Learner + private ComponentManager cm; - /** - * - */ + + // The Reasoning Service for the Reasoner + private ReasoningService rs; - /** - * - */ + + // The Knowledge source for the reasoner + private KnowledgeSource source; - /** - * - */ + + // The View of the DL-Learner Plugin + private OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view; - /** - * This is the count of Concepts which you get after learning - */ - private static final int anzahl = 6; - /** - * - */ + + // This is the count of Concepts which you get after learning + + private static final int ANZAHL = 6; + + // A Array of Concepts which the DL-Learner suggested + private Description[] description; - /** - * - */ + + // The Learning problem that is used to learn new concepts + private LearningProblem lp; - /** - * This boolean is - */ - private boolean alreadyLearned=false; - /** - * - */ + + // This boolean is for clearing the suggest Panel + + private boolean alreadyLearned = false; + + // The Ontology which is currently used + private OWLOntology ontology; - /** - * This is the learning algorithm - */ + + // This is the learning algorithm + private LearningAlgorithm la = null; - /** - * - */ + + // Necessary to get the currently loaded Ontology + private OWLEditorKit editor; - /** - * - */ - private OWLFrame<OWLClass> aktuell; - /** - * - */ + + // Necessary to get the BaseUri of the currently loaded Ontology + + private OWLFrame<OWLClass> current; + + // The Reasoner which is used to learn + private OWLAPIReasoner reasoner; - /** - * - */ - private Set<OWLDescription> OWLDescription; - /** - * This set stores the positive examples. - */ + + // A Set of Descriptions in OWL Syntax which the DL-Learner suggested + + private Set<OWLDescription> owlDescription; + + // This set stores the positive examples. + private Set<String> positiveExamples; - /** - * This set stores the negative examples that doesn't belong to the concept. - */ + + // This set stores the negative examples that doesn't belong to the concept. + private Set<String> negativeExamples; - /** - * - */ + + // The most fitting Description in OWL Syntax which the DL-Learner suggested + private OWLDescription desc; - /** - * - */ + + // String to distinguish between Equivalent classes and sub classes + private String id; - /** - * - */ + + // The new Concept which is learned by the DL-Learner + private OWLDescription newConceptOWLAPI; - /** - * - */ + + // The old concept that is chosen in Protege + private OWLDescription oldConceptOWLAPI; - /** - * - */ + + // A Set of Descriptions in OWL Syntax which the DL-Learner suggested + private Set<OWLDescription> ds; - /** - * - */ + + // The model for the suggested Descriptions + private DefaultListModel suggestModel; - /** - * - */ + + // The Individuals of the Ontology + private Set<Individual> individual; - /** - * - */ + + // This is a simple learning algorithm to get the first concepts before + // learning + private SimpleSuggestionLearningAlgorithm test; - /** - * - */ + + // The error message which is rendered when an error occured + private String error; - /** - * - */ + + // This is the new axiom which will be added to the Ontology + private OWLAxiom axiomOWLAPI; - + + // This is necessary to get the details of the suggested concept + + private JXTaskPane detailPane; + + // This is a List of evaluated descriptions to get more information of the + // suggested concept private List<EvaluatedDescription> evalDescription; + /** - * This is the constructor for DL-Learner model + * This is the constructor for DL-Learner model. + * * @param editorKit + * Editor Kit to get the currently loaded Ontology * @param h - * @param id String if it learns a subclass or a superclass. - * @param view current view of the DL-Learner tab + * OWLFrame(OWLClass) to get the base uri of the Ontology + * @param id + * String if it learns a subclass or a superclass. + * @param view + * current view of the DL-Learner tab */ - public DLLearnerModel(OWLEditorKit editorKit, OWLFrame<OWLClass> h,String id,OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view) - { - editor=editorKit; - aktuell=h; - this.id=id; - this.view=view; - OWLDescription = new HashSet<OWLDescription>(); + public DLLearnerModel(OWLEditorKit editorKit, OWLFrame<OWLClass> h, + String id, + OWLClassDescriptionEditorWithDLLearnerTab.DLLearnerView view) { + editor = editorKit; + current = h; + this.id = id; + this.view = view; + owlDescription = new HashSet<OWLDescription>(); positiv = new Vector<JCheckBox>(); negativ = new Vector<JCheckBox>(); test = new SimpleSuggestionLearningAlgorithm(); @@ -199,522 +234,560 @@ cm = ComponentManager.getInstance(); ds = new HashSet<OWLDescription>(); suggestModel = new DefaultListModel(); - + detailPane = new JXTaskPane(); + detailPane.setTitle("Details"); + } - + /** - * This method initializes the SimpleSuggestionLearningAlgorithm and adds the - * suggestions to the suggest panel model. + * This method initializes the SimpleSuggestionLearningAlgorithm and adds + * the suggestions to the suggest panel model. */ - public void initReasoner() - { + public void initReasoner() { alreadyLearned = false; setKnowledgeSource(); setReasoner(); - SortedSet<Individual> pos=rs.getIndividuals(); - Set<Description> desc = test.getSimpleSuggestions(rs, pos); + SortedSet<Individual> pos = rs.getIndividuals(); + Set<Description> descri = test.getSimpleSuggestions(rs, pos); int i = 0; - for(Iterator<Description> j = desc.iterator();j.hasNext();) - { - suggestModel.add(i,j.next()); + for (Iterator<Description> j = descri.iterator(); j.hasNext();) { + suggestModel.add(i, j.next()); } + // suggestModel.add(0,test.getCurrentlyBestEvaluatedDescription(). + // getDescription + // ().toManchesterSyntaxString(editor.getOWLModelManager(). + // getActiveOntology().getURI().toString()+"#", null)); } - + /** - * This method adds the solutions from the DL-Learner to the - * model for the + * This method adds the solutions from the DL-Learner to the List Model. */ - private void addToListModel() - { - evalDescription = la.getCurrentlyBestEvaluatedDescriptions(anzahl); - System.out.println("Size: "+la.getCurrentlyBestDescriptions().size()); - for(int j = 0;j<la.getCurrentlyBestEvaluatedDescriptions(anzahl).size();j++) - { - suggestModel.add(j,la.getCurrentlyBestEvaluatedDescriptions(anzahl).get(j).getDescription()); + private void addToListModel() { + evalDescription = la.getCurrentlyBestEvaluatedDescriptions(ANZAHL); + for (int j = 0; j < la.getCurrentlyBestEvaluatedDescriptions(ANZAHL).size(); j++) { + suggestModel.add(j, la + .getCurrentlyBestEvaluatedDescriptions(ANZAHL).get(j) + .getDescription().toManchesterSyntaxString( + editor.getOWLModelManager().getActiveOntology() + .getURI().toString() + + "#", null)); } } - + /** - * This method checks which positive and negative examples are checked - * and puts the checked examples into a tree set. + * This method checks which positive and negative examples are checked and + * puts the checked examples into a tree set. */ - public void setPositiveAndNegativeExamples() - { + public void setPositiveAndNegativeExamples() { positiveExamples = new TreeSet<String>(); negativeExamples = new TreeSet<String>(); - for(int i=0;i<positiv.size();i++) - { - if(positiv.get(i).isSelected()) - { + for (int i = 0; i < positiv.size(); i++) { + if (positiv.get(i).isSelected()) { positiveExamples.add(positiv.get(i).getText()); } - - if(negativ.get(i).isSelected()) - { + + if (negativ.get(i).isSelected()) { negativeExamples.add(negativ.get(i).getText()); } } } - + /** * This method returns the data for the suggest panel. + * * @return Model for the suggest panel. */ - public DefaultListModel getSuggestList() - { + public DefaultListModel getSuggestList() { return suggestModel; } - + /** * This method returns an array of descriptions learned by the DL-Learner. + * * @return Array of descriptions learned by the DL-Learner. */ - public Description[] getDescriptions() - { + public Description[] getDescriptions() { return description; } - public List<EvaluatedDescription> getEvaluatedDescriptionList() - { + + /** + * This Method returns a List of evaluated descriptions suggested by the + * DL-Learner. + * + * @return list of evaluated descriptions + */ + public List<EvaluatedDescription> getEvaluatedDescriptionList() { return evalDescription; } + /** - * This method sets the knowledge source for the learning process. - * Only OWLAPIOntology will be available. + * This method sets the knowledge source for the learning process. Only + * OWLAPIOntology will be available. */ - public void setKnowledgeSource() - { - this.source = new OWLAPIOntology(editor.getOWLModelManager().getActiveOntology()); + public void setKnowledgeSource() { + this.source = new OWLAPIOntology(editor.getOWLModelManager() + .getActiveOntology()); } - + /** - * This method sets the reasoner and the reasoning service - * Only OWLAPIReasoner is available. + * This method sets the reasoner and the reasoning service Only + * OWLAPIReasoner is available. */ - public void setReasoner() - { - this.reasoner =cm.reasoner(OWLAPIReasoner.class,source); + public void setReasoner() { + this.reasoner = cm.reasoner(OWLAPIReasoner.class, source); try { reasoner.init(); } catch (ComponentInitException e) { // TODO Auto-generated catch block + System.out.println("fehler!!!!!!!!!"); e.printStackTrace(); } rs = cm.reasoningService(reasoner); } - + /** * This method sets the Learning problem for the learning process. - * PosNegDefinitonLp for equivalent classes and - * PosNegInclusionLP for super classes. + * PosNegDefinitonLp for equivalent classes and PosNegInclusionLP for super + * classes. */ - public void setLearningProblem() - { - if(id.equals("Equivalent classes")) - { + public void setLearningProblem() { + if (id.equals("Equivalent classes")) { + // sets the learning problem to PosNegDefinitionLP when the + // dllearner should suggest an equivalent class lp = cm.learningProblem(PosNegDefinitionLP.class, rs); } - if(id.equals("Superclasses")) - { + if (id.equals("Superclasses")) { + // sets the learning problem to PosNegInclusionLP when the dllearner + // should suggest a subclass lp = cm.learningProblem(PosNegInclusionLP.class, rs); } - + // adds the positive examples cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); + // adds the neagtive examples cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); - try{ - lp.init(); - } - catch(ComponentInitException e) - { + try { + lp.init(); + } catch (ComponentInitException e) { e.printStackTrace(); } } - + /** * This method sets the learning algorithm for the learning process. */ - public void setLearningAlgorithm() - { + public void setLearningAlgorithm() { try { - this.la = cm.learningAlgorithm(ROLearner.class, lp, rs); + // sets the learning algorithm to ROlearner + this.la = cm.learningAlgorithm(ExampleBasedROLComponent.class, lp, + rs); } catch (LearningProblemUnsupportedException e) { // TODO Auto-generated catch block e.printStackTrace(); } cm.applyConfigEntry(la, "numberOfTrees", 100); cm.applyConfigEntry(la, "maxDepth", 5); - try{ + try { + // initializes the learning algorithm la.init(); - } - catch(ComponentInitException e){ - e.printStackTrace(); - } - alreadyLearned = true; + } catch (ComponentInitException e) { + e.printStackTrace(); + } + alreadyLearned = true; } /** * This method starts the learning process. */ - public void run() - { + public void run() { error = "Learning succesful"; // start the algorithm and print the best concept found la.start(); - description = new Description[la.getCurrentlyBestEvaluatedDescriptions(anzahl).size()]; + description = new Description[la.getCurrentlyBestEvaluatedDescriptions( + ANZAHL).size()]; addToListModel(); - System.out.println(la.getCurrentlyBestEvaluatedDescriptions()); + // renders the errormessage view.renderErrorMessage(error); + // reenables the run button view.getRunButton().setEnabled(true); + // disables the cancel button view.getCancelButton().setEnabled(false); view.getSuggestClassPanel().setSuggestList(suggestModel); } - + /** - * This method returns the Concepts from the DL-Learner. - * @return Array of learned Concepts. + * This method returns the Concepts from the DL-Learner. + * + * @return Array of learned Concepts. */ - public Description[] getSolutions() - { + public Description[] getSolutions() { return description; } - + /** * This method returns the check boxes for the positive examples. + * * @return Vector of check boxes for positive examples */ - public Vector<JCheckBox> getPosVector() - { + public Vector<JCheckBox> getPosVector() { return positiv; } - + /** * This method returns the check boxes for the negative examples. + * * @return Vector of check boxes for negative examples */ - public Vector<JCheckBox> getNegVector() - { + public Vector<JCheckBox> getNegVector() { return negativ; } - + /** * This method gets an error message and storess it. - * @param error error message + * + * @param err + * error message */ - public void setErrorMessage(String error) - { - this.error = error; + public void setErrorMessage(String err) { + this.error = err; } - + /** - * This method sets the check boxes for the positive check boxes checked - * if the individuals matches the concept that is chosen in protege. + * This method sets the check boxes for the positive check boxes checked if + * the individuals matches the concept that is chosen in protege. */ - public void setPosVector() - { + public void setPosVector() { setPositiveConcept(); - for(Iterator<Individual> j = rs.getIndividuals().iterator(); j.hasNext();) - { + for (Iterator<Individual> j = rs.getIndividuals().iterator(); j + .hasNext();) { String ind = j.next().toString(); - if(setPositivExamplesChecked(ind)) - { - JCheckBox box = new JCheckBox(ind.toString(),true); + // checks if individual belongs to the selected concept + if (setPositivExamplesChecked(ind)) { + // when yes then it sets the positive example checked + JCheckBox box = new JCheckBox(ind.toString(), true); box.setName("Positive"); positiv.add(box); - - } - else - { - JCheckBox box = new JCheckBox(ind.toString(),false); + // and ne genative examples unchecked + JCheckBox box2 = new JCheckBox(ind.toString(), false); + box.setName("Negative"); + negativ.add(box2); + + } else { + // When no it unchecks the positive example + JCheckBox box = new JCheckBox(ind.toString(), false); box.setName("Positive"); positiv.add(box); + // and checks the negative example + JCheckBox box2 = new JCheckBox(ind.toString(), true); + box.setName("Negative"); + negativ.add(box2); } - JCheckBox box = new JCheckBox(ind.toString(),false); - box.setName("Negative"); - negativ.add(box); } } /** * This method resets the Concepts that are learned. */ - public void unsetNewConcepts() - { - while(OWLDescription.iterator().hasNext()) - { - OWLDescription.remove(OWLDescription.iterator().next()); + public void unsetNewConcepts() { + while (owlDescription.iterator().hasNext()) { + owlDescription.remove(owlDescription.iterator().next()); } } - + /** - * This method sets the individuals that belong to the concept which is chosen in protege. + * This method sets the individuals that belong to the concept which is + * chosen in protege. */ - public void setPositiveConcept() - { + public void setPositiveConcept() { SortedSet<Individual> individuals = null; - if(!aktuell.getRootObject().toString().equals("Thing")) - { - for(Iterator<NamedClass> i = rs.getNamedClasses().iterator(); i.hasNext();) - { - if(individuals==null) - { + // checks if selected concept is thing when yes then it selects all + // individuals + if (!current.getRootObject().toString().equals("Thing")) { + + for (Iterator<NamedClass> i = rs.getNamedClasses().iterator(); i + .hasNext();) { + // if individuals is null + if (individuals == null) { NamedClass concept = i.next(); - if(concept.toString().endsWith("#"+aktuell.getRootObject().toString())) - { - if(rs.retrieval(concept)!=null) - { + // checks if the concept is the selected concept in protege + if (concept.toString().endsWith( + "#" + current.getRootObject().toString())) { + // if individuals is not null it gets all individuals of + // the concept + if (rs.retrieval(concept) != null) { individual = rs.retrieval(concept); break; - } + } } } } - } - else - { + } else { individual = rs.getIndividuals(); } } - + /** - * This method gets an Individual and checks if this individual belongs to the concept - * chosen in protege. - * @param indi Individual to check if it belongs to the chosen concept + * This method gets an Individual and checks if this individual belongs to + * the concept chosen in protege. + * + * @param indi + * Individual to check if it belongs to the chosen concept * @return is Individual belongs to the concept which is chosen in protege. */ - public boolean setPositivExamplesChecked(String indi) - { - boolean isChecked = false; - if(individual != null) - { - if(individual.toString().contains(indi)) - { - isChecked = true; - } + public boolean setPositivExamplesChecked(String indi) { + boolean isChecked = false; + // checks if individuals are not empty + if (individual != null) { + // checks if the delivered individual belongs to the individuals of + // the selected concept + if (individual.toString().contains(indi)) { + isChecked = true; } - return isChecked; - + } + return isChecked; + } /** - * This method resets the vectors where the check boxes for positive and negative Examples - * are stored. It is called when the DL-Learner View is closed. + * This method resets the vectors where the check boxes for positive and + * negative Examples are stored. It is called when the DL-Learner View is + * closed. */ - public void clearVector() - { + public void clearVector() { positiv.removeAllElements(); negativ.removeAllElements(); } - + /** * This method gets an array of concepts from the DL-Learner and stores it * in the description array. - * @param list Array of concepts from DL-Learner + * + * @param list + * Array of concepts from DL-Learner */ - public void setDescriptionList(Description[] list) - { - description=list; + public void setDescriptionList(Description[] list) { + description = list; } - + /** - * This method returns the current learning algorithm that is used to learn new concepts. + * This method returns the current learning algorithm that is used to learn + * new concepts. + * * @return Learning algorithm that is used for learning concepts. */ - public LearningAlgorithm getLearningAlgorithm() - { + public LearningAlgorithm getLearningAlgorithm() { return la; } - + /** - * This method gets an integer to return the positive examples check box on that position. - * @param i integer for the position in the vector + * This method gets an integer to return the positive examples check box on + * that position. + * + * @param i + * integer for the position in the vector * @return Positive examples check box on position i. */ - public JCheckBox getPositivJCheckBox(int i) - { + public JCheckBox getPositivJCheckBox(int i) { return positiv.get(i); } - + /** - * This method gets an integer to return the negative examples check box on that position. - * @param i integer for the position in the vector + * This method gets an integer to return the negative examples check box on + * that position. + * + * @param i + * integer for the position in the vector * @return Negative examples check box on position i. */ - public JCheckBox getNegativJCheckBox(int i) - { + public JCheckBox getNegativJCheckBox(int i) { return negativ.get(i); } - + /** - * This method resets the array of concepts from the DL_Learner. - * It is called after the DL-Learner tab is closed. + * This method resets the array of concepts from the DL_Learner. It is + * called after the DL-Learner tab is closed. */ - public void resetSuggestionList() - { - for(int i=0;i<description.length;i++) - { - description[i]=null; + public void resetSuggestionList() { + for (int i = 0; i < description.length; i++) { + description[i] = null; } } - + /** - * This method unchecks the checkboxes that are checked after the process - * of learning. + * This method unchecks the checkboxes that are checked after the process of + * learning. */ - public void unsetJCheckBoxen() - { - for(int j=0;j<positiv.size();j++) - { - if(positiv.get(j).isSelected()) - { - JCheckBox i = positiv.get(j); - i.setSelected(false); - positiv.set(j, i); - } - if(negativ.get(j).isSelected()) - { - JCheckBox i = negativ.get(j); - i.setSelected(false); - negativ.set(j, i); - } - } + public void unsetJCheckBoxen() { + for (int j = 0; j < positiv.size(); j++) { + // unselect all check poxes of the positive examples + if (positiv.get(j).isSelected()) { + JCheckBox i = positiv.get(j); + i.setSelected(false); + positiv.set(j, i); + } + // unselect all check boxes of the negative examples + if (negativ.get(j).isSelected()) { + JCheckBox i = negativ.get(j); + i.setSelected(false); + negativ.set(j, i); + } + } } /** - * This method resets the model for the suggest panel. - * It is called befor the DL-Learner learns the second time or when the - * DL-Learner tab is closed. + * This method resets the model for the suggest panel. It is called befor + * the DL-Learner learns the second time or when the DL-Learner tab is + * closed. */ - public void unsetListModel() - { - if(suggestModel!=null) - { + public void unsetListModel() { + if (suggestModel != null) { suggestModel.removeAllElements(); } } /** - * This method gets a description from the DL-Learner and adds is to the model from the suggest panel. - * @param desc Description from the DL-Learner + * This method gets a description from the DL-Learner and adds is to the + * model from the suggest panel. + * + * @param descript + * Description from the DL-Learner */ - public void setSuggestModel(Description desc) - { - suggestModel.add(0, desc); + public void setSuggestModel(Description descript) { + suggestModel.add(0, descript); } - + /** * This method returns the current OWLOntology that is loaded in protege. + * * @return current ontology */ - public OWLOntology getOWLOntology() - { + public OWLOntology getOWLOntology() { return ontology; } - + /** * This method returns a set of concepts that are learned by the DL-Learner. - * They are already converted into the OWLDescription format. + * They are already converted into the OWLDescription format. + * * @return Set of learned concepts in OWLDescription format */ - public Set<OWLDescription> getNewOWLDescription() - { - return OWLDescription; + public Set<OWLDescription> getNewOWLDescription() { + return owlDescription; } - + /** - * This method returns the old concept which is chosen in protege in OWLDescription format. + * This method returns the old concept which is chosen in protege in + * OWLDescription format. + * * @return Old Concept in OWLDescription format. */ - public OWLDescription getOldConceptOWLAPI() - { + public OWLDescription getOldConceptOWLAPI() { return oldConceptOWLAPI; } - + /** - * This method returns the currently learned description in OWLDescription format. + * This method returns the currently learned description in OWLDescription + * format. + * * @return currently used description in OWLDescription format */ - public OWLDescription getSolution() - { + public OWLDescription getSolution() { return desc; } - + /** * This method gets a description learned by the DL-Learner an converts it * to the OWLDescription format. - * @param desc Description learned by the DL-Learner + * + * @param desc + * Description learned by the DL-Learner */ - public void setNewConceptOWLAPI(Description desc) - { - newConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(desc); + private void setNewConceptOWLAPI(Description des) { + // converts DL-Learner description into an OWL API Description + newConceptOWLAPI = OWLAPIDescriptionConvertVisitor + .getOWLDescription(des); ds.add(newConceptOWLAPI); - OWLDescription.add(newConceptOWLAPI); + owlDescription.add(newConceptOWLAPI); this.desc = newConceptOWLAPI; } - + /** * This method gets the old concept from checking the positive examples. */ - public void setOldConceptOWLAPI() - { - SortedSet<Individual> indi=rs.getIndividuals(); - for(Iterator<Individual> i = indi.iterator(); i.hasNext();) - { + private void setOldConceptOWLAPI() { + // gets all individuals + SortedSet<Individual> indi = rs.getIndividuals(); + // Iterator of Individuals + for (Iterator<Individual> i = indi.iterator(); i.hasNext();) { Individual indi2 = i.next(); - if(positiveExamples.toString().contains(indi2.toString())) - { - Set<NamedClass> concept=reasoner.getConcepts(indi2); - for(Iterator<NamedClass> k = concept.iterator();k.hasNext();) - { - OWLDescription oldConceptOWLAPI = OWLAPIDescriptionConvertVisitor.getOWLDescription(k.next()); - ds.add(oldConceptOWLAPI); + // checks if the current individual belongs to positive examples + if (positiveExamples != null) { + if (positiveExamples.toString().contains(indi2.toString())) { + // if yes then get the concepts of this individuals + Set<NamedClass> concept = reasoner.getConcepts(indi2); + // adds all concepts to old concept OWLAPI + for (Iterator<NamedClass> k = concept.iterator(); k + .hasNext();) { + OWLDescription oldOWLAPI = OWLAPIDescriptionConvertVisitor + .getOWLDescription(k.next()); + ds.add(oldOWLAPI); + } + } - } } } - + /** - * This method stores the new concept learned by the DL-Learner in the Ontology. - * @param desc Description learn by the DL-Learner + * This method stores the new concept learned by the DL-Learner in the + * Ontology. + * + * @param descript + * Description learn by the DL-Learner */ - public void changeDLLearnerDescriptionsToOWLDescriptions(Description desc) - { - setNewConceptOWLAPI(desc); + public void changeDLLearnerDescriptionsToOWLDescriptions(Description descript) { + setNewConceptOWLAPI(descript); setOldConceptOWLAPI(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - + OWLDataFactory factory = manager.getOWLDataFactory(); - - axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); - - OWLOntology ontology = editor.getOWLModelManager().getActiveOntology(); - AddAxiom axiom = new AddAxiom(ontology, axiomOWLAPI); - System.out.println("axiom: "+axiomOWLAPI); + if (id.equals("Equivalent classes")) { + axiomOWLAPI = factory.getOWLEquivalentClassesAxiom(ds); + } else { + axiomOWLAPI = factory.getOWLSubClassAxiom(oldConceptOWLAPI, + newConceptOWLAPI); + } + OWLOntology onto = editor.getOWLModelManager().getActiveOntology(); + AddAxiom axiom = new AddAxiom(onto, axiomOWLAPI); try { + // adds the new concept to the ontology manager.applyChange(axiom); } catch (OWLOntologyChangeException e) { // TODO Auto-generated catch block e.printStackTrace(); - } - } - + + } + /** * This method returns the currently used reasoning service. + * * @return current reasoning service */ - public ReasoningService getReasoningService() - { + public ReasoningService getReasoningService() { return rs; } - + /** - * This method gets the status if the DL-Learner has already learned. - * It is only for reseting the suggest panel. + * This method gets the status if the DL-Learner has already learned. It is + * only for reseting the suggest panel. + * * @return boolean if the learner has already learned */ - public boolean getAlreadyLearned() - { + public boolean getAlreadyLearned() { return alreadyLearned; - } - -} \ No newline at end of file + } + + public URI getURI() { + return editor.getOWLModelManager().getActiveOntology().getURI(); + } +} Modified: trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/MANIFEST.MF 2008-08-14 12:07:43 UTC (rev 1070) @@ -1,12 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Hallo Welt +Bundle-Name: DL-Learner Plugin Bundle-SymbolicName: org.dllearner.tools.protege;singleton:=true Bundle-Category: protege Bundle-Description: blablabla Bundle-Vendor: blablabla Bundle-DocURL: blablabla -Bundle-ClassPath: .,lib/junit-4.4.jar,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/jena/json.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.jar +Bundle-ClassPath: .,lib/junit-4.4.jar,lib/jamon-2.7.jar,lib/pellet/pellet.jar,lib/pellet/aterm-java-1.6.jar,lib/jena/json.jar,lib/pellet/relaxngDatatype.jar,lib/pellet/xsdlib.jar,lib/jena/commons-logging-1.1.1.jar,lib/ore-tool/swingx-0.9.2.jar Import-Package: org.osgi.framework,org.apache.log4j Export-Package: lib Bundle-Version: 1.0.0 Modified: trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/plugin.xml =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/plugin.xml 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/META-INF/plugin.xml 2008-08-14 12:07:43 UTC (rev 1070) @@ -2,7 +2,7 @@ <plugin> <extension id="org.dllearner.tools.protege.ProtegePlugin" point="org.protege.editor.core.application.ViewComponent"> - <label value="Hallo Welt"/> + <label value="DL-Learner Plugin"/> <class value="org.dllearner.tools.protege.ProtegePlugin"/> <headerColor value="@org.protege.classcolor"/> <category value="@org.protege.classcategory"/> Modified: trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2008-08-14 09:50:45 UTC (rev 1069) +++ trunk/src/dl-learner/org/dllearner/tools/protege/MoreDetailForSuggestedConceptsPanel.java 2008-08-14 12:07:43 UTC (rev 1070) @@ -1,161 +1,209 @@ +/** + * Copyright (C) 2007-2008, 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.tools.protege; +import java.awt.GridLayout; +import java.awt.Color; + import java.util.Iterator; -import java.util.List; +import javax.swing.JDialog; +import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JLabel; +import javax.swing.JScrollPane; import javax.swing.JTextArea; -import javax.swing.JScrollPane; -import javax.swing.JDialog; import javax.swing.WindowConstants; -import java.awt.GridLayout; - import org.dllearner.core.EvaluatedDescription; -import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; -public class MoreDetailForSuggestedConceptsPanel extends JPanel{ +/** + * This class shows more details of the suggested concepts. It shows the positive and negative examples + * that are covered and that are not covered by the suggested concepts. It also shows the accuracya of the + * selected concept. + * @author Christian Koetteritzsch + * + */ +public class MoreDetailForSuggestedConceptsPanel extends JPanel { private static final long serialVersionUID = 785272797932584581L; - + + // Model of the dllearner + private DLLearnerModel model; + // Textarea to render the accuracy of the concept + private JTextArea accuracy; - private JPanel accuracyPanel; + // Label for the positive examples that are covered by the concept + private JLabel coveredPositiveExamples; + + // Label for the negative examples that are covered by the concept + private JLabel coveredNegativeExamples; + + // Label for the positive examples that are not covered by the concept + private JLabel notCoveredPositiveExamples; + + // Label for the negative examples that are not covered by the concept + private JLabel notCoveredNegativeExamples; + + // Pop up panel for the informations of the selected concept + private JDialog detailPopup; + + // Panel where the informations of the selected panel are rendered + private JPanel examplePanel; + + // Text area that shows the covered positive examples + private JTextArea posCoveredText; + + // Text area that shows the positive examples that are not covered by the selected concept + private JTextArea posNotCoveredText; + + // Text area that shows the covered negative examples + private JTextArea negCoveredText; + + // Text area that shows the negative examples that are not covered by the selected concept + private JTextArea negNotCoveredText; + + // Text area that shows the accurcy of the selected concept + private JTextArea accuracyText; + + // Scroll pane if scroll bar is necessary to show all covered examples + private JScrollPane detailScroll; - private JPanel detailPanel; - - public MoreDetailForSuggestedConceptsPanel(DLLearnerModel model) - { + // Evaluated description of the selected concept + + private EvaluatedDescription eval; + private final Color colorRed = Color.red; + private final Color colorGreen = Color.green; + /** + * This is the constructor for the Panel. + * @param model DLLearnerModel + */ + public MoreDetailForSuggestedConceptsPanel(DLLearnerModel model) { this.model = model; } - - public JDialog getMoreDialog() - { + /** + * This method returns the Detail Panel. + * @return DetailPanel + */ + public JDialog getMoreDialog() { return detailPopup; } - public JScrollPane getDetailScrollPane() - { - return detailScroll; - } - private EvaluatedDescription getSelectedConcept(Description eval) - { - List<EvaluatedDescription> evalDesc = model.getEvaluatedDescriptionList(); - EvaluatedDescription eDesc = null; - - for(Iterator<EvaluatedDescription> i = evalDesc.iterator(); i.hasNext();) - { - if(eDesc==null) - { - EvaluatedDescription e = i.next(); - System.out.println("Description: "+e.getDescription()); - System.out.println("Description2: "+eval); - if(e.getDescription().toString().equals(eval.toString())) - { - eDesc = e; - } - - } - } - return eDesc; - } - - public void renderDetailPanel(Description desc) - { - EvaluatedDescription eval = getSelectedConcept(desc); - System.out.println("Eval: "+eval); - accuracyPanel = new JPanel(new GridLayout(0,2)); + + /** + * This method renders the output for the detail panel. + * @param desc selected description + */ + public void renderDetailPanel(EvaluatedDescription desc) { + eval = desc; accuracy = new JTextArea("Accuracy:"); accuracy.setEditable(false); - accuracyPanel.add(accuracy); posCoveredText = new JTextArea(); + posCoveredText.setForeground(colorGreen); + //sets covered positive examples text area not editable posCoveredText.setEditable(false); posNotCoveredText = new JTextArea(); + posNotCoveredText.setForeground(colorRed); + //sets not covered positive examples text area not editable posNotCoveredText.setEditable(false); negCoveredText = new JTextArea(); + negCoveredText.se... [truncated message content] |
From: <ku...@us...> - 2008-08-14 09:50:49
|
Revision: 1069 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1069&view=rev Author: kurzum Date: 2008-08-14 09:50:45 +0000 (Thu, 14 Aug 2008) Log Message: ----------- test commit because of Christian Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 08:51:57 UTC (rev 1068) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-14 09:50:45 UTC (rev 1069) @@ -26,7 +26,7 @@ /** * Stores all configuration settings. this class collects all configuration * information see the other classes, which are used as attributes here - * + * * @author Sebastian Hellmann */ public class Configuration { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-14 08:52:02
|
Revision: 1068 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1068&view=rev Author: jenslehmann Date: 2008-08-14 08:51:57 +0000 (Thu, 14 Aug 2008) Log Message: ----------- continued EL downward refinement; implemented unit test by Christoph; minor parser change Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/parser/KBParser.java trunk/src/dl-learner/org/dllearner/parser/kb.jj trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java Modified: trunk/src/dl-learner/org/dllearner/parser/KBParser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-08-14 08:47:34 UTC (rev 1067) +++ trunk/src/dl-learner/org/dllearner/parser/KBParser.java 2008-08-14 08:51:57 UTC (rev 1068) @@ -36,7 +36,7 @@ return parseConcept(string); } - public static KB parseKBFile(String content) throws IOException, ParseException { + public static KB parseKBFile(String content) throws ParseException { KBParser parser = new KBParser(new StringReader(content)); return parser.KB(); } Modified: trunk/src/dl-learner/org/dllearner/parser/kb.jj =================================================================== --- trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-08-14 08:47:34 UTC (rev 1067) +++ trunk/src/dl-learner/org/dllearner/parser/kb.jj 2008-08-14 08:51:57 UTC (rev 1068) @@ -65,7 +65,7 @@ return parseConcept(string); } - public static KB parseKBFile(String content) throws IOException, ParseException { + public static KB parseKBFile(String content) throws ParseException { KBParser parser = new KBParser(new StringReader(content)); return parser.KB(); } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-14 08:47:34 UTC (rev 1067) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-14 08:51:57 UTC (rev 1068) @@ -19,10 +19,14 @@ */ package org.dllearner.refinementoperators; +import java.util.Collection; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; +import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; @@ -117,10 +121,10 @@ * @return Set of refined EL description trees. */ public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { - return refine(tree, tree.getRootNode(), new Thing()); + return refine(tree, tree.getRootNode(), new Thing(), true); } - private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) { + private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index, boolean minimize) { // the set of all refinements, which we will return Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); // the position of the node within the tree (needed for getting @@ -157,39 +161,73 @@ // TODO incomplete, it is still open how to construct this refinement !! SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index); Set<ObjectProperty> mgr = utility.computeMgr(appOPs); + // temporary set of all concepts, which still have to pass the equivalence check + Stack<ELDescriptionTree> stack = new Stack<ELDescriptionTree>(); for(ObjectProperty op : mgr) { // clone operation ELDescriptionTree clonedTree = tree.clone(); ELDescriptionNode clonedNode = clonedTree.getNode(position); // add a new node and edge ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>()); - refinements.add(clonedTree); +// refinements.add(clonedTree); + stack.add(clonedTree); + + // recurse if concept is equivalent + // TODO: efficient equivalence check needs to be implemented !! + while(stack.size() != 0) { + // we pick an arbitrary tree and remove it from the stack + ELDescriptionTree testTree = stack.pop(); + // test equivalence + boolean equivalent = false; + // TODO equivalence check + if(equivalent) { + // edge refinement + // we know that the edge we added is the last one for this node + int edgeNr = node.getEdges().size() - 1; + // all refinements of this edge are added to the stack + refineEdge(stack, tree, node, position, edgeNr); + // perform node refinements in non-minimize-mode + refinements.addAll(refineEdges(tree, newNode, position)); + } + } } - + // option 4: edge refinement - for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) { - ELDescriptionEdge edge = node.getEdges().get(edgeNumber); - ObjectProperty op = edge.getLabel(); - // find all more special properties - for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) { - // clone operation - ELDescriptionTree clonedTree = tree.clone(); - // find cloned edge and replace its label - ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); - clonedEdge.setLabel(op2); - } - } - + refinements.addAll(refineEdges(tree, node, position)); + // option 5: child refinement for(ELDescriptionEdge edge : node.getEdges()) { // recursive call on child node and property range as index Description range = rs.getRange(edge.getLabel()); - refinements.addAll(refine(tree, edge.getTree(), range)); + refinements.addAll(refine(tree, edge.getTree(), range, minimize)); } return refinements; } + private Set<ELDescriptionTree> refineEdges(ELDescriptionTree tree, ELDescriptionNode node, int[] position) { + Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) { + refineEdge(refinements, tree, node, position, edgeNumber); + } + return refinements; + } + + private void refineEdge(Collection<ELDescriptionTree> refinements, ELDescriptionTree tree, ELDescriptionNode node, int[] position, int edgeNumber) { + ELDescriptionEdge edge = node.getEdges().get(edgeNumber); + ObjectProperty op = edge.getLabel(); + // find all more special properties + for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) { + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + // find cloned edge and replace its label + ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); + clonedEdge.setLabel(op2); + refinements.add(clonedTree); + } + } + + // private void computeMg(Description index) { // // compute the applicable properties if this has not been done yet // if(app.get(index) == null) Added: trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/junit/ELDownTests.java 2008-08-14 08:51:57 UTC (rev 1068) @@ -0,0 +1,115 @@ +/** + * Copyright (C) 2007-2008, 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.test.junit; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.KB; +import org.dllearner.kb.KBFile; +import org.dllearner.parser.KBParser; +import org.dllearner.parser.ParseException; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.refinementoperators.ELDown; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests related to the EL downward refinement operator. + * + * @author Jens Lehmann + * + */ +public class ELDownTests { + + /** + * Implementation of test case created by Christoph Haase for + * new operator. + * + * @throws ParseException Thrown if concept syntax does not correspond + * to current KB syntax. + */ + @Test + public void refinementTest() throws ParseException { + ComponentManager cm = ComponentManager.getInstance(); + + // background knowledge + String kbString = ""; + kbString += "OP_DOMAIN(hasChild) = human."; + kbString += "OP_RANGE(hasChild) = human."; + kbString += "OP_DOMAIN(hasPet) = human."; + kbString += "OP_RANGE(hasPet) = animal."; + kbString += "Subrole(hasChild, has)."; + kbString += "Subrole(hasPet, has)."; + kbString += "bird SUB animal."; + kbString += "cat SUB animal."; + kbString += "cat SUB animal."; + KB kb = KBParser.parseKBFile(kbString); + + // input description + Description input = KBParser.parseConcept("human AND EXISTS has.animal"); + + // create reasoner + KBFile source = new KBFile(kb); + ReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, source); + ReasoningService rs = cm.reasoningService(rc); + ELDown operator = new ELDown(rs); + + // desired refinements as strings + Set<String> desiredString = new TreeSet<String>(); + desiredString.add("human AND EXISTS hasPet.animal"); + desiredString.add("human AND EXISTS has.bird"); + desiredString.add("human AND EXISTS has.cat"); + desiredString.add("(human AND EXISTS hasPet.TOP) AND EXISTS has.animal"); + desiredString.add("(human AND EXISTS hasChild.TOP) AND EXISTS has.animal"); + desiredString.add("(human AND EXISTS hasPet.TOP) AND EXISTS has.animal"); + desiredString.add("(human AND EXISTS has.person) AND EXISTS has.animal"); + desiredString.add("(human AND EXISTS has.EXISTS has.TOP) AND EXISTS has.animal"); + desiredString.add("human AND EXISTS has.(animal AND EXISTS has.TOP)"); + + ConceptComparator cc = new ConceptComparator(); + SortedSet<Description> desired = new TreeSet<Description>(cc); + for(String str : desiredString) { + Description tmp = KBParser.parseConcept(str); + // eliminate conjunctions nested in other conjunctions + ConceptTransformation.cleanConcept(tmp); + desired.add(tmp); + } + + // perform refinement and compare solutions + Set<Description> refinements = operator.refine(input); + + // number of refinements has to be correct and each produced + // refinement must be in the set of desired refinements + assertTrue(refinements.size() == desired.size()); + for(Description refinement : refinements) { + assertTrue(desired.contains(refinement)); + } + } + +} Modified: trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-08-14 08:47:34 UTC (rev 1067) +++ trunk/src/dl-learner/org/dllearner/test/junit/ReasonerTests.java 2008-08-14 08:51:57 UTC (rev 1068) @@ -19,7 +19,6 @@ */ package org.dllearner.test.junit; -import java.io.IOException; import java.util.List; import org.apache.log4j.Logger; @@ -61,8 +60,6 @@ KB kbObject = null; try { kbObject = KBParser.parseKBFile(kb); - } catch (IOException e) { - e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-14 08:47:39
|
Revision: 1067 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1067&view=rev Author: kurzum Date: 2008-08-14 08:47:34 +0000 (Thu, 14 Aug 2008) Log Message: ----------- paths for rdbtoonto Added Paths: ----------- trunk/src/dl-learner/rdbtoonto/converters/ trunk/src/dl-learner/rdbtoonto/dbmodel/ trunk/src/dl-learner/rdbtoonto/gui/ Property changes on: trunk/src/dl-learner/rdbtoonto/converters ___________________________________________________________________ Added: svn:ignore + AroundOneTable.java AroundOneTableLCS.java Property changes on: trunk/src/dl-learner/rdbtoonto/dbmodel ___________________________________________________________________ Added: svn:ignore + MSA_RDBDataHandler.java MSA_RDBFormHandler.java MSA_RDBRelationHandler.java MSA_RDBSchemaHandler.java Property changes on: trunk/src/dl-learner/rdbtoonto/gui ___________________________________________________________________ Added: svn:ignore + AroundOneTableGui_GOptPanel.java AroundOneTableGui_LCSEditPanel.java This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-14 05:52:22
|
Revision: 1066 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1066&view=rev Author: kurzum Date: 2008-08-14 05:52:18 +0000 (Thu, 14 Aug 2008) Log Message: ----------- added another level for recursion 2 Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java Added Paths: ----------- trunk/src/dl-learner/rdbtoonto/ Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-13 17:39:19 UTC (rev 1065) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-14 05:52:18 UTC (rev 1066) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-13 17:39:19 UTC (rev 1065) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-14 05:52:18 UTC (rev 1066) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Sebastian Hellmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -24,7 +24,6 @@ import java.util.SortedSet; import java.util.TreeSet; - /** * Can assemble sparql queries. can make queries for subject, predicate, object * according to the filter settings object SparqlQueryType, which gives the @@ -34,106 +33,152 @@ * */ public class SparqlQueryMaker { - + private static final String MODE_ALLOW = "allow"; + private static final String MODE_FORBID = "forbid"; + private static final String lineend = "\n"; - - //allow false is forbid + + // allow false is forbid private boolean allowMode = false; + private boolean assembled = false; + private String filter = ""; + private SortedSet<String> objectFilterList; + private SortedSet<String> predicateFilterList; + private boolean literals = false; - - - public SparqlQueryMaker(SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, - boolean literals) { + + public SparqlQueryMaker(SortedSet<String> objectFilterList, + SortedSet<String> predicateFilterList, boolean literals) { super(); this.objectFilterList = objectFilterList; this.predicateFilterList = predicateFilterList; this.literals = literals; } - - - public SparqlQueryMaker(boolean allowMode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, - boolean literals) { - this(objectFilterList,predicateFilterList,literals); + public SparqlQueryMaker(boolean allowMode, + SortedSet<String> objectFilterList, + SortedSet<String> predicateFilterList, boolean literals) { + + this(objectFilterList, predicateFilterList, literals); this.allowMode = allowMode; } - - public SparqlQueryMaker(String mode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, - boolean literals) { - this(objectFilterList,predicateFilterList,literals); - if( mode.equalsIgnoreCase(MODE_ALLOW)) { + + public SparqlQueryMaker(String mode, SortedSet<String> objectFilterList, + SortedSet<String> predicateFilterList, boolean literals) { + this(objectFilterList, predicateFilterList, literals); + if (mode.equalsIgnoreCase(MODE_ALLOW)) { this.allowMode = true; - } else if(mode.equalsIgnoreCase(MODE_FORBID)) { + } else if (mode.equalsIgnoreCase(MODE_FORBID)) { this.allowMode = false; } else { this.allowMode = false; } } - public String makeSubjectQueryUsingFilters(String subject) { - //String filter = internalFilterAssemblySubject(); + // String filter = internalFilterAssemblySubject(); if (!assembled) { filter = internalFilterAssemblySubject("predicate", "object"); - filter = (filter.length()>0) ? "FILTER( " + lineend + filter + "). " : " "; + filter = (filter.length() > 0) ? "FILTER( " + lineend + filter + + "). " : " "; assembled = true; } - - String returnString="SELECT * WHERE { " + lineend + "<" + subject - + "> ?predicate ?object. " + lineend + filter +" } "; - + + String returnString = "SELECT * WHERE { " + lineend + "<" + subject + + "> ?predicate ?object. " + lineend + filter + " } "; + return returnString; } - - private String internalFilterAssemblySubject(String predicateVariable, String objectVariable) { - predicateVariable = (predicateVariable.startsWith("?")) ? predicateVariable : "?"+predicateVariable ; - objectVariable = (objectVariable.startsWith("?")) ? objectVariable : "?"+objectVariable ; - + + public String makeSubjectQueryLevel(String subject, int level) { + + // String filter = internalFilterAssemblySubject(); + // if (!assembled) { + String filtertmp = ""; + filtertmp = internalFilterAssemblySubject("predicate0", "object0"); + filtertmp = (filtertmp.length() > 0) ? "FILTER( " + filtertmp + "). " + : " "; + + StringBuffer sbuff = new StringBuffer(1400); + sbuff.append("SELECT * WHERE { " + lineend + "{<" + subject + + "> ?predicate0 ?object0 ." + lineend); + sbuff.append(filtertmp + "} " + lineend); + + // " + lineend + filter +" } "; + for (int i = 1; i < level; i++) { + sbuff.append("OPTIONAL { "); + sbuff.append("?object" + (i - 1) + " ?predicate" + i + " ?object" + + i + " . " + lineend); + + filtertmp = internalFilterAssemblySubject("predicate" + i, "object" + + i); + filtertmp = (filtertmp.length() > 0) ? "FILTER " + filtertmp + ". " + : " "; + + sbuff.append(filtertmp + " }"); + } + + sbuff.append(lineend + "} "); + + return sbuff.toString(); + } + + private String internalFilterAssemblySubject(String predicateVariable, + String objectVariable) { + predicateVariable = (predicateVariable.startsWith("?")) ? predicateVariable + : "?" + predicateVariable; + objectVariable = (objectVariable.startsWith("?")) ? objectVariable + : "?" + objectVariable; + List<String> terms = new ArrayList<String>(); - if(!isLiterals()) { terms.add("!isLiteral("+objectVariable+")"); } - String not = (isAllowMode())? "" : "!" ; + if (!isLiterals()) { + terms.add("!isLiteral(" + objectVariable + ")"); + } + String not = (isAllowMode()) ? "" : "!"; for (String pred : getPredicateFilterList()) { - terms.add( not + "regex(str("+predicateVariable+"), '" + pred + "')" ); + terms.add(not + "regex(str(" + predicateVariable + "), '" + pred + + "')"); } for (String obj : getObjectFilterList()) { - terms.add( not + "regex(str("+objectVariable+"), '" + obj + "')" ); + terms + .add(not + "regex(str(" + objectVariable + "), '" + obj + + "')"); } - - return assembleTerms( terms); - + + return assembleTerms(terms); + } - - private String assembleTerms(List<String> terms){ - if(terms.isEmpty()) return ""; - else if(terms.size() == 1 ) return brackets(terms.get(0)); - else { + + private String assembleTerms(List<String> terms) { + if (terms.isEmpty()) + return ""; + else if (terms.size() == 1) + return brackets(terms.get(0)); + else { StringBuffer sbuf = new StringBuffer(1400); String operator = (isAllowMode()) ? "||" : "&&"; String first = terms.remove(0); sbuf.append(brackets(first)); for (String term : terms) { - sbuf.append(lineend+operator); + sbuf.append(lineend + operator); sbuf.append(brackets(term)); } return brackets(sbuf.toString()); } - + } - - private static String brackets(String s){ - return "("+s+")"; + + private static String brackets(String s) { + return "(" + s + ")"; } - - - public boolean isLiterals() { return literals; } @@ -154,11 +199,9 @@ assembled = false; predicateFilterList.add(newFilter); } - - - -public static SparqlQueryMaker getSparqlQueryMakerByName(String name) { - + + public static SparqlQueryMaker getSparqlQueryMakerByName(String name) { + if (name.equalsIgnoreCase("YAGO")) return getYAGOFilter(); else if (name.equalsIgnoreCase("SKOS")) @@ -171,12 +214,12 @@ return test(); else if (name.equalsIgnoreCase("DBPEDIA-NAVIGATOR")) return getDBpediaNavigatorFilter(); - else return null; + else + return null; } - - - public static SparqlQueryMaker getYAGOFilter(){ - SortedSet<String> pred = new TreeSet<String>(); + + public static SparqlQueryMaker getYAGOFilter() { + SortedSet<String> pred = new TreeSet<String>(); pred.add("http://www.w3.org/2004/02/skos/core"); pred.add("http://www.w3.org/2002/07/owl#sameAs"); pred.add("http://xmlns.com/foaf/0.1/"); @@ -187,10 +230,10 @@ pred.add("http://dbpedia.org/property/relatedInstance"); pred.add("http://dbpedia.org/property/owner"); pred.add("http://dbpedia.org/property/standard"); - + SortedSet<String> obj = new TreeSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); + // obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + // obj.add("http://dbpedia.org/resource/Category:Articles_"); obj.add("http://dbpedia.org/resource/Category:"); obj.add("http://dbpedia.org/resource/Template"); obj.add("http://xmlns.com/foaf/0.1/"); @@ -200,225 +243,195 @@ obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); obj.add("http://www.w3.org/2004/02/skos/core"); - + return new SparqlQueryMaker("forbid", obj, pred, false); } - - public static SparqlQueryMaker getDBpediaNavigatorFilter(){ + + public static SparqlQueryMaker getDBpediaNavigatorFilter() { SortedSet<String> pred = new TreeSet<String>(); pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf"); pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long"); - //pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - //pred.add("http://dbpedia.org/property/relatedInstance"); - //pred.add("http://dbpedia.org/property/owner"); - //pred.add("http://dbpedia.org/property/standard"); - return new SparqlQueryMaker("allow", new TreeSet<String>(), pred , true); - } - - public static SparqlQueryMaker getYagoSpecialHierarchyFilter(){ + // pred.add("http://dbpedia.org/property/wikipage"); + // pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + // pred.add("http://dbpedia.org/property/relatedInstance"); + // pred.add("http://dbpedia.org/property/owner"); + // pred.add("http://dbpedia.org/property/standard"); + return new SparqlQueryMaker("allow", new TreeSet<String>(), pred, true); + } + + public static SparqlQueryMaker getYagoSpecialHierarchyFilter() { SortedSet<String> pred = new TreeSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - pred.add("http://dbpedia.org/property/monarch"); - + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); - SortedSet<String> obj = new TreeSet<String>(); - obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + pred.add("http://dbpedia.org/property/monarch"); - return new SparqlQueryMaker("forbid", obj, pred, false); - } - - - public static SparqlQueryMaker getSKOSFilter(){ - SortedSet<String> pred = new TreeSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + SortedSet<String> obj = new TreeSet<String>(); + obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); - SortedSet<String> obj = new TreeSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryMaker("forbid", obj, pred, false); - } - public static SparqlQueryMaker getYAGOSKOS(){ + return new SparqlQueryMaker("forbid", obj, pred, false); + } + + public static SparqlQueryMaker getSKOSFilter() { SortedSet<String> pred = new TreeSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); + // pred.add("http://www.w3.org/2004/02/skos/core"); pred.add("http://www.w3.org/2002/07/owl#sameAs"); pred.add("http://xmlns.com/foaf/0.1/"); - + pred.add("http://dbpedia.org/property/reference"); pred.add("http://dbpedia.org/property/website"); pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://www.w3.org/2004/02/skos/core#narrower"); + pred.add("http://www.w3.org/2004/02/skos/core#narrower"); pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); SortedSet<String> obj = new TreeSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); + // obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + // obj.add("http://dbpedia.org/resource/Category:Articles_"); obj.add("http://xmlns.com/foaf/0.1/"); obj.add("http://upload.wikimedia.org/wikipedia/commons"); obj.add("http://upload.wikimedia.org/wikipedia"); - + obj.add("http://www.geonames.org"); obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - //obj.add("http://dbpedia.org/class/yago"); + + obj.add("http://dbpedia.org/class/yago"); obj.add("http://dbpedia.org/resource/Template"); - - + return new SparqlQueryMaker("forbid", obj, pred, false); } - - public static SparqlQueryMaker test(){ + + public static SparqlQueryMaker getYAGOSKOS() { SortedSet<String> pred = new TreeSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - //pred.add("http://dbpedia.org/property/reference"); - //pred.add("http://dbpedia.org/property/website"); - //pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - - SortedSet<String> obj = new TreeSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Category:"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - return new SparqlQueryMaker("forbid", obj, pred, false); - } - - - public static void main(String[] args){ - - String uri = "http://dbpedia.org/resource/Angela_Merkel"; - System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri)); - System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri).length()); - System.out.println(getDBpediaNavigatorFilter().makeSubjectQueryUsingFilters(uri)); - - - } - - /* - private String internalFilterAssemblySubject() { + // pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); - boolean emptyPredicateFilter = getPredicateFilterList().isEmpty(); - boolean emptyObjectFilter = getObjectFilterList().isEmpty(); - - String filterString = ""; - if (!isLiterals()) { - filterString += "(!isLiteral(?object))"; - if (!getPredicateFilterList().isEmpty()) { - filterString += "&&("; - } - - } else if (!emptyPredicateFilter) { - filterString += "("; - } - boolean firstRun = true; - for (String p : getPredicateFilterList()) { - filterString += lineend; - filterString += (firstRun) ? handlePredicate(p).substring(2) : handlePredicate(p); - firstRun = false; - } - if (!emptyPredicateFilter) { - filterString += ")"; - } - if ((!emptyPredicateFilter || !isLiterals()) && !emptyObjectFilter) { - filterString += "&&("; - }else if (!emptyObjectFilter) { - filterString += "("; - } - - firstRun = true; - for (String o : getObjectFilterList()) { - filterString += lineend; - filterString += (firstRun) ? handleObject(o).substring(2) : handleObject(o) ; - firstRun = false; - } - if (!emptyObjectFilter){ - filterString += ")"; - } - - return filterString; - }*/ + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + // pred.add("http://www.w3.org/2004/02/skos/core#narrower"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - /* - private String filterSubject(String ns) { - return "&&( !regex(str(?subject), '" + ns + "') )"; - } + SortedSet<String> obj = new TreeSet<String>(); + // obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + // obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); - - private String handlePredicate (String ns) { - return (isAllowMode()) ? allowPredicate(ns) : filterPredicate(ns) ; + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + + // obj.add("http://dbpedia.org/class/yago"); + obj.add("http://dbpedia.org/resource/Template"); + + return new SparqlQueryMaker("forbid", obj, pred, false); } - - private String handleObject (String ns) { - return (isAllowMode()) ? allowObject(ns) : filterObject(ns) ; - } - - private static String filterPredicate(String ns) { - return "&&( !regex(str(?predicate), '" + ns + "') )"; - } - private static String filterObject(String ns) { - return "&&( !regex(str(?object), '" + ns + "') )"; + public static SparqlQueryMaker test() { + SortedSet<String> pred = new TreeSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + // pred.add("http://dbpedia.org/property/reference"); + // pred.add("http://dbpedia.org/property/website"); + // pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + + SortedSet<String> obj = new TreeSet<String>(); + // obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + // obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Category:"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); + return new SparqlQueryMaker("forbid", obj, pred, false); } - - private static String allowPredicate(String ns) { - return "||( regex(str(?predicate), '" + ns + "') )"; - } - private static String allowObject(String ns) { - return "||( regex(str(?object), '" + ns + "') )"; + public static void main(String[] args) { + + String uri = "http://dbpedia.org/resource/Angela_Merkel"; + // System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri)); + // System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri).length()); + // System.out.println(getDBpediaNavigatorFilter().makeSubjectQueryUsingFilters(uri)); + System.out.println(); + System.out.println(getSparqlQueryMakerByName("YAGO") + .makeSubjectQueryLevel(uri, 3)); + } -*/ - } + /* + * private String internalFilterAssemblySubject() { + * + * boolean emptyPredicateFilter = getPredicateFilterList().isEmpty(); + * boolean emptyObjectFilter = getObjectFilterList().isEmpty(); + * + * String filterString = ""; if (!isLiterals()) { filterString += + * "(!isLiteral(?object))"; if (!getPredicateFilterList().isEmpty()) { + * filterString += "&&("; } + * } else if (!emptyPredicateFilter) { filterString += "("; } boolean + * firstRun = true; for (String p : getPredicateFilterList()) { filterString += + * lineend; filterString += (firstRun) ? handlePredicate(p).substring(2) : + * handlePredicate(p); firstRun = false; } if (!emptyPredicateFilter) { + * filterString += ")"; } if ((!emptyPredicateFilter || !isLiterals()) && + * !emptyObjectFilter) { filterString += "&&("; }else if + * (!emptyObjectFilter) { filterString += "("; } + * + * firstRun = true; for (String o : getObjectFilterList()) { filterString += + * lineend; filterString += (firstRun) ? handleObject(o).substring(2) : + * handleObject(o) ; firstRun = false; } if (!emptyObjectFilter){ + * filterString += ")"; } + * + * return filterString; } + */ + + /* + * private String filterSubject(String ns) { return "&&( + * !regex(str(?subject), '" + ns + "') )"; } + * + * + * private String handlePredicate (String ns) { return (isAllowMode()) ? + * allowPredicate(ns) : filterPredicate(ns) ; } + * + * private String handleObject (String ns) { return (isAllowMode()) ? + * allowObject(ns) : filterObject(ns) ; } + * + * private static String filterPredicate(String ns) { return "&&( + * !regex(str(?predicate), '" + ns + "') )"; } + * + * private static String filterObject(String ns) { return "&&( + * !regex(str(?object), '" + ns + "') )"; } + * + * private static String allowPredicate(String ns) { return "||( + * regex(str(?predicate), '" + ns + "') )"; } + * + * private static String allowObject(String ns) { return "||( + * regex(str(?object), '" + ns + "') )"; } + */ + +} Property changes on: trunk/src/dl-learner/rdbtoonto ___________________________________________________________________ Added: svn:ignore + converters dbmodel gui This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-13 17:39:28
|
Revision: 1065 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1065&view=rev Author: kurzum Date: 2008-08-13 17:39:19 +0000 (Wed, 13 Aug 2008) Log Message: ----------- removed some unnecessary classes, complete refactoring of SparqlQueryMaker Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -19,8 +19,9 @@ */ package org.dllearner.kb.extraction; +import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQueryType; +import org.dllearner.kb.sparql.SparqlQueryMaker; /** * Stores all configuration settings. this class collects all configuration @@ -30,8 +31,10 @@ */ public class Configuration { + private SPARQLTasks sparqlTasks; + private SparqlEndpoint endpoint; - private SparqlQueryType sparqlQueryType; + private SparqlQueryMaker sparqlQueryMaker; private Manipulators manipulator; // the following needs to be moved to // class extraction algorithm or manipulator @@ -43,11 +46,11 @@ public String cacheDir="cache"; public Configuration(SparqlEndpoint specificSparqlEndpoint, - SparqlQueryType sparqlQueryType, Manipulators manipulator, + SparqlQueryMaker sparqlQueryMaker, Manipulators manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion, String cacheDir) { this.endpoint = specificSparqlEndpoint; - this.sparqlQueryType = sparqlQueryType; + this.sparqlQueryMaker = sparqlQueryMaker; this.manipulator = manipulator; this.recursiondepth = recursiondepth; this.getAllSuperClasses = getAllSuperClasses; @@ -56,9 +59,9 @@ } - public Configuration changeQueryType(SparqlQueryType sqt) { + public Configuration changeQueryType(SparqlQueryMaker sqm) { // TODO must clone here - return new Configuration(this.endpoint, sqt, this.manipulator, + return new Configuration(this.endpoint, sqm, this.manipulator, this.recursiondepth, this.getAllSuperClasses, this.closeAfterRecursion, this.cacheDir); @@ -72,8 +75,8 @@ return endpoint; } - public SparqlQueryType getSparqlQueryType() { - return sparqlQueryType; + public SparqlQueryMaker getSparqlQueryMaker() { + return sparqlQueryMaker; } public boolean isGetAllSuperClasses() { @@ -87,13 +90,18 @@ public int getRecursiondepth() { return recursiondepth; } + + public SPARQLTasks getSparqlTasks() { + return sparqlTasks; + } - public void increaseNumberOfuncachedSparqlQueries() { + + /*public void increaseNumberOfuncachedSparqlQueries() { numberOfUncachedSparqlQueries++; } public void increaseNumberOfCachedSparqlQueries() { numberOfCachedSparqlQueries++; - } + }*/ } Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -61,7 +61,8 @@ } /** - * most important function expands one example cave: the recursion is not a + * most important function expands one example + * CAVE: the recursion is not a * recursion anymore, it was transformed to an iteration * * @param uri Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -26,7 +26,7 @@ import org.apache.log4j.Logger; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQueryType; +import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.statistics.Statistics; /** @@ -45,12 +45,12 @@ .getLogger(Manager.class); - public void useConfiguration(SparqlQueryType SparqlQueryType, + public void useConfiguration(SparqlQueryMaker sparqlQueryMaker, SparqlEndpoint SparqlEndpoint, Manipulators manipulator, int recursiondepth, boolean getAllSuperClasses, boolean closeAfterRecursion, String cacheDir) { - this.configuration = new Configuration(SparqlEndpoint, SparqlQueryType, + this.configuration = new Configuration(SparqlEndpoint, sparqlQueryMaker, manipulator, recursiondepth, getAllSuperClasses, closeAfterRecursion, cacheDir); //System.out.println(this.configuration); @@ -111,7 +111,7 @@ } public void addPredicateFilter(String str) { - this.configuration.getSparqlQueryType().addPredicateFilter(str); + this.configuration.getSparqlQueryMaker().addPredicateFilter(str); } Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Scrap.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -0,0 +1,112 @@ +package org.dllearner.kb.extraction; + +/** + * this class collects old source code and will be removed after refactoring + * @author Sebastian Hellmann + * + */ +public class Scrap { + + /* + public String makeRoleQueryUsingFilters(String role) { + + String Filter = internalFilterAssemblyRole(); + String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role + + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter + + ").}"; + // System.out.println(ret); + + return ret; + } + */ + + /* + public String makeRoleQueryUsingFilters(String role, boolean domain) { + + String Filter = internalFilterAssemblyRole(); + String ret = ""; + if (domain) { + ret = "SELECT * WHERE { " + lineend + "?subject <" + role + + "> ?object; a []. " + lineend + "FILTER( " + lineend + + "(" + Filter + ").}"; + // "ORDER BY ?subject"; + // System.out.println(ret); + } else { + ret = "SELECT * WHERE { " + lineend + "?object a [] . " + + "?subject <" + role + "> ?object . " + lineend + + "FILTER( " + lineend + "(" + Filter + ").}"; + // "ORDER BY ?object"; + + } + // System.out.println(ret); + + return ret; + }*/ + + + /* + * + private String internalFilterAssemblyRole() { + + String Filter = ""; + if (!this.sparqlQueryType.isLiterals()) + Filter += "!isLiteral(?object))"; + for (String s : sparqlQueryType.getObjectfilterlist()) { + Filter += lineend + filterSubject(s); + } + for (String o : sparqlQueryType.getObjectfilterlist()) { + Filter += lineend + filterObject(o); + } + return Filter; + }*/ + + + /* + * creates a query with the specified filters for all triples with subject + * + * @param subject + * the searched subject + * @param sf + * special object encapsulating all options + * @return sparql query + + /* + * public static String makeQueryFilter(String subject, oldSparqlFilter sf) { + * + * String Filter = ""; if (!sf.useLiterals) Filter += "!isLiteral(?object)"; + * for (String p : sf.getPredFilter()) { Filter += "\n" + + * filterPredicate(p); } for (String o : sf.getObjFilter()) { Filter += "\n" + + * filterObject(o); } + * + * String ret = "SELECT * WHERE { \n" + "<" + subject + "> ?predicate + * ?object.\n"; if (!(Filter.length() == 0)) ret += "FILTER( \n" + "(" + + * Filter + "))."; ret += "}"; // System.out.println(ret); return ret; } + */ + + /* + * moved to SparqlQuery remove here creates a query for subjects with + * the specified label @param label a phrase that is part of the label of a + * subject @param limit this limits the amount of results @return + * + * @Deprecated public static String makeLabelQuery(String label,int limit){ + * // maybe use http://xmlns:com/foaf/0.1/page return + * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject + * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object + * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; } + * + * + * creates a query for all subjects that are of the type concept @param + * concept the type that subjects are searched for @return + * + * + * moved to SparqlQuery remove here + * @Deprecated public static String makeConceptQuery(String concept){ return + * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a + * <"+concept+">}\n"; } moved to SparqlQuery remove here + * @Deprecated public static String makeArticleQuery(String subject){ return + * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+"> + * ?predicate ?object}\n"; } + */ + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlTupelAquisitor.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -0,0 +1,124 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.extraction; + +import java.net.URI; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.kb.sparql.Cache; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.kb.sparql.SparqlQueryMaker; +import org.dllearner.utilities.datastructures.StringTuple; + +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.sparql.core.ResultBinding; + +/** + * Can execute different queries. + * + * @author Sebastian Hellmann + * + */ +public class SparqlTupelAquisitor extends TupelAquisitor { + + private static Logger logger = Logger.getLogger(SparqlTupelAquisitor.class); + + + //boolean print_flag = false; + private Configuration configuration; + private SparqlQueryMaker sparqlQueryMaker; + Cache cache; + + // boolean debug_no_cache = false;// true means no cache is used + // private SparqlHTTPRequest SparqlHTTPRequest; + // private SparqlQuery sparqlQuery; + // private CachedSparqlQuery cachedSparqlQuery; + + public SparqlTupelAquisitor(Configuration Configuration) { + this.configuration = Configuration; + /*this.sparqlQueryMaker = new SparqlQueryMaker(Configuration + .getSparqlQueryType()); + */ + this.cache = new Cache(configuration.cacheDir); + // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); + // this.cachedSparqlQuery=new + // CachedSparqlQuery(this.sparqlQuery,this.cache); + } + + // standard query get a tupels (p,o) for subject s + /** + * uses a cache and gets the result tuples for a resource u + * + * @param uri + * the resource + * @param sparqlQueryString + * @param a + * the name of the first bound variable for xml parsing, normally + * predicate + * @param b + * the name of the second bound variable for xml parsing, + * normally object + * @return + */ + @Override + @SuppressWarnings({"unchecked"}) + public SortedSet<StringTuple> getTupelForResource(URI uri) { + SortedSet<StringTuple> s = new TreeSet<StringTuple>(); + + String a = "predicate"; + String b = "object"; + // getQuery + String sparqlQueryString = sparqlQueryMaker + .makeSubjectQueryUsingFilters(uri.toString()); + +// CachedSparqlQuery csq = new CachedSparqlQuery(configuration +// .getSparqlEndpoint(), cache, uri.toString(), sparqlQueryString); + + SparqlQuery query = new SparqlQuery(sparqlQueryString, configuration.getSparqlEndpoint()); +// query.extraDebugInfo=uri.toString(); + String JSON = cache.executeSparqlQuery(query); + + ResultSet rs = SparqlQuery.convertJSONtoResultSet(JSON); + + List<ResultBinding> l = ResultSetFormatter.toList(rs); + + logger.trace(l.toString()); + for (ResultBinding resultBinding : l) { + + s.add(new StringTuple(resultBinding.get(a).toString(), + resultBinding.get(b).toString())); + } + return s; + } + + + + + + + + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TupelAquisitor.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2007, Sebastian Hellmann + * + * 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.kb.extraction; + +import java.net.URI; +import java.util.SortedSet; + +import org.dllearner.utilities.datastructures.StringTuple; + +/** + * + * Typed SPARQL query interface. The typing means that they all have the same + * input and the same output: They are fn: resource -> ( a | b ) where a + * normally is a predicate and b an object + * + * @author Sebastian Hellmann + * + */ +public abstract class TupelAquisitor { + + public abstract SortedSet<StringTuple> getTupelForResource(URI u); +} + + Modified: trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/TypedSparqlQuery.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -58,8 +58,7 @@ public TypedSparqlQuery(Configuration Configuration) { this.configuration = Configuration; - this.sparqlQueryMaker = new SparqlQueryMaker(Configuration - .getSparqlQueryType()); + this.sparqlQueryMaker =Configuration.getSparqlQueryMaker(); this.cache = new Cache(configuration.cacheDir); // this.sparqlQuery=new SparqlQuery(configuration.getSparqlEndpoint()); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -29,6 +29,8 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.core.KnowledgeSource; @@ -75,8 +77,8 @@ private String predefinedFilter = null; private String predefinedEndpoint = null; private String predefinedManipulator = "STANDARD"; - private Set<String> predList = new HashSet<String>(); - private Set<String> objList = new HashSet<String>(); + private SortedSet<String> predList = new TreeSet<String>(); + private SortedSet<String> objList = new TreeSet<String>(); // private Set<String> classList; private String format = "N-TRIPLES"; private boolean dumpToFile = true; @@ -216,9 +218,9 @@ } else if (option.equals("recursionDepth")) { recursionDepth = (Integer) entry.getValue(); } else if (option.equals("predList")) { - predList = (Set<String>) entry.getValue(); + predList = (SortedSet<String>) entry.getValue(); } else if (option.equals("objList")) { - objList = (Set<String>) entry.getValue(); + objList = (SortedSet<String>) entry.getValue(); // } else if (option.equals("classList")) { // classList = (Set<String>) entry.getValue(); } else if (option.equals("predefinedEndpoint")) { @@ -299,7 +301,7 @@ */ Manager m = new Manager(); - SparqlQueryType sparqlQueryType = null; + SparqlQueryMaker sparqlQueryMaker = null; // get Options for Manipulator Manipulators manipulator = ManipulatorType.getManipulatorByName(predefinedManipulator, blankNodeIdentifier, breakSuperClassRetrievalAfter, replacePredicate, replaceObject); @@ -317,16 +319,15 @@ // get Options for Filters if (predefinedFilter != null) { - sparqlQueryType = SparqlQueryType - .getFilterByName(predefinedFilter); + sparqlQueryMaker = SparqlQueryMaker.getSparqlQueryMakerByName(predefinedFilter); } else { - sparqlQueryType = new SparqlQueryType("forbid", objList, predList, + sparqlQueryMaker = new SparqlQueryMaker("forbid", objList, predList, useLits); } // give everything to the manager - m.useConfiguration(sparqlQueryType, endpoint, manipulator, + m.useConfiguration(sparqlQueryMaker, endpoint, manipulator, recursionDepth, getAllSuperClasses, closeAfterRecursion, cacheDir); String ont = ""; Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -19,7 +19,12 @@ */ package org.dllearner.kb.sparql; +import java.util.ArrayList; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; + /** * Can assemble sparql queries. can make queries for subject, predicate, object * according to the filter settings object SparqlQueryType, which gives the @@ -29,135 +34,376 @@ * */ public class SparqlQueryMaker { - String lineend = "\n"; - boolean print_flag = false; - private SparqlQueryType sparqlQueryType; + + private static final String MODE_ALLOW = "allow"; + private static final String MODE_FORBID = "forbid"; + private static final String lineend = "\n"; + + //allow false is forbid + private boolean allowMode = false; + private boolean assembled = false; + private String filter = ""; + private SortedSet<String> objectFilterList; + private SortedSet<String> predicateFilterList; + private boolean literals = false; + + + public SparqlQueryMaker(SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, + boolean literals) { + super(); + this.objectFilterList = objectFilterList; + this.predicateFilterList = predicateFilterList; + this.literals = literals; + } + + + public SparqlQueryMaker(boolean allowMode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, + boolean literals) { - public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { - this.sparqlQueryType = SparqlQueryType; + this(objectFilterList,predicateFilterList,literals); + this.allowMode = allowMode; } + + public SparqlQueryMaker(String mode, SortedSet<String> objectFilterList, SortedSet<String> predicateFilterList, + boolean literals) { + this(objectFilterList,predicateFilterList,literals); + if( mode.equalsIgnoreCase(MODE_ALLOW)) { + this.allowMode = true; + } else if(mode.equalsIgnoreCase(MODE_FORBID)) { + this.allowMode = false; + } else { + this.allowMode = false; + } + } + public String makeSubjectQueryUsingFilters(String subject) { - String Filter = internalFilterAssemblySubject(); - String ret=""; - if (Filter.length()>0) ret = "SELECT * WHERE { " + lineend + "<" + subject - + "> ?predicate ?object. " + lineend + "FILTER( " + lineend - + Filter + ").}"; - else ret="SELECT * WHERE { " + lineend + "<" + subject - + "> ?predicate ?object}"; - // System.out.println("Query: "+ret); - // System.out.println(sparqlQueryType.getPredicatefilterlist().length); - return ret; + //String filter = internalFilterAssemblySubject(); + if (!assembled) { + filter = internalFilterAssemblySubject("predicate", "object"); + filter = (filter.length()>0) ? "FILTER( " + lineend + filter + "). " : " "; + assembled = true; + } + + String returnString="SELECT * WHERE { " + lineend + "<" + subject + + "> ?predicate ?object. " + lineend + filter +" } "; + + return returnString; } + + private String internalFilterAssemblySubject(String predicateVariable, String objectVariable) { + predicateVariable = (predicateVariable.startsWith("?")) ? predicateVariable : "?"+predicateVariable ; + objectVariable = (objectVariable.startsWith("?")) ? objectVariable : "?"+objectVariable ; + + List<String> terms = new ArrayList<String>(); + if(!isLiterals()) { terms.add("!isLiteral("+objectVariable+")"); } + String not = (isAllowMode())? "" : "!" ; + for (String pred : getPredicateFilterList()) { + terms.add( not + "regex(str("+predicateVariable+"), '" + pred + "')" ); + } + for (String obj : getObjectFilterList()) { + terms.add( not + "regex(str("+objectVariable+"), '" + obj + "')" ); + } + + return assembleTerms( terms); + + } + + private String assembleTerms(List<String> terms){ + if(terms.isEmpty()) return ""; + else if(terms.size() == 1 ) return brackets(terms.get(0)); + else { + StringBuffer sbuf = new StringBuffer(1400); + String operator = (isAllowMode()) ? "||" : "&&"; + String first = terms.remove(0); + sbuf.append(brackets(first)); + for (String term : terms) { + sbuf.append(lineend+operator); + sbuf.append(brackets(term)); + } + return brackets(sbuf.toString()); + } + + } + + private static String brackets(String s){ + return "("+s+")"; + } + - /** - * - * @param role - * @return - */ - public String makeRoleQueryUsingFilters(String role) { - String Filter = internalFilterAssemblyRole(); - String ret = "SELECT * WHERE { " + lineend + " ?subject <" + role - + "> ?object. " + lineend + "FILTER( " + lineend + "(" + Filter - + ").}"; - // System.out.println(ret); + + public boolean isLiterals() { + return literals; + } - return ret; + public boolean isAllowMode() { + return allowMode; } - public String makeRoleQueryUsingFilters(String role, boolean domain) { + public SortedSet<String> getObjectFilterList() { + return objectFilterList; + } - String Filter = internalFilterAssemblyRole(); - String ret = ""; - if (domain) { - ret = "SELECT * WHERE { " + lineend + "?subject <" + role - + "> ?object; a []. " + lineend + "FILTER( " + lineend - + "(" + Filter + ").}"; - // "ORDER BY ?subject"; - // System.out.println(ret); - } else { - ret = "SELECT * WHERE { " + lineend + "?object a [] . " - + "?subject <" + role + "> ?object . " + lineend - + "FILTER( " + lineend + "(" + Filter + ").}"; - // "ORDER BY ?object"; + public SortedSet<String> getPredicateFilterList() { + return predicateFilterList; + } + public void addPredicateFilter(String newFilter) { + assembled = false; + predicateFilterList.add(newFilter); + } + + + +public static SparqlQueryMaker getSparqlQueryMakerByName(String name) { + + if (name.equalsIgnoreCase("YAGO")) + return getYAGOFilter(); + else if (name.equalsIgnoreCase("SKOS")) + return getSKOSFilter(); + else if (name.equalsIgnoreCase("YAGOSKOS")) + return getYAGOSKOS(); + else if (name.equalsIgnoreCase("YAGOSPECIALHIERARCHY")) + return getYagoSpecialHierarchyFilter(); + else if (name.equalsIgnoreCase("TEST")) + return test(); + else if (name.equalsIgnoreCase("DBPEDIA-NAVIGATOR")) + return getDBpediaNavigatorFilter(); + else return null; + } + + + public static SparqlQueryMaker getYAGOFilter(){ + SortedSet<String> pred = new TreeSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + pred.add("http://dbpedia.org/property/owner"); + pred.add("http://dbpedia.org/property/standard"); + + SortedSet<String> obj = new TreeSet<String>(); + //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + //obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Category:"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); + + return new SparqlQueryMaker("forbid", obj, pred, false); + } + + public static SparqlQueryMaker getDBpediaNavigatorFilter(){ + SortedSet<String> pred = new TreeSet<String>(); + pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf"); + pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); + pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long"); + //pred.add("http://dbpedia.org/property/wikipage"); + //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + //pred.add("http://dbpedia.org/property/relatedInstance"); + //pred.add("http://dbpedia.org/property/owner"); + //pred.add("http://dbpedia.org/property/standard"); + return new SparqlQueryMaker("allow", new TreeSet<String>(), pred , true); } - // System.out.println(ret); + + public static SparqlQueryMaker getYagoSpecialHierarchyFilter(){ + SortedSet<String> pred = new TreeSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + pred.add("http://dbpedia.org/property/monarch"); + - return ret; - } + SortedSet<String> obj = new TreeSet<String>(); + obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); - private String internalFilterAssemblySubject() { + return new SparqlQueryMaker("forbid", obj, pred, false); + } + + + public static SparqlQueryMaker getSKOSFilter(){ + SortedSet<String> pred = new TreeSet<String>(); + //pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://www.w3.org/2004/02/skos/core#narrower"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - String Filter = ""; - if (!this.sparqlQueryType.isLiterals()){ - Filter += "(!isLiteral(?object))"; - if (sparqlQueryType.getPredicatefilterlist().size()>0) - Filter += "&&("; + SortedSet<String> obj = new TreeSet<String>(); + //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + //obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + + + obj.add("http://dbpedia.org/class/yago"); + obj.add("http://dbpedia.org/resource/Template"); + + + return new SparqlQueryMaker("forbid", obj, pred, false); } - else if (sparqlQueryType.getPredicatefilterlist().size()>0) - Filter += "("; - int i=1; - for (String p : sparqlQueryType.getPredicatefilterlist()) { - if (this.sparqlQueryType.getMode()=="forbid") - if (i!=1) - Filter += lineend + filterPredicate(p); - else - Filter += lineend + filterPredicate(p).substring(2); - else if (this.sparqlQueryType.getMode()=="allow") - if (i!=1) - Filter += lineend + allowPredicate(p); - else - Filter += lineend + allowPredicate(p).substring(2); - i++; - } - if (sparqlQueryType.getPredicatefilterlist().size()>0) - Filter += ")"; + public static SparqlQueryMaker getYAGOSKOS(){ + SortedSet<String> pred = new TreeSet<String>(); + //pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); - if ((sparqlQueryType.getPredicatefilterlist().size()>0||!this.sparqlQueryType.isLiterals())&&sparqlQueryType.getObjectfilterlist().size()>0) - Filter += "&&("; - else if (sparqlQueryType.getObjectfilterlist().size()>0) - Filter += "("; - i=1; - for (String o : sparqlQueryType.getObjectfilterlist()) { - if (this.sparqlQueryType.getMode()=="forbid") - if (i!=1) - Filter += lineend + filterObject(o); - else - Filter += lineend + filterObject(o).substring(2); - else if (this.sparqlQueryType.getMode()=="allow") - if (i!=1) - Filter += lineend + allowObject(o); - else - Filter += lineend + allowObject(o).substring(2); - i++; + pred.add("http://dbpedia.org/property/reference"); + pred.add("http://dbpedia.org/property/website"); + pred.add("http://dbpedia.org/property/wikipage"); + //pred.add("http://www.w3.org/2004/02/skos/core#narrower"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + + SortedSet<String> obj = new TreeSet<String>(); + //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + //obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + + + //obj.add("http://dbpedia.org/class/yago"); + obj.add("http://dbpedia.org/resource/Template"); + + + return new SparqlQueryMaker("forbid", obj, pred, false); + } + + public static SparqlQueryMaker test(){ + SortedSet<String> pred = new TreeSet<String>(); + pred.add("http://www.w3.org/2004/02/skos/core"); + pred.add("http://www.w3.org/2002/07/owl#sameAs"); + pred.add("http://xmlns.com/foaf/0.1/"); + //pred.add("http://dbpedia.org/property/reference"); + //pred.add("http://dbpedia.org/property/website"); + //pred.add("http://dbpedia.org/property/wikipage"); + pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); + pred.add("http://dbpedia.org/property/relatedInstance"); + + SortedSet<String> obj = new TreeSet<String>(); + //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); + //obj.add("http://dbpedia.org/resource/Category:Articles_"); + obj.add("http://dbpedia.org/resource/Category:"); + obj.add("http://dbpedia.org/resource/Template"); + obj.add("http://xmlns.com/foaf/0.1/"); + obj.add("http://upload.wikimedia.org/wikipedia/commons"); + obj.add("http://upload.wikimedia.org/wikipedia"); + obj.add("http://www.geonames.org"); + obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); + obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); + obj.add("http://www.w3.org/2004/02/skos/core"); + return new SparqlQueryMaker("forbid", obj, pred, false); } - if (sparqlQueryType.getObjectfilterlist().size()>0) - Filter += ")"; + + + public static void main(String[] args){ - return Filter; + String uri = "http://dbpedia.org/resource/Angela_Merkel"; + System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri)); + System.out.println(getSparqlQueryMakerByName("YAGO").makeSubjectQueryUsingFilters(uri).length()); + System.out.println(getDBpediaNavigatorFilter().makeSubjectQueryUsingFilters(uri)); + + } + + /* + private String internalFilterAssemblySubject() { - private String internalFilterAssemblyRole() { - - String Filter = ""; - if (!this.sparqlQueryType.isLiterals()) - Filter += "!isLiteral(?object))"; - for (String s : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterSubject(s); + boolean emptyPredicateFilter = getPredicateFilterList().isEmpty(); + boolean emptyObjectFilter = getObjectFilterList().isEmpty(); + + String filterString = ""; + if (!isLiterals()) { + filterString += "(!isLiteral(?object))"; + if (!getPredicateFilterList().isEmpty()) { + filterString += "&&("; + } + + } else if (!emptyPredicateFilter) { + filterString += "("; } - for (String o : sparqlQueryType.getObjectfilterlist()) { - Filter += lineend + filterObject(o); + boolean firstRun = true; + for (String p : getPredicateFilterList()) { + filterString += lineend; + filterString += (firstRun) ? handlePredicate(p).substring(2) : handlePredicate(p); + firstRun = false; } - return Filter; - } + if (!emptyPredicateFilter) { + filterString += ")"; + } + if ((!emptyPredicateFilter || !isLiterals()) && !emptyObjectFilter) { + filterString += "&&("; + }else if (!emptyObjectFilter) { + filterString += "("; + } + + firstRun = true; + for (String o : getObjectFilterList()) { + filterString += lineend; + filterString += (firstRun) ? handleObject(o).substring(2) : handleObject(o) ; + firstRun = false; + } + if (!emptyObjectFilter){ + filterString += ")"; + } + + return filterString; + }*/ + /* private String filterSubject(String ns) { return "&&( !regex(str(?subject), '" + ns + "') )"; } + + private String handlePredicate (String ns) { + return (isAllowMode()) ? allowPredicate(ns) : filterPredicate(ns) ; + } + + private String handleObject (String ns) { + return (isAllowMode()) ? allowObject(ns) : filterObject(ns) ; + } + private static String filterPredicate(String ns) { return "&&( !regex(str(?predicate), '" + ns + "') )"; } @@ -173,57 +419,6 @@ private static String allowObject(String ns) { return "||( regex(str(?object), '" + ns + "') )"; } +*/ - /*private void p(String str) { - if (print_flag) { - System.out.println(str); - } - }*/ - - /** - * creates a query with the specified filters for all triples with subject - * - * @param subject - * the searched subject - * @param sf - * special object encapsulating all options - * @return sparql query - */ - /* - * public static String makeQueryFilter(String subject, oldSparqlFilter sf) { - * - * String Filter = ""; if (!sf.useLiterals) Filter += "!isLiteral(?object)"; - * for (String p : sf.getPredFilter()) { Filter += "\n" + - * filterPredicate(p); } for (String o : sf.getObjFilter()) { Filter += "\n" + - * filterObject(o); } - * - * String ret = "SELECT * WHERE { \n" + "<" + subject + "> ?predicate - * ?object.\n"; if (!(Filter.length() == 0)) ret += "FILTER( \n" + "(" + - * Filter + "))."; ret += "}"; // System.out.println(ret); return ret; } - */ - - /* - * moved to SparqlQuery TODO remove here creates a query for subjects with - * the specified label @param label a phrase that is part of the label of a - * subject @param limit this limits the amount of results @return - * - * @Deprecated public static String makeLabelQuery(String label,int limit){ - * //TODO maybe use http://xmlns:com/foaf/0.1/page return - * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject - * <http://www.w3.org/2000/01/rdf-schema#label> ?object.?object - * bif:contains '\""+label+"\"'@en}\n"+ "LIMIT "+limit; } - * - * - * creates a query for all subjects that are of the type concept @param - * concept the type that subjects are searched for @return - * - * - * moved to SparqlQuery TODO remove here - * @Deprecated public static String makeConceptQuery(String concept){ return - * "SELECT DISTINCT ?subject\n"+ "WHERE { ?subject a - * <"+concept+">}\n"; } moved to SparqlQuery TODO remove here - * @Deprecated public static String makeArticleQuery(String subject){ return - * "SELECT ?predicate,?object\n"+ "WHERE { <"+subject+"> - * ?predicate ?object}\n"; } - */ -} + } Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -1,254 +0,0 @@ -/** - * Copyright (C) 2007, Sebastian Hellmann - * - * 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.kb.sparql; - -import java.util.HashSet; -import java.util.Set; - -/** - * Is used to set the filter: configuration. - * - * @author Sebastian Hellmann - * - */ -public class SparqlQueryType { - - private String mode = "forbid"; - private Set<String> objectfilterlist; - private Set<String> predicatefilterlist; - private boolean literals = false; - - public SparqlQueryType(String mode, Set<String> obectfilterlist, Set<String> predicatefilterlist, - boolean literals) { - super(); - this.mode = mode; - this.objectfilterlist = obectfilterlist; - this.predicatefilterlist = predicatefilterlist; - this.literals = literals; - } - - public boolean isLiterals() { - return literals; - } - - public String getMode() { - return mode; - } - - public Set<String> getObjectfilterlist() { - return objectfilterlist; - } - - public Set<String> getPredicatefilterlist() { - return predicatefilterlist; - } - - public void addPredicateFilter(String filter) { - predicatefilterlist.add(filter); - //System.out.println("added filter: "+filter); - } - - public static SparqlQueryType getFilterByName(String name) { - - - if (name.equals("YAGO")) - return YagoFilter(); - if (name.equals("SKOS")) - return SKOS(); - if (name.equals("YAGOSKOS")) - return YAGOSKOS(); - if (name.equals("YAGOSPECIALHIERARCHY")) - return YagoSpecialHierarchy(); - if (name.equals("TEST")) - return test(); - if (name.equals("DBPEDIA-NAVIGATOR")) - return DBpediaNavigatorFilter(); - - return null; - } - - - public static SparqlQueryType YagoFilter(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - pred.add("http://dbpedia.org/property/owner"); - pred.add("http://dbpedia.org/property/standard"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Category:"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, false); - } - - public static SparqlQueryType DBpediaNavigatorFilter(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); - pred.add("http://www.w3.org/2000/01/rdf-schema#subClassOf"); - pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#lat"); - pred.add("http://www.w3.org/2003/01/geo/wgs84_pos#long"); - //pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - //pred.add("http://dbpedia.org/property/relatedInstance"); - //pred.add("http://dbpedia.org/property/owner"); - //pred.add("http://dbpedia.org/property/standard"); - - Set<String> obj = new HashSet<String>(); - - return new SparqlQueryType("allow", obj, pred, true); - } - - public static SparqlQueryType YagoSpecialHierarchy(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - pred.add("http://dbpedia.org/property/monarch"); - - - Set<String> obj = new HashSet<String>(); - obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - - return new SparqlQueryType("forbid", obj, pred, false); - } - - - public static SparqlQueryType SKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, false); - } - public static SparqlQueryType YAGOSKOS(){ - Set<String> pred = new HashSet<String>(); - //pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - - pred.add("http://dbpedia.org/property/reference"); - pred.add("http://dbpedia.org/property/website"); - pred.add("http://dbpedia.org/property/wikipage"); - //pred.add("http://www.w3.org/2004/02/skos/core#narrower"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - - - //obj.add("http://dbpedia.org/class/yago"); - obj.add("http://dbpedia.org/resource/Template"); - - - return new SparqlQueryType("forbid", obj, pred, false); - } - - public static SparqlQueryType test(){ - Set<String> pred = new HashSet<String>(); - pred.add("http://www.w3.org/2004/02/skos/core"); - pred.add("http://www.w3.org/2002/07/owl#sameAs"); - pred.add("http://xmlns.com/foaf/0.1/"); - //pred.add("http://dbpedia.org/property/reference"); - //pred.add("http://dbpedia.org/property/website"); - //pred.add("http://dbpedia.org/property/wikipage"); - pred.add("http://dbpedia.org/property/wikiPageUsesTemplate"); - pred.add("http://dbpedia.org/property/relatedInstance"); - - Set<String> obj = new HashSet<String>(); - //obj.add("http://dbpedia.org/resource/Category:Wikipedia_"); - //obj.add("http://dbpedia.org/resource/Category:Articles_"); - obj.add("http://dbpedia.org/resource/Category:"); - obj.add("http://dbpedia.org/resource/Template"); - obj.add("http://xmlns.com/foaf/0.1/"); - obj.add("http://upload.wikimedia.org/wikipedia/commons"); - obj.add("http://upload.wikimedia.org/wikipedia"); - obj.add("http://www.geonames.org"); - obj.add("http://www.w3.org/2006/03/wn/wn20/instances/synset"); - obj.add("http://www4.wiwiss.fu-berlin.de/flickrwrappr"); - obj.add("http://www.w3.org/2004/02/skos/core"); - return new SparqlQueryType("forbid", obj, pred, false); - } - - - - -} Modified: trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-13 13:12:03 UTC (rev 1064) +++ trunk/src/dl-learner/org/dllearner/test/SparqlExtractionTest.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -27,7 +27,7 @@ import org.dllearner.kb.extraction.Manager; import org.dllearner.kb.extraction.Manipulator; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQueryType; +import org.dllearner.kb.sparql.SparqlQueryMaker; import org.dllearner.utilities.datastructures.StringTuple; /** @@ -48,8 +48,7 @@ // m.usePredefinedConfiguration(u); URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); - m.useConfiguration( - SparqlQueryType.getFilterByName("DBPEDIA"),SparqlEndpoint.getEndpointByName("YAGO"), + m.useConfiguration(SparqlQueryMaker.getSparqlQueryMakerByName("DBPEDIA"),SparqlEndpoint.getEndpointByName("YAGO"), new Manipulator("",200,new LinkedList<StringTuple>(),new LinkedList<StringTuple>()), 1,true,true,"cache"); //, , Added: trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/owl/OWLVocabulary.java 2008-08-13 17:39:19 UTC (rev 1065) @@ -0,0 +1,17 @@ +package org.dllearner.utilities.owl; + +public class OWLVocabulary { + + public static final String RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; + + public static final String RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + + + public static final String OWL_SAME_AS = "http://www.w3.org/2002/07/owl#sameAs"; +// public static final String RDF_TYPE = ""; +// public static final String RDF_TYPE = ""; +// public static final String RDF_TYPE = ""; +// public static final String RDF_TYPE = ""; +// public static final String RDF_TYPE = ""; +// public static final String RDF_TYPE = ""; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-08-13 13:12:06
|
Revision: 1064 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1064&view=rev Author: sknappe Date: 2008-08-13 13:12:03 +0000 (Wed, 13 Aug 2008) Log Message: ----------- changed to use search result function in helper_functions Modified Paths: -------------- trunk/src/dbpedia-navigator/ajax_search.php trunk/src/dbpedia-navigator/helper_functions.php Modified: trunk/src/dbpedia-navigator/ajax_search.php =================================================================== --- trunk/src/dbpedia-navigator/ajax_search.php 2008-08-13 12:55:56 UTC (rev 1063) +++ trunk/src/dbpedia-navigator/ajax_search.php 2008-08-13 13:12:03 UTC (rev 1064) @@ -30,9 +30,13 @@ mysql_select_db("navigator_db"); $query="SELECT name, label FROM rank WHERE MATCH (label) AGAINST ('$label') ORDER BY number LIMIT 3"; $res=mysql_query($query); + $names=array(); + $labels=array(); while ($result=mysql_fetch_array($res)){ - $content.='<a href="" onclick="get_article(\'label='.$result['name'].'&cache=-1\');return false;">'.$result['label'].'</a><br/>'; + $labels[]=$result['label']; + $names[]=$result['name']; } + $content.=getResultsTable($names,$labels); print $content; print '$$'; Modified: trunk/src/dbpedia-navigator/helper_functions.php =================================================================== --- trunk/src/dbpedia-navigator/helper_functions.php 2008-08-13 12:55:56 UTC (rev 1063) +++ trunk/src/dbpedia-navigator/helper_functions.php 2008-08-13 13:12:03 UTC (rev 1064) @@ -38,18 +38,19 @@ return $ret; } -function getResultsTable($results) +function getResultsTable($names,$labels) { - $ret="<p>Your search brought ".count($results)." results.</p><br/>"; + $ret="<p>Your search brought ".count($names)." results.</p><br/>"; $i=0; $display="block"; - while($i*30<count($results)) + while($i*30<count($names)) { $ret.="<div id='results".$i."' style='display:".$display."'>Seite ".($i+1)."<br/><br/>"; - for ($j=0;($j<30)&&(($i*30+$j)<count($results));$j++) + for ($j=0;($j<30)&&(($i*30+$j)<count($names));$j++) { - $result=$results[$i*30+$j]; - $ret.=" <a href=\"\" onclick=\"xajax_getarticle('".$result."',-1);return false;\">".urldecode(str_replace("_"," ",substr (strrchr ($result, "/"), 1)))."</a><br/>"; + $name=$names[$i*30+$j]; + $label=$labels[$i*30+$j]; + $ret.=' <a href="" onclick="get_article(\'label='.$name.'&cache=-1\');return false;">'.$label.'</a><br/>'; } $ret.="</div>"; $i++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-08-13 12:55:58
|
Revision: 1063 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1063&view=rev Author: sknappe Date: 2008-08-13 12:55:56 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Class to calculate pageranks and put them into mysql database, also add labels and later also add categories to use only the database for all searches Added Paths: ----------- trunk/src/dl-learner/org/dllearner/test/CalculatePageRank.java Added: trunk/src/dl-learner/org/dllearner/test/CalculatePageRank.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/CalculatePageRank.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/test/CalculatePageRank.java 2008-08-13 12:55:56 UTC (rev 1063) @@ -0,0 +1,127 @@ +package org.dllearner.test; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +public class CalculatePageRank { + + private final String wikilinks="../pagelinks_en.nt"; + private final String labels="../articles_label_en.nt"; + + private void calculateLinks() + { + try{ + Statement stmt; + ResultSet rs; + int number; + + Class.forName("com.mysql.jdbc.Driver"); + + String url = + "jdbc:mysql://localhost:3306/navigator_db"; + + Connection con = DriverManager.getConnection( + url,"navigator", "dbpedia"); + + stmt = con.createStatement(); + BufferedReader in = new BufferedReader(new FileReader(wikilinks)); + + String line; + String[] split; + String name; + int i=0; + while ((line=in.readLine())!=null) + { + split=line.split(" "); + name=split[2].substring(1, split[2].length()-1); + rs=stmt.executeQuery("SELECT number FROM rank WHERE name='"+name+"'"); + if (rs.next()){ + number=rs.getInt(1); + number++; + stmt.executeUpdate("UPDATE rank SET number="+number+" WHERE name='"+name+"'"); + } + else{ + stmt.executeUpdate("INSERT INTO rank (name,number) VALUES ('"+name+"',1)"); + } + if (i%100000==0) System.out.println(i); + i++; + } + + in.close(); + con.close(); + } catch (FileNotFoundException e) + { + System.out.println("File not found"); + } catch (IOException e) + { + System.out.println("IOException"); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + private void addLabels() + { + try{ + Statement stmt; + ResultSet rs; + + Class.forName("com.mysql.jdbc.Driver"); + + String url = + "jdbc:mysql://localhost:3306/navigator_db"; + + Connection con = DriverManager.getConnection( + url,"navigator", "dbpedia"); + + stmt = con.createStatement(); + BufferedReader in = new BufferedReader(new FileReader(labels)); + + String line; + String[] split; + String name; + String label; + int i=0; + while ((line=in.readLine())!=null) + { + split=line.split(">"); + name=split[0].substring(1); + label=split[2].substring(split[2].indexOf("\"")+1, split[2].lastIndexOf("\"")); + rs=stmt.executeQuery("SELECT number FROM rank WHERE name='"+name+"'"); + if (rs.next()){ + stmt.executeUpdate("UPDATE rank SET label=\""+label+"\" WHERE name='"+name+"'"); + } + else{ + stmt.executeUpdate("INSERT INTO rank (name,label) VALUES ('"+name+"',\""+label+"\")"); + } + if (i%100000==0) System.out.println(i); + i++; + } + + in.close(); + con.close(); + } catch (FileNotFoundException e) + { + System.out.println("File not found"); + } catch (IOException e) + { + System.out.println("IOException"); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args){ + CalculatePageRank cal=new CalculatePageRank(); + //cal.calculateLinks(); + cal.addLabels(); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2008-08-13 12:54:23
|
Revision: 1062 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1062&view=rev Author: sknappe Date: 2008-08-13 12:54:21 +0000 (Wed, 13 Aug 2008) Log Message: ----------- added search using mysql database, not perfect yet, have to add categories to get tag cloud Modified Paths: -------------- trunk/src/dbpedia-navigator/index-new.php Added Paths: ----------- trunk/src/dbpedia-navigator/ajax_search.php Added: trunk/src/dbpedia-navigator/ajax_search.php =================================================================== --- trunk/src/dbpedia-navigator/ajax_search.php (rev 0) +++ trunk/src/dbpedia-navigator/ajax_search.php 2008-08-13 12:54:21 UTC (rev 1062) @@ -0,0 +1,40 @@ +<?php + include('helper_functions.php'); + + $label=$_POST['label']; + $list=$_POST['list']; + session_start(); + $id=$_SESSION['id']; + $ksID=$_SESSION['ksID']; + session_write_close(); + + setRunning($id,"true"); + + //get parts of the list + $checkedInstances=preg_split("[,]",$list,-1,PREG_SPLIT_NO_EMPTY); + + //initialise content + $content=""; + /*try{ + require_once("DLLearnerConnection.php"); + $sc=new DLLearnerConnection($id,$ksID); + + $subjects=$sc->getSubjects($label,$checkedInstances); + + $content.=getTagCloud($subjects['tagcloud'],$subjects['tagcloudlabel']); + $content.=getResultsTable($subjects['subjects']); + } catch (Exception $e){ + $content=$e->getMessage(); + }*/ + mysql_connect('localhost','navigator','dbpedia'); + mysql_select_db("navigator_db"); + $query="SELECT name, label FROM rank WHERE MATCH (label) AGAINST ('$label') ORDER BY number LIMIT 3"; + $res=mysql_query($query); + while ($result=mysql_fetch_array($res)){ + $content.='<a href="" onclick="get_article(\'label='.$result['name'].'&cache=-1\');return false;">'.$result['label'].'</a><br/>'; + } + + print $content; + print '$$'; + print "Searchresult for ".$label; +?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/index-new.php =================================================================== --- trunk/src/dbpedia-navigator/index-new.php 2008-08-13 07:42:33 UTC (rev 1061) +++ trunk/src/dbpedia-navigator/index-new.php 2008-08-13 12:54:21 UTC (rev 1062) @@ -103,6 +103,32 @@ XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); XhrObj.send(param); } + + function search(param) + { + if (document.all){ + //IE + var XhrObj = new ActiveXObject("Microsoft.XMLHTTP"); + } + else{ + //Mozilla + var XhrObj = new XMLHttpRequest(); + } + + XhrObj.open("POST",'ajax_search.php'); + + XhrObj.onreadystatechange = function() + { + if (XhrObj.readyState == 4 && XhrObj.status == 200){ + var response = XhrObj.responseText.split('$$'); + document.getElementById('articlecontent').innerHTML=response[0]; + document.getElementById('ArticleTitle').innerHTML=response[1]; + } + } + + XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); + XhrObj.send(param); + } </script> </head> <body> @@ -122,7 +148,7 @@ <!-- Search:<br/> --> <form onSubmit="get_article('label='+document.getElementById('label').value+'&cache=-1');return false;"> <input type="text" name="label" id="label" /><br/> - <input type="button" value="Article" class="button" onclick="get_article('label='+document.getElementById('label').value+'&cache=-1');return false;" /> <input type="button" value="Search" class="button" onclick="var list=tree.getAllChecked();return false;" /> + <input type="button" value="Article" class="button" onclick="get_article('label='+document.getElementById('label').value+'&cache=-1');return false;" /> <input type="button" value="Search" class="button" onclick="var list=tree.getAllChecked();search('label='+document.getElementById('label').value+'&list='+list);return false;" /> <!-- <input type="button" value="Fulltext" class="button" onclick=""/> --> </form> </div> <!-- boxcontent --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-13 07:42:36
|
Revision: 1061 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1061&view=rev Author: jenslehmann Date: 2008-08-13 07:42:33 +0000 (Wed, 13 Aug 2008) Log Message: ----------- documentation improvements Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/core/KnowledgeSource.java trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java trunk/src/dl-learner/org/dllearner/core/LearningProblem.java Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-08-12 10:09:05 UTC (rev 1060) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-08-13 07:42:33 UTC (rev 1061) @@ -91,6 +91,7 @@ /** * @see org.dllearner.core.owl.Description#getDepth() + * @return Depth of the description. */ public int getDescriptionDepth() { return description.getDepth(); @@ -98,13 +99,17 @@ /** * @see org.dllearner.core.Score#getAccuracy() + * @return Accuracy of the description. */ public double getAccuracy() { return score.getAccuracy(); } /** + * Gets the score of this description. This can be used to get + * further statistical values. * @see org.dllearner.core.Score + * @return The score object associated with this evaluated description. */ public Score getScore() { return score; @@ -112,6 +117,7 @@ /** * @see org.dllearner.core.Score#getCoveredNegatives() + * @return Negative examples covered by the description. */ public Set<Individual> getCoveredNegatives() { return score.getCoveredNegatives(); @@ -119,6 +125,7 @@ /** * @see org.dllearner.core.Score#getCoveredPositives() + * @return Positive examples covered by the description. */ public Set<Individual> getCoveredPositives() { return score.getCoveredPositives(); @@ -126,6 +133,7 @@ /** * @see org.dllearner.core.Score#getNotCoveredNegatives() + * @return Negative examples not covered by the description. */ public Set<Individual> getNotCoveredNegatives() { return score.getNotCoveredNegatives(); @@ -133,6 +141,7 @@ /** * @see org.dllearner.core.Score#getNotCoveredPositives() + * @return Positive examples not covered by the description. */ public Set<Individual> getNotCoveredPositives() { return score.getNotCoveredPositives(); Modified: trunk/src/dl-learner/org/dllearner/core/KnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/KnowledgeSource.java 2008-08-12 10:09:05 UTC (rev 1060) +++ trunk/src/dl-learner/org/dllearner/core/KnowledgeSource.java 2008-08-13 07:42:33 UTC (rev 1061) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -25,17 +25,40 @@ import org.dllearner.core.owl.KB; /** - * Represents a knowledge source component. + * Represents a knowledge source component, e.g. OWL files, SPARQL Endpoints, + * Linked Data. * * @author Jens Lehmann * */ public abstract class KnowledgeSource extends Component { + /** + * Transforms this knowledge source into an internal knowledge base. + * @return An internal Knowledge base or null if this knowledge source + * does not support a conversion to an internal knowledge base. + */ public abstract KB toKB(); + /** + * Transforms this knowledge source to DIG 1.1 code according to + * <a href="http://dl.kr.org/dig/">the specification</a>. DIG is used + * for communicating with reasoners. + * + * @param kbURI The URI which is assigned to the knowledge base. The URI + * is used to refer to the knowledge base in queries (DIG supports using + * several knowledge bases). + * @return The DIG XML code. + */ public abstract String toDIG(URI kbURI); + /** + * Export the knowledge source to the specified file in the specified format. + * @param file File to store the knowledge base. + * @param format Format of the knowledge base, e.g. N-Triples. + * @throws OntologyFormatUnsupportedException Thrown if the conversion + * to the specified format is not supported by this knowledge source. + */ public abstract void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException; } Modified: trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-08-12 10:09:05 UTC (rev 1060) +++ trunk/src/dl-learner/org/dllearner/core/LearningAlgorithm.java 2008-08-13 07:42:33 UTC (rev 1061) @@ -45,6 +45,14 @@ public abstract class LearningAlgorithm extends Component { /** + * This is the maximum number of results, which the learning + * algorithms need to keep. (Often algorithms do not need + * to store any results except the best one, so this limit + * is used to limit the performance cost for storing results.) + */ + public static final int MAX_NR_OF_RESULTS = 100; + + /** * Starts the algorithm. It runs until paused, stopped, or * a termination criterion has been reached. */ @@ -90,11 +98,13 @@ /** * @see #getCurrentlyBestEvaluatedDescription() + * @return The best class description found by the learning algorithm so far. */ public abstract Description getCurrentlyBestDescription(); /** * @see #getCurrentlyBestEvaluatedDescriptions() + * @return The best class descriptions found by the learning algorithm so far. */ public List<Description> getCurrentlyBestDescriptions() { List<Description> ds = new LinkedList<Description>(); @@ -104,6 +114,8 @@ /** * @see #getCurrentlyBestEvaluatedDescriptions(int) + * @param nrOfDescriptions Limit for the number or returned descriptions. + * @return The best class descriptions found by the learning algorithm so far. */ public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions) { return getCurrentlyBestDescriptions(nrOfDescriptions, false); @@ -111,16 +123,22 @@ /** * @see #getCurrentlyBestEvaluatedDescriptions(int,double,boolean) + * @param nrOfDescriptions Limit for the number or returned descriptions. + * @param filterNonMinimalDescriptions Remove non-minimal descriptions (e.g. those which can be shortened + * to an equivalent concept) from the returned set. + * @return The best class descriptions found by the learning algorithm so far. */ public synchronized List<Description> getCurrentlyBestDescriptions(int nrOfDescriptions, boolean filterNonMinimalDescriptions) { List<Description> currentlyBest = getCurrentlyBestDescriptions(); List<Description> returnList = new LinkedList<Description>(); for(Description ed : currentlyBest) { - if(returnList.size() >= nrOfDescriptions) + if(returnList.size() >= nrOfDescriptions) { return returnList; + } - if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed)) + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed)) { returnList.add(ed); + } } return returnList; @@ -169,15 +187,18 @@ // once we hit a description with a below threshold accuracy, we simply return // because learning algorithms are advised to order descriptions by accuracy, // so we won't find any concept with higher accuracy in the remaining list - if(ed.getAccuracy() < accuracyThreshold) + if(ed.getAccuracy() < accuracyThreshold) { return returnList; + } // return if we have sufficiently many descriptions - if(returnList.size() >= nrOfDescriptions) + if(returnList.size() >= nrOfDescriptions) { return returnList; + } - if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed.getDescription())) + if(!filterNonMinimalDescriptions || ConceptTransformation.isDescriptionMinimal(ed.getDescription())) { returnList.add(ed); + } } return returnList; @@ -203,7 +224,9 @@ } /** - * Returns all learning problems supported by this component. + * Returns all learning problems supported by this component. This can be used to indicate that, e.g. + * an algorithm is only suitable for positive only learning. + * @return All classes implementing learning problems, which are supported by this learning algorithm. */ public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { return new LinkedList<Class<? extends LearningProblem>>(); Modified: trunk/src/dl-learner/org/dllearner/core/LearningProblem.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-08-12 10:09:05 UTC (rev 1060) +++ trunk/src/dl-learner/org/dllearner/core/LearningProblem.java 2008-08-13 07:42:33 UTC (rev 1061) @@ -42,6 +42,10 @@ */ public abstract class LearningProblem extends Component { + /** + * Implementations of learning problems can use this class + * variable to perform reasoner operations. + */ protected ReasoningService reasoningService; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-12 10:09:09
|
Revision: 1060 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1060&view=rev Author: kurzum Date: 2008-08-12 10:09:05 +0000 (Tue, 12 Aug 2008) Log Message: ----------- small changes Modified Paths: -------------- trunk/build.xml Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-08-08 14:02:47 UTC (rev 1059) +++ trunk/build.xml 2008-08-12 10:09:05 UTC (rev 1060) @@ -36,7 +36,7 @@ <classpath refid="classpath"/> </javac> - <jar jarfile="lib/rdbtoonto/test.jar"> + <jar jarfile="lib/rdbtoonto/converter.jar"> <fileset dir="classes_tmp"/> </jar> <delete dir="classes_tmp"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-08 14:02:50
|
Revision: 1059 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1059&view=rev Author: jenslehmann Date: 2008-08-08 14:02:47 +0000 (Fri, 08 Aug 2008) Log Message: ----------- EL downward refinement operator continued Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionEdge.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -46,6 +46,13 @@ } /** + * @param label the label to set + */ + public void setLabel(ObjectProperty label) { + this.label = label; + } + + /** * @return The label of this edge. */ public ObjectProperty getLabel() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -177,14 +177,35 @@ } /** - * Each node is assigned a number within the tree. - * TODO add explanation how this is done + * Gets a list describing the position of this node within the + * tree. If the list is e.g. [2,5,1], then the node can be reached + * by picking the second child of the root node, then picking the + * 5th child of this node and finally selecting the first child of + * the previous node. * @return The position number of this node within the tree as described above. */ - public int getCurrentPositionNumber() { - return 0; + public int[] getCurrentPosition() { + int[] position = new int[level]; + ELDescriptionNode root = this; + while(root.parent != null) { + position[root.level-1] = getChildNumber(); + root = parent; + } + return position; } + // returns the child number of this node, i.e. whether it is + // the first, second, third etc. child + private int getChildNumber() { + int count = 0; + for(ELDescriptionEdge edge : parent.edges) { + if(edge.getTree() == this) { + return count; + } + } + throw new RuntimeException("Inconsistent tree. Child tree not reachable from parent."); + } + /** * Replaces an entry in the node label. * @param oldClass Class to remove from label. @@ -196,7 +217,16 @@ } /** - * Gets the label of this node. Do not modify the returned object. + * Adds an entry to the node label. + * @param newClass Class to add to label. + */ + public void extendLabel(NamedClass newClass) { + label.add(newClass); + } + + /** + * Gets the label of this node. Do not modify the returned object, + * but use the provided methods instead! * @return The label of root node of this subtree. */ public SortedSet<NamedClass> getLabel() { @@ -204,14 +234,16 @@ } /** - * @return The outgoing edges of this subtree. Do not modify the - * returned object. + * Gets the edges of this node. Do not modify the + * returned object, but use the provided methods instead! + * @return The outgoing edges of this subtree. */ public List<ELDescriptionEdge> getEdges() { return edges; } /** + * Gets the level (distance from root) of this node. * @return The level of the (root node of) this subtree in the overall tree. */ public int getLevel() { Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -113,36 +113,20 @@ } /** - * Selects a sub tree. - * @param positionNumber A position in the tree. Positions are iteratively given to nodes - * by leftmost depth-first search. This allows efficient selection of subtrees. - * (TODO: Implementation does not work if any node has more than two children - * like conjunction and disjunction.) - * @return The selected subtree. + * Gets the node at the given position. The list is processed + * as follows: Starting with the root node, the first element i of + * list is read and the i-th child of root node is selected. This + * node is set as current node and the next element j of the list + * is read and the j-th child of the i-th child of the root node + * selected etc. + * @return The node at the specified position. */ - public Description getNode(int positionNumber) { -// if (children.size() == 0) -// return this; -// else if (children.size() == 1) { -// if (positionNumber == 0) -// return this; -// else -// return children.get(0).getSubtree(positionNumber - 1); -// } -// // arity 2 -// else { -// // we have found it -// if (positionNumber == 0) -// return this; -// // left subtree -// int leftTreeNodes = children.get(0).getNumberOfNodes(); -// if (positionNumber <= leftTreeNodes) -// return children.get(0).getSubtree(positionNumber - 1); -// // right subtree -// else -// return children.get(1).getSubtree(positionNumber - leftTreeNodes - 1); -// } - return null; + public ELDescriptionNode getNode(int[] position) { + ELDescriptionNode currentNode = rootNode; + for(int i=0; i<position.length; i++) { + currentNode = currentNode.getEdges().get(position[i]).getTree(); + } + return currentNode; } @Override Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 11:38:27 UTC (rev 1058) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-08 14:02:47 UTC (rev 1059) @@ -22,8 +22,11 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.SortedSet; import java.util.TreeMap; +import java.util.TreeSet; +import org.dllearner.algorithms.el.ELDescriptionEdge; import org.dllearner.algorithms.el.ELDescriptionNode; import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.core.ReasoningService; @@ -118,11 +121,21 @@ } private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) { - Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + // the set of all refinements, which we will return + Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); + // the position of the node within the tree (needed for getting + // the corresponding node in a cloned tree) + int[] position = node.getCurrentPosition(); + // option 1: label extension Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel()); for(NamedClass nc : candidates) { - + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // extend label + clonedNode.extendLabel(nc); + refinements.add(clonedTree); } // option 2: label refinement // loop through all classes in label @@ -130,22 +143,50 @@ // find all more special classes for the given label for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { if(moreSpecial instanceof NamedClass) { - // create refinements by replacing class - ELDescriptionTree tmp = tree.clone(); - // TODO we need to find a way to get this node in - // the cloned tree -// tmp.replaceInLabel(nc, (NamedClass) moreSpecial); - refinements.add(tmp); + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // create refinements by replacing class + clonedNode.replaceInLabel(nc, (NamedClass) moreSpecial); + refinements.add(clonedTree); } } } // option 3: new edge + // TODO incomplete, it is still open how to construct this refinement !! + SortedSet<ObjectProperty> appOPs = utility.computeApplicableObjectProperties(index); + Set<ObjectProperty> mgr = utility.computeMgr(appOPs); + for(ObjectProperty op : mgr) { + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + ELDescriptionNode clonedNode = clonedTree.getNode(position); + // add a new node and edge + ELDescriptionNode newNode = new ELDescriptionNode(clonedNode, op, new TreeSet<NamedClass>()); + refinements.add(clonedTree); + } // option 4: edge refinement + for(int edgeNumber = 0; edgeNumber < node.getEdges().size(); edgeNumber++) { + ELDescriptionEdge edge = node.getEdges().get(edgeNumber); + ObjectProperty op = edge.getLabel(); + // find all more special properties + for(ObjectProperty op2 : rs.getMoreSpecialRoles(op)) { + // clone operation + ELDescriptionTree clonedTree = tree.clone(); + // find cloned edge and replace its label + ELDescriptionEdge clonedEdge = clonedTree.getNode(position).getEdges().get(edgeNumber); + clonedEdge.setLabel(op2); + } + } // option 5: child refinement - + for(ELDescriptionEdge edge : node.getEdges()) { + // recursive call on child node and property range as index + Description range = rs.getRange(edge.getLabel()); + refinements.addAll(refine(tree, edge.getTree(), range)); + } + return refinements; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-08 11:38:30
|
Revision: 1058 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1058&view=rev Author: kurzum Date: 2008-08-08 11:38:27 +0000 (Fri, 08 Aug 2008) Log Message: ----------- added new ant task for rdbtoonto Modified Paths: -------------- trunk/build.xml trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java Property Changed: ---------------- trunk/ Property changes on: trunk ___________________________________________________________________ Modified: svn:ignore - .lastUsedExample .settings .project .classpath classes log cache + .lastUsedExample .settings .project .classpath classes log cache cachePersistant reports results local rdbtoonto the_log.txt Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-08-07 11:06:52 UTC (rev 1057) +++ trunk/build.xml 2008-08-08 11:38:27 UTC (rev 1058) @@ -27,7 +27,22 @@ <target name="full_release" depends="javadoc,build" description="full release, javadoc, scripts"> </target> + <!-- build target --> + <target name="rdbtoonto" description="makes jar"> + <!-- compile project into temporary directory --> + <mkdir dir="classes_tmp"/> + <javac destdir="classes_tmp" target="1.6"> + <src path="${source_dir}"/> + <classpath refid="classpath"/> + </javac> + + <jar jarfile="lib/rdbtoonto/test.jar"> + <fileset dir="classes_tmp"/> + </jar> + <delete dir="classes_tmp"/> + </target> + <!-- build target --> <target name="local" depends="createScripts" description="fast build including scripts, no javadoc, no tar, just executables in local, can be used on a server"> Modified: trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-07 11:06:52 UTC (rev 1057) +++ trunk/src/dl-learner/org/dllearner/scripts/WikipediaCategoryCleaner.java 2008-08-08 11:38:27 UTC (rev 1058) @@ -119,7 +119,7 @@ WikipediaCategoryTasks wikiTasks; ConceptSPARQLReEvaluator csparql; - + System.out.println("test"); wikiTasks = new WikipediaCategoryTasks(sparqlTasks); csparql = new ConceptSPARQLReEvaluator(sparqlTasks, DEPTH_OF_RDFS, SPARQL_RESULTSET_LIMIT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-07 11:06:58
|
Revision: 1057 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1057&view=rev Author: jenslehmann Date: 2008-08-07 11:06:52 +0000 (Thu, 07 Aug 2008) Log Message: ----------- implemented selection of candidate class in label extension in EL downward refinement operator Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-06 17:54:29 UTC (rev 1056) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionNode.java 2008-08-07 11:06:52 UTC (rev 1057) @@ -30,7 +30,6 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.ObjectSomeRestriction; import org.dllearner.core.owl.Thing; -import org.dllearner.core.owl.UnsupportedLanguageException; /** * Represents an EL description tree, which corresponds to a @@ -110,16 +109,6 @@ // } /** - * Constructs an EL description tree from an EL description. - * @param description A description - */ - public ELDescriptionNode(Description description) { - // TODO not implemented - // throw an exception if the description is not in EL - throw new UnsupportedLanguageException(description.toString(), "EL"); - } - - /** * Checks whether this node has a parent. If the parent link * is null, the node is considered to be a root node. * @return True of this is the root node and false otherwise. @@ -188,6 +177,15 @@ } /** + * Each node is assigned a number within the tree. + * TODO add explanation how this is done + * @return The position number of this node within the tree as described above. + */ + public int getCurrentPositionNumber() { + return 0; + } + + /** * Replaces an entry in the node label. * @param oldClass Class to remove from label. * @param newClass Class to add to label. @@ -220,24 +218,4 @@ return level; } - @Override - public ELDescriptionNode clone() { - ELDescriptionNode node = null; - try { - node = (ELDescriptionNode) super.clone(); - } catch (CloneNotSupportedException e) { - // should never happen - throw new InternalError(e.toString()); - } -/* - // create a deep copy - node.children = new LinkedList<Description>(); - for(Description child : children) { - Description clonedChild = (Description) child.clone(); - node.addChild(clonedChild); - } -*/ - return node; - } - } Modified: trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-06 17:54:29 UTC (rev 1056) +++ trunk/src/dl-learner/org/dllearner/algorithms/el/ELDescriptionTree.java 2008-08-07 11:06:52 UTC (rev 1057) @@ -25,7 +25,9 @@ import java.util.Set; import java.util.TreeSet; +import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.UnsupportedLanguageException; /** * Represents an EL description tree. Unlike {@link ELDescriptionNode}, @@ -50,6 +52,16 @@ public ELDescriptionTree() { } + + /** + * Constructs an EL description tree from an EL description. + * @param description A description + */ + public ELDescriptionTree(Description description) { + // TODO not implemented + // throw an exception if the description is not in EL + throw new UnsupportedLanguageException(description.toString(), "EL"); + } /** * Gets the nodes on a specific level of the tree. @@ -63,6 +75,10 @@ return levelNodeMapping.get(level); } + public Description transformToDescription() { + return rootNode.transformToDescription(); + } + /** * Internal method for updating the level node mapping. * It is called when a new node is added to the tree. @@ -96,6 +112,39 @@ return rootNode; } + /** + * Selects a sub tree. + * @param positionNumber A position in the tree. Positions are iteratively given to nodes + * by leftmost depth-first search. This allows efficient selection of subtrees. + * (TODO: Implementation does not work if any node has more than two children + * like conjunction and disjunction.) + * @return The selected subtree. + */ + public Description getNode(int positionNumber) { +// if (children.size() == 0) +// return this; +// else if (children.size() == 1) { +// if (positionNumber == 0) +// return this; +// else +// return children.get(0).getSubtree(positionNumber - 1); +// } +// // arity 2 +// else { +// // we have found it +// if (positionNumber == 0) +// return this; +// // left subtree +// int leftTreeNodes = children.get(0).getNumberOfNodes(); +// if (positionNumber <= leftTreeNodes) +// return children.get(0).getSubtree(positionNumber - 1); +// // right subtree +// else +// return children.get(1).getSubtree(positionNumber - leftTreeNodes - 1); +// } + return null; + } + @Override public ELDescriptionTree clone() { // create a new reference tree Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-06 17:54:29 UTC (rev 1056) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/ELDown.java 2008-08-07 11:06:52 UTC (rev 1057) @@ -25,6 +25,7 @@ import java.util.TreeMap; import org.dllearner.algorithms.el.ELDescriptionNode; +import org.dllearner.algorithms.el.ELDescriptionTree; import org.dllearner.core.ReasoningService; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; @@ -95,10 +96,10 @@ public Set<Description> refine(Description concept) { // TODO according to the specification, we need to minimise // the tree (not yet implemented) - ELDescriptionNode tree = new ELDescriptionNode(concept); - Set<ELDescriptionNode> refinementTrees = refine(tree); + ELDescriptionTree tree = new ELDescriptionTree(concept); + Set<ELDescriptionTree> refinementTrees = refine(tree); Set<Description> refinements = new HashSet<Description>(); - for(ELDescriptionNode refinementTree : refinementTrees) { + for(ELDescriptionTree refinementTree : refinementTrees) { refinements.add(refinementTree.transformToDescription()); } return refinements; @@ -112,23 +113,28 @@ * @param tree Input EL description tree. * @return Set of refined EL description trees. */ - public Set<ELDescriptionNode> refine(ELDescriptionNode tree) { - return refine(tree, new Thing()); + public Set<ELDescriptionTree> refine(ELDescriptionTree tree) { + return refine(tree, tree.getRootNode(), new Thing()); } - private Set<ELDescriptionNode> refine(ELDescriptionNode tree, Description index) { - Set<ELDescriptionNode> refinements = new HashSet<ELDescriptionNode>(); + private Set<ELDescriptionTree> refine(ELDescriptionTree tree, ELDescriptionNode node, Description index) { + Set<ELDescriptionTree> refinements = new HashSet<ELDescriptionTree>(); // option 1: label extension - + Set<NamedClass> candidates = utility.getClassCandidates(index, node.getLabel()); + for(NamedClass nc : candidates) { + + } // option 2: label refinement // loop through all classes in label - for(NamedClass nc : tree.getLabel()) { + for(NamedClass nc : node.getLabel()) { // find all more special classes for the given label for(Description moreSpecial : rs.getMoreSpecialConcepts(nc)) { if(moreSpecial instanceof NamedClass) { // create refinements by replacing class - ELDescriptionNode tmp = tree.clone(); - tmp.replaceInLabel(nc, (NamedClass) moreSpecial); + ELDescriptionTree tmp = tree.clone(); + // TODO we need to find a way to get this node in + // the cloned tree +// tmp.replaceInLabel(nc, (NamedClass) moreSpecial); refinements.add(tmp); } } Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 17:54:29 UTC (rev 1056) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-07 11:06:52 UTC (rev 1057) @@ -47,6 +47,7 @@ public final class Utility { private ReasoningService rs; + SubsumptionHierarchy sh; // concept comparator private ConceptComparator conceptComparator = new ConceptComparator(); @@ -61,6 +62,7 @@ public Utility(ReasoningService rs) { this.rs = rs; + sh = rs.getSubsumptionHierarchy(); } /** @@ -107,21 +109,58 @@ private Set<NamedClass> getClassCandidatesRecursive(Description index, Set<NamedClass> existingClasses, Description upperClass) { Set<NamedClass> candidates = new TreeSet<NamedClass>(); - SubsumptionHierarchy sh = rs.getSubsumptionHierarchy(); + + // we descend the subsumption hierarchy to ensure that we get + // the most general concepts satisfying the criteria + // there are 4 checks a class has to satisfy to get into the set; + // for 2 of them we can stop further traversal in the subsumption + // hierarchy for(Description d : sh.getMoreSpecialConcepts(upperClass)) { - // check disjointness with index - if(isDisjoint(d,index)) { - // check whether the class is meaningful, i.e. adds something to the index - // to do this, we need to make sure that the class is not a superclass of the - // index (otherwise we get nothing new) - if(isDisjoint(new Negation(d),index)) { - // TODO further checks + // owl:Nothing is never a candidate (not in EL) + if(!(d instanceof Nothing)) { + NamedClass candidate = (NamedClass) d; + // we first do those checks where we know that we do not + // need to traverse the subsumption hierarchy if they are + // not satisfied + // check1: disjointness with index + // check3: no superclass exists already + if(!isDisjoint(candidate,index) || !checkSubClasses(existingClasses,candidate)) { + // check whether the class is meaningful, i.e. adds something to the index + // to do this, we need to make sure that the class is not a superclass of the + // index (otherwise we get nothing new) + if(!isDisjoint(new Negation(candidate),index) || !checkSuperClasses(existingClasses,candidate)) { + // candidate went successfully through all checks + candidates.add(candidate); + } else { + // descend subsumption hierarchy to find candidates + candidates.addAll(getClassCandidatesRecursive(index, existingClasses, candidate)); + } } } } return candidates; } + // returns true of the candidate is not subclass of an existing class, + // false otherwise (check 3) + private boolean checkSubClasses(Set<NamedClass> existingClasses, NamedClass candidate) { + for(NamedClass nc : existingClasses) { + if(sh.isSubclassOf(candidate, nc)) + return false; + } + return true; + } + + // returns true of the candidate is not superclass of an existing class, + // false otherwise (check 4) + private boolean checkSuperClasses(Set<NamedClass> existingClasses, NamedClass candidate) { + for(NamedClass nc : existingClasses) { + if(sh.isSubclassOf(nc, candidate)) + return false; + } + return true; + } + private boolean isDisjoint(Description d1, Description d2) { // check whether we have cached this query Map<Description,Boolean> tmp = cachedDisjoints.get(d1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-06 17:54:33
|
Revision: 1056 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1056&view=rev Author: jenslehmann Date: 2008-08-06 17:54:29 +0000 (Wed, 06 Aug 2008) Log Message: ----------- EL refinement operator continued Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java Modified: trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java 2008-08-06 09:53:31 UTC (rev 1055) +++ trunk/src/dl-learner/org/dllearner/core/owl/SubsumptionHierarchy.java 2008-08-06 17:54:29 UTC (rev 1056) @@ -94,6 +94,35 @@ subsumptionHierarchyUp = hierarchyUpNew; } + /** + * Implements a subsumption check using the hierarchy (no further + * reasoning checks are used). + * @param subClass The (supposedly) more special class. + * @param superClass The (supposedly) more general class. + * @return True if <code>subClass</code> is a subclass of <code>superclass</code>. + */ + public boolean isSubclassOf(NamedClass subClass, NamedClass superClass) { + if(subClass.equals(superClass)) { + return true; + } else { + for(Description moreGeneralClass : subsumptionHierarchyUp.get(subClass)) { + // search the upper classes of the subclass + if(moreGeneralClass instanceof NamedClass) { + if(isSubclassOf((NamedClass)moreGeneralClass, superClass)) { + return true; + } + // we reached top, so we can return false (if top is a direct upper + // class, then no other upper classes can exist) + } else { + return false; + } + } + // we cannot reach the class via any of the upper classes, + // so it is not a super class + return false; + } + } + @Override public String toString() { return toString(false); Modified: trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java =================================================================== --- trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 09:53:31 UTC (rev 1055) +++ trunk/src/dl-learner/org/dllearner/refinementoperators/Utility.java 2008-08-06 17:54:29 UTC (rev 1056) @@ -29,8 +29,12 @@ import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Negation; import org.dllearner.core.owl.Nothing; import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.SubsumptionHierarchy; +import org.dllearner.core.owl.Thing; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; @@ -97,6 +101,27 @@ return Helper.intersection(rs.getMostGeneralRoles(), applicableObjectProperties); } + public Set<NamedClass> getClassCandidates(Description index, Set<NamedClass> existingClasses) { + return getClassCandidatesRecursive(index, existingClasses, Thing.instance); + } + + private Set<NamedClass> getClassCandidatesRecursive(Description index, Set<NamedClass> existingClasses, Description upperClass) { + Set<NamedClass> candidates = new TreeSet<NamedClass>(); + SubsumptionHierarchy sh = rs.getSubsumptionHierarchy(); + for(Description d : sh.getMoreSpecialConcepts(upperClass)) { + // check disjointness with index + if(isDisjoint(d,index)) { + // check whether the class is meaningful, i.e. adds something to the index + // to do this, we need to make sure that the class is not a superclass of the + // index (otherwise we get nothing new) + if(isDisjoint(new Negation(d),index)) { + // TODO further checks + } + } + } + return candidates; + } + private boolean isDisjoint(Description d1, Description d2) { // check whether we have cached this query Map<Description,Boolean> tmp = cachedDisjoints.get(d1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2008-08-06 10:10:26
|
Revision: 1055 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1055&view=rev Author: jenslehmann Date: 2008-08-06 09:53:31 +0000 (Wed, 06 Aug 2008) Log Message: ----------- code style and logging improvements Modified Paths: -------------- trunk/doc/checkstyle.xml trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/core/ComponentManager.java trunk/src/dl-learner/org/dllearner/core/ComponentPool.java trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java trunk/src/dl-learner/org/dllearner/core/owl/KBElement.java Modified: trunk/doc/checkstyle.xml =================================================================== --- trunk/doc/checkstyle.xml 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/doc/checkstyle.xml 2008-08-06 09:53:31 UTC (rev 1055) @@ -85,7 +85,6 @@ <property name="header" value="/** * Copyright (C) 2007-2008, 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/>. * */"/> <property name="ignoreLines" value="20"/> </module> - <module name="AbstractClassName"/> </module> <module name="JavadocPackage"/> <module name="NewlineAtEndOfFile"/> Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2008-08-06 09:53:31 UTC (rev 1055) @@ -57,6 +57,13 @@ * Method to be called after the component has been configured. * Implementation of components can overwrite this method to * perform setup and initialisation tasks for this component. + * + * @throws ComponentInitException This exception is thrown if any + * exceptions occur within the initialisation process of this + * component. As component developer, you are encouraged to + * rethrow occuring exception as ComponentInitException and + * giving an error message as well as the actualy exception by + * using the constructor {@link ComponentInitException#ComponentInitException(String, Throwable)}. */ public abstract void init() throws ComponentInitException; @@ -66,7 +73,16 @@ * perform an action (usually setting an internal variable to * an appropriate value). * + * @param <T> Type of the config entry (Integer, String etc.). * @param entry A configuration entry. + * @throws InvalidConfigOptionValueException This exception is thrown if the + * value of the config entry is not valid. For instance, a config option + * may only accept values, which are within intervals 0.1 to 0.3 or 0.5 to 0.8. + * If the value is outside of those intervals, an exception is thrown. Note + * that many of the common cases are already caught in the constructor of + * ConfigEntry (for instance for a {@link DoubleConfigOption} you can specify + * an interval for the value). This means that, as a component developer, you + * often do not need to implement further validity checks. */ public abstract <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException; Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2008-08-06 09:53:31 UTC (rev 1055) @@ -60,7 +60,7 @@ * @author Jens Lehmann * */ -public class ComponentManager { +public final class ComponentManager { private static Logger logger = Logger .getLogger(ComponentManager.class); @@ -95,14 +95,15 @@ }; - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings("unchecked") private ComponentManager() { // read in components file List<String> componentsString; - if(componentClasses.length > 0) + if(componentClasses.length > 0) { componentsString = Arrays.asList(componentClasses); - else + } else { componentsString = readComponentsFile(); + } // component list components = new TreeSet<Class<? extends Component>>(classComparator); @@ -120,13 +121,13 @@ Component.class); components.add(component); - if (KnowledgeSource.class.isAssignableFrom(component)) + if (KnowledgeSource.class.isAssignableFrom(component)) { knowledgeSources.add((Class<? extends KnowledgeSource>) component); - else if (ReasonerComponent.class.isAssignableFrom(component)) + } else if (ReasonerComponent.class.isAssignableFrom(component)) { reasonerComponents.add((Class<? extends ReasonerComponent>) component); - else if (LearningProblem.class.isAssignableFrom(component)) + } else if (LearningProblem.class.isAssignableFrom(component)) { learningProblems.add((Class<? extends LearningProblem>) component); - else if (LearningAlgorithm.class.isAssignableFrom(component)) { + } else if (LearningAlgorithm.class.isAssignableFrom(component)) { Class<? extends LearningAlgorithm> learningAlgorithmClass = (Class<? extends LearningAlgorithm>) component; learningAlgorithms.add(learningAlgorithmClass); Collection<Class<? extends LearningProblem>> problems = (Collection<Class<? extends LearningProblem>>) invokeStaticMethod( @@ -157,8 +158,9 @@ // make config options accessible by name Map<String, ConfigOption<?>> byName = new HashMap<String, ConfigOption<?>>(); - for (ConfigOption<?> option : options) + for (ConfigOption<?> option : options) { byName.put(option.getName(), option); + } componentOptionsByName.put(component, byName); } @@ -172,8 +174,9 @@ * @return The singleton <code>ComponentManager</code> instance. */ public static ComponentManager getInstance() { - if(cm == null) + if(cm == null) { cm = new ComponentManager(); + } return cm; } @@ -203,8 +206,9 @@ while ((line = br.readLine()) != null) { if (!(line.startsWith("#") || line.startsWith("//") || line.startsWith("%") || line - .length() <= 1)) + .length() <= 1)) { componentStrings.add(line); + } } in.close(); @@ -220,11 +224,12 @@ * value is correct, it is preferable to create a ConfigEntry object and * apply it to the component (no type checking necessary). * + * @param <T> Type of the config option (Integer, String etc.). * @param component A component. * @param optionName The name of the config option. * @param value The value of the config option. */ - @SuppressWarnings( { "unchecked" }) + @SuppressWarnings("unchecked") public <T> void applyConfigEntry(Component component, String optionName, T value) { logger.trace(component); logger.trace(optionName); @@ -258,11 +263,13 @@ System.out.println("Warning: value " + value + " is not valid for option " + optionName + " in component " + component); } - } else - System.out.println("Warning: undefined option " + optionName + " in component " + } else { + logger.warn("Warning: undefined option " + optionName + " in component " + component); - } else - System.out.println("Warning: unregistered component " + component); + } + } else { + logger.warn("Warning: unregistered component " + component); + } } /** @@ -276,10 +283,10 @@ public <T> boolean applyConfigEntry(Component component, ConfigEntry<T> entry) { try { component.applyConfigEntry(entry); - pool.addConfigEntry(component,entry,true); + pool.addConfigEntry(component, entry, true); return true; } catch (InvalidConfigOptionValueException e) { - pool.addConfigEntry(component,entry,false); + pool.addConfigEntry(component, entry, false); e.printStackTrace(); return false; } @@ -287,13 +294,16 @@ /** * Factory method for creating a knowledge source. + * + * @param <T> The type of this method is a subclass of knowledge source. * @param source A registered knowledge source component. * @return An instance of the given knowledge source class. */ public <T extends KnowledgeSource> T knowledgeSource(Class<T> source) { - if (!knowledgeSources.contains(source)) - System.err.println("Warning: knowledge source " + source + if (!knowledgeSources.contains(source)) { + logger.warn("Warning: knowledge source " + source + " is not a registered knowledge source component."); + } T ks = invokeConstructor(source, new Class[] {}, new Object[] {}); pool.registerComponent(ks); @@ -329,9 +339,10 @@ */ public <T extends ReasonerComponent> T reasoner(Class<T> reasoner, Set<KnowledgeSource> sources) { - if (!reasonerComponents.contains(reasoner)) + if (!reasonerComponents.contains(reasoner)) { System.err.println("Warning: reasoner component " + reasoner + " is not a registered reasoner component."); + } T rc = invokeConstructor(reasoner, new Class[] { Set.class }, new Object[] { sources }); @@ -363,9 +374,10 @@ * @return A learning problem component. */ public <T extends LearningProblem> T learningProblem(Class<T> lpClass, ReasoningService reasoner) { - if (!learningProblems.contains(lpClass)) + if (!learningProblems.contains(lpClass)) { System.err.println("Warning: learning problem " + lpClass + " is not a registered learning problem component."); + } T lp = invokeConstructor(lpClass, new Class[] { ReasoningService.class }, new Object[] { reasoner }); @@ -385,16 +397,18 @@ * the learning algorithm are not compatible. */ public <T extends LearningAlgorithm> T learningAlgorithm(Class<T> laClass, LearningProblem lp, ReasoningService rs) throws LearningProblemUnsupportedException { - if (!learningAlgorithms.contains(laClass)) + if (!learningAlgorithms.contains(laClass)) { System.err.println("Warning: learning algorithm " + laClass + " is not a registered learning algorithm component."); + } // find the right constructor: use the one that is registered and // has the class of the learning problem as a subclass Class<? extends LearningProblem> constructorArgument = null; for (Class<? extends LearningProblem> problemClass : algorithmProblemsMapping.get(laClass)) { - if (problemClass.isAssignableFrom(lp.getClass())) + if (problemClass.isAssignableFrom(lp.getClass())) { constructorArgument = problemClass; + } } if (constructorArgument == null) { @@ -447,10 +461,11 @@ */ public <T> T getConfigOptionValue(Component component, ConfigOption<T> option) { T object = pool.getLastValidConfigValue(component, option); - if(object==null) + if(object==null) { return option.getDefaultValue(); - else + } else { return object; + } } /** @@ -485,40 +500,44 @@ doc += "*********************\n"; doc += "* Knowledge Sources *\n"; doc += "*********************\n\n"; - for(Class<? extends Component> component : knowledgeSources) + for(Class<? extends Component> component : knowledgeSources) { doc += getComponentConfigString(component); + } doc += "*************\n"; doc += "* Reasoners *\n"; doc += "*************\n\n"; - for(Class<? extends Component> component : reasonerComponents) + for(Class<? extends Component> component : reasonerComponents) { doc += getComponentConfigString(component); + } doc += "*********************\n"; doc += "* Learning Problems *\n"; doc += "*********************\n\n"; - for(Class<? extends Component> component : learningProblems) + for(Class<? extends Component> component : learningProblems) { doc += getComponentConfigString(component); + } doc += "***********************\n"; doc += "* Learning Algorithms *\n"; doc += "***********************\n\n"; - for(Class<? extends Component> component : learningAlgorithms) + for(Class<? extends Component> component : learningAlgorithms) { doc += getComponentConfigString(component); + } Files.createFile(file, doc); } private String getComponentConfigString(Class<? extends Component> component) { - String componentDescription = "component: " + invokeStaticMethod(component,"getName") + " (" + component.getName() + ")"; + String componentDescription = "component: " + invokeStaticMethod(component, "getName") + " (" + component.getName() + ")"; String str = componentDescription + "\n"; - String CLI = Start.getCLIMapping(component.getSuperclass().getSimpleName()+""); + String cli = Start.getCLIMapping(component.getSuperclass().getSimpleName()+""); String usage =""; Map<Class<? extends Component>, String> m=Start.createComponentPrefixMapping(); for (Class<? extends Component> c : m.keySet()) { - if(c.getCanonicalName().equals(component.getCanonicalName())) - { usage=m.get(c); + if(c.getCanonicalName().equals(component.getCanonicalName())) { + usage=m.get(c); } } @@ -526,14 +545,12 @@ str += "="; } str += "\n\n"; - str += "CLI usage: "+CLI+" = "+usage+";\n\n"; + str += "CLI usage: "+cli+" = "+usage+";\n\n"; for(ConfigOption<?> option : componentOptions.get(component)) { - str += option.toString() + - "CLI usage: "+usage+"."+ - option.getName()+" = "+option.getDefaultValue()+ - ";\n\n"; + str += option.toString() + "CLI usage: "+usage+"." + + option.getName()+" = "+option.getDefaultValue()+";\n\n"; } return str+"\n"; } @@ -593,9 +610,10 @@ * @return A list of available configuration options of the specified component. */ public static List<ConfigOption<?>> getConfigOptions(Class<? extends Component> componentClass) { - if (!components.contains(componentClass)) + if (!components.contains(componentClass)) { System.err.println("Warning: component " + componentClass + " is not a registered component. [ComponentManager.getConfigOptions]"); + } return componentOptions.get(componentClass); } Modified: trunk/src/dl-learner/org/dllearner/core/ComponentPool.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/src/dl-learner/org/dllearner/core/ComponentPool.java 2008-08-06 09:53:31 UTC (rev 1055) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007, Jens Lehmann + * Copyright (C) 2007-2008, Jens Lehmann * * This file is part of DL-Learner. * @@ -24,57 +24,95 @@ import java.util.List; import java.util.Map; +import org.apache.log4j.Logger; import org.dllearner.core.config.ConfigEntry; import org.dllearner.core.config.ConfigOption; /** - * Stores all live components and the configuration options, which were - * applied to them. + * Stores all live components and the configuration options, which were applied + * to them. This allows to detect, which components are currently active, which + * values are assigned to specific options, and to collect statistics (e.g. in + * a web service scenario). * * @author Jens Lehmann - * + * */ -public class ComponentPool { +public final class ComponentPool { - // stores all components, which are live (components which are + private static Logger logger = Logger + .getLogger(ComponentPool.class); + + // stores all components, which are live (components which are // no longer used have to be deregistered) private List<Component> components = new LinkedList<Component>(); - - // stores the last value which was set for a particular + + // stores the last value which was set for a particular // config option - private Map<Component,Map<ConfigOption<?>,Object>> lastValidConfigValue = new HashMap<Component,Map<ConfigOption<?>,Object>>(); + private Map<Component, Map<ConfigOption<?>, Object>> lastValidConfigValue = new HashMap<Component, Map<ConfigOption<?>, Object>>(); // complete history of all made config entries for a component - private Map<Component,List<ConfigEntry<?>>> configEntryHistory = new HashMap<Component,List<ConfigEntry<?>>>(); - + private Map<Component, List<ConfigEntry<?>>> configEntryHistory = new HashMap<Component, List<ConfigEntry<?>>>(); + + /** + * Registers a component instance in the pool. + * @param component The component to add to the pool. + */ public void registerComponent(Component component) { components.add(component); - Map<ConfigOption<?>,Object> emptyMap = new HashMap<ConfigOption<?>,Object>(); + Map<ConfigOption<?>, Object> emptyMap = new HashMap<ConfigOption<?>, Object>(); lastValidConfigValue.put(component, emptyMap); configEntryHistory.put(component, new LinkedList<ConfigEntry<?>>()); + logger.debug("Component instance " + component + " added to component pool."); } + /** + * Unregisters a component instance. This method should be used if the + * component will not be used anymore. It frees the memory for + * storing the component and its configuration options. + * @param component The component to remove from the pool. + */ public void unregisterComponent(Component component) { configEntryHistory.remove(component); lastValidConfigValue.remove(component); components.remove(component); + logger.debug("Component instance " + component + " removed from component pool."); } - @SuppressWarnings({"unchecked"}) - public <T> T getLastValidConfigValue(Component component, ConfigOption<T> option) { + /** + * Gets the last valid config value set for this component. + * @param <T> The type of the value of the config option (String, Integer etc.). + * @param component The component to query. + * @param option The option for which one wants to get the value. + * @return The last value set for this option or null if the value hasn't been + * set using the {@link ComponentManager}. In this case, the value is + * usually at the default value (or has been set internally surpassing the + * component architecture, which is not recommended). + */ + @SuppressWarnings("unchecked") + protected <T> T getLastValidConfigValue(Component component, ConfigOption<T> option) { return (T) lastValidConfigValue.get(component).get(option); } - - public void addConfigEntry(Component component, ConfigEntry<?> entry, boolean valid) { + + /** + * Add a config entry change for the specified component. + * @param component The component, where the config entry has been set. + * @param entry The set config entry. + * @param valid A boolean value indicating whether the value was valid or not. + */ + protected void addConfigEntry(Component component, ConfigEntry<?> entry, boolean valid) { configEntryHistory.get(component).add(entry); - if(valid) + if (valid) { lastValidConfigValue.get(component).put(entry.getOption(), entry.getValue()); + } + logger.trace("Config entry " + entry + " has been set for component " + component + " (validity: " + valid + ")."); } - - // unregisters all components - public void clearComponents() { + + /** + * Unregisters all components. + */ + protected void clearComponents() { components = new LinkedList<Component>(); - lastValidConfigValue = new HashMap<Component,Map<ConfigOption<?>,Object>>(); - configEntryHistory = new HashMap<Component,List<ConfigEntry<?>>>(); + lastValidConfigValue = new HashMap<Component, Map<ConfigOption<?>, Object>>(); + configEntryHistory = new HashMap<Component, List<ConfigEntry<?>>>(); } - + } Modified: trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/src/dl-learner/org/dllearner/core/EvaluatedDescription.java 2008-08-06 09:53:31 UTC (rev 1055) @@ -83,6 +83,7 @@ /** * @see org.dllearner.core.owl.Description#getLength() + * @return Length of the description. */ public int getDescriptionLength() { return description.getLength(); @@ -185,8 +186,9 @@ // as arguments and does not use toString) private static JSONArray getJSONArray(Set<Individual> individuals) { JSONArray j = new JSONArray(); - for(Individual i : individuals) + for(Individual i : individuals) { j.put(i.getName()); + } return j; } } Modified: trunk/src/dl-learner/org/dllearner/core/owl/KBElement.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/owl/KBElement.java 2008-08-05 14:56:56 UTC (rev 1054) +++ trunk/src/dl-learner/org/dllearner/core/owl/KBElement.java 2008-08-06 09:53:31 UTC (rev 1055) @@ -10,6 +10,16 @@ */ public interface KBElement { + /** + * Gets the length of this knowledge base element. For instance, + * A AND B should have length 3 (as three constructs are involved). + * There are different ways to define the length of an axiom, + * class description etc., but this method provides a straightforward + * definition of it. + * + * @return The syntactic length of the KB element, defined as the + * number of syntactic constructs not including brackets. + */ public int getLength(); public String toString(String baseURI, Map<String,String> prefixes); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-05 14:57:01
|
Revision: 1054 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1054&view=rev Author: kurzum Date: 2008-08-05 14:56:56 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 10:45:13 UTC (rev 1053) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java 2008-08-05 14:56:56 UTC (rev 1054) @@ -122,12 +122,14 @@ json = SparqlQuery.convertResultSetToJSON(ResultSetFactory.makeRewindable(rs)); //writeToSparqlLog("JSON: " + json); - }catch (HTTPException e) { + //}catch (ResultSetException e) { + } catch (HTTPException e) { logger.warn("Exception in SparqlQuery\n"+ e.toString()); logger.warn("query was "+ sparqlQueryString); writeToSparqlLog("ERROR: HTTPException occured"+ e.toString()); writeToSparqlLog("ERROR: query was: "+sparqlQueryString); throw e; + }catch (RuntimeException e) { //if (!(e instanceof HTTPException)) { logger.warn("RuntimeException in SparqlQuery"+ e.toString()); @@ -317,4 +319,70 @@ } + /*** + public static String sendGetRequest(String urlStr) + { + String result = null; + + + try + { + StringBuffer data = new StringBuffer(); + + //String urlStr = endpoint; + // if (requestParameters != null && requestParameters.length () > 0) + //{ + //urlStr += "?" + requestParameters; + //} + //urlStr = "http://www.klappstuhlclub.de"; + URL url = new URL(urlStr); + System.out.println(urlStr); + URLConnection conn = url.openConnection (); + + // Get the response + BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); + StringBuffer sb = new StringBuffer(); + String line=""; + System.out.println("aa"+line); + while ((line = rd.readLine()) != null) + { + System.out.println("aa"+line); + sb.append(line); + } + rd.close(); + result = sb.toString(); + } catch (Exception e) + { + e.printStackTrace(); + } + + return result; + } + + public String fallback(){ + System.out.println("TEST"); + try{ + String urlStr = (sparqlEndpoint.getURL().toString()+"?query="+sparqlQueryString); + //URLConnection con = url.openConnection(); + System.out.println(sendGetRequest(urlStr)); + System.out.println("f"); + //System.out.println(con.getContentLength()); + //con.connect(); + System.out.println("sdf"); + String a = "12345"; + byte[] b = a.getBytes(); + //con.getInputStream().read(b); + System.out.println(new String (b)); + //Object o = con.getContent(); + //System.out.println(o+o.getClass().getCanonicalName()); + }catch (Exception ea) { + // TODO: handle exception + } + return ""; + } + + + + */ + } Modified: trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 10:45:13 UTC (rev 1053) +++ trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 14:56:56 UTC (rev 1054) @@ -2,8 +2,6 @@ import java.util.List; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; @@ -14,62 +12,84 @@ public class TestOneQueryForMusicRecommender { - private static Logger logger = Logger.getRootLogger(); + +static String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ +"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\">"+ +"<head> "+ +"<variable name=\"artist\"/>"+ +"<variable name=\"name\"/>"+ +"<variable name=\"image\"/>"+ +"<variable name=\"homepage\"/>"+ +"</head>"+ +"<results ordered=\"false\" distinct=\"false\">"+ +"<result>"+ + "<binding name=\"artist\">"+ + "<uri>http://dbtune.org/jamendo/artist/6108</uri>"+ + "</binding>"+ + "<binding name=\"name\">"+ + "<literal datatype=\"http://www.w3.org/2001/XMLSchema#string\">Allison Crowe</literal>"+ + "</binding>"+ + "<binding name=\"image\">"+ + "<uri>http://img.jamendo.com/artists/a/allison.crowe.jpg</uri>"+ + "</binding>"+ + "<binding name=\"homepage\">"+ + "<uri>http://www.allisoncrowe.com</uri>"+ + "</binding>"+ +"</result>"+ +"</results>"+ +"</sparql>"; + + public static void main(String[] args) { - Logger.getLogger(SparqlQuery.class).setLevel(Level.TRACE); - logger.info("Start"); - String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "; - p1 += "PREFIX mo: <http://purl.org/ontology/mo/> "; - String query1 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; - //String query2 = "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name 'Allison Crowe' .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; + + String p1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + + "PREFIX mo: <http://purl.org/ontology/mo/> "; + String sparqlQueryString = p1+ "SELECT ?artist ?name ?image ?homepage WHERE {?artist a mo:MusicArtist .?artist foaf:name \"Allison Crowe\" .?artist foaf:name ?name .?artist foaf:img ?image . ?artist foaf:homepage ?homepage . }LIMIT 10"; + System.out.println("SparqlQuery: "); + System.out.println(sparqlQueryString); + System.out.println("wget -S -O test.txt "+"'http://dbtune.org:2105/sparql/?query="+sparqlQueryString+"'"); + - SparqlEndpoint se = SparqlEndpoint.getEndpointJamendo(); - System.out.println(se.getURL()); - System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query1+"'"); - //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query2+"'"); - System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query1+"'"); - //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query2+"'"); - //System.out.println(se.getURL()+"?query="+query1); - //SparqlQuery s = new SparqlQuery(query1, se); - //s.send(); - //System.out.println(s.getJson()); - - - String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ -"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\">"+ - "<head>"+ - "<variable name=\"artist\"/>"+ - "<variable name=\"name\"/>"+ - "<variable name=\"image\"/>"+ - "<variable name=\"homepage\"/>"+ - "</head>"+ - "<results ordered=\"false\" distinct=\"false\">"+ - "<result>"+ - "<binding name=\"artist\">"+ - "<uri>http://dbtune.org/jamendo/artist/6108</uri>"+ - "</binding>"+ - "<binding name=\"name\">"+ - "<literal datatype=\"http://www.w3.org/2001/XMLSchema#string\">Allison Crowe</literal>"+ - "</binding>"+ - "<binding name=\"image\">"+ - "<uri>http://img.jamendo.com/artists/a/allison.crowe.jpg</uri>"+ - "</binding>"+ - "<binding name=\"homepage\">"+ - "<uri>http://www.allisoncrowe.com</uri>"+ - "</binding>"+ - "</result>"+ - "</results>"+ -"</sparql>"; - ResultSet rs = ResultSetFactory.fromXML(xml); List<ResultBinding> l = ResultSetFormatter.toList(rs); for (ResultBinding binding : l) { System.out.println(binding.toString()); } + + System.out.println("Executing query"); + rs = null; + //String service = "http://dbtune.org:2105/sparql/"; + //QueryEngineHTTP queryExecution = new QueryEngineHTTP(service, sparqlQueryString); + + try{ + SparqlQuery s = new SparqlQuery(sparqlQueryString, SparqlEndpoint.getEndpointJamendo()); + s.send(); + //rs = queryExecution.execSelect(); + + //ByteArrayOutputStream baos = new ByteArrayOutputStream(); + //ResultSetFormatter.outputAsJSON(baos, rs); + + + //System.out.println( baos.toString("UTF-8")); + } catch (Exception e) { + // should never happen as UTF-8 is supported + e.printStackTrace(); + + } + + + + + + + } + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jen...@us...> - 2008-08-05 10:45:16
|
Revision: 1053 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1053&view=rev Author: JensLehmann Date: 2008-08-05 10:45:13 +0000 (Tue, 05 Aug 2008) Log Message: ----------- updated checkstyle.xml to checkstyle 5 Modified Paths: -------------- trunk/doc/checkstyle.xml Modified: trunk/doc/checkstyle.xml =================================================================== --- trunk/doc/checkstyle.xml 2008-08-05 10:10:56 UTC (rev 1052) +++ trunk/doc/checkstyle.xml 2008-08-05 10:45:13 UTC (rev 1053) @@ -87,7 +87,7 @@ </module> <module name="AbstractClassName"/> </module> - <module name="PackageHtml"/> + <module name="JavadocPackage"/> <module name="NewlineAtEndOfFile"/> <module name="Translation"/> </module> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2008-08-05 10:11:05
|
Revision: 1052 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1052&view=rev Author: kurzum Date: 2008-08-05 10:10:56 +0000 (Tue, 05 Aug 2008) Log Message: ----------- new Jena release UPDATE CLASSPATH, CONFIGURE BUILD PATH commmons-logging-1.1 changed to 1.1.1 Modified Paths: -------------- trunk/lib/jena/arq.jar trunk/lib/jena/jena.jar Added Paths: ----------- trunk/lib/jena/commons-logging-1.1.1.jar Removed Paths: ------------- trunk/lib/jena/commons-logging-1.1.jar Property changes on: trunk/lib/jena/commons-logging-1.1.1.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: <ku...@us...> - 2008-08-05 10:04:11
|
Revision: 1051 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=1051&view=rev Author: kurzum Date: 2008-08-05 10:04:07 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java Modified: trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 09:50:39 UTC (rev 1050) +++ trunk/src/dl-learner/org/dllearner/test/TestOneQueryForMusicRecommender.java 2008-08-05 10:04:07 UTC (rev 1051) @@ -1,10 +1,17 @@ package org.dllearner.test; +import java.util.List; + import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.ResultSetFactory; +import com.hp.hpl.jena.query.ResultSetFormatter; +import com.hp.hpl.jena.sparql.core.ResultBinding; + public class TestOneQueryForMusicRecommender { private static Logger logger = Logger.getRootLogger(); @@ -24,11 +31,44 @@ //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+query2+"'"); System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query1+"'"); //System.out.println("wget -S -O test.txt '"+se.getURL()+"?query="+ p1+query2+"'"); - System.out.println(se.getURL()+"?query="+query1); - SparqlQuery s = new SparqlQuery(p1+query1, se); - s.send(); - System.out.println(s.getJson()); + //System.out.println(se.getURL()+"?query="+query1); + //SparqlQuery s = new SparqlQuery(query1, se); + //s.send(); + //System.out.println(s.getJson()); + + String xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+ +"<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\">"+ + "<head>"+ + "<variable name=\"artist\"/>"+ + "<variable name=\"name\"/>"+ + "<variable name=\"image\"/>"+ + "<variable name=\"homepage\"/>"+ + "</head>"+ + "<results ordered=\"false\" distinct=\"false\">"+ + "<result>"+ + "<binding name=\"artist\">"+ + "<uri>http://dbtune.org/jamendo/artist/6108</uri>"+ + "</binding>"+ + "<binding name=\"name\">"+ + "<literal datatype=\"http://www.w3.org/2001/XMLSchema#string\">Allison Crowe</literal>"+ + "</binding>"+ + "<binding name=\"image\">"+ + "<uri>http://img.jamendo.com/artists/a/allison.crowe.jpg</uri>"+ + "</binding>"+ + "<binding name=\"homepage\">"+ + "<uri>http://www.allisoncrowe.com</uri>"+ + "</binding>"+ + "</result>"+ + "</results>"+ +"</sparql>"; + + ResultSet rs = ResultSetFactory.fromXML(xml); + List<ResultBinding> l = ResultSetFormatter.toList(rs); + + for (ResultBinding binding : l) { + System.out.println(binding.toString()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |