From: <jen...@us...> - 2008-01-14 08:56:23
|
Revision: 369 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=369&view=rev Author: jenslehmann Date: 2008-01-14 00:56:17 -0800 (Mon, 14 Jan 2008) Log Message: ----------- started to merge the two SPARQL components Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.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 Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/SparqlCache.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/kb/SparqlQueryMaker.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/lib/components.ini 2008-01-14 08:56:17 UTC (rev 369) @@ -3,8 +3,7 @@ # knowledge sources org.dllearner.kb.OWLFile org.dllearner.kb.KBFile -org.dllearner.kb.SparqlEndpoint -org.dllearner.kb.SparqlEndpointRestructured +org.dllearner.kb.sparql.SparqlEndpoint # reasoners org.dllearner.reasoning.OWLAPIReasoner org.dllearner.reasoning.DIGReasoner Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-01-14 08:56:17 UTC (rev 369) @@ -61,7 +61,6 @@ import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; import org.dllearner.kb.SparqlEndpoint; -import org.dllearner.kb.SparqlEndpointRestructured; import org.dllearner.learningproblems.PosNegDefinitionLP; import org.dllearner.learningproblems.PosNegInclusionLP; import org.dllearner.learningproblems.PosOnlyDefinitionLP; @@ -231,7 +230,6 @@ Map<Class<? extends Component>, String> componentPrefixMapping = new HashMap<Class<? extends Component>, String>(); // knowledge sources componentPrefixMapping.put(SparqlEndpoint.class, "sparql"); - componentPrefixMapping.put(SparqlEndpointRestructured.class, "sparql2"); // reasoners componentPrefixMapping.put(DIGReasoner.class, "digReasoner"); componentPrefixMapping.put(OWLAPIReasoner.class, "owlAPIReasoner"); @@ -386,8 +384,6 @@ ksClass = KBFile.class; else if (formatString.equals("SPARQL")) ksClass = SparqlEndpoint.class; - else if (formatString.equals("SPARQL2")) - ksClass = SparqlEndpointRestructured.class; else if (formatString.equals("NT")) ksClass = OWLFile.class; else { Deleted: trunk/src/dl-learner/org/dllearner/kb/SparqlCache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlCache.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlCache.java 2008-01-14 08:56:17 UTC (rev 369) @@ -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; - -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/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2008-01-14 08:56:17 UTC (rev 369) @@ -1,342 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.kb; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.OntologyFormat; -import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; -import org.dllearner.core.config.StringSetConfigOption; -import org.dllearner.core.dl.KB; -import org.dllearner.parser.KBParser; -import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.utilities.Datastructures; - -/** - * Represents a SPARQL Endpoint. - * TODO: Is it necessary to create a class DBpediaSparqlEndpoint? - * - * @author Jens Lehmann - * @author Sebastian Knappe - */ -public class SparqlEndpoint extends KnowledgeSource { - - //ConfigOptions - private URL url; - private Set<String> instances; - private URL dumpFile; - private int numberOfRecursions; - private int filterMode; - private Set<String> predList; - private Set<String> objList; - private Set<String> classList; - private String format; - private boolean dumpToFile; - private boolean useLits=false; - - /** - * Holds the results of the calculateSubjects method - */ - private String[] subjects; - - /** - * Holds the results of the calculateTriples method - */ - private String[] triples; - - /** - * Holds the results of the calculateConceptSubjects method - */ - private String[] conceptSubjects; - - /** - * if a method is running this becomes true - */ - private boolean subjectThreadRunning=false; - - private boolean triplesThreadRunning=false; - - private boolean conceptThreadRunning=false; - - /** - * the Thread that is running a method - */ - private Thread subjectThread; - - private Thread triplesThread; - - private Thread conceptThread; - - //received ontology as array, used if format=Array(an element of the - //array consists of the subject, predicate and object separated by '<' - private String[] ontArray; - - //received ontology as KB, the internal format - private KB kb; - - public static String getName() { - return "SPARQL Endpoint"; - } - - /** - * sets the ConfigOptions for this KnowledgeSource - * @return - */ - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances","relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); - options.add(new IntegerConfigOption("filterMode","the mode of the SPARQL Filter")); - options.add(new StringSetConfigOption("predList","a predicate list")); - options.add(new StringSetConfigOption("objList","an object list")); - options.add(new StringSetConfigOption("classList","a class list")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format")); - options.add(new BooleanConfigOption("dumpToFile", "wether Ontology from DBPedia is written to a file or not")); - options.add(new BooleanConfigOption("useLits","use Literals in SPARQL query")); - return options; - } - - /* - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings({"unchecked"}) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String option = entry.getOptionName(); - if (option.equals("url")) { - String s = (String) entry.getValue(); - try { - url = new URL(s); - } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(),"malformed URL " + s); - } - } else if(option.equals("instances")) { - instances = (Set<String>) entry.getValue(); - } else if(option.equals("numberOfRecursions")){ - numberOfRecursions=(Integer)entry.getValue(); - } else if(option.equals("predList")) { - predList = (Set<String>) entry.getValue(); - } else if(option.equals("objList")) { - objList = (Set<String>) entry.getValue(); - } else if(option.equals("classList")) { - classList = (Set<String>) entry.getValue(); - } else if(option.equals("filterMode")){ - filterMode=(Integer)entry.getValue(); - } else if(option.equals("format")){ - format=(String)entry.getValue(); - } else if(option.equals("dumpToFile")){ - dumpToFile=(Boolean)entry.getValue(); - } else if(option.equals("useLits")){ - useLits=(Boolean)entry.getValue(); - } - } - - /* (non-Javadoc) - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - System.out.println("SparqlModul: Collecting Ontology"); - SparqlOntologyCollector oc=new SparqlOntologyCollector(Datastructures.setToArray(instances), numberOfRecursions, filterMode, - Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format,url,useLits); - - try - { - String ont=oc.collectOntology(); - - if (dumpToFile){ - String filename=System.currentTimeMillis()+".nt"; - String basedir="cache"+File.separator; - try{ - if(!new File(basedir).exists()) - new File(basedir).mkdir(); - - FileWriter fw=new FileWriter(new File(basedir+filename),true); - fw.write(ont); - fw.flush(); - fw.close(); - - dumpFile=(new File(basedir+filename)).toURI().toURL(); - }catch (Exception e) {e.printStackTrace();} - } - if (format.equals("KB")) { - try{ - // kb=KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); - } catch(Exception e) {e.printStackTrace();} - } - }catch(IOException e) { - e.printStackTrace(); - } - System.out.println("SparqlModul: ****Finished"); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ - @Override - public String toDIG(URI kbURI) { - if (format.equals("N-TRIPLES")) return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); - else return DIGConverter.getDIGString(kb, kbURI).toString(); - } - - /* (non-Javadoc) - * @see org.dllearner.core.KnowledgeSource#export(java.io.File, org.dllearner.core.OntologyFormat) - */ - @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { - // currently no export functions implemented, so we just throw an exception - throw new OntologyFormatUnsupportedException("export", format); - } - - public URL getURL() { - return url; - } - - public String[] getOntArray() { - return ontArray; - } - - public void calculateSubjects(String label,int limit) - { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc=new SparqlOntologyCollector(url); - try{ - subjects=oc.getSubjectsFromLabel(label,limit); - }catch (IOException e){ - subjects=new String[1]; - subjects[0]="[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); - SparqlOntologyCollector oc=new SparqlOntologyCollector(url); - try{ - triples=oc.collectTriples(subject); - }catch (IOException e){ - triples=new String[1]; - triples[0]="[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateConceptSubjects(String concept) - { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc=new SparqlOntologyCollector(url); - try{ - conceptSubjects=oc.getSubjectsFromConcept(concept); - }catch (IOException e){ - conceptSubjects=new String[1]; - conceptSubjects[0]="[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public boolean subjectThreadIsRunning() - { - return subjectThreadRunning; - } - - public void setSubjectThreadRunning(boolean bool) - { - subjectThreadRunning=bool; - } - - public boolean triplesThreadIsRunning() - { - return triplesThreadRunning; - } - - public void setTriplesThreadRunning(boolean bool) - { - triplesThreadRunning=bool; - } - - public boolean conceptThreadIsRunning() - { - return conceptThreadRunning; - } - - public void setConceptThreadRunning(boolean bool) - { - conceptThreadRunning=bool; - } - - public String[] getSubjects() - { - return subjects; - } - - public Thread getSubjectThread() { - return subjectThread; - } - - public void setSubjectThread(Thread subjectThread) { - this.subjectThread = subjectThread; - } - - public Thread getTriplesThread() { - return triplesThread; - } - - public void setTriplesThread(Thread triplesThread) { - this.triplesThread = triplesThread; - } - - public Thread getConceptThread() { - return conceptThread; - } - - public void setConceptThread(Thread conceptThread) { - this.conceptThread = conceptThread; - } - - public String[] getTriples() - { - return triples; - } - - public String[] getConceptSubjects() - { - return conceptSubjects; - } -} Copied: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java (from rev 367, trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpoint.java 2008-01-14 08:56:17 UTC (rev 369) @@ -0,0 +1,510 @@ +/** + * Copyright (C) 2007, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.kb; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; + +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.OntologyFormat; +import org.dllearner.core.OntologyFormatUnsupportedException; +import org.dllearner.core.config.BooleanConfigOption; +import org.dllearner.core.config.ConfigEntry; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.config.IntegerConfigOption; +import org.dllearner.core.config.InvalidConfigOptionValueException; +import org.dllearner.core.config.StringConfigOption; +import org.dllearner.core.config.StringSetConfigOption; +import org.dllearner.core.config.StringTupleListConfigOption; +import org.dllearner.core.dl.KB; +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.Manipulator; +import org.dllearner.kb.sparql.PredefinedEndpoint; +import org.dllearner.kb.sparql.PredefinedFilter; +import org.dllearner.kb.sparql.SparqlOntologyCollector; +import org.dllearner.kb.sparql.SparqlQueryType; +import org.dllearner.kb.sparql.SpecificSparqlEndpoint; +import org.dllearner.parser.KBParser; +import org.dllearner.reasoning.DIGConverter; +import org.dllearner.reasoning.JenaOWLDIGConverter; +import org.dllearner.utilities.StringTuple; + +/** + * Represents a SPARQL Endpoint. + * + * @author Jens Lehmann + * @author Sebastian Knappe + * @author Sebastian Hellmann + */ +public class SparqlEndpoint extends KnowledgeSource { + + // ConfigOptions + private URL url; + String host; + private Set<String> instances=new HashSet<String>();; + private URL dumpFile; + private int recursionDepth = 1; + private int predefinedFilter = 0; + private int predefinedEndpoint = 0; + private Set<String> predList=new HashSet<String>(); + private Set<String> objList=new HashSet<String>(); + // private Set<String> classList; + private String format = "N-TRIPLES"; + private boolean dumpToFile = true; + private boolean useLits = false; + private boolean getAllSuperClasses = true; + private boolean closeAfterRecursion = true; + private int breakSuperClassRetrievalAfter = 200; + + private boolean learnDomain = false; + private boolean learnRange = false; + private int numberOfInstancesUsedForRoleLearning=40; + private String role=""; + private String blankNodeIdentifier = "bnode"; + + LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); + LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); + + /** + * Holds the results of the calculateSubjects method + */ + private String[] subjects; + + /** + * Holds the results of the calculateTriples method + */ + private String[] triples; + + /** + * Holds the results of the calculateConceptSubjects method + */ + private String[] conceptSubjects; + + /** + * if a method is running this becomes true + */ + private boolean subjectThreadRunning = false; + + private boolean triplesThreadRunning = false; + + private boolean conceptThreadRunning = false; + + /** + * the Thread that is running a method + */ + private Thread subjectThread; + + private Thread triplesThread; + + private Thread conceptThread; + + // received ontology as array, used if format=Array(an element of the + // array consists of the subject, predicate and object separated by '<' + private String[] ontArray; + + // received ontology as KB, the internal format + private KB kb; + + public static String getName() { + return "SPARQL Endpoint Restructured"; + } + + /** + * sets the ConfigOptions for this KnowledgeSource + * + * @return + */ + public static Collection<ConfigOption<?>> createConfigOptions() { + Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); + options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); + options.add(new StringSetConfigOption("instances", + "relevant instances e.g. positive and negative examples in a learning problem")); + options.add(new IntegerConfigOption("recursionDepth", + "recursion depth of KB fragment selection", 2)); + options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); + options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); + + options.add(new StringSetConfigOption("predList", "list of all ignored roles")); + options.add(new StringSetConfigOption("objList", "list of all ignored objects")); + options.add(new StringSetConfigOption("classList", "list of all ignored classes")); + options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); + options.add(new BooleanConfigOption("dumpToFile", + "Specifies whether the extracted ontology is written to a file or not.", true)); + options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); + options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); + + options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); + options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); + options.add(new StringConfigOption("role", "role to learn Domain/Range from")); + options.add(new StringConfigOption("blankNodeIdentifier", + "used to identify blanknodes in Tripels")); + + options.add(new StringTupleListConfigOption("example", "example")); + options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); + options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); + options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); + options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); + options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); + + + + return options; + } + + /* + * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) + */ + @Override + @SuppressWarnings( { "unchecked" }) + public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { + String option = entry.getOptionName(); + if (option.equals("url")) { + String s = (String) entry.getValue(); + try { + url = new URL(s); + } catch (MalformedURLException e) { + throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), + "malformed URL " + s); + } + } else if (option.equals("host")) { + host = (String) entry.getValue(); + } else if (option.equals("instances")) { + instances = (Set<String>) entry.getValue(); + } else if (option.equals("recursionDepth")) { + recursionDepth = (Integer) entry.getValue(); + } else if (option.equals("predList")) { + predList = (Set<String>) entry.getValue(); + } else if (option.equals("objList")) { + objList = (Set<String>) entry.getValue(); + //} else if (option.equals("classList")) { + // classList = (Set<String>) entry.getValue(); + } else if (option.equals("predefinedEndpoint")) { + predefinedEndpoint = (Integer) entry.getValue(); + } else if (option.equals("predefinedFilter")) { + predefinedFilter = (Integer) entry.getValue(); + } else if (option.equals("format")) { + format = (String) entry.getValue(); + } else if (option.equals("dumpToFile")) { + dumpToFile = (Boolean) entry.getValue(); + } else if (option.equals("useLits")) { + useLits = (Boolean) entry.getValue(); + } else if (option.equals("getAllSuperClasses")) { + getAllSuperClasses = (Boolean) entry.getValue(); + } else if (option.equals("learnDomain")) { + learnDomain = (Boolean) entry.getValue(); + }else if (option.equals("learnRange")) { + learnRange = (Boolean) entry.getValue(); + } else if (option.equals("role")) { + role = (String) entry.getValue(); + } else if (option.equals("blankNodeIdentifier")) { + blankNodeIdentifier = (String) entry.getValue(); + } else if (option.equals("example")) { + //System.out.println(entry.getValue()); + }else if (option.equals("replacePredicate")) { + replacePredicate = (LinkedList)entry.getValue(); + }else if (option.equals("replaceObject")) { + replaceObject = (LinkedList)entry.getValue(); + }else if (option.equals("breakSuperClassRetrievalAfter")) { + breakSuperClassRetrievalAfter = (Integer) entry.getValue(); + }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { + numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); + }else if (option.equals("closeAfterRecursion")) { + closeAfterRecursion = (Boolean) entry.getValue(); + } + + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.Component#init() + */ + @Override + public void init() { + System.out.println("SparqlModul: Collecting Ontology"); + // SparqlOntologyCollector oc= + // new SparqlOntologyCollector(Datastructures.setToArray(instances), + // numberOfRecursions, filterMode, + // Datastructures.setToArray(predList),Datastructures.setToArray( + // objList),Datastructures.setToArray(classList),format,url,useLits); + Manager m = new Manager(); + SpecificSparqlEndpoint sse = null; + SparqlQueryType sqt = null; + // get Options for Manipulator + Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("default-graph-uri", "http://dbpedia.org"); + parameters.put("format", "application/sparql-results.xml"); + + // get Options for endpoints + if (predefinedEndpoint >= 1) { + sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); + } else { + sse = new SpecificSparqlEndpoint(url, host, parameters); + } + + // get Options for Filters + + if (predefinedFilter >= 1) { + sqt = PredefinedFilter.getFilter(predefinedFilter); + + } else { + sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); + + } + // give everything to the manager + m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); + try { + String ont = ""; + //System.out.println(learnDomain); + // used to learn a domain of a role + if (learnDomain || learnRange) { + Set<String> pos=new HashSet<String>(); + Set<String> neg=new HashSet<String>(); + if(learnDomain){ + pos = m.getDomainInstancesForRole(role); + neg = m.getRangeInstancesForRole(role); + }else if(learnRange){ + neg = m.getDomainInstancesForRole(role); + pos = m.getRangeInstancesForRole(role); + } + //choose 30 + + + Set<String> tmp=new HashSet<String>(); + for(String one:pos){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + pos=tmp; + System.out.println("Instances used: "+pos.size()); + + tmp=new HashSet<String>(); + for(String one:neg){ + tmp.add(one); + if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; + } + neg=tmp; + + instances=new HashSet<String>(); + instances.addAll(pos); + + instances.addAll(neg); + + for(String one:pos){ + System.out.println("+\""+one+"\""); + } + for(String one:neg){ + System.out.println("-\""+one+"\""); + } + + /*Random r= new Random(); + + + Object[] arr=instances.toArray(); + while(instances.size()>=30){ + + }*/ + // add the role to the filter(a solution is always EXISTS + // role.TOP) + m.addPredicateFilter(role); + //System.out.println(instances); + // THIS is a workaround + + } + // the actual extraction is started here + ont = m.extract(instances); + System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); + System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); + + System.out.println("Finished collecting Fragment"); + + if (dumpToFile) { + String filename = System.currentTimeMillis() + ".nt"; + String basedir = "cache" + File.separator; + try { + if (!new File(basedir).exists()) + new File(basedir).mkdir(); + + FileWriter fw = new FileWriter(new File(basedir + filename), true); + fw.write(ont); + fw.flush(); + fw.close(); + + dumpFile = (new File(basedir + filename)).toURI().toURL(); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (format.equals("KB")) { + try { + //kb = KBParser.parseKBFile(new StringReader(ont)); + kb=KBParser.parseKBFile(dumpFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("SparqlModul: ****Finished"); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ + @Override + public String toDIG(URI kbURI) { + if (format.equals("N-TRIPLES")) + return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); + else + return DIGConverter.getDIGString(kb, kbURI).toString(); + } + + /* + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#export(java.io.File, + * org.dllearner.core.OntologyFormat) + */ + @Override + public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { + // currently no export functions implemented, so we just throw an + // exception + throw new OntologyFormatUnsupportedException("export", format); + } + + public URL getURL() { + return url; + } + + public String[] getOntArray() { + return ontArray; + } + + public void calculateSubjects(String label, int limit) { + System.out.println("SparqlModul: Collecting Subjects"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + subjects = oc.getSubjectsFromLabel(label, limit); + } catch (IOException e) { + subjects = new String[1]; + subjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public void calculateTriples(String subject) { + System.out.println("SparqlModul: Collecting Triples"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + triples = oc.collectTriples(subject); + } catch (IOException e) { + triples = new String[1]; + triples[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public void calculateConceptSubjects(String concept) { + System.out.println("SparqlModul: Collecting Subjects"); + SparqlOntologyCollector oc = new SparqlOntologyCollector(url); + try { + conceptSubjects = oc.getSubjectsFromConcept(concept); + } catch (IOException e) { + conceptSubjects = new String[1]; + conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; + } + System.out.println("SparqlModul: ****Finished"); + } + + public boolean subjectThreadIsRunning() { + return subjectThreadRunning; + } + + public void setSubjectThreadRunning(boolean bool) { + subjectThreadRunning = bool; + } + + public boolean triplesThreadIsRunning() { + return triplesThreadRunning; + } + + public void setTriplesThreadRunning(boolean bool) { + triplesThreadRunning = bool; + } + + public boolean conceptThreadIsRunning() { + return conceptThreadRunning; + } + + public void setConceptThreadRunning(boolean bool) { + conceptThreadRunning = bool; + } + + public String[] getSubjects() { + return subjects; + } + + public Thread getSubjectThread() { + return subjectThread; + } + + public void setSubjectThread(Thread subjectThread) { + this.subjectThread = subjectThread; + } + + public Thread getTriplesThread() { + return triplesThread; + } + + public void setTriplesThread(Thread triplesThread) { + this.triplesThread = triplesThread; + } + + public Thread getConceptThread() { + return conceptThread; + } + + public void setConceptThread(Thread conceptThread) { + this.conceptThread = conceptThread; + } + + public String[] getTriples() { + return triples; + } + + public String[] getConceptSubjects() { + return conceptSubjects; + } +} Deleted: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2008-01-14 08:56:17 UTC (rev 369) @@ -1,509 +0,0 @@ -/** - * Copyright (C) 2007, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ -package org.dllearner.kb; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; - -import org.dllearner.core.KnowledgeSource; -import org.dllearner.core.OntologyFormat; -import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.BooleanConfigOption; -import org.dllearner.core.config.ConfigEntry; -import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.config.IntegerConfigOption; -import org.dllearner.core.config.InvalidConfigOptionValueException; -import org.dllearner.core.config.StringConfigOption; -import org.dllearner.core.config.StringSetConfigOption; -import org.dllearner.core.config.StringTupleListConfigOption; -import org.dllearner.core.dl.KB; -import org.dllearner.kb.sparql.Manager; -import org.dllearner.kb.sparql.Manipulator; -import org.dllearner.kb.sparql.PredefinedEndpoint; -import org.dllearner.kb.sparql.PredefinedFilter; -import org.dllearner.kb.sparql.SparqlQueryType; -import org.dllearner.kb.sparql.SpecificSparqlEndpoint; -import org.dllearner.parser.KBParser; -import org.dllearner.reasoning.DIGConverter; -import org.dllearner.reasoning.JenaOWLDIGConverter; -import org.dllearner.utilities.StringTuple; - -/** - * Represents a SPARQL Endpoint. - * - * @author Jens Lehmann - * @author Sebastian Knappe - * @author Sebastian Hellmann - */ -public class SparqlEndpointRestructured extends KnowledgeSource { - - // ConfigOptions - private URL url; - String host; - private Set<String> instances=new HashSet<String>();; - private URL dumpFile; - private int recursionDepth = 1; - private int predefinedFilter = 0; - private int predefinedEndpoint = 0; - private Set<String> predList=new HashSet<String>(); - private Set<String> objList=new HashSet<String>(); - private Set<String> classList; - private String format = "N-TRIPLES"; - private boolean dumpToFile = true; - private boolean useLits = false; - private boolean getAllSuperClasses = true; - private boolean closeAfterRecursion = true; - private int breakSuperClassRetrievalAfter = 200; - - private boolean learnDomain = false; - private boolean learnRange = false; - private int numberOfInstancesUsedForRoleLearning=40; - private String role=""; - private String blankNodeIdentifier = "bnode"; - - LinkedList<StringTuple> URIParameters = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replacePredicate = new LinkedList<StringTuple>(); - LinkedList<StringTuple> replaceObject = new LinkedList<StringTuple>(); - - /** - * Holds the results of the calculateSubjects method - */ - private String[] subjects; - - /** - * Holds the results of the calculateTriples method - */ - private String[] triples; - - /** - * Holds the results of the calculateConceptSubjects method - */ - private String[] conceptSubjects; - - /** - * if a method is running this becomes true - */ - private boolean subjectThreadRunning = false; - - private boolean triplesThreadRunning = false; - - private boolean conceptThreadRunning = false; - - /** - * the Thread that is running a method - */ - private Thread subjectThread; - - private Thread triplesThread; - - private Thread conceptThread; - - // received ontology as array, used if format=Array(an element of the - // array consists of the subject, predicate and object separated by '<' - private String[] ontArray; - - // received ontology as KB, the internal format - private KB kb; - - public static String getName() { - return "SPARQL Endpoint Restructured"; - } - - /** - * sets the ConfigOptions for this KnowledgeSource - * - * @return - */ - public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); - options.add(new StringConfigOption("url", "URL of SPARQL Endpoint")); - options.add(new StringConfigOption("host", "host of SPARQL Endpoint")); - options.add(new StringSetConfigOption("instances", - "relevant instances e.g. positive and negative examples in a learning problem")); - options.add(new IntegerConfigOption("recursionDepth", - "recursion depth of KB fragment selection", 2)); - options.add(new IntegerConfigOption("predefinedFilter", "the mode of the SPARQL Filter")); - options.add(new IntegerConfigOption("predefinedEndpoint", "the mode of the SPARQL Filter")); - - options.add(new StringSetConfigOption("predList", "list of all ignored roles")); - options.add(new StringSetConfigOption("objList", "list of all ignored objects")); - options.add(new StringSetConfigOption("classList", "list of all ignored classes")); - options.add(new StringConfigOption("format", "N-TRIPLES or KB format", "N-TRIPLES")); - options.add(new BooleanConfigOption("dumpToFile", - "Specifies whether the extracted ontology is written to a file or not.", true)); - options.add(new BooleanConfigOption("useLits", "use Literals in SPARQL query")); - options.add(new BooleanConfigOption("getAllSuperClasses", "If true then all superclasses are retrieved until the most general class (owl:Thing) is reached.", true)); - - options.add(new BooleanConfigOption("learnDomain", "learns the Domain for a Role")); - options.add(new BooleanConfigOption("learnRange", "learns the Range for a Role")); - options.add(new StringConfigOption("role", "role to learn Domain/Range from")); - options.add(new StringConfigOption("blankNodeIdentifier", - "used to identify blanknodes in Tripels")); - - options.add(new StringTupleListConfigOption("example", "example")); - options.add(new StringTupleListConfigOption("replacePredicate", "rule for replacing predicates")); - options.add(new StringTupleListConfigOption("replaceObject", "rule for replacing predicates")); - options.add(new IntegerConfigOption("breakSuperClassRetrievalAfter", "stops a cyclic hierarchy after specified number of classes")); - options.add(new IntegerConfigOption("numberOfInstancesUsedForRoleLearning", "")); - options.add(new BooleanConfigOption("closeAfterRecursion", "gets all classes for all instances")); - - - - return options; - } - - /* - * @see org.dllearner.core.Component#applyConfigEntry(org.dllearner.core.ConfigEntry) - */ - @Override - @SuppressWarnings( { "unchecked" }) - public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - String option = entry.getOptionName(); - if (option.equals("url")) { - String s = (String) entry.getValue(); - try { - url = new URL(s); - } catch (MalformedURLException e) { - throw new InvalidConfigOptionValueException(entry.getOption(), entry.getValue(), - "malformed URL " + s); - } - } else if (option.equals("host")) { - host = (String) entry.getValue(); - } else if (option.equals("instances")) { - instances = (Set<String>) entry.getValue(); - } else if (option.equals("recursionDepth")) { - recursionDepth = (Integer) entry.getValue(); - } else if (option.equals("predList")) { - predList = (Set<String>) entry.getValue(); - } else if (option.equals("objList")) { - objList = (Set<String>) entry.getValue(); - } else if (option.equals("classList")) { - classList = (Set<String>) entry.getValue(); - } else if (option.equals("predefinedEndpoint")) { - predefinedEndpoint = (Integer) entry.getValue(); - } else if (option.equals("predefinedFilter")) { - predefinedFilter = (Integer) entry.getValue(); - } else if (option.equals("format")) { - format = (String) entry.getValue(); - } else if (option.equals("dumpToFile")) { - dumpToFile = (Boolean) entry.getValue(); - } else if (option.equals("useLits")) { - useLits = (Boolean) entry.getValue(); - } else if (option.equals("getAllSuperClasses")) { - getAllSuperClasses = (Boolean) entry.getValue(); - } else if (option.equals("learnDomain")) { - learnDomain = (Boolean) entry.getValue(); - }else if (option.equals("learnRange")) { - learnRange = (Boolean) entry.getValue(); - } else if (option.equals("role")) { - role = (String) entry.getValue(); - } else if (option.equals("blankNodeIdentifier")) { - blankNodeIdentifier = (String) entry.getValue(); - } else if (option.equals("example")) { - //System.out.println(entry.getValue()); - }else if (option.equals("replacePredicate")) { - replacePredicate = (LinkedList)entry.getValue(); - }else if (option.equals("replaceObject")) { - replaceObject = (LinkedList)entry.getValue(); - }else if (option.equals("breakSuperClassRetrievalAfter")) { - breakSuperClassRetrievalAfter = (Integer) entry.getValue(); - }else if (option.equals("numberOfInstancesUsedForRoleLearning")) { - numberOfInstancesUsedForRoleLearning = (Integer) entry.getValue(); - }else if (option.equals("closeAfterRecursion")) { - closeAfterRecursion = (Boolean) entry.getValue(); - } - - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.Component#init() - */ - @Override - public void init() { - System.out.println("SparqlModul: Collecting Ontology"); - // SparqlOntologyCollector oc= - // new SparqlOntologyCollector(Datastructures.setToArray(instances), - // numberOfRecursions, filterMode, - // Datastructures.setToArray(predList),Datastructures.setToArray( - // objList),Datastructures.setToArray(classList),format,url,useLits); - Manager m = new Manager(); - SpecificSparqlEndpoint sse = null; - SparqlQueryType sqt = null; - // get Options for Manipulator - Manipulator man = new Manipulator(blankNodeIdentifier,breakSuperClassRetrievalAfter,replacePredicate,replaceObject); - HashMap<String, String> parameters = new HashMap<String, String>(); - parameters.put("default-graph-uri", "http://dbpedia.org"); - parameters.put("format", "application/sparql-results.xml"); - - // get Options for endpoints - if (predefinedEndpoint >= 1) { - sse = PredefinedEndpoint.getEndpoint(predefinedEndpoint); - } else { - sse = new SpecificSparqlEndpoint(url, host, parameters); - } - - // get Options for Filters - - if (predefinedFilter >= 1) { - sqt = PredefinedFilter.getFilter(predefinedFilter); - - } else { - sqt = new SparqlQueryType("forbid", objList, predList, useLits + ""); - - } - // give everything to the manager - m.useConfiguration(sqt, sse, man, recursionDepth, getAllSuperClasses,closeAfterRecursion); - try { - String ont = ""; - //System.out.println(learnDomain); - // used to learn a domain of a role - if (learnDomain || learnRange) { - Set<String> pos=new HashSet<String>(); - Set<String> neg=new HashSet<String>(); - if(learnDomain){ - pos = m.getDomainInstancesForRole(role); - neg = m.getRangeInstancesForRole(role); - }else if(learnRange){ - neg = m.getDomainInstancesForRole(role); - pos = m.getRangeInstancesForRole(role); - } - //choose 30 - - - Set<String> tmp=new HashSet<String>(); - for(String one:pos){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - pos=tmp; - System.out.println("Instances used: "+pos.size()); - - tmp=new HashSet<String>(); - for(String one:neg){ - tmp.add(one); - if(tmp.size()>=numberOfInstancesUsedForRoleLearning)break; - } - neg=tmp; - - instances=new HashSet<String>(); - instances.addAll(pos); - - instances.addAll(neg); - - for(String one:pos){ - System.out.println("+\""+one+"\""); - } - for(String one:neg){ - System.out.println("-\""+one+"\""); - } - - /*Random r= new Random(); - - - Object[] arr=instances.toArray(); - while(instances.size()>=30){ - - }*/ - // add the role to the filter(a solution is always EXISTS - // role.TOP) - m.addPredicateFilter(role); - //System.out.println(instances); - // THIS is a workaround - - } - // the actual extraction is started here - ont = m.extract(instances); - System.out.println("Number of cached SPARQL queries: "+m.getConfiguration().numberOfCachedSparqlQueries); - System.out.println("Number of uncached SPARQL queries: "+m.getConfiguration().numberOfUncachedSparqlQueries); - - System.out.println("Finished collecting Fragment"); - - if (dumpToFile) { - String filename = System.currentTimeMillis() + ".nt"; - String basedir = "cache" + File.separator; - try { - if (!new File(basedir).exists()) - new File(basedir).mkdir(); - - FileWriter fw = new FileWriter(new File(basedir + filename), true); - fw.write(ont); - fw.flush(); - fw.close(); - - dumpFile = (new File(basedir + filename)).toURI().toURL(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (format.equals("KB")) { - try { - //kb = KBParser.parseKBFile(new StringReader(ont)); - kb=KBParser.parseKBFile(dumpFile); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("SparqlModul: ****Finished"); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ - @Override - public String toDIG(URI kbURI) { - if (format.equals("N-TRIPLES")) - return JenaOWLDIGConverter.getTellsString(dumpFile, OntologyFormat.N_TRIPLES, kbURI); - else - return DIGConverter.getDIGString(kb, kbURI).toString(); - } - - /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#export(java.io.File, - * org.dllearner.core.OntologyFormat) - */ - @Override - public void export(File file, OntologyFormat format) throws OntologyFormatUnsupportedException { - // currently no export functions implemented, so we just throw an - // exception - throw new OntologyFormatUnsupportedException("export", format); - } - - public URL getURL() { - return url; - } - - public String[] getOntArray() { - return ontArray; - } - - public void calculateSubjects(String label, int limit) { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - subjects = oc.getSubjectsFromLabel(label, limit); - } catch (IOException e) { - subjects = new String[1]; - subjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateTriples(String subject) { - System.out.println("SparqlModul: Collecting Triples"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - triples = oc.collectTriples(subject); - } catch (IOException e) { - triples = new String[1]; - triples[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public void calculateConceptSubjects(String concept) { - System.out.println("SparqlModul: Collecting Subjects"); - SparqlOntologyCollector oc = new SparqlOntologyCollector(url); - try { - conceptSubjects = oc.getSubjectsFromConcept(concept); - } catch (IOException e) { - conceptSubjects = new String[1]; - conceptSubjects[0] = "[Error]Sparql Endpoint could not be reached."; - } - System.out.println("SparqlModul: ****Finished"); - } - - public boolean subjectThreadIsRunning() { - return subjectThreadRunning; - } - - public void setSubjectThreadRunning(boolean bool) { - subjectThreadRunning = bool; - } - - public boolean triplesThreadIsRunning() { - return triplesThreadRunning; - } - - public void setTriplesThreadRunning(boolean bool) { - triplesThreadRunning = bool; - } - - public boolean conceptThreadIsRunning() { - return conceptThreadRunning; - } - - public void setConceptThreadRunning(boolean bool) { - conceptThreadRunning = bool; - } - - public String[] getSubjects() { - return subjects; - } - - public Thread getSubjectThread() { - return subjectThread; - } - - public void setSubjectThread(Thread subjectThread) { - this.subjectThread = subjectThread; - } - - public Thread getTriplesThread() { - return triplesThread; - } - - public void setTriplesThread(Thread triplesThread) { - this.triplesThread = triplesThread; - } - - public Thread getConceptThread() { - return conceptThread; - } - - public void setConceptThread(Thread conceptThread) { - this.conceptThread = conceptThread; - } - - public String[] getTriples() { - return triples; - } - - public String[] getConceptSubjects() { - return conceptSubjects; - } -} Deleted: trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlFilter.java 2008-01-14 08:56:17 UTC (rev 369) @@ -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; - -/** - * - * - * 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; - 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 Deleted: trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java 2008-01-13 10:22:16 UTC (rev 368) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java 2008-01-14 08:56:17 UTC (rev 369) @@ -1,509 +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; - -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; - - -/** - * This class collects the ontology from dbpedia, - * everything is saved in hashsets, so the doublettes are taken care of - * - * - * @author Sebastia... [truncated message content] |