From: <seb...@us...> - 2012-03-29 16:47:00
|
Revision: 3626 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3626&view=rev Author: sebastianwtr Date: 2012-03-29 16:46:49 +0000 (Thu, 29 Mar 2012) Log Message: ----------- [tbsl exploration] included MainInterface and added sort function for the QueryPairs Modified Paths: -------------- 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/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 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-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -31,11 +31,11 @@ private static SQLiteIndex myindex; -public TemplateBuilder() throws MalformedURLException, ClassNotFoundException, SQLException{ +public TemplateBuilder(BasicTemplator bt, SQLiteIndex sq) throws MalformedURLException, ClassNotFoundException, SQLException{ - TemplateBuilder.btemplator = new BasicTemplator(); + TemplateBuilder.btemplator = bt; //btemplator.UNTAGGED_INPUT = false; - TemplateBuilder.myindex = new SQLiteIndex(); + TemplateBuilder.myindex = sq; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -0,0 +1,29 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.ArrayList; + +public class LinearSort { + + public static void doSort(ArrayList<QueryPair> qp){ + + boolean change=true; + while(change){ + change=false; + for(int i = 0; i<qp.size()-1;i++){ + if(qp.get(i).getRank()<qp.get(i+1).getRank()){ + change=true; + QueryPair one = qp.get(i); + QueryPair two = qp.get(i+1); + qp.set(i, two); + qp.set(i+1, one); + } + } + } + + for(QueryPair p : qp){ + p.printAll(); + } + + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -13,8 +13,8 @@ //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; //private static String server_Prefix="http://dbpedia.org/sparql"; - //private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; + private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; private static int timeToTimeoutOnServer=30000; Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -0,0 +1,107 @@ +package org.dllearner.algorithm.tbsl.exploration.exploration_main; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.sql.SQLException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; +import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; +import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; +import org.dllearner.algorithm.tbsl.exploration.Utils.Query; +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; + +public class MainInterface { + private int anzahlAbgeschickterQueries = 10; + public static void startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex ) throws ClassNotFoundException, SQLException, IOException{ + + TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); + ArrayList<Template> template_list = new ArrayList<Template>(); + + + /* + * generate Templates! + */ + template_list=templateObject.createTemplates(question); + + /* + * generate Queries and test the first Time + */ + ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + + //generate QueryPair + for(Template t : template_list){ + //t.printAll(); + ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); + qp_t = Query.returnSetOfQueries(t, "NORMAL"); + for(QueryPair p : qp_t){ + //if(!qp.contains(p)) qp.add(p); + boolean contain = false; + for(QueryPair p_t : qp){ + if(p_t.getRank()==p.getRank()){ + if(p_t.getQuery().contains(p.getQuery())) contain=true; + } + } + if(!contain)qp.add(p); + } + } + + //sort QueryPairs + LinearSort.doSort(qp); + + /* + * If there is no answer, start IterationMode with Levensthein + */ + for(Template t : template_list){ + try{ + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + t.setHypothesenLevensthein(hypothesenSetList); + } + catch (Exception e){ + + } + + } + + /* + * Generate Queries for Levensthein Mode and test queries + */ + qp.clear(); + //generate QueryPair + for(Template t : template_list){ + //t.printAll(); + ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); + qp_t = Query.returnSetOfQueries(t, "LEVENSTHEIN"); + for(QueryPair p : qp_t){ + //if(!qp.contains(p)) qp.add(p); + boolean contain = false; + for(QueryPair p_t : qp){ + if(p_t.getRank()==p.getRank()){ + if(p_t.getQuery().contains(p.getQuery())) contain=true; + } + } + if(!contain)qp.add(p); + } + } + + //sort QueryPairs + LinearSort.doSort(qp); + System.out.println("Anzahl: "+qp.size()); + /* + * still no answer, start IterationMode with Wordnet + */ + + /* + * Generate Queries for Wordnet Mode and test queries. + */ + } + + + private void sortQueries(){ + + } +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -17,8 +17,10 @@ import net.didion.jwnl.JWNLException; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import java.sql.Connection; import java.sql.DriverManager; @@ -46,15 +48,16 @@ */ public static void main(String[] args) throws IOException, JWNLException, InterruptedException, ClassNotFoundException, SQLException { - /** - * Do the starting initializing stuff - */ + System.out.println("Starting Main File"); long startInitTime = System.currentTimeMillis(); /* - * Create Sparql Object + * Initial Index and Templator */ - SparqlObject sparql = new SparqlObject(); + BasicTemplator btemplator = new BasicTemplator(); + //btemplator.UNTAGGED_INPUT = false; + SQLiteIndex myindex = new SQLiteIndex(); + long stopInitTime = System.currentTimeMillis(); System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); @@ -74,68 +77,7 @@ System.out.println("Bye!"); System.exit(0); } - if(line.contains(":setIterationdepth")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setIterationdepth(i_zahl); - doing = false; - } - if(line.contains(":getIterationdepth")){ - System.out.println(sparql.getIterationdepth()); - doing = false; - } - if(line.contains(":setExplorationdepthwordnet")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setExplorationdepthwordnet(i_zahl); - doing = false; - } - if(line.contains(":getExplorationdepthwordnet")){ - System.out.println(sparql.getExplorationdepthwordnet()); - doing = false; - } - if(line.contains(":setNumberofanswer")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setNumberofanswers(i_zahl); - doing = false; - } - if(line.contains(":getNumberofanswer")){ - System.out.println(sparql.getNumberofanswers()); - doing = false; - } - if(line.contains(":textfile")&& schleife==true){ - TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - - - System.out.println("Please enter Path of txt. File:"); - line=in.readLine(); - - //Start Time measuring - long startTime = System.currentTimeMillis(); - String s=""; - BufferedReader in_file = new BufferedReader(new InputStreamReader(new FileInputStream(line))); - int anzahl=0; - while( null != (s = in_file.readLine()) ) { - System.out.println(s); - anzahl++; - //get each line and send it to the parser - //String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1 - queryInformation newQuery = new queryInformation(s,"0","",false,false,false,"non",false); - queryInformation result = new queryInformation(s,"0","",false,false,false,"non",false); - result=sparql.create_Sparql_query(newQuery); - ArrayList<String> ergebnis = result.getResult(); - for(String i: ergebnis){ - System.out.println(i); - } - } - long timeNow = System.currentTimeMillis(); - long diff = timeNow-startTime; - - System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); - - } if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); @@ -154,24 +96,16 @@ int anzahl=0; int anzahl_query_with_answers=0; int yago_querys=0; - for(queryInformation s : list_of_structs){ + for(queryInformation qi : list_of_structs){ anzahl=anzahl+1; System.out.println(""); - if(s.getId()==""||s.getId()==null)System.out.println("NO"); - System.out.println("ID: "+s.getId()); - System.out.println("Query: "+s.getQuery()); - System.out.println("Type: "+s.getType()); - System.out.println("XMLType: "+s.getXMLtype()); - //queryInformation tmpquery; - //only question, which are not yago files - if(s.isYago()==true)yago_querys=yago_querys+1; - //if(s.isYago()==false){ - queryInformation tmpquery=sparql.create_Sparql_query(s); - if(!tmpquery.getResult().isEmpty()) { - list_of_resultstructs.add(sparql.create_Sparql_query(s)); - anzahl_query_with_answers=anzahl_query_with_answers+1; - } - //} + if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); + System.out.println("ID: "+qi.getId()); + System.out.println("Query: "+qi.getQuery()); + System.out.println("Type: "+qi.getType()); + System.out.println("XMLType: "+qi.getXMLtype()); + String question = qi.getQuery(); + MainInterface.startQuestioning(question,btemplator,myindex); } @@ -217,9 +151,8 @@ else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); - queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); - result= sparql.create_Sparql_query(newQuery); + MainInterface.startQuestioning(line,btemplator,myindex); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! Set<String> setString = new HashSet<String>(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -15,6 +15,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; @@ -23,6 +24,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class testClass_new { @@ -36,8 +38,12 @@ // TODO Auto-generated method stub ArrayList<Template> temp_list_result = new ArrayList<Template>(); - TemplateBuilder testobject = new TemplateBuilder(); + BasicTemplator btemplator = new BasicTemplator(); + //btemplator.UNTAGGED_INPUT = false; + SQLiteIndex myindex = new SQLiteIndex(); + TemplateBuilder testobject = new TemplateBuilder(btemplator, myindex); + String filepath = "/home/swalter/Dokumente/Auswertung/"; //String file="very_small.xml"; String file="dbpedia-train.xml"; @@ -53,7 +59,7 @@ String question ="Who is the daughter of Bill Clinton married to?"; long start_template = System.currentTimeMillis(); - //temp_list_result=testobject.createTemplates(question); + temp_list_result=testobject.createTemplates(question); Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.92; + private final static double LevenstheinMin=0.5; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |