From: <ku...@us...> - 2008-01-18 08:43:29
|
Revision: 385 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=385&view=rev Author: kurzum Date: 2008-01-18 00:43:11 -0800 (Fri, 18 Jan 2008) Log Message: ----------- changed package structure Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQueryClasses.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/ trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/configuration/SpecificSparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/datastructure/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/ trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlCache.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/sparql/old/oldSparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/ trunk/src/dl-learner/org/dllearner/kb/sparql/query/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/query/TestSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQuery.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,235 +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.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.URLEncoder; -import java.util.HashMap; - -/** - * SPARQL query cache to avoid possibly expensive multiple queries. An object of - * this class can be the cache itself or a cache object(one entry), We could - * split that in two classes, but one entry o object only has contains data and - * one additional function and would just be a data class - * - * it writes the files according to one resource in the basedir and saves the - * cache object in it. Filename is the subject, a resource - * e.g. http://dbpedia.org/resource/Angela_Merkel which is first urlencoded - * and so serves as the hash for the filename. - * - * the cache object in the file remembers: a timestamp, - * a hashmap SparqlQuery -> SparqlXMLResult - * Cache validates if timestamp too old and Sparql-Query the same - * before returning the SPARQL xml-result - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - */ -public class Cache implements Serializable { - - /** - * This maps sparql query to sparql result - */ - protected HashMap<String, String> hm; - - final static long serialVersionUID = 104; - transient String basedir = ""; - transient String fileending = ".cache"; - transient boolean debug_print_flag = false; - long timestamp; - /** - * After how many days cache entries get invalid - */ - protected long daysoffreshness = 15; - protected long multiplier = 24 * 60 * 60 * 1000;// h m s ms - - // private HashMap<String, String> inmem_cache; - - // - /** - * constructor for the cache itself - * Called once at the startup - * @param path - * Where the base path to the cache is - */ - public Cache(String path) { - this.basedir = path + File.separator; - if (!new File(path).exists()) { - System.out.println("created directory: " + path + " : " - + new File(path).mkdir()); - - } - } - - - /** - * constructor for single cache object(one entry) - * @param sparqlQuery - * query - * @param content - * that is the sparql query result as xml - */ - protected Cache(String sparqlQuery, String content) { - // this.content = c; - // this.sparqlquery = sparql; - this.timestamp = System.currentTimeMillis(); - this.hm = new HashMap<String, String>(); - hm.put(sparqlQuery, content); - } - - /** - * gets a chached sparqlQuery for a resource(key) and returns the - * sparqlXMLResult or null, if none is found. - * - * @param key - * is the resource, the identifier - * @param sparqlQuery - * is a special sparql query about that resource - * @return sparqlXMLResult - */ - public String get(String key, String sparqlQuery) { - // System.out.println("get From "+key); - String ret = null; - try { - Cache c = readFromFile(makeFilename(key)); - if (c == null) - return null; - // System.out.println(" file found"); - if (!c.checkFreshness()) - return null; - // System.out.println("fresh"); - String xml = ""; - try { - xml = c.hm.get(sparqlQuery); - } catch (Exception e) { - return null; - } - return xml; - // System.out.println("valid"); - // ret = c.content; - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - /** - * @param key - * is the resource, the identifier - * @param sparqlquery - * is the query used as another identifier - * @param content - * is the result of the query - */ - public void put(String key, String sparqlquery, String content) { - // System.out.println("put into "+key); - Cache c = readFromFile(makeFilename(key)); - if (c == null) { - c = new Cache(sparqlquery, content); - putIntoFile(makeFilename(key), c); - } else { - c.hm.put(sparqlquery, content); - putIntoFile(makeFilename(key), c); - } - - } - - /** - * this function takes a resource string and then URIencodes it and makes a - * filename out of it for the use in the hashmap - * - * @param key - * @return the complete key for filename in the hashmap - */ - protected String makeFilename(String key) { - String ret = ""; - try { - ret = basedir + URLEncoder.encode(key, "UTF-8") + fileending; - } catch (Exception e) { - e.printStackTrace(); - } - return ret; - } - - public void checkFile(String Filename) { - if (!new File(Filename).exists()) { - try { - new File(Filename).createNewFile(); - } catch (Exception e) { - e.printStackTrace(); - } - - } - - } - - /** - * puts a cache entry in a file - * - * @param Filename - * @param c - */ - protected void putIntoFile(String Filename, Cache c) { - try { - // FileWriter fw=new FileWriter(new File(Filename),true); - FileOutputStream fos = new FileOutputStream(Filename, false); - ObjectOutputStream o = new ObjectOutputStream(fos); - o.writeObject(c); - fos.flush(); - fos.close(); - } catch (Exception e) { - System.out.println("Not in cache creating: " + Filename); - } - } - - /** - * reads a cache entry from a file - * - * @param Filename - * @return cache entry - */ - protected Cache readFromFile(String Filename) { - Cache content = null; - try { - FileInputStream fos = new FileInputStream(Filename); - ObjectInputStream o = new ObjectInputStream(fos); - content = (Cache) o.readObject(); - // FileReader fr=new FileReader(new File(Filename,"r")); - // BufferedReader br=new BufferedReader(fr); - } catch (Exception e) { - } - return content; - - } - - protected boolean checkFreshness() { - if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) - // fresh - return true; - else - return false; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,113 +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.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * Is a node in the graph that is a class. - * - * @author Sebastian Hellmann - */ -public class ClassNode extends Node { - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public ClassNode(URI u) { - super(u); - this.type = "class"; - } - - //expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - Set<StringTuple> s = tsq.query(this.uri); - // see manipulator - s = m.check(s, this); - Vector<Node> Nodes = new Vector<Node>(); - - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - // substitute rdf:type with owl:subclassof - if (t.a.equals(m.type) || t.a.equals(m.subclass)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(m.subclass), this, tmp)); - Nodes.add(tmp); - } else { - // further expansion stops here - // Nodes.add(tmp); is missing on purpose - ClassNode tmp = new ClassNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(t.a), this, tmp)); - // System.out.println(m.blankNodeIdentifier); - // System.out.println("XXXXX"+t.b); - - // if o is a blank node expand further - if (t.b.startsWith(m.blankNodeIdentifier)) { - tmp.expand(tsq, m); - System.out.println(m.blankNodeIdentifier); - System.out.println("XXXXX" + t.b); - } - // Nodes.add(tmp); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - // TODO return type doesn't make sense - return new Vector<Node>(); - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + this.uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Class" + ">."); - - for (PropertyNode one : properties) { - s.add("<" + this.uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - // - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,94 +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; - -/** - * Stores all configuration settings. - * - * @author Sebastian Hellmann - */ -public class Configuration { - - /* - * this class colects all configuration information - * see the other classes, which are used as attributes here - * */ - - private SpecificSparqlEndpoint specificSparqlEndpoint; - private SparqlQueryType sparqlQueryType; - private Manipulator manipulator; - // the following needs to be moved to - // class extraction algorithm or manipulator - private int recursiondepth = 2; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - public int numberOfUncachedSparqlQueries=0; - public int numberOfCachedSparqlQueries=0; - - public Configuration(SpecificSparqlEndpoint specificSparqlEndpoint, - SparqlQueryType sparqlQueryType, Manipulator manipulator, int recursiondepth, - boolean getAllSuperClasses, boolean closeAfterRecursion) { - this.specificSparqlEndpoint = specificSparqlEndpoint; - this.sparqlQueryType = sparqlQueryType; - this.manipulator = manipulator; - this.recursiondepth = recursiondepth; - this.getAllSuperClasses = getAllSuperClasses; - this.closeAfterRecursion=closeAfterRecursion; - - } - - public Configuration changeQueryType(SparqlQueryType sqt) { - // TODO must clone here - return new Configuration(this.specificSparqlEndpoint, sqt, this.manipulator, - this.recursiondepth, this.getAllSuperClasses,this.closeAfterRecursion); - - } - - public Manipulator getManipulator() { - return this.manipulator; - } - - public SpecificSparqlEndpoint getSparqlEndpoint() { - return specificSparqlEndpoint; - } - - public SparqlQueryType getSparqlQueryType() { - return sparqlQueryType; - } - - public boolean isGetAllSuperClasses() { - return getAllSuperClasses; - } - public boolean isCloseAfterRecursion() { - return closeAfterRecursion; - } - - public int getRecursiondepth() { - return recursiondepth; - } - - public void increaseNumberOfuncachedSparqlQueries(){ - numberOfUncachedSparqlQueries++; - } - public void increaseNumberOfCachedSparqlQueries(){ - numberOfCachedSparqlQueries++; - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2008-01-18 08:43:11 UTC (rev 385) @@ -23,6 +23,11 @@ import java.util.HashSet; import java.util.Vector; +import org.dllearner.kb.sparql.configuration.Configuration; +import org.dllearner.kb.sparql.datastructure.ClassNode; +import org.dllearner.kb.sparql.datastructure.InstanceNode; +import org.dllearner.kb.sparql.datastructure.Node; + /** * This class is used to extract the information recursively. * @@ -127,10 +132,10 @@ //classes.remove(next); Node next = classes.remove(0); - if(!hadAlready.contains(next.uri.toString())){ + if(!hadAlready.contains(next.getURI().toString())){ p("Expanding: " + next); //System.out.println(hadAlready.size()); - hadAlready.add(next.uri.toString()); + hadAlready.add(next.getURI().toString()); tmp=next.expand(tsp, manipulator); classes.addAll(tmp); tmp=new Vector<Node>(); Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,118 +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.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * A node in the graph that is an instance. - * - * @author Sebastian Hellmann - * - */ -public class InstanceNode extends Node { - - Set<ClassNode> classes = new HashSet<ClassNode>(); - Set<StringTuple> datatypes = new HashSet<StringTuple>(); - Set<PropertyNode> properties = new HashSet<PropertyNode>(); - - public InstanceNode(URI u) { - super(u); - this.type = "instance"; - - } - - //expands all directly connected nodes - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - - Set<StringTuple> s = tsq.query(uri); - // see Manipulator - m.check(s, this); - // System.out.println("fffffff"+m); - Vector<Node> Nodes = new Vector<Node>(); - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - // basically : if p is rdf:type then o is a class - // else it is an instance - try { - if (t.a.equals(m.type)) { - ClassNode tmp = new ClassNode(new URI(t.b)); - classes.add(tmp); - Nodes.add(tmp); - } else { - InstanceNode tmp = new InstanceNode(new URI(t.b)); - properties.add(new PropertyNode(new URI(t.a), this, tmp)); - Nodes.add(tmp); - - } - } catch (Exception e) { - System.out.println("Problem with: " + t); - e.printStackTrace(); - } - - } - expanded = true; - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - for (PropertyNode one : properties) { - one.expandProperties(tsq, m); - } - return new Vector<Node>(); - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#Thing" + ">."); - for (ClassNode one : classes) { - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one.getURI() + ">."); - s.addAll(one.toNTriple()); - } - for (PropertyNode one : properties) { - s.add("<" + uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); - s.addAll(one.toNTriple()); - s.addAll(one.getB().toNTriple()); - } - - return s; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - // - } - -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2008-01-18 08:43:11 UTC (rev 385) @@ -25,6 +25,10 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.kb.sparql.configuration.Configuration; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.datastructure.Node; import org.dllearner.utilities.StringTuple; /** Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2008-01-18 08:43:11 UTC (rev 385) @@ -24,6 +24,9 @@ import java.util.LinkedList; import java.util.Set; +import org.dllearner.kb.sparql.datastructure.ClassNode; +import org.dllearner.kb.sparql.datastructure.InstanceNode; +import org.dllearner.kb.sparql.datastructure.Node; import org.dllearner.utilities.StringTuple; /** Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,64 +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.net.URI; -import java.util.Set; -import java.util.Vector; - -/** - * Abstract class. - * - * @author Sebastian Hellmann - * - */ -public abstract class Node implements Comparable<Node> { - URI uri; - protected String type; - protected boolean expanded = false; - - public Node(URI u) { - this.uri = u; - } - - public abstract Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m); - - public abstract Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m); - - public abstract Set<String> toNTriple(); - - @Override - public String toString() { - return "Node: " + uri + ":" + type; - - } - - 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()); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedEndpoint.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,167 +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.net.URL; -import java.util.HashMap; - -/** - * Holds some predefined endpoints. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedEndpoint { - public static SpecificSparqlEndpoint getEndpoint(int i) { - - switch (i) { - case 1: - return dbpediaEndpoint(); - case 2: - return localJoseki(); - case 3: - return govTrack(); - case 4: - return revyu(); - case 5: - return myopenlink(); - case 6: - return worldFactBook(); - } - return null; - } - - public static SpecificSparqlEndpoint dbpediaEndpoint() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://dbpedia.org"); - m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://dbpedia.openlinksw.com:8890/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); - } - - public static SpecificSparqlEndpoint localJoseki() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://localhost:2020/books"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "localhost", m); - } - public static SpecificSparqlEndpoint worldFactBook() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/factbook/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - - /* - * it only has 4 classes - public static SpecificSparqlEndpoint dblp() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www4.wiwiss.fu-berlin.de/dblp/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www4.wiwiss.fu-berlin.de", m); - } - */ - public static SpecificSparqlEndpoint govTrack() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - try { - u = new URL("http://www.rdfabout.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "www.rdfabout.com", m); - } - public static SpecificSparqlEndpoint revyu() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://revyu.com/sparql?query=SELECT DISTINCT * WHERE {[] a ?c} - try { - u = new URL("http://revyu.com/sparql"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "revyu.com", m); - } - - // returns strange xml - /*public static SpecificSparqlEndpoint dbtune() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - // m.put("default-graph-uri", "http://dbpedia.org"); - // m.put("format", "application/sparql-results.xml"); - //http://dbtune.org:2020/sparql/?query=SELECT DISTINCT * WHERE {[] a ?c}Limit 10 - http://dbtune.org:2020/evaluateQuery?repository=default&serialization=rdfxml&queryLanguage=SPARQL&query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - http://dbtune.org:2020/evaluateQuery - ?repository=default&serialization=rdfxml&queryLanguage=SPARQL - &query=SELECT+DISTINCT+*+WHERE+%7B%5B%5D+a+%3Fc%7D - &resultFormat=xml - &resourceFormat=ns&entailment=none - try { - u = new URL("http://dbtune.org:2020/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "dbtune.org", m); - }*/ - - public static SpecificSparqlEndpoint myopenlink() { - URL u = null; - HashMap<String, String> m = new HashMap<String, String>(); - m.put("default-graph-uri", "http://myopenlink.net/dataspace"); - m.put("format", "application/sparql-results.xml"); - //http://myopenlink.net:8890/sparql/?query=select+distinct+%3FConcept+where+%7B%5B%5D+a+%3FConcept%7D - try { - u = new URL("http://myopenlink.net:8890/sparql/"); - } catch (Exception e) { - e.printStackTrace(); - } - return new SpecificSparqlEndpoint(u, "myopenlink.net", m); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedFilter.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,170 +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; - -/** - * Predefined filters. - * - * @author Sebastian Hellmann - * - */ -public class PredefinedFilter { - - - public static SparqlQueryType getFilter(int i) { - - switch (i) { - case 1: - return YagoFilter(); - case 2: - return SKOS(); - case 3: - return YAGOSKOS(); - case 4: - return YagoSpecialHierarchy(); - } - 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"); - - 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 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"); - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,120 +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.net.URI; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import org.dllearner.utilities.StringTuple; - -/** - * Property node. - * - * @author Sebastian Hellmann - * - */ -public class PropertyNode extends Node { - - // the a and b part of a property - private Node a; - private Node b; - // specialtypes like owl:symmetricproperty - private Set<String> specialTypes; - - public PropertyNode(URI u) { - super(u); - this.type = "property"; - - } - - public PropertyNode(URI u, Node a, Node b) { - super(u); - this.type = "property"; - this.a = a; - this.b = b; - this.specialTypes = new HashSet<String>(); - } - - @Override - public Vector<Node> expand(TypedSparqlQueryInterface tsq, Manipulator m) { - Set<StringTuple> s = tsq.query(uri); - Vector<Node> Nodes = new Vector<Node>(); - // Manipulation - - Iterator<StringTuple> it = s.iterator(); - while (it.hasNext()) { - StringTuple t = (StringTuple) it.next(); - try { - if (t.a.equals(m.type)) { - specialTypes.add(t.b); - } - } catch (Exception e) { - System.out.println(t); - e.printStackTrace(); - } - - } - return Nodes; - } - - // gets the types for properties recursively - @Override - public Vector<Node> expandProperties(TypedSparqlQueryInterface tsq, Manipulator m) { - b.expandProperties(tsq, m); - return this.expand(tsq, m); - } - - public Node getA() { - return a; - } - - public Node getB() { - return b; - } - - @Override - public Set<String> toNTriple() { - Set<String> s = new HashSet<String>(); - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + "http://www.w3.org/2002/07/owl#ObjectProperty" + ">."); - for (String one : specialTypes) { - s.add("<" + uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" - + one + ">."); - - } - - return s; - } - - @Override - public boolean equals(Node n){ - if(this.uri.equals(n.uri))return true; - else return false; - } - - @Override - public int compareTo(Node n){ - return super.compareTo(n); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlCache.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,202 +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.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.net.URLEncoder; -/** - * - * This is a primitive cache. - * The objects of this class can be either the cache itself or just on entry in the cache - * - * the cache remembers: a timestamp, the original sparql-query, the result - * key is the subject http://dbpedia.org/resource/Angela_Merkel which is first urlencoded - * and so serves as the hash for the filename. - * Cache validates if timestamp too old and Sparql-Query the same - * before returning the SPARQL xml-result - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - */ -public class SparqlCache implements Serializable{ - - final static long serialVersionUID=104; - transient String basedir=""; - transient String fileending=".cache"; - long timestamp; - String content=""; - long daysoffreshness=15; - long multiplier=24*60*60*1000;//h m s ms - String sparqlquery=""; - - - /** - * Constructor for the cache itself. - * Called once at the beginning - * - * @param path Where the base path to the cache is - */ - public SparqlCache(String path){ - this.basedir=path+File.separator; - if(!new File(path).exists()) - {System.out.println(new File(path).mkdir());;} - - } - -// - /** - * Constructor for single cache object(one entry) - * - * @param content the sparql xml result - * @param sparql the sparql query - */ - public SparqlCache(String content, String sparql){ - this.content=content; - this.sparqlquery=sparql; - this.timestamp=System.currentTimeMillis(); - } - - - - /** - * use only on the cache object describing the cache itself - * - * @param key the individual - * @param sparql the sparql query - * @return the cached sparql result or null - */ - public String get(String key, String sparql){ - String ret=null; - try{ - SparqlCache c =readFromFile(makeFilename(key)); - if(c==null)return null; - if(!c.checkFreshness())return null; - if(!c.validate(sparql))return null; - - ret=c.content; - }catch (Exception e) {e.printStackTrace();} - return ret; - } - - /** - * - * constructor for single cache object(one entry) - * - * @param key the individual - * @param content the sparql result - * @param sparql the sparql query - */ - public void put(String key, String content, String sparql){ - SparqlCache c=new SparqlCache(content,sparql); - putIntoFile(makeFilename(key), c); - } - - - /** - * to normalize the filenames - * - * @param key - * @return - */ - String makeFilename(String key){ - String ret=""; - try{ - ret=basedir+URLEncoder.encode(key, "UTF-8")+fileending; - }catch (Exception e) {e.printStackTrace();} - return ret; - } - - /** - * how old is the result - * @return - */ - boolean checkFreshness(){ - if((System.currentTimeMillis()-this.timestamp)<=(daysoffreshness*multiplier)) - //fresh - return true; - else return false; - } - - - /** - * some sparql query - * @param sparql - * @return - */ - boolean validate(String sparql){ - if(this.sparqlquery.equals(sparql)) - //valid - return true; - else return false; - } - - /** - * makes a new file if none exists - * @param Filename - */ - public void checkFile(String Filename){ - if(!new File(Filename).exists()){ - try{ - new File(Filename).createNewFile(); - }catch (Exception e) {e.printStackTrace();} - - } - - } - - /** - * internal saving function - * puts a cache object into a file - * - * @param Filename - * @param content - */ - public void putIntoFile(String Filename,SparqlCache content){ - try{ - FileOutputStream fos = new FileOutputStream( Filename , false ); - ObjectOutputStream o = new ObjectOutputStream( fos ); - o.writeObject( content ); - fos.flush(); - fos.close(); - }catch (Exception e) {System.out.println("Not in cache creating: "+Filename);} - } - - /** - * internal retrieval function - * - * @param Filename - * @return one entry object - */ - public SparqlCache readFromFile(String Filename){ - SparqlCache content=null; - try{ - FileInputStream fos = new FileInputStream( Filename ); - ObjectInputStream o = new ObjectInputStream( fos ); - content=(SparqlCache)o.readObject(); - }catch (Exception e) {} - return content; - - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlFilter.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,119 +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; - -/** - * - * - * encapsulates all the options - * see the documentation for more help - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - * - */ -public class SparqlFilter { - public int mode=0; - // 0 yago, 1 only cat, 2 skos+cat - String[] PredFilter=null; - String[] ObjFilter=null; - public boolean useLiterals=false; - - - String[] yagoPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] yagoObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/resource/Category", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - String[] onlyCatPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] onlyCatObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - String[] skosPredFilterDefault={ - "http://www.w3.org/2004/02/skos/core#narrower", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/property/wikipage-", - "http://www.w3.org/2002/07/owl#sameAs", - "http://dbpedia.org/property/reference" }; - String[] skosObjFilterDefault={ - "http://dbpedia.org/resource/Category:Articles_", - "http://dbpedia.org/resource/Category:Wikipedia_", - "http://xmlns.com/foaf/0.1/", - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Template", - "http://upload.wikimedia.org/wikipedia/commons"}; - - public SparqlFilter(int mode, String[] pred, String[] obj) { - if (mode==-1 && (pred==null || obj==null)) - {mode=0;} - this.mode=mode; - - switch (mode){ - case 0: //yago - ObjFilter=yagoObjFilterDefault; - PredFilter=yagoPredFilterDefault; - break; - case 1: // only Categories - ObjFilter=onlyCatObjFilterDefault; - PredFilter=onlyCatPredFilterDefault; - break; - case 2: // there are some other changes to, which are made directly in other functions - ObjFilter=skosObjFilterDefault; - PredFilter=skosPredFilterDefault; - break; - default: - ObjFilter=obj; - PredFilter=pred; - break; - } - } - - public SparqlFilter(int mode, String[] pred, String[] obj,boolean uselits) throws Exception{ - this(mode,pred,obj); - this.useLiterals=uselits; - } - - public String[] getObjFilter(){ - return this.ObjFilter; - } - - public String[] getPredFilter(){ - return this.PredFilter; - } -} \ No newline at end of file Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2008-01-18 08:43:11 UTC (rev 385) @@ -43,6 +43,11 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.config.StringTupleListConfigOption; import org.dllearner.core.dl.KB; +import org.dllearner.kb.sparql.configuration.PredefinedEndpoint; +import org.dllearner.kb.sparql.configuration.PredefinedFilter; +import org.dllearner.kb.sparql.configuration.SparqlQueryType; +import org.dllearner.kb.sparql.configuration.SpecificSparqlEndpoint; +import org.dllearner.kb.sparql.old.SparqlOntologyCollector; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java 2008-01-18 08:14:37 UTC (rev 384) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlOntologyCollector.java 2008-01-18 08:43:11 UTC (rev 385) @@ -1,511 +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.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Vector; - -import org.dllearner.kb.sparql.SparqlQueryMaker; - - -/** - * This class collects the ontology from dbpedia, - * everything is saved in hashsets, so the doublettes are taken care of - * - * - * @author Sebastian Hellmann - * @author Sebastian Knappe - * - */ -public class SparqlOntologyCollector { - - boolean print_flag=false; - SparqlQueryMaker queryMaker; - SparqlCache cache; - URL url; - SparqlFilter sf; - String[] subjectList; - int numberOfRecursions; - HashSet<String> properties; - HashSet<String> classes; - HashSet<String> instances; - HashSet<String> triples; - String format; - - // some namespaces - String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - String type="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; - String objectProperty="http://www.w3.org/2002/07/owl#ObjectProperty"; - String classns="http://www.w3.org/2002/07/owl#Class"; - String thing="http://www.w3.org/2002/07/owl#Thing"; - - - String[] defaultClasses={ - "http://dbpedia.org/class/yago", - "http://dbpedia.org/resource/Category:", - "http://dbpedia.org/resource/Template:", - "http://www.w3.org/2004/02/skos/core", - "http://dbpedia.org/class/"}; - - - /** - * - * - * @param subjectList - * @param numberOfRecursions - * @param filterMode - * @param FilterPredList - * @param FilterObjList - * @param defClasses - */ - public SparqlOntologyCollector(String[] subjectList,int numberOfRecursions, - int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses, String format, URL url, boolean useLits){ - this.subjectList=subjectList; - this.numberOfRecursions=numberOfRecursions; - this.format=format; - //this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); - if(defClasses!=null && defClasses.length>0 ){ - this.defaultClasses=defClasses; - } - try{ - this.sf=new SparqlFilter(filterMode,FilterPredList,FilterObjList,useLits); - this.url=url; - this.properties=new HashSet<String>(); - this.classes=new HashSet<String>(); - this.instances=new HashSet<String>(); - this.triples=new HashSet<String>(); - }catch (Exception e) {e.printStackTrace();} - - } - - public SparqlOntologyCollector(URL url) - { - // this.queryMaker=new SparqlQueryMaker(); - this.cache=new SparqlCache("cache"); - this.url=url; - } - - /** - * first collects the ontology - * then types everything so it becomes owl-dl - * - * @return all triples in n-triple format - */ - public String collectOntology() throws IOException{ - getRecursiveList(subjectList, numberOfRecursions); - finalize(); - String ret=""; - for (Iterator<String> iter = triples.iterator(); iter.hasNext();) { - ret += iter.next(); - } - return ret; - } - - public String[] collectTriples(String subject) throws IOException{ - System.out.println("Searching for Article: "+subject); - String sparql=SparqlQueryMaker.makeArticleQuery(subject); - String fromCache=cache.get(subject, sparql); - String xml; - // if not in cache get it from dbpedia - if(fromCache==null){ - xml=sendAndReceive(sparql); - cache.put(subject, xml, sparql); - System.out.print("\n"); - } - else{ - xml=fromCache; - System.out.println("FROM CACHE"); - } - - return processArticle(xml); - } - - public String[] processArticle(String xml) - { - Vector<String> vec=new Vector<String>(); - String one="<binding name=\"predicate\"><uri>"; - String two="<binding name=\"object\">"; - String end="</uri></binding>"; - String predtmp=""; - String objtmp=""; - // ArrayList<String> al=new ArrayList<String>(); - while(xml.indexOf(one)!=-1){ - //get pred - xml=xml.substring(xml.indexOf(one)+one.length()); - predtmp=xml.substring(0,xml.indexOf(end)); - //getobj - xml=xml.substring(xml.indexOf(two)+two.length()); - if (xml.startsWith("<literal xml:lang=\"en\">")){ - xml=xml.substring(xml.indexOf(">")+1); - objtmp=xml.substring(0,xml.indexOf("</literal>")); - } - else if (xml.startsWith("<uri>")) objtmp=xml.substring(5,xml.indexOf(end)); - else continue; - - System.out.println("Pred: "+predtmp+" Obj: "+objtmp); - - vec.add(predtmp+"<"+objtmp); - } - - String[] ret=new String[vec.size()]; - return vec.toArray(ret); - } - - public String[] getSubjectsFromLabel(String label, int limit) throws IOException{ - System.out.println("Searching for Label: "+label); - String sparql=SparqlQueryMaker.makeLabelQuery(label,limit); - String FromCache=cache.get(label, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(label, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - return processSubjects(xml); - } - - public String[] getSubjectsFromConcept(String concept) throws IOException - { - System.out.println("Searching for Subjects of type: "+concept); - String sparql=SparqlQueryMaker.makeConceptQuery(concept); - String FromCache=cache.get(concept, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(concept, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - return processSubjects(xml); - } - - /** - * calls getRecursive for each subject in list - * @param subjects - * @param NumberofRecursions - */ - public void getRecursiveList(String[] subjects,int NumberofRecursions) throws IOException{ - for (int i = 0; i < subjects.length; i++) { - getRecursive(subjects[i], NumberofRecursions); - } - } - - /** - * gets all triples until numberofrecursion-- gets 0 - * - * @param StartingSubject - * @param NumberofRecursions - */ - public void getRecursive(String StartingSubject,int NumberofRecursions) throws IOException{ - System.out.print("SparqlModul: Depth: "+NumberofRecursions+" @ "+StartingSubject+" "); - if(NumberofRecursions<=0) - return; - else {NumberofRecursions--;} - - String sparql=SparqlQueryMaker.makeQueryFilter(StartingSubject,this.sf); - // checks cache - String FromCache=cache.get(StartingSubject, sparql); - String xml; - // if not in cache get it from dbpedia - if(FromCache==null){ - xml=sendAndReceive(sparql); - cache.put(StartingSubject, xml, sparql); - System.out.print("\n"); - } - else{ - xml=FromCache; - System.out.println("FROM CACHE"); - } - - // get new Subjects - String[] newSubjects=processResult(StartingSubject,xml); - - for (int i = 0; (i < newSubjects.length)&& NumberofRecursions!=0; i++) { - getRecursive(newSubjects[i], NumberofRecursions); - } - } - - /** - * process the sparql result xml in a simple manner - * - * - * @param subject - * @param xml - * @return list of new individuals - */ - public String[] processResult(String subject,String xml){ - //TODO if result is empty, catch exceptions - String one="<binding name=\"predicate\"><uri>"; - String two="<binding name=\"object\">"; - String end="</uri></binding>"; - String predtmp=""; - String objtmp=""; - ArrayList<String> al=new ArrayList<String>(); - while(xml.indexOf(one)!=-1){ - //get pred - xml=xml.substring(xml.indexOf(one)+one.length()); - predtmp=xml.substring(0,... [truncated message content] |