From: <seb...@us...> - 2011-10-16 09:27:03
|
Revision: 3306 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3306&view=rev Author: sebastianwtr Date: 2011-10-16 09:26:57 +0000 (Sun, 16 Oct 2011) Log Message: ----------- [tbsl] added a lot of new functions Modified Paths: -------------- 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/exploration_main/exploration_main.java 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 2011-10-16 09:21:24 UTC (rev 3305) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-10-16 09:26:57 UTC (rev 3306) @@ -14,6 +14,10 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; +import org.dllearner.algorithm.tbsl.sparql.Path; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; +import org.dllearner.algorithm.tbsl.sparql.Slot; +import org.dllearner.algorithm.tbsl.sparql.Template; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import org.dllearner.algorithm.tbsl.templator.Templator; @@ -27,6 +31,7 @@ static WordNet wordnet; BasicTemplator btemplator; Templator templator; + HashMap<String, String> hm; /*Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(line); for (BasicQueryTemplate temp : querytemps) { @@ -35,218 +40,220 @@ */ //Konstruktor - public SparqlObject() throws MalformedURLException{ + public SparqlObject(HashMap<String, String> hm_new) throws MalformedURLException{ wordnet = new WordNet(); + hm=hm_new; System.out.println("Loading SPARQL Templator"); btemplator = new BasicTemplator(); templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); } + + private void doIteration(String string1, String string2) throws JWNLException{ + long startTime = System.currentTimeMillis(); - public void create_Sparql_query(String string,HashMap<String, String> hm) throws JWNLException{ - // string=string.replaceAll("?", ""); - String[] array= string.split(" "); - String teststring=""; - /*Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries("Who is the Mayor of Berlin?"); - for (BasicQueryTemplate temp : querytemps) { - //System.out.println(temp.toString()); - teststring=teststring.concat(temp.toString()); - } - - System.out.println("##################"); - System.out.println(teststring);*/ - - /** - * Cluster function - */ - /* - int length=array.length; - int [] result_array= new int[length]; - for(int p =0;p<length;p++){ - result_array[p]=0; + String string2_uri; + string2_uri=hm.get(string2); + string2_uri=string2_uri.replace("Category:", ""); + string2_uri=string2_uri.replace("category:", ""); + System.out.println("Get Propertys of "+string2); + + //contains uri AND string, every second is the string + ArrayList<String> properties = new ArrayList<String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + try { + //using uri now, not the string + properties=property.getPropertys(hm.get(string2)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Start Iterating Wordnet with "+string1+" and deept of "+iteration_deept); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + semantics.add(string1); + tmp_semantics=semantics; + for(int i=0;i<=iteration_deept;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); } - int zaehler=1; - - //looking for max 3 word as one index - for(int z=length-1;z>=0;z=z-1){ - if(z-2>=0){ - String tmp1 = array[z]; - String tmp2 = array[z-1]; - String tmp3 = array[z-2]; - String tmpstring3=(((tmp3.concat(" ")).concat(tmp2)).concat(" ")).concat(tmp1); - String tmpstring2=(tmp2.concat(" ")).concat(tmp1); - String tmpstring1=tmp1; - - //always looking for the "biggest" match - if(hm.get(tmpstring3)!=null){ - result_array[z]=zaehler; - result_array[z-1]=zaehler; - result_array[z-2]=zaehler; - zaehler++; - } - else{ - if(hm.get(tmpstring2)!=null){ - result_array[z]=zaehler; - result_array[z-1]=zaehler; - zaehler++; - } - else{ - if(hm.get(tmpstring1)!=null){ - result_array[z]=zaehler; - zaehler++; - } - } - } - - } - else{ - if(z-1>=0){ - String tmp1 = array[z]; - String tmp2 = array[z-1]; - - String tmpstring2=(tmp2.concat(" ")).concat(tmp1); - String tmpstring1=tmp1; - - //always looking for the "biggest" match + } + long endTime = System.currentTimeMillis(); + System.out.println("Getting Properties and Semantics took "+(endTime-startTime) +" ms\n"); + + //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) + for(int h=1;h<properties.size()-2;h=h+2){ + for(String b : semantics){ + //System.out.println(properties.get(h)); + //System.out.println(b); + if(properties.get(h).contains(b.toLowerCase())){ + if(!result_SemanticsMatchProperties.contains(properties.get(h))) + result_SemanticsMatchProperties.add(properties.get(h)); + } + } + } + for(String b : result_SemanticsMatchProperties){ + string1=b.toLowerCase(); + String anfrage; + String string1_uri; + string1_uri=hm.get(string1); + if(string1_uri!=null){ + anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+string2_uri+"> <"+string1_uri+"> ?x.}"; + System.out.println("Answer with the property \" " + b + "\" :\n"+sendServerQuestionRequest(anfrage)); + } + } + long endTime2 = System.currentTimeMillis(); + System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); + } + + - if(hm.get(tmpstring2)!=null){ - result_array[z]=zaehler; - result_array[z-1]=zaehler; - zaehler++; - } - else{ - if(hm.get(tmpstring1)!=null){ - result_array[z]=zaehler; - zaehler++; - } - } - } - if(z==0){ - if(hm.get(array[z])!=null){ - result_array[z]=zaehler; - zaehler++; - } - } - } - } - - System.out.println("###### Cluster ######"); - for(int p =0;p<length;p++){ - System.out.println(result_array[p]); + private void create_Sparql_query_new(String string) throws JWNLException{ + String[] array_new=new String[4]; + array_new=getyy0AndQuery(string); + if(!array_new[0].contains("error")){ + String result=null; + + //Version 1 + result=sendServerQuestionRequest(array_new[0]); + if(result!="noanswer"){ + // System.out.println("Version1"); + System.out.println(result); } - System.out.println("######"); - */ - - //look, if the first word is a who! - if(array[0].contains("who")){ - int position=0; - for(int i=0;i<array.length;i++){ - if (array[i].contains("of")){ - position=i; - break; - } + else{ + doIteration(array_new[3],array_new[2]); + } + //Version2 + /* else{ + result=sendServerQuestionRequest(array_new[1]); + if(result!="noanswer"){ + System.out.println("Version2"); + System.out.println(result); } - String vor_of=array[position-1]; - String nach_of=""; - //if there is only one element after of - 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.concat(array[i])).concat(" "); - } - - //delete last emty space - 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; - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; - - //if there is no answer from the server, start searching with wordnet - String result=""; - result=sendServerQuestionRequest(anfrage); - if(result!="noanswer"){ - System.out.println(result); - } - else{ - long startTime = System.currentTimeMillis(); - - System.out.println("Get Propertys of "+nach_of); - - //contains uri AND string, every second is the string - ArrayList<String> properties = new ArrayList<String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - try { - //using uri now, not the string - properties=property.getPropertys(hm.get(nach_of)); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - System.out.println("Start Iterating Wordnet with "+vor_of+" and deept of "+iteration_deept); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(vor_of); - tmp_semantics=semantics; - for(int i=0;i<=iteration_deept;i++){ + }*/ + } - try { - tmp_semantics=getSemantics(tmp_semantics); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - - } - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); - } - - } - long endTime = System.currentTimeMillis(); - System.out.println("Getting Properties and Semantics took "+(endTime-startTime) +" ms\n"); - - //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) - for(int h=1;h<properties.size()-2;h=h+2){ - for(String b : semantics){ - //System.out.println(properties.get(h)); - //System.out.println(b); - if(properties.get(h).contains(b.toLowerCase())){ - if(!result_SemanticsMatchProperties.contains(properties.get(h))) - result_SemanticsMatchProperties.add(properties.get(h)); - } - } - } - for(String b : result_SemanticsMatchProperties){ - vor_of=b.toLowerCase(); - uri_vor_of=hm.get(vor_of); - if(uri_vor_of!=null){ - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; - System.out.println("Answer with the property \" " + b + "\" :\n"+sendServerQuestionRequest(anfrage)); - } - } - long endTime2 = System.currentTimeMillis(); - System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); - } - } - - } + } + public void create_Sparql_query(String string) throws JWNLException{ + //create_Sparql_query_new(string); + + Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(string.toLowerCase()); + for (BasicQueryTemplate temp : querytemps) { + + System.out.println("temp.getQt();" + temp.getQt()); + System.out.println("temp.getSelTerms();" + temp.getSelTerms()); + System.out.println("temp.getVariablesAsStringList();" + temp.getVariablesAsStringList()); + System.out.println("temp.getConditions();" + temp.getConditions()); + System.out.println("temp.getSlots();" + temp.getSlots()); + + String query; + SPARQL_Term selTerms = null; + for(SPARQL_Term terms :temp.getSelTerms()) selTerms=terms; + + Path conditions = null; + for(Path condition: temp.getConditions()) conditions=condition; + + + + //System.out.println("\n"); + System.out.println("\n"); + query=temp.getQt().toString()+" "+selTerms.toString()+" { "+ conditions.toString().replace("--","") + "} "; + + String[] slots= null; + for(Slot slot : temp.getSlots()){ + + //hier muss dann noch die abfrage aus der hm raus, also das direkt die uri eingebettet wird. + String tmp= slot.toString(); + tmp= tmp.replace("UNSPEC",""); + tmp= tmp.replace("RESOURCE",""); + tmp= tmp.replace("{",""); + tmp= tmp.replace("}",""); + tmp=tmp.replace(" ",""); + //System.out.println(tmp); + //damit auch wirklich nur ?y und nicht ?y0 ersetzt wird, einfach nach "?y " suchen. + String[] array = tmp.split(":"); + String replace; + if(array[0].length()<2)replace = "?"+array[0]+" "; + else replace="?"+array[0]; + //System.out.println("replace: " + replace); + //hier dann den hm wert von array[1] eintragen + query=query.replace(replace, "<"+hm.get(array[1])+">"); + + } + System.out.println(query); + } + // string=string.replaceAll("?", ""); + //create_Sparql_query_old(string); } + + + + + private String[] getyy0AndQuery(String string) { + String teststring=""; + String[] return_array = new String[4]; + Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(string); + for (BasicQueryTemplate temp : querytemps) { + teststring=temp.toString(); + System.out.println(teststring); + } + teststring=teststring.replace("\n", ""); + String[] array_tmp=teststring.split("\\}"); + + //only for y and y0 + String sparqlquery=""; + String y=""; + String y0=""; + for(String i : array_tmp){ + i=i.replace(" ", ""); + String[] tmp=null; + if(i.contains("SELECT")) sparqlquery=i.concat("}"); + if(i.contains("y0")){ + y0=i; + tmp=y0.split("\\{"); + y0=tmp[1];} + if(i.contains("y")&& !i.contains("y0")){ + y=i; + tmp=y.split("\\{"); + y=tmp[1]; + } + } + String uri1=hm.get(y0); + String uri2=hm.get(y); + if(uri1!=null && uri2!=null){ + uri1=uri1.replace("Category:", ""); + uri1=uri1.replace("category:", ""); + uri2=uri2.replace("Category:", ""); + uri2=uri2.replace("category:", ""); + String anfrage1; + anfrage1="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri1+"> <"+uri2+"> ?x.}"; + String anfrage2; + anfrage2="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri2+"> <"+uri1+"> ?x.}"; + return_array[0]=anfrage1; + return_array[1]=anfrage2; + return_array[2]=y0; + return_array[3]=y; + } + else{ + return_array[0]="error"; + } + return return_array; + + } private static ArrayList<String> getSemantics (ArrayList<String> semantics) throws IOException, JWNLException { ArrayList<String> result = new ArrayList<String>(); @@ -361,4 +368,201 @@ // query=query.replaceAll("\v",""); return query; } + } + +/** + * Cluster function + */ +/* +int length=array.length; +int [] result_array= new int[length]; +for(int p =0;p<length;p++){ + result_array[p]=0; +} +int zaehler=1; + +//looking for max 3 word as one index +for(int z=length-1;z>=0;z=z-1){ + if(z-2>=0){ + String tmp1 = array[z]; + String tmp2 = array[z-1]; + String tmp3 = array[z-2]; + + String tmpstring3=(((tmp3.concat(" ")).concat(tmp2)).concat(" ")).concat(tmp1); + String tmpstring2=(tmp2.concat(" ")).concat(tmp1); + String tmpstring1=tmp1; + + //always looking for the "biggest" match + if(hm.get(tmpstring3)!=null){ + result_array[z]=zaehler; + result_array[z-1]=zaehler; + result_array[z-2]=zaehler; + zaehler++; + } + else{ + if(hm.get(tmpstring2)!=null){ + result_array[z]=zaehler; + result_array[z-1]=zaehler; + zaehler++; + } + else{ + if(hm.get(tmpstring1)!=null){ + result_array[z]=zaehler; + zaehler++; + } + } + } + + } + else{ + if(z-1>=0){ + String tmp1 = array[z]; + String tmp2 = array[z-1]; + + String tmpstring2=(tmp2.concat(" ")).concat(tmp1); + String tmpstring1=tmp1; + + //always looking for the "biggest" match + + if(hm.get(tmpstring2)!=null){ + result_array[z]=zaehler; + result_array[z-1]=zaehler; + zaehler++; + } + else{ + if(hm.get(tmpstring1)!=null){ + result_array[z]=zaehler; + zaehler++; + } + } + } + if(z==0){ + if(hm.get(array[z])!=null){ + result_array[z]=zaehler; + zaehler++; + } + } + } + } + +System.out.println("###### Cluster ######"); +for(int p =0;p<length;p++){ + System.out.println(result_array[p]); +} +System.out.println("######"); +*/ + +/* + * private void create_Sparql_query_old(String string) throws JWNLException { + String[] array= string.split(" "); + + + //look, if the first word is a who! + 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=""; + //if there is only one element after of + 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.concat(array[i])).concat(" "); + } + + //delete last emty space + 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; + anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; + + //if there is no answer from the server, start searching with wordnet + String result=""; + result=sendServerQuestionRequest(anfrage); + if(result!="noanswer"){ + System.out.println(result); + } + else{ + long startTime = System.currentTimeMillis(); + + System.out.println("Get Propertys of "+nach_of); + + //contains uri AND string, every second is the string + ArrayList<String> properties = new ArrayList<String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + try { + //using uri now, not the string + properties=property.getPropertys(hm.get(nach_of)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Start Iterating Wordnet with "+vor_of+" and deept of "+iteration_deept); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + semantics.add(vor_of); + tmp_semantics=semantics; + for(int i=0;i<=iteration_deept;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + + } + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + + } + long endTime = System.currentTimeMillis(); + System.out.println("Getting Properties and Semantics took "+(endTime-startTime) +" ms\n"); + + //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) + for(int h=1;h<properties.size()-2;h=h+2){ + for(String b : semantics){ + //System.out.println(properties.get(h)); + //System.out.println(b); + if(properties.get(h).contains(b.toLowerCase())){ + if(!result_SemanticsMatchProperties.contains(properties.get(h))) + result_SemanticsMatchProperties.add(properties.get(h)); + } + } + } + for(String b : result_SemanticsMatchProperties){ + vor_of=b.toLowerCase(); + uri_vor_of=hm.get(vor_of); + if(uri_vor_of!=null){ + anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; + System.out.println("Answer with the property \" " + b + "\" :\n"+sendServerQuestionRequest(anfrage)); + } + } + long endTime2 = System.currentTimeMillis(); + System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); + } + } + + } + } +*/ 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 2011-10-16 09:21:24 UTC (rev 3305) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-10-16 09:26:57 UTC (rev 3306) @@ -63,7 +63,7 @@ System.out.println("Entity1 done");*/ System.out.println("Done with indexing\n"); System.out.println("Start generating Wordnet Dictionary"); - SparqlObject sparql = new SparqlObject(); + SparqlObject sparql = new SparqlObject(hm); System.out.println("Generating Wordnet Dictionary Done"); long stopInitTime = System.currentTimeMillis(); System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); @@ -97,7 +97,7 @@ anzahl++; //get each line and send it to the parser s=s.replace("?",""); - sparql.create_Sparql_query(s.toLowerCase(),hm); + sparql.create_Sparql_query(s.toLowerCase()); } long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -112,7 +112,7 @@ for (BasicQueryTemplate temp : querytemps) { System.out.println(temp.toString()); }*/ - sparql.create_Sparql_query(line.toLowerCase(),hm); + sparql.create_Sparql_query(line.toLowerCase()); long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-10-30 11:45:40
|
Revision: 3341 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3341&view=rev Author: sebastianwtr Date: 2011-10-30 11:45:33 +0000 (Sun, 30 Oct 2011) Log Message: ----------- [tbsl] added a few getter and setter methods and start to implement the different iterations Modified Paths: -------------- 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/exploration_main/exploration_main.java 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 2011-10-29 20:29:02 UTC (rev 3340) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-10-30 11:45:33 UTC (rev 3341) @@ -1,8 +1,13 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -15,6 +20,7 @@ import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; import org.dllearner.algorithm.tbsl.sparql.Path; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.Template; @@ -27,18 +33,15 @@ //global Variable dict //start counting with 0 - static int iteration_deept=1; + static int explorationdepthwordnet=1; + static int iterationdepth =0; + static int numberofanswers=1; static WordNet wordnet; BasicTemplator btemplator; Templator templator; HashMap<String, String> hm; - /*Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(line); - for (BasicQueryTemplate temp : querytemps) { - System.out.println(temp.toString()); - } - - */ + //Konstruktor public SparqlObject(HashMap<String, String> hm_new) throws MalformedURLException{ wordnet = new WordNet(); @@ -47,9 +50,233 @@ btemplator = new BasicTemplator(); templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); + setExplorationdepthwordnet(1); + setIterationdepth(0); + setNumberofanswers(1); } + + /* + * ##################################### + * Getter and Setter Methods + */ + + public int getExplorationdepthwordnet() { + return explorationdepthwordnet; + } + + public void setExplorationdepthwordnet(int explorationdepthwordnet) { + SparqlObject.explorationdepthwordnet = explorationdepthwordnet; + } + + + public int getIterationdepth() { + return iterationdepth; + } + + + public void setIterationdepth(int iterationdepth) { + SparqlObject.iterationdepth = iterationdepth; + } + + + public int getNumberofanswers() { + return numberofanswers; + } + + + public void setNumberofanswers(int numberofanswers) { + SparqlObject.numberofanswers = numberofanswers; + } + + /* + * ############################## + * + */ + /* + * "Main" Method of this Class. + * + */ + public void create_Sparql_query(String question) throws JWNLException, IOException{ + //create_Sparql_query_new(string); + + ArrayList<String> lstquery = new ArrayList<String>(); + lstquery=getQuery(question); + + //if(!lstquery.isEmpty()){ + //for each querry + for(String query : lstquery){ + + /* + * ################################################################################################# + */ + //only testfunction to save the generated queries in the tmp-folder + if(getIterationdepth()==-1){ + String tmp = new String(); + String s = null; + BufferedReader in = null; + + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/tmp/testresult.txt" ) ) ); + while( null != (s = in.readLine()) ) { + tmp=tmp+"\n"+s; + } + } 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(); + } + } + + String out=null; + if (query=="" || query==" ") query="Could not parse"; + out=tmp + "\n" + question + ":\n"+query+"\n"; + + BufferedWriter outfile = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream( "/tmp/testresult.txt" ) ) ); + + outfile.write(out); + outfile.close(); + + } + + /* + * ################################################################################################# + */ + //Iteration 0 + if(getIterationdepth()==0){ + String tmp = new String(); + String s = null; + BufferedReader in = null; + + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/tmp/answer.txt" ) ) ); + while( null != (s = in.readLine()) ) { + tmp=tmp+"\n"+s; + } + } 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(); + } + } + String answer; + answer=sendServerQuestionRequest(query); + //System.out.println(query); + System.out.println("Antwort: " + answer); + String out=tmp + "\n" + question + ":\n"+answer+"\n"; + + BufferedWriter outfile = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream( "/tmp/answer.txt" ) ) ); + + outfile.write(out); + outfile.close(); + } + /* + * ################################################################################################# + */ + //Iterration 1 + if(getIterationdepth()==1){ + + } + /* + * ################################################################################################# + */ + //Iterration 2 + if(getIterationdepth()==2){ + + } + } + } + + // string=string.replaceAll("?", ""); + //create_Sparql_query_old(string); + + // } + + /** + * Method gets a String and takes the information from the templator to creat a Sparql query. + * @param question question in natural language + * @return ArrayList of Sparql queries. + */ + private ArrayList<String> getQuery(String question) { + ArrayList<String> lstquery = new ArrayList<String>(); + Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); + for (BasicQueryTemplate temp : querytemps) { + + /*System.out.println("temp.getQt();" + temp.getQt()); + System.out.println("temp.getSelTerms();" + temp.getSelTerms()); + System.out.println("temp.getVariablesAsStringList();" + temp.getVariablesAsStringList()); + System.out.println("temp.getConditions();" + temp.getConditions()); + System.out.println("temp.getSlots();" + temp.getSlots());*/ + + String query; + String selTerms =""; + for(SPARQL_Term terms :temp.getSelTerms()) selTerms=selTerms+(terms.toString())+" "; + + String conditions = ""; + for(Path condition: temp.getConditions()) conditions=conditions+(condition.toString())+"."; + + String filters=""; + for(SPARQL_Filter tmp : temp.getFilters()) filters=filters+tmp+" "; + //System.out.println("\n"); + System.out.println("\n"); + query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" { "+ conditions.replace("--","") + "}"+filters; + + String[] slots= null; + for(Slot slot : temp.getSlots()){ + + //hier muss dann noch die abfrage aus der hm raus, also das direkt die uri eingebettet wird. + String tmp= slot.toString(); + tmp= tmp.replace("UNSPEC",""); + tmp= tmp.replace("RESOURCE",""); + tmp= tmp.replace("{",""); + tmp= tmp.replace("}",""); + tmp=tmp.replace(" ",""); + //System.out.println(tmp); + //damit auch wirklich nur ?y und nicht ?y0 ersetzt wird, einfach nach "?y " suchen. + String[] array = tmp.split(":"); + String replace; + if(array[0].length()<2)replace = "?"+array[0]+" "; + else replace="?"+array[0]; + //System.out.println("replace: " + replace); + //hier dann den hm wert von array[1] eintragen + query=query.replace(replace, "<"+hm.get(array[1].toLowerCase())+">"); + + } + //System.out.println("Query: "+query); + lstquery.add(query); + + } + + return lstquery; + } + + + + + private void doIteration(String string1, String string2) throws JWNLException{ long startTime = System.currentTimeMillis(); @@ -70,13 +297,13 @@ e.printStackTrace(); } - System.out.println("Start Iterating Wordnet with "+string1+" and deept of "+iteration_deept); + System.out.println("Start Iterating Wordnet with "+string1+" and deept of "+explorationdepthwordnet); ArrayList<String> semantics=new ArrayList<String>(); ArrayList<String> tmp_semantics=new ArrayList<String>(); ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); semantics.add(string1); tmp_semantics=semantics; - for(int i=0;i<=iteration_deept;i++){ + for(int i=0;i<=explorationdepthwordnet;i++){ try { tmp_semantics=getSemantics(tmp_semantics); @@ -119,142 +346,9 @@ System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); } - - private void create_Sparql_query_new(String string) throws JWNLException{ - String[] array_new=new String[4]; - array_new=getyy0AndQuery(string); - if(!array_new[0].contains("error")){ - String result=null; - - //Version 1 - result=sendServerQuestionRequest(array_new[0]); - if(result!="noanswer"){ - // System.out.println("Version1"); - System.out.println(result); - } - else{ - doIteration(array_new[3],array_new[2]); - } - //Version2 - /* else{ - result=sendServerQuestionRequest(array_new[1]); - if(result!="noanswer"){ - System.out.println("Version2"); - System.out.println(result); - } - }*/ - } - - } - public void create_Sparql_query(String string) throws JWNLException{ - //create_Sparql_query_new(string); - - Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(string.toLowerCase()); - for (BasicQueryTemplate temp : querytemps) { - - System.out.println("temp.getQt();" + temp.getQt()); - System.out.println("temp.getSelTerms();" + temp.getSelTerms()); - System.out.println("temp.getVariablesAsStringList();" + temp.getVariablesAsStringList()); - System.out.println("temp.getConditions();" + temp.getConditions()); - System.out.println("temp.getSlots();" + temp.getSlots()); - - String query; - SPARQL_Term selTerms = null; - for(SPARQL_Term terms :temp.getSelTerms()) selTerms=terms; - - Path conditions = null; - for(Path condition: temp.getConditions()) conditions=condition; - - - - //System.out.println("\n"); - System.out.println("\n"); - query=temp.getQt().toString()+" "+selTerms.toString()+" { "+ conditions.toString().replace("--","") + "} "; - - String[] slots= null; - for(Slot slot : temp.getSlots()){ - - //hier muss dann noch die abfrage aus der hm raus, also das direkt die uri eingebettet wird. - String tmp= slot.toString(); - tmp= tmp.replace("UNSPEC",""); - tmp= tmp.replace("RESOURCE",""); - tmp= tmp.replace("{",""); - tmp= tmp.replace("}",""); - tmp=tmp.replace(" ",""); - //System.out.println(tmp); - //damit auch wirklich nur ?y und nicht ?y0 ersetzt wird, einfach nach "?y " suchen. - String[] array = tmp.split(":"); - String replace; - if(array[0].length()<2)replace = "?"+array[0]+" "; - else replace="?"+array[0]; - //System.out.println("replace: " + replace); - //hier dann den hm wert von array[1] eintragen - query=query.replace(replace, "<"+hm.get(array[1])+">"); - - } - System.out.println(query); - } - // string=string.replaceAll("?", ""); - //create_Sparql_query_old(string); - - } - - - - - private String[] getyy0AndQuery(String string) { - String teststring=""; - String[] return_array = new String[4]; - Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(string); - for (BasicQueryTemplate temp : querytemps) { - teststring=temp.toString(); - System.out.println(teststring); - } - teststring=teststring.replace("\n", ""); - String[] array_tmp=teststring.split("\\}"); - - //only for y and y0 - String sparqlquery=""; - String y=""; - String y0=""; - for(String i : array_tmp){ - i=i.replace(" ", ""); - String[] tmp=null; - if(i.contains("SELECT")) sparqlquery=i.concat("}"); - if(i.contains("y0")){ - y0=i; - tmp=y0.split("\\{"); - y0=tmp[1];} - if(i.contains("y")&& !i.contains("y0")){ - y=i; - tmp=y.split("\\{"); - y=tmp[1]; - } - } - String uri1=hm.get(y0); - String uri2=hm.get(y); - if(uri1!=null && uri2!=null){ - uri1=uri1.replace("Category:", ""); - uri1=uri1.replace("category:", ""); - uri2=uri2.replace("Category:", ""); - uri2=uri2.replace("category:", ""); - String anfrage1; - anfrage1="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri1+"> <"+uri2+"> ?x.}"; - String anfrage2; - anfrage2="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri2+"> <"+uri1+"> ?x.}"; - return_array[0]=anfrage1; - return_array[1]=anfrage2; - return_array[2]=y0; - return_array[3]=y; - } - else{ - return_array[0]="error"; - } - return return_array; - - } + private static ArrayList<String> getSemantics (ArrayList<String> semantics) throws IOException, JWNLException { ArrayList<String> result = new ArrayList<String>(); for(String id :semantics){ @@ -294,12 +388,11 @@ counter=counter+1;} } while (str != null); - if(result.isEmpty()) System.out.println("HALOSHSS"); - //TODO:if counter = 5 or less, there is an empty answer from the Server! Still to Verify! - if(counter<=5){ + //TODO:if counter = 5 or less, there is an empty answer from the Server! Still to Verify! + /* if(counter<=5){ System.out.println("Empty Answer from Server"); return "noanswer"; - } + }*/ } catch (MalformedURLException e) { System.out.println("Must enter a valid URL"); } catch (IOException e) { @@ -324,6 +417,7 @@ string=string.replace(" ",""); string=string.replace("</td>",""); string=string.replace("<td>",""); + string=string.replace("<th>callret-0</th>", ""); return string; } 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 2011-10-29 20:29:02 UTC (rev 3340) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-10-30 11:45:33 UTC (rev 3341) @@ -69,18 +69,52 @@ System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); boolean schleife=true; + boolean doing = true; while(schleife==true){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line; + doing = true; try { System.out.println("\n\n"); System.out.println("Please enter a Question:"); line = in.readLine(); - if(line.contains("quit")){ + if(line.contains(":q")){ schleife=false; System.out.println("Bye!"); + System.exit(0); } - if(line.contains("text")&& schleife==true){ + 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")); @@ -96,8 +130,7 @@ System.out.println(s); anzahl++; //get each line and send it to the parser - s=s.replace("?",""); - sparql.create_Sparql_query(s.toLowerCase()); + sparql.create_Sparql_query(s); } long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -105,14 +138,9 @@ System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); } - else if(schleife==true){ + else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); - line=line.replace("?",""); - /* Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(line); - for (BasicQueryTemplate temp : querytemps) { - System.out.println(temp.toString()); - }*/ - sparql.create_Sparql_query(line.toLowerCase()); + sparql.create_Sparql_query(line); long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-10 13:01:32
|
Revision: 3392 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3392&view=rev Author: sebastianwtr Date: 2011-11-10 13:01:22 +0000 (Thu, 10 Nov 2011) Log Message: ----------- [tbsl] fixed some errors and programmed iteration depth 1 Modified 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/SparqlObject.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/test_vergleich.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/sax/ParseXmlHtml.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java Modified: 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 2011-11-10 08:15:41 UTC (rev 3391) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -15,8 +15,12 @@ public class GetRessourcePropertys { public ArrayList<String> getPropertys(String element) throws IOException{ + try{ sendServerPropertyRequest(element); return do_parsing("answer_property"); + } catch (Exception e){ + return null; + } } Added: 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 (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Levenshtein.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -0,0 +1,88 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + + +import java.lang.Math; +import java.math.BigDecimal; + +public class Levenshtein { + + + //http://de.wikipedia.org/wiki/Levenshtein-Distanz + public double nld(String orig, String eing){ + //int result = diff(orig,eing); + int result = computeLevenshteinDistance(orig,eing); + int length=Math.max(orig.length(),eing.length()); + + + //if distance between both is zero, then the NLD must be one + if(result==0 ){ + return 1; + } + else{ + BigDecimal m = new BigDecimal(result); + BigDecimal n = new BigDecimal(length); + + BigDecimal c = new BigDecimal(0); + c=m.divide(n, 5, BigDecimal.ROUND_FLOOR); + + return c.doubleValue(); + } + + } + + public int diff(String orig, String eing) { + + int matrix[][] = new int[orig.length() + 1][eing.length() + 1]; + for (int i = 0; i < orig.length() + 1; i++) { + matrix[i][0] = i; + } + for (int i = 0; i < eing.length() + 1; i++) { + matrix[0][i] = i; + } + for (int a = 1; a < orig.length() + 1; a++) { + for (int b = 1; b < eing.length() + 1; b++) { + int right = 0; + if (orig.charAt(a - 1) != eing.charAt(b - 1)) { + right = 1; + } + int mini = matrix[a - 1][b] + 1; + if (matrix[a][b - 1] + 1 < mini) { + mini = matrix[a][b - 1] + 1; + } + if (matrix[a - 1][b - 1] + right < mini) { + mini = matrix[a - 1][b - 1] + right; + } + matrix[a][b] = mini; + } + } + + return matrix[orig.length()][eing.length()]; + } + + + //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()]; + } +} 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 2011-11-10 08:15:41 UTC (rev 3391) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -17,6 +17,7 @@ import net.didion.jwnl.JWNLException; +import org.dllearner.algorithm.tbsl.exploration.sax.ParseXmlHtml; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; import org.dllearner.algorithm.tbsl.sparql.Path; @@ -36,22 +37,26 @@ static int explorationdepthwordnet=1; static int iterationdepth =0; static int numberofanswers=1; + static double LvenstheinMin = 0.95; static WordNet wordnet; BasicTemplator btemplator; Templator templator; - HashMap<String, String> hm; + private static HashMap<String, String> hm = new HashMap<String, String>(); //Konstruktor - public SparqlObject(HashMap<String, String> hm_new) throws MalformedURLException{ + public SparqlObject() throws MalformedURLException{ wordnet = new WordNet(); - hm=hm_new; + //hm=hm_new; + hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); + hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm); System.out.println("Loading SPARQL Templator"); btemplator = new BasicTemplator(); templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); setExplorationdepthwordnet(1); - setIterationdepth(0); + //eigentlich immer mit 0 initialisieren + setIterationdepth(1); setNumberofanswers(1); } @@ -101,17 +106,23 @@ public void create_Sparql_query(String question) throws JWNLException, IOException{ //create_Sparql_query_new(string); - ArrayList<String> lstquery = new ArrayList<String>(); + ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); + long startParsingTime = System.currentTimeMillis(); lstquery=getQuery(question); + long endParsingTime = System.currentTimeMillis(); + System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); + ArrayList<String> final_answer = new ArrayList<String>(); //if(!lstquery.isEmpty()){ //for each querry - for(String query : lstquery){ + for(ArrayList<String> querylist : lstquery){ /* * ################################################################################################# */ //only testfunction to save the generated queries in the tmp-folder + String query=""; + query=querylist.get(0).toString(); if(getIterationdepth()==-1){ String tmp = new String(); String s = null; @@ -139,7 +150,7 @@ } String out=null; - if (query=="" || query==" ") query="Could not parse"; + if (query=="" || query==" "||query.length()==0) query="Could not parse"; out=tmp + "\n" + question + ":\n"+query+"\n"; BufferedWriter outfile = new BufferedWriter( @@ -182,7 +193,9 @@ } String answer; answer=sendServerQuestionRequest(query); - System.out.println(query); + final_answer.add(answer); + /*System.out.println(query); + if (query=="" || query==" "||query.length()==0) answer="Could not parse"; System.out.println("Antwort: " + answer); String out=tmp + "\n" + "Question: "+question + "\n"+"Query: " + query +"\n Anwer: "+answer+"\n\n##############################"; @@ -191,7 +204,7 @@ new FileOutputStream( "/tmp/answer.txt" ) ) ); outfile.write(out); - outfile.close(); + outfile.close(); */ } /* * ################################################################################################# @@ -199,6 +212,134 @@ //Iterration 1 if(getIterationdepth()==1){ + //asking server + String answer; + answer=sendServerQuestionRequest(query); + + //if Emty answer, get properties an look up the right property with levensthein + if(answer.contains("EmtyAnswer")){ + //TODO: get all information from the query + //TODO: maybe put the query + information in an array list of arraylist. each arraylist contains the query, the variables and the uris. Then iterate over the List and get the query for sending to server + String rescource=""; + + //get the resource of the query. always the last Item in the array! + //Funktioniert! + String resource_tmp=""; + int tmp_length=querylist.size(); + resource_tmp=querylist.get(tmp_length-1); + String[] array_tmp = resource_tmp.split(":"); + rescource=array_tmp[1]; + + + //the property we are looking for is always the second last in the array! + //Funktioniert! + String property_to_compare_with=""; + tmp_length=querylist.size(); + //second last + property_to_compare_with=querylist.get(tmp_length-2); + array_tmp = property_to_compare_with.split(":"); + property_to_compare_with=array_tmp[1]; + //System.out.println("property_to_compare_with: "+property_to_compare_with); + + + //contains uri AND string, every second is the string + //Funktioniert + ArrayList<String> properties = new ArrayList<String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; + try { + //using uri now, not the string + properties=property.getPropertys(hm.get(rescource.toLowerCase())); + if (properties==null){ + final_answer.add("Error in getting Properties\n"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + final_answer.add("Error in getting Properties\n"); + goOnAfterProperty=false; + + } + if(goOnAfterProperty==true){ + //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + Levenshtein levensthein = new Levenshtein(); + ArrayList<String> new_queries= new ArrayList<String>(); + for(int i =1; i<=properties.size()-2;i=i+2){ + //double tmp=levensthein.nld(property_to_compare_with.toLowerCase(), properties.get(i).toLowerCase()); + double tmp=levensthein.computeLevenshteinDistance(property_to_compare_with.toLowerCase(), properties.get(i).toLowerCase()); + //create new query + //System.out.println(tmp); + //if(tmp>=LvenstheinMin){ + if(tmp<=3.0){ + //System.out.println(tmp); + //alte property uri mit neuer ersetzen: + String query_tmp=query; + query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(i-1)); + //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); + new_queries.add(query_tmp); + } + + } + + System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + semantics.add(property_to_compare_with); + tmp_semantics=semantics; + Boolean goOnAfterWordnet = true; + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + goOnAfterWordnet=false; + final_answer.add("Error in searching Wordnet\n"); + + } + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + + } + + if(goOnAfterWordnet==true){ + // ArrayList<String> new_queries= new ArrayList<String>(); + + //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) + for(int h=1;h<properties.size()-2;h=h+2){ + for(String b : semantics){ + //System.out.println(properties.get(h)); + //System.out.println(b); + if(properties.get(h).contains(b.toLowerCase())){ + if(!result_SemanticsMatchProperties.contains(properties.get(h))){ + //create new query + result_SemanticsMatchProperties.add(properties.get(h)); + String query_tmp=query; + query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(h-1)); + //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); + new_queries.add(query_tmp); + } + } + } + } + + for(String bla : new_queries){ + String answer_tmp; + answer_tmp=sendServerQuestionRequest(bla); + if(!answer_tmp.contains("EmtyAnswer")){ + final_answer.add(answer_tmp); + } + } + } + } + } + } /* * ################################################################################################# @@ -208,6 +349,46 @@ } } + + BufferedReader in = null; + + String tmp=""; + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/tmp/answer" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + tmp=tmp+"\n"+s; + } + } 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(); + } + } + + String out=""; + for(String answer : final_answer){ + + out=out+ "\n"+answer+"\n"; + + } + System.out.println(question); + System.out.println(out); + BufferedWriter outfile = new BufferedWriter( + new OutputStreamWriter( + new FileOutputStream( "/tmp/answer" ) ) ); + + outfile.write(tmp+"\n"+question+" :\n"+out); + outfile.close(); } // string=string.replaceAll("?", ""); @@ -220,8 +401,8 @@ * @param question question in natural language * @return ArrayList of Sparql queries. */ - private ArrayList<String> getQuery(String question) { - ArrayList<String> lstquery = new ArrayList<String>(); + private ArrayList<ArrayList<String>> getQuery(String question) { + ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); for (BasicQueryTemplate temp : querytemps) { @@ -230,7 +411,8 @@ System.out.println("temp.getVariablesAsStringList();" + temp.getVariablesAsStringList()); System.out.println("temp.getConditions();" + temp.getConditions()); System.out.println("temp.getSlots();" + temp.getSlots());*/ - + ArrayList<String> lstquerynew = new ArrayList<String>(); + ArrayList<String> lstquerupsidedown = new ArrayList<String>(); String query; String selTerms =""; for(SPARQL_Term terms :temp.getSelTerms()) selTerms=selTerms+(terms.toString())+" "; @@ -270,7 +452,6 @@ String[] slots= null; for(Slot slot : temp.getSlots()){ - //hier muss dann noch die abfrage aus der hm raus, also das direkt die uri eingebettet wird. String tmp= slot.toString(); tmp= tmp.replace("UNSPEC",""); tmp= tmp.replace("RESOURCE",""); @@ -300,9 +481,25 @@ query_upside_down=query_upside_down.replace(replace, "<"+hm_result+">"); } + lstquerupsidedown.add(query_upside_down); + lstquerynew.add(query); + + //slots hinzufügen + for(Slot slot : temp.getSlots()){ + String tmp= slot.toString(); + tmp= tmp.replace("UNSPEC",""); + tmp= tmp.replace("RESOURCE",""); + tmp= tmp.replace("{",""); + tmp= tmp.replace("}",""); + tmp=tmp.replace(" ",""); + lstquerupsidedown.add(tmp); + lstquerynew.add(tmp); + } //System.out.println("Query: "+query); - lstquery.add(query); - lstquery.add(query_upside_down); + /*lstquery.add(query); + lstquery.add(query_upside_down);*/ + lstquery.add(lstquerynew); + lstquery.add(lstquerupsidedown); } @@ -455,6 +652,9 @@ string=string.replace("<td>",""); string=string.replace("<th>callret-0</th>", ""); string=string.replace("<th>y</th>",""); + while (string.contains(" ")) string=string.replace(" ",""); + if (string.length()==0) string="EmtyAnswer"; + //System.out.println("Stringlänge: "+string.length()); return string; } 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 2011-11-10 08:15:41 UTC (rev 3391) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -31,7 +31,7 @@ */ public class exploration_main { - private static HashMap<String, String> hm = new HashMap<String, String>(); + //private static HashMap<String, String> hm = new HashMap<String, String>(); private static String qaldEntity2="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fc+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fc+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout="; private static String qaldEntity1="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fx+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fx+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout="; /** @@ -50,20 +50,20 @@ System.out.println("Start Indexing"); //For testing! - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/ressource/sparql_zwei",hm); - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/ressource/sparql_eins",hm); + //hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); + //hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm); - + //30% Ram /* * For real use! */ - /* hm=ParseXmlHtml.parse_xml((getEntity(qaldEntity2,"/tmp/qaldEntity2")),hm); + /*hm=ParseXmlHtml.parse_xml((getEntity(qaldEntity2,"/tmp/qaldEntity2")),hm); System.out.println("Entity2 done"); hm=ParseXmlHtml.parse_xml((getEntity(qaldEntity1,"/tmp/qaldEntity1")),hm); System.out.println("Entity1 done");*/ System.out.println("Done with indexing\n"); System.out.println("Start generating Wordnet Dictionary"); - SparqlObject sparql = new SparqlObject(hm); + SparqlObject sparql = new SparqlObject(); System.out.println("Generating Wordnet Dictionary Done"); long stopInitTime = System.currentTimeMillis(); System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); Modified: 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/exploration_main/test_vergleich.java 2011-11-10 08:15:41 UTC (rev 3391) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/test_vergleich.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -9,6 +9,7 @@ import java.net.URL; import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Levenshtein; import org.dllearner.algorithm.tbsl.exploration.sax.MySaxParser; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/sax/ParseXmlHtml.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/sax/ParseXmlHtml.java 2011-11-10 08:15:41 UTC (rev 3391) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/sax/ParseXmlHtml.java 2011-11-10 13:01:22 UTC (rev 3392) @@ -5,10 +5,15 @@ import java.util.HashMap; public class ParseXmlHtml { + + //TODO: zweite Hashmap in der als Key (barack,Obama) auf die Value barack Obama verweißt + //TODO: Rückgabewert in List<Map<String, String>> listOfMaps = new ArrayList<Map<String, String>>(); ändern und dann beide hashmaps übergeben und dann hm aus dem Funktionsheader nehmen + public static HashMap<String, String> parse_xml(String dateiname, HashMap<String, String> hm) { ArrayList<String> indexObject = null; File file = new File(dateiname); + HashMap<String, String> hm_new = new HashMap<String, String>(); try { MySaxParser parser = new MySaxParser(file); @@ -18,11 +23,18 @@ { hm.put((indexObject.get(i+1)).toLowerCase(), indexObject.get(i)); }*/ + int zaehler=0; for (int i = 1; i < indexObject.size(); i=i+2) { hm.put((indexObject.get(i)).toLowerCase(), indexObject.get(i-1)); + String[] tmp_array = indexObject.get(i).toLowerCase().split(" "); + if(tmp_array.length>=2) { + for(String tmp : tmp_array)hm_new.put(tmp.toLowerCase(), indexObject.get(i-1)); + } + zaehler=zaehler+1; } indexObject.clear(); + System.out.println("Anzahl: "+zaehler); } catch (Exception ex) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-11-24 18:11:08
|
Revision: 3437 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3437&view=rev Author: sebastianwtr Date: 2011-11-24 18:11:01 +0000 (Thu, 24 Nov 2011) Log Message: ----------- [tbsl.exploration] added sqlite function etc Modified Paths: -------------- 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/exploration_main/exploration_main.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 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 2011-11-24 12:19:01 UTC (rev 3436) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; import java.io.BufferedReader; + import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -13,6 +14,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import net.didion.jwnl.JWNLException; @@ -28,8 +30,15 @@ import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import org.dllearner.algorithm.tbsl.templator.Templator; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + public class SparqlObject { //global Variable dict @@ -41,19 +50,25 @@ static WordNet wordnet; BasicTemplator btemplator; Templator templator; - private static HashMap<String, String> hm = new HashMap<String, String>(); +/* private static HashMap<String, String> hm = new HashMap<String, String>(); + private static HashMap<String, String> hm_new = new HashMap<String, String>();*/ + private static mySQLDictionary myindex; //Konstruktor - public SparqlObject() throws MalformedURLException{ + public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ wordnet = new WordNet(); //hm=hm_new; - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); - hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm); + /*hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); + hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm);*/ System.out.println("Loading SPARQL Templator"); btemplator = new BasicTemplator(); templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); + System.out.println("Start Indexing Wikipedia URI's"); + myindex = new mySQLDictionary(); + + System.out.println("Done:Indexing Wikipedia URI's"); setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren setIterationdepth(1); @@ -103,7 +118,7 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(String question) throws JWNLException, IOException{ + public void create_Sparql_query(String question) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); @@ -215,7 +230,7 @@ //asking server String answer; answer=sendServerQuestionRequest(query); - + System.out.println(query); //if Emty answer, get properties an look up the right property with levensthein if(answer.contains("EmtyAnswer")){ //TODO: get all information from the query @@ -249,7 +264,8 @@ Boolean goOnAfterProperty = true; try { //using uri now, not the string - properties=property.getPropertys(hm.get(rescource.toLowerCase())); + //properties=property.getPropertys(hm.get(rescource.toLowerCase())); + properties=property.getPropertys(getUriFromIndex(rescource.toLowerCase(),0)); if (properties==null){ final_answer.add("Error in getting Properties\n"); goOnAfterProperty=false; @@ -276,7 +292,8 @@ //System.out.println(tmp); //alte property uri mit neuer ersetzen: String query_tmp=query; - query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(i-1)); + //query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(i-1)); + query_tmp=query_tmp.replace(getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties.get(i-1)); //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); new_queries.add(query_tmp); } @@ -328,7 +345,9 @@ //create new query result_SemanticsMatchProperties.add(properties.get(h)); String query_tmp=query; - query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(h-1)); + + //query_tmp=query_tmp.replace(hm.get(property_to_compare_with.toLowerCase()),properties.get(h-1)); + query_tmp=query_tmp.replace(getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties.get(h-1)); //System.out.println("hm.get(property_to_compare_with.toLowerCase(): " + hm.get(property_to_compare_with.toLowerCase())); new_queries.add(query_tmp); } @@ -402,13 +421,16 @@ //create_Sparql_query_old(string); // } + + /** * Method gets a String and takes the information from the templator to creat a Sparql query. * @param question question in natural language * @return ArrayList of Sparql queries. + * @throws SQLException */ - private ArrayList<ArrayList<String>> getQuery(String question) { + private ArrayList<ArrayList<String>> getQuery(String question) throws SQLException { ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); for (BasicQueryTemplate temp : querytemps) { @@ -423,6 +445,7 @@ String query; String selTerms =""; for(SPARQL_Term terms :temp.getSelTerms()) selTerms=selTerms+(terms.toString())+" "; + System.out.println(selTerms); String conditions = ""; for(Path condition: temp.getConditions()) conditions=conditions+(condition.toString())+"."; @@ -474,7 +497,9 @@ //System.out.println("replace: " + replace); //hier dann den hm wert von array[1] eintragen - String hm_result=hm.get(array[1].toLowerCase()); + + //String hm_result=hm.get(array[1].toLowerCase()); + String hm_result=getUriFromIndex(array[1].toLowerCase(),0); try { if(hm_result.contains("Category:")) hm_result=hm_result.replace("Category:",""); @@ -515,78 +540,40 @@ - - - private void doIteration(String string1, String string2) throws JWNLException{ - long startTime = System.currentTimeMillis(); - - String string2_uri; - string2_uri=hm.get(string2); - string2_uri=string2_uri.replace("Category:", ""); - string2_uri=string2_uri.replace("category:", ""); - System.out.println("Get Propertys of "+string2); - - //contains uri AND string, every second is the string - ArrayList<String> properties = new ArrayList<String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); - try { - //using uri now, not the string - properties=property.getPropertys(hm.get(string2)); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + /** + * + * @param string + * @param fall 1 Property 0 no Property + * @return + * @throws SQLException + */ + private String getUriFromIndex(String string, int fall) throws SQLException{ + String result=null; + if(fall==0){ + //result=hm.get(string.toLowerCase()); + //if(result==null)result=myindex.getURI(string); + result=myindex.getResourceURI(string.toLowerCase()); + if(result==null)result=myindex.getPropertyURI(string.toLowerCase()); } - - System.out.println("Start Iterating Wordnet with "+string1+" and deept of "+explorationdepthwordnet); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(string1); - tmp_semantics=semantics; - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semantics=getSemantics(tmp_semantics); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - + if(fall==1){ + /*result=hm.get(string.toLowerCase()); + if(result==null)result=myindex.getURI(string); + if(result==null)result="http://dbpedia.org/property/"+string.toLowerCase();*/ + //should be alway property an not resource + //result=result.replace("resource", "property"); + result=myindex.getPropertyURI(string.toLowerCase()); + if(result==null){ + result=myindex.getResourceURI(string.toLowerCase()); + result=result.replace("resource", "property"); } - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); - } - - } - long endTime = System.currentTimeMillis(); - System.out.println("Getting Properties and Semantics took "+(endTime-startTime) +" ms\n"); - - //TODO: Try, if it works, if you use only one loop: (b.lowerCase).contains(properties.get(h)) - for(int h=1;h<properties.size()-2;h=h+2){ - for(String b : semantics){ - //System.out.println(properties.get(h)); - //System.out.println(b); - if(properties.get(h).contains(b.toLowerCase())){ - if(!result_SemanticsMatchProperties.contains(properties.get(h))) - result_SemanticsMatchProperties.add(properties.get(h)); - } - } + } - for(String b : result_SemanticsMatchProperties){ - string1=b.toLowerCase(); - String anfrage; - String string1_uri; - string1_uri=hm.get(string1); - if(string1_uri!=null){ - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+string2_uri+"> <"+string1_uri+"> ?x.}"; - System.out.println("Answer with the property \" " + b + "\" :\n"+sendServerQuestionRequest(anfrage)); - } - } - long endTime2 = System.currentTimeMillis(); - System.out.println("Getting Properties, Semantics and Answer from server took "+(endTime2-startTime) +" ms"); + + if(result==null) return "http://dbpedia.org/property/"+string.toLowerCase(); + else return result; } - + private static ArrayList<String> getSemantics (ArrayList<String> semantics) throws IOException, JWNLException { @@ -612,6 +599,7 @@ private String sendServerQuestionRequest(String query){ //SPARQL-Endpoint of Semantic Computing Group String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + System.out.println(tmp); URL url; InputStream is; InputStreamReader isr; @@ -711,8 +699,14 @@ return query; } + + + + } + + /** * Cluster function */ Added: 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 (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -0,0 +1,309 @@ +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; + +public class mySQLDictionary { + private Connection conn; + + public mySQLDictionary() throws ClassNotFoundException, SQLException { + // TODO Auto-generated constructor stub + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:"); + createIndexPropertys(); + createIndexResource(); + + //optional!! + //createIndexWikipedia(); + + } + +private String createSimpleHashKey(String string){ + string = string.replace("!",""); + string = string.replace(":",""); + string = string.replace("/",""); + string = string.replace("\\",""); + string = string.replace("?",""); + string = string.replace(":",""); + + string = string.replace("a","1"); + string = string.replace("b","2"); + string = string.replace("c","3"); + string = string.replace("d","4"); + string = string.replace("e","5"); + string = string.replace("f","6"); + string = string.replace("g","7"); + string = string.replace("h","8"); + string = string.replace("i","9"); + string = string.replace("j","10"); + string = string.replace("k","11"); + string = string.replace("l","12"); + string = string.replace("m","13"); + string = string.replace("n","14"); + string = string.replace("o","15"); + string = string.replace("p","16"); + string = string.replace("q","17"); + string = string.replace("r","18"); + string = string.replace("s","19"); + string = string.replace("t","20"); + string = string.replace("u","21"); + string = string.replace("v","22"); + string = string.replace("w","23"); + string = string.replace("x","24"); + string = string.replace("y","25"); + string = string.replace("z","26"); + string = string.replace("ä","0"); + string = string.replace("ö","0"); + string = string.replace("ü","0"); + string = string.replace("?","0"); + string = string.replace(" ","0"); + return string; + + +} + + public String getResourceURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from resource 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 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; + } + + + } + + + 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"); + //Statement stat = conn.createStatement(); + /* long start = System.currentTimeMillis(); + // zu messender Code + + ResultSet rs = stat.executeQuery("select * from people where name='kornyval';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + start = System.currentTimeMillis(); + // zu messender Code + + rs = stat.executeQuery("select * from people where name='barack obama';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + rs = stat.executeQuery("select * from people where name='kornyval';"); + while (rs.next()) + { + System.out.println("name = " + rs.getString("name")); + System.out.println("job = " + rs.getString("occupation")); + } + System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); + + + rs.close();*/ + // conn.close(); + } +private void createIndexPropertys() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test"); + Class.forName( "org.sqlite.JDBC" ); + conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ + 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; + // conn.setAutoCommit(false); + 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[1]); + prep.setString(2, tmp_array[0]); + 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"); + } + + } + } + } 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 createIndexResource() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + 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; + // conn.setAutoCommit(false); + 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[1]); + prep.setString(2, tmp_array[0]); + 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"); + } + + } + } + } 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"); + + } + +} \ No newline at end of file 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 2011-11-24 12:19:01 UTC (rev 3436) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-11-24 18:11:01 UTC (rev 3437) @@ -13,7 +13,11 @@ import net.didion.jwnl.JWNLException; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; -import org.dllearner.algorithm.tbsl.exploration.sax.ParseXmlHtml; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /* * @@ -21,6 +25,18 @@ * in Eclipse Run -> RunConfigurations -> Arguments -> VM Arguments -> -Xmx1024m */ +/* + * + * + * for pom.xml file + * <dependencies> + <dependency> + <groupId>org.xerial</groupId> + <artifactId>sqlite-jdbc</artifactId> + <version>3.6.16</version> + </dependency> + </dependencies> + */ // Sax example from http://www.bennyn.de/programmierung/java/java-xml-sax-parser.html /* @@ -39,14 +55,15 @@ * @throws IOException * @throws JWNLException * @throws InterruptedException + * @throws ClassNotFoundException + * @throws SQLException */ - public static void main(String[] args) throws IOException, JWNLException, InterruptedException { + public static void main(String[] args) throws IOException, JWNLException, InterruptedException, ClassNotFoundException, SQLException { /** * Do the starting initializing stuff */ long startInitTime = System.currentTimeMillis(); - System.out.println("Start Indexing"); //For testing! @@ -168,5 +185,7 @@ return name; } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2011-12-08 09:01:19
|
Revision: 3489 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3489&view=rev Author: sebastianwtr Date: 2011-12-08 09:01:12 +0000 (Thu, 08 Dec 2011) Log Message: ----------- [tbsl exploration] start changing project into following steps 1) Direct matching using only the Templator 2) Matching with Levenshtein Distanz 3) Matching with wordnet Modified Paths: -------------- 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/exploration_main/exploration_main.java 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 2011-12-07 22:23:04 UTC (rev 3488) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-12-08 09:01:12 UTC (rev 3489) @@ -223,20 +223,32 @@ */ //Iterration 1 if(getIterationdepth()==1&&startIterating==true){ - + /* //4, because of query + three conditions for the simple case if(querylist.size()==4)final_answer=simpleIteration1Case(querylist, query); //if we have more conditions, we need to change the way of replacing the uris got from wordnet etc + if(querylist.size()>4)final_answer=complexeIteration1Case(querylist, query); + */ + + if(querylist.size()==4)final_answer=simpleLevinstheinIteration(querylist, query); + if(querylist.size()>4)final_answer=complexeLevinstheinIteration(querylist, query); + } /* * ################################################################################################# */ //Iterration 2 + /* + * Only Levensthein!!! + */ if(getIterationdepth()==2&&startIterating==true){ - + if(querylist.size()==4)final_answer=simpleWordnetIteration(querylist, query); + if(querylist.size()>4)final_answer=complexWordnetIteration(querylist, query); } + + } BufferedReader in = null; @@ -293,6 +305,626 @@ } + private ArrayList<String> simpleLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, + JWNLException { + //asking server + String answer; + ArrayList<String> final_answer=new ArrayList<String>(); + String resource=""; + String property_to_compare_with=""; + String sideOfProperty="LEFT"; + + + int tmpcounter=0; + for(String s : querylist){ + //we dont need the first one, because thats the query itself + tmpcounter=tmpcounter+1; + if(tmpcounter>=1){ + if(s.contains("LEFT")){ + sideOfProperty="LEFT"; + resource=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfProperty="RIGHT"; + resource=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_with=s.replace("PROPERTY",""); + } + + } + } + System.out.println("Property to compare:: "+ property_to_compare_with); + System.out.println("Resource: "+ resource); + //contains uri AND string, every second is the string + HashMap<String,String> properties = new HashMap<String, String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; + try { + /* + * TODO: Have to check now, if we need a right Property or a left one + */ + properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); + if (properties==null){ + //final_answer.add("Error in getting Properties\n"); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + + } + if(goOnAfterProperty==true){ + //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + double tmp=Levenshtein.computeLevenshteinDistance(property_to_compare_with.toLowerCase(), key); + + /* + * TODO: Implement Normalised levensthein + */ + if(tmp<=3.0){ + //alte property uri mit neuer ersetzen: + String query_tmp=query; + String test = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + //query_tmp=query_tmp.replace(test,properties.get(i-1)); + query_tmp=query_tmp.replace(test,value); + new_queries.add(query_tmp); + } + } + + + for(String anfrage : new_queries){ + String answer_tmp; + answer_tmp=sendServerQuestionRequest(anfrage); + System.out.println("Antwort vom Server: "+answer_tmp); + final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + } + } + + + return final_answer; +} + + private ArrayList<String> complexeLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, + JWNLException { + + /* + * in this case we need a inner and outer loop, because the properties are different from the resource or up side down + * Only for questions with two sets of conditions(s p o . s p o) + */ + + //asking server + String answer; + ArrayList<String> final_answer=new ArrayList<String>(); + String resourceOne=""; + String property_to_compare_withOne=""; + String resourceTwo=""; + String property_to_compare_withTwo=""; + String sideOfPropertyOne="LEFT"; + String sideOfPropertyTwo="LEFT"; + + + int tmpcounter=0; + for(String s : querylist){ + //we dont need the first one, because thats the query itself + tmpcounter=tmpcounter+1; + if(tmpcounter>=1&&tmpcounter<=4){ + if(s.contains("LEFT")){ + sideOfPropertyOne="LEFT"; + resourceOne=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfPropertyOne="RIGHT"; + resourceOne=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_withOne=s.replace("PROPERTY",""); + } + + } + if(tmpcounter>4){ + if(s.contains("LEFT")){ + sideOfPropertyOne="LEFT"; + resourceTwo=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfPropertyOne="RIGHT"; + resourceTwo=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_withTwo=s.replace("PROPERTY",""); + } + + } + } + HashMap<String,String> propertiesOne = new HashMap<String, String>(); + HashMap<String,String> propertiesTwo = new HashMap<String, String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; + try { + /* + * TODO: Have to check now, if we need a right Property or a left one + */ + propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + if (propertiesOne==null){ + //final_answer.add("Error in getting Properties\n"); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + + } + try { + /* + * TODO: Have to check now, if we need a right Property or a left one + */ + propertiesTwo=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyTwo); + if (propertiesOne==null){ + //final_answer.add("Error in getting Properties\n"); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + + } + + if(goOnAfterProperty==true){ + //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); + + for (Entry<String, String> entryOne : propertiesOne.entrySet()) { + + String queryOne=query; + String keyOne = entryOne.getKey(); + String valueOne = entryOne.getValue(); + double levnstheinDistanzeOne=Levenshtein.computeLevenshteinDistance(property_to_compare_withOne.toLowerCase(), keyOne); + if(levnstheinDistanzeOne<=3.0){ + String test = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); + queryOne=queryOne.replace(test,valueOne); + } + + for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { + String keyTwo = entryTwo.getKey(); + String valueTwo = entryTwo.getValue(); + double levnstheinDistanzeTwo=Levenshtein.computeLevenshteinDistance(property_to_compare_withTwo.toLowerCase(), keyTwo); + + /* + * TODO: Implement Normalised levensthein + */ + if(levnstheinDistanzeTwo<=3.0){ + //alte property uri mit neuer ersetzen: + String queryTwo=queryOne; + String test = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); + queryTwo=queryTwo.replace(test,valueTwo); + new_queries.add(queryTwo); + } + + } + } + + + + for(String anfrage : new_queries){ + String answer_tmp; + answer_tmp=sendServerQuestionRequest(anfrage); + System.out.println("Antwort vom Server: "+answer_tmp); + final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + } + + } + + return final_answer; +} + + private ArrayList<String> simpleWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, + JWNLException { + //asking server + String answer; + ArrayList<String> final_answer=new ArrayList<String>(); + + /* + * First try the original query on the server. If that doesnt work, try it with Iteration + */ + answer=sendServerQuestionRequest(query); + + if(answer.contains("EmtyAnswer")){ + + String resource=""; + String property_to_compare_with=""; + String sideOfProperty="LEFT"; + + + int tmpcounter=0; + for(String s : querylist){ + //we dont need the first one, because thats the query itself + tmpcounter=tmpcounter+1; + if(tmpcounter>=1){ + if(s.contains("LEFT")){ + sideOfProperty="LEFT"; + resource=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfProperty="RIGHT"; + resource=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_with=s.replace("PROPERTY",""); + } + + } + } + System.out.println("Property to compare:: "+ property_to_compare_with); + System.out.println("Resource: "+ resource); + //contains uri AND string, every second is the string + HashMap<String,String> properties = new HashMap<String, String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; + try { + /* + * TODO: Have to check now, if we need a right Property or a left one + */ + properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); + if (properties==null){ + //final_answer.add("Error in getting Properties\n"); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + + } + if(goOnAfterProperty==true){ + //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); + + System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + semantics.add(property_to_compare_with); + + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_=myindex.getWordnetHelp(property_to_compare_with); + if(_temp_==null){ + tmp_semantics=semantics; + } + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + } + Boolean goOnAfterWordnet = true; + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics); + if (tmp_semantics==null){ + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + } + + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); + + } + + } + + if(goOnAfterWordnet==true){ + + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + + for(String b : semantics){ + if(key.contains(b.toLowerCase())){ + if(!result_SemanticsMatchProperties.contains(key)){ + //create new query + result_SemanticsMatchProperties.add(key); + String query_tmp=query; + String test = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + query_tmp=query_tmp.replace(test,value); + System.out.println("New query after wordnet: "+ query_tmp); + new_queries.add(query_tmp); + } + } + } + } + + for(String bla : new_queries){ + String answer_tmp; + answer_tmp=sendServerQuestionRequest(bla); + System.out.println("Antwort vom Server: "+answer_tmp); + final_answer.add("Begin:\n"+bla +"\n"+answer_tmp+" \n End"); + } + } + } + } + + return final_answer; +} + + + private ArrayList<String> complexWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, + JWNLException { + //asking server + String answer; + ArrayList<String> final_answer=new ArrayList<String>(); + + /* + * First try the original query on the server. If that doesnt work, try it with Iteration + */ + answer=sendServerQuestionRequest(query); + + if(answer.contains("EmtyAnswer")){ + + String resourceOne=""; + String property_to_compare_withOne=""; + String resourceTwo=""; + String property_to_compare_withTwo=""; + String sideOfPropertyOne="LEFT"; + String sideOfPropertyTwo="LEFT"; + + + int tmpcounter=0; + for(String s : querylist){ + //we dont need the first one, because thats the query itself + tmpcounter=tmpcounter+1; + if(tmpcounter>=1&&tmpcounter<=4){ + if(s.contains("LEFT")){ + sideOfPropertyOne="LEFT"; + resourceOne=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfPropertyOne="RIGHT"; + resourceOne=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_withOne=s.replace("PROPERTY",""); + } + + } + if(tmpcounter>4){ + if(s.contains("LEFT")){ + sideOfPropertyOne="LEFT"; + resourceTwo=s.replace("LEFT",""); + } + if(s.contains("RIGHT")){ + sideOfPropertyOne="RIGHT"; + resourceTwo=s.replace("RIGHT",""); + } + if(s.contains("PROPERTY")){ + property_to_compare_withTwo=s.replace("PROPERTY",""); + } + + } + } + System.out.println("Property to compare:: "+ property_to_compare_withOne); + System.out.println("Resource: "+ resourceOne); + //contains uri AND string, every second is the string + HashMap<String,String> propertiesOne = new HashMap<String, String>(); + HashMap<String,String> propertiesTwo = new HashMap<String, String>(); + GetRessourcePropertys property = new GetRessourcePropertys(); + Boolean goOnAfterProperty = true; + try { + /* + * TODO: Have to check now, if we need a right Property or a left one + */ + propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); + if (propertiesOne==null){ + //final_answer.add("Error in getting Properties\n"); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + } + //System.out.println(properties); + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); + goOnAfterProperty=false; + + } + if(goOnAfterProperty==true){ + + /* + * #################################### Semantics One############################################# + */ + //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); + + System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); + ArrayList<String> semanticsOne=new ArrayList<String>(); + ArrayList<String> tmp_semanticsOne=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchPropertiesOne=new ArrayList<String>(); + semanticsOne.add(property_to_compare_withOne); + + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_One=myindex.getWordnetHelp(property_to_compare_withOne); + if(_temp_One==null){ + tmp_semanticsOne=semanticsOne; + } + else{ + semanticsOne.clear(); + semanticsOne.add(_temp_One); + tmp_semanticsOne=semanticsOne; + } + Boolean goOnAfterWordnet = true; + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semanticsOne=getSemantics(tmp_semanticsOne); + if (tmp_semanticsOne==null){ + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semanticsOne){ + if(!semanticsOne.contains(k)) semanticsOne.add(k); + } + } + + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); + + } + + + } + /* + * #################################### Semantics Two############################################# + */ + + System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); + ArrayList<String> semanticsTwo=new ArrayList<String>(); + ArrayList<String> tmp_semanticsTwo=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchPropertiesTwo=new ArrayList<String>(); + semanticsTwo.add(property_to_compare_withTwo); + + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + String _temp_Two=myindex.getWordnetHelp(property_to_compare_withTwo); + if(_temp_Two==null){ + tmp_semanticsOne=semanticsTwo; + } + else{ + semanticsTwo.clear(); + semanticsTwo.add(_temp_Two); + tmp_semanticsTwo=semanticsTwo; + } + + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semanticsTwo=getSemantics(tmp_semanticsTwo); + if (tmp_semanticsTwo==null){ + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semanticsTwo){ + if(!semanticsTwo.contains(k)) semanticsTwo.add(k); + } + } + + } catch (IOException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + goOnAfterWordnet=false; + final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); + + } + + + } + + + if(goOnAfterWordnet==true){ + + for (Entry<String, String> entryOne : propertiesOne.entrySet()) { + String keyOne = entryOne.getKey(); + String valueOne = entryOne.getValue(); + String queryOne=query; + + for(String b : semanticsOne){ + if(keyOne.contains(b.toLowerCase())){ + if(!result_SemanticsMatchPropertiesOne.contains(keyOne)){ + //create new query + result_SemanticsMatchPropertiesOne.add(keyOne); + String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); + queryOne=queryOne.replace(replacementOne,valueOne); + + for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { + String keyTwo = entryTwo.getKey(); + String valueTwo = entryTwo.getValue(); + + for(String z : semanticsTwo){ + if(keyTwo.contains(z.toLowerCase())){ + if(!result_SemanticsMatchPropertiesTwo.contains(keyTwo)){ + //create new query + result_SemanticsMatchPropertiesTwo.add(keyTwo); + String queryTwo=queryOne; + String replacementTwo = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); + queryTwo=queryTwo.replace(replacementTwo,valueTwo); + System.out.println("New query after wordnet: "+ queryTwo); + new_queries.add(queryTwo); + } + } + } + } + + } + } + } + + + + } + + + + + for(String bla : new_queries){ + String answer_tmp; + answer_tmp=sendServerQuestionRequest(bla); + System.out.println("Antwort vom Server: "+answer_tmp); + final_answer.add("Begin:\n"+bla +"\n"+answer_tmp+" \n End"); + } + } + } + } + + return final_answer; +} + + /** * Is the function for the Case, you are in Iteration one and have only one triple of condition (s,p,o). * @param querylist @@ -463,6 +1095,13 @@ return final_answer; } + + + + + + + /** * Iterates thru the conditions and returns an array, where one can see, if the Property is left or right from the resource 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 2011-12-07 22:23:04 UTC (rev 3488) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2011-12-08 09:01:12 UTC (rev 3489) @@ -25,31 +25,10 @@ * in Eclipse Run -> RunConfigurations -> Arguments -> VM Arguments -> -Xmx1024m */ -/* - * - * - * for pom.xml file - * <dependencies> - <dependency> - <groupId>org.xerial</groupId> - <artifactId>sqlite-jdbc</artifactId> - <version>3.6.16</version> - </dependency> - </dependencies> - */ -// Sax example from http://www.bennyn.de/programmierung/java/java-xml-sax-parser.html -/* - * - * eins:http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fx+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fx+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout= - * zwei:http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fc+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fc+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout= - * - */ public class exploration_main { - //private static HashMap<String, String> hm = new HashMap<String, String>(); - private static String qaldEntity2="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fc+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fc+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout="; - private static String qaldEntity1="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=SELECT+DISTINCT+%3Fx+%3Fl++WHERE+{%0D%0A++%3Fx+rdf%3Atype+%3Fc+.%0D%0A++%3Fx+rdfs%3Alabel+%3Fl+.%0D%0A++FILTER+%28lang%28%3Fl%29+%3D+%27en%27%29%0D%0A}&format=text%2Fhtml&debug=on&timeout="; + /** * @param args * @throws IOException @@ -64,24 +43,12 @@ * Do the starting initializing stuff */ long startInitTime = System.currentTimeMillis(); - System.out.println("Start Indexing"); - - //For testing! - //hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity2",hm); - //hm=ParseXmlHtml.parse_xml("/home/swalter/workspace/qaldEntity1",hm); - - //30% Ram - /* - * For real use! - */ - /*hm=ParseXmlHtml.parse_xml((getEntity(qaldEntity2,"/tmp/qaldEntity2")),hm); - System.out.println("Entity2 done"); - hm=ParseXmlHtml.parse_xml((getEntity(qaldEntity1,"/tmp/qaldEntity1")),hm); - System.out.println("Entity1 done");*/ - System.out.println("Done with indexing\n"); - System.out.println("Start generating Wordnet Dictionary"); + + /* + * Create Sparql Object + */ SparqlObject sparql = new SparqlObject(); - System.out.println("Generating Wordnet Dictionary Done"); + long stopInitTime = System.currentTimeMillis(); System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-04 13:49:52
|
Revision: 3525 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3525&view=rev Author: sebastianwtr Date: 2012-01-04 13:49:40 +0000 (Wed, 04 Jan 2012) Log Message: ----------- [tbsl exploration] started to implement XML input/output Modified 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/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java Modified: 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-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -16,6 +16,10 @@ 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:8892/sparql"; + public HashMap<String,String> getPropertys(String element, String side) throws IOException{ return sendServerPropertyRequest(element,side); @@ -55,10 +59,10 @@ * 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="http://dbpedia.org/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="http://dbpedia.org/sparql?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_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 verarbeitungsurl=null; if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; 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-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -13,6 +13,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -43,6 +45,7 @@ + public class SparqlObject { //global Variable dict @@ -57,6 +60,12 @@ private static mySQLDictionary myindex; boolean only_best_levensthein_query; + //change here and in 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:8892/sparql"; + + //Konstruktor public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ @@ -75,7 +84,7 @@ //normaly 1 setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren - setIterationdepth(1); + setIterationdepth(9); setNumberofanswers(1); only_best_levensthein_query=false; @@ -124,20 +133,22 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(String question) throws JWNLException, IOException, SQLException{ + public void create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); long startParsingTime = System.currentTimeMillis(); - lstquery=getQuery(question); + lstquery=getQuery(query_struct.getQuery()); long endParsingTime = System.currentTimeMillis(); long startIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); ArrayList<String> final_answer = new ArrayList<String>(); ArrayList<String> final_query = new ArrayList<String>(); + Set<String> final_query_hash = new HashSet<String>(); + Set<String> final_answer_hash = new HashSet<String>(); if(lstquery.isEmpty()){ - saveNotParsedQuestions(question); + saveNotParsedQuestions(query_struct.getQuery()); } for(ArrayList<String> querylist : lstquery){ @@ -179,7 +190,7 @@ String out=null; if (query.equals("") || query.equals(" ")||query.length()==0) query="Could not parse"; - out=tmp + "\n" + question + ":\n"+query+"\n"; + out=tmp + "\n" + query_struct.getQuery() + ":\n"+query+"\n"; BufferedWriter outfile = new BufferedWriter( new OutputStreamWriter( @@ -219,9 +230,8 @@ e.printStackTrace(); } } - String answer; - answer=sendServerQuestionRequest(query); - final_answer.add("Begin:\n"+query +"\n"+answer+" \n End"); + + final_query_hash.add(query); } /* @@ -236,68 +246,28 @@ ArrayList<String> final_answer_tmp = new ArrayList<String>(); ArrayList<String> final_query_tmp=new ArrayList<String>(); if(querylist.size()==4){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); - //final_query_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN"); for(String i: final_query_tmp){ + final_query_hash.add(i); - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } } } if(querylist.size()>4&&query.contains("rdf:type")){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN"); for(String i: final_query_tmp){ - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&!query.contains("rdf:type")){ final_query_tmp=advancedCase(querylist, query,"LEVENSTHEIN"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } @@ -321,106 +291,28 @@ final_query_tmp=simpleCase(querylist, query, "WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&query.contains("rdf:type")){ - //System.out.println("YEAH!!!!!"); - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); + final_query_tmp=isAIteration(querylist, query,"WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } if(querylist.size()>4&&!query.contains("rdf:type")){ final_query_tmp=advancedCase(querylist, query,"WORDNET"); for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } + final_query_hash.add(i); } } - /* if(querylist.size()==4){ - - //final_answer_tmp=simpleLevinstheinIteration(querylist, query); - final_query_tmp = simpleWordnetIteration(querylist, query); - for(String i: final_query_tmp){ - - //do it unnice for first - boolean double_query=false; - for(String s: final_query ){ - - if(s.contains(i)){ - double_query=true; - - } - } - if(double_query==false){ - - final_query.add(i); - } - } - } - final_answer_tmp=simpleWordnetIteration(querylist, query); - //if(querylist.size()>4)final_answer=complexWordnetIteration(querylist, query); - - //for a test only use: - if(querylist.size()>4){ - final_query_tmp=newIteration(querylist,query); - for(String i: final_query_tmp){ - boolean double_query=false; - for(String s: final_query ){ - if(s.contains(i)){ - double_query=true; - } - } - if(double_query==false){ - final_query.add(i); - } - } - }*/ + } @@ -431,16 +323,25 @@ * Send Query to Server and get answers */ - for(String anfrage : final_query){ - String answer_tmp; - answer_tmp=sendServerQuestionRequest(anfrage); - //System.out.println("Antwort vom Server: "+answer_tmp); - if(!final_answer.contains(anfrage)) - final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - } + Iterator it = final_query_hash.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + String answer_tmp; + try{ + String anfrage=it.next().toString(); + answer_tmp=sendServerQuestionRequest(anfrage); + final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + } + catch (Exception e){ + + } + } + + + + BufferedReader in = null; String tmp=""; @@ -488,7 +389,7 @@ } } - System.out.println(question); + System.out.println(query_struct.getQuery()); out = out.replace("@en","").replace("\"","").replace("^^<http://www.w3.org/2001/XMLSchema#int> ", ""); System.out.println(out); @@ -496,7 +397,7 @@ new OutputStreamWriter( new FileOutputStream( "/tmp/answer" ) ) ); - outfile.write(tmp+"\n"+question+" :\n"+out); + outfile.write(tmp+"\n"+query_struct.getQuery()+" :\n"+out); outfile.close(); long stopIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); @@ -1928,7 +1829,7 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); + String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); URL url; InputStream is; InputStreamReader isr; @@ -1966,7 +1867,7 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - String tmp="http://dbpedia.org/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); URL url; @@ -2001,11 +1902,8 @@ } private String createAnswer(String string){ - //<td>Klaus Wowereit</td> - //get with regex all between <td> </td> - - Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); + /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); Matcher m = p.matcher (string); String result=""; @@ -2013,8 +1911,23 @@ if(m.group(1)!=null) result = result+" "+ m.group(1); } - + */ + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + String result=""; + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + result = result+"\n"+ m.group(1); + + } + } + if (result.length()==0) result="EmtyAnswer"; + if(string.matches("true")|| string.matches("false")) result=string; return result; @@ -2024,17 +1937,31 @@ //get with regex all between <td> </td> - Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); + /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); Matcher m = p.matcher (string); ArrayList<String> result=new ArrayList<String>(); while (m.find()) { if(m.group(1)!=null) result.add(m.group(1)); - } + }*/ + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + ArrayList<String> result= new ArrayList<String>(); + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + result.add(m.group(1)); + + } + } + //if (result.length()==0) result="EmtyAnswer"; - + if(string.matches("true")|| string.matches("false")) result.add(string); return result; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -0,0 +1,53 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +public class queryInformation { + // <question id="32" type="boolean" fusion="false" aggregation="false" yago="false"> + public final String query; + public final String type; + public final boolean fusion; + public final boolean aggregation; + public final boolean yago; + public final String id; + public final String XMLtype; + public final boolean hint; + + public boolean isHint() { + return hint; + } + + + public String getXMLtype() { + return XMLtype; + } + + + public String getId() { + return id; + } + public String getQuery() { + return query; + } + public String getType() { + return type; + } + public boolean isFusion() { + return fusion; + } + public boolean isAggregation() { + return aggregation; + } + public boolean isYago() { + return yago; + } + + public queryInformation(String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1, boolean hint1){ + this.query=query1; + this.type=type1; + this.fusion=fusion1; + this.aggregation=aggregation1; + this.yago=yago1; + this.id=id1; + this.XMLtype=XMLtype1; + this.hint=hint1; + } +} 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-01-03 12:56:11 UTC (rev 3524) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-01-04 13:49:40 UTC (rev 3525) @@ -2,6 +2,7 @@ import java.io.BufferedReader; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -9,10 +10,14 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.didion.jwnl.JWNLException; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; +import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -114,7 +119,9 @@ System.out.println(s); anzahl++; //get each line and send it to the parser - sparql.create_Sparql_query(s); + //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); + sparql.create_Sparql_query(newQuery); } long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -122,9 +129,46 @@ System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); } + if(line.contains(":xml")&& schleife==true){ + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + + + System.out.println("Please enter Path of xml File:"); + line=in.readLine(); + + //create Structs + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + //if you dont want to use the hints in the questions, use false + list_of_structs=generateStruct(line,true); + //Start Time measuring + long startTime = System.currentTimeMillis(); + + int anzahl=0; + for(queryInformation s : 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()); + sparql.create_Sparql_query(s); + } + + + //sparql.create_Sparql_query(s); + + long timeNow = System.currentTimeMillis(); + long diff = timeNow-startTime; + + System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); + + } + else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); - sparql.create_Sparql_query(line); + queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); + sparql.create_Sparql_query(newQuery); long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -139,20 +183,126 @@ - private static String getEntity(String query, String name) throws IOException, InterruptedException{ + private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { - // String query_complete="wget "+"\""+query+"\""+" -O "+"\""+name+"\""; - URL url = new URL(query); - ReadableByteChannel rbc = Channels.newChannel(url.openStream()); - //System.out.println(rbc.toString()); - FileOutputStream fos = new FileOutputStream(name); - //max 200MB = 209715200 Byte - fos.getChannel().transferFrom(rbc, 0, 209715200 ); - + String XMLType=null; + + BufferedReader in = null; + + String tmp=""; + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream(filename) ) ); + String s; + while( null != (s = in.readLine()) ) { + tmp=tmp+s; + //System.out.println(tmp); + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } - return name; + String string=tmp; + Pattern p = Pattern.compile (".*\\<question(.*)\\</question\\>.*"); + Matcher m = p.matcher (string); + + + if(string.contains("id=\"dbpedia-train\"><question")){ + string=string.replace("id=\"dbpedia-train\"><question", ""); + XMLType="dbpedia-train"; + System.out.println("dbpedia-train"); + } + if(string.contains("id=\"dbpedia-test\"><question")){ + string=string.replace("id=\"dbpedia-test\"><question", ""); + XMLType="dbpedia-test"; + //System.out.println("dbpedia-test"); + } + ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); + String [] bla = string.split("</question><question"); + for(String s : bla){ + String query=""; + String type=""; + boolean fusion=false; + boolean aggregation=false; + boolean yago=false; + String id=""; + + Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + Matcher m1 = p1.matcher(s); + //System.out.println(""); + while(m1.find()){ + //System.out.println(m1.group(1)); + Pattern p2= Pattern.compile(".*><string>(.*)"); + Matcher m2 = p2.matcher(m1.group(1)); + while(m2.find()){ + //System.out.println("Query: "+ m2.group(1)); + query=m2.group(1); + } + Pattern p3= Pattern.compile("id=\"(.*)\" answer.*"); + Matcher m3 = p3.matcher(m1.group(1)); + while(m3.find()){ + //System.out.println("Id: "+ m3.group(1)); + id=m3.group(1); + } + + Pattern p4= Pattern.compile(".*answertype=\"(.*)\" fusion.*"); + Matcher m4 = p4.matcher(m1.group(1)); + while(m4.find()){ + //System.out.println("answertype: "+ m4.group(1)); + type=m4.group(1); + } + + Pattern p5= Pattern.compile(".*fusion=\"(.*)\" aggregation.*"); + Matcher m5 = p5.matcher(m1.group(1)); + while(m5.find()){ + //System.out.println("fusion: "+ m5.group(1)); + if(m5.group(1).contains("true"))fusion=true; + else fusion=false; + } + + Pattern p6= Pattern.compile(".*aggregation=\"(.*)\" yago.*"); + Matcher m6 = p6.matcher(m1.group(1)); + while(m6.find()){ + //System.out.println("aggregation: "+ m6.group(1)); + if(m6.group(1).contains("true"))aggregation=true; + else aggregation=false; + } + + Pattern p7= Pattern.compile(".*yago=\"(.*)\" ><string>.*"); + Matcher m7 = p7.matcher(m1.group(1)); + while(m7.find()){ + //System.out.println("yago: "+ m7.group(1)); + if(m7.group(1).contains("true"))yago=true; + else yago=false; + } + + + + } + queryInformation blaquery=new queryInformation(query, id,type,fusion,aggregation,yago,XMLType,hint); + if(id!=""&&id!=null) querylist.add(blaquery); + } + /* for(queryInformation s : querylist){ + 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()); + }*/ + return querylist; } + - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-04 15:02:01
|
Revision: 3526 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3526&view=rev Author: sebastianwtr Date: 2012-01-04 15:01:50 +0000 (Wed, 04 Jan 2012) Log Message: ----------- [tbsl exploration] writes now into XML-Files Modified Paths: -------------- 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/queryInformation.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 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-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -133,7 +133,7 @@ * "Main" Method of this Class. * */ - public void create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ + public queryInformation create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); @@ -143,9 +143,7 @@ long startIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); ArrayList<String> final_answer = new ArrayList<String>(); - ArrayList<String> final_query = new ArrayList<String>(); Set<String> final_query_hash = new HashSet<String>(); - Set<String> final_answer_hash = new HashSet<String>(); if(lstquery.isEmpty()){ saveNotParsedQuestions(query_struct.getQuery()); @@ -332,7 +330,41 @@ try{ String anfrage=it.next().toString(); answer_tmp=sendServerQuestionRequest(anfrage); - final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + answer_tmp=answer_tmp.replace("\"@en", ""); + answer_tmp=answer_tmp.replace("\"", ""); + + //filter answers! + if(query_struct.isHint()){ + System.out.println("Using hint!"); + /* + * Answertyps: resource, string, boolean, num, date + */ + if(query_struct.getType().contains("boolean")){ + if(answer_tmp.contains("true")||answer_tmp.contains("false")) final_answer.add(answer_tmp); + + } + else if (query_struct.getType().contains("resource")){ + final_answer.add(answer_tmp); + } + else if (query_struct.getType().contains("string")){ + if(!answer_tmp.contains("http")&&!answer_tmp.contains("EmtyAnswer")) { + String[] tmparray = answer_tmp.split("\n"); + for(String z : tmparray)final_answer.add(z); + } + + } + else if (query_struct.getType().contains("num")){ + if(answer_tmp.matches("[0-9]*")) final_answer.add(answer_tmp); + + } + else if (query_struct.getType().contains("date")){ + final_answer.add(answer_tmp); + } + } + else{ + //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + final_answer.add(answer_tmp); + } } catch (Exception e){ @@ -341,68 +373,9 @@ + query_struct.setResult(final_answer); - BufferedReader in = null; - - String tmp=""; - // Lies Textzeilen aus der Datei in einen Vector: - try { - in = new BufferedReader( - new InputStreamReader( - new FileInputStream( "/tmp/answer" ) ) ); - String s; - while( null != (s = in.readLine()) ) { - tmp+="\n"+s; - } - } catch( FileNotFoundException ex ) { - } catch( Exception ex ) { - System.out.println( ex ); - } finally { - if( in != null ) - try { - in.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - String out=""; - for(String answer : final_answer){ - if(answer!=null){ - //only answered question - if(!answer.contains("Error in searching Wordnet with word") && !answer.contains("EmtyAnswer")&& !answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; - - /* - //only questions with wordnet error - if(answer.contains("Error in searching Wordnet with word"))out=out+ "\n"+answer+"\n"; - - //only questions with emty answers - if(answer.contains("EmtyAnswer"))out=out+ "\n"+answer+"\n"; -*/ - //only questions with Error in Properties - // if(answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; - - //out+= "\n"+answer+"\n"; - } - else{ - System.out.println("Answer was null"); - } - - } - System.out.println(query_struct.getQuery()); - out = out.replace("@en","").replace("\"","").replace("^^<http://www.w3.org/2001/XMLSchema#int> ", ""); - System.out.println(out); - - BufferedWriter outfile = new BufferedWriter( - new OutputStreamWriter( - new FileOutputStream( "/tmp/answer" ) ) ); - - outfile.write(tmp+"\n"+query_struct.getQuery()+" :\n"+out); - outfile.close(); - long stopIterationTime = System.currentTimeMillis(); - System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); - System.out.println("The Iteration took "+ (stopIterationTime-startIterationTime)+ " ms"); - System.out.println("All took "+ (stopIterationTime-startParsingTime)+ " ms"); + return query_struct; } private ArrayList<String> newIteration(ArrayList<String> querylist, String query) throws SQLException, Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -1,5 +1,7 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; +import java.util.ArrayList; + public class queryInformation { // <question id="32" type="boolean" fusion="false" aggregation="false" yago="false"> public final String query; @@ -10,8 +12,18 @@ public final String id; public final String XMLtype; public final boolean hint; + public ArrayList<String> result = new ArrayList<String>(); - public boolean isHint() { + public ArrayList<String> getResult() { + return result; + } + + public void setResult(ArrayList<String> new_result) { + this.result=new_result; + } + + + public boolean isHint() { return hint; } 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-01-04 13:49:40 UTC (rev 3525) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-01-04 15:01:50 UTC (rev 3526) @@ -1,9 +1,11 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; @@ -121,7 +123,12 @@ //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); - sparql.create_Sparql_query(newQuery); + 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; @@ -138,6 +145,7 @@ //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + ArrayList<queryInformation> list_of_resultstructs = new ArrayList<queryInformation>(); //if you dont want to use the hints in the questions, use false list_of_structs=generateStruct(line,true); //Start Time measuring @@ -152,12 +160,16 @@ System.out.println("Query: "+s.getQuery()); System.out.println("Type: "+s.getType()); System.out.println("XMLType: "+s.getXMLtype()); - sparql.create_Sparql_query(s); + list_of_resultstructs.add(sparql.create_Sparql_query(s)); } - //sparql.create_Sparql_query(s); - + //Print to Console + System.out.println("\n#############\n Result:"); + for(queryInformation s : list_of_resultstructs){ + System.out.println(s.getResult()); + } + createXML(list_of_resultstructs); long timeNow = System.currentTimeMillis(); long diff = timeNow-startTime; @@ -168,7 +180,12 @@ else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); - sparql.create_Sparql_query(newQuery); + queryInformation result = new queryInformation(line,"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 endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -182,6 +199,39 @@ } + private static void createXML(ArrayList<queryInformation> list){ + + + String xmlDocument=""; + int counter=0; + for (queryInformation s : list){ + String tmp; + if(counter==0){ + counter=counter+1; + xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + } + tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string><query></query><ANSWERS>"; + for(String i : s.getResult())tmp+="<answer>"+i+"</answer>"; + tmp+="</ANSWERS></question>"; + xmlDocument+=tmp; + + } + xmlDocument+="</dataset>"; + File file; + FileWriter writer; + file = new File("/home/swalter/result.xml"); + try { + writer = new FileWriter(file ,false); + writer.write(xmlDocument); + writer.flush(); + + + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-01-08 13:42:31
|
Revision: 3542 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3542&view=rev Author: sebastianwtr Date: 2012-01-08 13:42:22 +0000 (Sun, 08 Jan 2012) Log Message: ----------- [tbsl exploration] changed function for server connection and some other minor functions Modified 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/SparqlObject.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/queryInformation.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: 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-01-06 14:24:45 UTC (rev 3541) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-01-08 13:42:22 UTC (rev 3542) @@ -6,6 +6,8 @@ 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; @@ -17,12 +19,12 @@ 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:8892/sparql"; + String Prefix="http://dbpedia.org/sparql"; + //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; - public HashMap<String,String> getPropertys(String element, String side) throws IOException{ + public HashMap<String,String> getPropertys(String element, String side, int timeToTimeoutOnServer) throws IOException{ - return sendServerPropertyRequest(element,side); + return sendServerPropertyRequest(element,side, timeToTimeoutOnServer); @@ -34,7 +36,7 @@ * @return * @throws IOException */ - private HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) 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); @@ -64,43 +66,65 @@ //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; - if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; + /*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 verarbeitungsstring="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%0D%0APREFIX+res%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2F%3E%0D%0A%0D%0ASELECT+DISTINCT+%3Fp+%3Fl+WHERE++{%0D%0A+{+res%3A"+vergleich+"+%3Fp+%3Fo+.+}%0D%0A+UNION%0D%0A+{+%3Fs+%3Fp+res%3A"+vergleich+"+.+}%0D%0A+{+%3Fp+rdfs%3Alabel+%3Fl+.+}%0D%0A}%0D%0A&format=text%2Fhtml&debug=on&timeout="; - URL url; - InputStream is; - InputStreamReader isr; - BufferedReader r; - String str; String result=""; - - try { - url = new URL(verarbeitungsurl); - is = url.openStream(); - isr = new InputStreamReader(is); - r = new BufferedReader(isr); - do { - str = r.readLine(); - if (str != null) - result=result+str; - } while (str != null); - } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); - } catch (IOException e) { - System.out.println("Can not connect"); - } + HttpURLConnection connection = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; - /* FileWriter w = new FileWriter("answer_property"); - w.write(result); - w.close(); - */ + 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>",""); 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-01-06 14:24:45 UTC (rev 3541) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-01-08 13:42:22 UTC (rev 3542) @@ -9,8 +9,10 @@ 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.net.URLConnection; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -26,15 +28,18 @@ import net.didion.jwnl.data.POS; import org.dllearner.algorithm.tbsl.exploration.sax.ParseXmlHtml; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; import org.dllearner.algorithm.tbsl.sparql.Path; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Having; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; import org.dllearner.algorithm.tbsl.sparql.Slot; import org.dllearner.algorithm.tbsl.sparql.Template; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import org.dllearner.algorithm.tbsl.templator.Templator; +import org.xml.sax.InputSource; import java.sql.Connection; import java.sql.DriverManager; @@ -53,17 +58,20 @@ static int explorationdepthwordnet=2; static int iterationdepth =0; static int numberofanswers=1; - static double LevenstheinMin = 0.8; + static double LevenstheinMin = 0.9; static WordNet wordnet; BasicTemplator btemplator; Templator templator; private static mySQLDictionary myindex; boolean only_best_levensthein_query; + static StanfordLemmatizer lemmatiser; + //one Minute + private static int timeToTimeoutOnServer=60000; //change here and in 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:8892/sparql"; + String Prefix="http://dbpedia.org/sparql"; + //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; //Konstruktor @@ -88,6 +96,7 @@ setNumberofanswers(1); only_best_levensthein_query=false; + lemmatiser = new StanfordLemmatizer(); } /* @@ -133,12 +142,19 @@ * "Main" Method of this Class. * */ - public queryInformation create_Sparql_query(queryInformation query_struct) throws JWNLException, IOException, SQLException{ + public queryInformation create_Sparql_query(queryInformation queryObject) throws JWNLException, IOException, SQLException{ //create_Sparql_query_new(string); ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); long startParsingTime = System.currentTimeMillis(); - lstquery=getQuery(query_struct.getQuery()); + //lstquery=getQuery(queryObject.getQuery(),queryObject); + queryObject=getQuery(queryObject); + lstquery=queryObject.getQueryInformation(); + queryObject.setQueryInformation(lstquery); + /*BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); + String line; + + line = in1.readLine();*/ long endParsingTime = System.currentTimeMillis(); long startIterationTime = System.currentTimeMillis(); System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); @@ -146,7 +162,7 @@ Set<String> final_query_hash = new HashSet<String>(); if(lstquery.isEmpty()){ - saveNotParsedQuestions(query_struct.getQuery()); + saveNotParsedQuestions(queryObject.getQuery()); } for(ArrayList<String> querylist : lstquery){ @@ -188,7 +204,7 @@ String out=null; if (query.equals("") || query.equals(" ")||query.length()==0) query="Could not parse"; - out=tmp + "\n" + query_struct.getQuery() + ":\n"+query+"\n"; + out=tmp + "\n" + queryObject.getQuery() + ":\n"+query+"\n"; BufferedWriter outfile = new BufferedWriter( new OutputStreamWriter( @@ -243,19 +259,23 @@ ArrayList<String> final_answer_tmp = new ArrayList<String>(); ArrayList<String> final_query_tmp=new ArrayList<String>(); - if(querylist.size()==4){ + if(querylist.size()==4&&!query.contains("rdf:type")){ - final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN"); + final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN",queryObject); for(String i: final_query_tmp){ final_query_hash.add(i); } } + //e.g. Select ßy Where (?y rdf:type <http://..../ontology/School> + if(querylist.size()==4&&query.contains("rdf:type")){ + final_query_hash.add(query); + } if(querylist.size()>4&&query.contains("rdf:type")){ - final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN"); + final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN",queryObject.getIsaResource()); for(String i: final_query_tmp){ final_query_hash.add(i); @@ -285,17 +305,21 @@ ArrayList<String> final_query_tmp = new ArrayList<String>(); //isAIteration(querylist, query); - if(querylist.size()==4){ + if(querylist.size()==4&&!query.contains("rdf:type")){ - final_query_tmp=simpleCase(querylist, query, "WORDNET"); + final_query_tmp=simpleCase(querylist, query, "WORDNET",queryObject); for(String i: final_query_tmp){ final_query_hash.add(i); } } + //e.g. Select ßy Where (?y rdf:type <http://..../ontology/School> + if(querylist.size()==4&&query.contains("rdf:type")){ + final_query_hash.add(query); + } if(querylist.size()>4&&query.contains("rdf:type")){ - final_query_tmp=isAIteration(querylist, query,"WORDNET"); + final_query_tmp=isAIteration(querylist, query,"WORDNET",queryObject.getIsaResource()); for(String i: final_query_tmp){ final_query_hash.add(i); } @@ -323,48 +347,60 @@ - Iterator it = final_query_hash.iterator(); + Iterator<String> it = final_query_hash.iterator(); while (it.hasNext()) { System.out.println(it.next()); - String answer_tmp; + ArrayList<String> answer= new ArrayList<String>(); try{ String anfrage=it.next().toString(); - answer_tmp=sendServerQuestionRequest(anfrage); + answer=sendServerQuestionRequestArray(anfrage); + // @en is also in the ML + /* answer_tmp=answer_tmp.replace("\"@en", ""); - answer_tmp=answer_tmp.replace("\"", ""); + answer_tmp=answer_tmp.replace("\"", "");*/ //filter answers! - if(query_struct.isHint()){ - System.out.println("Using hint!"); - /* - * Answertyps: resource, string, boolean, num, date - */ - if(query_struct.getType().contains("boolean")){ - if(answer_tmp.contains("true")||answer_tmp.contains("false")) final_answer.add(answer_tmp); - - } - else if (query_struct.getType().contains("resource")){ - final_answer.add(answer_tmp); - } - else if (query_struct.getType().contains("string")){ - if(!answer_tmp.contains("http")&&!answer_tmp.contains("EmtyAnswer")) { - String[] tmparray = answer_tmp.split("\n"); - for(String z : tmparray)final_answer.add(z); - } - - } - else if (query_struct.getType().contains("num")){ - if(answer_tmp.matches("[0-9]*")) final_answer.add(answer_tmp); - - } - else if (query_struct.getType().contains("date")){ - final_answer.add(answer_tmp); - } + for(String answer_tmp : answer ){ + if(answer_tmp!="EmtyAnswer"){ + if(queryObject.isHint()){ + //System.out.println("Using hint!"); + /* + * Answertyps: resource, string, boolean, num, date + */ + if(queryObject.getType().contains("boolean")){ + if(answer_tmp.contains("true")||answer_tmp.contains("false")) final_answer.add(answer_tmp); + + } + else if (queryObject.getType().contains("resource")){ + try{ + String[] tmparray = answer_tmp.split("\n"); + for(String z : tmparray)final_answer.add(z); + } + catch(Exception e){ + final_answer.add(answer_tmp); + } + } + else if (queryObject.getType().contains("string")||queryObject.getType().contains("uri")){ + if(!answer_tmp.contains("EmtyAnswer")) { + String[] tmparray = answer_tmp.split("\n"); + for(String z : tmparray)final_answer.add(z); + } + + } + else if (queryObject.getType().contains("num")){ + if(answer_tmp.matches("[0-9]*")) final_answer.add(answer_tmp); + + } + else if (queryObject.getType().contains("date")){ + final_answer.add(answer_tmp); + } + } + else{ + //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); + final_answer.add(answer_tmp); + } + } } - else{ - //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - final_answer.add(answer_tmp); - } } catch (Exception e){ @@ -372,13 +408,20 @@ } + long stopIterationTime = System.currentTimeMillis(); + /* + * Set time + */ + + queryObject.setTimeGesamt(stopIterationTime-startParsingTime); + queryObject.setTimeParser(endParsingTime-startParsingTime); + queryObject.setTimeWithoutParser(stopIterationTime-startIterationTime); + queryObject.setResult(final_answer); - query_struct.setResult(final_answer); - - return query_struct; + return queryObject; } - private ArrayList<String> newIteration(ArrayList<String> querylist, String query) throws SQLException, + private ArrayList<String> newIteration(ArrayList<String> querylist, String query, queryInformation queryObject) throws SQLException, JWNLException { //only for special case, that the first condition has a resource ArrayList<String> final_answer=new ArrayList<String>(); @@ -439,7 +482,7 @@ querylist_new.add("PROPERTY"+firstProperty); querylist_new.add(sideOfProperty+firstResource); if(answer_tmp.isEmpty()){ - answer_tmp=simpleCase(querylist_new,firstquery,"WORDNET"); + answer_tmp=simpleCase(querylist_new,firstquery,"WORDNET",queryObject); } //if answer_tmp is still empty return null and exit function if(answer_tmp.isEmpty()){final_answer.add("new Iteration didnt work"); @@ -481,7 +524,7 @@ for(ArrayList as: secondquerylist){ ArrayList<String> answer_tmp_two=new ArrayList<String>(); //answer_tmp_two=sendServerQuestionRequestArray(s); - answer_tmp=simpleCase(as,as.get(0).toString(),"WORDNET"); + answer_tmp=simpleCase(as,as.get(0).toString(),"WORDNET",queryObject); for(String t :answer_tmp_two){ final_answer.add(t); System.out.println("Answer from advanced Iteration: "+ t); @@ -495,7 +538,7 @@ - private ArrayList<String> isAIteration(ArrayList<String> querylist, String query, String fall) throws SQLException, + private ArrayList<String> isAIteration(ArrayList<String> querylist, String query, String fall, String uri_isA_Resource) throws SQLException, JWNLException { ArrayList<String> new_queries= new ArrayList<String>(); //TODO: in get Query change, that there will be a second query, but only with the part of the condition upsidedown, which doesnt contains an isA @@ -506,29 +549,17 @@ */ - //take query and use regex, to take only the part beween the {} - Pattern p = Pattern.compile (".*\\{(.*\\<http.*)\\}.*"); - Matcher m = p.matcher (query); ArrayList<String> list_of_x=new ArrayList<String>(); String query_for_x=null; - while(m.find()){ - String tmp=m.group(1); - - Pattern p2=Pattern.compile (".*(http://dbpedia.org/ontology/[A-Z].*)\\>\\W.*"); - Matcher m2 = p2.matcher (tmp); - //now we know, that we are in the part with the rdf type thing - while(m2.find()){ - query_for_x="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE { ?x rdf:type <"+m2.group(1)+">}"; - //System.out.println("Done: "+ query_for_x); - } - - } + + + + query_for_x="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE { ?x rdf:type <"+uri_isA_Resource+">}"; //now send query_for_x to the server, to get all x System.out.println("IsA x-query: "+query_for_x); if(query_for_x!=null)list_of_x=sendServerQuestionRequestArray(query_for_x); - /* * Zweiter Schritt: * alle Propertys z.B. der ersten 5 xe holen und in eine Liste packen @@ -543,6 +574,7 @@ /* * First use left and also right Propertys */ + tmpcounter++; if(tmpcounter <=number_of_x_used){ HashMap<String,String> propertiesleft = new HashMap<String, String>(); @@ -550,8 +582,8 @@ GetRessourcePropertys property = new GetRessourcePropertys(); try { - propertiesleft=property.getPropertys(s,"LEFT"); - propertiesright=property.getPropertys(s,"RIGHT"); + propertiesleft=property.getPropertys(s,"LEFT",timeToTimeoutOnServer); + propertiesright=property.getPropertys(s,"RIGHT",timeToTimeoutOnServer); } catch (Exception e){ @@ -565,7 +597,14 @@ } } - //System.out.println(list_of_properties); + /* System.out.println("List of Properties: "); + for (Entry<String, String> entry : list_of_properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + String value = entry.getValue(); + System.out.println("Key: "+ key + " Value: "+value); + }*/ /* * get Property used in the original query @@ -577,47 +616,44 @@ //http://dbpedia.org/ontology/officialLanguage //look for property - Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/property/.*)\\>\\W\\?.*"); + Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/property/.*)\\>\\W\\W*\\?.*"); Matcher m3 = p3.matcher(query); - while(m3.find()) System.out.println("Property in IsA: "+m3.group(1)); + String property_to_compare_with_uri=""; + while(m3.find()) { + property_to_compare_with_uri=m3.group(1); + System.out.println("Property in IsA: "+m3.group(1)); + } - //look for ontology, which is NO class - //Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/^[A-Z].*)\\>\\W.*"); - Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[a-z].*)\\>\\W\\?.*"); - Matcher m4 = p4.matcher(query); - String uri_property=null; - while(m4.find()) { - uri_property=m4.group(1); - System.out.println("Uri_Property: "+ uri_property); + //if there is no property but an ontology-property + if(property_to_compare_with_uri==""){ + Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[a-z].*)\\>\\W\\W*\\?.*"); + Matcher m4 = p4.matcher(query); + while(m4.find()) { + property_to_compare_with_uri=m4.group(1); + System.out.println("Property in IsA: "+m4.group(1)); + } } - /* - * Nice, now i get http://dbpedia.org/ontology/officialLanguage - */ - if(uri_property!=null){ - String property=uri_property.replace("http://dbpedia.org/ontology/", "").replace("http://dbpedia.org/property/", ""); - String property_to_compare_with=""; - + String property_to_compare_with=property_to_compare_with_uri.replace("http://dbpedia.org/property/","").replace("http://dbpedia.org/ontology/",""); + + /* BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String line; - for(String s : querylist){ - if(s.contains("PROPERTY")){ - property_to_compare_with=s.replace("PROPERTY",""); - } - - } - - - /* - * Dritter Schritt: original Query nehmen und über die Liste mit den Propertys laufen und normal mit wordnet/levensthein vergleichen - */ - - //I think, i dont need here the last part of the uri but the original word from the query! - //new_queries=doWordnet(query,property,uri_property,list_of_properties); - - //if you want to use wordnet: - if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,uri_property,list_of_properties); - if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with,uri_property,list_of_properties); - } + System.out.println("############################"); + System.out.println("query: "+query); + System.out.println("property_to_compare_with: "+property_to_compare_with); + System.out.println("property_to_compare_with_uri: "+property_to_compare_with_uri); + System.out.println("############################"); + try { + line = in.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ + if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,property_to_compare_with_uri,list_of_properties); + if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with_uri,property_to_compare_with_uri,list_of_properties); + + return new_queries; @@ -625,7 +661,7 @@ - private ArrayList<String> simpleCase(ArrayList<String> querylist, String query, String fall) throws SQLException, + private ArrayList<String> simpleCase(ArrayList<String> querylist, String query, String fall, queryInformation queryObject) throws SQLException, JWNLException { System.out.println("In Simpe levensthein case!!"); @@ -655,6 +691,7 @@ } } + System.out.println("ARRAY LIST: "+querylist); System.out.println("Property to compare:: "+ property_to_compare_with); System.out.println("Resource: "+ resource); @@ -664,11 +701,12 @@ Boolean goOnAfterProperty = true; - System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); + //System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); + System.out.println("URI from Resource "+ resource +": "+queryObject.getHashValue(resource.toLowerCase())); //gets Propertys left or right from the resource! try { - properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); + properties=property.getPropertys(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty,timeToTimeoutOnServer); if (properties==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -684,8 +722,8 @@ } if(goOnAfterProperty==true){ - if(fall.contains("WORDNET")) new_queries=doWordnet(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); - if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); + if(fall.contains("WORDNET")) new_queries=doWordnet(query, property_to_compare_with,queryObject.getHashValue(property_to_compare_with.toLowerCase()),properties); + if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query, property_to_compare_with,queryObject.getHashValue(property_to_compare_with.toLowerCase()),properties); //new_queries=doLevensthein(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); //add original query @@ -797,8 +835,8 @@ //Get Properties for Resource in condition One and Two from Server try { - propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); - propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); + propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne,timeToTimeoutOnServer); + propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo,timeToTimeoutOnServer); if (propertiesOne==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -1128,7 +1166,8 @@ - + + //TODO: Write function new!!!!! /** * Iterates thrue the conditions and returns an array, where one can see, if the Property is left or right from the resource * @param query @@ -1140,31 +1179,83 @@ Matcher m = p.matcher (query); ArrayList<String> lstquery = new ArrayList<String>(); while (m.find()) { - String tmp= m.group(1); + System.out.println("In While Loop!"); + String workingQuery= m.group(1); //if there is an .../ontology/C, dann ist das eine Klasse und das ganze soll dann nicht ersetzt reingepackt werden, sondern so bleiben, wie es ist. - System.out.println("Before new pattern and checking "+tmp); - Pattern p1=Pattern.compile (".*(http://dbpedia.org/ontology/[A-Z].*)\\>\\W.*"); - Matcher m1 = p1.matcher (tmp); + System.out.println("Before new pattern and checking "+workingQuery); + + //take the Filter out, so you only have the conditions left + Pattern p2=Pattern.compile (".*(\\.FILTER\\(.*\\)).*"); + Matcher m2 = p2.matcher (workingQuery); + while(m2.find()){ + System.out.println("FIlter: "+m2.group(1)); + workingQuery=workingQuery.replace(m2.group(1), ""); + System.out.println("Without Filter: "+workingQuery); + } + String resourceTemp=""; - while(m1.find()){ - resourceTemp="RESOURCE"+m1.group(1); - tmp=tmp.replace("<"+m1.group(1)+">", "SKIP"); - System.out.println("New temp: "+tmp); + if(workingQuery.contains("ontologie")){ + Pattern p1=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[A-Z].*)\\>\\W\\W*.*"); + Matcher m1 = p1.matcher (workingQuery); + + + /* + * Das darf nicht sein: + * Replacment: <http://dbpedia.org/ontology/Caves> rdf:type ?x .?y <http://dbpedia.org/property/entrances> + */ + while(m1.find()){ + resourceTemp="RESOURCE"+m1.group(1); + String replacment="<"+m1.group(1)+">"; + //TODO: Make it nice!!! + //if he doesnt find the ontolokg party, kind of skip + if(!replacment.contains("property")&&!replacment.contains("resource")){ + System.out.println("Replacment: "+replacment); + workingQuery=workingQuery.replace(replacment, "SKIP"); + System.out.println("New temp: "+workingQuery); + } + + } + } - /* if(m1.find()){ - System.out.println("YEAHHHHHHHHHHHHHHHHHHHH "+m1.group(1)); + + /* + * dbpedia.org/class/yago/ + */ + if(workingQuery.contains("yago")){ + Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/class/yago//[A-Z].*)\\>\\W.*"); + Matcher m3 = p3.matcher (workingQuery); + + + /* + * Das darf nicht sein: + * Replacment: <http://dbpedia.org/ontology/Caves> rdf:type ?x .?y <http://dbpedia.org/property/entrances> + */ + while(m3.find()){ + resourceTemp="RESOURCE"+m3.group(1); + String replacment="<"+m3.group(1)+">"; + //TODO: Make it nice!!! + //if he doesnt find the ontolokg party, kind of skip + if(!replacment.contains("property")&&!replacment.contains("resource")){ + System.out.println("Replacment: "+replacment); + workingQuery=workingQuery.replace(replacment, "SKIP"); + System.out.println("New temp: "+workingQuery); + } + + } + } - else{*/ - + + System.out.println("TMP before replace :"+workingQuery); + workingQuery=workingQuery.replace("http://dbpedia.org/resource/","").replace("http://dbpedia.org/property/", "").replace("http://dbpedia.org/ontology/", ""); - tmp=tmp.replace("http://dbpedia.org/resource/","").replace("http://dbpedia.org/property/", "").replace("http://dbpedia.org/ontology/", ""); - + System.out.println("TMP After replace :"+workingQuery); //split on . for sign for end of conditions - String[] firstArray=tmp.split("\\."); + String[] firstArray=workingQuery.split("\\."); for(String i : firstArray){ String[] secondArray=i.split(" "); + //always in three counts int counter=0; for(String j : secondArray){ @@ -1189,7 +1280,7 @@ else if(j.contains("SKIP"))lstquery.add(resourceTemp); else if(j.contains("rdf:type"))lstquery.add("IsA"); } - if(counter==0)counter=0; + if(counter==3)counter=0; } @@ -1202,6 +1293,7 @@ } + //TODO: Plural Singual abfragen über die Wordnetdatei... /** @@ -1210,8 +1302,9 @@ * @return ArrayList of Sparql queries. * @throws SQLException */ - private ArrayList<ArrayList<String>> getQuery(String question) throws SQLException { + private queryInformation getQuery(queryInformation queryObject) throws SQLException { ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); + String question=queryObject.getQuery(); Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); for (BasicQueryTemplate temp : querytemps) { @@ -1219,6 +1312,8 @@ ArrayList<String> lstquerupsidedown = new ArrayList<String>(); String query; String selTerms =""; + String yago_query=""; + String yago_query_upside_down=""; boolean addQuery=true; //sometimes there isnt an Selectterm, so dont use this query @@ -1248,6 +1343,14 @@ filters=""; addQuery=false; } + String having=""; + try{ + for(SPARQL_Having tmp : temp.getHavings()) having=having+tmp+" "; + } + catch(Exception e){ + having=""; + addQuery=false; + } //if there is no order by, replace with "" String orderdBy="ORDER BY "; @@ -1276,7 +1379,7 @@ } if(addQuery==true){ - query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions.replace("--","") + filters+"}"+orderdBy +" "+limit; + query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions.replace("--","") + filters+"}"+orderdBy+" "+having +" "+limit; String conditions_new = ""; for(Path condition: temp.getConditions()){ @@ -1300,7 +1403,7 @@ System.out.println("Conditions_new: " + conditions_new); - String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+ "}" + orderdBy +" "+limit; + String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+"}" + orderdBy +" "+having+" "+limit; String[] slots= null; @@ -1313,7 +1416,7 @@ int slotcounter=1; /* - * the one after the isA, has to be an ontology Class!!! + * the one after the isA, has to be an ontology Class or an Yago Class!!! * so first find out, which one is behind the isA * best with regex or so.... take the condition, regex the thing between isA and . for End of Condition * kind of regex=[*a IsA (\\?*a.)*a] @@ -1381,6 +1484,10 @@ System.out.println("Property "+property);*/ boolean skip=false; + + /* + * Der geht hier garnicht in die Schleife. + */ if(resource.contains(isaComponent.replace("?", "")) || property.contains(isaComponent.replace("?", ""))){ skip=true; @@ -1402,8 +1509,40 @@ catch(Exception e){ } - String hm_result=myindex.getontologyClassURI(array[1]); - if(hm_result==null)hm_result="http://dbpedia.org/ontology/"+Character.toUpperCase(array[1].charAt(0)) + array[1].substring(1, array[1].length()); + + /* + * Here lookup in ontology and in Yago, if ontology doesnt exist, use Yago, if not, use Ontology + * if both exist, add yago_query and yago_query upsideDown, but also change the isACase function for Yago + */ + //first look in Hasmap, if there is already an entry, if not, add founded result + String hm_result=""; + hm_result=queryObject.getHashValue(array[1]); + if(hm_result.contains("NONE")){ + //hm_result=myindex.getontologyClassURI(array[1]); + hm_result=getUriFromIndex(array[1].toLowerCase(),2); + System.out.println("direkt gefunden URI: "+hm_result); + if(hm_result.contains("NONE")){ + hm_result=getUriFromIndex(array[1].toLowerCase(),3); + if(hm_result.contains("NONE"))hm_result="http://dbpedia.org/ontology/"+Character.toUpperCase(array[1].charAt(0)) + array[1].substring(1, array[1].length()); + } + queryObject.setHashValue(array[1], hm_result); + } + + //check for Yago! + String hm_result_new=getUriFromIndex(array[1].toLowerCase(),3); + /*if(!hm_result_new.contains("NONE")){ + //set identefire + yago_query="YAGO"+query.replace(replace, "<"+hm_result_new+">"); + yago_query_upside_down="YAGO"+query_upside_down.replace(replace, "<"+hm_result_new+">"); + } + else{*/ + yago_query="NONE"; + yago_query_upside_down="NONE"; + //} + //add the uri for the Resource in isA case, so I dont have to search for it again + queryObject.setIsaResource(hm_result); + + System.out.println(array[1]+" for getOntologyClass "+hm_result); //System.out.print("URI for_ThingGettingURIfor: "+hm_result); try @@ -1431,8 +1570,13 @@ if(array[0].length()<2)replace = "?"+array[0]+" "; else replace="?"+array[0]; - String hm_result=getUriFromIndex(array[1],0); - //System.out.print("URI for_ThingGettingURIfor: "+hm_result); + String hm_result=""; + hm_result=queryObject.getHashValue(array[1]); + if(hm_result.contains("NONE")){ + hm_result=getUriFromIndex(array[1],0); + queryObject.setHashValue(array[1], hm_result); + } + try { if(hm_result.contains("Category:")) hm_result=hm_result.replace("Category:",""); @@ -1446,6 +1590,10 @@ //System.out.println("Query: "+query); query_upside_down=query_upside_down.replace(replace, "<"+hm_result+">"); //System.out.println("Query Up Side Down: "+query_upside_down); + /* if(!yago_query.contains("NONE")){ + yago_query=yago_query.replace(replace, "<"+hm_result+">"); + yago_query_upside_down=yago_query_upside_down.replace(replace, "<"+hm_result+">"); + }*/ } @@ -1455,12 +1603,21 @@ if(array[0].length()<2)replace = "?"+array[0]+" "; else replace="?"+array[0]; - String hm_result=getUriFromIndex(array[1],1); + String hm_result=""; + hm_result=queryObject.getHashValue(array[1]); + if(hm_result.contains("NONE")){ + hm_result=getUriFromIndex(array[1],1); + queryObject.setHashValue(array[1], hm_result); + } query=query.replace(replace, "<"+hm_result+">"); //System.out.println("Query: "+query); query_upside_down=query_upside_down.replace(replace, "<"+hm_result+">"); //System.out.println("Query Up Side Down: "+query_upside_down); + /* if(!yago_query.contains("NONE")){ + yago_query=yago_query.replace(replace, "<"+hm_result+">"); + yago_query_upside_down=yago_query_upside_down.replace(replace, "<"+hm_result+">"); + }*/ } @@ -1470,6 +1627,12 @@ query=query.replace("><","> <").replace(">?", "> ?"); query=query.replace("/__", "/"); query_upside_down=query_upside_down.replace("/__", "/"); + /*if(!yago_query.contains("NONE")){ + yago_query_upside_down=yago_query_upside_down.replace("><","> <").replace(">?", "> ?"); + yago_query=yago_query.replace("><","> <").replace(">?", "> ?"); + yago_query=yago_query.replace("/__", "/"); + yago_query_upside_down=yago_query_upside_down.replace("/__", "/"); + }*/ lstquerupsidedown.add(query_upside_down); lstquerynew.add(query); System.out.println("Query: "+query); @@ -1484,6 +1647,7 @@ ArrayList<String> lsttmp=createLeftAndRightPropertyArray(query); //if its lower than three, we dont have any conditions and dont need to check it. //also if the size%3 isnt 0, than something else is wrong and we dont need to test the query + System.out.println("lsttmp :"+lsttmp); if(lsttmp.size()>=3&&lsttmp.size()%3==0){ for(String i : lsttmp) lstquerynew.add(i.replace("__","")); lstquery.add(lstquerynew); @@ -1515,7 +1679,8 @@ } System.out.println("List of Query: "+lstquery); - return lstquery; + queryObject.setQueryInformation(lstquery); + return queryObject; } @@ -1558,7 +1723,7 @@ /** * * @param string - * @param fall 1 Property 0 no Property + * @param fall 1=Property, 0=Resource, 2=OntologyClass, 3=Yago * @return * @throws SQLException */ @@ -1574,25 +1739,114 @@ String result=null; String tmp1=null; String tmp2 = null; - //just to be sure its only 0 or 1 - if(fall!=0 && fall!=1) fall=0; + if(fall==0){ - //first try: take always the ontology if existing and not the Resource - tmp1=myindex.getResourceURI(string.toLowerCase()); - tmp2=myindex.getontologyClassURI(string.toLowerCase()); - /*System.out.println("URI from resource: "+tmp1); - System.out.println("URI from ontologyClass: "+tmp2);*/ + result=myindex.getResourceURI(string.toLowerCase()); + if(result==null){ + /* + * Second try lemmatised one + */ + result=myindex.getResourceURI(lemmatiser.stem(string.toLowerCase())); + if(result==null){ + /* + * Third try lemmatised with like + */ + ArrayList<String> tmp=myindex.getResourceURILike(lemmatiser.stem(string.toLowerCase())); + double highestNLD=0; + String bestWord=""; + try{ + if(!tmp.isEmpty()){ + for(String i : tmp){ + double nld_tmp=Levenshtein.nld(string.toLowerCase(), i); + if(nld_tmp>highestNLD) bestWord=i; + } + result=bestWord; + } + else{ + result="NONE"; + } + } + catch(Exception e){ + result="NONE"; + } + } + } + + } + if(fall==2){ + System.out.println("Im Ontology Fall"); + result=myindex.getontologyClassURI(string.toLowerCase()); + if(result==null){ + /* + * Second try lemmatised one + */ + result=myindex.getontologyClassURI(lemmatiser.stem(string.toLowerCase())); + if(result==null){ + /* + * Third try lemmatised with like + */ + ArrayList<String> tmp=myindex.getontologyClassURILike(lemmatiser.stem(string.toLowerCase())); + double highestNLD=0; + String bestWord=""; + try{ + if(!tmp.isEmpty()){ + for(String i : tmp){ + double nld_tmp=Levenshtein.nld(string.toLowerCase(), i); + if(nld_tmp>highestNLD) bestWord=i; + } + result=bestWord; + } + else{ + result="NONE"; + } + } + catch(Exception e){ + result="NONE"; + } + } + } + System.out.println("URi in Ontology: "+result); + + } + if(fall==3){ - - if(tmp1!=null && tmp2!=null) result=tmp2; - if(tmp1!=null && tmp2==null) result=tmp1; - if(tmp1==null && tmp2!=null) result=tmp2; - - //result=myindex.getResourceURI(string.toLowerCase()); - if(result==null)result=myindex.getPropertyURI(string.toLowerCase()); + System.out.println("Im Yago Fall"); + result=myindex.getYagoURI(string.toLowerCase()); + if(result==null){ + /* + * Second try lemmatised one + */ + result=myindex.getYagoURI(lemmatiser.stem(string.toLowerCase())); + if(result==null){ + /* + * Third try lemmatised with like + */ + ArrayList<String> tmp=myindex.getYagoURILike(lemmatiser.stem(string.toLowerCase())); + double highestNLD=0; + String bestWord=""; + try{ + if(!tmp.isEmpty()){ + for(String i : tmp){ + double nld_tmp=Levenshtein.nld(string.toLowerCase(), i); + if(nld_tmp>highestNLD) bestWord=i; + } + result=bestWord; + } + else{ + result="NONE"; + } + } + catch(Exception e){ + result="NONE"; + } + } + } + System.out.println("URi in Ontology: "+result); + } + if(fall==1){ tmp1=myindex.getPropertyURI(string.toLowerCase()); tmp2=myindex.getontologyURI(string.toLowerCase()); @@ -1600,7 +1854,10 @@ if(tmp1!=null && tmp2==null) result=tmp1; if(tmp1==null && tmp2!=null) result=tmp2; if(result==null){ + //kann ich mir sparen result=myindex.getResourceURI(string.toLowerCase()); + + if(result!=null) result=result.replace("resource", "property"); } @@ -1653,25 +1910,11 @@ ArrayList<String> semantics = new ArrayList<String>(); semantics=semanticsOrig; - /*//check out, if in the semantics are still terms, with _ or , - //if so, split on _ and , and add them to the semantic list - for(String id :semanticsOrig){ - if(id.contains("_")){ - System.out.println("in _"); - String[] tmp=id.split("_"); - for(String i: tmp) if(!semantics.contains(i))semantics.add(i); - - //and also add a term without _ - if(!semantics.contains(id.replace("_"," ")))semantics.add(id.replace("_"," ")); - //remove old id - //semantics.remove(id); - } - if(id.contains(",")){ - System.out.println("in ,"); - String[] tmp=id.split(","); - for(String i: tmp) if(!semantics.contains(i))semantics.add(i); - //semantics.remove(id); - } + //also look at the stemmt part! + /*for(String s: semanticsOrig){ + String bla=lemmatiser.stem(s); + semantics.add(bla); + semantics.add(s); }*/ try{ @@ -1802,35 +2045,59 @@ * change to dbpedia http://dbpedia.org/sparql */ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; System.out.println(tmp); - URL url; - InputStream is; - InputStreamReader isr; - BufferedReader r; - String str=""; - String result=""; + String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + //System.out.println(tmp); + String result=""; + HttpURLConnection connection = null; + OutputStreamWriter wr = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + + URL serverAddress = null; + + try { + serverAddress = new URL(tmp); + //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; + wr = null; + connection = null; + } + - try { - url = new URL(tmp); - is = url.openStream(); - isr = new InputStreamReader(is); - r = new BufferedReader(isr); - int counter=0; - do { - str = r.readLine(); - if (str != null){ - result=result.concat(str); - counter=counter+1;} - } while (str != null); - - } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); - } catch (IOException e) { - System.out.println("Can not connect"); - } + - return createAnswer(result); } @@ -1842,35 +2109,56 @@ //String tmp="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; String tmp=Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - System.out.println(tmp); - URL url; - InputStream is; - InputStreamReader isr; - BufferedReader r; - String str=""; - String result=""; - - try { - url = new URL(tmp); - is = url.openStream(); - isr = new InputStreamReader(is); - r = new BufferedReader(isr); - int counter=0; - do { - str = r.readLine(); - if (str != null){ - result=result.concat(str); - counter=counter+1;} - } while (str != null); - - } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); - } catch (IOException e) { - System.out.println("Can not connect"); - } + //System.out.println(tmp); + String result=""; + HttpURLConnection connection = null; + OutputStreamWriter wr = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + URL serverAddress = null; + try { + serverAddress = new URL(tmp); + //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; + wr = null; + connection = null; + } + + return createAnswerArray(result); } Modified: 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-01-06 14:24:45 UTC (rev 3541) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2012-01-08 13:42:22 UTC (rev 3542) @@ -11,9 +11,13 @@ 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 @@ -23,18 +27,33 @@ createIndexResource(); createWordnetHelp(); createIndexOntology(); - createIndexoOntologyClass(); + 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 @@ -43,6 +62,66 @@ } } + + 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(); @@ -88,9 +167,28 @@ } + 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; @@ -233,16 +331,12 @@ System.out.println("Done"); } private void createIndexPropertys() throws ClassNotFoundException, SQLException{ - /*System.out.println("Start SQL test"); - Class.forName( "org.sqlite.JDBC" ); - conn = DriverManager.getConnection("jdbc:sqlite::memory:");*/ 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; - // conn.setAutoCommit(false); int zaehler=0; try { in = new BufferedReader( @@ -256,12 +350,11 @@ 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"); + // System.out.println(zaehler+" done"); } } @@ -282,18 +375,17 @@ 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 SQL test");*/ 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; - // conn.setAutoCommit(false); int zaehler=0; try { in = new BufferedReader( @@ -307,12 +399,10 @@ 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); } } @@ -333,6 +423,7 @@ conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); + System.out.println("Number of Resources: "+zaehler); System.out.println("Done"); @@ -365,7 +456,7 @@ conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(false); - System.out.println("done" + zaehler); + //System.out.println("done" + zaehler); } } @@ -386,11 +477,12 @@ conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); + System.out.println("Number of Ontologys: "+zaehler); System.out.println("Done"); } -private void createIndexoOntologyClass() throws ClassNotFoundException, SQLException{ +private void createIndexOntologyClass() throws ClassNotFoundException, SQLException{ /*System.out.println("Start SQL test");*/ System.out.println("start indexing ontologyClass"); Statement stat = conn.createStatement(); @@ -417,7 +509,7 @@ conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(false); - System.out.println("done" + zaehler); + //System.out.println("done" + zaehler); } } @@ -438,9 +530,65 @@ 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("dro... [truncated message content] |
From: <seb...@us...> - 2012-02-09 16:15:38
|
Revision: 3579 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3579&view=rev Author: sebastianwtr Date: 2012-02-09 16:15:27 +0000 (Thu, 09 Feb 2012) Log Message: ----------- [tbsl-exploration] some minor changes Modified 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/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: 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-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -20,7 +20,8 @@ //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; String Prefix="http://dbpedia.org/sparql"; - //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/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{ 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-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -58,7 +58,7 @@ static int explorationdepthwordnet=2; static int iterationdepth =0; static int numberofanswers=1; - static double LevenstheinMin = 0.9; + static double LevenstheinMin = 0.8; static WordNet wordnet; BasicTemplator btemplator; Templator templator; @@ -71,7 +71,8 @@ //change here and in 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:8892/sparql"; + //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; //Konstruktor @@ -650,11 +651,20 @@ // TODO Auto-generated catch block e.printStackTrace(); }*/ + System.out.println(property_to_compare_with + " : "+property_to_compare_with_uri +" : "+uri_isA_Resource); if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,property_to_compare_with_uri,list_of_properties); if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with_uri,property_to_compare_with_uri,list_of_properties); - + /* BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); + String line; + + try { + line = in1.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ return new_queries; } @@ -703,6 +713,9 @@ //System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); System.out.println("URI from Resource "+ resource +": "+queryObject.getHashValue(resource.toLowerCase())); + HashMap<String, String> bla = queryObject.getHashMap(); + System.out.println("INhalt Hasmap QueryObject:"); + for (String z: bla.keySet()) System.out.println(z); //gets Propertys left or right from the resource! try { @@ -756,7 +769,7 @@ double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); //check if nld is greater than Levensthein - if(nld>=LevenstheinMin){ + if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ //if its so, replace old uri with the new one String querynew=query; //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); @@ -913,19 +926,31 @@ ArrayList<String> semantics=new ArrayList<String>(); ArrayList<String> tmp_semantics=new ArrayList<String>(); ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(property); + if(property.contains("_")){ + String[] fix = property.split("_"); + //here add also lemmatiser + for(String s: fix) semantics.add(s); + } + else semantics.add(property); System.out.println("Semantics: "+ semantics); - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_=myindex.getWordnetHelp(property); - if(_temp_==null){ - tmp_semantics=semantics; + for(String s: semantics){ + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + //String _temp_=myindex.getWordnetHelp(property); + String _temp_=myindex.getWordnetHelp(s); + if(_temp_!=null){ + //tmp_semantics=semantics; + tmp_semantics.add(_temp_); + tmp_semantics.add(s); + } + else tmp_semantics.add(s); + /* + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + }*/ } - else{ - semantics.clear(); - semantics.add(_temp_); - tmp_semantics=semantics; - } System.out.println("tmp_semantics: "+ tmp_semantics); Boolean goOnAfterWordnet = true; @@ -965,11 +990,12 @@ key=key.replace("@en",""); for(String b : semantics){ - if(key.contains(b.toLowerCase())){ + if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ if(!result_SemanticsMatchProperties.contains(key)){ result_SemanticsMatchProperties.add(key); String query_tmp=query; //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + System.out.println("URI of property: "+uri_of_property); String replacement = uri_of_property; if(!query_tmp.contains(replacement)){ replacement=replacement.replace("ontology", "property"); @@ -1765,6 +1791,21 @@ } else{ result="NONE"; + String tmp11=originalString; + String hotfix ="http://dbpedia.org/resource/"+tmp11; + if(tmp11.contains("_")){ + String[] newarraytmp=tmp11.split("_"); + String tmpneu=""; + for(String s :newarraytmp){ + tmpneu+= "_"+ Character.toUpperCase(s.charAt(0)) + s.substring(1); + } + tmpneu=tmpneu.replaceFirst("_", ""); + hotfix ="http://dbpedia.org/resource/"+tmpneu; + hotfix=hotfix.replace("/__", "/"); + System.out.println("Hotfix: "+hotfix); + } + result=hotfix; + } } catch(Exception e){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -39,6 +39,8 @@ public String getHashValue(String key) { key=key.toLowerCase(); + key=key.replace(" ", ""); + key=key.replace("_", " "); String result ="NONE"; try{ result=this.hashMap.get(key); @@ -51,6 +53,9 @@ } public void setHashValue(String key, String value) { + key=key.replace(" ", ""); + key=key.replace("_", " "); + value=value.replace("__", ""); this.hashMap.put(key.toLowerCase(), value); } 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-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -165,17 +165,17 @@ //queryInformation tmpquery; //only question, which are not yago files if(s.isYago()==true)yago_querys=yago_querys+1; - if(s.isYago()==false){ + //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; } - } + //} } - /* - //Print to Console + + /* //Print to Console System.out.println("\n#############\n Result:"); for(queryInformation s : list_of_resultstructs){ System.out.println(s.getResult()); @@ -221,9 +221,15 @@ queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); result= sparql.create_Sparql_query(newQuery); ArrayList<String> ergebnis = result.getResult(); + //get eacht result only once! + Set<String> setString = new HashSet<String>(); for(String i: ergebnis){ - System.out.println(i); + setString.add(i); + //System.out.println(i); } + for(String z: setString){ + System.out.println(z); + } long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -311,7 +317,13 @@ xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; } tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; - for(String i : s.getResult()){ + + //to get all answers only once! + Set<String> setString = new HashSet<String>(); + for(String z: s.getResult()){ + setString.add(z); + } + for(String i : setString){ String input=""; if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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] |
From: <seb...@us...> - 2012-03-14 17:27:24
|
Revision: 3610 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3610&view=rev Author: sebastianwtr Date: 2012-03-14 17:27:16 +0000 (Wed, 14 Mar 2012) Log Message: ----------- [tbsl exploration] added some functions Modified Paths: -------------- 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/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/TemplateBuilder.java 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/exploration_main/testClass_new.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java Modified: 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/Index_utils.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -50,7 +50,113 @@ return result_List; } + + +public static ArrayList<String> searchIndexForResource(String string, SQLiteIndex myindex) throws SQLException{ + + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String result=null; + ArrayList<String> result_List = new ArrayList<String>(); + result=myindex.getResourceURI(string.toLowerCase()); + if(result!=null){ + result_List.add(result); + } + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getResourceURILike(s.toLowerCase(), string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + return result_List; + } + +public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String result=null; + ArrayList<String> result_List = new ArrayList<String>(); + result=myindex.getPropertyURI(string.toLowerCase()); + if(result!=null){ + result_List.add(result); + } + else{ + result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + } + + + + return result_List; } + + + +public static ArrayList<String> searchIndexForClass(String string, SQLiteIndex myindex) throws SQLException{ + + /* + * TODO: also return a rank, if you find a direct match, give back 1, if you find a part match, give back for example 0.3 if you have a string you can split in 3 + */ + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String tmp1=null; + String tmp2 = null; + ArrayList<String> result_List = new ArrayList<String>(); + + tmp1=myindex.getontologyClassURI(string.toLowerCase()); + tmp2=myindex.getYagoURI(string.toLowerCase()); + if(tmp1!=null){ + result_List.add(tmp1); + } + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getontologyClassURILike(s.toLowerCase(),string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + if(tmp2!=null) { + result_List.add(tmp2); + } + /* + * if nothing is found, also try the like operator for each part of the string + */ + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getYagoURILike(s.toLowerCase(),string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + + return result_List; + } + + + + +} Modified: 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/Index/SQLiteIndex.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -13,11 +13,13 @@ import java.sql.Statement; import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; + double lim_levensthein=0.84; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub @@ -63,17 +65,20 @@ } - public ArrayList<String> getResourceURILike(String string) throws SQLException{ + public ArrayList<String> getResourceURILike(String string, String original_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()+"%';"); + rs = stat.executeQuery("select * from resource where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { @@ -84,17 +89,21 @@ } - public ArrayList<String> getYagoURILike(String string) throws SQLException{ + public ArrayList<String> getYagoURILike(String string, String original_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()+"%';"); + rs = stat.executeQuery("select * from yago where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + //System.out.println("Next: "+rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { @@ -167,15 +176,18 @@ } - public ArrayList<String> getontologyClassURILike(String string) throws SQLException{ + public ArrayList<String> getontologyClassURILike(String string, String original_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()+"%';"); + rs = stat.executeQuery("select * from ontologyClass where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { 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-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,6 +1,5 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; -import edu.stanford.nlp.io.EncodingPrintWriter.out; public class Hypothesis { private String variable; 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-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1780,7 +1780,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getResourceURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getResourceURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ @@ -1830,7 +1830,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getontologyClassURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getontologyClassURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ @@ -1866,7 +1866,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getYagoURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getYagoURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ 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-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -161,7 +161,10 @@ */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit,question); - //TODO: Iterate over slots + + boolean add_reverse_template = true; + + ArrayList<Hypothesis> list_of_hypothesis = new ArrayList<Hypothesis>(); for(Slot slot : bqt.getSlots()){ //System.out.println("Slot: "+slot.toString()); @@ -169,9 +172,26 @@ 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], tmp_array[1], "UNSPEC", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); + for(ArrayList<String> x : condition){ + if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0); + //tmp_hypothesis.printAll(); + list_of_hypothesis.add(tmp_hypothesis); + + /* + * if you have already found an isA -Class-Pair, you dont have to creat the up-side-down, because it will be false + */ + add_reverse_template = false; + } + /* + * Make sure you dont have the case that a class is left of an isA + */ + else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[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 {", ""); @@ -193,13 +213,18 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for(Hypothesis x : list_of_hypothesis){ - if(x.getType().contains("RESOURCE")|| x.getType().contains("UNSPEC") ){ + /* + * TODO: Change if ISA only ask classes, else resource + */ + if(x.getType().contains("RESOURCE")|| x.getType().contains("UNSPEC")|| x.getType().contains("ISA") ){ ArrayList<String> result= new ArrayList<String>(); try { - /* 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); + if(x.getType().contains("ISA")){ + result = Index_utils.searchIndexForClass(x.getUri(), myindex); + } + else{ + result = Index_utils.searchIndexForResource(x.getUri(), myindex); + } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -252,7 +277,7 @@ result.add(hm.get(h.getUri().toLowerCase())); } else{ - result = Index_utils.searchIndex(h.getUri(), 1, myindex); + result = Index_utils.searchIndexForProperty(h.getUri(), myindex); if(!result.isEmpty())hm.put(h.getUri().toLowerCase(),result.get(0)); } if(!result.isEmpty()){ @@ -260,12 +285,12 @@ h.setRank(1); } - else{ + /* else{ String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase().replace(" ", "_"); h.setUri(tmp); h.setRank(0); - } + }*/ } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -278,18 +303,18 @@ - //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.getQuestion()); - //= template; ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); - for (ArrayList<String> x : condition_template_reverse_conditions){ - ArrayList<String> new_list = new ArrayList<String>(); - new_list.add(x.get(2)); - new_list.add(x.get(1)); - new_list.add(x.get(0)); - condition_reverse_new.add(new_list); + if(add_reverse_template){ + for (ArrayList<String> x : condition_template_reverse_conditions){ + ArrayList<String> new_list = new ArrayList<String>(); + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } } long stop = System.currentTimeMillis(); @@ -303,7 +328,7 @@ template_reverse_conditions.setHypothesen(template.getHypothesen()); resultArrayList.add(template); - resultArrayList.add(template_reverse_conditions); + if(add_reverse_template) resultArrayList.add(template_reverse_conditions); } } /*for(Template temp : resultArrayList){ Modified: 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/GetRessourcePropertys.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,18 +1,12 @@ package org.dllearner.algorithm.tbsl.exploration.Utils; 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; public class GetRessourcePropertys { Modified: 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/Levenshtein.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -2,7 +2,6 @@ import java.lang.Math; -import java.math.BigDecimal; public class Levenshtein { @@ -12,10 +11,8 @@ //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; + return 1.0; } else{ Deleted: 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/Utils/SparqlFilter.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,54 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Utils; - -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/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -32,38 +32,60 @@ TemplateBuilder testobject = new TemplateBuilder(); - String dateiname = "/home/swalter/Dokumente/Auswertung/"; + String filepath = "/home/swalter/Dokumente/Auswertung/"; + //String file="very_small.xml"; + String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); //String question = "Is the wife of president Obama called Michelle?"; - /*String question = "Which bridges are of the same type as the Manhattan Bridge?"; - temp_list_result=testobject.createTemplates(question);*/ + String question = "Who is the mayor of Berlin?"; + temp_list_result=testobject.createTemplates(question); + for(Template t : temp_list_result){ + t.printAll(); + } ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - //if you dont want to use the hints in the questions, use false - list_of_structs=generateStruct(dateiname+"XMLDateien/dbpedia-train_small.xml"); - System.out.println("Start Templating"); + + /* + * Generate Templates + */ + /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); for(queryInformation s : list_of_structs){ - System.out.println("In For Schleife"); ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); } - } + }*/ + /* + * Get Elements for Each Resource and Class + */ + long stop = System.currentTimeMillis(); System.out.println("Duration in ms: " + (stop - start)); - - String result =""; + + /* + * Write Results in File + */ + writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + + } + + + private static void writeTemplatesInFile(ArrayList<Template> temp_list_result, String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Ausgabe"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + int anzahl1 =1; for(Template t: temp_list_result){ //t.printAll(); + String result =""; result+="###### Template ######\n"; result+="question: "+t.getQuestion()+"\n"; result+="condition: "+t.getCondition()+"\n"; @@ -91,24 +113,24 @@ result+="Overalltime: "+t.getOverallTime()+"ms\n"; result+="Time for Templator: "+t.getTime_Templator()+"ms\n"; result+="////////////////////////////////////////////////////////////////////\n\n\n"; + bw.write(result+"\n"); + //bw.flush(); + System.out.println("Done "+anzahl1); + anzahl1 +=1; + } - + String result=""; result+="Time over generating All Templates: "+(stop-start)+"ms\n"; result+="Average Time for one Template: "+((stop-start)/temp_list_result.size())+"ms\n"; result+="Overall created Templates: "+temp_list_result.size(); //System.out.println(result); - File file = new File(dateiname+"Ausgabe"+stop+".txt"); - BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(result); bw.flush(); bw.close(); - } - - private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); String XMLType=null; @@ -158,13 +180,13 @@ } ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); if(string.contains("</question><question")){ - System.out.println("true"); + //System.out.println("true"); } else System.out.println("false"); String [] bla = string.split("</question><question"); - System.out.println(bla.length); + //System.out.println(bla.length); for(String s : bla){ - System.out.println("in bla"); + //System.out.println("in bla"); String query=""; String type=""; boolean fusion=false; @@ -181,7 +203,7 @@ Pattern p2= Pattern.compile(".*><string>(.*)"); Matcher m2 = p2.matcher(m1.group(1)); while(m2.find()){ - System.out.println("Query: "+ m2.group(1)); + //System.out.println("Query: "+ m2.group(1)); query=m2.group(1).replace("<![CDATA[", ""); query=query.replace("CDATA", ""); query=query.replace("CDATA", ""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-18 21:44:37
|
Revision: 3615 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3615&view=rev Author: sebastianwtr Date: 2012-03-18 21:44:30 +0000 (Sun, 18 Mar 2012) Log Message: ----------- [tbsl exploration] improved some functions Modified Paths: -------------- 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/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 trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java Modified: 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/Index_utils.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -2,6 +2,8 @@ import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; public class Index_utils { @@ -15,7 +17,7 @@ */ 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(".", " "); @@ -54,8 +56,8 @@ public static ArrayList<String> searchIndexForResource(String string, SQLiteIndex myindex) throws SQLException{ - - string=string.replace("_", " "); + HashMap<String,Float> hm = new HashMap<String,Float>(); +string=string.replace("_", " "); string=string.replace("-", " "); string=string.replace(".", " "); String result=null; @@ -82,6 +84,15 @@ } public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ + HashMap<String,Float> hm = new HashMap<String,Float>(); + + // adding or set elements in Map by put method key and value pair + /* + * + * // autoboxing takes care of that. +map.put(23, 2.5f); +map.put(64, 4.83f); + */ string=string.replace("_", " "); string=string.replace("-", " "); @@ -91,14 +102,17 @@ result=myindex.getPropertyURI(string.toLowerCase()); if(result!=null){ result_List.add(result); + hm.put(result, 1.0f); } else{ result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + hm.put(result, 0.0f); } return result_List; + //return hm; } Modified: 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/Index/SQLiteIndex.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.84; + double lim_levensthein=0.88; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub 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-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -28,8 +28,8 @@ import net.didion.jwnl.data.POS; 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.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; @@ -582,11 +582,11 @@ if(tmpcounter <=number_of_x_used){ HashMap<String,String> propertiesleft = new HashMap<String, String>(); HashMap<String,String> propertiesright = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); + // GetRessourcePropertys property = new GetRessourcePropertys(); try { - propertiesleft=property.getPropertys(s,"LEFT",timeToTimeoutOnServer); - propertiesright=property.getPropertys(s,"RIGHT",timeToTimeoutOnServer); + propertiesleft=ServerUtil.sendServerPropertyRequest(s,"LEFT"); + propertiesright=ServerUtil.sendServerPropertyRequest(s,"RIGHT"); } catch (Exception e){ @@ -709,7 +709,6 @@ HashMap<String,String> properties = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; @@ -721,7 +720,7 @@ //gets Propertys left or right from the resource! try { - properties=property.getPropertys(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty,timeToTimeoutOnServer); + properties=ServerUtil.sendServerPropertyRequest(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); if (properties==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -844,14 +843,13 @@ } HashMap<String,String> propertiesOne = new HashMap<String, String>(); HashMap<String,String> propertiesTwo = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; //Get Properties for Resource in condition One and Two from Server try { - propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne,timeToTimeoutOnServer); - propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo,timeToTimeoutOnServer); + propertiesOne=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + propertiesTwo=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); if (propertiesOne==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); 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-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -13,6 +13,7 @@ private String OrderBy; private String limit; private String question; + private String queryType; private float overallTime; private float time_Templator; @@ -49,7 +50,7 @@ } - 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){ + public Template(ArrayList<ArrayList<String>>condition_new, String queryType_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); @@ -57,6 +58,7 @@ this.setLimit(limit_new); this.setSelectTerm(SelectTerm_new); this.setQuestion(question_new); + this.setQueryType(queryType_new); } public ArrayList<ArrayList<String>> getCondition() { return condition; @@ -90,6 +92,7 @@ } } System.out.print("\n"); + System.out.println("QueryType "+queryType); System.out.println("selectTerm: "+selectTerm); System.out.println("having: "+having); System.out.println("filter: "+filter); @@ -125,6 +128,12 @@ public void addToList_of_element_uri_pair(ElementList_new newElement) { this.list_of_element_uri_pair.add(newElement); } + public String getQueryType() { + return queryType; + } + public void setQueryType(String queryType) { + this.queryType = queryType; + } } 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-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -160,7 +160,7 @@ * SLOT_title: PROPERTY {title,name,label} mitfuehren */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit,question); + Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); boolean add_reverse_template = true; @@ -226,12 +226,12 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /*System.out.println("Alle Hypothesen VOR der Verarbeitung"); + /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); - */ + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n");*/ + for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource @@ -258,16 +258,19 @@ if(s!=null){ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1); new_list.add(new_h); + //new_h.printAll(); } else{ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1); new_list.add(new_h); + //new_h.printAll(); } } else{ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), h.getRank()); new_list.add(new_h); + //new_h.printAll(); } } final_list_set_hypothesis.add(new_list); @@ -275,8 +278,14 @@ } } + /*System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ + for(Hypothesis x : lh){ + x.printAll(); + } + } + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n");*/ - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* @@ -288,7 +297,7 @@ for(Hypothesis h : x){ - + //h.printAll(); //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"))){ @@ -321,11 +330,23 @@ } } + /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ + for(Hypothesis x : lh){ + x.printAll(); + } + } + + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n");*/ + + + + template.setHypothesen(final_list_set_hypothesis); - Template template_reverse_conditions = new Template(template.getCondition(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); + Template template_reverse_conditions = new Template(template.getCondition(),template.getQueryType(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); @@ -353,9 +374,13 @@ if(add_reverse_template) resultArrayList.add(template_reverse_conditions); } } - /*for(Template temp : resultArrayList){ + + /*System.out.println("Nach allen Verarbeitungsschritten:"); + for(Template temp : resultArrayList){ temp.printAll(); - }*/ + } + + System.out.println("Nach allen Verarbeitungsschritten - DONE");*/ return resultArrayList; } } Deleted: 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/GetRessourcePropertys.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -1,159 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; - - -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{ - - String vergleichorig = vergleich; - - 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="; - - 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("BOTH")) verarbeitungsurl=tmp_both; - - 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'); - } - - 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; - connection = null; - } - - HashMap<String,String> hm = new HashMap<String,String>(); - 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]); - } - - return hm; - } - - - - - - 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; - } - -} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,63 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; + +public class Query { + + /** + * Creates Queries + * @param t + * @return + */ + public static ArrayList<QueryPair> returnSetOfQueries(Template t){ + + ArrayList<QueryPair> queryList = new ArrayList<QueryPair>(); + /* + * TODO: Generate a Query for each Hypothesenset, replacing the variable in the condition with the uri from the hypothesenset in <> + */ + String condition=""; + for(ArrayList<String> conditionList :t.getCondition()){ + for(String s : conditionList) condition+=s+" "; + //to End a triple of variables + condition+="."; + } + /* + * Now replacing varibale with the uri from the Hypot. + */ + for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ + String condition_new = condition; + //System.out.println("New_Condition before replacing "+condition_new); + float global_rank=0; + boolean addQuery=true; + for(Hypothesis h : hypothesenList){ + condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); + /* + * Dont create a Query with variables, which dont have a correct uri + */ + if(!h.getUri().contains("http")){ + addQuery=false; + } + condition_new=condition_new.replace("isA", "rdf:type"); + global_rank=global_rank+h.getRank(); + } + //System.out.println("New_Condition after replacing "+condition_new); + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); + QueryPair qp = new QueryPair(query,global_rank); + if(addQuery)queryList.add(qp); + } + + + return queryList; + } + + /*public static QueryPair getBestQuery(Template t){ + ArrayList<QueryPair> qp = returnSetOfQueries(t); + + + return ; + }*/ + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,30 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +public class QueryPair { + private String Query; + private float rank; + public String getQuery() { + return Query; + } + public void setQuery(String query) { + Query = query; + } + public float getRank() { + return rank; + } + public void setRank(float rank) { + this.rank = rank; + } + + public void printAll(){ + System.out.println("Query :"+this.getQuery()); + System.out.println("Rank :"+this.getRank()); + } + + public QueryPair(String query_new, float rank_new){ + this.setQuery(query_new); + this.setRank(rank_new); + } + + +} Added: 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 (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,163 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; + +public class ServerUtil { + + + //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 int timeToTimeoutOnServer=30000; + + + public static 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 static 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; + } + + public static String getServer_Prefix() { + return server_Prefix; + } + + public static int getTimeToTimeoutOnServer() { + return timeToTimeoutOnServer; + } + + public static void setTimeToTimeoutOnServer(int timeToTimeoutOnServer) { + ServerUtil.timeToTimeoutOnServer = timeToTimeoutOnServer; + } + + + /** + * Get an uri and saves the properties of this resource + * @param vergleich + * @return + * @throws IOException + */ + public static HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) throws IOException{ + + String vergleichorig = vergleich; + + String tmp_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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("BOTH")) verarbeitungsurl=tmp_both; + + 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(getTimeToTimeoutOnServer()); + + connection.connect(); + rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + sb = new StringBuilder(); + + while ((line = rd.readLine()) != null) + { + sb.append(line + '\n'); + } + + 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; + connection = null; + } + + HashMap<String,String> hm = new HashMap<String,String>(); + 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]); + } + + return hm; + } + +} 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-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -10,6 +10,8 @@ import java.io.InputStreamReader; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,6 +19,8 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.exploration.Utils.Query; +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; public class testClass_new { @@ -37,22 +41,33 @@ String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); + /* + * TODO: WHy is there no Hypothese for the question: "Who is the mayor of Berlin?" + */ + /*String question = "Is the wife of president Obama called Michelle?"; + //String question = "Who is the mayor of Berlin?"; + //temp_list_result=testobject.createTemplates(question); - //String question = "Is the wife of president Obama called Michelle?"; - String question = "Who is the mayor of Berlin?"; - temp_list_result=testobject.createTemplates(question); + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + for(Template t : temp_list_result){ - t.printAll(); + //t.printAll(); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + for(QueryPair p : qp){ + tm.put(p, t.getQuestion()); + } } + writeQueriesInFile(tm,filepath,file,start,stop );*/ + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); /* * Generate Templates */ - /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + list_of_structs=generateStruct(filepath+"XMLDateien/"+file); for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); @@ -60,9 +75,23 @@ temp_list_result.add(t); } - }*/ + } + /* + * Create Query for each Template + */ + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + for(Template t : temp_list_result){ + //t.printAll(); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + for(QueryPair p : qp){ + tm.put(p, t.getQuestion()); + } + } + + + /* * Get Elements for Each Resource and Class */ @@ -74,7 +103,8 @@ /* * Write Results in File */ - writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + writeQueriesInFile(tm,filepath,file,start,stop ); + //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -105,6 +135,7 @@ } } result+="\n"; + result+="queryType: "+t.getQueryType()+"\n"; result+="selectTerm: "+t.getSelectTerm()+"\n"; result+="having: "+t.getHaving()+"\n"; result+="filter: "+t.getFilter()+"\n"; @@ -130,7 +161,31 @@ bw.flush(); bw.close(); } + + + private static void writeQueriesInFile(Map<QueryPair,String> tm, String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Queries"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + String result=""; + /* + * for(String key : map.keySet()) + { + System.out.print("Key: " + key + " - "); + System.out.print("Value: " + map.get(key) + "\n"); + } + */ + for(QueryPair key : tm.keySet()){ + result+=tm.get(key)+": "+key.getQuery()+" "+key.getRank()+"\n"; + } + bw.write(result); + bw.flush(); + bw.close(); + } + + + + private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); String XMLType=null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-20 15:21:12
|
Revision: 3616 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3616&view=rev Author: sebastianwtr Date: 2012-03-20 15:21:00 +0000 (Tue, 20 Mar 2012) Log Message: ----------- [tbsl exploration] started implemanting the main interation function/module Modified Paths: -------------- 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/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 trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.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/testClass_new.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 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/WordnetModule.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java Modified: 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/Index/SQLiteIndex.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.88; + double lim_levensthein=0.92; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub @@ -76,8 +76,8 @@ while(rs.next()){ if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; @@ -101,8 +101,8 @@ //System.out.println("Next: "+rs.getString("uri")); if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; @@ -185,8 +185,8 @@ while(rs.next()){ if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; Copied: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java (from rev 3613, 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.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,73 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.util.HashMap; + +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; + + +/** + * + * @author swalter + * + */ +public class ElementList { + + /** + * 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 uri; + /** + * 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 getURI() { + return uri; + } + public void setURI(String resourceURI) { + this.uri = resourceURI; + } + + public ElementList(String name_new, String resource, HashMap<String,String> hm){ + this.setHm(hm); + this.setURI(resource); + this.setVariablename(name_new); + } + + public void printAll(){ + System.out.println("Name: "+this.getVariablename()); + System.out.println("URI: "+this.getURI()); + System.out.println("List of Elements:"); + for(String key : this.hm.keySet()){ + System.out.println( key + ": "+this.hm.get(key)); + } + } + + public String printToString(){ + String result=""; + result+="Name: "+this.getVariablename()+"\n"; + result+="URI: "+this.getURI()+"\n"; + result+="List of Elements:"+"\n"; + for(String key : this.hm.keySet()){ + result+=key + ": "+this.hm.get(key)+"\n"; + } + + return result; + } +} Deleted: 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 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -1,49 +0,0 @@ -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); - } -} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,153 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.io.IOException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; + +/** + * Creates Set of Classes and Resources with their properties + * @author swalter + * + */ +public class Elements { + private ArrayList<ElementList> resources = new ArrayList<ElementList>(); + private ArrayList<ElementList> classes = new ArrayList<ElementList>(); + public ArrayList<ElementList> getResources() { + return resources; + } + public void setResources(ArrayList<ElementList> resources) { + this.resources = resources; + } + public ArrayList<ElementList> getClasses() { + return classes; + } + public void setClasses(ArrayList<ElementList> classes) { + this.classes = classes; + } + + private void addClasses(ElementList cl) { + this.classes.add(cl); + } + + private void addResources(ElementList cl) { + this.resources.add(cl); + } + + public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ + + /* + * first all Classes! + */ + try { + this.setClasses(createElementsOfClasses(hypothesen)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + /* + * second all Resources + */ + try { + this.setResources(createElementsOfResources(hypothesen,condition)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Created Elements"); + } + + private ArrayList<ElementList> createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ + ArrayList<ElementList> classes = new ArrayList<ElementList>(); + + /* + * Iterate over all Hypothesis and look for an IsA + */ + for(ArrayList<Hypothesis> hl : hypothesenList){ + for(Hypothesis h : hl){ + /* + * if isA is found and if Class has uri, get Elements + */ + if(h.getType().contains("isA")&&h.getUri().contains("http")){ + /* + * TODO: improver performance, using geschicktes zwischenspeichern + */ + ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); + classes.add(el); + } + } + } + + return classes; + } + + + private ArrayList<ElementList> createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + /* + * Iterate over all Hypothesis and look for an resource + */ + for(ArrayList<Hypothesis> hl : hypothesenList){ + for(Hypothesis h : hl){ + if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ + for(ArrayList<String> cl : conditionList){ + if(h.getVariable().equals(cl.get(0))) { + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); + resources.add(el); + } + if(h.getVariable().equals(cl.get(2))) { + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); + resources.add(el); + } + } + + + } + } + } + + return resources; + } + + + public void printAll(){ + System.out.println("Resources: "); + for(ElementList el: this.resources){ + el.printAll(); + } + System.out.println("\nClasses: "); + for(ElementList el: this.classes){ + el.printAll(); + } + } + + public String printToString(){ + String result=""; + result+="Resources: \n"; + for(ElementList el: this.resources){ + result+=el.printToString()+"\n"; + } + result+="\nClasses: \n"; + for(ElementList el: this.classes){ + result+=el.printToString()+"\n"; + } + return result; + } + + + public boolean isElementEmty(){ + try { + if(this.getClasses().isEmpty()||this.getResources().isEmpty()) return true; + else return false; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return true; + } + } + +} + + 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -4,7 +4,7 @@ public class Hypothesis { private String variable; private String uri; -private float rank; +private double rank; private String name; /** @@ -24,14 +24,14 @@ public void setVariable(String variable) { this.variable = variable; } -public float getRank() { +public double getRank() { return rank; } -public void setRank(float rank) { +public void setRank(double rank) { this.rank = rank; } -public Hypothesis(String variable, String name, String uri, String type, float rank){ +public Hypothesis(String variable, String name, String uri, String type, double rank){ this.setRank(rank); this.setVariable(variable); this.setUri(uri); 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -585,8 +585,8 @@ // GetRessourcePropertys property = new GetRessourcePropertys(); try { - propertiesleft=ServerUtil.sendServerPropertyRequest(s,"LEFT"); - propertiesright=ServerUtil.sendServerPropertyRequest(s,"RIGHT"); + propertiesleft=ServerUtil.getPropertiesForGivenResource(s,"LEFT"); + propertiesright=ServerUtil.getPropertiesForGivenResource(s,"RIGHT"); } catch (Exception e){ @@ -720,7 +720,7 @@ //gets Propertys left or right from the resource! try { - properties=ServerUtil.sendServerPropertyRequest(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); + properties=ServerUtil.getPropertiesForGivenResource(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); if (properties==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -848,8 +848,8 @@ //Get Properties for Resource in condition One and Two from Server try { - propertiesOne=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); - propertiesTwo=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); + propertiesOne=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + propertiesTwo=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); if (propertiesOne==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -4,7 +4,7 @@ public class Template { - private ArrayList<ElementList_new> list_of_element_uri_pair = new ArrayList<ElementList_new>(); + private ArrayList<ElementList> list_of_element_uri_pair = new ArrayList<ElementList>(); private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; @@ -14,6 +14,7 @@ private String limit; private String question; private String queryType; + private Elements elm; private float overallTime; private float time_Templator; @@ -118,14 +119,14 @@ public void setTime_Templator(float time_Templator) { this.time_Templator = time_Templator; } - public ArrayList<ElementList_new> getList_of_element_uri_pair() { + public ArrayList<ElementList> 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) { + public void setList_of_element_uri_pair(ArrayList<ElementList> 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) { + public void addToList_of_element_uri_pair(ElementList newElement) { this.list_of_element_uri_pair.add(newElement); } public String getQueryType() { @@ -134,6 +135,12 @@ public void setQueryType(String queryType) { this.queryType = queryType; } + public Elements getElm() { + return elm; + } + public void setElm(Elements elm) { + this.elm = elm; + } } 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -176,7 +176,7 @@ for(ArrayList<String> x : condition){ if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ no_iaA_found=false; - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0.0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); @@ -185,23 +185,10 @@ */ add_reverse_template = false; } - /* - * Make sure you don't have the case that a class is left of an isA - */ - /*else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[0])){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); - } - else if(!x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0]) ){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); - }*/ } if(no_iaA_found){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0.0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); } @@ -211,7 +198,7 @@ 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],tmp_array[1], "PROPERTY", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); list_of_hypothesis.add(tmp_hypothesis); } @@ -219,7 +206,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], tmp_array[1], "RESOURCE", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "RESOURCE", 0.0); list_of_hypothesis.add(tmp_hypothesis); } } @@ -256,12 +243,12 @@ for(Hypothesis h : list_of_hypothesis){ if (h.getUri().equals(x.getUri())){ if(s!=null){ - Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1); + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1.0); new_list.add(new_h); //new_h.printAll(); } else{ - Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1); + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1.0); new_list.add(new_h); //new_h.printAll(); } @@ -297,10 +284,6 @@ for(Hypothesis h : x){ - //h.printAll(); - - //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"))){ if(h.getType().contains("PROPERTY")){ ArrayList<String> result= new ArrayList<String>(); try { @@ -313,15 +296,8 @@ } if(!result.isEmpty()){ h.setUri(result.get(0)); - h.setRank(1); + h.setRank(0.0); } - - /* else{ - String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase().replace(" ", "_"); - - h.setUri(tmp); - h.setRank(0); - }*/ } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -369,9 +345,25 @@ template_reverse_conditions.setCondition(condition_reverse_new); template_reverse_conditions.setHypothesen(template.getHypothesen()); - - resultArrayList.add(template); - if(add_reverse_template) resultArrayList.add(template_reverse_conditions); + + /* + * Before adding Templates, generate for each Template a set of Properties and Elements + */ + Elements elm = new Elements(template.getCondition(),template.getHypothesen()); + /* + * If no Elements are created, dont add Template! + */ + //if(elm.isElementEmty()==false){ + template.setElm(elm); + resultArrayList.add(template); + //} + if(add_reverse_template){ + Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); + //if(elm_reverse.isElementEmty()==false){ + template.setElm(elm_reverse); + resultArrayList.add(template_reverse_conditions); + //} + } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -30,7 +30,7 @@ for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ String condition_new = condition; //System.out.println("New_Condition before replacing "+condition_new); - float global_rank=0; + double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -2,17 +2,17 @@ public class QueryPair { private String Query; - private float rank; + private double rank; public String getQuery() { return Query; } public void setQuery(String query) { Query = query; } - public float getRank() { + public double getRank() { return rank; } - public void setRank(float rank) { + public void setRank(double rank) { this.rank = rank; } @@ -21,7 +21,7 @@ System.out.println("Rank :"+this.getRank()); } - public QueryPair(String query_new, float rank_new){ + public QueryPair(String query_new, double rank_new){ this.setQuery(query_new); this.setRank(rank_new); } 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -73,30 +73,82 @@ /** - * Get an uri and saves the properties of this resource - * @param vergleich + * Uses an URI to get the properties of this resource + * @param uri * @return * @throws IOException */ - public static HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) throws IOException{ + public static HashMap<String,String> getPropertiesForGivenResource(String uri, String side) throws IOException{ - String vergleichorig = vergleich; - String tmp_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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 query_property_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+uri+">. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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 query_property_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+uri+"> ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_both=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.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 query_property_leftANDright=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+uri+">. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') } UNION {<"+uri+"> ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }}")+"%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("BOTH")) verarbeitungsurl=tmp_both; + if(side.contains("RIGHT")) verarbeitungsurl=query_property_right; + if(side.contains("LEFT")) verarbeitungsurl=query_property_left; + if(side.contains("BOTH")) verarbeitungsurl=query_property_leftANDright; - if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; + if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=query_property_left; String result=""; + result = getListOfElements(verarbeitungsurl); + + return generateList(result); + } + + /** + * Uses an URI of a Class to get the Elements of the Class and the related URIs + * @param classUri + * @return + * @throws IOException + */ + public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ + + + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s ?x WHERE { ?x rdf:type <"+classUri+">. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + + String result=""; + result = getListOfElements(query); + + return generateList(result); + } + + + + + + + private static HashMap<String, String> generateList(String result) { + HashMap<String,String> hm = new HashMap<String,String>(); + 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]); + } + + return hm; + } + + + + private static String getListOfElements(String verarbeitungsurl) { + + String result=""; HttpURLConnection connection = null; BufferedReader rd = null; StringBuilder sb = null; @@ -139,25 +191,9 @@ sb = null; connection = null; } - - HashMap<String,String> hm = new HashMap<String,String>(); - 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]); - } - - return hm; + return result; } + + } 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-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -15,12 +15,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; 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.Sparql.queryInformation; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; public class testClass_new { @@ -37,28 +39,35 @@ TemplateBuilder testobject = new TemplateBuilder(); String filepath = "/home/swalter/Dokumente/Auswertung/"; - //String file="very_small.xml"; - String file="dbpedia-train.xml"; + String file="very_small.xml"; + //String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); - /* - * TODO: WHy is there no Hypothese for the question: "Who is the mayor of Berlin?" - */ - /*String question = "Is the wife of president Obama called Michelle?"; - //String question = "Who is the mayor of Berlin?"; - //temp_list_result=testobject.createTemplates(question); + + //String question = "Is the wife of president Obama called Michelle?"; + String question = "Who is the leader of Hamburg?"; + temp_list_result=testobject.createTemplates(question); Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - for(Template t : temp_list_result){ + /*for(Template t : temp_list_result){ //t.printAll(); + try { + t.getElm().printAll(); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } + }*/ + for(Template t : temp_list_result){ + t.getElm().getResources(); + IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition()); } - writeQueriesInFile(tm,filepath,file,start,stop );*/ @@ -67,20 +76,28 @@ /* * Generate Templates */ - list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + String result=""; for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); + try { + result+=t.getElm().printToString()+"\n"; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } } - } + }*/ + /* * Create Query for each Template */ - Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + /*Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); for(Template t : temp_list_result){ //t.printAll(); @@ -88,7 +105,7 @@ for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } - } + }*/ @@ -96,14 +113,14 @@ * Get Elements for Each Resource and Class */ - long stop = System.currentTimeMillis(); + /*long stop = System.currentTimeMillis(); System.out.println("Duration in ms: " + (stop - start)); - + writeStringToFile(result,filepath,file,start,stop); */ /* * Write Results in File */ - writeQueriesInFile(tm,filepath,file,start,stop ); + //writeQueriesInFile(tm,filepath,file,start,stop ); //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -177,14 +194,23 @@ for(QueryPair key : tm.keySet()){ result+=tm.get(key)+": "+key.getQuery()+" "+key.getRank()+"\n"; } - + result+="OverAll Time: "+(stop-start)+"ms\n"; bw.write(result); bw.flush(); bw.close(); } + private static void writeStringToFile(String result,String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Sonstiges"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + bw.write(result); + bw.flush(); + bw.close(); + } + + private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,127 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +import java.sql.SQLException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; + +/** + * Gets Elements, Condition and Hypothesen and returns HypothesenSets. + * Also the different Modules, like Levensthein, Wordnet are used here. + * @author swalter + * + */ +public class IterationModule { + + /** + * returns ArrayList<ArrayList<Hypothesis>> which than can be added using + * @param elm + * @param hypothesen + * @param condition + * @return ArrayList<ArrayList<Hypothesis>> + */ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList){ + + for(ArrayList<Hypothesis> hl :givenHypothesenList){ + + /* + * First look for resources and generate List with properties + */ + for(Hypothesis h : hl){ + if(h.getType().contains("RESOURCE")){ + /* + * Get Variable from Resource + */ + String variable = h.getVariable(); + + /* + * Look in Condition for the Set, in which the variable appears + */ + ArrayList<String> propertyVariableList = new ArrayList<String>(); + for(ArrayList<String> cl : givenConditionList){ + for(String s : cl){ + if(s.contains(variable)){ + /* + * Mark Also if the Property is left or right from the Resource + */ + if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+variable); + else propertyVariableList.add(cl.get(1)+"LEFT::"+variable); + } + } + } + + /* + * Now get for each found Property the Name + */ + ArrayList<String> propertyNameList = new ArrayList<String>(); + for(String s : propertyVariableList){ + for(Hypothesis h_t : hl){ + //System.out.println("s in creating propertyNameList: "+s); + String variable_t = s; + variable_t=variable_t.replace("RIGHT", ""); + variable_t=variable_t.replace("LEFT", ""); + if(h_t.getVariable().contains(variable_t)) propertyNameList.add(h_t.getName()+"::"+s); + + } + } + + /* + * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc + */ + ArrayList<ElementList> resources = elm.getResources(); + for(String s : propertyNameList){ + String[] array = s.split("::"); + + System.out.println("s: "+s); + System.out.println("Array:"); + for(String t : array){ + System.out.println(t); + } + + /* + * array[0] contains name of Property + * array[1] contains LEFT/RIGHT and Variable of Property + * array[2] contains Name of Resource + */ + + String side="LEFT"; + if(array[1].contains("RIGHT")) side="RIGHT"; + + for(ElementList el : resources){ + if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ + String propertyVariable = array[1]; + propertyVariable=propertyVariable.replace("LEFT", ""); + propertyVariable=propertyVariable.replace("RIGHT", ""); + ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); + try { + resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for(Hypothesis h_p : resultHypothesenList) h_p.printAll(); + + } + } + + } + + } + } + + + + /* + * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case + */ + } + + return null; + + } + + +} Added: 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 (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,41 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; + +public class LevenstheinModule { + private final static double LevenstheinMin=0.8; + + public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) + throws SQLException { + ArrayList<Hypothesis> listOfNewHypothesen= new ArrayList<Hypothesis>(); + + + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + String value = entry.getValue(); + + //compare property gotten from the resource with the property from the original query + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + + //if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ + + if(nld>=LevenstheinMin){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + + } + + return listOfNewHypothesen; + } + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,8 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +public class WordnetModule { + + private int explorationdepthwordnet =2; + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-29 13:11:05
|
Revision: 3625 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3625&view=rev Author: sebastianwtr Date: 2012-03-29 13:10:53 +0000 (Thu, 29 Mar 2012) Log Message: ----------- [tbsl exploration] went on to implement the different Modules, especially the Iteration Module Modified Paths: -------------- 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.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.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 trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.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/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java Modified: 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/Index/SQLiteIndex.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.92; + double lim_levensthein=0.99; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -25,6 +25,11 @@ * HashMap with name -uri pairs. */ private HashMap<String,String> hm = new HashMap<String,String>(); + + /** + * Resource or Class! + */ + //private String type public String getVariablename() { return variablename; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -11,36 +11,27 @@ * */ public class Elements { - private ArrayList<ElementList> resources = new ArrayList<ElementList>(); - private ArrayList<ElementList> classes = new ArrayList<ElementList>(); - public ArrayList<ElementList> getResources() { - return resources; + private ArrayList<ElementList> elements = new ArrayList<ElementList>(); + + public ArrayList<ElementList> getElements() { + return elements; } - public void setResources(ArrayList<ElementList> resources) { - this.resources = resources; + public void setElements(ArrayList<ElementList> resources) { + this.elements = resources; } - public ArrayList<ElementList> getClasses() { - return classes; - } - public void setClasses(ArrayList<ElementList> classes) { - this.classes = classes; - } - private void addClasses(ElementList cl) { - this.classes.add(cl); + private void addElements(ElementList cl) { + this.elements.add(cl); } - private void addResources(ElementList cl) { - this.resources.add(cl); - } - public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ /* * first all Classes! */ try { - this.setClasses(createElementsOfClasses(hypothesen)); + //this.setClasses(createElementsOfClasses(hypothesen)); + createElementsOfClasses(hypothesen); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -50,7 +41,8 @@ * second all Resources */ try { - this.setResources(createElementsOfResources(hypothesen,condition)); + //this.setResources(createElementsOfResources(hypothesen,condition)); + createElementsOfResources(hypothesen,condition); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -59,8 +51,7 @@ System.out.println("Created Elements"); } - private ArrayList<ElementList> createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ - ArrayList<ElementList> classes = new ArrayList<ElementList>(); + private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ /* * Iterate over all Hypothesis and look for an IsA @@ -75,17 +66,17 @@ * TODO: improver performance, using geschicktes zwischenspeichern */ ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); - classes.add(el); + //classes.add(el); + this.addElements(el); } } } - return classes; + //return classes; } - private ArrayList<ElementList> createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ - ArrayList<ElementList> resources = new ArrayList<ElementList>(); + private void createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ /* * Iterate over all Hypothesis and look for an resource */ @@ -95,11 +86,17 @@ for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); - resources.add(el); + //resources.add(el); + this.addElements(el); } if(h.getVariable().equals(cl.get(2))) { - ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); - resources.add(el); + /* + * TDO: Geht hier in die Schleife, aber die Liste wird nicht hinzugefügt.... + */ + ElementList el_left = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); + //resources.add(el); + //el_left.printAll(); + this.addElements(el_left); } } @@ -108,38 +105,30 @@ } } - return resources; + //return resources; } public void printAll(){ - System.out.println("Resources: "); - for(ElementList el: this.resources){ + System.out.println("Elements: "); + for(ElementList el: this.elements){ el.printAll(); } - System.out.println("\nClasses: "); - for(ElementList el: this.classes){ - el.printAll(); - } } public String printToString(){ String result=""; - result+="Resources: \n"; - for(ElementList el: this.resources){ + result+="Elements: \n"; + for(ElementList el: this.elements){ result+=el.printToString()+"\n"; } - result+="\nClasses: \n"; - for(ElementList el: this.classes){ - result+=el.printToString()+"\n"; - } return result; } public boolean isElementEmty(){ try { - if(this.getClasses().isEmpty()||this.getResources().isEmpty()) return true; + if(this.getElements().isEmpty()) return true; else return false; } catch (Exception e) { // TODO Auto-generated catch block 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-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -7,6 +7,7 @@ private ArrayList<ElementList> list_of_element_uri_pair = new ArrayList<ElementList>(); private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -15,8 +16,11 @@ private String question; private String queryType; private Elements elm; - private float overallTime; - private float time_Templator; + private long overallTime; + private long time_Templator; + private long time_generateElements; + private long time_part1; + private long time_part2; public String getHaving() { return having; @@ -92,6 +96,17 @@ z.printAll(); } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : hypothesenLevensthein){ + System.out.println("\nSet of HypothesenLevensthein"+anzahl+":"); + anzahl+=1; + for ( Hypothesis z : x){ + z.printAll(); + } + } + + System.out.print("\n"); System.out.println("QueryType "+queryType); System.out.println("selectTerm: "+selectTerm); @@ -107,16 +122,16 @@ public void setQuestion(String question) { this.question = question; } - public float getOverallTime() { + public long getOverallTime() { return overallTime; } - public void setOverallTime(float overallTime) { + public void setOverallTime(long overallTime) { this.overallTime = overallTime; } - public float getTime_Templator() { + public long getTime_Templator() { return time_Templator; } - public void setTime_Templator(float time_Templator) { + public void setTime_Templator(long time_Templator) { this.time_Templator = time_Templator; } public ArrayList<ElementList> getList_of_element_uri_pair() { @@ -141,6 +156,30 @@ public void setElm(Elements elm) { this.elm = elm; } + public long getTime_generateElements() { + return time_generateElements; + } + public void setTime_generateElements(long time_generateElements) { + this.time_generateElements = time_generateElements; + } + public long getTime_part1() { + return time_part1; + } + public void setTime_part1(long time_part1) { + this.time_part1 = time_part1; + } + public long getTime_part2() { + return time_part2; + } + public void setTime_part2(long time_part2) { + this.time_part2 = time_part2; + } + public ArrayList<ArrayList<Hypothesis>> getHypothesenLevensthein() { + return hypothesenLevensthein; + } + public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { + this.hypothesenLevensthein = hypothesenLevensthein; + } } 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:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -77,6 +77,8 @@ long stop_template = System.currentTimeMillis(); for (BasicQueryTemplate bqt : querytemps) { + + long start_part1= System.currentTimeMillis(); ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); //ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); String selectTerm = ""; @@ -153,8 +155,10 @@ addTemplate=false; } + long stop_part1= System.currentTimeMillis(); + if(addTemplate!=false){ - + long start_part2= System.currentTimeMillis(); /* * SLOT_title: PROPERTY {title,name,label} mitfuehren @@ -162,6 +166,7 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -349,20 +354,34 @@ /* * Before adding Templates, generate for each Template a set of Properties and Elements */ + long start_elements = System.currentTimeMillis(); Elements elm = new Elements(template.getCondition(),template.getHypothesen()); + long stop_elements = System.currentTimeMillis(); + template.setTime_generateElements(stop_elements-start_elements); + /* * If no Elements are created, dont add Template! */ - //if(elm.isElementEmty()==false){ + long stop_part2= System.currentTimeMillis(); + template.setTime_part2(stop_part2-start_part2); + if(elm.isElementEmty()==false){ + //elm.printAll(); template.setElm(elm); resultArrayList.add(template); - //} + } if(add_reverse_template){ + start_elements = System.currentTimeMillis(); Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); - //if(elm_reverse.isElementEmty()==false){ - template.setElm(elm_reverse); + stop_elements = System.currentTimeMillis(); + template_reverse_conditions.setTime_generateElements(stop_elements-start_elements); + template_reverse_conditions.setTime_part1(stop_part1-start_part1); + template_reverse_conditions.setTime_part2(stop_part2-start_part2); + + if(elm_reverse.isElementEmty()==false){ + //elm_reverse.printAll(); + template_reverse_conditions.setElm(elm_reverse); resultArrayList.add(template_reverse_conditions); - //} + } } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -12,7 +12,7 @@ * @param t * @return */ - public static ArrayList<QueryPair> returnSetOfQueries(Template t){ + public static ArrayList<QueryPair> returnSetOfQueries(Template t, String type){ ArrayList<QueryPair> queryList = new ArrayList<QueryPair>(); /* @@ -27,7 +27,15 @@ /* * Now replacing varibale with the uri from the Hypot. */ - for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> givenHypothesenList = new ArrayList<ArrayList<Hypothesis>>() ; + if(type.contains("LEVENSTHEIN")){ + givenHypothesenList=t.getHypothesenLevensthein(); + } + else{ + givenHypothesenList=t.getHypothesen(); + } + + for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; 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:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -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; @@ -96,6 +96,8 @@ if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=query_property_left; String result=""; + /*System.out.println(verarbeitungsurl); + System.out.println("side: "+ side);*/ result = getListOfElements(verarbeitungsurl); return generateList(result); @@ -109,8 +111,24 @@ */ public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ + /* + PREFIX dbo: <http://dbpedia.org/ontology/> +SELECT DISTINCT ?p WHERE { + { ?x ?p ?y . } UNION { ?y ?p ?x . } + { + SELECT ?x { + ?x rdf:type dbo:Mountain . + } + LIMIT 10 + } +} +ORDER BY ?x + + + TODO:Try with different Limits + */ - String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s ?x WHERE { ?x rdf:type <"+classUri+">. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + String query="PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').}{?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; String result=""; result = getListOfElements(query); 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:09:03 UTC (rev 3624) +++ 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) @@ -39,69 +39,95 @@ TemplateBuilder testobject = new TemplateBuilder(); String filepath = "/home/swalter/Dokumente/Auswertung/"; - String file="very_small.xml"; - //String file="dbpedia-train.xml"; + //String file="very_small.xml"; + String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); - //String question = "Is the wife of president Obama called Michelle?"; - String question = "Who is the leader of Hamburg?"; - temp_list_result=testobject.createTemplates(question); - Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //String question = "Who is the mayor of Berlin?"; - /*for(Template t : temp_list_result){ - //t.printAll(); - try { - t.getElm().printAll(); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - } - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); - for(QueryPair p : qp){ - tm.put(p, t.getQuestion()); - } - }*/ - for(Template t : temp_list_result){ - t.getElm().getResources(); - IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition()); - } + /* + * Original eine resource zwei properties, nachher nur noch eine Resource und eine property + */ + String question ="Who is the daughter of Bill Clinton married to?"; + long start_template = System.currentTimeMillis(); + //temp_list_result=testobject.createTemplates(question); + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - - ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - /* * Generate Templates */ - /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + /* ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + list_of_structs=generateStruct(filepath+"XMLDateien/"+file); String result=""; for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); - try { + /*try { result+=t.getElm().printToString()+"\n"; } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); - } - } + }*/ + // } - }*/ + //} + long stop_template = System.currentTimeMillis(); + + long start_iteration = System.currentTimeMillis(); + long time_generatingElements=0; + long time_part1=0; + long time_part2=0; + + for(Template t : temp_list_result){ + time_generatingElements+=t.getTime_generateElements(); + time_part1+=t.getTime_part1(); + time_part2+=t.getTime_part2(); + try{ + //t.getElm().printAll(); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + t.setHypothesenLevensthein(blub); + + //t.printAll(); + } + catch (Exception e){ + + } + + } + long stop_iteration = System.currentTimeMillis(); + System.out.println("The Iteration and Levensthein Mode took "+ (stop_iteration-start_iteration)+"ms"); + System.out.println("The Iteration and Levensthein Mode took for one Template "+ (stop_iteration-start_iteration)/temp_list_result.size()+"ms"); + float time_template =stop_template-start_template; + float time_Templator=temp_list_result.get(0).getTime_Templator(); + System.out.println("Generating the Template took "+ time_template+"ms"); + System.out.println("Generating one Template took "+ time_template/temp_list_result.size()+"ms"); + System.out.println("Templator took "+ time_Templator+"ms"); + System.out.println("Generating the Templates Without Parser "+ (time_template-time_Templator)+"ms"); + System.out.println("Average Time getting Properties etc "+ (time_generatingElements/temp_list_result.size())+"ms"); + System.out.println("Average Time part1 "+ (time_part1/temp_list_result.size())+"ms"); + System.out.println("Average Time part2 "+ (time_part2/temp_list_result.size())+"ms"); + System.out.println("Time getting Properties etc "+ (time_generatingElements)+"ms"); + System.out.println("DONE"); + + + + /* * Create Query for each Template */ - /*Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - for(Template t : temp_list_result){ + /*for(Template t : temp_list_result){ //t.printAll(); - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t, "LEVENSTHEIN"); for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } @@ -113,15 +139,16 @@ * Get Elements for Each Resource and Class */ - /*long stop = System.currentTimeMillis(); + /* System.out.println("Duration in ms: " + (stop - start)); writeStringToFile(result,filepath,file,start,stop); */ /* * Write Results in File */ - //writeQueriesInFile(tm,filepath,file,start,stop ); - //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + long stop = System.currentTimeMillis(); + // writeQueriesInFile(tm,filepath,file,start,stop ); + // writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -151,6 +178,22 @@ result+="%%%%%%%%%%%"+"\n"; } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : t.getHypothesenLevensthein()){ + result+="\nSet of LevenstheinHypothesen"+anzahl+":\n"; + anzahl+=1; + for ( Hypothesis z : x){ + result+="%%%%%%%%%%%"+"\n"; + result+="Variable: "+z.getVariable()+"\n"; + result+="Name: "+z.getName()+"\n"; + result+="Uri: " + z.getUri()+"\n"; + result+="Type: " + z.getType()+"\n"; + result+="Rank: "+z.getRank()+"\n"; + result+="%%%%%%%%%%%"+"\n"; + } + } + result+="\n"; result+="queryType: "+t.getQueryType()+"\n"; result+="selectTerm: "+t.getSelectTerm()+"\n"; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -21,21 +21,64 @@ * @param hypothesen * @param condition * @return ArrayList<ArrayList<Hypothesis>> + * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList){ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + boolean gotResource=true; + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + try{ + resources = elm.getElements(); + } + catch (Exception e){ + gotResource=false; + System.out.println("Didnt get any Resource"); + } + + //System.out.println("Anzahl der Resource Listen: "+resources.size()); + + ArrayList<ArrayList<Hypothesis>>finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); + + for(ArrayList<Hypothesis> hl :givenHypothesenList){ + /* + * foundedResourcesClasses + */ + ArrayList<Hypothesis> RL = new ArrayList<Hypothesis>(); /* + * foundedProperty + */ + ArrayList<String> PL = new ArrayList<String>(); + + /* + * hypothesenListBeforSorting + */ + ArrayList<Hypothesis>HL = new ArrayList<Hypothesis>(); + + + /* + * AL abhängig von jeder einzelnen Resource R aus RL + */ + ArrayList<ArrayList<ArrayList<Hypothesis>>> ALR = new ArrayList<ArrayList<ArrayList<Hypothesis>>>(); + + + /* * First look for resources and generate List with properties */ for(Hypothesis h : hl){ + + //System.out.println("In Hypothesis Loop"); if(h.getType().contains("RESOURCE")){ /* * Get Variable from Resource */ String variable = h.getVariable(); + String name = h.getName(); + RL.add(h); + System.out.println("Found Resource"); + /* * Look in Condition for the Set, in which the variable appears */ @@ -43,11 +86,8 @@ for(ArrayList<String> cl : givenConditionList){ for(String s : cl){ if(s.contains(variable)){ - /* - * Mark Also if the Property is left or right from the Resource - */ - if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+variable); - else propertyVariableList.add(cl.get(1)+"LEFT::"+variable); + if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+name); + else propertyVariableList.add(cl.get(1)+"LEFT::"+name); } } } @@ -58,68 +98,215 @@ ArrayList<String> propertyNameList = new ArrayList<String>(); for(String s : propertyVariableList){ for(Hypothesis h_t : hl){ - //System.out.println("s in creating propertyNameList: "+s); String variable_t = s; variable_t=variable_t.replace("RIGHT", ""); variable_t=variable_t.replace("LEFT", ""); - if(h_t.getVariable().contains(variable_t)) propertyNameList.add(h_t.getName()+"::"+s); + String[] variable_t1=variable_t.split("::"); + if(h_t.getVariable().contains(variable_t1[0])){ + propertyNameList.add(h_t.getName()+"::"+s); + } } } - /* * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc */ - ArrayList<ElementList> resources = elm.getResources(); - for(String s : propertyNameList){ - String[] array = s.split("::"); - - System.out.println("s: "+s); - System.out.println("Array:"); - for(String t : array){ - System.out.println(t); + + if(gotResource){ + for(String s : propertyNameList){ + String[] array = s.split("::"); + + System.out.println("String: "+s); + /*System.out.println("Array:"); + for(String t : array){ + System.out.println(t); + }*/ + + /* + * array[0] contains name of Property + * array[1] contains LEFT/RIGHT and Variable of Property + * array[2] contains Name of Resource + */ + + String side="LEFT"; + if(array[1].contains("RIGHT")) side="RIGHT"; + + for(ElementList el : resources){ + if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ + String propertyVariable = array[1]; + propertyVariable=propertyVariable.replace("LEFT", ""); + propertyVariable=propertyVariable.replace("RIGHT", ""); + ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); + try { + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); + + } + } + } - + } + + + } + + if(h.getType().contains("isA")){ + /* + * TODO:Add special case, if we have only one condition but with an isA in it. + */ + RL.add(h); + System.out.println("Found Class"); + + for(ElementList el:resources){ /* - * array[0] contains name of Property - * array[1] contains LEFT/RIGHT and Variable of Property - * array[2] contains Name of Resource + * Find the resource with the same uri as in h an then start Levensthein/Wordnet etc */ - - String side="LEFT"; - if(array[1].contains("RIGHT")) side="RIGHT"; - - for(ElementList el : resources){ - if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ - String propertyVariable = array[1]; - propertyVariable=propertyVariable.replace("LEFT", ""); - propertyVariable=propertyVariable.replace("RIGHT", ""); - ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - try { - resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if(el.getURI().contains(h.getUri())){ + /* + * Iterate over condition and find the coressesponding variable of the Class, wich is used for the new Hypothesis + */ + ArrayList<String> propertyVariableList= new ArrayList<String>(); + for(ArrayList<String> cl : givenConditionList){ + /* + * Dont look for line, where e.g. ?x isA ?y + */ + //get(1) is the middle Term and if there is an isa, than its there + if(!cl.get(1).contains("isA")){ + for(String s : cl){ + if(s.contains(h.getVariable())){ + propertyVariableList.add(s); + } + } } + + } + for(String propertyVariable : propertyVariableList){ + for(ArrayList<Hypothesis> hl_small :givenHypothesenList){ + for(Hypothesis h_small : hl_small){ + if(h_small.getVariable().contains(propertyVariable)){ + try { + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable); + for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } - for(Hypothesis h_p : resultHypothesenList) h_p.printAll(); - } + //for(Hypothesis h_p : finalHypothesenList) h_p.printAll(); + + } - } + + } + + } - /* * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case */ + + /*for(Hypothesis h : RL){ + h.printAll(); + } + + for(String s : PL){ + System.out.println("Variable P: "+s); + }*/ + + /* + * Here add new function! + */ + for(Hypothesis R : RL){ + /* + * AL, abhängig von jeder einzelnen P aus PL und R aus RL + */ + ArrayList<ArrayList<Hypothesis>> AL = new ArrayList<ArrayList<Hypothesis>>(); + + + for(String P : PL){ + if(P.contains(R.getVariable())){ + for(Hypothesis H : HL){ + if(P.contains(H.getVariable())){ + ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); + t_h_l.add(H); + t_h_l.add(R); + AL.add(t_h_l); + } + } + } + } + + ALR.add(AL); + } + + if(ALR.size()==1){ + System.out.println("ONLY One Element in ALR"); + finalHypothesenList=ALR.get(0); + System.out.println("One Element in ALR added to finalHypothesenList"); + } + if(ALR.size()==2){ + System.out.println("Two Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + } + System.out.println("Two Element in ALR added to finalHypothesenList"); + + } + + if(ALR.size()==2){ + System.out.println("Three Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + for(ArrayList<Hypothesis> hl2_t : ALR.get(2)){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + for(Hypothesis h_t : hl2_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + + } + } + System.out.println("Three Element in ALR added to finalHypothesenList"); + + } + + } + + + + System.out.println("######################DONE######################"); - return null; + return finalHypothesenList; } 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:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.8; + private final static double LevenstheinMin=0.92; 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. |
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. |
From: <seb...@us...> - 2012-04-04 15:12:43
|
Revision: 3627 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3627&view=rev Author: sebastianwtr Date: 2012-04-04 15:12:31 +0000 (Wed, 04 Apr 2012) Log Message: ----------- [tbsl exploration] started fixing some bugs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.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 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/LinearSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.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/MainInterface.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/IterationModule.java 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/WordnetModule.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -61,10 +61,11 @@ /* * if isA is found and if Class has uri, get Elements */ - if(h.getType().contains("isA")&&h.getUri().contains("http")){ + if(h.getType().contains("ISA")&&h.getUri().contains("http")){ /* * TODO: improver performance, using geschicktes zwischenspeichern */ + System.out.println("Class Name: "+h.getName()+" Uri: "+h.getUri()); ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); this.addElements(el); @@ -83,6 +84,8 @@ for(ArrayList<Hypothesis> hl : hypothesenList){ for(Hypothesis h : hl){ if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ + System.out.println("Resource Name: "+h.getName()+" Uri: "+h.getUri()); + for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); 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-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -8,6 +8,7 @@ private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenWordnet = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -180,6 +181,12 @@ public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { this.hypothesenLevensthein = hypothesenLevensthein; } + public ArrayList<ArrayList<Hypothesis>> getHypothesenWordnet() { + return hypothesenWordnet; + } + public void setHypothesenWordnet(ArrayList<ArrayList<Hypothesis>> hypothesenWordnet) { + this.hypothesenWordnet = hypothesenWordnet; + } } 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 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -104,6 +104,7 @@ String[] tmp_array = conditions1.toString().split(" -- "); for(String s: tmp_array){ //System.out.println(s); + s=s.replace("isA", "ISA"); temp_array.add(s); } condition.add(temp_array); @@ -166,6 +167,14 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + for(ArrayList<String> al : condition){ + String con_temp=""; + for(String s : al){ + con_temp+=" " + s; + } + System.out.println("Condition: "+con_temp); + } + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -179,7 +188,7 @@ String[] tmp_array = tmp.split(":"); boolean no_iaA_found=true; for(ArrayList<String> x : condition){ - if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + if(x.get(1).equals("ISA") && x.get(2).equals("?"+tmp_array[0])){ no_iaA_found=false; Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0.0); //tmp_hypothesis.printAll(); @@ -218,11 +227,11 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); + System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); for(Hypothesis x : list_of_hypothesis){ /* @@ -270,13 +279,13 @@ } } - /*System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -311,18 +320,51 @@ } } - /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + + + + /* + * BUGFIX: Before adding Hypothesis to template check, if each Hypothesis has an uri + * TODO: check all functions before + */ + /*for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ + for(Hypothesis h : al){ + if(!h.getUri().contains("http")){ + if(h.getType().contains("ISA")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + if(h.getType().contains("RESOURCE")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } + } + } + */ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); - template.setHypothesen(final_list_set_hypothesis); Modified: 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/Levenshtein.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -17,7 +17,9 @@ else{ double result_nld =result/length; - return result_nld; + double result1 = 1-result_nld; + //System.out.println(orig + " " + eing +" : "+result1); + return result1; } } Modified: 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 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -20,9 +20,9 @@ } } - for(QueryPair p : qp){ + /*for(QueryPair p : qp){ p.printAll(); - } + }*/ } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -31,7 +31,12 @@ if(type.contains("LEVENSTHEIN")){ givenHypothesenList=t.getHypothesenLevensthein(); } - else{ + else if(type.contains("WORDNET")){ + givenHypothesenList=t.getHypothesenWordnet(); + } + + else { + if(!type.contains("NORMAL"))System.err.println("ATTENTION\n Given Type: "+type+" was not found in generating Queries!!\n"); givenHypothesenList=t.getHypothesen(); } @@ -48,6 +53,8 @@ if(!h.getUri().contains("http")){ addQuery=false; } + condition_new=condition_new.replace("ISA", "rdf:type"); + //just in case... condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); } 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 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,10 +3,14 @@ import java.io.BufferedReader; import java.io.IOException; 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.regex.Matcher; +import java.util.regex.Pattern; public class ServerUtil { @@ -128,10 +132,13 @@ TODO:Try with different Limits */ - String query="PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').}{?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; - + /* + * TODO: Still a not "valid" url + */ + String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; + String query_final=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String result=""; - result = getListOfElements(query); + result = getListOfElements(query_final); return generateList(result); } @@ -197,8 +204,66 @@ result=sb.toString(); } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); + //System.out.println("Must enter a valid URL"); + System.err.println("ATTENTION\n URL not valid : "+verarbeitungsurl+"\n"); } catch (IOException e) { + System.err.println("Can not connect or timeout"); + } + finally + { + //close the connection, set all objects to null + try{ + connection.disconnect(); + } + catch (Exception e){ + System.err.println("ATTENTION\n Error in disconecting Connection to Server in getListOfElements\n "); + } + rd = null; + sb = null; + connection = null; + } + return result; + } + + public static ArrayList<String> requestAnswerFromServer(String query){ + String query_url=server_Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + + //System.out.println(tmp); + String result=""; + HttpURLConnection connection = null; + OutputStreamWriter wr = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + + URL serverAddress = null; + + try { + serverAddress = new URL(query_url); + //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.err.println("ATTENTION\n URL not valid : "+query_url+"\n"); + } catch (IOException e) { System.out.println("Can not connect or timeout"); } finally @@ -207,11 +272,41 @@ connection.disconnect(); rd = null; sb = null; + wr = null; connection = null; } + + + + return createAnswerArray(result); + } + + private static ArrayList<String> createAnswerArray(String string){ + + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + ArrayList<String> result= new ArrayList<String>(); + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + String temp = m.group(1); + temp = temp.replace("\"@en",""); + temp = temp.replace("\"",""); + //result.add(m.group(1)); + result.add(temp); + + } + } + + + //if (result.length()==0) result="EmtyAnswer"; + if(string.matches("true")|| string.matches("false")) result.add(string); return result; + } - } Modified: 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 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,8 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.sql.SQLException; import java.util.ArrayList; @@ -12,17 +14,27 @@ 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.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; 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{ + private static int anzahlAbgeschickterQueries = 10; + + + public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); ArrayList<Template> template_list = new ArrayList<Template>(); + /* + * Array List with the answers from the queries + */ + ArrayList<String> answers = new ArrayList<String>(); + /* * generate Templates! */ @@ -35,7 +47,7 @@ //generate QueryPair for(Template t : template_list){ - //t.printAll(); + t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); qp_t = Query.returnSetOfQueries(t, "NORMAL"); for(QueryPair p : qp_t){ @@ -51,15 +63,101 @@ } //sort QueryPairs - LinearSort.doSort(qp); + LinearSort.doSort(qp); + int anzahl=1; + boolean go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + System.out.println(q.getQuery()); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String line; + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + + /* * If there is no answer, start IterationMode with Levensthein */ + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + /* + * still no answer, start IterationMode with Wordnet + */ + + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + + + /*if(answers.isEmpty()){ + System.out.println("No answers were found with the three Modules"); + //answers.add("No answers were found with the three Modules"); + }*/ + + + /* + * return answers! + */ + + return answers; + } + + + + + + + private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, + StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type) { + ArrayList<String> answers = new ArrayList<String>(); + ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + int anzahl; + boolean go_on; + System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); - t.setHypothesenLevensthein(hypothesenSetList); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); } catch (Exception e){ @@ -68,14 +166,13 @@ } /* - * Generate Queries for Levensthein Mode and test queries + * Generate Queries 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"); + qp_t = Query.returnSetOfQueries(t, type); for(QueryPair p : qp_t){ //if(!qp.contains(p)) qp.add(p); boolean contain = false; @@ -84,24 +181,57 @@ if(p_t.getQuery().contains(p.getQuery())) contain=true; } } - if(!contain)qp.add(p); + if(!contain&&checkQuery(p.getQuery()))qp.add(p); } } //sort QueryPairs LinearSort.doSort(qp); - System.out.println("Anzahl: "+qp.size()); - /* - * still no answer, start IterationMode with Wordnet - */ + anzahl=1; + go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + System.out.println(q.getQuery() + " Rank: "+q.getRank()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } - /* - * Generate Queries for Wordnet Mode and test queries. - */ + return answers; } - private void sortQueries(){ + + + private static boolean checkAnswer(String answer){ + if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")) return false; + else return true; } + + private static boolean checkQuery(String query){ + if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")) return false; + else return true; + + } } 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 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,7 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -20,7 +21,10 @@ 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.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; +import org.ibex.nestedvm.util.Seekable.InputStream; import java.sql.Connection; import java.sql.DriverManager; @@ -57,6 +61,8 @@ BasicTemplator btemplator = new BasicTemplator(); //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + StanfordLemmatizer lemmatiser = new StanfordLemmatizer(); long stopInitTime = System.currentTimeMillis(); @@ -82,13 +88,18 @@ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - System.out.println("Please enter Path of xml File:"); - line=in.readLine(); + /*System.out.println("Please enter Path of xml File:"); + line=in.readLine();*/ + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - ArrayList<queryInformation> list_of_resultstructs = new ArrayList<queryInformation>(); - //if you dont want to use the hints in the questions, use false + list_of_structs=generateStruct(line,true); //Start Time measuring long startTime = System.currentTimeMillis(); @@ -100,12 +111,13 @@ anzahl=anzahl+1; System.out.println(""); if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); - System.out.println("ID: "+qi.getId()); + /*System.out.println("ID: "+qi.getId()); System.out.println("Query: "+qi.getQuery()); System.out.println("Type: "+qi.getType()); - System.out.println("XMLType: "+qi.getXMLtype()); + System.out.println("XMLType: "+qi.getXMLtype());*/ String question = qi.getQuery(); - MainInterface.startQuestioning(question,btemplator,myindex); + ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); + qi.setResult(answers); } @@ -115,44 +127,28 @@ System.out.println(s.getResult()); }*/ String systemid=""; - systemid=createXML(list_of_resultstructs); - writeQueryInformation(list_of_structs,systemid); - writeTime(list_of_structs,systemid); - - //now create File with systemid for time and a file, which lists alle propertys and so on - - long timeNow = System.currentTimeMillis(); - long diff = timeNow-startTime; - String string1="Time for "+anzahl+" questions = "+diff+" ms."; - System.out.println(string1); - String string2="From "+anzahl_query_with_answers+" questions I got an answer"; - String string3=yago_querys+ " Yago Questions were skiped"; - System.out.println(string2); - System.out.println(string3); - String string4 ="Average time for one question : "+(diff/anzahl/1000)+"sek"; - File file; - FileWriter writer; - file = new File("../../generalInformation"+systemid+".txt"); - try { - writer = new FileWriter(file ,true); - writer.write(string1+"\n"+string2+"\n"+string3+"\n"+string4); - writer.flush(); - - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } + systemid=createXML(list_of_structs); + String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; + String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; + + /* + * First only for training + */ + + System.out.println("execute: "+execute); + Runtime r = Runtime.getRuntime(); + Process p = r.exec(execute); + + String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; + execute ="firefox "+ open_file; + p = r.exec(execute); - System.out.println("Finished test"); - System.exit(0); - } else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); - MainInterface.startQuestioning(line,btemplator,myindex); + MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! Set<String> setString = new HashSet<String>(); @@ -239,39 +235,43 @@ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); String systemid = sdf.format(now); - + System.out.println("In createXML"); String xmlDocument=""; int counter=0; + System.out.println("Anzahl queryInformations: "+list.size()); for (queryInformation s : list){ - String tmp; - if(counter==0){ - counter=counter+1; - xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + if(!s.getResult().isEmpty()){ + String tmp; + if(counter==0){ + counter=counter+1; + xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + } + tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; + + //to get all answers only once! + Set<String> setString = new HashSet<String>(); + for(String z: s.getResult()){ + setString.add(z); + } + for(String i : setString){ + //System.out.println("i: "+i); + String input=""; + if(i.contains("http")) input="<uri>"+i+"</uri>\n"; + else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; + else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else input="<string>"+i+"</string>\n"; + tmp+="<answer>"+input+"</answer>\n"; + } + tmp+="</answers></question>\n"; + xmlDocument+=tmp; } - tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; - //to get all answers only once! - Set<String> setString = new HashSet<String>(); - for(String z: s.getResult()){ - setString.add(z); - } - for(String i : setString){ - String input=""; - if(i.contains("http")) input="<uri>"+i+"</uri>\n"; - else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; - else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; - else input="<string>"+i+"</string>\n"; - tmp+="<answer>"+input+"</answer>\n"; - } - tmp+="</answers></question>\n"; - xmlDocument+=tmp; - } xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("../../result"+systemid+".xml"); + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); @@ -283,6 +283,7 @@ e.printStackTrace(); } + System.out.println("In createXML - Done"); return systemid; } @@ -318,18 +319,28 @@ String string=tmp; Pattern p = Pattern.compile (".*\\<question(.*)\\</question\\>.*"); Matcher m = p.matcher (string); + /* string= string.replace(" answertype=\"number\"", ""); + string= string.replace(" answertype=\"string\"", ""); + string= string.replace(" answertype=\"date\"", ""); + string= string.replace(" answertype=\"resource\"", ""); + string= string.replace(" answertype=\"boolean\"", ""); + string = string.replace(" aggregation=\"true\"", ""); + string = string.replace(" aggregation=\"false\"", ""); + string = string.replace(" onlydbo=\"false\"", ""); + string = string.replace(" onlydbo=\"true\"", "");*/ - if(string.contains("id=\"dbpedia-train\"><question")){ string=string.replace("id=\"dbpedia-train\"><question", ""); XMLType="dbpedia-train"; System.out.println("dbpedia-train"); } - if(string.contains("id=\"dbpedia-test\"><question")){ + else if(string.contains("id=\"dbpedia-test\"><question")){ string=string.replace("id=\"dbpedia-test\"><question", ""); XMLType="dbpedia-test"; //System.out.println("dbpedia-test"); } + + else XMLType="dbpedia-train"; ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); String [] bla = string.split("</question><question"); for(String s : bla){ @@ -340,7 +351,10 @@ boolean yago=false; String id=""; - Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + /* + * Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + */ + Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<keywords\\>.*"); Matcher m1 = p1.matcher(s); //System.out.println(""); while(m1.find()){ @@ -349,7 +363,15 @@ Matcher m2 = p2.matcher(m1.group(1)); while(m2.find()){ //System.out.println("Query: "+ m2.group(1)); + query=m2.group(1); + query=query.replace("<![CDATA[", ""); + query=query.replace("]]>", ""); + query=query.replace("CDATA", ""); + query=query.replace("]", ""); + query=query.replace("!", ""); + query=query.replace(">", ""); + query=query.replace("<", ""); } Pattern p3= Pattern.compile("id=\"(.*)\" answer.*"); Matcher m3 = p3.matcher(m1.group(1)); @@ -395,14 +417,14 @@ queryInformation blaquery=new queryInformation(query, id,type,fusion,aggregation,yago,XMLType,hint); if(id!=""&&id!=null) querylist.add(blaquery); } - /* for(queryInformation s : querylist){ + for(queryInformation s : querylist){ 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()); - }*/ + } return querylist; } 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 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -24,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.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class testClass_new { @@ -42,6 +43,8 @@ //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + TemplateBuilder testobject = new TemplateBuilder(btemplator, myindex); String filepath = "/home/swalter/Dokumente/Auswertung/"; @@ -84,7 +87,7 @@ //} - long stop_template = System.currentTimeMillis(); + /* long stop_template = System.currentTimeMillis(); long start_iteration = System.currentTimeMillis(); long time_generatingElements=0; @@ -97,7 +100,7 @@ time_part2+=t.getTime_part2(); try{ //t.getElm().printAll(); - ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN",myindex,wordnet); t.setHypothesenLevensthein(blub); //t.printAll(); @@ -106,8 +109,8 @@ } - } - long stop_iteration = System.currentTimeMillis(); + }*/ + /*long stop_iteration = System.currentTimeMillis(); System.out.println("The Iteration and Levensthein Mode took "+ (stop_iteration-start_iteration)+"ms"); System.out.println("The Iteration and Levensthein Mode took for one Template "+ (stop_iteration-start_iteration)/temp_list_result.size()+"ms"); float time_template =stop_template-start_template; @@ -120,7 +123,7 @@ System.out.println("Average Time part1 "+ (time_part1/temp_list_result.size())+"ms"); System.out.println("Average Time part2 "+ (time_part2/temp_list_result.size())+"ms"); System.out.println("Time getting Properties etc "+ (time_generatingElements)+"ms"); - System.out.println("DONE"); + System.out.println("DONE");*/ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,9 +3,14 @@ import java.sql.SQLException; import java.util.ArrayList; +import net.didion.jwnl.JWNLException; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; /** * Gets Elements, Condition and Hypothesen and returns HypothesenSets. @@ -23,7 +28,7 @@ * @return ArrayList<ArrayList<Hypothesis>> * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ boolean gotResource=true; ArrayList<ElementList> resources = new ArrayList<ElementList>(); @@ -142,10 +147,14 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); @@ -159,7 +168,7 @@ } - if(h.getType().contains("isA")){ + if(h.getType().contains("ISA")){ /* * TODO:Add special case, if we have only one condition but with an isA in it. */ @@ -180,7 +189,7 @@ * Dont look for line, where e.g. ?x isA ?y */ //get(1) is the middle Term and if there is an isa, than its there - if(!cl.get(1).contains("isA")){ + if(!cl.get(1).contains("ISA")){ for(String s : cl){ if(s.contains(h.getVariable())){ propertyVariableList.add(s); @@ -199,6 +208,7 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable); for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); } catch (Exception e) { 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 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.5; + private final static double LevenstheinMin=0.85; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,8 +1,241 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.didion.jwnl.JWNLException; +import net.didion.jwnl.data.POS; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; + public class WordnetModule { - private int explorationdepthwordnet =2; + private static int explorationdepthwordnet =2; + public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException, + JWNLException { + ArrayList<Hypothesis> listOfNewHypothesen = new ArrayList<Hypothesis>(); + + System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + if(property_to_compare_with.contains("_")){ + String[] fix = property_to_compare_with.split("_"); + //here add also lemmatiser + for(String s: fix) semantics.add(s); + } + else semantics.add(property_to_compare_with); + System.out.println("Semantics: "+ semantics); + + for(String s: semantics){ + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + //String _temp_=myindex.getWordnetHelp(property); + String _temp_=myindex.getWordnetHelp(s); + if(_temp_!=null){ + //tmp_semantics=semantics; + tmp_semantics.add(_temp_); + tmp_semantics.add(s); + } + else tmp_semantics.add(s); + /* + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + }*/ + } + + System.out.println("tmp_semantics: "+ tmp_semantics); + Boolean goOnAfterWordnet = true; + + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics,wordnet); + System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); + if (tmp_semantics==null){ + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + } + + } catch (IOException e) { + + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + + } + if(goOnAfterWordnet==true){ + + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + key=key.replace("\"",""); + key=key.replace("@en",""); + + for(String b : semantics){ + if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ + if(!result_SemanticsMatchProperties.contains(key)){ + result_SemanticsMatchProperties.add(key); + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + } + } + } + + } + + return listOfNewHypothesen; + } + + private static ArrayList<String> getSemantics (ArrayList<String> semanticsOrig,WordNet wordnet) throws IOException, JWNLException { + ArrayList<String> result = new ArrayList<String>(); + + //System.out.println("in function get Semantics!"); + + ArrayList<String> semantics = new ArrayList<String>(); + semantics=semanticsOrig; + //also look at the stemmt part! + /*for(String s: semanticsOrig){ + String bla=lemmatiser.stem(s); + semantics.add(bla); + semantics.add(s); + }*/ + + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics"); + //System.out.println("ID :"+id); + + //add id also to the result, if its not already in there + if(!result.contains(id))result.add(id); + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + + //System.out.println("Wordnet Word: "+id); + try{ + array_relatedNouns =wordnet.getRelatedNouns(id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, id); + //System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + + } + } + catch(Exception e){ + return null; + } + + if(!result.isEmpty()) return result; + else{ + //System.out.println("Didnt find ") + /*this is the case, if the first time nothing was found. + * but sometimes wordnet doesnt find anything e.g. die place... bzt you have also die and place + * so we try to find the seperate words and test them as well + */ + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics TWO"); + String[] tmp_array=id.split(" "); + //System.out.println("ID TWO:"+id); + if(tmp_array.length>=2){ + for(String advanced_id : tmp_array){ + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + //add id also to the result, if its not already in there + if(!result.contains(advanced_id))result.add(advanced_id); + + try{ + array_relatedNouns =wordnet.getRelatedNouns(advanced_id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, advanced_id); + // System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + } + } + + } + } + catch(Exception e){ + if(result.isEmpty()) return semanticsOrig; + } + + } + + if(!result.isEmpty()) return result; + else return null; + // else{ return result;} + } + + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-11 12:29:57
|
Revision: 3631 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3631&view=rev Author: sebastianwtr Date: 2012-04-11 12:29:50 +0000 (Wed, 11 Apr 2012) Log Message: ----------- [tbsl exploration] fixed some small bugs Modified Paths: -------------- 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/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/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: 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/Index_utils.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -85,6 +85,8 @@ public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ HashMap<String,Float> hm = new HashMap<String,Float>(); + System.err.println("########"); + System.err.println("In search Index for Property"); // adding or set elements in Map by put method key and value pair /* @@ -100,15 +102,19 @@ String result=null; ArrayList<String> result_List = new ArrayList<String>(); result=myindex.getPropertyURI(string.toLowerCase()); + System.err.println("Result: "+result); if(result!=null){ result_List.add(result); hm.put(result, 1.0f); + System.err.println("Found uri for: "+string.toLowerCase()); } else{ + System.err.println("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); hm.put(result, 0.0f); } + System.err.println("########"); return result_List; Modified: 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/Index/SQLiteIndex.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -135,12 +135,54 @@ public String getPropertyURI(String string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; + ArrayList<String> al = new ArrayList<String>(); try { rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); - return rs.getString("uri"); + while(rs.next()){ + String result_string= rs.getString("uri"); + System.out.println("Property: "+result_string); + //check for double: + boolean found = false; + for(String s: al){ + if(s.equals(result_string))found=true; + } + if(found==false)al.add(result_string); + } + + rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); + while(rs.next()){ + String result_string= rs.getString("uri"); + System.out.println("OntologyProperty: "+result_string); + //check for double: + boolean found = false; + for(String s: al){ + if(s.equals(result_string))found=true; + } + if(found==false)al.add(result_string); + } + System.out.println("Anzahl ArrayList: "+al.size()); + if(al.size()==1) return al.get(0); + //check if there is one with an ontology in it + else{ + boolean found = false; + for(String s : al){ + if(s.contains("ontology")){ + System.out.println("Return String: "+s); + found=true; + return s; + } + } + if(found==false){ + System.out.println("Return String: "+al.get(0)); + return al.get(0); + } + } + + return null; } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); + System.err.println("Error in SQLiteIndex.getProperty!!"); return null; } 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-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -227,12 +227,12 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - System.out.println("Alle Hypothesen VOR der Verarbeitung"); + /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); - + */ for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource @@ -279,14 +279,14 @@ } } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + /* System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); - + */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* @@ -327,13 +327,14 @@ * BUGFIX: Before adding Hypothesis to template check, if each Hypothesis has an uri * TODO: check all functions before */ - /*for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ + for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ for(Hypothesis h : al){ if(!h.getUri().contains("http")){ if(h.getType().contains("ISA")){ try { ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); - h.setUri(tmp.get(0)); + System.out.println("Laenge tmp: "+tmp.size()); + if(tmp.size()>0)h.setUri(tmp.get(0)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -343,7 +344,8 @@ if(h.getType().contains("RESOURCE")){ try { ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); - h.setUri(tmp.get(0)); + System.out.println("Laenge tmp: "+tmp.size()); + if(tmp.size()>0)h.setUri(tmp.get(0)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -353,8 +355,8 @@ } } } - */ - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + + /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); @@ -362,9 +364,9 @@ } System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); + */ - template.setHypothesen(final_list_set_hypothesis); 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-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -295,6 +295,10 @@ String temp = m.group(1); temp = temp.replace("\"@en",""); temp = temp.replace("\"",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#date>",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#int>",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#number>",""); + temp = temp.replace("\"",""); //result.add(m.group(1)); result.add(temp); Modified: 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 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -199,6 +199,7 @@ else{ //else go_on=false; go_on=true; + //go_on=false; for(String s : answer_tmp){ if(checkAnswer(s)){ boolean test = false; @@ -224,7 +225,7 @@ private static boolean checkAnswer(String answer){ - if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")) return false; + if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")||answer.contains("flickerwrappr/photos/")) return false; else return true; } 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-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -90,12 +90,12 @@ /*System.out.println("Please enter Path of xml File:"); line=in.readLine();*/ - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); @@ -260,6 +260,7 @@ if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else if(i.matches("[0-9]*-[0-9][0-9]-[0-9]*"))input="<date>"+i+"</date>\n"; else input="<string>"+i+"</string>\n"; tmp+="<answer>"+input+"</answer>\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-13 08:30:53
|
Revision: 3635 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3635&view=rev Author: sebastianwtr Date: 2012-04-13 08:30:41 +0000 (Fri, 13 Apr 2012) Log Message: ----------- [tbsl exploration] startet with DebugOutputs Modified Paths: -------------- 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/Sparql/Elements.java 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/LinearSort.java 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/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/DebugMode.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java Modified: 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/Index_utils.java 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -5,7 +5,10 @@ import java.util.HashMap; import java.util.Map; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; + public class Index_utils { /** @@ -78,15 +81,13 @@ } - return result_List; } public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ HashMap<String,Float> hm = new HashMap<String,Float>(); - System.err.println("########"); - System.err.println("In search Index for Property"); + if(Setting.isDebugModus())DebugMode.debugPrint("######\n In search Index for Property"); // adding or set elements in Map by put method key and value pair /* @@ -102,19 +103,20 @@ String result=null; ArrayList<String> result_List = new ArrayList<String>(); result=myindex.getPropertyURI(string.toLowerCase()); - System.err.println("Result: "+result); + if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); if(result!=null){ result_List.add(result); hm.put(result, 1.0f); - System.err.println("Found uri for: "+string.toLowerCase()); + if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else{ - System.err.println("Didnt find uri for: "+string.toLowerCase()); + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); + result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); hm.put(result, 0.0f); } - System.err.println("########"); + if(Setting.isDebugModus())DebugMode.debugPrint("######\n"); return result_List; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -3,7 +3,9 @@ import java.io.IOException; import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; /** * Creates Set of Classes and Resources with their properties @@ -48,7 +50,7 @@ e.printStackTrace(); } - System.out.println("Created Elements"); + if(Setting.isDebugModus())DebugMode.debugPrint("Created Elements"); } private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ @@ -65,7 +67,7 @@ /* * TODO: improver performance, using geschicktes zwischenspeichern */ - System.out.println("Class Name: "+h.getName()+" Uri: "+h.getUri()); + if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Class: "+h.getName()+" Uri: "+h.getUri()); ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); this.addElements(el); @@ -84,7 +86,7 @@ for(ArrayList<Hypothesis> hl : hypothesenList){ for(Hypothesis h : hl){ if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ - System.out.println("Resource Name: "+h.getName()+" Uri: "+h.getUri()); + if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Resource: "+h.getName()+" Uri: "+h.getUri()); for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { 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-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -17,6 +17,8 @@ import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Index.Index_utils; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; import org.dllearner.algorithm.tbsl.sparql.Path; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; @@ -49,33 +51,38 @@ /* * check if templates were build, if not, safe the question and delete it for next time from the xml file. + * Only in Debug Mode */ - 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)); + if(Setting.isDebugModus()){ + 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(); - - + bw.write(result_string+"\n"+question); + bw.flush(); + bw.close(); + + + } } + long stop_template = System.currentTimeMillis(); + if(Setting.isDebugModus())DebugMode.waitForButton(); for (BasicQueryTemplate bqt : querytemps) { long start_part1= System.currentTimeMillis(); @@ -172,7 +179,7 @@ for(String s : al){ con_temp+=" " + s; } - System.out.println("Condition: "+con_temp); + if(Setting.isDebugModus())DebugMode.debugPrint("Condition: "+con_temp); } template.setTime_part1(stop_part1-start_part1); @@ -225,15 +232,12 @@ } } ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); + if(Setting.isDebugModus())DebugMode.printHypothesen(list_of_hypothesis,"Alle Hypothesen VOR der Verarbeitung"); + + for(Hypothesis x : list_of_hypothesis){ - x.printAll(); - } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); - */ - for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource */ @@ -279,14 +283,9 @@ } } - /* System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); - for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ - for(Hypothesis x : lh){ - x.printAll(); - } - } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); - */ + + if(Setting.isDebugModus())DebugMode.printHypothesenSet(final_list_set_hypothesis,"Alle Hypothesen nach der ERSTEN Verarbeitung"); + //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* @@ -356,17 +355,8 @@ } } - /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); - for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ - for(Hypothesis x : lh){ - x.printAll(); - } - } + if(Setting.isDebugModus())DebugMode.printHypothesenSet(final_list_set_hypothesis,"Alle Hypothesen nach der ZWEITEN Verarbeitung"); - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); - */ - - template.setHypothesen(final_list_set_hypothesis); @@ -430,12 +420,10 @@ } } - /*System.out.println("Nach allen Verarbeitungsschritten:"); - for(Template temp : resultArrayList){ - temp.printAll(); - } - System.out.println("Nach allen Verarbeitungsschritten - DONE");*/ + if(Setting.isDebugModus())DebugMode.printTemplateList(resultArrayList, "Templates nach allen Verarbeitungsschritten"); + + return resultArrayList; } } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/DebugMode.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/DebugMode.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/DebugMode.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -0,0 +1,99 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; + +public class DebugMode { + + public static void waitForButton() throws IOException { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String line; + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + + public static void printHypothesen(ArrayList<Hypothesis> list_of_hypothesis, String string){ + System.out.println(string); + for(Hypothesis x : list_of_hypothesis){ + x.printAll(); + } + System.out.println(string +" Done \n\n"); + try { + waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public static void printHypothesenSet(ArrayList<ArrayList<Hypothesis>> set_hypothesis, String string){ + System.out.println(string); + for(ArrayList<Hypothesis> lh : set_hypothesis){ + for(Hypothesis x : lh){ + x.printAll(); + } + } + System.out.println(string +" Done \n\n"); + try { + waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public static void printTemplateList(ArrayList<Template> templateList, String string){ + System.out.println(string); + for(Template t : templateList) t.printAll(); + System.out.println(string +" Done \n\n"); + try { + waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + public static void debugPrint(String string){ + System.out.println(string); + } + + public static void debugErrorPrint(String string){ + System.err.println(string); + try { + waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void printQueryPair(ArrayList<QueryPair> qp){ + System.out.println("All constructed Queries with Rank"); + for(QueryPair p : qp){ + p.printAll(); + } + + try { + waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + + +} Modified: 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 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -2,6 +2,8 @@ import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; + public class LinearSort { public static void doSort(ArrayList<QueryPair> qp){ @@ -20,9 +22,7 @@ } } - /*for(QueryPair p : qp){ - p.printAll(); - }*/ + if(Setting.isDebugModus())DebugMode.printQueryPair(qp); } Modified: 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 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -11,6 +11,7 @@ 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.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; @@ -26,6 +27,14 @@ public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ + /* + * true, if you have to push a button to get to the next module + * false, goes through all + */ + boolean wait = false; + + if(Setting.isWaitModus())wait=true; + TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); ArrayList<Template> template_list = new ArrayList<Template>(); @@ -69,20 +78,35 @@ for(QueryPair q : qp){ if(anzahl<anzahlAbgeschickterQueries&go_on){ ArrayList<String> answer_tmp = new ArrayList<String>(); - System.out.println(q.getQuery()); + System.out.println("Sending Query to Server: "+q.getQuery()); answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); if(answer_tmp.isEmpty()) go_on=true; else{ - //else go_on=false; - go_on=true; + go_on=false; + System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + //go_on=true; + boolean contains_uri=false; for(String s : answer_tmp){ + if(s.contains("http")){ + contains_uri=true; + break; + } + } + for(String s : answer_tmp){ if(checkAnswer(s)){ - boolean test = false; + boolean double_result = false; for(String s_t : answers){ - if(s_t.contains(s)) test=true; + if(s_t.contains(s)) double_result=true; } - if(!test)answers.add(s); + //TODO Test!!!!!! + //if in one answer is an http, only add uri's + if(!double_result){ + if(contains_uri){ + if(s.contains("http"))answers.add(s); + } + else answers.add(s); + } } } //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); @@ -91,14 +115,11 @@ anzahl+=1; } + System.out.println("\n Answer from Server: \n"); for(String answer:answers){ System.out.println(answer); } - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - String line; - System.out.println("\n\n"); - System.out.println("Press Any Key to continue"); - line = in.readLine(); + if(wait)DebugMode.waitForButton(); /* @@ -108,9 +129,7 @@ answers.clear(); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN")); - System.out.println("\n\n"); - System.out.println("Press Any Key to continue"); - line = in.readLine(); + if(wait)DebugMode.waitForButton(); } /* @@ -121,17 +140,15 @@ answers.clear(); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET")); - System.out.println("\n\n"); - System.out.println("Press Any Key to continue"); - line = in.readLine(); + if(wait)DebugMode.waitForButton(); } - /*if(answers.isEmpty()){ - System.out.println("No answers were found with the three Modules"); + if(answers.isEmpty()){ + System.out.println(""); //answers.add("No answers were found with the three Modules"); - }*/ + } /* @@ -142,9 +159,16 @@ } + + + + + + + private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type) { @@ -193,20 +217,35 @@ if(anzahl<anzahlAbgeschickterQueries&go_on){ ArrayList<String> answer_tmp = new ArrayList<String>(); answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); - System.out.println(q.getQuery() + " Rank: "+q.getRank()); + System.out.println("Sending Query to Server: "+q.getQuery()); if(answer_tmp.isEmpty()) go_on=true; else{ //else go_on=false; - go_on=true; - //go_on=false; + //go_on=true; + go_on=false; + System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + boolean contains_uri=false; for(String s : answer_tmp){ + if(s.contains("http")){ + contains_uri=true; + break; + } + } + for(String s : answer_tmp){ if(checkAnswer(s)){ - boolean test = false; + boolean double_result = false; for(String s_t : answers){ - if(s_t.contains(s)) test=true; + if(s_t.contains(s)) double_result=true; } - if(!test)answers.add(s); + //TODO Test!!!!!! + //if in one answer is an http, only add uri's + if(!double_result){ + if(contains_uri){ + if(s.contains("http"))answers.add(s); + } + else answers.add(s); + } } } //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); @@ -214,6 +253,7 @@ } anzahl+=1; } + System.out.println("\n Answer from Server: \n"); for(String answer:answers){ System.out.println(answer); } @@ -231,7 +271,7 @@ } private static boolean checkQuery(String query){ - if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")) return false; + if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")||query.contains("wikiPage")) return false; else return true; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -0,0 +1,21 @@ +package org.dllearner.algorithm.tbsl.exploration.exploration_main; + +public class Setting { + + private static boolean waitModus; + private static boolean debugModus; + public static boolean isWaitModus() { + return waitModus; + } + public static void setWaitModus(boolean waitModus) { + Setting.waitModus = waitModus; + } + public static boolean isDebugModus() { + return debugModus; + } + public static void setDebugModus(boolean debugModus) { + Setting.debugModus = debugModus; + } + + +} 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-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -40,7 +40,6 @@ public class exploration_main { - /** * @param args @@ -59,21 +58,26 @@ * Initial Index and Templator */ BasicTemplator btemplator = new BasicTemplator(); - //btemplator.UNTAGGED_INPUT = false; + btemplator.UNTAGGED_INPUT = false; + SQLiteIndex myindex = new SQLiteIndex(); WordNet wordnet = new WordNet(); StanfordLemmatizer lemmatiser = new StanfordLemmatizer(); long stopInitTime = System.currentTimeMillis(); + + Setting.setWaitModus(false); + Setting.setDebugModus(false); + System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); boolean schleife=true; - boolean doing = true; + boolean startQuestioning = true; while(schleife==true){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line; - doing = true; + startQuestioning = true; try { System.out.println("\n\n"); System.out.println("Please enter a Question:"); @@ -83,6 +87,33 @@ System.out.println("Bye!"); System.exit(0); } + + if(line.contains(":wait on")){ + Setting.setWaitModus(true); + startQuestioning=false; + if(Setting.isWaitModus()) System.out.println("WaitModus is now online"); + else System.out.println("Wait Modus is now offline"); + } + if(line.contains(":wait off")){ + Setting.setWaitModus(false); + startQuestioning=false; + if(Setting.isWaitModus()) System.out.println("WaitModus is now online"); + else System.out.println("Wait Modus is now offline"); + } + if(line.contains(":debug on")){ + Setting.setDebugModus(true); + startQuestioning=false; + if(Setting.isDebugModus()) System.out.println("DebugModus is now online"); + else System.out.println("DebugModus is now offline"); + } + if(line.contains(":debug off")){ + Setting.setDebugModus(false); + startQuestioning=false; + if(Setting.isDebugModus()) System.out.println("DebugModus is now online"); + else System.out.println("DebugModus is now offline"); + } + + if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); @@ -90,12 +121,14 @@ /*System.out.println("Please enter Path of xml File:"); line=in.readLine();*/ - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); @@ -145,7 +178,7 @@ } - else if(schleife==true && doing ==true){ + else if(schleife==true && startQuestioning ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); @@ -241,7 +274,8 @@ int counter=0; System.out.println("Anzahl queryInformations: "+list.size()); for (queryInformation s : list){ - if(!s.getResult().isEmpty()){ + //why doing this? try that it doesnt matter if there is an answer or not.... + //if(!s.getResult().isEmpty()){ String tmp; if(counter==0){ counter=counter+1; @@ -266,7 +300,7 @@ } tmp+="</answers></question>\n"; xmlDocument+=tmp; - } + //} } xmlDocument+="</dataset>"; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -9,6 +9,8 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; @@ -37,7 +39,7 @@ } catch (Exception e){ gotResource=false; - System.out.println("Didnt get any Resource"); + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt get any Resource"); } //System.out.println("Anzahl der Resource Listen: "+resources.size()); @@ -81,7 +83,7 @@ String variable = h.getVariable(); String name = h.getName(); RL.add(h); - System.out.println("Found Resource"); + if(Setting.isDebugModus())DebugMode.debugPrint("Found Resource "+h.getName() +" "+h.getUri()); /* @@ -121,11 +123,6 @@ for(String s : propertyNameList){ String[] array = s.split("::"); - System.out.println("String: "+s); - /*System.out.println("Array:"); - for(String t : array){ - System.out.println(t); - }*/ /* * array[0] contains name of Property @@ -173,7 +170,7 @@ * TODO:Add special case, if we have only one condition but with an isA in it. */ RL.add(h); - System.out.println("Found Class"); + if(Setting.isDebugModus())DebugMode.debugPrint("Found Class "+h.getName() +" "+h.getUri()); for(ElementList el:resources){ /* Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-11 15:07:53 UTC (rev 3634) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-13 08:30:41 UTC (rev 3635) @@ -95,9 +95,16 @@ if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ if(!result_SemanticsMatchProperties.contains(key)){ result_SemanticsMatchProperties.add(key); - double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); - listOfNewHypothesen.add(h); + if(key.toLowerCase().contains(property_to_compare_with.toLowerCase())){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 1.5); + listOfNewHypothesen.add(h); + } + else{ + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-18 14:01:39
|
Revision: 3641 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3641&view=rev Author: sebastianwtr Date: 2012-04-18 14:01:32 +0000 (Wed, 18 Apr 2012) Log Message: ----------- [tbsl exploration] added 1 R and 2 Conditions Modified 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/Utils/ServerUtil.java 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/Setting.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/modules/IterationModule.java 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/WordnetModule.java Modified: 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 2012-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -6,7 +6,10 @@ public class LinearSort { - public static void doSort(ArrayList<QueryPair> qp){ + /* + * TODO: test if the sorted queries are given back properly + */ + public static ArrayList<QueryPair> doSort(ArrayList<QueryPair> qp){ boolean change=true; while(change){ @@ -23,6 +26,8 @@ } if(Setting.isDebugModus())DebugMode.printQueryPair(qp); + + return qp; } 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-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -22,6 +22,12 @@ private static int timeToTimeoutOnServer=30000; + public static HashMap<String, String> generatesQueryForOutsideClasses(String query){ + String working_query= ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + + return generateList(getListOfElements(working_query)); + + } public static String createServerRequest(String query){ String anfrage=null; @@ -135,7 +141,9 @@ /* * TODO: Still a not "valid" url */ - String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; + String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; + //System.out.println(query); + //DebugMode.waitForButton(); String query_final=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String result=""; result = getListOfElements(query_final); Modified: 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 2012-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -1,6 +1,10 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; @@ -22,7 +26,7 @@ import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class MainInterface { - private static int anzahlAbgeschickterQueries = 10; + private static int anzahlAbgeschickterQueries = 100; public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ @@ -55,7 +59,9 @@ ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); //generate QueryPair + String Question=""; for(Template t : template_list){ + Question=t.getQuestion(); t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); qp_t = Query.returnSetOfQueries(t, "NORMAL"); @@ -72,7 +78,10 @@ } //sort QueryPairs - LinearSort.doSort(qp); + qp=LinearSort.doSort(qp); + printQueries(qp, "NORMAL", Question); + + int anzahl=1; boolean go_on = true; for(QueryPair q : qp){ @@ -128,7 +137,7 @@ if(answers.isEmpty()){ answers.clear(); - answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN")); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); if(wait)DebugMode.waitForButton(); } @@ -139,7 +148,7 @@ if(answers.isEmpty()){ answers.clear(); - answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET")); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET","neu")); if(wait)DebugMode.waitForButton(); } @@ -171,7 +180,7 @@ private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, - StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type) { + StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type, String test) { ArrayList<String> answers = new ArrayList<String>(); ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); int anzahl; @@ -179,9 +188,32 @@ System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); - if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); - if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + if(test.contains("alt")){ + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + } + + if(test.contains("neu")){ + System.err.println("IN NEU!!!!!"); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); + for(ArrayList<Hypothesis> l_h : t.getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); + generated_hypothesis= IterationModule.new_iteration(t.getElm(),l_h,t.getCondition(),type,myindex,wordnet,lemmatiser); + for(ArrayList<Hypothesis> h_t : generated_hypothesis){ + ArrayList<Hypothesis> new_hypothesen_set = new ArrayList<Hypothesis>(); + for(Hypothesis bla : h_t){ + new_hypothesen_set.add(bla); + } + hypothesenSetList.add(new_hypothesen_set); + } + + //hypothesenSetList.addAll(blub); + } + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + } + } catch (Exception e){ @@ -193,8 +225,10 @@ * Generate Queries and test queries */ //generate QueryPair + String Question=""; for(Template t : template_list){ //t.printAll(); + Question=t.getQuestion(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); qp_t = Query.returnSetOfQueries(t, type); for(QueryPair p : qp_t){ @@ -210,7 +244,9 @@ } //sort QueryPairs - LinearSort.doSort(qp); + qp=LinearSort.doSort(qp); + + printQueries(qp, type, Question); anzahl=1; go_on = true; for(QueryPair q : qp){ @@ -275,4 +311,63 @@ else return true; } + + private static void printQueries(ArrayList<QueryPair> qp, String type, String Question){ + String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQueryList.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 = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + String querylist=""; + querylist="\n Modul: "+type+"\nfor Question: "+ Question+"\n"; + int anzahl= 0; + /* + * write only the first 10 queries: + */ + for(QueryPair q : qp){ + if(anzahl<10){ + querylist+=q.getQuery()+" "+q.getRank()+"\n"; + anzahl+=1; + } + + } + + + + try { + bw.write(result_string+querylist); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -4,6 +4,7 @@ private static boolean waitModus; private static boolean debugModus; + public static boolean isWaitModus() { return waitModus; } @@ -16,6 +17,6 @@ public static void setDebugModus(boolean debugModus) { Setting.debugModus = debugModus; } + - } 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-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -70,6 +70,8 @@ Setting.setWaitModus(false); Setting.setDebugModus(false); + + System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); boolean schleife=true; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -1,7 +1,15 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; import net.didion.jwnl.JWNLException; @@ -10,6 +18,7 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; @@ -32,6 +41,9 @@ */ public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ + + + boolean gotResource=true; ArrayList<ElementList> resources = new ArrayList<ElementList>(); try{ @@ -316,6 +328,440 @@ return finalHypothesenList; } + + + /* + * Use Here only one Hypothesen Set at each time, so for each "AusgangshypothesenSet" start this function + */ + public static ArrayList<ArrayList<Hypothesis>> new_iteration(Elements elm,ArrayList<Hypothesis> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException, JWNLException, IOException{ + + //System.err.println("Startet new_iteration"); + ArrayList<ArrayList<Hypothesis>> finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); + + boolean simple_structure = false; + + + /* String dateiname="/home/swalter/Dokumente/Auswertung/ConditionsList.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 = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + String condition_string=""; + for(ArrayList<String> cl : givenConditionList){ + condition_string+="["; + for(String s : cl){ + condition_string+=s+" "; + } + condition_string+="]"; + } + + + try { + bw.write(result_string+condition_string); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ + + + + + + /*for(ArrayList<String> als : givenConditionList){ + for(String s : als) System.err.println(s); + }*/ + /*try { + DebugMode.waitForButton(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + if(givenConditionList.size()==1){ + System.err.println("Only one Condition => simple Struktur"); + simple_structure=true; + + boolean resource_case=false; + boolean isa_case=false; + + for(Hypothesis h : givenHypothesenList){ + /* + * if there is an ISA you cant to any thing, except returning HypothesenList to be send to the Server + */ + if(h.getType().contains("ISA")){ + isa_case=true; + finalHypothesenList.add(givenHypothesenList); + } + if(h.getType().contains("RESOURCE")){ + /* + * Check if Property is left or right of oneself + */ + String case_side = "RIGHT"; + + ArrayList<String> condition = new ArrayList<String>(); + condition = givenConditionList.get(0); + if(condition.get(2).contains(h.getVariable())) case_side="LEFT"; + + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + boolean gotResource=true; + try{ + resources = elm.getElements(); + } + catch (Exception e){ + gotResource=false; + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt get any Resource"); + } + + if(gotResource){ + for(ElementList el : resources){ + if(el.getVariablename().contains(h.getName())&&el.getVariablename().contains(case_side)){ + + String property_name=""; + for(Hypothesis h_t : givenHypothesenList){ + if(h_t.getVariable().contains(condition.get(1))){ + property_name=h_t.getName(); + break; + } + } + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(condition.get(1),property_name,el.getHm(),myindex,wordnet,lemmatiser); + for(Hypothesis h_temp : resultHypothesenList) { + ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); + temp_al.add(h); + temp_al.add(h_temp); + finalHypothesenList.add(temp_al); + } + } + } + + } + + } + } + + + + return finalHypothesenList; + } + + + + + + /* + * two conditions! + */ + if(givenConditionList.size()==2){ + System.out.println("two Conditions => NOT simple Struktur"); + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + boolean gotResource=true; + try{ + resources = elm.getElements(); + } + catch (Exception e){ + gotResource=false; + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt get any Resource"); + } + + + ArrayList<String> condition1 = givenConditionList.get(0); + ArrayList<String> condition2 = givenConditionList.get(1); + + /* + * ISA + */ + boolean condition1_exists_isa = false; + boolean condition2_exists_isa = false; + if(condition1.get(1).contains("ISA")) condition1_exists_isa=true; + if(condition2.get(1).contains("ISA")) condition2_exists_isa=true; + + + /* + * Resource: Find out the Resource, the Side of the depending Property and mark the Hypothesis for the Resource + */ + + boolean condition1_exists_resource = false; + boolean condition2_exists_resource = false; + String resource_variable=null; + Hypothesis resource_h=null; + + + String property_Side = "RIGHT"; + for(Hypothesis h : givenHypothesenList){ + if(h.getVariable().contains(condition1.get(0))&&h.getType().contains("RESOURCE")){ + condition1_exists_resource=true; + property_Side="RIGHT"; + resource_variable=h.getVariable(); + resource_h=h; + } + if(h.getVariable().contains(condition1.get(2))&&h.getType().contains("RESOURCE")){ + condition1_exists_resource=true; + property_Side="LEFT"; + resource_variable=h.getVariable(); + resource_h=h; + } + + if(h.getVariable().contains(condition2.get(0))&&h.getType().contains("RESOURCE")){ + condition2_exists_resource=true; + property_Side="RIGHT"; + resource_variable=h.getVariable(); + resource_h=h; + } + if(h.getVariable().contains(condition2.get(2))&&h.getType().contains("RESOURCE")){ + condition2_exists_resource=true; + property_Side="LEFT"; + resource_variable=h.getVariable(); + resource_h=h; + } + + } + + + /* + * ISA + */ + if((condition1_exists_isa||condition2_exists_isa)&&gotResource){ + + /* + * get Hypothese for the Class + */ + String class_variable=null; + if(condition1_exists_isa)class_variable= condition1.get(2); + if(condition2_exists_isa)class_variable= condition2.get(2); + + Hypothesis class_h=null; + + for(Hypothesis h_t : givenHypothesenList){ + if(h_t.getVariable().contains(class_variable)){ + class_h=h_t; + break; + } + } + + System.out.println("class_variable: " + class_variable); + System.out.println("Class Hypothese: "); + class_h.printAll(); + for(ElementList el : resources){ + //System.out.println("el.getVariablename(): "+el.getVariablename()); + if(el.getVariablename().contains(class_h.getName())){ + System.out.println("In If Abfrage bei der Iteration ueber el"); + String property_name=""; + String property_variable=""; + + if(condition1_exists_isa)property_variable= condition2.get(1); + if(condition2_exists_isa)property_variable= condition1.get(1); + + System.out.println("property_variable: " + property_variable); + + for(Hypothesis h_t : givenHypothesenList){ + if(h_t.getVariable().contains(property_variable)){ + property_name=h_t.getName(); + break; + } + } + System.out.println("property_name: " + property_name); + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + for (Entry<String, String> entry : el.getHm().entrySet()) { + System.out.println(entry.getKey()+" "+entry.getValue()); + } + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); + System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); + for(Hypothesis h_temp : resultHypothesenList) { + ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); + temp_al.add(class_h); + temp_al.add(h_temp); + System.out.println("Hypothesen:"); + class_h.printAll(); + h_temp.printAll(); + finalHypothesenList.add(temp_al); + } + } + } + + +/* try { + DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + */ + return finalHypothesenList; + + } + + + + + /* + * Resource + */ + + if((condition1_exists_resource||condition2_exists_resource)&&gotResource){ + + System.out.println("IN RESOURCE NOT SIMPLE CASE!!!"); + System.out.println("resource_variable: " + resource_variable); + System.out.println("Resource Hypothese: "); + resource_h.printAll(); + + String property_name=""; + String second_property_name=""; + String property_variable=""; + String second_property_variable=""; + + if(condition1_exists_resource){ + //property_variable= condition1.get(1); + //second_property_variable=condition2.get(1); + property_variable= condition2.get(1); + second_property_variable=condition1.get(1); + } + if(condition2_exists_resource){ + //property_variable= condition2.get(1); + //second_property_variable=condition1.get(1); + property_variable= condition1.get(1); + second_property_variable=condition2.get(1); + } + + System.out.println("property_variable: " + property_variable); + System.out.println("scond_property_variable: " + second_property_variable); + for(ArrayList<String> al : givenConditionList){ + for(String s : al) System.out.println(s); + } + for(Hypothesis h : givenHypothesenList){ + h.printAll(); + } + + for(Hypothesis h_t : givenHypothesenList){ + if(h_t.getVariable().contains(property_variable)){ + property_name=h_t.getName(); + + } + if(h_t.getVariable().contains(second_property_variable)){ + second_property_name=h_t.getName(); + + } + } + System.out.println("property_name: " + property_name); + System.out.println("second_property_name: " + second_property_name); + + if(Setting.isWaitModus())DebugMode.waitForButton(); + + + for(ElementList el : resources){ + //System.out.println("el.getVariablename(): "+el.getVariablename()); + if(el.getVariablename().contains(resource_h.getName())&&el.getVariablename().contains(property_Side)){ + System.out.println("In If Abfrage bei der Iteration ueber el"); + + + System.out.println("property_name: " + property_name); + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + /*for (Entry<String, String> entry : el.getHm().entrySet()) { + System.out.println(entry.getKey()+" "+entry.getValue()); + } + + if(Setting.isWaitModus()) + try { + DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); + System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); + for(Hypothesis h_temp : resultHypothesenList) { + String Query=""; + if(property_Side.contains("LEFT")){ + Query= "SELECT DISTINCT ?s ?x WHERE {<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + + } + else{ + Query= "SELECT DISTINCT ?s ?x WHERE {?x <"+h_temp.getUri()+"> <"+ resource_h.getUri()+"> . ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + + } + /* + * Now use the variable from the second condition which does not has an Resource in the Hypothesis + */ + System.out.println("Query: "+Query); + HashMap<String, String> hm_newClasses=ServerUtil.generatesQueryForOutsideClasses(Query); + + + ArrayList<Hypothesis> second_resultHypothesenList=new ArrayList<Hypothesis>(); + + + + if(type.contains("LEVENSTHEIN"))second_resultHypothesenList= LevenstheinModule.doLevensthein(second_property_variable,second_property_name,hm_newClasses); + if(type.contains("WORDNET"))second_resultHypothesenList= WordnetModule.doWordnet(second_property_variable,second_property_name,hm_newClasses,myindex,wordnet,lemmatiser); + System.out.println("SIze of second_resultHypothesenList: "+second_resultHypothesenList.size()); + + for(Hypothesis second_h_temp : second_resultHypothesenList) { + ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); + temp_al.add(resource_h); + temp_al.add(h_temp); + temp_al.add(second_h_temp); + resource_h.printAll(); + h_temp.printAll(); + second_h_temp.printAll(); + /* + * for each hypothesis now get the x from the Server an generate for second condition depending on the x new Hypothesen Set. + * afterwars add new_h_temp, h_temp, resource_h to the array Set temp_al and add temp_all to final Hypothesen Set + */ + + finalHypothesenList.add(temp_al); + } + + } + } + } + + return finalHypothesenList; + } + } + + return finalHypothesenList; + + + } + } 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-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.85; + private final static double LevenstheinMin=0.65; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-18 12:51:51 UTC (rev 3640) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-18 14:01:32 UTC (rev 3641) @@ -12,7 +12,9 @@ import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; @@ -90,19 +92,48 @@ String value = entry.getValue(); key=key.replace("\"",""); key=key.replace("@en",""); + key=key.toLowerCase(); for(String b : semantics){ - if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ + /* + * Error in StanfordLemmatizer, thats why first left out here + */ + //if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ + //System.out.println("B: "+b +" Key: "+key); + if(key.contains(b.toLowerCase())||b.toLowerCase().contains(key)){ + + /*System.out.println("Found: "+b); + if(Setting.isWaitModus()) + try { + DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ if(!result_SemanticsMatchProperties.contains(key)){ result_SemanticsMatchProperties.add(key); - if(key.toLowerCase().contains(property_to_compare_with.toLowerCase())){ + if(key.toLowerCase().contains(property_to_compare_with.toLowerCase())||property_to_compare_with.toLowerCase().contains(key)){ + System.out.println("Variable: "+ variable+" key: "+key+" value : "+value); Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 1.5); listOfNewHypothesen.add(h); + try { + if(Setting.isWaitModus())DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } else{ double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); listOfNewHypothesen.add(h); + System.out.println("Found for key: "+key); + try { + if(Setting.isWaitModus())DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } @@ -111,6 +142,13 @@ } } + /*System.out.println("Anzahl listOfNewHypothesen: "+listOfNewHypothesen.size()); + try { + DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ return listOfNewHypothesen; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-20 14:41:02
|
Revision: 3650 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3650&view=rev Author: sebastianwtr Date: 2012-04-20 14:40:53 +0000 (Fri, 20 Apr 2012) Log Message: ----------- [tbsl exploration] improved settings Modified Paths: -------------- 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/Sparql/TemplateBuilder.java 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/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java Modified: 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/Index_utils.java 2012-04-20 09:07:54 UTC (rev 3649) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-20 14:40:53 UTC (rev 3650) @@ -101,10 +101,17 @@ string=string.replace("-", " "); string=string.replace(".", " "); String result=null; + String result2 = null; ArrayList<String> result_List = new ArrayList<String>(); result=myindex.getPropertyURI(string.toLowerCase()); + result2=myindex.getontologyURI(string.toLowerCase()); if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); - if(result!=null){ + if(result2!=null){ + result_List.add(result2); + hm.put(result, 1.0f); + if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); + } + else if(result!=null){ result_List.add(result); hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); @@ -173,6 +180,38 @@ } + /* + * also add String without the plural s at the end. + */ + if(string.substring(string.length()-1).contains("s")){ + String neuer_string = string.substring(0, string.length() -1); + tmp1=myindex.getontologyClassURI(neuer_string.toLowerCase()); + tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); + if(tmp1!=null){ + result_List.add(tmp1); + } + if(tmp2!=null){ + result_List.add(tmp1); + } + } + + if(string.length()>3){ + if(string.substring(string.length()-3).contains("ies")){ + String neuer_string = string.substring(0, string.length() -3); + neuer_string+="y"; + tmp1=myindex.getontologyClassURI(neuer_string.toLowerCase()); + tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); + if(tmp1!=null){ + result_List.add(tmp1); + } + if(tmp2!=null){ + result_List.add(tmp1); + } + + } + } + + return result_List; 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-04-20 09:07:54 UTC (rev 3649) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-20 14:40:53 UTC (rev 3650) @@ -48,12 +48,13 @@ ArrayList<Template> resultArrayList = new ArrayList<Template>(); 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. * Only in Debug Mode */ - if(Setting.isDebugModus()){ + //if(Setting.isDebugModus()){ if(querytemps.contains("could not be parsed") || querytemps.isEmpty()){ String dateiname="/home/swalter/Dokumente/Auswertung/NotParsed.txt"; String result_string =""; @@ -78,7 +79,7 @@ } - } + //} long stop_template = System.currentTimeMillis(); Modified: 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 2012-04-20 09:07:54 UTC (rev 3649) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-20 14:40:53 UTC (rev 3650) @@ -24,9 +24,10 @@ import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; +import org.dllearner.algorithms.gp.GP; public class MainInterface { - private static int anzahlAbgeschickterQueries = 100; + private static int anzahlAbgeschickterQueries = 10; public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ @@ -93,6 +94,7 @@ else{ go_on=false; + if(qp.size()<3)go_on=true; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); //go_on=true; boolean contains_uri=false; @@ -249,6 +251,7 @@ printQueries(qp, type, Question); anzahl=1; go_on = true; + int id=0; for(QueryPair q : qp){ if(anzahl<anzahlAbgeschickterQueries&go_on){ ArrayList<String> answer_tmp = new ArrayList<String>(); @@ -261,6 +264,13 @@ //go_on=true; go_on=false; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(qp.size()>(id+1)){ + if(q.getRank()==qp.get(id+1).getRank()){ + go_on=true; + } + } + + boolean contains_uri=false; for(String s : answer_tmp){ if(s.contains("http")){ @@ -288,6 +298,7 @@ } } anzahl+=1; + id+=1; } System.out.println("\n Answer from Server: \n"); for(String answer:answers){ 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-04-20 09:07:54 UTC (rev 3649) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-20 14:40:53 UTC (rev 3650) @@ -130,7 +130,8 @@ //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-questions.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); @@ -161,6 +162,10 @@ for(queryInformation s : list_of_resultstructs){ System.out.println(s.getResult()); }*/ + + long stopTime = System.currentTimeMillis(); + System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); + String systemid=""; systemid=createXML(list_of_structs); String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; 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-04-20 09:07:54 UTC (rev 3649) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-20 14:40:53 UTC (rev 3650) @@ -21,14 +21,33 @@ String key = entry.getKey(); key=key.replace("\"",""); key=key.replace("@en",""); + key=key.toLowerCase(); String value = entry.getValue(); //compare property gotten from the resource with the property from the original query double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); //if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ - - if(nld>=LevenstheinMin){ + + if(key.contains(property_to_compare_with)||property_to_compare_with.contains(key)){ + if(nld<0.8){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.85); + listOfNewHypothesen.add(h); + } + else{ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + + } + else if(key.substring(key.length()-1).contains("s")){ + String neuer_string = key.substring(0, key.length() -1); + if(neuer_string.contains(property_to_compare_with)||property_to_compare_with.contains(neuer_string)){ + Hypothesis h = new Hypothesis(variable, neuer_string, value, "PROPERTY", 1.5); + listOfNewHypothesen.add(h); + } + } + else if(nld>=LevenstheinMin){ Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); listOfNewHypothesen.add(h); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-23 16:27:59
|
Revision: 3652 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3652&view=rev Author: sebastianwtr Date: 2012-04-23 16:04:23 +0000 (Mon, 23 Apr 2012) Log Message: ----------- [tbsl exploration] changed some functions Modified Paths: -------------- 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/exploration_main/Setting.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/modules/LevenstheinModule.java Modified: 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/Index_utils.java 2012-04-21 15:10:29 UTC (rev 3651) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-23 16:04:23 UTC (rev 3652) @@ -150,12 +150,12 @@ if(tmp1!=null){ result_List.add(tmp1); } - else{ + /*else{ /* * doesnt contains to much classes right now */ - ArrayList<String> tmp_List = new ArrayList<String>(); + /* ArrayList<String> tmp_List = new ArrayList<String>(); String[] array_tmp= string.split(" "); if(array_tmp.length>1){ @@ -163,7 +163,7 @@ } if(tmp_List!=null)for(String st : tmp_List){ if(st.contains("ontology")|| st.contains("yago"))result_List.add(st); - } + }*/ /*ArrayList<String> tmp_List = new ArrayList<String>(); @@ -175,7 +175,7 @@ } }*/ - } + //} if(tmp2!=null) { @@ -184,7 +184,7 @@ /* * if nothing is found, also try the like operator for each part of the string */ - else{ + /*else{ ArrayList<String> tmp_List = new ArrayList<String>(); String[] array_tmp= string.split(" "); for(String s : array_tmp){ @@ -194,7 +194,7 @@ } } - } + }*/ /* * also add String without the plural s at the end. Modified: 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/Index/SQLiteIndex.java 2012-04-21 15:10:29 UTC (rev 3651) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-04-23 16:04:23 UTC (rev 3652) @@ -13,7 +13,9 @@ import java.sql.Statement; import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; public class SQLiteIndex { @@ -650,6 +652,8 @@ } public ArrayList<String> getListOfUriSpecialIndex(String string){ + + if(!Setting.isNewIndex())return null; string= string.toLowerCase(); String[] temp_list = string.split(" "); ArrayList<String> first_result=new ArrayList<String>(); @@ -696,8 +700,14 @@ return null; } + System.out.println(result.size() + " URI's over new Index were found!"); + try { + DebugMode.waitForButton(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - return result; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-21 15:10:29 UTC (rev 3651) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-23 16:04:23 UTC (rev 3652) @@ -4,6 +4,7 @@ private static boolean waitModus; private static boolean debugModus; + private static boolean newIndex; public static boolean isWaitModus() { return waitModus; @@ -17,6 +18,12 @@ public static void setDebugModus(boolean debugModus) { Setting.debugModus = debugModus; } + public static boolean isNewIndex() { + return newIndex; + } + public static void setNewIndex(boolean newIndex) { + Setting.newIndex = newIndex; + } } 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-04-21 15:10:29 UTC (rev 3651) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-23 16:04:23 UTC (rev 3652) @@ -69,6 +69,7 @@ Setting.setWaitModus(false); Setting.setDebugModus(false); + Setting.setNewIndex(false); @@ -114,6 +115,18 @@ if(Setting.isDebugModus()) System.out.println("DebugModus is now online"); else System.out.println("DebugModus is now offline"); } + if(line.contains(":newIndex on")){ + Setting.setNewIndex(true); + startQuestioning=false; + if(Setting.isDebugModus()) System.out.println("newIndex is now online"); + else System.out.println("DebugModus is now offline"); + } + if(line.contains(":newIndex off")){ + Setting.setNewIndex(false); + startQuestioning=false; + if(Setting.isDebugModus()) System.out.println("newIndex is now online"); + else System.out.println("DebugModus is now offline"); + } 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-04-21 15:10:29 UTC (rev 3651) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-23 16:04:23 UTC (rev 3652) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.65; + private final static double LevenstheinMin=0.85; 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. |
From: <seb...@us...> - 2012-04-29 15:58:44
|
Revision: 3665 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3665&view=rev Author: sebastianwtr Date: 2012-04-29 15:58:36 +0000 (Sun, 29 Apr 2012) Log Message: ----------- [tbsl-exploration] updated some functions and repaired the function for getting informations from the server Modified Paths: -------------- 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/Template.java 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/Query.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/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.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/modules/IterationModule.java 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/WordnetModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/SemanticRelatenes.java Modified: 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/Index_utils.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -104,26 +104,51 @@ String result=null; String result2 = null; ArrayList<String> result_List = new ArrayList<String>(); - result=myindex.getPropertyURI(string.toLowerCase()); - result2=myindex.getontologyURI(string.toLowerCase()); - if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); - if(result2!=null){ - result_List.add(result2); - hm.put(result, 1.0f); - if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); + + if(string.substring(string.length()-1).contains("s")){ + String neuer_string = string.substring(0, string.length() -1); + result=myindex.getPropertyURI(neuer_string.toLowerCase()); + result2=myindex.getontologyURI(neuer_string.toLowerCase()); + //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); + if(result2!=null){ + result_List.add(result2); + hm.put(result, 1.0f); + } + else if(result!=null){ + result_List.add(result); + hm.put(result, 1.0f); + if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); + } + else{ + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); + + result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + hm.put(result, 0.0f); + } } - else if(result!=null){ - result_List.add(result); - hm.put(result, 1.0f); - if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); - } else{ - if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); - - result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); - hm.put(result, 0.0f); + result=myindex.getPropertyURI(string.toLowerCase()); + result2=myindex.getontologyURI(string.toLowerCase()); + if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); + if(result2!=null){ + result_List.add(result2); + hm.put(result, 1.0f); + if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); + } + else if(result!=null){ + result_List.add(result); + hm.put(result, 1.0f); + if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); + } + else{ + if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); + + result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + hm.put(result, 0.0f); + } } + if(Setting.isDebugModus())DebugMode.debugPrint("######\n"); @@ -146,7 +171,7 @@ ArrayList<String> result_List = new ArrayList<String>(); tmp1=myindex.getontologyClassURI(string.toLowerCase()); - tmp2=myindex.getYagoURI(string.toLowerCase()); + //tmp2=myindex.getYagoURI(string.toLowerCase()); if(tmp1!=null){ result_List.add(tmp1); } @@ -178,9 +203,9 @@ //} - if(tmp2!=null) { + /*if(tmp2!=null) { result_List.add(tmp2); - } + }*/ /* * if nothing is found, also try the like operator for each part of the string */ @@ -202,13 +227,13 @@ if(string.substring(string.length()-1).contains("s")){ String neuer_string = string.substring(0, string.length() -1); tmp1=myindex.getontologyClassURI(neuer_string.toLowerCase()); - tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); + //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); if(tmp1!=null){ result_List.add(tmp1); } - if(tmp2!=null){ + /*if(tmp2!=null){ result_List.add(tmp1); - } + }*/ } if(string.length()>3){ @@ -216,13 +241,13 @@ String neuer_string = string.substring(0, string.length() -3); neuer_string+="y"; tmp1=myindex.getontologyClassURI(neuer_string.toLowerCase()); - tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); + //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); if(tmp1!=null){ result_List.add(tmp1); } - if(tmp2!=null){ + /*if(tmp2!=null){ result_List.add(tmp1); - } + }*/ } } Modified: 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/Index/SQLiteIndex.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -32,12 +32,12 @@ createWordnetHelp(); createIndexOntology(); createIndexOntologyClass(); - createIndexofYago(); + //createIndexofYago(); - System.out.println("start IndexNumber"); + /*System.out.println("start IndexNumber"); createNewSpecialIndexNumber(); System.out.println("start SpecialIndex"); - createNewSpecialIndex(); + createNewSpecialIndex();*/ lemma = new StanfordLemmatizer(); @@ -148,7 +148,7 @@ rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); while(rs.next()){ String result_string= rs.getString("uri"); - System.out.println("Property: "+result_string); + //System.out.println("Property: "+result_string); //check for double: boolean found = false; for(String s: al){ @@ -160,7 +160,7 @@ rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); while(rs.next()){ String result_string= rs.getString("uri"); - System.out.println("OntologyProperty: "+result_string); + //System.out.println("OntologyProperty: "+result_string); //check for double: boolean found = false; for(String s: al){ @@ -168,7 +168,7 @@ } if(found==false)al.add(result_string); } - System.out.println("Anzahl ArrayList: "+al.size()); + //System.out.println("Anzahl ArrayList: "+al.size()); if(al.size()==1) return al.get(0); //check if there is one with an ontology in it else{ 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-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -9,6 +9,7 @@ private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); private ArrayList<ArrayList<Hypothesis>> hypothesenWordnet = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenRelate = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -187,6 +188,12 @@ public void setHypothesenWordnet(ArrayList<ArrayList<Hypothesis>> hypothesenWordnet) { this.hypothesenWordnet = hypothesenWordnet; } + public ArrayList<ArrayList<Hypothesis>> getHypothesenRelate() { + return hypothesenRelate; + } + public void setHypothesenRelate(ArrayList<ArrayList<Hypothesis>> hypothesenRelate) { + this.hypothesenRelate = hypothesenRelate; + } } 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-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -54,7 +54,7 @@ * check if templates were build, if not, safe the question and delete it for next time from the xml file. * Only in Debug Mode */ - //if(Setting.isDebugModus()){ + if(Setting.isDebugModus()){ if(querytemps.contains("could not be parsed") || querytemps.isEmpty()){ String dateiname="/home/swalter/Dokumente/Auswertung/NotParsed.txt"; String result_string =""; @@ -79,7 +79,7 @@ } - //} + } long stop_template = System.currentTimeMillis(); @@ -310,7 +310,7 @@ } if(!result.isEmpty()){ h.setUri(result.get(0)); - h.setRank(0.0); + h.setRank(1.0); } } catch (SQLException e) { // TODO Auto-generated catch block @@ -334,7 +334,10 @@ try { ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); System.out.println("Laenge tmp: "+tmp.size()); - if(tmp.size()>0)h.setUri(tmp.get(0)); + if(tmp.size()>0){ + h.setUri(tmp.get(0)); + h.setRank(1.0); + } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -345,7 +348,10 @@ try { ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); System.out.println("Laenge tmp: "+tmp.size()); - if(tmp.size()>0)h.setUri(tmp.get(0)); + if(tmp.size()>0){ + h.setUri(tmp.get(0)); + h.setRank(1.0); + } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -369,10 +375,20 @@ if(add_reverse_template){ for (ArrayList<String> x : condition_template_reverse_conditions){ ArrayList<String> new_list = new ArrayList<String>(); - new_list.add(x.get(2)); - new_list.add(x.get(1)); - new_list.add(x.get(0)); - condition_reverse_new.add(new_list); + if(x.get(1).contains("ISA")){ + new_list.add(x.get(0)); + new_list.add(x.get(1)); + new_list.add(x.get(2)); + condition_reverse_new.add(new_list); + if(condition_template_reverse_conditions.size()>=2) add_reverse_template=true; + } + else{ + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } + } } @@ -404,7 +420,10 @@ template.setElm(elm); resultArrayList.add(template); } - if(add_reverse_template){ + /* + * Also change the condition, if you have two Conditions in which is one an isa + */ + //if(add_reverse_template ||template_reverse_conditions.getCondition().size()>1 ){ start_elements = System.currentTimeMillis(); Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); stop_elements = System.currentTimeMillis(); @@ -417,7 +436,7 @@ template_reverse_conditions.setElm(elm_reverse); resultArrayList.add(template_reverse_conditions); } - } + //} } } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -0,0 +1,47 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; + +public class HeuristicSort { + + /* + * TODO: test if the sorted queries are given back properly + */ + public static ArrayList<QueryPair> doSort(ArrayList<QueryPair> qp, String question){ + + 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()&&question.contains("of")){ + //change=true; + QueryPair one = qp.get(i); + QueryPair two = qp.get(i+1); + String string = one.getQuery(); + //Pattern p = Pattern.compile (".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*"); + //Matcher m = p.matcher (string); + if(string.matches(".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*")){ + qp.set(i, one); + qp.set(i+1, two); + + } + else{ + qp.set(i, two); + qp.set(i+1, one); + } + + } + } + //} + + if(Setting.isDebugModus())DebugMode.printQueryPair(qp); + + return qp; + + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -34,7 +34,9 @@ else if(type.contains("WORDNET")){ givenHypothesenList=t.getHypothesenWordnet(); } - + else if(type.contains("RELATE")){ + givenHypothesenList=t.getHypothesenRelate(); + } else { if(!type.contains("NORMAL"))System.err.println("ATTENTION\n Given Type: "+type+" was not found in generating Queries!!\n"); givenHypothesenList=t.getHypothesen(); @@ -58,10 +60,34 @@ condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); } + + /* + * normalise Rank! + */ + + global_rank = global_rank/hypothesenList.size(); + //System.out.println("New_Condition after replacing "+condition_new); - String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); - QueryPair qp = new QueryPair(query,global_rank); - if(addQuery)queryList.add(qp); + if(t.getQuestion().toLowerCase().contains("who")){ + /* + * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> +SELECT DISTINCT ?uri ?string +WHERE { + res:Brooklyn_Bridge dbp:designer ?uri . + OPTIONAL { ?uri rdfs:label ?string. FILTER (lang(?string) = 'en') } + */ + + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+t.getQueryType()+" "+t.getSelectTerm()+"?string WHERE {"+ condition_new+" OPTIONAL { "+ t.getSelectTerm()+" rdfs:label ?string. FILTER (lang(?string) = 'en') }"+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); + QueryPair qp = new QueryPair(query,global_rank); + if(addQuery)queryList.add(qp); + + } + else{ + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); + QueryPair qp = new QueryPair(query,global_rank); + if(addQuery)queryList.add(qp); + } + } 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-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -290,17 +290,63 @@ } private static ArrayList<String> createAnswerArray(String string){ + /* + * <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><table class="sparql" border="1"> + <tbody><tr> + <th>x</th> + <th>string</th> + </tr> + <tr> + <td>http://dbpedia.org/resource/John_A._Roebling</td> + <td>"John A. Roebling"@en</td> + </tr> +</tbody></table></body></html> + */ Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); - Matcher m = p.matcher (string); + + //System.out.println("Nach erster Bearbeitung: "+string); + + Matcher m = p.matcher (string); String[] bla = string.split(" "); ArrayList<String> result= new ArrayList<String>(); for(String s: bla){ - m=p.matcher(s); + //System.out.println("s von bla: "+s); + s=s.replace("<td>\"", ""); + s=s.replace("\"@en</td>", ""); + s=s.replace("<td>", ""); + s=s.replace("</td>", ""); + + //System.out.println("s new von bla: "+s); + + s = s.replace("\"@en",""); + s = s.replace("\"",""); + s = s.replace("\n",""); + s = s.replace("^^<http://www.w3.org/2001/XMLSchema#date>",""); + s = s.replace("^^<http://www.w3.org/2001/XMLSchema#int>",""); + s = s.replace("^^<http://www.w3.org/2001/XMLSchema#number>",""); + s = s.replace("\"",""); + s=s.replace(" ", ""); + for(int i =0; i<s.length();i++){ + s=s.replace(" ",""); + } + + if(s.length()>1){ + if(s.substring(0,1).contains(" ")){ + s = s.substring(1, s.length()); + } + } + + if(!s.contains("<th>")&&!s.matches(" ")&&s.length()>0){ + //System.out.println("add :"+s+"DONE"); + result.add(s); + } + /*m=p.matcher(s); while (m.find()) { String temp = m.group(1); + System.out.println("temp: "+temp); temp = temp.replace("\"@en",""); temp = temp.replace("\"",""); temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#date>",""); @@ -310,7 +356,7 @@ //result.add(m.group(1)); result.add(temp); - } + }*/ } Modified: 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 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -16,6 +16,7 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.HeuristicSort; import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; @@ -27,7 +28,7 @@ import org.dllearner.algorithms.gp.GP; public class MainInterface { - private static int anzahlAbgeschickterQueries = 10; + //private static int anzahlAbgeschickterQueries = 10; public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ @@ -37,6 +38,7 @@ * false, goes through all */ boolean wait = false; + Setting.setThresholdSelect(0.5); if(Setting.isWaitModus())wait=true; @@ -80,13 +82,15 @@ //sort QueryPairs qp=LinearSort.doSort(qp); + qp=HeuristicSort.doSort(qp, Question); + //if(Setting.isDebugModus())printQueries(qp, "NORMAL", Question); printQueries(qp, "NORMAL", Question); + Setting.setAnzahlAbgeschickterQueries(10); - int anzahl=1; boolean go_on = true; for(QueryPair q : qp){ - if(anzahl<anzahlAbgeschickterQueries&go_on){ + if(anzahl<10&go_on &!q.getQuery().contains("ASK")){ ArrayList<String> answer_tmp = new ArrayList<String>(); System.out.println("Sending Query to Server: "+q.getQuery()); answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); @@ -94,7 +98,7 @@ else{ go_on=false; - if(qp.size()<3)go_on=true; + //if(qp.size()<3)go_on=true; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); //go_on=true; boolean contains_uri=false; @@ -106,18 +110,21 @@ } for(String s : answer_tmp){ if(checkAnswer(s)){ - boolean double_result = false; - for(String s_t : answers){ - if(s_t.contains(s)) double_result=true; - } - //TODO Test!!!!!! - //if in one answer is an http, only add uri's - if(!double_result){ - if(contains_uri){ - if(s.contains("http"))answers.add(s); + if(!s.equals("0")){ + boolean double_result = false; + for(String s_t : answers){ + if(s_t.contains(s)) double_result=true; } - else answers.add(s); + //TODO Test!!!!!! + //if in one answer is an http, only add uri's + if(!double_result){ + if(contains_uri){ + if(s.contains("http"))answers.add(s); + } + else answers.add(s); + } } + } } //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); @@ -136,9 +143,11 @@ /* * If there is no answer, start IterationMode with Levensthein */ - if(answers.isEmpty()){ + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ answers.clear(); + //Setting.setLevenstheinMin(0.65); + //Setting.setAnzahlAbgeschickterQueries(10); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); if(wait)DebugMode.waitForButton(); } @@ -147,19 +156,40 @@ * still no answer, start IterationMode with Wordnet */ - if(answers.isEmpty()){ + if(answers.isEmpty()&&Setting.getModuleStep()>=3){ answers.clear(); + //Setting.setAnzahlAbgeschickterQueries(10); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET","neu")); if(wait)DebugMode.waitForButton(); } + if(answers.isEmpty()&&Setting.getModuleStep()>=4){ + + answers.clear(); + //Setting.setAnzahlAbgeschickterQueries(10); + //Setting.setThresholdSelect(0.2); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"RELATE","neu")); + if(wait)DebugMode.waitForButton(); + } + + /*if(answers.isEmpty()){ + + answers.clear(); + Setting.setLevenstheinMin(0.25); + Setting.setAnzahlAbgeschickterQueries(20); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"SPECIAL","neu")); + if(wait)DebugMode.waitForButton(); + }*/ + - if(answers.isEmpty()){ + + + /*if(answers.isEmpty()){ System.out.println(""); //answers.add("No answers were found with the three Modules"); - } + }*/ /* @@ -185,8 +215,14 @@ StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type, String test) { ArrayList<String> answers = new ArrayList<String>(); ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + boolean special=false; int anzahl; boolean go_on; + if(type.contains("SPECIAL")){ + type ="LEVENSTHEIN"; + special=true; + } + System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ @@ -194,11 +230,14 @@ ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); } if(test.contains("neu")){ System.err.println("IN NEU!!!!!"); ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); + + for(ArrayList<Hypothesis> l_h : t.getHypothesen()){ ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); generated_hypothesis= IterationModule.new_iteration(t.getElm(),l_h,t.getCondition(),type,myindex,wordnet,lemmatiser); @@ -214,6 +253,8 @@ } if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); + } } @@ -247,13 +288,23 @@ //sort QueryPairs qp=LinearSort.doSort(qp); + printQueries(qp, type, Question); + /* + * Only for test! + */ + qp=HeuristicSort.doSort(qp, Question); - printQueries(qp, type, Question); + System.out.println("Following Querries were created:"); + for(QueryPair z : qp){ + System.out.println(z.getQuery()+" "+z.getRank()); + } + if(Setting.isDebugModus())printQueries(qp, type, Question); + //printQueries(qp, type, Question); anzahl=1; go_on = true; int id=0; for(QueryPair q : qp){ - if(anzahl<anzahlAbgeschickterQueries&go_on){ + if(q.getRank()>Setting.getThresholdSelect()&go_on &!q.getQuery().contains("ASK")){ ArrayList<String> answer_tmp = new ArrayList<String>(); answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); System.out.println("Sending Query to Server: "+q.getQuery()); @@ -263,8 +314,10 @@ //else go_on=false; //go_on=true; go_on=false; + if(special) go_on=true; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); if(qp.size()>(id+1)){ + //&&anzahl<2 if(q.getRank()==qp.get(id+1).getRank()){ go_on=true; } @@ -278,6 +331,12 @@ break; } } + /*System.out.println("\n Answer from Server Befor check answer: \n"); + for(String answer:answer_tmp){ + System.out.println(answer); + }*/ + + for(String s : answer_tmp){ if(checkAnswer(s)){ boolean double_result = false; @@ -287,6 +346,57 @@ //TODO Test!!!!!! //if in one answer is an http, only add uri's if(!double_result){ + if (Question.toLowerCase().contains("who")){ + if(!s.contains("http"))answers.add(s); + } + else if(contains_uri){ + if(s.contains("http"))answers.add(s); + } + else answers.add(s); + } + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + + else if(q.getRank()>Setting.getThresholdAsk()&go_on &q.getQuery().contains("ASK")){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + System.out.println("Sending Query to Server: "+q.getQuery()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + //go_on=true; + go_on=false; + if(special) go_on=true; + System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(qp.size()>(id+1)){ + if(q.getRank()==qp.get(id+1).getRank()){ + go_on=true; + } + } + + + boolean contains_uri=false; + for(String s : answer_tmp){ + if(s.contains("http")){ + contains_uri=true; + break; + } + } + + + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean double_result = false; + for(String s_t : answers){ + if(s_t.contains(s)) double_result=true; + } + //TODO Test!!!!!! + //if in one answer is an http, only add uri's + if(!double_result){ if(contains_uri){ if(s.contains("http"))answers.add(s); } @@ -300,6 +410,15 @@ anzahl+=1; id+=1; } + /* + * here Filter answer + */ + /*System.out.println("\n Answer from Server: \n"); + for(String answer:answers){ + System.out.println(answer); + }*/ + //System.out.println("FILTER NOW!!"); + answers=filterAnswer(answers,Question); System.out.println("\n Answer from Server: \n"); for(String answer:answers){ System.out.println(answer); @@ -310,7 +429,31 @@ - + private static ArrayList<String> filterAnswer(ArrayList<String> answers, String Question){ + if(Question.toLowerCase().contains("who")){ + boolean contains_only_uri=true; + for(String s: answers){ + if(!s.contains("http")) contains_only_uri=false; + } + if(contains_only_uri==false){ + ArrayList<String> new_answer= new ArrayList<String>(); + for(String s: answers){ + if(!s.contains("http")) { + System.out.println("s :"+s); + new_answer.add(s); + } + } + + return new_answer; + } + else{ + return answers; + } + } + + + return answers; + } private static boolean checkAnswer(String answer){ if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")||answer.contains("flickerwrappr/photos/")) return false; else return true; @@ -324,7 +467,7 @@ } private static void printQueries(ArrayList<QueryPair> qp, String type, String Question){ - String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQueryList.txt"; + String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQueryListNLD"+Setting.getLevenstheinMin()+".txt"; String result_string =""; //Open the file for reading try { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -5,7 +5,14 @@ private static boolean waitModus; private static boolean debugModus; private static boolean newIndex; + private static double LevenstheinMin; + private static int anzahlAbgeschickterQueries; + private static double thresholdSelect; + private static double thresholdAsk; + private static int moduleStep; + + public static boolean isWaitModus() { return waitModus; } @@ -24,6 +31,37 @@ public static void setNewIndex(boolean newIndex) { Setting.newIndex = newIndex; } + public static double getLevenstheinMin() { + return LevenstheinMin; + } + public static void setLevenstheinMin(double levenstheinMin) { + LevenstheinMin = levenstheinMin; + } + public static int getAnzahlAbgeschickterQueries() { + return anzahlAbgeschickterQueries; + } + public static void setAnzahlAbgeschickterQueries( + int anzahlAbgeschickterQueries) { + Setting.anzahlAbgeschickterQueries = anzahlAbgeschickterQueries; + } + public static double getThresholdSelect() { + return thresholdSelect; + } + public static void setThresholdSelect(double thresholdSelect) { + Setting.thresholdSelect = thresholdSelect; + } + public static double getThresholdAsk() { + return thresholdAsk; + } + public static void setThresholdAsk(double thresholdAsk) { + Setting.thresholdAsk = thresholdAsk; + } + public static int getModuleStep() { + return moduleStep; + } + public static void setModuleStep(int moduleStep) { + Setting.moduleStep = moduleStep; + } } 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-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -70,6 +70,16 @@ Setting.setWaitModus(false); Setting.setDebugModus(false); Setting.setNewIndex(false); + Setting.setLevenstheinMin(0.95); + Setting.setAnzahlAbgeschickterQueries(10); + Setting.setThresholdAsk(0.9); + Setting.setThresholdSelect(0.5); + /* + * 1= only "Normal" + * 2= "Normal" + Levensthein + * 3= Normal+Levensthein+Wordnet + */ + Setting.setModuleStep(2); @@ -133,7 +143,14 @@ if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - + for(int i = 0; i<1;i++){ + double min = 0.95; + min+=(i*0.05); + + //Setting.setLevenstheinMin(min); + Setting.setLevenstheinMin(0.95); + + /*System.out.println("Please enter Path of xml File:"); line=in.readLine();*/ //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; @@ -142,10 +159,13 @@ //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-questions.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-onlyWithWorking.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); @@ -160,21 +180,11 @@ anzahl=anzahl+1; System.out.println(""); 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(); ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); qi.setResult(answers); } - - /* //Print to Console - System.out.println("\n#############\n Result:"); - for(queryInformation s : list_of_resultstructs){ - System.out.println(s.getResult()); - }*/ long stopTime = System.currentTimeMillis(); System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); @@ -183,7 +193,7 @@ systemid=createXML(list_of_structs); String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; - + System.out.println(filename_for_evaluation); /* * First only for training */ @@ -192,9 +202,13 @@ Runtime r = Runtime.getRuntime(); Process p = r.exec(execute); - String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; + /* String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; execute ="firefox "+ open_file; - p = r.exec(execute); + p = r.exec(execute);*/ + } + schleife=false; + System.out.println("Bye!"); + System.exit(0); } @@ -293,9 +307,12 @@ String xmlDocument=""; int counter=0; System.out.println("Anzahl queryInformations: "+list.size()); + int anzahl = 0; for (queryInformation s : list){ //why doing this? try that it doesnt matter if there is an answer or not.... - //if(!s.getResult().isEmpty()){ + anzahl+=1; + System.out.println("Number "+anzahl); + if(!s.getResult().isEmpty()){ String tmp; if(counter==0){ counter=counter+1; @@ -315,18 +332,18 @@ else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; else if(i.matches("[0-9]*-[0-9][0-9]-[0-9]*"))input="<date>"+i+"</date>\n"; - else input="<string>"+i+"</string>\n"; + else if(i.length()>=1 && !i.equals(" "))input="<string>"+i+"</string>\n"; tmp+="<answer>"+input+"</answer>\n"; } tmp+="</answers></question>\n"; xmlDocument+=tmp; - //} + } } xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"); + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+"NLD"+Setting.getLevenstheinMin()+".xml"); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -156,6 +156,7 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,array[0],el.getHm()); if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); } catch (SQLException e) { @@ -217,6 +218,7 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,h_small.getName(),el.getHm()); if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable); for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); @@ -458,6 +460,7 @@ */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm()); if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(condition.get(1),property_name,el.getHm(),myindex,wordnet,lemmatiser); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(condition.get(1),property_name,el.getHm()); for(Hypothesis h_temp : resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(h); @@ -577,14 +580,14 @@ for(ElementList el : resources){ //System.out.println("el.getVariablename(): "+el.getVariablename()); if(el.getVariablename().contains(class_h.getName())){ - System.out.println("In If Abfrage bei der Iteration ueber el"); + //System.out.println("In If Abfrage bei der Iteration ueber el"); String property_name=""; String property_variable=""; if(condition1_exists_isa)property_variable= condition2.get(1); if(condition2_exists_isa)property_variable= condition1.get(1); - System.out.println("property_variable: " + property_variable); + //System.out.println("property_variable: " + property_variable); for(Hypothesis h_t : givenHypothesenList){ if(h_t.getVariable().contains(property_variable)){ @@ -592,15 +595,17 @@ break; } } - System.out.println("property_name: " + property_name); + //System.out.println("property_name: " + property_name); ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); - for (Entry<String, String> entry : el.getHm().entrySet()) { + /*for (Entry<String, String> entry : el.getHm().entrySet()) { System.out.println(entry.getKey()+" "+entry.getValue()); - } + }*/ /* * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); for(Hypothesis h_temp : resultHypothesenList) { @@ -687,10 +692,10 @@ for(ElementList el : resources){ //System.out.println("el.getVariablename(): "+el.getVariablename()); if(el.getVariablename().contains(resource_h.getName())&&el.getVariablename().contains(property_Side)){ - System.out.println("In If Abfrage bei der Iteration ueber el"); + //System.out.println("In If Abfrage bei der Iteration ueber el"); - System.out.println("property_name: " + property_name); + //System.out.println("property_name: " + property_name); ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); /*for (Entry<String, String> entry : el.getHm().entrySet()) { System.out.println(entry.getKey()+" "+entry.getValue()); @@ -707,6 +712,8 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); for(Hypothesis h_temp : resultHypothesenList) { @@ -731,6 +738,8 @@ if(type.contains("LEVENSTHEIN"))second_resultHypothesenList= LevenstheinModule.doLevensthein(second_property_variable,second_property_name,hm_newClasses); + if(type.contains("RELATE"))second_resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(second_property_variable,second_property_name,hm_newClasses); + if(type.contains("WORDNET"))second_resultHypothesenList= WordnetModule.doWordnet(second_property_variable,second_property_name,hm_newClasses,myindex,wordnet,lemmatiser); System.out.println("SIze of second_resultHypothesenList: "+second_resultHypothesenList.size()); 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-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -7,9 +7,10 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; public class LevenstheinModule { - private final static double LevenstheinMin=0.65; + //private final static double LevenstheinMin=0.65; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { @@ -23,6 +24,7 @@ key=key.replace("@en",""); key=key.toLowerCase(); String value = entry.getValue(); + // System.out.println("Key: "+key); ArrayList<String> property_array=new ArrayList<String>(); property_array.add(property_to_compare_with); @@ -32,30 +34,48 @@ for(String s : array_temp) property_array.add(s); } for(String compare_property :property_array ){ - + // System.out.println("compare_property: "+compare_property); double nld=Levenshtein.nld(compare_property.toLowerCase(), key); //if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ - if(key.contains(compare_property)||compare_property.contains(key)){ - if(nld<0.8){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.85); - listOfNewHypothesen.add(h); - } - else{ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); - listOfNewHypothesen.add(h); - } + if((key.contains(compare_property)||compare_property.contains(key))){ + double score=0; + if(compare_property.length()>key.length()){ + score = 0.8+(key.length()/compare_property.length()); + } + else{ + score=0.8+(compare_property.length()/key.length()); + } + + + if(compare_property.length()>4&&key.length()>4) { + //0.95 + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score); + listOfNewHypothesen.add(h); + } + else{ + //0.7 + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score-0.2); + listOfNewHypothesen.add(h); + } + + + // Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (key.length()/compare_property.length())); + // listOfNewHypothesen.add(h); + } - else if(key.substring(key.length()-1).contains("s")){ - String neuer_string = key.substring(0, key.length() -1); - if(neuer_string.contains(compare_property)||compare_property.contains(neuer_string)){ - Hypothesis h = new Hypothesis(variable, neuer_string, value, "PROPERTY", 1.5); + else if(compare_property.substring(compare_property.length()-2).contains("ed")){ + String compare_property_neu = compare_property.substring(0, compare_property.length() -2); + System.out.println("NEW compare_property: "+compare_property_neu); + if(key.contains(compare_property_neu)||compare_property_neu.contains(key)){ + + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.95); listOfNewHypothesen.add(h); } } - else if(nld>=LevenstheinMin){ + else if(nld>=Setting.getLevenstheinMin()){ Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); listOfNewHypothesen.add(h); } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/SemanticRelatenes.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/SemanticRelatenes.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/SemanticRelatenes.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -0,0 +1,63 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; + + + +public class SemanticRelatenes { + //private final static double LevenstheinMin=0.65; + + public static ArrayList<Hypothesis> doSemanticRelatenes(String variable, String property_to_compare_with, HashMap<String, String> properties) + throws SQLException { + ArrayList<Hypothesis> listOfNewHypothesen= new ArrayList<Hypothesis>(); + + + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.toLowerCase(); + String value = entry.getValue(); + + ArrayList<String> property_array=new ArrayList<String>(); + property_array.add(property_to_compare_with); + if(property_to_compare_with.contains(" ")){ + + String[] array_temp = property_to_compare_with.split(" "); + for(String s : array_temp) property_array.add(s); + } + for(String compare_property :property_array ){ + + + + double score=0; + try { + //score = CallSemRelatNess.returnSemRelat(key, compare_property); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(score>0){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score); + listOfNewHypothesen.add(h); + } + + + } + //compare property gotten from the resource with the property from the original query + + + } + + + + return listOfNewHypothesen; + } + + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-29 12:31:22 UTC (rev 3664) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-29 15:58:36 UTC (rev 3665) @@ -20,7 +20,7 @@ public class WordnetModule { - private static int explorationdepthwordnet =2; + private static int explorationdepthwordnet =1; public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException, JWNLException { @@ -100,8 +100,61 @@ */ //if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ //System.out.println("B: "+b +" Key: "+key); - if(key.contains(b.toLowerCase())||b.toLowerCase().contains(key)){ + if(key.equals(b)){ + //System.out.println("EQUALS"); + //System.out.println("B: " +b); + //System.out.println("key: " +key); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 1.0); + + + listOfNewHypothesen.add(h); + + } + else if(key.contains(b.toLowerCase())||b.toLowerCase().contains(key)){ + + //System.out.println("B: " +b); + //System.out.println("key: " +key); + + /*if(b.length()>key.length()) { + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (key.length()/b.length())); + listOfNewHypothesen.add(h); + } + else{ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (b.length()/key.length())); + listOfNewHypothesen.add(h); + }*/ + if(b.length()>4&&key.length()>4) { + double score=0; + if(b.length()>key.length()){ + score = 0.8+(key.length()/b.length()); + } + else{ + score=0.8+(b.length()/key.length()); + } + //0.95 + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score); + listOfNewHypothesen.add(h); + } + else{ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.7); + listOfNewHypothesen.add(h); + } + + + + + + + } + + else if(Levenshtein.nld(key.toLowerCase(), b.toLowerCase())>Setting.getLevenstheinMin()){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (Levenshtein.nld(key.toLowerCase(), b.toLowerCase()))); + + + listOfNewHypothesen.add(h); + } + /*System.out.println("Found: "+b); if(Setting.isWaitModus()) try { @@ -110,11 +163,11 @@ // TODO Auto-generated catch block e.printStackTrace(); }*/ - if(!result_SemanticsMatchProperties.contains(key)){ + /*if(!result_SemanticsMatchProperties.contains(key)){ result_SemanticsMatchProperties.add(key); if(key.toLowerCase().contains(property_to_compare_with.toLowerCase())||property_to_compare_with.toLowerCase().contains(key)){ - System.out.println("Variable: "+ variable+" key: "+key+" value : "+value); - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 1.5); + //System.out.println("Variable: "+ variable+" key: "+key+" value : "+value); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (key.length()/property_to_compare_with.length())); listOfNewHypothesen.add(h); try { if(Setting.isWaitModus())DebugMode.waitForButton(); @@ -127,7 +180,7 @@ double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); listOfNewHypothesen.add(h); - System.out.println("Found for key: "+key); + //System.out.println("Found for key: "+key); try { if(Setting.isWaitModus())DebugMode.waitForButton(); } catch (IOException e) { @@ -136,8 +189,8 @@ } } - } - } + }*/ + //} } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-05-06 21:36:01
|
Revision: 3693 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3693&view=rev Author: sebastianwtr Date: 2012-05-06 21:35:52 +0000 (Sun, 06 May 2012) Log Message: ----------- [tbsl exploration] implementing Step5 Modified Paths: -------------- 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/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/MainInterface.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/IterationModule.java 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/SemanticRelatenes.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Modified: 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/Index_utils.java 2012-05-04 01:00:54 UTC (rev 3692) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-05-06 21:35:52 UTC (rev 3693) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.exploration.Index; +import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; @@ -31,7 +32,12 @@ if(fall==0 || fall==3){ - result=myindex.getResourceURI(string.toLowerCase()); + try { + result=myindex.getResourceURI(string.toLowerCase()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } result_List.add(result); } @@ -46,7 +52,12 @@ if(fall==1){ - tmp1=myindex.getPropertyURI(string.toLowerCase()); + try { + tmp1=myindex.getPropertyURI(string.toLowerCase()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } tmp2=myindex.getontologyURI(string.toLowerCase()); if(tmp1!=null) result_List.add(tmp1); if(tmp2!=null) result_List.add(tmp2); @@ -65,7 +76,12 @@ string=string.replace(".", " "); String result=null; ArrayList<String> result_List = new ArrayList<String>(); - result=myindex.getResourceURI(string.toLowerCase()); + try { + result=myindex.getResourceURI(string.toLowerCase()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if(result!=null){ result_List.add(result); } @@ -107,7 +123,12 @@ if(string.substring(string.length()-1).contains("s")){ String neuer_string = string.substring(0, string.length() -1); - result=myindex.getPropertyURI(neuer_string.toLowerCase()); + try { + result=myindex.getPropertyURI(neuer_string.toLowerCase()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } result2=myindex.getontologyURI(neuer_string.toLowerCase()); //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); if(result2!=null){ @@ -127,7 +148,12 @@ } } else{ - result=myindex.getPropertyURI(string.toLowerCase()); + try { + result=myindex.getPropertyURI(string.toLowerCase()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } result2=myindex.getontologyURI(string.toLowerCase()); if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); if(result2!=null){ Modified: 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/Index/SQLiteIndex.java 2012-05-04 01:00:54 UTC (rev 3692) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-05-06 21:35:52 UTC (rev 3693) @@ -1,8 +1,12 @@ package org.dllearner.algorithm.tbsl.exploration.Index; import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.sql.Connection; @@ -54,7 +58,7 @@ WHERE City LIKE '%tav%' */ - public String getResourceURI(String string) throws SQLException{ + public String getResourceURI(String string) throws SQLException, IOException{ /* while(rs.next()) {*/ Statement stat = conn.createStatement(); @@ -68,7 +72,9 @@ } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); + return null; + } } @@ -140,7 +146,7 @@ } - public String getPropertyURI(String string) throws SQLException{ + public String getPropertyURI(String string) throws SQLException, IOException{ Statement stat = conn.createStatement(); ResultSet rs; ArrayList<String> al = new ArrayList<String>(); @@ -175,13 +181,13 @@ boolean found = false; for(String s : al){ if(s.contains("ontology")){ - System.out.println("Return String: "+s); + //System.out.println("Return String: "+s); found=true; return s; } } if(found==false){ - System.out.println("Return String: "+al.get(0)); + //System.out.println("Return String: "+al.get(0)); return al.get(0); } } @@ -190,7 +196,9 @@ } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); - System.err.println("Error in SQLiteIndex.getProperty!!"); + //System.err.println("Error in SQLiteIndex.getProperty!!"); + + return null; } Deleted: 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-05-04 01:00:54 UTC (rev 3692) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-05-06 21:35:52 UTC (rev 3693) @@ -1,2665 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; -import java.io.BufferedReader; - -import java.io.BufferedWriter; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -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.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.Set; - -import net.didion.jwnl.JWNLException; -import net.didion.jwnl.data.POS; - -import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; -import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; -import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; -import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; -import org.dllearner.algorithm.tbsl.nlp.WordNet; -import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; -import org.dllearner.algorithm.tbsl.sparql.Path; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Having; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; -import org.dllearner.algorithm.tbsl.sparql.Slot; -import org.dllearner.algorithm.tbsl.sparql.Template; -import org.dllearner.algorithm.tbsl.templator.BasicTemplator; -import org.dllearner.algorithm.tbsl.templator.Templator; -import org.xml.sax.InputSource; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - - - - -public class SparqlObject { - //global Variable dict - - //start counting with 0 - static int explorationdepthwordnet=2; - static int iterationdepth =0; - static int numberofanswers=1; - static double LevenstheinMin = 0.8; - static WordNet wordnet; - BasicTemplator btemplator; - Templator templator; - private static SQLiteIndex myindex; - boolean only_best_levensthein_query; - static StanfordLemmatizer lemmatiser; - //one Minute - private static int timeToTimeoutOnServer=60000; - - //change here and in getRessourcePropertys - //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - String Prefix="http://dbpedia.org/sparql"; - //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; - - - //Konstruktor - public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ - - wordnet = new WordNet(); - System.out.println("Loading SPARQL Templator"); - // - btemplator = new BasicTemplator(); - //btemplator.UNTAGGED_INPUT = false; - //templator = new Templator(); - System.out.println("Loading SPARQL Templator Done\n"); - System.out.println("Start Indexing"); - myindex = new SQLiteIndex(); - - System.out.println("Done:Indexing"); - - //normaly 1 - setExplorationdepthwordnet(1); - //eigentlich immer mit 0 initialisieren - setIterationdepth(9); - setNumberofanswers(1); - - only_best_levensthein_query=false; - lemmatiser = new StanfordLemmatizer(); - } - - /* - * ##################################### - * Getter and Setter Methods - */ - - public int getExplorationdepthwordnet() { - return explorationdepthwordnet; - } - - - public void setExplorationdepthwordnet(int explorationdepthwordnet) { - SparqlObject.explorationdepthwordnet = explorationdepthwordnet; - } - - - public int getIterationdepth() { - return iterationdepth; - } - - - public void setIterationdepth(int iterationdepth) { - SparqlObject.iterationdepth = iterationdepth; - } - - - public int getNumberofanswers() { - return numberofanswers; - } - - - public void setNumberofanswers(int numberofanswers) { - SparqlObject.numberofanswers = numberofanswers; - } - - - /* - * ############################## - * - */ - /* - * "Main" Method of this Class. - * - */ - public queryInformation create_Sparql_query(queryInformation queryObject) throws JWNLException, IOException, SQLException{ - //create_Sparql_query_new(string); - - ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); - long startParsingTime = System.currentTimeMillis(); - //lstquery=getQuery(queryObject.getQuery(),queryObject); - queryObject=getQuery(queryObject); - lstquery=queryObject.getQueryInformation(); - queryObject.setQueryInformation(lstquery); - /*BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); - String line; - - line = in1.readLine();*/ - long endParsingTime = System.currentTimeMillis(); - long startIterationTime = System.currentTimeMillis(); - System.out.println("The Questionparsing took "+ (endParsingTime-startParsingTime)+ " ms"); - ArrayList<String> final_answer = new ArrayList<String>(); - Set<String> final_query_hash = new HashSet<String>(); - - if(lstquery.isEmpty()){ - saveNotParsedQuestions(queryObject.getQuery()); - } - - for(ArrayList<String> querylist : lstquery){ - - boolean startIterating=true; - String query=""; - if(querylist.get(0).contains("ERROR"))startIterating=false; - else query=querylist.get(0).toString(); - - //TODO: Somewhere is an error, because sometimes there is an double _ a __ and thats not allowed. - //fixing it now with an replace of "__" to "" - query=query.replace("__", ""); - - if(getIterationdepth()==-1&&startIterating==true){ - String tmp = new String(); - String s = null; - BufferedReader in = null; - - // Liest Textzeilen aus der Datei in einen Vector: - try { - in = new BufferedReader( - new InputStreamReader( - new FileInputStream( "/tmp/testresult.txt" ) ) ); - while( null != (s = in.readLine()) ) { - tmp=tmp.concat("\n".concat(s)); - } - } 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(); - } - } - - String out=null; - if (query.equals("") || query.equals(" ")||query.length()==0) query="Could not parse"; - out=tmp + "\n" + queryObject.getQuery() + ":\n"+query+"\n"; - - BufferedWriter outfile = new BufferedWriter( - new OutputStreamWriter( - new FileOutputStream( "/tmp/testresult.txt" ) ) ); - - outfile.write(out); - outfile.close(); - - } - - /* - * ################################################################################################# - */ - //Iteration 0 - if(getIterationdepth()==0&&startIterating==true||getIterationdepth()==9&&startIterating==true){ - String tmp = new String(); - String s = null; - BufferedReader in = null; - - // Lies Textzeilen aus der Datei in einen Vector: - try { - in = new BufferedReader( - new InputStreamReader( - new FileInputStream( "/tmp/answer.txt" ) ) ); - while( null != (s = in.readLine()) ) { - tmp+="\n"+s; - } - } 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(); - } - } - - final_query_hash.add(query); - - } - /* - * ################################################################################################# - */ - //Iterration 1 - /* - * Only Levensthein!!! - */ - if(getIterationdepth()==1&&startIterating==true||getIterationdepth()==9&&startIterating==true){ - - ArrayList<String> final_answer_tmp = new ArrayList<String>(); - ArrayList<String> final_query_tmp=new ArrayList<String>(); - if(querylist.size()==4&&!query.contains("rdf:type")){ - - final_query_tmp=simpleCase(querylist, query, "LEVENSTHEIN",queryObject); - for(String i: final_query_tmp){ - final_query_hash.add(i); - - } - } - //e.g. Select ßy Where (?y rdf:type <http://..../ontology/School> - if(querylist.size()==4&&query.contains("rdf:type")){ - final_query_hash.add(query); - } - - - if(querylist.size()>4&&query.contains("rdf:type")){ - - final_query_tmp=isAIteration(querylist, query,"LEVENSTHEIN",queryObject.getIsaResource()); - for(String i: final_query_tmp){ - - final_query_hash.add(i); - } - } - - if(querylist.size()>4&&!query.contains("rdf:type")){ - final_query_tmp=advancedCase(querylist, query,"LEVENSTHEIN"); - for(String i: final_query_tmp){ - final_query_hash.add(i); - } - } - - - - - - } - /* - * ################################################################################################# - */ - //Iterration 2 - /* - * Only Wordnet!!! - */ - if(getIterationdepth()==2&&startIterating==true||getIterationdepth()==9&&startIterating==true){ - ArrayList<String> final_query_tmp = new ArrayList<String>(); - //isAIteration(querylist, query); - - if(querylist.size()==4&&!query.contains("rdf:type")){ - - final_query_tmp=simpleCase(querylist, query, "WORDNET",queryObject); - for(String i: final_query_tmp){ - final_query_hash.add(i); - } - } - //e.g. Select ßy Where (?y rdf:type <http://..../ontology/School> - if(querylist.size()==4&&query.contains("rdf:type")){ - final_query_hash.add(query); - } - - if(querylist.size()>4&&query.contains("rdf:type")){ - - final_query_tmp=isAIteration(querylist, query,"WORDNET",queryObject.getIsaResource()); - for(String i: final_query_tmp){ - final_query_hash.add(i); - } - } - - if(querylist.size()>4&&!query.contains("rdf:type")){ - final_query_tmp=advancedCase(querylist, query,"WORDNET"); - for(String i: final_query_tmp){ - final_query_hash.add(i); - } - } - - - - - } - - - } - - - /* - * Send Query to Server and get answers - */ - - - - Iterator<String> it = final_query_hash.iterator(); - while (it.hasNext()) { - System.out.println(it.next()); - ArrayList<String> answer= new ArrayList<String>(); - try{ - String anfrage=it.next().toString(); - answer=sendServerQuestionRequestArray(anfrage); - // @en is also in the ML - /* - answer_tmp=answer_tmp.replace("\"@en", ""); - answer_tmp=answer_tmp.replace("\"", "");*/ - - //filter answers! - for(String answer_tmp : answer ){ - if(answer_tmp!="EmtyAnswer"){ - if(queryObject.isHint()){ - //System.out.println("Using hint!"); - /* - * Answertyps: resource, string, boolean, num, date - */ - if(queryObject.getType().contains("boolean")){ - if(answer_tmp.contains("true")||answer_tmp.contains("false")) final_answer.add(answer_tmp); - - } - else if (queryObject.getType().contains("resource")){ - try{ - String[] tmparray = answer_tmp.split("\n"); - for(String z : tmparray)final_answer.add(z); - } - catch(Exception e){ - final_answer.add(answer_tmp); - } - } - else if (queryObject.getType().contains("string")||queryObject.getType().contains("uri")){ - if(!answer_tmp.contains("EmtyAnswer")) { - String[] tmparray = answer_tmp.split("\n"); - for(String z : tmparray)final_answer.add(z); - } - - } - else if (queryObject.getType().contains("num")){ - if(answer_tmp.matches("[0-9]*")) final_answer.add(answer_tmp); - - } - else if (queryObject.getType().contains("date")){ - final_answer.add(answer_tmp); - } - } - else{ - //final_answer.add("Begin:\n"+anfrage +"\n"+answer_tmp+" \n End"); - final_answer.add(answer_tmp); - } - } - } - } - catch (Exception e){ - - } - } - - - long stopIterationTime = System.currentTimeMillis(); - /* - * Set time - */ - - queryObject.setTimeGesamt(stopIterationTime-startParsingTime); - queryObject.setTimeParser(endParsingTime-startParsingTime); - queryObject.setTimeWithoutParser(stopIterationTime-startIterationTime); - queryObject.setResult(final_answer); - - return queryObject; - } - - private ArrayList<String> newIteration(ArrayList<String> querylist, String query, queryInformation queryObject) throws SQLException, - JWNLException { - //only for special case, that the first condition has a resource - ArrayList<String> final_answer=new ArrayList<String>(); - String firstResource=""; - String firstProperty=""; - String secondProperty=null; - String sideOfProperty=null; - String sideOfPropertyTwo=null; - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - tmpcounter=tmpcounter+1; - if(tmpcounter>=1&&tmpcounter<=4){ - if(s.contains("LEFT")){ - sideOfProperty="LEFT"; - firstResource=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfProperty="RIGHT"; - firstResource=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - firstProperty=s.replace("PROPERTY",""); - } - - } - if(tmpcounter>4){ - if(s.contains("LEFT")){ - sideOfPropertyTwo="LEFT"; - } - if(s.contains("RIGHT")){ - sideOfPropertyTwo="RIGHT"; - } - if(s.contains("PROPERTY")){ - secondProperty=s.replace("PROPERTY",""); - } - - } - - } - //first create Query and get the URI's - String firstquery=""; - if(sideOfProperty=="RIGHT"){ - firstquery="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?y WHERE {<"+getUriFromIndex(firstResource.toLowerCase(),0)+"> <"+getUriFromIndex(firstProperty.toLowerCase(),1) +"> ?y}"; - } - if(sideOfProperty=="RIGHT"){ - firstquery="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?y WHERE {<"+getUriFromIndex(firstProperty.toLowerCase(),1)+"> <"+getUriFromIndex(firstResource.toLowerCase(),0) +"> ?y}"; - - } - - //first try without iterating over wordnet and levensthein - ArrayList<String> answer_tmp=new ArrayList<String>(); - answer_tmp=sendServerQuestionRequestArray(firstquery); - - //if answer_tmp is emty try to iterate in this case with wordnet - ArrayList<String>querylist_new=new ArrayList<String>(); - querylist_new.add(firstquery); - querylist_new.add("PROPERTY"+firstProperty); - querylist_new.add(sideOfProperty+firstResource); - if(answer_tmp.isEmpty()){ - answer_tmp=simpleCase(querylist_new,firstquery,"WORDNET",queryObject); - } - //if answer_tmp is still empty return null and exit function - if(answer_tmp.isEmpty()){final_answer.add("new Iteration didnt work"); - - return final_answer; - } - - ArrayList<ArrayList<String>>secondquerylist=new ArrayList<ArrayList<String>>(); - - //we have now the uri's for the second query and the result answers - //create now for every entry, if it contains something like http an new query - for(String s : answer_tmp){ - System.out.println("!!!!!!!!!!!!!"); - System.out.println("URI found: "+ s); - System.out.println("!!!!!!!!!!!!!"); - String secondquery =""; - ArrayList<String> tmp = new ArrayList<String>(); - if(s.contains("http:")){ - if(sideOfPropertyTwo=="RIGHT"){ - secondquery="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?y WHERE {<"+getUriFromIndex(s.toLowerCase(),0)+"> <"+getUriFromIndex(secondProperty.toLowerCase(),1) +"> ?y}"; - tmp.add(secondquery); - tmp.add("PROPERTY"+secondProperty); - querylist_new.add(sideOfPropertyTwo+s); - secondquerylist.add(tmp); - } - if(sideOfPropertyTwo=="RIGHT"){ - secondquery="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?y WHERE {<"+getUriFromIndex(secondProperty.toLowerCase(),1)+"> <"+getUriFromIndex(s.toLowerCase(),0) +"> ?y}"; - tmp.add(secondquery); - tmp.add("PROPERTY"+secondProperty); - querylist_new.add(sideOfPropertyTwo+s); - secondquerylist.add(tmp); - } - - } - } - - - //TODO: Check this part of the function!!! - for(ArrayList as: secondquerylist){ - ArrayList<String> answer_tmp_two=new ArrayList<String>(); - //answer_tmp_two=sendServerQuestionRequestArray(s); - answer_tmp=simpleCase(as,as.get(0).toString(),"WORDNET",queryObject); - for(String t :answer_tmp_two){ - final_answer.add(t); - System.out.println("Answer from advanced Iteration: "+ t); - } - } - if(final_answer.isEmpty())final_answer.add("new Iteration didnt work"); - System.out.println("Returning the function"); - return final_answer; - - } - - - - private ArrayList<String> isAIteration(ArrayList<String> querylist, String query, String fall, String uri_isA_Resource) throws SQLException, - JWNLException { - ArrayList<String> new_queries= new ArrayList<String>(); - //TODO: in get Query change, that there will be a second query, but only with the part of the condition upsidedown, which doesnt contains an isA - System.out.println("\n In IsA Iteration \n"); - - /* Erster Schritt, alle x rausbekommen: - e.g: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE {?x rdf:type <http://dbpedia.org/ontology/Country>.} - - */ - - ArrayList<String> list_of_x=new ArrayList<String>(); - String query_for_x=null; - - - - - query_for_x="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?x WHERE { ?x rdf:type <"+uri_isA_Resource+">}"; - //now send query_for_x to the server, to get all x - System.out.println("IsA x-query: "+query_for_x); - if(query_for_x!=null)list_of_x=sendServerQuestionRequestArray(query_for_x); - - /* - * Zweiter Schritt: - * alle Propertys z.B. der ersten 5 xe holen und in eine Liste packen - */ - - int number_of_x_used=5; - int tmpcounter=0; - - HashMap<String,String> list_of_properties=new HashMap<String,String>(); - - for(String s: list_of_x){ - /* - * First use left and also right Propertys - */ - - tmpcounter++; - if(tmpcounter <=number_of_x_used){ - HashMap<String,String> propertiesleft = new HashMap<String, String>(); - HashMap<String,String> propertiesright = new HashMap<String, String>(); - // GetRessourcePropertys property = new GetRessourcePropertys(); - - try { - propertiesleft=ServerUtil.getPropertiesForGivenResource(s,"LEFT"); - propertiesright=ServerUtil.getPropertiesForGivenResource(s,"RIGHT"); - } - catch (Exception e){ - - } - - /* - * now put the properties togehter - */ - list_of_properties.putAll(propertiesright); - list_of_properties.putAll(propertiesleft); - } - - } - /* System.out.println("List of Properties: "); - for (Entry<String, String> entry : list_of_properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - String value = entry.getValue(); - System.out.println("Key: "+ key + " Value: "+value); - }*/ - - /* - * get Property used in the original query - * - */ - - System.out.println("Original Query: "+query); - - //http://dbpedia.org/ontology/officialLanguage - - //look for property - Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/property/.*)\\>\\W\\W*\\?.*"); - Matcher m3 = p3.matcher(query); - String property_to_compare_with_uri=""; - while(m3.find()) { - property_to_compare_with_uri=m3.group(1); - System.out.println("Property in IsA: "+m3.group(1)); - } - - //if there is no property but an ontology-property - if(property_to_compare_with_uri==""){ - Pattern p4=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[a-z].*)\\>\\W\\W*\\?.*"); - Matcher m4 = p4.matcher(query); - while(m4.find()) { - property_to_compare_with_uri=m4.group(1); - System.out.println("Property in IsA: "+m4.group(1)); - } - } - - String property_to_compare_with=property_to_compare_with_uri.replace("http://dbpedia.org/property/","").replace("http://dbpedia.org/ontology/",""); - - /* BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - String line; - - System.out.println("############################"); - System.out.println("query: "+query); - System.out.println("property_to_compare_with: "+property_to_compare_with); - System.out.println("property_to_compare_with_uri: "+property_to_compare_with_uri); - System.out.println("############################"); - try { - line = in.readLine(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }*/ - System.out.println(property_to_compare_with + " : "+property_to_compare_with_uri +" : "+uri_isA_Resource); - if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,property_to_compare_with_uri,list_of_properties); - if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with_uri,property_to_compare_with_uri,list_of_properties); - - - /* BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); - String line; - - try { - line = in1.readLine(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }*/ - return new_queries; - - } - - - - private ArrayList<String> simpleCase(ArrayList<String> querylist, String query, String fall, queryInformation queryObject) throws SQLException, - JWNLException { - - System.out.println("In Simpe levensthein case!!"); - String resource=""; - String property_to_compare_with=""; - String sideOfProperty="LEFT"; - ArrayList<String> new_queries= new ArrayList<String>(); - - - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - tmpcounter=tmpcounter+1; - if(tmpcounter>=1){ - if(s.contains("LEFT")){ - sideOfProperty="LEFT"; - resource=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfProperty="RIGHT"; - resource=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_with=s.replace("PROPERTY",""); - } - - } - - } - System.out.println("ARRAY LIST: "+querylist); - System.out.println("Property to compare:: "+ property_to_compare_with); - System.out.println("Resource: "+ resource); - - - HashMap<String,String> properties = new HashMap<String, String>(); - - Boolean goOnAfterProperty = true; - - //System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); - System.out.println("URI from Resource "+ resource +": "+queryObject.getHashValue(resource.toLowerCase())); - HashMap<String, String> bla = queryObject.getHashMap(); - System.out.println("INhalt Hasmap QueryObject:"); - for (String z: bla.keySet()) System.out.println(z); - - //gets Propertys left or right from the resource! - try { - properties=ServerUtil.getPropertiesForGivenResource(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); - if (properties==null){ - - System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - } - - System.out.println("Properties from Resource "+resource+": "+properties); - - } catch (IOException e) { - - System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - - } - if(goOnAfterProperty==true){ - if(fall.contains("WORDNET")) new_queries=doWordnet(query, property_to_compare_with,queryObject.getHashValue(property_to_compare_with.toLowerCase()),properties); - if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query, property_to_compare_with,queryObject.getHashValue(property_to_compare_with.toLowerCase()),properties); - //new_queries=doLevensthein(query, property_to_compare_with,getUriFromIndex(property_to_compare_with.toLowerCase(),1),properties); - - //add original query - new_queries.add(query); - - } - - - //test to returnqueries, put them together and than send them to the server. - return new_queries; - //return final_answer; -} - - - - - private ArrayList<String> doLevensthein(String query, String property_to_compare_with,String uri_of_property, HashMap<String, String> properties) - throws SQLException { - ArrayList<String> new_queries= new ArrayList<String>(); - String bestQuery=""; - double highestNLD=0; - //iterate over properties - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - String value = entry.getValue(); - - //compare property gotten from the resource with the property from the original query - double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); - - //check if nld is greater than Levensthein - if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ - //if its so, replace old uri with the new one - String querynew=query; - //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - String replacement =uri_of_property ; - if(!querynew.contains(replacement)){ - replacement=replacement.replace("ontology", "property"); - } - querynew=querynew.replace(replacement,value); - if(nld>highestNLD){ - bestQuery=querynew; - highestNLD=nld; - } - if(only_best_levensthein_query==true) new_queries.add(bestQuery); - else new_queries.add(querynew); - } - - } - - return new_queries; - } - - private ArrayList<String> advancedCase(ArrayList<String> querylist, String query, String fall) throws SQLException, - JWNLException { - - ArrayList<String> new_queries= new ArrayList<String>(); - String resourceOne=""; - String property_to_compare_withOne=""; - String resourceTwo=""; - String property_to_compare_withTwo=""; - String sideOfPropertyOne="LEFT"; - String sideOfPropertyTwo="LEFT"; - - - int tmpcounter=0; - for(String s : querylist){ - //we dont need the first one, because thats the query itself - - //for condition One - tmpcounter=tmpcounter+1; - if(tmpcounter>=1&&tmpcounter<=4){ - if(s.contains("LEFT")){ - sideOfPropertyOne="LEFT"; - resourceOne=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfPropertyOne="RIGHT"; - resourceOne=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_withOne=s.replace("PROPERTY",""); - } - - } - - //for condition Two - if(tmpcounter>4){ - if(s.contains("LEFT")){ - sideOfPropertyTwo="LEFT"; - resourceTwo=s.replace("LEFT",""); - } - if(s.contains("RIGHT")){ - sideOfPropertyTwo="RIGHT"; - resourceTwo=s.replace("RIGHT",""); - } - if(s.contains("PROPERTY")){ - property_to_compare_withTwo=s.replace("PROPERTY",""); - } - - } - } - HashMap<String,String> propertiesOne = new HashMap<String, String>(); - HashMap<String,String> propertiesTwo = new HashMap<String, String>(); - Boolean goOnAfterProperty = true; - - //Get Properties for Resource in condition One and Two from Server - try { - - propertiesOne=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); - propertiesTwo=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); - - if (propertiesOne==null){ - System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - } - - } catch (IOException e) { - - System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); - goOnAfterProperty=false; - - } - - - if(goOnAfterProperty==true){ - - - - //Iterate over property from resource one - - if(fall.contains("LEVENSTHEIN"))new_queries=doComplexLevensthein(query, property_to_compare_withOne,property_to_compare_withTwo, getUriFromIndex(property_to_compare_withOne.toLowerCase(),1),propertiesOne,propertiesTwo); - if(fall.contains("WORDNET")) new_queries=doComplexeWordnet(query, property_to_compare_withOne,property_to_compare_withTwo, propertiesOne, propertiesTwo); - - - //add original query for iteration - new_queries.add(query); - } - - return new_queries; -} - -private ArrayList<String> doComplexLevensthein(String query, String property_to_compare_withOne, String property_to_compare_withTwo, String uri_of_property_one, HashMap<String,String> propertiesOne,HashMap<String,String> propertiesTwo) throws SQLException{ - ArrayList<String> new_queries= new ArrayList<String>(); - for (Entry<String, String> entryOne : propertiesOne.entrySet()) { - - String queryOne=query; - String keyOne = entryOne.getKey(); - keyOne=keyOne.replace("\"",""); - keyOne=keyOne.replace("@en",""); - String valueOne = entryOne.getValue(); - - - double levnstheinDistanzeOne=Levenshtein.nld(property_to_compare_withOne.toLowerCase(), keyOne); - - /*if distance is higher or equals LevenstheinMin, replace old uri with new uri - * and use that new query, for the property of the second resource - */ - if(levnstheinDistanzeOne>=LevenstheinMin){ - //String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); - String replacementOne =uri_of_property_one; - if(!queryOne.contains(replacementOne)){ - replacementOne=replacementOne.replace("ontology", "property"); - } - queryOne=queryOne.replace(replacementOne,valueOne); - - - /* - * Iterate now over the second set of properties, but this time not using the original query in which - * to replace the old uri with the new one, but using queryOne from the first step. - */ - new_queries=doLevensthein(queryOne, property_to_compare_withTwo, getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1), propertiesTwo); - } - } - return new_queries; -} - - - -private ArrayList<String> doWordnet(String query, String property, String uri_of_property,HashMap<String,String> properties) throws SQLException, -JWNLException { - ArrayList<String> new_queries= new ArrayList<String>(); - - System.out.println("Start Iterating Wordnet with "+property+" and deept of "+explorationdepthwordnet); - ArrayList<String> semantics=new ArrayList<String>(); - ArrayList<String> tmp_semantics=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - if(property.contains("_")){ - String[] fix = property.split("_"); - //here add also lemmatiser - for(String s: fix) semantics.add(s); - } - else semantics.add(property); - System.out.println("Semantics: "+ semantics); - - for(String s: semantics){ - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - //String _temp_=myindex.getWordnetHelp(property); - String _temp_=myindex.getWordnetHelp(s); - if(_temp_!=null){ - //tmp_semantics=semantics; - tmp_semantics.add(_temp_); - tmp_semantics.add(s); - } - else tmp_semantics.add(s); - /* - else{ - semantics.clear(); - semantics.add(_temp_); - tmp_semantics=semantics; - }*/ - } - - System.out.println("tmp_semantics: "+ tmp_semantics); - Boolean goOnAfterWordnet = true; - - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semantics=getSemantics(tmp_semantics); - System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); - if (tmp_semantics==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semantics){ - if(!semantics.contains(k)) semantics.add(k); - } - } - - } catch (IOException e) { - - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); - - } - - } - - if(goOnAfterWordnet==true){ - - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - key=key.replace("\"",""); - key=key.replace("@en",""); - - for(String b : semantics){ - if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ - if(!result_SemanticsMatchProperties.contains(key)){ - result_SemanticsMatchProperties.add(key); - String query_tmp=query; - //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - System.out.println("URI of property: "+uri_of_property); - String replacement = uri_of_property; - if(!query_tmp.contains(replacement)){ - replacement=replacement.replace("ontology", "property"); - } - query_tmp=query_tmp.replace(replacement,value); - System.out.println("Simple Wordnet Query: "+ query_tmp); - new_queries.add(query_tmp); - } - } - } - } - - } - - return new_queries; -} - - - private ArrayList<String> doComplexeWordnet(String query, - String property_to_compare_withOne, - String property_to_compare_withTwo, - HashMap<String, String> propertiesOne, - HashMap<String, String> propertiesTwo) throws SQLException, - JWNLException { - - ArrayList<String> new_queries = new ArrayList<String> (); - /* - * #################################### Semantics One############################################# - */ - - - //System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); - ArrayList<String> semanticsOne=new ArrayList<String>(); - ArrayList<String> tmp_semanticsOne=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchPropertiesOne=new ArrayList<String>(); - semanticsOne.add(property_to_compare_withOne); - - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_One=myindex.getWordnetHelp(property_to_compare_withOne); - if(_temp_One==null){ - tmp_semanticsOne=semanticsOne; - } - else{ - semanticsOne.clear(); - semanticsOne.add(_temp_One); - tmp_semanticsOne=semanticsOne; - } - - //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached - Boolean goOnAfterWordnet = true; - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semanticsOne=getSemantics(tmp_semanticsOne); - if (tmp_semanticsOne==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semanticsOne){ - if(!semanticsOne.contains(k)) semanticsOne.add(k); - } - } - - } catch (IOException e) { - - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); - - } - - - } - /* - * #################################### Semantics Two############################################# - */ - - System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); - ArrayList<String> semanticsTwo=new ArrayList<String>(); - ArrayList<String> tmp_semanticsTwo=new ArrayList<String>(); - ArrayList<String> result_SemanticsMatchPropertiesTwo=new ArrayList<String>(); - semanticsTwo.add(property_to_compare_withTwo); - - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_Two=myindex.getWordnetHelp(property_to_compare_withTwo); - if(_temp_Two==null){ - tmp_semanticsOne=semanticsTwo; - } - else{ - semanticsTwo.clear(); - semanticsTwo.add(_temp_Two); - tmp_semanticsTwo=semanticsTwo; - } - - //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached - for(int i=0;i<=explorationdepthwordnet;i++){ - - try { - tmp_semanticsTwo=getSemantics(tmp_semanticsTwo); - if (tmp_semanticsTwo==null){ - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); - - } - else{ - //each word only one time - for(String k : tmp_semanticsTwo){ - if(!semanticsTwo.contains(k)) semanticsTwo.add(k); - } - } - - } catch (IOException e) { - - goOnAfterWordnet=false; - System.out.println("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); - - } - - - } - - - if(goOnAfterWordnet==true){ - - - //start iterating over the propery sets - for (Entry<String, String> entryOne : propertiesOne.entrySet()) { - String keyOne = entryOne.getKey(); - String valueOne = entryOne.getValue(); - String queryOne=query; - keyOne=keyOne.replace("\"",""); - keyOne=keyOne.replace("@en",""); - - for(String b : semanticsOne){ - if(keyOne.contains(b.toLowerCase())){ - if(!result_SemanticsMatchPropertiesOne.contains(keyOne)){ - //create new query - result_SemanticsMatchPropertiesOne.add(keyOne); - String replacementOne = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); - if(!queryOne.contains(replacementOne)){ - replacementOne=replacementOne.replace("ontology", "property"); - } - queryOne=queryOne.replace(replacementOne,valueOne); - - for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { - String keyTwo = entryTwo.getKey(); - String valueTwo = entryTwo.getValue(); - keyTwo=keyTwo.replace("\"",""); - keyTwo=keyTwo.replace("@en",""); - - for(String z : semanticsTwo){ - if(keyTwo.contains(z.toLowerCase())){ - if(!result_SemanticsMatchPropertiesTwo.contains(keyTwo)){ - //create new query - result_SemanticsMatchPropertiesTwo.add(keyTwo); - String queryTwo=queryOne; - String replacementTwo = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); - if(!queryTwo.contains(replacementTwo)){ - replacementTwo=replacementTwo.replace("ontology", "property"); - } - queryTwo=queryTwo.replace(replacementTwo,valueTwo); - System.out.println("Complexe Wordnet Query: "+ queryTwo); - new_queries.add(queryTwo); - } - } - } - } - - } - } - } - - - - } - - - //add original query for iteration - new_queries.add(query); - - } - - return new_queries; - } - - - - - - - - - - - - //TODO: Write function new!!!!! - /** - * Iterates thrue the conditions and returns an array, where one can see, if the Property is left or right from the resource - * @param query - * @return returns an array, where one can see, if the Property is left or right from the resource - */ - private static ArrayList<String> createLeftAndRightPropertyArray(String query){ - query=query.replace(" ", " "); - Pattern p = Pattern.compile (".*\\{(.*\\<http.*)\\}.*"); - Matcher m = p.matcher (query); - ArrayList<String> lstquery = new ArrayList<String>(); - while (m.find()) { - System.out.println("In While Loop!"); - String workingQuery= m.group(1); - //if there is an .../ontology/C, dann ist das eine Klasse und das ganze soll dann nicht ersetzt reingepackt werden, sondern so bleiben, wie es ist. - System.out.println("Before new pattern and checking "+workingQuery); - - //take the Filter out, so you only have the conditions left - Pattern p2=Pattern.compile (".*(\\.FILTER\\(.*\\)).*"); - Matcher m2 = p2.matcher (workingQuery); - while(m2.find()){ - System.out.println("FIlter: "+m2.group(1)); - workingQuery=workingQuery.replace(m2.group(1), ""); - System.out.println("Without Filter: "+workingQuery); - } - - String resourceTemp=""; - - if(workingQuery.contains("ontologie")){ - Pattern p1=Pattern.compile (".*\\<(http://dbpedia.org/ontology/[A-Z].*)\\>\\W\\W*.*"); - Matcher m1 = p1.matcher (workingQuery); - - - /* - * Das darf nicht sein: - * Replacment: <http://dbpedia.org/ontology/Caves> rdf:type ?x .?y <http://dbpedia.org/property/entrances> - */ - while(m1.find()){ - resourceTemp="RESOURCE"+m1.group(1); - String replacment="<"+m1.group(1)+">"; - //TODO: Make it nice!!! - //if he doesnt find the ontolokg party, kind of skip - if(!replacment.contains("property")&&!replacment.contains("resource")){ - System.out.println("Replacment: "+replacment); - workingQuery=workingQuery.replace(replacment, "SKIP"); - System.out.println("New temp: "+workingQuery); - } - - } - - } - - /* - * dbpedia.org/class/yago/ - */ - if(workingQuery.contains("yago")){ - Pattern p3=Pattern.compile (".*\\<(http://dbpedia.org/class/yago//[A-Z].*)\\>\\W.*"); - Matcher m3 = p3.matcher (workingQuery); - - - /* - * Das darf nicht sein: - * Replacment: <http://dbpedia.org/ontology/Caves> rdf:type ?x .?y <http://dbpedia.org/property/entrances> - */ - while(m3.find()){ - resourceTemp="RESOURCE"+m3.group(1); - String replacment="<"+m3.group(1)+">"; - //TODO: Make it nice!!! - //if he doesnt find the ontolokg party, kind of skip - if(!replacment.contains("property")&&!replacment.contains("resource")){ - System.out.println("Replacment: "+replacment); - workingQuery=workingQuery.replace(replacment, "SKIP"); - System.out.println("New temp: "+workingQuery); - } - - } - - } - - System.out.println("TMP before replace :"+workingQuery); - workingQuery=workingQuery.replace("http://dbpedia.org/resource/","").replace("http://dbpedia.org/property/", "").replace("http://dbpedia.org/ontology/", ""); - - System.out.println("TMP After replace :"+workingQuery); - //split on . for sign for end of conditions - String[] firstArray=workingQuery.split("\\."); - for(String i : firstArray){ - - String[] secondArray=i.split(" "); - - //always in three counts - int counter=0; - for(String j : secondArray){ - //System.out.println("j "+j); - counter=counter+1; - //only one condition - if(secondArray.length%3==0){ - if(counter==1&&j.contains("<")&&!j.contains("SKIP")&&!j.contains("rdf:type")){ - //position of Property is right - lstquery.add("RIGHT"+j.replace("<", "").replace(">","")); - } - else if(counter==3&&j.contains("<")&&!j.contains("SKIP")&&!j.contains("rdf:type")){ - //position of Property is left - //here was RIGHT before.... - lstquery.add("LEFT"+j.replace("<", "").replace(">","")); - } - else if(counter==2&&!j.contains("SKIP")&&!j.contains("rdf:type")){ - lstquery.add("PROPERTY"+j.replace("<", "").replace(">","")); - } - - else if(j.contains("?")) lstquery.add("VARIABLE"); - else if(j.contains("SKIP"))lstquery.add(resourceTemp); - else if(j.contains("rdf:type"))lstquery.add("IsA"); - } - if(counter==3)counter=0; - - - } - } - //} - } - - //System.out.println("lstquery "+lstquery); - return lstquery; - } - - - - //TODO: Plural Singual abfragen über die Wordnetdatei... - - /** - * Method gets a String and takes the information from the templator to creat a Sparql query. - * @param question question in natural language - * @return ArrayList of Sparql queries. - * @throws SQLException - */ - private queryInformation getQuery(queryInformation queryObject) throws SQLException { - ArrayList<ArrayList<String>> lstquery = new ArrayList<ArrayList<String>>(); - String question=queryObject.getQuery(); - Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); - for (BasicQueryTemplate temp : querytemps) { - - ArrayList<String> lstquerynew = new ArrayList<String>(); - ArrayList<String> lstquerupsidedown = new ArrayList<String>(); - String query; - String selTerms =""; - String yago_query=""; - String yago_query_upside_down=""; - - boolean addQuery=true; - //sometimes there isnt an Selectterm, so dont use this query - try{ - for(SPARQL_Term terms :temp.getSelTerms()) selTerms=selTerms+(terms.toString())+" "; - } - catch (Exception e){ - selTerms=""; - addQuery=false; - } - - - String conditions = ""; - try{ - for(Path condition: temp.getConditions()) conditions=conditions+(condition.toString())+"."; - } - catch (Exception e){ - conditions=""; - addQuery=false; - } - - String filters=""; - try{ - for(SPARQL_Filter tmp : temp.getFilters()) filters=filters+tmp+" "; - } - catch(Exception e){ - filters=""; - addQuery=false; - } - String having=""; - try{ - for(SPARQL_Having tmp : temp.getHavings()) having=having+tmp+" "; - } - catch(Exception e){ - having=""; - addQuery=false; - } - - //if there is no order by, replace with "" - String orderdBy="ORDER BY "; - try{ - for(SPARQL_Term tmp : temp.getOrderBy()) { - System.out.println("Yeah"); - orderdBy=orderdBy+tmp+" "; - } - if((temp.getOrderBy()).size()==0)orderdBy=""; - } - catch(Exception e){ - orderdBy=""; - addQuery=false; - } - - //if limit == 0, then set limit as "" - String limit=""; - try{ - limit="LIMIT "+temp.getLimit(); - - if(temp.getLimit()==0)limit=""; - } - catch(Exception e){ - limit=""; - addQuery=false; - } - - if(addQuery==true){ - query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions.replace("--","") + filters+"}"+orderdBy+" "+having +" "+limit; - - String conditions_new = ""; - for(Path condition: temp.getConditions()){ - //make conditions up-side-down - String[] tmp_upside = condition.toString().split(" -- "); - String tmp_conditions_new=""; - for(String con : tmp_upside) tmp_conditions_new = con +" "+tmp_conditions_new; - //remove all dots befor end - tmp_conditions_new=tmp_conditions_new.replace(".", ""); - //at the end ein . - tmp_conditions_new = tmp_conditions_new + "."; - - //conditions_new=tmp_conditions_new; - - conditions_new=conditions_new + tmp_conditions_new; - } - - - - System.out.println("Conditions: " + conditions); - System.out.println("Conditions_new: " + conditions_new); - - - String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+"}" + orderdBy +" "+having+" "+limit; - String[] slots= null; - - - /* - * replace isA with rdf:type - */ - query_upside_down=query_upside_down.replace("isA", "rdf:type"); - query=query.replace("isA", "rdf:type"); - - int slotcounter=1; - - /* - * the one after the isA, has to be an ontology Class or an Yago Class!!! - * so first find out, which one is behind the isA - * best with regex or so.... take the condition, regex the thing between isA and . for End of Condition - * kind of regex=[*a IsA (\\?*a.)*a] - * Then put the isA thing in the variable isaComponent and mark it as later on as Resource! - */ - String isaComponent=""; - - Pattern p = Pattern.compile (".*isA (\\?.*)\\..*"); - - /* - * use conditions, because only in this case, there is the right resource right of the isA - */ - Matcher m = p.matcher (conditions.replace("--", "").replace(" ", " ")); - String result=""; - - System.out.println("################"); - while (m.find()) { - if(m.group(1)!=null) - //System.out.println(m.group(1)); - isaComponent=m.group(1); - } - System.out.println("isaComponent "+isaComponent); - - /* - * just in case, there is still a . in it... - * funzt - * - */ - if(isaComponent.contains(".")){ - String[] tmp_array=isaComponent.split("\\."); - for(String i: tmp_array) System.out.println("tmp_array "+i); - isaComponent=tmp_array[0]; - - System.out.println("new isaComponent "+isaComponent); - } - - if(isaComponent=="") isaComponent="No isa Component"; - System.out.println("isaComponent "+isaComponent); - System.out.println("################"); - - for(Slot slot : temp.getSlots()){ - - System.out.println("Slot: "+slot); - //see below - slotcounter=slotcounter+1; - - //resource will be detectet. - //If its not a resource, it has to be a property! - String resource=""; - String property=""; - String slotstring=""; - if(slot.toString().contains("RESOURCE")){ - resource=slot.toString().replace("{","").replace("}","").replace(" RESOURCE ", ""); - System.out.println("Found Resource in getQuery: "+ resource); - } - else{ - property=slot.toString().replace("UNSPEC","").replace("RESOURCE","").replace("{","").replace("}","").replace(" PROPERTY ",""); - System.out.println("Found Property in getQuery: "+ property); - } - - - //query=query.replace(replace, "<"+hm_result+">"); - - /*System.out.println("Recource "+resource); - System.out.println("Property "+property);*/ - - boolean skip=false; - - /* - * Der geht hier garnicht in die Schleife. - */ - if(resource.contains(isaComponent.replace("?", "")) || property.contains(isaComponent.replace("?", ""))){ - skip=true; - - /* - * now replace the variable with the value of OntologyClass - */ - String replace=""; - String tmp=""; - - if(resource.contains(isaComponent.replace("?", ""))) tmp=resource; - if(property.contains(isaComponent.replace("?", ""))) tmp=property; - - String[] array = tmp.split(":"); - if(array[0].length()<2)replace = "?"+array[0]+" "; - else replace="?"+array[0]; - try{ - array[1]=array[1].replace(" ", ""); - } - catch(Exception e){ - - } - - /* - * Here lookup in ontology and in Yago, if ontology doesnt exist, use Yago, if not, use Ontology - * if both exist, add yago_query... [truncated message content] |
From: <seb...@us...> - 2012-05-17 09:36:02
|
Revision: 3717 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3717&view=rev Author: sebastianwtr Date: 2012-05-17 09:35:54 +0000 (Thu, 17 May 2012) Log Message: ----------- [tbsl exploration] updated the Query Manipulation part 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/HeuristicSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.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/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.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/modules/IterationModule.java 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/WordnetModule.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-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -217,11 +217,18 @@ } if(slot.toString().contains("PROPERTY")){ + System.out.println("Slot.toString(): "+slot.toString()); String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); + System.out.println(tmp); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); - list_of_hypothesis.add(tmp_hypothesis); + if(tmp_array.length>1){ + System.out.println("tmp_array[0]:"+tmp_array[0]); + System.out.println("tmp_array[1]:"+tmp_array[1]); + + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); + list_of_hypothesis.add(tmp_hypothesis); + } } if(slot.toString().contains("RESOURCE")){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/HeuristicSort.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -11,19 +11,17 @@ /* * TODO: test if the sorted queries are given back properly */ - public static ArrayList<QueryPair> doSort(ArrayList<QueryPair> qp, String question){ + public static ArrayList<QueryPair> doHeuristicSort(ArrayList<QueryPair> qp, String question){ 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()&&question.contains("of")){ + if(qp.get(i).getRank()==qp.get(i+1).getRank()&&(question.toLowerCase().contains("of")||question.toLowerCase().contains("which")||question.toLowerCase().contains("who"))){ //change=true; QueryPair one = qp.get(i); QueryPair two = qp.get(i+1); String string = one.getQuery(); - //Pattern p = Pattern.compile (".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*"); - //Matcher m = p.matcher (string); if(string.matches(".*\\<http://dbpedia.org/resource/.*\\> \\<http://dbpedia.org/.*\\> \\?.*")){ qp.set(i, one); qp.set(i+1, two); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -42,12 +42,19 @@ givenHypothesenList=t.getHypothesen(); } + int anzahl_globalrank=0; for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; + String Resource=null; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ + if(h.getType().toLowerCase().contains("resource")){ + Resource=h.getName(); + } + + condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); /* * Dont create a Query with variables, which dont have a correct uri @@ -59,6 +66,11 @@ //just in case... condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); + /*if(h.getType().toLowerCase().contains("property")){ + global_rank=global_rank+h.getRank(); + anzahl_globalrank+=1; + }*/ + } /* @@ -66,25 +78,21 @@ */ global_rank = global_rank/hypothesenList.size(); - + //global_rank=global_rank/anzahl_globalrank; //System.out.println("New_Condition after replacing "+condition_new); - if(t.getQuestion().toLowerCase().contains("who")){ - /* - * PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> -SELECT DISTINCT ?uri ?string -WHERE { - res:Brooklyn_Bridge dbp:designer ?uri . - OPTIONAL { ?uri rdfs:label ?string. FILTER (lang(?string) = 'en') } - */ + if(t.getQuestion().toLowerCase().contains("who")&&!t.getSelectTerm().toLowerCase().contains("count")){ + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+t.getQueryType()+" "+t.getSelectTerm()+"?string WHERE {"+ condition_new+" OPTIONAL { "+ t.getSelectTerm()+" rdfs:label ?string. FILTER (lang(?string) = 'en') }"+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); + qp.setResource(Resource); if(addQuery)queryList.add(qp); } else{ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); + qp.setResource(Resource); if(addQuery)queryList.add(qp); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -2,6 +2,7 @@ public class QueryPair { private String Query; + private String Resource; private double rank; public String getQuery() { return Query; @@ -25,6 +26,12 @@ this.setQuery(query_new); this.setRank(rank_new); } + public String getResource() { + return Resource; + } + public void setResource(String resource) { + Resource = resource; + } } 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-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -20,7 +20,7 @@ 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; + private static int timeToTimeoutOnServer=3000; public static HashMap<String, String> generatesQueryForOutsideClasses(String query){ String working_query= ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; Modified: 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 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -12,6 +12,7 @@ import java.util.ArrayList; 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; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; @@ -38,7 +39,7 @@ * false, goes through all */ boolean wait = false; - Setting.setThresholdSelect(0.5); + //Setting.setThresholdSelect(0.5); if(Setting.isWaitModus())wait=true; @@ -105,7 +106,7 @@ //sort QueryPairs qp=LinearSort.doSort(qp); - qp=HeuristicSort.doSort(qp, Question); + qp=HeuristicSort.doHeuristicSort(qp, Question); //if(Setting.isDebugModus())printQueries(qp, "NORMAL", Question); //printQueries(qp, "NORMAL", Question); Setting.setAnzahlAbgeschickterQueries(10); @@ -162,23 +163,15 @@ } if(wait)DebugMode.waitForButton(); - - /* - * If there is no answer, start IterationMode with Levensthein - */ - if(answers.isEmpty()&&Setting.getModuleStep()>=2){ + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ - answers.clear(); - //Setting.setLevenstheinMin(0.65); - //Setting.setAnzahlAbgeschickterQueries(10); - answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); - if(wait)DebugMode.waitForButton(); + answers.clear(); + //Setting.setLevenstheinMin(0.65); + //Setting.setAnzahlAbgeschickterQueries(10); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); + if(wait)DebugMode.waitForButton(); } - /* - * still no answer, start IterationMode with Wordnet - */ - if(answers.isEmpty()&&Setting.getModuleStep()>=3){ answers.clear(); @@ -186,7 +179,8 @@ answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET","neu")); if(wait)DebugMode.waitForButton(); } - + + if(answers.isEmpty()&&Setting.getModuleStep()>=4){ answers.clear(); @@ -197,23 +191,18 @@ } if(answers.isEmpty()&&Setting.getModuleStep()>=5){ - System.out.println("Stufe 5"); - DebugMode.waitForButton(); + System.out.println("NO Answer from Server =>Start Query Manipulation"); answers.clear(); - //Setting.setAnzahlAbgeschickterQueries(10); - //Setting.setThresholdSelect(0.2); - //ArrayList<String> answers.addAll(stufe5(myindex,wordnet,lemmatiser,wait,template_list)); if(wait)DebugMode.waitForButton(); } - /*if(answers.isEmpty()){ - System.out.println(""); - //answers.add("No answers were found with the three Modules"); - }*/ + + + /* * return answers! */ @@ -240,23 +229,23 @@ boolean special=false; int anzahl; boolean go_on; - if(type.contains("SPECIAL")){ + /*if(type.contains("SPECIAL")){ type ="LEVENSTHEIN"; special=true; - } + }*/ System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - if(test.contains("alt")){ + /*if(test.contains("alt")){ ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); - } + }*/ - if(test.contains("neu")){ - System.err.println("IN NEU!!!!!"); + //if(test.contains("neu")){ + // System.err.println("IN NEU!!!!!"); ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); @@ -279,7 +268,7 @@ } - } + //} catch (Exception e){ } @@ -311,10 +300,7 @@ //sort QueryPairs qp=LinearSort.doSort(qp); //printQueries(qp, type, Question); - /* - * Only for test! - */ - qp=HeuristicSort.doSort(qp, Question); + qp=HeuristicSort.doHeuristicSort(qp, Question); System.out.println("Following Querries were created:"); for(QueryPair z : qp){ @@ -336,7 +322,7 @@ //else go_on=false; //go_on=true; go_on=false; - if(special) go_on=true; + System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); if(qp.size()>(id+1)){ //&&anzahl<2 @@ -344,6 +330,11 @@ go_on=true; } } + /* + * in which queries with an answer, dont accept a second Query, is there is already an answer. + */ + if(Question.toLowerCase().contains("which")) go_on=false; + if(Question.toLowerCase().contains("who")) go_on=false; boolean contains_uri=false; @@ -557,10 +548,112 @@ * iterate over Templates to create new one's but only if you have [isa][resource] and condition.size=2; */ for(Template t: template_list){ + //t.printAll(); + if(t.getCondition().size()==1){ + System.out.println("Nur eine Condition"); + ArrayList<String> condition=t.getCondition().get(0); + boolean go_on=false; + if(condition.get(1).toLowerCase().equals("isa")) go_on=true; + System.out.println("go_on:"+go_on); + if(go_on){ + + String resource_variable=condition.get(0); + String class_variable=condition.get(2); + Hypothesis resource_h = null; + Hypothesis class_h = null; + boolean go_on_resource=false; + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource_variable)){ + if(h.getType().toLowerCase().contains("resource")) { + go_on_resource=true; + resource_h=h; + } + } + if(h.getVariable().equals(class_variable)){ + class_h=h; + } + } + + } + System.out.println("go_on_resource:"+go_on_resource); + if(go_on_resource){ + + /* + * manipulate Class variable to make a property from it + */ + class_h.setType("PROPERTY"); + class_h.setUri(class_h.getUri().toLowerCase()); + class_h.setVariable("?y"); + resource_h.setVariable("?x"); + ArrayList<ArrayList<Hypothesis>> new_hypothesen_list = new ArrayList<ArrayList<Hypothesis>>(); + ArrayList<Hypothesis> small_h_list = new ArrayList<Hypothesis>(); + small_h_list.add(resource_h); + small_h_list.add(class_h); + new_hypothesen_list.add(small_h_list); + + ArrayList<String> condition_new = new ArrayList<String>(); + condition_new.add("?x"); + condition_new.add("?y"); + condition_new.add("?z"); + + ArrayList<ArrayList<String>> new_c_list = new ArrayList<ArrayList<String>>(); + new_c_list.add(condition_new); + + Template new_Template = new Template(new_c_list, t.getQueryType(), "","" , "?z", "", "", t.getQuestion()); + + new_Template.setHypothesen(new_hypothesen_list); + Elements elm = new Elements(new_Template.getCondition(),new_Template.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + new_Template.setElm(elm); + new_template_list.add(new_Template); + } + + Template template_reverse_conditions = new Template(new_Template.getCondition(),new_Template.getQueryType(), new_Template.getHaving(), new_Template.getFilter(), new_Template.getSelectTerm(), new_Template.getOrderBy(), new_Template.getLimit(), new_Template.getQuestion()); + template_reverse_conditions.setHypothesen(new_hypothesen_list); + + ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); + ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); + + + for (ArrayList<String> x : condition_template_reverse_conditions){ + ArrayList<String> new_list = new ArrayList<String>(); + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } + + + template_reverse_conditions.setCondition(condition_reverse_new); + + Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); + if(elm_reverse.isElementEmty()==false){ + //elm.printAll(); + template_reverse_conditions.setElm(elm_reverse); + new_template_list.add(template_reverse_conditions); + } + + + + } + + + + + } + } + + + + /* * only if condition.size==2 */ if(t.getCondition().size()==2){ + System.out.println("Yeah, found two Conditions!"); + /* * now look if one have the [isa][resource] or [resource][isa] case */ @@ -569,24 +662,55 @@ condition1=t.getCondition().get(0); condition2=t.getCondition().get(1); + System.out.println("condition1:"+condition1); + System.out.println("condition2:"+condition2); boolean go_on=false; if(condition1.get(1).toLowerCase().contains("isa")&&!condition2.get(1).toLowerCase().contains("isa")){ - if(condition2.get(0).contains("resource/")||condition2.get(2).contains("resource/")){ + String resource1_variable=condition2.get(0); + String resource2_variable=condition2.get(2); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource2_variable)||h.getVariable().equals(resource1_variable)){ + if(h.getType().toLowerCase().contains("resource")) go_on=true; + } + } + + } + + /*if(condition2.get(0).contains("resource/")||condition2.get(2).contains("resource/")){ go_on=true; } - else go_on=false; + else go_on=false;*/ } - else if(!condition1.get(1).toLowerCase().contains("isa")&&condition2.get(1).toLowerCase().contains("isa")){ - if(condition1.get(0).contains("resource/")||condition1.get(2).contains("resource/")){ + else if(condition2.get(1).toLowerCase().contains("isa")){ + + String resource1_variable=condition1.get(0); + String resource2_variable=condition1.get(2); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + for(Hypothesis h : h_l){ + if(h.getVariable().equals(resource2_variable)||h.getVariable().equals(resource1_variable)){ + if(h.getType().toLowerCase().contains("resource")) go_on=true; + } + } + + } + + + /* + * in the conditions there is for sure no resource!!! + */ + /*if(condition1.get(0).contains("resource/")||condition1.get(2).contains("resource/")){ go_on=true; } - else go_on=false; + else go_on=false;*/ } else go_on=false; + + System.out.println("Go_on:"+go_on); if(go_on==true){ /* @@ -607,6 +731,13 @@ } /* + * New HypothesenList + */ + System.out.println("New Hypothesen List"); + for(ArrayList<Hypothesis> h_blub : new_hypothesen_list){ + for(Hypothesis blub:h_blub) blub.printAll(); + } + /* * create new ArrayList for Conditions, only with the */ ArrayList<String> new_condition= new ArrayList<String>(); @@ -629,6 +760,8 @@ * Elements can still be the same */ new_Template.setElm(t.getElm()); + new_template_list.add(new_Template); + //new_Template.printAll(); } @@ -640,6 +773,7 @@ * if there are new templates, start rescursive call; */ if(new_template_list.size()>0){ + System.out.println("Generated new Templates"); try { return singleSteps(myindex, wordnet, lemmatiser, wait,new_template_list); } catch (IOException e) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -10,6 +10,10 @@ private static double thresholdSelect; private static double thresholdAsk; private static int moduleStep; + private static double EsaMin; + private static boolean loadedProperties; + private static int version; + private static boolean saveAnsweredQueries; @@ -62,6 +66,30 @@ public static void setModuleStep(int moduleStep) { Setting.moduleStep = moduleStep; } + public static double getEsaMin() { + return EsaMin; + } + public static void setEsaMin(double esaMin) { + EsaMin = esaMin; + } + public static boolean isLoadedProperties() { + return loadedProperties; + } + public static void setLoadedProperties(boolean loadedProperties) { + Setting.loadedProperties = loadedProperties; + } + public static int getVersion() { + return version; + } + public static void setVersion(int version) { + Setting.version = version; + } + public static boolean isSaveAnsweredQueries() { + return saveAnsweredQueries; + } + public static void setSaveAnsweredQueries(boolean saveAnsweredQueries) { + Setting.saveAnsweredQueries = saveAnsweredQueries; + } } 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-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -63,13 +63,18 @@ Setting.setLevenstheinMin(0.95); Setting.setAnzahlAbgeschickterQueries(10); Setting.setThresholdAsk(0.9); - Setting.setThresholdSelect(0.6); + Setting.setThresholdSelect(0.5); + Setting.setLoadedProperties(false); + Setting.setSaveAnsweredQueries(false); + //default + //Setting.setVersion(1); /* * 1= only "Normal" * 2= "Normal" + Levensthein * 3= Normal+Levensthein+Wordnet */ - Setting.setModuleStep(4); + Setting.setModuleStep(5); + Setting.setEsaMin(0.4); @@ -133,71 +138,106 @@ if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - for(int i = 1; i<2;i++){ - double min = 0.95; - min+=(i*0.05); - - //Setting.setLevenstheinMin(min); - Setting.setLevenstheinMin(0.95); - //Setting.setModuleStep(i); - + //for(int i = 1; i<2;i++){ + //double min = 0.95; + //min+=(i*0.05); - /*System.out.println("Please enter Path of xml File:"); - line=in.readLine();*/ - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-withoutNotparsed.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-questions.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-onlyWithWorking.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + /*if(i==1){ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + } + if(i==2){ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; + }*/ + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; - //create Structs - ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - - list_of_structs=generateStruct(line,true); - //Start Time measuring - long startTime = System.currentTimeMillis(); - - int anzahl=0; - int anzahl_query_with_answers=0; - int yago_querys=0; - for(queryInformation qi : list_of_structs){ - anzahl=anzahl+1; - System.out.println(""); - if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); - String question = qi.getQuery(); - ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); - qi.setResult(answers); + for(int j=1;j<2;j++){ + + Setting.setVersion(1); + + for(int z=1;z<7;z++){ + //Setting.setLevenstheinMin(min); + Setting.setLevenstheinMin(0.95); + //Setting.setThresholdSelect(0.4); + Setting.setModuleStep(2); + Setting.setThresholdSelect(0.5); + Setting.setEsaMin(0.0+(z/10.0)); + Setting.setLoadedProperties(false); + /*if(i==2)Setting.setLoadedProperties(true); + else Setting.setLoadedProperties(false); + */ + + + + + //create Structs + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + + list_of_structs=generateStruct(line,true); + //Start Time measuring + long startTime = System.currentTimeMillis(); + + int anzahl=0; + int anzahl_query_with_answers=0; + int yago_querys=0; + for(queryInformation qi : list_of_structs){ + anzahl=anzahl+1; + System.out.println(""); + if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); + String question = qi.getQuery(); + ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); + qi.setResult(answers); + } + + + long stopTime = System.currentTimeMillis(); + System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); + + String filename=""; + filename=createXML(list_of_structs,((stopTime-startTime)/1000)); + String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/"+filename; + String execute=""; + if(filename_for_evaluation.contains("train")){ + execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation-C.py "+filename_for_evaluation+" 0"; + } + else{ + execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation-C.py "+filename_for_evaluation+" 1"; + + } + System.out.println(filename_for_evaluation); + /* + * First only for training + */ + + System.out.println("execute: "+execute); + + + try + { + Runtime r = Runtime.getRuntime(); + Process p = r.exec(execute); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + p.waitFor(); + while (br.ready()) + System.out.println(br.readLine()); + + } + catch (Exception e) + { + String cause = e.getMessage(); + if (cause.equals("python: not found")) + System.out.println("No python interpreter found."); + } + + + } + + } + - long stopTime = System.currentTimeMillis(); - System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); - - String systemid=""; - systemid=createXML(list_of_structs); - String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; - String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; - System.out.println(filename_for_evaluation); - /* - * First only for training - */ - - System.out.println("execute: "+execute); - Runtime r = Runtime.getRuntime(); - Process p = r.exec(execute); - - /* String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; - execute ="firefox "+ open_file; - p = r.exec(execute);*/ - } + // } /*schleife=false; System.out.println("Bye!"); System.exit(0);*/ @@ -288,13 +328,14 @@ } - private static String createXML(ArrayList<queryInformation> list){ + private static String createXML(ArrayList<queryInformation> list, double average_time){ java.util.Date now = new java.util.Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); String systemid = sdf.format(now); System.out.println("In createXML"); + String filename=null; String xmlDocument=""; int counter=0; @@ -325,6 +366,8 @@ if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else if(i.matches("[0-9][.][0-9]"))input="<number>"+i+"</number>\n"; + //<number>1.8</number> else if(i.matches("[0-9]*-[0-9][0-9]-[0-9]*"))input="<date>"+i+"</date>\n"; else if(i.length()>=1 && !i.equals(" "))input="<string>"+i+"</string>\n"; tmp+="<answer>"+input+"</answer>\n"; @@ -337,7 +380,8 @@ xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+"NLD"+Setting.getLevenstheinMin()+"Stufe"+Setting.getModuleStep()+"Type"+xmltype+"Anzahl"+anzahl+".xml"); + filename="result"+systemid.replace(" ", "_")+"NLD"+Setting.getLevenstheinMin()+"Stufe"+Setting.getModuleStep()+"Type"+xmltype+"Anzahl"+anzahl+"Time"+average_time+"Threshold"+Setting.getThresholdSelect()+"ESA"+Setting.getEsaMin()+"LoadedProperty"+Setting.isLoadedProperties()+"Version"+Setting.getVersion()+".xml"; + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/"+filename); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); @@ -350,7 +394,7 @@ } System.out.println("In createXML - Done"); - return systemid; + return filename; } private static ArrayList<queryInformation> generateStruct(String filename, boolean hint) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -30,308 +30,8 @@ * */ public class IterationModule { - - /** - * returns ArrayList<ArrayList<Hypothesis>> which than can be added using - * @param elm - * @param hypothesen - * @param condition - * @return ArrayList<ArrayList<Hypothesis>> - * @throws SQLException - */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ - - - - boolean gotResource=true; - ArrayList<ElementList> resources = new ArrayList<ElementList>(); - try{ - resources = elm.getElements(); - } - catch (Exception e){ - gotResource=false; - if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt get any Resource"); - } - - //System.out.println("Anzahl der Resource Listen: "+resources.size()); - - ArrayList<ArrayList<Hypothesis>>finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); - - - for(ArrayList<Hypothesis> hl :givenHypothesenList){ - /* - * foundedResourcesClasses - */ - ArrayList<Hypothesis> RL = new ArrayList<Hypothesis>(); - - /* - * foundedProperty - */ - ArrayList<String> PL = new ArrayList<String>(); - - /* - * hypothesenListBeforSorting - */ - ArrayList<Hypothesis>HL = new ArrayList<Hypothesis>(); - - - /* - * AL abhängig von jeder einzelnen Resource R aus RL - */ - ArrayList<ArrayList<ArrayList<Hypothesis>>> ALR = new ArrayList<ArrayList<ArrayList<Hypothesis>>>(); - - - /* - * First look for resources and generate List with properties - */ - for(Hypothesis h : hl){ - - //System.out.println("In Hypothesis Loop"); - if(h.getType().contains("RESOURCE")){ - /* - * Get Variable from Resource - */ - String variable = h.getVariable(); - String name = h.getName(); - RL.add(h); - if(Setting.isDebugModus())DebugMode.debugPrint("Found Resource "+h.getName() +" "+h.getUri()); - - - /* - * Look in Condition for the Set, in which the variable appears - */ - ArrayList<String> propertyVariableList = new ArrayList<String>(); - for(ArrayList<String> cl : givenConditionList){ - for(String s : cl){ - if(s.contains(variable)){ - if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+name); - else propertyVariableList.add(cl.get(1)+"LEFT::"+name); - } - } - } - - /* - * Now get for each found Property the Name - */ - ArrayList<String> propertyNameList = new ArrayList<String>(); - for(String s : propertyVariableList){ - for(Hypothesis h_t : hl){ - String variable_t = s; - variable_t=variable_t.replace("RIGHT", ""); - variable_t=variable_t.replace("LEFT", ""); - String[] variable_t1=variable_t.split("::"); - if(h_t.getVariable().contains(variable_t1[0])){ - propertyNameList.add(h_t.getName()+"::"+s); - } - - } - } - /* - * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc - */ - - if(gotResource){ - for(String s : propertyNameList){ - String[] array = s.split("::"); - - - /* - * array[0] contains name of Property - * array[1] contains LEFT/RIGHT and Variable of Property - * array[2] contains Name of Resource - */ - - String side="LEFT"; - if(array[1].contains("RIGHT")) side="RIGHT"; - - for(ElementList el : resources){ - if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ - String propertyVariable = array[1]; - propertyVariable=propertyVariable.replace("LEFT", ""); - propertyVariable=propertyVariable.replace("RIGHT", ""); - ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - try { - /* - * Here start levenstehin, wordnet etc etc - */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,array[0],el.getHm()); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); - if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JWNLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); - - } - } - - } - } - - - } - - if(h.getType().contains("ISA")){ - /* - * TODO:Add special case, if we have only one condition but with an isA in it. - */ - RL.add(h); - if(Setting.isDebugModus())DebugMode.debugPrint("Found Class "+h.getName() +" "+h.getUri()); - - for(ElementList el:resources){ - /* - * Find the resource with the same uri as in h an then start Levensthein/Wordnet etc - */ - if(el.getURI().contains(h.getUri())){ - /* - * Iterate over condition and find the coressesponding variable of the Class, wich is used for the new Hypothesis - */ - ArrayList<String> propertyVariableList= new ArrayList<String>(); - for(ArrayList<String> cl : givenConditionList){ - /* - * Dont look for line, where e.g. ?x isA ?y - */ - //get(1) is the middle Term and if there is an isa, than its there - if(!cl.get(1).contains("ISA")){ - for(String s : cl){ - if(s.contains(h.getVariable())){ - propertyVariableList.add(s); - } - } - } - - } - for(String propertyVariable : propertyVariableList){ - for(ArrayList<Hypothesis> hl_small :givenHypothesenList){ - for(Hypothesis h_small : hl_small){ - if(h_small.getVariable().contains(propertyVariable)){ - try { - ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); - /* - * Here start levenstehin, wordnet etc etc - */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(propertyVariable,h_small.getName(),el.getHm()); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); - if(!PL.contains(propertyVariable)) PL.add(propertyVariable); - for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - } - //for(Hypothesis h_p : finalHypothesenList) h_p.printAll(); - - - } - } - - - - } - - - } - - - /* - * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case - */ - - /*for(Hypothesis h : RL){ - h.printAll(); - } - - for(String s : PL){ - System.out.println("Variable P: "+s); - }*/ - - /* - * Here add new function! - */ - for(Hypothesis R : RL){ - /* - * AL, abhängig von jeder einzelnen P aus PL und R aus RL - */ - ArrayList<ArrayList<Hypothesis>> AL = new ArrayList<ArrayList<Hypothesis>>(); - - - for(String P : PL){ - if(P.contains(R.getVariable())){ - for(Hypothesis H : HL){ - if(P.contains(H.getVariable())){ - ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); - t_h_l.add(H); - t_h_l.add(R); - AL.add(t_h_l); - } - } - } - } - - ALR.add(AL); - } - - if(ALR.size()==1){ - System.out.println("ONLY One Element in ALR"); - finalHypothesenList=ALR.get(0); - System.out.println("One Element in ALR added to finalHypothesenList"); - } - if(ALR.size()==2){ - System.out.println("Two Elements in ALR"); - for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ - for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ - ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); - for(Hypothesis h_t : hl_t) al_t.add(h_t); - for(Hypothesis h_t : hl1_t) al_t.add(h_t); - finalHypothesenList.add(al_t); - } - } - System.out.println("Two Element in ALR added to finalHypothesenList"); - - } - - if(ALR.size()==2){ - System.out.println("Three Elements in ALR"); - for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ - for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ - for(ArrayList<Hypothesis> hl2_t : ALR.get(2)){ - ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); - for(Hypothesis h_t : hl_t) al_t.add(h_t); - for(Hypothesis h_t : hl1_t) al_t.add(h_t); - for(Hypothesis h_t : hl2_t) al_t.add(h_t); - finalHypothesenList.add(al_t); - } - - } - } - System.out.println("Three Element in ALR added to finalHypothesenList"); - - } - - - } - - - - System.out.println("######################DONE######################"); - - return finalHypothesenList; - - } - /* * Use Here only one Hypothesen Set at each time, so for each "AusgangshypothesenSet" start this function */ @@ -458,7 +158,7 @@ /* * Here start levenstehin, wordnet etc etc */ - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm()); + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(condition.get(1),property_name,el.getHm(),h.getName()); if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(condition.get(1),property_name,el.getHm(),myindex,wordnet,lemmatiser); if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(condition.get(1),property_name,el.getHm()); for(Hypothesis h_temp : resultHypothesenList) { @@ -623,13 +323,13 @@ resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable_local, property_name, el); + property_variable_local, property_name, el.getHm(),resource_h.getName()); for(Hypothesis h_temp : resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(class_h); temp_al.add(h_temp); temp_al.add(resource_h); - System.out.println("Hypothesen:"); + //System.out.println("Hypothesen:"); //class_h.printAll(); //h_temp.printAll(); finalHypothesenList.add(temp_al); @@ -687,7 +387,7 @@ ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable, property_name, el); + property_variable, property_name, el.getHm(),class_h.getName()); for(Hypothesis h_temp : resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(class_h); @@ -726,28 +426,19 @@ String second_property_name=""; String property_variable=""; String second_property_variable=""; + String property_side_new="LEFT"; if(condition1_exists_resource){ - //property_variable= condition1.get(1); - //second_property_variable=condition2.get(1); property_variable= condition2.get(1); second_property_variable=condition1.get(1); + property_side_new="RIGHT"; } if(condition2_exists_resource){ - //property_variable= condition2.get(1); - //second_property_variable=condition1.get(1); property_variable= condition1.get(1); second_property_variable=condition2.get(1); + property_side_new="LEFT"; } - //System.out.println("property_variable: " + property_variable); - //System.out.println("scond_property_variable: " + second_property_variable); - /*for(ArrayList<String> al : givenConditionList){ - for(String s : al) System.out.println(s); - } - for(Hypothesis h : givenHypothesenList){ - h.printAll(); - }*/ for(Hypothesis h_t : givenHypothesenList){ if(h_t.getVariable().contains(property_variable)){ @@ -759,8 +450,7 @@ } } - // System.out.println("property_name: " + property_name); - // System.out.println("second_property_name: " + second_property_name); + if(Setting.isWaitModus())DebugMode.waitForButton(); @@ -775,10 +465,11 @@ ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, - property_variable, property_name, el); + property_variable, property_name, el.getHm(),resource_h.getName()); + for(Hypothesis h_temp : resultHypothesenList) { String Query=""; - if(property_Side.contains("LEFT")){ + if(property_side_new.contains("LEFT")){ Query= "SELECT DISTINCT ?s ?x WHERE {<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } @@ -795,16 +486,9 @@ ArrayList<Hypothesis> second_resultHypothesenList=new ArrayList<Hypothesis>(); - - - if(type.contains("LEVENSTHEIN"))second_resultHypothesenList= LevenstheinModule.doLevensthein(second_property_variable,second_property_name,hm_newClasses); - if(type.contains("RELATE"))second_resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(second_property_variable,second_property_name,hm_newClasses); - - if(type.contains("WORDNET"))second_resultHypothesenList= WordnetModule.doWordnet(second_property_variable,second_property_name,hm_newClasses,myindex,wordnet,lemmatiser); - //System.out.println("SIze of second_resultHypothesenList: "+second_resultHypothesenList.size()); second_resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, second_property_variable, - second_property_name,el); + second_property_name,hm_newClasses,resource_h.getName()); for(Hypothesis second_h_temp : second_resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); @@ -924,7 +608,7 @@ property_name1=proptery1_hypothesis.getName(); resultHypothesenListPropertyOne = creatNewPropertyList(type, myindex, wordnet, lemmatiser, property_variable1, - property_name1, el); + property_name1, el.getHm(),class_hypothesis.getName()); } } @@ -941,7 +625,7 @@ property_name1=property2_hypothesis.getName(); resultHypothesenListPropertyTwo = creatNewPropertyList(type, myindex, wordnet, lemmatiser, property_variable2, - property_name2, el); + property_name2, el.getHm(),class_hypothesis.getName()); } } @@ -975,15 +659,15 @@ SQLiteIndex myindex, WordNet wordnet, StanfordLemmatizer lemmatiser, String property_variable, String property_name, - ElementList el) throws SQLException, JWNLException { + HashMap<String, String> hm, String resourceName) throws SQLException, JWNLException { /* * Here start levenstehin, wordnet etc etc */ ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,el.getHm()); - if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,el.getHm()); + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(property_variable,property_name,hm,resourceName); + if(type.contains("RELATE"))resultHypothesenList= SemanticRelatenes.doSemanticRelatenes(property_variable,property_name,hm); - if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,el.getHm(),myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(property_variable,property_name,hm,myindex,wordnet,lemmatiser); //System.out.println("After generating new Hypothesen.\n "+resultHypothesenList.size()+" new were generated"); return resultHypothesenList; } 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-05-17 03:45:50 UTC (rev 3716) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-05-17 09:35:54 UTC (rev 3717) @@ -1,94 +1,233 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; public class LevenstheinModule { //private final static double LevenstheinMin=0.65; - public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) + public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties, String resource_name) throws SQLException { ArrayList<Hypothesis> listOfNewHypothesen= new ArrayList<Hypothesis>(); - - //iterate over properties - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.toLowerCase(); - String value = entry.getValue(); - // System.out.println("Key: "+key); - - ArrayList<String> property_array=new ArrayList<String>(); - property_array.add(property_to_compare_with); - if(property_to_compare_with.contains(" ")){ + /* + * First Read in propertyFile, then iterate with keys over the entries. But first look, if there is a property for the property_to_compare with and if so, check if the + * resulting giving property is in keys. if it is so, set a high rank and close levenstheinMode. + * + * File: MostPropertyCombinations + */ + + String dateiname="/home/swalter/workspace/MostPropertyCombinations"; + HashMap<String, String> loaded_properties = new HashMap<String, String>(); + + boolean found_property_in_loaded_property=false; + boolean found_property_in_created_property=false; + if(Setting.isLoadedProperties()){ + System.out.println("in Loaded!!"); + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + String[] tmp_array = thisLine.split("::"); + if(tmp_array.length>1){ + loaded_properties.put(tmp_array[0].replace("\n", ""), tmp_array[1].replace("\n", "")); + } + + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + for (Entry<String, String> entry_loaded : loaded_properties.entrySet()) { + + String key_loaded= entry_loaded.getKey(); + String value_loaded= entry_loaded.getValue(); + if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ + System.out.println("FOUND!!"); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + /*System.out.println("KEY_old:"+key); + System.out.println("value_loaded:"+value_loaded+"DONE"); + System.out.println("Value:"+value); + System.out.println("\n");*/ + if(key.equals(value_loaded)){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + h.printAll(); + found_property_in_loaded_property=true; + } + } + } + + } + } + + /* + * createdPropertyCombinations + */ + + /* + * Second read in File with the propertys, which were created, when a query produced an answer and query had the rank >0.8 + * and the property hast the given "matserresource" + */ + + /* if(found_property_in_loaded_property==false&&Setting.isSaveAnsweredQueries()){ + HashMap<String, String> created_properties = new HashMap<String, String>(); + System.out.println("in Save!!"); + dateiname="/home/swalter/workspace/createdPropertyCombinations"; + System.out.println("Resource to compare: "+resource_name); + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + String[] tmp_array = thisLine.split("::"); + if(tmp_array.length>2){ + + // check, if the given resource is equal to the reosource loaded from the file! + + if(tmp_array[0].toLowerCase().replace("\n", "").equals(resource_name.toLowerCase())){ + created_properties.put(tmp_array[1].replace("\n", ""), tmp_array[2].replace("\n", "")); + } + + } + + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + if(!created_properties.isEmpty()){ + for (Entry<String, String> entry_loaded : created_properties.entrySet()) { + + String key_loaded= entry_loaded.getKey(); + String value_loaded= entry_loaded.getValue(); + if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ + System.out.println("FOUND!!"); + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + System.out.println("KEY_old:"+key); + System.out.println("value_loaded:"+value_loaded+"DONE"); + System.out.println("Value:"+value); + System.out.println("\n"); + if(key.equals(value_loaded)){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + h.printAll(); + found_property_in_created_property=true; + } + } + } + + } + } + + + }*/ + + if(found_property_in_loaded_property==false||found_property_in_created_property==false){ + + //} + + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + key=key.replace("(μ)", ""); + key=key.replace("(cm)", ""); + key=key.toLowerCase(); + String value = entry.getValue(); + // System.out.println("Key: "+key); - String[] array_temp = property_to_compare_with.split(" "); - for(String s : array_temp) property_array.add(s); - } - for(String compare_property :property_array ){ - // System.out.println("compare_property: "+compare_property); - double nld=Levenshtein.nld(compare_property.toLowerCase(), key); - - /* - * At the beginning first realy test with the original Property, to make sure, if there is a match, that only this one is taken. - */ - if(key.toLowerCase().equals(property_to_compare_with.toLowerCase())||key.toLowerCase().equals(property_to_compare_with.replace(" ", "").toLowerCase()) ){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); + ArrayList<String> property_array=new ArrayList<String>(); + property_array.add(property_to_compare_with); + if(property_to_compare_with.contains(" ")){ + + String[] array_temp = property_to_compare_with.split(" "); + for(String s : array_temp) property_array.add(s); } - else if((key.contains(compare_property)||compare_property.contains(key))){ + for(String compare_property :property_array ){ + // System.out.println("compare_property: "+compare_property); + double nld=Levenshtein.nld(compare_property.toLowerCase(), key); - double score=0; - if(compare_property.length()>key.length()){ - score = 0.8+(key.length()/compare_property.length()); - } - else{ - score=0.8+(compare_property.length()/key.length()); - } - - - if(compare_property.length()>4&&key.length()>4) { - //0.95 - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score); - listOfNewHypothesen.add(h); - } - else{ - //0.7 - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", score-0.2); - listOfNewHypothesen.add(h); - } - - - // Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", (key.length()/compare_property.length())); - // listOfNewHypothesen.add(h); - + /* + * At the beginning first realy test with the original Property, to make sure, if there is a match, that only this one is taken. + */ + if(key.toLowerCase().equals(property_to_compare_with.toLowerCase())||key.toLowerCase().equals(property_to_compare_with.replace(" ", "").toLowerCase()) ){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); + listOfNewHypothesen.add(h); + } + //else + else if((key.... [truncated message content] |
From: <seb...@us...> - 2012-06-20 12:49:01
|
Revision: 3762 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3762&view=rev Author: sebastianwtr Date: 2012-06-20 12:48:53 +0000 (Wed, 20 Jun 2012) Log Message: ----------- [tbsl exploration] submitting the last changes of the system Modified Paths: -------------- 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/Elements.java 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/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.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/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.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/modules/IterationModule.java 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/WordnetModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java Modified: 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/Index_utils.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -7,6 +7,7 @@ import java.util.Map; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.ElementStorage; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; @@ -103,7 +104,7 @@ } public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ - HashMap<String,Float> hm = new HashMap<String,Float>(); + //HashMap<String,Float> hm = new HashMap<String,Float>(); if(Setting.isDebugModus())DebugMode.debugPrint("######\n In search Index for Property"); // adding or set elements in Map by put method key and value pair @@ -113,13 +114,38 @@ map.put(23, 2.5f); map.put(64, 4.83f); */ - + ArrayList<String> result_List = new ArrayList<String>(); string=string.replace("_", " "); string=string.replace("-", " "); string=string.replace(".", " "); + if(string.contains("label")&&string.contains("name")){ + string="name"; + } + + /*String value= null; + value=ElementStorage.getStorage_property().get(string); + + if(value!=null){ + result_List.add(value); + return result_List; + } + else{*/ + String result_new= null; + if(Setting.isLoadedProperties()){ + try { + result_new = myindex.getManualPropertyURI(string); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(result_new!=null){ + result_List.add(result_new); + ElementStorage.addStorage_property(string, result_new); + return result_List; + } + } String result=null; String result2 = null; - ArrayList<String> result_List = new ArrayList<String>(); if(string.substring(string.length()-1).contains("s")){ String neuer_string = string.substring(0, string.length() -1); @@ -133,18 +159,19 @@ //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); if(result2!=null){ result_List.add(result2); - hm.put(result, 1.0f); + //hm.put(result, 1.0f); } else if(result!=null){ result_List.add(result); - hm.put(result, 1.0f); + ElementStorage.addStorage_property(string, result); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else{ if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); - hm.put(result, 0.0f); + //hm.put(result, 0.0f); } } else{ @@ -158,19 +185,22 @@ if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); if(result2!=null){ result_List.add(result2); - hm.put(result, 1.0f); + //ElementStorage.addStorage_property(string, result2); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else if(result!=null){ result_List.add(result); - hm.put(result, 1.0f); + //ElementStorage.addStorage_property(string, result); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else{ if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); - hm.put(result, 0.0f); + //ElementStorage.addStorage_property(string, "http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + //hm.put(result, 0.0f); } } Modified: 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/Index/SQLiteIndex.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -32,6 +32,7 @@ Class.forName( "org.sqlite.JDBC" ); conn = DriverManager.getConnection("jdbc:sqlite::memory:"); createIndexPropertys(); + createIndexManualPropertys(); createIndexResource(); createWordnetHelp(); createIndexOntology(); @@ -205,6 +206,30 @@ } + public String getManualPropertyURI(String string) throws SQLException, IOException{ + Statement stat = conn.createStatement(); + ResultSet rs; + string = string.replace("_"," "); + try { + rs = stat.executeQuery("select uri from manualproperty where name='"+string.toLowerCase()+"';"); + while(rs.next()){ + String result_string= rs.getString("uri"); + return result_string; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + //System.err.println("Error in SQLiteIndex.getProperty!!"); + + + return null; + } + + return null; + } + + public String getontologyURI(String string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; @@ -449,6 +474,61 @@ System.out.println("Done"); } + + + +private void createIndexManualPropertys() throws ClassNotFoundException, SQLException{ + System.out.println("start indexing ManualProperties"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists manualproperty;"); + stat.executeUpdate("create table manualproperty (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into manualproperty values (?, ?);"); + BufferedReader in=null; + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/manualAddedProperties" ) ) ); + 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 ManualProperty: "+zaehler); + System.out.println("Done"); + + } + + + private void createIndexResource() throws ClassNotFoundException, SQLException{ System.out.println("start indexing Resources"); Statement stat = conn.createStatement(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -2,8 +2,10 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.ElementStorage; import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; @@ -27,7 +29,7 @@ } public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ - + long start = System.currentTimeMillis(); /* * first all Classes! */ @@ -51,6 +53,8 @@ } if(Setting.isDebugModus())DebugMode.debugPrint("Created Elements"); + long stop = System.currentTimeMillis(); + Setting.addTime_elements(stop-start); } private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ @@ -64,13 +68,25 @@ * if isA is found and if Class has uri, get Elements */ if(h.getType().contains("ISA")&&h.getUri().contains("http")){ + if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Class: "+h.getName()+" Uri: "+h.getUri()); /* - * TODO: improver performance, using geschicktes zwischenspeichern + * Todo First Lookup an HashMap with if the resource is in it, if yes, take the results, + * if not, create new Elements */ - if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Class: "+h.getName()+" Uri: "+h.getUri()); - ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); + if(ElementStorage.getStorage_classes().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName(),h.getUri(),ElementStorage.getStorage_classes().get(h.getUri())); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getElementsForGivenClass(h.getUri()); + ElementList el = new ElementList(h.getName(),h.getUri(),tmp_hm); + ElementStorage.addStorage_classes(h.getUri(), tmp_hm); + this.addElements(el); + } + //ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); - this.addElements(el); + //this.addElements(el); } } } @@ -90,18 +106,38 @@ for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { - ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); - //resources.add(el); - this.addElements(el); + if(ElementStorage.getStorage_resource_right().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ElementStorage.getStorage_resource_right().get(h.getUri())); + //resources.add(el); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT"); + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),tmp_hm); + ElementStorage.addStorage_resource_right(h.getUri(), tmp_hm); + //resources.add(el); + this.addElements(el); + } + + } if(h.getVariable().equals(cl.get(2))) { - /* - * TDO: Geht hier in die Schleife, aber die Liste wird nicht hinzugefügt.... - */ - ElementList el_left = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); - //resources.add(el); - //el_left.printAll(); - this.addElements(el_left); + + if(ElementStorage.getStorage_resource_left().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ElementStorage.getStorage_resource_left().get(h.getUri())); + //resources.add(el); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT"); + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),tmp_hm); + ElementStorage.addStorage_resource_left(h.getUri(), tmp_hm); + //resources.add(el); + this.addElements(el); + } + } } 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-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -47,8 +47,13 @@ ArrayList<Template> resultArrayList = new ArrayList<Template>(); Set<BasicQueryTemplate> querytemps =null; - querytemps = btemplator.buildBasicQueries(question); - + try{ + querytemps = btemplator.buildBasicQueries(question); + } + catch (Exception e){ + System.err.println("Error in Templategeneration"); + querytemps=null; + } /* * check if templates were build, if not, safe the question and delete it for next time from the xml file. @@ -83,7 +88,15 @@ long stop_template = System.currentTimeMillis(); + Setting.addTime_tbsl(stop_template-start); + + + + + + long start_builder = System.currentTimeMillis(); if(Setting.isDebugModus())DebugMode.waitForButton(); + if(querytemps!=null){ for (BasicQueryTemplate bqt : querytemps) { long start_part1= System.currentTimeMillis(); @@ -217,14 +230,10 @@ } if(slot.toString().contains("PROPERTY")){ - System.out.println("Slot.toString(): "+slot.toString()); String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); - System.out.println(tmp); String[] tmp_array = tmp.split(":"); if(tmp_array.length>1){ - System.out.println("tmp_array[0]:"+tmp_array[0]); - System.out.println("tmp_array[1]:"+tmp_array[1]); Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); list_of_hypothesis.add(tmp_hypothesis); @@ -340,7 +349,6 @@ if(h.getType().contains("ISA")){ try { ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); - System.out.println("Laenge tmp: "+tmp.size()); if(tmp.size()>0){ h.setUri(tmp.get(0)); h.setRank(1.0); @@ -354,7 +362,6 @@ if(h.getType().contains("RESOURCE")){ try { ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); - System.out.println("Laenge tmp: "+tmp.size()); if(tmp.size()>0){ h.setUri(tmp.get(0)); h.setRank(1.0); @@ -453,10 +460,13 @@ } } - + long stop_builder = System.currentTimeMillis(); + Setting.addTime_builder(stop_builder-start_builder); if(Setting.isDebugModus())DebugMode.printTemplateList(resultArrayList, "Templates nach allen Verarbeitungsschritten"); return resultArrayList; } + return resultArrayList; + } } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -0,0 +1,63 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.HashMap; + +public class ElementStorage { +private static HashMap<String,HashMap<String,String>> storage_classes = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,HashMap<String,String>> storage_resource_right = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,HashMap<String,String>> storage_resource_left = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,String> storage_property= new HashMap<String,String> (); + +/* + * First String contains URI + */ +public static HashMap<String,HashMap<String,String>> getStorage_classes() { + return storage_classes; +} + +public static void setStorage_classes(HashMap<String,HashMap<String,String>> storage_classes) { + ElementStorage.storage_classes = storage_classes; +} + +public static void addStorage_classes(String key, HashMap<String,String> value) { + ElementStorage.storage_classes.put(key, value); +} + +public static HashMap<String,HashMap<String,String>> getStorage_resource_right() { + return storage_resource_right; +} + +public static void setStorage_resource_right(HashMap<String,HashMap<String,String>> storage_resource_right) { + ElementStorage.storage_resource_right = storage_resource_right; +} + +public static void addStorage_resource_right(String key, HashMap<String,String> value) { + ElementStorage.storage_resource_right.put(key, value); +} + +public static HashMap<String,HashMap<String,String>> getStorage_resource_left() { + return storage_resource_left; +} + +public static void setStorage_resource_left(HashMap<String,HashMap<String,String>> storage_resource_left) { + ElementStorage.storage_resource_left = storage_resource_left; +} + +public static void addStorage_resource_left(String key, HashMap<String,String> value) { + ElementStorage.storage_resource_left.put(key, value); +} + +public static HashMap<String,String> getStorage_property() { + return storage_property; +} + +public static void setStorage_property(HashMap<String,String> storage_property) { + ElementStorage.storage_property = storage_property; +} + +public static void addStorage_property(String key, String value) { + ElementStorage.storage_property.put(key, value); +} + + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.exploration.Utils; +import java.io.IOException; import java.util.ArrayList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; @@ -46,16 +47,23 @@ for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; String Resource=null; + String PropertyName=null; + String Property=null; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ if(h.getType().toLowerCase().contains("resource")){ - Resource=h.getName(); + Resource=h.getUri(); } + if(h.getType().toLowerCase().contains("property")){ + PropertyName=h.getName(); + Property=h.getUri(); + } - condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); + condition_new=condition_new.replace(h.getVariable()+" ", "<"+h.getUri()+"> "); + /* * Dont create a Query with variables, which dont have a correct uri */ @@ -86,6 +94,8 @@ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+t.getQueryType()+" "+t.getSelectTerm()+"?string WHERE {"+ condition_new+" OPTIONAL { "+ t.getSelectTerm()+" rdfs:label ?string. FILTER (lang(?string) = 'en') }"+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); qp.setResource(Resource); + qp.setProperty(Property); + qp.setPropertyName(PropertyName); if(addQuery)queryList.add(qp); } @@ -93,6 +103,8 @@ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); qp.setResource(Resource); + qp.setProperty(Property); + qp.setPropertyName(PropertyName); if(addQuery)queryList.add(qp); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -3,6 +3,8 @@ public class QueryPair { private String Query; private String Resource; + private String Property; + private String PropertyName; private double rank; public String getQuery() { return Query; @@ -32,6 +34,18 @@ public void setResource(String resource) { Resource = resource; } + public String getProperty() { + return Property; + } + public void setProperty(String property) { + Property = property; + } + public String getPropertyName() { + return PropertyName; + } + public void setPropertyName(String propertyName) { + PropertyName = propertyName; + } } 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-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -15,9 +15,10 @@ public class ServerUtil { - //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String 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:8897/sparql"; //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; private static int timeToTimeoutOnServer=3000; @@ -108,6 +109,7 @@ String result=""; /*System.out.println(verarbeitungsurl); System.out.println("side: "+ side);*/ + // System.out.println(verarbeitungsurl); result = getListOfElements(verarbeitungsurl); return generateList(result); @@ -121,26 +123,7 @@ */ public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ - /* - PREFIX dbo: <http://dbpedia.org/ontology/> -SELECT DISTINCT ?p WHERE { - { ?x ?p ?y . } UNION { ?y ?p ?x . } - { - SELECT ?x { - ?x rdf:type dbo:Mountain . - } - LIMIT 10 - } -} -ORDER BY ?x - - - TODO:Try with different Limits - */ - /* - * TODO: Still a not "valid" url - */ String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; //System.out.println(query); //DebugMode.waitForButton(); @@ -243,8 +226,8 @@ } public static ArrayList<String> requestAnswerFromServer(String query){ + query=query.replace(">0",">"); String query_url=server_Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - //System.out.println(tmp); String result=""; HttpURLConnection connection = null; Modified: 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 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -11,6 +11,8 @@ import java.sql.SQLException; import java.util.ArrayList; +import net.didion.jwnl.JWNLException; + import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; @@ -31,6 +33,12 @@ public class MainInterface { //private static int anzahlAbgeschickterQueries = 10; + private static ArrayList<Template> global_template_list=new ArrayList<Template>(); + private static BasicTemplator btemplator_global; + private static SQLiteIndex myindex_global; + private static WordNet wordnet_global; + private static StanfordLemmatizer lemmatiser_global; + private static String type_global=""; public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ @@ -87,6 +95,8 @@ //generate QueryPair String Question=""; + + //TODO: parallel here? for(Template t : template_list){ Question=t.getQuestion(); t.printAll(); @@ -110,6 +120,10 @@ //if(Setting.isDebugModus())printQueries(qp, "NORMAL", Question); //printQueries(qp, "NORMAL", Question); Setting.setAnzahlAbgeschickterQueries(10); + System.out.println("Following Querries were created:"); + for(QueryPair q : qp){ + System.out.println(q.getQuery()+" rank:"+q.getRank()); + } int anzahl=1; boolean go_on = true; @@ -124,6 +138,9 @@ go_on=false; //if(qp.size()<3)go_on=true; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(Setting.isTagging()) write_ResourcePropertyInformation(q.getResource(),q.getPropertyName(),q.getProperty()); + + //printSingleQuery(q.getQuery(),Question); //go_on=true; boolean contains_uri=false; for(String s : answer_tmp){ @@ -162,6 +179,8 @@ System.out.println(answer); } if(wait)DebugMode.waitForButton(); + + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ @@ -190,6 +209,7 @@ if(wait)DebugMode.waitForButton(); } + if(answers.isEmpty()&&Setting.getModuleStep()>=5){ System.out.println("NO Answer from Server =>Start Query Manipulation"); answers.clear(); @@ -202,7 +222,6 @@ - /* * return answers! */ @@ -229,23 +248,65 @@ boolean special=false; int anzahl; boolean go_on; - /*if(type.contains("SPECIAL")){ - type ="LEVENSTHEIN"; - special=true; - }*/ System.out.println("No answer from direkt match, start "+type+"Modul"); + + /*ArrayList<Thread> thread_list = new ArrayList<Thread>(); + ThreadGroup group = new ThreadGroup("QA-Threads"); + int anzahl_thread=0; + global_template_list.clear(); + global_template_list=template_list; + myindex_global=myindex; + wordnet_global=wordnet; + lemmatiser_global=lemmatiser; + type_global=type; + for(Template t : template_list){ + final int anzahl_thread_new=anzahl_thread; + + Thread t1; + try { + t1 = new Thread(group,String.valueOf(anzahl_thread)) + { + String blub=do_something(anzahl_thread_new); + }; + + thread_list.add(t1); + t1.start(); + + + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + anzahl_thread+=1; + + } + */ + + /* + * NOw wait until all are finished + */ + + /*for(int i =0; i<thread_list.size();i++){ + try { + thread_list.get(i).join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }*/ + + + for(Template t : template_list){ try{ - /*if(test.contains("alt")){ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); - if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); - if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); - if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); - }*/ - //if(test.contains("neu")){ - // System.err.println("IN NEU!!!!!"); ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); @@ -275,6 +336,8 @@ } + + /* * Generate Queries and test queries */ @@ -299,12 +362,12 @@ //sort QueryPairs qp=LinearSort.doSort(qp); + qp=HeuristicSort.doHeuristicSort(qp, Question); //printQueries(qp, type, Question); - qp=HeuristicSort.doHeuristicSort(qp, Question); System.out.println("Following Querries were created:"); - for(QueryPair z : qp){ - System.out.println(z.getQuery()+" "+z.getRank()); + for(QueryPair q : qp){ + System.out.println(q.getQuery()+" rank:"+q.getRank()); } if(Setting.isDebugModus())printQueries(qp, type, Question); //printQueries(qp, type, Question); @@ -324,6 +387,8 @@ go_on=false; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(Setting.isTagging()) write_ResourcePropertyInformation(q.getResource(),q.getPropertyName(),q.getProperty()); + //printSingleQuery(q.getQuery(),Question); if(qp.size()>(id+1)){ //&&anzahl<2 if(q.getRank()==qp.get(id+1).getRank()){ @@ -480,7 +545,7 @@ } private static void printQueries(ArrayList<QueryPair> qp, String type, String Question){ - String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQueryListNLD"+Setting.getLevenstheinMin()+".txt"; + /*String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQuery"+Setting.getLevenstheinMin()+".txt"; String result_string =""; //Open the file for reading try { @@ -508,7 +573,7 @@ /* * write only the first 10 queries: */ - for(QueryPair q : qp){ + /* for(QueryPair q : qp){ if(anzahl<10){ querylist+=q.getQuery()+" "+q.getRank()+"\n"; anzahl+=1; @@ -535,7 +600,54 @@ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); + }*/ + } + + + + private static void printSingleQuery(String query,String Question){ + /*String dateiname="/home/swalter/Dokumente/Auswertung/WorkingQuery"+Setting.getLevenstheinMin()+".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 = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + + try { + bw.write(result_string+Question+" "+query+"\n"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ } @@ -767,6 +879,115 @@ } + + if(t.getCondition().size()>=30){ + ArrayList<ArrayList<Hypothesis>> new_hypothesen_list = new ArrayList<ArrayList<Hypothesis>>(); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + /* + * if greater 2, than it means, there are at least 3 propertys/resources or whatever + */ + + /* + * Resource ?x + * Property ?y + * Select auf ?z + */ + if(h_l.size()>2){ + if(h_l.get(0).getUri().contains("resource")){ + Hypothesis h_r= h_l.get(0); + Hypothesis h_p1= h_l.get(1); + Hypothesis h_p2= h_l.get(2); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + } + else if(h_l.get(1).getUri().contains("resource")){ + Hypothesis h_r= h_l.get(1); + Hypothesis h_p1= h_l.get(0); + Hypothesis h_p2= h_l.get(2); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + } + else{ + Hypothesis h_r= h_l.get(2); + Hypothesis h_p1= h_l.get(1); + Hypothesis h_p2= h_l.get(0); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + + } + } + } + + ArrayList<ArrayList<String>> condition_new=new ArrayList<ArrayList<String>>(); + ArrayList<String> con = new ArrayList<String>(); + con.add("?x"); + con.add("?y"); + con.add("?z"); + condition_new.add(con); + + ArrayList<ArrayList<String>> condition_new_r=new ArrayList<ArrayList<String>>(); + ArrayList<String> con_r = new ArrayList<String>(); + con_r.add("?z"); + con_r.add("?y"); + con_r.add("?x"); + condition_new_r.add(con_r); + + + + Template template_new = new Template(condition_new,"SELECT", t.getHaving(), t.getFilter(), "?z", t.getOrderBy(), t.getLimit(), t.getQuestion()); + template_new.setHypothesen(new_hypothesen_list); + template_new.setElm(t.getElm()); + + Template template_new_r = new Template(condition_new_r,"SELECT", t.getHaving(), t.getFilter(), "?z", t.getOrderBy(), t.getLimit(), t.getQuestion()); + template_new_r.setHypothesen(new_hypothesen_list); + template_new_r.setElm(t.getElm()); + + Elements elm = new Elements(template_new.getCondition(),template_new.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + template_new.setElm(elm); + new_template_list.add(template_new); + } + + Elements elm_r = new Elements(template_new.getCondition(),template_new.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + template_new_r.setElm(elm_r); + new_template_list.add(template_new_r); + } + + + + //new_template_list.add(template_new); + //new_template_list.add(template_new_r); + } } /* @@ -785,4 +1006,80 @@ return answers; } + + + private static String do_something(int number) throws SQLException, JWNLException, IOException{ + //String str_number=Thread.currentThread().getName(); + //System.out.println("ThreadName: "+str_number); + //int number= Integer.parseInt(str_number); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); + + + for(ArrayList<Hypothesis> l_h : global_template_list.get(number).getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); + generated_hypothesis= IterationModule.new_iteration(global_template_list.get(number).getElm(),l_h,global_template_list.get(number).getCondition(),type_global,myindex_global,wordnet_global,lemmatiser_global); + for(ArrayList<Hypothesis> h_t : generated_hypothesis){ + ArrayList<Hypothesis> new_hypothesen_set = new ArrayList<Hypothesis>(); + for(Hypothesis bla : h_t){ + new_hypothesen_set.add(bla); + } + hypothesenSetList.add(new_hypothesen_set); + } + + //hypothesenSetList.addAll(blub); + } + if(type_global.contains("WORDNET"))global_template_list.get(number).setHypothesenWordnet(hypothesenSetList); + if(type_global.contains("LEVENSTHEIN"))global_template_list.get(number).setHypothesenLevensthein(hypothesenSetList); + if(type_global.contains("RELATE"))global_template_list.get(number).setHypothesenRelate(hypothesenSetList); + return "DONE"; + + } + + private static void write_ResourcePropertyInformation(String Resource, String PropertyName, String Property){ + String dateiname="/home/swalter/Dokumente/Auswertung/ResourcePropertyRelation.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 = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + + + try { + bw.write(result_string+Resource+"::"+PropertyName+"::"+Property+"\n"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -14,9 +14,15 @@ private static boolean loadedProperties; private static int version; private static boolean saveAnsweredQueries; + private static boolean tagging; + private static boolean loadTagging; + private static long time_tbsl; + private static long time_builder; + private static long time_elements; + public static boolean isWaitModus() { return waitModus; } @@ -90,6 +96,54 @@ public static void setSaveAnsweredQueries(boolean saveAnsweredQueries) { Setting.saveAnsweredQueries = saveAnsweredQueries; } + public static long getTime_tbsl() { + return time_tbsl; + } + public static void setTime_tbsl(long time_tbsl) { + Setting.time_tbsl = time_tbsl; + } + + public static void addTime_tbsl(long time_tbsl) { + long tmp=getTime_tbsl(); + Setting.time_tbsl = time_tbsl+tmp; + } + public static long getTime_builder() { + return time_builder; + } + public static void setTime_builder(long time_builder) { + Setting.time_builder = time_builder; + } + + public static void addTime_builder(long time_builder) { + long tmp=getTime_builder(); + Setting.time_builder = time_builder+tmp; + } + public static long getTime_elements() { + return time_elements; + } + public static void setTime_elements(long time_elements) { + Setting.time_elements = time_elements; + } + + public static void addTime_elements(long time_elements) { + long tmp = getTime_elements(); + Setting.time_elements = time_elements+tmp; + } + public static boolean isTagging() { + //if(isLoadTagging()) return false; + return tagging; + } + public static void setTagging(boolean tagging) { + Setting.tagging = tagging; + } + public static boolean isLoadTagging() { + if(isTagging())return false; + else return loadTagging; + } + public static void setLoadTagging(boolean loadTagging) { + Setting.loadTagging = loadTagging; + } + } 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-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -9,6 +9,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintStream; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,6 +45,9 @@ System.out.println("Starting Main File"); long startInitTime = System.currentTimeMillis(); + //PrintStream err = new PrintStream(new FileOutputStream("/home/swalter/Dokumente/ERRListe.txt")); + //System.setErr(err); + /* * Initial Index and Templator */ @@ -66,6 +70,7 @@ Setting.setThresholdSelect(0.5); Setting.setLoadedProperties(false); Setting.setSaveAnsweredQueries(false); + Setting.setTagging(false); //default //Setting.setVersion(1); /* @@ -73,7 +78,7 @@ * 2= "Normal" + Levensthein * 3= Normal+Levensthein+Wordnet */ - Setting.setModuleStep(5); + Setting.setModuleStep(4); Setting.setEsaMin(0.4); @@ -84,7 +89,7 @@ boolean startQuestioning = true; while(schleife==true){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - String line; + String line=""; startQuestioning = true; try { System.out.println("\n\n"); @@ -134,35 +139,40 @@ } - + if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + + float global_tbsl_avaerage = 0; + float global_builder_average=0; - //for(int i = 1; i<2;i++){ + for(int i = 1; i<2;i++){ //double min = 0.95; //min+=(i*0.05); - /*if(i==1){ + if(i==1){ line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; } if(i==2){ line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; - }*/ + } - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + //line="/home/swalter/Dokumente/Auswertung/Yahoo/works"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; for(int j=1;j<2;j++){ - Setting.setVersion(1); + //Setting.setVersion(99); - for(int z=1;z<7;z++){ + for(int z=4;z<5;z++){ //Setting.setLevenstheinMin(min); Setting.setLevenstheinMin(0.95); //Setting.setThresholdSelect(0.4); - Setting.setModuleStep(2); + Setting.setModuleStep(z); Setting.setThresholdSelect(0.5); - Setting.setEsaMin(0.0+(z/10.0)); + Setting.setEsaMin(0.4); Setting.setLoadedProperties(false); + Setting.setTagging(false); /*if(i==2)Setting.setLoadedProperties(true); else Setting.setLoadedProperties(false); */ @@ -174,6 +184,7 @@ ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); list_of_structs=generateStruct(line,true); + //list_of_structs=generateStructTextfile(line,true); //Start Time measuring long startTime = System.currentTimeMillis(); @@ -192,7 +203,18 @@ long stopTime = System.currentTimeMillis(); System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); + System.out.println("Tbsl took overall: "+Setting.getTime_tbsl()+"ms"); + System.out.println("Builder took overall: "+Setting.getTime_builder()+"ms"); + int anzahl_questions=list_of_structs.size(); + System.out.println("Tbsl Average: "+Setting.getTime_tbsl()/anzahl_questions+"ms"); + System.out.println("Builder Average: "+Setting.getTime_builder()/anzahl_questions+"ms"); + System.out.println("Elements Average: "+Setting.getTime_elements()/anzahl_questions+"ms"); + System.out.println("OverallTime Average: "+(stopTime-startTime)/anzahl_questions+"ms"); + global_tbsl_avaerage+=Setting.getTime_tbsl()/anzahl_questions; + global_builder_average+=Setting.getTime_builder()/anzahl_questions; + + String filename=""; filename=createXML(list_of_structs,((stopTime-startTime)/1000)); String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/"+filename; @@ -237,16 +259,20 @@ - // } + } + System.out.println("Average Tbsl:"+global_tbsl_avaerage/4/1000); + System.out.println("Average Builder:"+global_builder_average/4/1000); /*schleife=false; System.out.println("Bye!"); System.exit(0);*/ } + //else else if(schleife==true && startQuestioning ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); + //line="Give/VB me/PRP all/DT actors/NNS starring/VBG in/IN Batman/NNP Begins/NNP"; MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! @@ -260,6 +286,7 @@ } long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); + //System.exit(0); } } catch (IOException e) { @@ -539,5 +566,53 @@ } + +private static ArrayList<queryInformation> generateStructTextfile(String filename, boolean hint) { + + + + BufferedReader in = null; + ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); + String tmp=""; + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream(filename) ) ); + String s; + int anzahl=0; + String XMLType="dbpedia-train"; + while( null != (s = in.readLine()) ) { + anzahl+=1; + queryInformation blaquery=new queryInformation(s.replace("\n", ""), Integer.toString(anzahl),"",false,false,false,XMLType,false); + querylist.add(blaquery); + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + + + + for(queryInformation s : querylist){ + 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()); + } + return querylist; + } + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -109,7 +109,6 @@ e1.printStackTrace(); }*/ if(givenConditionList.size()==1){ - System.err.println("Only one Condition => simple Struktur"); simple_structure=true; boolean resource_case=false; @@ -188,7 +187,6 @@ * two conditions! */ if(givenConditionList.size()==2){ - System.out.println("two Conditions => NOT simple Struktur"); ArrayList<ElementList> resources = new ArrayList<ElementList>(); boolean gotResource=true; try{ @@ -259,7 +257,6 @@ * */ if((condition1_exists_isa||condition2_exists_isa)&&gotResource&&(condition1_exists_resource||condition2_exists_resource)){ - System.err.println("CASE1"); String class_variable=null; String class_property_variable=null; ArrayList<String> working_condition=new ArrayList<String>(); @@ -345,7 +342,6 @@ * ISA */ else if((condition1_exists_isa||condition2_exists_isa)&&gotResource){ - System.err.println("CASE2"); /* * get Hypothese for the Class */ @@ -421,7 +417,6 @@ else if((condition1_exists_resource||condition2_exists_resource)&&gotResource){ - System.err.println("CASE3"); String property_name=""; String second_property_name=""; String property_variable=""; @@ -470,26 +465,26 @@ for(Hypothesis h_temp : resultHypothesenList) { String Query=""; if(property_side_new.contains("LEFT")){ - Query= "SELECT DISTINCT ?s ?x WHERE {<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + //{ [] foaf:name ?name1 } UNION { [] vCard:FN ?name2 } + Query= "SELECT DISTINCT ?s ?x WHERE {{<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x} UNION {<"+ resource_h.getUri()+"> <"+h_temp.getUri().replace("property", "ontology")+"> ?x}. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } else{ - Query= "SELECT DISTINCT ?s ?x WHERE {?x <"+h_temp.getUri()+"> <"+ resource_h.getUri()+"> . ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + Query= "SELECT DISTINCT ?s ?x WHERE {{?x <"+h_temp.getUri()+"> <"+ resource_h.getUri()+">} UNION {?x <"+h_temp.getUri().replace("property", "ontology")+"> <"+ resource_h.getUri()+">} . ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } /* * Now use the variable from the second condition which does not has an Resource in the Hypothesis */ - System.out.println("Query: "+Query); HashMap<String, String> hm_newClasses=ServerUtil.generatesQueryForOutsideClasses(Query); ArrayList<Hypothesis> second_resultHypothesenList=new ArrayList<Hypothesis>(); - second_resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, second_property_variable, second_property_name,hm_newClasses,resource_h.getName()); + for(Hypothesis second_h_temp : second_resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(resource_h); 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-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -32,122 +32,8 @@ boolean found_property_in_loaded_property=false; boolean found_property_in_created_property=false; - if(Setting.isLoadedProperties()){ - System.out.println("in Loaded!!"); - //Open the file for reading - try { - BufferedReader br = new BufferedReader(new FileReader(dateiname)); - String thisLine; - while ((thisLine = br.readLine()) != null) { // while loop begins here - String[] tmp_array = thisLine.split("::"); - if(tmp_array.length>1){ - loaded_properties.put(tmp_array[0].replace("\n", ""), tmp_array[1].replace("\n", "")); - } - - } // end while - } // end try - catch (IOException e) { - System.err.println("Error: " + e); - } - for (Entry<String, String> entry_loaded : loaded_properties.entrySet()) { - - String key_loaded= entry_loaded.getKey(); - String value_loaded= entry_loaded.getValue(); - if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ - System.out.println("FOUND!!"); - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.replace("(μ)", ""); - key=key.replace("(cm)", ""); - key=key.toLowerCase(); - String value = entry.getValue(); - /*System.out.println("KEY_old:"+key); - System.out.println("value_loaded:"+value_loaded+"DONE"); - System.out.println("Value:"+value); - System.out.println("\n");*/ - if(key.equals(value_loaded)){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); - h.printAll(); - found_property_in_loaded_property=true; - } - } - } - - } - } - /* - * createdPropertyCombinations - */ - - /* - * Second read in File with the propertys, which were created, when a query produced an answer and query had the rank >0.8 - * and the property hast the given "matserresource" - */ - /* if(found_property_in_loaded_property==false&&Setting.isSaveAnsweredQueries()){ - HashMap<String, String> created_properties = new HashMap<String, String>(); - System.out.println("in Save!!"); - dateiname="/home/swalter/workspace/createdPropertyCombinations"; - System.out.println("Resource to compare: "+resource_name); - //Open the file for reading - try { - BufferedReader br = new BufferedReader(new FileReader(dateiname)); - String thisLine; - while ((thisLine = br.readLine()) != null) { // while loop begins here - String[] tmp_array = thisLine.split("::"); - if(tmp_array.length>2){ - - // check, if the given resource is equal to the reosource loaded from the file! - - if(tmp_array[0].toLowerCase().replace("\n", "").equals(resource_name.toLowerCase())){ - created_properties.put(tmp_array[1].replace("\n", ""), tmp_array[2].replace("\n", "")); - } - - } - - } // end while - } // end try - catch (IOException e) { - System.err.println("Error: " + e); - } - if(!created_properties.isEmpty()){ - for (Entry<String, String> entry_loaded : created_properties.entrySet()) { - - String key_loaded= entry_loaded.getKey(); - String value_loaded= entry_loaded.getValue(); - if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ - System.out.println("FOUND!!"); - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.replace("(μ)", ""); - key=key.replace("(cm)", ""); - key=key.toLowerCase(); - String value = entry.getValue(); - System.out.println("KEY_old:"+key); - System.out.println("value_loaded:"+value_loaded+"DONE"); - System.out.println("Value:"+value); - System.out.println("\n"); - if(key.equals(value_loaded)){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); - h.printAll(); - found_property_in_created_property=true; - } - } - } - - } - } - - - }*/ - if(found_property_in_loaded_property==false||found_property_in_created_property==false){ //} @@ -211,7 +97,6 @@ } else if(compare_property.substring(compare_property.length()-2).contains("ed")){ String compare_property_neu = compare_property.substring(0, compare_property.length() -2); - System.out.println("NEW compare_property: "+compare_property_neu); if(key.contains(compare_property_neu)||compare_property_neu.contains(key)){ Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.95); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -20,14 +20,12 @@ public class WordnetModule { - private static int explorationdepthwordnet =0; + private static int explorationdepthwordnet =1; public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throw... [truncated message content] |