From: <seb...@us...> - 2012-03-07 14:50:39
|
Revision: 3605 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3605&view=rev Author: sebastianwtr Date: 2012-03-07 14:50:29 +0000 (Wed, 07 Mar 2012) Log Message: ----------- [tbsl_exploration] first step reorganizing the project Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlFilter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/utils_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Parsing.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/test_vergleich.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/sax/ Copied: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java (from rev 3595, trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/utils_new.java) =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -0,0 +1,56 @@ +package org.dllearner.algorithm.tbsl.exploration.Index; + +import java.sql.SQLException; +import java.util.ArrayList; + + +public class Index_utils { + + /** + * + * @param string + * @param fall 1=Property, 0=Resource, 2=OntologyClass/Yago, 2=resource+yago+ontlogy + * @return ArrayList with possible URIs gotten from the Index + * @throws SQLException + */ + public static ArrayList<String> searchIndex(String string, int fall, SQLiteIndex myindex) throws SQLException{ + + String originalString=string; + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String result=null; + String tmp1=null; + String tmp2 = null; + ArrayList<String> result_List = new ArrayList<String>(); + + if(fall==0 || fall==3){ + + result=myindex.getResourceURI(string.toLowerCase()); + result_List.add(result); + + } + if(fall==2||fall==3){ + + tmp1=myindex.getontologyClassURI(string.toLowerCase()); + tmp2=myindex.getYagoURI(string.toLowerCase()); + if(tmp1!=null) result_List.add(tmp1); + if(tmp2!=null) result_List.add(tmp2); + //result_List.add("www.TEST.de"); + } + + + if(fall==1){ + tmp1=myindex.getPropertyURI(string.toLowerCase()); + tmp2=myindex.getontologyURI(string.toLowerCase()); + if(tmp1!=null) result_List.add(tmp1); + if(tmp2!=null) result_List.add(tmp2); + + } + + return result_List; + } + + + +} Copied: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java (from rev 3594, trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java) =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -0,0 +1,594 @@ +package org.dllearner.algorithm.tbsl.exploration.Index; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; + +public class SQLiteIndex { + private Connection conn; + StanfordLemmatizer lemma; + + public SQLiteIndex() throws ClassNotFoundException, SQLException { + // TODO Auto-generated constructor stub + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:"); + createIndexPropertys(); + createIndexResource(); + createWordnetHelp(); + createIndexOntology(); + createIndexOntologyClass(); + createIndexofYago(); + lemma = new StanfordLemmatizer(); + + //optional!! + //createIndexWikipedia(); + + } + + /* + * Next, we want to select the persons living in a city that contains the pattern "tav" from the "Persons" table. + +We use the following SELECT statement: +SELECT * FROM Persons +WHERE City LIKE '%tav%' + */ + + public String getResourceURI(String string) throws SQLException{ + /* while(rs.next()) + {*/ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from resource where name='"+string.toLowerCase()+"';"); + /*while(rs.next()){ + System.out.println("Next: "+rs.getString("uri")); + }*/ + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + } + + public ArrayList<String> getResourceURILike(String string) throws SQLException{ + /* while(rs.next()) + {*/ + Statement stat = conn.createStatement(); + ResultSet rs; + ArrayList<String> result= new ArrayList<String>(); + try { + rs = stat.executeQuery("select uri from resource where name like'"+string.toLowerCase()+"%';"); + while(rs.next()){ + System.out.println("Next: "+rs.getString("uri")); + result.add(rs.getString("uri")); + } + return result; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + } + + public ArrayList<String> getYagoURILike(String string) throws SQLException{ + /* while(rs.next()) + {*/ + Statement stat = conn.createStatement(); + ResultSet rs; + ArrayList<String> result= new ArrayList<String>(); + try { + rs = stat.executeQuery("select uri from yago where name like'"+string.toLowerCase()+"%';"); + while(rs.next()){ + System.out.println("Next: "+rs.getString("uri")); + result.add(rs.getString("uri")); + } + return result; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + } + + + public String getYagoURI(String string) throws SQLException{ + /* while(rs.next()) + {*/ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from yago where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + } + + + public String getPropertyURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + public String getontologyURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + public String getontologyClassURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from ontologyClass where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + public ArrayList<String> getontologyClassURILike(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + ArrayList<String> result= new ArrayList<String>(); + try { + rs = stat.executeQuery("select uri from ontologyClass where name like'"+string.toLowerCase()+"%';"); + while(rs.next()){ + System.out.println("Next: "+rs.getString("uri")); + result.add(rs.getString("uri")); + } + return result; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + + + public String getWikipediaURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from wikiindex where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + public String getWordnetHelp(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select singular from wordnet where plural='"+string.toLowerCase()+"';"); + return rs.getString("singular"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + private void createWordnetHelp() throws SQLException{ /*System.out.println("Start SQL test"); + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ + System.out.println("start generating Wordnet Help-Function"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists wordnet;"); + stat.executeUpdate("create table wordnet (plural, singular);"); + PreparedStatement prep = conn.prepareStatement("insert into wordnet values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/noun.exc" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(" "); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + String temp=""; + if(tmp_array.length>2){ + for(int i =1;i<tmp_array.length;i++){ + temp=temp+tmp_array[i]+" "; + } + prep.setString(2, temp); + } + prep.addBatch(); + zaehler=zaehler+1; + //if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%10000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + + } + + private void createIndexWikipedia() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test"); + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists wikiindex;"); + stat.executeUpdate("create table wikiindex (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into wikiindex values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/URIsFromWikipedia" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split("::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + //if(zaehler%100000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + } +private void createIndexPropertys() throws ClassNotFoundException, SQLException{ + System.out.println("start indexing Properties"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists property;"); + stat.executeUpdate("create table property (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into property values (?, ?);"); + BufferedReader in=null; + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/property" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + // System.out.println(zaehler+" done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of Property: "+zaehler); + System.out.println("Done"); + + } +private void createIndexResource() throws ClassNotFoundException, SQLException{ + System.out.println("start indexing Resources"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists resource;"); + stat.executeUpdate("create table resource (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into resource values (?, ?);"); + BufferedReader in=null; + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/resource" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of Resources: "+zaehler); + System.out.println("Done"); + + + + } +private void createIndexOntology() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing Ontology"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists ontology;"); + stat.executeUpdate("create table ontology (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into ontology values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/ontology" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + //System.out.println("done" + zaehler); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of Ontologys: "+zaehler); + System.out.println("Done"); + + } + +private void createIndexOntologyClass() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing ontologyClass"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists ontologyClass;"); + stat.executeUpdate("create table ontologyClass (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into ontologyClass values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/ontologyClass" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + //System.out.println("done" + zaehler); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of OntologyClass: "+zaehler); + System.out.println("Done"); + + } + + +private void createIndexofYago() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing yago"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists yago;"); + stat.executeUpdate("create table yago (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into yago values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/yago" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + //System.out.println("done" + zaehler); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of Yago: "+zaehler); + System.out.println("Done"); + + } + + + +} \ No newline at end of file Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -0,0 +1,49 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.util.HashMap; + +/** + * + * @author swalter + * + */ +public class ElementList_new { + + /** + * Name of the variable, e.g. ?y0 + */ + private String variablename; + + /** + * URI of the Resource or Class, which was used for getting the depending elements with the uri + */ + private String resourceURI; + /** + * HashMap with name -uri pairs. + */ + private HashMap<String,String> hm = new HashMap<String,String>(); + public String getVariablename() { + return variablename; + } + public void setVariablename(String variablename) { + this.variablename = variablename; + } + public HashMap<String,String> getHm() { + return hm; + } + public void setHm(HashMap<String,String> hm) { + this.hm = hm; + } + public String getResourceURI() { + return resourceURI; + } + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + + public ElementList_new(String variable, String resource, HashMap<String,String> hm){ + this.setHm(hm); + this.setResourceURI(resource); + this.setVariablename(variable); + } +} Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -1,214 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.dllearner.algorithm.tbsl.exploration.sax.MySaxParser; - -public class GetRessourcePropertys { - - //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - String Prefix="http://dbpedia.org/sparql"; - //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; - //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - - public HashMap<String,String> getPropertys(String element, String side, int timeToTimeoutOnServer) throws IOException{ - - return sendServerPropertyRequest(element,side, timeToTimeoutOnServer); - - - - } - - /** - * Get an uri and saves the properties of this resource - * @param vergleich - * @return - * @throws IOException - */ - private HashMap<String,String> sendServerPropertyRequest(String vergleich, String side, int timeToTimeoutOnServer) throws IOException{ - - //System.out.println("Resource die gesucht wird: "+ vergleich); - //System.out.println("Seite die gesucht wird: "+side); - /* - * - * For the second Iteration, I can just add the sparql property here. - */ - - /* - * - * SELECT DISTINCT ?p WHERE {<http://dbpedia.org/resource/Berlin> ?y ?p.} für Berlin links der Property - * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<http://dbpedia.org/resource/Berlin> ?p ?y. ?p rdfs:label ?s.} - * - * SELECT DISTINCT ?p WHERE {?y ?p <http://dbpedia.org/resource/Berlin>.} für Berlin rechts der Property - * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <http://dbpedia.org/resource/Berlin>. ?p rdfs:label ?s.} - * http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=PREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E+SELECT+DISTINCT+%3Fs+%3Fp+WHERE+{%3Fy+%3Fp+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FBerlin%3E.+%3Fp+rdfs%3Alabel+%3Fs.}&format=text%2Fhtml&debug=on&timeout= - */ - - String vergleichorig = vergleich; - - /* - * change to dbpedia http://dbpedia.org/sparql - */ - //String tmp_left="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_left=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - - //System.out.println("property right!!! : " +tmp_right); - String tmp_right=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - - String tmp_both=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.} UNION {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String verarbeitungsurl=null; - /*Original*/ - if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; - if(side.contains("LEFT")) verarbeitungsurl=tmp_left; - - /*if(side.contains("LEFT")) verarbeitungsurl=tmp_both; - if(side.contains("RIGHT")) verarbeitungsurl=tmp_both;*/ - - //System.out.println(verarbeitungsurl); - //just in case..... - if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; - - String result=""; - HttpURLConnection connection = null; - BufferedReader rd = null; - StringBuilder sb = null; - String line = null; - - URL serverAddress = null; - - try { - serverAddress = new URL(verarbeitungsurl); - //set up out communications stuff - connection = null; - - //Set up the initial connection - connection = (HttpURLConnection)serverAddress.openConnection(); - connection.setRequestMethod("GET"); - connection.setDoOutput(true); - connection.setReadTimeout(timeToTimeoutOnServer); - - connection.connect(); - rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); - sb = new StringBuilder(); - - while ((line = rd.readLine()) != null) - { - sb.append(line + '\n'); - } - - //System.out.println(sb.toString()); - result=sb.toString(); - - } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); - } catch (IOException e) { - System.out.println("Can not connect or timeout"); - } - finally - { - //close the connection, set all objects to null - connection.disconnect(); - rd = null; - sb = null; - Object wr = null; - connection = null; - } - - HashMap<String,String> hm = new HashMap(); - result=result.replace("<th>s</th>",""); - result=result.replace("<th>p</th>",""); - result=result.replace("<table class=\"sparql\" border=\"1\">",""); - result=result.replace("<tr>",""); - result=result.replace("</tr>",""); - result=result.replace("\n", ""); - result=result.replace(" ", ""); - result=result.replaceFirst("<td>", ""); - - - String[] tmp_array=result.split("</td><td>"); - - for(int i =1; i<=tmp_array.length-2;i=i+2) { - hm.put(tmp_array[i-1].toLowerCase(), tmp_array[i]); - //System.out.println(tmp_array[i-1].toLowerCase() + " " +tmp_array[i]); - } - - // System.out.println("created Properties: "+hm); - return hm; - } - - - private static ArrayList<String> do_parsing(String datei) - { - ArrayList<String> indexObject = null; - - File file = new File(datei); - try - { - MySaxParser parser = new MySaxParser(file); - parser.parse(); - indexObject = parser.getIndexObject(); - } - catch (Exception ex) - { - System.out.println("Another exciting error occured: " + ex.getLocalizedMessage()); - } - - return indexObject; - } - - - - - private String createServerRequest(String query){ - String anfrage=null; - anfrage=removeSpecialKeys(query); - anfrage=anfrage.replace("<","<"); - anfrage=anfrage.replace("%gt;",">"); - anfrage=anfrage.replace("&","&"); - //anfrage=anfrage.replaceAll("#>","%23%3E%0D%0A%"); - anfrage=anfrage.replace("#","%23"); - anfrage=anfrage.replace(" ","+"); - anfrage=anfrage.replace("/","%2F"); - anfrage=anfrage.replace(":","%3A"); - anfrage=anfrage.replace("?","%3F"); - anfrage=anfrage.replace("$","%24"); - //anfrage=anfrage.replaceAll("F>+","F%3E%0D%0A"); - anfrage=anfrage.replace(">","%3E"); - anfrage=anfrage.replace("<","%3C"); - anfrage=anfrage.replace("\"","%22"); - anfrage=anfrage.replace("\n","%0D%0A%09"); - anfrage=anfrage.replace("%%0D%0A%09","%09"); - anfrage=anfrage.replace("=","%3D"); - anfrage=anfrage.replace("@","%40"); - anfrage=anfrage.replace("&","%26"); - anfrage=anfrage.replace("(","%28"); - anfrage=anfrage.replace(")","%29"); - anfrage=anfrage.replace("%3E%0D%0A%25","%3E"); - //anfrage=anfrage.replaceAll("\n",".%0D%0A%09"); - return anfrage; - } - - private String removeSpecialKeys(String query){ - query=query.replace("\\",""); - //query=query.replaceAll("\a",""); - query=query.replace("\b",""); - query=query.replace("\f",""); - query=query.replace("\r",""); - query=query.replace("\t",""); - // query=query.replaceAll("\v",""); - return query; - } - -} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -6,6 +6,7 @@ private String variable; private String uri; private float rank; +private String name; /** * RESOURCE,PROPERTY,UNSPEC @@ -31,11 +32,12 @@ this.rank = rank; } -public Hypothesis(String variable, String uri, String type, float rank){ - setRank(rank); - setVariable(variable); - setUri(uri); - setType(type); +public Hypothesis(String variable, String name, String uri, String type, float rank){ + this.setRank(rank); + this.setVariable(variable); + this.setUri(uri); + this.setType(type); + this.setName(name); } public String getType() { @@ -48,10 +50,17 @@ public void printAll(){ System.out.println("%%%%%%%%%%%"); System.out.println("Variable: "+variable); + System.out.println("Name: "+name); System.out.println("Uri: " + uri); System.out.println("Type: " + type); System.out.println("Rank: "+rank); System.out.println("%%%%%%%%%%%"); } +public String getName() { + return name; +} +public void setName(String name) { + this.name = name; +} } Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -1,54 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; - - -import java.lang.Math; -import java.math.BigDecimal; - -public class Levenshtein { - - - public static double nld(String orig, String eing){ - double result = computeLevenshteinDistance(orig,eing); - //System.out - double length=Math.max(orig.length(),eing.length()); - - //if distance between both is zero, then the NLD must be one - //but because they are equal, return a very high value, so that that query will be taken. - if(result==0.0 ){ - return 10.0; - } - else{ - - double result_nld =result/length; - return result_nld; - } - - } - - - //http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Java - private static int minimum(int a, int b, int c) { - return Math.min(Math.min(a, b), c); - } - - public static int computeLevenshteinDistance(CharSequence str1, - CharSequence str2) { - int[][] distance = new int[str1.length() + 1][str2.length() + 1]; - - for (int i = 0; i <= str1.length(); i++) - distance[i][0] = i; - for (int j = 0; j <= str2.length(); j++) - distance[0][j] = j; - - for (int i = 1; i <= str1.length(); i++) - for (int j = 1; j <= str2.length(); j++) - distance[i][j] = minimum( - distance[i - 1][j] + 1, - distance[i][j - 1] + 1, - distance[i - 1][j - 1] - + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0 - : 1)); - - return distance[str1.length()][str2.length()]; - } -} Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlFilter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlFilter.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlFilter.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -1,54 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; - -import java.util.HashMap; - -public class SparqlFilter { - public void create_Sparql_who(String string,HashMap<String, String> hm){ - // string=string.replaceAll("?", ""); - String[] array= string.split(" "); - //schauen ob erstes Wort ein who ist! - if(array[0].contains("who")){ - int position=0; - for(int i=0;i<array.length;i++){ - if (array[i].contains("of")){ - position=i; - break; - } - } - String vor_of=array[position-1]; - String nach_of=""; - //wenn nur ein element hinter of kommt - if(array.length-position-1==1){ - nach_of=array[position+1]; - } - else{ - for(int i=position+1; i<array.length;i++){ - //nach_of=nach_of+array[i]+" "; - nach_of=(nach_of.concat(array[i])).concat(" "); - } - - //letztes leerzeichen loeschen - nach_of = nach_of.substring(0, nach_of.length()-1); - } - String uri_vor_of=" "; - String uri_nach_of=" "; - - uri_vor_of=hm.get(vor_of); - uri_nach_of=hm.get(nach_of); - if(uri_vor_of!=null && uri_nach_of!=null){ - uri_nach_of=uri_nach_of.replace("Category:", ""); - uri_nach_of=uri_nach_of.replace("category:", ""); - - - String anfrage=null; - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; - - } - else{ - //System.out.println("Nothing to do"); - } - - } - - } -} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -27,7 +27,9 @@ import net.didion.jwnl.JWNLException; import net.didion.jwnl.data.POS; -import org.dllearner.algorithm.tbsl.exploration.sax.ParseXmlHtml; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Utils.GetRessourcePropertys; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; @@ -62,7 +64,7 @@ static WordNet wordnet; BasicTemplator btemplator; Templator templator; - private static mySQLDictionary myindex; + private static SQLiteIndex myindex; boolean only_best_levensthein_query; static StanfordLemmatizer lemmatiser; //one Minute @@ -86,7 +88,7 @@ //templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); System.out.println("Start Indexing"); - myindex = new mySQLDictionary(); + myindex = new SQLiteIndex(); System.out.println("Done:Indexing"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -4,6 +4,7 @@ public class Template { + private ArrayList<ElementList_new> list_of_element_uri_pair = new ArrayList<ElementList_new>(); private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; @@ -11,6 +12,9 @@ private String filter; private String OrderBy; private String limit; + private String question; + private float overallTime; + private float time_Templator; public String getHaving() { return having; @@ -45,13 +49,14 @@ } - public Template(ArrayList<ArrayList<String>>condition_new, String having_new, String filter_new, String SelectTerm_new, String OrderBy_new, String limit_new){ - setCondition(condition_new); - setHaving(having_new); - setFilter(filter_new); - setOrderBy(OrderBy_new); - setLimit(limit_new); - setSelectTerm(SelectTerm_new); + public Template(ArrayList<ArrayList<String>>condition_new, String having_new, String filter_new, String SelectTerm_new, String OrderBy_new, String limit_new, String question_new){ + this.setCondition(condition_new); + this.setHaving(having_new); + this.setFilter(filter_new); + this.setOrderBy(OrderBy_new); + this.setLimit(limit_new); + this.setSelectTerm(SelectTerm_new); + this.setQuestion(question_new); } public ArrayList<ArrayList<String>> getCondition() { return condition; @@ -73,6 +78,7 @@ public void printAll(){ System.out.println("###### Template ######"); + System.out.println("question: "+ question); System.out.println("condition: "+condition); //System.out.println("hypotesen: "+hypothesen); int anzahl = 1; @@ -91,6 +97,35 @@ System.out.println("limit: "+limit); System.out.println("###### Template printed ######\n"); } + public String getQuestion() { + return question; + } + public void setQuestion(String question) { + this.question = question; + } + public float getOverallTime() { + return overallTime; + } + public void setOverallTime(float overallTime) { + this.overallTime = overallTime; + } + public float getTime_Templator() { + return time_Templator; + } + public void setTime_Templator(float time_Templator) { + this.time_Templator = time_Templator; + } + public ArrayList<ElementList_new> getList_of_element_uri_pair() { + return list_of_element_uri_pair; + } + public void setList_of_element_uri_pair(ArrayList<ElementList_new> list_of_element_uri_pair) { + this.list_of_element_uri_pair = list_of_element_uri_pair; + } + + public void addToList_of_element_uri_pair(ElementList_new newElement) { + this.list_of_element_uri_pair.add(newElement); + } + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -1,10 +1,22 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.net.MalformedURLException; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.Set; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Index.Index_utils; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; import org.dllearner.algorithm.tbsl.sparql.Path; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; @@ -16,20 +28,54 @@ public class TemplateBuilder { static BasicTemplator btemplator; -private static mySQLDictionary myindex; +private static SQLiteIndex myindex; public TemplateBuilder() throws MalformedURLException, ClassNotFoundException, SQLException{ TemplateBuilder.btemplator = new BasicTemplator(); //btemplator.UNTAGGED_INPUT = false; - TemplateBuilder.myindex = new mySQLDictionary(); + TemplateBuilder.myindex = new SQLiteIndex(); } - public ArrayList<Template> createTemplates(String question){ + public ArrayList<Template> createTemplates(String question) throws IOException{ + + long start = System.currentTimeMillis(); + ArrayList<Template> resultArrayList = new ArrayList<Template>(); - Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); + Set<BasicQueryTemplate> querytemps =null; + querytemps = btemplator.buildBasicQueries(question); + + /* + * check if templates were build, if not, safe the question and delete it for next time from the xml file. + */ + if(querytemps.contains("could not be parsed") || querytemps.isEmpty()){ + String dateiname="/home/swalter/Dokumente/Auswertung/NotParsed.txt"; + String result_string =""; + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + result_string+=thisLine+"\n"; + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + + File file = new File(dateiname); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + + bw.write(result_string+"\n"+question); + bw.flush(); + bw.close(); + + + } + + long stop_template = System.currentTimeMillis(); for (BasicQueryTemplate bqt : querytemps) { ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); //ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); @@ -114,22 +160,24 @@ * SLOT_title: PROPERTY {title,name,label} mitfuehren */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit); + Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit,question); //TODO: Iterate over slots ArrayList<Hypothesis> list_of_hypothesis = new ArrayList<Hypothesis>(); for(Slot slot : bqt.getSlots()){ + //System.out.println("Slot: "+slot.toString()); if(slot.toString().contains("UNSPEC")){ String tmp= slot.toString().replace(" UNSPEC {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1], "UNSPEC", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "UNSPEC", 0); + //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); } if(slot.toString().contains("PROPERTY")){ String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1], "PROPERTY", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0); list_of_hypothesis.add(tmp_hypothesis); } @@ -137,7 +185,7 @@ String tmp= slot.toString().replace(" RESOURCE {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1], "RESOURCE", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "RESOURCE", 0); list_of_hypothesis.add(tmp_hypothesis); } } @@ -145,10 +193,13 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for(Hypothesis x : list_of_hypothesis){ - if(x.getType().contains("RESOURCE")){ + if(x.getType().contains("RESOURCE")|| x.getType().contains("UNSPEC") ){ ArrayList<String> result= new ArrayList<String>(); try { - result = utils_new.searchIndex(x.getUri(), 3, myindex); + /* here I have to check the hypothesis if I have an isA in my Condition, + * if so, only look up Yago and OntologyClass. + */ + result = Index_utils.searchIndex(x.getUri(), 3, myindex); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -159,11 +210,18 @@ //String variable, String uri, String type, float rank for(Hypothesis h : list_of_hypothesis){ if (h.getUri().equals(x.getUri())){ - Hypothesis new_h = new Hypothesis(h.getVariable(), s, h.getType(), 1); - new_list.add(new_h); + if(s!=null){ + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1); + new_list.add(new_h); + } + else{ + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1); + new_list.add(new_h); + } + } else{ - Hypothesis new_h = new Hypothesis(h.getVariable(), h.getUri(), h.getType(), h.getRank()); + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), h.getRank()); new_list.add(new_h); } } @@ -174,20 +232,37 @@ - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + /* + * safe lookups for properties, so we dont have to access sql database every time + */ + HashMap<String,String> hm = new HashMap<String, String>(); + for(ArrayList<Hypothesis> x : final_list_set_hypothesis){ + + for(Hypothesis h : x){ - if(h.getType().contains("PROPERTY") || h.getType().contains("UNSPEC")){ + + //only if you have a Property or an Unspec, which still has no http:/dbpedia etc + if(h.getType().contains("PROPERTY") || (h.getType().contains("UNSPEC")&& !h.getUri().contains("http"))){ ArrayList<String> result= new ArrayList<String>(); try { - result = utils_new.searchIndex(h.getUri(), 1, myindex); + if(hm.containsKey(h.getUri().toLowerCase())){ + result.add(hm.get(h.getUri().toLowerCase())); + } + else{ + result = Index_utils.searchIndex(h.getUri(), 1, myindex); + if(!result.isEmpty())hm.put(h.getUri().toLowerCase(),result.get(0)); + } if(!result.isEmpty()){ h.setUri(result.get(0)); h.setRank(1); } else{ - String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase(); + String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase().replace(" ", "_"); + h.setUri(tmp); h.setRank(0); } @@ -200,8 +275,11 @@ } template.setHypothesen(final_list_set_hypothesis); + + + //TODO: Take Template like it is and change Condition - Template template_reverse_conditions = new Template(template.getCondition(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit()); + Template template_reverse_conditions = new Template(template.getCondition(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); //= template; ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); @@ -214,7 +292,15 @@ condition_reverse_new.add(new_list); } + long stop = System.currentTimeMillis(); + template_reverse_conditions.setOverallTime(stop-start); + template.setOverallTime(stop-start); + + template_reverse_conditions.setTime_Templator(stop_template-start); + template.setTime_Templator(stop_template-start); + template_reverse_conditions.setCondition(condition_reverse_new); + template_reverse_conditions.setHypothesen(template.getHypothesen()); resultArrayList.add(template); resultArrayList.add(template_reverse_conditions); Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2012-03-05 12:12:37 UTC (rev 3604) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2012-03-07 14:50:29 UTC (rev 3605) @@ -1,594 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; - -import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; - -public class mySQLDictionary { - private Connection conn; - StanfordLemmatizer lemma; - - public mySQLDictionary() throws ClassNotFoundException, SQLException { - // TODO Auto-generated constructor stub - Class.forName( "org.sqlite.JDBC" ); - conn = DriverManager.getConnection("jdbc:sqlite::memory:"); - createIndexPropertys(); - createIndexResource(); - createWordnetHelp(); - createIndexOntology(); - createIndexOntologyClass(); - createIndexofYago(); - lemma = new StanfordLemmatizer(); - - //optional!! - //createIndexWikipedia(); - - } - - /* - * Next, we want to select the persons living in a city that contains the pattern "tav" from the "Persons" table. - -We use the following SELECT statement: -SELECT * FROM Persons -WHERE City LIKE '%tav%' - */ - - public String getResourceURI(String string) throws SQLException{ - /* while(rs.next()) - {*/ - Statement stat = conn.createStatement(); - ResultSet rs; - try { - rs = stat.executeQuery("select uri from resource where name='"+string.toLowerCase()+"';"); - /*while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - }*/ - return rs.getString("uri"); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - } - - public ArrayList<String> getResourceURILike(String string) throws SQLException{ - /* while(rs.next()) - {*/ - Statement stat = conn.createStatement(); - ResultSet rs; - ArrayList<String> result= new ArrayList<String>(); - try { - rs = stat.executeQuery("select uri from resource where name like'"+string.toLowerCase()+"%';"); - while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); - } - return result; - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - } - - public ArrayList<String> getYagoURILike(String string) throws SQLException{ - /* while(rs.next()) - {*/ - Statement stat = conn.createStatement(); - ResultSet rs; - ArrayList<String> result= new ArrayList<String>(); - try { - rs = stat.executeQuery("select uri from yago where name like'"+string.toLowerCase()+"%';"); - while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); - } - return result; - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - } - - - public String getYagoURI(String string) throws SQLException{ - /* while(rs.next()) - {*/ - Statement stat = conn.createStatement(); - ResultSet rs; - try { - rs = stat.executeQuery("select uri from yago where name='"+string.toLowerCase()+"';"); - return rs.getString("uri"); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - } - - - public String getPropertyURI(String string) throws SQLException{ - Statement stat = conn.createStatement(); - ResultSet rs; - try { - rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); - return rs.getString("uri"); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - - } - - public String getontologyURI(String string) throws SQLException{ - Statement stat = conn.createStatement(); - ResultSet rs; - try { - rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); - return rs.getString("uri"); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - return null; - } - - - } - - public String getontologyClassURI(String string) throws SQLException{ - Statement stat = conn.createStatement(); - ResultSet rs; - try { - rs = stat.executeQuery("select uri from ontologyClass where name='"+string.toLowerCase()+"'... [truncated message content] |