From: <seb...@us...> - 2012-03-29 13:11:05
|
Revision: 3625 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3625&view=rev Author: sebastianwtr Date: 2012-03-29 13:10:53 +0000 (Thu, 29 Mar 2012) Log Message: ----------- [tbsl exploration] went on to implement the different Modules, especially the Iteration Module Modified Paths: -------------- 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/ElementList.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/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/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 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-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.92; + double lim_levensthein=0.99; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -25,6 +25,11 @@ * HashMap with name -uri pairs. */ private HashMap<String,String> hm = new HashMap<String,String>(); + + /** + * Resource or Class! + */ + //private String type public String getVariablename() { return variablename; } 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -11,36 +11,27 @@ * */ public class Elements { - private ArrayList<ElementList> resources = new ArrayList<ElementList>(); - private ArrayList<ElementList> classes = new ArrayList<ElementList>(); - public ArrayList<ElementList> getResources() { - return resources; + private ArrayList<ElementList> elements = new ArrayList<ElementList>(); + + public ArrayList<ElementList> getElements() { + return elements; } - public void setResources(ArrayList<ElementList> resources) { - this.resources = resources; + public void setElements(ArrayList<ElementList> resources) { + this.elements = resources; } - public ArrayList<ElementList> getClasses() { - return classes; - } - public void setClasses(ArrayList<ElementList> classes) { - this.classes = classes; - } - private void addClasses(ElementList cl) { - this.classes.add(cl); + private void addElements(ElementList cl) { + this.elements.add(cl); } - private void addResources(ElementList cl) { - this.resources.add(cl); - } - public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ /* * first all Classes! */ try { - this.setClasses(createElementsOfClasses(hypothesen)); + //this.setClasses(createElementsOfClasses(hypothesen)); + createElementsOfClasses(hypothesen); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -50,7 +41,8 @@ * second all Resources */ try { - this.setResources(createElementsOfResources(hypothesen,condition)); + //this.setResources(createElementsOfResources(hypothesen,condition)); + createElementsOfResources(hypothesen,condition); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -59,8 +51,7 @@ System.out.println("Created Elements"); } - private ArrayList<ElementList> createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ - ArrayList<ElementList> classes = new ArrayList<ElementList>(); + private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ /* * Iterate over all Hypothesis and look for an IsA @@ -75,17 +66,17 @@ * TODO: improver performance, using geschicktes zwischenspeichern */ ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); - classes.add(el); + //classes.add(el); + this.addElements(el); } } } - return classes; + //return classes; } - private ArrayList<ElementList> createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ - ArrayList<ElementList> resources = new ArrayList<ElementList>(); + private void createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ /* * Iterate over all Hypothesis and look for an resource */ @@ -95,11 +86,17 @@ 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); + //resources.add(el); + this.addElements(el); } if(h.getVariable().equals(cl.get(2))) { - ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); - resources.add(el); + /* + * 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); } } @@ -108,38 +105,30 @@ } } - return resources; + //return resources; } public void printAll(){ - System.out.println("Resources: "); - for(ElementList el: this.resources){ + System.out.println("Elements: "); + for(ElementList el: this.elements){ el.printAll(); } - System.out.println("\nClasses: "); - for(ElementList el: this.classes){ - el.printAll(); - } } public String printToString(){ String result=""; - result+="Resources: \n"; - for(ElementList el: this.resources){ + result+="Elements: \n"; + for(ElementList el: this.elements){ result+=el.printToString()+"\n"; } - result+="\nClasses: \n"; - for(ElementList el: this.classes){ - result+=el.printToString()+"\n"; - } return result; } public boolean isElementEmty(){ try { - if(this.getClasses().isEmpty()||this.getResources().isEmpty()) return true; + if(this.getElements().isEmpty()) return true; else return false; } catch (Exception e) { // TODO Auto-generated catch block 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -7,6 +7,7 @@ private ArrayList<ElementList> list_of_element_uri_pair = new ArrayList<ElementList>(); 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 String selectTerm; private String having; private String filter; @@ -15,8 +16,11 @@ private String question; private String queryType; private Elements elm; - private float overallTime; - private float time_Templator; + private long overallTime; + private long time_Templator; + private long time_generateElements; + private long time_part1; + private long time_part2; public String getHaving() { return having; @@ -92,6 +96,17 @@ z.printAll(); } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : hypothesenLevensthein){ + System.out.println("\nSet of HypothesenLevensthein"+anzahl+":"); + anzahl+=1; + for ( Hypothesis z : x){ + z.printAll(); + } + } + + System.out.print("\n"); System.out.println("QueryType "+queryType); System.out.println("selectTerm: "+selectTerm); @@ -107,16 +122,16 @@ public void setQuestion(String question) { this.question = question; } - public float getOverallTime() { + public long getOverallTime() { return overallTime; } - public void setOverallTime(float overallTime) { + public void setOverallTime(long overallTime) { this.overallTime = overallTime; } - public float getTime_Templator() { + public long getTime_Templator() { return time_Templator; } - public void setTime_Templator(float time_Templator) { + public void setTime_Templator(long time_Templator) { this.time_Templator = time_Templator; } public ArrayList<ElementList> getList_of_element_uri_pair() { @@ -141,6 +156,30 @@ public void setElm(Elements elm) { this.elm = elm; } + public long getTime_generateElements() { + return time_generateElements; + } + public void setTime_generateElements(long time_generateElements) { + this.time_generateElements = time_generateElements; + } + public long getTime_part1() { + return time_part1; + } + public void setTime_part1(long time_part1) { + this.time_part1 = time_part1; + } + public long getTime_part2() { + return time_part2; + } + public void setTime_part2(long time_part2) { + this.time_part2 = time_part2; + } + public ArrayList<ArrayList<Hypothesis>> getHypothesenLevensthein() { + return hypothesenLevensthein; + } + public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { + this.hypothesenLevensthein = hypothesenLevensthein; + } } 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -77,6 +77,8 @@ long stop_template = System.currentTimeMillis(); for (BasicQueryTemplate bqt : querytemps) { + + long start_part1= System.currentTimeMillis(); ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); //ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); String selectTerm = ""; @@ -153,8 +155,10 @@ addTemplate=false; } + long stop_part1= System.currentTimeMillis(); + if(addTemplate!=false){ - + long start_part2= System.currentTimeMillis(); /* * SLOT_title: PROPERTY {title,name,label} mitfuehren @@ -162,6 +166,7 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -349,20 +354,34 @@ /* * Before adding Templates, generate for each Template a set of Properties and Elements */ + long start_elements = System.currentTimeMillis(); Elements elm = new Elements(template.getCondition(),template.getHypothesen()); + long stop_elements = System.currentTimeMillis(); + template.setTime_generateElements(stop_elements-start_elements); + /* * If no Elements are created, dont add Template! */ - //if(elm.isElementEmty()==false){ + long stop_part2= System.currentTimeMillis(); + template.setTime_part2(stop_part2-start_part2); + if(elm.isElementEmty()==false){ + //elm.printAll(); template.setElm(elm); resultArrayList.add(template); - //} + } if(add_reverse_template){ + start_elements = System.currentTimeMillis(); Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); - //if(elm_reverse.isElementEmty()==false){ - template.setElm(elm_reverse); + stop_elements = System.currentTimeMillis(); + template_reverse_conditions.setTime_generateElements(stop_elements-start_elements); + template_reverse_conditions.setTime_part1(stop_part1-start_part1); + template_reverse_conditions.setTime_part2(stop_part2-start_part2); + + if(elm_reverse.isElementEmty()==false){ + //elm_reverse.printAll(); + template_reverse_conditions.setElm(elm_reverse); resultArrayList.add(template_reverse_conditions); - //} + } } } } 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -12,7 +12,7 @@ * @param t * @return */ - public static ArrayList<QueryPair> returnSetOfQueries(Template t){ + public static ArrayList<QueryPair> returnSetOfQueries(Template t, String type){ ArrayList<QueryPair> queryList = new ArrayList<QueryPair>(); /* @@ -27,7 +27,15 @@ /* * Now replacing varibale with the uri from the Hypot. */ - for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> givenHypothesenList = new ArrayList<ArrayList<Hypothesis>>() ; + if(type.contains("LEVENSTHEIN")){ + givenHypothesenList=t.getHypothesenLevensthein(); + } + else{ + givenHypothesenList=t.getHypothesen(); + } + + for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -13,8 +13,8 @@ //String static 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:8890/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:8890/sparql"; private static int timeToTimeoutOnServer=30000; @@ -96,6 +96,8 @@ if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=query_property_left; String result=""; + /*System.out.println(verarbeitungsurl); + System.out.println("side: "+ side);*/ result = getListOfElements(verarbeitungsurl); return generateList(result); @@ -109,8 +111,24 @@ */ 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 + */ - String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s ?x WHERE { ?x rdf:type <"+classUri+">. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + 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}}"; String result=""; result = getListOfElements(query); 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -39,69 +39,95 @@ TemplateBuilder testobject = new TemplateBuilder(); String filepath = "/home/swalter/Dokumente/Auswertung/"; - String file="very_small.xml"; - //String file="dbpedia-train.xml"; + //String file="very_small.xml"; + String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); - //String question = "Is the wife of president Obama called Michelle?"; - String question = "Who is the leader of Hamburg?"; - temp_list_result=testobject.createTemplates(question); - Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //String question = "Who is the mayor of Berlin?"; - /*for(Template t : temp_list_result){ - //t.printAll(); - try { - t.getElm().printAll(); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - } - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); - for(QueryPair p : qp){ - tm.put(p, t.getQuestion()); - } - }*/ - for(Template t : temp_list_result){ - t.getElm().getResources(); - IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition()); - } + /* + * Original eine resource zwei properties, nachher nur noch eine Resource und eine property + */ + String question ="Who is the daughter of Bill Clinton married to?"; + long start_template = System.currentTimeMillis(); + //temp_list_result=testobject.createTemplates(question); + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - - ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - /* * Generate Templates */ - /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + /* ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + list_of_structs=generateStruct(filepath+"XMLDateien/"+file); String result=""; for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); - try { + /*try { result+=t.getElm().printToString()+"\n"; } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); - } - } + }*/ + // } - }*/ + //} + long stop_template = System.currentTimeMillis(); + + long start_iteration = System.currentTimeMillis(); + long time_generatingElements=0; + long time_part1=0; + long time_part2=0; + + for(Template t : temp_list_result){ + time_generatingElements+=t.getTime_generateElements(); + time_part1+=t.getTime_part1(); + time_part2+=t.getTime_part2(); + try{ + //t.getElm().printAll(); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + t.setHypothesenLevensthein(blub); + + //t.printAll(); + } + catch (Exception e){ + + } + + } + 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; + float time_Templator=temp_list_result.get(0).getTime_Templator(); + System.out.println("Generating the Template took "+ time_template+"ms"); + System.out.println("Generating one Template took "+ time_template/temp_list_result.size()+"ms"); + System.out.println("Templator took "+ time_Templator+"ms"); + System.out.println("Generating the Templates Without Parser "+ (time_template-time_Templator)+"ms"); + System.out.println("Average Time getting Properties etc "+ (time_generatingElements/temp_list_result.size())+"ms"); + 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"); + + + + /* * Create Query for each Template */ - /*Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - for(Template t : temp_list_result){ + /*for(Template t : temp_list_result){ //t.printAll(); - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t, "LEVENSTHEIN"); for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } @@ -113,15 +139,16 @@ * Get Elements for Each Resource and Class */ - /*long stop = System.currentTimeMillis(); + /* System.out.println("Duration in ms: " + (stop - start)); writeStringToFile(result,filepath,file,start,stop); */ /* * Write Results in File */ - //writeQueriesInFile(tm,filepath,file,start,stop ); - //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + long stop = System.currentTimeMillis(); + // writeQueriesInFile(tm,filepath,file,start,stop ); + // writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -151,6 +178,22 @@ result+="%%%%%%%%%%%"+"\n"; } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : t.getHypothesenLevensthein()){ + result+="\nSet of LevenstheinHypothesen"+anzahl+":\n"; + anzahl+=1; + for ( Hypothesis z : x){ + result+="%%%%%%%%%%%"+"\n"; + result+="Variable: "+z.getVariable()+"\n"; + result+="Name: "+z.getName()+"\n"; + result+="Uri: " + z.getUri()+"\n"; + result+="Type: " + z.getType()+"\n"; + result+="Rank: "+z.getRank()+"\n"; + result+="%%%%%%%%%%%"+"\n"; + } + } + result+="\n"; result+="queryType: "+t.getQueryType()+"\n"; result+="selectTerm: "+t.getSelectTerm()+"\n"; 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -21,21 +21,64 @@ * @param hypothesen * @param condition * @return ArrayList<ArrayList<Hypothesis>> + * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList){ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + boolean gotResource=true; + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + try{ + resources = elm.getElements(); + } + catch (Exception e){ + gotResource=false; + System.out.println("Didnt get any Resource"); + } + + //System.out.println("Anzahl der Resource Listen: "+resources.size()); + + ArrayList<ArrayList<Hypothesis>>finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); + + for(ArrayList<Hypothesis> hl :givenHypothesenList){ + /* + * foundedResourcesClasses + */ + ArrayList<Hypothesis> RL = new ArrayList<Hypothesis>(); /* + * foundedProperty + */ + ArrayList<String> PL = new ArrayList<String>(); + + /* + * hypothesenListBeforSorting + */ + ArrayList<Hypothesis>HL = new ArrayList<Hypothesis>(); + + + /* + * AL abhängig von jeder einzelnen Resource R aus RL + */ + ArrayList<ArrayList<ArrayList<Hypothesis>>> ALR = new ArrayList<ArrayList<ArrayList<Hypothesis>>>(); + + + /* * First look for resources and generate List with properties */ for(Hypothesis h : hl){ + + //System.out.println("In Hypothesis Loop"); if(h.getType().contains("RESOURCE")){ /* * Get Variable from Resource */ String variable = h.getVariable(); + String name = h.getName(); + RL.add(h); + System.out.println("Found Resource"); + /* * Look in Condition for the Set, in which the variable appears */ @@ -43,11 +86,8 @@ for(ArrayList<String> cl : givenConditionList){ for(String s : cl){ if(s.contains(variable)){ - /* - * Mark Also if the Property is left or right from the Resource - */ - if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+variable); - else propertyVariableList.add(cl.get(1)+"LEFT::"+variable); + if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+name); + else propertyVariableList.add(cl.get(1)+"LEFT::"+name); } } } @@ -58,68 +98,215 @@ ArrayList<String> propertyNameList = new ArrayList<String>(); for(String s : propertyVariableList){ for(Hypothesis h_t : hl){ - //System.out.println("s in creating propertyNameList: "+s); String variable_t = s; variable_t=variable_t.replace("RIGHT", ""); variable_t=variable_t.replace("LEFT", ""); - if(h_t.getVariable().contains(variable_t)) propertyNameList.add(h_t.getName()+"::"+s); + String[] variable_t1=variable_t.split("::"); + if(h_t.getVariable().contains(variable_t1[0])){ + propertyNameList.add(h_t.getName()+"::"+s); + } } } - /* * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc */ - ArrayList<ElementList> resources = elm.getResources(); - for(String s : propertyNameList){ - String[] array = s.split("::"); - - System.out.println("s: "+s); - System.out.println("Array:"); - for(String t : array){ - System.out.println(t); + + if(gotResource){ + for(String s : propertyNameList){ + String[] array = s.split("::"); + + System.out.println("String: "+s); + /*System.out.println("Array:"); + for(String t : array){ + System.out.println(t); + }*/ + + /* + * array[0] contains name of Property + * array[1] contains LEFT/RIGHT and Variable of Property + * array[2] contains Name of Resource + */ + + String side="LEFT"; + if(array[1].contains("RIGHT")) side="RIGHT"; + + for(ElementList el : resources){ + if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ + String propertyVariable = array[1]; + propertyVariable=propertyVariable.replace("LEFT", ""); + propertyVariable=propertyVariable.replace("RIGHT", ""); + ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); + try { + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); + + } + } + } - + } + + + } + + if(h.getType().contains("isA")){ + /* + * TODO:Add special case, if we have only one condition but with an isA in it. + */ + RL.add(h); + System.out.println("Found Class"); + + for(ElementList el:resources){ /* - * array[0] contains name of Property - * array[1] contains LEFT/RIGHT and Variable of Property - * array[2] contains Name of Resource + * Find the resource with the same uri as in h an then start Levensthein/Wordnet etc */ - - String side="LEFT"; - if(array[1].contains("RIGHT")) side="RIGHT"; - - for(ElementList el : resources){ - if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ - String propertyVariable = array[1]; - propertyVariable=propertyVariable.replace("LEFT", ""); - propertyVariable=propertyVariable.replace("RIGHT", ""); - ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - try { - resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if(el.getURI().contains(h.getUri())){ + /* + * Iterate over condition and find the coressesponding variable of the Class, wich is used for the new Hypothesis + */ + ArrayList<String> propertyVariableList= new ArrayList<String>(); + for(ArrayList<String> cl : givenConditionList){ + /* + * Dont look for line, where e.g. ?x isA ?y + */ + //get(1) is the middle Term and if there is an isa, than its there + if(!cl.get(1).contains("isA")){ + for(String s : cl){ + if(s.contains(h.getVariable())){ + propertyVariableList.add(s); + } + } } + + } + for(String propertyVariable : propertyVariableList){ + for(ArrayList<Hypothesis> hl_small :givenHypothesenList){ + for(Hypothesis h_small : hl_small){ + if(h_small.getVariable().contains(propertyVariable)){ + try { + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable); + for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } - for(Hypothesis h_p : resultHypothesenList) h_p.printAll(); - } + //for(Hypothesis h_p : finalHypothesenList) h_p.printAll(); + + } - } + + } + + } - /* * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case */ + + /*for(Hypothesis h : RL){ + h.printAll(); + } + + for(String s : PL){ + System.out.println("Variable P: "+s); + }*/ + + /* + * Here add new function! + */ + for(Hypothesis R : RL){ + /* + * AL, abhängig von jeder einzelnen P aus PL und R aus RL + */ + ArrayList<ArrayList<Hypothesis>> AL = new ArrayList<ArrayList<Hypothesis>>(); + + + for(String P : PL){ + if(P.contains(R.getVariable())){ + for(Hypothesis H : HL){ + if(P.contains(H.getVariable())){ + ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); + t_h_l.add(H); + t_h_l.add(R); + AL.add(t_h_l); + } + } + } + } + + ALR.add(AL); + } + + if(ALR.size()==1){ + System.out.println("ONLY One Element in ALR"); + finalHypothesenList=ALR.get(0); + System.out.println("One Element in ALR added to finalHypothesenList"); + } + if(ALR.size()==2){ + System.out.println("Two Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + } + System.out.println("Two Element in ALR added to finalHypothesenList"); + + } + + if(ALR.size()==2){ + System.out.println("Three Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + for(ArrayList<Hypothesis> hl2_t : ALR.get(2)){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + for(Hypothesis h_t : hl2_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + + } + } + System.out.println("Three Element in ALR added to finalHypothesenList"); + + } + + } + + + + System.out.println("######################DONE######################"); - return null; + return finalHypothesenList; } 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 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.8; + private final static double LevenstheinMin=0.92; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |