From: <seb...@us...> - 2012-04-04 15:12:43
|
Revision: 3627 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3627&view=rev Author: sebastianwtr Date: 2012-04-04 15:12:31 +0000 (Wed, 04 Apr 2012) Log Message: ----------- [tbsl exploration] started fixing some bugs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -61,10 +61,11 @@ /* * if isA is found and if Class has uri, get Elements */ - if(h.getType().contains("isA")&&h.getUri().contains("http")){ + if(h.getType().contains("ISA")&&h.getUri().contains("http")){ /* * TODO: improver performance, using geschicktes zwischenspeichern */ + System.out.println("Class Name: "+h.getName()+" Uri: "+h.getUri()); ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); this.addElements(el); @@ -83,6 +84,8 @@ for(ArrayList<Hypothesis> hl : hypothesenList){ for(Hypothesis h : hl){ if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ + System.out.println("Resource Name: "+h.getName()+" Uri: "+h.getUri()); + for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -8,6 +8,7 @@ private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenWordnet = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -180,6 +181,12 @@ public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { this.hypothesenLevensthein = hypothesenLevensthein; } + public ArrayList<ArrayList<Hypothesis>> getHypothesenWordnet() { + return hypothesenWordnet; + } + public void setHypothesenWordnet(ArrayList<ArrayList<Hypothesis>> hypothesenWordnet) { + this.hypothesenWordnet = hypothesenWordnet; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -104,6 +104,7 @@ String[] tmp_array = conditions1.toString().split(" -- "); for(String s: tmp_array){ //System.out.println(s); + s=s.replace("isA", "ISA"); temp_array.add(s); } condition.add(temp_array); @@ -166,6 +167,14 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + for(ArrayList<String> al : condition){ + String con_temp=""; + for(String s : al){ + con_temp+=" " + s; + } + System.out.println("Condition: "+con_temp); + } + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -179,7 +188,7 @@ String[] tmp_array = tmp.split(":"); boolean no_iaA_found=true; for(ArrayList<String> x : condition){ - if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + if(x.get(1).equals("ISA") && x.get(2).equals("?"+tmp_array[0])){ no_iaA_found=false; Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0.0); //tmp_hypothesis.printAll(); @@ -218,11 +227,11 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); + System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); for(Hypothesis x : list_of_hypothesis){ /* @@ -270,13 +279,13 @@ } } - /*System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -311,18 +320,51 @@ } } - /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + + + + /* + * BUGFIX: Before adding Hypothesis to template check, if each Hypothesis has an uri + * TODO: check all functions before + */ + /*for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ + for(Hypothesis h : al){ + if(!h.getUri().contains("http")){ + if(h.getType().contains("ISA")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + if(h.getType().contains("RESOURCE")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } + } + } + */ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); - template.setHypothesen(final_list_set_hypothesis); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -17,7 +17,9 @@ else{ double result_nld =result/length; - return result_nld; + double result1 = 1-result_nld; + //System.out.println(orig + " " + eing +" : "+result1); + return result1; } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -20,9 +20,9 @@ } } - for(QueryPair p : qp){ + /*for(QueryPair p : qp){ p.printAll(); - } + }*/ } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -31,7 +31,12 @@ if(type.contains("LEVENSTHEIN")){ givenHypothesenList=t.getHypothesenLevensthein(); } - else{ + else if(type.contains("WORDNET")){ + givenHypothesenList=t.getHypothesenWordnet(); + } + + else { + if(!type.contains("NORMAL"))System.err.println("ATTENTION\n Given Type: "+type+" was not found in generating Queries!!\n"); givenHypothesenList=t.getHypothesen(); } @@ -48,6 +53,8 @@ if(!h.getUri().contains("http")){ addQuery=false; } + condition_new=condition_new.replace("ISA", "rdf:type"); + //just in case... condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,10 +3,14 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ServerUtil { @@ -128,10 +132,13 @@ TODO:Try with different Limits */ - String query="PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').}{?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; - + /* + * TODO: Still a not "valid" url + */ + String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; + String query_final=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String result=""; - result = getListOfElements(query); + result = getListOfElements(query_final); return generateList(result); } @@ -197,8 +204,66 @@ result=sb.toString(); } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); + //System.out.println("Must enter a valid URL"); + System.err.println("ATTENTION\n URL not valid : "+verarbeitungsurl+"\n"); } catch (IOException e) { + System.err.println("Can not connect or timeout"); + } + finally + { + //close the connection, set all objects to null + try{ + connection.disconnect(); + } + catch (Exception e){ + System.err.println("ATTENTION\n Error in disconecting Connection to Server in getListOfElements\n "); + } + rd = null; + sb = null; + connection = null; + } + return result; + } + + public static ArrayList<String> requestAnswerFromServer(String query){ + String query_url=server_Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + + //System.out.println(tmp); + String result=""; + HttpURLConnection connection = null; + OutputStreamWriter wr = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + + URL serverAddress = null; + + try { + serverAddress = new URL(query_url); + //set up out communications stuff + connection = null; + + //Set up the initial connection + connection = (HttpURLConnection)serverAddress.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(timeToTimeoutOnServer); + + connection.connect(); + rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + sb = new StringBuilder(); + + while ((line = rd.readLine()) != null) + { + sb.append(line + '\n'); + } + + //System.out.println(sb.toString()); + result=sb.toString(); + + } catch (MalformedURLException e) { + System.err.println("ATTENTION\n URL not valid : "+query_url+"\n"); + } catch (IOException e) { System.out.println("Can not connect or timeout"); } finally @@ -207,11 +272,41 @@ connection.disconnect(); rd = null; sb = null; + wr = null; connection = null; } + + + + return createAnswerArray(result); + } + + private static ArrayList<String> createAnswerArray(String string){ + + Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); + string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); + Matcher m = p.matcher (string); + String[] bla = string.split(" "); + + ArrayList<String> result= new ArrayList<String>(); + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + String temp = m.group(1); + temp = temp.replace("\"@en",""); + temp = temp.replace("\"",""); + //result.add(m.group(1)); + result.add(temp); + + } + } + + + //if (result.length()==0) result="EmtyAnswer"; + if(string.matches("true")|| string.matches("false")) result.add(string); return result; + } - } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,8 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.sql.SQLException; import java.util.ArrayList; @@ -12,17 +14,27 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class MainInterface { - private int anzahlAbgeschickterQueries = 10; - public static void startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex ) throws ClassNotFoundException, SQLException, IOException{ + private static int anzahlAbgeschickterQueries = 10; + + + public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); ArrayList<Template> template_list = new ArrayList<Template>(); + /* + * Array List with the answers from the queries + */ + ArrayList<String> answers = new ArrayList<String>(); + /* * generate Templates! */ @@ -35,7 +47,7 @@ //generate QueryPair for(Template t : template_list){ - //t.printAll(); + t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); qp_t = Query.returnSetOfQueries(t, "NORMAL"); for(QueryPair p : qp_t){ @@ -51,15 +63,101 @@ } //sort QueryPairs - LinearSort.doSort(qp); + LinearSort.doSort(qp); + int anzahl=1; + boolean go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + System.out.println(q.getQuery()); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String line; + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + + /* * If there is no answer, start IterationMode with Levensthein */ + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + /* + * still no answer, start IterationMode with Wordnet + */ + + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + + + /*if(answers.isEmpty()){ + System.out.println("No answers were found with the three Modules"); + //answers.add("No answers were found with the three Modules"); + }*/ + + + /* + * return answers! + */ + + return answers; + } + + + + + + + private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, + StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type) { + ArrayList<String> answers = new ArrayList<String>(); + ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + int anzahl; + boolean go_on; + System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); - t.setHypothesenLevensthein(hypothesenSetList); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); } catch (Exception e){ @@ -68,14 +166,13 @@ } /* - * Generate Queries for Levensthein Mode and test queries + * Generate Queries and test queries */ - qp.clear(); //generate QueryPair for(Template t : template_list){ //t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); - qp_t = Query.returnSetOfQueries(t, "LEVENSTHEIN"); + qp_t = Query.returnSetOfQueries(t, type); for(QueryPair p : qp_t){ //if(!qp.contains(p)) qp.add(p); boolean contain = false; @@ -84,24 +181,57 @@ if(p_t.getQuery().contains(p.getQuery())) contain=true; } } - if(!contain)qp.add(p); + if(!contain&&checkQuery(p.getQuery()))qp.add(p); } } //sort QueryPairs LinearSort.doSort(qp); - System.out.println("Anzahl: "+qp.size()); - /* - * still no answer, start IterationMode with Wordnet - */ + anzahl=1; + go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + System.out.println(q.getQuery() + " Rank: "+q.getRank()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } - /* - * Generate Queries for Wordnet Mode and test queries. - */ + return answers; } - private void sortQueries(){ + + + private static boolean checkAnswer(String answer){ + if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")) return false; + else return true; } + + private static boolean checkQuery(String query){ + if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")) return false; + else return true; + + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,7 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -20,7 +21,10 @@ import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; +import org.ibex.nestedvm.util.Seekable.InputStream; import java.sql.Connection; import java.sql.DriverManager; @@ -57,6 +61,8 @@ BasicTemplator btemplator = new BasicTemplator(); //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + StanfordLemmatizer lemmatiser = new StanfordLemmatizer(); long stopInitTime = System.currentTimeMillis(); @@ -82,13 +88,18 @@ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - System.out.println("Please enter Path of xml File:"); - line=in.readLine(); + /*System.out.println("Please enter Path of xml File:"); + line=in.readLine();*/ + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - ArrayList<queryInformation> list_of_resultstructs = new ArrayList<queryInformation>(); - //if you dont want to use the hints in the questions, use false + list_of_structs=generateStruct(line,true); //Start Time measuring long startTime = System.currentTimeMillis(); @@ -100,12 +111,13 @@ anzahl=anzahl+1; System.out.println(""); if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); - System.out.println("ID: "+qi.getId()); + /*System.out.println("ID: "+qi.getId()); System.out.println("Query: "+qi.getQuery()); System.out.println("Type: "+qi.getType()); - System.out.println("XMLType: "+qi.getXMLtype()); + System.out.println("XMLType: "+qi.getXMLtype());*/ String question = qi.getQuery(); - MainInterface.startQuestioning(question,btemplator,myindex); + ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); + qi.setResult(answers); } @@ -115,44 +127,28 @@ System.out.println(s.getResult()); }*/ String systemid=""; - systemid=createXML(list_of_resultstructs); - writeQueryInformation(list_of_structs,systemid); - writeTime(list_of_structs,systemid); - - //now create File with systemid for time and a file, which lists alle propertys and so on - - long timeNow = System.currentTimeMillis(); - long diff = timeNow-startTime; - String string1="Time for "+anzahl+" questions = "+diff+" ms."; - System.out.println(string1); - String string2="From "+anzahl_query_with_answers+" questions I got an answer"; - String string3=yago_querys+ " Yago Questions were skiped"; - System.out.println(string2); - System.out.println(string3); - String string4 ="Average time for one question : "+(diff/anzahl/1000)+"sek"; - File file; - FileWriter writer; - file = new File("../../generalInformation"+systemid+".txt"); - try { - writer = new FileWriter(file ,true); - writer.write(string1+"\n"+string2+"\n"+string3+"\n"+string4); - writer.flush(); - - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } + systemid=createXML(list_of_structs); + String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; + String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; + + /* + * First only for training + */ + + System.out.println("execute: "+execute); + Runtime r = Runtime.getRuntime(); + Process p = r.exec(execute); + + String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; + execute ="firefox "+ open_file; + p = r.exec(execute); - System.out.println("Finished test"); - System.exit(0); - } else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); - MainInterface.startQuestioning(line,btemplator,myindex); + MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! Set<String> setString = new HashSet<String>(); @@ -239,39 +235,43 @@ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); String systemid = sdf.format(now); - + System.out.println("In createXML"); String xmlDocument=""; int counter=0; + System.out.println("Anzahl queryInformations: "+list.size()); for (queryInformation s : list){ - String tmp; - if(counter==0){ - counter=counter+1; - xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + if(!s.getResult().isEmpty()){ + String tmp; + if(counter==0){ + counter=counter+1; + xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + } + tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; + + //to get all answers only once! + Set<String> setString = new HashSet<String>(); + for(String z: s.getResult()){ + setString.add(z); + } + for(String i : setString){ + //System.out.println("i: "+i); + String input=""; + if(i.contains("http")) input="<uri>"+i+"</uri>\n"; + else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; + else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else input="<string>"+i+"</string>\n"; + tmp+="<answer>"+input+"</answer>\n"; + } + tmp+="</answers></question>\n"; + xmlDocument+=tmp; } - tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; - //to get all answers only once! - Set<String> setString = new HashSet<String>(); - for(String z: s.getResult()){ - setString.add(z); - } - for(String i : setString){ - String input=""; - if(i.contains("http")) input="<uri>"+i+"</uri>\n"; - else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; - else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; - else input="<string>"+i+"</string>\n"; - tmp+="<answer>"+input+"</answer>\n"; - } - tmp+="</answers></question>\n"; - xmlDocument+=tmp; - } xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("../../result"+systemid+".xml"); + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); @@ -283,6 +283,7 @@ e.printStackTrace(); } + System.out.println("In createXML - Done"); return systemid; } @@ -318,18 +319,28 @@ String string=tmp; Pattern p = Pattern.compile (".*\\<question(.*)\\</question\\>.*"); Matcher m = p.matcher (string); + /* string= string.replace(" answertype=\"number\"", ""); + string= string.replace(" answertype=\"string\"", ""); + string= string.replace(" answertype=\"date\"", ""); + string= string.replace(" answertype=\"resource\"", ""); + string= string.replace(" answertype=\"boolean\"", ""); + string = string.replace(" aggregation=\"true\"", ""); + string = string.replace(" aggregation=\"false\"", ""); + string = string.replace(" onlydbo=\"false\"", ""); + string = string.replace(" onlydbo=\"true\"", "");*/ - if(string.contains("id=\"dbpedia-train\"><question")){ string=string.replace("id=\"dbpedia-train\"><question", ""); XMLType="dbpedia-train"; System.out.println("dbpedia-train"); } - if(string.contains("id=\"dbpedia-test\"><question")){ + else if(string.contains("id=\"dbpedia-test\"><question")){ string=string.replace("id=\"dbpedia-test\"><question", ""); XMLType="dbpedia-test"; //System.out.println("dbpedia-test"); } + + else XMLType="dbpedia-train"; ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); String [] bla = string.split("</question><question"); for(String s : bla){ @@ -340,7 +351,10 @@ boolean yago=false; String id=""; - Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + /* + * Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + */ + Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<keywords\\>.*"); Matcher m1 = p1.matcher(s); //System.out.println(""); while(m1.find()){ @@ -349,7 +363,15 @@ Matcher m2 = p2.matcher(m1.group(1)); while(m2.find()){ //System.out.println("Query: "+ m2.group(1)); + query=m2.group(1); + query=query.replace("<![CDATA[", ""); + query=query.replace("]]>", ""); + query=query.replace("CDATA", ""); + query=query.replace("]", ""); + query=query.replace("!", ""); + query=query.replace(">", ""); + query=query.replace("<", ""); } Pattern p3= Pattern.compile("id=\"(.*)\" answer.*"); Matcher m3 = p3.matcher(m1.group(1)); @@ -395,14 +417,14 @@ queryInformation blaquery=new queryInformation(query, id,type,fusion,aggregation,yago,XMLType,hint); if(id!=""&&id!=null) querylist.add(blaquery); } - /* for(queryInformation s : querylist){ + for(queryInformation s : querylist){ System.out.println(""); if(s.getId()==""||s.getId()==null)System.out.println("NO"); System.out.println("ID: "+s.getId()); System.out.println("Query: "+s.getQuery()); System.out.println("Type: "+s.getType()); System.out.println("XMLType: "+s.getXMLtype()); - }*/ + } return querylist; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -24,6 +24,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class testClass_new { @@ -42,6 +43,8 @@ //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + TemplateBuilder testobject = new TemplateBuilder(btemplator, myindex); String filepath = "/home/swalter/Dokumente/Auswertung/"; @@ -84,7 +87,7 @@ //} - long stop_template = System.currentTimeMillis(); + /* long stop_template = System.currentTimeMillis(); long start_iteration = System.currentTimeMillis(); long time_generatingElements=0; @@ -97,7 +100,7 @@ time_part2+=t.getTime_part2(); try{ //t.getElm().printAll(); - ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN",myindex,wordnet); t.setHypothesenLevensthein(blub); //t.printAll(); @@ -106,8 +109,8 @@ } - } - long stop_iteration = System.currentTimeMillis(); + }*/ + /*long stop_iteration = System.currentTimeMillis(); System.out.println("The Iteration and Levensthein Mode took "+ (stop_iteration-start_iteration)+"ms"); System.out.println("The Iteration and Levensthein Mode took for one Template "+ (stop_iteration-start_iteration)/temp_list_result.size()+"ms"); float time_template =stop_template-start_template; @@ -120,7 +123,7 @@ System.out.println("Average Time part1 "+ (time_part1/temp_list_result.size())+"ms"); System.out.println("Average Time part2 "+ (time_part2/temp_list_result.size())+"ms"); System.out.println("Time getting Properties etc "+ (time_generatingElements)+"ms"); - System.out.println("DONE"); + System.out.println("DONE");*/ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,9 +3,14 @@ import java.sql.SQLException; import java.util.ArrayList; +import net.didion.jwnl.JWNLException; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; /** * Gets Elements, Condition and Hypothesen and returns HypothesenSets. @@ -23,7 +28,7 @@ * @return ArrayList<ArrayList<Hypothesis>> * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ boolean gotResource=true; ArrayList<ElementList> resources = new ArrayList<ElementList>(); @@ -142,10 +147,14 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); @@ -159,7 +168,7 @@ } - if(h.getType().contains("isA")){ + if(h.getType().contains("ISA")){ /* * TODO:Add special case, if we have only one condition but with an isA in it. */ @@ -180,7 +189,7 @@ * Dont look for line, where e.g. ?x isA ?y */ //get(1) is the middle Term and if there is an isa, than its there - if(!cl.get(1).contains("isA")){ + if(!cl.get(1).contains("ISA")){ for(String s : cl){ if(s.contains(h.getVariable())){ propertyVariableList.add(s); @@ -199,6 +208,7 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable); for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); } catch (Exception e) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.5; + private final static double LevenstheinMin=0.85; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,8 +1,241 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.didion.jwnl.JWNLException; +import net.didion.jwnl.data.POS; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; + public class WordnetModule { - private int explorationdepthwordnet =2; + private static int explorationdepthwordnet =2; + public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException, + JWNLException { + ArrayList<Hypothesis> listOfNewHypothesen = new ArrayList<Hypothesis>(); + + System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + if(property_to_compare_with.contains("_")){ + String[] fix = property_to_compare_with.split("_"); + //here add also lemmatiser + for(String s: fix) semantics.add(s); + } + else semantics.add(property_to_compare_with); + System.out.println("Semantics: "+ semantics); + + for(String s: semantics){ + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + //String _temp_=myindex.getWordnetHelp(property); + String _temp_=myindex.getWordnetHelp(s); + if(_temp_!=null){ + //tmp_semantics=semantics; + tmp_semantics.add(_temp_); + tmp_semantics.add(s); + } + else tmp_semantics.add(s); + /* + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + }*/ + } + + System.out.println("tmp_semantics: "+ tmp_semantics); + Boolean goOnAfterWordnet = true; + + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics,wordnet); + System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); + if (tmp_semantics==null){ + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + } + + } catch (IOException e) { + + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + + } + if(goOnAfterWordnet==true){ + + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + key=key.replace("\"",""); + key=key.replace("@en",""); + + for(String b : semantics){ + if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ + if(!result_SemanticsMatchProperties.contains(key)){ + result_SemanticsMatchProperties.add(key); + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + } + } + } + + } + + return listOfNewHypothesen; + } + + private static ArrayList<String> getSemantics (ArrayList<String> semanticsOrig,WordNet wordnet) throws IOException, JWNLException { + ArrayList<String> result = new ArrayList<String>(); + + //System.out.println("in function get Semantics!"); + + ArrayList<String> semantics = new ArrayList<String>(); + semantics=semanticsOrig; + //also look at the stemmt part! + /*for(String s: semanticsOrig){ + String bla=lemmatiser.stem(s); + semantics.add(bla); + semantics.add(s); + }*/ + + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics"); + //System.out.println("ID :"+id); + + //add id also to the result, if its not already in there + if(!result.contains(id))result.add(id); + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + + //System.out.println("Wordnet Word: "+id); + try{ + array_relatedNouns =wordnet.getRelatedNouns(id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, id); + //System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + + } + } + catch(Exception e){ + return null; + } + + if(!result.isEmpty()) return result; + else{ + //System.out.println("Didnt find ") + /*this is the case, if the first time nothing was found. + * but sometimes wordnet doesnt find anything e.g. die place... bzt you have also die and place + * so we try to find the seperate words and test them as well + */ + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics TWO"); + String[] tmp_array=id.split(" "); + //System.out.println("ID TWO:"+id); + if(tmp_array.length>=2){ + for(String advanced_id : tmp_array){ + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + //add id also to the result, if its not already in there + if(!result.contains(advanced_id))result.add(advanced_id); + + try{ + array_relatedNouns =wordnet.getRelatedNouns(advanced_id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, advanced_id); + // System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + } + } + + } + } + catch(Exception e){ + if(result.isEmpty()) return semanticsOrig; + } + + } + + if(!result.isEmpty()) return result; + else return null; + // else{ return result;} + } + + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |