From: <seb...@us...> - 2011-12-11 11:37:37
|
Revision: 3497 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3497&view=rev Author: sebastianwtr Date: 2011-12-11 11:37:29 +0000 (Sun, 11 Dec 2011) Log Message: ----------- [tbsl expolration] found error in Sqlite function Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2011-12-11 09:24:58 UTC (rev 3496) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2011-12-11 11:37:29 UTC (rev 3497) @@ -31,6 +31,9 @@ * @throws IOException */ private HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) throws IOException{ + + System.out.println("Resource die gesucht wird: "+ vergleich); + System.out.println("Seite die gesucht wird: "+side); /* * * For the second Iteration, I can just add the sparql property here. @@ -53,12 +56,13 @@ //System.out.println("property right!!! : " +tmp_right); String tmp_right="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String verarbeitungsstring=null; - if(side.contains("RIGHT")) verarbeitungsstring=tmp_right; - if(side.contains("LEFT")) verarbeitungsstring=tmp_left; + String verarbeitungsurl=null; + if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; + if(side.contains("LEFT")) verarbeitungsurl=tmp_left; + System.out.println(verarbeitungsurl); //just in case..... - if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsstring=tmp_left; + if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; //String verarbeitungsstring="http://greententacle.techfak.uni-bielefeld.de:5171/sparql?default-graph-uri=&query=PREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0APREFIX+res%3A+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2F%3E%0D%0A%0D%0ASELECT+DISTINCT+%3Fp+%3Fl+WHERE++{%0D%0A+{+res%3A"+vergleich+"+%3Fp+%3Fo+.+}%0D%0A+UNION%0D%0A+{+%3Fs+%3Fp+res%3A"+vergleich+"+.+}%0D%0A+{+%3Fp+rdfs%3Alabel+%3Fl+.+}%0D%0A}%0D%0A&format=text%2Fhtml&debug=on&timeout="; URL url; @@ -69,7 +73,7 @@ String result=""; try { - url = new URL(verarbeitungsstring); + url = new URL(verarbeitungsurl); is = url.openStream(); isr = new InputStreamReader(is); r = new BufferedReader(isr); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-12-11 09:24:58 UTC (rev 3496) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2011-12-11 11:37:29 UTC (rev 3497) @@ -47,29 +47,31 @@ //global Variable dict //start counting with 0 - static int explorationdepthwordnet=1; + static int explorationdepthwordnet=2; static int iterationdepth =0; static int numberofanswers=1; - static double LvenstheinMin = 0.95; + static double LevenstheinMin = 0.8; static WordNet wordnet; BasicTemplator btemplator; Templator templator; -/* private static HashMap<String, String> hm = new HashMap<String, String>(); - private static HashMap<String, String> hm_new = new HashMap<String, String>();*/ private static mySQLDictionary myindex; - //Konstruktor public SparqlObject() throws MalformedURLException, ClassNotFoundException, SQLException{ wordnet = new WordNet(); System.out.println("Loading SPARQL Templator"); + // btemplator = new BasicTemplator(); + //wenn ich das nehme, dann gebe ich dem parser den ideal.... + //btemplator.UNTAGGED_INPUT = false; templator = new Templator(); System.out.println("Loading SPARQL Templator Done\n"); System.out.println("Start Indexing"); myindex = new mySQLDictionary(); System.out.println("Done:Indexing"); + + //normaly 1 setExplorationdepthwordnet(1); //eigentlich immer mit 0 initialisieren setIterationdepth(1); @@ -155,7 +157,7 @@ new InputStreamReader( new FileInputStream( "/tmp/testresult.txt" ) ) ); while( null != (s = in.readLine()) ) { - tmp=tmp+"\n"+s; + tmp+="\n"+s; } } catch( FileNotFoundException ex ) { } catch( Exception ex ) { @@ -198,7 +200,7 @@ new InputStreamReader( new FileInputStream( "/tmp/answer.txt" ) ) ); while( null != (s = in.readLine()) ) { - tmp=tmp+"\n"+s; + tmp+="\n"+s; } } catch( FileNotFoundException ex ) { } catch( Exception ex ) { @@ -221,6 +223,9 @@ * ################################################################################################# */ //Iterration 1 + /* + * Only Levensthein!!! + */ if(getIterationdepth()==1&&startIterating==true){ /* //4, because of query + three conditions for the simple case @@ -240,7 +245,7 @@ */ //Iterration 2 /* - * Only Levensthein!!! + * Only Wordnet!!! */ if(getIterationdepth()==2&&startIterating==true){ if(querylist.size()==4)final_answer=simpleWordnetIteration(querylist, query); @@ -260,7 +265,7 @@ new FileInputStream( "/tmp/answer" ) ) ); String s; while( null != (s = in.readLine()) ) { - tmp=tmp+"\n"+s; + tmp+="\n"+s; } } catch( FileNotFoundException ex ) { } catch( Exception ex ) { @@ -277,7 +282,7 @@ String out=""; for(String answer : final_answer){ //only answered question - if(!answer.contains("Error in searching Wordnet with word") && !answer.contains("EmtyAnswer")&& !answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; + //if(!answer.contains("Error in searching Wordnet with word") && !answer.contains("EmtyAnswer")&& !answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; /* //only questions with wordnet error @@ -289,8 +294,8 @@ //only questions with Error in Properties // if(answer.contains("Error in getting Properties"))out=out+ "\n"+answer+"\n"; + out+= "\n"+answer+"\n"; - } System.out.println(question); System.out.println(out); @@ -305,9 +310,8 @@ private ArrayList<String> simpleLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { - //asking server - String answer; - ArrayList<String> final_answer=new ArrayList<String>(); + + ArrayList<String> final_answer=new ArrayList<String>(); String resource=""; String property_to_compare_with=""; String sideOfProperty="LEFT"; @@ -334,54 +338,53 @@ } System.out.println("Property to compare:: "+ property_to_compare_with); System.out.println("Resource: "+ resource); - //contains uri AND string, every second is the string + + HashMap<String,String> properties = new HashMap<String, String>(); GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; + + System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); + + //gets Propertys left or right from the resource! try { - /* - * TODO: Have to check now, if we need a right Property or a left one - */ properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); if (properties==null){ - //final_answer.add("Error in getting Properties\n"); final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } - //System.out.println(properties); + + System.out.println("Properties from Resource "+resource+": "+properties); + } catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } if(goOnAfterProperty==true){ - //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. ArrayList<String> new_queries= new ArrayList<String>(); + //iterate over properties for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - double tmp=Levenshtein.computeLevenshteinDistance(property_to_compare_with.toLowerCase(), key); + String key = entry.getKey(); + String value = entry.getValue(); + //compare property gotten from the resource with the property from the original query double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); - /* - * TODO: Implement Normalised levensthein - */ - //if(tmp<=3.0){ - if(nld>=LvenstheinMin){ - //alte property uri mit neuer ersetzen: - String query_tmp=query; - String test = getUriFromIndex(property_to_compare_with.toLowerCase(),1); - //query_tmp=query_tmp.replace(test,properties.get(i-1)); - query_tmp=query_tmp.replace(test,value); - new_queries.add(query_tmp); + //check if nld is greater than Levensthein + if(nld>=LevenstheinMin){ + //if its so, replace old uri with the new one + String querynew=query; + String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + querynew=querynew.replace(replacement,value); + System.out.println("Simple Levensthein Query: "+ querynew); + new_queries.add(querynew); } } - + + //iterate over all Queries and get answer from Server for(String anfrage : new_queries){ String answer_tmp; answer_tmp=sendServerQuestionRequest(anfrage); @@ -396,15 +399,8 @@ private ArrayList<String> complexeLevinstheinIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { - - /* - * in this case we need a inner and outer loop, because the properties are different from the resource or up side down - * Only for questions with two sets of conditions(s p o . s p o) - */ - - //asking server - String answer; - ArrayList<String> final_answer=new ArrayList<String>(); + + ArrayList<String> final_answer=new ArrayList<String>(); String resourceOne=""; String property_to_compare_withOne=""; String resourceTwo=""; @@ -416,6 +412,8 @@ int tmpcounter=0; for(String s : querylist){ //we dont need the first one, because thats the query itself + + //for condition One tmpcounter=tmpcounter+1; if(tmpcounter>=1&&tmpcounter<=4){ if(s.contains("LEFT")){ @@ -431,6 +429,8 @@ } } + + //for condition Two if(tmpcounter>4){ if(s.contains("LEFT")){ sideOfPropertyTwo="LEFT"; @@ -450,19 +450,19 @@ HashMap<String,String> propertiesTwo = new HashMap<String, String>(); GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; + + //Get Properties for Resource in condition One and Two from Server try { propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); + if (propertiesOne==null){ - //final_answer.add("Error in getting Properties\n"); - final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } - //System.out.println(properties); + } catch (IOException e) { - //e.printStackTrace(); final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; @@ -471,55 +471,51 @@ if(goOnAfterProperty==true){ - //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); + //Iterate over property from resource one for (Entry<String, String> entryOne : propertiesOne.entrySet()) { String queryOne=query; String keyOne = entryOne.getKey(); String valueOne = entryOne.getValue(); - //double levnstheinDistanzeOne=Levenshtein.computeLevenshteinDistance(property_to_compare_withOne.toLowerCase(), keyOne); - //if(levnstheinDistanzeOne<=3.0){ + + double levnstheinDistanzeOne=Levenshtein.nld(property_to_compare_withOne.toLowerCase(), keyOne); - - /* - * TODO: Implement Normalised levensthein - */ - //if(tmp<=3.0){ - if(levnstheinDistanzeOne>=LvenstheinMin){ + + /*if distance is higher or equals LevenstheinMin, replace old uri with new uri + * and use that new query, for the property of the second resource + */ + if(levnstheinDistanzeOne>=LevenstheinMin){ String test = getUriFromIndex(property_to_compare_withOne.toLowerCase(),1); queryOne=queryOne.replace(test,valueOne); } + /* + * Iterate now over the second set of properties, but this time not using the original query in which + * to replace the old uri with the new one, but using queryOne from the first step. + */ for (Entry<String, String> entryTwo : propertiesTwo.entrySet()) { String keyTwo = entryTwo.getKey(); String valueTwo = entryTwo.getValue(); - // double levnstheinDistanzeTwo=Levenshtein.computeLevenshteinDistance(property_to_compare_withTwo.toLowerCase(), keyTwo); - - /* - * TODO: Implement Normalised levensthein - */ - //if(levnstheinDistanzeTwo<=3.0){ - double levnstheinDistanzeTwo=Levenshtein.nld(property_to_compare_withTwo.toLowerCase(), keyTwo); + + //again calculate the nld with the property from the second condition and the property from the propertyset + double levnstheinDistanzeTwo=Levenshtein.nld(property_to_compare_withTwo.toLowerCase(), keyTwo); - /* - * TODO: Implement Normalised levensthein - */ - //if(tmp<=3.0){ - if(levnstheinDistanzeTwo>=0.9){ - //alte property uri mit neuer ersetzen: - String queryTwo=queryOne; - String test = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); - queryTwo=queryTwo.replace(test,valueTwo); - new_queries.add(queryTwo); - } - + if(levnstheinDistanzeTwo>LevenstheinMin){ + String queryTwo=queryOne; + String replacement = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); + queryTwo=queryTwo.replace(replacement,valueTwo); + System.out.println("Complex Levensthein Query: "+ queryTwo); + new_queries.add(queryTwo); + } + } } - + //iterate over all Queries and get answer from Server for(String anfrage : new_queries){ String answer_tmp; answer_tmp=sendServerQuestionRequest(anfrage); @@ -534,16 +530,9 @@ private ArrayList<String> simpleWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { - //asking server - String answer; ArrayList<String> final_answer=new ArrayList<String>(); - /* - * First try the original query on the server. If that doesnt work, try it with Iteration - */ - answer=sendServerQuestionRequest(query); - - if(answer.contains("EmtyAnswer")){ + System.out.println("In simpleWordnetIteration"); String resource=""; String property_to_compare_with=""; @@ -571,28 +560,27 @@ } System.out.println("Property to compare:: "+ property_to_compare_with); System.out.println("Resource: "+ resource); - //contains uri AND string, every second is the string + + HashMap<String,String> properties = new HashMap<String, String>(); GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; try { properties=property.getPropertys(getUriFromIndex(resource.toLowerCase(),0),sideOfProperty); if (properties==null){ - //final_answer.add("Error in getting Properties\n"); - + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } - //System.out.println(properties); + } catch (IOException e) { - //e.printStackTrace(); final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } if(goOnAfterProperty==true){ - //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); @@ -600,6 +588,7 @@ ArrayList<String> tmp_semantics=new ArrayList<String>(); ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); semantics.add(property_to_compare_with); + System.out.println("Semantics: "+ semantics); //first check, if there is a singular form in the wordnet dictionary.. eg children -> child String _temp_=myindex.getWordnetHelp(property_to_compare_with); @@ -611,11 +600,21 @@ semantics.add(_temp_); tmp_semantics=semantics; } + + System.out.println("tmp_semantics: "+ tmp_semantics); Boolean goOnAfterWordnet = true; + + + System.out.println("##########################"); + System.out.println("properties for "+getUriFromIndex(resource.toLowerCase(),0)+": "+properties); + System.out.println("Property to compare with: "+property_to_compare_with); + System.out.println("Semantics: "+semantics); + System.out.println("##########################"); for(int i=0;i<=explorationdepthwordnet;i++){ try { tmp_semantics=getSemantics(tmp_semantics); + System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); if (tmp_semantics==null){ goOnAfterWordnet=false; final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); @@ -629,8 +628,7 @@ } } catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); + goOnAfterWordnet=false; final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semantics+" \n End"); @@ -646,19 +644,23 @@ for(String b : semantics){ if(key.contains(b.toLowerCase())){ + System.out.println("Hey, Iam in too!!!!!!!!!!!"); + //to check, if no property is used twice... if(!result_SemanticsMatchProperties.contains(key)){ //create new query - result_SemanticsMatchProperties.add(key); + System.out.println("Hey, Iam in!!!!!!!!!!!"); + result_SemanticsMatchProperties.add(key); String query_tmp=query; String test = getUriFromIndex(property_to_compare_with.toLowerCase(),1); query_tmp=query_tmp.replace(test,value); - System.out.println("New query after wordnet: "+ query_tmp); + System.out.println("Simple Wordnet Query: "+ query_tmp); new_queries.add(query_tmp); } } } } + //iterate over all Queries and get answer from Server for(String bla : new_queries){ String answer_tmp; answer_tmp=sendServerQuestionRequest(bla); @@ -667,25 +669,16 @@ } } } - } + return final_answer; } private ArrayList<String> complexWordnetIteration(ArrayList<String> querylist, String query) throws SQLException, JWNLException { - //asking server - String answer; ArrayList<String> final_answer=new ArrayList<String>(); - /* - * First try the original query on the server. If that doesnt work, try it with Iteration - */ - answer=sendServerQuestionRequest(query); - - if(answer.contains("EmtyAnswer")){ - String resourceOne=""; String property_to_compare_withOne=""; String resourceTwo=""; @@ -698,6 +691,7 @@ for(String s : querylist){ //we dont need the first one, because thats the query itself tmpcounter=tmpcounter+1; + //get resource and property from the first condtion if(tmpcounter>=1&&tmpcounter<=4){ if(s.contains("LEFT")){ sideOfPropertyOne="LEFT"; @@ -712,6 +706,7 @@ } } + //get resource and property from the second condtion if(tmpcounter>4){ if(s.contains("LEFT")){ sideOfPropertyTwo="LEFT"; @@ -729,24 +724,24 @@ } System.out.println("Property to compare:: "+ property_to_compare_withOne); System.out.println("Resource: "+ resourceOne); + HashMap<String,String> propertiesOne = new HashMap<String, String>(); HashMap<String,String> propertiesTwo = new HashMap<String, String>(); GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; + + //gets the properties for both conditions try { propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); if (propertiesOne==null){ - //final_answer.add("Error in getting Properties\n"); final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; } - //System.out.println(properties); + } catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - + final_answer.add("Begin:\n"+query +"\nError in getting Properties \n End"); goOnAfterProperty=false; @@ -756,7 +751,7 @@ /* * #################################### Semantics One############################################# */ - //property_to_compare_with mit der Liste der propertys vergleichen, und wenn der normalisierte Wert >= LvenstheinMin ist, einbauen und neue query erzeugen. + ArrayList<String> new_queries= new ArrayList<String>(); //System.out.println("Start Iterating Wordnet with "+property_to_compare_withOne+" and deept of "+explorationdepthwordnet); @@ -775,6 +770,8 @@ semanticsOne.add(_temp_One); tmp_semanticsOne=semanticsOne; } + + //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached Boolean goOnAfterWordnet = true; for(int i=0;i<=explorationdepthwordnet;i++){ @@ -793,8 +790,7 @@ } } catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); + goOnAfterWordnet=false; final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsOne+" \n End"); @@ -823,6 +819,7 @@ tmp_semanticsTwo=semanticsTwo; } + //get the "semantics" from wordnet. Iterate as long as the explorationdepthwordnet is reached for(int i=0;i<=explorationdepthwordnet;i++){ try { @@ -840,8 +837,7 @@ } } catch (IOException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); + goOnAfterWordnet=false; final_answer.add("Begin:\n"+query +"\n Error in searching Wordnet with word "+semanticsTwo+" \n End"); @@ -853,6 +849,8 @@ if(goOnAfterWordnet==true){ + + //start iterating over the propery sets for (Entry<String, String> entryOne : propertiesOne.entrySet()) { String keyOne = entryOne.getKey(); String valueOne = entryOne.getValue(); @@ -878,7 +876,7 @@ String queryTwo=queryOne; String replacementTwo = getUriFromIndex(property_to_compare_withTwo.toLowerCase(),1); queryTwo=queryTwo.replace(replacementTwo,valueTwo); - System.out.println("New query after wordnet: "+ queryTwo); + System.out.println("Complexe Wordnet Query: "+ queryTwo); new_queries.add(queryTwo); } } @@ -895,7 +893,7 @@ - + //iterate over all Queries and get answer from Server for(String bla : new_queries){ String answer_tmp; answer_tmp=sendServerQuestionRequest(bla); @@ -904,7 +902,6 @@ } } } - } return final_answer; } @@ -1033,8 +1030,8 @@ - /*System.out.println("Conditions: " + conditions); - System.out.println("Conditions_new: " + conditions_new);*/ + System.out.println("Conditions: " + conditions); + System.out.println("Conditions_new: " + conditions_new); String query_upside_down = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+temp.getQt().toString()+" "+selTerms+" WHERE {"+ conditions_new.replace("--","") +filters+ "}"; @@ -1163,14 +1160,33 @@ */ private String getUriFromIndex(String string, int fall) throws SQLException{ String result=null; + String tmp1=null; + String tmp2 = null; //just to be sure its only 0 or 1 if(fall!=0 && fall!=1) fall=0; if(fall==0){ - result=myindex.getResourceURI(string.toLowerCase()); + + //first try: take always the ontology if existing and not the Resource + tmp1=myindex.getResourceURI(string.toLowerCase()); + tmp2=myindex.getontologyClassURI(string.toLowerCase()); + System.out.println("URI from resource: "+tmp1); + System.out.println("URI from ontologyClass: "+tmp2); + + + System.out.println("value from http://dbpedia.org/resource/WikiLeaks : "+ myindex.getResourceURI("http://dbpedia.org/resource/WikiLeaks")); + System.out.println("value from author : "+ myindex.getResourceURI("author")); + if(tmp1!=null && tmp2!=null) result=tmp2; + if(tmp1!=null && tmp2==null) result=tmp1; + if(tmp1==null && tmp2!=null) result=tmp2; + //result=myindex.getResourceURI(string.toLowerCase()); if(result==null)result=myindex.getPropertyURI(string.toLowerCase()); } if(fall==1){ - result=myindex.getPropertyURI(string.toLowerCase()); + tmp1=myindex.getPropertyURI(string.toLowerCase()); + tmp2=myindex.getontologyURI(string.toLowerCase()); + if(tmp1!=null && tmp2!=null) result=tmp2; + if(tmp1!=null && tmp2==null) result=tmp1; + if(tmp1==null && tmp2!=null) result=tmp2; if(result==null){ result=myindex.getResourceURI(string.toLowerCase()); if(result!=null) result=result.replace("resource", "property"); @@ -1184,10 +1200,11 @@ if(result==null) { if(fall==1)return "http://dbpedia.org/property/"+tmp; if(fall==0)return "http://dbpedia.org/resource/"+tmp; - else{ + else{ + System.out.println("return result: "+result); return result; - } } + } else return result; } @@ -1198,22 +1215,62 @@ * TODO: if for example title,name,label is given, replace , and get for each thing the semantics * */ - private static ArrayList<String> getSemantics (ArrayList<String> semantics) throws IOException, JWNLException { + private static ArrayList<String> getSemantics (ArrayList<String> semanticsOrig) throws IOException, JWNLException { ArrayList<String> result = new ArrayList<String>(); - //result.clear(); - //try{ - try{ + + //System.out.println("in function get Semantics!"); + + ArrayList<String> semantics = new ArrayList<String>(); + semantics=semanticsOrig; + /*//check out, if in the semantics are still terms, with _ or , + //if so, split on _ and , and add them to the semantic list + for(String id :semanticsOrig){ + if(id.contains("_")){ + System.out.println("in _"); + String[] tmp=id.split("_"); + for(String i: tmp) if(!semantics.contains(i))semantics.add(i); + + //and also add a term without _ + if(!semantics.contains(id.replace("_"," ")))semantics.add(id.replace("_"," ")); + //remove old id + //semantics.remove(id); + } + if(id.contains(",")){ + System.out.println("in ,"); + String[] tmp=id.split(","); + for(String i: tmp) if(!semantics.contains(i))semantics.add(i); + //semantics.remove(id); + } + }*/ + 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; - List<String> array_siterterms=null; - //array.clear(); - System.out.println("Wordnet Word: "+id); + + 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){ + // + } + - array_siterterms=wordnet.getSisterTerms(POS.NOUN, id); if(array_relatedNouns!=null){ for(String i:array_relatedNouns){ @@ -1225,20 +1282,11 @@ if(!result.contains(i))result.add(i); } } - if(array_siterterms!=null){ - for(String i:array_siterterms){ - if(!result.contains(i))result.add(i); - } - } } - } - catch(Exception e){ - if(result.isEmpty()) return null; - } - + if(!result.isEmpty()) return result; else{ //System.out.println("Didnt find ") @@ -1248,20 +1296,33 @@ */ 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 tmp : tmp_array){ + for(String advanced_id : tmp_array){ List<String> array_relatedNouns=null; List<String> array_bestsynonyms=null; - List<String> array_siterterms=null; - //array.clear(); - //System.out.println("Wordnet Word: "+tmp); - array_relatedNouns =wordnet.getRelatedNouns(tmp); - - array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, tmp); + //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){ + // + } - array_siterterms=wordnet.getSisterTerms(POS.NOUN, tmp); - if(array_relatedNouns!=null){ for(String i:array_relatedNouns){ if(!result.contains(i))result.add(i); @@ -1272,11 +1333,7 @@ if(!result.contains(i))result.add(i); } } - if(array_siterterms!=null){ - for(String i:array_siterterms){ - if(!result.contains(i))result.add(i); - } - } + } } @@ -1284,7 +1341,7 @@ } } catch(Exception e){ - if(result.isEmpty()) return null; + if(result.isEmpty()) return semanticsOrig; } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2011-12-11 09:24:58 UTC (rev 3496) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/mySQLDictionary.java 2011-12-11 11:37:29 UTC (rev 3497) @@ -22,6 +22,8 @@ createIndexPropertys(); createIndexResource(); createWordnetHelp(); + createIndexOntology(); + createIndexoOntologyClass(); //optional!! //createIndexWikipedia(); @@ -57,6 +59,38 @@ } + public String getontologyURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + public String getontologyClassURI(String string) throws SQLException{ + Statement stat = conn.createStatement(); + ResultSet rs; + try { + rs = stat.executeQuery("select uri from ontologyClass where name='"+string.toLowerCase()+"';"); + return rs.getString("uri"); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return null; + } + + + } + + + public String getWikipediaURI(String string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; @@ -197,40 +231,6 @@ prep.executeBatch(); conn.setAutoCommit(true); System.out.println("Done"); - //Statement stat = conn.createStatement(); - /* long start = System.currentTimeMillis(); - // zu messender Code - - ResultSet rs = stat.executeQuery("select * from people where name='kornyval';"); - while (rs.next()) - { - System.out.println("name = " + rs.getString("name")); - System.out.println("job = " + rs.getString("occupation")); - } - System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); - - start = System.currentTimeMillis(); - // zu messender Code - - rs = stat.executeQuery("select * from people where name='barack obama';"); - while (rs.next()) - { - System.out.println("name = " + rs.getString("name")); - System.out.println("job = " + rs.getString("occupation")); - } - System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); - - rs = stat.executeQuery("select * from people where name='kornyval';"); - while (rs.next()) - { - System.out.println("name = " + rs.getString("name")); - System.out.println("job = " + rs.getString("occupation")); - } - System.out.println("Duration in ms: " + (System.currentTimeMillis() - start)); - - - rs.close();*/ - // conn.close(); } private void createIndexPropertys() throws ClassNotFoundException, SQLException{ /*System.out.println("Start SQL test"); @@ -252,8 +252,8 @@ while( null != (s = in.readLine()) ) { String[] tmp_array =s.split(":::"); if(tmp_array.length>=2){ - prep.setString(1, tmp_array[1]); - prep.setString(2, tmp_array[0]); + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); prep.addBatch(); zaehler=zaehler+1; //if(zaehler%10000==0) System.out.println(zaehler); @@ -303,8 +303,8 @@ while( null != (s = in.readLine()) ) { String[] tmp_array =s.split(":::"); if(tmp_array.length>=2){ - prep.setString(1, tmp_array[1]); - prep.setString(2, tmp_array[0]); + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); prep.addBatch(); zaehler=zaehler+1; // if(zaehler%10000==0) System.out.println(zaehler); @@ -312,7 +312,7 @@ conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(false); - System.out.println("done"); + System.out.println("done"+zaehler); } } @@ -334,7 +334,113 @@ prep.executeBatch(); conn.setAutoCommit(true); System.out.println("Done"); + + } +private void createIndexOntology() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing Ontology"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists ontology;"); + stat.executeUpdate("create table ontology (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into ontology values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/ontology" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done" + zaehler); + } + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + + } + +private void createIndexoOntologyClass() throws ClassNotFoundException, SQLException{ + /*System.out.println("Start SQL test");*/ + System.out.println("start indexing ontologyClass"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists ontologyClass;"); + stat.executeUpdate("create table ontologyClass (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into ontologyClass values (?, ?);"); + BufferedReader in=null; + // conn.setAutoCommit(false); + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/ontologyClass" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + // if(zaehler%10000==0) System.out.println(zaehler); + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + System.out.println("done" + zaehler); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Done"); + + } + + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |