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