From: <seb...@us...> - 2012-06-20 12:49:01
|
Revision: 3762 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3762&view=rev Author: sebastianwtr Date: 2012-06-20 12:48:53 +0000 (Wed, 20 Jun 2012) Log Message: ----------- [tbsl exploration] submitting the last changes of the system Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -7,6 +7,7 @@ import java.util.Map; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.ElementStorage; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; @@ -103,7 +104,7 @@ } public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ - HashMap<String,Float> hm = new HashMap<String,Float>(); + //HashMap<String,Float> hm = new HashMap<String,Float>(); if(Setting.isDebugModus())DebugMode.debugPrint("######\n In search Index for Property"); // adding or set elements in Map by put method key and value pair @@ -113,13 +114,38 @@ map.put(23, 2.5f); map.put(64, 4.83f); */ - + ArrayList<String> result_List = new ArrayList<String>(); string=string.replace("_", " "); string=string.replace("-", " "); string=string.replace(".", " "); + if(string.contains("label")&&string.contains("name")){ + string="name"; + } + + /*String value= null; + value=ElementStorage.getStorage_property().get(string); + + if(value!=null){ + result_List.add(value); + return result_List; + } + else{*/ + String result_new= null; + if(Setting.isLoadedProperties()){ + try { + result_new = myindex.getManualPropertyURI(string); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(result_new!=null){ + result_List.add(result_new); + ElementStorage.addStorage_property(string, result_new); + return result_List; + } + } String result=null; String result2 = null; - ArrayList<String> result_List = new ArrayList<String>(); if(string.substring(string.length()-1).contains("s")){ String neuer_string = string.substring(0, string.length() -1); @@ -133,18 +159,19 @@ //tmp2=myindex.getYagoURI(neuer_string.toLowerCase()); if(result2!=null){ result_List.add(result2); - hm.put(result, 1.0f); + //hm.put(result, 1.0f); } else if(result!=null){ result_List.add(result); - hm.put(result, 1.0f); + ElementStorage.addStorage_property(string, result); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else{ if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); - hm.put(result, 0.0f); + //hm.put(result, 0.0f); } } else{ @@ -158,19 +185,22 @@ if(Setting.isDebugModus())DebugMode.debugPrint("Result: "+result); if(result2!=null){ result_List.add(result2); - hm.put(result, 1.0f); + //ElementStorage.addStorage_property(string, result2); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else if(result!=null){ result_List.add(result); - hm.put(result, 1.0f); + //ElementStorage.addStorage_property(string, result); + //hm.put(result, 1.0f); if(Setting.isDebugModus())DebugMode.debugPrint("Found uri for: "+string.toLowerCase()); } else{ if(Setting.isDebugModus())DebugMode.debugErrorPrint("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); - hm.put(result, 0.0f); + //ElementStorage.addStorage_property(string, "http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + //hm.put(result, 0.0f); } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -32,6 +32,7 @@ Class.forName( "org.sqlite.JDBC" ); conn = DriverManager.getConnection("jdbc:sqlite::memory:"); createIndexPropertys(); + createIndexManualPropertys(); createIndexResource(); createWordnetHelp(); createIndexOntology(); @@ -205,6 +206,30 @@ } + public String getManualPropertyURI(String string) throws SQLException, IOException{ + Statement stat = conn.createStatement(); + ResultSet rs; + string = string.replace("_"," "); + try { + rs = stat.executeQuery("select uri from manualproperty where name='"+string.toLowerCase()+"';"); + while(rs.next()){ + String result_string= rs.getString("uri"); + return result_string; + } + + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + //System.err.println("Error in SQLiteIndex.getProperty!!"); + + + return null; + } + + return null; + } + + public String getontologyURI(String string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; @@ -449,6 +474,61 @@ System.out.println("Done"); } + + + +private void createIndexManualPropertys() throws ClassNotFoundException, SQLException{ + System.out.println("start indexing ManualProperties"); + Statement stat = conn.createStatement(); + stat.executeUpdate("drop table if exists manualproperty;"); + stat.executeUpdate("create table manualproperty (name, uri);"); + PreparedStatement prep = conn.prepareStatement("insert into manualproperty values (?, ?);"); + BufferedReader in=null; + int zaehler=0; + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream( "/home/swalter/workspace/manualAddedProperties" ) ) ); + String s; + while( null != (s = in.readLine()) ) { + String[] tmp_array =s.split(":::"); + if(tmp_array.length>=2){ + prep.setString(1, tmp_array[0]); + prep.setString(2, tmp_array[1]); + prep.addBatch(); + zaehler=zaehler+1; + if(zaehler%1000000==0){ + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(false); + // System.out.println(zaehler+" done"); + } + + } + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + conn.setAutoCommit(false); + prep.executeBatch(); + conn.setAutoCommit(true); + System.out.println("Number of ManualProperty: "+zaehler); + System.out.println("Done"); + + } + + + private void createIndexResource() throws ClassNotFoundException, SQLException{ System.out.println("start indexing Resources"); Statement stat = conn.createStatement(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -2,8 +2,10 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import org.dllearner.algorithm.tbsl.exploration.Utils.DebugMode; +import org.dllearner.algorithm.tbsl.exploration.Utils.ElementStorage; import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.exploration_main.Setting; @@ -27,7 +29,7 @@ } public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ - + long start = System.currentTimeMillis(); /* * first all Classes! */ @@ -51,6 +53,8 @@ } if(Setting.isDebugModus())DebugMode.debugPrint("Created Elements"); + long stop = System.currentTimeMillis(); + Setting.addTime_elements(stop-start); } private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ @@ -64,13 +68,25 @@ * if isA is found and if Class has uri, get Elements */ if(h.getType().contains("ISA")&&h.getUri().contains("http")){ + if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Class: "+h.getName()+" Uri: "+h.getUri()); /* - * TODO: improver performance, using geschicktes zwischenspeichern + * Todo First Lookup an HashMap with if the resource is in it, if yes, take the results, + * if not, create new Elements */ - if(Setting.isDebugModus())DebugMode.debugPrint("Create Elements for Class: "+h.getName()+" Uri: "+h.getUri()); - ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); + if(ElementStorage.getStorage_classes().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName(),h.getUri(),ElementStorage.getStorage_classes().get(h.getUri())); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getElementsForGivenClass(h.getUri()); + ElementList el = new ElementList(h.getName(),h.getUri(),tmp_hm); + ElementStorage.addStorage_classes(h.getUri(), tmp_hm); + this.addElements(el); + } + //ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); - this.addElements(el); + //this.addElements(el); } } } @@ -90,18 +106,38 @@ for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { - ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); - //resources.add(el); - this.addElements(el); + if(ElementStorage.getStorage_resource_right().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ElementStorage.getStorage_resource_right().get(h.getUri())); + //resources.add(el); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT"); + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),tmp_hm); + ElementStorage.addStorage_resource_right(h.getUri(), tmp_hm); + //resources.add(el); + this.addElements(el); + } + + } if(h.getVariable().equals(cl.get(2))) { - /* - * TDO: Geht hier in die Schleife, aber die Liste wird nicht hinzugefügt.... - */ - ElementList el_left = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); - //resources.add(el); - //el_left.printAll(); - this.addElements(el_left); + + if(ElementStorage.getStorage_resource_left().containsKey(h.getUri())){ + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ElementStorage.getStorage_resource_left().get(h.getUri())); + //resources.add(el); + this.addElements(el); + } + else{ + HashMap<String,String> tmp_hm = new HashMap<String,String>(); + tmp_hm=ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT"); + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),tmp_hm); + ElementStorage.addStorage_resource_left(h.getUri(), tmp_hm); + //resources.add(el); + this.addElements(el); + } + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -47,8 +47,13 @@ ArrayList<Template> resultArrayList = new ArrayList<Template>(); Set<BasicQueryTemplate> querytemps =null; - querytemps = btemplator.buildBasicQueries(question); - + try{ + querytemps = btemplator.buildBasicQueries(question); + } + catch (Exception e){ + System.err.println("Error in Templategeneration"); + querytemps=null; + } /* * check if templates were build, if not, safe the question and delete it for next time from the xml file. @@ -83,7 +88,15 @@ long stop_template = System.currentTimeMillis(); + Setting.addTime_tbsl(stop_template-start); + + + + + + long start_builder = System.currentTimeMillis(); if(Setting.isDebugModus())DebugMode.waitForButton(); + if(querytemps!=null){ for (BasicQueryTemplate bqt : querytemps) { long start_part1= System.currentTimeMillis(); @@ -217,14 +230,10 @@ } if(slot.toString().contains("PROPERTY")){ - System.out.println("Slot.toString(): "+slot.toString()); String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); - System.out.println(tmp); String[] tmp_array = tmp.split(":"); if(tmp_array.length>1){ - System.out.println("tmp_array[0]:"+tmp_array[0]); - System.out.println("tmp_array[1]:"+tmp_array[1]); Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); list_of_hypothesis.add(tmp_hypothesis); @@ -340,7 +349,6 @@ if(h.getType().contains("ISA")){ try { ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); - System.out.println("Laenge tmp: "+tmp.size()); if(tmp.size()>0){ h.setUri(tmp.get(0)); h.setRank(1.0); @@ -354,7 +362,6 @@ if(h.getType().contains("RESOURCE")){ try { ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); - System.out.println("Laenge tmp: "+tmp.size()); if(tmp.size()>0){ h.setUri(tmp.get(0)); h.setRank(1.0); @@ -453,10 +460,13 @@ } } - + long stop_builder = System.currentTimeMillis(); + Setting.addTime_builder(stop_builder-start_builder); if(Setting.isDebugModus())DebugMode.printTemplateList(resultArrayList, "Templates nach allen Verarbeitungsschritten"); return resultArrayList; } + return resultArrayList; + } } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ElementStorage.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -0,0 +1,63 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.HashMap; + +public class ElementStorage { +private static HashMap<String,HashMap<String,String>> storage_classes = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,HashMap<String,String>> storage_resource_right = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,HashMap<String,String>> storage_resource_left = new HashMap<String,HashMap<String,String>> (); +private static HashMap<String,String> storage_property= new HashMap<String,String> (); + +/* + * First String contains URI + */ +public static HashMap<String,HashMap<String,String>> getStorage_classes() { + return storage_classes; +} + +public static void setStorage_classes(HashMap<String,HashMap<String,String>> storage_classes) { + ElementStorage.storage_classes = storage_classes; +} + +public static void addStorage_classes(String key, HashMap<String,String> value) { + ElementStorage.storage_classes.put(key, value); +} + +public static HashMap<String,HashMap<String,String>> getStorage_resource_right() { + return storage_resource_right; +} + +public static void setStorage_resource_right(HashMap<String,HashMap<String,String>> storage_resource_right) { + ElementStorage.storage_resource_right = storage_resource_right; +} + +public static void addStorage_resource_right(String key, HashMap<String,String> value) { + ElementStorage.storage_resource_right.put(key, value); +} + +public static HashMap<String,HashMap<String,String>> getStorage_resource_left() { + return storage_resource_left; +} + +public static void setStorage_resource_left(HashMap<String,HashMap<String,String>> storage_resource_left) { + ElementStorage.storage_resource_left = storage_resource_left; +} + +public static void addStorage_resource_left(String key, HashMap<String,String> value) { + ElementStorage.storage_resource_left.put(key, value); +} + +public static HashMap<String,String> getStorage_property() { + return storage_property; +} + +public static void setStorage_property(HashMap<String,String> storage_property) { + ElementStorage.storage_property = storage_property; +} + +public static void addStorage_property(String key, String value) { + ElementStorage.storage_property.put(key, value); +} + + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -1,5 +1,6 @@ package org.dllearner.algorithm.tbsl.exploration.Utils; +import java.io.IOException; import java.util.ArrayList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; @@ -46,16 +47,23 @@ for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; String Resource=null; + String PropertyName=null; + String Property=null; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ if(h.getType().toLowerCase().contains("resource")){ - Resource=h.getName(); + Resource=h.getUri(); } + if(h.getType().toLowerCase().contains("property")){ + PropertyName=h.getName(); + Property=h.getUri(); + } - condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); + condition_new=condition_new.replace(h.getVariable()+" ", "<"+h.getUri()+"> "); + /* * Dont create a Query with variables, which dont have a correct uri */ @@ -86,6 +94,8 @@ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+t.getQueryType()+" "+t.getSelectTerm()+"?string WHERE {"+ condition_new+" OPTIONAL { "+ t.getSelectTerm()+" rdfs:label ?string. FILTER (lang(?string) = 'en') }"+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); qp.setResource(Resource); + qp.setProperty(Property); + qp.setPropertyName(PropertyName); if(addQuery)queryList.add(qp); } @@ -93,6 +103,8 @@ String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); QueryPair qp = new QueryPair(query,global_rank); qp.setResource(Resource); + qp.setProperty(Property); + qp.setPropertyName(PropertyName); if(addQuery)queryList.add(qp); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -3,6 +3,8 @@ public class QueryPair { private String Query; private String Resource; + private String Property; + private String PropertyName; private double rank; public String getQuery() { return Query; @@ -32,6 +34,18 @@ public void setResource(String resource) { Resource = resource; } + public String getProperty() { + return Property; + } + public void setProperty(String property) { + Property = property; + } + public String getPropertyName() { + return PropertyName; + } + public void setPropertyName(String propertyName) { + PropertyName = propertyName; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -15,9 +15,10 @@ public class ServerUtil { - //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; //private static String server_Prefix="http://dbpedia.org/sparql"; private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8897/sparql"; //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; private static int timeToTimeoutOnServer=3000; @@ -108,6 +109,7 @@ String result=""; /*System.out.println(verarbeitungsurl); System.out.println("side: "+ side);*/ + // System.out.println(verarbeitungsurl); result = getListOfElements(verarbeitungsurl); return generateList(result); @@ -121,26 +123,7 @@ */ public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ - /* - PREFIX dbo: <http://dbpedia.org/ontology/> -SELECT DISTINCT ?p WHERE { - { ?x ?p ?y . } UNION { ?y ?p ?x . } - { - SELECT ?x { - ?x rdf:type dbo:Mountain . - } - LIMIT 10 - } -} -ORDER BY ?x - - - TODO:Try with different Limits - */ - /* - * TODO: Still a not "valid" url - */ String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?p rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; //System.out.println(query); //DebugMode.waitForButton(); @@ -243,8 +226,8 @@ } public static ArrayList<String> requestAnswerFromServer(String query){ + query=query.replace(">0",">"); String query_url=server_Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; - //System.out.println(tmp); String result=""; HttpURLConnection connection = null; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -11,6 +11,8 @@ import java.sql.SQLException; import java.util.ArrayList; +import net.didion.jwnl.JWNLException; + import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; @@ -31,6 +33,12 @@ public class MainInterface { //private static int anzahlAbgeschickterQueries = 10; + private static ArrayList<Template> global_template_list=new ArrayList<Template>(); + private static BasicTemplator btemplator_global; + private static SQLiteIndex myindex_global; + private static WordNet wordnet_global; + private static StanfordLemmatizer lemmatiser_global; + private static String type_global=""; public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ @@ -87,6 +95,8 @@ //generate QueryPair String Question=""; + + //TODO: parallel here? for(Template t : template_list){ Question=t.getQuestion(); t.printAll(); @@ -110,6 +120,10 @@ //if(Setting.isDebugModus())printQueries(qp, "NORMAL", Question); //printQueries(qp, "NORMAL", Question); Setting.setAnzahlAbgeschickterQueries(10); + System.out.println("Following Querries were created:"); + for(QueryPair q : qp){ + System.out.println(q.getQuery()+" rank:"+q.getRank()); + } int anzahl=1; boolean go_on = true; @@ -124,6 +138,9 @@ go_on=false; //if(qp.size()<3)go_on=true; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(Setting.isTagging()) write_ResourcePropertyInformation(q.getResource(),q.getPropertyName(),q.getProperty()); + + //printSingleQuery(q.getQuery(),Question); //go_on=true; boolean contains_uri=false; for(String s : answer_tmp){ @@ -162,6 +179,8 @@ System.out.println(answer); } if(wait)DebugMode.waitForButton(); + + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ @@ -190,6 +209,7 @@ if(wait)DebugMode.waitForButton(); } + if(answers.isEmpty()&&Setting.getModuleStep()>=5){ System.out.println("NO Answer from Server =>Start Query Manipulation"); answers.clear(); @@ -202,7 +222,6 @@ - /* * return answers! */ @@ -229,23 +248,65 @@ boolean special=false; int anzahl; boolean go_on; - /*if(type.contains("SPECIAL")){ - type ="LEVENSTHEIN"; - special=true; - }*/ System.out.println("No answer from direkt match, start "+type+"Modul"); + + /*ArrayList<Thread> thread_list = new ArrayList<Thread>(); + ThreadGroup group = new ThreadGroup("QA-Threads"); + int anzahl_thread=0; + global_template_list.clear(); + global_template_list=template_list; + myindex_global=myindex; + wordnet_global=wordnet; + lemmatiser_global=lemmatiser; + type_global=type; + for(Template t : template_list){ + final int anzahl_thread_new=anzahl_thread; + + Thread t1; + try { + t1 = new Thread(group,String.valueOf(anzahl_thread)) + { + String blub=do_something(anzahl_thread_new); + }; + + thread_list.add(t1); + t1.start(); + + + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + anzahl_thread+=1; + + } + */ + + /* + * NOw wait until all are finished + */ + + /*for(int i =0; i<thread_list.size();i++){ + try { + thread_list.get(i).join(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }*/ + + + for(Template t : template_list){ try{ - /*if(test.contains("alt")){ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); - if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); - if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); - if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); - }*/ - //if(test.contains("neu")){ - // System.err.println("IN NEU!!!!!"); ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); @@ -275,6 +336,8 @@ } + + /* * Generate Queries and test queries */ @@ -299,12 +362,12 @@ //sort QueryPairs qp=LinearSort.doSort(qp); + qp=HeuristicSort.doHeuristicSort(qp, Question); //printQueries(qp, type, Question); - qp=HeuristicSort.doHeuristicSort(qp, Question); System.out.println("Following Querries were created:"); - for(QueryPair z : qp){ - System.out.println(z.getQuery()+" "+z.getRank()); + for(QueryPair q : qp){ + System.out.println(q.getQuery()+" rank:"+q.getRank()); } if(Setting.isDebugModus())printQueries(qp, type, Question); //printQueries(qp, type, Question); @@ -324,6 +387,8 @@ go_on=false; System.out.println("Got Answer from Server with this Query: "+ q.getQuery()); + if(Setting.isTagging()) write_ResourcePropertyInformation(q.getResource(),q.getPropertyName(),q.getProperty()); + //printSingleQuery(q.getQuery(),Question); if(qp.size()>(id+1)){ //&&anzahl<2 if(q.getRank()==qp.get(id+1).getRank()){ @@ -480,7 +545,7 @@ } private static void printQueries(ArrayList<QueryPair> qp, String type, String Question){ - String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQueryListNLD"+Setting.getLevenstheinMin()+".txt"; + /*String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQuery"+Setting.getLevenstheinMin()+".txt"; String result_string =""; //Open the file for reading try { @@ -508,7 +573,7 @@ /* * write only the first 10 queries: */ - for(QueryPair q : qp){ + /* for(QueryPair q : qp){ if(anzahl<10){ querylist+=q.getQuery()+" "+q.getRank()+"\n"; anzahl+=1; @@ -535,7 +600,54 @@ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); + }*/ + } + + + + private static void printSingleQuery(String query,String Question){ + /*String dateiname="/home/swalter/Dokumente/Auswertung/WorkingQuery"+Setting.getLevenstheinMin()+".txt"; + String result_string =""; + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + result_string+=thisLine+"\n"; + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + + File file = new File(dateiname); + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + + try { + bw.write(result_string+Question+" "+query+"\n"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ } @@ -767,6 +879,115 @@ } + + if(t.getCondition().size()>=30){ + ArrayList<ArrayList<Hypothesis>> new_hypothesen_list = new ArrayList<ArrayList<Hypothesis>>(); + for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ + /* + * if greater 2, than it means, there are at least 3 propertys/resources or whatever + */ + + /* + * Resource ?x + * Property ?y + * Select auf ?z + */ + if(h_l.size()>2){ + if(h_l.get(0).getUri().contains("resource")){ + Hypothesis h_r= h_l.get(0); + Hypothesis h_p1= h_l.get(1); + Hypothesis h_p2= h_l.get(2); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + } + else if(h_l.get(1).getUri().contains("resource")){ + Hypothesis h_r= h_l.get(1); + Hypothesis h_p1= h_l.get(0); + Hypothesis h_p2= h_l.get(2); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + } + else{ + Hypothesis h_r= h_l.get(2); + Hypothesis h_p1= h_l.get(1); + Hypothesis h_p2= h_l.get(0); + h_r.setVariable("?x"); + h_p1.setVariable("?y"); + h_p2.setVariable("?y"); + ArrayList<Hypothesis> list_one = new ArrayList<Hypothesis>(); + ArrayList<Hypothesis> list_two = new ArrayList<Hypothesis>(); + list_one.add(h_r); + list_one.add(h_p1); + new_hypothesen_list.add(list_one); + list_two.add(h_r); + list_two.add(h_p2); + new_hypothesen_list.add(list_two); + + } + } + } + + ArrayList<ArrayList<String>> condition_new=new ArrayList<ArrayList<String>>(); + ArrayList<String> con = new ArrayList<String>(); + con.add("?x"); + con.add("?y"); + con.add("?z"); + condition_new.add(con); + + ArrayList<ArrayList<String>> condition_new_r=new ArrayList<ArrayList<String>>(); + ArrayList<String> con_r = new ArrayList<String>(); + con_r.add("?z"); + con_r.add("?y"); + con_r.add("?x"); + condition_new_r.add(con_r); + + + + Template template_new = new Template(condition_new,"SELECT", t.getHaving(), t.getFilter(), "?z", t.getOrderBy(), t.getLimit(), t.getQuestion()); + template_new.setHypothesen(new_hypothesen_list); + template_new.setElm(t.getElm()); + + Template template_new_r = new Template(condition_new_r,"SELECT", t.getHaving(), t.getFilter(), "?z", t.getOrderBy(), t.getLimit(), t.getQuestion()); + template_new_r.setHypothesen(new_hypothesen_list); + template_new_r.setElm(t.getElm()); + + Elements elm = new Elements(template_new.getCondition(),template_new.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + template_new.setElm(elm); + new_template_list.add(template_new); + } + + Elements elm_r = new Elements(template_new.getCondition(),template_new.getHypothesen()); + if(elm.isElementEmty()==false){ + //elm.printAll(); + template_new_r.setElm(elm_r); + new_template_list.add(template_new_r); + } + + + + //new_template_list.add(template_new); + //new_template_list.add(template_new_r); + } } /* @@ -785,4 +1006,80 @@ return answers; } + + + private static String do_something(int number) throws SQLException, JWNLException, IOException{ + //String str_number=Thread.currentThread().getName(); + //System.out.println("ThreadName: "+str_number); + //int number= Integer.parseInt(str_number); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); + + + for(ArrayList<Hypothesis> l_h : global_template_list.get(number).getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); + generated_hypothesis= IterationModule.new_iteration(global_template_list.get(number).getElm(),l_h,global_template_list.get(number).getCondition(),type_global,myindex_global,wordnet_global,lemmatiser_global); + for(ArrayList<Hypothesis> h_t : generated_hypothesis){ + ArrayList<Hypothesis> new_hypothesen_set = new ArrayList<Hypothesis>(); + for(Hypothesis bla : h_t){ + new_hypothesen_set.add(bla); + } + hypothesenSetList.add(new_hypothesen_set); + } + + //hypothesenSetList.addAll(blub); + } + if(type_global.contains("WORDNET"))global_template_list.get(number).setHypothesenWordnet(hypothesenSetList); + if(type_global.contains("LEVENSTHEIN"))global_template_list.get(number).setHypothesenLevensthein(hypothesenSetList); + if(type_global.contains("RELATE"))global_template_list.get(number).setHypothesenRelate(hypothesenSetList); + return "DONE"; + + } + + private static void write_ResourcePropertyInformation(String Resource, String PropertyName, String Property){ + String dateiname="/home/swalter/Dokumente/Auswertung/ResourcePropertyRelation.txt"; + String result_string =""; + //Open the file for reading + try { + BufferedReader br = new BufferedReader(new FileReader(dateiname)); + String thisLine; + while ((thisLine = br.readLine()) != null) { // while loop begins here + result_string+=thisLine+"\n"; + } // end while + } // end try + catch (IOException e) { + System.err.println("Error: " + e); + } + + + + File file = new File(dateiname); + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(file)); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + + + + try { + bw.write(result_string+Resource+"::"+PropertyName+"::"+Property+"\n"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + bw.flush(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + bw.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/Setting.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -14,9 +14,15 @@ private static boolean loadedProperties; private static int version; private static boolean saveAnsweredQueries; + private static boolean tagging; + private static boolean loadTagging; + private static long time_tbsl; + private static long time_builder; + private static long time_elements; + public static boolean isWaitModus() { return waitModus; } @@ -90,6 +96,54 @@ public static void setSaveAnsweredQueries(boolean saveAnsweredQueries) { Setting.saveAnsweredQueries = saveAnsweredQueries; } + public static long getTime_tbsl() { + return time_tbsl; + } + public static void setTime_tbsl(long time_tbsl) { + Setting.time_tbsl = time_tbsl; + } + + public static void addTime_tbsl(long time_tbsl) { + long tmp=getTime_tbsl(); + Setting.time_tbsl = time_tbsl+tmp; + } + public static long getTime_builder() { + return time_builder; + } + public static void setTime_builder(long time_builder) { + Setting.time_builder = time_builder; + } + + public static void addTime_builder(long time_builder) { + long tmp=getTime_builder(); + Setting.time_builder = time_builder+tmp; + } + public static long getTime_elements() { + return time_elements; + } + public static void setTime_elements(long time_elements) { + Setting.time_elements = time_elements; + } + + public static void addTime_elements(long time_elements) { + long tmp = getTime_elements(); + Setting.time_elements = time_elements+tmp; + } + public static boolean isTagging() { + //if(isLoadTagging()) return false; + return tagging; + } + public static void setTagging(boolean tagging) { + Setting.tagging = tagging; + } + public static boolean isLoadTagging() { + if(isTagging())return false; + else return loadTagging; + } + public static void setLoadTagging(boolean loadTagging) { + Setting.loadTagging = loadTagging; + } + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -9,6 +9,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintStream; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,6 +45,9 @@ System.out.println("Starting Main File"); long startInitTime = System.currentTimeMillis(); + //PrintStream err = new PrintStream(new FileOutputStream("/home/swalter/Dokumente/ERRListe.txt")); + //System.setErr(err); + /* * Initial Index and Templator */ @@ -66,6 +70,7 @@ Setting.setThresholdSelect(0.5); Setting.setLoadedProperties(false); Setting.setSaveAnsweredQueries(false); + Setting.setTagging(false); //default //Setting.setVersion(1); /* @@ -73,7 +78,7 @@ * 2= "Normal" + Levensthein * 3= Normal+Levensthein+Wordnet */ - Setting.setModuleStep(5); + Setting.setModuleStep(4); Setting.setEsaMin(0.4); @@ -84,7 +89,7 @@ boolean startQuestioning = true; while(schleife==true){ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - String line; + String line=""; startQuestioning = true; try { System.out.println("\n\n"); @@ -134,35 +139,40 @@ } - + if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); + + float global_tbsl_avaerage = 0; + float global_builder_average=0; - //for(int i = 1; i<2;i++){ + for(int i = 1; i<2;i++){ //double min = 0.95; //min+=(i*0.05); - /*if(i==1){ + if(i==1){ line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; } if(i==2){ line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; - }*/ + } - line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-tagged-new.xml"; + //line="/home/swalter/Dokumente/Auswertung/Yahoo/works"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-test-new-tagged2.xml"; for(int j=1;j<2;j++){ - Setting.setVersion(1); + //Setting.setVersion(99); - for(int z=1;z<7;z++){ + for(int z=4;z<5;z++){ //Setting.setLevenstheinMin(min); Setting.setLevenstheinMin(0.95); //Setting.setThresholdSelect(0.4); - Setting.setModuleStep(2); + Setting.setModuleStep(z); Setting.setThresholdSelect(0.5); - Setting.setEsaMin(0.0+(z/10.0)); + Setting.setEsaMin(0.4); Setting.setLoadedProperties(false); + Setting.setTagging(false); /*if(i==2)Setting.setLoadedProperties(true); else Setting.setLoadedProperties(false); */ @@ -174,6 +184,7 @@ ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); list_of_structs=generateStruct(line,true); + //list_of_structs=generateStructTextfile(line,true); //Start Time measuring long startTime = System.currentTimeMillis(); @@ -192,7 +203,18 @@ long stopTime = System.currentTimeMillis(); System.out.println("For "+anzahl+" Questions the QA_System took "+ ((stopTime-startTime)/1000)+"sek"); + System.out.println("Tbsl took overall: "+Setting.getTime_tbsl()+"ms"); + System.out.println("Builder took overall: "+Setting.getTime_builder()+"ms"); + int anzahl_questions=list_of_structs.size(); + System.out.println("Tbsl Average: "+Setting.getTime_tbsl()/anzahl_questions+"ms"); + System.out.println("Builder Average: "+Setting.getTime_builder()/anzahl_questions+"ms"); + System.out.println("Elements Average: "+Setting.getTime_elements()/anzahl_questions+"ms"); + System.out.println("OverallTime Average: "+(stopTime-startTime)/anzahl_questions+"ms"); + global_tbsl_avaerage+=Setting.getTime_tbsl()/anzahl_questions; + global_builder_average+=Setting.getTime_builder()/anzahl_questions; + + String filename=""; filename=createXML(list_of_structs,((stopTime-startTime)/1000)); String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/"+filename; @@ -237,16 +259,20 @@ - // } + } + System.out.println("Average Tbsl:"+global_tbsl_avaerage/4/1000); + System.out.println("Average Builder:"+global_builder_average/4/1000); /*schleife=false; System.out.println("Bye!"); System.exit(0);*/ } + //else else if(schleife==true && startQuestioning ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); + //line="Give/VB me/PRP all/DT actors/NNS starring/VBG in/IN Batman/NNP Begins/NNP"; MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! @@ -260,6 +286,7 @@ } long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); + //System.exit(0); } } catch (IOException e) { @@ -539,5 +566,53 @@ } + +private static ArrayList<queryInformation> generateStructTextfile(String filename, boolean hint) { + + + + BufferedReader in = null; + ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); + String tmp=""; + // Lies Textzeilen aus der Datei in einen Vector: + try { + in = new BufferedReader( + new InputStreamReader( + new FileInputStream(filename) ) ); + String s; + int anzahl=0; + String XMLType="dbpedia-train"; + while( null != (s = in.readLine()) ) { + anzahl+=1; + queryInformation blaquery=new queryInformation(s.replace("\n", ""), Integer.toString(anzahl),"",false,false,false,XMLType,false); + querylist.add(blaquery); + } + } catch( FileNotFoundException ex ) { + } catch( Exception ex ) { + System.out.println( ex ); + } finally { + if( in != null ) + try { + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + + + + for(queryInformation s : querylist){ + System.out.println(""); + if(s.getId()==""||s.getId()==null)System.out.println("NO"); + System.out.println("ID: "+s.getId()); + System.out.println("Query: "+s.getQuery()); + System.out.println("Type: "+s.getType()); + System.out.println("XMLType: "+s.getXMLtype()); + } + return querylist; + } + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -109,7 +109,6 @@ e1.printStackTrace(); }*/ if(givenConditionList.size()==1){ - System.err.println("Only one Condition => simple Struktur"); simple_structure=true; boolean resource_case=false; @@ -188,7 +187,6 @@ * two conditions! */ if(givenConditionList.size()==2){ - System.out.println("two Conditions => NOT simple Struktur"); ArrayList<ElementList> resources = new ArrayList<ElementList>(); boolean gotResource=true; try{ @@ -259,7 +257,6 @@ * */ if((condition1_exists_isa||condition2_exists_isa)&&gotResource&&(condition1_exists_resource||condition2_exists_resource)){ - System.err.println("CASE1"); String class_variable=null; String class_property_variable=null; ArrayList<String> working_condition=new ArrayList<String>(); @@ -345,7 +342,6 @@ * ISA */ else if((condition1_exists_isa||condition2_exists_isa)&&gotResource){ - System.err.println("CASE2"); /* * get Hypothese for the Class */ @@ -421,7 +417,6 @@ else if((condition1_exists_resource||condition2_exists_resource)&&gotResource){ - System.err.println("CASE3"); String property_name=""; String second_property_name=""; String property_variable=""; @@ -470,26 +465,26 @@ for(Hypothesis h_temp : resultHypothesenList) { String Query=""; if(property_side_new.contains("LEFT")){ - Query= "SELECT DISTINCT ?s ?x WHERE {<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + //{ [] foaf:name ?name1 } UNION { [] vCard:FN ?name2 } + Query= "SELECT DISTINCT ?s ?x WHERE {{<"+ resource_h.getUri()+"> <"+h_temp.getUri()+"> ?x} UNION {<"+ resource_h.getUri()+"> <"+h_temp.getUri().replace("property", "ontology")+"> ?x}. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } else{ - Query= "SELECT DISTINCT ?s ?x WHERE {?x <"+h_temp.getUri()+"> <"+ resource_h.getUri()+"> . ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + Query= "SELECT DISTINCT ?s ?x WHERE {{?x <"+h_temp.getUri()+"> <"+ resource_h.getUri()+">} UNION {?x <"+h_temp.getUri().replace("property", "ontology")+"> <"+ resource_h.getUri()+">} . ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; } /* * Now use the variable from the second condition which does not has an Resource in the Hypothesis */ - System.out.println("Query: "+Query); HashMap<String, String> hm_newClasses=ServerUtil.generatesQueryForOutsideClasses(Query); ArrayList<Hypothesis> second_resultHypothesenList=new ArrayList<Hypothesis>(); - second_resultHypothesenList = creatNewPropertyList(type, myindex, wordnet, lemmatiser, second_property_variable, second_property_name,hm_newClasses,resource_h.getName()); + for(Hypothesis second_h_temp : second_resultHypothesenList) { ArrayList<Hypothesis> temp_al = new ArrayList<Hypothesis>(); temp_al.add(resource_h); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -32,122 +32,8 @@ boolean found_property_in_loaded_property=false; boolean found_property_in_created_property=false; - if(Setting.isLoadedProperties()){ - System.out.println("in Loaded!!"); - //Open the file for reading - try { - BufferedReader br = new BufferedReader(new FileReader(dateiname)); - String thisLine; - while ((thisLine = br.readLine()) != null) { // while loop begins here - String[] tmp_array = thisLine.split("::"); - if(tmp_array.length>1){ - loaded_properties.put(tmp_array[0].replace("\n", ""), tmp_array[1].replace("\n", "")); - } - - } // end while - } // end try - catch (IOException e) { - System.err.println("Error: " + e); - } - for (Entry<String, String> entry_loaded : loaded_properties.entrySet()) { - - String key_loaded= entry_loaded.getKey(); - String value_loaded= entry_loaded.getValue(); - if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ - System.out.println("FOUND!!"); - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.replace("(μ)", ""); - key=key.replace("(cm)", ""); - key=key.toLowerCase(); - String value = entry.getValue(); - /*System.out.println("KEY_old:"+key); - System.out.println("value_loaded:"+value_loaded+"DONE"); - System.out.println("Value:"+value); - System.out.println("\n");*/ - if(key.equals(value_loaded)){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); - h.printAll(); - found_property_in_loaded_property=true; - } - } - } - - } - } - /* - * createdPropertyCombinations - */ - - /* - * Second read in File with the propertys, which were created, when a query produced an answer and query had the rank >0.8 - * and the property hast the given "matserresource" - */ - /* if(found_property_in_loaded_property==false&&Setting.isSaveAnsweredQueries()){ - HashMap<String, String> created_properties = new HashMap<String, String>(); - System.out.println("in Save!!"); - dateiname="/home/swalter/workspace/createdPropertyCombinations"; - System.out.println("Resource to compare: "+resource_name); - //Open the file for reading - try { - BufferedReader br = new BufferedReader(new FileReader(dateiname)); - String thisLine; - while ((thisLine = br.readLine()) != null) { // while loop begins here - String[] tmp_array = thisLine.split("::"); - if(tmp_array.length>2){ - - // check, if the given resource is equal to the reosource loaded from the file! - - if(tmp_array[0].toLowerCase().replace("\n", "").equals(resource_name.toLowerCase())){ - created_properties.put(tmp_array[1].replace("\n", ""), tmp_array[2].replace("\n", "")); - } - - } - - } // end while - } // end try - catch (IOException e) { - System.err.println("Error: " + e); - } - if(!created_properties.isEmpty()){ - for (Entry<String, String> entry_loaded : created_properties.entrySet()) { - - String key_loaded= entry_loaded.getKey(); - String value_loaded= entry_loaded.getValue(); - if(key_loaded.replace("_", " ").equals(property_to_compare_with.replace("_", " ").toLowerCase())){ - System.out.println("FOUND!!"); - for (Entry<String, String> entry : properties.entrySet()) { - String key = entry.getKey(); - key=key.replace("\"",""); - key=key.replace("@en",""); - key=key.replace("(μ)", ""); - key=key.replace("(cm)", ""); - key=key.toLowerCase(); - String value = entry.getValue(); - System.out.println("KEY_old:"+key); - System.out.println("value_loaded:"+value_loaded+"DONE"); - System.out.println("Value:"+value); - System.out.println("\n"); - if(key.equals(value_loaded)){ - Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 2.0); - listOfNewHypothesen.add(h); - h.printAll(); - found_property_in_created_property=true; - } - } - } - - } - } - - - }*/ - if(found_property_in_loaded_property==false||found_property_in_created_property==false){ //} @@ -211,7 +97,6 @@ } else if(compare_property.substring(compare_property.length()-2).contains("ed")){ String compare_property_neu = compare_property.substring(0, compare_property.length() -2); - System.out.println("NEW compare_property: "+compare_property_neu); if(key.contains(compare_property_neu)||compare_property_neu.contains(key)){ Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", 0.95); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-06-18 13:55:56 UTC (rev 3761) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-06-20 12:48:53 UTC (rev 3762) @@ -20,14 +20,12 @@ public class WordnetModule { - private static int explorationdepthwordnet =0; + private static int explorationdepthwordnet =1; public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throw... [truncated message content] |