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] |