You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <jen...@us...> - 2007-12-02 14:34:18
|
Revision: 302 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=302&view=rev Author: jenslehmann Date: 2007-12-02 06:34:12 -0800 (Sun, 02 Dec 2007) Log Message: ----------- more code cleanup Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-02 14:34:12 UTC (rev 302) @@ -16,7 +16,7 @@ @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(this.URI); + Set<Tupel> s = tsq.query(this.uri); s = m.check(s, this); Vector<Node> Nodes = new Vector<Node>(); // Manipulation @@ -47,11 +47,11 @@ @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" + "><" + 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.add("<" + this.uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); s.addAll(one.getB().toNTriple()); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 14:34:12 UTC (rev 302) @@ -5,15 +5,15 @@ public class ExtractionAlgorithm { - private Configuration Configuration; - private Manipulator Manipulator; - private int recursiondepth = 2; + private Configuration configuration; + private Manipulator manipulator; + private int recursionDepth = 2; private boolean getAllBackground = true; public ExtractionAlgorithm(Configuration Configuration) { - this.Configuration = Configuration; - this.Manipulator = Configuration.getManipulator(); - this.recursiondepth=Configuration.getRecursiondepth(); + this.configuration = Configuration; + this.manipulator = Configuration.getManipulator(); + this.recursionDepth=Configuration.getRecursiondepth(); this.getAllBackground=Configuration.isGetAllBackground(); } @@ -37,14 +37,14 @@ System.out.println("StartVector: " + v); // n.expand(tsp, this.Manipulator); // Vector<Node> second= - for (int x = 1; x <= this.recursiondepth; x++) { + for (int x = 1; x <= this.recursionDepth; x++) { Vector<Node> tmp = new Vector<Node>(); while (v.size() > 0) { Node tmpNode = v.remove(0); System.out.println("Expanding " + tmpNode); //System.out.println(this.Manipulator); - Vector<Node> tmpVec = tmpNode.expand(tsp, this.Manipulator); + Vector<Node> tmpVec = tmpNode.expand(tsp, this.manipulator); tmp.addAll(tmpVec); } @@ -62,7 +62,7 @@ System.out.println(classes.size()); Node next=classes.remove(0); System.out.println(next); - classes.addAll(next.expand(tsp, this.Manipulator)); + classes.addAll(next.expand(tsp, this.manipulator)); } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 14:34:12 UTC (rev 302) @@ -21,7 +21,7 @@ @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(this.URI); + Set<Tupel> s = tsq.query(this.uri); // Manipulation m.check(s, this); //System.out.println("fffffff"+m); @@ -60,15 +60,15 @@ @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" + "><" + s.add("<" + this.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("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + s.add("<" + this.uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + one.getURI() + ">."); s.addAll(one.toNTriple()); } for (PropertyNode one : properties) { - s.add("<" + this.URI + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.add("<" + this.uri + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); s.addAll(one.toNTriple()); s.addAll(one.getB().toNTriple()); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 14:34:12 UTC (rev 302) @@ -6,9 +6,9 @@ public class Manager { - private Configuration Configuration; - private TypedSparqlQuery TypedSparqlQuery; - private ExtractionAlgorithm ExtractionAlgorithm; + private Configuration configuration; + private TypedSparqlQuery typedSparqlQuery; + private ExtractionAlgorithm extractionAlgorithm; /*public void usePredefinedConfiguration(URI uri) { @@ -19,23 +19,23 @@ public void usePredefinedConfiguration(int i) { - this.Configuration = PredefinedConfigurations.get(i); - this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + this.configuration = PredefinedConfigurations.get(i); + this.typedSparqlQuery = new TypedSparqlQuery(configuration); + this.extractionAlgorithm = new ExtractionAlgorithm(configuration); } public void useConfiguration(SparqlQueryType SparqlQueryType, SpecificSparqlEndpoint SparqlEndpoint, int recursiondepth,boolean getAllBackground) { - this.Configuration = new Configuration(SparqlEndpoint, SparqlQueryType,recursiondepth,getAllBackground); - this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + this.configuration = new Configuration(SparqlEndpoint, SparqlQueryType,recursiondepth,getAllBackground); + this.typedSparqlQuery = new TypedSparqlQuery(configuration); + this.extractionAlgorithm = new ExtractionAlgorithm(configuration); } public String extract(URI uri) { // this.TypedSparqlQuery.query(uri); // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); System.out.println("Start extracting"); - Node n = this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); + Node n = this.extractionAlgorithm.expandNode(uri, this.typedSparqlQuery); Set<String> s = n.toNTriple(); String nt = ""; for (String str : s) { @@ -52,7 +52,7 @@ for (String one : instances) { try { - Node n = this.ExtractionAlgorithm.expandNode(new URI(one), this.TypedSparqlQuery); + Node n = this.extractionAlgorithm.expandNode(new URI(one), this.typedSparqlQuery); ret.addAll(n.toNTriple()); } catch (Exception e) { e.printStackTrace(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2007-12-02 14:34:12 UTC (rev 302) @@ -5,7 +5,7 @@ import java.util.Vector; public abstract class Node { - URI URI; + URI uri; protected String type; protected boolean expanded = false; @@ -14,7 +14,7 @@ // Hashtable<String,Node> datatype=new Hashtable<String,Node>();; public Node(URI u) { - this.URI = u; + this.uri = u; } @@ -31,7 +31,7 @@ @Override public String toString() { - return "Node: " + URI + ":" + type; + return "Node: " + uri + ":" + type; } @@ -48,7 +48,7 @@ } public URI getURI() { - return URI; + return uri; } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 14:34:12 UTC (rev 302) @@ -7,53 +7,51 @@ public class PredefinedConfigurations { - public static Configuration get(int i){ - - switch (i){ - case 0: return dbpediaYago(); - + public static Configuration get(int i) { + + switch (i) { + case 0: + return dbpediaYago(); + + } + return null; } - return null; - } - - public static Configuration dbpediaYago(){ - 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();} - SpecificSparqlEndpoint sse=new SpecificSparqlEndpoint( - u,"dbpedia.openlinksw.com",m); - //System.out.println(u); - 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"); - - - 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://www.w3.org/2004/02/skos/core"); - - SparqlQueryType sqt=new SparqlQueryType("forbid",obj,pred,"false"); - - - - return new Configuration(sse,sqt,2,true); - - } - - + + public static Configuration dbpediaYago() { + 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(); + } + SpecificSparqlEndpoint sse = new SpecificSparqlEndpoint(u, "dbpedia.openlinksw.com", m); + // System.out.println(u); + 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"); + + 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://www.w3.org/2004/02/skos/core"); + + SparqlQueryType sqt = new SparqlQueryType("forbid", obj, pred, "false"); + + return new Configuration(sse, sqt, 2, true); + + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-02 14:34:12 UTC (rev 302) @@ -10,7 +10,7 @@ private Node a; private Node b; - private Set<String> SpecialTypes; + private Set<String> specialTypes; public PropertyNode(URI u) { super(u); @@ -23,12 +23,12 @@ this.type = "property"; this.a = a; this.b = b; - this.SpecialTypes = new HashSet<String>(); + this.specialTypes = new HashSet<String>(); } @Override public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { - Set<Tupel> s = tsq.query(this.URI); + Set<Tupel> s = tsq.query(this.uri); Vector<Node> Nodes = new Vector<Node>(); // Manipulation @@ -37,7 +37,7 @@ Tupel t = (Tupel) it.next(); try { if (t.a.equals(m.type)) { - SpecialTypes.add(t.b); + specialTypes.add(t.b); } } catch (Exception e) { System.out.println(t); @@ -60,10 +60,10 @@ @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" + "><" + s.add("<" + this.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("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + for (String one : specialTypes) { + s.add("<" + this.uri + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + one + ">."); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-02 14:34:12 UTC (rev 302) @@ -2,22 +2,22 @@ public class SparqlQueryMaker { - private SparqlQueryType SparqlQueryType; + private SparqlQueryType sparqlQueryType; public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { - this.SparqlQueryType = SparqlQueryType; + this.sparqlQueryType = SparqlQueryType; } public String makeQueryUsingFilters(String subject) { String lineend = "\n"; String Filter = ""; - if (!this.SparqlQueryType.isLiterals()) + if (!this.sparqlQueryType.isLiterals()) Filter += "!isLiteral(?object))"; - for (String p : this.SparqlQueryType.getPredicatefilterlist()) { + for (String p : this.sparqlQueryType.getPredicatefilterlist()) { Filter += lineend + filterPredicate(p); } - for (String o : this.SparqlQueryType.getObjectfilterlist()) { + for (String o : this.sparqlQueryType.getObjectfilterlist()) { Filter += lineend + filterObject(o); } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java 2007-12-02 14:34:12 UTC (rev 302) @@ -9,14 +9,14 @@ String host; String hasQueryParameter; - URL URL; + URL url; public HashMap<String, String> parameters = new HashMap<String, String>(); public SpecificSparqlEndpoint(URL url,String host, HashMap<String, String> parameters) { super(); this.host=host; - this.URL = url; + this.url = url; this.hasQueryParameter = "query"; this.parameters = parameters; } @@ -47,7 +47,7 @@ } public URL getURL() { - return this.URL; + return this.url; } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 14:19:48 UTC (rev 301) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 14:34:12 UTC (rev 302) @@ -14,22 +14,22 @@ import java.util.Set; public class TypedSparqlQuery { - private Configuration Configuration; + private Configuration configuration; // private SparqlHTTPRequest SparqlHTTPRequest; - private SparqlQueryMaker SparqlQueryMaker; + private SparqlQueryMaker sparqlQueryMaker; Cache Cache; public TypedSparqlQuery(Configuration Configuration) { - this.Configuration = Configuration; + this.configuration = Configuration; // this.SparqlHTTPRequest = new SparqlHTTPRequest(Configuration.getSparqlEndpoint()); - this.SparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); + this.sparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); this.Cache = new Cache("cache"); } public Set<Tupel> query(URI u) { // getQuery - String sparql = SparqlQueryMaker.makeQueryUsingFilters(u.toString()); + String sparql = sparqlQueryMaker.makeQueryUsingFilters(u.toString()); // check cache String FromCache = this.Cache.get(u.toString(), sparql); @@ -96,7 +96,7 @@ // String an Sparql-Endpoint schicken HttpURLConnection connection; - SpecificSparqlEndpoint se = Configuration.getSparqlEndpoint(); + SpecificSparqlEndpoint se = configuration.getSparqlEndpoint(); connection = (HttpURLConnection) se.getURL().openConnection(); connection.setDoOutput(true); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-02 14:19:50
|
Revision: 301 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=301&view=rev Author: jenslehmann Date: 2007-12-02 06:19:48 -0800 (Sun, 02 Dec 2007) Log Message: ----------- some cleanup Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 13:31:59 UTC (rev 300) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 14:19:48 UTC (rev 301) @@ -1,105 +0,0 @@ -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.InetAddress; -import java.net.URLEncoder; -import java.util.Iterator; -import java.util.Set; - - - -public class SparqlHTTPRequest { - - - private SpecificSparqlEndpoint SparqlEndpoint; - - - - public SparqlHTTPRequest(SpecificSparqlEndpoint SparqlEndpoint){ - this.SparqlEndpoint=SparqlEndpoint; - - - } - - - public String sendAndReceiveSPARQL( String sparql){ - String ret= ""; - try{ - //System.out.println(sparql); - - //System.out.println(content); - - ret=this.sendAndReceive(sparql); - //System.out.println(ret); - - //this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); - }catch (Exception e) {e.printStackTrace();} - return ret; - - - }//down - - - - - - - private String sendAndReceive(String sparql) throws IOException{ - StringBuilder answer = new StringBuilder(); - - // String an Sparql-Endpoint schicken - HttpURLConnection connection; - - connection = (HttpURLConnection) this.SparqlEndpoint.getURL().openConnection(); - connection.setDoOutput(true); - - connection.addRequestProperty("Host", this.SparqlEndpoint.getHost()); - connection.addRequestProperty("Connection","close"); - connection.addRequestProperty("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - connection.addRequestProperty("Accept-Language","de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); - connection.addRequestProperty("Accept-Charset","utf-8;q=1.0"); - connection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); - - OutputStream os = connection.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - - Set<String> s =SparqlEndpoint.getParameters().keySet(); - Iterator<String> it=s.iterator(); - String FullURI=""; - while (it.hasNext()) { - String element = (String) it.next(); - FullURI+=""+URLEncoder.encode(element, "UTF-8")+"="+ - URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8")+"&"; - } - //System.out.println(FullURI); - FullURI+=""+SparqlEndpoint.getHasQueryParameter()+"="+URLEncoder.encode(sparql, "UTF-8"); - - - osw.write(FullURI); - osw.close(); - - // receive answer - InputStream is = connection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is,"UTF-8"); - BufferedReader br = new BufferedReader(isr); - - String line; - do { - line = br.readLine(); - if(line!=null) - answer.append(line); - } while (line != null); - - br.close(); - - return answer.toString(); - } - -} - Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 13:31:59 UTC (rev 300) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 14:19:48 UTC (rev 301) @@ -1,18 +1,27 @@ 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.URI; +import java.net.URLEncoder; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; public class TypedSparqlQuery { private Configuration Configuration; - private SparqlHTTPRequest SparqlHTTPRequest; + // private SparqlHTTPRequest SparqlHTTPRequest; private SparqlQueryMaker SparqlQueryMaker; Cache Cache; public TypedSparqlQuery(Configuration Configuration) { this.Configuration = Configuration; - this.SparqlHTTPRequest = new SparqlHTTPRequest(Configuration.getSparqlEndpoint()); + // this.SparqlHTTPRequest = new SparqlHTTPRequest(Configuration.getSparqlEndpoint()); this.SparqlQueryMaker = new SparqlQueryMaker(Configuration.getSparqlQueryType()); this.Cache = new Cache("cache"); } @@ -25,10 +34,15 @@ // check cache String FromCache = this.Cache.get(u.toString(), sparql); - String xml; + String xml = null; // if not in cache get it from EndPoint if (FromCache == null) { - xml = this.SparqlHTTPRequest.sendAndReceiveSPARQL(sparql); + try { + xml = sendAndReceiveSPARQL(sparql); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } //System.out.println(sparql); //System.out.println(xml); this.Cache.put(u.toString(), xml, sparql); @@ -77,4 +91,56 @@ } + private String sendAndReceiveSPARQL(String sparql) throws IOException{ + StringBuilder answer = new StringBuilder(); + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + SpecificSparqlEndpoint se = Configuration.getSparqlEndpoint(); + + connection = (HttpURLConnection) se.getURL().openConnection(); + connection.setDoOutput(true); + + connection.addRequestProperty("Host", se.getHost()); + connection.addRequestProperty("Connection","close"); + connection.addRequestProperty("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language","de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset","utf-8;q=1.0"); + connection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + + Set<String> s =se.getParameters().keySet(); + Iterator<String> it=s.iterator(); + String FullURI=""; + while (it.hasNext()) { + String element = (String) it.next(); + FullURI+=""+URLEncoder.encode(element, "UTF-8")+"="+ + URLEncoder.encode(se.getParameters().get(element), "UTF-8")+"&"; + } + //System.out.println(FullURI); + FullURI+=""+se.getHasQueryParameter()+"="+URLEncoder.encode(sparql, "UTF-8"); + + + osw.write(FullURI); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is,"UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if(line!=null) + answer.append(line); + } while (line != null); + + br.close(); + + return answer.toString(); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-02 13:32:01
|
Revision: 300 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=300&view=rev Author: kurzum Date: 2007-12-02 05:31:59 -0800 (Sun, 02 Dec 2007) Log Message: ----------- checked in wrong file Added Paths: ----------- trunk/examples/dbpedia/newworking.conf Removed Paths: ------------- trunk/examples/dbpedia/newtest.conf Deleted: trunk/examples/dbpedia/newtest.conf =================================================================== --- trunk/examples/dbpedia/newtest.conf 2007-12-02 13:31:13 UTC (rev 299) +++ trunk/examples/dbpedia/newtest.conf 2007-12-02 13:31:59 UTC (rev 300) @@ -1,49 +0,0 @@ -/** - * Father Example - * - * possible solution: - * male AND EXISTS hasChild.TOP - * - * Copyright (C) 2007, Jens Lehmann - */ - -/** settings **/ -// reasoner settings -reasoner = dig; -//digReasonerURL = "http://localhost:8081"; -//useRetrievalForClassification = true; -//refinement.useDIGMultiInstanceChecks = twoChecks; - -// algorithm settings -algorithm = refinement; -//refinement.horizontalExpansionFactor = 0.5; -//refinement.quiet = false; - -// search tree protocol -// refinement.writeSearchTree = false; -// refinement.searchTreeFile = "log/searchTree.txt"; - -// control output -cli.checkSatisfiability = true; -cli.showIndividuals = false; -cli.showConcepts = false; -cli.showRoles = true; -cli.showSubsumptionHierarchy = false; - -// SPARQL options -sparql2.numberOfRecursions = 2; -sparql2.host = "dbpedia.openlinksw.com"; -sparql2.getAllBackground=true; -sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel"}; -sparql2.filterMode = 0; -sparql2.predList = {}; -sparql2.objList = {}; -sparql2.classList = {}; -sparql2.format = "N-TRIPLES"; -sparql2.dumpToFile = true; - -import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); - -/** examples **/ -+"http://dbpedia.org/resource/Angela_Merkel" --"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" \ No newline at end of file Added: trunk/examples/dbpedia/newworking.conf =================================================================== --- trunk/examples/dbpedia/newworking.conf (rev 0) +++ trunk/examples/dbpedia/newworking.conf 2007-12-02 13:31:59 UTC (rev 300) @@ -0,0 +1,49 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +sparql2.numberOfRecursions = 2; +sparql2.host = "dbpedia.openlinksw.com"; +sparql2.getAllBackground=true; +sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel"}; +sparql2.filterMode = 0; +sparql2.predList = {}; +sparql2.objList = {}; +sparql2.classList = {}; +sparql2.format = "N-TRIPLES"; +sparql2.dumpToFile = true; + +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +/** examples **/ ++"http://dbpedia.org/resource/Angela_Merkel" +-"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-02 13:31:15
|
Revision: 299 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=299&view=rev Author: kurzum Date: 2007-12-02 05:31:13 -0800 (Sun, 02 Dec 2007) Log Message: ----------- working example Added Paths: ----------- trunk/examples/dbpedia/newtest.conf Added: trunk/examples/dbpedia/newtest.conf =================================================================== --- trunk/examples/dbpedia/newtest.conf (rev 0) +++ trunk/examples/dbpedia/newtest.conf 2007-12-02 13:31:13 UTC (rev 299) @@ -0,0 +1,49 @@ +/** + * Father Example + * + * possible solution: + * male AND EXISTS hasChild.TOP + * + * Copyright (C) 2007, Jens Lehmann + */ + +/** settings **/ +// reasoner settings +reasoner = dig; +//digReasonerURL = "http://localhost:8081"; +//useRetrievalForClassification = true; +//refinement.useDIGMultiInstanceChecks = twoChecks; + +// algorithm settings +algorithm = refinement; +//refinement.horizontalExpansionFactor = 0.5; +//refinement.quiet = false; + +// search tree protocol +// refinement.writeSearchTree = false; +// refinement.searchTreeFile = "log/searchTree.txt"; + +// control output +cli.checkSatisfiability = true; +cli.showIndividuals = false; +cli.showConcepts = false; +cli.showRoles = true; +cli.showSubsumptionHierarchy = false; + +// SPARQL options +sparql2.numberOfRecursions = 2; +sparql2.host = "dbpedia.openlinksw.com"; +sparql2.getAllBackground=true; +sparql2.instances = {"http://dbpedia.org/resource/Angela_Merkel"}; +sparql2.filterMode = 0; +sparql2.predList = {}; +sparql2.objList = {}; +sparql2.classList = {}; +sparql2.format = "N-TRIPLES"; +sparql2.dumpToFile = true; + +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); + +/** examples **/ ++"http://dbpedia.org/resource/Angela_Merkel" +-"http://dbpedia.org/resource/Gerhard_Schr%C3%B6der" \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-02 13:30:02
|
Revision: 298 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=298&view=rev Author: kurzum Date: 2007-12-02 05:29:58 -0800 (Sun, 02 Dec 2007) Log Message: ----------- working, filtermode gives a predefined set wchich is stored in kb.sparql.Predefined. Manual configuration might not work yet. Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 13:29:58 UTC (rev 298) @@ -27,6 +27,7 @@ import java.net.URI; import java.net.URL; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedList; import java.util.Set; @@ -42,12 +43,11 @@ import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.KB; import org.dllearner.kb.sparql.Manager; -import org.dllearner.kb.sparql.SparqlEndpoint; 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.Datastructures; /** * Represents a SPARQL Endpoint. @@ -59,7 +59,8 @@ public class SparqlEndpointRestructured extends KnowledgeSource { //ConfigOptions - private URL url; + private URL url; + String host; private Set<String> instances; private URL dumpFile; private int numberOfRecursions; @@ -70,6 +71,7 @@ private String format; private boolean dumpToFile; private boolean useLits=false; + private boolean getAllBackground=false; /** * Holds the results of the calculateSubjects method @@ -120,8 +122,9 @@ * @return */ public static Collection<ConfigOption<?>> createConfigOptions() { - Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); + 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("numberOfRecursions","number of Recursions, the Sparql-Endpoint is asked")); options.add(new IntegerConfigOption("filterMode","the mode of the SPARQL Filter")); @@ -131,6 +134,7 @@ 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")); + options.add(new BooleanConfigOption("getAllBackground","get")); return options; } @@ -148,6 +152,8 @@ } 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("numberOfRecursions")){ @@ -166,6 +172,8 @@ dumpToFile=(Boolean)entry.getValue(); } else if(option.equals("useLits")){ useLits=(Boolean)entry.getValue(); + } else if(option.equals("getAllBackground")){ + getAllBackground=(Boolean)entry.getValue(); } } @@ -182,15 +190,16 @@ //Datastructures.setToArray(predList),Datastructures.setToArray( objList),Datastructures.setToArray(classList),format,url,useLits); Manager m=new Manager(); if(filterMode==0){ - try{ - m.usePredefinedConfiguration(new URI("http://www.extraction.org/config#dbpediatest")); - }catch (Exception e) {e.printStackTrace();} + + m.usePredefinedConfiguration(filterMode); + } else{ - //SparqlQueryType sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); - //SparqlEndpoint se=new SparqlEndpoint(); - //m.useConfiguration(SparqlQueryType, SparqlEndpoint) + SparqlQueryType sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); + SpecificSparqlEndpoint se=new SpecificSparqlEndpoint(url, host, new HashMap<String, String>()); + m.useConfiguration(sqt, se,numberOfRecursions,getAllBackground); } + try { String ont=m.extract(instances); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-02 13:29:58 UTC (rev 298) @@ -18,16 +18,26 @@ import org.semanticweb.owl.model.OWLOntologyManager; public class Configuration { - private SparqlEndpoint SparqlEndpoint; + private SpecificSparqlEndpoint SparqlEndpoint; private SparqlQueryType SparqlQueryType; private Manipulator Manipulator; - + private int recursiondepth = 2; + private boolean getAllBackground = true; + private Configuration() { } - public Configuration(SparqlEndpoint SparqlEndpoint, SparqlQueryType SparqlQueryType) { + + public Configuration(SpecificSparqlEndpoint SparqlEndpoint, + SparqlQueryType SparqlQueryType, int recursiondepth, + boolean getAllBackground) { this.SparqlEndpoint = SparqlEndpoint; this.SparqlQueryType = SparqlQueryType; + this.Manipulator=new Manipulator(); + this.recursiondepth = recursiondepth; + this.getAllBackground = getAllBackground; + + } public static Configuration getConfiguration(URI uri) { @@ -123,7 +133,7 @@ } - public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint, OWLOntology o) { + public static SpecificSparqlEndpoint makeEndpoint(OWLIndividual sEndpoint, OWLOntology o) { String host = getFirstValueForDataProperty("hasHost", sEndpoint.getDataPropertyValues(o)); String port = getFirstValueForDataProperty("hasPort", sEndpoint.getDataPropertyValues(o)); String hasAfterGET = getFirstValueForDataProperty("hasAfterGET", sEndpoint @@ -135,7 +145,7 @@ // System.out.println("test"); HashMap<String, String> parameters = new HashMap<String, String>(); if (para == null) - return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + return null;//new SpecificSparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); for (OWLIndividual p : para) { // System.out.println("test2"); String a1 = getFirstValueForDataProperty("hasParameterName", p.getDataPropertyValues(o)); @@ -146,7 +156,7 @@ // System.out.println("test2"); // System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ // parameters); - return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + return null;//new SpecificSparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); } @@ -196,7 +206,7 @@ return this.Manipulator; } - public SparqlEndpoint getSparqlEndpoint() { + public SpecificSparqlEndpoint getSparqlEndpoint() { return SparqlEndpoint; } @@ -204,4 +214,14 @@ return SparqlQueryType; } + + public boolean isGetAllBackground() { + return getAllBackground; + } + + + public int getRecursiondepth() { + return recursiondepth; + } + } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 13:29:58 UTC (rev 298) @@ -13,6 +13,8 @@ public ExtractionAlgorithm(Configuration Configuration) { this.Configuration = Configuration; this.Manipulator = Configuration.getManipulator(); + this.recursiondepth=Configuration.getRecursiondepth(); + this.getAllBackground=Configuration.isGetAllBackground(); } @@ -41,6 +43,7 @@ while (v.size() > 0) { Node tmpNode = v.remove(0); System.out.println("Expanding " + tmpNode); + //System.out.println(this.Manipulator); Vector<Node> tmpVec = tmpNode.expand(tsp, this.Manipulator); tmp.addAll(tmpVec); @@ -57,7 +60,9 @@ } while (classes.size() > 0) { System.out.println(classes.size()); - classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); + Node next=classes.remove(0); + System.out.println(next); + classes.addAll(next.expand(tsp, this.Manipulator)); } } Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 13:29:58 UTC (rev 298) @@ -24,6 +24,7 @@ Set<Tupel> s = tsq.query(this.URI); // Manipulation m.check(s, this); + //System.out.println("fffffff"+m); Vector<Node> Nodes = new Vector<Node>(); Iterator<Tupel> it = s.iterator(); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 13:29:58 UTC (rev 298) @@ -10,16 +10,23 @@ private TypedSparqlQuery TypedSparqlQuery; private ExtractionAlgorithm ExtractionAlgorithm; - public void usePredefinedConfiguration(URI uri) { + /*public void usePredefinedConfiguration(URI uri) { this.Configuration = org.dllearner.kb.sparql.Configuration.getConfiguration(uri); this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + }*/ + + public void usePredefinedConfiguration(int i) { + + this.Configuration = PredefinedConfigurations.get(i); + this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); } - public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint) { + public void useConfiguration(SparqlQueryType SparqlQueryType, SpecificSparqlEndpoint SparqlEndpoint, int recursiondepth,boolean getAllBackground) { - this.Configuration = new Configuration(SparqlEndpoint, SparqlQueryType); + this.Configuration = new Configuration(SparqlEndpoint, SparqlQueryType,recursiondepth,getAllBackground); this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); } Added: trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PredefinedConfigurations.java 2007-12-02 13:29:58 UTC (rev 298) @@ -0,0 +1,59 @@ +package org.dllearner.kb.sparql; + +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +public class PredefinedConfigurations { + + public static Configuration get(int i){ + + switch (i){ + case 0: return dbpediaYago(); + + } + return null; + } + + public static Configuration dbpediaYago(){ + 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();} + SpecificSparqlEndpoint sse=new SpecificSparqlEndpoint( + u,"dbpedia.openlinksw.com",m); + //System.out.println(u); + 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"); + + + 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://www.w3.org/2004/02/skos/core"); + + SparqlQueryType sqt=new SparqlQueryType("forbid",obj,pred,"false"); + + + + return new Configuration(sse,sqt,2,true); + + } + + +} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java 2007-12-02 13:29:58 UTC (rev 298) @@ -1,128 +0,0 @@ -package org.dllearner.kb.sparql; - -import java.io.BufferedInputStream; -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.InetAddress; -import java.net.Socket; -import java.net.URL; -import java.net.URLEncoder; - -public class SimpleHTTPRequest { - static final char value[] = { 13, 10 }; - static final String cut = new String(value); - private InetAddress ia; - private int port; - - public SimpleHTTPRequest(InetAddress ia, int port) { - super(); - this.ia = ia; - this.port = port; - - } - - public String sendAndReceive(String content) { - String retval = ""; - // - - byte resp[] = null; - - try { - Socket SparqlServer = new Socket(this.ia, this.port); - // String request=makeHeader(content); - // send request - (SparqlServer.getOutputStream()).write(content.getBytes()); - - // get Response - resp = readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); - retval = new String(resp); - retval = subtractResponseHeader(retval); - // retval="||"+retval; - - SparqlServer.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - // System.out.println("got it"); - return retval; - - }// down - - public static byte[] readBuffer(InputStream IS) throws IOException { - byte buffer[] = new byte[0xffff]; - int nbytes = 0; - byte resp[] = new byte[0]; - while ((nbytes = IS.read(buffer)) != -1) { - byte tmp[] = new byte[resp.length + nbytes]; - int i = 0; - for (; i < resp.length; i++) { - tmp[i] = resp[i]; - } - for (int a = 0; a < nbytes; a++, i++) { - tmp[i] = buffer[a]; - } - resp = tmp; - } - return resp; - } - - public String subtractResponseHeader(String in) { - // System.out.println(in.indexOf(cut+""+cut)); - return in.substring(in.indexOf(cut + "" + cut) + 4); - - } - - private String sendAndReceive2(String sparql, URL url) throws IOException { - StringBuilder answer = new StringBuilder(); - - // String an Sparql-Endpoint schicken - HttpURLConnection connection; - - connection = (HttpURLConnection) url.openConnection(); - connection.setDoOutput(true); - - connection.addRequestProperty("Host", "dbpedia.openlinksw.com"); - connection.addRequestProperty("Connection", "close"); - connection - .addRequestProperty( - "Accept", - "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); - connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); - connection - .addRequestProperty( - "User-Agent", - "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); - - OutputStream os = connection.getOutputStream(); - OutputStreamWriter osw = new OutputStreamWriter(os); - osw - .write("default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" - + URLEncoder.encode(sparql, "UTF-8") - + "&format=application%2Fsparql-results%2Bxml"); - osw.close(); - - // receive answer - InputStream is = connection.getInputStream(); - InputStreamReader isr = new InputStreamReader(is, "UTF-8"); - BufferedReader br = new BufferedReader(isr); - - String line; - do { - line = br.readLine(); - if (line != null) - answer.append(line); - } while (line != null); - - br.close(); - - return answer.toString(); - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2007-12-02 13:29:58 UTC (rev 298) @@ -1,79 +0,0 @@ -package org.dllearner.kb.sparql; - -import java.util.HashMap; - -public class SparqlEndpoint { - - String host; - int port; - String hasAfterGET; - String hasQueryParameter; - String hasURL; - public HashMap<String, String> parameters = new HashMap<String, String>(); - - public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, - HashMap<String, String> parameters) { - super(); - this.host = host; - this.port = Integer.parseInt(port); - this.hasAfterGET = hasAfterGET; - this.hasQueryParameter = hasQueryParameter; - this.parameters = parameters; - } - - public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { - super(); - this.port = port; - this.host = host; - this.hasURL = hasURL; - this.hasQueryParameter = "query"; - this.parameters = parameters; - } - - public String getHasAfterGET() { - return hasAfterGET; - } - - public void setHasAfterGET(String hasAfterGET) { - this.hasAfterGET = hasAfterGET; - } - - public String getHasQueryParameter() { - return hasQueryParameter; - } - - public void setHasQueryParameter(String hasQueryParameter) { - this.hasQueryParameter = hasQueryParameter; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public HashMap<String, String> getParameters() { - return parameters; - } - - public void setParameters(HashMap<String, String> parameters) { - this.parameters = parameters; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - /* - * sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + - * //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + - * URLEncoder.encode(query, "UTF-8")+ //query+// URLencode - * "&format=application%2Fsparql-results%2Bxml - */ -} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 13:29:58 UTC (rev 298) @@ -1,81 +1,105 @@ 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.InetAddress; import java.net.URLEncoder; import java.util.Iterator; import java.util.Set; -public class SparqlHTTPRequest { - static final char value[] = { 13, 10 }; - static final String cut = new String(value); - private SparqlEndpoint SparqlEndpoint; - private SimpleHTTPRequest SimpleHTTPRequest; - public SparqlHTTPRequest(SparqlEndpoint SparqlEndpoint) { - this.SparqlEndpoint = SparqlEndpoint; - InetAddress ia = null; - try { - ia = InetAddress.getByName(SparqlEndpoint.getHost()); - } catch (Exception e) { - e.printStackTrace(); - } - this.SimpleHTTPRequest = new SimpleHTTPRequest(ia, SparqlEndpoint.getPort()); - +public class SparqlHTTPRequest { + + + private SpecificSparqlEndpoint SparqlEndpoint; + + + + public SparqlHTTPRequest(SpecificSparqlEndpoint SparqlEndpoint){ + this.SparqlEndpoint=SparqlEndpoint; + + } - - public String sendAndReceiveSPARQL(String sparql) { - - // System.out.println(sparql); - String content = makeContent(sparql); - // System.out.println(content); - String ret = this.SimpleHTTPRequest.sendAndReceive(content); - // System.out.println(ret); - - // this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); - + + + public String sendAndReceiveSPARQL( String sparql){ + String ret= ""; + try{ + //System.out.println(sparql); + + //System.out.println(content); + + ret=this.sendAndReceive(sparql); + //System.out.println(ret); + + //this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); + }catch (Exception e) {e.printStackTrace();} return ret; - - }// down - - public String makeContent(String query) { - - String RequestHeader = ""; - try { - - RequestHeader = "GET "; - RequestHeader += SparqlEndpoint.getHasAfterGET() + "?"; - // parameters - Set<String> s = SparqlEndpoint.getParameters().keySet(); - Iterator<String> it = s.iterator(); - while (it.hasNext()) { - String element = (String) it.next(); - RequestHeader += "" + URLEncoder.encode(element, "UTF-8") + "=" - + URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8") - + "&"; - } - RequestHeader += "" + SparqlEndpoint.getHasQueryParameter() + "=" - + URLEncoder.encode(query, "UTF-8"); - RequestHeader += " HTTP/1.1" + cut; - RequestHeader += "Host: " + SparqlEndpoint.getHost() + cut; - - RequestHeader += "Connection: close" - + cut - + - // "Accept-Encoding: gzip"+cut+ - "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" - + cut - + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" - + cut - + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" - + cut - + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24" - + cut + cut; - } catch (Exception e) { - e.printStackTrace(); + + + }//down + + + + + + + private String sendAndReceive(String sparql) throws IOException{ + StringBuilder answer = new StringBuilder(); + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + + connection = (HttpURLConnection) this.SparqlEndpoint.getURL().openConnection(); + connection.setDoOutput(true); + + connection.addRequestProperty("Host", this.SparqlEndpoint.getHost()); + connection.addRequestProperty("Connection","close"); + connection.addRequestProperty("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language","de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset","utf-8;q=1.0"); + connection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + + Set<String> s =SparqlEndpoint.getParameters().keySet(); + Iterator<String> it=s.iterator(); + String FullURI=""; + while (it.hasNext()) { + String element = (String) it.next(); + FullURI+=""+URLEncoder.encode(element, "UTF-8")+"="+ + URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8")+"&"; } - return RequestHeader; - + //System.out.println(FullURI); + FullURI+=""+SparqlEndpoint.getHasQueryParameter()+"="+URLEncoder.encode(sparql, "UTF-8"); + + + osw.write(FullURI); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is,"UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if(line!=null) + answer.append(line); + } while (line != null); + + br.close(); + + return answer.toString(); } + +} -} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java (from rev 296, trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SpecificSparqlEndpoint.java 2007-12-02 13:29:58 UTC (rev 298) @@ -0,0 +1,53 @@ +package org.dllearner.kb.sparql; + +import java.net.URL; +import java.util.HashMap; + +public class SpecificSparqlEndpoint { + + + + String host; + String hasQueryParameter; + URL URL; + public HashMap<String, String> parameters = new HashMap<String, String>(); + + + public SpecificSparqlEndpoint(URL url,String host, HashMap<String, String> parameters) { + super(); + this.host=host; + this.URL = url; + this.hasQueryParameter = "query"; + this.parameters = parameters; + } + + + public String getHasQueryParameter() { + return hasQueryParameter; + } + + public void setHasQueryParameter(String hasQueryParameter) { + this.hasQueryParameter = hasQueryParameter; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public HashMap<String, String> getParameters() { + return parameters; + } + + public void setParameters(HashMap<String, String> parameters) { + this.parameters = parameters; + } + + public URL getURL() { + return this.URL; + } + +} Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Test.java 2007-12-02 13:29:58 UTC (rev 298) @@ -13,7 +13,7 @@ try { URI u = new URI(test); Manager m = new Manager(); - m.usePredefinedConfiguration(u); + //m.usePredefinedConfiguration(u); URI u2 = new URI("http://dbpedia.org/resource/Angela_Merkel"); Modified: trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 12:03:41 UTC (rev 297) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java 2007-12-02 13:29:58 UTC (rev 298) @@ -24,12 +24,14 @@ // check cache String FromCache = this.Cache.get(u.toString(), sparql); - FromCache = null; + String xml; // if not in cache get it from EndPoint if (FromCache == null) { xml = this.SparqlHTTPRequest.sendAndReceiveSPARQL(sparql); - // this.Cache.put(u.toString(), xml, sparql); + //System.out.println(sparql); + //System.out.println(xml); + this.Cache.put(u.toString(), xml, sparql); System.out.print("\n"); } else { xml = FromCache; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-02 12:03:44
|
Revision: 297 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=297&view=rev Author: jenslehmann Date: 2007-12-02 04:03:41 -0800 (Sun, 02 Dec 2007) Log Message: ----------- changed component name Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 11:52:02 UTC (rev 296) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 12:03:41 UTC (rev 297) @@ -112,7 +112,7 @@ private KB kb; public static String getName() { - return "SPARQL Endpoint"; + return "SPARQL Endpoint Restructured"; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-12-02 11:52:08
|
Revision: 296 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=296&view=rev Author: jenslehmann Date: 2007-12-02 03:52:02 -0800 (Sun, 02 Dec 2007) Log Message: ----------- refactored and formatted new SPARQL component files Modified Paths: -------------- trunk/examples/dbpedia/sparql.conf trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/sparql/ 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/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.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/Node.java trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.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/Test.java trunk/src/dl-learner/org/dllearner/kb/sparql/Tupel.java trunk/src/dl-learner/org/dllearner/kb/sparql/TypedSparqlQuery.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/ Modified: trunk/examples/dbpedia/sparql.conf =================================================================== --- trunk/examples/dbpedia/sparql.conf 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/examples/dbpedia/sparql.conf 2007-12-02 11:52:02 UTC (rev 296) @@ -31,16 +31,16 @@ cli.showSubsumptionHierarchy = false; // SPARQL options -sparql.numberOfRecursions = 2; -sparql.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Philolaus","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; -sparql.filterMode = 0; -sparql.predList = {}; -sparql.objList = {}; -sparql.classList = {}; -sparql.format = "KB"; -sparql.dumpToFile = false; +sparql2.numberOfRecursions = 2; +sparql2.instances = {"http://dbpedia.org/resource/Democritus","http://dbpedia.org/resource/Zeno_of_Elea","http://dbpedia.org/resource/Archytas","http://dbpedia.org/resource/Plato","http://dbpedia.org/resource/Philolaus","http://dbpedia.org/resource/Pythagoras","http://dbpedia.org/resource/Socrates"}; +sparql2.filterMode = 0; +sparql2.predList = {}; +sparql2.objList = {}; +sparql2.classList = {}; +sparql2.format = "KB"; +sparql2.dumpToFile = false; -import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL"); +import("http://dbpedia.openlinksw.com:8890/sparql","SPARQL2"); /** examples **/ +"http://dbpedia.org/resource/Pythagoras" Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-02 11:52:02 UTC (rev 296) @@ -41,9 +41,9 @@ import org.dllearner.core.config.StringConfigOption; import org.dllearner.core.config.StringSetConfigOption; import org.dllearner.core.dl.KB; -import org.dllearner.kb.extraction.Manager; -import org.dllearner.kb.extraction.SparqlEndpoint; -import org.dllearner.kb.extraction.SparqlQueryType; +import org.dllearner.kb.sparql.Manager; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQueryType; import org.dllearner.parser.KBParser; import org.dllearner.reasoning.DIGConverter; import org.dllearner.reasoning.JenaOWLDIGConverter; Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,202 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.semanticweb.owl.apibinding.OWLManager; -import org.semanticweb.owl.model.OWLConstant; -import org.semanticweb.owl.model.OWLDataPropertyExpression; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLObjectPropertyExpression; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLOntologyManager; - -public class Configuration { - private SparqlEndpoint SparqlEndpoint; - private SparqlQueryType SparqlQueryType; - private Manipulator Manipulator; - - - private Configuration(){ - } - public Configuration(SparqlEndpoint SparqlEndpoint,SparqlQueryType SparqlQueryType){ - this.SparqlEndpoint=SparqlEndpoint; - this.SparqlQueryType=SparqlQueryType; - } - - - public static Configuration getConfiguration(URI uri){ - //public static String getTellsString(URL file, URI kbURI){//throws OWLOntologyCreationException{ - Configuration ret=new Configuration(); - try{ - String file="config/config.owl"; - - - File f= new File(file); - String fileURL="file:///"+f.getAbsolutePath(); - URL u=new URL(fileURL); - /* Load an ontology from a physical URI */ - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - OWLOntology ontology = manager.loadOntologyFromPhysicalURI(u.toURI()); - //System.out.println( ontology.containsIndividualReference(uri)); - //OWLIndividualImpl ind=new OWLIndividualImpl(); - //System.out.println(ontology.getReferencedIndividuals()); - Set<OWLIndividual> s=ontology.getReferencedIndividuals(); - //System.out.println(ontology.getReferencedClasses()); - //Set<OWLIndividualAxiom> s= ontology.getIndividualAxioms(); - Iterator<OWLIndividual> it=s.iterator(); - while (it.hasNext()){ - OWLIndividual tmp=(OWLIndividual)it.next(); - //tmp.getURI() - if(tmp.getURI().equals(uri)){ - OWLIndividual[] arr=getIndividualsForProperty("hasSparqlEndpoint",tmp.getObjectPropertyValues(ontology)); - OWLIndividual sEndpoint=arr[0]; - ret.SparqlEndpoint=makeEndpoint(sEndpoint, ontology); - arr=getIndividualsForProperty("hasTypedQuery",tmp.getObjectPropertyValues(ontology)); - OWLIndividual typedQuery=arr[0]; - ret.SparqlQueryType=makeSparqlQueryType(typedQuery, ontology); - - } - //{hasSparqlEndpoint=[dbpediaEndpoint]} - } - - ret.Manipulator=makeManipulator(); - }catch (Exception e) {e.printStackTrace();} - - return ret; - } - - - - - - public static OWLIndividual[] getIndividualsForProperty(String propertyname,Map<OWLObjectPropertyExpression, Set<OWLIndividual>> m){ - Set<OWLObjectPropertyExpression> s=m.keySet(); - - Iterator<OWLObjectPropertyExpression> it=s.iterator(); - while (it.hasNext()){ - OWLObjectPropertyExpression tmp=(OWLObjectPropertyExpression)it.next(); - //System.out.println(tmp); - //System.out.println(propertyname); - if(tmp.toString().equals(propertyname)) - { - Object[] arr=((Set<OWLIndividual>)m.get(tmp)).toArray() ; - OWLIndividual[] o=new OWLIndividual[arr.length]; - for (int i = 0; i < o.length; i++) { - o[i]=(OWLIndividual)arr[i]; - } - - return o;} - } - return null; - - } - - public static String getFirstValueForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ - return getValuesForDataProperty(propertyname, m)[0]; - } - - public static String[] getValuesForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ - Set<OWLDataPropertyExpression> s=m.keySet(); - - Iterator<OWLDataPropertyExpression> it=s.iterator(); - while (it.hasNext()){ - OWLDataPropertyExpression tmp=(OWLDataPropertyExpression)it.next(); - if(tmp.toString().equals(propertyname)) - { - Object[] arr=((Set<OWLConstant>)m.get(tmp)).toArray() ; - String[] str=new String[arr.length]; - for (int i = 0; i < str.length; i++) { - str[i]=((OWLConstant)arr[i]).getLiteral(); - } - return str;} - } - return null; - - } - - public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint,OWLOntology o){ - String host=getFirstValueForDataProperty("hasHost",sEndpoint.getDataPropertyValues(o)); - String port=getFirstValueForDataProperty("hasPort",sEndpoint.getDataPropertyValues(o)); - String hasAfterGET=getFirstValueForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); - String hasQueryParameter=getFirstValueForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); - OWLIndividual[] para=getIndividualsForProperty("hasGETParameter",sEndpoint.getObjectPropertyValues(o)); - //System.out.println("test"); - HashMap<String,String> parameters=new HashMap<String,String>(); - if(para==null)return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); - for (OWLIndividual p : para) { - //System.out.println("test2"); - String a1=getFirstValueForDataProperty("hasParameterName",p.getDataPropertyValues(o)); - String a2=getFirstValueForDataProperty("hasParameterContent",p.getDataPropertyValues(o)); - parameters.put(a1, a2); - } - //System.out.println("test2"); - //System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ parameters); - return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); - - - - } - - public static SparqlQueryType makeSparqlQueryType(OWLIndividual typedQuery,OWLOntology o){ - String useLiterals=getFirstValueForDataProperty("usesLiterals",typedQuery.getDataPropertyValues(o)); - String hasMode=getFirstValueForDataProperty("hasMode",typedQuery.getDataPropertyValues(o)); - //String hasAfterGET=getValuesForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); - //String hasQueryParameter=getValuesForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); - OWLIndividual[] objFilter=getIndividualsForProperty("hasObjectFilterSet",typedQuery.getObjectPropertyValues(o)); - OWLIndividual[] predFilter=getIndividualsForProperty("hasPredicateFilterSet",typedQuery.getObjectPropertyValues(o)); - - Set<String> objectFilter=new HashSet<String>(); - Set<String> predicateFilter=new HashSet<String>(); - - for (OWLIndividual of : objFilter) { - String[] tmp=getValuesForDataProperty("filtersURI",of.getDataPropertyValues(o)); - for (String s : tmp){ - objectFilter.add(s); - - } - } - - for (OWLIndividual pf : predFilter) { - String[] tmp=getValuesForDataProperty("filtersURI",pf.getDataPropertyValues(o)); - for (String s : tmp){ - predicateFilter.add(s); - - } - } - //System.out.println(predicateFilter); - //System.out.println(hasMode+objectFilter+predicateFilter+useLiterals); - return new SparqlQueryType(hasMode,objectFilter,predicateFilter,useLiterals); - - - - } - - public static Manipulator makeManipulator() { - return new Manipulator(); - } - - - public Manipulator getManipulator() { - return this.Manipulator; - } - - public SparqlEndpoint getSparqlEndpoint() { - return SparqlEndpoint; - } - - - - public SparqlQueryType getSparqlQueryType() { - return SparqlQueryType; - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,74 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.net.URI; -import java.util.Vector; - -import org.dllearner.kb.extraction.datastructures.InstanceNode; -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; - -public class ExtractionAlgorithm { - - private Configuration Configuration; - private Manipulator Manipulator; - private int recursiondepth=2; - private boolean getAllBackground=true; - - - - public ExtractionAlgorithm (Configuration Configuration){ - this.Configuration=Configuration; - this.Manipulator=Configuration.getManipulator(); - - } - - public Node getFirstNode(URI u){ - return new InstanceNode(u); - } - public Vector<Node> expandAll(URI[] u,TypedSparqlQuery tsp){ - Vector<Node> v=new Vector<Node>(); - for(URI one:u){ - v.add(expandNode(one, tsp)); - } - return v; - } - - - public Node expandNode(URI u, TypedSparqlQuery tsp){ - Node n=getFirstNode(u); - Vector<Node> v=new Vector<Node>(); - v.add(n); - System.out.println("StartVector: "+v); - // n.expand(tsp, this.Manipulator); - //Vector<Node> second= - for(int x=1;x<=this.recursiondepth;x++){ - - Vector<Node>tmp=new Vector<Node>(); - while (v.size()>0) { - Node tmpNode=v.remove(0); - System.out.println("Expanding "+tmpNode); - Vector<Node> tmpVec=tmpNode.expand(tsp, this.Manipulator); - - tmp.addAll(tmpVec); - } - v=tmp; - System.out.println("Rec: "+x+" with "+v); - } - if(this.getAllBackground){ - Vector<Node> classes=new Vector<Node>(); - for(Node one:v){ - if(one.isClass()) {classes.add(one);} - } - while(classes.size()>0){ - System.out.println(classes.size()); - classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); - } - - } - return n; - - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,67 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.net.URI; -import java.util.HashSet; -import java.util.Set; - -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; - -public class Manager { - - private Configuration Configuration; - private TypedSparqlQuery TypedSparqlQuery; - private ExtractionAlgorithm ExtractionAlgorithm; - - - public void usePredefinedConfiguration(URI uri){ - - this.Configuration=org.dllearner.kb.extraction.Configuration.getConfiguration(uri); - this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); - } - - public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint){ - - this.Configuration=new Configuration(SparqlEndpoint,SparqlQueryType); - this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); - this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); - } - - public String extract(URI uri){ - //this.TypedSparqlQuery.query(uri); - //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - System.out.println("Start extracting"); - Node n=this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); - Set<String> s=n.toNTriple(); - String nt=""; - for(String str:s){ - nt+=str+"\n"; - } - return nt; - } - - public String extract(Set<String> instances){ - //this.TypedSparqlQuery.query(uri); - //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); - System.out.println("Start extracting"); - Set<String> ret=new HashSet<String>(); - - - for(String one:instances){ - try{ - Node n=this.ExtractionAlgorithm.expandNode(new URI(one),this.TypedSparqlQuery); - ret.addAll(n.toNTriple()); - }catch (Exception e) {e.printStackTrace();} - } - - - String nt=""; - for(String str:ret){ - nt+=str+"\n"; - } - return nt; - } - - -} \ No newline at end of file Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,55 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.dllearner.kb.extraction.datastructures.Node; -import org.dllearner.kb.extraction.datastructures.Tupel; - -public class Manipulator { - public String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; - public 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"; - - Set<String> classproperties; - - - 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/"}; //TODO FEHLER hier fehlt yago - - public Manipulator(){ - Set<String> classproperties=new HashSet<String>(); - classproperties.add(subclass); - - } - - public Set<Tupel> check(Set<Tupel> s,Node node){ - Set<Tupel> toRemove=new HashSet<Tupel>(); - Iterator<Tupel> it=s.iterator(); - while(it.hasNext()){ - Tupel t=(Tupel)it.next(); - //all classes with owl:type class - if(t.a.equals(this.type) && t.b.equals(this.classns)&& node.isClass() ) - {toRemove.add(t);}; - // all with type class - if( t.b.equals(this.classns) && node.isClass() ) - {toRemove.add(t);}; - // all instances with owl:type thing - if(t.a.equals(this.type) && t.b.equals(this.thing)&& node.isInstance() ) - {toRemove.add(t);}; - - } - s.removeAll(toRemove); - - return s; - } - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,69 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.HashMap; - -public class SparqlEndpoint { - - String host; - int port; - String hasAfterGET; - String hasQueryParameter; - String hasURL; - public HashMap<String,String> parameters=new HashMap<String,String>(); - public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, HashMap<String, String> parameters) { - super(); - this.host = host; - this.port = Integer.parseInt(port); - this.hasAfterGET = hasAfterGET; - this.hasQueryParameter = hasQueryParameter; - this.parameters = parameters; - } - - public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { - super(); - this.port=port; - this.host=host; - this.hasURL = hasURL; - this.hasQueryParameter = "query"; - this.parameters = parameters; - } - public String getHasAfterGET() { - return hasAfterGET; - } - public void setHasAfterGET(String hasAfterGET) { - this.hasAfterGET = hasAfterGET; - } - public String getHasQueryParameter() { - return hasQueryParameter; - } - public void setHasQueryParameter(String hasQueryParameter) { - this.hasQueryParameter = hasQueryParameter; - } - public String getHost() { - return host; - } - public void setHost(String host) { - this.host = host; - } - public HashMap<String, String> getParameters() { - return parameters; - } - public void setParameters(HashMap<String, String> parameters) { - this.parameters = parameters; - } - public int getPort() { - return port; - } - public void setPort(int port) { - this.port = port; - } - - - - - /*sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + - //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + - URLEncoder.encode(query, "UTF-8")+ - //query+// URLencode - "&format=application%2Fsparql-results%2Bxml*/ -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,68 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.util.Set; - -public class SparqlQueryType { - - private String mode="forbid"; - private String[] objectfilterlist={ - "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"}; - private String[] predicatefilterlist={ - "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" }; - private boolean literals=false; - - public SparqlQueryType(String mode, String[] obectfilterlist, String[] predicatefilterlist, boolean literals) { - super(); - this.mode = mode; - this.objectfilterlist = obectfilterlist; - this.predicatefilterlist = predicatefilterlist; - this.literals = literals; - } - - public SparqlQueryType(String mode, Set<String> objectfilterlist, Set<String> predicatefilterlist, String literals) { - super(); - this.mode = mode; - this.literals = (literals.equals("true"))?true:false; - - Object[] arr=objectfilterlist.toArray(); - Object[] arr2=predicatefilterlist.toArray(); - this.objectfilterlist = new String[arr.length]; - this.predicatefilterlist = new String[arr2.length]; - for (int i = 0; i < arr.length; i++) { - this.objectfilterlist[i]=(String)arr[i]; - } - for (int i = 0; i < arr2.length; i++) { - this.predicatefilterlist[i]=(String)arr2[i]; - } - - - } - - public boolean isLiterals() { - return literals; - } - - public String getMode() { - return mode; - } - - public String[] getObjectfilterlist() { - return objectfilterlist; - } - - public String[] getPredicatefilterlist() { - return predicatefilterlist; - } - - - -} Deleted: trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java 2007-12-02 11:42:36 UTC (rev 295) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java 2007-12-02 11:52:02 UTC (rev 296) @@ -1,31 +0,0 @@ -package org.dllearner.kb.extraction; - -import java.io.File; -import java.io.FileWriter; -import java.net.URI; - -public class Test { - - - public static void main(String[] args) { - System.out.println("Start"); - String test2="http://www.extraction.org/config#dbpediatest"; - String test="http://www.extraction.org/config#localjoseki"; - try{ - URI u=new URI(test); - Manager m=new Manager(); - m.usePredefinedConfiguration(u); - - - URI u2=new URI("http://dbpedia.org/resource/Angela_Merkel"); - - String filename=System.currentTimeMillis()+".nt"; - FileWriter fw=new FileWriter(new File(filename),true); - fw.write(m.extract(u2)); - fw.flush(); - fw.close(); - - }catch (Exception e) {e.printStackTrace();} - } - -} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Cache.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,132 @@ +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; + +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"; + long timestamp; + String content = ""; + long daysoffreshness = 15; + long multiplier = 24 * 60 * 60 * 1000;// h m s ms + String sparqlquery = ""; + + // constructor for the cache itself + public Cache(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) + public Cache(String c, String sparql) { + this.content = c; + this.sparqlquery = sparql; + this.timestamp = System.currentTimeMillis(); + } + + public String get(String key, String sparql) { + // 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"); + if (!c.validate(sparql)) + return null; + // System.out.println("valid"); + ret = c.content; + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + }; + + public void put(String key, String content, String sparql) { + // System.out.println("put into "+key); + Cache c = new Cache(content, sparql); + putIntoFile(makeFilename(key), c); + } + + String makeFilename(String key) { + String ret = ""; + try { + ret = basedir + URLEncoder.encode(key, "UTF-8") + fileending; + } catch (Exception e) { + e.printStackTrace(); + } + return ret; + } + + boolean checkFreshness() { + if ((System.currentTimeMillis() - this.timestamp) <= (daysoffreshness * multiplier)) + // fresh + return true; + else + return false; + } + + boolean validate(String sparql) { + if (this.sparqlquery.equals(sparql)) + // valid + return true; + else + return false; + } + + public void checkFile(String Filename) { + if (!new File(Filename).exists()) { + try { + new File(Filename).createNewFile(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + } + + public void putIntoFile(String Filename, Cache content) { + try { + // FileWriter fw=new FileWriter(new File(Filename),true); + 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); + } + } + + public 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; + + } +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ClassNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,61 @@ +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; + +public class ClassNode extends Node { + Set<PropertyNode> properties = new HashSet<PropertyNode>(); + + public ClassNode(URI u) { + super(u); + this.type = "class"; + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { + Set<Tupel> s = tsq.query(this.URI); + s = m.check(s, this); + Vector<Node> Nodes = new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + try { + 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); + } + } catch (Exception e) { + System.out.println(t); + e.printStackTrace(); + } + + } + return Nodes; + } + + @Override + public boolean isClass() { + return true; + } + + @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; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Configuration.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,207 @@ +package org.dllearner.kb.sparql; + +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLConstant; +import org.semanticweb.owl.model.OWLDataPropertyExpression; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLObjectPropertyExpression; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyManager; + +public class Configuration { + private SparqlEndpoint SparqlEndpoint; + private SparqlQueryType SparqlQueryType; + private Manipulator Manipulator; + + private Configuration() { + } + + public Configuration(SparqlEndpoint SparqlEndpoint, SparqlQueryType SparqlQueryType) { + this.SparqlEndpoint = SparqlEndpoint; + this.SparqlQueryType = SparqlQueryType; + } + + public static Configuration getConfiguration(URI uri) { + // public static String getTellsString(URL file, URI kbURI){//throws + // OWLOntologyCreationException{ + Configuration ret = new Configuration(); + try { + String file = "config/config.owl"; + + File f = new File(file); + String fileURL = "file:///" + f.getAbsolutePath(); + URL u = new URL(fileURL); + /* Load an ontology from a physical URI */ + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(u.toURI()); + // System.out.println( ontology.containsIndividualReference(uri)); + // OWLIndividualImpl ind=new OWLIndividualImpl(); + // System.out.println(ontology.getReferencedIndividuals()); + Set<OWLIndividual> s = ontology.getReferencedIndividuals(); + // System.out.println(ontology.getReferencedClasses()); + // Set<OWLIndividualAxiom> s= ontology.getIndividualAxioms(); + Iterator<OWLIndividual> it = s.iterator(); + while (it.hasNext()) { + OWLIndividual tmp = (OWLIndividual) it.next(); + // tmp.getURI() + if (tmp.getURI().equals(uri)) { + OWLIndividual[] arr = getIndividualsForProperty("hasSparqlEndpoint", tmp + .getObjectPropertyValues(ontology)); + OWLIndividual sEndpoint = arr[0]; + ret.SparqlEndpoint = makeEndpoint(sEndpoint, ontology); + arr = getIndividualsForProperty("hasTypedQuery", tmp + .getObjectPropertyValues(ontology)); + OWLIndividual typedQuery = arr[0]; + ret.SparqlQueryType = makeSparqlQueryType(typedQuery, ontology); + + } + // {hasSparqlEndpoint=[dbpediaEndpoint]} + } + + ret.Manipulator = makeManipulator(); + } catch (Exception e) { + e.printStackTrace(); + } + + return ret; + } + + public static OWLIndividual[] getIndividualsForProperty(String propertyname, + Map<OWLObjectPropertyExpression, Set<OWLIndividual>> m) { + Set<OWLObjectPropertyExpression> s = m.keySet(); + + Iterator<OWLObjectPropertyExpression> it = s.iterator(); + while (it.hasNext()) { + OWLObjectPropertyExpression tmp = (OWLObjectPropertyExpression) it.next(); + // System.out.println(tmp); + // System.out.println(propertyname); + if (tmp.toString().equals(propertyname)) { + Object[] arr = ((Set<OWLIndividual>) m.get(tmp)).toArray(); + OWLIndividual[] o = new OWLIndividual[arr.length]; + for (int i = 0; i < o.length; i++) { + o[i] = (OWLIndividual) arr[i]; + } + + return o; + } + } + return null; + + } + + public static String getFirstValueForDataProperty(String propertyname, + Map<OWLDataPropertyExpression, Set<OWLConstant>> m) { + return getValuesForDataProperty(propertyname, m)[0]; + } + + public static String[] getValuesForDataProperty(String propertyname, + Map<OWLDataPropertyExpression, Set<OWLConstant>> m) { + Set<OWLDataPropertyExpression> s = m.keySet(); + + Iterator<OWLDataPropertyExpression> it = s.iterator(); + while (it.hasNext()) { + OWLDataPropertyExpression tmp = (OWLDataPropertyExpression) it.next(); + if (tmp.toString().equals(propertyname)) { + Object[] arr = ((Set<OWLConstant>) m.get(tmp)).toArray(); + String[] str = new String[arr.length]; + for (int i = 0; i < str.length; i++) { + str[i] = ((OWLConstant) arr[i]).getLiteral(); + } + return str; + } + } + return null; + + } + + public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint, OWLOntology o) { + String host = getFirstValueForDataProperty("hasHost", sEndpoint.getDataPropertyValues(o)); + String port = getFirstValueForDataProperty("hasPort", sEndpoint.getDataPropertyValues(o)); + String hasAfterGET = getFirstValueForDataProperty("hasAfterGET", sEndpoint + .getDataPropertyValues(o)); + String hasQueryParameter = getFirstValueForDataProperty("hasQueryParameter", sEndpoint + .getDataPropertyValues(o)); + OWLIndividual[] para = getIndividualsForProperty("hasGETParameter", sEndpoint + .getObjectPropertyValues(o)); + // System.out.println("test"); + HashMap<String, String> parameters = new HashMap<String, String>(); + if (para == null) + return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + for (OWLIndividual p : para) { + // System.out.println("test2"); + String a1 = getFirstValueForDataProperty("hasParameterName", p.getDataPropertyValues(o)); + String a2 = getFirstValueForDataProperty("hasParameterContent", p + .getDataPropertyValues(o)); + parameters.put(a1, a2); + } + // System.out.println("test2"); + // System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ + // parameters); + return new SparqlEndpoint(host, port, hasAfterGET, hasQueryParameter, parameters); + + } + + public static SparqlQueryType makeSparqlQueryType(OWLIndividual typedQuery, OWLOntology o) { + String useLiterals = getFirstValueForDataProperty("usesLiterals", typedQuery + .getDataPropertyValues(o)); + String hasMode = getFirstValueForDataProperty("hasMode", typedQuery + .getDataPropertyValues(o)); + // String + // hasAfterGET=getValuesForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); + // String + // hasQueryParameter=getValuesForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); + OWLIndividual[] objFilter = getIndividualsForProperty("hasObjectFilterSet", typedQuery + .getObjectPropertyValues(o)); + OWLIndividual[] predFilter = getIndividualsForProperty("hasPredicateFilterSet", typedQuery + .getObjectPropertyValues(o)); + + Set<String> objectFilter = new HashSet<String>(); + Set<String> predicateFilter = new HashSet<String>(); + + for (OWLIndividual of : objFilter) { + String[] tmp = getValuesForDataProperty("filtersURI", of.getDataPropertyValues(o)); + for (String s : tmp) { + objectFilter.add(s); + + } + } + + for (OWLIndividual pf : predFilter) { + String[] tmp = getValuesForDataProperty("filtersURI", pf.getDataPropertyValues(o)); + for (String s : tmp) { + predicateFilter.add(s); + + } + } + // System.out.println(predicateFilter); + // System.out.println(hasMode+objectFilter+predicateFilter+useLiterals); + return new SparqlQueryType(hasMode, objectFilter, predicateFilter, useLiterals); + + } + + public static Manipulator makeManipulator() { + return new Manipulator(); + } + + public Manipulator getManipulator() { + return this.Manipulator; + } + + public SparqlEndpoint getSparqlEndpoint() { + return SparqlEndpoint; + } + + public SparqlQueryType getSparqlQueryType() { + return SparqlQueryType; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/ExtractionAlgorithm.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,68 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.Vector; + +public class ExtractionAlgorithm { + + private Configuration Configuration; + private Manipulator Manipulator; + private int recursiondepth = 2; + private boolean getAllBackground = true; + + public ExtractionAlgorithm(Configuration Configuration) { + this.Configuration = Configuration; + this.Manipulator = Configuration.getManipulator(); + + } + + public Node getFirstNode(URI u) { + return new InstanceNode(u); + } + + public Vector<Node> expandAll(URI[] u, TypedSparqlQuery tsp) { + Vector<Node> v = new Vector<Node>(); + for (URI one : u) { + v.add(expandNode(one, tsp)); + } + return v; + } + + public Node expandNode(URI u, TypedSparqlQuery tsp) { + Node n = getFirstNode(u); + Vector<Node> v = new Vector<Node>(); + v.add(n); + System.out.println("StartVector: " + v); + // n.expand(tsp, this.Manipulator); + // Vector<Node> second= + for (int x = 1; x <= this.recursiondepth; x++) { + + Vector<Node> tmp = new Vector<Node>(); + while (v.size() > 0) { + Node tmpNode = v.remove(0); + System.out.println("Expanding " + tmpNode); + Vector<Node> tmpVec = tmpNode.expand(tsp, this.Manipulator); + + tmp.addAll(tmpVec); + } + v = tmp; + System.out.println("Rec: " + x + " with " + v); + } + if (this.getAllBackground) { + Vector<Node> classes = new Vector<Node>(); + for (Node one : v) { + if (one.isClass()) { + classes.add(one); + } + } + while (classes.size() > 0) { + System.out.println(classes.size()); + classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); + } + + } + return n; + + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/InstanceNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,78 @@ +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; + +public class InstanceNode extends Node { + + Set<ClassNode> classes = new HashSet<ClassNode>(); + Set<Tupel> datatypes = new HashSet<Tupel>(); + Set<PropertyNode> properties = new HashSet<PropertyNode>(); + + public InstanceNode(URI u) { + super(u); + this.type = "instance"; + + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m) { + + Set<Tupel> s = tsq.query(this.URI); + // Manipulation + m.check(s, this); + Vector<Node> Nodes = new Vector<Node>(); + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + + 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(); + } + + } + this.expanded = true; + return Nodes; + } + + @Override + public boolean isInstance() { + return true; + } + + @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#Thing" + ">."); + for (ClassNode one : classes) { + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + one.getURI() + ">."); + s.addAll(one.toNTriple()); + } + for (PropertyNode one : properties) { + s.add("<" + this.URI + "><" + one.getURI() + "><" + one.getB().getURI() + ">."); + s.addAll(one.toNTriple()); + s.addAll(one.getB().toNTriple()); + } + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manager.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,62 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +public class Manager { + + private Configuration Configuration; + private TypedSparqlQuery TypedSparqlQuery; + private ExtractionAlgorithm ExtractionAlgorithm; + + public void usePredefinedConfiguration(URI uri) { + + this.Configuration = org.dllearner.kb.sparql.Configuration.getConfiguration(uri); + this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + } + + public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint) { + + this.Configuration = new Configuration(SparqlEndpoint, SparqlQueryType); + this.TypedSparqlQuery = new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm = new ExtractionAlgorithm(Configuration); + } + + public String extract(URI uri) { + // this.TypedSparqlQuery.query(uri); + // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Node n = this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); + Set<String> s = n.toNTriple(); + String nt = ""; + for (String str : s) { + nt += str + "\n"; + } + return nt; + } + + public String extract(Set<String> instances) { + // this.TypedSparqlQuery.query(uri); + // System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Set<String> ret = new HashSet<String>(); + + for (String one : instances) { + try { + Node n = this.ExtractionAlgorithm.expandNode(new URI(one), this.TypedSparqlQuery); + ret.addAll(n.toNTriple()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + String nt = ""; + for (String str : ret) { + nt += str + "\n"; + } + return nt; + } + +} \ No newline at end of file Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Manipulator.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,58 @@ +package org.dllearner.kb.sparql; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class Manipulator { + public String subclass = "http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public 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"; + + Set<String> classproperties; + + 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/" }; // TODO + // FEHLER + // hier + // fehlt + // yago + + public Manipulator() { + Set<String> classproperties = new HashSet<String>(); + classproperties.add(subclass); + + } + + public Set<Tupel> check(Set<Tupel> s, Node node) { + Set<Tupel> toRemove = new HashSet<Tupel>(); + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + // all classes with owl:type class + if (t.a.equals(this.type) && t.b.equals(this.classns) && node.isClass()) { + toRemove.add(t); + } + ; + // all with type class + if (t.b.equals(this.classns) && node.isClass()) { + toRemove.add(t); + } + ; + // all instances with owl:type thing + if (t.a.equals(this.type) && t.b.equals(this.thing) && node.isInstance()) { + toRemove.add(t); + } + ; + + } + s.removeAll(toRemove); + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/Node.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,54 @@ +package org.dllearner.kb.sparql; + +import java.net.URI; +import java.util.Set; +import java.util.Vector; + +public abstract class Node { + URI URI; + protected String type; + protected boolean expanded = false; + + // Hashtable<String,Node> classes=new Hashtable<String,Node>(); + // Hashtable<String,Node> instances=new Hashtable<String,Node>();; + // Hashtable<String,Node> datatype=new Hashtable<String,Node>();; + + public Node(URI u) { + this.URI = u; + + } + + /* + * public void checkConsistency(){ if (type.equals("class") && ( + * instances.size()>0 || datatype.size()>0)){ System.out.println("Warning, + * inconsistent:"+this.toString()); } + * } + */ + + public abstract Vector<Node> expand(TypedSparqlQuery tsq, Manipulator m); + + public abstract Set<String> toNTriple(); + + @Override + public String toString() { + return "Node: " + URI + ":" + type; + + } + + public boolean isClass() { + return false; + } + + public boolean isInstance() { + return false; + } + + public boolean isProperty() { + return false; + } + + public URI getURI() { + return URI; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/PropertyNode.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,74 @@ +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; + +public class PropertyNode extends Node { + + private Node a; + private Node b; + 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(TypedSparqlQuery tsq, Manipulator m) { + Set<Tupel> s = tsq.query(this.URI); + Vector<Node> Nodes = new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it = s.iterator(); + while (it.hasNext()) { + Tupel t = (Tupel) it.next(); + try { + if (t.a.equals(m.type)) { + SpecialTypes.add(t.b); + } + } catch (Exception e) { + System.out.println(t); + e.printStackTrace(); + } + + } + return Nodes; + } + + @Override + public boolean isProperty() { + return true; + } + + public Node getB() { + return this.b; + } + + @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#ObjectProperty" + ">."); + for (String one : SpecialTypes) { + s.add("<" + this.URI + "><" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" + "><" + + one + ">."); + + } + + return s; + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SimpleHTTPRequest.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,128 @@ +package org.dllearner.kb.sparql; + +import java.io.BufferedInputStream; +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.InetAddress; +import java.net.Socket; +import java.net.URL; +import java.net.URLEncoder; + +public class SimpleHTTPRequest { + static final char value[] = { 13, 10 }; + static final String cut = new String(value); + private InetAddress ia; + private int port; + + public SimpleHTTPRequest(InetAddress ia, int port) { + super(); + this.ia = ia; + this.port = port; + + } + + public String sendAndReceive(String content) { + String retval = ""; + // + + byte resp[] = null; + + try { + Socket SparqlServer = new Socket(this.ia, this.port); + // String request=makeHeader(content); + // send request + (SparqlServer.getOutputStream()).write(content.getBytes()); + + // get Response + resp = readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval = new String(resp); + retval = subtractResponseHeader(retval); + // retval="||"+retval; + + SparqlServer.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + // System.out.println("got it"); + return retval; + + }// down + + public static byte[] readBuffer(InputStream IS) throws IOException { + byte buffer[] = new byte[0xffff]; + int nbytes = 0; + byte resp[] = new byte[0]; + while ((nbytes = IS.read(buffer)) != -1) { + byte tmp[] = new byte[resp.length + nbytes]; + int i = 0; + for (; i < resp.length; i++) { + tmp[i] = resp[i]; + } + for (int a = 0; a < nbytes; a++, i++) { + tmp[i] = buffer[a]; + } + resp = tmp; + } + return resp; + } + + public String subtractResponseHeader(String in) { + // System.out.println(in.indexOf(cut+""+cut)); + return in.substring(in.indexOf(cut + "" + cut) + 4); + + } + + private String sendAndReceive2(String sparql, URL url) throws IOException { + StringBuilder answer = new StringBuilder(); + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + + connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + + connection.addRequestProperty("Host", "dbpedia.openlinksw.com"); + connection.addRequestProperty("Connection", "close"); + connection + .addRequestProperty( + "Accept", + "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset", "utf-8;q=1.0"); + connection + .addRequestProperty( + "User-Agent", + "Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + osw + .write("default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + URLEncoder.encode(sparql, "UTF-8") + + "&format=application%2Fsparql-results%2Bxml"); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if (line != null) + answer.append(line); + } while (line != null); + + br.close(); + + return answer.toString(); + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlEndpoint.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,79 @@ +package org.dllearner.kb.sparql; + +import java.util.HashMap; + +public class SparqlEndpoint { + + String host; + int port; + String hasAfterGET; + String hasQueryParameter; + String hasURL; + public HashMap<String, String> parameters = new HashMap<String, String>(); + + public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, + HashMap<String, String> parameters) { + super(); + this.host = host; + this.port = Integer.parseInt(port); + this.hasAfterGET = hasAfterGET; + this.hasQueryParameter = hasQueryParameter; + this.parameters = parameters; + } + + public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { + super(); + this.port = port; + this.host = host; + this.hasURL = hasURL; + this.hasQueryParameter = "query"; + this.parameters = parameters; + } + + public String getHasAfterGET() { + return hasAfterGET; + } + + public void setHasAfterGET(String hasAfterGET) { + this.hasAfterGET = hasAfterGET; + } + + public String getHasQueryParameter() { + return hasQueryParameter; + } + + public void setHasQueryParameter(String hasQueryParameter) { + this.hasQueryParameter = hasQueryParameter; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public HashMap<String, String> getParameters() { + return parameters; + } + + public void setParameters(HashMap<String, String> parameters) { + this.parameters = parameters; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + /* + * sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + * //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + + * URLEncoder.encode(query, "UTF-8")+ //query+// URLencode + * "&format=application%2Fsparql-results%2Bxml + */ +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlHTTPRequest.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,81 @@ +package org.dllearner.kb.sparql; + +import java.net.InetAddress; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Set; + +public class SparqlHTTPRequest { + static final char value[] = { 13, 10 }; + static final String cut = new String(value); + + private SparqlEndpoint SparqlEndpoint; + private SimpleHTTPRequest SimpleHTTPRequest; + + public SparqlHTTPRequest(SparqlEndpoint SparqlEndpoint) { + this.SparqlEndpoint = SparqlEndpoint; + InetAddress ia = null; + try { + ia = InetAddress.getByName(SparqlEndpoint.getHost()); + } catch (Exception e) { + e.printStackTrace(); + } + this.SimpleHTTPRequest = new SimpleHTTPRequest(ia, SparqlEndpoint.getPort()); + + } + + public String sendAndReceiveSPARQL(String sparql) { + + // System.out.println(sparql); + String content = makeContent(sparql); + // System.out.println(content); + String ret = this.SimpleHTTPRequest.sendAndReceive(content); + // System.out.println(ret); + + // this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); + + return ret; + + }// down + + public String makeContent(String query) { + + String RequestHeader = ""; + try { + + RequestHeader = "GET "; + RequestHeader += SparqlEndpoint.getHasAfterGET() + "?"; + // parameters + Set<String> s = SparqlEndpoint.getParameters().keySet(); + Iterator<String> it = s.iterator(); + while (it.hasNext()) { + String element = (String) it.next(); + RequestHeader += "" + URLEncoder.encode(element, "UTF-8") + "=" + + URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8") + + "&"; + } + RequestHeader += "" + SparqlEndpoint.getHasQueryParameter() + "=" + + URLEncoder.encode(query, "UTF-8"); + RequestHeader += " HTTP/1.1" + cut; + RequestHeader += "Host: " + SparqlEndpoint.getHost() + cut; + + RequestHeader += "Connection: close" + + cut + + + // "Accept-Encoding: gzip"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" + + cut + + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" + + cut + + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" + + cut + + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24" + + cut + cut; + } catch (Exception e) { + e.printStackTrace(); + } + return RequestHeader; + + } + +} Copied: trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java (from rev 294, trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java) =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/sparql/SparqlQueryMaker.java 2007-12-02 11:52:02 UTC (rev 296) @@ -0,0 +1,37 @@ +package org.dllearner.kb.sparql; + +public class SparqlQueryMaker { + + private SparqlQueryType SparqlQueryType; + + public SparqlQueryMaker(SparqlQueryType SparqlQueryType) { + this.SparqlQueryType = SparqlQu... [truncated message content] |
From: <jen...@us...> - 2007-12-02 11:42:40
|
Revision: 295 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=295&view=rev Author: jenslehmann Date: 2007-12-02 03:42:36 -0800 (Sun, 02 Dec 2007) Log Message: ----------- added SparqlEndpointRestructured as component - prefix "sparql2" in CLI, use import(...,SPARQL2) in conf file Modified Paths: -------------- trunk/lib/components.ini trunk/src/dl-learner/org/dllearner/cli/Start.java Modified: trunk/lib/components.ini =================================================================== --- trunk/lib/components.ini 2007-12-01 20:54:13 UTC (rev 294) +++ trunk/lib/components.ini 2007-12-02 11:42:36 UTC (rev 295) @@ -4,6 +4,7 @@ org.dllearner.kb.OWLFile org.dllearner.kb.KBFile org.dllearner.kb.SparqlEndpoint +org.dllearner.kb.SparqlEndpointRestructured # reasoners org.dllearner.reasoning.DIGReasoner org.dllearner.reasoning.FastRetrievalReasoner Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-01 20:54:13 UTC (rev 294) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-12-02 11:42:36 UTC (rev 295) @@ -60,6 +60,7 @@ 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; @@ -224,6 +225,7 @@ 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"); // learning problems - configured via + and - flags for examples @@ -370,6 +372,8 @@ 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 { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-01 20:54:22
|
Revision: 294 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=294&view=rev Author: kurzum Date: 2007-12-01 12:54:13 -0800 (Sat, 01 Dec 2007) Log Message: ----------- ontology with config sets Added Paths: ----------- trunk/config/ trunk/config/config.owl Added: trunk/config/config.owl =================================================================== --- trunk/config/config.owl (rev 0) +++ trunk/config/config.owl 2007-12-01 20:54:13 UTC (rev 294) @@ -0,0 +1,172 @@ +<?xml version="1.0"?> +<!DOCTYPE rdf:RDF [ + <!ENTITY config "http://www.extraction.org/config#"> + <!ENTITY owl "http://www.w3.org/2002/07/owl#"> + <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#"> + <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#"> +]> +<rdf:RDF xml:base="http://www.extraction.org/config" xmlns:config="http://www.extraction.org/config#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> + <!-- Ontology Information --> + <owl:Ontology rdf:about=""> + <owl:versionInfo xml:lang="en">version 0.1</owl:versionInfo> + </owl:Ontology> + <!-- Classes --> + <owl:Class rdf:about="#Configuration"/> + <owl:Class rdf:about="#FilterSet"/> + <owl:Class rdf:about="#GETParameter"/> + <owl:Class rdf:about="#ObjectFilterSet"> + <rdfs:subClassOf rdf:resource="#FilterSet"/> + </owl:Class> + <owl:Class rdf:about="#PredicateFilterSet"> + <rdfs:subClassOf rdf:resource="#FilterSet"/> + </owl:Class> + <owl:Class rdf:about="#SparqlEndpoint"/> + <owl:Class rdf:about="#TypedQuery"/> + <!-- Annotation Properties --> + <owl:AnnotationProperty rdf:about="&rdfs;comment"/> + <owl:AnnotationProperty rdf:about="&owl;versionInfo"/> + <!-- Datatype Properties --> + <owl:DatatypeProperty rdf:about="#filtersURI"> + <rdfs:domain rdf:resource="#ObjectFilterSet"/> + <rdfs:domain rdf:resource="#PredicateFilterSet"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasAfterGET"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasHost"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasMode"> + <rdfs:domain rdf:resource="#TypedQuery"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasParameterContent"> + <rdfs:domain rdf:resource="#GETParameter"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasParameterName"> + <rdfs:domain rdf:resource="#GETParameter"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasPort"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasQueryParameter"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#hasRecursionDepth"> + <rdfs:domain rdf:resource="#Configuration"/> + </owl:DatatypeProperty> + <owl:DatatypeProperty rdf:about="#usesLiterals"> + <rdfs:domain rdf:resource="#TypedQuery"/> + </owl:DatatypeProperty> + <!-- Object Properties --> + <owl:ObjectProperty rdf:about="#hasGETParameter"> + <rdfs:domain rdf:resource="#SparqlEndpoint"/> + <rdfs:range rdf:resource="#GETParameter"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasObjectFilterSet"> + <rdfs:domain rdf:resource="#TypedQuery"/> + <rdfs:range rdf:resource="#ObjectFilterSet"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasPredicateFilterSet"> + <rdfs:domain rdf:resource="#TypedQuery"/> + <rdfs:range rdf:resource="#PredicateFilterSet"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasSparqlEndpoint"> + <rdfs:domain rdf:resource="#Configuration"/> + <rdfs:range rdf:resource="#SparqlEndpoint"/> + </owl:ObjectProperty> + <owl:ObjectProperty rdf:about="#hasTypedQuery"> + <rdfs:domain rdf:resource="#Configuration"/> + <rdfs:range rdf:resource="#TypedQuery"/> + </owl:ObjectProperty> + <!-- Instances --> + <config:SparqlEndpoint rdf:about="#dbpediaEndpoint"> + <config:hasAfterGET rdf:datatype="&xsd;string">/sparql</config:hasAfterGET> + <config:hasGETParameter rdf:resource="#defaultgraphuri"/> + <config:hasGETParameter rdf:resource="#format"/> + <config:hasHost rdf:datatype="&xsd;string">dbpedia.openlinksw.com</config:hasHost> + <config:hasPort rdf:datatype="&xsd;string">80</config:hasPort> + <config:hasQueryParameter rdf:datatype="&xsd;string">query</config:hasQueryParameter> + <config:hasURL>dbpedia.openlinksw.com:80/sparql</config:hasURL> + </config:SparqlEndpoint> + <config:ObjectFilterSet rdf:about="#dbpediaGeneralObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Articles_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Wikipedia_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://upload.wikimedia.org/wikipedia/commons</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://upload.wikimedia.org/wikipedia</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www.geonames.org</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2006/03/wn/wn20/instances/synset</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://www4.wiwiss.fu-berlin.de/flickrwrappr</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#dbpediaGeneralPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/reference</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/website</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/property/wikipage-</config:filtersURI> + </config:PredicateFilterSet> + <config:TypedQuery rdf:about="#dbpediaYago"> + <config:hasMode rdf:datatype="&xsd;string">forbid</config:hasMode> + <config:hasObjectFilterSet rdf:resource="#dbpediaGeneralObjectFilter"/> + <config:hasObjectFilterSet rdf:resource="#foafObjectFilter"/> + <config:hasObjectFilterSet rdf:resource="#yagoObjectFilter"/> + <config:hasPredicateFilterSet rdf:resource="#dbpediaGeneralPredicateFilter"/> + <config:hasPredicateFilterSet rdf:resource="#foafPredicateFilter"/> + <config:hasPredicateFilterSet rdf:resource="#sameAsFilter"/> + <config:hasPredicateFilterSet rdf:resource="#yagoPredicateFilter"/> + <config:usesLiterals rdf:datatype="&xsd;string">false</config:usesLiterals> + </config:TypedQuery> + <config:Configuration rdf:about="#dbpediatest" rdfs:comment="for first test"> + <config:hasRecursionDepth rdf:datatype="&xsd;string">2</config:hasRecursionDepth> + <config:hasSparqlEndpoint rdf:resource="#dbpediaEndpoint"/> + <config:hasTypedQuery rdf:resource="#dbpediaYago"/> + </config:Configuration> + <config:GETParameter rdf:about="#defaultgraphuri"> + <config:hasParameterContent rdf:datatype="&xsd;string">http://dbpedia.org</config:hasParameterContent> + <config:hasParameterName rdf:datatype="&xsd;string">default-graph-uri</config:hasParameterName> + </config:GETParameter> + <config:ObjectFilterSet rdf:about="#foafObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://xmlns.com/foaf/0.1/</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#foafPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://xmlns.com/foaf/0.1/</config:filtersURI> + </config:PredicateFilterSet> + <config:GETParameter rdf:about="#format"> + <config:hasParameterContent rdf:datatype="&xsd;string">application/sparql-results.xml</config:hasParameterContent> + <config:hasParameterName rdf:datatype="&xsd;string">format</config:hasParameterName> + </config:GETParameter> + <config:Configuration rdf:about="#localjoseki"> + <config:hasRecursionDepth rdf:datatype="&xsd;string">2</config:hasRecursionDepth> + <config:hasSparqlEndpoint rdf:resource="#localjosekiendpoint"/> + <config:hasTypedQuery rdf:resource="#localjosekitypedquery"/> + </config:Configuration> + <config:SparqlEndpoint rdf:about="#localjosekiendpoint"> + <config:hasAfterGET rdf:datatype="&xsd;string">/books</config:hasAfterGET> + <config:hasHost rdf:datatype="http://www.w3.org/2001/XMLSchema#string">localhost</config:hasHost> + <config:hasPort rdf:datatype="&xsd;string">2020</config:hasPort> + <config:hasQueryParameter rdf:datatype="&xsd;string">query</config:hasQueryParameter> + <config:hasURL>localhost:2020/books</config:hasURL> + </config:SparqlEndpoint> + <config:TypedQuery rdf:about="#localjosekitypedquery"> + <config:hasMode rdf:datatype="&xsd;string">forbid</config:hasMode> + <config:hasObjectFilterSet rdf:resource="#dbpediaGeneralObjectFilter"/> + <config:hasPredicateFilterSet rdf:resource="#dbpediaGeneralPredicateFilter"/> + <config:usesLiterals rdf:datatype="&xsd;string">false</config:usesLiterals> + </config:TypedQuery> + <config:PredicateFilterSet rdf:about="#sameAsFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2002/07/owl#sameAs</config:filtersURI> + </config:PredicateFilterSet> + <config:ObjectFilterSet rdf:about="#yagoObjectFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Articles_</config:filtersURI> + <config:filtersURI rdf:datatype="&xsd;string">http://dbpedia.org/resource/Category:Wikipedia_</config:filtersURI> + </config:ObjectFilterSet> + <config:PredicateFilterSet rdf:about="#yagoPredicateFilter"> + <config:filtersURI rdf:datatype="&xsd;string">http://www.w3.org/2004/02/skos/core</config:filtersURI> + </config:PredicateFilterSet> + <rdf:Description rdf:about="#hasURL"> + <rdf:type> + <rdf:Description rdf:about="http://www.w3.org/2002/07/owl#DatatypeProperty"/> + </rdf:type> + <rdfs:domain> + <rdf:Description rdf:about="#SparqlEndpoint"/> + </rdfs:domain> + </rdf:Description> +</rdf:RDF> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-01 20:50:21
|
Revision: 293 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=293&view=rev Author: kurzum Date: 2007-12-01 12:50:16 -0800 (Sat, 01 Dec 2007) Log Message: ----------- all files Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/extraction/ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Tupel.java trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/TypedSparqlQuery.java Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Configuration.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,202 @@ +package org.dllearner.kb.extraction; + +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import org.semanticweb.owl.apibinding.OWLManager; +import org.semanticweb.owl.model.OWLConstant; +import org.semanticweb.owl.model.OWLDataPropertyExpression; +import org.semanticweb.owl.model.OWLIndividual; +import org.semanticweb.owl.model.OWLObjectPropertyExpression; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.model.OWLOntologyManager; + +public class Configuration { + private SparqlEndpoint SparqlEndpoint; + private SparqlQueryType SparqlQueryType; + private Manipulator Manipulator; + + + private Configuration(){ + } + public Configuration(SparqlEndpoint SparqlEndpoint,SparqlQueryType SparqlQueryType){ + this.SparqlEndpoint=SparqlEndpoint; + this.SparqlQueryType=SparqlQueryType; + } + + + public static Configuration getConfiguration(URI uri){ + //public static String getTellsString(URL file, URI kbURI){//throws OWLOntologyCreationException{ + Configuration ret=new Configuration(); + try{ + String file="config/config.owl"; + + + File f= new File(file); + String fileURL="file:///"+f.getAbsolutePath(); + URL u=new URL(fileURL); + /* Load an ontology from a physical URI */ + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = manager.loadOntologyFromPhysicalURI(u.toURI()); + //System.out.println( ontology.containsIndividualReference(uri)); + //OWLIndividualImpl ind=new OWLIndividualImpl(); + //System.out.println(ontology.getReferencedIndividuals()); + Set<OWLIndividual> s=ontology.getReferencedIndividuals(); + //System.out.println(ontology.getReferencedClasses()); + //Set<OWLIndividualAxiom> s= ontology.getIndividualAxioms(); + Iterator<OWLIndividual> it=s.iterator(); + while (it.hasNext()){ + OWLIndividual tmp=(OWLIndividual)it.next(); + //tmp.getURI() + if(tmp.getURI().equals(uri)){ + OWLIndividual[] arr=getIndividualsForProperty("hasSparqlEndpoint",tmp.getObjectPropertyValues(ontology)); + OWLIndividual sEndpoint=arr[0]; + ret.SparqlEndpoint=makeEndpoint(sEndpoint, ontology); + arr=getIndividualsForProperty("hasTypedQuery",tmp.getObjectPropertyValues(ontology)); + OWLIndividual typedQuery=arr[0]; + ret.SparqlQueryType=makeSparqlQueryType(typedQuery, ontology); + + } + //{hasSparqlEndpoint=[dbpediaEndpoint]} + } + + ret.Manipulator=makeManipulator(); + }catch (Exception e) {e.printStackTrace();} + + return ret; + } + + + + + + public static OWLIndividual[] getIndividualsForProperty(String propertyname,Map<OWLObjectPropertyExpression, Set<OWLIndividual>> m){ + Set<OWLObjectPropertyExpression> s=m.keySet(); + + Iterator<OWLObjectPropertyExpression> it=s.iterator(); + while (it.hasNext()){ + OWLObjectPropertyExpression tmp=(OWLObjectPropertyExpression)it.next(); + //System.out.println(tmp); + //System.out.println(propertyname); + if(tmp.toString().equals(propertyname)) + { + Object[] arr=((Set<OWLIndividual>)m.get(tmp)).toArray() ; + OWLIndividual[] o=new OWLIndividual[arr.length]; + for (int i = 0; i < o.length; i++) { + o[i]=(OWLIndividual)arr[i]; + } + + return o;} + } + return null; + + } + + public static String getFirstValueForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ + return getValuesForDataProperty(propertyname, m)[0]; + } + + public static String[] getValuesForDataProperty(String propertyname,Map<OWLDataPropertyExpression, Set<OWLConstant>> m){ + Set<OWLDataPropertyExpression> s=m.keySet(); + + Iterator<OWLDataPropertyExpression> it=s.iterator(); + while (it.hasNext()){ + OWLDataPropertyExpression tmp=(OWLDataPropertyExpression)it.next(); + if(tmp.toString().equals(propertyname)) + { + Object[] arr=((Set<OWLConstant>)m.get(tmp)).toArray() ; + String[] str=new String[arr.length]; + for (int i = 0; i < str.length; i++) { + str[i]=((OWLConstant)arr[i]).getLiteral(); + } + return str;} + } + return null; + + } + + public static SparqlEndpoint makeEndpoint(OWLIndividual sEndpoint,OWLOntology o){ + String host=getFirstValueForDataProperty("hasHost",sEndpoint.getDataPropertyValues(o)); + String port=getFirstValueForDataProperty("hasPort",sEndpoint.getDataPropertyValues(o)); + String hasAfterGET=getFirstValueForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); + String hasQueryParameter=getFirstValueForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); + OWLIndividual[] para=getIndividualsForProperty("hasGETParameter",sEndpoint.getObjectPropertyValues(o)); + //System.out.println("test"); + HashMap<String,String> parameters=new HashMap<String,String>(); + if(para==null)return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); + for (OWLIndividual p : para) { + //System.out.println("test2"); + String a1=getFirstValueForDataProperty("hasParameterName",p.getDataPropertyValues(o)); + String a2=getFirstValueForDataProperty("hasParameterContent",p.getDataPropertyValues(o)); + parameters.put(a1, a2); + } + //System.out.println("test2"); + //System.out.println(host+port+ hasAfterGET+ hasQueryParameter+ parameters); + return new SparqlEndpoint( host, port, hasAfterGET, hasQueryParameter, parameters); + + + + } + + public static SparqlQueryType makeSparqlQueryType(OWLIndividual typedQuery,OWLOntology o){ + String useLiterals=getFirstValueForDataProperty("usesLiterals",typedQuery.getDataPropertyValues(o)); + String hasMode=getFirstValueForDataProperty("hasMode",typedQuery.getDataPropertyValues(o)); + //String hasAfterGET=getValuesForDataProperty("hasAfterGET",sEndpoint.getDataPropertyValues(o)); + //String hasQueryParameter=getValuesForDataProperty("hasQueryParameter",sEndpoint.getDataPropertyValues(o)); + OWLIndividual[] objFilter=getIndividualsForProperty("hasObjectFilterSet",typedQuery.getObjectPropertyValues(o)); + OWLIndividual[] predFilter=getIndividualsForProperty("hasPredicateFilterSet",typedQuery.getObjectPropertyValues(o)); + + Set<String> objectFilter=new HashSet<String>(); + Set<String> predicateFilter=new HashSet<String>(); + + for (OWLIndividual of : objFilter) { + String[] tmp=getValuesForDataProperty("filtersURI",of.getDataPropertyValues(o)); + for (String s : tmp){ + objectFilter.add(s); + + } + } + + for (OWLIndividual pf : predFilter) { + String[] tmp=getValuesForDataProperty("filtersURI",pf.getDataPropertyValues(o)); + for (String s : tmp){ + predicateFilter.add(s); + + } + } + //System.out.println(predicateFilter); + //System.out.println(hasMode+objectFilter+predicateFilter+useLiterals); + return new SparqlQueryType(hasMode,objectFilter,predicateFilter,useLiterals); + + + + } + + public static Manipulator makeManipulator() { + return new Manipulator(); + } + + + public Manipulator getManipulator() { + return this.Manipulator; + } + + public SparqlEndpoint getSparqlEndpoint() { + return SparqlEndpoint; + } + + + + public SparqlQueryType getSparqlQueryType() { + return SparqlQueryType; + } + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/ExtractionAlgorithm.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,74 @@ +package org.dllearner.kb.extraction; + +import java.net.URI; +import java.util.Vector; + +import org.dllearner.kb.extraction.datastructures.InstanceNode; +import org.dllearner.kb.extraction.datastructures.Node; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public class ExtractionAlgorithm { + + private Configuration Configuration; + private Manipulator Manipulator; + private int recursiondepth=2; + private boolean getAllBackground=true; + + + + public ExtractionAlgorithm (Configuration Configuration){ + this.Configuration=Configuration; + this.Manipulator=Configuration.getManipulator(); + + } + + public Node getFirstNode(URI u){ + return new InstanceNode(u); + } + public Vector<Node> expandAll(URI[] u,TypedSparqlQuery tsp){ + Vector<Node> v=new Vector<Node>(); + for(URI one:u){ + v.add(expandNode(one, tsp)); + } + return v; + } + + + public Node expandNode(URI u, TypedSparqlQuery tsp){ + Node n=getFirstNode(u); + Vector<Node> v=new Vector<Node>(); + v.add(n); + System.out.println("StartVector: "+v); + // n.expand(tsp, this.Manipulator); + //Vector<Node> second= + for(int x=1;x<=this.recursiondepth;x++){ + + Vector<Node>tmp=new Vector<Node>(); + while (v.size()>0) { + Node tmpNode=v.remove(0); + System.out.println("Expanding "+tmpNode); + Vector<Node> tmpVec=tmpNode.expand(tsp, this.Manipulator); + + tmp.addAll(tmpVec); + } + v=tmp; + System.out.println("Rec: "+x+" with "+v); + } + if(this.getAllBackground){ + Vector<Node> classes=new Vector<Node>(); + for(Node one:v){ + if(one.isClass()) {classes.add(one);} + } + while(classes.size()>0){ + System.out.println(classes.size()); + classes.addAll(classes.remove(0).expand(tsp, this.Manipulator)); + } + + } + return n; + + } + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manager.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,67 @@ +package org.dllearner.kb.extraction; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +import org.dllearner.kb.extraction.datastructures.Node; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public class Manager { + + private Configuration Configuration; + private TypedSparqlQuery TypedSparqlQuery; + private ExtractionAlgorithm ExtractionAlgorithm; + + + public void usePredefinedConfiguration(URI uri){ + + this.Configuration=org.dllearner.kb.extraction.Configuration.getConfiguration(uri); + this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); + } + + public void useConfiguration(SparqlQueryType SparqlQueryType, SparqlEndpoint SparqlEndpoint){ + + this.Configuration=new Configuration(SparqlEndpoint,SparqlQueryType); + this.TypedSparqlQuery=new TypedSparqlQuery(Configuration); + this.ExtractionAlgorithm=new ExtractionAlgorithm(Configuration); + } + + public String extract(URI uri){ + //this.TypedSparqlQuery.query(uri); + //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Node n=this.ExtractionAlgorithm.expandNode(uri, this.TypedSparqlQuery); + Set<String> s=n.toNTriple(); + String nt=""; + for(String str:s){ + nt+=str+"\n"; + } + return nt; + } + + public String extract(Set<String> instances){ + //this.TypedSparqlQuery.query(uri); + //System.out.println(ExtractionAlgorithm.getFirstNode(uri)); + System.out.println("Start extracting"); + Set<String> ret=new HashSet<String>(); + + + for(String one:instances){ + try{ + Node n=this.ExtractionAlgorithm.expandNode(new URI(one),this.TypedSparqlQuery); + ret.addAll(n.toNTriple()); + }catch (Exception e) {e.printStackTrace();} + } + + + String nt=""; + for(String str:ret){ + nt+=str+"\n"; + } + return nt; + } + + +} \ No newline at end of file Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Manipulator.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,55 @@ +package org.dllearner.kb.extraction; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.dllearner.kb.extraction.datastructures.Node; +import org.dllearner.kb.extraction.datastructures.Tupel; + +public class Manipulator { + public String subclass="http://www.w3.org/2000/01/rdf-schema#subClassOf"; + public 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"; + + Set<String> classproperties; + + + 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/"}; //TODO FEHLER hier fehlt yago + + public Manipulator(){ + Set<String> classproperties=new HashSet<String>(); + classproperties.add(subclass); + + } + + public Set<Tupel> check(Set<Tupel> s,Node node){ + Set<Tupel> toRemove=new HashSet<Tupel>(); + Iterator<Tupel> it=s.iterator(); + while(it.hasNext()){ + Tupel t=(Tupel)it.next(); + //all classes with owl:type class + if(t.a.equals(this.type) && t.b.equals(this.classns)&& node.isClass() ) + {toRemove.add(t);}; + // all with type class + if( t.b.equals(this.classns) && node.isClass() ) + {toRemove.add(t);}; + // all instances with owl:type thing + if(t.a.equals(this.type) && t.b.equals(this.thing)&& node.isInstance() ) + {toRemove.add(t);}; + + } + s.removeAll(toRemove); + + return s; + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlEndpoint.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,69 @@ +package org.dllearner.kb.extraction; + +import java.util.HashMap; + +public class SparqlEndpoint { + + String host; + int port; + String hasAfterGET; + String hasQueryParameter; + String hasURL; + public HashMap<String,String> parameters=new HashMap<String,String>(); + public SparqlEndpoint(String host, String port, String hasAfterGET, String hasQueryParameter, HashMap<String, String> parameters) { + super(); + this.host = host; + this.port = Integer.parseInt(port); + this.hasAfterGET = hasAfterGET; + this.hasQueryParameter = hasQueryParameter; + this.parameters = parameters; + } + + public SparqlEndpoint(String host, int port, String hasURL, HashMap<String, String> parameters) { + super(); + this.port=port; + this.host=host; + this.hasURL = hasURL; + this.hasQueryParameter = "query"; + this.parameters = parameters; + } + public String getHasAfterGET() { + return hasAfterGET; + } + public void setHasAfterGET(String hasAfterGET) { + this.hasAfterGET = hasAfterGET; + } + public String getHasQueryParameter() { + return hasQueryParameter; + } + public void setHasQueryParameter(String hasQueryParameter) { + this.hasQueryParameter = hasQueryParameter; + } + public String getHost() { + return host; + } + public void setHost(String host) { + this.host = host; + } + public HashMap<String, String> getParameters() { + return parameters; + } + public void setParameters(HashMap<String, String> parameters) { + this.parameters = parameters; + } + public int getPort() { + return port; + } + public void setPort(int port) { + this.port = port; + } + + + + + /*sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + //"SELECT%20%2A%20WHERE%20%7B%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FAristotle%3E%20%3Fa%20%3Fb%20%7D%20" + + URLEncoder.encode(query, "UTF-8")+ + //query+// URLencode + "&format=application%2Fsparql-results%2Bxml*/ +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/SparqlQueryType.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,68 @@ +package org.dllearner.kb.extraction; + +import java.util.Set; + +public class SparqlQueryType { + + private String mode="forbid"; + private String[] objectfilterlist={ + "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"}; + private String[] predicatefilterlist={ + "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" }; + private boolean literals=false; + + public SparqlQueryType(String mode, String[] obectfilterlist, String[] predicatefilterlist, boolean literals) { + super(); + this.mode = mode; + this.objectfilterlist = obectfilterlist; + this.predicatefilterlist = predicatefilterlist; + this.literals = literals; + } + + public SparqlQueryType(String mode, Set<String> objectfilterlist, Set<String> predicatefilterlist, String literals) { + super(); + this.mode = mode; + this.literals = (literals.equals("true"))?true:false; + + Object[] arr=objectfilterlist.toArray(); + Object[] arr2=predicatefilterlist.toArray(); + this.objectfilterlist = new String[arr.length]; + this.predicatefilterlist = new String[arr2.length]; + for (int i = 0; i < arr.length; i++) { + this.objectfilterlist[i]=(String)arr[i]; + } + for (int i = 0; i < arr2.length; i++) { + this.predicatefilterlist[i]=(String)arr2[i]; + } + + + } + + public boolean isLiterals() { + return literals; + } + + public String getMode() { + return mode; + } + + public String[] getObjectfilterlist() { + return objectfilterlist; + } + + public String[] getPredicatefilterlist() { + return predicatefilterlist; + } + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/Test.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,31 @@ +package org.dllearner.kb.extraction; + +import java.io.File; +import java.io.FileWriter; +import java.net.URI; + +public class Test { + + + public static void main(String[] args) { + System.out.println("Start"); + String test2="http://www.extraction.org/config#dbpediatest"; + String test="http://www.extraction.org/config#localjoseki"; + try{ + URI u=new URI(test); + Manager m=new Manager(); + m.usePredefinedConfiguration(u); + + + URI u2=new URI("http://dbpedia.org/resource/Angela_Merkel"); + + String filename=System.currentTimeMillis()+".nt"; + FileWriter fw=new FileWriter(new File(filename),true); + fw.write(m.extract(u2)); + fw.flush(); + fw.close(); + + }catch (Exception e) {e.printStackTrace();} + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/ClassNode.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,60 @@ +package org.dllearner.kb.extraction.datastructures; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public class ClassNode extends Node{ + Set<PropertyNode> properties=new HashSet<PropertyNode>(); + + public ClassNode(URI u) { + super(u); + this.type="class"; + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq,Manipulator m){ + Set<Tupel> s =tsq.query(this.URI); + s=m.check(s, this); + Vector<Node> Nodes=new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it=s.iterator(); + while(it.hasNext()){ + Tupel t=(Tupel)it.next(); + try{ + 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); + } + }catch (Exception e) {System.out.println(t);e.printStackTrace();} + + } + return Nodes; + } + + @Override + public boolean isClass(){ + return true; + } + + @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; + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/InstanceNode.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,77 @@ +package org.dllearner.kb.extraction.datastructures; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public class InstanceNode extends Node{ + + Set<ClassNode> classes=new HashSet<ClassNode>(); + Set<Tupel> datatypes=new HashSet<Tupel>(); + Set<PropertyNode> properties=new HashSet<PropertyNode>(); + + public InstanceNode(URI u) { + super(u); + this.type="instance"; + + } + + @Override + public Vector<Node> expand(TypedSparqlQuery tsq,Manipulator m){ + + Set<Tupel> s =tsq.query(this.URI); + // Manipulation + m.check(s,this); + Vector<Node> Nodes=new Vector<Node>(); + + Iterator<Tupel> it=s.iterator(); + while(it.hasNext()){ + Tupel t=(Tupel)it.next(); + + 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();} + + } + this.expanded=true; + return Nodes; + } + @Override + public boolean isInstance(){ + return true; + } + + @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#Thing"+">."); + for (ClassNode one:classes){ + s.add("<"+this.URI+"><"+"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"+"><"+one.getURI()+">."); + s.addAll(one.toNTriple()); + } + for (PropertyNode one:properties){ + s.add("<"+this.URI+"><"+one.getURI()+"><"+one.getB().getURI()+">."); + s.addAll(one.toNTriple()); + s.addAll(one.getB().toNTriple()); + } + + return s; + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Node.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,54 @@ +package org.dllearner.kb.extraction.datastructures; + +import java.net.URI; +import java.util.Set; +import java.util.Vector; + +import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public abstract class Node { + URI URI; + protected String type; + protected boolean expanded=false; + + //Hashtable<String,Node> classes=new Hashtable<String,Node>(); + //Hashtable<String,Node> instances=new Hashtable<String,Node>();; + //Hashtable<String,Node> datatype=new Hashtable<String,Node>();; + + public Node (URI u){ + this.URI=u; + + } + + /*public void checkConsistency(){ + if (type.equals("class") && ( instances.size()>0 || datatype.size()>0)){ + System.out.println("Warning, inconsistent:"+this.toString()); + } + + }*/ + + public abstract Vector<Node> expand(TypedSparqlQuery tsq,Manipulator m); + public abstract Set<String> toNTriple(); + + @Override + public String toString(){ + return "Node: "+URI+":"+type; + + } + + + public boolean isClass(){ + return false; + } + public boolean isInstance(){ + return false; + } + public boolean isProperty(){ + return false; + } + public URI getURI() { + return URI; + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/PropertyNode.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,74 @@ +package org.dllearner.kb.extraction.datastructures; + +import java.net.URI; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import org.dllearner.kb.extraction.Manipulator; +import org.dllearner.kb.extraction.sparql.TypedSparqlQuery; + +public class PropertyNode extends Node{ + + private Node a; + private Node b; + 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(TypedSparqlQuery tsq,Manipulator m){ + Set<Tupel> s =tsq.query(this.URI); + Vector<Node> Nodes=new Vector<Node>(); + // Manipulation + + Iterator<Tupel> it=s.iterator(); + while(it.hasNext()){ + Tupel t=(Tupel)it.next(); + try{ + if(t.a.equals(m.type) ){ + SpecialTypes.add(t.b); + } + }catch (Exception e) {System.out.println(t);e.printStackTrace();} + + } + return Nodes; + } + @Override + public boolean isProperty(){ + return true; + } + public Node getB(){ + return this.b; + } + + @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#ObjectProperty"+">."); + for (String one:SpecialTypes){ + s.add("<"+this.URI+"><"+"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"+"><"+one+">."); + + } + + return s; + } + + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Tupel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Tupel.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/datastructures/Tupel.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,25 @@ +package org.dllearner.kb.extraction.datastructures; + +public class Tupel { + + public String a; + public String b; + + public Tupel(String a, String b) { + this.a = a; + this.b = b; + } + + @Override + public String toString(){ + return "<"+a+"|"+b+">"; + } + + public boolean equals(Tupel t){ + if(this.a.equals(t.a)&& this.b.equals(t.b))return true; + else return false; + } + + + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/Cache.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,115 @@ +package org.dllearner.kb.extraction.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; + +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"; + long timestamp; + String content=""; + long daysoffreshness=15; + long multiplier=24*60*60*1000;//h m s ms + String sparqlquery=""; + + //constructor for the cache itself + public Cache(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) + public Cache(String c, String sparql){ + this.content=c; + this.sparqlquery=sparql; + this.timestamp=System.currentTimeMillis(); + } + + + public String get(String key, String sparql){ + //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"); + if(!c.validate(sparql))return null; + //System.out.println("valid"); + ret=c.content; + }catch (Exception e) {e.printStackTrace();} + return ret; + }; + public void put(String key, String content, String sparql){ + //System.out.println("put into "+key); + Cache c=new Cache(content,sparql); + putIntoFile(makeFilename(key), c); + } + + + String makeFilename(String key){ + String ret=""; + try{ + ret=basedir+URLEncoder.encode(key, "UTF-8")+fileending; + }catch (Exception e) {e.printStackTrace();} + return ret; + } + boolean checkFreshness(){ + if((System.currentTimeMillis()-this.timestamp)<=(daysoffreshness*multiplier)) + //fresh + return true; + else return false; + } + boolean validate(String sparql){ + if(this.sparqlquery.equals(sparql)) + //valid + return true; + else return false; + } + + public void checkFile(String Filename){ + if(!new File(Filename).exists()){ + try{ + new File(Filename).createNewFile(); + }catch (Exception e) {e.printStackTrace();} + + } + + } + + public void putIntoFile(String Filename,Cache content){ + try{ + //FileWriter fw=new FileWriter(new File(Filename),true); + 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);} + } + + public 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; + + } +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SimpleHTTPRequest.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,129 @@ +package org.dllearner.kb.extraction.sparql; + +import java.io.BufferedInputStream; +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.InetAddress; +import java.net.Socket; +import java.net.URL; +import java.net.URLEncoder; + + + +public class SimpleHTTPRequest { + static final char value[]={13,10}; + static final String cut=new String(value); + private InetAddress ia; + private int port; + + + + public SimpleHTTPRequest(InetAddress ia, int port) { + super(); + this.ia = ia; + this.port = port; + + } + + public String sendAndReceive( String content){ + String retval=""; + // + + byte resp[]=null; + + try{ + Socket SparqlServer=new Socket(this.ia,this.port); + //String request=makeHeader(content); + // send request + (SparqlServer.getOutputStream()).write(content.getBytes()); + + //get Response + resp=readBuffer(new BufferedInputStream(SparqlServer.getInputStream())); + retval=new String(resp); + retval=subtractResponseHeader(retval); + //retval="||"+retval; + + SparqlServer.close(); + + + + } + catch(Exception e){e.printStackTrace();} + //System.out.println("got it"); + return retval; + + }//down + + public static byte[] readBuffer(InputStream IS) + throws IOException{ + byte buffer[] = new byte[0xffff]; + int nbytes=0; + byte resp[]=new byte[0]; + while ((nbytes=IS.read(buffer))!=-1) { + byte tmp[]=new byte[resp.length+nbytes]; + int i=0; + for (;i<resp.length;i++){ + tmp[i]=resp[i]; + } + for(int a=0;a<nbytes;a++,i++){ + tmp[i]=buffer[a]; + } + resp=tmp; + } + return resp; + } + + public String subtractResponseHeader(String in){ + //System.out.println(in.indexOf(cut+""+cut)); + return in.substring(in.indexOf(cut+""+cut)+4); + + + } + + + private String sendAndReceive2(String sparql,URL url) throws IOException{ + StringBuilder answer = new StringBuilder(); + + // String an Sparql-Endpoint schicken + HttpURLConnection connection; + + connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + + connection.addRequestProperty("Host", "dbpedia.openlinksw.com"); + connection.addRequestProperty("Connection","close"); + connection.addRequestProperty("Accept","text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); + connection.addRequestProperty("Accept-Language","de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"); + connection.addRequestProperty("Accept-Charset","utf-8;q=1.0"); + connection.addRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"); + + OutputStream os = connection.getOutputStream(); + OutputStreamWriter osw = new OutputStreamWriter(os); + osw.write("default-graph-uri=http%3A%2F%2Fdbpedia.org&query=" + + URLEncoder.encode(sparql, "UTF-8")+ + "&format=application%2Fsparql-results%2Bxml"); + osw.close(); + + // receive answer + InputStream is = connection.getInputStream(); + InputStreamReader isr = new InputStreamReader(is,"UTF-8"); + BufferedReader br = new BufferedReader(isr); + + String line; + do { + line = br.readLine(); + if(line!=null) + answer.append(line); + } while (line != null); + + br.close(); + + return answer.toString(); + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlHTTPRequest.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,82 @@ +package org.dllearner.kb.extraction.sparql; + +import java.net.InetAddress; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Set; + +import org.dllearner.kb.extraction.SparqlEndpoint; + + + +public class SparqlHTTPRequest { + static final char value[]={13,10}; + static final String cut=new String(value); + + private SparqlEndpoint SparqlEndpoint; + private SimpleHTTPRequest SimpleHTTPRequest; + + + public SparqlHTTPRequest(SparqlEndpoint SparqlEndpoint){ + this.SparqlEndpoint=SparqlEndpoint; + InetAddress ia=null; + try{ + ia=InetAddress.getByName(SparqlEndpoint.getHost()); + }catch (Exception e) {e.printStackTrace();} + this.SimpleHTTPRequest=new SimpleHTTPRequest(ia,SparqlEndpoint.getPort()); + + } + + + public String sendAndReceiveSPARQL( String sparql){ + + //System.out.println(sparql); + String content=makeContent(sparql ); + //System.out.println(content); + String ret= this.SimpleHTTPRequest.sendAndReceive(content); + //System.out.println(ret); + + //this.sendAndReceiveSPARQL("SELECT * WHERE {?a ?b ?c} LIMIT 10"); + + return ret; + + + }//down + + + + + public String makeContent(String query){ + + + String RequestHeader=""; + try{ + + RequestHeader="GET "; + RequestHeader+=SparqlEndpoint.getHasAfterGET()+"?"; + // parameters + Set<String> s =SparqlEndpoint.getParameters().keySet(); + Iterator<String> it=s.iterator(); + while (it.hasNext()) { + String element = (String) it.next(); + RequestHeader+=""+URLEncoder.encode(element, "UTF-8")+"="+ + URLEncoder.encode(SparqlEndpoint.getParameters().get(element), "UTF-8")+"&"; + } + RequestHeader+=""+SparqlEndpoint.getHasQueryParameter()+"="+URLEncoder.encode(query, "UTF-8"); + RequestHeader+=" HTTP/1.1"+cut; + RequestHeader+="Host: "+SparqlEndpoint.getHost()+cut; + + RequestHeader+= + "Connection: close"+cut+ + //"Accept-Encoding: gzip"+cut+ + "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"+cut+ + "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"+cut+ + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"+cut+ + "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4 Web-Sniffer/1.0.24"+cut+ + cut; + }catch (Exception e) {e.printStackTrace();} + return RequestHeader; + + } + +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/SparqlQueryMaker.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,46 @@ +package org.dllearner.kb.extraction.sparql; + +import org.dllearner.kb.extraction.SparqlQueryType; + + + +public class SparqlQueryMaker { + + private SparqlQueryType SparqlQueryType; + + public SparqlQueryMaker(SparqlQueryType SparqlQueryType){ + this.SparqlQueryType=SparqlQueryType; + } + + public String makeQueryUsingFilters(String subject){ + String lineend="\n"; + + String Filter=""; + if(!this.SparqlQueryType.isLiterals())Filter+="!isLiteral(?object))"; + for (String p : this.SparqlQueryType.getPredicatefilterlist()) { + Filter+=lineend + filterPredicate(p); + } + for (String o : this.SparqlQueryType.getObjectfilterlist()) { + Filter+=lineend + filterObject(o); + } + + + String ret= + "SELECT * WHERE { "+lineend + + "<"+ + subject+ + "> ?predicate ?object. "+ lineend+ + "FILTER( "+lineend + + "(" +Filter+").}"; + //System.out.println(ret); + return ret; + } + + + public String filterObject(String ns){ + return "&&( !regex(str(?object), '"+ns+"') )"; + } + public String filterPredicate(String ns){ + return "&&( !regex(str(?predicate), '"+ns+"') )"; + } +} Added: trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/TypedSparqlQuery.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/TypedSparqlQuery.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/extraction/sparql/TypedSparqlQuery.java 2007-12-01 20:50:16 UTC (rev 293) @@ -0,0 +1,83 @@ +package org.dllearner.kb.extraction.sparql; + +import java.net.URI; +import java.util.HashSet; +import java.util.Set; + +import org.dllearner.kb.extraction.Configuration; +import org.dllearner.kb.extraction.datastructures.Tupel; + + +public class TypedSparqlQuery { + private Configuration Configuration; + private SparqlHTTPRequest SparqlHTTPRequest; + private SparqlQueryMaker SparqlQueryMaker; + Cache Cache; + + public TypedSparqlQuery(Configuration Configuration){ + this.Configuration=Configuration; + this.SparqlHTTPRequest=new SparqlHTTPRequest(Configuration.getSparqlEndpoint()); + this.SparqlQueryMaker=new SparqlQueryMaker(Configuration.getSparqlQueryType()); + this.Cache=new Cache("cache"); + } + + public Set<Tupel> query(URI u){ + + //getQuery + String sparql=SparqlQueryMaker.makeQueryUsingFilters(u.toString()); + + // check cache + String FromCache=this.Cache.get(u.toString(), sparql); + FromCache=null; + String xml; + // if not in cache get it from EndPoint + if(FromCache==null){ + xml=this.SparqlHTTPRequest.sendAndReceiveSPARQL(sparql); + //this.Cache.put(u.toString(), xml, sparql); + System.out.print("\n"); + } + else{ + xml=FromCache; + System.out.println("FROM CACHE"); + } + + //System.out.println(xml); + //process XML + Set<Tupel> s=this.processResult(xml); + try { + System.out.println("retrieved "+s.size()+" tupels"); + } catch (Exception e) { } + return s; + } + + public Set<Tupel> processResult(String xml){ + + Set<Tupel> ret=new HashSet<Tupel>(); + //TODO if result is empty, catch exceptions + String one="<binding name=\"predicate\">"; + String two="<binding name=\"object\">"; + String uridel="<uri>"; + String end="</uri>"; + String predtmp=""; + String objtmp=""; + + while(xml.indexOf(one)!=-1){ + //get pred + xml=xml.substring(xml.indexOf(one)+one.length()); + xml=xml.substring(xml.indexOf(uridel)+uridel.length()); + predtmp=xml.substring(0,xml.indexOf(end)); + + //getobj + xml=xml.substring(xml.indexOf(two)+two.length()); + xml=xml.substring(xml.indexOf(uridel)+uridel.length()); + objtmp=xml.substring(0,xml.indexOf(end)); + ret.add(new Tupel(predtmp,objtmp)); + //System.out.println(new Tupel(predtmp,objtmp)); + } + + + return ret; + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ku...@us...> - 2007-12-01 20:48:58
|
Revision: 292 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=292&view=rev Author: kurzum Date: 2007-12-01 12:48:56 -0800 (Sat, 01 Dec 2007) Log Message: ----------- i tried to integrate it, but it is not working yet Added Paths: ----------- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java Added: trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlEndpointRestructured.java 2007-12-01 20:48:56 UTC (rev 292) @@ -0,0 +1,358 @@ +/** + * 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.io.StringReader; +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.kb.extraction.Manager; +import org.dllearner.kb.extraction.SparqlEndpoint; +import org.dllearner.kb.extraction.SparqlQueryType; +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 SparqlEndpointRestructured 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); + Manager m=new Manager(); + if(filterMode==0){ + try{ + m.usePredefinedConfiguration(new URI("http://www.extraction.org/config#dbpediatest")); + }catch (Exception e) {e.printStackTrace();} + } + else{ + //SparqlQueryType sqt=new SparqlQueryType("forbid", objList,predList,useLits+""); + //SparqlEndpoint se=new SparqlEndpoint(); + //m.useConfiguration(SparqlQueryType, SparqlEndpoint) + } + try + { + String ont=m.extract(instances); + + 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)); + } 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; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-30 16:12:24
|
Revision: 291 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=291&view=rev Author: jenslehmann Date: 2007-11-30 08:12:21 -0800 (Fri, 30 Nov 2007) Log Message: ----------- updated startup files Modified Paths: -------------- trunk/bin/dllearner trunk/bin/dllearner.bat trunk/bin/quickstart trunk/bin/quickstart.bat Modified: trunk/bin/dllearner =================================================================== --- trunk/bin/dllearner 2007-11-27 15:10:29 UTC (rev 290) +++ trunk/bin/dllearner 2007-11-30 16:12:21 UTC (rev 291) @@ -1 +1 @@ -java -cp .:./lib/dig1.1-xmlbeans.jar:./lib/jena/antlr-2.7.5.jar:./lib/jena/commons-logging.jar:./lib/jena/concurrent.jar:./lib/jena/icu4j_3_4.jar:./lib/jena/iri.jar:./lib/jena/jena.jar:./lib/jena/xercesImpl.jar:./lib/kaon2.jar:./lib/owlapi/antlr-runtime-3.0.jar:./lib/owlapi/commons-lang-2.2.jar:./lib/owlapi/owlapi-api.jar:./lib/owlapi/owlapi-apibinding.jar:./lib/owlapi/owlapi-change.jar:./lib/owlapi/owlapi-debugging.jar:./lib/owlapi/owlapi-dig1_1.jar:./lib/owlapi/owlapi-functionalparser.jar:./lib/owlapi/owlapi-functionalrenderer.jar:./lib/owlapi/owlapi-impl.jar:./lib/owlapi/owlapi-krssparser.jar:./lib/owlapi/owlapi-mansyntaxparser.jar:./lib/owlapi/owlapi-mansyntaxrenderer.jar:./lib/owlapi/owlapi-metrics.jar:./lib/owlapi/owlapi-oboparser.jar:./lib/owlapi/owlapi-owlxmlparser.jar:./lib/owlapi/owlapi-owlxmlrenderer.jar:./lib/owlapi/owlapi-rdfapi.jar:./lib/owlapi/owlapi-rdfxmlparser.jar:./lib/owlapi/owlapi-rdfxmlrenderer.jar:./lib/owlapi/owlapi-util.jar:./lib/xbean.jar:./lib/dllearner.jar org.dllearner.parser.DLLearner $@ \ No newline at end of file +java -cp .:./lib/dig1.1-xmlbeans.jar:./lib/jena/antlr-2.7.5.jar:./lib/jena/commons-logging.jar:./lib/jena/concurrent.jar:./lib/jena/icu4j_3_4.jar:./lib/jena/iri.jar:./lib/jena/jena.jar:./lib/jena/xercesImpl.jar:./lib/kaon2.jar:./lib/owlapi/antlr-runtime-3.0.jar:./lib/owlapi/commons-lang-2.2.jar:./lib/owlapi/owlapi-api.jar:./lib/owlapi/owlapi-apibinding.jar:./lib/owlapi/owlapi-change.jar:./lib/owlapi/owlapi-debugging.jar:./lib/owlapi/owlapi-dig1_1.jar:./lib/owlapi/owlapi-functionalparser.jar:./lib/owlapi/owlapi-functionalrenderer.jar:./lib/owlapi/owlapi-impl.jar:./lib/owlapi/owlapi-krssparser.jar:./lib/owlapi/owlapi-mansyntaxparser.jar:./lib/owlapi/owlapi-mansyntaxrenderer.jar:./lib/owlapi/owlapi-metrics.jar:./lib/owlapi/owlapi-oboparser.jar:./lib/owlapi/owlapi-owlxmlparser.jar:./lib/owlapi/owlapi-owlxmlrenderer.jar:./lib/owlapi/owlapi-rdfapi.jar:./lib/owlapi/owlapi-rdfxmlparser.jar:./lib/owlapi/owlapi-rdfxmlrenderer.jar:./lib/owlapi/owlapi-util.jar:./lib/xbean.jar:./lib/dllearner.jar org.dllearner.cli.start $@ \ No newline at end of file Modified: trunk/bin/dllearner.bat =================================================================== --- trunk/bin/dllearner.bat 2007-11-27 15:10:29 UTC (rev 290) +++ trunk/bin/dllearner.bat 2007-11-30 16:12:21 UTC (rev 291) @@ -1 +1 @@ -java -cp .;.\lib\dig1.1-xmlbeans.jar;.\lib\jena\antlr-2.7.5.jar;.\lib\jena\commons-logging.jar;.\lib\jena\concurrent.jar;.\lib\jena\icu4j_3_4.jar;.\lib\jena\iri.jar;.\lib\jena\jena.jar;.\lib\jena\xercesImpl.jar;.\lib\kaon2.jar;.\lib\owlapi\antlr-runtime-3.0.jar;.\lib\owlapi\commons-lang-2.2.jar;.\lib\owlapi\owlapi-api.jar;.\lib\owlapi\owlapi-apibinding.jar;.\lib\owlapi\owlapi-change.jar;.\lib\owlapi\owlapi-debugging.jar;.\lib\owlapi\owlapi-dig1_1.jar;.\lib\owlapi\owlapi-functionalparser.jar;.\lib\owlapi\owlapi-functionalrenderer.jar;.\lib\owlapi\owlapi-impl.jar;.\lib\owlapi\owlapi-krssparser.jar;.\lib\owlapi\owlapi-mansyntaxparser.jar;.\lib\owlapi\owlapi-mansyntaxrenderer.jar;.\lib\owlapi\owlapi-metrics.jar;.\lib\owlapi\owlapi-oboparser.jar;.\lib\owlapi\owlapi-owlxmlparser.jar;.\lib\owlapi\owlapi-owlxmlrenderer.jar;.\lib\owlapi\owlapi-rdfapi.jar;.\lib\owlapi\owlapi-rdfxmlparser.jar;.\lib\owlapi\owlapi-rdfxmlrenderer.jar;.\lib\owlapi\owlapi-util.jar;.\lib\xbean.jar;.\lib\dllearner.jar org.dllearner.parser.DLLearner %* \ No newline at end of file +java -cp .;.\lib\dig1.1-xmlbeans.jar;.\lib\jena\antlr-2.7.5.jar;.\lib\jena\commons-logging.jar;.\lib\jena\concurrent.jar;.\lib\jena\icu4j_3_4.jar;.\lib\jena\iri.jar;.\lib\jena\jena.jar;.\lib\jena\xercesImpl.jar;.\lib\kaon2.jar;.\lib\owlapi\antlr-runtime-3.0.jar;.\lib\owlapi\commons-lang-2.2.jar;.\lib\owlapi\owlapi-api.jar;.\lib\owlapi\owlapi-apibinding.jar;.\lib\owlapi\owlapi-change.jar;.\lib\owlapi\owlapi-debugging.jar;.\lib\owlapi\owlapi-dig1_1.jar;.\lib\owlapi\owlapi-functionalparser.jar;.\lib\owlapi\owlapi-functionalrenderer.jar;.\lib\owlapi\owlapi-impl.jar;.\lib\owlapi\owlapi-krssparser.jar;.\lib\owlapi\owlapi-mansyntaxparser.jar;.\lib\owlapi\owlapi-mansyntaxrenderer.jar;.\lib\owlapi\owlapi-metrics.jar;.\lib\owlapi\owlapi-oboparser.jar;.\lib\owlapi\owlapi-owlxmlparser.jar;.\lib\owlapi\owlapi-owlxmlrenderer.jar;.\lib\owlapi\owlapi-rdfapi.jar;.\lib\owlapi\owlapi-rdfxmlparser.jar;.\lib\owlapi\owlapi-rdfxmlrenderer.jar;.\lib\owlapi\owlapi-util.jar;.\lib\xbean.jar;.\lib\dllearner.jar org.dllearner.cli.Start %* \ No newline at end of file Modified: trunk/bin/quickstart =================================================================== --- trunk/bin/quickstart 2007-11-27 15:10:29 UTC (rev 290) +++ trunk/bin/quickstart 2007-11-30 16:12:21 UTC (rev 291) @@ -1 +1 @@ -java -cp .:./lib/dig1.1-xmlbeans.jar:./lib/jena/antlr-2.7.5.jar:./lib/jena/commons-logging.jar:./lib/jena/concurrent.jar:./lib/jena/icu4j_3_4.jar:./lib/jena/iri.jar:./lib/jena/jena.jar:./lib/jena/xercesImpl.jar:./lib/kaon2.jar:./lib/owlapi/antlr-runtime-3.0.jar:./lib/owlapi/commons-lang-2.2.jar:./lib/owlapi/owlapi-api.jar:./lib/owlapi/owlapi-apibinding.jar:./lib/owlapi/owlapi-change.jar:./lib/owlapi/owlapi-debugging.jar:./lib/owlapi/owlapi-dig1_1.jar:./lib/owlapi/owlapi-functionalparser.jar:./lib/owlapi/owlapi-functionalrenderer.jar:./lib/owlapi/owlapi-impl.jar:./lib/owlapi/owlapi-krssparser.jar:./lib/owlapi/owlapi-mansyntaxparser.jar:./lib/owlapi/owlapi-mansyntaxrenderer.jar:./lib/owlapi/owlapi-metrics.jar:./lib/owlapi/owlapi-oboparser.jar:./lib/owlapi/owlapi-owlxmlparser.jar:./lib/owlapi/owlapi-owlxmlrenderer.jar:./lib/owlapi/owlapi-rdfapi.jar:./lib/owlapi/owlapi-rdfxmlparser.jar:./lib/owlapi/owlapi-rdfxmlrenderer.jar:./lib/owlapi/owlapi-util.jar:./lib/xbean.jar:./lib/dllearner.jar org.dllearner.QuickStart \ No newline at end of file +java -cp .:./lib/dig1.1-xmlbeans.jar:./lib/jena/antlr-2.7.5.jar:./lib/jena/commons-logging.jar:./lib/jena/concurrent.jar:./lib/jena/icu4j_3_4.jar:./lib/jena/iri.jar:./lib/jena/jena.jar:./lib/jena/xercesImpl.jar:./lib/kaon2.jar:./lib/owlapi/antlr-runtime-3.0.jar:./lib/owlapi/commons-lang-2.2.jar:./lib/owlapi/owlapi-api.jar:./lib/owlapi/owlapi-apibinding.jar:./lib/owlapi/owlapi-change.jar:./lib/owlapi/owlapi-debugging.jar:./lib/owlapi/owlapi-dig1_1.jar:./lib/owlapi/owlapi-functionalparser.jar:./lib/owlapi/owlapi-functionalrenderer.jar:./lib/owlapi/owlapi-impl.jar:./lib/owlapi/owlapi-krssparser.jar:./lib/owlapi/owlapi-mansyntaxparser.jar:./lib/owlapi/owlapi-mansyntaxrenderer.jar:./lib/owlapi/owlapi-metrics.jar:./lib/owlapi/owlapi-oboparser.jar:./lib/owlapi/owlapi-owlxmlparser.jar:./lib/owlapi/owlapi-owlxmlrenderer.jar:./lib/owlapi/owlapi-rdfapi.jar:./lib/owlapi/owlapi-rdfxmlparser.jar:./lib/owlapi/owlapi-rdfxmlrenderer.jar:./lib/owlapi/owlapi-util.jar:./lib/xbean.jar:./lib/dllearner.jar org.dllearner.cli.QuickStart \ No newline at end of file Modified: trunk/bin/quickstart.bat =================================================================== --- trunk/bin/quickstart.bat 2007-11-27 15:10:29 UTC (rev 290) +++ trunk/bin/quickstart.bat 2007-11-30 16:12:21 UTC (rev 291) @@ -1 +1 @@ -java -cp .;.\lib\dig1.1-xmlbeans.jar;.\lib\jena\antlr-2.7.5.jar;.\lib\jena\commons-logging.jar;.\lib\jena\concurrent.jar;.\lib\jena\icu4j_3_4.jar;.\lib\jena\iri.jar;.\lib\jena\jena.jar;.\lib\jena\xercesImpl.jar;.\lib\kaon2.jar;.\lib\owlapi\antlr-runtime-3.0.jar;.\lib\owlapi\commons-lang-2.2.jar;.\lib\owlapi\owlapi-api.jar;.\lib\owlapi\owlapi-apibinding.jar;.\lib\owlapi\owlapi-change.jar;.\lib\owlapi\owlapi-debugging.jar;.\lib\owlapi\owlapi-dig1_1.jar;.\lib\owlapi\owlapi-functionalparser.jar;.\lib\owlapi\owlapi-functionalrenderer.jar;.\lib\owlapi\owlapi-impl.jar;.\lib\owlapi\owlapi-krssparser.jar;.\lib\owlapi\owlapi-mansyntaxparser.jar;.\lib\owlapi\owlapi-mansyntaxrenderer.jar;.\lib\owlapi\owlapi-metrics.jar;.\lib\owlapi\owlapi-oboparser.jar;.\lib\owlapi\owlapi-owlxmlparser.jar;.\lib\owlapi\owlapi-owlxmlrenderer.jar;.\lib\owlapi\owlapi-rdfapi.jar;.\lib\owlapi\owlapi-rdfxmlparser.jar;.\lib\owlapi\owlapi-rdfxmlrenderer.jar;.\lib\owlapi\owlapi-util.jar;.\lib\xbean.jar;.\lib\dllearner.jar org.dllearner.QuickStart \ No newline at end of file +java -cp .;.\lib\dig1.1-xmlbeans.jar;.\lib\jena\antlr-2.7.5.jar;.\lib\jena\commons-logging.jar;.\lib\jena\concurrent.jar;.\lib\jena\icu4j_3_4.jar;.\lib\jena\iri.jar;.\lib\jena\jena.jar;.\lib\jena\xercesImpl.jar;.\lib\kaon2.jar;.\lib\owlapi\antlr-runtime-3.0.jar;.\lib\owlapi\commons-lang-2.2.jar;.\lib\owlapi\owlapi-api.jar;.\lib\owlapi\owlapi-apibinding.jar;.\lib\owlapi\owlapi-change.jar;.\lib\owlapi\owlapi-debugging.jar;.\lib\owlapi\owlapi-dig1_1.jar;.\lib\owlapi\owlapi-functionalparser.jar;.\lib\owlapi\owlapi-functionalrenderer.jar;.\lib\owlapi\owlapi-impl.jar;.\lib\owlapi\owlapi-krssparser.jar;.\lib\owlapi\owlapi-mansyntaxparser.jar;.\lib\owlapi\owlapi-mansyntaxrenderer.jar;.\lib\owlapi\owlapi-metrics.jar;.\lib\owlapi\owlapi-oboparser.jar;.\lib\owlapi\owlapi-owlxmlparser.jar;.\lib\owlapi\owlapi-owlxmlrenderer.jar;.\lib\owlapi\owlapi-rdfapi.jar;.\lib\owlapi\owlapi-rdfxmlparser.jar;.\lib\owlapi\owlapi-rdfxmlrenderer.jar;.\lib\owlapi\owlapi-util.jar;.\lib\xbean.jar;.\lib\dllearner.jar org.dllearner.cli.QuickStart \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-27 15:10:36
|
Revision: 290 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=290&view=rev Author: jenslehmann Date: 2007-11-27 07:10:29 -0800 (Tue, 27 Nov 2007) Log Message: ----------- added getConceptLength() method to web service for family benchmark Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-11-25 11:37:52 UTC (rev 289) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-11-27 15:10:29 UTC (rev 290) @@ -420,7 +420,6 @@ try { concept = KBParser.parseConcept(conceptString); } catch (ParseException e) { - // TODO Auto-generated catch block e.printStackTrace(); } Set<Individual> individuals = state.getReasoningService().retrieval(concept); @@ -428,6 +427,18 @@ } @WebMethod + public int getConceptLength(String conceptString) { + // call parser to parse concept + Concept concept = null; + try { + concept = KBParser.parseConcept(conceptString); + } catch (ParseException e) { + e.printStackTrace(); + } + return concept.getLength(); + } + + @WebMethod public String[] getAtomicRoles(int id) throws ClientNotKnownException { ClientState state = getState(id); Set<AtomicRole> roles = state.getReasoningService().getAtomicRoles(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-25 11:37:57
|
Revision: 289 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=289&view=rev Author: jenslehmann Date: 2007-11-25 03:37:52 -0800 (Sun, 25 Nov 2007) Log Message: ----------- small example for Tilo Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ComponentRetrievalTest.java Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-11-24 09:04:49 UTC (rev 288) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-11-25 11:37:52 UTC (rev 289) @@ -64,11 +64,11 @@ // these variables are valid for the complete lifetime of DL-Learner private static String componentsFile = "lib/components.ini"; private static ComponentManager cm = new ComponentManager(); - private static Set<Class<? extends Component>> components; - private static Set<Class<? extends KnowledgeSource>> knowledgeSources; - private static Set<Class<? extends ReasonerComponent>> reasonerComponents; - private static Set<Class<? extends LearningProblem>> learningProblems; - private static Set<Class<? extends LearningAlgorithm>> learningAlgorithms; + private static Collection<Class<? extends Component>> components; + private static Collection<Class<? extends KnowledgeSource>> knowledgeSources; + private static Collection<Class<? extends ReasonerComponent>> reasonerComponents; + private static Collection<Class<? extends LearningProblem>> learningProblems; + private static Collection<Class<? extends LearningAlgorithm>> learningAlgorithms; // list of all configuration options of all components private static Map<Class<? extends Component>, String> componentNames; @@ -486,38 +486,36 @@ /** * @return the components */ - public static Set<Class<? extends Component>> getComponents() { - return components; + public List<Class<? extends Component>> getComponents() { + return new LinkedList<Class<? extends Component>>(components); } /** * @return the knowledgeSources */ - public static Set<Class<? extends KnowledgeSource>> getKnowledgeSources() { - return knowledgeSources; + public List<Class<? extends KnowledgeSource>> getKnowledgeSources() { + return new LinkedList<Class<? extends KnowledgeSource>>(knowledgeSources); } /** * @return the reasonerComponents */ - public static Set<Class<? extends ReasonerComponent>> getReasonerComponents() { - return reasonerComponents; + public List<Class<? extends ReasonerComponent>> getReasonerComponents() { + return new LinkedList<Class<? extends ReasonerComponent>>(reasonerComponents); } /** * @return the learningProblems */ - public static Set<Class<? extends LearningProblem>> getLearningProblems() { - return learningProblems; + public List<Class<? extends LearningProblem>> getLearningProblems() { + return new LinkedList<Class<? extends LearningProblem>>(learningProblems); } /** * @return the learningAlgorithms */ - public static Set<Class<? extends LearningAlgorithm>> getLearningAlgorithms() { - return learningAlgorithms; + public List<Class<? extends LearningAlgorithm>> getLearningAlgorithms() { + return new LinkedList<Class<? extends LearningAlgorithm>>(learningAlgorithms); } - - } Added: trunk/src/dl-learner/org/dllearner/gui/ComponentRetrievalTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ComponentRetrievalTest.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/ComponentRetrievalTest.java 2007-11-25 11:37:52 UTC (rev 289) @@ -0,0 +1,42 @@ +/** + * 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.gui; + +import java.util.List; + +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; + +/** + * @author Jens Lehmann + * + */ +public class ComponentRetrievalTest { + + /** + * @param args + */ + public static void main(String[] args) { + ComponentManager cm = ComponentManager.getInstance(); + List<Class<? extends KnowledgeSource>> sources = cm.getKnowledgeSources(); + cm.knowledgeSource(sources.get(0)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-24 09:04:54
|
Revision: 288 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=288&view=rev Author: jenslehmann Date: 2007-11-24 01:04:49 -0800 (Sat, 24 Nov 2007) Log Message: ----------- created a GUI demo using Swing Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java Added: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2007-11-24 09:04:49 UTC (rev 288) @@ -0,0 +1,190 @@ +/** + * 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.gui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.ReasoningService; +import org.dllearner.core.dl.Concept; +import org.dllearner.core.dl.Individual; +import org.dllearner.kb.OWLFile; +import org.dllearner.learningproblems.PosOnlyDefinitionLP; +import org.dllearner.reasoning.DIGReasoner; + +/** + * Mini GUI Demo. + * + * @author Jens Lehmann + * + */ +public class MiniGUI extends JPanel implements ActionListener { + + private static final long serialVersionUID = -4247224068574471307L; + + private static ComponentManager cm = ComponentManager.getInstance(); + private ReasoningService rs; + private File selectedFile; + + private JButton openButton; + private JButton startLearnButton; + private JTextField fileDisplay; + private JFileChooser fc; + private List<Individual> individuals; + private JList exampleList; + private JTextField solutionDisplay; + + public MiniGUI() { + super(new BorderLayout()); + + // create file chooser and a text field showing + // the file name + // (for simplicity we only allow to select one knowledge source) + fc = new JFileChooser(new File("examples/")); + openButton = new JButton("Open File ..."); + openButton.addActionListener(this); + fileDisplay = new JTextField(40); + fileDisplay.setEditable(false); + + JPanel openPanel = new JPanel(); + openPanel.add(fileDisplay); + openPanel.add(openButton); + + // create a scrollable list of examples + JPanel examplePanel = new JPanel(); + exampleList = new JList(); + exampleList.setLayoutOrientation(JList.VERTICAL); + exampleList.setVisibleRowCount(-1); + JScrollPane listScroller = new JScrollPane(exampleList); + listScroller.setPreferredSize(new Dimension(250, 80)); + examplePanel.add(listScroller); + + // create a "learn" button and a text field for displaying + // the obtained solution + startLearnButton = new JButton("Learn Concept"); + startLearnButton.addActionListener(this); + JPanel startLearnButtonPanel = new JPanel(); + startLearnButtonPanel.add(startLearnButton); + solutionDisplay = new JTextField(50); + solutionDisplay.setEditable(false); + JPanel startPanel = new JPanel(new BorderLayout()); + startPanel.add(startLearnButtonPanel, BorderLayout.NORTH); + startPanel.add(solutionDisplay, BorderLayout.SOUTH); + + // arrange the components on this panel + add(openPanel, BorderLayout.PAGE_START); + add(examplePanel, BorderLayout.CENTER); + add(startPanel, BorderLayout.PAGE_END); + } + + /* + * (non-Javadoc) + * + * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) + */ + public void actionPerformed(ActionEvent e) { + if (e.getSource() == openButton) { + int returnVal = fc.showOpenDialog(MiniGUI.this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + selectedFile = fc.getSelectedFile(); + fileDisplay.setText(selectedFile.toString()); + + // we blindly assume an OWL file was selected + // (everything else will cause an exception) + KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + cm.applyConfigEntry(source, "url", selectedFile.toURI().toString()); + source.init(); + + // use a reasoner to find out which instances exist + // in the background knowledge + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); + reasoner.init(); + rs = cm.reasoningService(reasoner); + Set<Individual> individualsSet = rs.getIndividuals(); + individuals = new LinkedList<Individual>(individualsSet); + + DefaultListModel listModel = new DefaultListModel(); + for(Individual ind : individuals) + listModel.addElement(ind); + + exampleList.setModel(listModel); + } + } else if(e.getSource() == startLearnButton) { + // detect which examples have been selected + Set<String> exampleSet = new HashSet<String>(); + int[] selectedIndices = exampleList.getSelectedIndices(); + for(int i : selectedIndices) + exampleSet.add(individuals.get(i).toString()); + + // create a positive only learning problem + LearningProblem lp = cm.learningProblem(PosOnlyDefinitionLP.class, rs); + cm.applyConfigEntry(lp, "positiveExamples", exampleSet); + lp.init(); + + // try the refinement operator based learning algorithm to solve + // the problem + LearningAlgorithm la = cm.learningAlgorithm(ROLearner.class, lp, rs); + la.init(); + la.start(); + + // wait for a solution (note that not all learning problems have a + // solution (100% accuracy), so one usually has to run the algorithm in its own + // thread, such that it can be aborted after some time + Concept solution = la.getBestSolution(); + solutionDisplay.setText(solution.toString()); + } + } + + public static void main(String[] args) { + + // create a frame containing the main panel + JFrame frame = new JFrame("Mini DL-Learner GUI Demo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new MiniGUI()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ton...@us...> - 2007-11-23 12:09:20
|
Revision: 287 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=287&view=rev Author: tonytacker Date: 2007-11-23 04:09:14 -0800 (Fri, 23 Nov 2007) Log Message: ----------- It is a first version and does'nt work yet. Added Paths: ----------- trunk/src/dl-learner/org/dllearner/gui/ trunk/src/dl-learner/org/dllearner/gui/StartGUI_v4.java Added: trunk/src/dl-learner/org/dllearner/gui/StartGUI_v4.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/StartGUI_v4.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/gui/StartGUI_v4.java 2007-11-23 12:09:14 UTC (rev 287) @@ -0,0 +1,214 @@ +package org.dllearner.gui; + +//File : gui/containers/dialogs/filechooser/CountWords.java +//Purpose: Counts words in file. +// Illustrates menus, JFileChooser, Scanner.. +//Author : Fred Swartz - 2006-10-10 - Placed in public domain. + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +//import org.dllearner.algorithms.RandomGuesser; +//import org.dllearner.core.Component; +import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; +//import org.dllearner.core.LearningAlgorithm; +//import org.dllearner.core.LearningProblem; +//import org.dllearner.core.ReasonerComponent; +//import org.dllearner.core.ReasoningService; +import org.dllearner.kb.OWLFile; +//import org.dllearner.learningproblems.PosNegDefinitionLP; +//import org.dllearner.reasoning.DIGReasoner; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////////////CountWords +public class StartGUI_v4 extends JFrame { + + + /** + * + */ + private static final long serialVersionUID = 9151367563590748364L; + +//====================================================== fields + JTextField _fileNameTF = new JTextField(15); + JTextField _wordCountTF = new JTextField(4); + JFileChooser _fileChooser = new JFileChooser(); + JTextArea _textField = new JTextArea(); + ComponentManager cm = ComponentManager.getInstance(); // create singleton instance + + //================================================= constructor + StartGUI_v4() { + //... Create / set component characteristics. + _fileNameTF.setEditable(false); + _wordCountTF.setEditable(false); + + //... Add listeners <-- extra classes + + //... Create content pane, layout components + JPanel content = new JPanel(); + content.setLayout(new FlowLayout()); + content.add(new JLabel("File:")); // name of opend file + content.add(_fileNameTF); + content.add(new JLabel("Word Count:")); // test + content.add(_wordCountTF); // test + content.add(_textField); // test_output + + //... Create menu elements (menubar, menu, menu item) + JMenuBar menubar = new JMenuBar(); + JMenu fileMenu = new JMenu("File"); + JMenuItem openItem = new JMenuItem("Open"); + openItem.addActionListener(new OpenAction()); + JMenuItem saveItem = new JMenuItem("Save"); + saveItem.addActionListener(new SaveAction()); + JMenuItem exitItem = new JMenuItem("Exit"); + exitItem.addActionListener(new ExitAction()); + + + //... Assemble the menu + menubar.add(fileMenu); + fileMenu.add(openItem); + //fileMenu.add(saveItem); + fileMenu.add(exitItem); + + //... _textField (TextArea) into a JScrollPane + JScrollPane scrollPane = new JScrollPane(_textField); + scrollPane.setPreferredSize(new Dimension(320, 240)); + + //... Set window characteristics + this.setJMenuBar(menubar); + this.setContentPane(content); + this.setTitle("DL-Learner"); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.add(scrollPane); + this.pack(); // Layout components. + this.setLocationRelativeTo(null); // Center window. + + // RUN + + + //System.out.println("components"); + //System.out.println(cm.getComponents()); // show components + //System.out.println("knowledgeSources"); + //System.out.println(cm.getKnowledgeSources()); // possible sources + + + +/* + // create DIG reasoning service with standard settings + ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); + // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); + reasoner.init(); + ReasoningService rs = cm.reasoningService(reasoner); + + // create a learning problem and set positive and negative examples + LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); + Set<String> positiveExamples = new TreeSet<String>(); + positiveExamples.add("http://example.com/father#stefan"); + positiveExamples.add("http://example.com/father#markus"); + positiveExamples.add("http://example.com/father#martin"); + Set<String> negativeExamples = new TreeSet<String>(); + negativeExamples.add("http://example.com/father#heinz"); + negativeExamples.add("http://example.com/father#anna"); + negativeExamples.add("http://example.com/father#michelle"); + cm.applyConfigEntry(lp, "positiveExamples", positiveExamples); + cm.applyConfigEntry(lp, "negativeExamples", negativeExamples); + lp.init(); + + // create the learning algorithm + LearningAlgorithm la = cm.learningAlgorithm(RandomGuesser.class, lp, rs); + cm.applyConfigEntry(la, "numberOfTrees", 100); + cm.applyConfigEntry(la, "maxDepth", 5); + la.init(); + + // start the algorithm and print the best concept found + //la.start(); + //System.out.println(la.getBestSolution()); +*/ + + } + + // a test method + //============================================= countWordsInFile + private int countWordsInFile(File f) { + + int numberOfWords = 0; // Count of words. + + try { + Scanner in = new Scanner(f); + + while (in.hasNext()) { + String word = in.next(); // Read a "token". + numberOfWords++; + } + in.close(); // Close Scanner's file. + + } catch (FileNotFoundException fnfex) { + // ... We just got the file from the JFileChooser, + // so it's hard to believe there's problem, but... + JOptionPane.showMessageDialog(StartGUI_v4.this, + fnfex.getMessage()); + } + return numberOfWords; + } + + + ///////////////////////////////////////////////////// OpenAction + class OpenAction implements ActionListener { + public void actionPerformed(ActionEvent ae) { + //... Open a file dialog. + int retval = _fileChooser.showOpenDialog(StartGUI_v4.this); + if (retval == JFileChooser.APPROVE_OPTION) { + //... The user selected a file, get it, use it. + File file = _fileChooser.getSelectedFile(); + + //... Update user interface. + _fileNameTF.setText(file.getName()); + _wordCountTF.setText("" + countWordsInFile(file)); + //show file in _textField + try { + _textField.read(new FileReader(file), ""); + } catch (Exception e) { + e.printStackTrace(); + } + // create knowledge source + KnowledgeSource source = cm.knowledgeSource(OWLFile.class); + //String example = "examples/father.owl"; + cm.applyConfigEntry(source, "url", file.toURI().toString()); + source.init(); + } + } + } + + ///////////////////////////////////////////////////// OpenAction + class SaveAction implements ActionListener { + public void actionPerformed(ActionEvent ae) { + //... Open a file dialog. + int retval = _fileChooser.showOpenDialog(StartGUI_v4.this); + if (retval == JFileChooser.APPROVE_OPTION) { + //... The user selected a file, get it, use it. + File file = _fileChooser.getSelectedFile(); + + //... Update user interface. + _fileNameTF.setText(file.getName()); + _wordCountTF.setText("" + countWordsInFile(file)); + } + } + } + + ///////////////////////////////////////////////////// ExitAction + class ExitAction implements ActionListener { + public void actionPerformed(ActionEvent ae) { + System.exit(0); + } + } + + //========================================================= main + public static void main(String[] args) { + JFrame window = new StartGUI_v4(); + window.setVisible(true); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-11-20 09:06:21
|
Revision: 286 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=286&view=rev Author: sknappe Date: 2007-11-20 01:06:19 -0800 (Tue, 20 Nov 2007) Log Message: ----------- deleted some xajax folders, that are not needed Removed Paths: ------------- trunk/src/dbpedia-navigator/xajax/documentation/ trunk/src/dbpedia-navigator/xajax/examples/ trunk/src/dbpedia-navigator/xajax/tests/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sk...@us...> - 2007-11-20 08:51:36
|
Revision: 285 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=285&view=rev Author: sknappe Date: 2007-11-20 00:51:34 -0800 (Tue, 20 Nov 2007) Log Message: ----------- moved ajax version to root folder Added Paths: ----------- trunk/src/dbpedia-navigator/Settings.php trunk/src/dbpedia-navigator/SparqlConnection.php trunk/src/dbpedia-navigator/ajax-loader.gif trunk/src/dbpedia-navigator/ajax.php trunk/src/dbpedia-navigator/ajaxfunctions.php trunk/src/dbpedia-navigator/clearsession.php trunk/src/dbpedia-navigator/index.php trunk/src/dbpedia-navigator/pear/ trunk/src/dbpedia-navigator/pear/HTTP_Request.php trunk/src/dbpedia-navigator/pear/PEAR.php trunk/src/dbpedia-navigator/pear/Socket.php trunk/src/dbpedia-navigator/pear/URL.php trunk/src/dbpedia-navigator/xajax/ trunk/src/dbpedia-navigator/xajax/LICENSE.txt trunk/src/dbpedia-navigator/xajax/README.txt trunk/src/dbpedia-navigator/xajax/copyright.inc.php trunk/src/dbpedia-navigator/xajax/documentation/ trunk/src/dbpedia-navigator/xajax/examples/ trunk/src/dbpedia-navigator/xajax/release_notes.txt trunk/src/dbpedia-navigator/xajax/tests/ trunk/src/dbpedia-navigator/xajax/xajax_controls/ trunk/src/dbpedia-navigator/xajax/xajax_core/ trunk/src/dbpedia-navigator/xajax/xajax_js/ trunk/src/dbpedia-navigator/xajax/xajax_plugins/ Removed Paths: ------------- trunk/src/dbpedia-navigator/Ajax-Test/ trunk/src/dbpedia-navigator/pear/HTTP_Request.php trunk/src/dbpedia-navigator/pear/PEAR.php trunk/src/dbpedia-navigator/pear/Socket.php trunk/src/dbpedia-navigator/pear/URL.php trunk/src/dbpedia-navigator/xajax/LICENSE.txt trunk/src/dbpedia-navigator/xajax/README.txt trunk/src/dbpedia-navigator/xajax/copyright.inc.php trunk/src/dbpedia-navigator/xajax/documentation/ trunk/src/dbpedia-navigator/xajax/examples/ trunk/src/dbpedia-navigator/xajax/release_notes.txt trunk/src/dbpedia-navigator/xajax/tests/ trunk/src/dbpedia-navigator/xajax/xajax_controls/ trunk/src/dbpedia-navigator/xajax/xajax_core/ trunk/src/dbpedia-navigator/xajax/xajax_js/ trunk/src/dbpedia-navigator/xajax/xajax_plugins/ Added: trunk/src/dbpedia-navigator/Settings.php =================================================================== --- trunk/src/dbpedia-navigator/Settings.php (rev 0) +++ trunk/src/dbpedia-navigator/Settings.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,8 @@ +<?php + +class Settings{ + public $wsdluri="http://localhost:8181/services?wsdl"; + public $dbpediauri="http://localhost:8890/sparql"; + public $sparqlttl=60; +} +?> \ No newline at end of file Added: trunk/src/dbpedia-navigator/SparqlConnection.php =================================================================== --- trunk/src/dbpedia-navigator/SparqlConnection.php (rev 0) +++ trunk/src/dbpedia-navigator/SparqlConnection.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,243 @@ +<?php + +class SparqlConnection +{ + private $DBPediaUrl; + private $DLLearnerUri; + private $client; + private $id; + private $ksID; + + function SparqlConnection($DBPediaUrl,$DLLearnerUri,$id=0,$ksID=0) + { + ini_set('default_socket_timeout',200); + $this->DBPediaUrl=$DBPediaUrl; + $this->DLLearnerUri=$DLLearnerUri; + $this->client=new SoapClient("main.wsdl"); + $this->id=$id; + $this->ksID=$ksID; + } + + function getIDs() + { + $id=$this->client->generateID(); + $ksID=$this->client->addKnowledgeSource($id,"sparql",$this->DBPediaUrl); + return array(0 => $id, 1 => $ksID); + } + + function test() + { + $object=$this->client->test($this->id,$this->ksID); + return $object->item; + } + + function getConceptFromExamples($ttl,$posExamples,$negExamples) + { + $this->client->applyConfigEntryInt($this->id, $this->ksID, "numberOfRecursions", 2); + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "instances", array_merge($posExamples,$negExamples)); + $this->client->applyConfigEntryInt($this->id, $this->ksID, "filterMode", 0); + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "predList", array()); + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "objList", array()); + $this->client->applyConfigEntryStringArray($this->id, $this->ksID, "classList", array()); + $this->client->applyConfigEntryString($this->id, $this->ksID, "format", "KB"); + $this->client->applyConfigEntryBoolean($this->id, $this->ksID, "dumpToFile", true); + + $this->client->setReasoner($this->id, "dig"); + $this->client->setLearningProblem($this->id, "posNegDefinition"); + $this->client->setPositiveExamples($this->id, $posExamples); + $this->client->setNegativeExamples($this->id, $negExamples); + $this->client->setLearningAlgorithm($this->id, "refinement"); + + $start = microtime(true); + + $this->client->init($this->id); + + $threaded=true; + + if($threaded == false) { + + $concept = $this->client->learn($this->id); + + } else { + + $this->client->learnThreaded($this->id); + + $i = 1; + $sleeptime = 1; + + do { + // sleep a while + sleep($sleeptime); + + // see what we have learned so far + $concept=$this->client->getCurrentlyBestConcept($this->id); + $running=$this->client->isAlgorithmRunning($this->id); + + $seconds = $i * $sleeptime; + + $i++; + } while($seconds<$ttl&&$running); + + $this->client->stop($this->id); + } + return $concept; + } + + function getTriples($ttl,$individual) + { + $options=array("triples",$individual); + $this->client->startThread($this->id,$this->ksID,$options); + $i = 1; + $sleeptime = 1; + + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($this->id,$this->ksID,"triples")) + { + $object=$this->client->getFromSparql($this->id,$this->ksID,"triples"); + $array=$object->item; + if (count($array)==1) return $array; + $ret=array(); + foreach ($array as $element) + { + $items=preg_split("[<]",$element,-1, PREG_SPLIT_NO_EMPTY); + $ret[$items[0]]=$items[1]; + } + return $ret; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); + + $this->client->stopSparqlThread($this->id,$this->ksID,"triples"); + return array(); + } + + function getSubjects($ttl,$label) + { + $options=array("subjects",$label,15); + $this->client->startThread($this->id,$this->ksID,$options); + $i = 1; + $sleeptime = 1; + + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($this->id,$this->ksID,"subjects")) + { + $object=$this->client->getFromSparql($this->id,$this->ksID,"subjects"); + return $object->item; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); + + $this->client->stopSparqlThread($this->id,$this->ksID,"subjects"); + return array(); + } + + function getSubjectsFromConcept($ttl,$concept) + { + $options=array("conceptSubjects",$concept); + $this->client->startThread($this->id,$this->ksID,$options); + $i = 1; + $sleeptime = 1; + do { + // sleep a while + sleep($sleeptime); + + // see if algorithm is running + if (!$this->client->isThreadRunning($this->id,$this->ksID,"conceptSubjects")) + { + $object=$this->client->getFromSparql($this->id,$this->ksID,"conceptSubjects"); + return $object->item; + } + + $seconds = $i * $sleeptime; + $i++; + } while($seconds<$ttl); + + $this->client->stopSparqlThread($this->id,$this->ksID,"conceptSubjects"); + return array(); + } + + public function loadWSDLfiles($wsdluri){ + $main=SparqlConnection::getwsdl($wsdluri); + $other=SparqlConnection::getOtherWSDL($main); + $newMain=SparqlConnection::changeWSDL($main); + SparqlConnection::writeToFile("main.wsdl",$newMain); + $x=0; + foreach ($other as $o){ + SparqlConnection::writeToFile("def".($x++).".xsd",SparqlConnection::getwsdl($o)); + } + + } + + private function changeWSDL($wsdl){ + $before="<xsd:import schemaLocation=\""; + $after="\" namespace=\""; + $newWSDL=""; + $desca="def"; + $descb=".xsd"; + $x=0; + while($posstart= strpos ( $wsdl, $before )){ + + $posstart+=strlen($before); + $newWSDL.=substr($wsdl,0,$posstart); + $wsdl=substr($wsdl,$posstart); + $newWSDL.=$desca.($x++).$descb; + $posend= strpos ( $wsdl, $after ); + $wsdl=substr($wsdl,$posend); + + } + return $newWSDL.$wsdl; + + } + + private function getOtherWSDL($wsdl){ + $before="<xsd:import schemaLocation=\""; + $after="\" namespace=\""; + $ret=array(); + while($posstart= strpos ( $wsdl, $before )){ + $posstart+=strlen($before); + $wsdl=substr($wsdl,$posstart); + $posend= strpos ( $wsdl, $after ); + $tmp=substr($wsdl,0,$posend); + $ret[]=$tmp; + $wsdl=substr($wsdl,$posend+strlen($after)); + } + return $ret; + } + + + + + private function getwsdl($wsdluri){ + // this is copied from the Pear example + // please don't ask me how it works + $req = &new HTTP_Request($wsdluri); + $message=""; + $req->setMethod(HTTP_REQUEST_METHOD_GET); + $req->sendRequest(); + $ret=$req->getResponseBody(); + return $ret; + } + + + + private function writeToFile($filename,$content){ + + $fp=fopen($filename,"w"); + fwrite($fp,$content); + fclose($fp); + + } +} +?> \ No newline at end of file Copied: trunk/src/dbpedia-navigator/ajax-loader.gif (from rev 283, trunk/src/dbpedia-navigator/Ajax-Test/ajax-loader.gif) =================================================================== (Binary files differ) Copied: trunk/src/dbpedia-navigator/ajax.php (from rev 284, trunk/src/dbpedia-navigator/Ajax-Test/ajax.php) =================================================================== --- trunk/src/dbpedia-navigator/ajax.php (rev 0) +++ trunk/src/dbpedia-navigator/ajax.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,24 @@ +<?php +require_once ("xajax/xajax_core/xajax.inc.php"); +$sid = session_id(); + +$xajax = new xajax("ajaxfunctions.php?sid=$sid"); +$xajax->register(XAJAX_FUNCTION, 'getsubjects', array( + 'onResponseDelay' => 'showLoadingSubjects', + 'beforeResponseProcessing' => 'hideLoadingSubjects' + )); +$xajax->registerFunction('getarticle'); +$xajax->registerFunction('addPositive'); +$xajax->registerFunction('addNegative'); +$xajax->registerFunction('clearPositives'); +$xajax->registerFunction('clearNegatives'); +$xajax->register(XAJAX_FUNCTION, 'learnConcept', array( + 'onResponseDelay' => 'showLoadingConcept', + 'beforeResponseProcessing' => 'hideLoadingConcept' + )); +$xajax->register(XAJAX_FUNCTION, 'getSubjectsFromConcept', array( + 'onResponseDelay' => 'showLoadingConceptSubjects', + 'beforeResponseProcessing' => 'hideLoadingConceptSubjects' + )); +$xajax->registerFunction('searchAndShowArticle'); +?> \ No newline at end of file Copied: trunk/src/dbpedia-navigator/ajaxfunctions.php (from rev 284, trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php) =================================================================== --- trunk/src/dbpedia-navigator/ajaxfunctions.php (rev 0) +++ trunk/src/dbpedia-navigator/ajaxfunctions.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,222 @@ +<?php +ini_set('max_execution_time',200); +$sid = $_GET['sid']; +session_id($sid); +session_start(); + +require("ajax.php"); +$xajax->processRequest(); + +function getsubjects($label) +{ + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + + $content=""; + $subjects=$sc->getSubjects($settings->sparqlttl,$label); + if (count($subjects)==1) + { + if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); + else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; + } + else if (count($subjects)==0) $content.="No search result found in time."; + else{ + foreach ($subjects as $subject) + { + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + } + } + + $objResponse = new xajaxResponse(); + $objResponse->assign("searchcontent", "innerHTML", $content); + return $objResponse; +} + +function getarticle($subject,$fromCache) +{ + if (isset($_SESSION['articles'])) + foreach ($_SESSION['articles'] as $key => $value) + { + if ($value['subject']==$subject){ + $fromCache=$key; + break; + } + } + if ($fromCache==-1) { + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + $triples=$sc->getTriples($settings->sparqlttl,$subject); + $content=""; + if (count($triples)==1) + { + $content.=substr($triples,7); + } + else if (count($triples)==0) $content.="Article not found."; + else { + $content=""; + $content.="<img src=\"".$triples['http://xmlns.com/foaf/0.1/depiction']."\" alt=\"Picture of ".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."\" width=\"50\"/ style=\"float:left\">"; + $content.="<div>".urldecode($triples['http://dbpedia.org/property/abstract'])."</div>"; + + $contentbuttons="<input type=\"button\" value=\"Positive\" class=\"button\" onclick=\"xajax_addPositive('".$subject."');return false;\" /> <input type=\"button\" value=\"Negative\" class=\"button\" onclick=\"xajax_addNegative('".$subject."');return false;\" />"; + } + + //store article in session, to navigate between last 5 articles quickly + $contentArray=array('content' => $content,'contentbuttons' => $contentbuttons, 'subject' => $subject); + if (!isset($_SESSION['nextArticle'])){ + $_SESSION['nextArticle']=0; + $_SESSION['articles']=array(); + } + if ($_SESSION['nextArticle']==5) $_SESSION['nextArticle']=0; + $_SESSION['articles'][$_SESSION['nextArticle']]=$contentArray; + $_SESSION['currentArticle']=$_SESSION['nextArticle']; + $_SESSION['nextArticle']++; + } + else { + $content=$_SESSION['articles'][$fromCache]['content']; + $contentbuttons=$_SESSION['articles'][$fromCache]['contentbuttons']; + $subject=$_SESSION['articles'][$fromCache]['subject']; + } + + $lastArticles=""; + foreach ($_SESSION['articles'] as $key => $value) + { + $lastArticles.="<a href=\"\" onclick=\"xajax_getarticle('',".$key.");return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($value['subject'], "/"), 1)))."</a><br/>"; + } + + //build the response + $objResponse = new xajaxResponse(); + $objResponse->assign("articlecontent", "innerHTML", $content); + $objResponse->assign("contentbuttons", "innerHTML", $contentbuttons); + $objResponse->assign("ArticleTitle","innerHTML",str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))); + $objResponse->assign("lastarticles","innerHTML",$lastArticles); + return $objResponse; +} + +function addPositive($subject) +{ + if (!isset($_SESSION['positive'])){ + $array=array($subject); + $_SESSION['positive']=$array; + } + else{ + $array=$_SESSION['positive']; + $array[]=$subject; + $_SESSION['positive']=$array; + } + + $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; + + $objResponse = new xajaxResponse(); + $objResponse->append("Positives", "innerHTML", $content); + return $objResponse; +} + +function addNegative($subject) +{ + if (!isset($_SESSION['negative'])){ + $array=array($subject); + $_SESSION['negative']=$array; + } + else{ + $array=$_SESSION['negative']; + $array[]=$subject; + $_SESSION['negative']=$array; + } + + $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; + + $objResponse = new xajaxResponse(); + $objResponse->append("Negatives", "innerHTML", $content); + return $objResponse; +} + +function clearPositives() +{ + unset($_SESSION['positive']); + + $objResponse = new xajaxResponse(); + $objResponse->assign("Positives", "innerHTML", ""); + return $objResponse; +} + +function clearNegatives() +{ + unset($_SESSION['negative']); + + $objResponse = new xajaxResponse(); + $objResponse->assign("Negatives", "innerHTML", ""); + return $objResponse; +} + +function learnConcept() +{ + if (isset($_SESSION['positive'])&&isset($_SESSION['negative'])) + { + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + + $concept=$sc->getConceptFromExamples($settings->sparqlttl,$_SESSION['positive'],$_SESSION['negative']); + $_SESSION['lastLearnedConcept']=$concept; + if (strlen(substr (strrchr ($concept, "/"), 1))>0) $concept=urldecode(substr (strrchr ($concept, "/"), 1)); + } + else $concept="You must choose at least one<br/> positive and one negative example."; + + $objResponse = new xajaxResponse(); + $objResponse->assign("conceptcontent", "innerHTML", $concept); + return $objResponse; +} + +function getSubjectsFromConcept() +{ + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + + $content=""; + if (isset($_SESSION['lastLearnedConcept'])) + { + $subjects=$sc->getSubjectsFromConcept($settings->sparqlttl,$_SESSION['lastLearnedConcept']); + if (count($subjects)==1) + { + if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); + else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."');return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; + } + else if (count($subjects)==0) $content.="No examples for concept found in time."; + else { + foreach ($subjects as $subject) + { + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; + } + } + } + else $content.="No concept to get Subjects from."; + + $objResponse = new xajaxResponse(); + $objResponse->assign("conceptsubjectcontent", "innerHTML", $content); + return $objResponse; +} + +function searchAndShowArticle($keyword) +{ + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + + $content=""; + + $objResponse = new xajaxResponse(); + $objResponse->call('xajax_getarticle', "http://dbpedia.org/resource/".str_replace(" ","_",$keyword),-1); + $objResponse->call('xajax_getsubjects',$keyword); + return $objResponse; +} + +?> \ No newline at end of file Copied: trunk/src/dbpedia-navigator/clearsession.php (from rev 283, trunk/src/dbpedia-navigator/Ajax-Test/clearsession.php) =================================================================== --- trunk/src/dbpedia-navigator/clearsession.php (rev 0) +++ trunk/src/dbpedia-navigator/clearsession.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,12 @@ +<?php +session_start(); + +session_unset(); +ob_start(); +require_once 'pear/HTTP_Request.php'; +require_once 'SparqlConnection.php'; +require_once 'Settings.php'; +$settings=new Settings(); +SparqlConnection::loadWSDLfiles($settings->wsdluri); +header("Location: http://" . $_SERVER["HTTP_HOST"] . "/Ajax-Test/index.php"); +?> \ No newline at end of file Added: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php (rev 0) +++ trunk/src/dbpedia-navigator/index.php 2007-11-20 08:51:34 UTC (rev 285) @@ -0,0 +1,140 @@ +<?php +ini_set('error_reporting',E_ALL); +ini_set('max_execution_time',200); +ini_set("soap.wsdl_cache_enabled","1"); +session_start(); +require_once('Settings.php'); +require_once('SparqlConnection.php'); +$settings=new Settings(); +$sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); +$ids=$sc->getIDs(); +$_SESSION['id']=$ids[0]; +$_SESSION['ksID']=$ids[1]; + +echo "<a href='clearsession.php'>start from scratch</a>"; + +require("ajax.php"); + +echo '<?xml version="1.0" encoding="UTF-8"?>'; +?> +<html> + <head> + <title>DL Learner</title> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> + <link rel="stylesheet" href="default.css"/> + <?php $xajax->printJavascript('xajax/'); ?> + <script type="text/javascript"> + showLoadingSubjects = function() { + xajax.$('loadingSubject').style.display='block'; + xajax.$('searchcontent').style.display = 'none'; + }; + hideLoadingSubjects = function() { + xajax.$('loadingSubject').style.display = 'none'; + xajax.$('searchcontent').style.display='block'; + }; + showLoadingArticle = function() { + xajax.$('loadingArticle').style.display='block'; + xajax.$('articlecontent').style.display = 'none'; + }; + hideLoadingArticle = function() { + xajax.$('loadingArticle').style.display = 'none'; + xajax.$('articlecontent').style.display = 'block'; + }; + showLoadingConcept = function() { + xajax.$('loadingConcept').style.display='block'; + xajax.$('conceptcontent').style.display = 'none'; + }; + hideLoadingConcept = function() { + xajax.$('loadingConcept').style.display = 'none'; + xajax.$('conceptcontent').style.display = 'block'; + }; + showLoadingConceptSubjects = function() { + xajax.$('loadingConceptSubjects').style.display='block'; + xajax.$('conceptsubjectcontent').style.display = 'none'; + }; + hideLoadingConceptSubjects = function() { + xajax.$('loadingConceptSubjects').style.display = 'none'; + xajax.$('conceptsubjectcontent').style.display = 'block'; + } + </script> + </head> + <body> +<h3>DBPedia-Navigator-Test</h3> +<div id="layer" style="display:none"><div id="layerContent" style="display:none"></div></div> +<div id="wrapper"> +<div id="leftSidebar"> + +<div class="box"> + <div class="boxtitle">Search</div> + <div class="boxcontent" id="search"> + Search:<br/> + <input type="textfield" name="label" id="label"><br/> + <input type="button" value="Article" class="button" onclick="xajax_searchAndShowArticle(document.getElementById('label').value);return false;" /> <input type="button" value="Fulltext" class="button" onclick=""/> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<div class="box"> + <div class="boxtitle">Searchresults</div> + <div class="boxcontent"> + <div id="searchcontent" style="display:block"></div> + <div id="loadingSubject" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<div class="box" id="concept"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Learned Concept</td><td class="right"><input type="button" value="Learn" class="button" onclick="xajax_learnConcept();return false;" /></td></tr></table></div> + <div class="boxcontent"> + <div id="conceptcontent" style="display:none"></div> + <div id="loadingConcept" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<div class="box" id="conceptSubjects"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Subjects From Concept</td><td class="right"><input type="button" value="Show" class="button" onclick="xajax_getSubjectsFromConcept();return false;" /></td></tr></table></div> + <div class="boxcontent"> + <div id="conceptsubjectcontent" style="display:none"></div> + <div id="loadingConceptSubjects" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> +</div><!-- END leftSidebar --> + +<div id="content"> +<div class="box"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left" id="ArticleTitle">Article</td><td class="right"><span id="contentbuttons"></span></td></tr></table></div> + <div class="boxcontent" id="article"> + <div id="articlecontent" style="display:block"></div> + <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> +</div><!-- content --> +<div id="rightSidebar"> + +<div class="box"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Positives</td><td class="right"><input type="button" value="Clear" class="button" onclick="xajax_clearPositives();return false;" /></td></tr></table></div> + <div class="boxcontent" id="Positives"> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<div class="box"> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Negatives</td><td class="right"><input type="button" value="Clear" class="button" onclick="xajax_clearNegatives();return false;" /></td></tr></table></div> + <div class="boxcontent" id="Negatives"> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<div class="box"> + <div class="boxtitle">Last Articles</div> + <div class="boxcontent" id="lastarticles"> + </div> <!-- boxcontent --> +</div> <!-- box --> + +<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> +</div><!-- rightSidebar --> +<div id="clear"></div> +</div> + </body> +</html> + \ No newline at end of file Copied: trunk/src/dbpedia-navigator/pear (from rev 283, trunk/src/dbpedia-navigator/Ajax-Test/pear) Deleted: trunk/src/dbpedia-navigator/pear/HTTP_Request.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/pear/HTTP_Request.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/pear/HTTP_Request.php 2007-11-20 08:51:34 UTC (rev 285) @@ -1,2760 +0,0 @@ -<?php - -// +-----------------------------------------------------------------------+ -// | Copyright (c) 2002-2003, Richard Heyes | -// | All rights reserved. | -// | | -// | Redistribution and use in source and binary forms, with or without | -// | modification, are permitted provided that the following conditions | -// | are met: | -// | | -// | o Redistributions of source code must retain the above copyright | -// | notice, this list of conditions and the following disclaimer. | -// | o Redistributions in binary form must reproduce the above copyright | -// | notice, this list of conditions and the following disclaimer in the | -// | documentation and/or other materials provided with the distribution.| -// | o The names of the authors may not be used to endorse or promote | -// | products derived from this software without specific prior written | -// | permission. | -// | | -// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | -// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | -// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | -// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | - -// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - -// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | - -// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | - -// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | - -// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | - -// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | - -// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | - -// | | - -// +-----------------------------------------------------------------------+ - -// | Author: Richard Heyes <ri...@ph...> | - -// +-----------------------------------------------------------------------+ - -/* -// $Id: Request.php,v 1.1 2006/12/12 16:42:26 punkrock Exp $ -// -// HTTP_Request Class -// -// Simple example, (Fetches yahoo.com and displays it): -// -// $a = &new HTTP_Request('http://localhost:8081'); -// $a->sendRequest(); -// echo $a->getResponseBody(); -*/ - - - -require_once 'PEAR.php'; - -require_once 'Socket.php'; - -require_once 'URL.php'; - - - -define('HTTP_REQUEST_METHOD_GET', 'GET', true); - -define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true); - -define('HTTP_REQUEST_METHOD_POST', 'POST', true); - -define('HTTP_REQUEST_METHOD_PUT', 'PUT', true); - -define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true); - -define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true); - -define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true); - - - -define('HTTP_REQUEST_HTTP_VER_1_0', '1.0', true); - -define('HTTP_REQUEST_HTTP_VER_1_1', '1.1', true); - - - -class HTTP_Request { - - - - /** - - * Instance of Net_URL - - * @var object Net_URL - - */ - - var $_url; - - - - /** - - * Type of request - - * @var string - - */ - - var $_method; - - - - /** - - * HTTP Version - - * @var string - - */ - - var $_http; - - - - /** - - * Request headers - - * @var array - - */ - - var $_requestHeaders; - - - - /** - - * Basic Auth Username - - * @var string - - */ - - var $_user; - - - - /** - - * Basic Auth Password - - * @var string - - */ - - var $_pass; - - - - /** - - * Socket object - - * @var object Net_Socket - - */ - - var $_sock; - - - - /** - - * Proxy server - - * @var string - - */ - - var $_proxy_host; - - - - /** - - * Proxy port - - * @var integer - - */ - - var $_proxy_port; - - - - /** - - * Proxy username - - * @var string - - */ - - var $_proxy_user; - - - - /** - - * Proxy password - - * @var string - - */ - - var $_proxy_pass; - - - - /** - - * Post data - - * @var array - - */ - - var $_postData; - - - - /** - - * Request body - - * @var string - - */ - - var $_body; - - - - /** - - * A list of methods that MUST NOT have a request body, per RFC 2616 - - * @var array - - */ - - var $_bodyDisallowed = array('TRACE'); - - - - /** - - * Files to post - - * @var array - - */ - - var $_postFiles = array(); - - - - /** - - * Connection timeout. - - * @var float - - */ - - var $_timeout; - - - - /** - - * HTTP_Response object - - * @var object HTTP_Response - - */ - - var $_response; - - - - /** - - * Whether to allow redirects - - * @var boolean - - */ - - var $_allowRedirects; - - - - /** - - * Maximum redirects allowed - - * @var integer - - */ - - var $_maxRedirects; - - - - /** - - * Current number of redirects - - * @var integer - - */ - - var $_redirects; - - - - /** - - * Whether to append brackets [] to array variables - - * @var bool - - */ - - var $_useBrackets = true; - - - - /** - - * Attached listeners - - * @var array - - */ - - var $_listeners = array(); - - - - /** - - * Whether to save response body in response object property - - * @var bool - - */ - - var $_saveBody = true; - - - - /** - - * Timeout for reading from socket (array(seconds, microseconds)) - - * @var array - - */ - - var $_readTimeout = null; - - - - /** - - * Options to pass to Net_Socket::connect. See stream_context_create - - * @var array - - */ - - var $_socketOptions = null; - - - - /** - - * Constructor - - * - - * Sets up the object - - * @param string The url to fetch/access - - * @param array Associative array of parameters which can have the following keys: - - * <ul> - - * <li>method - Method to use, GET, POST etc (string)</li> - - * <li>http - HTTP Version to use, 1.0 or 1.1 (string)</li> - - * <li>user - Basic Auth username (string)</li> - - * <li>pass - Basic Auth password (string)</li> - - * <li>proxy_host - Proxy server host (string)</li> - - * <li>proxy_port - Proxy server port (integer)</li> - - * <li>proxy_user - Proxy auth username (string)</li> - - * <li>proxy_pass - Proxy auth password (string)</li> - - * <li>timeout - Connection timeout in seconds (float)</li> - - * <li>allowRedirects - Whether to follow redirects or not (bool)</li> - - * <li>maxRedirects - Max number of redirects to follow (integer)</li> - - * <li>useBrackets - Whether to append [] to array variable names (bool)</li> - - * <li>saveBody - Whether to save response body in response object property (bool)</li> - - * <li>readTimeout - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li> - - * <li>socketOptions - Options to pass to Net_Socket object (array)</li> - - * </ul> - - * @access public - - */ - - function HTTP_Request($url = '', $params = array()) - - { - - $this->_method = HTTP_REQUEST_METHOD_GET; - - $this->_http = HTTP_REQUEST_HTTP_VER_1_1; - - $this->_requestHeaders = array(); - - $this->_postData = array(); - - $this->_body = null; - - - - $this->_user = null; - - $this->_pass = null; - - - - $this->_proxy_host = null; - - $this->_proxy_port = null; - - $this->_proxy_user = null; - - $this->_proxy_pass = null; - - - - $this->_allowRedirects = false; - - $this->_maxRedirects = 3; - - $this->_redirects = 0; - - - - $this->_timeout = null; - - $this->_response = null; - - - - foreach ($params as $key => $value) { - - $this->{'_' . $key} = $value; - - } - - - - if (!empty($url)) { - - $this->setURL($url); - - } - - - - // Default useragent - - $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )'); - - - - // We don't do keep-alives by default - - $this->addHeader('Connection', 'close'); - - - - // Basic authentication - - if (!empty($this->_user)) { - - $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass)); - - } - - - - // Proxy authentication (see bug #5913) - - if (!empty($this->_proxy_user)) { - - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass)); - - } - - - - // Use gzip encoding if possible - - // Avoid gzip encoding if using multibyte functions (see #1781) - - if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib') && - - 0 == (2 & ini_get('mbstring.func_overload'))) { - - - - $this->addHeader('Accept-Encoding', 'gzip'); - - } - - } - - - - /** - - * Generates a Host header for HTTP/1.1 requests - - * - - * @access private - - * @return string - - */ - - function _generateHostHeader() - - { - - if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) { - - $host = $this->_url->host . ':' . $this->_url->port; - - - - } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) { - - $host = $this->_url->host . ':' . $this->_url->port; - - - - } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { - - $host = $this->_url->host . ':' . $this->_url->port; - - - - } else { - - $host = $this->_url->host; - - } - - - - return $host; - - } - - - - /** - - * Resets the object to its initial state (DEPRECATED). - - * Takes the same parameters as the constructor. - - * - - * @param string $url The url to be requested - - * @param array $params Associative array of parameters - - * (see constructor for details) - - * @access public - - * @deprecated deprecated since 1.2, call the constructor if this is necessary - - */ - - function reset($url, $params = array()) - - { - - $this->HTTP_Request($url, $params); - - } - - - - /** - - * Sets the URL to be requested - - * - - * @param string The url to be requested - - * @access public - - */ - - function setURL($url) - - { - - $this->_url = &new Net_URL($url, $this->_useBrackets); - - - - if (!empty($this->_url->user) || !empty($this->_url->pass)) { - - $this->setBasicAuth($this->_url->user, $this->_url->pass); - - } - - - - if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) { - - $this->addHeader('Host', $this->_generateHostHeader()); - - } - - - - // set '/' instead of empty path rather than check later (see bug #8662) - - if (empty($this->_url->path)) { - - $this->_url->path = '/'; - - } - - } - - - - /** - - * Returns the current request URL - - * - - * @return string Current request URL - - * @access public - - */ - - function getUrl($url) - - { - - return empty($this->_url)? '': $this->_url->getUrl(); - - } - - - - /** - - * Sets a proxy to be used - - * - - * @param string Proxy host - - * @param int Proxy port - - * @param string Proxy username - - * @param string Proxy password - - * @access public - - */ - - function setProxy($host, $port = 8080, $user = null, $pass = null) - - { - - $this->_proxy_host = $host; - - $this->_proxy_port = $port; - - $this->_proxy_user = $user; - - $this->_proxy_pass = $pass; - - - - if (!empty($user)) { - - $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); - - } - - } - - - - /** - - * Sets basic authentication parameters - - * - - * @param string Username - - * @param string Password - - */ - - function setBasicAuth($user, $pass) - - { - - $this->_user = $user; - - $this->_pass = $pass; - - - - $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass)); - - } - - - - /** - - * Sets the method to be used, GET, POST etc. - - * - - * @param string Method to use. Use the defined constants for this - - * @access public - - */ - - function setMethod($method) - - { - - $this->_method = $method; - - } - - - - /** - - * Sets the HTTP version to use, 1.0 or 1.1 - - * - - * @param string Version to use. Use the defined constants for this - - * @access public - - */ - - function setHttpVer($http) - - { - - $this->_http = $http; - - } - - - - /** - - * Adds a request header - - * - - * @param string Header name - - * @param string Header value - - * @access public - - */ - - function addHeader($name, $value) - - { - - $this->_requestHeaders[strtolower($name)] = $value; - - } - - - - /** - - * Removes a request header - - * - - * @param string Header name to remove - - * @access public - - */ - - function removeHeader($name) - - { - - if (isset($this->_requestHeaders[strtolower($name)])) { - - unset($this->_requestHeaders[strtolower($name)]); - - } - - } - - - - /** - - * Adds a querystring parameter - - * - - * @param string Querystring parameter name - - * @param string Querystring parameter value - - * @param bool Whether the value is already urlencoded or not, default = not - - * @access public - - */ - - function addQueryString($name, $value, $preencoded = false) - - { - - $this->_url->addQueryString($name, $value, $preencoded); - - } - - - - /** - - * Sets the querystring to literally what you supply - - * - - * @param string The querystring data. Should be of the format foo=bar&x=y etc - - * @param bool Whether data is already urlencoded or not, default = already encoded - - * @access public - - */ - - function addRawQueryString($querystring, $preencoded = true) - - { - - $this->_url->addRawQueryString($querystring, $preencoded); - - } - - - - /** - - * Adds postdata items - - * - - * @param string Post data name - - * @param string Post data value - - * @param bool Whether data is already urlencoded or not, default = not - - * @access public - - */ - - function addPostData($name, $value, $preencoded = false) - - { - - if ($preencoded) { - - $this->_postData[$name] = $value; - - } else { - - $this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value); - - } - - } - - - - /** - - * Recursively applies the callback function to the value - - * - - * @param mixed Callback function - - * @param mixed Value to process - - * @access private - - * @return mixed Processed value - - */ - - function _arrayMapRecursive($callback, $value) - - { - - if (!is_array($value)) { - - return call_user_func($callback, $value); - - } else { - - $map = array(); - - foreach ($value as $k => $v) { - - $map[$k] = $this->_arrayMapRecursive($callback, $v); - - } - - return $map; - - } - - } - - - - /** - - * Adds a file to upload - - * - - * This also changes content-type to 'multipart/form-data' for proper upload - - * - - * @access public - - * @param string name of file-upload field - - * @param mixed file name(s) - - * @param mixed content-type(s) of file(s) being uploaded - - * @return bool true on success - - * @throws PEAR_Error - - */ - - function addFile($inputName, $fileName, $contentType = 'application/octet-stream') - - { - - if (!is_array($fileName) && !is_readable($fileName)) { - - return PEAR::raiseError("File '{$fileName}' is not readable"); - - } elseif (is_array($fileName)) { - - foreach ($fileName as $name) { - - if (!is_readable($name)) { - - return PEAR::raiseError("File '{$name}' is not readable"); - - } - - } - - } - - $this->addHeader('Content-Type', 'multipart/form-data'); - - $this->_postFiles[$inputName] = array( - - 'name' => $fileName, - - 'type' => $contentType - - ); - - return true; - - } - - - - /** - - * Adds raw postdata (DEPRECATED) - - * - - * @param string The data - - * @param bool Whether data is preencoded or not, default = already encoded - - * @access public - - * @deprecated deprecated since 1.3.0, method setBody() should be used instead - - */ - - function addRawPostData($postdata, $preencoded = true) - - { - - $this->_body = $preencoded ? $postdata : urlencode($postdata); - - } - - - - /** - - * Sets the request body (for POST, PUT and similar requests) - - * - - * @param string Request body - - * @access public - - */ - - function setBody($body) - - { - - $this->_body = $body; - - } - - - - /** - - * Clears any postdata that has been added (DEPRECATED). - - * - - * Useful for multiple request scenarios. - - * - - * @access public - - * @deprecated deprecated since 1.2 - - */ - - function clearPostData() - - { - - $this->_postData = null; - - } - - - - /** - - * Appends a cookie to "Cookie:" header - - * - - * @param string $name cookie name - - * @param string $value cookie value - - * @access public - - */ - - function addCookie($name, $value) - - { - - $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : ''; - - $this->addHeader('Cookie', $cookies . $name . '=' . $value); - - } - - - - /** - - * Clears any cookies that have been added (DEPRECATED). - - * - - * Useful for multiple request scenarios - - * - - * @access public - - * @deprecated deprecated since 1.2 - - */ - - function clearCookies() - - { - - $this->removeHeader('Cookie'); - - } - - - - /** - - * Sends the request - - * - - * @access public - - * @param bool Whether to store response body in Response object property, - - * set this to false if downloading a LARGE file and using a Listener - - * @return mixed PEAR error on error, true otherwise - - */ - - function sendRequest($saveBody = true){ - - if (!is_a($this->_url, 'Net_URL')) { - - return PEAR::raiseError('No URL given.'); - - } - - - - $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; - - $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; - - - - // 4.3.0 supports SSL connections using OpenSSL. The function test determines - - // we running on at least 4.3.0 - - if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { - - if (isset($this->_proxy_host)) { - - return PEAR::raiseError('HTTPS proxies are not supported.'); - - } - - $host = 'ssl://' . $host; - - } - - - - // magic quotes may fuck up file uploads and chunked response processing - - $magicQuotes = ini_get('magic_quotes_runtime'); - - ini_set('magic_quotes_runtime', false); - - - - // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive - - // connection token to a proxy server... - - if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && - - 'Keep-Alive' == $this->_requestHeaders['connection']) - - { - - $this->removeHeader('connection'); - - } - - - - $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) || - - (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']); - - $sockets = &PEAR::getStaticProperty('HTTP_Request', 'sockets'); - - $sockKey = $host . ':' . $port; - - unset($this->_sock); - - - - // There is a connected socket in the "static" property? - - if ($keepAlive && !empty($sockets[$sockKey]) && - - !empty($sockets[$sockKey]->fp)) - - { - - $this->_sock =& $sockets[$sockKey]; - - $err = null; - - } else { - - $this->_notify('connect'); - - $this->_sock =& new Net_Socket(); - - $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions); - - } - - PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest()); - - - - if (!PEAR::isError($err)) { - - if (!empty($this->_readTimeout)) { - - $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]); - - } - - - - $this->_notify('sentRequest'); - - - - // Read the response - - $this->_response = &new HTTP_Response($this->_sock, $this->_listeners); - - $err = $this->_response->process( - - $this->_saveBody && $saveBody, - - HTTP_REQUEST_METHOD_HEAD != $this->_method - - ); - - - - if ($keepAlive) { - - $keepAlive = (isset($this->_response->_headers['content-length']) - - || (isset($this->_response->_headers['transfer-encoding']) - - && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked')); - - if ($keepAlive) { - - if (isset($this->_response->_headers['connection'])) { - - $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive'; - - } else { - - $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol; - - } - - } - - } - - } - - - - ini_set('magic_quotes_runtime', $magicQuotes); - - - - if (PEAR::isError($err)) { - - return $err; - - } - - - - if (!$keepAlive) { - - $this->disconnect(); - - // Store the connected socket in "static" property - - } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) { - - $sockets[$sockKey] =& $this->_sock; - - } - - - - // Check for redirection - - if ( $this->_allowRedirects - - AND $this->_redirects <= $this->_maxRedirects - - AND $this->getResponseCode() > 300 - - AND $this->getResponseCode() < 399 - - AND !empty($this->_response->_headers['location'])) { - - - - - - $redirect = $this->_response->_headers['location']; - - - - // Absolute URL - - if (preg_match('/^https?:\/\//i', $redirect)) { - - $this->_url = &new Net_URL($redirect); - - $this->addHeader('Host', $this->_generateHostHeader()); - - // Absolute path - - } elseif ($redirect{0} == '/') { - - $this->_url->path = $redirect; - - - - // Relative path - - } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { - - if (substr($this->_url->path, -1) == '/') { - - $redirect = $this->_url->path . $redirect; - - } else { - - $redirect = dirname($this->_url->path) . '/' . $redirect; - - } - - $redirect = Net_URL::resolvePath($redirect); - - $this->_url->path = $redirect; - - - - // Filename, no path - - } else { - - if (substr($this->_url->path, -1) == '/') { - - $redirect = $this->_url->path . $redirect; - - } else { - - $redirect = dirname($this->_url->path) . '/' . $redirect; - - } - - $this->_url->path = $redirect; - - } - - - - $this->_redirects++; - - return $this->sendRequest($saveBody); - - - - // Too many redirects - - } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { - - return PEAR::raiseError('Too many redirects'); - - } - - - - return true; - - } - - - - /** - - * Disconnect the socket, if connected. Only useful if using Keep-Alive. - - * - - * @access public - - */ - - function disconnect() - - { - - if (!empty($this->_sock) && !empty($this->_sock->fp)) { - - $this->_notify('disconnect'); - - $this->_sock->disconnect(); - - } - - } - - - - /** - - * Returns the response code - - * - - * @access public - - * @return mixed Response code, false if not set - - */ - - function getResponseCode() - - { - - return isset($this->_response->_code) ? $this->_response->_code : false; - - } - - - - /** - - * Returns either the named header or all if no name given - - * - - * @access public - - * @param string The header name to return, do not set to get all headers - - * @return mixed either the value of $headername (false if header is not present) - - * or an array of all headers - - */ - - function getResponseHeader($headername = null) - - { - - if (!isset($headername)) { - - return isset($this->_response->_headers)? $this->_response->_headers: array(); - - } else { - - $headername = strtolower($headername); - - return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false; - - } - - } - - - - /** - - * Returns the body of the response - - * - - * @access public - - * @return mixed response body, false if not set - - */ - - function getResponseBody() - - { - - return isset($this->_response->_body) ? $this->_response->_body : false; - - } - - - - /** - - * Returns cookies set in response - - * - - * @access public - - * @return mixed array of response cookies, false if none are present - - */ - - function getResponseCookies() - - { - - return isset($this->_response->_cookies) ? $this->_response->_cookies : false; - - } - - - - /** - - * Builds the request string - - * - - * @access private - - * @return string The request string - - */ - - function _buildRequest() - - { - - $separator = ini_get('arg_separator.output'); - - ini_set('arg_separator.output', '&'); - - $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : ''; - - ini_set('arg_separator.output', $separator); - - - - $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : ''; - - $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : ''; - - $path = $this->_url->path . $querystring; - - $url = $host . $port . $path; - - - - $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; - - - - if (in_array($this->_method, $this->_bodyDisallowed) || - - (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || - - (empty($this->_postData) && empty($this->_postFiles))))) - - { - - $this->removeHeader('Content-Type'); - - } else { - - if (empty($this->_requestHeaders['content-type'])) { - - // Add default content-type - - $this->addHeader('Content-Type', 'application/x-www-form-urlencoded'); - - } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) { - - $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime()); - - $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary); - - } - - } - - - - // Request Headers - - if (!empty($this->_requestHeaders)) { - - foreach ($this->_requestHeaders as $name => $value) { - - $canonicalName = implode('-', array_map('ucfirst', explode('-', $name))); - - $request .= $canonicalName . ': ' . $value . "\r\n"; - - } - - } - - - - // No post data or wrong method, so simply add a final CRLF - - if (in_array($this->_method, $this->_bodyDisallowed) || - - (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) { - - - - $request .= "\r\n"; - - - - // Post data if it's an array - - } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && - - (!empty($this->_postData) || !empty($this->_postFiles))) { - - - - // "normal" POST request - - if (!isset($boundary)) { - - $postdata = implode('&', array_map( - - create_function('$a', 'return $a[0] . \'=\' . $a[1];'), - - $this->_flattenArray('', $this->_postData) - - )); - - - - // multipart request, probably with file uploads - - } else { - - $postdata = ''; - - if (!empty($this->_postData)) { - - $flatData = $this->_flattenArray('', $this->_postData); - - foreach ($flatData as $item) { - - $postdata .= '--' . $boundary . "\r\n"; - - $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"'; - - $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n"; - - } - - } - - foreach ($this->_postFiles as $name => $value) { - - if (is_array($value['name'])) { - - $varname = $name . ($this->_useBrackets? '[]': ''); - - } else { - - $varname = $name; - - $value['name'] = array($value['name']); - - } - - foreach ($value['name'] as $key => $filename) { - - $fp = fopen($filename, 'r'); - - $data = fread($fp, filesize($filename)); - - fclose($fp); - - $basename = basename($filename); - - $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; - - - - $postdata .= '--' . $boundary . "\r\n"; - - $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; - - $postdata .= "\r\nContent-Type: " . $type; - - $postdata .= "\r\n\r\n" . $data . "\r\n"; - - } - - } - - $postdata .= '--' . $boundary . "--\r\n"; - - } - - $request .= 'Content-Length: ' . strlen($postdata) . "\r\n\r\n"; - - $request .= $postdata; - - - - // Explicitly set request body - - } elseif (!empty($this->_body)) { - - - - $request .= 'Content-Length: ' . strlen($this->_body) . "\r\n\r\n"; - - $request .= $this->_body; - - } - - - - return $request; - - } - - - - /** - - * Helper function to change the (probably multidimensional) associative array - - * into the simple one. - - * - - * @param string name for item - - * @param mixed item's values - - * @return array array with the following items: array('item name', 'item value'); - - */ - - function _flattenArray($name, $values) - - { - - if (!is_array($values)) { - - return array(array($name, $values)); - - } else { - - $ret = array(); - - foreach ($values as $k => $v) { - - if (empty($name)) { - - $newName = $k; - - } elseif ($this->_useBrackets) { - - $newName = $name . '[' . $k . ']'; - - } else { - - $newName = $name; - - } - - $ret = array_merge($ret, $this->_flattenArray($newName, $v)); - - } - - return $ret; - - } - - } - - - - - - /** - - * Adds a Listener to the list of listeners that are notified of - - * the object's events - - * - - * @param object HTTP_Request_Listener instance to attach - - * @return boolean whether the listener was successfully attached - - * @access public - - */ - - function attach(&$listener) - - { - - ... [truncated message content] |
From: <sk...@us...> - 2007-11-20 08:42:34
|
Revision: 284 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=284&view=rev Author: sknappe Date: 2007-11-20 00:42:28 -0800 (Tue, 20 Nov 2007) Log Message: ----------- deleted old files Modified Paths: -------------- trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php trunk/src/dbpedia-navigator/Ajax-Test/ajax.php trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php trunk/src/dbpedia-navigator/Ajax-Test/index.php Removed Paths: ------------- trunk/src/dbpedia-navigator/Settings.php trunk/src/dbpedia-navigator/SparqlConnection.php trunk/src/dbpedia-navigator/default.css trunk/src/dbpedia-navigator/index.php trunk/src/dbpedia-navigator/master.php trunk/src/dbpedia-navigator/pear/ Modified: trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/Ajax-Test/SparqlConnection.php 2007-11-20 08:42:28 UTC (rev 284) @@ -8,16 +8,29 @@ private $id; private $ksID; - function SparqlConnection($DBPediaUrl,$DLLearnerUri) + function SparqlConnection($DBPediaUrl,$DLLearnerUri,$id=0,$ksID=0) { ini_set('default_socket_timeout',200); $this->DBPediaUrl=$DBPediaUrl; $this->DLLearnerUri=$DLLearnerUri; $this->client=new SoapClient("main.wsdl"); - $this->id=$this->client->generateID(); - $this->ksID = $this->client->addKnowledgeSource($this->id, "sparql", $this->DBPediaUrl); + $this->id=$id; + $this->ksID=$ksID; } + function getIDs() + { + $id=$this->client->generateID(); + $ksID=$this->client->addKnowledgeSource($id,"sparql",$this->DBPediaUrl); + return array(0 => $id, 1 => $ksID); + } + + function test() + { + $object=$this->client->test($this->id,$this->ksID); + return $object->item; + } + function getConceptFromExamples($ttl,$posExamples,$negExamples) { $this->client->applyConfigEntryInt($this->id, $this->ksID, "numberOfRecursions", 2); @@ -104,9 +117,9 @@ return array(); } - function getSubjects($ttl,$label='Leipzig',$limit=5) + function getSubjects($ttl,$label) { - $options=array("subjects",$label,$limit); + $options=array("subjects",$label,15); $this->client->startThread($this->id,$this->ksID,$options); $i = 1; $sleeptime = 1; @@ -155,70 +168,7 @@ return array(); } - /*public function testSoapTime() - { - $start = microtime(true); - $this->id=$this->client->generateID(); - $test=$this->client->debug("Test"); - $time=microtime(true)-$start; - return "Word: ".$test." got from SOAP in: ".$time; - }*/ - - public function startSearchAndShowArticle($keyword) - { - //TODO work on $keyword to get white space out - //TODO change article get function - $options=array("triples","http://dbpedia.org/resource/".$keyword); - $this->client->startThread($this->id,$this->ksID,$options); - - $options=array("subjects",$keyword,15); - $this->client->startThread($this->id,$this->ksID,$options); - } - - public function checkSearch($stop) - { - $this->client=new SoapClient("main.wsdl"); - if ($stop){ - $this->client->stopSparqlThread($this->id,$this->ksID,"subjects"); - return; - } - - // see if algorithm is running - if (!$this->client->isThreadRunning($this->id,$this->ksID,"subjects")) - { - $object=$this->client->getFromSparql($this->id,$this->ksID,"subjects"); - return $object->item; - } - return NULL; - } - - public function checkShowArticle($stop) - { - $this->client=new SoapClient("main.wsdl"); - if ($stop){ - $this->client->stopSparqlThread($this->id,$this->ksID,"triples"); - return; - } - - if (!$this->client->isThreadRunning($this->id,$this->ksID,"triples")) - { - $object=$this->client->getFromSparql($this->id,$this->ksID,"triples"); - $array=$object->item; - if (count($array)==1) return $array; - $ret=array(); - foreach ($array as $element) - { - $items=preg_split("[<]",$element,-1, PREG_SPLIT_NO_EMPTY); - $ret[$items[0]]=$items[1]; - } - return $ret; - } - return NULL; - } - public function loadWSDLfiles($wsdluri){ - ini_set("soap.wsdl_cache_enabled","0"); - $main=SparqlConnection::getwsdl($wsdluri); $other=SparqlConnection::getOtherWSDL($main); $newMain=SparqlConnection::changeWSDL($main); Modified: trunk/src/dbpedia-navigator/Ajax-Test/ajax.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/ajax.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/Ajax-Test/ajax.php 2007-11-20 08:42:28 UTC (rev 284) @@ -7,10 +7,7 @@ 'onResponseDelay' => 'showLoadingSubjects', 'beforeResponseProcessing' => 'hideLoadingSubjects' )); -$xajax->register(XAJAX_FUNCTION, 'getarticle', array( - 'onResponseDelay' => 'showLoadingArticle', - 'beforeResponseProcessing' => 'hideLoadingArticle' - )); +$xajax->registerFunction('getarticle'); $xajax->registerFunction('addPositive'); $xajax->registerFunction('addNegative'); $xajax->registerFunction('clearPositives'); @@ -24,9 +21,4 @@ 'beforeResponseProcessing' => 'hideLoadingConceptSubjects' )); $xajax->registerFunction('searchAndShowArticle'); -$xajax->register(XAJAX_FUNCTION, 'showThisSearchResult', array( - 'onResponseDelay' => 'showLoadingSubjects', - 'beforeResponseProcessing' => 'hideLoadingSubjects' - )); -$xajax->registerFunction('showThisArticle'); ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/Ajax-Test/ajaxfunctions.php 2007-11-20 08:42:28 UTC (rev 284) @@ -7,25 +7,25 @@ require("ajax.php"); $xajax->processRequest(); -function getsubjects($label, $limit) +function getsubjects($label) { - include_once("Settings.php"); + require_once("Settings.php"); require_once("SparqlConnection.php"); $settings=new Settings(); - $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); $content=""; - $subjects=$sc->getSubjects($settings->sparqlttl,$label,$limit); + $subjects=$sc->getSubjects($settings->sparqlttl,$label); if (count($subjects)==1) { if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); - else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."');return false;\">".urldecode(substr (strrchr ($subjects, "/"), 1))."</a><br/>"; + else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; } else if (count($subjects)==0) $content.="No search result found in time."; else{ foreach ($subjects as $subject) { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."',-1);return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } } @@ -34,30 +34,65 @@ return $objResponse; } -function getarticle($subject) +function getarticle($subject,$fromCache) { - include_once("Settings.php"); - require_once("SparqlConnection.php"); - $settings=new Settings(); - $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); - $triples=$sc->getTriples($settings->sparqlttl,$subject); - $content=""; - if (count($triples)==1) - { - $content.=substr($triples,7); - } - else if (count($triples)==0) $content.="Article not found."; - else { + if (isset($_SESSION['articles'])) + foreach ($_SESSION['articles'] as $key => $value) + { + if ($value['subject']==$subject){ + $fromCache=$key; + break; + } + } + if ($fromCache==-1) { + require_once("Settings.php"); + require_once("SparqlConnection.php"); + $settings=new Settings(); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); + $triples=$sc->getTriples($settings->sparqlttl,$subject); $content=""; - $content.="<img src=\"".$triples['http://xmlns.com/foaf/0.1/depiction']."\" alt=\"Picture of ".urldecode(substr (strrchr ($subject, "/"), 1))."\" width=\"50\"/ style=\"float:left\">"; - $content.="<div>".urldecode($triples['http://dbpedia.org/property/abstract'])."</div>"; + if (count($triples)==1) + { + $content.=substr($triples,7); + } + else if (count($triples)==0) $content.="Article not found."; + else { + $content=""; + $content.="<img src=\"".$triples['http://xmlns.com/foaf/0.1/depiction']."\" alt=\"Picture of ".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."\" width=\"50\"/ style=\"float:left\">"; + $content.="<div>".urldecode($triples['http://dbpedia.org/property/abstract'])."</div>"; + + $contentbuttons="<input type=\"button\" value=\"Positive\" class=\"button\" onclick=\"xajax_addPositive('".$subject."');return false;\" /> <input type=\"button\" value=\"Negative\" class=\"button\" onclick=\"xajax_addNegative('".$subject."');return false;\" />"; + } - $contentbuttons="<input type=\"button\" value=\"Positive\" class=\"button\" onclick=\"xajax_addPositive('".$subject."');return false;\" /> <input type=\"button\" value=\"Negative\" class=\"button\" onclick=\"xajax_addNegative('".$subject."');return false;\" />"; + //store article in session, to navigate between last 5 articles quickly + $contentArray=array('content' => $content,'contentbuttons' => $contentbuttons, 'subject' => $subject); + if (!isset($_SESSION['nextArticle'])){ + $_SESSION['nextArticle']=0; + $_SESSION['articles']=array(); + } + if ($_SESSION['nextArticle']==5) $_SESSION['nextArticle']=0; + $_SESSION['articles'][$_SESSION['nextArticle']]=$contentArray; + $_SESSION['currentArticle']=$_SESSION['nextArticle']; + $_SESSION['nextArticle']++; } + else { + $content=$_SESSION['articles'][$fromCache]['content']; + $contentbuttons=$_SESSION['articles'][$fromCache]['contentbuttons']; + $subject=$_SESSION['articles'][$fromCache]['subject']; + } + $lastArticles=""; + foreach ($_SESSION['articles'] as $key => $value) + { + $lastArticles.="<a href=\"\" onclick=\"xajax_getarticle('',".$key.");return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($value['subject'], "/"), 1)))."</a><br/>"; + } + + //build the response $objResponse = new xajaxResponse(); $objResponse->assign("articlecontent", "innerHTML", $content); $objResponse->assign("contentbuttons", "innerHTML", $contentbuttons); + $objResponse->assign("ArticleTitle","innerHTML",str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))); + $objResponse->assign("lastarticles","innerHTML",$lastArticles); return $objResponse; } @@ -73,7 +108,7 @@ $_SESSION['positive']=$array; } - $content=urldecode(substr (strrchr ($subject, "/"), 1))."<br/>"; + $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; $objResponse = new xajaxResponse(); $objResponse->append("Positives", "innerHTML", $content); @@ -92,7 +127,7 @@ $_SESSION['negative']=$array; } - $content=urldecode(substr (strrchr ($subject, "/"), 1))."<br/>"; + $content=str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."<br/>"; $objResponse = new xajaxResponse(); $objResponse->append("Negatives", "innerHTML", $content); @@ -124,7 +159,7 @@ require_once("Settings.php"); require_once("SparqlConnection.php"); $settings=new Settings(); - $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); $concept=$sc->getConceptFromExamples($settings->sparqlttl,$_SESSION['positive'],$_SESSION['negative']); $_SESSION['lastLearnedConcept']=$concept; @@ -142,7 +177,7 @@ require_once("Settings.php"); require_once("SparqlConnection.php"); $settings=new Settings(); - $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); $content=""; if (isset($_SESSION['lastLearnedConcept'])) @@ -151,13 +186,13 @@ if (count($subjects)==1) { if (strpos($subjects,"[Error]")===0) $content.=substr($subjects,7); - else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."');return false;\">".urldecode(substr (strrchr ($subjects, "/"), 1))."</a><br/>"; + else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subjects."');return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subjects, "/"), 1)))."</a><br/>"; } else if (count($subjects)==0) $content.="No examples for concept found in time."; else { foreach ($subjects as $subject) { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".urldecode(substr (strrchr ($subject, "/"), 1))."</a><br/>"; + $content.="<a href=\"\" onclick=\"xajax_getarticle('".$subject."');return false;\">".str_replace("_"," ",urldecode(substr (strrchr ($subject, "/"), 1)))."</a><br/>"; } } } @@ -174,111 +209,14 @@ require_once("SparqlConnection.php"); $settings=new Settings(); - $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); + $sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri,$_SESSION['id'],$_SESSION['ksID']); $content=""; - $sc->startSearchAndShowArticle($keyword); $objResponse = new xajaxResponse(); - $objResponse->call('xajax_showThisArticle', urlencode(serialize($sc)),"http://dbpedia.org/resource/".$keyword); - $objResponse->call('xajax_showThisSearchResult', urlencode(serialize($sc))); + $objResponse->call('xajax_getarticle', "http://dbpedia.org/resource/".str_replace(" ","_",$keyword),-1); + $objResponse->call('xajax_getsubjects',$keyword); return $objResponse; } -function showThisSearchResult($sc) -{ - require_once("Settings.php"); - require_once("SparqlConnection.php"); - $settings=new Settings(); - $sc=unserialize(urldecode($sc)); - $objResponse = new xajaxResponse(); - $i = 1; - $sleeptime = 1; - $searchComplete=false; - do { - if (!$searchComplete) $searchResult=$sc->checkSearch(false); - if (!is_null($searchResult)){ - $searchComplete=true; - break; - } - - $seconds = $i * $sleeptime; - $i++; - - // sleep a while - sleep($sleeptime); - } while ($seconds<$settings->sparqlttl); - - if (!$searchComplete){ - $sc->checkSearch(true); - $objResponse->assign("searchcontent","innerHtml","No search result found in time."); - } - - $content=""; - if (count($searchResult)==1) - { - if (strpos($searchResult,"[Error]")===0) $content.=substr($searchResult,7); - else $content.="<a href=\"\" onclick=\"xajax_getarticle('".$searchResult."');return false;\">".urldecode(substr (strrchr ($searchResult, "/"), 1))."</a><br/>"; - } - else if (count($searchResult)==0) $content.="No search result found in time."; - else{ - foreach ($searchResult as $result) - { - $content.="<a href=\"\" onclick=\"xajax_getarticle('".$result."');return false;\">".urldecode(substr (strrchr ($result, "/"), 1))."</a><br/>"; - } - } - - - $objResponse->assign("searchcontent", "innerHTML", $content); - return $objResponse; -} - -function showThisArticle($sc,$subject) -{ - require_once("Settings.php"); - require_once("SparqlConnection.php"); - $settings=new Settings(); - $sc=unserialize(urldecode($sc)); - $i = 1; - $sleeptime = 1; - $showArticleComplete=false; - do { - if (!$showArticleComplete) $article=$sc->checkShowArticle(false); - if (!is_null($article)){ - $showArticleComplete=true; - break; - } - - $seconds = $i * $sleeptime; - $i++; - - // sleep a while - sleep($sleeptime); - } while ($seconds<$settings->sparqlttl); - - $content=""; - if (!$showArticleComplete){ - $sc->checkShowArticle(true); - } - - - if (count($article)==1) - { - $content.=substr($article,7); - } - else if (count($article)==0) $content.="Article not found."; - else { - $content=""; - $content.="<img src=\"".$article['http://xmlns.com/foaf/0.1/depiction']."\" alt=\"Picture of ".urldecode(substr (strrchr ($subject, "/"), 1))."\" width=\"50\"/ style=\"float:left\">"; - $content.="<div>".urldecode($article['http://dbpedia.org/property/abstract'])."</div>"; - - $contentbuttons="<input type=\"button\" value=\"Positive\" class=\"button\" onclick=\"xajax_addPositive('".$subject."');return false;\" /> <input type=\"button\" value=\"Negative\" class=\"button\" onclick=\"xajax_addNegative('".$subject."');return false;\" />"; - } - - $objResponse = new xajaxResponse(); - $objResponse->assign("articlecontent", "innerHTML", $content); - $objResponse->assign("contentbuttons", "innerHTML", $contentbuttons); - return $objResponse; -} - ?> \ No newline at end of file Modified: trunk/src/dbpedia-navigator/Ajax-Test/index.php =================================================================== --- trunk/src/dbpedia-navigator/Ajax-Test/index.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/Ajax-Test/index.php 2007-11-20 08:42:28 UTC (rev 284) @@ -1,7 +1,15 @@ <?php ini_set('error_reporting',E_ALL); ini_set('max_execution_time',200); +ini_set("soap.wsdl_cache_enabled","1"); session_start(); +require_once('Settings.php'); +require_once('SparqlConnection.php'); +$settings=new Settings(); +$sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); +$ids=$sc->getIDs(); +$_SESSION['id']=$ids[0]; +$_SESSION['ksID']=$ids[1]; echo "<a href='clearsession.php'>start from scratch</a>"; @@ -94,7 +102,7 @@ <div id="content"> <div class="box"> - <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left">Article</td><td class="right"><span id="contentbuttons"></span></td></tr></table></div> + <div class="boxtitlewithbutton"><table border="0" class="titletable"><tr><td class="left" id="ArticleTitle">Article</td><td class="right"><span id="contentbuttons"></span></td></tr></table></div> <div class="boxcontent" id="article"> <div id="articlecontent" style="display:block"></div> <div id="loadingArticle" style="display:none"><img src="ajax-loader.gif" alt="Loading..."/></div> @@ -117,6 +125,12 @@ </div> <!-- boxcontent --> </div> <!-- box --> +<div class="box"> + <div class="boxtitle">Last Articles</div> + <div class="boxcontent" id="lastarticles"> + </div> <!-- boxcontent --> +</div> <!-- box --> + <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> </div><!-- rightSidebar --> <div id="clear"></div> Deleted: trunk/src/dbpedia-navigator/Settings.php =================================================================== --- trunk/src/dbpedia-navigator/Settings.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/Settings.php 2007-11-20 08:42:28 UTC (rev 284) @@ -1,7 +0,0 @@ -<?php - -class Settings{ - public $wsdluri="http://localhost:8181/services?wsdl"; - public $dbpediauri="http://dbpedia.openlinksw.com:8890/sparql"; -} -?> \ No newline at end of file Deleted: trunk/src/dbpedia-navigator/SparqlConnection.php =================================================================== --- trunk/src/dbpedia-navigator/SparqlConnection.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/SparqlConnection.php 2007-11-20 08:42:28 UTC (rev 284) @@ -1,195 +0,0 @@ -<?php - -require_once 'pear/HTTP_Request.php'; - -class SparqlConnection -{ - private $DBPediaUrl; - private $DLLearnerUri; - private $client; - - function SparqlConnection($DBPediaUrl,$DLLearnerUri) - { - ini_set("soap.wsdl_cache_enabled","0"); - ini_set('default_socket_timeout',200); - $this->DBPediaUrl=$DBPediaUrl; - $this->DLLearnerUri=$DLLearnerUri; - $this->loadWSDLfiles($DLLearnerUri); - $this->client=new SoapClient("main.wsdl"); - } - - function getConceptFromExamples($posExamples,$negExamples) - { - $id=$this->client->generateID(); - - $ksID = $this->client->addKnowledgeSource($id, "sparql", $this->DBPediaUrl); - $this->client->applyConfigEntryInt($id, $ksID, "numberOfRecursions", 2); - $this->client->applyConfigEntryStringArray($id, $ksID, "instances", array_merge($posExamples,$negExamples)); - $this->client->applyConfigEntryInt($id, $ksID, "filterMode", 0); - $this->client->applyConfigEntryStringArray($id, $ksID, "predList", array()); - $this->client->applyConfigEntryStringArray($id, $ksID, "objList", array()); - $this->client->applyConfigEntryStringArray($id, $ksID, "classList", array()); - $this->client->applyConfigEntryString($id, $ksID, "format", "KB"); - $this->client->applyConfigEntryBoolean($id, $ksID, "dumpToFile", true); - - $this->client->setReasoner($id, "dig"); - $this->client->setLearningProblem($id, "posNegDefinition"); - $this->client->setPositiveExamples($id, $posExamples); - $this->client->setNegativeExamples($id, $negExamples); - $this->client->setLearningAlgorithm($id, "refinement"); - - $start = microtime(true); - - $this->client->init($id); - - $learn_start = microtime(true); - $init = $learn_start - $start; - echo 'components initialised in '.$init.' seconds<br />'; - - $threaded=true; - - if($threaded == false) { - - $concept = $this->client->learn($id); - - $learn = microtime(true) - $learn_start; - echo 'concept learned in '.$learn.' seconds<br />'; - - echo 'result: '.$concept; - - } else { - - $this->client->learnThreaded($id); - - $i = 1; - $sleeptime = 1; - - do { - // sleep a while - sleep($sleeptime); - - // see what we have learned so far - $concept=$this->client->getCurrentlyBestConcept($id); - $running=$this->client->isAlgorithmRunning($id); - - $seconds = $i * $sleeptime; - - echo 'result after '.$seconds.' seconds of sleep: '.$concept.'<br />'; - - $i++; - } while($running); - - echo 'algorithm finished'; - } - return $concept; - } - - function getTriples($individual) - { - $id=$this->client->generateID(); - - $ksID = $this->client->addKnowledgeSource($id, "sparql", $this->DBPediaUrl); - $this->client->applyConfigEntryInt($id, $ksID, "numberOfRecursions", 1); - $this->client->applyConfigEntryStringArray($id, $ksID, "instances", array($individual)); - $this->client->applyConfigEntryInt($id, $ksID, "filterMode", -1); - $this->client->applyConfigEntryStringArray($id, $ksID, "predList", array()); - $this->client->applyConfigEntryStringArray($id, $ksID, "objList", array()); - $this->client->applyConfigEntryStringArray($id, $ksID, "classList", array()); - $this->client->applyConfigEntryString($id, $ksID, "format", "Array"); - $this->client->applyConfigEntryBoolean($id, $ksID, "dumpToFile", false); - $this->client->applyConfigEntryBoolean($id,$ksID,"useLits",true); - - $object=$this->client->getTriples($id,$ksID); - $array=$object->item; - $ret=array(); - foreach ($array as $element) - { - $items=preg_split("[<]",$element,-1, PREG_SPLIT_NO_EMPTY); - $ret[]=$items; - } - - return $ret; - } - - function getSubjects($label,$limit) - { - $id=$this->client->generateID(); - - $ksID = $this->client->addKnowledgeSource($id, "sparql", $this->DBPediaUrl); - $object=$this->client->getSubjects($id,$ksID,$label,$limit); - return $object->item; - } - - private function loadWSDLfiles($wsdluri){ - $main=$this->getwsdl($wsdluri); - $other=$this->getOtherWSDL($main); - $newMain=$this->changeWSDL($main); - $this->writeToFile("main.wsdl",$newMain); - $x=0; - foreach ($other as $o){ - $this->writeToFile("def".($x++).".xsd",$this->getwsdl($o)); - } - - } - - private function changeWSDL($wsdl){ - $before="<xsd:import schemaLocation=\""; - $after="\" namespace=\""; - $newWSDL=""; - $desca="def"; - $descb=".xsd"; - $x=0; - while($posstart= strpos ( $wsdl, $before )){ - - $posstart+=strlen($before); - $newWSDL.=substr($wsdl,0,$posstart); - $wsdl=substr($wsdl,$posstart); - $newWSDL.=$desca.($x++).$descb; - $posend= strpos ( $wsdl, $after ); - $wsdl=substr($wsdl,$posend); - - } - return $newWSDL.$wsdl; - - } - - private function getOtherWSDL($wsdl){ - $before="<xsd:import schemaLocation=\""; - $after="\" namespace=\""; - $ret=array(); - while($posstart= strpos ( $wsdl, $before )){ - $posstart+=strlen($before); - $wsdl=substr($wsdl,$posstart); - $posend= strpos ( $wsdl, $after ); - $tmp=substr($wsdl,0,$posend); - $ret[]=$tmp; - $wsdl=substr($wsdl,$posend+strlen($after)); - } - return $ret; - } - - - - - private function getwsdl($wsdluri){ - // this is copied from the Pear example - // please don't ask me how it works - $req = &new HTTP_Request($wsdluri); - $message=""; - $req->setMethod(HTTP_REQUEST_METHOD_GET); - $req->sendRequest(); - $ret=$req->getResponseBody(); - return $ret; - } - - - - private function writeToFile($filename,$content){ - - $fp=fopen($filename,"w"); - fwrite($fp,$content); - fclose($fp); - - } -} -?> \ No newline at end of file Deleted: trunk/src/dbpedia-navigator/default.css =================================================================== --- trunk/src/dbpedia-navigator/default.css 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/default.css 2007-11-20 08:42:28 UTC (rev 284) @@ -1,453 +0,0 @@ -/** - * default.css - * main Ontowiki style sheet - * @author: Norman Heino - * @version: $Id: default.css 751 2007-02-14 19:20:17Z nheino $ - */ - -/* remove browser specific margins */ -* { - margin: 0; - padding: 0; -} - -html { - font: 80%/1.2 "Lucida Grande", Helvetica, Arial, sans-serif; -} - -p { - margin: 8px 0; -} - -h2 { - margin: 0.5em 0 0.1em 0; -/* background-color: #eee;*/ - font-size: 110%; -} - - -/* - * Main site structure - */ - -#wrapper { - position: relative; - max-width: 100%; - padding: 15px; -/* margin: 15px;*/ -} - -#content { - margin: 0 19em; - overflow: hidden; -/* border-left: 1px solid #bbb; - border-right: 1px solid #bbb; - padding: 0 5px;*/ -} - -/* - * Side bars are positioned absolutely due to several reasons: - * (1)Internet Explorer has problems displaying float elements, - * (2) the content's position in html is irrelevant, - * (3) positioning the content div is more straightforward. - */ -#leftSidebar { - position: absolute; - width: 18em; -} - -#rightSidebar { - position: absolute; - width: 18em; - top: 15px; - right: 15px; -} - -#clear { - clear: both; -} - - -/* - * sidebar content (boxes) - */ - -.box { - color: #666; - margin-bottom: 20px; - border: 1px solid #bbb; - font-size: 85%; -} - -/*.box td { - font-size: 100%; -}*/ - -.box .boxtitle { - color: #666; - background-color: #eee; - padding: 3px 0.4em; - font-weight: bold; - white-space: nowrap; -} - -.box .boxtitle .boxtitle_string { - width: 80%; - overflow: hidden; -/* display: none;*/ -} - -.box .boxcontent { - padding: 0.6em; - border-top: 1px solid #bbb; -} - -/* restrict content of certain boxes */ -.box#predicates .boxcontent, -.box#classes .boxcontent { - overflow: hidden; -} - -.box p { - margin: 0 2px 4px 0; -} - -.box ul, .box ol { - margin: 0px; -/* padding-left: 15px;*/ - list-style-position: inside; -} - -.box ul.no_bullet, .box ul.no_bullet { - list-style-type: none; -} - -.box ul li.horizontal, .box ol li.horizontal, -.box ul.horizontal, .box ol.horizontal { - display: inline; -} - -.box a.title_switch { - position: absolute; - right: 0.5em; - margin: auto 0; - color: #666; - border: 1px solid #bbb; - width: 1em; - height: 1em; - background-color: #fff; - text-align: center; -} - -.box a.title_switch:hover { - color: #02a; - text-decoration: none; - background-color: #eee; -} - -.box hr { - margin: 0.5em 0; - border: none; - border-top: 1px dotted #bbb; - height: 0; -} - -.box#classes .boxcontent a { - display: block; -} - -/*.box select { - width: 250px; /* TODO remove absolute size */ -}*/ - -.box input { - width: auto; -} - -.box td input { - width: 100%; -} - -.box img.rating { - position: relative; - top: 1px; -} - -.hidden { - display: none; -} - - -/* - * Links - */ - -a, a:link, a:visited { - color: #02a; - text-decoration: none; - cursor: pointer; -} - -a:hover { - text-decoration: underline; -} - - -/* - * Tabs - */ - -/* all the tabs */ -.tabs { - float: left; - width: 100%; - background: #fff url("../images/tabs_back.png") repeat-x bottom; -} - -.tabs ul { - list-style: none; -} - -.tabs li { - float: left; - margin-right: 1px; -} - -.tabs a { - display: block; - margin-top: 1px; - padding: 0.35em 1.35em; - background-image: url("../images/tab_back.png"); - background-repeat: repeat-x; - background-color: #cbcbcb; - border: 1px solid #bbb; -} - -.tabs a:hover { - background: #fff; - text-decoration: none; -} - -.tabs a.current { - background: #fff; - border-bottom: 1px solid #fff; -} - -/* horizontal line underneath the tabs */ -#tab-line { - height: 1em; - clear: both; -} - -#instances { - float: right; -} - -.selected { - background-color: #bde; /*#b4d5fe;*/ -} - -.button { - border: solid black 1px; - padding: 0px 1px; - background-color: #eee; -} - -/* - * Tables - */ - -tr.odd { - background-color: #ccc; -} - -tr.even { - background-color: #eee; -} - -table.instanceTable th { - text-align: left; -/* background-color: #eee;*/ -} - -table.instanceTable > tbody > tr > td { - padding-top: 0.5em; -} - -table.instanceTable td.property { - text-align: right; - font-style: italic; - padding-right: 5px; -} - -table.instanceTable ul { - margin: 0px; - padding-left: 20px; -} - -table.instanceTable { - width: 100%; -} - -.searchHighlight { - background-color: orange; -} - -table.tripletable { - width: 100%; - font-size: 90%; -} - -.tripletable td { - padding: 0.4em; -} - -table.blind tr td { - padding-top: 0.4em; -} - -/* - * Instances - */ - -.instance .instance { - margin-left: 13px; - background-color: #ddd; -} -.instance .instance td { - font-size: 90%; -} -.instance .instance .instance { - background-color: #eee; -} - -.instance .instance .instance .instance { - background-color: #fff; -} - -#instanceEdit { - border-spacing: 0px; - width: 100%; -} - -#instanceEdit input, #instanceEdit textarea { -/* width: 250px;*/ - background-color: #fff; - font-size: 95%; - font-family: "Lucida Grande", Helvetica, Arial, sans-serif; - padding: 0.1em 0; -} - -#instanceEdit > tbody > tr > td, #instanceEdit > tr > td { - background-color: #eee; - padding: 5px; - border-bottom: 2px solid #fdfdfd; -} - -/* - * Calendar - */ - -table.calendar { - margin-top: 1em; - width: 100%; - height: 730px; - table-layout: fixed; - font-size: 90%; -} - -.calendar .weekday0 { - background-color: #eee; - padding: 0.4em; -} -.calendar .weekday1 { - background-color: #f5f5f5; - padding: 0.4em; -} -.calendar .weekend0 { - background-color: #ddd; - padding: 0.4em; -} -.calendar .weekend1 { - background-color: #eaeaea; - padding: 0.4em; -} - -#map { - margin-top: 0.5em; - width: 100%; - height: 750px; - font-size: 90%; -} - -#map .instance td { - font-size: 80%; - padding: 0 3px; - border-bottom: 5px solid white; -} - -#superClassPath { - margin-bottom: 0.5em; -} - -img { - border: none; -} - -span.submit { - float: right; - padding-right: 100px; -} - -/* - * Autosuggest box - */ -div.autosuggest { - font-size: 85%; - position: absolute; - background-color: #fff; - border: 1px solid #bbb; -} - -div.autosuggest ul { - list-style-type: none; - list-style-position: inside; - padding-left: 0px; -} - -div.autosuggest ul li.selected { - background-color: #bde; -} - -div.autosuggest ul li { - display: block; - padding: 0.2em; -/* height: 22px;*/ - cursor: pointer; -} - -span.formal { - display: none; -} - -/* - * Layer - */ -#layer { - width: 100%; - height: 100%; - position: absolute; - background-image: url("../images/black_50.png"); - background-repeat: repeat; - z-index: 98; -} - -#layerContent { - margin-top: 100px; - margin: auto; - width: 500px; - height: 300px; - background-color: #ffb; - border: 2px solid #bbb; - z-index: 99; -} Deleted: trunk/src/dbpedia-navigator/index.php =================================================================== --- trunk/src/dbpedia-navigator/index.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/index.php 2007-11-20 08:42:28 UTC (rev 284) @@ -1,190 +0,0 @@ -<?php - -@session_start(); - -include_once("Settings.php"); -include_once("SparqlConnection.php"); - - ini_set('error_reporting',E_ALL); - ini_set('max_execution_time',200); - -//clear session -echo "<a href='index.php?clearsession=clear'>start from scratch</a>"; -if(isset($_GET['clearsession'])){ - session_unset(); -} - -//initialize variables -$content=""; -$positiveAdd=""; -$negativeAdd=""; - -//initialize the sparql connection -$settings=new Settings(); -$sc=new SparqlConnection($settings->dbpediauri,$settings->wsdluri); - - -//add positives or negatives to session -if (@$_GET['action']=='AddPositive'){ - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - if (!isset($_SESSION['positive'])){ - $array=array($_GET['subject']); - $_SESSION['positive']=$array; - } - else{ - $array=$_SESSION['positive']; - $array[]=$_GET['subject']; - $_SESSION['positive']=$array; - } -} -if (@$_GET['action']=='AddNegative'){ - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - if (!isset($_SESSION['negative'])){ - $array=array($_GET['subject']); - $_SESSION['negative']=$array; - } - else{ - $array=$_SESSION['negative']; - $array[]=$_GET['subject']; - $_SESSION['negative']=$array; - } -} - -//delete Positives or Negatives from Session -if (@$_GET['action']=='ClearPositive'){ - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - unset($_SESSION['positive']); -} -if (@$_GET['action']=='ClearNegative'){ - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - unset($_SESSION['negative']); -} - -//learn a concept -if (@$_GET['action']=="GetConcept") -{ - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - $conc=$sc->getConceptFromExamples($_SESSION['positive'],$_SESSION['negative']); - $_SESSION['learnedConcept']=$conc; -} - -//Get Search result -if (@$_GET['action']=='Search') -{ - $label=$_GET['search']; - $limit=$_GET['limit']; - $_GET=$_SESSION["lastGet"]; - $content=$_SESSION['lastContent']; - $subjects=$sc->getSubjects($label,$limit); - $_SESSION['lastSubjectSearch']=$subjects; -} - -//SearchBox - $search="<form action=\"index.php\" method=\"GET\">\n". - "<table border=\"0\">\n". - "<tr><tb>Search:<br/></tb></tr>\n". - "<tr><tb><input type=\"textfield\" name=\"search\"><select name=\"limit\" size=\"1\">\n". - "<option>1</option>\n". - "<option selected=\"selected\">5</option>\n". - "<option>10</option>\n". - "<option>15</option>\n". - "</select><br/></tb></tr>\n". - "<tr><tb><input type=\"submit\" name=\"action\" value=\"Search\"><input type=\"submit\" name=\"action\" value=\"Fulltext\"></tb></tr>\n". - "</table>\n". - "</form>\n"; - - -if (isset($_SESSION['learnedConcept'])) $learnedConc="<br/>Last learned Concept: ".$_SESSION['learnedConcept']; -else $learnedConc=""; - -if (isset($_SESSION['lastSubjectSearch'])){ - $search.="<br/>Last Search:<br/><br/>\n"; - $subjects=$_SESSION['lastSubjectSearch']; - foreach ($subjects as $subject){ - $search.="<a href=\"index.php?action=showPage&subject=".$subject."\">".$subject."</a><br/>\n"; - } -} - -//Show Subject Page -if ((@$_GET['action']=="showPage")&&($content==="")) -{ - $triples=$sc->getTriples($_GET['subject']); - foreach ($triples as $triple){ - $content.="Subject: ".urldecode($triple[0])."<br/>Predicate: ".urldecode($triple[1])."<br/>Object: ".urldecode($triple[2])."<br/><br/>\n"; - } -} - -//if an articel is shown, you can add it to Positives or Negatives -if (@$_GET['action']=="showPage") -{ - $positiveAdd="<input type=\"submit\" name=\"action\" value=\"AddPositive\">"; - $negativeAdd="<input type=\"submit\" name=\"action\" value=\"AddNegative\">"; -} - -//add box for adding articles to positive or negative -$examples="<form action=\"index.php\" method=\"GET\">\n". - "Positive:<br/>\n"; -if (!isset($_SESSION['positive'])) $examples.="No positive example picked yet.<br/>\n"; -else{ - $pos=$_SESSION['positive']; - foreach ($pos as $p) - { - $examples.=$p."<br/>\n"; - } -} -$examples.="<br/>".$positiveAdd." <input type=\"submit\" name=\"action\" value=\"ClearPositive\">\n". - "</form>\n"; - -$examples.="<form action=\"index.php\" method=\"GET\">\n". - "<br/>Negative:<br/>\n"; -if (!isset($_SESSION['negative'])) $examples.="No negative example picked yet.<br/>\n"; -else{ - $neg=$_SESSION['negative']; - foreach ($neg as $n) - { - $examples.=$n."<br/>\n"; - } -} -$examples.="<br/>".$negativeAdd." <input type=\"submit\" name=\"action\" value=\"ClearNegative\">\n". - "</form>\n"; - - -//fill concept box -$concept="<form action=\"index.php\" method=\"GET\">\n". - "<input type=\"submit\" name=\"action\" value=\"GetConcept\">\n". - "</form>\n"; -$concept.=$learnedConc; - - -$_SESSION['lastGet']=$_GET; -$_SESSION['lastContent']=$content; -//include master -include("master.php"); - -echo $masterContent; - - -//make a box -function makeBox($title,$content,$toggleBoxContent=true) -{ - if($toggleBoxContent) - { - $click="<a class=\"title_switch\" onclick=\"toggleBoxContent(this);\">\x96</a>"; - } - else{$click="";} - - $ret=" - <div class=\"box\" id=\"ontology\"> - <div class=\"boxtitle\">".$title.$click."</div> - <div class=\"boxcontent\"> - ".$content." - </div> <!-- boxcontent --> - </div> <!-- box -->"; - return $ret; -} -?> \ No newline at end of file Deleted: trunk/src/dbpedia-navigator/master.php =================================================================== --- trunk/src/dbpedia-navigator/master.php 2007-11-12 15:19:23 UTC (rev 283) +++ trunk/src/dbpedia-navigator/master.php 2007-11-20 08:42:28 UTC (rev 284) @@ -1,71 +0,0 @@ -<?php - -$masterContent=" - - -<html> - <head> - <title>DL Learner</title> - <meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\"/> - <link rel=\"stylesheet\" href=\"default.css\"/> - </head> - <body> -<script type=\"text/javascript\" src=\"jscript/wz_tooltip.js\"></script> -<script type=\"text/javascript\" src=\"jscript/scripts.js\"></script> -<h3>DBPedia-Navigator-Test</h3> -<div id=\"layer\" style=\"display:none\"><div id=\"layerContent\" style=\"display:none\"></div></div> -<div id=\"wrapper\"> - -<div id=\"leftSidebar\"> - -<div class=\"box\" id=\"search\"> - <div class=\"boxtitle\">Search<a class=\"title_switch\" onclick=\"toggleBoxContent(this);\">\x96</a></div> - <div class=\"boxcontent\"> - ".$search." - </div> <!-- boxcontent --> - -</div> <!-- box --> - -<div class=\"box\" id=\"examples\"> - <div class=\"boxtitle\">Examples<a class=\"title_switch\" onclick=\"toggleBoxContent(this);\">\x96</a></div> - <div class=\"boxcontent\"> - ".$examples." - </div> <!-- boxcontent --> - -</div> <!-- box --> - -<div class=\"box\" id=\"examples\"> - <div class=\"boxtitle\">Concept<a class=\"title_switch\" onclick=\"toggleBoxContent(this);\">\x96</a></div> - <div class=\"boxcontent\"> - ".$concept." - </div> <!-- boxcontent --> - -</div> <!-- box --> - -<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> -</div><!-- END leftSidebar --> - -<div id=\"content\"> -<div class=\"box\" id=\"search\"> - <div class=\"boxtitle\">Content</div> - <div class=\"boxcontent\"> - ".$content." - </div> <!-- boxcontent --> -</div> <!-- box --> - -<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> -</div><!-- content --> - -<div id=\"rightSidebar\"> - -<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> -</div><!-- rightSidebar --> - - <div id=\"clear\"></div> -</div><!-- wrapper --> - - </body> -</html> -"; - -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-12 15:19:31
|
Revision: 283 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=283&view=rev Author: jenslehmann Date: 2007-11-12 07:19:23 -0800 (Mon, 12 Nov 2007) Log Message: ----------- removed deprecated classes Config and ConfigurationManager (finally) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Removed Paths: ------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java Deleted: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 15:13:50 UTC (rev 282) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 15:19:23 UTC (rev 283) @@ -1,261 +0,0 @@ -package org.dllearner; - -import java.lang.reflect.Field; - -public class Config { - // standardmäßig wird bis Tiefe 7 gesucht - // public static int maxLength = 7; - - // public static int maxDepth; - - // Punktabzug für "ungenaue" Klassifizierungen, also positiv als neutral, - // neutral als negativ und negativ als neutral - // public static double accuracyPenalty = 1; - - // Punktabzug für fehlerhafte Klassifizierungen, also positiv als negativ - // und negativ als positiv - // public static double errorPenalty = 3; - - // public static ScoreMethod scoreMethod = ScoreMethod.POSITIVE; - - // public static LearningProblemType learningProblemType = LearningProblemType.TWO_VALUED; - - // public static boolean penalizeNeutralExamples = false; - - // public static boolean showCorrectClassifications = false; - - // wieviel Prozent darf ein um eine Einheit längeres Konzept schlechter - // sein (aktuell: 5% sind eine Verlängerung um 1 wert) - // Problem: dieser Parameter hat für GP und Refinement zwar die gleiche - // Bedeutung, - // aber es sind unterschiedliche Werte angebracht; - // bei GP sollte der Wert so sein, dass am Ende das gewünschte Konzept - // tatsächlich die beste Fitness hat, also eher niedrig (<0.005); - // bei Refinement in flexible heuristic soll es so sein, dass schlechtere - // Konzepte - // probiert werden sollen, sobald horizontal expansion eines gut - // klassifizierenden - // Knotens steigt => da ist also gewünscht das kürzere aber schlechtere - // Knoten - // ev. einen Vorsprung haben => demzufolge ist dort ein hoher Wert (ca. - // 0.05) - // angebracht - // public static double percentPerLengthUnit = 0.0025; - // public static double percentPerLengthUnit = 0.05; - -// public enum Algorithm { -// GP, BRUTE_FORCE, RANDOM_GUESSER, REFINEMENT, HYBRID_GP -// }; -// -// public static Algorithm algorithm = Algorithm.REFINEMENT; - - // Rückgabetyp des gelernten Konzepts - // public static String returnType = ""; - - // public static boolean statisticMode = false; - - // if set to true a retrieval algorithm is used for classification - // instead of single instance checks (default is now false, because - // we can send all instance checks in a single request), for KAON2 - // as reasoner it should in many cases be set to true - // public static boolean useRetrievalForClassification = false; - - // welche Art von Reasoning wird benutzt (eigener Algorithmus, - // KAON2-API, DIG-Interface) - // public static ReasonerType reasonerType = ReasonerType.DIG; - - // bei fast retrieval muss trotzdem irgendein Reasoner gesetzt - // werden um die flat ABox zu erzeugen - // public static ReasonerType startUpReasoningType = ReasonerType.KAON2; - - // public static URL digReasonerURL = null; - - // unique names assumption - // public static boolean una = false; - - // open world assumption; momentan wird closed world assumption nur - // fuer Rollen unterstuetzt - // public static boolean owa = true; - - // an-/abschalten von System.nanoTime()-Aufrufen außerhalb des - // Reasoningservice - // public static boolean useNonReasonerBenchmarks = false; - - // erlaubt das abschalten von Benchmarks bei der Subsumptionhierarchie, - // da diese ohnehin gecacht wird, also die System.nanoTime()-Aufrufe nur - // Zeit kosten - // public static boolean useHierarchyReasonerBenchmarks = false; - - // public static List<String> hidePrefixes = new LinkedList<String>(); - - // Informationen (Rollen, Konzepte, Individuen, Anzahl Axiome) über - // Wissensbasis anzeigen => alles konfigurierbar um Output in Grenzen - // zu halten -// public static boolean showRoles = false; -// public static boolean showConcepts = false; -// public static boolean showIndividuals = false; -// public static boolean showSubsumptionHierarchy = false; - // zeigt die interne Wissensbasis an (d.h. keine externen OWL-Dateien) -// public static boolean showInternalKB = false; -// public static int maxLineLength = 100; - - // public static boolean writeDIGProtocol = false; - // public static File digProtocolFile = new File("log/digProtocol.txt"); - - // public static String preprocessingModule = ""; - - // TODO: noch nicht implementiert, dass man diese per Config-Datei setzen - // kann - public static class Refinement { - - // Nutzung der Äquivalenz ALL R.C AND ALL R.D = ALL R.(C AND D) -// public static boolean applyAllFilter = true; - - // Nutzung der Äquivalenz EXISTS R.C OR EXISTS R.D = EXISTS R.(C OR D) -// public static boolean applyExistsFilter = true; - -// public static boolean useTooWeakList = true; - -// public static boolean useOverlyGeneralList = true; - -// public static boolean useShortConceptConstruction = true; - -// public static double horizontalExpansionFactor = 0.6; - -// public static boolean improveSubsumptionHierarchy = true; - -// public static boolean quiet = false; - - // public static boolean writeSearchTree = false; - - // public static File searchTreeFile = new File("searchTree.txt"); - - // public static Heuristic heuristic = Heuristic.LEXICOGRAPHIC; - - // multi instance check => es wird versucht mehrere instance checks pro - // Anfrage auf einmal an den Reasoner zu schicken; Vorteil bei DIG: - // weniger Kommunikation; Nachteil: es müssen alle instanceChecks - // ausgeführt - // werden, bevor too weak festgestellt werden kann - // TODO: not implemented -// public static UseMultiInstanceChecks useDIGMultiInstanceChecks = UseMultiInstanceChecks.TWOCHECKS; - - // geplante Optionen um den Suchraum einzuschränken - - // Konzepte, die in der Definition vorkommen können (per Default - // ("null") alle) - // nicht implementiert -// public static Set<AtomicConcept> allowedConcepts = null; - // ignorierte Konzepte; Default null = keine -// public static Set<AtomicConcept> ignoredConcepts = null; - // beachte: es können nur entweder die erlaubten oder die ignorierten - // Konzepte - // gesetzt werden - - // true falls die Konzepte vom Nutzer gesetzt worden (also - // allowedConcepts - // gleich null), ansonsten false -// public static boolean allowedConceptsAutoDetect = true; - - // Rollen, die in der Lösung vorkommen können - // nicht implementiert -// public static Set<AtomicRole> allowedRoles = null; -// public static Set<AtomicRole> ignoredRoles = null; -// public static boolean allowedRolesAutoDetect = true; - - // max. Verschachtelungstiefe der Lösung - // nicht implementiert -// public static int maxDepth = 0; - - // Konstruktoren an- und abschalten - // nicht implementiert -// public static boolean useAllConstructor = true; -// public static boolean useExistsConstructor = true; -// public static boolean useNegation = true; - // public static boolean useDisjunction = true; - // public static boolean useConjunction = true; - - // Domain und Range beim Verschachteln von Rollen beachten - // nicht implementiert - // TODO: Wie soll man das in DIG machen? -// public static boolean useDomainRange = false; - - // bereits vorher allgemeinere Konzepte festlegen (Default: keine) - // nicht implementiert - // => ist eigentlich unnötig, da dieses Wissen zur Ontologie hinzugefügt - // und dann gelernt werden kann - // public static List<AtomicConcept> fixedUpperConcepts; - - } - - public static class GP { - - // FPS funktioniert momentan noch nicht, es muss sichergestellt werden, - // dass die Fitness positiv ist (momentan ist sie nie gr��er 0) -// public static SelectionType selectionType = SelectionType.RANK_SELECTION; -// -// public static int tournamentSize = 3; -// -// public static boolean elitism = true; -// -// public static AlgorithmType algorithmType = AlgorithmType.STEADY_STATE; -// -// public static double mutationProbability = 0.03d; -// -// public static double crossoverProbability = 0.95d; -// -// public static double hillClimbingProbability = 0.0d; -// -// public static double refinementProbability = 0.0; -// -// public static int numberOfIndividuals = 100; -// -// public static int numberOfSelectedIndividuals = 96; -// -// public static boolean useFixedNumberOfGenerations = false; -// -// public static int generations = 20; -// -// public static int postConvergenceGenerations = 50; -// -// public static boolean adc = false; -// -// public static int initMinDepth = 4; -// -// public static int initMaxDepth = 6; -// -// public static int maxConceptLength = 75; -// -// // bei true werden statt Disjunction MultiDisjunction und statt -// // Conjunction -// // MultiConjunction im GP benutzt (es gibt derzeit keinen Grund es auf -// // false -// // zu setzen) -// public static boolean useMultiStructures = true; - - } - - public static String print() { - StringBuffer buff = new StringBuffer(); - buff.append("** overview of all set config values**\n\n"); - - Field[] fields = Config.class.getDeclaredFields(); - // Field[] fields = this.getClass().getDeclaredFields(); - for (int i = 0; i < fields.length; i++) { - try { - buff.append(fields[i].getName()).append("\t=>\t").append(fields[i].get(Config.class)) - .append("\n"); - - // System.out.println(fields[i].getName() + " : values: " + - // fields[i].get(this)); - } catch (IllegalAccessException ex) { - ex.printStackTrace(System.out); - } catch (IllegalArgumentException ex) { - ex.printStackTrace(System.out); - } - - } - return buff.toString(); - - } -} Deleted: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 15:13:50 UTC (rev 282) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 15:19:23 UTC (rev 283) @@ -1,574 +0,0 @@ -package org.dllearner; - -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.dllearner.cli.ConfFileOption; - -/** - * Nach dem einlesen der Datei werden hier alle Konfigurationsoptionen - * abgespeichert. Diese werden hier erst verwaltet und dann - * angewandt, indem die Werte der Variablen in Config umgeschrieben - * werden (bzw. es werden Fehlermeldungen bei nicht existierenden, - * inkorrekten oder inkompatiblen Einstellungen ausgegeben). - * - * TODO: Eventuell kann man damit Config.java ersetzen? Das w�re etwas - * sauberer, wenn man den DL-Learner als API sieht, der z.B. von - * OntoWiki aus genutzt wird. Dann k�nnte man sicherstellen, dass - * Konfigurationsoptionen nicht direkt ge�ndert werden, sondern - * �ber Anmeldung von �nderungen beim Konfigurationsmanager. - * - * TODO: noch checken, ob man die �berpr�fung der G�ltigkeit von - * Konfigurationsoptionen nicht schon bei deren Erstellung machen sollte - * - * @author jl - * - */ -public class ConfigurationManager { - - private Collection<ConfFileOption> options; - - // verfuegbare Optionen - // Problemfall: double-Optionen, die auch int-Optionen sein können; - // diese sind in beiden Mengen vertreten => man kann vereinbaren, dass - // jede double-Option auch eine int-Option sein kann - private Map<String, Integer[]> intOptions; - private Map<String, Double[]> doubleOptions; - private Map<String, String[]> strOptions; - private List<String> setOptions; - - public ConfigurationManager() { - this(new LinkedList<ConfFileOption>()); - } - - public ConfigurationManager(Collection<ConfFileOption> confOptions) { - // options = new HashSet<ConfigurationOption>(); - options = confOptions; - strOptions = new HashMap<String, String[]>(); - intOptions = new HashMap<String, Integer[]>(); - doubleOptions = new HashMap<String, Double[]>(); - setOptions = new LinkedList<String>(); - createIntOptions(); - createDoubleOptions(); - createStringOptions(); - createSetOptions(); - } - - public void applyOptions() { - for(ConfFileOption option : options) { - // System.out.println(option); - applyConfigurationOption(option); - } - - // DIG-Reasoner-URL setzen, falls nicht schon geschehen (kann wegen Exception - // nicht in Config gesetzt werden) -// if(Config.digReasonerURL == null) { -// try { -// Config.digReasonerURL = new URL("http://localhost:8081"); -// } catch (MalformedURLException e) { -// // Exception tritt nie auf, da URL korrekt -// e.printStackTrace(); -// } -// } - - // der parserinterne Namespace wird immer ausgeblendet - ; // Config.hidePrefixes.add(KBParser.internalNamespace); - - } - - // ueberprueft, ob es Konflikte zwischen derzeit gesetzten Konfigurationsoptionen gibt - public boolean checkConsistency() { - return true; - } - - // TODO: bei Fehlerbehandlungen müsste man jetzt noch berücksichtigen, dass - // Mengen als 4. Optionstyp (neben int, double, string) dazugekommen sind - public void applyConfigurationOption(ConfFileOption option) { - String optionString; - if(option.containsSubOption()) - optionString = option.getOption() + "." + option.getSubOption(); - else - optionString = option.getOption(); - - if(option.isNumeric()) { - - boolean isInIntOptions = intOptions.containsKey(optionString); - boolean isInDoubleOptions = doubleOptions.containsKey(optionString); - - // numerische Option existiert - if(isInIntOptions || isInDoubleOptions) { - - // es ist eine Option, die nur int-Werte haben darf - if(isInIntOptions) { - if(!option.isIntegerOption()) - throw new Error("The argument of configuration option \"" - + optionString + "\" has to be an integer."); - - // ueberpruefen, ob Wert innerhalb der vorgegebenen Schranken liegt - int minValue = intOptions.get(optionString)[0]; - int maxValue = intOptions.get(optionString)[1]; - if (option.getIntValue() < minValue || option.getIntValue() > maxValue) { - System.out.println("Error: The argument of configuration option \"" - + optionString + "\" is out of range. It has to be between " - + minValue + " and " + maxValue + "."); - System.exit(0); - } - - // alles OK, Option kann angewandt werden - applyIntOptions(optionString,option.getIntValue()); - // es ist eine Option, die int- oder double-Werte haben darf - } else { - // ueberpruefen, ob Wert innerhalb der vorgegebenen Schranken liegt - double minValue = doubleOptions.get(optionString)[0]; - double maxValue = doubleOptions.get(optionString)[1]; - - // Wert der Option bestimmen - double val; - if(option.isIntegerOption()) - val = option.getIntValue(); - else - val = option.getDoubleValue(); - - if (val < minValue || val > maxValue) { - System.out.println("Error: The argument of configuration option \"" - + optionString + "\" is out of range. It has to be between " - + minValue + " and " + maxValue + "."); - System.exit(0); - } - - // alles OK, Option kann angewandt werden - applyDoubleOptions(optionString,val); - } - - // numerische Option existiert nicht => Fehlerbehandlung - } else { - if(strOptions.containsKey(optionString)) - throw new RuntimeException("The argument of configuration option \"" - + optionString + "\" has to be a string."); - else - throw new RuntimeException("Configuration option \"" - + optionString + "\" does not exist."); - } - } else if (option.isSetOption()) { - if(setOptions.contains(optionString)) { - applySetOptions(optionString,option.getSetValues()); - } else { - throw new Error("Configuration option \"" - + optionString + "\" does not exist or its argument is not a list."); - } - - } else { - // Option existiert - if(strOptions.containsKey(optionString)) { - // ueberpruefen, ob Optionswert numerisch ist - if(option.isIntegerOption()) - throw new Error("The argument of configuration option \"" - + optionString + "\" has to be a string."); - - // moegliche Werte pruefen (wenn keine moeglichen Werte angegeben sind, dann sind - // alle Strings erlaubt) - String[] possibleValuesArray = strOptions.get(optionString); - List<String> possibleValues = Arrays.asList(possibleValuesArray); - if (!possibleValues.contains(option.getStringValue()) && possibleValues.size() != 0) { - System.out.println("Error: The configuration option \"" + optionString - + "\" must not have value \"" + option.getStringValue() - + "\". The value must be one of " + possibleValues + "."); - System.exit(0); - } - - // alles OK, Option kann angewandt werden - applyStringOptions(optionString,option.getStringValue()); - - // Option existiert nicht => Fehlerbehandlung - } else { - if(intOptions.containsKey(optionString)) - throw new Error("The argument of configuration option \"" - + optionString + "\" has to be a number."); - else - throw new Error("Configuration option \"" - + optionString + "\" does not exist."); - } - } - // options.add(option); - } - - // Code aus Main zur Behandlung von Optionen - /* - if (node instanceof ASTConfOption) { - // allgemeine Variablenzuweisungen, damit die Implementierung - // f�r jede einzelne Option dann einfach wird - String option = ((ASTId) node.jjtGetChild(0)).getId(); - String optionIndex = option; - // etwas vorsichtig sein, da Werte initialisiert werden, auch - // wenn es z.B. keinen Integer in der Option gibt - String subOption = ""; - boolean valueIsInt = false; - int intValue = 0; - String strValue = ""; - // zwei Optionen mit Punkt getrennt - if (node.jjtGetNumChildren() == 3) { - subOption = ((ASTId) node.jjtGetChild(1)).getId(); - optionIndex += "." + subOption; - if (node.jjtGetChild(2) instanceof ASTNumber) { - intValue = ((ASTNumber) node.jjtGetChild(2)).getId(); - valueIsInt = true; - } else - strValue = ((ASTId) node.jjtGetChild(2)).getId(); - // eine Option - } else { - if (node.jjtGetChild(1) instanceof ASTNumber) { - intValue = ((ASTNumber) node.jjtGetChild(1)).getId(); - valueIsInt = true; - } else - strValue = ((ASTId) node.jjtGetChild(1)).getId(); - } - - if (intOptions.containsKey(optionIndex)) { - if (!valueIsInt) { - System.out.println("Error: The argument of configuration option \"" - + optionIndex + "\" has to be a number."); - System.exit(0); - } - int minValue = intOptions.get(optionIndex)[0]; - int maxValue = intOptions.get(optionIndex)[1]; - if (intValue < minValue || intValue > maxValue) { - System.out.println("Error: The argument of configuration option \"" - + optionIndex + "\" is out of range. It has to be between " - + minValue + " and " + maxValue + "."); - System.exit(0); - } - - applyIntOptions(optionIndex, intValue); - - } else if (strOptions.containsKey(optionIndex)) { - if (valueIsInt) { - System.out.println("The argument of configuration option \"" + optionIndex - + "\" must not be a number."); - System.exit(0); - } - - String[] possibleValuesArray = strOptions.get(optionIndex); - List<String> possibleValues = Arrays.asList(possibleValuesArray); - if (!possibleValues.contains(strValue) && possibleValues.size() != 0) { - System.out.println("Error: The configuration option \"" + optionIndex - + "\" must not have value \"" + strValue - + "\". The value must be one of " + possibleValues + "."); - System.exit(0); - } - - applyStringOptions(optionIndex, strValue); - - } else { - System.out.println("Error: " + optionIndex - + " is not a valid configuration option"); - System.exit(0); - } - - } - - */ - - - - //private Map<String, Integer[]> createIntOptions() { - // Map<String, Integer[]> intOptions = new HashMap<String, Integer[]>(); - private void createIntOptions() { - - intOptions.put("maxLength", new Integer[] { 1, 20 }); - // intOptions.put("accuracyPenalty", new Integer[] { 1, 1000 }); - // intOptions.put("errorPenalty", new Integer[] { 1, 1000 }); - intOptions.put("gp.numberOfIndividuals", new Integer[] { 10, 1000000 }); - intOptions.put("gp.numberOfSelectedIndividuals", new Integer[] { 10, 1000000 }); - // intOptions.put("gp.crossoverPercent", new Integer[] { 0, 100 }); - // intOptions.put("gp.mutationPercent", new Integer[] { 0, 100 }); - // intOptions.put("gp.hillClimbingPercent", new Integer[] { 0, 100 }); - intOptions.put("gp.postConvergenceGenerations", new Integer[] { 10, 1000 }); - intOptions.put("gp.generations", new Integer[] { 10, 1000 }); - intOptions.put("gp.tournamentSize", new Integer[] { 1, 10 }); - intOptions.put("gp.initMinDepth", new Integer[] { 1, 10 }); - intOptions.put("gp.initMaxDepth", new Integer[] { 1, 20 }); - - // return intOptions; - } - - private void createDoubleOptions() { - - // double-Optionen, die auch int sein können - doubleOptions.put("accuracyPenalty", new Double[] { 1d, 1000d }); - doubleOptions.put("errorPenalty", new Double[] { 1d, 1000d }); - doubleOptions.put("gp.crossoverPercent", new Double[] { 0d, 100d }); - doubleOptions.put("gp.mutationPercent", new Double[] { 0d, 100d }); - doubleOptions.put("gp.hillClimbingPercent", new Double[] { 0d, 100d }); - doubleOptions.put("gp.refinementPercent", new Double[] { 0d, 100d }); - doubleOptions.put("refinement.horizontalExpansionFactor", new Double[] { 0d, 1d }); - doubleOptions.put("percentPerLengthUnit", new Double[] { 0d, 1d }); - - } - - //private Map<String, String[]> createStringOptions() { - // Map<String, String[]> strOptions = new HashMap<String, String[]>(); - private void createStringOptions() { - final String[] booleanArray = new String[] { "true", "false" }; - // leerer Array = keine Einschraenkung - - strOptions.put("penalizeNeutralExamples", booleanArray); - strOptions.put("scoreMethod", new String[] { "full", "positive" }); - strOptions.put("showCorrectClassifications", booleanArray); - // etwas eleganter waere hier, wenn man erst die Wissensbasis und dann - // die Optionen parst, dann koennte man implementieren, dass der Rueckgabetyp - // einem Konzeptname entsprechen muss - strOptions.put("returnType", new String[] {}); - strOptions.put("statMode", booleanArray); - strOptions.put("una", booleanArray); - strOptions.put("owa", booleanArray); - strOptions.put("algorithm", new String[] { "gp", "bruteForce", "random", "refinement", "hybridGP" }); - strOptions.put("reasoner", new String[] { "dig", "kaon2", "fastRetrieval" }); - strOptions.put("digReasonerURL", new String[] {}); - strOptions.put("useRetrievalForClassification", booleanArray); - strOptions.put("hidePrefix", new String[] {}); - strOptions.put("showIndividuals", booleanArray); - strOptions.put("showConcepts", booleanArray); - strOptions.put("showRoles", booleanArray); - strOptions.put("showInternalKB", booleanArray); - strOptions.put("showSubsumptionHierarchy", booleanArray); - strOptions.put("writeDIGProtocol", booleanArray); - strOptions.put("digProtocolFile", new String[] {}); - // strOptions.put("preprocessingModule", new String[] {}); - strOptions.put("gp.selectionType", new String[] { "rankSelection", "fps", "tournament" }); - strOptions.put("gp.elitism", booleanArray); - strOptions.put("gp.algorithmType", new String[] { "steadyState", "generational" }); - strOptions.put("gp.adc", booleanArray); - strOptions.put("gp.useFixedNumberOfGenerations", booleanArray); - strOptions.put("refinement.heuristic", new String[] { "lexicographic", "flexible" }); - strOptions.put("refinement.quiet", booleanArray); - strOptions.put("refinement.writeSearchTree", new String[] {}); - strOptions.put("refinement.searchTreeFile", new String[] {}); - strOptions.put("refinement.applyAllFilter", booleanArray); - strOptions.put("refinement.applyExistsFilter", booleanArray); - strOptions.put("refinement.useTooWeakList", booleanArray); - strOptions.put("refinement.useOverlyGeneralList", booleanArray); - strOptions.put("refinement.useShortConceptConstruction", booleanArray); - strOptions.put("refinement.useDIGMultiInstanceChecks", new String[] { "never", "twoChecks", "oneCheck"}); - strOptions.put("refinement.useAllConstructor", booleanArray); - strOptions.put("refinement.useExistsConstructor", booleanArray); - strOptions.put("refinement.useNegation", booleanArray); - } - - private void createSetOptions() { - setOptions.add("refinement.allowedConcepts"); - setOptions.add("refinement.allowedRoles"); - setOptions.add("refinement.ignoredConcepts"); - setOptions.add("refinement.ignoredRoles"); - } - - private void applyIntOptions(String option, int value) { - if (option.equals("maxLength")) - ;//Config.maxLength = value; -// else if (option.equals("gp.numberOfIndividuals")) -// Config.GP.numberOfIndividuals = value; -// else if (option.equals("gp.numberOfSelectedIndividuals")) -// Config.GP.numberOfSelectedIndividuals = value; -// else if (option.equals("gp.postConvergenceGenerations")) -// Config.GP.postConvergenceGenerations = value; -// else if (option.equals("gp.generations")) -// Config.GP.generations = value; -// else if (option.equals("gp.tournamentSize")) -// Config.GP.tournamentSize = value; -// else if (option.equals("gp.initMinDepth")) -// Config.GP.initMinDepth = value; -// else if (option.equals("gp.initMaxDepth")) -// Config.GP.initMaxDepth = value; - } - - private void applyDoubleOptions(String option, double value) { - // System.out.println(option + " " + value); - if (option.equals("accuracyPenalty")) - ; //Config.accuracyPenalty = value; - else if (option.equals("errorPenalty")) - ; //Config.errorPenalty = value; -// else if (option.equals("gp.crossoverPercent")) -// Config.GP.crossoverProbability = value / (double) 100; -// else if (option.equals("gp.mutationPercent")) -// Config.GP.mutationProbability = value / (double) 100; -// else if (option.equals("gp.hillClimbingPercent")) -// Config.GP.hillClimbingProbability = value / (double) 100; -// else if (option.equals("gp.refinementPercent")) -// Config.GP.refinementProbability = value / (double) 100; -// else if (option.equals("refinement.horizontalExpansionFactor")) -// Config.Refinement.horizontalExpansionFactor = value; - else if (option.equals("percentPerLengthUnit")) - ; // Config.percentPerLengthUnit = value; - } - - private void applyStringOptions(String option, String value) { - if (option.equals("penalizeNeutralExamples")) - ; // Config.penalizeNeutralExamples = Datastructures.strToBool(value); - else if (option.equals("showCorrectClassifications")) - ; // Config.showCorrectClassifications = Datastructures.strToBool(value); - else if (option.equals("statMode")) - ; // Config.statisticMode = Datastructures.strToBool(value); - else if (option.equals("una")) - ; // Config.una = Datastructures.strToBool(value); - else if (option.equals("owa")) - ; // Config.owa = Datastructures.strToBool(value); -// else if (option.equals("gp.useFixedNumberOfGenerations")) -// Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); -// else if (option.equals("scoreMethod")) { -// if (value.equals("full")) -// Config.scoreMethod = ScoreMethod.FULL; -// else -// Config.scoreMethod = ScoreMethod.POSITIVE; -// } else if (option.equals("returnType")) -// Config.returnType = value; -// else if (option.equals("algorithm")) { -// if (value.equals("gp")) -// Config.algorithm = Algorithm.GP; -// else if (value.equals("random")) -// Config.algorithm = Algorithm.RANDOM_GUESSER; -// else if(value.equals("bruteForce")) -// Config.algorithm = Algorithm.BRUTE_FORCE; -// else if(value.equals("refinement")) -// Config.algorithm = Algorithm.REFINEMENT; -// // hybrid GP = Menge von Konfigurationsoptionen -// else { -// Config.algorithm = Algorithm.HYBRID_GP; -// Config.GP.refinementProbability = 1.0d; -// Config.GP.crossoverProbability = 0.0d; -// Config.GP.hillClimbingProbability = 0.0d; -// Config.GP.mutationProbability = 0.0d; -// } - else if(option.equals("hidePrefix")) { -// Config.hidePrefixes.add(value); - } else if (option.equals("showIndividuals")) { -// Config.showIndividuals = Datastructures.strToBool(value); - } else if (option.equals("showConcepts")) { -// Config.showConcepts = Datastructures.strToBool(value); - } else if (option.equals("showRoles")) { -// Config.showRoles = Datastructures.strToBool(value); - } else if (option.equals("showInternalKB")) { -// Config.showInternalKB = Datastructures.strToBool(value); - } else if (option.equals("showSubsumptionHierarchy")) { -// Config.showSubsumptionHierarchy = Datastructures.strToBool(value); - } else if (option.equals("writeDIGProtocol")) { - // Config.writeDIGProtocol = Datastructures.strToBool(value); - } else if (option.equals("digProtocolFile")) { - // Config.digProtocolFile = new File(value); - // } else if (option.equals("preprocessingModule")) { -// // Config.preprocessingModule = value; -// } else if (option.equals("gp.selectionType")) { -// if (value.equals("fps")) -// Config.GP.selectionType = SelectionType.FPS; -// else if (value.equals("rankSelection")) -// Config.GP.selectionType = SelectionType.RANK_SELECTION; -// else -// Config.GP.selectionType = SelectionType.TOURNAMENT_SELECTION; -// } else if (option.equals("gp.algorithmType")) { -// if (value.equals("steadyState")) -// Config.GP.algorithmType = AlgorithmType.STEADY_STATE; -// else -// Config.GP.algorithmType = AlgorithmType.GENERATIONAL; -// } else if (option.equals("gp.adc")) { -//// Config.GP.adc = Datastructures.strToBool(value); - } else if (option.equals("refinement.heuristic")) { -// if(value.equals("lexicographic")) -// Config.Refinement.heuristic = Config.Refinement.Heuristic.LEXICOGRAPHIC; -// else -// Config.Refinement.heuristic = Config.Refinement.Heuristic.FLEXIBLE; - } else if (option.equals("refinement.quiet")) { -// Config.Refinement.quiet = Datastructures.strToBool(value); - } else if (option.equals("refinement.writeSearchTree")) - ; //Config.Refinement.writeSearchTree = Datastructures.strToBool(value); - else if (option.equals("refinement.searchTreeFile")) { - ; // Config.Refinement.searchTreeFile = new File(value); -// } else if (option.equals("refinement.applyAllFilter")) -// Config.Refinement.applyAllFilter = Datastructures.strToBool(value); - } else if (option.equals("refinement.applyExistsFilter")) { -// Config.Refinement.applyExistsFilter = Datastructures.strToBool(value); -// } else if (option.equals("refinement.useTooWeakList")) -// Config.Refinement.useTooWeakList = Datastructures.strToBool(value); -// else if (option.equals("refinement.useOverlyGeneralList")) -// Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); -// else if (option.equals("refinement.useShortConceptConstruction")) -// Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); -// } else if (option.equals("refinement.useAllConstructor")) -// Config.Refinement.useAllConstructor = Datastructures.strToBool(value); -// else if (option.equals("refinement.useExistsConstructor")) -// Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); -// else if (option.equals("refinement.useNegation")) -// Config.Refinement.useNegation = Datastructures.strToBool(value); -// else if (option.equals("reasoner")) { -// if(value.equals("dig")) -// Config.reasonerType = ReasonerType.DIG; -// else if(value.equals("kaon2")) -// Config.reasonerType = ReasonerType.KAON2; -// else if(value.equals("fastRetrieval")) -// Config.reasonerType = ReasonerType.FAST_RETRIEVAL; -// else if (option.equals("digReasonerURL")) { -// try { -// Config.digReasonerURL = new URL(value); -// } catch (MalformedURLException e) { -// e.printStackTrace(); -// System.err.println("Malformed URL for DIG reasoner was given."); -// System.exit(0); -// } - } -// } else if (option.equals("useRetrievalForClassification")) -// Config.useRetrievalForClassification = Datastructures.strToBool(value); -// else if (option.equals("refinement.useDIGMultiInstanceChecks")) { -// if(value.equals("never")) -// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.NEVER; -// else if(value.equals("twoChecks")) -// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.TWOCHECKS; -// else if(value.equals("oneCheck")) -// Config.Refinement.useDIGMultiInstanceChecks = Config.Refinement.UseDIGMultiInstanceChecks.ONECHECK; -// } - } - - private void applySetOptions(String optionString, Set<String> setValues) { - // System.out.println(":" + optionString + " " + setValues); - - if(optionString.equals("refinement.allowedConcepts")) { -// Config.Refinement.allowedConceptsAutoDetect = false; - ; // Config.Refinement.allowedConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); -// for(String s : setValues) - // es wird die gleiche Funktion wie im Parser genommen um Namen auf URIs zu mappen -// Config.Refinement.allowedConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); - } else if(optionString.equals("refinement.allowedRoles")) { -// Config.Refinement.allowedRolesAutoDetect = false; -// Config.Refinement.allowedRoles = new TreeSet<AtomicRole>(new RoleComparator()); -// for(String s : setValues) -// Config.Refinement.allowedRoles.add(new AtomicRole(KBParser.getInternalURI(s))); - } else if(optionString.equals("refinement.ignoredConcepts")) { -// Config.Refinement.ignoredConcepts = new TreeSet<AtomicConcept>(new ConceptComparator()); -// for(String s : setValues) -// Config.Refinement.ignoredConcepts.add(new AtomicConcept(KBParser.getInternalURI(s))); - } else if(optionString.equals("refinement.ignoredRoles")) { -// Config.Refinement.ignoredRoles = new TreeSet<AtomicRole>(new RoleComparator()); -// for(String s : setValues) -// Config.Refinement.ignoredRoles.add(new AtomicRole(KBParser.getInternalURI(s))); - } - } - - public void addDoubleOption(String option, Double[] range) { - doubleOptions.put(option, range); - } - - public Integer[] addIntegerOption(String option, Integer[] value) { - return intOptions.put(option, value); - } - - public boolean addSetOption(String option) { - return setOptions.add(option); - } - - public String[] addStringOption(String option, String[] value) { - return strOptions.put(option, value); - } - -} - Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 15:13:50 UTC (rev 282) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 15:19:23 UTC (rev 283) @@ -27,7 +27,6 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.ConfigurationManager; import org.dllearner.algorithms.gp.GP; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; @@ -145,8 +144,8 @@ ComponentManager cm = ComponentManager.getInstance(); // just set default options - ConfigurationManager confMgr = new ConfigurationManager(); - confMgr.applyOptions(); +// ConfigurationManager confMgr = new ConfigurationManager(); +// confMgr.applyOptions(); for(int exampleNr=startExampleNr; exampleNr < examples.length; exampleNr++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-12 15:13:54
|
Revision: 282 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=282&view=rev Author: jenslehmann Date: 2007-11-12 07:13:50 -0800 (Mon, 12 Nov 2007) Log Message: ----------- - adapted genetic programming algorithm to work with new DL-Learner core - all configuration options of GP are now thread safe (removed option useMultiStructures) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 15:13:50 UTC (rev 282) @@ -2,9 +2,6 @@ import java.lang.reflect.Field; -import org.dllearner.algorithms.gp.GP.AlgorithmType; -import org.dllearner.algorithms.gp.GP.SelectionType; - public class Config { // standardmäßig wird bis Tiefe 7 gesucht // public static int maxLength = 7; @@ -195,46 +192,46 @@ // FPS funktioniert momentan noch nicht, es muss sichergestellt werden, // dass die Fitness positiv ist (momentan ist sie nie gr��er 0) - public static SelectionType selectionType = SelectionType.RANK_SELECTION; - - public static int tournamentSize = 3; - - public static boolean elitism = true; - - public static AlgorithmType algorithmType = AlgorithmType.STEADY_STATE; - - public static double mutationProbability = 0.03d; - - public static double crossoverProbability = 0.95d; - - public static double hillClimbingProbability = 0.0d; - - public static double refinementProbability = 0.0; - - public static int numberOfIndividuals = 100; - - public static int numberOfSelectedIndividuals = 96; - - public static boolean useFixedNumberOfGenerations = false; - - public static int generations = 20; - - public static int postConvergenceGenerations = 50; - - public static boolean adc = false; - - public static int initMinDepth = 4; - - public static int initMaxDepth = 6; - - public static int maxConceptLength = 75; - - // bei true werden statt Disjunction MultiDisjunction und statt - // Conjunction - // MultiConjunction im GP benutzt (es gibt derzeit keinen Grund es auf - // false - // zu setzen) - public static boolean useMultiStructures = true; +// public static SelectionType selectionType = SelectionType.RANK_SELECTION; +// +// public static int tournamentSize = 3; +// +// public static boolean elitism = true; +// +// public static AlgorithmType algorithmType = AlgorithmType.STEADY_STATE; +// +// public static double mutationProbability = 0.03d; +// +// public static double crossoverProbability = 0.95d; +// +// public static double hillClimbingProbability = 0.0d; +// +// public static double refinementProbability = 0.0; +// +// public static int numberOfIndividuals = 100; +// +// public static int numberOfSelectedIndividuals = 96; +// +// public static boolean useFixedNumberOfGenerations = false; +// +// public static int generations = 20; +// +// public static int postConvergenceGenerations = 50; +// +// public static boolean adc = false; +// +// public static int initMinDepth = 4; +// +// public static int initMaxDepth = 6; +// +// public static int maxConceptLength = 75; +// +// // bei true werden statt Disjunction MultiDisjunction und statt +// // Conjunction +// // MultiConjunction im GP benutzt (es gibt derzeit keinen Grund es auf +// // false +// // zu setzen) +// public static boolean useMultiStructures = true; } Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 15:13:50 UTC (rev 282) @@ -8,10 +8,7 @@ import java.util.Map; import java.util.Set; -import org.dllearner.algorithms.gp.GP.AlgorithmType; -import org.dllearner.algorithms.gp.GP.SelectionType; import org.dllearner.cli.ConfFileOption; -import org.dllearner.utilities.Datastructures; /** * Nach dem einlesen der Datei werden hier alle Konfigurationsoptionen @@ -372,20 +369,20 @@ private void applyIntOptions(String option, int value) { if (option.equals("maxLength")) ;//Config.maxLength = value; - else if (option.equals("gp.numberOfIndividuals")) - Config.GP.numberOfIndividuals = value; - else if (option.equals("gp.numberOfSelectedIndividuals")) - Config.GP.numberOfSelectedIndividuals = value; - else if (option.equals("gp.postConvergenceGenerations")) - Config.GP.postConvergenceGenerations = value; - else if (option.equals("gp.generations")) - Config.GP.generations = value; - else if (option.equals("gp.tournamentSize")) - Config.GP.tournamentSize = value; - else if (option.equals("gp.initMinDepth")) - Config.GP.initMinDepth = value; - else if (option.equals("gp.initMaxDepth")) - Config.GP.initMaxDepth = value; +// else if (option.equals("gp.numberOfIndividuals")) +// Config.GP.numberOfIndividuals = value; +// else if (option.equals("gp.numberOfSelectedIndividuals")) +// Config.GP.numberOfSelectedIndividuals = value; +// else if (option.equals("gp.postConvergenceGenerations")) +// Config.GP.postConvergenceGenerations = value; +// else if (option.equals("gp.generations")) +// Config.GP.generations = value; +// else if (option.equals("gp.tournamentSize")) +// Config.GP.tournamentSize = value; +// else if (option.equals("gp.initMinDepth")) +// Config.GP.initMinDepth = value; +// else if (option.equals("gp.initMaxDepth")) +// Config.GP.initMaxDepth = value; } private void applyDoubleOptions(String option, double value) { @@ -394,14 +391,14 @@ ; //Config.accuracyPenalty = value; else if (option.equals("errorPenalty")) ; //Config.errorPenalty = value; - else if (option.equals("gp.crossoverPercent")) - Config.GP.crossoverProbability = value / (double) 100; - else if (option.equals("gp.mutationPercent")) - Config.GP.mutationProbability = value / (double) 100; - else if (option.equals("gp.hillClimbingPercent")) - Config.GP.hillClimbingProbability = value / (double) 100; - else if (option.equals("gp.refinementPercent")) - Config.GP.refinementProbability = value / (double) 100; +// else if (option.equals("gp.crossoverPercent")) +// Config.GP.crossoverProbability = value / (double) 100; +// else if (option.equals("gp.mutationPercent")) +// Config.GP.mutationProbability = value / (double) 100; +// else if (option.equals("gp.hillClimbingPercent")) +// Config.GP.hillClimbingProbability = value / (double) 100; +// else if (option.equals("gp.refinementPercent")) +// Config.GP.refinementProbability = value / (double) 100; // else if (option.equals("refinement.horizontalExpansionFactor")) // Config.Refinement.horizontalExpansionFactor = value; else if (option.equals("percentPerLengthUnit")) @@ -419,8 +416,8 @@ ; // Config.una = Datastructures.strToBool(value); else if (option.equals("owa")) ; // Config.owa = Datastructures.strToBool(value); - else if (option.equals("gp.useFixedNumberOfGenerations")) - Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); +// else if (option.equals("gp.useFixedNumberOfGenerations")) +// Config.GP.useFixedNumberOfGenerations = Datastructures.strToBool(value); // else if (option.equals("scoreMethod")) { // if (value.equals("full")) // Config.scoreMethod = ScoreMethod.FULL; @@ -462,21 +459,21 @@ } else if (option.equals("digProtocolFile")) { // Config.digProtocolFile = new File(value); // } else if (option.equals("preprocessingModule")) { - // Config.preprocessingModule = value; - } else if (option.equals("gp.selectionType")) { - if (value.equals("fps")) - Config.GP.selectionType = SelectionType.FPS; - else if (value.equals("rankSelection")) - Config.GP.selectionType = SelectionType.RANK_SELECTION; - else - Config.GP.selectionType = SelectionType.TOURNAMENT_SELECTION; - } else if (option.equals("gp.algorithmType")) { - if (value.equals("steadyState")) - Config.GP.algorithmType = AlgorithmType.STEADY_STATE; - else - Config.GP.algorithmType = AlgorithmType.GENERATIONAL; - } else if (option.equals("gp.adc")) { - Config.GP.adc = Datastructures.strToBool(value); +// // Config.preprocessingModule = value; +// } else if (option.equals("gp.selectionType")) { +// if (value.equals("fps")) +// Config.GP.selectionType = SelectionType.FPS; +// else if (value.equals("rankSelection")) +// Config.GP.selectionType = SelectionType.RANK_SELECTION; +// else +// Config.GP.selectionType = SelectionType.TOURNAMENT_SELECTION; +// } else if (option.equals("gp.algorithmType")) { +// if (value.equals("steadyState")) +// Config.GP.algorithmType = AlgorithmType.STEADY_STATE; +// else +// Config.GP.algorithmType = AlgorithmType.GENERATIONAL; +// } else if (option.equals("gp.adc")) { +//// Config.GP.adc = Datastructures.strToBool(value); } else if (option.equals("refinement.heuristic")) { // if(value.equals("lexicographic")) // Config.Refinement.heuristic = Config.Refinement.Heuristic.LEXICOGRAPHIC; Modified: trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/algorithms/RandomGuesser.java 2007-11-12 15:13:50 UTC (rev 282) @@ -91,7 +91,7 @@ for(int i=0; i<numberOfTrees; i++) { // p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth); - p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth); + p = GPUtilities.createGrowRandomProgram(learningProblem, maxDepth, false); if(p.getFitness()>bestFitness) { bestFitness = p.getFitness(); bestScore = p.getScore(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GP.java 2007-11-12 15:13:50 UTC (rev 282) @@ -20,22 +20,6 @@ package org.dllearner.algorithms.gp; -import static org.dllearner.Config.GP.algorithmType; -import static org.dllearner.Config.GP.crossoverProbability; -import static org.dllearner.Config.GP.elitism; -import static org.dllearner.Config.GP.generations; -import static org.dllearner.Config.GP.hillClimbingProbability; -import static org.dllearner.Config.GP.initMaxDepth; -import static org.dllearner.Config.GP.initMinDepth; -import static org.dllearner.Config.GP.mutationProbability; -import static org.dllearner.Config.GP.numberOfIndividuals; -import static org.dllearner.Config.GP.numberOfSelectedIndividuals; -import static org.dllearner.Config.GP.postConvergenceGenerations; -import static org.dllearner.Config.GP.refinementProbability; -import static org.dllearner.Config.GP.selectionType; -import static org.dllearner.Config.GP.tournamentSize; -import static org.dllearner.Config.GP.useFixedNumberOfGenerations; - import java.text.DecimalFormat; import java.util.Arrays; import java.util.Collection; @@ -45,10 +29,10 @@ import java.util.Set; import java.util.Map.Entry; -import org.dllearner.Config; import org.dllearner.algorithms.hybridgp.Psi; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; +import org.dllearner.core.ReasoningService; import org.dllearner.core.Score; import org.dllearner.core.config.BooleanConfigOption; import org.dllearner.core.config.ConfigEntry; @@ -70,7 +54,7 @@ * */ public class GP extends LearningAlgorithm { - + // NumberFormat f; DecimalFormat df = new DecimalFormat("0.00"); @@ -103,6 +87,26 @@ FPS, TOURNAMENT_SELECTION}; + // configuration options + private SelectionType selectionType = SelectionType.RANK_SELECTION; + private int tournamentSize = 3; + private boolean elitism = true; + private AlgorithmType algorithmType = AlgorithmType.STEADY_STATE; + private double mutationProbability = 0.03d; + private double crossoverProbability = 0.95d; + private double hillClimbingProbability = 0.0d; + private double refinementProbability = 0.0; + private int numberOfIndividuals = 100; + private int numberOfSelectedIndividuals = 96; + private boolean useFixedNumberOfGenerations = false; + private int generations = 20; + private int postConvergenceGenerations = 50; + private boolean adc = false; + private int initMinDepth = 4; + private int initMaxDepth = 6; + private int maxConceptLength = 75; +// private boolean useMultiStructures = true; + private Program[] individuals; private Program fittestIndividual; @@ -123,6 +127,8 @@ // private GeneticRefinementOperator psi; private Psi psi; + private ReasoningService rs; + /** * Creates an algorithm object. By default a steady state algorithm with * rank selection is used. This operates @@ -130,16 +136,17 @@ * 1.0 and a probability of mutation of 0.01. * */ - public GP(PosNegLP learningProblem) { + public GP(PosNegLP learningProblem, ReasoningService rs) { this.learningProblem = learningProblem; + this.rs = rs; } - - public static Collection<Class<? extends LearningProblem>> supportedLearningAlgorithms() { + + public static Collection<Class<? extends LearningProblem>> supportedLearningProblems() { Collection<Class<? extends LearningProblem>> problems = new LinkedList<Class<? extends LearningProblem>>(); problems.add(PosNegLP.class); return problems; - } - + } + public static Collection<ConfigOption<?>> createConfigOptions() { Collection<ConfigOption<?>> options = new LinkedList<ConfigOption<?>>(); StringConfigOption selectionType = new StringConfigOption("selectionType", "selection type", "rankSelection"); @@ -191,7 +198,7 @@ IntegerConfigOption max = new IntegerConfigOption("maxConceptLength", "maximum concept length (higher length means lowest possible fitness)", 75); max.setLowerLimit(1); options.add(max); - options.add(new BooleanConfigOption("useMultiStructures", "specifies whether to use e.g. (a AND b AND c) instead of ((A and b) and c) - there is no apparent reason to set this to false", true)); +// options.add(new BooleanConfigOption("useMultiStructures", "specifies whether to use e.g. (a AND b AND c) instead of ((A and b) and c) - there is no apparent reason to set this to false", true)); return options; } @@ -200,7 +207,53 @@ */ @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { - // String name = entry.getOptionName(); + String name = entry.getOptionName(); + if(name.equals("selectionType")) { + String value = (String) entry.getValue(); + if(value.equals("fps")) + selectionType = SelectionType.FPS; + else if(value.equals("tournament")) + selectionType = SelectionType.TOURNAMENT_SELECTION; + else + selectionType = SelectionType.RANK_SELECTION; + } else if(name.equals("tournamentSize")) { + tournamentSize = (Integer) entry.getValue(); + } else if(name.equals("elitism")) { + elitism = (Boolean) entry.getValue(); + } else if(name.equals("algorithmType")) { + String value = (String) entry.getValue(); + if(value.equals("generational")) + algorithmType = AlgorithmType.GENERATIONAL; + else + algorithmType = AlgorithmType.STEADY_STATE; + } else if(name.equals("mutationProbability")) { + mutationProbability = (Double) entry.getValue(); + } else if(name.equals("crossoverProbability")) { + crossoverProbability = (Double) entry.getValue(); + } else if(name.equals("refinementProbability")) { + refinementProbability = (Double) entry.getValue(); + } else if(name.equals("hillClimbingProbability")) { + hillClimbingProbability = (Double) entry.getValue(); + } else if(name.equals("numberOfIndividuals")) { + numberOfIndividuals = (Integer) entry.getValue(); + } else if(name.equals("numberOfSelectedIndividuals")) { + numberOfSelectedIndividuals = (Integer) entry.getValue(); + } else if(name.equals("useFixedNumberOfGenerations")) { + useFixedNumberOfGenerations = (Boolean) entry.getValue(); + } else if(name.equals("generations")) { + generations = (Integer) entry.getValue(); + } else if(name.equals("postConvergenceGenerations")) { + postConvergenceGenerations = (Integer) entry.getValue(); + } else if(name.equals("adc")) { + adc = (Boolean) entry.getValue(); + } else if(name.equals("initMinDepth")) { + initMinDepth = (Integer) entry.getValue(); + } else if(name.equals("initMaxDepth")) { + initMaxDepth = (Integer) entry.getValue(); + } else if(name.equals("maxConceptLength")) { + maxConceptLength = (Integer) entry.getValue(); + } + } /* (non-Javadoc) @@ -208,6 +261,8 @@ */ @Override public void init() { + rs.prepareSubsumptionHierarchy(); + rs.prepareRoleHierarchy(); } @Override @@ -449,8 +504,8 @@ // alle Individuen auf maximale Konzeptlänge überprüfen um mögliche // Speicherprobleme zu verhindern for(int i=0; i<numberOfIndividuals; i++) { - if(individuals[i].getTree().getLength()>Config.GP.maxConceptLength) { - System.out.println("Warning: GP produced concept longer then " + Config.GP.maxConceptLength + ". Replacing it with TOP."); + if(individuals[i].getTree().getLength()>maxConceptLength) { + System.out.println("Warning: GP produced concept longer then " + maxConceptLength + ". Replacing it with TOP."); individuals[i] = GPUtilities.createProgram(learningProblem, new Top()); } } @@ -470,7 +525,7 @@ boolean betterValueFoundInPsiCache = false; double bestValue = bestScore.getScore(); - if(Config.GP.refinementProbability > 0) { + if(refinementProbability > 0) { // das Problem ist hier, dass die gecachte Score nicht unbedingt // der echten Score entsprechen muss, d.h. hier muss die // Konzeptlänge mit einberechnet werden => deswegen werden @@ -554,9 +609,9 @@ // int depth = rand.nextInt(initMaxDepth-initMinDepth)+initMinDepth; if(grow) - individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem,depth); + individuals[i] = GPUtilities.createGrowRandomProgram(learningProblem,depth, adc); else - individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, depth); + individuals[i] = GPUtilities.createFullRandomProgram(learningProblem, depth, adc); } /* @@ -809,7 +864,7 @@ System.out.println("Psi application time percentage: " + df.format(psiTimePercent) + "%; " + df.format(psiWOReasoningTimePercent) + "% excluding reasoning"); } - if(Config.GP.adc) + if(adc) System.out.println("ADC: " + fittestIndividual.getAdc()); // TODO: hier muss noch eine Zusammenfassung rein, die sowohl f�r zweiwertiges als auch // dreiwertiges Lernproblem funktioniert Modified: trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/algorithms/gp/GPUtilities.java 2007-11-12 15:13:50 UTC (rev 282) @@ -7,7 +7,6 @@ import java.util.SortedSet; import java.util.TreeMap; -import org.dllearner.Config; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.Score; @@ -16,8 +15,6 @@ import org.dllearner.core.dl.AtomicRole; import org.dllearner.core.dl.Bottom; import org.dllearner.core.dl.Concept; -import org.dllearner.core.dl.Conjunction; -import org.dllearner.core.dl.Disjunction; import org.dllearner.core.dl.Exists; import org.dllearner.core.dl.FlatABox; import org.dllearner.core.dl.Individual; @@ -90,7 +87,7 @@ extendedHypothesis = hypothesis; Score score; - if(Config.GP.adc) + if(adc != null) // TODO: ADC-Support // score = learningProblem.computeScore(extendedHypothesis, adc); throw new RuntimeException("ADC not supported"); @@ -139,7 +136,7 @@ */ public static Program mutation(LearningProblem learningProblem, Program p) { mutation++; - if(Config.GP.adc) { + if(p.getAdc() != null) { // TODO: hier kann man noch mehr Feinabstimmung machen, d.h. // Mutation abh�ngig von Knotenanzahl if(Math.random()<0.5) { @@ -232,7 +229,7 @@ */ public static Program[] crossover(LearningProblem learningProblem, Program p1, Program p2) { crossover++; - if(Config.GP.adc) { + if(p1.getAdc() != null) { Concept[] pt; Program result[] = new Program[2]; @@ -318,7 +315,7 @@ // Knoten kopieren, damit er sich nicht ver�ndert (es wird sonst der // parent-Link ver�ndert) Concept treecloned = (Concept) p.getTree().clone(); - if(Config.GP.adc) + if(p.getAdc() != null) return createProgram(learningProblem,hillClimbing(learningProblem,treecloned,(ScoreThreeValued)p.getScore()),p.getAdc()); else return createProgram(learningProblem,hillClimbing(learningProblem,treecloned,(ScoreThreeValued)p.getScore())); @@ -424,20 +421,20 @@ // returnNode = new Disjunction(); // returnNode.addChild(new AtomicConcept(name)); // returnNode.addChild(node); - if(Config.GP.useMultiStructures) +// if(useMultiStructures) returnNode = new MultiDisjunction(new AtomicConcept(name),node); - else - returnNode = new Disjunction(new AtomicConcept(name),node); +// else +// returnNode = new Disjunction(new AtomicConcept(name),node); // wegen else if schlie�en sich die F�lle gegenseitig aus } else if(nr<sizeSum2) { name = bestNeighbours.get(2).get(nr-sizeSum1); // returnNode = new Conjunction(); // returnNode.addChild(new AtomicConcept(name)); // returnNode.addChild(node); - if(Config.GP.useMultiStructures) +// if(useMultiStructures) returnNode = new MultiConjunction(new AtomicConcept(name),node); - else - returnNode = new Conjunction(new AtomicConcept(name),node); +// else +// returnNode = new Conjunction(new AtomicConcept(name),node); } else if(nr<sizeSum3) { name = bestNeighbours.get(3).get(nr-sizeSum2); // returnNode = new Exists(new AtomicRole(name)); @@ -621,8 +618,8 @@ * @param depth Depth of the tree. * @return The created program. */ - public static Program createFullRandomProgram(LearningProblem learningProblem, int depth) { - if(Config.GP.adc) { + public static Program createFullRandomProgram(LearningProblem learningProblem, int depth, boolean adc) { + if(adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createFullRandomTree(learningProblem, depth, true), createFullRandomTree(learningProblem, depth, false)); @@ -644,15 +641,15 @@ if(nr == 0 || nr == 1) { Concept child2 = createFullRandomTree(learningProblem, depth-1, useADC); if(nr == 0) { - if(Config.GP.useMultiStructures) +// if(useMultiStructures) return new MultiDisjunction(child1,child2); - else - return new Disjunction(child1,child2); +// else +// return new Disjunction(child1,child2); } else { - if(Config.GP.useMultiStructures) +// if(useMultiStructures) return new MultiConjunction(child1, child2); - else - return new Conjunction(child1, child2); +// else +// return new Conjunction(child1, child2); } } else if(nr==2) { return new Negation(child1); @@ -682,8 +679,8 @@ * @param depth The maximum depth of the program tree. * @return The created program. */ - public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth) { - if(Config.GP.adc) { + public static Program createGrowRandomProgram(LearningProblem learningProblem, int depth, boolean adc) { + if(adc) { // erster Baum Hauptbaum, zweiter Baum ADC return createProgram(learningProblem, createGrowRandomTree(learningProblem,depth,true), createGrowRandomTree(learningProblem,depth,false)); @@ -773,15 +770,15 @@ else if(nr>=2 && nr < numberOfConcepts+2) return (AtomicConcept)learningProblem.getReasoningService().getAtomicConceptsList().get(nr-2).clone(); else if(nr==numberOfConcepts+2) { - if(Config.GP.useMultiStructures) +// if(useMultiStructures) return new MultiConjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); - else - return new Conjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); +// else +// return new Conjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); } else if(nr==numberOfConcepts+3) { - if(Config.GP.useMultiStructures) +// if(useMultiStructures) return new MultiDisjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); - else - return new Disjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); +// else +// return new Disjunction(createGrowRandomTree(learningProblem, depth-1, useADC),createGrowRandomTree(learningProblem, depth-1, useADC)); } else if(nr==numberOfConcepts+4) return new Negation(createGrowRandomTree(learningProblem, depth-1, useADC)); else if(nr>=numberOfConcepts+5 && nr<numberOfConcepts+5+numberOfRoles) Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-11-12 15:13:50 UTC (rev 282) @@ -165,6 +165,10 @@ Class<? extends LearningAlgorithm> laClass = null; if (algorithmOption == null || algorithmOption.getStringValue().equals("refinement")) laClass = ROLearner.class; + else if(algorithmOption.getStringValue().equals("gp")) + laClass = GP.class; + else + handleError("Unknown value in " + algorithmOption); la = cm.learningAlgorithm(laClass, lp, rs); configureComponent(cm, la, componentPrefixMapping, parser); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-11-12 15:13:50 UTC (rev 282) @@ -329,6 +329,10 @@ return getRoleHierarchy().getMostSpecialRoles(); } + public void prepareSubsumptionHierarchy() { + reasoner.prepareSubsumptionHierarchy(getAtomicConcepts()); + } + public void prepareSubsumptionHierarchy(Set<AtomicConcept> allowedConcepts) { reasoner.prepareSubsumptionHierarchy(allowedConcepts); } @@ -343,6 +347,10 @@ } } + public void prepareRoleHierarchy() { + prepareRoleHierarchy(getAtomicRoles()); + } + public void prepareRoleHierarchy(Set<AtomicRole> allowedRoles) { try { reasoner.prepareRoleHierarchy(allowedRoles); Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 14:26:03 UTC (rev 281) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 15:13:50 UTC (rev 282) @@ -27,7 +27,6 @@ import java.util.Map; import java.util.SortedSet; -import org.dllearner.Config; import org.dllearner.ConfigurationManager; import org.dllearner.algorithms.gp.GP; import org.dllearner.core.ComponentManager; @@ -222,17 +221,17 @@ // learningAlgorithm = cm.learningAlgorithm(ROLearner.class, learningProblem); } else if(algorithmNr==1) { // Config.algorithm = Algorithm.GP; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.selectionType = GP.SelectionType.RANK_SELECTION; - Config.GP.generations = 50; - Config.GP.useFixedNumberOfGenerations = true; - Config.GP.numberOfIndividuals = 201; +// Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; +//// Config.GP.selectionType = GP.SelectionType.RANK_SELECTION; +// Config.GP.generations = 50; +// Config.GP.useFixedNumberOfGenerations = true; +// Config.GP.numberOfIndividuals = 201; // if(exampleNr == 3 || exampleNr == 4) // Config.GP.numberOfIndividuals = 51; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; +// Config.GP.refinementProbability = 0; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.8; +// Config.GP.hillClimbingProbability = 0; // Config.percentPerLengthUnit = 0.005; // give GP a chance to find the long solution of the // uncle problem @@ -242,17 +241,17 @@ learningAlgorithm = cm.learningAlgorithm(GP.class, learningProblem, rs); } else if(algorithmNr==2) { // Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; - Config.GP.selectionType = GP.SelectionType.RANK_SELECTION; - Config.GP.generations = 50; - Config.GP.useFixedNumberOfGenerations = true; - Config.GP.numberOfIndividuals = 201; +// Config.GP.algorithmType = GP.AlgorithmType.GENERATIONAL; +// Config.GP.selectionType = GP.SelectionType.RANK_SELECTION; +// Config.GP.generations = 50; +// Config.GP.useFixedNumberOfGenerations = true; +// Config.GP.numberOfIndividuals = 201; //if(exampleNr == 3 || exampleNr == 4) // Config.GP.numberOfIndividuals = 51; - Config.GP.refinementProbability = 0.65; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.2; - Config.GP.hillClimbingProbability = 0; +// Config.GP.refinementProbability = 0.65; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.2; +// Config.GP.hillClimbingProbability = 0; // Config.percentPerLengthUnit = 0.005; // if(exampleNr == 3 || exampleNr==5 || exampleNr==6) // Config.percentPerLengthUnit = 0.002; @@ -438,36 +437,36 @@ if (j == 0) { // Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.85; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.05; - Config.GP.hillClimbingProbability = 0; +// Config.GP.numberOfIndividuals = i + 1; +// Config.GP.refinementProbability = 0.85; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.05; +// Config.GP.hillClimbingProbability = 0; } else if (j == 1) { // Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.4; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.4; - Config.GP.hillClimbingProbability = 0; +// Config.GP.numberOfIndividuals = i + 1; +// Config.GP.refinementProbability = 0.4; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.4; +// Config.GP.hillClimbingProbability = 0; } else if (j == 2) { // Config.algorithm = Algorithm.GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.8; - Config.GP.hillClimbingProbability = 0; +// Config.GP.numberOfIndividuals = i + 1; +// Config.GP.refinementProbability = 0; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.8; +// Config.GP.hillClimbingProbability = 0; } else if (j == 3) { // Config.algorithm = Algorithm.HYBRID_GP; - Config.GP.numberOfIndividuals = i + 1; - Config.GP.refinementProbability = 0.7; - Config.GP.mutationProbability = 0.02; - Config.GP.crossoverProbability = 0.1; - Config.GP.hillClimbingProbability = 0; +// Config.GP.numberOfIndividuals = i + 1; +// Config.GP.refinementProbability = 0.7; +// Config.GP.mutationProbability = 0.02; +// Config.GP.crossoverProbability = 0.1; +// Config.GP.hillClimbingProbability = 0; } algorithmStartTime = System.nanoTime(); - gp = new GP(learningProblem); +// gp = new GP(learningProblem); long algorithmTime = System.nanoTime() - algorithmStartTime; long algorithmTimeSeconds = algorithmTime / 1000000000; @@ -475,16 +474,16 @@ // freigibt ((DIGReasoner) reasoner).releaseKB(); - int conceptLength = gp.getBestSolution().getLength(); - Score bestScore = gp.getSolutionScore(); - int misClassifications = bestScore.getCoveredNegatives().size() - + bestScore.getNotCoveredPositives().size(); - double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); +// int conceptLength = gp.getBestSolution().getLength(); +// Score bestScore = gp.getSolutionScore(); +// int misClassifications = bestScore.getCoveredNegatives().size() +// + bestScore.getNotCoveredPositives().size(); +// double classificationRatePercent = 100 * ((nrOfExamples - misClassifications) / (double) nrOfExamples); +// +// statAr[j][0].addNumber(classificationRatePercent); +// statAr[j][1].addNumber(conceptLength); +// statAr[j][2].addNumber(algorithmTimeSeconds); - statAr[j][0].addNumber(classificationRatePercent); - statAr[j][1].addNumber(conceptLength); - statAr[j][2].addNumber(algorithmTimeSeconds); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-12 14:26:11
|
Revision: 281 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=281&view=rev Author: jenslehmann Date: 2007-11-12 06:26:03 -0800 (Mon, 12 Nov 2007) Log Message: ----------- - now all options for the refinement operator based learning algorithm are thread safe - fixed some warnings Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 14:26:03 UTC (rev 281) @@ -123,11 +123,11 @@ // public static boolean useShortConceptConstruction = true; - public static double horizontalExpansionFactor = 0.6; +// public static double horizontalExpansionFactor = 0.6; - public static boolean improveSubsumptionHierarchy = true; +// public static boolean improveSubsumptionHierarchy = true; - public static boolean quiet = false; +// public static boolean quiet = false; // public static boolean writeSearchTree = false; @@ -168,13 +168,13 @@ // max. Verschachtelungstiefe der Lösung // nicht implementiert - public static int maxDepth = 0; +// public static int maxDepth = 0; // Konstruktoren an- und abschalten // nicht implementiert - public static boolean useAllConstructor = true; - public static boolean useExistsConstructor = true; - public static boolean useNegation = true; +// public static boolean useAllConstructor = true; +// public static boolean useExistsConstructor = true; +// public static boolean useNegation = true; // public static boolean useDisjunction = true; // public static boolean useConjunction = true; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 14:26:03 UTC (rev 281) @@ -402,8 +402,8 @@ Config.GP.hillClimbingProbability = value / (double) 100; else if (option.equals("gp.refinementPercent")) Config.GP.refinementProbability = value / (double) 100; - else if (option.equals("refinement.horizontalExpansionFactor")) - Config.Refinement.horizontalExpansionFactor = value; +// else if (option.equals("refinement.horizontalExpansionFactor")) +// Config.Refinement.horizontalExpansionFactor = value; else if (option.equals("percentPerLengthUnit")) ; // Config.percentPerLengthUnit = value; } @@ -482,9 +482,9 @@ // Config.Refinement.heuristic = Config.Refinement.Heuristic.LEXICOGRAPHIC; // else // Config.Refinement.heuristic = Config.Refinement.Heuristic.FLEXIBLE; - } else if (option.equals("refinement.quiet")) - Config.Refinement.quiet = Datastructures.strToBool(value); - else if (option.equals("refinement.writeSearchTree")) + } else if (option.equals("refinement.quiet")) { +// Config.Refinement.quiet = Datastructures.strToBool(value); + } else if (option.equals("refinement.writeSearchTree")) ; //Config.Refinement.writeSearchTree = Datastructures.strToBool(value); else if (option.equals("refinement.searchTreeFile")) { ; // Config.Refinement.searchTreeFile = new File(value); @@ -498,12 +498,12 @@ // Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); // else if (option.equals("refinement.useShortConceptConstruction")) // Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); - } else if (option.equals("refinement.useAllConstructor")) - Config.Refinement.useAllConstructor = Datastructures.strToBool(value); - else if (option.equals("refinement.useExistsConstructor")) - Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); - else if (option.equals("refinement.useNegation")) - Config.Refinement.useNegation = Datastructures.strToBool(value); +// } else if (option.equals("refinement.useAllConstructor")) +// Config.Refinement.useAllConstructor = Datastructures.strToBool(value); +// else if (option.equals("refinement.useExistsConstructor")) +// Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); +// else if (option.equals("refinement.useNegation")) +// Config.Refinement.useNegation = Datastructures.strToBool(value); // else if (option.equals("reasoner")) { // if(value.equals("dig")) // Config.reasonerType = ReasonerType.DIG; @@ -511,7 +511,7 @@ // Config.reasonerType = ReasonerType.KAON2; // else if(value.equals("fastRetrieval")) // Config.reasonerType = ReasonerType.FAST_RETRIEVAL; - else if (option.equals("digReasonerURL")) { +// else if (option.equals("digReasonerURL")) { // try { // Config.digReasonerURL = new URL(value); // } catch (MalformedURLException e) { Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-11-12 14:26:03 UTC (rev 281) @@ -11,7 +11,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.Config; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; import org.dllearner.core.ReasoningService; @@ -58,8 +57,14 @@ private boolean applyExistsFilter = true; private boolean useTooWeakList = true; private boolean useOverlyGeneralList = true; - private boolean useShortConceptConstruction = true; + private boolean useShortConceptConstruction = true; + private double horizontalExpansionFactor = 0.6; + private boolean useAllConstructor = true; + private boolean useExistsConstructor = true; + private boolean useNegation = true; + private boolean quiet = false; + private boolean stop = false; private ReasoningService rs; @@ -229,6 +234,14 @@ useOverlyGeneralList = (Boolean) entry.getValue(); } else if(name.equals("useShortConceptConstruction")) { useShortConceptConstruction = (Boolean) entry.getValue(); + } else if(name.equals("horzontalExpansionFactor")) { + horizontalExpansionFactor = (Double) entry.getValue(); + } else if(name.equals("useAllConstructor")) { + useAllConstructor = (Boolean) entry.getValue(); + } else if(name.equals("useExistsConstructor")) { + useExistsConstructor = (Boolean) entry.getValue(); + } else if(name.equals("useNegation")) { + useNegation = (Boolean) entry.getValue(); } } @@ -255,7 +268,7 @@ } // this.learningProblem2 = learningProblem2; - operator = new RhoDown(rs, applyAllFilter, applyExistsFilter); + operator = new RhoDown(rs, applyAllFilter, applyExistsFilter, useAllConstructor, useExistsConstructor, useNegation); // candidate sets entsprechend der gewählten Heuristik initialisieren candidates = new TreeSet<Node>(nodeComparator); @@ -343,7 +356,7 @@ // proper refinements mehr gefunden werden, aber wie stelle man das fest? while(!solutionFound && !stop) { - if(!Config.Refinement.quiet) + if(!quiet) printStatistics(false); // besten Knoten nach Heuristik auswählen @@ -360,7 +373,7 @@ // minimum horizontal expansion berechnen if(bestNode.getHorizontalExpansion()>maximumHorizontalExpansion) maximumHorizontalExpansion = bestNode.getHorizontalExpansion(); - minimumHorizontalExpansion = (int) Math.floor(Config.Refinement.horizontalExpansionFactor*maximumHorizontalExpansion); + minimumHorizontalExpansion = (int) Math.floor(horizontalExpansionFactor*maximumHorizontalExpansion); // neu: es werden solange Knoten erweitert bis wirklich jeder Knoten die // notwendige minimum horizontal expansion hat @@ -443,7 +456,7 @@ // Anzahl Schleifendurchläufe loop++; - if(!Config.Refinement.quiet) + if(!quiet) System.out.println("--- loop " + loop + " finished ---"); } Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-11-12 14:26:03 UTC (rev 281) @@ -29,7 +29,6 @@ import java.util.SortedSet; import java.util.TreeSet; -import org.dllearner.Config; import org.dllearner.core.ReasoningService; import org.dllearner.core.dl.All; import org.dllearner.core.dl.AtomicConcept; @@ -90,13 +89,21 @@ private boolean applyAllFilter = true; private boolean applyExistsFilter = true; + private boolean useAllConstructor = true; + private boolean useExistsConstructor = true; + private boolean useNegation = true; // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter) { + public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, + boolean useExistsConstructor, boolean useNegation) { this.rs = reasoningService; this.applyAllFilter = applyAllFilter; this.applyExistsFilter = applyExistsFilter; + this.useAllConstructor = useAllConstructor; + this.useExistsConstructor = useExistsConstructor; + this.useNegation = useNegation; + // this.learningProblem = learningProblem; // rs = learningProblem.getReasoningService(); } @@ -517,7 +524,7 @@ if(topRefinementsLength<2 && maxLength>1) { // Konzepte der Länge 2 = Negation aller Konzepte, die über Bottom liegen - if(Config.Refinement.useNegation) { + if(useNegation) { Set<Concept> m2tmp = rs.getMoreGeneralConcepts(new Bottom()); Set<Concept> m2 = new TreeSet<Concept>(conceptComparator); for(Concept c : m2tmp) { @@ -529,7 +536,7 @@ if(topRefinementsLength<3 && maxLength>2) { // Konzepte der Länge 3: EXISTS r.TOP - if(Config.Refinement.useExistsConstructor) { + if(useExistsConstructor) { Set<Concept> m3 = new TreeSet<Concept>(conceptComparator); // previous operator: uses all roles // for(AtomicRole r : Config.Refinement.allowedRoles) { @@ -544,7 +551,7 @@ } if(maxLength>2) { - if(Config.Refinement.useAllConstructor) { + if(useAllConstructor) { // Konzepte, die mit ALL r starten // alle existierenden Konzepte durchgehen, die maximal 2 k�rzer als // die maximale L�nge sind Modified: trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/kb/SparqlOntologyCollector.java 2007-11-12 14:26:03 UTC (rev 281) @@ -33,9 +33,7 @@ import java.util.Iterator; import java.util.Vector; -import org.dllearner.utilities.Datastructures; - /** * This class collects the ontology from dbpedia, * everything is saved in hashsets, so the doublettes are taken care of @@ -157,7 +155,7 @@ String end="</uri></binding>"; String predtmp=""; String objtmp=""; - ArrayList<String> al=new ArrayList<String>(); + // ArrayList<String> al=new ArrayList<String>(); while(xml.indexOf(one)!=-1){ //get pred xml=xml.substring(xml.indexOf(one)+one.length()); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2007-11-12 14:26:03 UTC (rev 281) @@ -20,8 +20,6 @@ package org.dllearner.server; import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Random; Modified: trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 14:11:18 UTC (rev 280) +++ trunk/src/dl-learner/org/dllearner/utilities/PaperStatistics.java 2007-11-12 14:26:03 UTC (rev 281) @@ -215,8 +215,8 @@ if(algorithmNr==0) { // Config.algorithm = Algorithm.REFINEMENT; // Config.Refinement.heuristic = Config.Refinement.Heuristic.FLEXIBLE; - Config.Refinement.horizontalExpansionFactor = 0.6; - Config.Refinement.quiet = true; +// Config.Refinement.horizontalExpansionFactor = 0.6; +// Config.Refinement.quiet = true; // Config.percentPerLengthUnit = 0.05; // learningAlgorithm = new ROLearner(learningProblem); // learningAlgorithm = cm.learningAlgorithm(ROLearner.class, learningProblem); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-12 14:11:23
|
Revision: 280 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=280&view=rev Author: jenslehmann Date: 2007-11-12 06:11:18 -0800 (Mon, 12 Nov 2007) Log Message: ----------- made some more options thread safe Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/Config.java trunk/src/dl-learner/org/dllearner/ConfigurationManager.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java trunk/src/dl-learner/org/dllearner/cli/Start.java Modified: trunk/src/dl-learner/org/dllearner/Config.java =================================================================== --- trunk/src/dl-learner/org/dllearner/Config.java 2007-11-11 09:41:14 UTC (rev 279) +++ trunk/src/dl-learner/org/dllearner/Config.java 2007-11-12 14:11:18 UTC (rev 280) @@ -112,16 +112,16 @@ public static class Refinement { // Nutzung der Äquivalenz ALL R.C AND ALL R.D = ALL R.(C AND D) - public static boolean applyAllFilter = true; +// public static boolean applyAllFilter = true; // Nutzung der Äquivalenz EXISTS R.C OR EXISTS R.D = EXISTS R.(C OR D) - public static boolean applyExistsFilter = true; +// public static boolean applyExistsFilter = true; - public static boolean useTooWeakList = true; +// public static boolean useTooWeakList = true; - public static boolean useOverlyGeneralList = true; +// public static boolean useOverlyGeneralList = true; - public static boolean useShortConceptConstruction = true; +// public static boolean useShortConceptConstruction = true; public static double horizontalExpansionFactor = 0.6; Modified: trunk/src/dl-learner/org/dllearner/ConfigurationManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-11 09:41:14 UTC (rev 279) +++ trunk/src/dl-learner/org/dllearner/ConfigurationManager.java 2007-11-12 14:11:18 UTC (rev 280) @@ -488,17 +488,17 @@ ; //Config.Refinement.writeSearchTree = Datastructures.strToBool(value); else if (option.equals("refinement.searchTreeFile")) { ; // Config.Refinement.searchTreeFile = new File(value); - } else if (option.equals("refinement.applyAllFilter")) - Config.Refinement.applyAllFilter = Datastructures.strToBool(value); - else if (option.equals("refinement.applyExistsFilter")) - Config.Refinement.applyExistsFilter = Datastructures.strToBool(value); - else if (option.equals("refinement.useTooWeakList")) - Config.Refinement.useTooWeakList = Datastructures.strToBool(value); - else if (option.equals("refinement.useOverlyGeneralList")) - Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); - else if (option.equals("refinement.useShortConceptConstruction")) - Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); - else if (option.equals("refinement.useAllConstructor")) +// } else if (option.equals("refinement.applyAllFilter")) +// Config.Refinement.applyAllFilter = Datastructures.strToBool(value); + } else if (option.equals("refinement.applyExistsFilter")) { +// Config.Refinement.applyExistsFilter = Datastructures.strToBool(value); +// } else if (option.equals("refinement.useTooWeakList")) +// Config.Refinement.useTooWeakList = Datastructures.strToBool(value); +// else if (option.equals("refinement.useOverlyGeneralList")) +// Config.Refinement.useOverlyGeneralList = Datastructures.strToBool(value); +// else if (option.equals("refinement.useShortConceptConstruction")) +// Config.Refinement.useShortConceptConstruction = Datastructures.strToBool(value); + } else if (option.equals("refinement.useAllConstructor")) Config.Refinement.useAllConstructor = Datastructures.strToBool(value); else if (option.equals("refinement.useExistsConstructor")) Config.Refinement.useExistsConstructor = Datastructures.strToBool(value); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-11-11 09:41:14 UTC (rev 279) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/ROLearner.java 2007-11-12 14:11:18 UTC (rev 280) @@ -54,6 +54,11 @@ // these are computed as the result of the previous four settings Set<AtomicConcept> usedConcepts; Set<AtomicRole> usedRoles; + private boolean applyAllFilter = true; + private boolean applyExistsFilter = true; + private boolean useTooWeakList = true; + private boolean useOverlyGeneralList = true; + private boolean useShortConceptConstruction = true; private boolean stop = false; @@ -214,6 +219,16 @@ ignoredConcepts = CommonConfigMappings.getAtomicConceptSet((Set<String>)entry.getValue()); } else if(name.equals("ignoredRoles")) { ignoredRoles = CommonConfigMappings.getAtomicRoleSet((Set<String>)entry.getValue()); + } else if(name.equals("applyAllFilter")) { + applyAllFilter = (Boolean) entry.getValue(); + } else if(name.equals("applyExistsFilter")) { + applyExistsFilter = (Boolean) entry.getValue(); + } else if(name.equals("useTooWeakList")) { + useTooWeakList = (Boolean) entry.getValue(); + } else if(name.equals("useOverlyGeneralList")) { + useOverlyGeneralList = (Boolean) entry.getValue(); + } else if(name.equals("useShortConceptConstruction")) { + useShortConceptConstruction = (Boolean) entry.getValue(); } } @@ -240,7 +255,7 @@ } // this.learningProblem2 = learningProblem2; - operator = new RhoDown(rs); + operator = new RhoDown(rs, applyAllFilter, applyExistsFilter); // candidate sets entsprechend der gewählten Heuristik initialisieren candidates = new TreeSet<Node>(nodeComparator); @@ -574,7 +589,7 @@ boolean propernessDetected = false; // 1. short concept construction - if(Config.Refinement.useShortConceptConstruction) { + if(useShortConceptConstruction) { // kurzes Konzept konstruieren Concept shortConcept = ConceptTransformation.getShortConcept(refinement, conceptComparator); int n = conceptComparator.compare(shortConcept, concept); @@ -587,7 +602,7 @@ } // 2. too weak test - if(!propernessDetected && Config.Refinement.useTooWeakList) { + if(!propernessDetected && useTooWeakList) { if(refinement instanceof MultiConjunction) { boolean tooWeakElement = containsTooWeakElement((MultiConjunction)refinement); if(tooWeakElement) { @@ -695,7 +710,7 @@ int quality = -2; // overly general list verwenden - if(Config.Refinement.useOverlyGeneralList && refinement instanceof MultiDisjunction) { + if(useOverlyGeneralList && refinement instanceof MultiDisjunction) { if(containsOverlyGeneralElement((MultiDisjunction)refinement)) { conceptTestsOverlyGeneralList++; quality = getNumberOfNegatives(); Modified: trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java =================================================================== --- trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-11-11 09:41:14 UTC (rev 279) +++ trunk/src/dl-learner/org/dllearner/algorithms/refinement/RhoDown.java 2007-11-12 14:11:18 UTC (rev 280) @@ -88,10 +88,15 @@ public long mComputationTimeNs = 0; public long topComputationTimeNs = 0; + private boolean applyAllFilter = true; + private boolean applyExistsFilter = true; + // braucht man wirklich das learningProblem oder reicht der Reasoning-Service? // TODO: conceptComparator könnte auch noch Parameter sein - public RhoDown(ReasoningService reasoningService) { + public RhoDown(ReasoningService reasoningService, boolean applyAllFilter, boolean applyExistsFilter) { this.rs = reasoningService; + this.applyAllFilter = applyAllFilter; + this.applyExistsFilter = applyExistsFilter; // this.learningProblem = learningProblem; // rs = learningProblem.getReasoningService(); } @@ -318,7 +323,7 @@ // falls Refinement von der Form ALL r ist, dann prüfen, ob // ALL r nicht bereits vorkommt - if(Config.Refinement.applyAllFilter) { + if(applyAllFilter) { if(c instanceof All) { for(Concept child : concept.getChildren()) { if(child instanceof All) { @@ -444,7 +449,7 @@ ConceptTransformation.transformToOrderedNegationNormalForm(concept, conceptComparator); } - if(Config.Refinement.applyExistsFilter) { + if(applyExistsFilter) { Iterator<MultiDisjunction> it = baseSet.iterator(); while(it.hasNext()) { MultiDisjunction md = it.next(); Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-11-11 09:41:14 UTC (rev 279) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2007-11-12 14:11:18 UTC (rev 280) @@ -120,6 +120,7 @@ sources.add(ks); configureComponent(cm, ks, componentPrefixMapping, parser); + initComponent(cm, ks); } // step 2: detect used reasoner @@ -134,6 +135,7 @@ } ReasonerComponent reasoner = cm.reasoner(reasonerClass, sources); configureComponent(cm, reasoner, componentPrefixMapping, parser); + initComponent(cm, reasoner); ReasoningService rs = cm.reasoningService(reasoner); // step 3: detect learning problem @@ -155,7 +157,8 @@ cm.applyConfigEntry(lp, "positiveExamples", posExamples); if(lpClass != PosOnlyDefinitionLP.class) cm.applyConfigEntry(lp, "negativeExamples", negExamples); - + initComponent(cm, lp); + // step 4: detect learning algorithm ConfFileOption algorithmOption = parser.getConfOptionsByName("algorithm"); LearningAlgorithm la = null; @@ -165,13 +168,14 @@ la = cm.learningAlgorithm(laClass, lp, rs); configureComponent(cm, la, componentPrefixMapping, parser); - + initComponent(cm, la); + // initialise all structures - for (KnowledgeSource source : sources) - initComponent(cm, source); - initComponent(cm, reasoner); - initComponent(cm, lp); - initComponent(cm, la); +// for (KnowledgeSource source : sources) +// initComponent(cm, source); +// initComponent(cm, reasoner); +// initComponent(cm, lp); +// initComponent(cm, la); // perform file exports performExports(parser, baseDir, sources, rs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-11 09:41:15
|
Revision: 279 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=279&view=rev Author: jenslehmann Date: 2007-11-11 01:41:14 -0800 (Sun, 11 Nov 2007) Log Message: ----------- added some getters to component manager such that you can now query available components (in general and by type) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java Modified: trunk/src/dl-learner/org/dllearner/core/ComponentManager.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-11-11 09:19:18 UTC (rev 278) +++ trunk/src/dl-learner/org/dllearner/core/ComponentManager.java 2007-11-11 09:41:14 UTC (rev 279) @@ -483,6 +483,41 @@ return componentNames.get(component); } + /** + * @return the components + */ + public static Set<Class<? extends Component>> getComponents() { + return components; + } + /** + * @return the knowledgeSources + */ + public static Set<Class<? extends KnowledgeSource>> getKnowledgeSources() { + return knowledgeSources; + } + /** + * @return the reasonerComponents + */ + public static Set<Class<? extends ReasonerComponent>> getReasonerComponents() { + return reasonerComponents; + } + + /** + * @return the learningProblems + */ + public static Set<Class<? extends LearningProblem>> getLearningProblems() { + return learningProblems; + } + + /** + * @return the learningAlgorithms + */ + public static Set<Class<? extends LearningAlgorithm>> getLearningAlgorithms() { + return learningAlgorithms; + } + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2007-11-11 09:19:21
|
Revision: 278 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=278&view=rev Author: jenslehmann Date: 2007-11-11 01:19:18 -0800 (Sun, 11 Nov 2007) Log Message: ----------- small fixes in component tester and reasoning service Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java trunk/src/dl-learner/org/dllearner/core/ReasoningService.java Modified: trunk/src/dl-learner/org/dllearner/core/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-11-05 13:07:09 UTC (rev 277) +++ trunk/src/dl-learner/org/dllearner/core/ComponentTest.java 2007-11-11 09:19:18 UTC (rev 278) @@ -44,8 +44,6 @@ // get singleton instance of component manager ComponentManager cm = ComponentManager.getInstance(); - cm.writeConfigDocumentation(new File("doc/configOptionsNew.txt")); - // create knowledge source KnowledgeSource source = cm.knowledgeSource(OWLFile.class); String example = "examples/father.owl"; @@ -55,8 +53,8 @@ // create DIG reasoning service with standard settings ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); // ReasoningService rs = cm.reasoningService(DIGReasonerNew.class, source); - ReasoningService rs = cm.reasoningService(reasoner); reasoner.init(); + ReasoningService rs = cm.reasoningService(reasoner); // create a learning problem and set positive and negative examples LearningProblem lp = cm.learningProblem(PosNegDefinitionLP.class, rs); Modified: trunk/src/dl-learner/org/dllearner/core/ReasoningService.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-11-05 13:07:09 UTC (rev 277) +++ trunk/src/dl-learner/org/dllearner/core/ReasoningService.java 2007-11-11 09:19:18 UTC (rev 278) @@ -21,6 +21,7 @@ package org.dllearner.core; import java.io.File; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -84,32 +85,19 @@ // private Map<Concept,Set<Concept>> moreSpecialConcepts = new HashMap<Concept,Set<Concept>>(); private Reasoner reasoner; - - // Beachte: wenn Wissensbasis modifiziert wird, muss ein neues - // Reasoner-Objekt - // angelegt werden (da Wissensbasis sofort entsprechend verwendetem - // Reasoning-Typ - // umgewandelt wird) - public ReasoningService(Reasoner reasoner) { - this.reasoner = reasoner; - - resetStatistics(); - } + // note that you must not modify the underlying knowledge base of + // a reasoning service (if you do, you have to create a new reasoning + // service object) public ReasoningService(ReasonerComponent reasoner) { this.reasoner = reasoner; - } - - /* - public void init() { - // temporary ugly hack to keep old version working - ((ReasonerComponent)reasoner).init(); - - // Listenansicht + + // list view atomicConceptsList = new LinkedList<AtomicConcept>(getAtomicConcepts()); - atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); + atomicRolesList = new LinkedList<AtomicRole>(getAtomicRoles()); + + resetStatistics(); } - */ // zurücksetzen aller Statistiken (wenn z.B. vorher ein Satisfiability Check gemacht wird, // der allerdings nicht zum eigentlichen Algorithmus gehört) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |