From: <ku...@us...> - 2007-09-05 11:34:29
|
Revision: 131 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=131&view=rev Author: kurzum Date: 2007-09-05 04:34:25 -0700 (Wed, 05 Sep 2007) Log Message: ----------- updated all comments for javadoc Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/modules/sparql/Cache.java trunk/src/dl-learner/org/dllearner/modules/sparql/OntologyCollector.java trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java trunk/src/dl-learner/org/dllearner/modules/sparql/QueryMaker.java trunk/src/dl-learner/org/dllearner/modules/sparql/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlFilter.java trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/Cache.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/Cache.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.io.File; @@ -7,11 +26,23 @@ 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 + * + */ public class Cache implements Serializable{ - // Object can be the cache itself - // or a cache object(one entry) + final static long serialVersionUID=104; transient String basedir=""; transient String fileending=".cache"; @@ -21,7 +52,13 @@ long multiplier=24*60*60*1000;//h m s ms String sparqlquery=""; - //constructor for the cache itself + + /** + * Constructor for the cache itself. + * Called once at the beginning + * + * @param path Where the base path to the cache is + */ public Cache(String path){ this.basedir=path+File.separator; if(!new File(path).exists()) @@ -29,14 +66,28 @@ } -// constructor for single cache object(one entry) - public Cache(String c, String sparql){ - this.content=c; +// + /** + * Constructor for single cache object(one entry) + * + * @param content the sparql xml result + * @param sparql the sparql query + */ + public Cache(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){ //System.out.println("get From "+key); String ret=null; @@ -51,7 +102,16 @@ 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){ //System.out.println("put into "+key); Cache c=new Cache(content,sparql); @@ -59,6 +119,12 @@ } + /** + * to normalize the filenames + * + * @param key + * @return + */ String makeFilename(String key){ String ret=""; try{ @@ -66,12 +132,24 @@ }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 @@ -79,6 +157,10 @@ else return false; } + /** + * makes a new file if none exists + * @param Filename + */ public void checkFile(String Filename){ if(!new File(Filename).exists()){ try{ @@ -89,6 +171,13 @@ } + /** + * internal saving function + * puts a cache object into a file + * + * @param Filename + * @param content + */ public void putIntoFile(String Filename,Cache content){ try{ //FileWriter fw=new FileWriter(new File(Filename),true); @@ -100,6 +189,12 @@ }catch (Exception e) {System.out.println("Not in cache creating: "+Filename);} } + /** + * internal retrieval function + * + * @param Filename + * @return one entry object + */ public Cache readFromFile(String Filename){ Cache content=null; try{ Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/OntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/OntologyCollector.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/OntologyCollector.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.net.InetAddress; @@ -5,6 +24,14 @@ import java.util.HashSet; import java.util.Iterator; +/** + * This class collects the ontology from dbpedia, + * everything is saved in hashsets, so the doublettes are taken care of + * + * + * @author Sebastian Hellmann + * + */ public class OntologyCollector { boolean print_flag=false; @@ -20,6 +47,7 @@ HashSet<String> instances; HashSet<String> triples; + // 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"; @@ -35,6 +63,16 @@ "http://dbpedia.org/class/"}; //TODO FEHLER hier fehlt yago + /** + * + * + * @param subjectList + * @param numberOfRecursions + * @param filterMode + * @param FilterPredList + * @param FilterObjList + * @param defClasses + */ public OntologyCollector(String[] subjectList,int numberOfRecursions, int filterMode, String[] FilterPredList,String[] FilterObjList,String[] defClasses){ this.subjectList=subjectList; @@ -59,6 +97,12 @@ }catch (Exception e) {e.printStackTrace();} } + /** + * first collects the ontology + * then types everything so it becomes owl-dl + * + * @return all triples in n-triple format + */ public String collectOntology(){ getRecursiveList(subjectList, numberOfRecursions); finalize(); @@ -70,6 +114,11 @@ return ret; } + /** + * calls getRecursive for each subject in list + * @param subjects + * @param NumberofRecursions + */ public void getRecursiveList(String[] subjects,int NumberofRecursions){ for (int i = 0; i < subjects.length; i++) { getRecursive(subjects[i], NumberofRecursions); @@ -78,6 +127,12 @@ } + /** + * gets all triples until numberofrecursion-- gets 0 + * + * @param StartingSubject + * @param NumberofRecursions + */ public void getRecursive(String StartingSubject,int NumberofRecursions){ System.out.print("SparqlModul: Depth: "+NumberofRecursions+" @ "+StartingSubject+" "); if(NumberofRecursions<=0) @@ -90,8 +145,10 @@ String sparql=q.makeQueryFilter(StartingSubject,this.sf); p(sparql); p("*******************"); + // checks cache String FromCache=c.get(StartingSubject, sparql); String xml; + // if not in cache get it from dbpedia if(FromCache==null){ xml=s.sendAndReceive(ia, 8890, sparql); c.put(StartingSubject, xml, sparql); @@ -103,6 +160,7 @@ } p(xml); p("***********************"); + // get new Subjects String[] newSubjects=processResult(StartingSubject,xml); for (int i = 0; (i < newSubjects.length)&& NumberofRecursions!=0; i++) { @@ -114,6 +172,14 @@ } + /** + * 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>"; @@ -131,12 +197,14 @@ xml=xml.substring(xml.indexOf(two)+two.length()); objtmp=xml.substring(0,xml.indexOf(end)); - + // writes the triples and resources in the hashsets + // also fills the arraylist al processTriples(subject, predtmp, objtmp,al); //System.out.println(al.size()); } + // convert al to list Object[] o=al.toArray(); String[] ret=new String[o.length]; for (int i = 0; i < o.length; i++) { @@ -146,7 +214,20 @@ //return (String[])al.toArray(); //System.out.println(xml); } - public void processTriples(String s,String p, String o,ArrayList<String> al){ + + + + /** + * + * writes the triples and resources in the hashsets + * also fills the arraylist al with new individals for further processing + * @param s + * @param p + * @param o + * @param al + */ + public void processTriples(String s,String p, String o,ArrayList<String> al){ + // the next two lines bump out some inconsistencies within dbpedia String t="/Category"; if(s.equals(t) || o.equals(t))return ; @@ -169,6 +250,7 @@ //save for further processing al.add(o); + // type classes if(isClass(o)){ classes.add(o); if(isClass(s))p=subclass; @@ -190,7 +272,15 @@ return; } -// also makes subclass property between classes +// + /** + * also makes subclass property between classes + * + * @param s + * @param p + * @param o + * @return triple in the n triple notation + */ public String makeTriples(String s,String p, String o){ //s=replaceNamespace(s); //p=replaceNamespace(p); @@ -200,6 +290,12 @@ return ret; } + /** + * decides if an object is treated as a class + * + * @param obj + * @return true if obj is in the defaultClassesList + */ public boolean isClass(String obj){ boolean retval=false; @@ -209,7 +305,10 @@ return retval; } - + + /** + * @see java.lang.Object#finalize() + */ @Override public void finalize(){ typeProperties(); @@ -253,6 +352,10 @@ } } + /** + * debug print turn on print_flag + * @param s + */ public void p(String s){ if(print_flag) System.out.println(s); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/PartialOntology.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.io.File; @@ -17,6 +36,13 @@ import org.dllearner.modules.PreprocessingModule; +/** + * + * old class, originally thought to extract just the owl-dl ontology from dbpedia + * + * @author Sebastian Hellmann + * + */ public class PartialOntology implements PreprocessingModule { SimpleHTTPRequest s; QueryMaker q; Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/QueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/QueryMaker.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/QueryMaker.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,5 +1,31 @@ +/** + * 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.modules.sparql; +/** + * + * This class produces sparql queries + * + * @author Sebastian Hellmann + * + */ public class QueryMaker { //Good /*public static String owl ="http://www.w3.org/2002/07/owl#"; @@ -19,13 +45,14 @@ public static String sameAs="http://www.w3.org/2002/07/owl#sameAs"; public static String reference="http://dbpedia.org/property/reference";*/ - - int tempyago=0; - - - + /** + * reads all the options and makes the sparql query accordingly + * @param subject + * @param sf special object encapsulating all options + * @return sparql query + */ public String makeQueryFilter(String subject, SparqlFilter sf){ @@ -75,9 +102,21 @@ return ret; }*/ + /** + * add a new object filter + * (objects are filtered out of sparql result) + * @param ns namespace + * @return + */ public String filterObject(String ns){ return "&&( !regex((?object), '"+ns+"') )"; } + /** + * add a new object filter + * (objects are filtered out of sparql result) + * @param ns namespace + * * @return + */ public String filterPredicate(String ns){ return "&&( !regex(str(?predicate), '"+ns+"') )"; } Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SimpleHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SimpleHTTPRequest.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SimpleHTTPRequest.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.io.BufferedInputStream; @@ -9,6 +28,15 @@ +/** + * + * This class makes a simple http request + * the dbpedia url is hardcoded + * + * @author Sebastian Hellmann + * + * + */ public class SimpleHTTPRequest { static final char value[]={13,10}; static final String cut=new String(value); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlFilter.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlFilter.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlFilter.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,5 +1,33 @@ +/** + * 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.modules.sparql; +/** + * + * + * encapsulates all the options + * see the documentation for more help + * + * @author Sebastian Hellmann + * + */ public class SparqlFilter { public int mode=0; // 0 yago, 1 only cat, 2 skos+cat @@ -63,7 +91,7 @@ ObjFilter=onlyCatObjFilterDefault; PredFilter=onlyCatPredFilterDefault; break; - case 2: + case 2: // there are some other changes to, which are made directly in other functions ObjFilter=skosObjFilterDefault; PredFilter=skosPredFilterDefault; break; Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/SparqlModule.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.io.File; @@ -17,6 +36,13 @@ import org.dllearner.modules.PreprocessingModule; +/** + * implements the module + * like a main function + * + * @author Sebastian Hellmann + * + */ public class SparqlModule implements PreprocessingModule { FileWriter fw; @@ -27,10 +53,19 @@ +/** +* @return current version + */ public String getModuleName(){ return "Sparql Module v0.3"; } + /** + * + * implements the required function + * sets up everything, reads the option collects the ontology, writes it to a file + * + */ public void preprocess(KB kb, Map<AtomicConcept, SortedSet<Individual>> positiveExamples, Map<AtomicConcept, SortedSet<Individual>> negativeExamples, @@ -93,7 +128,7 @@ } }// end for System.out.println("SparqlModul: Processing finished"); - // subject for which information is drafted from wikipedia + // subjects for which information is drafted from wikipedia String[] subjectList=makeSubjectList(prefix, positiveExamples, negativeExamples); Modified: trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java =================================================================== --- trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-09-05 09:59:01 UTC (rev 130) +++ trunk/src/dl-learner/org/dllearner/modules/sparql/Util.java 2007-09-05 11:34:25 UTC (rev 131) @@ -1,3 +1,22 @@ +/** + * 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.modules.sparql; import java.util.HashSet; @@ -4,9 +23,21 @@ import java.util.Iterator; import java.util.Set; +/** + * mainly converts datatypes + * + * @author Sebastian Hellmann + * + */ public class Util { + /** + * easy conversion + * + * @param s + * @return + */ public static String[] setToArray(Set<String> s){ if(s==null)return null; String[] ret=new String[s.size()]; @@ -20,6 +51,11 @@ } + /** + * Warning use only for visualization + * @param s + * @return String without certain namespaces + */ public static String replaceNamespace(String s){ s=s.replace("http://dbpedia.org/class/yago/", "yago:"); s=s.replace("http://dbpedia.org/class/", "yago2:"); @@ -32,6 +68,10 @@ return s; } + /** + * prints a hashset to stdout + * @param h + */ public static void printHashSet(HashSet<String> h){ Iterator<String> it=h.iterator(); String current=""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |