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. |