You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(120) |
Sep
(36) |
Oct
(116) |
Nov
(17) |
Dec
(44) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(143) |
Feb
(192) |
Mar
(74) |
Apr
(84) |
May
(105) |
Jun
(64) |
Jul
(49) |
Aug
(120) |
Sep
(159) |
Oct
(156) |
Nov
(51) |
Dec
(28) |
2009 |
Jan
(17) |
Feb
(55) |
Mar
(33) |
Apr
(57) |
May
(54) |
Jun
(28) |
Jul
(6) |
Aug
(16) |
Sep
(38) |
Oct
(30) |
Nov
(26) |
Dec
(52) |
2010 |
Jan
(7) |
Feb
(91) |
Mar
(65) |
Apr
(2) |
May
(14) |
Jun
(25) |
Jul
(38) |
Aug
(48) |
Sep
(80) |
Oct
(70) |
Nov
(75) |
Dec
(77) |
2011 |
Jan
(68) |
Feb
(53) |
Mar
(51) |
Apr
(35) |
May
(65) |
Jun
(101) |
Jul
(29) |
Aug
(230) |
Sep
(95) |
Oct
(49) |
Nov
(110) |
Dec
(63) |
2012 |
Jan
(41) |
Feb
(42) |
Mar
(25) |
Apr
(46) |
May
(51) |
Jun
(44) |
Jul
(45) |
Aug
(29) |
Sep
(12) |
Oct
(9) |
Nov
(17) |
Dec
(2) |
2013 |
Jan
(12) |
Feb
(14) |
Mar
(7) |
Apr
(16) |
May
(54) |
Jun
(27) |
Jul
(11) |
Aug
(5) |
Sep
(85) |
Oct
(27) |
Nov
(37) |
Dec
(32) |
2014 |
Jan
(8) |
Feb
(29) |
Mar
(5) |
Apr
(3) |
May
(22) |
Jun
(3) |
Jul
(4) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
From: <lor...@us...> - 2012-07-28 19:27:26
|
Revision: 3808 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3808&view=rev Author: lorenz_b Date: 2012-07-28 19:27:20 +0000 (Sat, 28 Jul 2012) Log Message: ----------- Added constructor Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-07-26 14:21:14 UTC (rev 3807) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-07-28 19:27:20 UTC (rev 3808) @@ -182,6 +182,11 @@ super(sources); } + public PelletReasoner(com.clarkparsia.pellet.owlapiv3.PelletReasoner reasoner) { + setSources(new OWLAPIOntology(reasoner.getRootOntology())); + this.reasoner = reasoner; + } + public void loadOntologies() throws URISyntaxException, OWLOntologyCreationException { Comparator<OWLNamedObject> namedObjectComparator = new Comparator<OWLNamedObject>() { public int compare(OWLNamedObject o1, OWLNamedObject o2) { @@ -566,7 +571,9 @@ Logger pelletLogger = Logger.getLogger("org.mindswap.pellet"); pelletLogger.setLevel(Level.WARN); - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); + if(reasoner != null){ + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); + } classifier = PelletIncremantalReasonerFactory.getInstance().createReasoner(reasoner); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-07-26 14:21:26
|
Revision: 3807 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3807&view=rev Author: kirdie Date: 2012-07-26 14:21:14 +0000 (Thu, 26 Jul 2012) Log Message: ----------- test nearly finished. Modified Paths: -------------- 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/ltag/agreement/Unification.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 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-07-26 11:01:22 UTC (rev 3806) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-07-26 14:21:14 UTC (rev 3807) @@ -32,41 +32,41 @@ 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{ - + /* * true, if you have to push a button to get to the next module * false, goes through all */ boolean wait = false; //Setting.setThresholdSelect(0.5); - + if(Setting.isWaitModus())wait=true; - + TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); ArrayList<Template> template_list = new ArrayList<Template>(); - + /* * Array List with the answers from the queries */ ArrayList<String> answers = new ArrayList<String>(); - - + + /* * generate Templates! */ template_list=templateObject.createTemplates(question); - + answers = singleSteps(myindex, wordnet, lemmatiser, wait, template_list); - + return answers; } @@ -85,17 +85,17 @@ private static ArrayList<String> singleSteps(SQLiteIndex myindex, WordNet wordnet, StanfordLemmatizer lemmatiser, boolean wait, ArrayList<Template> template_list) - throws IOException { - + throws IOException { + ArrayList<String> answers = new ArrayList<String>(); /* * generate Queries and test the first Time */ ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); - + //generate QueryPair String Question=""; - + //TODO: parallel here? for(Template t : template_list){ Question=t.getQuestion(); @@ -113,7 +113,7 @@ if(!contain)qp.add(p); } } - + //sort QueryPairs qp=LinearSort.doSort(qp); qp=HeuristicSort.doHeuristicSort(qp, Question); @@ -124,7 +124,7 @@ for(QueryPair q : qp){ System.out.println(q.getQuery()+" rank:"+q.getRank()); } - + int anzahl=1; boolean go_on = true; for(QueryPair q : qp){ @@ -139,7 +139,7 @@ //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; @@ -165,7 +165,7 @@ else answers.add(s); } } - + } } //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); @@ -173,26 +173,26 @@ } anzahl+=1; } - + System.out.println("\n Answer from Server: \n"); for(String answer:answers){ System.out.println(answer); } if(wait)DebugMode.waitForButton(); - - + + if(answers.isEmpty()&&Setting.getModuleStep()>=2){ - + answers.clear(); //Setting.setLevenstheinMin(0.65); //Setting.setAnzahlAbgeschickterQueries(10); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN","neu")); if(wait)DebugMode.waitForButton(); } - + if(answers.isEmpty()&&Setting.getModuleStep()>=3){ - + answers.clear(); //Setting.setAnzahlAbgeschickterQueries(10); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET","neu")); @@ -201,31 +201,31 @@ if(answers.isEmpty()&&Setting.getModuleStep()>=4){ - + answers.clear(); //Setting.setAnzahlAbgeschickterQueries(10); //Setting.setThresholdSelect(0.2); answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"RELATE","neu")); if(wait)DebugMode.waitForButton(); } - - + + if(answers.isEmpty()&&Setting.getModuleStep()>=5){ System.out.println("NO Answer from Server =>Start Query Manipulation"); answers.clear(); answers.addAll(stufe5(myindex,wordnet,lemmatiser,wait,template_list)); if(wait)DebugMode.waitForButton(); } - - - - - - + + + + + + /* * return answers! */ - + return answers; } @@ -234,13 +234,13 @@ - - - - + + + + private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type, String test) { ArrayList<String> answers = new ArrayList<String>(); @@ -248,9 +248,9 @@ boolean special=false; int anzahl; boolean go_on; - + 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; @@ -260,7 +260,7 @@ wordnet_global=wordnet; lemmatiser_global=lemmatiser; type_global=type; - + for(Template t : template_list){ final int anzahl_thread_new=anzahl_thread; @@ -270,11 +270,11 @@ { String blub=do_something(anzahl_thread_new); }; - + thread_list.add(t1); t1.start(); - - + + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -286,14 +286,14 @@ 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(); @@ -302,42 +302,42 @@ e.printStackTrace(); } }*/ - - + + for(Template t : template_list){ try{ - - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); - - - for(ArrayList<Hypothesis> l_h : t.getHypothesen()){ - ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); - generated_hypothesis= IterationModule.new_iteration(t.getElm(),l_h,t.getCondition(),type,myindex,wordnet,lemmatiser); - 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); + + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = new ArrayList<ArrayList<Hypothesis>>(); + + + for(ArrayList<Hypothesis> l_h : t.getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> generated_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); + generated_hypothesis= IterationModule.new_iteration(t.getElm(),l_h,t.getCondition(),type,myindex,wordnet,lemmatiser); + 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.addAll(blub); + hypothesenSetList.add(new_hypothesen_set); } - if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); - if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); - if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); - + + //hypothesenSetList.addAll(blub); } - + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); + if(type.contains("RELATE"))t.setHypothesenRelate(hypothesenSetList); + + } + //} catch (Exception e){ - + } - + } - - + + /* * Generate Queries and test queries */ @@ -359,12 +359,12 @@ if(!contain&&checkQuery(p.getQuery()))qp.add(p); } } - + //sort QueryPairs qp=LinearSort.doSort(qp); qp=HeuristicSort.doHeuristicSort(qp, Question); //printQueries(qp, type, Question); - + System.out.println("Following Querries were created:"); for(QueryPair q : qp){ System.out.println(q.getQuery()+" rank:"+q.getRank()); @@ -385,7 +385,7 @@ //else go_on=false; //go_on=true; 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); @@ -400,8 +400,8 @@ */ if(Question.toLowerCase().contains("which")) go_on=false; if(Question.toLowerCase().contains("who")) go_on=false; - - + + boolean contains_uri=false; for(String s : answer_tmp){ if(s.contains("http")){ @@ -413,8 +413,8 @@ for(String answer:answer_tmp){ System.out.println(answer); }*/ - - + + for(String s : answer_tmp){ if(checkAnswer(s)){ boolean double_result = false; @@ -437,7 +437,7 @@ //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); } } - + else if(q.getRank()>Setting.getThresholdAsk()&go_on &q.getQuery().contains("ASK")){ ArrayList<String> answer_tmp = new ArrayList<String>(); answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); @@ -455,8 +455,8 @@ go_on=true; } } - - + + boolean contains_uri=false; for(String s : answer_tmp){ if(s.contains("http")){ @@ -464,8 +464,8 @@ break; } } - - + + for(String s : answer_tmp){ if(checkAnswer(s)){ boolean double_result = false; @@ -501,12 +501,12 @@ for(String answer:answers){ System.out.println(answer); } - + return answers; } - - - + + + private static ArrayList<String> filterAnswer(ArrayList<String> answers, String Question){ if(Question.toLowerCase().contains("who")){ boolean contains_only_uri=true; @@ -521,29 +521,29 @@ new_answer.add(s); } } - + return new_answer; } else{ return answers; } } - - + + return answers; } private static boolean checkAnswer(String answer){ if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")||answer.contains("flickerwrappr/photos/")) return false; else return true; - + } - + private static boolean checkQuery(String query){ if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")||query.contains("wikiPage")) return false; else return true; - + } - + private static void printQueries(ArrayList<QueryPair> qp, String type, String Question){ /*String dateiname="/home/swalter/Dokumente/Auswertung/CreatedQuery"+Setting.getLevenstheinMin()+".txt"; String result_string =""; @@ -558,7 +558,7 @@ catch (IOException e) { System.err.println("Error: " + e); } - + File file = new File(dateiname); BufferedWriter bw = null; try { @@ -571,18 +571,18 @@ querylist="\n Modul: "+type+"\nfor Question: "+ Question+"\n"; int anzahl= 0; /* - * write only the first 10 queries: - */ - /* for(QueryPair q : qp){ + * write only the first 10 queries: + */ + /* for(QueryPair q : qp){ if(anzahl<10){ querylist+=q.getQuery()+" "+q.getRank()+"\n"; anzahl+=1; } - + } - - + + try { bw.write(result_string+querylist); } catch (IOException e) { @@ -602,9 +602,9 @@ e.printStackTrace(); }*/ } - - - + + + private static void printSingleQuery(String query,String Question){ /*String dateiname="/home/swalter/Dokumente/Auswertung/WorkingQuery"+Setting.getLevenstheinMin()+".txt"; String result_string =""; @@ -619,7 +619,7 @@ catch (IOException e) { System.err.println("Error: " + e); } - + File file = new File(dateiname); BufferedWriter bw = null; try { @@ -628,8 +628,8 @@ // TODO Auto-generated catch block e2.printStackTrace(); } - + try { bw.write(result_string+Question+" "+query+"\n"); } catch (IOException e) { @@ -649,11 +649,11 @@ e.printStackTrace(); }*/ } - - - + + + private static ArrayList<String> stufe5(SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser, boolean wait,ArrayList<Template> template_list){ - + ArrayList<Template> new_template_list=new ArrayList<Template>(); ArrayList<String> answers=new ArrayList<String>(); /* @@ -668,7 +668,7 @@ if(condition.get(1).toLowerCase().equals("isa")) go_on=true; System.out.println("go_on:"+go_on); if(go_on){ - + String resource_variable=condition.get(0); String class_variable=condition.get(2); Hypothesis resource_h = null; @@ -686,11 +686,11 @@ class_h=h; } } - + } System.out.println("go_on_resource:"+go_on_resource); if(go_on_resource){ - + /* * manipulate Class variable to make a property from it */ @@ -703,82 +703,82 @@ small_h_list.add(resource_h); small_h_list.add(class_h); new_hypothesen_list.add(small_h_list); - + ArrayList<String> condition_new = new ArrayList<String>(); condition_new.add("?x"); condition_new.add("?y"); condition_new.add("?z"); - + ArrayList<ArrayList<String>> new_c_list = new ArrayList<ArrayList<String>>(); new_c_list.add(condition_new); - + Template new_Template = new Template(new_c_list, t.getQueryType(), "","" , "?z", "", "", t.getQuestion()); - + new_Template.setHypothesen(new_hypothesen_list); Elements elm = new Elements(new_Template.getCondition(),new_Template.getHypothesen()); - if(elm.isElementEmty()==false){ - //elm.printAll(); - new_Template.setElm(elm); - new_template_list.add(new_Template); - } - - Template template_reverse_conditions = new Template(new_Template.getCondition(),new_Template.getQueryType(), new_Template.getHaving(), new_Template.getFilter(), new_Template.getSelectTerm(), new_Template.getOrderBy(), new_Template.getLimit(), new_Template.getQuestion()); - template_reverse_conditions.setHypothesen(new_hypothesen_list); - - ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); - ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); + if(elm.isElementEmty()==false){ + //elm.printAll(); + new_Template.setElm(elm); + new_template_list.add(new_Template); + } + Template template_reverse_conditions = new Template(new_Template.getCondition(),new_Template.getQueryType(), new_Template.getHaving(), new_Template.getFilter(), new_Template.getSelectTerm(), new_Template.getOrderBy(), new_Template.getLimit(), new_Template.getQuestion()); + template_reverse_conditions.setHypothesen(new_hypothesen_list); - for (ArrayList<String> x : condition_template_reverse_conditions){ - ArrayList<String> new_list = new ArrayList<String>(); - new_list.add(x.get(2)); - new_list.add(x.get(1)); - new_list.add(x.get(0)); - condition_reverse_new.add(new_list); - } - - - template_reverse_conditions.setCondition(condition_reverse_new); - - Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); - if(elm_reverse.isElementEmty()==false){ - //elm.printAll(); - template_reverse_conditions.setElm(elm_reverse); - new_template_list.add(template_reverse_conditions); - } - - - + ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); + ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); + + + for (ArrayList<String> x : condition_template_reverse_conditions){ + ArrayList<String> new_list = new ArrayList<String>(); + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } + + + template_reverse_conditions.setCondition(condition_reverse_new); + + Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); + if(elm_reverse.isElementEmty()==false){ + //elm.printAll(); + template_reverse_conditions.setElm(elm_reverse); + new_template_list.add(template_reverse_conditions); + } + + + } - - - - + + + + } } - - - - + + + + /* * only if condition.size==2 */ if(t.getCondition().size()==2){ System.out.println("Yeah, found two Conditions!"); - + /* * now look if one have the [isa][resource] or [resource][isa] case */ ArrayList<String> condition1=new ArrayList<String>(); ArrayList<String> condition2=new ArrayList<String>(); - + condition1=t.getCondition().get(0); condition2=t.getCondition().get(1); System.out.println("condition1:"+condition1); System.out.println("condition2:"+condition2); - + boolean go_on=false; - + if(condition1.get(1).toLowerCase().contains("isa")&&!condition2.get(1).toLowerCase().contains("isa")){ String resource1_variable=condition2.get(0); String resource2_variable=condition2.get(2); @@ -788,17 +788,17 @@ if(h.getType().toLowerCase().contains("resource")) go_on=true; } } - + } - + /*if(condition2.get(0).contains("resource/")||condition2.get(2).contains("resource/")){ go_on=true; } else go_on=false;*/ } - + else if(condition2.get(1).toLowerCase().contains("isa")){ - + String resource1_variable=condition1.get(0); String resource2_variable=condition1.get(2); for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ @@ -807,10 +807,10 @@ if(h.getType().toLowerCase().contains("resource")) go_on=true; } } - + } - - + + /* * in the conditions there is for sure no resource!!! */ @@ -820,28 +820,28 @@ else go_on=false;*/ } else go_on=false; - - + + System.out.println("Go_on:"+go_on); if(go_on==true){ - + /* * use now only the conditions WITHOUT the class */ ArrayList<ArrayList<Hypothesis>> new_hypothesen_list = new ArrayList<ArrayList<Hypothesis>>(); - + String resource_variable=null; for(ArrayList<Hypothesis> h_l :t.getHypothesen()){ ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); - + for(Hypothesis h : h_l){ if(!h.getType().toLowerCase().contains("isa"))t_h_l.add(h); if(h.getType().toLowerCase().contains("resource"))resource_variable=h.getVariable(); } - + if(t_h_l.size()>0) new_hypothesen_list.add(t_h_l); } - + /* * New HypothesenList */ @@ -855,12 +855,12 @@ ArrayList<String> new_condition= new ArrayList<String>(); if(!condition1.get(1).toLowerCase().contains("isa")) new_condition=condition1; else new_condition=condition2; - + String new_SelectTerm=null; - + if(new_condition.get(0).contains(resource_variable)) new_SelectTerm=new_condition.get(2); else new_SelectTerm=new_condition.get(0); - + ArrayList<ArrayList<String>> new_c_list = new ArrayList<ArrayList<String>>(); new_c_list.add(new_condition); /* @@ -874,19 +874,19 @@ new_Template.setElm(t.getElm()); new_template_list.add(new_Template); //new_Template.printAll(); - + } - - + + } - + 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 @@ -940,56 +940,56 @@ 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); - } - - - + 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); } } - + /* * if there are new templates, start rescursive call; */ @@ -1003,18 +1003,18 @@ return answers; } } - + 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); @@ -1025,61 +1025,40 @@ } 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(); + 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); } - - - 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(); - } + File file = new File(dateiname); + BufferedWriter bw = null; + try + { + bw = new BufferedWriter(new FileWriter(file)); + bw.write(result_string+Resource+"::"+PropertyName+"::"+Property+"\n"); + bw.flush(); + bw.close(); + } + catch (IOException e) {e.printStackTrace();} } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/agreement/Unification.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/agreement/Unification.java 2012-07-26 11:01:22 UTC (rev 3806) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/agreement/Unification.java 2012-07-26 14:21:14 UTC (rev 3807) @@ -58,7 +58,7 @@ private static boolean unify(LexicalSelection a, LexicalSelection b) { if (a == null && b == null) { return true; - } else if (a.equals(b)) { + } else if (a!=null&&a.equals(b)) { return true; } return false; Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-26 11:01:22 UTC (rev 3806) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-26 14:21:14 UTC (rev 3807) @@ -1,12 +1,14 @@ package org.dllearner.algorithm.tbsl.learning; -import static org.junit.Assert.assertTrue; -import org.ini4j.Options; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.net.MalformedURLException; -import java.net.URL; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -15,19 +17,15 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import opennlp.tools.postag.POSTagger; +import net.sf.oval.constraint.AssertTrue; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -41,17 +39,14 @@ import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; import org.dllearner.common.index.SOLRIndex; -import org.dllearner.common.index.SPARQLIndex; -import org.dllearner.common.index.VirtuosoClassesIndex; -import org.dllearner.common.index.VirtuosoPropertiesIndex; -import org.dllearner.common.index.VirtuosoResourcesIndex; import org.dllearner.core.ComponentInitException; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import org.ini4j.Options; import org.junit.Before; import org.junit.Test; -import org.openjena.atlas.logging.Log; +import static org.junit.Assert.*; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -68,6 +63,7 @@ * only contains the questions where the reference query does not return a nonempty list of resources. * This could be questions which return literals, ask queries, queries which have no results in the DBpedia endpoint * and queries that cause errors. This updated test file contains the reference answers as well and is only created once. + * The answers in the updated query could be out of date as well, so if the answers don't match they are newly queried from the reference query. * Because there are multiple queries that are not all valid at first, further test runs are compared against the first run. * The updated test data and the test runs are saved in the cache folder in the same format as the original test data * (an xml with the tags question, query and answer). @@ -78,20 +74,42 @@ * **/ public class SPARQLTemplateBasedLearner3Test { - @Test public void testDBpedia() throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException + @Test public void testDBpedia() throws Exception {test(new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train.xml").getFile()),"http://live.dbpedia.org/sparql");} //@Test public void testOxford() {test(new File(""),"");} - public void test(File file, String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException + public void test(final File referenceXML,final String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException { String dir = "cache/"+getClass().getSimpleName()+"/"; new File(dir).mkdirs(); - File updatedFile=new File(dir+"updated_"+file.getName()); - if(!updatedFile.exists()) {generateUpdatedFile(file,updatedFile,endpoint);} + File updatedReferenceXML=new File(dir+"updated_"+referenceXML.getName()); + if(!updatedReferenceXML.exists()) {generateUpdatedXML(referenceXML,updatedReferenceXML,endpoint);} - QueryTestData savedTestData = readQueries(updatedFile); - QueryTestData newTestData = generateTestData(savedTestData.id2Question); - Diff QueryTestDataDiff = diffTestData(savedTestData,newTestData); + logger.debug("Reading updated reference test data"); + QueryTestData referenceTestData = readQueries(updatedReferenceXML); + QueryTestData learnedTestData = generateTestData(referenceTestData.id2Question); + + logger.info("Comparing updated reference test data a with learned test data b:"); + Diff queryTestDataDiff = diffTestData(referenceTestData,learnedTestData); + logger.info(queryTestDataDiff); + + logger.info("Comparing learned test data with old learned test data"); + + try{ + QueryTestData oldLearnedTestData = QueryTestData.read(); + Diff queryTestDataDiff2 = diffTestData(oldLearnedTestData,learnedTestData); + logger.info(queryTestDataDiff); +// assertFalse("the following queries did not return an answer in the current learned test data: "+queryTestDataDiff2.aMinusB, +// queryTestDataDiff2.aMinusB.isEmpty()); + assertFalse("the following queries had different answers: "+queryTestDataDiff2.differentAnswers, + queryTestDataDiff2.differentAnswers.isEmpty()); + + } + catch(IOException e) + { + logger.info("Old test data not loadable, creating it and exiting."); + learnedTestData.write(); + } } /** @@ -99,32 +117,47 @@ * @param newTestData * @return */ - private Diff diffTestData(QueryTestData d, QueryTestData e) + private static Diff diffTestData(QueryTestData a, QueryTestData b) { -// if(d.id2Question.size()!=e.id2Question.size()) - {logger.info("comparing test data D against E. number of questions: "+d.id2Question.size()+" vs "+e.id2Question.size());} - - Set<Integer> dMinusE = new HashSet<Integer>(d.id2Question.keySet()); - dMinusE.removeAll(e.id2Question.keySet()); - if(!dMinusE.isEmpty()) logger.info("questions D/E: "+dMinusE+" ("+dMinusE.size()+" elements)"); - - Set<Integer> eMinusD = new HashSet<Integer>(e.id2Question.keySet()); - eMinusD.removeAll(d.id2Question.keySet()); - if(!eMinusD.isEmpty()) logger.info("questions E/D: "+eMinusD+" ("+eMinusD.size()+" elements)"); - - Set<Integer> intersection = new HashSet<Integer>(d.id2Question.keySet()); - intersection.retainAll(e.id2Question.keySet()); - - if(!eMinusD.isEmpty()) logger.info("questions E/D: "+eMinusD+" ("+eMinusD.size()+" elements)"); - - + // if(d.id2Question.size()!=e.id2Question.size()) + {logger.info("comparing test data a against b. number of questions: "+a.id2Question.size()+" vs "+b.id2Question.size());} + Diff diff = new Diff(); + diff.aMinusB.addAll(a.id2Question.keySet()); + diff.aMinusB.removeAll(b.id2Question.keySet()); + + diff.bMinusA.addAll(b.id2Question.keySet()); + diff.bMinusA.removeAll(a.id2Question.keySet()); + + diff.intersection.addAll(a.id2Question.keySet()); + diff.intersection.retainAll(b.id2Question.keySet()); + + for(int i: diff.intersection) + { + if(a.id2Answers.containsKey(i)&&!a.id2Answers.get(i).equals(b.id2Answers.get(i))) {diff.differentAnswers.add(i);} + } + // if(!eMinusD.isEmpty()) logger.info("questions E/D: "+eMinusD+" ("+eMinusD.size()+" elements)"); + + // TODO Auto-generated method stub - return null; + return diff; } - private class Diff + public static class Diff { + final Set<Integer> aMinusB = new HashSet<Integer>(); + final Set<Integer> bMinusA = new HashSet<Integer>(); + final Set<Integer> intersection = new HashSet<Integer>(); + final Set<Integer> differentAnswers = new HashSet<Integer>(); + @Override public String toString() + { + StringBuilder sb = new StringBuilder(); + if(!aMinusB.isEmpty()) sb.append("questions a/b: "+aMinusB+" ("+aMinusB.size()+" elements)\n"); + if(!bMinusA.isEmpty()) sb.append("questions b/a: "+bMinusA+" ("+bMinusA.size()+" elements)\n"); + if(!intersection.isEmpty()) sb.append("questions intersection: "+intersection+" ("+intersection.size()+" elements)\n"); + if(!differentAnswers.isEmpty()) sb.append("questions with different answers: "+differentAnswers+" ("+differentAnswers.size()+" elements)\n"); + return sb.substring(0, sb.length()-2); // remove last \n + } } /** @@ -148,7 +181,7 @@ dbpediaLiveLearner.init(); dbpediaLiveLearner.setQuestion(question); - + try{dbpediaLiveLearner.learnSPARQLQueries();} catch(NoTemplateFoundException e) {continue;} catch(Exception e) {logger.error("Error processing question "+question,e);continue;} @@ -156,7 +189,9 @@ testData.id2Question.put(i, question); String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); testData.id2Query.put(i, learnedQuery); - + // generate answers + // getUris(endpoint, learnedQuery); + long end = System.currentTimeMillis(); logger.debug(String.format("Generated query \"%s\" after %d ms", learnedQuery,end-start)); @@ -174,7 +209,7 @@ * @throws SAXException * @throws TransformerException */ - private void generateUpdatedFile(File originalFile, File updatedFile,String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException + private void generateUpdatedXML(File originalFile, File updatedFile,String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException { logger.info(String.format("Updating question file \"%s\" by removing questions without nonempty resource list answer and adding answers.\n" + " Saving the result to file \"%s\"",originalFile.getPath(),updatedFile.getPath())); @@ -262,55 +297,55 @@ // int successfullTestThreadRuns = 0; /** */ - private static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; + private static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; - private static Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); + private static final Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); // private SPARQLTemplateBasedLearner2 oxfordLearner; // private SPARQLTemplateBasedLearner2 dbpediaLiveLearner; - private ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); - private ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); + private final ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); + private final ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); - private Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); - - static SparqlEndpoint dbpediaLiveEndpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); + private final Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); + + static final SparqlEndpoint dbpediaLiveEndpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); //static SparqlEndpoint oxfordEndpoint; private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} -// private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} + // private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} -// @Test public void benchmarkCreateOxfordKnowledgeBase() -// { -// long start = System.currentTimeMillis(); -// for(int i=0;i<1000;i++) -// { -// createOxfordKnowledgebase(oxfordCache); -// } -// long end = System.currentTimeMillis(); -// long diff = end-start; -// System.out.println(diff+" millis as a whole, "+diff/1000.0+" millis per run"); -// } + // @Test public void benchmarkCreateOxfordKnowledgeBase() + // { + // long start = System.currentTimeMillis(); + // for(int i=0;i<1000;i++) + // { + // createOxfordKnowledgebase(oxfordCache); + // } + // long end = System.currentTimeMillis(); + // long diff = end-start; + // System.out.println(diff+" millis as a whole, "+diff/1000.0+" millis per run"); + // } -// private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) -// { -// URL url; -// try{url = new URL("http://lgd.aksw.org:8900/sparql");} catch(Exception e) {throw new RuntimeException(e);} -// SparqlEndpoint endpoint = new SparqlEndpoint(url, Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); -// -// SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); -// SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); -// SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); -// MappingBasedIndex mappingIndex= new MappingBasedIndex( -// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), -// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), -// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), -// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() -// ); -// -// Knowledgebase kb = new Knowledgebase(oxfordEndpoint, "Oxford - Real estate", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); -// return kb; -// } + // private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) + // { + // URL url; + // try{url = new URL("http://lgd.aksw.org:8900/sparql");} catch(Exception e) {throw new RuntimeException(e);} + // SparqlEndpoint endpoint = new SparqlEndpoint(url, Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); + // + // SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); + // SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); + // SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); + // MappingBasedIndex mappingIndex= new MappingBasedIndex( + // SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), + // SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), + // SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), + // SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() + // ); + // + // Knowledgebase kb = new Knowledgebase(oxfordEndpoint, "Oxford - Real estate", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); + // return kb; + // } private Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) { @@ -344,11 +379,35 @@ // oxfordLearner = new SPARQLTemplateBasedLearner2(createOxfordKnowledgebase(oxfordCache)); } - private class QueryTestData + private static class QueryTestData implements Serializable { public SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); public SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); public SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); + + private static final String persistancePath = "cache/"+SPARQLTemplateBasedLearner3Test.class.getSimpleName()+'/'+QueryTestData.class.getSimpleName(); + + public void write() + { + try + { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(persistancePath))); + oos.writeObject(this); + oos.close(); + } catch(IOException e) {throw new RuntimeException(e);} + } + + public static QueryTestData read() throws FileNotFoundException, IOException + { + try + { + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(persistancePath))); + QueryTestData testData = (QueryTestData) ois.readObject(); + ois.close(); + return testData; + } + catch (ClassNotFoundException e){throw new RuntimeException(e);} + } } private QueryTestData readQueries(final File file) @@ -467,69 +526,69 @@ return uris; } - private class TestQueryThread implements Runnable - { - private String question; - private String referenceQuery; + // private class TestQueryThread implements Runnable + // { + // private String question; + // private String referenceQuery; + // + // public TestQueryThread(String question, String referenceQuery) + // { + // this.question=question; + // this.referenceQuery=referenceQuery; + // } + // // String referenceQuery = id2Query.get(i); + // // String question = id2Question.get(i); + // @Override public void run() + // { + // + // logger.trace("question: "+question); + // + // // TODO: check for query isomorphism and leave out result comparison if possible + // // TODO: only load the reference answers once and permanently cache them somehow (file, ehcache, serialization, ...) + // // get the answers for the gold standard query + // logger.trace("reference query: "+referenceQuery); + // + // try + // { + // Set<String> referenceURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); + // + // // learn query + // SPARQLTemplateBasedLearner2 dbpediaLiveLearner = new SPARQLTemplateBasedLearner2(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); + // dbpediaLiveLearner.init(); + // dbpediaLiveLearner.setQuestion(question); + // dbpediaLiveLearner.learnSPARQLQueries(); + // String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); + // + // logger.trace(learnedQuery); + // + // Set<String> learnedURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); + // + // logger.trace("referenced uris: "+referenceURIs); + // logger.trace("learned uris: "+learnedURIs); + // + // boolean correctMatch = referenceURIs.equals(learnedURIs); + // logger.trace(correctMatch?"matches":"doesn't match"); + //// if(correctMatch) {synchronized(this) {correctMatches++;}} + // } + // catch(NoTemplateFoundException e) + // { + // synchronized(this) {numberOfNoTemplateFoundExceptions++;} + // logger.warn(String.format("no template found for question \"%s\"",question)); + // } + // catch(Exception e) + // { + // synchronized(this) {numberOfOtherExceptions++;} + // logger.error(String.format("Exception for question \"%s\": %s",question,e.getLocalizedMessage())); + // e.printStackTrace(); + // // maybe the exception has corrupted the learner? better create a new one + // // + // } + // // get the answers for the learned query + // // compare gold standard query and learned query answers + // } + // + // } - public TestQueryThread(String question, String referenceQuery) - { - this.question=question; - this.referenceQuery=referenceQuery; - } - // String referenceQuery = id2Query.get(i); - // String question = id2Question.get(i); - @Override public void run() - { - - logger.trace("question: "+question); - - // TODO: check for query isomorphism and leave out result comparison if possible - // TODO: only load the reference answers once and permanently cache them somehow (file, ehcache, serialization, ...) - // get the answers for the gold standard query - logger.trace("reference query: "+referenceQuery); - - try - { - Set<String> referenceURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); - - // learn query - SPARQLTemplateBasedLearner2 dbpediaLiveLearner = new SPARQLTemplateBasedLearner2(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); - dbpediaLiveLearner.init(); - dbpediaLiveLearner.setQuestion(question); - dbpediaLiveLearner.learnSPARQLQueries(); - String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); - - logger.trace(learnedQuery); - - Set<String> learnedURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); - - logger.trace("referenced uris: "+referenceURIs); - logger.trace("learned uris: "+learnedURIs); - - boolean correctMatch = referenceURIs.equals(learnedURIs); - logger.trace(correctMatch?"matches":"doesn't match"); - if(correctMatch) {synchronized(this) {correctMatches++;}} - } - catch(NoTemplateFoundException e) - { - synchronized(this) {numberOfNoTemplateFoundExceptions++;} - logger.warn(String.format("no template found for question \"%s\"",question)); - } - catch(Exception e) - { - synchronized(this) {numberOfOtherExceptions++;} - logger.error(String.format("Exception for question \"%s\": %s",question,e.getLocalizedMessage())); - e.printStackTrace(); - // maybe the exception has corrupted the learner? better create a new one - // - } - // get the answers for the learned query - // compare gold standard query and learned query answers - } - - } - private void updateFile(File originalFile, File updatedFile, String endpoint) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-07-26 11:01:32
|
Revision: 3806 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3806&view=rev Author: kirdie Date: 2012-07-26 11:01:22 +0000 (Thu, 26 Jul 2012) Log Message: ----------- more work on junit test. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java trunk/components-ext/src/main/resources/log4j.properties trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -691,8 +691,7 @@ allTypes.add(type); if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ - drop = true; - System.err.println("DROPPING: \n" + q.toString()); + drop = true; } else { } @@ -1258,7 +1257,7 @@ SPARQLTemplateBasedLearner2 learner = new SPARQLTemplateBasedLearner2(endpoint, resourcesIndex, classesIndex, propertiesIndex); learner.init(); - String question = "Give me all books written by Dan Brown"; + String question = "What is the highest mountain?"; learner.setQuestion(question); learner.learnSPARQLQueries(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -1023,10 +1023,7 @@ learner.learnSPARQLQueries(); System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); - System.out.println(learner.getLearnedPosition()); - + System.out.println(learner.getLearnedPosition()); } - - -} +} \ No newline at end of file Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -79,11 +79,11 @@ if (SHOW_GRAMMAR) { - logger.trace(parseGrammar); + logger.debug(parseGrammar); } if (SHOW_LEXICAL_COVERAGE) { - logger.trace("# OF TREES FOUND: " + parseGrammar.size()); - logger.trace("# OF INPUT TOKENS: " + n); + logger.debug("# OF TREES FOUND: " + parseGrammar.size()); + logger.debug("# OF INPUT TOKENS: " + n); } List<Pair<TreeNode, Short>> initTrees = parseGrammar.getInitTrees(); @@ -94,7 +94,7 @@ internalParse(parseGrammar.getDPInitTrees(), n); } - if (VERBOSE) logger.trace("Constructed " + derivationTrees.size() + " derivation trees.\n"); + if (VERBOSE) logger.debug("Constructed " + derivationTrees.size() + " derivation trees.\n"); return derivationTrees; } @@ -130,11 +130,11 @@ if (SHOW_GRAMMAR) { - logger.trace(parseGrammar); + logger.debug(parseGrammar); } if (SHOW_LEXICAL_COVERAGE) { - logger.trace("# OF TREES FOUND: " + parseGrammar.size()); - logger.trace("# OF INPUT TOKENS: " + n); + logger.debug("# OF TREES FOUND: " + parseGrammar.size()); + logger.debug("# OF INPUT TOKENS: " + n); } List<Pair<TreeNode, Short>> initTrees = parseGrammar.getInitTrees(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -382,11 +382,10 @@ try { Template temp = d2s.convert(drs,slots); + if (temp == null) {continue;} temp = temp.checkandrefine(); - if (temp == null) { - continue; - } + if (USE_WORDNET) { // find WordNet synonyms List<String> newwords; String word; Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -116,8 +116,7 @@ } else { solrString += queryString; } - } - System.out.println(solrString); + } SolrQuery query = new SolrQuery(solrString); query.setRows(limit); query.setStart(offset); Modified: trunk/components-ext/src/main/resources/log4j.properties =================================================================== --- trunk/components-ext/src/main/resources/log4j.properties 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/main/resources/log4j.properties 2012-07-26 11:01:22 UTC (rev 3806) @@ -40,8 +40,8 @@ ####TBSL log4j.category.org.dllearner.algorithm.tbsl=INFO -log4j.category.org.dllearner.algorithm.tbsl.ltag.parser=TRACE -log4j.category.org.dllearner.algorithm.tbsl.templator=TRACE +log4j.category.org.dllearner.algorithm.tbsl.ltag.parser=WARN +log4j.category.org.dllearner.algorithm.tbsl.templator=WARN ####SOLR log4j.category.org.apache.solr.level = OFF Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-25 14:46:12 UTC (rev 3805) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-26 11:01:22 UTC (rev 3806) @@ -1,6 +1,7 @@ package org.dllearner.algorithm.tbsl.learning; import static org.junit.Assert.assertTrue; +import org.ini4j.Options; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -26,10 +27,16 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import opennlp.tools.postag.POSTagger; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithm.tbsl.ltag.parser.Parser; +import org.dllearner.algorithm.tbsl.nlp.PartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.StanfordPartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.WordNet; +import org.dllearner.algorithm.tbsl.templator.Templator; import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; @@ -44,6 +51,7 @@ import org.dllearner.kb.sparql.SparqlQuery; import org.junit.Before; import org.junit.Test; +import org.openjena.atlas.logging.Log; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -69,12 +77,12 @@ * @author Konrad Höffner * **/ public class SPARQLTemplateBasedLearner3Test -{ - @Test public void testDBpedia() throws ParserConfigurationException, SAXException, IOException, TransformerException +{ + @Test public void testDBpedia() throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException {test(new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train.xml").getFile()),"http://live.dbpedia.org/sparql");} //@Test public void testOxford() {test(new File(""),"");} - public void test(File file, String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException + public void test(File file, String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException, ComponentInitException, NoTemplateFoundException { String dir = "cache/"+getClass().getSimpleName()+"/"; new File(dir).mkdirs(); @@ -82,34 +90,80 @@ if(!updatedFile.exists()) {generateUpdatedFile(file,updatedFile,endpoint);} QueryTestData savedTestData = readQueries(updatedFile); - QueryTestData newTestData = generateQueries(updatedFile); - Diff QueryTestDataDiff = diffTestQueries(savedTestData,newTestData); + QueryTestData newTestData = generateTestData(savedTestData.id2Question); + Diff QueryTestDataDiff = diffTestData(savedTestData,newTestData); } - + /** * @param savedTestData * @param newTestData * @return */ - private Diff diffTestQueries(QueryTestData savedTestData, QueryTestData newTestData) + private Diff diffTestData(QueryTestData d, QueryTestData e) { +// if(d.id2Question.size()!=e.id2Question.size()) + {logger.info("comparing test data D against E. number of questions: "+d.id2Question.size()+" vs "+e.id2Question.size());} + + Set<Integer> dMinusE = new HashSet<Integer>(d.id2Question.keySet()); + dMinusE.removeAll(e.id2Question.keySet()); + if(!dMinusE.isEmpty()) logger.info("questions D/E: "+dMinusE+" ("+dMinusE.size()+" elements)"); + + Set<Integer> eMinusD = new HashSet<Integer>(e.id2Question.keySet()); + eMinusD.removeAll(d.id2Question.keySet()); + if(!eMinusD.isEmpty()) logger.info("questions E/D: "+eMinusD+" ("+eMinusD.size()+" elements)"); + + Set<Integer> intersection = new HashSet<Integer>(d.id2Question.keySet()); + intersection.retainAll(e.id2Question.keySet()); + + if(!eMinusD.isEmpty()) logger.info("questions E/D: "+eMinusD+" ("+eMinusD.size()+" elements)"); + + // TODO Auto-generated method stub return null; } private class Diff { - + } - - /** - * @param updatedFile - * @return + + /** + * @return the test data containing those of the given questions for which queries were found and the results of the queries */ - private QueryTestData generateQueries(File updatedFile) + private QueryTestData generateTestData(SortedMap<Integer, String> id2Question) throws MalformedURLException, ComponentInitException { + QueryTestData testData = new QueryTestData(); + // -- only create the learner parameters once to save time -- + PartOfSpeechTagger posTagger = new StanfordPartOfSpeechTagger(); + WordNet wordnet = new WordNet(); + Options options = new Options(); + // ---------------------------------------------------------- + int successes = 0; + for(int i:id2Question.keySet()) + { + String question = id2Question.get(i); + logger.debug("generating query for question \""+question+"\", id "+i); + long start = System.currentTimeMillis(); + SPARQLTemplateBasedLearner2 dbpediaLiveLearner = new SPARQLTemplateBasedLearner2(dbpediaLiveKnowledgebase,posTagger,wordnet,options); + + dbpediaLiveLearner.init(); + dbpediaLiveLearner.setQuestion(question); + + try{dbpediaLiveLearner.learnSPARQLQueries();} + catch(NoTemplateFoundException e) {continue;} + catch(Exception e) {logger.error("Error processing question "+question,e);continue;} + successes++; + testData.id2Question.put(i, question); + String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); + testData.id2Query.put(i, learnedQuery); + + long end = System.currentTimeMillis(); + logger.debug(String.format("Generated query \"%s\" after %d ms", learnedQuery,end-start)); + + } + logger.info(String.format("Successfully learned queries for %d of %d questions.",successes,id2Question.size())); // TODO Auto-generated method stub - return null; + return testData; } /** @@ -124,81 +178,81 @@ { logger.info(String.format("Updating question file \"%s\" by removing questions without nonempty resource list answer and adding answers.\n" + " Saving the result to file \"%s\"",originalFile.getPath(),updatedFile.getPath())); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - - DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(originalFile); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - doc.getDocumentElement().normalize(); - NodeList questionNodes = doc.getElementsByTagName("question"); - List<Element> questionElementsToDelete = new LinkedList<Element>(); - int id; - String question; - String query; - // Set<String> answers; + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(originalFile); - for(int i = 0; i < questionNodes.getLength(); i++) - { - Element questionNode = (Element) questionNodes.item(i); - //keep the id to aid comparison between original and updated files - id = Integer.valueOf(questionNode.getAttribute("id")); - //Read question + doc.getDocumentElement().normalize(); + NodeList questionNodes = doc.getElementsByTagName("question"); + List<Element> questionElementsToDelete = new LinkedList<Element>(); + int id; + String question; + String query; + // Set<String> answers; - question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); - //Read SPARQL query - query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); - // //Read answers - // answers = new HashSet<String>(); - // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); - // for(int j = 0; j < aswersNodes.getLength(); j++){ - // Element answerNode = (Element) aswersNodes.item(j); - // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); - // } + for(int i = 0; i < questionNodes.getLength(); i++) + { + Element questionNode = (Element) questionNodes.item(i); + //keep the id to aid comparison between original and updated files + id = Integer.valueOf(questionNode.getAttribute("id")); + //Read question - if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) + question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); + //Read SPARQL query + query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); + // //Read answers + // answers = new HashSet<String>(); + // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); + // for(int j = 0; j < aswersNodes.getLength(); j++){ + // Element answerNode = (Element) aswersNodes.item(j); + // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); + // } + + if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) + { + Set<String> uris = getUris(endpoint, query); + if(!uris.isEmpty()) { - Set<String> uris = getUris(endpoint, query); - if(!uris.isEmpty()) - { - // remove reference answers of the benchmark because they are obtained from an other endpoint - Element existingAnswersElement = (Element)questionNode.getElementsByTagName("answers").item(0); // there is at most one "answers"-element - if(existingAnswersElement!=null) {questionNode.removeChild(existingAnswersElement);} + // remove reference answers of the benchmark because they are obtained from an other endpoint + Element existingAnswersElement = (Element)questionNode.getElementsByTagName("answers").item(0); // there is at most one "answers"-element + if(existingAnswersElement!=null) {questionNode.removeChild(existingAnswersElement);} - Element answersElement = doc.createElement("answers"); - questionNode.appendChild(answersElement); - for(String uri:uris) - { - Element answerElement = doc.createElement("answer"); - answerElement.setTextContent(uri); - answersElement.appendChild(answerElement); - } - System.out.print('.'); - continue; - } + Element answersElement = doc.createElement("answers"); + questionNode.appendChild(answersElement); + for(String uri:uris) + { + Element answerElement = doc.createElement("answer"); + answerElement.setTextContent(uri); + answersElement.appendChild(answerElement); + } + System.out.print('.'); + continue; } - // no answers gotten, mark for deletion - questionElementsToDelete.add(questionNode); - System.out.print('x'); } - for(Element element: questionElementsToDelete) {doc.getDocumentElement().removeChild(element);} + // no answers gotten, mark for deletion + questionElementsToDelete.add(questionNode); + System.out.print('x'); + } + for(Element element: questionElementsToDelete) {doc.getDocumentElement().removeChild(element);} - TransformerFactory tFactory = - TransformerFactory.newInstance(); - Transformer transformer = tFactory.newTransformer(); + TransformerFactory tFactory = + TransformerFactory.newInstance(); + Transformer transformer = tFactory.newTransformer(); - DOMSource source = new DOMSource(doc); - StreamResult result = new StreamResult(new FileOutputStream(updatedFile)); - transformer.transform(source, result); - -// catch (DOMException e) { -// e.printStackTrace(); -// } catch (ParserConfigurationException e) { -// e.printStackTrace(); -// } catch (SAXException e) { -// e.printStackTrace(); -// } catch (IOException e) { -// e.printStackTrace(); -// } + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(new FileOutputStream(updatedFile)); + transformer.transform(source, result); + + // catch (DOMException e) { + // e.printStackTrace(); + // } catch (ParserConfigurationException e) { + // e.printStackTrace(); + // } catch (SAXException e) { + // e.printStackTrace(); + // } catch (IOException e) { + // e.printStackTrace(); + // } } @@ -212,37 +266,53 @@ private static Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); - // private SPARQLTemplateBasedLearner3 oxfordLearner; - // private SPARQLTemplateBasedLearner3 dbpediaLiveLearner; + // private SPARQLTemplateBasedLearner2 oxfordLearner; + // private SPARQLTemplateBasedLearner2 dbpediaLiveLearner; private ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); private ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); - SparqlEndpoint dbpediaLiveEndpoint; - SparqlEndpoint oxfordEndpoint; + private Knowledgebase dbpediaLiveKnowledgebase = createDBpediaLiveKnowledgebase(dbpediaLiveCache); + + static SparqlEndpoint dbpediaLiveEndpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); + //static SparqlEndpoint oxfordEndpoint; private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} - private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} +// private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} - private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) throws MalformedURLException - { - SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); +// @Test public void benchmarkCreateOxfordKnowledgeBase() +// { +// long start = System.currentTimeMillis(); +// for(int i=0;i<1000;i++) +// { +// createOxfordKnowledgebase(oxfordCache); +// } +// long end = System.currentTimeMillis(); +// long diff = end-start; +// System.out.println(diff+" millis as a whole, "+diff/1000.0+" millis per run"); +// } - SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); - SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); - SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); - MappingBasedIndex mappingIndex= new MappingBasedIndex( - this.getClass().getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() - ); +// private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) +// { +// URL url; +// try{url = new URL("http://lgd.aksw.org:8900/sparql");} catch(Exception e) {throw new RuntimeException(e);} +// SparqlEndpoint endpoint = new SparqlEndpoint(url, Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); +// +// SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); +// SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); +// SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); +// MappingBasedIndex mappingIndex= new MappingBasedIndex( +// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), +// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), +// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), +// SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() +// ); +// +// Knowledgebase kb = new Knowledgebase(oxfordEndpoint, "Oxford - Real estate", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); +// return kb; +// } - Knowledgebase kb = new Knowledgebase(oxfordEndpoint, "Oxford - Real estate", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); - return kb; - } - - private Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) throws MalformedURLException + private Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) { SOLRIndex resourcesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_resources"); resourcesIndex.setPrimarySearchField("label"); @@ -251,10 +321,10 @@ Index propertiesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_properties"); MappingBasedIndex mappingIndex= new MappingBasedIndex( - this.getClass().getClassLoader().getResource("test/dbpedia_class_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("test/dbpedia_resource_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("test/dbpedia_dataproperty_mappings.txt").getPath(), - this.getClass().getClassLoader().getResource("test/dbpedia_objectproperty_mappings.txt").getPath() + SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("test/dbpedia_class_mappings.txt").getPath(), + SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("test/dbpedia_resource_mappings.txt").getPath(), + SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("test/dbpedia_dataproperty_mappings.txt").getPath(), + SPARQLTemplateBasedLearner2.class.getClassLoader().getResource("test/dbpedia_objectproperty_mappings.txt").getPath() ); Knowledgebase kb = new Knowledgebase(dbpediaLiveEndpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); @@ -264,10 +334,14 @@ @Before public void setup() throws IOException { + Logger.getRootLogger().setLevel(Level.WARN); + Logger.getLogger(Templator.class).setLevel(Level.WARN); + Logger.getLogger(Parser.class).setLevel(Level.WARN); + Logger.getLogger(SPARQLTemplateBasedLearner2.class).setLevel(Level.INFO); logger.setLevel(Level.ALL); // TODO: remove when finishing implementation of this class logger.addAppender(new FileAppender(new SimpleLayout(), "log/"+this.getClass().getSimpleName()+".log", false)); // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); - // oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); + // oxfordLearner = new SPARQLTemplateBasedLearner2(createOxfordKnowledgebase(oxfordCache)); } private class QueryTestData @@ -276,7 +350,7 @@ public SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); public SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); } - + private QueryTestData readQueries(final File file) { QueryTestData testData = new QueryTestData(); @@ -420,7 +494,7 @@ Set<String> referenceURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); // learn query - SPARQLTemplateBasedLearner3 dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); + SPARQLTemplateBasedLearner2 dbpediaLiveLearner = new SPARQLTemplateBasedLearner2(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); dbpediaLiveLearner.init(); dbpediaLiveLearner.setQuestion(question); dbpediaLiveLearner.learnSPARQLQueries(); @@ -462,70 +536,70 @@ } -// private void test(File file) throws MalformedURLException, InterruptedException -// { -// SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); -// SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); -// SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); -// -// { -// // URL url = getClass().getClassLoader().getResource(s); -// // assertFalse("resource not found: "+s,url==null); -// // readQueries(new File(url.getPath()),id2Question,id2Query); -// readQueries(file); -// } -// assertTrue("no questions loaded",id2Question.size()>0); -// logger.info(id2Question.size()+" questions loaded."); -// assertTrue(String.format("number of questions (%d) != number of queries (%d).",id2Question.size(),id2Query.size()), -// id2Question.size()==id2Query.size()); -// -// // get question and answer from file -// dbpediaLiveEndpoint = new SparqlEndpoint(new URL(DBPEDIA_LIVE_ENDPOINT_URL_STRING), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); -// -// // dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); -// // dbpediaLiveLearner.init(); -// -// // TODO: use thread pools -// ExecutorService service = Executors.newFixedThreadPool(10); -// for(int i: id2Query.keySet()) -// { -// Runnable r = new TestQueryThread(id2Question.get(i),id2Query.get(i)); -// service.execute(r); -// } -// boolean timeout =!service.awaitTermination(600, TimeUnit.SECONDS); -// -// logger.info(timeout?"timeout":"finished all threads"); -// if(numberOfNoTemplateFoundExceptions>0) {logger.warn(numberOfNoTemplateFoundExceptions+" NoTemplateFoundExceptions");} -// if(numberOfOtherExceptions>0) {logger.error(numberOfOtherExceptions+" other exceptions");} -// assertTrue(String.format("only %d/%d correct answers",correctMatches,id2Query.size()),correctMatches==id2Query.size()); -// -// // dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); -// // dbpediaLiveLearner.learnSPARQLQueries(); -// // String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); -// // logger.trace(learnedQuery); -// //fail("Not yet implemented"); -// } + // private void test(File file) throws MalformedURLException, InterruptedException + // { + // SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); + // SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); + // SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); + // + // { + // // URL url = getClass().getClassLoader().getResource(s); + // // assertFalse("resource not found: "+s,url==null); + // // readQueries(new File(url.getPath()),id2Question,id2Query); + // readQueries(file); + // } + // assertTrue("no questions loaded",id2Question.size()>0); + // logger.info(id2Question.size()+" questions loaded."); + // assertTrue(String.format("number of questions (%d) != number of queries (%d).",id2Question.size(),id2Query.size()), + // id2Question.size()==id2Query.size()); + // + // // get question and answer from file + // dbpediaLiveEndpoint = new SparqlEndpoint(new URL(DBPEDIA_LIVE_ENDPOINT_URL_STRING), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); + // + // // dbpediaLiveLearner = new SPARQLTemplateBasedLearner2(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); + // // dbpediaLiveLearner.init(); + // + // // TODO: use thread pools + // ExecutorService service = Executors.newFixedThreadPool(10); + // for(int i: id2Query.keySet()) + // { + // Runnable r = new TestQueryThread(id2Question.get(i),id2Query.get(i)); + // service.execute(r); + // } + // boolean timeout =!service.awaitTermination(600, TimeUnit.SECONDS); + // + // logger.info(timeout?"timeout":"finished all threads"); + // if(numberOfNoTemplateFoundExceptions>0) {logger.warn(numberOfNoTemplateFoundExceptions+" NoTemplateFoundExceptions");} + // if(numberOfOtherExceptions>0) {logger.error(numberOfOtherExceptions+" other exceptions");} + // assertTrue(String.format("only %d/%d correct answers",correctMatches,id2Query.size()),correctMatches==id2Query.size()); + // + // // dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); + // // dbpediaLiveLearner.learnSPARQLQueries(); + // // String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); + // // logger.trace(learnedQuery); + // //fail("Not yet implemented"); + // } -// @Test public void testDBpediaX() throws NoTemplateFoundException, ComponentInitException, MalformedURLException, InterruptedException -// { -// // original file - qald benchmark xml -// // updated file - delete questions giving no nonempty list of resources (literals, ask query, no result or error) -// final String originalDirName = "tbsl/evaluation"; -// final String updatedDirName = "cache"; -// final File processedDir = new File(updatedDirName); -// -// if(!processedDir.exists()) {processedDir.mkdirs();} -// -// final String originalFilename = "qald2-dbpedia-train.xml"; -// final String updatedFilename = "processed_"+originalFilename; -// final File originalFile = new File(originalDirName+'/'+originalFilename); -// final File updatedFile = new File(updatedDirName+'/'+updatedFilename); -// -// if(!updatedFile.exists()) {updateFile(originalFile,updatedFile,DBPEDIA_LIVE_ENDPOINT_URL_STRING);} -// -// test(updatedFile); -// -// } + // @Test public void testDBpediaX() throws NoTemplateFoundException, ComponentInitException, MalformedURLException, InterruptedException + // { + // // original file - qald benchmark xml + // // updated file - delete questions giving no nonempty list of resources (literals, ask query, no result or error) + // final String originalDirName = "tbsl/evaluation"; + // final String updatedDirName = "cache"; + // final File processedDir = new File(updatedDirName); + // + // if(!processedDir.exists()) {processedDir.mkdirs();} + // + // final String originalFilename = "qald2-dbpedia-train.xml"; + // final String updatedFilename = "processed_"+originalFilename; + // final File originalFile = new File(originalDirName+'/'+originalFilename); + // final File updatedFile = new File(updatedDirName+'/'+updatedFilename); + // + // if(!updatedFile.exists()) {updateFile(originalFile,updatedFile,DBPEDIA_LIVE_ENDPOINT_URL_STRING);} + // + // test(updatedFile); + // + // } // @Test public void test() throws NoTemplateFoundException, ComponentInitException // { // // get question and answer from file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-07-25 14:46:22
|
Revision: 3805 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3805&view=rev Author: kirdie Date: 2012-07-25 14:46:12 +0000 (Wed, 25 Jul 2012) Log Message: ----------- updating old reference test data complete. reading reference data complete. generating test data from sparql endpoints nearly complete. still to do: save first run of test data and compare further test runs with it, letting the test pass if all correctly learned queries from the first run still work. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-25 10:33:43 UTC (rev 3804) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-25 14:46:12 UTC (rev 3805) @@ -95,6 +95,7 @@ public class SPARQLTemplateBasedLearner3 implements SparqlQueryLearningAlgorithm{ + // TODO: is it possible to use this learner concurrently? and if not would it be easy to implement it or at least a copy constructor? enum Mode{ BEST_QUERY, BEST_NON_EMPTY_QUERY Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-25 10:33:43 UTC (rev 3804) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-25 14:46:12 UTC (rev 3805) @@ -1,21 +1,35 @@ package org.dllearner.algorithm.tbsl.learning; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; @@ -37,18 +51,169 @@ import org.xml.sax.SAXException; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -/** @author konrad * */ +/** Tests TSBL against the qald2 benchmark test data with the DBpedia endpoint. + * The qald2 endpoint is not used because it may not always be available. + * To speed up the process at first the test file is read and an updated copy of it is saved that + * only contains the questions where the reference query does not return a nonempty list of resources. + * This could be questions which return literals, ask queries, queries which have no results in the DBpedia endpoint + * and queries that cause errors. This updated test file contains the reference answers as well and is only created once. + * Because there are multiple queries that are not all valid at first, further test runs are compared against the first run. + * The updated test data and the test runs are saved in the cache folder in the same format as the original test data + * (an xml with the tags question, query and answer). + * A test fails if it generates questions whose generated queries fail while in the first test run it worked. + * Because the logging in the dl-learner is so verbose (TODO: rewrite all prints to logging statements), the + * logging output is also wrote to the file log/#classname. + * @author Konrad Höffner + * **/ public class SPARQLTemplateBasedLearner3Test { + @Test public void testDBpedia() throws ParserConfigurationException, SAXException, IOException, TransformerException + {test(new File(getClass().getClassLoader().getResource("tbsl/evaluation/qald2-dbpedia-train.xml").getFile()),"http://live.dbpedia.org/sparql");} + //@Test public void testOxford() {test(new File(""),"");} + + public void test(File file, String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException + { + String dir = "cache/"+getClass().getSimpleName()+"/"; + new File(dir).mkdirs(); + File updatedFile=new File(dir+"updated_"+file.getName()); + if(!updatedFile.exists()) {generateUpdatedFile(file,updatedFile,endpoint);} + + QueryTestData savedTestData = readQueries(updatedFile); + QueryTestData newTestData = generateQueries(updatedFile); + Diff QueryTestDataDiff = diffTestQueries(savedTestData,newTestData); + } + + /** + * @param savedTestData + * @param newTestData + * @return + */ + private Diff diffTestQueries(QueryTestData savedTestData, QueryTestData newTestData) + { + // TODO Auto-generated method stub + return null; + } + + private class Diff + { + + } + + /** + * @param updatedFile + * @return + */ + private QueryTestData generateQueries(File updatedFile) + { + // TODO Auto-generated method stub + return null; + } + + /** + * @param file + * @param updatedFile + * @throws ParserConfigurationException + * @throws IOException + * @throws SAXException + * @throws TransformerException + */ + private void generateUpdatedFile(File originalFile, File updatedFile,String endpoint) throws ParserConfigurationException, SAXException, IOException, TransformerException + { + logger.info(String.format("Updating question file \"%s\" by removing questions without nonempty resource list answer and adding answers.\n" + + " Saving the result to file \"%s\"",originalFile.getPath(),updatedFile.getPath())); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(originalFile); + + doc.getDocumentElement().normalize(); + NodeList questionNodes = doc.getElementsByTagName("question"); + List<Element> questionElementsToDelete = new LinkedList<Element>(); + int id; + String question; + String query; + // Set<String> answers; + + for(int i = 0; i < questionNodes.getLength(); i++) + { + Element questionNode = (Element) questionNodes.item(i); + //keep the id to aid comparison between original and updated files + id = Integer.valueOf(questionNode.getAttribute("id")); + //Read question + + question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); + //Read SPARQL query + query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); + // //Read answers + // answers = new HashSet<String>(); + // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); + // for(int j = 0; j < aswersNodes.getLength(); j++){ + // Element answerNode = (Element) aswersNodes.item(j); + // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); + // } + + if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) + { + Set<String> uris = getUris(endpoint, query); + if(!uris.isEmpty()) + { + // remove reference answers of the benchmark because they are obtained from an other endpoint + Element existingAnswersElement = (Element)questionNode.getElementsByTagName("answers").item(0); // there is at most one "answers"-element + if(existingAnswersElement!=null) {questionNode.removeChild(existingAnswersElement);} + + Element answersElement = doc.createElement("answers"); + questionNode.appendChild(answersElement); + for(String uri:uris) + { + Element answerElement = doc.createElement("answer"); + answerElement.setTextContent(uri); + answersElement.appendChild(answerElement); + } + System.out.print('.'); + continue; + } + } + // no answers gotten, mark for deletion + questionElementsToDelete.add(questionNode); + System.out.print('x'); + } + for(Element element: questionElementsToDelete) {doc.getDocumentElement().removeChild(element);} + + TransformerFactory tFactory = + TransformerFactory.newInstance(); + Transformer transformer = tFactory.newTransformer(); + + DOMSource source = new DOMSource(doc); + StreamResult result = new StreamResult(new FileOutputStream(updatedFile)); + transformer.transform(source, result); + +// catch (DOMException e) { +// e.printStackTrace(); +// } catch (ParserConfigurationException e) { +// e.printStackTrace(); +// } catch (SAXException e) { +// e.printStackTrace(); +// } catch (IOException e) { +// e.printStackTrace(); +// } + } + + + int correctMatches = 0; + int numberOfNoTemplateFoundExceptions = 0; + int numberOfOtherExceptions = 0; + // int successfullTestThreadRuns = 0; + /** */ private static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; private static Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); - private SPARQLTemplateBasedLearner3 oxfordLearner; - private SPARQLTemplateBasedLearner3 dbpediaLiveLearner; + // private SPARQLTemplateBasedLearner3 oxfordLearner; + // private SPARQLTemplateBasedLearner3 dbpediaLiveLearner; private ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); private ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); @@ -96,18 +261,25 @@ return kb; } - @Before - public void setup() throws MalformedURLException - { - logger.setLevel(Level.ALL); - // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); - // oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); - } + @Before + public void setup() throws IOException + { + logger.setLevel(Level.ALL); // TODO: remove when finishing implementation of this class + logger.addAppender(new FileAppender(new SimpleLayout(), "log/"+this.getClass().getSimpleName()+".log", false)); + // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); + // oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); + } - private void readQueries(final File file,final SortedMap<Integer, String> id2Question,final SortedMap<Integer, String> id2Query) + private class QueryTestData { - id2Question.clear(); - id2Query.clear(); + public SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); + public SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); + public SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); + } + + private QueryTestData readQueries(final File file) + { + QueryTestData testData = new QueryTestData(); logger.info("Reading file containing queries and answers..."); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -116,11 +288,12 @@ doc.getDocumentElement().normalize(); NodeList questionNodes = doc.getElementsByTagName("question"); int id; - String question; - String query; - Set<String> answers; - for(int i = 0; i < questionNodes.getLength(); i++){ + for(int i = 0; i < questionNodes.getLength(); i++) + { + String question; + String query; + Set<String> answers = new HashSet<String>(); Element questionNode = (Element) questionNodes.item(i); //read question ID id = Integer.valueOf(questionNode.getAttribute("id")); @@ -138,8 +311,19 @@ if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) { - id2Question.put(id, question); - id2Query.put(id, query); + testData.id2Question.put(id, question); + testData.id2Query.put(id, query); + Element answersElement = (Element) questionNode.getElementsByTagName("answers").item(0); + if(answersElement!=null) + { + NodeList answerElements = answersElement.getElementsByTagName("answer"); + for(int j=0; j<answerElements.getLength();j++) + { + String answer = ((Element)answerElements.item(j)).getTextContent(); + answers.add(answer); + } + testData.id2Answers.put(id, answers); + } } // question2Answers.put(question, answers); @@ -168,83 +352,180 @@ // // } logger.info("Done."); + return testData; } - private Set<String> getURIs(String endpoint, String query) + private Set<String> getUris(String endpoint, String query) { + if(!query.contains("SELECT")&&!query.contains("select")) {return Collections.<String>emptySet();} // abort when not a select query Set<String> uris = new HashSet<String>(); QueryEngineHTTP qe = new QueryEngineHTTP(DBPEDIA_LIVE_ENDPOINT_URL_STRING, query); ResultSet rs = qe.execSelect(); - while(rs.hasNext()) - { - QuerySolution qs = rs.nextSolution(); - String uri = qs.getResource("?uri").getURI(); - uris.add(uri); - } + String variable = "?uri"; + resultsetloop: + while(rs.hasNext()) + { + QuerySolution qs = rs.nextSolution(); + RDFNode node = qs.get(variable); + if(node!=null&&node.isResource()) + { + String uri=node.asResource().getURI(); + uris.add(uri); + } + else // there is no variable "uri" + { + // try to guess the correct variable by using the first one which is assigned to a resource + for(Iterator<String> it = qs.varNames();it.hasNext();) + { + String varName = it.next(); + RDFNode node2 = qs.get(varName); + if(node2.isResource()) + { + variable = "?"+varName; + String uri=node2.asResource().getURI(); + uris.add(uri); + continue resultsetloop; + } + } + return Collections.<String>emptySet(); // we didn't a resource for the first query solution - give up and don't look in the others + } + } return uris; } - @Test public void testDBpedia() throws NoTemplateFoundException, ComponentInitException, MalformedURLException + private class TestQueryThread implements Runnable { - SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); - SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); - SortedMap<Integer, Object> id2Answer = new TreeMap<Integer, Object>(); + private String question; + private String referenceQuery; + public TestQueryThread(String question, String referenceQuery) { - String s = "tbsl/evaluation/qald2-dbpedia-train.xml"; - URL url = getClass().getClassLoader().getResource(s); - assertFalse("resource not found: "+s,url==null); - readQueries(new File(url.getPath()),id2Question,id2Query); + this.question=question; + this.referenceQuery=referenceQuery; } - assertTrue("no questions loaded",id2Question.size()>0); - logger.info(id2Question.size()+" questions loaded."); - assertTrue(String.format("no number of questions (%n) != number of queries (%n).",id2Question.size(),id2Query.size()), - id2Question.size()==id2Query.size()); + // String referenceQuery = id2Query.get(i); + // String question = id2Question.get(i); + @Override public void run() + { - // get question and answer from file - dbpediaLiveEndpoint = new SparqlEndpoint(new URL(DBPEDIA_LIVE_ENDPOINT_URL_STRING), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); - - dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); - dbpediaLiveLearner.init(); - - // TODO: use thread pools - for(int i: id2Query.keySet()) - { - if(i>3) break; // TODO: remove - String question = id2Question.get(i); logger.trace("question: "+question); - String referenceQuery = id2Query.get(i); + // TODO: check for query isomorphism and leave out result comparison if possible // TODO: only load the reference answers once and permanently cache them somehow (file, ehcache, serialization, ...) // get the answers for the gold standard query logger.trace("reference query: "+referenceQuery); - - Set<String> referenceURIs = getURIs(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); - - // learn query - dbpediaLiveLearner.setQuestion(question); - dbpediaLiveLearner.learnSPARQLQueries(); - String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); - - logger.trace(learnedQuery); - - Set<String> learnedURIs = getURIs(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); - - logger.trace(referenceURIs); - logger.trace(learnedURIs); - assertTrue(referenceURIs.equals(learnedURIs)); + + try + { + Set<String> referenceURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); + + // learn query + SPARQLTemplateBasedLearner3 dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); + dbpediaLiveLearner.init(); + dbpediaLiveLearner.setQuestion(question); + dbpediaLiveLearner.learnSPARQLQueries(); + String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); + + logger.trace(learnedQuery); + + Set<String> learnedURIs = getUris(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); + + logger.trace("referenced uris: "+referenceURIs); + logger.trace("learned uris: "+learnedURIs); + + boolean correctMatch = referenceURIs.equals(learnedURIs); + logger.trace(correctMatch?"matches":"doesn't match"); + if(correctMatch) {synchronized(this) {correctMatches++;}} + } + catch(NoTemplateFoundException e) + { + synchronized(this) {numberOfNoTemplateFoundExceptions++;} + logger.warn(String.format("no template found for question \"%s\"",question)); + } + catch(Exception e) + { + synchronized(this) {numberOfOtherExceptions++;} + logger.error(String.format("Exception for question \"%s\": %s",question,e.getLocalizedMessage())); + e.printStackTrace(); + // maybe the exception has corrupted the learner? better create a new one + // + } // get the answers for the learned query // compare gold standard query and learned query answers } - -// dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); -// dbpediaLiveLearner.learnSPARQLQueries(); -// String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); -// logger.trace(learnedQuery); - //fail("Not yet implemented"); } + private void updateFile(File originalFile, File updatedFile, String endpoint) + { + + + } + +// private void test(File file) throws MalformedURLException, InterruptedException +// { +// SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); +// SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); +// SortedMap<Integer, Set<String>> id2Answers = new TreeMap<Integer, Set<String>>(); +// +// { +// // URL url = getClass().getClassLoader().getResource(s); +// // assertFalse("resource not found: "+s,url==null); +// // readQueries(new File(url.getPath()),id2Question,id2Query); +// readQueries(file); +// } +// assertTrue("no questions loaded",id2Question.size()>0); +// logger.info(id2Question.size()+" questions loaded."); +// assertTrue(String.format("number of questions (%d) != number of queries (%d).",id2Question.size(),id2Query.size()), +// id2Question.size()==id2Query.size()); +// +// // get question and answer from file +// dbpediaLiveEndpoint = new SparqlEndpoint(new URL(DBPEDIA_LIVE_ENDPOINT_URL_STRING), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); +// +// // dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); +// // dbpediaLiveLearner.init(); +// +// // TODO: use thread pools +// ExecutorService service = Executors.newFixedThreadPool(10); +// for(int i: id2Query.keySet()) +// { +// Runnable r = new TestQueryThread(id2Question.get(i),id2Query.get(i)); +// service.execute(r); +// } +// boolean timeout =!service.awaitTermination(600, TimeUnit.SECONDS); +// +// logger.info(timeout?"timeout":"finished all threads"); +// if(numberOfNoTemplateFoundExceptions>0) {logger.warn(numberOfNoTemplateFoundExceptions+" NoTemplateFoundExceptions");} +// if(numberOfOtherExceptions>0) {logger.error(numberOfOtherExceptions+" other exceptions");} +// assertTrue(String.format("only %d/%d correct answers",correctMatches,id2Query.size()),correctMatches==id2Query.size()); +// +// // dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); +// // dbpediaLiveLearner.learnSPARQLQueries(); +// // String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); +// // logger.trace(learnedQuery); +// //fail("Not yet implemented"); +// } + +// @Test public void testDBpediaX() throws NoTemplateFoundException, ComponentInitException, MalformedURLException, InterruptedException +// { +// // original file - qald benchmark xml +// // updated file - delete questions giving no nonempty list of resources (literals, ask query, no result or error) +// final String originalDirName = "tbsl/evaluation"; +// final String updatedDirName = "cache"; +// final File processedDir = new File(updatedDirName); +// +// if(!processedDir.exists()) {processedDir.mkdirs();} +// +// final String originalFilename = "qald2-dbpedia-train.xml"; +// final String updatedFilename = "processed_"+originalFilename; +// final File originalFile = new File(originalDirName+'/'+originalFilename); +// final File updatedFile = new File(updatedDirName+'/'+updatedFilename); +// +// if(!updatedFile.exists()) {updateFile(originalFile,updatedFile,DBPEDIA_LIVE_ENDPOINT_URL_STRING);} +// +// test(updatedFile); +// +// } // @Test public void test() throws NoTemplateFoundException, ComponentInitException // { // // get question and answer from file @@ -256,5 +537,4 @@ // // //fail("Not yet implemented"); // } - } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-25 10:34:00
|
Revision: 3804 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3804&view=rev Author: lorenz_b Date: 2012-07-25 10:33:43 +0000 (Wed, 25 Jul 2012) Log Message: ----------- Changed default log level to DEBUG. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-23 14:25:40 UTC (rev 3803) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-25 10:33:43 UTC (rev 3804) @@ -65,7 +65,6 @@ import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; import org.dllearner.core.owl.Description; -import org.dllearner.core.owl.Intersection; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.Thing; @@ -76,7 +75,6 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; -import org.semanticweb.HermiT.Configuration.DirectBlockingType; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; @@ -84,7 +82,6 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.shared.UnknownPropertyException; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.RDFS; import com.jamonapi.Monitor; @@ -92,7 +89,6 @@ public class SPARQLTemplateBasedLearner2 implements SparqlQueryLearningAlgorithm{ - enum Mode{ BEST_QUERY, BEST_NON_EMPTY_QUERY } @@ -383,7 +379,7 @@ public void learnSPARQLQueries() throws NoTemplateFoundException{ reset(); //generate SPARQL query templates - logger.info("Generating SPARQL query templates..."); + logger.debug("Generating SPARQL query templates..."); templateMon.start(); if(multiThreaded){ templates = templateGenerator.buildTemplatesMultiThreaded(question); @@ -391,15 +387,15 @@ templates = templateGenerator.buildTemplates(question); } templateMon.stop(); - logger.info("Done in " + templateMon.getLastValue() + "ms."); + logger.debug("Done in " + templateMon.getLastValue() + "ms."); relevantKeywords.addAll(templateGenerator.getUnknownWords()); if(templates.isEmpty()){ throw new NoTemplateFoundException(); } - logger.info("Templates:"); + logger.debug("Templates:"); for(Template t : templates){ - logger.info(t); + logger.debug(t); } //get the weighted query candidates @@ -407,7 +403,7 @@ sparqlQueryCandidates = new ArrayList<WeightedQuery>(); int i = 0; for(WeightedQuery wQ : generatedQueries){ - System.out.println(wQ.explain()); + logger.debug(wQ.explain()); sparqlQueryCandidates.add(wQ); if(i == maxTestedQueries){ break; @@ -506,7 +502,7 @@ } private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ - logger.info("Generating SPARQL query candidates..."); + logger.debug("Generating SPARQL query candidates..."); Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { @@ -527,7 +523,7 @@ Set<Allocation> allocations; for(Template t : templates){ - logger.info("Processing template:\n" + t.toString()); + logger.debug("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); @@ -541,9 +537,7 @@ Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); list.add(submit); - } else { - System.out.println("CACHE HIT"); - } + } } for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { @@ -582,7 +576,7 @@ } allocations.addAll(tmp); }*/ - System.out.println("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + logger.debug("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); Query cleanQuery = t.getQuery(); @@ -794,10 +788,8 @@ List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); for(SPARQL_Triple typeTriple : typeTriples){ String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); - System.out.println(typeURI + "---" + resourceURI); List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); for(Entry<String, Integer> property : mostFrequentProperties){ - System.out.println(property); wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); wQ.setScore(wQ.getScore() + 0.1); } @@ -859,7 +851,7 @@ } template2Queries.put(t, qList); } - logger.info("...done in "); + logger.debug("...done in "); return allQueries; } @@ -993,14 +985,14 @@ } private void validate(Collection<WeightedQuery> queries, SPARQL_QueryType queryType){ - logger.info("Testing candidate SPARQL queries on remote endpoint..."); + logger.debug("Testing candidate SPARQL queries on remote endpoint..."); sparqlMon.start(); if(queryType == SPARQL_QueryType.SELECT){ for(WeightedQuery query : queries){ learnedPos++; List<String> results; try { - logger.info("Testing query:\n" + query); + logger.debug("Testing query:\n" + query); com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); q.setLimit(1); ResultSet rs = executeSelect(q.toString()); @@ -1033,7 +1025,7 @@ return; } } - logger.info("Result: " + results); + logger.debug("Result: " + results); } } catch (Exception e) { e.printStackTrace(); @@ -1043,7 +1035,7 @@ } else if(queryType == SPARQL_QueryType.ASK){ for(WeightedQuery query : queries){ learnedPos++; - logger.info("Testing query:\n" + query); + logger.debug("Testing query:\n" + query); boolean result = executeAskQuery(query.getQuery().toString()); learnedSPARQLQueries.add(query); // if(stopIfQueryResultNotEmpty && result){ @@ -1052,12 +1044,12 @@ if(stopIfQueryResultNotEmpty){ return; } - logger.info("Result: " + result); + logger.debug("Result: " + result); } } sparqlMon.stop(); - logger.info("Done in " + sparqlMon.getLastValue() + "ms."); + logger.debug("Done in " + sparqlMon.getLastValue() + "ms."); } private boolean executeAskQuery(String query){ @@ -1154,7 +1146,7 @@ } private SortedSet<Allocation> computeAllocations(Slot slot){ - logger.info("Computing allocations for slot: " + slot); + logger.debug("Computing allocations for slot: " + slot); SortedSet<Allocation> allocations = new TreeSet<Allocation>(); Index index = getIndexBySlotType(slot); @@ -1210,7 +1202,7 @@ normProminenceValues(allocations); computeScore(allocations); - logger.info("Found " + allocations.size() + " allocations for slot " + slot); + logger.debug("Found " + allocations.size() + " allocations for slot " + slot); return new TreeSet<Allocation>(allocations); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-07-23 14:25:40 UTC (rev 3803) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Parser.java 2012-07-25 10:33:43 UTC (rev 3804) @@ -145,7 +145,7 @@ internalParseMultiThreaded(parseGrammar.getDPInitTrees(), n); } - if (VERBOSE) logger.trace("Constructed " + derivationTrees.size() + " derivation trees.\n"); + if (VERBOSE) logger.debug("Constructed " + derivationTrees.size() + " derivation trees.\n"); return derivationTrees; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2012-07-23 14:25:40 UTC (rev 3803) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/ltag/parser/Preprocessor.java 2012-07-25 10:33:43 UTC (rev 3804) @@ -102,67 +102,67 @@ m = compAdjPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/JJR"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/JJR"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/JJR"); } // m = superAdjPattern.matcher(condensedstring); // while (m.find()) { -// logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/JJS"); +// logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/JJS"); // condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/JJS"); // } m = howManyPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by how/WLEX many/WLEX"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by how/WLEX many/WLEX"); condensedstring = condensedstring.replaceFirst(m.group(1),"how/WLEX many/WLEX"); } m = howAdjPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/JJH"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/JJH"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/JJH"); } m = thesameasPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/NNSAME"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/NNSAME"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/NNSAME"); } m = nprepPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/NPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/NPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/NPREP"); } m = didPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by \"\""); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by \"\""); condensedstring = condensedstring.replaceFirst(m.group(1),""); } m = prepfrontPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by \"\""); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by \"\""); condensedstring = condensedstring.replaceFirst(m.group(1),""); } m = passivePattern1a.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(6)+"/PASSIVE"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(6)+"/PASSIVE"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(6)+"/PASSIVE"); } m = passivePattern1b.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(6)+m.group(7)+"/PASSIVE"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(6)+m.group(7)+"/PASSIVE"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(6) + m.group(7)+"/PASSIVE"); } m = passivePattern2a.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(7)+"/PASSIVE"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(7)+"/PASSIVE"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(7)+"/PASSIVE"); } m = pseudopassPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(7)+"/VPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(7)+"/VPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(7)+"/VPREP"); } m = pseudopwhPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(7)+m.group(8)+"/VPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(7)+m.group(8)+"/VPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(7)+" "+m.group(8)+"/VPREP"); } m = saveIsThere.matcher(condensedstring); @@ -171,64 +171,64 @@ } m = passivePattern2b.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(7)+"/PASSIVE"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(7)+"/PASSIVE"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(7)+"/PASSIVE"); } m = passpartPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/PASSPART"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/PASSPART"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/PASSPART"); } m = vpassPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/VPASS"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/VPASS"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/VPASS"); } m = vpassinPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/VPASSIN"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/VPASSIN"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/VPASSIN"); } m = gerundinPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/GERUNDIN"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/GERUNDIN"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/GERUNDIN"); } m = vprepPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"/VPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"/VPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"/VPREP"); } m = whenPattern.matcher(condensedstring); while (m.find()) { if (m.group(4).equals("VPREP")) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHENPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHENPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2) + m.group(3)+"/WHENPREP"); } else { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHEN"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHEN"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2) + m.group(3)+"/WHEN"); } } m = wherePattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHERE"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+m.group(3)+"/WHERE"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2) + m.group(3)+"/WHERE"); } m = adjsPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/JJ"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/JJ"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"_"+m.group(3)+"/JJ"); } m = adjnounPattern.matcher(condensedstring); while (m.find()) { // if (!m.group(4).startsWith("NNP")) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/JJNN"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/JJNN"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"_"+m.group(3)+"/JJNN "); // } } m = adjnprepPattern.matcher(condensedstring); while (m.find()) { - if (VERBOSE) logger.trace("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/NPREP"); + if (VERBOSE) logger.debug("Replacing " + m.group(1) + " by " + m.group(2)+"_"+m.group(3)+"/NPREP"); condensedstring = condensedstring.replaceFirst(m.group(1),m.group(2)+"_"+m.group(3)+"/NPREP"); } @@ -291,7 +291,7 @@ List<String> namedentities = ner.getNamedEntitites(untagged); List<String> usefulnamedentities = new ArrayList<String>(); - if (VERBOSE) logger.trace("Proposed NEs: " + namedentities); + if (VERBOSE) logger.debug("Proposed NEs: " + namedentities); // keep only longest matches (e.g. keep 'World of Warcraft' and forget about 'Warcraft') // containing at least one upper case letter (in order to filter out errors like 'software') @@ -309,7 +309,7 @@ } } - if (VERBOSE) logger.trace("Accepted NEs: " + usefulnamedentities); + if (VERBOSE) logger.debug("Accepted NEs: " + usefulnamedentities); // replace POS tags accordingly for (String ne : usefulnamedentities) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-07-23 14:25:40 UTC (rev 3803) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/templator/Templator.java 2012-07-25 10:33:43 UTC (rev 3804) @@ -164,7 +164,7 @@ if (UNTAGGED_INPUT) { s = pp.normalize(s); tagged = tagger.tag(s); - if (VERBOSE) logger.trace("Tagged input: " + tagged); + logger.debug("Tagged input: " + tagged); } else { tagged = s; @@ -178,7 +178,7 @@ else newtagged = pp.condenseNominals(tagged); newtagged = pp.condense(newtagged); - if (VERBOSE) logger.trace("Preprocessed: " + newtagged); + logger.debug("Preprocessed: " + newtagged); parser.parse(newtagged,g); @@ -219,10 +219,10 @@ if (!containsModuloRenaming(drses,drs)) { // // DEBUG if (VERBOSE) { - System.out.println(">>> DUDE:\n" + dude.toString()); - System.out.println("\n>>> DRS:\n"+ drs.toString()); + logger.debug(">>> DUDE:\n" + dude.toString()); + logger.debug("\n>>> DRS:\n"+ drs.toString()); for (Slot sl : slots) { - System.out.println(sl.toString()); + logger.debug(sl.toString()); } } // // @@ -310,7 +310,7 @@ if (UNTAGGED_INPUT) { s = pp.normalize(s); tagged = tagger.tag(s); - if (VERBOSE) logger.trace("Tagged input: " + tagged); + logger.debug("Tagged input: " + tagged); } else { tagged = s; @@ -324,20 +324,20 @@ else newtagged = pp.condenseNominals(tagged); newtagged = pp.condense(newtagged); - if (VERBOSE) logger.trace("Preprocessed: " + newtagged); + logger.debug("Preprocessed: " + newtagged); parser.parseMultiThreaded(newtagged,g); if (parser.getDerivationTrees().isEmpty()) { parser.clear(g,parser.getTemps()); clearAgain = false; - if (VERBOSE) logger.error("[Templator.java] '" + s + "' could not be parsed."); + logger.error("[Templator.java] '" + s + "' could not be parsed."); } else { try { parser.buildDerivedTreesMultiThreaded(g); } catch (ParseException e) { - if (VERBOSE) logger.error("[Templator.java] ParseException at '" + e.getMessage() + "'", e); + logger.error("[Templator.java] ParseException at '" + e.getMessage() + "'", e); } } @@ -372,13 +372,11 @@ if (!containsModuloRenaming(drses,drs)) { // // DEBUG - if (VERBOSE) { - System.out.println(dude); - System.out.println(drs); + logger.debug(dude); + logger.debug(drs); for (Slot sl : slots) { - System.out.println(sl.toString()); + logger.debug(sl.toString()); } - } // // drses.add(drs); @@ -546,10 +544,10 @@ if (!containsModuloRenaming(drses,drs)) { // // DEBUG if (VERBOSE) { - System.out.println(dude); - System.out.println(drs); + logger.debug(dude); + logger.debug(drs); for (Slot sl : slots) { - System.out.println(sl.toString()); + logger.debug(sl.toString()); } } // // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-07-23 14:25:51
|
Revision: 3803 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3803&view=rev Author: kirdie Date: 2012-07-23 14:25:40 +0000 (Mon, 23 Jul 2012) Log Message: ----------- tests for dbpedia should work now but there is still a problem with the solr index (down?). Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-20 14:01:29 UTC (rev 3802) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-23 14:25:40 UTC (rev 3803) @@ -1,22 +1,21 @@ package org.dllearner.algorithm.tbsl.learning; -import static org.junit.Assert.fail; -import java.io.BufferedWriter; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; +import java.util.HashSet; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; -import java.util.Map.Entry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.dllearner.algorithm.tbsl.Evaluation; import org.dllearner.algorithm.tbsl.util.Knowledgebase; import org.dllearner.common.index.Index; import org.dllearner.common.index.MappingBasedIndex; @@ -36,29 +35,30 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; /** @author konrad * */ public class SPARQLTemplateBasedLearner3Test { + /** */ + private static final String DBPEDIA_LIVE_ENDPOINT_URL_STRING = "http://live.dbpedia.org/sparql"; + private static Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); - + private SPARQLTemplateBasedLearner3 oxfordLearner; private SPARQLTemplateBasedLearner3 dbpediaLiveLearner; - + private ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); private ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); SparqlEndpoint dbpediaLiveEndpoint; SparqlEndpoint oxfordEndpoint; - - private SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); - private SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); - private SortedMap<Integer, Object> id2Answer = new TreeMap<Integer, Object>(); - + private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} - + private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) throws MalformedURLException { SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); @@ -96,18 +96,18 @@ return kb; } - @Before - public void setup() throws MalformedURLException + @Before + public void setup() throws MalformedURLException + { + logger.setLevel(Level.ALL); + // oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); + // oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); + } + + private void readQueries(final File file,final SortedMap<Integer, String> id2Question,final SortedMap<Integer, String> id2Query) { - dbpediaLiveEndpoint = new SparqlEndpoint(new URL("http://live.dbpedia.org/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); - dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); - -// oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); -// oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); - } - - private void readQueries(File file) - { + id2Question.clear(); + id2Query.clear(); logger.info("Reading file containing queries and answers..."); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); @@ -119,7 +119,7 @@ String question; String query; Set<String> answers; - + for(int i = 0; i < questionNodes.getLength(); i++){ Element questionNode = (Element) questionNodes.item(i); //read question ID @@ -128,18 +128,21 @@ question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); //Read SPARQL query query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); -// //Read answers -// answers = new HashSet<String>(); -// NodeList aswersNodes = questionNode.getElementsByTagName("answer"); -// for(int j = 0; j < aswersNodes.getLength(); j++){ -// Element answerNode = (Element) aswersNodes.item(j); -// answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); -// } - - id2Question.put(id, question); - id2Query.put(id, query); -// question2Answers.put(question, answers); - + // //Read answers + // answers = new HashSet<String>(); + // NodeList aswersNodes = questionNode.getElementsByTagName("answer"); + // for(int j = 0; j < aswersNodes.getLength(); j++){ + // Element answerNode = (Element) aswersNodes.item(j); + // answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); + // } + + if(!query.equals("OUT OF SCOPE")) // marker in qald benchmark file, will create holes interval of ids (e.g. 1,2,5,7) + { + id2Question.put(id, question); + id2Query.put(id, query); + } + // question2Answers.put(question, answers); + } } catch (DOMException e) { e.printStackTrace(); @@ -150,47 +153,108 @@ } catch (IOException e) { e.printStackTrace(); } -// StringBuilder sb = new StringBuilder(); -// for(Entry<Integer, String> e : id2Question.entrySet()){ -// sb.append(e.getKey()+ ": " + extractSentence(e.getValue()) + "\n"); -// } -// try { -// BufferedWriter out = new BufferedWriter(new FileWriter("questions.txt")); -// out.write(sb.toString()); -// out.close(); -// } -// catch (IOException e) -// { -// System.out.println("Exception "); -// -// } + // StringBuilder sb = new StringBuilder(); + // for(Entry<Integer, String> e : id2Question.entrySet()){ + // sb.append(e.getKey()+ ": " + extractSentence(e.getValue()) + "\n"); + // } + // try { + // BufferedWriter out = new BufferedWriter(new FileWriter("questions.txt")); + // out.write(sb.toString()); + // out.close(); + // } + // catch (IOException e) + // { + // System.out.println("Exception "); + // + // } logger.info("Done."); } - @Test public void testDBpedia() throws NoTemplateFoundException, ComponentInitException + private Set<String> getURIs(String endpoint, String query) { + Set<String> uris = new HashSet<String>(); + QueryEngineHTTP qe = new QueryEngineHTTP(DBPEDIA_LIVE_ENDPOINT_URL_STRING, query); + ResultSet rs = qe.execSelect(); + while(rs.hasNext()) + { + QuerySolution qs = rs.nextSolution(); + String uri = qs.getResource("?uri").getURI(); + uris.add(uri); + } + return uris; + } + + @Test public void testDBpedia() throws NoTemplateFoundException, ComponentInitException, MalformedURLException + { + SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); + SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); + SortedMap<Integer, Object> id2Answer = new TreeMap<Integer, Object>(); + + { + String s = "tbsl/evaluation/qald2-dbpedia-train.xml"; + URL url = getClass().getClassLoader().getResource(s); + assertFalse("resource not found: "+s,url==null); + readQueries(new File(url.getPath()),id2Question,id2Query); + } + assertTrue("no questions loaded",id2Question.size()>0); + logger.info(id2Question.size()+" questions loaded."); + assertTrue(String.format("no number of questions (%n) != number of queries (%n).",id2Question.size(),id2Query.size()), + id2Question.size()==id2Query.size()); + // get question and answer from file - readQueries(new File(getClass().getClassLoader().getResource("/tbsl/evaluation/qald2-dbpedia-train.xml").getPath())); + dbpediaLiveEndpoint = new SparqlEndpoint(new URL(DBPEDIA_LIVE_ENDPOINT_URL_STRING), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); + + dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); dbpediaLiveLearner.init(); - dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); - dbpediaLiveLearner.learnSPARQLQueries(); - String learnedQuery = oxfordLearner.getBestSPARQLQuery(); + // TODO: use thread pools + for(int i: id2Query.keySet()) + { + if(i>3) break; // TODO: remove + String question = id2Question.get(i); + logger.trace("question: "+question); + String referenceQuery = id2Query.get(i); + // TODO: check for query isomorphism and leave out result comparison if possible + // TODO: only load the reference answers once and permanently cache them somehow (file, ehcache, serialization, ...) + // get the answers for the gold standard query + logger.trace("reference query: "+referenceQuery); + + Set<String> referenceURIs = getURIs(DBPEDIA_LIVE_ENDPOINT_URL_STRING,referenceQuery); + // learn query + dbpediaLiveLearner.setQuestion(question); + dbpediaLiveLearner.learnSPARQLQueries(); + String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); + + logger.trace(learnedQuery); + + Set<String> learnedURIs = getURIs(DBPEDIA_LIVE_ENDPOINT_URL_STRING,learnedQuery); + + logger.trace(referenceURIs); + logger.trace(learnedURIs); + assertTrue(referenceURIs.equals(learnedURIs)); + // get the answers for the learned query + // compare gold standard query and learned query answers + } + + +// dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); +// dbpediaLiveLearner.learnSPARQLQueries(); +// String learnedQuery = dbpediaLiveLearner.getBestSPARQLQuery(); +// logger.trace(learnedQuery); //fail("Not yet implemented"); } - - -// @Test public void test() throws NoTemplateFoundException, ComponentInitException -// { -// // get question and answer from file -// -// oxfordLearner.init(); -// oxfordLearner.setQuestion("houses with more than 2 bedrooms"); -// oxfordLearner.learnSPARQLQueries(); -// String learnedQuery = oxfordLearner.getBestSPARQLQuery(); -// -// //fail("Not yet implemented"); -// } + // @Test public void test() throws NoTemplateFoundException, ComponentInitException + // { + // // get question and answer from file + // + // oxfordLearner.init(); + // oxfordLearner.setQuestion("houses with more than 2 bedrooms"); + // oxfordLearner.learnSPARQLQueries(); + // String learnedQuery = oxfordLearner.getBestSPARQLQuery(); + // + // //fail("Not yet implemented"); + // } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ki...@us...> - 2012-07-20 14:01:35
|
Revision: 3802 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3802&view=rev Author: kirdie Date: 2012-07-20 14:01:29 +0000 (Fri, 20 Jul 2012) Log Message: ----------- continued on Junit test (not finished). Added Paths: ----------- trunk/components-ext/src/main/resources/test/ trunk/components-ext/src/main/resources/test/dbpedia_class_mappings.txt trunk/components-ext/src/main/resources/test/dbpedia_dataproperty_mappings.txt trunk/components-ext/src/main/resources/test/dbpedia_objectproperty_mappings.txt trunk/components-ext/src/main/resources/test/dbpedia_resource_mappings.txt trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java Added: trunk/components-ext/src/main/resources/test/dbpedia_class_mappings.txt =================================================================== Added: trunk/components-ext/src/main/resources/test/dbpedia_dataproperty_mappings.txt =================================================================== Added: trunk/components-ext/src/main/resources/test/dbpedia_objectproperty_mappings.txt =================================================================== --- trunk/components-ext/src/main/resources/test/dbpedia_objectproperty_mappings.txt (rev 0) +++ trunk/components-ext/src/main/resources/test/dbpedia_objectproperty_mappings.txt 2012-07-20 14:01:29 UTC (rev 3802) @@ -0,0 +1,6 @@ +http://dbpedia.org/ontology/writer|written by, written +http://dbpedia.org/ontology/author|written by, written, author, author of +http://dbpedia.org/ontology/director|directed by, directed, director +http://dbpedia.org/ontology/producer|produced by, produced, producer +http://dbpedia.org/ontology/birthPlace|birth place, birth, born in, born +http://dbpedia.org/ontology/deathPlace|death place, death, died in, died \ No newline at end of file Added: trunk/components-ext/src/main/resources/test/dbpedia_resource_mappings.txt =================================================================== Added: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java (rev 0) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3Test.java 2012-07-20 14:01:29 UTC (rev 3802) @@ -0,0 +1,196 @@ +package org.dllearner.algorithm.tbsl.learning; + +import static org.junit.Assert.fail; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.Map.Entry; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.apache.log4j.Logger; +import org.dllearner.algorithm.tbsl.Evaluation; +import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.common.index.Index; +import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.common.index.SOLRIndex; +import org.dllearner.common.index.SPARQLIndex; +import org.dllearner.common.index.VirtuosoClassesIndex; +import org.dllearner.common.index.VirtuosoPropertiesIndex; +import org.dllearner.common.index.VirtuosoResourcesIndex; +import org.dllearner.core.ComponentInitException; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; +import com.hp.hpl.jena.query.ResultSet; + +/** @author konrad * */ +public class SPARQLTemplateBasedLearner3Test +{ + private static Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3Test.class); + + private SPARQLTemplateBasedLearner3 oxfordLearner; + private SPARQLTemplateBasedLearner3 dbpediaLiveLearner; + + private ExtractionDBCache oxfordCache = new ExtractionDBCache("cache"); + private ExtractionDBCache dbpediaLiveCache = new ExtractionDBCache("cache"); + + SparqlEndpoint dbpediaLiveEndpoint; + SparqlEndpoint oxfordEndpoint; + + private SortedMap<Integer, String> id2Question = new TreeMap<Integer, String>(); + private SortedMap<Integer, String> id2Query = new TreeMap<Integer, String>(); + private SortedMap<Integer, Object> id2Answer = new TreeMap<Integer, Object>(); + + private ResultSet executeDBpediaLiveSelect(String query){return SparqlQuery.convertJSONtoResultSet(dbpediaLiveCache.executeSelectQuery(dbpediaLiveEndpoint, query));} + private ResultSet executeOxfordSelect(String query){return SparqlQuery.convertJSONtoResultSet(oxfordCache.executeSelectQuery(oxfordEndpoint, query));} + + private Knowledgebase createOxfordKnowledgebase(ExtractionDBCache cache) throws MalformedURLException + { + SparqlEndpoint endpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); + + SPARQLIndex resourcesIndex = new VirtuosoResourcesIndex(endpoint, cache); + SPARQLIndex classesIndex = new VirtuosoClassesIndex(endpoint, cache); + SPARQLIndex propertiesIndex = new VirtuosoPropertiesIndex(endpoint, cache); + MappingBasedIndex mappingIndex= new MappingBasedIndex( + this.getClass().getClassLoader().getResource("tbsl/oxford_class_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("tbsl/oxford_resource_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("tbsl/oxford_dataproperty_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("tbsl/oxford_objectproperty_mappings.txt").getPath() + ); + + Knowledgebase kb = new Knowledgebase(oxfordEndpoint, "Oxford - Real estate", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); + return kb; + } + + private Knowledgebase createDBpediaLiveKnowledgebase(ExtractionDBCache cache) throws MalformedURLException + { + SOLRIndex resourcesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_resources"); + resourcesIndex.setPrimarySearchField("label"); + // resourcesIndex.setSortField("pagerank"); + Index classesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_classes"); + Index propertiesIndex = new SOLRIndex("http://dbpedia.aksw.org:8080/solr/dbpedia_properties"); + + MappingBasedIndex mappingIndex= new MappingBasedIndex( + this.getClass().getClassLoader().getResource("test/dbpedia_class_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("test/dbpedia_resource_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("test/dbpedia_dataproperty_mappings.txt").getPath(), + this.getClass().getClassLoader().getResource("test/dbpedia_objectproperty_mappings.txt").getPath() + ); + + Knowledgebase kb = new Knowledgebase(dbpediaLiveEndpoint, "DBpedia Live", "TODO", resourcesIndex, propertiesIndex, classesIndex, mappingIndex); + return kb; + } + + @Before + public void setup() throws MalformedURLException + { + dbpediaLiveEndpoint = new SparqlEndpoint(new URL("http://live.dbpedia.org/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()); + dbpediaLiveLearner = new SPARQLTemplateBasedLearner3(createDBpediaLiveKnowledgebase(dbpediaLiveCache)); + +// oxfordEndpoint = new SparqlEndpoint(new URL("http://lgd.aksw.org:8900/sparql"), Collections.singletonList("http://diadem.cs.ox.ac.uk"), Collections.<String>emptyList()); +// oxfordLearner = new SPARQLTemplateBasedLearner3(createOxfordKnowledgebase(oxfordCache)); + } + + private void readQueries(File file) + { + logger.info("Reading file containing queries and answers..."); + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(file); + doc.getDocumentElement().normalize(); + NodeList questionNodes = doc.getElementsByTagName("question"); + int id; + String question; + String query; + Set<String> answers; + + for(int i = 0; i < questionNodes.getLength(); i++){ + Element questionNode = (Element) questionNodes.item(i); + //read question ID + id = Integer.valueOf(questionNode.getAttribute("id")); + //Read question + question = ((Element)questionNode.getElementsByTagName("string").item(0)).getChildNodes().item(0).getNodeValue().trim(); + //Read SPARQL query + query = ((Element)questionNode.getElementsByTagName("query").item(0)).getChildNodes().item(0).getNodeValue().trim(); +// //Read answers +// answers = new HashSet<String>(); +// NodeList aswersNodes = questionNode.getElementsByTagName("answer"); +// for(int j = 0; j < aswersNodes.getLength(); j++){ +// Element answerNode = (Element) aswersNodes.item(j); +// answers.add(((Element)answerNode.getElementsByTagName("uri").item(0)).getChildNodes().item(0).getNodeValue().trim()); +// } + + id2Question.put(id, question); + id2Query.put(id, query); +// question2Answers.put(question, answers); + + } + } catch (DOMException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } +// StringBuilder sb = new StringBuilder(); +// for(Entry<Integer, String> e : id2Question.entrySet()){ +// sb.append(e.getKey()+ ": " + extractSentence(e.getValue()) + "\n"); +// } +// try { +// BufferedWriter out = new BufferedWriter(new FileWriter("questions.txt")); +// out.write(sb.toString()); +// out.close(); +// } +// catch (IOException e) +// { +// System.out.println("Exception "); +// +// } + logger.info("Done."); + } + + @Test public void testDBpedia() throws NoTemplateFoundException, ComponentInitException + { + // get question and answer from file + readQueries(new File(getClass().getClassLoader().getResource("/tbsl/evaluation/qald2-dbpedia-train.xml").getPath())); + dbpediaLiveLearner.init(); + + dbpediaLiveLearner.setQuestion("houses with more than 2 bedrooms"); + dbpediaLiveLearner.learnSPARQLQueries(); + String learnedQuery = oxfordLearner.getBestSPARQLQuery(); + + //fail("Not yet implemented"); + } + + +// @Test public void test() throws NoTemplateFoundException, ComponentInitException +// { +// // get question and answer from file +// +// oxfordLearner.init(); +// oxfordLearner.setQuestion("houses with more than 2 bedrooms"); +// oxfordLearner.learnSPARQLQueries(); +// String learnedQuery = oxfordLearner.getBestSPARQLQuery(); +// +// //fail("Not yet implemented"); +// } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-20 12:44:47
|
Revision: 3801 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3801&view=rev Author: lorenz_b Date: 2012-07-20 12:44:41 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Some changes for precomputing metrics. Modified Paths: -------------- trunk/components-ext/pom.xml trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java trunk/components-ext/src/main/resources/tbsl/oxford_dataproperty_mappings.txt Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/pom.xml 2012-07-20 12:44:41 UTC (rev 3801) @@ -53,7 +53,6 @@ <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> - <version>3.5.0</version> </dependency> <!--BEGIN Logging Dependencies--> @@ -155,7 +154,6 @@ <dependency> <groupId>org.ini4j</groupId> <artifactId>ini4j</artifactId> - <version>0.5.2</version> </dependency> <dependency> <groupId>net.didion.jwnl</groupId> Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/qtl/operations/NBR.java 2012-07-20 12:44:41 UTC (rev 3801) @@ -40,6 +40,7 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.sparql.expr.E_Equals; import com.hp.hpl.jena.sparql.expr.E_LogicalNot; import com.hp.hpl.jena.sparql.expr.ExprVar; @@ -744,10 +745,14 @@ String uri; QuerySolution qs; + RDFNode node; while(rs.hasNext()){ qs = rs.next(); - uri = qs.getResource("x0").getURI(); - resources.add(uri); + node = qs.get("x0"); + if(node.isURIResource()){ + uri = qs.getResource("x0").getURI(); + resources.add(uri); + } } return resources; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-20 12:44:41 UTC (rev 3801) @@ -286,6 +286,10 @@ this.mappingIndex = mappingIndex; } + public void setCache(ExtractionDBCache cache) { + this.cache = cache; + } + public void setKnowledgebase(Knowledgebase knowledgebase){ this.endpoint = knowledgebase.getEndpoint(); this.resourcesIndex = knowledgebase.getResourceIndex(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-20 12:44:41 UTC (rev 3801) @@ -645,7 +645,7 @@ for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(varName)){ types.add(typeTriple.getValue().getName().replace(">", "").replace("<", "")); } - for(String type : types){System.out.println(type); + for(String type : types){ metrics.getGoodness(new NamedClass(type), new ObjectProperty(predicate.getName().replace(">", "").replace("<", "")), new Individual(object.getName().replace(">", "").replace("<", ""))); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java 2012-07-20 12:44:41 UTC (rev 3801) @@ -362,25 +362,25 @@ } } - for(NamedClass cls1 : classes){ - for(NamedClass cls2 : classes){ - if(!cls1.equals(cls2)){ - log.info("Processing class " + cls1 + " and class " + cls2); - try { - getPMI(cls1, cls2); - getPMI(cls2, cls1); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } +// for(NamedClass cls1 : classes){ +// for(NamedClass cls2 : classes){ +// if(!cls1.equals(cls2)){ +// log.info("Processing class " + cls1 + " and class " + cls2); +// try { +// getPMI(cls1, cls2); +// getPMI(cls2, cls1); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// } log.info("Done in " + ((System.currentTimeMillis() - startTime)/1000d) + "s"); } public static void main(String[] args) { - SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); - ExtractionDBCache cache = new ExtractionDBCache("/opt/tbsl/cache"); + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); + ExtractionDBCache cache = new ExtractionDBCache("/opt/tbsl/cache2"); String NS = "http://dbpedia.org/ontology/"; String NS_Res = "http://dbpedia.org/resource/"; Modified: trunk/components-ext/src/main/resources/tbsl/oxford_dataproperty_mappings.txt =================================================================== --- trunk/components-ext/src/main/resources/tbsl/oxford_dataproperty_mappings.txt 2012-07-20 12:43:03 UTC (rev 3800) +++ trunk/components-ext/src/main/resources/tbsl/oxford_dataproperty_mappings.txt 2012-07-20 12:44:41 UTC (rev 3801) @@ -1,5 +1,4 @@ http://www.w3.org/2006/vcard/ns#street-address|address, location, postal code -http://www.w3.org/2006/vcard/ns#locality|address, location http://purl.org/goodrelations/v1#description|description http://purl.org/goodrelations/v1#hasPrice|has price, price http://diadem.cs.ox.ac.uk/ontologies/real-estate#receptions|receptions, reception room, reception rooms \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-20 12:43:13
|
Revision: 3800 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3800&view=rev Author: lorenz_b Date: 2012-07-20 12:43:03 +0000 (Fri, 20 Jul 2012) Log Message: ----------- Updated ELK dependency. Fixed problem in SPARQL reasoner. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-07-19 08:12:17 UTC (rev 3799) +++ trunk/components-core/pom.xml 2012-07-20 12:43:03 UTC (rev 3800) @@ -230,7 +230,7 @@ <dependency> <groupId>org.semanticweb.elk</groupId> <artifactId>elk-owlapi</artifactId> - <version>0.2.0</version> + <version>0.3.0</version> </dependency> <dependency> <groupId>de.tudresden.inf.lat.cel</groupId> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2012-07-19 08:12:17 UTC (rev 3799) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ObjectPropertyDomainAxiomLearner.java 2012-07-20 12:43:03 UTC (rev 3800) @@ -190,7 +190,7 @@ ObjectPropertyDomainAxiomLearner l = new ObjectPropertyDomainAxiomLearner(ks); l.setReasoner(reasoner); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/creator")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/grammyAward")); l.setMaxExecutionTimeInSeconds(40); l.addFilterNamespace("http://dbpedia.org/ontology/"); // l.setReturnOnlyNewAxioms(true); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-07-19 08:12:17 UTC (rev 3799) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-07-20 12:43:03 UTC (rev 3800) @@ -108,15 +108,20 @@ if(useCache){ cache = new ExtractionDBCache("cache"); } + classPopularityMap = new HashMap<NamedClass, Integer>(); } public SPARQLReasoner(SparqlEndpointKS ks, ExtractionDBCache cache) { this.ks = ks; this.cache = cache; + + classPopularityMap = new HashMap<NamedClass, Integer>(); } public SPARQLReasoner(OntModel model) { this.model = model; + + classPopularityMap = new HashMap<NamedClass, Integer>(); } public void precomputePopularity(){ @@ -127,7 +132,6 @@ public void precomputeClassPopularity(){ logger.info("Precomputing class popularity ..."); - classPopularityMap = new HashMap<NamedClass, Integer>(); Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); String queryTemplate = "SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>}"; @@ -197,7 +201,7 @@ } public int getPopularity(NamedClass nc){ - if(classPopularityMap.containsKey(nc)){ + if(classPopularityMap != null && classPopularityMap.containsKey(nc)){ return classPopularityMap.get(nc); } else { System.out.println("Cache miss: " + nc); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2012-07-19 08:12:31
|
Revision: 3799 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3799&view=rev Author: edka Date: 2012-07-19 08:12:17 +0000 (Thu, 19 Jul 2012) Log Message: ----------- remove annotation-properties Modified Paths: -------------- trunk/test/phaenotype/mp.owl Added Paths: ----------- trunk/test/phaenotype/auswertung.txt trunk/test/phaenotype/mp-big.owl trunk/test/phaenotype/mp_no_anno.owl Added: trunk/test/phaenotype/auswertung.txt =================================================================== --- trunk/test/phaenotype/auswertung.txt (rev 0) +++ trunk/test/phaenotype/auswertung.txt 2012-07-19 08:12:17 UTC (rev 3799) @@ -0,0 +1,176 @@ +Bestand der mp-Datei + + + + +################################################################################################################################################### + +1 pos. Bsp ang. +1 neg. Bsp ang. +1 unb. pos. Bsp +1 unb. neg. Bsp + +Eintraege 7,8,16,17,20 aus unb. pos. Bsp mit 50% accuracy +Eintraege 1,2,3,4,5,6,9,10,11,12,13,14,15,18,19 aus bek. pos. Bsp mit 100% accuracy + +################################################################################################################################################### +DL-Learner command line interface +Initializing Component "OWL File"... OK (0ms) +Initializing Component "OWL File"... OK (0ms) +Initializing Component "OWL API Reasoner"... OK (831ms) +Initializing Component "PosNegLPStandard"... OK (0ms) +Initializing Component "OWL Class Expression Learner"... OK (90ms) +Running algorithm instance "alg" (OCEL) +starting top down refinement with: Thing (50% accuracy) +start node: TOP [acc:50% h:0,62 q:0p-1n (START), he:0 c:0] +currently best node: TOP [acc:50% h:0,62 q:0p-1n (START), he:0 c:0] +currently best node KBSyntax: TOP +next expanded node: TOP [acc:50% h:0,62 q:0p-1n (START), he:0 c:0] +algorithm runtime 0ms +size of candidate set: 1 +subsumption time: 0ms +instance check time: 0ms +retrieval time: 0ms +properness tests (reasoner/short concept/too weak list): 0/0/0 +concept tests (reasoner/too weak list/overly general list/redundant concepts): 0/0/0/0 +--- loop 0 started --- +solutions (at most 20 are shown): +1: obo::MP_0000029 (accuracy 100%, length 1, depth 1) +2: obo::MP_0004319 (accuracy 100%, length 1, depth 1) +3: obo::MP_0000030 (accuracy 100%, length 1, depth 1) +4: obo::MP_0003138 (accuracy 100%, length 1, depth 1) +5: obo::MP_0000049 (accuracy 100%, length 1, depth 1) +6: obo::MP_0005105 (accuracy 100%, length 1, depth 1) +7: obo::MP_0000137 (accuracy 50%, length 1, depth 1) +8: obo::MP_0004599 (accuracy 50%, length 1, depth 1) +9: obo::MP_0000259 (accuracy 100%, length 1, depth 1) +10: obo::MP_0004787 (accuracy 100%, length 1, depth 1) +11: obo::MP_0000272 (accuracy 100%, length 1, depth 1) +12: obo::MP_0000273 (accuracy 100%, length 1, depth 1) +13: obo::MP_0010544 (accuracy 100%, length 1, depth 1) +14: obo::MP_0000364 (accuracy 100%, length 1, depth 1) +15: obo::MP_0003139 (accuracy 100%, length 1, depth 1) +16: obo::MP_0000428 (accuracy 50%, length 1, depth 1) +17: obo::MP_0003935 (accuracy 50%, length 1, depth 1) +18: obo::MP_0000432 (accuracy 100%, length 1, depth 1) +19: obo::MP_0002177 (accuracy 100%, length 1, depth 1) +20: obo::MP_0000023 (accuracy 50%, length 1, depth 1) +MANCHESTER: + +KBSyntax: +1: "http://purl.obolibrary.org/obo/MP_0000029" +2: "http://purl.obolibrary.org/obo/MP_0004319" +3: "http://purl.obolibrary.org/obo/MP_0000030" +4: "http://purl.obolibrary.org/obo/MP_0003138" +5: "http://purl.obolibrary.org/obo/MP_0000049" +6: "http://purl.obolibrary.org/obo/MP_0005105" +7: "http://purl.obolibrary.org/obo/MP_0000137" +8: "http://purl.obolibrary.org/obo/MP_0004599" +9: "http://purl.obolibrary.org/obo/MP_0000259" +10: "http://purl.obolibrary.org/obo/MP_0004787" +11: "http://purl.obolibrary.org/obo/MP_0000272" +12: "http://purl.obolibrary.org/obo/MP_0000273" +13: "http://purl.obolibrary.org/obo/MP_0010544" +14: "http://purl.obolibrary.org/obo/MP_0000364" +15: "http://purl.obolibrary.org/obo/MP_0003139" +16: "http://purl.obolibrary.org/obo/MP_0000428" +17: "http://purl.obolibrary.org/obo/MP_0003935" +18: "http://purl.obolibrary.org/obo/MP_0000432" +19: "http://purl.obolibrary.org/obo/MP_0002177" +20: "http://purl.obolibrary.org/obo/MP_0000023" + +size of candidate set: 156 +properness tests (reasoner/short concept/too weak list): 0/0/0 +concept tests (reasoner/too weak list/overly general list/redundant concepts): 155/0/0/0 +Algorithm terminated successfully (155 descriptions tested). + +number of instance checks: 202 (0 multiple) +instance check reasoning time: 26ms ( 0ms per instance check) +overall reasoning time: 27ms + +################################################################################################################################################### + +2 pos. Bsp ang. +1 neg. Bsp ang. +1 unb. pos. Bsp +1 unb. neg. Bsp + +Eintraege 18,19 aus pos. Bsp mit 100% accuracy +Eintraege 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 aus pos. Bsp mit 66,667% accuracy + +################################################################################################################################################### +DL-Learner command line interface +Initializing Component "OWL File"... OK (0ms) +Initializing Component "OWL File"... OK (0ms) +Initializing Component "OWL API Reasoner"... OK (871ms) +Initializing Component "PosNegLPStandard"... OK (0ms) +Initializing Component "OWL Class Expression Learner"... OK (80ms) +Running algorithm instance "alg" (OCEL) +starting top down refinement with: Thing (66,667% accuracy) +start node: TOP [acc:66,667% h:0,787 q:0p-1n (START), he:0 c:0] +currently best node: TOP [acc:66,667% h:0,787 q:0p-1n (START), he:0 c:0] +currently best node KBSyntax: TOP +next expanded node: TOP [acc:66,667% h:0,787 q:0p-1n (START), he:0 c:0] +algorithm runtime 0ms +size of candidate set: 1 +subsumption time: 0ms +instance check time: 0ms +retrieval time: 0ms +properness tests (reasoner/short concept/too weak list): 0/0/0 +concept tests (reasoner/too weak list/overly general list/redundant concepts): 0/0/0/0 +--- loop 0 started --- +solutions (at most 20 are shown): +1: obo::MP_0000029 (accuracy 66,667%, length 1, depth 1) +2: obo::MP_0004319 (accuracy 66,667%, length 1, depth 1) +3: obo::MP_0000030 (accuracy 66,667%, length 1, depth 1) +4: obo::MP_0003138 (accuracy 66,667%, length 1, depth 1) +5: obo::MP_0000049 (accuracy 66,667%, length 1, depth 1) +6: obo::MP_0005105 (accuracy 66,667%, length 1, depth 1) +7: obo::MP_0000137 (accuracy 66,667%, length 1, depth 1) +8: obo::MP_0004599 (accuracy 66,667%, length 1, depth 1) +9: obo::MP_0000259 (accuracy 66,667%, length 1, depth 1) +10: obo::MP_0004787 (accuracy 66,667%, length 1, depth 1) +11: obo::MP_0000272 (accuracy 66,667%, length 1, depth 1) +12: obo::MP_0000273 (accuracy 66,667%, length 1, depth 1) +13: obo::MP_0010544 (accuracy 66,667%, length 1, depth 1) +14: obo::MP_0000364 (accuracy 66,667%, length 1, depth 1) +15: obo::MP_0003139 (accuracy 66,667%, length 1, depth 1) +16: obo::MP_0000428 (accuracy 66,667%, length 1, depth 1) +17: obo::MP_0003935 (accuracy 66,667%, length 1, depth 1) +18: obo::MP_0000432 (accuracy 100%, length 1, depth 1) +19: obo::MP_0002177 (accuracy 100%, length 1, depth 1) +20: obo::MP_0000023 (accuracy 66,667%, length 1, depth 1) +MANCHESTER: + +KBSyntax: +1: "http://purl.obolibrary.org/obo/MP_0000029" +2: "http://purl.obolibrary.org/obo/MP_0004319" +3: "http://purl.obolibrary.org/obo/MP_0000030" +4: "http://purl.obolibrary.org/obo/MP_0003138" +5: "http://purl.obolibrary.org/obo/MP_0000049" +6: "http://purl.obolibrary.org/obo/MP_0005105" +7: "http://purl.obolibrary.org/obo/MP_0000137" +8: "http://purl.obolibrary.org/obo/MP_0004599" +9: "http://purl.obolibrary.org/obo/MP_0000259" +10: "http://purl.obolibrary.org/obo/MP_0004787" +11: "http://purl.obolibrary.org/obo/MP_0000272" +12: "http://purl.obolibrary.org/obo/MP_0000273" +13: "http://purl.obolibrary.org/obo/MP_0010544" +14: "http://purl.obolibrary.org/obo/MP_0000364" +15: "http://purl.obolibrary.org/obo/MP_0003139" +16: "http://purl.obolibrary.org/obo/MP_0000428" +17: "http://purl.obolibrary.org/obo/MP_0003935" +18: "http://purl.obolibrary.org/obo/MP_0000432" +19: "http://purl.obolibrary.org/obo/MP_0002177" +20: "http://purl.obolibrary.org/obo/MP_0000023" + +size of candidate set: 156 +properness tests (reasoner/short concept/too weak list): 0/0/0 +concept tests (reasoner/too weak list/overly general list/redundant concepts): 155/0/0/0 +Algorithm terminated successfully (155 descriptions tested). + +number of instance checks: 311 (0 multiple) +instance check reasoning time: 42ms ( 0ms per instance check) +overall reasoning time: 43ms + +################################################################################################################################################### \ No newline at end of file Copied: trunk/test/phaenotype/mp-big.owl (from rev 3795, trunk/test/phaenotype/mp.owl) =================================================================== --- trunk/test/phaenotype/mp-big.owl (rev 0) +++ trunk/test/phaenotype/mp-big.owl 2012-07-19 08:12:17 UTC (rev 3799) @@ -0,0 +1,188520 @@ +<?xml version="1.0"?> +<rdf:RDF xmlns="http://purl.obolibrary.org/obo/mp.owl#" + xml:base="http://purl.obolibrary.org/obo/mp.owl" + xmlns:obo="http://purl.obolibrary.org/obo/" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:mp="http://purl.obolibrary.org/obo/mp#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#"> + <owl:Ontology rdf:about="http://purl.obolibrary.org/obo/mp.owl"> + <oboInOwl:hasOBOFormatVersion rdf:datatype="http://www.w3.org/2001/XMLSchema#string">1.2</oboInOwl:hasOBOFormatVersion> + <oboInOwl:date rdf:datatype="http://www.w3.org/2001/XMLSchema#string">26:01:2012 14:45</oboInOwl:date> + <oboInOwl:default-namespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:default-namespace> + <oboInOwl:auto-generated-by rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBO-Edit 2.0</oboInOwl:auto-generated-by> + <oboInOwl:remark rdf:datatype="http://www.w3.org/2001/XMLSchema#string">The Mammalian Phenotype Ontology is being developed by Cynthia L. Smith, Susan M. Bello, Carroll W. Goldsmith and Janan T. Eppig, as part of the Mouse Genome Database (MGD) Project, Mouse Genome Informatics (MGI), The Jackson Laboratory, Bar Harbor, ME. Copyright 2007 The Jackson Laboratory. This file contains pre-coordinated phenotype terms, definitions and synonyms that can be used to describe mammalian phenotypes. The ontology is represented as a directed acyclic graph (DAG). It organizes phenotype terms into major biological system headers such as nervous system and respiratory system. Behavior and lethality terms are also represented. This ontology is currently under development. Daily updates are available at the Mouse Genome Informatics (MGI) ftp site (ftp://ftp.informatics.jax.org/pub/reports/index.html#pheno) as well as the OBO Foundry site (http://obofoundry.org/). Questions, comments and suggestions are welcome, and should be directed to ph...@in... MGD is funded by NIH/NHGRI grant HG000330.</oboInOwl:remark> + <oboInOwl:saved-by rdf:datatype="http://www.w3.org/2001/XMLSchema#string">csmith</oboInOwl:saved-by> + </owl:Ontology> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Annotation properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#creation_date"/> + <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"> + <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Terms in use by Europhenome</rdfs:comment> + <rdfs:subPropertyOf rdf:resource="http://www.geneontology.org/formats/oboInOwl#SubsetProperty"/> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#inSubset"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">in_subset</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasOBOFormatVersion"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_obo_format_version</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#auto-generated-by"/> + <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/mp#CvDC_Terms"> + <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">NHLBI Cardiovascular Development Consortium (CvDC) Terms</rdfs:comment> + <rdfs:subPropertyOf rdf:resource="http://www.geneontology.org/formats/oboInOwl#SubsetProperty"/> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#created_by"/> + <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0100001"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">term replaced by</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#saved-by"/> + <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">definition</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasDbXref"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">database_cross_reference</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasAlternativeId"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_alternative_id</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasOBONamespace"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_obo_namespace</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#SubsetProperty"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">subset_property</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#id"/> + <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/mp#Sanger_Terms"> + <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Terms in use by Mouse Genetics Project, Sanger Institute, Wellcome Trust Genome Campus</rdfs:comment> + <rdfs:subPropertyOf rdf:resource="http://www.geneontology.org/formats/oboInOwl#SubsetProperty"/> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#remark"/> + <owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#label"/> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#default-namespace"/> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasExactSynonym"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_exact_synonym</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.w3.org/2002/07/owl#deprecated"/> + <owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#comment"/> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasRelatedSynonym"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_related_synonym</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#date"/> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_narrow_synonym</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#consider"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">consider</rdfs:label> + </owl:AnnotationProperty> + <owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">has_broad_synonym</rdfs:label> + </owl:AnnotationProperty> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Datatypes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Object Properties + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://purl.obolibrary.org/obo/mp#part_of --> + + <owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/mp#part_of"> + <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</rdfs:label> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</oboInOwl:id> + </owl:ObjectProperty> + + + + <!-- + /////////////////////////////////////////////////////////////////////////////////////// + // + // Classes + // + /////////////////////////////////////////////////////////////////////////////////////// + --> + + + + + <!-- http://purl.obolibrary.org/obo/MP_0000001 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000001"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian phenotype</rdfs:label> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000001</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">the observable morphological, physiological, behavioral and other characteristics of mammalian organisms that are manifested through development and lifespan</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:csmith</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">the observable morphological, physiological, behavioral and other characteristics of mammalian organisms that are manifested through development and lifespan</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000001"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000002 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000002"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Morphology</rdfs:label> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Anatomy</oboInOwl:hasExactSynonym> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000002</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE.</obo:IAO_0000115> + <owl:deprecated rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</owl:deprecated> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:csmith</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE.</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000002"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000003 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000003"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal adipose tissue morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0005375"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000003</oboInOwl:id> + <oboInOwl:hasAlternativeId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000011</oboInOwl:hasAlternativeId> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasBroadSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">adipose tissue abnormalities</oboInOwl:hasBroadSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">adipose tissue dysplasia</oboInOwl:hasExactSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the connective tissue composed of fat cells enmeshed in areolar tissue</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MESH:A10.165.114</oboInOwl:hasDbXref> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the connective tissue composed of fat cells enmeshed in areolar tissue</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000003"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000005 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000005"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased brown adipose tissue amount</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0001778"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000005</oboInOwl:id> + <oboInOwl:hasAlternativeId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001779</oboInOwl:hasAlternativeId> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased amount of the thermogenic form of adipose tissue that is composed of brown adipocytes</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased brown fat</oboInOwl:hasExactSynonym> + <oboInOwl:hasRelatedSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased brown fat amount</oboInOwl:hasRelatedSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MESH:A10.165.114.322</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased amount of the thermogenic form of adipose tissue that is composed of brown adipocytes</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000005"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000008 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000008"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased white adipose tissue amount</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0001781"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000008</oboInOwl:id> + <oboInOwl:hasAlternativeId rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001782</oboInOwl:hasAlternativeId> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased quantity of fat-storing cells/tissue</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased white fat</oboInOwl:hasExactSynonym> + <oboInOwl:hasRelatedSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased white fat amount</oboInOwl:hasRelatedSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased quantity of fat-storing cells/tissue</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000008"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000010 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000010"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal abdominal fat pad morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0005334"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000010</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal abdominal fat depot morphology</oboInOwl:hasExactSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the encapsulated adipose tissue in the abdomen</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:8941642</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the encapsulated adipose tissue in the abdomen</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000010"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000012 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000012"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">loss of subcutaneous adipose tissue</rdfs:label> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000012</oboInOwl:id> + <oboInOwl:consider rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0008843</oboInOwl:consider> + <oboInOwl:consider rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0008844</oboInOwl:consider> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE. reduction in amount or absence of adipose tissue beneath the skin</obo:IAO_0000115> + <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Obsolete. Use instead the terms decreased subcutaneous adipose tissue amount (MP:0008844) or absent subcutaneous adipose tissue (MP:0008843).</rdfs:comment> + <owl:deprecated rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</owl:deprecated> + </owl:Class> + <owl:Axiom> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE. reduction in amount or absence of adipose tissue beneath the skin</owl:annotatedTarget> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:8941642</oboInOwl:hasDbXref> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000012"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000013 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000013"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal adipose tissue distribution</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000003"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000013</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasRelatedSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal fat distribution</oboInOwl:hasRelatedSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">alterations in the normal placement of body fat</obo:IAO_0000115> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:10471508</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">alterations in the normal placement of body fat</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000013"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000015 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000015"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal ear pigmentation</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002095"/> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000015</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">anomaly in the coloration of the ear due to changes in the amount, shape, or distribution of cells producing pigment</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:llw2</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">anomaly in the coloration of the ear due to changes in the amount, shape, or distribution of cells producing pigment</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000015"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000017 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000017"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">big ears</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000017</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">enlarged ears</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased outer ear size</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">large ears</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">macrotia</oboInOwl:hasExactSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears of a greater than normal size</obo:IAO_0000115> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"/> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Sanger_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears of a greater than normal size</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000017"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000018 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000018"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">small ears</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000018</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">decreased ear size</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">microtia</oboInOwl:hasExactSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears of a smaller than normal size</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">reduced ear size</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">reduced pinna size</oboInOwl:hasExactSynonym> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"/> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Sanger_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears of a smaller than normal size</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000018"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000019 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000019"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">thick ears</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000019</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased width of the epidermal and cartilaginous tissue that makes up the ear</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:1709129</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased width of the epidermal and cartilaginous tissue that makes up the ear</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000019"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000020 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000020"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">scaly ears</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000020</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ears covered with shedding scales or flakes</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:1709129</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ears covered with shedding scales or flakes</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000020"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000021 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000021"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">prominent ears</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000021</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">protuberant outer ears</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:10769039</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">protuberant outer ears</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000021"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000022 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000022"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal ear shape</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000022</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the pattern of the external ear</obo:IAO_0000115> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PMID:10921880</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the pattern of the external ear</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000022"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000023 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000023"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal ear distance/ position</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002177"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000023</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">anomaly in the space between or the placement of the outer ears</obo:IAO_0000115> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Sanger_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">anomaly in the space between or the placement of the outer ears</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000023"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000024 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000024"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">lowered ear position</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000023"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000024</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears are situated below the normal location often giving the perception of protruding from the head</obo:IAO_0000115> + <oboInOwl:hasBroadSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">protruding ears</oboInOwl:hasBroadSynonym> + <oboInOwl:inSubset rdf:resource="http://purl.obolibrary.org/obo/mp#Europhenome_Terms"/> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:llw2</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">outer ears are situated below the normal location often giving the perception of protruding from the head</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000024"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000025 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000025"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">otic hypertelorism</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000023"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000025</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">greater than normal space between the outer ears</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">hypertelorism of ears</oboInOwl:hasExactSynonym> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">increased distance between the ears</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">greater than normal space between the outer ears</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000025"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000026 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000026"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal inner ear morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002102"/> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">GO:0042472</oboInOwl:hasDbXref> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000026</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of any components of the labyrinth, including the semicircular canals, vestibule and cochlea</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">inner ear dysplasia</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of any components of the labyrinth, including the semicircular canals, vestibule and cochlea</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000026"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000027 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000027"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">horizontal canal defects</rdfs:label> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000027</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE.</obo:IAO_0000115> + <owl:deprecated rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</owl:deprecated> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:csmith</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">OBSOLETE.</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000027"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000028 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000028"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal pars superior vestibularis morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000026"/> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0002856"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000028</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly in the part of the vestibular ganglion that receives fibers from the maculae of the utricle and the sacculae and the ampullae of the anterior and lateral semicircular ducts</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">pars superior vestibularis dysplasia</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly in the part of the vestibular ganglion that receives fibers from the maculae of the utricle and the sacculae and the ampullae of the anterior and lateral semicircular ducts</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000028"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000029 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000029"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal malleus morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0005105"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000029</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the largest of the three auditory ossicles, which resembles a club or hammer</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MGI:cwg</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the largest of the three auditory ossicles, which resembles a club or hammer</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000029"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000030 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000030"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal tympanic ring morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000049"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000030</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasRelatedSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal ectotympanic</oboInOwl:hasRelatedSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the bony ring at the ear canal to which the tympanic membrane is attached</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">tympanic ring dysplasia</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the bony ring at the ear canal to which the tympanic membrane is attached</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000030"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000031 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000031"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal cochlea morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000026"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000031</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the spiral-shaped bony canal in the inner ear containing the hair cells that transduce sound</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">cochlear dysplasia</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the spiral-shaped bony canal in the inner ear containing the hair cells that transduce sound</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000031"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000032 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000032"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">cochlear degeneration</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000031"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000032</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">a retrogressive impairment of function or destruction of the spiral-shaped bony canal in the inner ear containing the hair cells that transduce sound</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">a retrogressive impairment of function or destruction of the spiral-shaped bony canal in the inner ear containing the hair cells that transduce sound</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000032"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000033 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000033"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">absent scala media</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0003169"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000033</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">absent cochlear duct</oboInOwl:hasExactSynonym> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">missing spiral tube within the cochlea that contains the organ of Corti, the neuroepithelial receptor organ for hearing</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">missing spiral tube within the cochlea that contains the organ of Corti, the neuroepithelial receptor organ for hearing</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000033"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000034 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000034"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal vestibule morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000026"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000034</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the cavity between the semicircular canals and the cochlea of the inner ear</obo:IAO_0000115> + <oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">vestibular dysplasia</oboInOwl:hasExactSynonym> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the cavity between the semicircular canals and the cochlea of the inner ear</owl:annotatedTarget> + <owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/> + <owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/MP_0000034"/> + </owl:Axiom> + + + + <!-- http://purl.obolibrary.org/obo/MP_0000035 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0000035"> + <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abnormal membranous labyrinth morphology</rdfs:label> + <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/MP_0000026"/> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0000035</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MPheno.ontology</oboInOwl:hasOBONamespace> + <obo:IAO_0000115 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the complex arrangement of communicating canaliculi and sacs suspended within the cavity of the bony labyrinth of the inner ear</obo:IAO_0000115> + </owl:Class> + <owl:Axiom> + <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ISBN:0-683-40008-8</oboInOwl:hasDbXref> + <owl:annotatedTarget rdf:datatype="http://www.w3.org/2001/XMLSchema#string">any structural anomaly of the complex arrangement of communicating canaliculi and sacs suspended with... [truncated message content] |
From: <lor...@us...> - 2012-07-18 13:20:05
|
Revision: 3798 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3798&view=rev Author: lorenz_b Date: 2012-07-18 13:19:54 +0000 (Wed, 18 Jul 2012) Log Message: ----------- Catch exceptions in precomputing method to handle as much as possible pairs of entities. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java 2012-07-18 13:08:45 UTC (rev 3797) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java 2012-07-18 13:19:54 UTC (rev 3798) @@ -353,16 +353,26 @@ for(NamedClass cls : classes){ for(ObjectProperty prop : objectProperties){ log.info("Processing class " + cls + " and property " + prop); - getDirectedPMI(cls, prop); - getDirectedPMI(prop, cls); + try { + getDirectedPMI(cls, prop); + getDirectedPMI(prop, cls); + } catch (Exception e) { + e.printStackTrace(); + } } } for(NamedClass cls1 : classes){ for(NamedClass cls2 : classes){ - log.info("Processing class " + cls1 + " and class " + cls2); - getPMI(cls1, cls2); - getPMI(cls2, cls1); + if(!cls1.equals(cls2)){ + log.info("Processing class " + cls1 + " and class " + cls2); + try { + getPMI(cls1, cls2); + getPMI(cls2, cls1); + } catch (Exception e) { + e.printStackTrace(); + } + } } } log.info("Done in " + ((System.currentTimeMillis() - startTime)/1000d) + "s"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-18 13:08:53
|
Revision: 3797 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3797&view=rev Author: lorenz_b Date: 2012-07-18 13:08:45 +0000 (Wed, 18 Jul 2012) Log Message: ----------- Started metrics class for SPARQL endpoints. Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner3.java 2012-07-18 13:08:45 UTC (rev 3797) @@ -0,0 +1,1031 @@ +package org.dllearner.algorithm.tbsl.learning; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.apache.log4j.Logger; +import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; +import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.PartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.PlingStemmer; +import org.dllearner.algorithm.tbsl.nlp.StanfordPartOfSpeechTagger; +import org.dllearner.algorithm.tbsl.nlp.WordNet; +import org.dllearner.algorithm.tbsl.sparql.Allocation; +import org.dllearner.algorithm.tbsl.sparql.Query; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Pair; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; +import org.dllearner.algorithm.tbsl.sparql.Slot; +import org.dllearner.algorithm.tbsl.sparql.SlotType; +import org.dllearner.algorithm.tbsl.sparql.Template; +import org.dllearner.algorithm.tbsl.sparql.WeightedQuery; +import org.dllearner.algorithm.tbsl.templator.Templator; +import org.dllearner.algorithm.tbsl.util.Knowledgebase; +import org.dllearner.algorithm.tbsl.util.PopularityMap; +import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; +import org.dllearner.algorithm.tbsl.util.SPARQLEndpointMetrics; +import org.dllearner.algorithm.tbsl.util.Similarity; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; +import org.dllearner.common.index.Index; +import org.dllearner.common.index.IndexResultItem; +import org.dllearner.common.index.IndexResultSet; +import org.dllearner.common.index.MappingBasedIndex; +import org.dllearner.common.index.SOLRIndex; +import org.dllearner.common.index.SPARQLDatatypePropertiesIndex; +import org.dllearner.common.index.SPARQLObjectPropertiesIndex; +import org.dllearner.common.index.SPARQLPropertiesIndex; +import org.dllearner.common.index.VirtuosoDatatypePropertiesIndex; +import org.dllearner.common.index.VirtuosoObjectPropertiesIndex; +import org.dllearner.common.index.VirtuosoPropertiesIndex; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.LearningProblem; +import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.reasoning.SPARQLReasoner; +import org.ini4j.InvalidFileFormatException; +import org.ini4j.Options; +import org.semanticweb.HermiT.Configuration.DirectBlockingType; + +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.query.Syntax; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.shared.UnknownPropertyException; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +import com.hp.hpl.jena.vocabulary.RDFS; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; + +public class SPARQLTemplateBasedLearner3 implements SparqlQueryLearningAlgorithm{ + + + enum Mode{ + BEST_QUERY, BEST_NON_EMPTY_QUERY + } + + private Mode mode = Mode.BEST_QUERY; + + private static final Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner3.class); + private Monitor templateMon = MonitorFactory.getTimeMonitor("template"); + private Monitor sparqlMon = MonitorFactory.getTimeMonitor("sparql"); + + private boolean useRemoteEndpointValidation; + private boolean stopIfQueryResultNotEmpty; + private int maxTestedQueriesPerTemplate = 50; + private int maxQueryExecutionTimeInSeconds; + private int maxTestedQueries = 200; + private int maxIndexResults; + + private SparqlEndpoint endpoint; + private Model model; + + private ExtractionDBCache cache = new ExtractionDBCache("cache"); + + private Index resourcesIndex; + private Index classesIndex; + private Index propertiesIndex; + + private Index datatypePropertiesIndex; + private Index objectPropertiesIndex; + + private MappingBasedIndex mappingIndex; + + private Templator templateGenerator; + private Lemmatizer lemmatizer; + private PartOfSpeechTagger posTagger; + private WordNet wordNet; + + private String question; + private int learnedPos = -1; + + private Set<Template> templates; + private Map<Template, Collection<? extends Query>> template2Queries; + private Map<Slot, List<String>> slot2URI; + + private Collection<WeightedQuery> sparqlQueryCandidates; + private SortedSet<WeightedQuery> learnedSPARQLQueries; + private SortedSet<WeightedQuery> generatedQueries; + + private SPARQLReasoner reasoner; + + private String currentlyExecutedQuery; + + private boolean dropZeroScoredQueries = true; + private boolean useManualMappingsIfExistOnly = true; + + private boolean multiThreaded = true; + + private String [] grammarFiles = new String[]{"tbsl/lexicon/english.lex"}; + + private PopularityMap popularityMap; + + private Set<String> relevantKeywords; + + private boolean useDomainRangeRestriction = true; + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger()); + } + + public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options); + } + + public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ + this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), posTagger, wordNet, options, cache); + } + + public SPARQLTemplateBasedLearner3(Knowledgebase knowledgebase){ + this(knowledgebase.getEndpoint(), knowledgebase.getResourceIndex(), knowledgebase.getClassIndex(),knowledgebase.getPropertyIndex(), new StanfordPartOfSpeechTagger(), new WordNet(), new Options()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index index){ + this(endpoint, index, new StanfordPartOfSpeechTagger()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, new WordNet(), new Options()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger){ + this(endpoint, index, posTagger, new WordNet(), new Options()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, WordNet wordNet){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger(), wordNet, new Options()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index index, WordNet wordNet){ + this(endpoint, index, new StanfordPartOfSpeechTagger(), wordNet, new Options()); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, new Options(), new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger, WordNet wordNet){ + this(endpoint, index, index, index, posTagger, wordNet, new Options(), new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(endpoint, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index index, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(endpoint, index, index, index, posTagger, wordNet, options, new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner3(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ + this.endpoint = endpoint; + this.resourcesIndex = resourcesIndex; + this.classesIndex = classesIndex; + this.propertiesIndex = propertiesIndex; + this.posTagger = posTagger; + this.wordNet = wordNet; + this.cache = cache; + + setOptions(options); + + if(propertiesIndex instanceof SPARQLPropertiesIndex){ + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } + } else { + datatypePropertiesIndex = propertiesIndex; + objectPropertiesIndex = propertiesIndex; + } + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cache); + } + + public SPARQLTemplateBasedLearner3(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ + this(model, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger()); + } + + public SPARQLTemplateBasedLearner3(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger){ + this(model, resourcesIndex, classesIndex, propertiesIndex, posTagger, new WordNet(), new Options()); + } + + public SPARQLTemplateBasedLearner3(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, WordNet wordNet){ + this(model, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger(), wordNet, new Options()); + } + + public SPARQLTemplateBasedLearner3(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options){ + this(model, resourcesIndex, classesIndex, propertiesIndex, posTagger, wordNet, options, new ExtractionDBCache("cache")); + } + + public SPARQLTemplateBasedLearner3(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex, PartOfSpeechTagger posTagger, WordNet wordNet, Options options, ExtractionDBCache cache){ + this.model = model; + this.resourcesIndex = resourcesIndex; + this.classesIndex = classesIndex; + this.propertiesIndex = propertiesIndex; + this.posTagger = posTagger; + this.wordNet = wordNet; + this.cache = cache; + + setOptions(options); + + if(propertiesIndex instanceof SPARQLPropertiesIndex){ + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } + } else { + datatypePropertiesIndex = propertiesIndex; + objectPropertiesIndex = propertiesIndex; + } + } + + public void setGrammarFiles(String[] grammarFiles){ + templateGenerator.setGrammarFiles(grammarFiles); + } + + @Override + public void init() throws ComponentInitException { + templateGenerator = new Templator(posTagger, wordNet, grammarFiles); + lemmatizer = new LingPipeLemmatizer(); + } + + public void setMappingIndex(MappingBasedIndex mappingIndex) { + this.mappingIndex = mappingIndex; + } + + public void setKnowledgebase(Knowledgebase knowledgebase){ + this.endpoint = knowledgebase.getEndpoint(); + this.resourcesIndex = knowledgebase.getResourceIndex(); + this.classesIndex = knowledgebase.getClassIndex(); + this.propertiesIndex = knowledgebase.getPropertyIndex(); + this.mappingIndex = knowledgebase.getMappingIndex(); + if(propertiesIndex instanceof SPARQLPropertiesIndex){ + if(propertiesIndex instanceof VirtuosoPropertiesIndex){ + datatypePropertiesIndex = new VirtuosoDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new VirtuosoObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } else { + datatypePropertiesIndex = new SPARQLDatatypePropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + objectPropertiesIndex = new SPARQLObjectPropertiesIndex((SPARQLPropertiesIndex)propertiesIndex); + } + } else { + datatypePropertiesIndex = propertiesIndex; + objectPropertiesIndex = propertiesIndex; + } + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + } + + public void setCache(ExtractionDBCache cache) { + this.cache = cache; + } + + public void setUseDomainRangeRestriction(boolean useDomainRangeRestriction) { + this.useDomainRangeRestriction = useDomainRangeRestriction; + } + + /* + * Only for Evaluation useful. + */ + public void setUseIdealTagger(boolean value){ + templateGenerator.setUNTAGGED_INPUT(!value); + } + + private void setOptions(Options options){ + maxIndexResults = Integer.parseInt(options.get("solr.query.limit", "10")); + + maxQueryExecutionTimeInSeconds = Integer.parseInt(options.get("sparql.query.maxExecutionTimeInSeconds", "100")); + cache.setMaxExecutionTimeInSeconds(maxQueryExecutionTimeInSeconds); + + useRemoteEndpointValidation = options.get("learning.validationType", "remote").equals("remote") ? true : false; + stopIfQueryResultNotEmpty = Boolean.parseBoolean(options.get("learning.stopAfterFirstNonEmptyQueryResult", "true")); + maxTestedQueriesPerTemplate = Integer.parseInt(options.get("learning.maxTestedQueriesPerTemplate", "20")); + + String wordnetPath = options.get("wordnet.dictionary", "tbsl/dict"); + wordnetPath = this.getClass().getClassLoader().getResource(wordnetPath).getPath(); + System.setProperty("wordnet.database.dir", wordnetPath); + } + + public void setEndpoint(SparqlEndpoint endpoint){ + this.endpoint = endpoint; + + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + reasoner.setCache(cache); + reasoner.prepareSubsumptionHierarchy(); + } + + public void setQuestion(String question){ + this.question = question; + } + + public void setUseRemoteEndpointValidation(boolean useRemoteEndpointValidation){ + this.useRemoteEndpointValidation = useRemoteEndpointValidation; + } + + public int getMaxQueryExecutionTimeInSeconds() { + return maxQueryExecutionTimeInSeconds; + } + + public void setMaxQueryExecutionTimeInSeconds(int maxQueryExecutionTimeInSeconds) { + this.maxQueryExecutionTimeInSeconds = maxQueryExecutionTimeInSeconds; + } + + public int getMaxTestedQueriesPerTemplate() { + return maxTestedQueriesPerTemplate; + } + + public void setMaxTestedQueriesPerTemplate(int maxTestedQueriesPerTemplate) { + this.maxTestedQueriesPerTemplate = maxTestedQueriesPerTemplate; + } + + private void reset(){ + learnedSPARQLQueries = new TreeSet<WeightedQuery>(); + template2Queries = new HashMap<Template, Collection<? extends Query>>(); + slot2URI = new HashMap<Slot, List<String>>(); + relevantKeywords = new HashSet<String>(); + currentlyExecutedQuery = null; + +// templateMon.reset(); +// sparqlMon.reset(); + } + + public void learnSPARQLQueries() throws NoTemplateFoundException{ + reset(); + //generate SPARQL query templates + logger.info("Generating SPARQL query templates..."); + templateMon.start(); + if(multiThreaded){ + templates = templateGenerator.buildTemplatesMultiThreaded(question); + } else { + templates = templateGenerator.buildTemplates(question); + } + templateMon.stop(); + logger.info("Done in " + templateMon.getLastValue() + "ms."); + relevantKeywords.addAll(templateGenerator.getUnknownWords()); + if(templates.isEmpty()){ + throw new NoTemplateFoundException(); + + } + logger.info("Templates:"); + for(Template t : templates){ + logger.info(t); + } + + //get the weighted query candidates + generatedQueries = getWeightedSPARQLQueries(templates); + sparqlQueryCandidates = new ArrayList<WeightedQuery>(); + int i = 0; + for(WeightedQuery wQ : generatedQueries){ + System.out.println(wQ.explain()); + sparqlQueryCandidates.add(wQ); + if(i == maxTestedQueries){ + break; + } + i++; + } + + if(mode == Mode.BEST_QUERY){ + double bestScore = -1; + for(WeightedQuery candidate : generatedQueries){ + double score = candidate.getScore(); + if(score >= bestScore){ + bestScore = score; + learnedSPARQLQueries.add(candidate); + } else { + break; + } + } + } else if(mode == Mode.BEST_NON_EMPTY_QUERY){ + //test candidates + if(useRemoteEndpointValidation){ //on remote endpoint + validateAgainstRemoteEndpoint(sparqlQueryCandidates); + } else {//on local model + + } + } + } + + public SortedSet<WeightedQuery> getGeneratedQueries() { + return generatedQueries; + } + + public SortedSet<WeightedQuery> getGeneratedQueries(int topN) { + SortedSet<WeightedQuery> topNQueries = new TreeSet<WeightedQuery>(); + int max = Math.min(topN, generatedQueries.size()); + for(WeightedQuery wQ : generatedQueries){ + topNQueries.add(wQ); + if(topNQueries.size() == max){ + break; + } + } + return topNQueries; + } + + public Set<Template> getTemplates(){ + return templates; + } + + public List<String> getGeneratedSPARQLQueries(){ + List<String> queries = new ArrayList<String>(); + for(WeightedQuery wQ : sparqlQueryCandidates){ + queries.add(wQ.getQuery().toString()); + } + + return queries; + } + + public Map<Template, Collection<? extends Query>> getTemplates2SPARQLQueries(){ + return template2Queries; + } + + public Map<Slot, List<String>> getSlot2URIs(){ + return slot2URI; + } + + private void normProminenceValues(Set<Allocation> allocations){ + double min = 0; + double max = 0; + for(Allocation a : allocations){ + if(a.getProminence() < min){ + min = a.getProminence(); + } + if(a.getProminence() > max){ + max = a.getProminence(); + } + } + for(Allocation a : allocations){ + double prominence = a.getProminence()/(max-min); + a.setProminence(prominence); + } + } + + private void computeScore(Set<Allocation> allocations){ + double alpha = 0.8; + double beta = 1 - alpha; + + for(Allocation a : allocations){ + double score = alpha * a.getSimilarity() + beta * a.getProminence(); + a.setScore(score); + } + + } + + public Set<String> getRelevantKeywords(){ + return relevantKeywords; + } + + private SortedSet<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + logger.info("Generating SPARQL query candidates..."); + + Map<Slot, Set<Allocation>> slot2Allocations = new TreeMap<Slot, Set<Allocation>>(new Comparator<Slot>() { + + @Override + public int compare(Slot o1, Slot o2) { + if(o1.getSlotType() == o2.getSlotType()){ + return o1.getToken().compareTo(o2.getToken()); + } else { + return -1; + } + } + }); + slot2Allocations = Collections.synchronizedMap(new HashMap<Slot, Set<Allocation>>()); + + + SortedSet<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); + + Set<Allocation> allocations; + + for(Template t : templates){ + logger.info("Processing template:\n" + t.toString()); + allocations = new TreeSet<Allocation>(); + + ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); + List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); + + long startTime = System.currentTimeMillis(); + + for (Slot slot : t.getSlots()) { + if(!slot2Allocations.containsKey(slot)){//System.out.println(slot + ": " + slot.hashCode());System.out.println(slot2Allocations); + Callable<Map<Slot, SortedSet<Allocation>>> worker = new SlotProcessor(slot); + Future<Map<Slot, SortedSet<Allocation>>> submit = executor.submit(worker); + list.add(submit); + } else { + System.out.println("CACHE HIT"); + } + } + + for (Future<Map<Slot, SortedSet<Allocation>>> future : list) { + try { + Map<Slot, SortedSet<Allocation>> result = future.get(); + Entry<Slot, SortedSet<Allocation>> item = result.entrySet().iterator().next(); + slot2Allocations.put(item.getKey(), item.getValue()); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + } + + executor.shutdown(); + System.out.println("Time needed: " + (System.currentTimeMillis() - startTime) + "ms"); + + Set<WeightedQuery> queries = new HashSet<WeightedQuery>(); + Query cleanQuery = t.getQuery(); + queries.add(new WeightedQuery(cleanQuery)); + + Set<WeightedQuery> tmp = new TreeSet<WeightedQuery>(); + List<Slot> sortedSlots = new ArrayList<Slot>(); + Set<Slot> classSlots = new HashSet<Slot>(); + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.CLASS){ + sortedSlots.add(slot); + classSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY || slot.getSlotType() == SlotType.DATATYPEPROPERTY){ + sortedSlots.add(slot); + } + } + for(Slot slot : t.getSlots()){ + if(!sortedSlots.contains(slot)){ + sortedSlots.add(slot); + } + } + //add for each SYMPROPERTY Slot the reversed query + for(Slot slot : sortedSlots){ + for(WeightedQuery wQ : queries){ + if(slot.getSlotType() == SlotType.SYMPROPERTY || slot.getSlotType() == SlotType.OBJECTPROPERTY){ + Query reversedQuery = new Query(wQ.getQuery()); + reversedQuery.getTriplesWithVar(slot.getAnchor()).iterator().next().reverse(); + tmp.add(new WeightedQuery(reversedQuery)); + } + tmp.add(wQ); + } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); + } + + for(Slot slot : sortedSlots){ + if(!slot2Allocations.get(slot).isEmpty()){ + for(Allocation a : slot2Allocations.get(slot)){ + for(WeightedQuery query : queries){ + Query q = new Query(query.getQuery()); + q.replaceVarWithURI(slot.getAnchor(), a.getUri()); + WeightedQuery w = new WeightedQuery(q); + double newScore = query.getScore() + a.getScore(); + w.setScore(newScore); + w.addAllocations(query.getAllocations()); + w.addAllocation(a); + tmp.add(w); + + + } + } + queries.clear(); + queries.addAll(tmp); + tmp.clear(); + + + } + + } + SPARQLEndpointMetrics metrics = new SPARQLEndpointMetrics(endpoint, cache); + for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { + WeightedQuery wQ = iterator.next(); + Query q = wQ.getQuery(); + for(SPARQL_Triple triple : q.getConditions()){ + SPARQL_Term subject = triple.getVariable(); + SPARQL_Property predicate = triple.getProperty(); + SPARQL_Value object = triple.getValue(); + + if(!predicate.isVariable() && !predicate.getName().equals("type")){ + if(subject.isVariable() && !object.isVariable()){ + String varName = triple.getVariable().getName(); + Set<String> types = new HashSet<String>(); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(varName)){ + types.add(typeTriple.getValue().getName().replace(">", "").replace("<", "")); + } + for(String type : types){System.out.println(type); + metrics.getGoodness(new NamedClass(type), + new ObjectProperty(predicate.getName().replace(">", "").replace("<", "")), + new Individual(object.getName().replace(">", "").replace("<", ""))); + } + } else if(object.isVariable() && !subject.isVariable()){ + String varName = triple.getVariable().getName(); + Set<String> types = new HashSet<String>(); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(varName)){ + types.add(typeTriple.getValue().getName().replace(">", "").replace("<", "")); + } + for(String type : types){ + metrics.getGoodness(new Individual(subject.getName().replace(">", "").replace("<", "")), + new ObjectProperty(predicate.getName().replace(">", "").replace("<", "")), + new NamedClass(type)); + } + } + } + } + + } + for (Iterator<WeightedQuery> iterator = queries.iterator(); iterator.hasNext();) { + WeightedQuery wQ = iterator.next(); + if(dropZeroScoredQueries){ + if(wQ.getScore() <= 0){ + iterator.remove(); + } + } else { + wQ.setScore(wQ.getScore()/t.getSlots().size()); + } + + } + allQueries.addAll(queries); + List<Query> qList = new ArrayList<Query>(); + for(WeightedQuery wQ : queries){//System.err.println(wQ.getQuery()); + qList.add(wQ.getQuery()); + } + template2Queries.put(t, qList); + } + logger.info("...done in "); + return allQueries; + } + + private double getProminenceValue(String uri, SlotType type){ + Integer popularity = null; + if(popularityMap != null){ + if(type == SlotType.CLASS){ + popularity = popularityMap.getPopularity(uri, EntityType.CLASS); + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY + || type == SlotType.DATATYPEPROPERTY || type == SlotType.OBJECTPROPERTY){ + popularity = popularityMap.getPopularity(uri, EntityType.PROPERTY); + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + popularity = popularityMap.getPopularity(uri, EntityType.RESOURCE); + } + } + if(popularity == null){ + String query = null; + if(type == SlotType.CLASS){ + query = "SELECT COUNT(?s) WHERE {?s a <%s>}"; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY + || type == SlotType.DATATYPEPROPERTY || type == SlotType.OBJECTPROPERTY){ + query = "SELECT COUNT(*) WHERE {?s <%s> ?o}"; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + query = "SELECT COUNT(*) WHERE {?s ?p <%s>}"; + } + query = String.format(query, uri); + + ResultSet rs = executeSelect(query); + QuerySolution qs; + String projectionVar; + while(rs.hasNext()){ + qs = rs.next(); + projectionVar = qs.varNames().next(); + popularity = qs.get(projectionVar).asLiteral().getInt(); + } + } + if(popularity == null){ + popularity = Integer.valueOf(0); + } + + +// if(cnt == 0){ +// return 0; +// } +// return Math.log(cnt); + return popularity; + } + + public void setPopularityMap(PopularityMap popularityMap) { + this.popularityMap = popularityMap; + } + + + private void validateAgainstRemoteEndpoint(Collection<WeightedQuery> queries){ + SPARQL_QueryType queryType = queries.iterator().next().getQuery().getQt(); + validate(queries, queryType); + } + + private void validate(Collection<WeightedQuery> queries, SPARQL_QueryType queryType){ + logger.info("Testing candidate SPARQL queries on remote endpoint..."); + sparqlMon.start(); + if(queryType == SPARQL_QueryType.SELECT){ + for(WeightedQuery query : queries){ + learnedPos++; + List<String> results; + try { + logger.info("Testing query:\n" + query); + com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); + q.setLimit(1); + ResultSet rs = executeSelect(q.toString()); + + results = new ArrayList<String>(); + QuerySolution qs; + String projectionVar; + while(rs.hasNext()){ + qs = rs.next(); + projectionVar = qs.varNames().next(); + if(qs.get(projectionVar).isLiteral()){ + results.add(qs.get(projectionVar).asLiteral().getLexicalForm()); + } else if(qs.get(projectionVar).isURIResource()){ + results.add(qs.get(projectionVar).asResource().getURI()); + } + + } + if(!results.isEmpty()){ + try{ + int cnt = Integer.parseInt(results.get(0)); + if(cnt > 0){ + learnedSPARQLQueries.add(query); + if(stopIfQueryResultNotEmpty){ + return; + } + } + } catch (NumberFormatException e){ + learnedSPARQLQueries.add(query); + if(stopIfQueryResultNotEmpty){ + return; + } + } + logger.info("Result: " + results); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + } else if(queryType == SPARQL_QueryType.ASK){ + for(WeightedQuery query : queries){ + learnedPos++; + logger.info("Testing query:\n" + query); + boolean result = executeAskQuery(query.getQuery().toString()); + learnedSPARQLQueries.add(query); +// if(stopIfQueryResultNotEmpty && result){ +// return; +// } + if(stopIfQueryResultNotEmpty){ + return; + } + logger.info("Result: " + result); + } + } + + sparqlMon.stop(); + logger.info("Done in " + sparqlMon.getLastValue() + "ms."); + } + + private boolean executeAskQuery(String query){ + currentlyExecutedQuery = query; + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), query); + for(String uri : endpoint.getDefaultGraphURIs()){ + qe.addDefaultGraph(uri); + } + boolean ret = qe.execAsk(); + return ret; + } + + private ResultSet executeSelect(String query) { + currentlyExecutedQuery = query; + ResultSet rs; + if (model == null) { + if (cache == null) { + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), query); + qe.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + rs = qe.execSelect(); + } else { + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + } + } else { + rs = QueryExecutionFactory.create(QueryFactory.create(query, Syntax.syntaxARQ), model) + .execSelect(); + } + + return rs; + } + + public String getCurrentlyExecutedQuery() { + return currentlyExecutedQuery; + } + + public int getLearnedPosition() { + if(learnedPos >= 0){ + return learnedPos+1; + } + return learnedPos; + } + + @Override + public void start() { + } + + @Override + public List<String> getCurrentlyBestSPARQLQueries(int nrOfSPARQLQueries) { + List<String> bestQueries = new ArrayList<String>(); + for(WeightedQuery wQ : learnedSPARQLQueries){ + bestQueries.add(wQ.getQuery().toString()); + } + return bestQueries; + } + + @Override + public String getBestSPARQLQuery() { + if(!learnedSPARQLQueries.isEmpty()){ + return learnedSPARQLQueries.iterator().next().getQuery().toString(); + } else { + return null; + } + } + + public SortedSet<WeightedQuery> getLearnedSPARQLQueries() { + return learnedSPARQLQueries; + } + + @Override + public LearningProblem getLearningProblem() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setLearningProblem(LearningProblem learningProblem) { + // TODO Auto-generated method stub + + } + + class SlotProcessor implements Callable<Map<Slot, SortedSet<Allocation>>>{ + + private Slot slot; + + public SlotProcessor(Slot slot) { + this.slot = slot; + } + + @Override + public Map<Slot, SortedSet<Allocation>> call() throws Exception { + Map<Slot, SortedSet<Allocation>> result = new HashMap<Slot, SortedSet<Allocation>>(); + result.put(slot, computeAllocations(slot)); + return result; + } + + private SortedSet<Allocation> computeAllocations(Slot slot){ + logger.info("Computing allocations for slot: " + slot); + SortedSet<Allocation> allocations = new TreeSet<Allocation>(); + + Index index = getIndexBySlotType(slot); + + IndexResultSet rs; + for(String word : slot.getWords()){ + rs = new IndexResultSet(); + if(mappingIndex != null){ + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + rs.add(mappingIndex.getClassesWithScores(word)); + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + rs.add(mappingIndex.getPropertiesWithScores(word)); + } else if(type == SlotType.DATATYPEPROPERTY){ + rs.add(mappingIndex.getDatatypePropertiesWithScores(word)); + } else if(type == SlotType.OBJECTPROPERTY){ + rs.add(mappingIndex.getObjectPropertiesWithScores(word)); + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + rs.add(mappingIndex.getResourcesWithScores(word)); + } + } + //use the non manual indexes only if mapping based resultset is not empty and option is set + if(!useManualMappingsIfExistOnly || rs.isEmpty()){ + if(slot.getSlotType() == SlotType.RESOURCE){ + rs.add(index.getResourcesWithScores(word, 20)); + } else { + if(slot.getSlotType() == SlotType.CLASS){ + word = PlingStemmer.stem(word); + } + rs.add(index.getResourcesWithScores(word, 20)); + } + } + + + for(IndexResultItem item : rs.getItems()){ + double similarity = Similarity.getSimilarity(word, item.getLabel()); +// //get the labels of the redirects and compute the highest similarity +// if(slot.getSlotType() == SlotType.RESOURCE){ +// Set<String> labels = getRedirectLabels(item.getUri()); +// for(String label : labels){ +// double tmp = Similarity.getSimilarity(word, label); +// if(tmp > similarity){ +// similarity = tmp; +// } +// } +// } + double prominence = getProminenceValue(item.getUri(), slot.getSlotType()); + allocations.add(new Allocation(item.getUri(), prominence, similarity)); + } + + } + + normProminenceValues(allocations); + + computeScore(allocations); + logger.info("Found " + allocations.size() + " allocations for slot " + slot); + return new TreeSet<Allocation>(allocations); + } + + private Index getIndexBySlotType(Slot slot){ + Index index = null; + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + index = classesIndex; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + index = propertiesIndex; + } else if(type == SlotType.DATATYPEPROPERTY){ + index = datatypePropertiesIndex; + } else if(type == SlotType.OBJECTPROPERTY){ + index = objectPropertiesIndex; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + index = resourcesIndex; + } + return index; + } + + } + + public String getTaggedInput(){ + return templateGenerator.getTaggedInput(); + } + + private boolean isDatatypeProperty(String uri){ + Boolean isDatatypeProperty = null; + if(mappingIndex != null){ + isDatatypeProperty = mappingIndex.isDataProperty(uri); + } + if(isDatatypeProperty == null){ + String query = String.format("ASK {<%s> a <http://www.w3.org/2002/07/owl#DatatypeProperty> .}", uri); + isDatatypeProperty = executeAskQuery(query); + } + return isDatatypeProperty; + } + + /** + * @param args + * @throws NoTemplateFoundException + * @throws IOException + * @throws FileNotFoundException + * @throws InvalidFileFormatException + */ + public static void main(String[] args) throws Exception { + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); + Index resourcesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_resources"); + Index classesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_classes"); + Index propertiesIndex = new SOLRIndex("http://139.18.2.173:8080/solr/dbpedia_properties"); + + SPARQLTemplateBasedLearner3 learner = new SPARQLTemplateBasedLearner3(endpoint, resourcesIndex, classesIndex, propertiesIndex); + learner.init(); + + String question = "Give me all books written by Dan Brown"; + + learner.setQuestion(question); + learner.learnSPARQLQueries(); + System.out.println("Learned query:\n" + learner.getBestSPARQLQuery()); + System.out.println("Lexical answer type is: " + learner.getTemplates().iterator().next().getLexicalAnswerType()); + System.out.println(learner.getLearnedPosition()); + + } + + + +} Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java 2012-07-17 14:27:32 UTC (rev 3796) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java 2012-07-18 13:08:45 UTC (rev 3797) @@ -1,187 +0,0 @@ -package org.dllearner.algorithm.tbsl.util; - -import java.util.HashMap; -import java.util.Map; - -import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.ObjectProperty; -import org.dllearner.core.owl.Property; -import org.dllearner.kb.sparql.ExtractionDBCache; -import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SparqlQuery; - -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; - -public class PMI { - - private SparqlEndpoint endpoint; - private ExtractionDBCache cache; - - public PMI(SparqlEndpoint endpoint, ExtractionDBCache cache) { - this.endpoint = endpoint; - this.cache = cache; - } - - public double getDirectedPMI(ObjectProperty prop, NamedClass cls){ - System.out.println(String.format("Computing PMI(%s, %s)", prop, cls)); - String query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>}", cls.getName()); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Class occurence: " + classOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double propertyOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Property occurence: " + propertyOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?o a <%s>}", prop.getName(), cls.getName()); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double coOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Co-occurence: " + coOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o}"); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double total = rs.next().getLiteral("cnt").getInt(); - System.out.println("Total: " + total); - - if(classOccurenceCnt == 0 || propertyOccurenceCnt == 0 || coOccurenceCnt == 0){ - return 0; - } - - double pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); - - return pmi; - } - - public double getDirectedPMI(NamedClass cls, Property prop){ - System.out.println(String.format("Computing PMI(%s, %s)", cls, prop)); - String query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>}", cls.getName()); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Class occurence: " + classOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double propertyOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Property occurence: " + propertyOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double coOccurenceCnt = rs.next().getLiteral("cnt").getInt(); - System.out.println("Co-occurence: " + coOccurenceCnt); - - query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o}"); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - double total = rs.next().getLiteral("cnt").getInt(); - System.out.println("Total: " + total); - - if(classOccurenceCnt == 0 || propertyOccurenceCnt == 0 || coOccurenceCnt == 0){ - return 0; - } - - double pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); - - return pmi; - } - - /** - * Returns the direction of the given triple, computed by calculated the PMI values of each combination. - * @param subject - * @param predicate - * @param object - * @return -1 if the given triple should by reversed, else 1. - */ - public int getDirection(NamedClass subject, ObjectProperty predicate, NamedClass object){ - System.out.println(String.format("Computing direction between [%s, %s, %s]", subject, predicate, object)); - double pmi_obj_pred = getDirectedPMI(object, predicate);System.out.println("PMI(OBJECT, PREDICATE): " + pmi_obj_pred); - double pmi_pred_subj = getDirectedPMI(predicate, subject);System.out.println("PMI(PREDICATE, SUBJECT): " + pmi_pred_subj); - double pmi_subj_pred = getDirectedPMI(subject, predicate);System.out.println("PMI(SUBJECT, PREDICATE): " + pmi_subj_pred); - double pmi_pred_obj = getDirectedPMI(predicate, object);System.out.println("PMI(PREDICATE, OBJECT): " + pmi_pred_obj); - - double threshold = 2.0; - - double value = ((pmi_obj_pred + pmi_pred_subj) - (pmi_subj_pred + pmi_pred_obj)); - System.out.println("(PMI(OBJECT, PREDICATE) + PMI(PREDICATE, SUBJECT)) - (PMI(SUBJECT, PREDICATE) + PMI(PREDICATE, OBJECT)) = " + value); - - if( value > threshold){ - System.out.println(object + "---" + predicate + "--->" + subject); - return -1; - } else { - System.out.println(subject + "---" + predicate + "--->" + object); - return 1; - } - } - - public Map<ObjectProperty, Integer> getMostFrequentProperties(NamedClass cls1, NamedClass cls2){ - Map<ObjectProperty, Integer> prop2Cnt = new HashMap<ObjectProperty, Integer>(); - String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?x1 a <%s>. ?x2 a <%s>. ?x1 ?p ?x2} GROUP BY ?p", cls1, cls2); - ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - QuerySolution qs; - while(rs.hasNext()){ - qs = rs.next(); - ObjectProperty p = new ObjectProperty(qs.getResource("p").getURI()); - int cnt = qs.getLiteral("cnt").getInt(); - prop2Cnt.put(p, cnt); - } - return prop2Cnt; - } - - public static void main(String[] args) { - SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); - ExtractionDBCache cache = new ExtractionDBCache("cache"); - String NS = "http://dbpedia.org/ontology/"; - - PMI pmiGen = new PMI(endpoint, cache); - System.out.println(pmiGen.getDirectedPMI( - new ObjectProperty(NS + "author"), - new NamedClass(NS+ "Person"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getDirectedPMI( - new ObjectProperty(NS + "author"), - new NamedClass(NS+ "Writer"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getDirectedPMI( - new NamedClass(NS+ "Book"), - new ObjectProperty(NS + "author")) - ); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getDirection( - new NamedClass(NS+ "Writer"), - new ObjectProperty(NS + "author"), - new NamedClass(NS+ "Book"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getDirection( - new NamedClass(NS+ "Person"), - new ObjectProperty(NS + "starring"), - new NamedClass(NS+ "Film"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getMostFrequentProperties( - new NamedClass(NS+ "Person"), - new NamedClass(NS+ "Film"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getMostFrequentProperties( - new NamedClass(NS+ "Film"), - new NamedClass(NS+ "Actor"))); - - System.out.println("#########################################"); - - System.out.println(pmiGen.getMostFrequentProperties( - new NamedClass(NS+ "Film"), - new NamedClass(NS+ "Person"))); - - } - -} Copied: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java (from rev 3794, trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java) =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/SPARQLEndpointMetrics.java 2012-07-18 13:08:45 UTC (rev 3797) @@ -0,0 +1,446 @@ +package org.dllearner.algorithm.tbsl.util; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Property; +import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.reasoning.SPARQLReasoner; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +public class SPARQLEndpointMetrics { + + private static final Logger log = Logger.getLogger(SPARQLEndpointMetrics.class); + + private SparqlEndpoint endpoint; + private ExtractionDBCache cache; + private SPARQLReasoner reasoner; + + public SPARQLEndpointMetrics(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + + this.reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cache); + } + + /** + * Computes the directed Pointwise Mutual Information(PMI) measure. Formula: log( (f(prop, cls) * N) / (f(cls) * f(prop) ) ) + * @param cls + * @param prop + * @return + */ + public double getDirectedPMI(ObjectProperty prop, NamedClass cls){ + log.debug(String.format("Computing PMI(%s, %s)", prop, cls)); + + double classOccurenceCnt = getOccurencesInObjectPosition(cls); + double propertyOccurenceCnt = getOccurences(prop); + double coOccurenceCnt = getOccurencesPredicateObject(prop, cls); + double total = getTotalTripleCount(); + + double pmi = 0; + if(coOccurenceCnt > 0 && classOccurenceCnt > 0 && propertyOccurenceCnt > 0){ + pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); + } + log.info(String.format("PMI(%s, %s) = %f", prop, cls, pmi)); + return pmi; + } + + /** + * Computes the directed Pointwise Mutual Information(PMI) measure. Formula: log( (f(cls,prop) * N) / (f(cls) * f(prop) ) ) + * @param cls + * @param prop + * @return + */ + public double getDirectedPMI(NamedClass cls, Property prop){ + log.debug(String.format("Computing PMI(%s, %s)...", cls, prop)); + + double classOccurenceCnt = getOccurencesInSubjectPosition(cls); + double propertyOccurenceCnt = getOccurences(prop); + double coOccurenceCnt = getOccurencesSubjectPredicate(cls, prop); + double total = getTotalTripleCount(); + + double pmi = 0; + if(coOccurenceCnt > 0 && classOccurenceCnt > 0 && propertyOccurenceCnt > 0){ + pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); + } + log.info(String.format("PMI(%s, %s) = %f", cls, prop, pmi)); + return pmi; + } + + /** + * Computes the directed Pointwise Mutual Information(PMI) measure. Formula: log( (f(cls,prop) * N) / (f(cls) * f(prop) ) ) + * @param cls + * @param prop + * @return + */ + public double getPMI(NamedClass subject, NamedClass object){ + log.debug(String.format("Computing PMI(%s, %s)", subject, object)); + + double coOccurenceCnt = getOccurencesSubjectObject(subject, object); + double subjectOccurenceCnt = getOccurencesInSubjectPosition(subject); + double objectOccurenceCnt = getOccurencesInObjectPosition(object); + double total = getTotalTripleCount(); + + double pmi = 0; + if(coOccurenceCnt > 0 && subjectOccurenceCnt > 0 && objectOccurenceCnt > 0){ + pmi = Math.log( (coOccurenceCnt * total) / (subjectOccurenceCnt * objectOccurenceCnt) ); + } + log.info(String.format("PMI(%s, %s) = %f", subject, object, pmi)); + return pmi; + } + + /** + * Returns the direction of the given triple, computed by calculating the PMI values of each combination. + * @param subject + * @param predicate + * @param object + * @return -1 if the given triple should by reversed, else 1. + */ + public int getDirection(NamedClass subject, ObjectProperty predicate, NamedClass object){ + log.info(String.format("Computing direction between [%s, %s, %s]", subject, predicate, object)); + double pmi_obj_pred = getDirectedPMI(object, predicate); + double pmi_pred_subj = getDirectedPMI(predicate, subject); + double pmi_subj_pred = getDirectedPMI(subject, predicate); + double pmi_pred_obj = getDirectedPMI(predicate, object); + + double threshold = 2.0; + + double value = ((pmi_obj_pred + pmi_pred_subj) - (pmi_subj_pred + pmi_pred_obj)); + log.info("(PMI(OBJECT, PREDICATE) + PMI(PREDICATE, SUBJECT)) - (PMI(SUBJECT, PREDICATE) + PMI(PREDICATE, OBJECT)) = " + value); + + if( value > threshold){ + log.info(object + "---" + predicate + "--->" + subject); + return -1; + } else { + log.info(subject + "---" + predicate + "--->" + object); + return 1; + } + } + + public Map<ObjectProperty, Integer> getMostFrequentProperties(NamedClass cls1, NamedClass cls2){ + Map<ObjectProperty, Integer> prop2Cnt = new HashMap<ObjectProperty, Integer>(); + String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?x1 a <%s>. ?x2 a <%s>. ?x1 ?p ?x2} GROUP BY ?p", cls1, cls2); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + ObjectProperty p = new ObjectProperty(qs.getResource("p").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + prop2Cnt.put(p, cnt); + } + return prop2Cnt; + } + + /** + * Returns the number of triples with the given property as predicate and where the subject belongs to the given class. + * @param cls + * @return + */ + public int getOccurencesSubjectPredicate(NamedClass cls, Property prop){ + String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int cnt = rs.next().getLiteral("cnt").getInt(); + return cnt; + } + + /** + * Returns the number of triples with the given property as predicate and where the object belongs to the given class. + * @param cls + * @return + */ + public int getOccurencesPredicateObject(Property prop, NamedClass cls){ + String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?o a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int cnt = rs.next().getLiteral("cnt").getInt(); + return cnt; + } + + /** + * Returns the number of triples with the first given class as subject and the second given class as object. + * @param cls + * @return + */ + public int getOccurencesSubjectObject(NamedClass subject, NamedClass object){ + String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s ?p ?o. ?o a <%s>}", subject.getName(), object.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int cnt = rs.next().getLiteral("cnt").getInt(); + return cnt; + } + + /** + * Returns the number of triples where the subject belongs to the given class. + * @param cls + * @return + */ + public int getOccurencesInSubjectPosition(NamedClass cls){ + String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>. ?s ?p ?o.}", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + return classOccurenceCnt; + } + + /** + * Returns the number of triples where the object belongs to the given class. + * @param cls + * @return + */ + public int getOccurencesInObjectPosition(NamedClass cls){ + String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?o a <%s>. ?s ?p ?o.}", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + return classOccurenceCnt; + } + + /** + * Returns the number triples with the given property as predicate. + * @param prop + * @return + */ + public int getOccurences(Property prop){ + String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int propOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + return propOccurenceCnt; + } + + /** + * Returns the number of triples where the subject or object belongs to the given class. + * (This is not the same as computing the number of instances of the given class {@link SPARQLEndpointMetrics#getPopularity(NamedClass)}) + * @param cls + * @return + */ + public int getOccurences(NamedClass cls){ + String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>.{?s ?p1 ?o1.} UNION {?o2 ?p2 ?s} }", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + return classOccurenceCnt; + } + + /** + * Returns the number of instances of the given class. + * @param cls + * @return + */ + public int getPopularity(NamedClass cls){ + String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {?s a <%s>.{?s ?p1 ?o1.} UNION {?o2 ?p2 ?s} }", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + return classOccurenceCnt; + } + + /** + * Returns the total number of triples in the endpoint. For now we return a fixed number 275494030(got from DBpedia Live 18. July 14:00). + * @return + */ + public int getTotalTripleCount(){ + return 275494030; + /*String query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o}"); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int cnt = rs.next().getLiteral("cnt").getInt(); + return cnt;*/ + } + + public double getGoodness(NamedClass subject, ObjectProperty predicate, NamedClass object){ + + double pmi_subject_predicate = getDirectedPMI(subject, predicate); + double pmi_preciate_object = getDirectedPMI(predicate, object); + double pmi_subject_object = getPMI(subject, object); + + double goodness = pmi_subject_predicate + pmi_preciate_object + 2*pmi_subject_object; + + return goodness; + } + + public double getGoodness(Individual subject, ObjectProperty predicate, NamedClass object){ + //this is independent of the subject types + double pmi_preciate_object = getDirectedPMI(predicate, object); + + double goodness = Double.MIN_VALUE; + //get all asserted classes of subject and get the highest value + //TODO inference + Set<NamedClass> types = reasoner.getTypes(subject); + for(NamedClass type : types){ + double pmi_subject_predicate = getDirectedPMI(type, predicate); + double pmi_subject_object = getPMI(type, object); + double tmpGoodness = pmi_subject_predicate + pmi_preciate_object + 2*pmi_subject_object; + if(tmpGoodness >= goodness){ + goodness = tmpGoodness; + } + } + return goodness; + } + + public double getGoodness(NamedClass subject, ObjectProperty predicate, Individual object){ + //this is independent of the object types + double pmi_subject_predicate = getDirectedPMI(subject, predicate); + + double goodness = Double.MIN_VALUE; + //get all asserted classes of subject and get the highest value + //TODO inference + Set<NamedClass> types = reasoner.getTypes(object); + for(NamedClass type : types){ + double pmi_preciate_object = getDirectedPMI(predicate, type); + double pmi_subject_object = getPMI(subject, type); + double tmpGoodness = pmi_subject_predicate + pmi_preciate_object + 2*pmi_subject_object; + if(tmpGoodness >= goodness){ + goodness = tmpGoodness; + } + } + return goodness; + } + + public double getGoodnessConsideringSimilarity(NamedClass subject, ObjectProperty predicate, NamedClass object, + double subjectSim, double predicateSim, double objectSim){ + + double pmi_subject_predicate = getDirectedPMI(subject, predicate); + double pmi_preciate_object = getDirectedPMI(predicate, object); + double pmi_subject_object = getPMI(subject, object); + + double goodness = pmi_subject_predicate * subjectSim * predicateSim + + pmi_preciate_object * objectSim * predicateSim + + 2 * pmi_subject_object * subjectSim * objectSim; + + return goodness; + } + + public void precompute(){ + precompute(Collections.<String>emptySet()); + } + + public void precompute(Collection<String> namespaces){ + log.info("Precomputing..."); + long startTime = System.currentTimeMillis(); + SortedSet<NamedClass> classes = new TreeSet<NamedClass>(); + String query = "SELECT DISTINCT ?class WHERE {?s a ... [truncated message content] |
From: <jen...@us...> - 2012-07-17 14:27:43
|
Revision: 3796 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3796&view=rev Author: jenslehmann Date: 2012-07-17 14:27:32 +0000 (Tue, 17 Jul 2012) Log Message: ----------- tried CEL reasoner Modified Paths: -------------- trunk/test/phaenotype/phaenotype2.conf Modified: trunk/test/phaenotype/phaenotype2.conf =================================================================== --- trunk/test/phaenotype/phaenotype2.conf 2012-07-17 04:50:50 UTC (rev 3795) +++ trunk/test/phaenotype/phaenotype2.conf 2012-07-17 14:27:32 UTC (rev 3796) @@ -10,12 +10,13 @@ ks1.type = "OWL File" ks1.fileName = "mp.owl" -// ks2.type = "OWL File" -// ks2.fileName = "mp-equivalence-axioms-subq.owl" +ks2.type = "OWL File" +ks2.fileName = "mp-equivalence-axioms-subq.owl" // reasoner reasoner.type = "OWL API Reasoner" -reasoner.sources = { ks, ks1 } +reasoner.sources = { ks, ks1, ks2 } +reasoner.reasonerTypeString = "cel" // annotation axioms need to be removed for this to work lp.type = "posNegStandard" lp.positiveExamples = { "kb:MGI_1857473" , "kb:MGI_1856276" } @@ -23,4 +24,4 @@ alg.type = "ocel" alg.maxExecutionTimeInSeconds = 100 -alg.noisePercentage = 50 \ No newline at end of file +alg.noisePercentage = 50 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ed...@us...> - 2012-07-17 04:50:58
|
Revision: 3795 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3795&view=rev Author: edka Date: 2012-07-17 04:50:50 +0000 (Tue, 17 Jul 2012) Log Message: ----------- Modified Paths: -------------- trunk/test/phaenotype/mp-equivalence-axioms-subq.owl trunk/test/phaenotype/mp.owl trunk/test/phaenotype/phaenotype.conf Added Paths: ----------- trunk/test/phaenotype/mp_small.owl trunk/test/phaenotype/phaenotype2.conf trunk/test/phaenotype/pos_3_neg_3.owl Modified: trunk/test/phaenotype/mp-equivalence-axioms-subq.owl =================================================================== --- trunk/test/phaenotype/mp-equivalence-axioms-subq.owl 2012-07-16 12:52:38 UTC (rev 3794) +++ trunk/test/phaenotype/mp-equivalence-axioms-subq.owl 2012-07-17 04:50:50 UTC (rev 3795) @@ -42303,7 +42303,161466 @@ <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> </owl:Class> - + + + <!-- http://purl.obolibrary.org/obo/MP_0001570 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001570"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000033"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000059"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/IMR_0000207"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001570</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001573 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001573"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000033"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000059"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/IMR_0010135"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001573</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001574 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001574"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000033"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CHEBI_25805"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001574</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001575 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001575"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000319"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000151"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001575</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001577 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001577"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000911"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/_#_erytrhocyte_oxygen_transport"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001577</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001584 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001584"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0002001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0042827"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001584</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001586 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001586"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001555"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CL_0000232"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001586</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001588 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001588"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CL_0000232"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CHEBI_35143"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001588</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001589 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001589"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000033"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CL_0000595"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/CHEBI_35143"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001589</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001596 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001596"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001575"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000059"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0001863"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#inheres_in_part_of"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000060"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001596</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001598 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001598"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000992"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000059"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001598</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001599 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001599"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000918"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000059"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001599</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001601 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001601"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0030099"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001601</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001602 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001602"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0002018"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0030099"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001602</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001603 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001603"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001558"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0030099"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001603</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001606 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001606"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0002018"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0030097"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001606</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001613 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001613"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0042311"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001613</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001614 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001614"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000060"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001614</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001619 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001619"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000970"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000060"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001619</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001622 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001622"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0001570"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001622</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001625 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001625"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000584"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000072"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001625</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001629 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001629"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000161"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0060047"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001629</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001633 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001633"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0002018"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0008015"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001633</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001634 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001634"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0002002"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0002405"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MPATH_119"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001634</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001636 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001636"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001845"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0060047"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001636</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001648 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001648"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0006915"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001648</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001649 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001649"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0001490"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001649</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001650 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001650"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001043"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000070"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/NBO_0000724"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001650</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001651 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001651"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0008219"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_central_participant"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0000003"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001651</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001652 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001652"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000912"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/_#_colon_cell_death"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001652</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001653 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001653"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000912"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/_#_stomach_cell_death"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001653</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001654 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001654"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000912"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/_#_liver_cell_death"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001654</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001661 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001661"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001603"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0002405"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001661</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001663 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001663"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001509"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0002431"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001663</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001664 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001664"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0007586"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001664</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001665 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001665"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0001548"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/MA_0002509"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000498"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001665</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001666 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001666"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0022600"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001666</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">mammalian_phenotype_xp</oboInOwl:hasOBONamespace> + </owl:Class> + + + + <!-- http://purl.obolibrary.org/obo/MP_0001667 --> + + <owl:Class rdf:about="http://purl.obolibrary.org/obo/MP_0001667"> + <owl:equivalentClass> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/> + <owl:someValuesFrom> + <owl:Class> + <owl:intersectionOf rdf:parseType="Collection"> + <rdf:Description rdf:about="http://purl.obolibrary.org/obo/PATO_0000001"/> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/BFO_0000052"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/GO_0050892"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/RO_0002180"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/PATO_0000460"/> + </owl:Restriction> + <owl:Restriction> + <owl:onProperty rdf:resource="http://purl.obolibrary.org/obo/mp/mp-logical-definitions-subq#has_central_participant"/> + <owl:someValuesFrom rdf:resource="http://purl.obolibrary.org/obo/IMR_0001657"/> + </owl:Restriction> + </owl:intersectionOf> + </owl:Class> + </owl:someValuesFrom> + </owl:Restriction> + </owl:equivalentClass> + <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">MP:0001667</oboInOwl:id> + <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSc... [truncated message content] |
From: <lor...@us...> - 2012-07-16 12:52:49
|
Revision: 3794 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3794&view=rev Author: lorenz_b Date: 2012-07-16 12:52:38 +0000 (Mon, 16 Jul 2012) Log Message: ----------- Added class to compute PMI. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-16 07:10:22 UTC (rev 3793) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-16 12:52:38 UTC (rev 3794) @@ -155,6 +155,8 @@ private Set<String> relevantKeywords; + private boolean useDomainRangeRestriction = true; + public SPARQLTemplateBasedLearner2(SparqlEndpoint endpoint, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ this(endpoint, resourcesIndex, classesIndex, propertiesIndex, new StanfordPartOfSpeechTagger()); } @@ -305,6 +307,10 @@ reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); } + public void setUseDomainRangeRestriction(boolean useDomainRangeRestriction) { + this.useDomainRangeRestriction = useDomainRangeRestriction; + } + /* * Only for Evaluation useful. */ @@ -619,31 +625,66 @@ Query q = new Query(query.getQuery()); boolean drop = false; - if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ - for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ - String objectVar = triple.getValue().getName(); - String subjectVar = triple.getVariable().getName(); -// System.out.println(triple); - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ -// System.out.println(typeTriple); - if(true){//reasoner.isObjectProperty(a.getUri())){ - Description range = reasoner.getRange(new ObjectProperty(a.getUri())); + if(useDomainRangeRestriction){ + if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ + for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ + String objectVar = triple.getValue().getName(); + String subjectVar = triple.getVariable().getName(); +// System.out.println(triple); + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ +// System.out.println(typeTriple); + if(true){//reasoner.isObjectProperty(a.getUri())){ + Description range = reasoner.getRange(new ObjectProperty(a.getUri())); +// System.out.println(a); + if(range != null){ + Set<Description> allRanges = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(range instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(range); + allRanges.addAll(superClasses); + } else { + for(Description nc : range.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allRanges.addAll(superClasses); + } + } + allRanges.add(range); + allRanges.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); + String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); + + if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + drop = true; + } + } + } else { + drop = true; + } + + } + for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ + Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); // System.out.println(a); - if(range != null){ - Set<Description> allRanges = new HashSet<Description>(); + if(domain != null){ + Set<Description> allDomains = new HashSet<Description>(); SortedSet<Description> superClasses; - if(range instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(range); - allRanges.addAll(superClasses); + if(domain instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(domain); + allDomains.addAll(superClasses); } else { - for(Description nc : range.getChildren()){ + for(Description nc : domain.getChildren()){ superClasses = reasoner.getSuperClasses(nc); - allRanges.addAll(superClasses); + allDomains.addAll(superClasses); } } - allRanges.add(range); - allRanges.remove(new NamedClass(Thing.instance.getURI())); - + allDomains.add(domain); + allDomains.remove(new NamedClass(Thing.instance.getURI())); + Set<Description> allTypes = new HashSet<Description>(); String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); Description type = new NamedClass(typeURI); @@ -651,46 +692,13 @@ allTypes.addAll(superClasses); allTypes.add(type); - if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ + if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ drop = true; - } - } - } else { - drop = true; - } - - } - for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ - Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); -// System.out.println(a); - if(domain != null){ - Set<Description> allDomains = new HashSet<Description>(); - SortedSet<Description> superClasses; - if(domain instanceof NamedClass){ - superClasses = reasoner.getSuperClasses(domain); - allDomains.addAll(superClasses); - } else { - for(Description nc : domain.getChildren()){ - superClasses = reasoner.getSuperClasses(nc); - allDomains.addAll(superClasses); + System.err.println("DROPPING: \n" + q.toString()); + } else { + } } - allDomains.add(domain); - allDomains.remove(new NamedClass(Thing.instance.getURI())); - - Set<Description> allTypes = new HashSet<Description>(); - String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Description type = new NamedClass(typeURI); - superClasses = reasoner.getSuperClasses(type); - allTypes.addAll(superClasses); - allTypes.add(type); - - if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ - drop = true; -// System.err.println("DROPPING: \n" + q.toString()); - } else { - - } } } } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/PMI.java 2012-07-16 12:52:38 UTC (rev 3794) @@ -0,0 +1,187 @@ +package org.dllearner.algorithm.tbsl.util; + +import java.util.HashMap; +import java.util.Map; + +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Property; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +public class PMI { + + private SparqlEndpoint endpoint; + private ExtractionDBCache cache; + + public PMI(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + } + + public double getDirectedPMI(ObjectProperty prop, NamedClass cls){ + System.out.println(String.format("Computing PMI(%s, %s)", prop, cls)); + String query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>}", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Class occurence: " + classOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double propertyOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Property occurence: " + propertyOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o. ?o a <%s>}", prop.getName(), cls.getName()); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double coOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Co-occurence: " + coOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o}"); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double total = rs.next().getLiteral("cnt").getInt(); + System.out.println("Total: " + total); + + if(classOccurenceCnt == 0 || propertyOccurenceCnt == 0 || coOccurenceCnt == 0){ + return 0; + } + + double pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); + + return pmi; + } + + public double getDirectedPMI(NamedClass cls, Property prop){ + System.out.println(String.format("Computing PMI(%s, %s)", cls, prop)); + String query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>}", cls.getName()); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double classOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Class occurence: " + classOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s <%s> ?o}", prop.getName()); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double propertyOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Property occurence: " + propertyOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s a <%s>. ?s <%s> ?o}", cls.getName(), prop.getName()); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double coOccurenceCnt = rs.next().getLiteral("cnt").getInt(); + System.out.println("Co-occurence: " + coOccurenceCnt); + + query = String.format("SELECT (COUNT(*) AS ?cnt) WHERE {?s ?p ?o}"); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + double total = rs.next().getLiteral("cnt").getInt(); + System.out.println("Total: " + total); + + if(classOccurenceCnt == 0 || propertyOccurenceCnt == 0 || coOccurenceCnt == 0){ + return 0; + } + + double pmi = Math.log( (coOccurenceCnt * total) / (classOccurenceCnt * propertyOccurenceCnt) ); + + return pmi; + } + + /** + * Returns the direction of the given triple, computed by calculated the PMI values of each combination. + * @param subject + * @param predicate + * @param object + * @return -1 if the given triple should by reversed, else 1. + */ + public int getDirection(NamedClass subject, ObjectProperty predicate, NamedClass object){ + System.out.println(String.format("Computing direction between [%s, %s, %s]", subject, predicate, object)); + double pmi_obj_pred = getDirectedPMI(object, predicate);System.out.println("PMI(OBJECT, PREDICATE): " + pmi_obj_pred); + double pmi_pred_subj = getDirectedPMI(predicate, subject);System.out.println("PMI(PREDICATE, SUBJECT): " + pmi_pred_subj); + double pmi_subj_pred = getDirectedPMI(subject, predicate);System.out.println("PMI(SUBJECT, PREDICATE): " + pmi_subj_pred); + double pmi_pred_obj = getDirectedPMI(predicate, object);System.out.println("PMI(PREDICATE, OBJECT): " + pmi_pred_obj); + + double threshold = 2.0; + + double value = ((pmi_obj_pred + pmi_pred_subj) - (pmi_subj_pred + pmi_pred_obj)); + System.out.println("(PMI(OBJECT, PREDICATE) + PMI(PREDICATE, SUBJECT)) - (PMI(SUBJECT, PREDICATE) + PMI(PREDICATE, OBJECT)) = " + value); + + if( value > threshold){ + System.out.println(object + "---" + predicate + "--->" + subject); + return -1; + } else { + System.out.println(subject + "---" + predicate + "--->" + object); + return 1; + } + } + + public Map<ObjectProperty, Integer> getMostFrequentProperties(NamedClass cls1, NamedClass cls2){ + Map<ObjectProperty, Integer> prop2Cnt = new HashMap<ObjectProperty, Integer>(); + String query = String.format("SELECT ?p (COUNT(*) AS ?cnt) WHERE {?x1 a <%s>. ?x2 a <%s>. ?x1 ?p ?x2} GROUP BY ?p", cls1, cls2); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + ObjectProperty p = new ObjectProperty(qs.getResource("p").getURI()); + int cnt = qs.getLiteral("cnt").getInt(); + prop2Cnt.put(p, cnt); + } + return prop2Cnt; + } + + public static void main(String[] args) { + SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); + ExtractionDBCache cache = new ExtractionDBCache("cache"); + String NS = "http://dbpedia.org/ontology/"; + + PMI pmiGen = new PMI(endpoint, cache); + System.out.println(pmiGen.getDirectedPMI( + new ObjectProperty(NS + "author"), + new NamedClass(NS+ "Person"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getDirectedPMI( + new ObjectProperty(NS + "author"), + new NamedClass(NS+ "Writer"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getDirectedPMI( + new NamedClass(NS+ "Book"), + new ObjectProperty(NS + "author")) + ); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getDirection( + new NamedClass(NS+ "Writer"), + new ObjectProperty(NS + "author"), + new NamedClass(NS+ "Book"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getDirection( + new NamedClass(NS+ "Person"), + new ObjectProperty(NS + "starring"), + new NamedClass(NS+ "Film"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getMostFrequentProperties( + new NamedClass(NS+ "Person"), + new NamedClass(NS+ "Film"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getMostFrequentProperties( + new NamedClass(NS+ "Film"), + new NamedClass(NS+ "Actor"))); + + System.out.println("#########################################"); + + System.out.println(pmiGen.getMostFrequentProperties( + new NamedClass(NS+ "Film"), + new NamedClass(NS+ "Person"))); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-15 17:50:53
|
Revision: 3792 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3792&view=rev Author: lorenz_b Date: 2012-07-15 17:50:46 +0000 (Sun, 15 Jul 2012) Log Message: ----------- Added more disambiguation. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/UnknownPropertyHelper.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-15 17:49:04 UTC (rev 3791) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-15 17:50:46 UTC (rev 3792) @@ -24,7 +24,6 @@ import java.util.concurrent.Future; import org.apache.log4j.Logger; -import org.dllearner.algorithm.tbsl.ltag.parser.GrammarFilter; import org.dllearner.algorithm.tbsl.nlp.Lemmatizer; import org.dllearner.algorithm.tbsl.nlp.LingPipeLemmatizer; import org.dllearner.algorithm.tbsl.nlp.PartOfSpeechTagger; @@ -38,7 +37,6 @@ import org.dllearner.algorithm.tbsl.sparql.SPARQL_PairType; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Property; import org.dllearner.algorithm.tbsl.sparql.SPARQL_QueryType; -import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Triple; import org.dllearner.algorithm.tbsl.sparql.SPARQL_Value; import org.dllearner.algorithm.tbsl.sparql.Slot; @@ -50,6 +48,8 @@ import org.dllearner.algorithm.tbsl.util.PopularityMap; import org.dllearner.algorithm.tbsl.util.PopularityMap.EntityType; import org.dllearner.algorithm.tbsl.util.Similarity; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper; +import org.dllearner.algorithm.tbsl.util.UnknownPropertyHelper.SymPropertyDirection; import org.dllearner.common.index.Index; import org.dllearner.common.index.IndexResultItem; import org.dllearner.common.index.IndexResultSet; @@ -64,6 +64,11 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; import org.dllearner.core.SparqlQueryLearningAlgorithm; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -71,6 +76,7 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.ini4j.InvalidFileFormatException; import org.ini4j.Options; +import org.semanticweb.HermiT.Configuration.DirectBlockingType; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; @@ -78,6 +84,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.shared.UnknownPropertyException; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.RDFS; import com.jamonapi.Monitor; @@ -85,10 +92,12 @@ public class SPARQLTemplateBasedLearner2 implements SparqlQueryLearningAlgorithm{ - enum Ranking{ - LUCENE, SIMILARITY, NONE + + enum Mode{ + BEST_QUERY, BEST_NON_EMPTY_QUERY } + private Mode mode = Mode.BEST_QUERY; private static final Logger logger = Logger.getLogger(SPARQLTemplateBasedLearner2.class); private Monitor templateMon = MonitorFactory.getTimeMonitor("template"); @@ -123,12 +132,12 @@ private String question; private int learnedPos = -1; - private Map<String, Object> learnedSPARQLQueries; private Set<Template> templates; - private Collection<Query> sparqlQueryCandidates; private Map<Template, Collection<? extends Query>> template2Queries; private Map<Slot, List<String>> slot2URI; + private Collection<WeightedQuery> sparqlQueryCandidates; + private SortedSet<WeightedQuery> learnedSPARQLQueries; private SortedSet<WeightedQuery> generatedQueries; private SPARQLReasoner reasoner; @@ -217,6 +226,7 @@ datatypePropertiesIndex = propertiesIndex; objectPropertiesIndex = propertiesIndex; } + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint), cache); } public SPARQLTemplateBasedLearner2(Model model, Index resourcesIndex, Index classesIndex, Index propertiesIndex){ @@ -292,6 +302,7 @@ datatypePropertiesIndex = propertiesIndex; objectPropertiesIndex = propertiesIndex; } + reasoner = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); } /* @@ -349,7 +360,7 @@ } private void reset(){ - learnedSPARQLQueries = new HashMap<String, Object>(); + learnedSPARQLQueries = new TreeSet<WeightedQuery>(); template2Queries = new HashMap<Template, Collection<? extends Query>>(); slot2URI = new HashMap<Slot, List<String>>(); relevantKeywords = new HashSet<String>(); @@ -383,24 +394,36 @@ //get the weighted query candidates generatedQueries = getWeightedSPARQLQueries(templates); - sparqlQueryCandidates = new ArrayList<Query>(); + sparqlQueryCandidates = new ArrayList<WeightedQuery>(); int i = 0; for(WeightedQuery wQ : generatedQueries){ System.out.println(wQ.explain()); - sparqlQueryCandidates.add(wQ.getQuery()); + sparqlQueryCandidates.add(wQ); if(i == maxTestedQueries){ break; } i++; } - //test candidates - if(useRemoteEndpointValidation){ //on remote endpoint - validateAgainstRemoteEndpoint(sparqlQueryCandidates); - } else {//on local model - + if(mode == Mode.BEST_QUERY){ + double bestScore = -1; + for(WeightedQuery candidate : generatedQueries){ + double score = candidate.getScore(); + if(score >= bestScore){ + bestScore = score; + learnedSPARQLQueries.add(candidate); + } else { + break; + } + } + } else if(mode == Mode.BEST_NON_EMPTY_QUERY){ + //test candidates + if(useRemoteEndpointValidation){ //on remote endpoint + validateAgainstRemoteEndpoint(sparqlQueryCandidates); + } else {//on local model + + } } - } public SortedSet<WeightedQuery> getGeneratedQueries() { @@ -425,8 +448,8 @@ public List<String> getGeneratedSPARQLQueries(){ List<String> queries = new ArrayList<String>(); - for(Query q : sparqlQueryCandidates){ - queries.add(q.toString()); + for(WeightedQuery wQ : sparqlQueryCandidates){ + queries.add(wQ.getQuery().toString()); } return queries; @@ -595,7 +618,7 @@ for(WeightedQuery query : queries){ Query q = new Query(query.getQuery()); - boolean drop = false;/* + boolean drop = false; if(slot.getSlotType() == SlotType.PROPERTY || slot.getSlotType() == SlotType.SYMPROPERTY){ for(SPARQL_Triple triple : q.getTriplesWithVar(slot.getAnchor())){ String objectVar = triple.getValue().getName(); @@ -603,34 +626,34 @@ // System.out.println(triple); for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(objectVar)){ // System.out.println(typeTriple); - if(isObjectProperty(a.getUri())){ - Set<String> ranges = getRanges(a.getUri()); + if(true){//reasoner.isObjectProperty(a.getUri())){ + Description range = reasoner.getRange(new ObjectProperty(a.getUri())); // System.out.println(a); - if(!ranges.isEmpty()){ - Set<String> allRanges = new HashSet<String>(); - for(String range : ranges){ - allRanges.addAll(getSuperClasses(range)); + if(range != null){ + Set<Description> allRanges = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(range instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(range); + allRanges.addAll(superClasses); + } else { + for(Description nc : range.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allRanges.addAll(superClasses); + } } - allRanges.addAll(ranges); - allRanges.remove("http://www.w3.org/2002/07/owl#Thing"); + allRanges.add(range); + allRanges.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Set<String> allTypes = getSuperClasses(typeURI); - allTypes.add(typeURI); -// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ -// System.out.println("RANGES: " + allRanges); -// System.out.println("TYPES: " + allTypes); -// } + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); if(!org.mindswap.pellet.utils.SetUtils.intersects(allRanges, allTypes)){ drop = true; -// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer") && q.toString().contains("/Software>")){ -// System.out.println("RANGES: " + allRanges); -// System.out.println("TYPES: " + allTypes); -// System.out.println("DROPPING: \n" + q.toString()); -// } - } else { - - } + } } } else { drop = true; @@ -638,34 +661,40 @@ } for(SPARQL_Triple typeTriple : q.getRDFTypeTriples(subjectVar)){ -// System.out.println(typeTriple); - Set<String> domains = getDomains(a.getUri()); + Description domain = reasoner.getDomain(new ObjectProperty(a.getUri())); // System.out.println(a); - if(!domains.isEmpty()){ - Set<String> allDomains = new HashSet<String>(); - for(String domain : domains){ - allDomains.addAll(getSuperClasses(domain)); + if(domain != null){ + Set<Description> allDomains = new HashSet<Description>(); + SortedSet<Description> superClasses; + if(domain instanceof NamedClass){ + superClasses = reasoner.getSuperClasses(domain); + allDomains.addAll(superClasses); + } else { + for(Description nc : domain.getChildren()){ + superClasses = reasoner.getSuperClasses(nc); + allDomains.addAll(superClasses); + } } - allDomains.addAll(domains); - allDomains.remove("http://www.w3.org/2002/07/owl#Thing"); + allDomains.add(domain); + allDomains.remove(new NamedClass(Thing.instance.getURI())); + + Set<Description> allTypes = new HashSet<Description>(); String typeURI = typeTriple.getValue().getName().substring(1,typeTriple.getValue().getName().length()-1); - Set<String> allTypes = getSuperClasses(typeURI); - allTypes.add(typeTriple.getValue().getName()); -// if(typeURI.equals("http://dbpedia.org/ontology/Organisation") && a.getUri().equals("http://dbpedia.org/ontology/developer")){ -// System.out.println("DOMAINS: " + allDomains); -// System.out.println("TYPES: " + allTypes); -// } + Description type = new NamedClass(typeURI); + superClasses = reasoner.getSuperClasses(type); + allTypes.addAll(superClasses); + allTypes.add(type); if(!org.mindswap.pellet.utils.SetUtils.intersects(allDomains, allTypes)){ drop = true; -// System.out.println("DROPPING: \n" + q.toString()); +// System.err.println("DROPPING: \n" + q.toString()); } else { } } } } - }*/ + } if(!drop){ if(slot.getSlotType() == SlotType.RESOURCE){//avoid queries where predicate is data property and object resource->add REGEX filter in this case @@ -732,7 +761,40 @@ } - } + } else { + if(slot.getSlotType() == SlotType.SYMPROPERTY){ + for(WeightedQuery wQ : queries){ + List<SPARQL_Triple> triples = wQ.getQuery().getTriplesWithVar(slot.getAnchor()); + for(SPARQL_Triple triple : triples){ + String typeVar; + String resourceURI; + SymPropertyDirection direction; + if(triple.getValue().isVariable()){ + direction = SymPropertyDirection.VAR_RIGHT; + typeVar = triple.getValue().getName(); + resourceURI = triple.getVariable().getName(); + } else { + direction = SymPropertyDirection.VAR_LEFT; + typeVar = triple.getVariable().getName(); + resourceURI = triple.getValue().getName(); + } + resourceURI = resourceURI.replace("<", "").replace(">", ""); + List<SPARQL_Triple> typeTriples = wQ.getQuery().getRDFTypeTriples(typeVar); + for(SPARQL_Triple typeTriple : typeTriples){ + String typeURI = typeTriple.getValue().getName().replace("<", "").replace(">", ""); + System.out.println(typeURI + "---" + resourceURI); + List<Entry<String, Integer>> mostFrequentProperties = UnknownPropertyHelper.getMostFrequentProperties(endpoint, cache, typeURI, resourceURI, direction); + for(Entry<String, Integer> property : mostFrequentProperties){ + System.out.println(property); + wQ.getQuery().replaceVarWithURI(slot.getAnchor(), property.getKey()); + wQ.setScore(wQ.getScore() + 0.1); + } + } + + } + } + } + } // else if(slot.getSlotType() == SlotType.CLASS){ // String token = slot.getWords().get(0); // if(slot.getToken().contains("house")){ @@ -913,31 +975,23 @@ return index; } - private void validateAgainstRemoteEndpoint(Collection<? extends Query> queries){ - List<String> queryStrings = new ArrayList<String>(); - SPARQL_QueryType queryType = SPARQL_QueryType.SELECT; - for(Query query : queries){ - if(query.getQt() == SPARQL_QueryType.ASK){ - queryType = SPARQL_QueryType.ASK; - } else if(query.getQt() == SPARQL_QueryType.SELECT){ - queryType = SPARQL_QueryType.SELECT; - } - queryStrings.add(query.toString()); - } - validate(queryStrings, queryType); + private void validateAgainstRemoteEndpoint(Collection<WeightedQuery> queries){ + SPARQL_QueryType queryType = queries.iterator().next().getQuery().getQt(); + validate(queries, queryType); } - private void validate(List<String> queries, SPARQL_QueryType queryType){ + private void validate(Collection<WeightedQuery> queries, SPARQL_QueryType queryType){ logger.info("Testing candidate SPARQL queries on remote endpoint..."); sparqlMon.start(); if(queryType == SPARQL_QueryType.SELECT){ - for(String query : queries){ + for(WeightedQuery query : queries){ + learnedPos++; List<String> results; try { logger.info("Testing query:\n" + query); - com.hp.hpl.jena.query.Query q = QueryFactory.create(query, Syntax.syntaxARQ); + com.hp.hpl.jena.query.Query q = QueryFactory.create(query.getQuery().toString(), Syntax.syntaxARQ); q.setLimit(1); - ResultSet rs = executeSelect(q.toString());//executeSelect(query); + ResultSet rs = executeSelect(q.toString()); results = new ArrayList<String>(); QuerySolution qs; @@ -955,15 +1009,14 @@ if(!results.isEmpty()){ try{ int cnt = Integer.parseInt(results.get(0)); - if(cnt > 0){learnedPos = queries.indexOf(query); - learnedSPARQLQueries.put(query, results); + if(cnt > 0){ + learnedSPARQLQueries.add(query); if(stopIfQueryResultNotEmpty){ return; } } } catch (NumberFormatException e){ - learnedSPARQLQueries.put(query, results); - learnedPos = queries.indexOf(query); + learnedSPARQLQueries.add(query); if(stopIfQueryResultNotEmpty){ return; } @@ -976,14 +1029,15 @@ } } else if(queryType == SPARQL_QueryType.ASK){ - for(String query : queries){ + for(WeightedQuery query : queries){ + learnedPos++; logger.info("Testing query:\n" + query); - boolean result = executeAskQuery(query); - learnedSPARQLQueries.put(query, result); + boolean result = executeAskQuery(query.getQuery().toString()); + learnedSPARQLQueries.add(query); // if(stopIfQueryResultNotEmpty && result){ // return; // } - if(stopIfQueryResultNotEmpty){learnedPos = queries.indexOf(query); + if(stopIfQueryResultNotEmpty){ return; } logger.info("Result: " + result); @@ -1040,19 +1094,25 @@ @Override public List<String> getCurrentlyBestSPARQLQueries(int nrOfSPARQLQueries) { - return new ArrayList<String>(learnedSPARQLQueries.keySet()); + List<String> bestQueries = new ArrayList<String>(); + for(WeightedQuery wQ : learnedSPARQLQueries){ + bestQueries.add(wQ.getQuery().toString()); + } + return bestQueries; } @Override public String getBestSPARQLQuery() { if(!learnedSPARQLQueries.isEmpty()){ - return learnedSPARQLQueries.keySet().iterator().next(); + return learnedSPARQLQueries.iterator().next().getQuery().toString(); } else { return null; } } - + public SortedSet<WeightedQuery> getLearnedSPARQLQueries() { + return learnedSPARQLQueries; + } @Override public LearningProblem getLearningProblem() { @@ -1107,7 +1167,7 @@ //use the non manual indexes only if mapping based resultset is not empty and option is set if(!useManualMappingsIfExistOnly || rs.isEmpty()){ if(slot.getSlotType() == SlotType.RESOURCE){ - rs.add(index.getResourcesWithScores(word, 50)); + rs.add(index.getResourcesWithScores(word, 20)); } else { if(slot.getSlotType() == SlotType.CLASS){ word = PlingStemmer.stem(word); Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/UnknownPropertyHelper.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/UnknownPropertyHelper.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/util/UnknownPropertyHelper.java 2012-07-15 17:50:46 UTC (rev 3792) @@ -0,0 +1,102 @@ +package org.dllearner.algorithm.tbsl.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.collections.keyvalue.DefaultMapEntry; +import org.dllearner.kb.sparql.ExtractionDBCache; +import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.utilities.MapUtils; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; + +public class UnknownPropertyHelper { + + public enum SymPropertyDirection { + VAR_LEFT, VAR_RIGHT, UNKNOWN + } + + private SparqlEndpoint endpoint; + private ExtractionDBCache cache; + + public UnknownPropertyHelper(SparqlEndpoint endpoint, ExtractionDBCache cache) { + this.endpoint = endpoint; + this.cache = cache; + } + + public static void getPopularity(SparqlEndpoint endpoint, ExtractionDBCache cache, String type, String resource){ + String query = String.format("SELECT ?p COUNT(?x) WHERE {?x a <%s>. <%s> ?p ?x.} GROUP BY ?p", type, resource); + System.out.println(query); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + while(rs.hasNext()){ + System.out.println(rs.next()); + } + + query = String.format("SELECT ?p COUNT(?x) WHERE {?x a <%s>. ?x ?p <%s>.} GROUP BY ?p", type, resource); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + while(rs.hasNext()){ + System.out.println(rs.next()); + } + } + + + public static List<Entry<String, Integer>> getMostFrequentProperties(SparqlEndpoint endpoint, ExtractionDBCache cache, String type, String resource, SymPropertyDirection direction){ + Map<String, Integer> property2Frequency = new HashMap<String, Integer>(); + String query; + ResultSet rs; + if(direction == SymPropertyDirection.VAR_LEFT){ + query = String.format("SELECT ?p (COUNT(?x) AS ?cnt) WHERE {?x a <%s>. ?x ?p <%s>.} GROUP BY ?p ORDER BY DESC(?cnt)", type, resource); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + String propertyURI = qs.getResource("p").getURI(); + int cnt = qs.getLiteral("cnt").getInt(); + property2Frequency.put(propertyURI, cnt); + } + } else if(direction == SymPropertyDirection.VAR_RIGHT){ + query = String.format("SELECT ?p (COUNT(?x) AS ?cnt) WHERE {?x a <%s>. <%s> ?p ?x.} GROUP BY ?p ORDER BY DESC(?cnt)", type, resource); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + QuerySolution qs; + while(rs.hasNext()){ + qs = rs.next(); + String propertyURI = qs.getResource("p").getURI(); + int cnt = qs.getLiteral("cnt").getInt(); + property2Frequency.put(propertyURI, cnt); + } + } else if(direction == SymPropertyDirection.UNKNOWN){ + + } + List<Entry<String, Integer>> sortedProperty2Frequency = MapUtils.sortByValues(property2Frequency); + return sortedProperty2Frequency; + } + + public static SymPropertyDirection getDirection(SparqlEndpoint endpoint, ExtractionDBCache cache, String typeURI, String propertyURI){ + String query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>. ?x <%s> ?o.}", typeURI, propertyURI); + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classLeftCnt = 0; + while(rs.hasNext()){ + classLeftCnt = rs.next().getLiteral("cnt").getInt(); + } + + query = String.format("SELECT (COUNT(?x) AS ?cnt) WHERE {?x a <%s>. ?o <%s> ?x.}", typeURI, propertyURI); + rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int classRightCnt = 0; + while(rs.hasNext()){ + classRightCnt = rs.next().getLiteral("cnt").getInt(); + } + if(classLeftCnt > classRightCnt){ + return SymPropertyDirection.VAR_LEFT; + } else if(classRightCnt > classLeftCnt){ + return SymPropertyDirection.VAR_RIGHT; + } else { + return SymPropertyDirection.UNKNOWN; + } + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2012-07-15 17:49:04 UTC (rev 3791) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/SOLRIndex.java 2012-07-15 17:50:46 UTC (rev 3792) @@ -26,6 +26,8 @@ private String sortField; + private boolean restrictiveSearch = true; + public SOLRIndex(String solrServerURL){ try { server = new CommonsHttpSolrServer(solrServerURL); @@ -96,8 +98,26 @@ try { String solrString = queryString; if(primarySearchField != null){ - solrString = primarySearchField + ":" + "\"" + queryString + "\"" + "^2 " + queryString; + solrString = primarySearchField + ":" + "\"" + queryString + "\"" + "^2 "; + if(restrictiveSearch){ + String[] tokens = queryString.split(" "); + if(tokens.length > 1){ + solrString += " OR ("; + for(int i = 0; i < tokens.length; i++){ + String token = tokens[i]; + solrString += primarySearchField + ":" + token; + if(i < tokens.length-1){ + solrString += " AND "; + } + } + solrString += ")"; + } + + } else { + solrString += queryString; + } } + System.out.println(solrString); SolrQuery query = new SolrQuery(solrString); query.setRows(limit); query.setStart(offset); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-15 17:49:11
|
Revision: 3791 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3791&view=rev Author: lorenz_b Date: 2012-07-15 17:49:04 +0000 (Sun, 15 Jul 2012) Log Message: ----------- Added methods to check if property is objectproperty or dataproperty. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-07-13 13:21:30 UTC (rev 3790) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/SPARQLReasoner.java 2012-07-15 17:49:04 UTC (rev 3791) @@ -727,6 +727,18 @@ return null; } + public boolean isObjectProperty(String propertyURI){ + String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.ObjectProperty.getURI()); + boolean isObjectProperty = executeAskQuery(query); + return isObjectProperty; + } + + public boolean isDataProperty(String propertyURI){ + String query = String.format("ASK {<%s> a <%s>}", propertyURI, OWL.DatatypeProperty.getURI()); + boolean isObjectProperty = executeAskQuery(query); + return isObjectProperty; + } + public int getIndividualsCount(NamedClass nc){ String query = String.format("SELECT (COUNT(?s) AS ?cnt) WHERE {" + "?s a <%s>." + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 13:21:39
|
Revision: 3790 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3790&view=rev Author: lorenz_b Date: 2012-07-13 13:21:30 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Lowering score for queries with REGEX. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-13 13:20:45 UTC (rev 3789) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner2.java 2012-07-13 13:21:30 UTC (rev 3790) @@ -496,6 +496,7 @@ for(Template t : templates){ logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); + boolean containsRegex = t.getQuery().toString().toLowerCase().contains("(regex("); ExecutorService executor = Executors.newFixedThreadPool(t.getSlots().size()); List<Future<Map<Slot, SortedSet<Allocation>>>> list = new ArrayList<Future<Map<Slot, SortedSet<Allocation>>>>(); @@ -701,6 +702,13 @@ } } + //lower queries with FILTER-REGEX + if(containsRegex){ + for(WeightedQuery wQ : tmp){ + wQ.setScore(wQ.getScore() - 0.01); + } + } + queries.clear(); queries.addAll(tmp);//System.out.println(tmp); tmp.clear(); @@ -1134,6 +1142,23 @@ return new TreeSet<Allocation>(allocations); } + private Index getIndexBySlotType(Slot slot){ + Index index = null; + SlotType type = slot.getSlotType(); + if(type == SlotType.CLASS){ + index = classesIndex; + } else if(type == SlotType.PROPERTY || type == SlotType.SYMPROPERTY){ + index = propertiesIndex; + } else if(type == SlotType.DATATYPEPROPERTY){ + index = datatypePropertiesIndex; + } else if(type == SlotType.OBJECTPROPERTY){ + index = objectPropertiesIndex; + } else if(type == SlotType.RESOURCE || type == SlotType.UNSPEC){ + index = resourcesIndex; + } + return index; + } + } public String getTaggedInput(){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 13:20:54
|
Revision: 3789 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3789&view=rev Author: lorenz_b Date: 2012-07-13 13:20:45 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Changed supertype. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java Modified: trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java 2012-07-13 09:50:38 UTC (rev 3788) +++ trunk/components-ext/src/main/java/org/dllearner/common/index/VirtuosoPropertiesIndex.java 2012-07-13 13:20:45 UTC (rev 3789) @@ -5,7 +5,7 @@ import com.hp.hpl.jena.rdf.model.Model; -public class VirtuosoPropertiesIndex extends SPARQLIndex{ +public class VirtuosoPropertiesIndex extends SPARQLPropertiesIndex{ public VirtuosoPropertiesIndex(SparqlEndpoint endpoint) { super(endpoint); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-07-13 09:50:44
|
Revision: 3788 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3788&view=rev Author: christinaunger Date: 2012-07-13 09:50:38 +0000 (Fri, 13 Jul 2012) Log Message: ----------- - again tried to the number problem :P - introduced distinction between equal and equals Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-07-13 08:39:06 UTC (rev 3787) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-07-13 09:50:38 UTC (rev 3788) @@ -319,7 +319,7 @@ out.addOrderBy(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_OrderBy.ASC)); out.setLimit(1); return out; - } else if (predicate.equals("equal")) { + } else if (predicate.equals("equals")) { out.addFilter(new SPARQL_Filter( new SPARQL_Pair( new SPARQL_Term(simple.getArguments().get(0).getValue(),false), @@ -347,9 +347,11 @@ out.addCondition(new SPARQL_Triple(term,new SPARQL_Property("type",new SPARQL_Prefix("rdf","")),prop)); } else if (arity == 2) { - String arg1 = simple.getArguments().get(0).getValue();SPARQL_Term term1 = new SPARQL_Term(arg1,false);term1.setIsVariable(true); - String arg2 = simple.getArguments().get(1).getValue();SPARQL_Term term2 = new SPARQL_Term(arg2,false);term2.setIsVariable(true); - out.addCondition(new SPARQL_Triple(term1, prop, term2)); + String arg1 = simple.getArguments().get(0).getValue(); + SPARQL_Term term1 = new SPARQL_Term(arg1,arg1.contains(":"),!arg1.matches("(\\?)?[0-9]+")); + String arg2 = simple.getArguments().get(1).getValue(); + SPARQL_Term term2 = new SPARQL_Term(arg2,arg2.contains(":"),!arg2.matches("(\\?)?[0-9]+")); + out.addCondition(new SPARQL_Triple(term1,prop,term2)); } else if (arity > 2) { // TODO @@ -371,11 +373,11 @@ if (s.getAnchor().equals(v1)) v1isSlotVar = true; if (s.getAnchor().equals(v2)) v2isSlotVar = true; } - if (!v1isSlotVar && !v1.matches("[0..9]+") && !v1.contains("count")) { + if (!v1isSlotVar && !v1.matches("(\\?)?[0-9]+") && !v1.contains("count")) { if (vs.containsKey(v1)) vs.put(v1,vs.get(v1)+1); else vs.put(v1,1); } - if (!v2isSlotVar && !v2.matches("[0..9]+") && !v2.contains("count")) { + if (!v2isSlotVar && !v2.matches("(\\?)?[0-9]+") && !v2.contains("count")) { if (vs.containsKey(v2)) vs.put(v2,vs.get(v2)+1); else vs.put(v2,1); } @@ -402,9 +404,7 @@ Set<Simple_DRS_Condition> equalsConditions = new HashSet<Simple_DRS_Condition>(); for (Simple_DRS_Condition c : drs.getAllSimpleConditions()) { - if(c.getPredicate().equals("equal") - && !c.getArguments().get(0).getValue().matches("[0-9]+") - && !c.getArguments().get(1).getValue().matches("[0-9]+")) + if(c.getPredicate().equals("equal")) equalsConditions.add(c); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java 2012-07-13 08:39:06 UTC (rev 3787) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sem/drs/DRS.java 2012-07-13 09:50:38 UTC (rev 3788) @@ -312,7 +312,7 @@ next = true; } m_DiscourseReferents.remove(dr2); - if (!isInUpperUniverse) { + if (!isInUpperUniverse && !dr2.m_Referent.matches("[0-9]+")) { m_DiscourseReferents.add(new DiscourseReferent(dr2.m_Referent,marked,nonex)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 08:39:15
|
Revision: 3787 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3787&view=rev Author: lorenz_b Date: 2012-07-13 08:39:06 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Updated JENA dependencies. Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2012-07-13 08:19:48 UTC (rev 3786) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2012-07-13 08:39:06 UTC (rev 3787) @@ -10,6 +10,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -61,7 +62,6 @@ import com.hp.hpl.jena.sparql.vocabulary.FOAF; import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; -import com.ibm.icu.util.Calendar; public class Evaluation{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-13 08:19:59
|
Revision: 3786 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3786&view=rev Author: lorenz_b Date: 2012-07-13 08:19:48 +0000 (Fri, 13 Jul 2012) Log Message: ----------- Updated JENA dependencies. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java trunk/components-core/src/main/java/org/dllearner/utilities/Files.java trunk/pom.xml Modified: trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/components-core/src/main/java/org/dllearner/utilities/CSVFileToArray.java 2012-07-13 08:19:48 UTC (rev 3786) @@ -25,8 +25,8 @@ import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; +import java.util.StringTokenizer; -import com.ibm.icu.util.StringTokenizer; /** * @author Jens Lehmann Modified: trunk/components-core/src/main/java/org/dllearner/utilities/Files.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/Files.java 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/components-core/src/main/java/org/dllearner/utilities/Files.java 2012-07-13 08:19:48 UTC (rev 3786) @@ -34,8 +34,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.StringTokenizer; -import com.ibm.icu.util.StringTokenizer; /** * @author Jens Lehmann Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-07-12 13:46:06 UTC (rev 3785) +++ trunk/pom.xml 2012-07-13 08:19:48 UTC (rev 3786) @@ -180,7 +180,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-core</artifactId> - <version>2.7.1-incubating-SNAPSHOT</version> + <version>2.7.2</version> </dependency> <!--SwingX is in central --> <dependency> @@ -240,7 +240,7 @@ <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-arq</artifactId> - <version>2.9.1-incubating-SNAPSHOT</version> + <version>2.9.2</version> </dependency> <!--Junits --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-07-12 13:46:17
|
Revision: 3785 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3785&view=rev Author: lorenz_b Date: 2012-07-12 13:46:06 +0000 (Thu, 12 Jul 2012) Log Message: ----------- Fixed NPE in HAVING constructs when copying Query object. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-07-12 12:13:02 UTC (rev 3784) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-07-12 13:46:06 UTC (rev 3785) @@ -112,7 +112,7 @@ } } this.filter = filters; - this.having = having; + this.having = query.having; this.unions = query.unions; // TODO copy unions this.limit = query.getLimit(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-07-12 12:13:13
|
Revision: 3784 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3784&view=rev Author: christinaunger Date: 2012-07-12 12:13:02 +0000 (Thu, 12 Jul 2012) Log Message: ----------- [tbsl] if COUNT then GROUP BY + HAVING. also removed number replacement. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-07-12 11:34:09 UTC (rev 3783) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/converter/DRS2SPARQL_Converter.java 2012-07-12 12:13:02 UTC (rev 3784) @@ -264,7 +264,7 @@ if (!predicate.contains(":")) prop.setIsVariable(true); boolean literal = false; - if (simple.getArguments().size() > 1 && simple.getArguments().get(1).getValue().matches("\\d+")) { + if (simple.getArguments().size() > 1 && (simple.getArguments().get(1).getValue().startsWith("\'") || simple.getArguments().get(1).getValue().matches("[0-9]+"))) { literal = true; } @@ -273,11 +273,7 @@ if (simple.getArguments().get(1).getValue().matches("[0-9]+")) { String fresh = "v"+createFresh(); out.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, fresh)); - out.addFilter(new SPARQL_Filter( - new SPARQL_Pair( - new SPARQL_Term(fresh,false), - new SPARQL_Term(simple.getArguments().get(1).getValue(),literal), - SPARQL_PairType.EQ))); + out.addHaving(new SPARQL_Having("?"+fresh + " = " + simple.getArguments().get(1).getValue())); } else { out.addSelTerm(new SPARQL_Term(simple.getArguments().get(0).getValue(), SPARQL_Aggregate.COUNT, simple.getArguments().get(1).getValue())); } @@ -326,7 +322,7 @@ } else if (predicate.equals("equal")) { out.addFilter(new SPARQL_Filter( new SPARQL_Pair( - new SPARQL_Term(simple.getArguments().get(0).getValue(),true), + new SPARQL_Term(simple.getArguments().get(0).getValue(),false), new SPARQL_Term(simple.getArguments().get(1).getValue(),literal), SPARQL_PairType.EQ))); return out; @@ -335,14 +331,14 @@ out.addFilter(new SPARQL_Filter( new SPARQL_Pair( new SPARQL_Term(simple.getArguments().get(0).getValue(),false), - new SPARQL_Term("'^"+simple.getArguments().get(1).getValue()+"'",true), + new SPARQL_Term("'^"+simple.getArguments().get(1).getValue()+"'",false), SPARQL_PairType.REGEX))); } else if (predicate.equals("regex")) { out.addFilter(new SPARQL_Filter( new SPARQL_Pair( new SPARQL_Term(simple.getArguments().get(0).getValue(),false), - new SPARQL_Term(simple.getArguments().get(1).getValue().replace("_","").trim(),true), + new SPARQL_Term(simple.getArguments().get(1).getValue().replace("_","").trim(),false), SPARQL_PairType.REGEX))); } else { @@ -403,10 +399,13 @@ } public void redundantEqualRenaming(DRS drs) { - + Set<Simple_DRS_Condition> equalsConditions = new HashSet<Simple_DRS_Condition>(); for (Simple_DRS_Condition c : drs.getAllSimpleConditions()) { - if(c.getPredicate().equals("equal")) equalsConditions.add(c); + if(c.getPredicate().equals("equal") + && !c.getArguments().get(0).getValue().matches("[0-9]+") + && !c.getArguments().get(1).getValue().matches("[0-9]+")) + equalsConditions.add(c); } DiscourseReferent firstArg; @@ -426,7 +425,7 @@ secondIsInt = secondArg.getValue().matches("(\\?)?[0..9]+"); drs.removeCondition(c); - if (firstIsURI || firstIsInt) { + if (firstIsURI) { // firstIsURI || firstIsInt drs.replaceEqualRef(secondArg, firstArg, true); for (Slot s : slots) { if (s.getAnchor().equals(secondArg.getValue())) @@ -436,7 +435,7 @@ s.getWords().add(firstArg.getValue()); } } - } else if (secondIsURI || secondIsInt) { + } else if (secondIsURI) { // secondIsURI || secondIsInt drs.replaceEqualRef(firstArg, secondArg, true); for (Slot s : slots) { if (s.getAnchor().equals(firstArg.getValue())) Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-07-12 11:34:09 UTC (rev 3783) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/Query.java 2012-07-12 12:13:02 UTC (rev 3784) @@ -14,6 +14,7 @@ Set<SPARQL_Triple> conditions; Set<SPARQL_Term> orderBy; Set<SPARQL_Filter> filter; + Set<SPARQL_Having> having; Set<SPARQL_Union> unions; SPARQL_QueryType qt = SPARQL_QueryType.SELECT; @@ -28,6 +29,7 @@ conditions = new HashSet<SPARQL_Triple>(); orderBy = new HashSet<SPARQL_Term>(); filter = new HashSet<SPARQL_Filter>(); + having = new HashSet<SPARQL_Having>(); unions = new HashSet<SPARQL_Union>(); } @@ -38,6 +40,7 @@ this.prefixes = prefixes; this.conditions = conditions; filter = new HashSet<SPARQL_Filter>(); + having = new HashSet<SPARQL_Having>(); unions = new HashSet<SPARQL_Union>(); } @@ -50,6 +53,8 @@ this.orderBy = orderBy; this.limit = limit; this.offset = offset; + filter = new HashSet<SPARQL_Filter>(); + having = new HashSet<SPARQL_Having>(); unions = new HashSet<SPARQL_Union>(); } @@ -107,6 +112,7 @@ } } this.filter = filters; + this.having = having; this.unions = query.unions; // TODO copy unions this.limit = query.getLimit(); @@ -195,6 +201,10 @@ if(groupBy != null){ retVal += "GROUP BY " + groupBy + "\n"; } + + if (!having.isEmpty()) { + for (SPARQL_Having h : having) retVal += h.toString() + "\n"; + } if (orderBy != null && !orderBy.isEmpty()) { @@ -275,6 +285,10 @@ this.filter.add(f); } + public void addHaving(SPARQL_Having h) + { + this.having.add(h); + } public Set<SPARQL_Term> getOrderBy() { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java 2012-07-12 11:34:09 UTC (rev 3783) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/sparql/SPARQL_Term.java 2012-07-12 12:13:02 UTC (rev 3784) @@ -79,7 +79,7 @@ public boolean isString() { - return name.startsWith("'") || name.matches("\\d+"); + return name.startsWith("'"); } public void setIsURI(boolean isURI){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |