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: <seb...@us...> - 2012-02-22 17:57:05
|
Revision: 3582 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3582&view=rev Author: sebastianwtr Date: 2012-02-22 17:56:55 +0000 (Wed, 22 Feb 2012) Log Message: ----------- [tbsl exploration] start new implementation Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/testClass_new.java Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-02-22 17:56:55 UTC (rev 3582) @@ -0,0 +1,31 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +public class Hypothesis { +private String variable; +private String uri; +private float rank; +public String getUri() { + return uri; +} +public void setUri(String uri) { + this.uri = uri; +} +public String getVariable() { + return variable; +} +public void setVariable(String variable) { + this.variable = variable; +} +public float getRank() { + return rank; +} +public void setRank(float rank) { + this.rank = rank; +} + +public Hypothesis(String variable, String uri, float rank){ + setRank(rank); + setVariable(variable); + setUri(uri); +} +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-02-14 15:44:21 UTC (rev 3581) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-02-22 17:56:55 UTC (rev 3582) @@ -2204,16 +2204,7 @@ } private String createAnswer(String string){ - - /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); - Matcher m = p.matcher (string); - String result=""; - while (m.find()) { - if(m.group(1)!=null) - result = result+" "+ m.group(1); - } - */ Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); Matcher m = p.matcher (string); @@ -2235,18 +2226,7 @@ } private ArrayList<String> createAnswerArray(String string){ - //<td>Klaus Wowereit</td> - - //get with regex all between <td> </td> - - /*Pattern p = Pattern.compile (".*<td>(.*)</td>.*"); - Matcher m = p.matcher (string); - ArrayList<String> result=new ArrayList<String>(); - while (m.find()) { - if(m.group(1)!=null) - result.add(m.group(1)); - }*/ Pattern p = Pattern.compile (".*\\<td\\>(.*)\\</td\\>.*"); string = string.replace("<table class=\"sparql\" border=\"1\">", "").replace("<tr>","").replace("</tr>", "").replace("</table>", ""); Matcher m = p.matcher (string); @@ -2309,14 +2289,8 @@ return query; } - - - - } - - /* * Backup original Iteration function * Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-02-22 17:56:55 UTC (rev 3582) @@ -0,0 +1,87 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.util.ArrayList; + +public class Template { + + private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); + private ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); + private String selectTerm; + private String having; + private String filter; + private String OrderBy; + private String limit; + + public String getHaving() { + return having; + } + public void setHaving(String having) { + this.having = having; + } + public String getFilter() { + return filter; + } + public void setFilter(String filter) { + this.filter = filter; + } + public String getOrderBy() { + return OrderBy; + } + public void setOrderBy(String orderBy) { + OrderBy = orderBy; + } + public String getLimit() { + return limit; + } + public void setLimit(String limit) { + this.limit = limit; + } + + public String getSelectTerm() { + return selectTerm; + } + public void setSelectTerm(String selectTerm) { + this.selectTerm = selectTerm; + } + + + public Template(ArrayList<ArrayList<String>>condition_new, String having_new, String filter_new, String SelectTerm_new, String OrderBy_new, String limit_new){ + setCondition(condition_new); + setHaving(having_new); + setFilter(filter_new); + setOrderBy(OrderBy_new); + setLimit(limit_new); + setSelectTerm(SelectTerm_new); + } + public ArrayList<ArrayList<String>> getCondition() { + return condition; + } + public void setCondition(ArrayList<ArrayList<String>> condition) { + this.condition = condition; + } + public ArrayList<ArrayList<Hypothesis>> getHypotesen() { + return hypotesen; + } + public void setHypotesen(ArrayList<ArrayList<Hypothesis>> hypotesen) { + this.hypotesen = hypotesen; + } + + public void addHypothese(ArrayList<Hypothesis> ht){ + this.hypotesen.add(ht); + } + + + public void printAll(){ + System.out.println("###### Template ######"); + System.out.println("condition: "+condition); + System.out.println("hypotesen: "+hypotesen); + System.out.println("selectTerm: "+selectTerm); + System.out.println("having: "+having); + System.out.println("filter: "+filter); + System.out.println("OrderBy: "+OrderBy); + System.out.println("limit: "+limit); + System.out.println("###### Template printed ######\n"); + } + +} + Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-02-22 17:56:55 UTC (rev 3582) @@ -0,0 +1,121 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.net.MalformedURLException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Set; + +import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; +import org.dllearner.algorithm.tbsl.sparql.Path; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Filter; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Having; +import org.dllearner.algorithm.tbsl.sparql.SPARQL_Term; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; + +public class TemplateBuilder { + + static BasicTemplator btemplator; + + +public TemplateBuilder() throws MalformedURLException, ClassNotFoundException, SQLException{ + + TemplateBuilder.btemplator = new BasicTemplator(); + //btemplator.UNTAGGED_INPUT = false; + //Object_new.myindex = new mySQLDictionary(); + } + + + public ArrayList<Template> createTemplates(String question){ + ArrayList<Template> resultArrayList = new ArrayList<Template>(); + Set<BasicQueryTemplate> querytemps = btemplator.buildBasicQueries(question); + for (BasicQueryTemplate bqt : querytemps) { + ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); + ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); + String selectTerm = ""; + String having= ""; + String filter= ""; + String OrderBy= ""; + String limit= ""; + String condition_String = ""; + + boolean addTemplate=true; + try{ + for(SPARQL_Term terms :bqt.getSelTerms()) selectTerm=selectTerm+(terms.toString())+" "; + } + catch (Exception e){ + selectTerm=""; + addTemplate=false; + } + + ArrayList<String> temp_array = new ArrayList<String>(); + try{ + for(Path conditions1: bqt.getConditions()) condition_String=condition_String+(conditions1.toString())+"."; + for(Path conditions1: bqt.getConditions()) { + temp_array.clear(); + String[] tmp_array = conditions1.toString().split(" -- "); + for(String s: tmp_array){ + temp_array.add(s); + } + condition.add(temp_array); + } + + } + catch (Exception e){ + condition_String=""; + addTemplate=false; + } + + try{ + for(SPARQL_Filter tmp : bqt.getFilters()) filter=filter+tmp+" "; + } + catch(Exception e){ + filter=""; + addTemplate=false; + } + try{ + for(SPARQL_Having tmp : bqt.getHavings()) having=having+tmp+" "; + } + catch(Exception e){ + having=""; + addTemplate=false; + } + + //if there is no order by, replace with "" + OrderBy="ORDER BY "; + try{ + for(SPARQL_Term tmp : bqt.getOrderBy()) { + System.out.println("Yeah"); + OrderBy=OrderBy+tmp+" "; + } + if((bqt.getOrderBy()).size()==0)OrderBy=""; + } + catch(Exception e){ + OrderBy=""; + addTemplate=false; + } + + + try{ + limit="LIMIT "+bqt.getLimit(); + + if(bqt.getLimit()==0)limit=""; + } + catch(Exception e){ + limit=""; + addTemplate=false; + } + + Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit); + + //TODO: Add Hypothesis + //TODO: Take Template like it is and change Condition + + + resultArrayList.add(template); + } + for(Template temp : resultArrayList){ + temp.printAll(); + } + return resultArrayList; + } +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/testClass_new.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/testClass_new.java 2012-02-22 17:56:55 UTC (rev 3582) @@ -0,0 +1,21 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.net.MalformedURLException; +import java.sql.SQLException; + +public class testClass_new { + + /** + * @param args + * @throws SQLException + * @throws ClassNotFoundException + * @throws MalformedURLException + */ + public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, SQLException { + // TODO Auto-generated method stub + TemplateBuilder testobject = new TemplateBuilder(); + String question = "Which books are written by Daniele Steel?"; + testobject.createTemplates(question); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-14 15:44:32
|
Revision: 3581 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3581&view=rev Author: lorenz_b Date: 2012-02-14 15:44:21 +0000 (Tue, 14 Feb 2012) Log Message: ----------- Somes updates needed because of new SOLR BOA index. Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-02-14 10:14:06 UTC (rev 3580) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/learning/SPARQLTemplateBasedLearner.java 2012-02-14 15:44:21 UTC (rev 3581) @@ -16,6 +16,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.log4j.Logger; @@ -193,7 +194,7 @@ String boaPatternIndexUrl = options.fetch("solr.boa.properties.url"); String boaPatternIndexSearchField = options.fetch("solr.boa.properties.searchfield"); - SolrSearch patternBasedPropertyIndex = new SolrSearch(boaPatternIndexUrl, boaPatternIndexSearchField, "nlr"); + SolrSearch patternBasedPropertyIndex = new SolrSearch(boaPatternIndexUrl, boaPatternIndexSearchField, "nlr-no-var"); //first BOA pattern then label based // property_index = new HierarchicalSolrSearch(patternBasedPropertyIndex, labelBasedPropertyIndex); @@ -641,18 +642,37 @@ } private Set<WeightedQuery> getWeightedSPARQLQueries(Set<Template> templates){ + logger.info("Generating SPARQL query candidates..."); + Map<Slot, Set<Allocation>> slot2Allocations2 = 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; + } + } + }); + + Map<Slot, Set<Allocation>> slot2Allocations = new HashMap<Slot, Set<Allocation>>(); Set<WeightedQuery> allQueries = new TreeSet<WeightedQuery>(); Set<Allocation> allocations; + for(Template t : templates){ + logger.info("Processing template:\n" + t.toString()); allocations = new TreeSet<Allocation>(); for(Slot slot : t.getSlots()){ - allocations = computeAllocations(slot, 50); - + allocations = slot2Allocations2.get(slot); + if(allocations == null){ + allocations = computeAllocations(slot, 20); + slot2Allocations2.put(slot, allocations); + } slot2Allocations.put(slot, allocations); //for tests add the property URI with http://dbpedia.org/property/ namespace @@ -702,14 +722,14 @@ queries.addAll(tmp); tmp.clear(); } - + for(Slot slot : sortedSlots){ - if(!slot2Allocations.get(slot).isEmpty()){System.out.println(slot2Allocations.get(slot)); + if(!slot2Allocations.get(slot).isEmpty()){ for(Allocation a : slot2Allocations.get(slot)){ 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(); @@ -779,7 +799,7 @@ } } } - } + }*/ if(!drop){ @@ -811,6 +831,7 @@ } template2Queries.put(t, qList); } + logger.info("...done in "); return allQueries; } @@ -859,7 +880,6 @@ // } // } - System.out.println(word + "->" + rs); for(SolrQueryResultItem item : rs.getItems()){ double similarity = Similarity.getSimilarity(word, item.getLabel()); //get the labels of the redirects and compute the highest similarity @@ -885,9 +905,11 @@ } private Set<Allocation> computeAllocations(Slot slot, int limit){ + logger.info("Computing allocations for " + slot); SortedSet<Allocation> allocations = computeAllocations(slot); if(allocations.isEmpty()){ + logger.info("...done."); return allocations; } @@ -906,7 +928,7 @@ } } }); - + logger.info("...done."); return new TreeSet<Allocation>(l.subList(0, Math.min(limit, allocations.size()))); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-14 10:14:17
|
Revision: 3580 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3580&view=rev Author: lorenz_b Date: 2012-02-14 10:14:06 +0000 (Tue, 14 Feb 2012) Log Message: ----------- Updated SOLR URI. Modified Paths: -------------- trunk/components-ext/src/main/resources/tbsl/tbsl.properties Modified: trunk/components-ext/src/main/resources/tbsl/tbsl.properties =================================================================== --- trunk/components-ext/src/main/resources/tbsl/tbsl.properties 2012-02-09 16:15:27 UTC (rev 3579) +++ trunk/components-ext/src/main/resources/tbsl/tbsl.properties 2012-02-14 10:14:06 UTC (rev 3580) @@ -1,4 +1,4 @@ -solr.server.url = http://139.18.2.173:8080/apache-solr-3.3.0 +solr.server.url = http://139.18.2.173:8080/solr solr.classes.url = ${solr.server.url}/dbpedia_classes solr.classes.searchfield = label solr.yago.classes.url = ${solr.server.url}/yago_classes @@ -8,7 +8,7 @@ solr.properties.url = ${solr.server.url}/dbpedia_properties solr.properties.searchfield = label solr.boa.properties.url = ${solr.server.url}/boa_pattern -solr.boa.properties.searchfield = nlr +solr.boa.properties.searchfield = nlr-no-var solr.query.limit = 20 sparql.endpoint.url = http://live.dbpedia.org/sparql This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-02-09 16:15:38
|
Revision: 3579 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3579&view=rev Author: sebastianwtr Date: 2012-02-09 16:15:27 +0000 (Thu, 09 Feb 2012) Log Message: ----------- [tbsl-exploration] some minor changes Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/GetRessourcePropertys.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -20,7 +20,8 @@ //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; String Prefix="http://dbpedia.org/sparql"; - //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; + //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; + //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; public HashMap<String,String> getPropertys(String element, String side, int timeToTimeoutOnServer) throws IOException{ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -58,7 +58,7 @@ static int explorationdepthwordnet=2; static int iterationdepth =0; static int numberofanswers=1; - static double LevenstheinMin = 0.9; + static double LevenstheinMin = 0.8; static WordNet wordnet; BasicTemplator btemplator; Templator templator; @@ -71,7 +71,8 @@ //change here and in getRessourcePropertys //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; String Prefix="http://dbpedia.org/sparql"; - //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8892/sparql"; + //String Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //String Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; //Konstruktor @@ -650,11 +651,20 @@ // TODO Auto-generated catch block e.printStackTrace(); }*/ + System.out.println(property_to_compare_with + " : "+property_to_compare_with_uri +" : "+uri_isA_Resource); if(fall.contains("WORDNET")) new_queries=doWordnet(query,property_to_compare_with,property_to_compare_with_uri,list_of_properties); if(fall.contains("LEVENSTHEIN")) new_queries=doLevensthein(query,property_to_compare_with_uri,property_to_compare_with_uri,list_of_properties); - + /* BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); + String line; + + try { + line = in1.readLine(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }*/ return new_queries; } @@ -703,6 +713,9 @@ //System.out.println("URI from Resource "+ resource +": "+getUriFromIndex(resource.toLowerCase(),0)); System.out.println("URI from Resource "+ resource +": "+queryObject.getHashValue(resource.toLowerCase())); + HashMap<String, String> bla = queryObject.getHashMap(); + System.out.println("INhalt Hasmap QueryObject:"); + for (String z: bla.keySet()) System.out.println(z); //gets Propertys left or right from the resource! try { @@ -756,7 +769,7 @@ double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); //check if nld is greater than Levensthein - if(nld>=LevenstheinMin){ + if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ //if its so, replace old uri with the new one String querynew=query; //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); @@ -913,19 +926,31 @@ ArrayList<String> semantics=new ArrayList<String>(); ArrayList<String> tmp_semantics=new ArrayList<String>(); ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); - semantics.add(property); + if(property.contains("_")){ + String[] fix = property.split("_"); + //here add also lemmatiser + for(String s: fix) semantics.add(s); + } + else semantics.add(property); System.out.println("Semantics: "+ semantics); - //first check, if there is a singular form in the wordnet dictionary.. eg children -> child - String _temp_=myindex.getWordnetHelp(property); - if(_temp_==null){ - tmp_semantics=semantics; + for(String s: semantics){ + //first check, if there is a singular form in the wordnet dictionary.. eg children -> child + //String _temp_=myindex.getWordnetHelp(property); + String _temp_=myindex.getWordnetHelp(s); + if(_temp_!=null){ + //tmp_semantics=semantics; + tmp_semantics.add(_temp_); + tmp_semantics.add(s); + } + else tmp_semantics.add(s); + /* + else{ + semantics.clear(); + semantics.add(_temp_); + tmp_semantics=semantics; + }*/ } - else{ - semantics.clear(); - semantics.add(_temp_); - tmp_semantics=semantics; - } System.out.println("tmp_semantics: "+ tmp_semantics); Boolean goOnAfterWordnet = true; @@ -965,11 +990,12 @@ key=key.replace("@en",""); for(String b : semantics){ - if(key.contains(b.toLowerCase())){ + if(key.contains(b.toLowerCase())||key.contains(lemmatiser.stem(b.toLowerCase()))||b.toLowerCase().contains(lemmatiser.stem(key))){ if(!result_SemanticsMatchProperties.contains(key)){ result_SemanticsMatchProperties.add(key); String query_tmp=query; //String replacement = getUriFromIndex(property_to_compare_with.toLowerCase(),1); + System.out.println("URI of property: "+uri_of_property); String replacement = uri_of_property; if(!query_tmp.contains(replacement)){ replacement=replacement.replace("ontology", "property"); @@ -1765,6 +1791,21 @@ } else{ result="NONE"; + String tmp11=originalString; + String hotfix ="http://dbpedia.org/resource/"+tmp11; + if(tmp11.contains("_")){ + String[] newarraytmp=tmp11.split("_"); + String tmpneu=""; + for(String s :newarraytmp){ + tmpneu+= "_"+ Character.toUpperCase(s.charAt(0)) + s.substring(1); + } + tmpneu=tmpneu.replaceFirst("_", ""); + hotfix ="http://dbpedia.org/resource/"+tmpneu; + hotfix=hotfix.replace("/__", "/"); + System.out.println("Hotfix: "+hotfix); + } + result=hotfix; + } } catch(Exception e){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/queryInformation.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -39,6 +39,8 @@ public String getHashValue(String key) { key=key.toLowerCase(); + key=key.replace(" ", ""); + key=key.replace("_", " "); String result ="NONE"; try{ result=this.hashMap.get(key); @@ -51,6 +53,9 @@ } public void setHashValue(String key, String value) { + key=key.replace(" ", ""); + key=key.replace("_", " "); + value=value.replace("__", ""); this.hashMap.put(key.toLowerCase(), value); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-02-08 13:48:02 UTC (rev 3578) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-02-09 16:15:27 UTC (rev 3579) @@ -165,17 +165,17 @@ //queryInformation tmpquery; //only question, which are not yago files if(s.isYago()==true)yago_querys=yago_querys+1; - if(s.isYago()==false){ + //if(s.isYago()==false){ queryInformation tmpquery=sparql.create_Sparql_query(s); if(!tmpquery.getResult().isEmpty()) { list_of_resultstructs.add(sparql.create_Sparql_query(s)); anzahl_query_with_answers=anzahl_query_with_answers+1; } - } + //} } - /* - //Print to Console + + /* //Print to Console System.out.println("\n#############\n Result:"); for(queryInformation s : list_of_resultstructs){ System.out.println(s.getResult()); @@ -221,9 +221,15 @@ queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); result= sparql.create_Sparql_query(newQuery); ArrayList<String> ergebnis = result.getResult(); + //get eacht result only once! + Set<String> setString = new HashSet<String>(); for(String i: ergebnis){ - System.out.println(i); + setString.add(i); + //System.out.println(i); } + for(String z: setString){ + System.out.println(z); + } long endTime= System.currentTimeMillis(); System.out.println("\n The complete answering of the Question took "+(endTime-startTime)+" ms"); } @@ -311,7 +317,13 @@ xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; } tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; - for(String i : s.getResult()){ + + //to get all answers only once! + Set<String> setString = new HashSet<String>(); + for(String z: s.getResult()){ + setString.add(z); + } + for(String i : setString){ String input=""; if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-08 13:48:13
|
Revision: 3578 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3578&view=rev Author: lorenz_b Date: 2012-02-08 13:48:02 +0000 (Wed, 08 Feb 2012) Log Message: ----------- Fixed bug. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-08 13:23:08 UTC (rev 3577) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-08 13:48:02 UTC (rev 3578) @@ -115,7 +115,9 @@ this.ontology = ontology; this.incoherentOntology = getOntologyWithoutAnnotations(ontology); - File diffFile = new File(new File(ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toURI()).getParent() + "/" + DIFF_ONTOLOGY_NAME); + new File("log").mkdir(); + + File diffFile = new File("log/" + DIFF_ONTOLOGY_NAME); try { if(diffFile.exists()){ diffOntology = manager.loadOntologyFromOntologyDocument(diffFile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-08 13:23:18
|
Revision: 3577 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3577&view=rev Author: lorenz_b Date: 2012-02-08 13:23:08 +0000 (Wed, 08 Feb 2012) Log Message: ----------- Reading ontologies from BZIP2. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-08 11:49:16 UTC (rev 3576) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-08 13:23:08 UTC (rev 3577) @@ -1,7 +1,9 @@ package org.dllearner.utilities; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -682,8 +684,11 @@ boolean computeParallel = Boolean.valueOf(args[3]); System.out.println("Loading ontology..."); - File file = new File(filename); - OWLOntology schema = man.loadOntologyFromOntologyDocument(file); + InputStream is = new BufferedInputStream(new FileInputStream(filename)); + if(args[0].endsWith("bz2")){ + is = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + } + OWLOntology schema = man.loadOntologyFromOntologyDocument(is); man.removeAxioms(schema, schema.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY)); // OWLOntology cleaned = man.createOntology(IRI.create("http://dbpedia_cleaned.owl")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-08 11:49:26
|
Revision: 3576 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3576&view=rev Author: lorenz_b Date: 2012-02-08 11:49:16 +0000 (Wed, 08 Feb 2012) Log Message: ----------- Remove only axioms not contained in the original DBpedia ontology. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-07 21:43:20 UTC (rev 3575) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-08 11:49:16 UTC (rev 3576) @@ -4,6 +4,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collections; @@ -20,6 +24,8 @@ import openlink.util.MD5; +import org.apache.commons.compress.compressors.CompressorException; +import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.mindswap.pellet.RBox; import org.semanticweb.HermiT.Configuration; import org.semanticweb.HermiT.Reasoner; @@ -39,6 +45,7 @@ import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; import org.semanticweb.owlapi.model.RemoveAxiom; +import org.semanticweb.owlapi.owllink.builtin.requests.LoadOntologies; import org.semanticweb.owlapi.reasoner.IllegalConfigurationException; import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; @@ -83,12 +90,15 @@ //whether to debug classes and properties in parallel private boolean computeParallel = false; + private OWLOntology dbpediaOntology; + public JustificationBasedCoherentOntologyExtractor() { try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } + dbpediaOntology = loadDBpediaOntology(); } static {PelletExplanation.setup();} @@ -185,19 +195,14 @@ } logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - while(!unsatClasses.isEmpty()){ - //get frequency for each axiom - Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); + if(computeParallel){ + cnt += unsatPropCnt; + } + + while(cnt >= 0){ + //we remove the most appropriate axiom from the ontology + removeAppropriateAxiom(); - //get a sorted list of entries with the highest axiom count first - List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); - for(Entry<OWLAxiom, Integer> entry : sortedEntries){ -// System.out.println(entry.getKey() + ":" + entry.getValue()); - } - //we remove the most frequent axiom from the ontology - OWLAxiom toRemove = sortedEntries.get(0).getKey(); - removeAxiom(toRemove); - //recompute the unsatisfiable classes logger.info("Reclassifying..."); startTime = System.currentTimeMillis(); @@ -229,6 +234,9 @@ save("log/dbpedia_" + cnt + "cls" + unsatPropCnt + "prop.owl"); cnt = rootCnt + derivedCnt; unsatPropCnt = unsatObjectProperties.size(); + if(computeParallel){ + cnt += unsatPropCnt; + } } //recompute explanations if necessary @@ -251,15 +259,9 @@ entity2ModuleMap.putAll(extractModules(unsatObjectProperties)); while(!unsatObjectProperties.isEmpty()){ - //get frequency for each axiom - Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); + //we remove the most appropriate axiom from the ontology + removeAppropriateAxiom(); - //get a sorted list of entries with the highest axiom count first - List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); - //we remove the most frequent axiom from the ontology - OWLAxiom toRemove = sortedEntries.get(0).getKey(); - removeAxiom(toRemove); - //recompute the unsatisfiable classes logger.info("Reclassifying..."); startTime = System.currentTimeMillis(); @@ -324,18 +326,9 @@ logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); while(!unsatClasses.isEmpty()){ - //get frequency for each axiom - Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); + //we remove the most appropriate axiom from the ontology + removeAppropriateAxiom(); - //get a sorted list of entries with the highest axiom count first - List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); - for(Entry<OWLAxiom, Integer> entry : sortedEntries){ -// System.out.println(entry.getKey() + ":" + entry.getValue()); - } - //we remove the most frequent axiom from the ontology - OWLAxiom toRemove = sortedEntries.get(0).getKey(); - removeAxiom(toRemove); - //recompute the unsatisfiable classes logger.info("Reclassifying..."); startTime = System.currentTimeMillis(); @@ -375,13 +368,24 @@ return getOntologyWithAnnotations(incoherentOntology); } - private void removeAxiom(OWLAxiom axiom){ - logger.info("Removing axiom " + axiom + "."); - manager.removeAxiom(incoherentOntology, axiom); - manager.addAxiom(diffOntology, axiom); - manager.applyChange(new RemoveAxiom(incoherentOntology, axiom)); - removeFromExplanations(entity2Explanations, axiom); - removeFromModules(axiom); + private void removeAppropriateAxiom(){ + //get frequency for each axiom + Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); + //get a sorted list of entries with the highest axiom count first + List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); + //we remove the most frequent axiom from the ontology which is not contained in the original DBpedia ontology + for(Entry<OWLAxiom, Integer> e : sortedEntries){ + OWLAxiom axiom = e.getKey(); + if(!dbpediaOntology.containsAxiomIgnoreAnnotations(axiom)){ + logger.info("Removing axiom " + axiom + "."); + manager.removeAxiom(incoherentOntology, axiom); + manager.addAxiom(diffOntology, axiom); + manager.applyChange(new RemoveAxiom(incoherentOntology, axiom)); + removeFromExplanations(entity2Explanations, axiom); + removeFromModules(axiom); + return; + } + } } private void save(String fileName){ @@ -603,6 +607,28 @@ return module; } + private OWLOntology loadDBpediaOntology() { + long startTime = System.currentTimeMillis(); + logger.info("Loading DBpedia reference ontology..."); + OWLOntology ontology = null; + try { + URL dbpediaURL = new URL("http://downloads.dbpedia.org/3.7/dbpedia_3.7.owl.bz2"); + InputStream is = dbpediaURL.openStream(); + is = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(is); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (CompressorException e) { + e.printStackTrace(); + } + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); + return ontology; + } + // private Map<OWLClass, OWLOntology> extractModules(Set<OWLClass> classes){ // Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); // for(OWLClass cls : classes){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-07 21:43:27
|
Revision: 3575 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3575&view=rev Author: lorenz_b Date: 2012-02-07 21:43:20 +0000 (Tue, 07 Feb 2012) Log Message: ----------- Added method to check if axiom is already entailed by DBpedia ontology. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-02-07 09:53:33 UTC (rev 3574) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-02-07 21:43:20 UTC (rev 3575) @@ -12,6 +12,7 @@ import java.io.PrintWriter; import java.io.StringReader; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; @@ -30,6 +31,7 @@ import java.util.TreeSet; import java.util.prefs.Preferences; +import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; @@ -65,7 +67,13 @@ import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; +import org.semanticweb.owlapi.reasoner.ClassExpressionNotInProfileException; +import org.semanticweb.owlapi.reasoner.FreshEntitiesException; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import org.semanticweb.owlapi.reasoner.InferenceType; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; +import org.semanticweb.owlapi.reasoner.TimeOutException; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; @@ -109,11 +117,18 @@ private OWLDataFactory factory = new OWLDataFactoryImpl(); + private OWLOntology dbpediaOntology; + private OWLReasoner dbpediaReasoner; + private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + static {PelletExplanation.setup();} public SPARQLSampleDebugging(SparqlEndpoint endpoint) { this.endpoint = endpoint; initDBConnection(); + dbpediaOntology = loadDBpediaOntology(); + dbpediaReasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbpediaOntology); + dbpediaReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); } private void initDBConnection() { @@ -302,6 +317,30 @@ return ontology; } + private OWLOntology loadDBpediaOntology() { + long startTime = System.currentTimeMillis(); + logger.info("Loading DBpedia reference ontology..."); + OWLOntology ontology = null; + try { + URL dbpediaURL = new URL("http://downloads.dbpedia.org/3.7/dbpedia_3.7.owl.bz2"); + InputStream is = dbpediaURL.openStream(); + is = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(is); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (CompressorException e) { + e.printStackTrace(); + } + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); + return ontology; + } + + + private OWLOntology convert(Model model) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); model.write(baos, "N-TRIPLE"); @@ -470,16 +509,13 @@ explanations.addAll(computeInconsistencyExplanationsByIrreflexivityPattern(reference, model)); explanations.addAll(computeInconsistencyExplanationsByFunctionalityPattern(reference, model)); logger.info("Found " + explanations.size() + " explanations."); - for(Set<OWLAxiom> exp : explanations){ - logger.info(exp + "\n"); - } Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); try { FileWriter out = new FileWriter( "log/justifications.txt" ); renderer.startRendering(out ); for(Set<OWLAxiom> explanation : explanations){ - logger.info(explanation); + logger.info(explanation + "\n"); out.flush(); try { renderer.render( Collections.singleton(explanation) ); @@ -702,6 +738,42 @@ return properties; } + private boolean isLearnedAxiom(OWLAxiom axiom){ + return !dbpediaReasoner.isEntailed(axiom); + } + + private boolean containsUnsatisfiableObjectProperty(Set<OWLAxiom> justification){ + boolean value = false; + + OWLReasoner reasoner = null; + try { + OWLOntology ontology = manager.createOntology(justification); + manager.removeAxioms(ontology, ontology.getABoxAxioms(true)); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); + for(OWLObjectProperty p : ontology.getObjectPropertiesInSignature()){ + boolean satisfiable = reasoner.isSatisfiable(factory.getOWLObjectExactCardinality(1, p)); + if(!satisfiable){ + value = true; + break; + } + } + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (ClassExpressionNotInProfileException e) { + e.printStackTrace(); + } catch (FreshEntitiesException e) { + e.printStackTrace(); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + reasoner.dispose(); + return value; + } + public void removeAxiomsWithNamespace(Set<String> namespaces){ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-07 09:53:39
|
Revision: 3574 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3574&view=rev Author: lorenz_b Date: 2012-02-07 09:53:33 +0000 (Tue, 07 Feb 2012) Log Message: ----------- Continued option to debug classes and properties in one step or sequentially. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-07 09:48:07 UTC (rev 3573) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-07 09:53:33 UTC (rev 3574) @@ -129,7 +129,9 @@ //compute the unsatisfiable object properties and their corresponding modules unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); logger.info("Found unsatisfiable object properties: " + unsatObjectProperties.size()); - entity2ModuleMap.putAll(extractModules(unsatObjectProperties)); + if(computeParallel){ + entity2ModuleMap.putAll(extractModules(unsatObjectProperties)); + } //start main process, either preferring root classes or not if(preferRoots){ @@ -240,9 +242,14 @@ System.gc(); } + entity2Explanations.clear(); + entity2ModuleMap.clear(); + if(!computeParallel){ unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + + entity2ModuleMap.putAll(extractModules(unsatObjectProperties)); while(!unsatObjectProperties.isEmpty()){ //get frequency for each axiom Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-07 09:48:13
|
Revision: 3573 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3573&view=rev Author: lorenz_b Date: 2012-02-07 09:48:07 +0000 (Tue, 07 Feb 2012) Log Message: ----------- Added option to debug classes and properties in one step or sequentially. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-06 20:22:07 UTC (rev 3572) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-07 09:48:07 UTC (rev 3573) @@ -80,6 +80,9 @@ private Set<OWLTransitiveObjectPropertyAxiom> removedTransitiveAxioms; private Set<OWLObjectProperty> unsatObjectProperties; + //whether to debug classes and properties in parallel + private boolean computeParallel = false; + public JustificationBasedCoherentOntologyExtractor() { try { md5 = MessageDigest.getInstance("MD5"); @@ -101,7 +104,7 @@ this.incoherentOntology = getOntologyWithoutAnnotations(ontology); File diffFile = new File(new File(ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toURI()).getParent() + "/" + DIFF_ONTOLOGY_NAME); - try {System.out.println(diffFile); + try { if(diffFile.exists()){ diffOntology = manager.loadOntologyFromOntologyDocument(diffFile); } else { @@ -175,7 +178,9 @@ logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); entity2Explanations.putAll(getInitialExplanations(unsatClasses)); - entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); + if(computeParallel){ + entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); + } logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); while(!unsatClasses.isEmpty()){ @@ -211,8 +216,10 @@ logger.info("Remaining unsatisfiable classes: " + (rootCnt + derivedCnt) + "(" + rootCnt + " roots)."); //recompute unsatisfiable object properties - unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); - logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + if(computeParallel){ + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + } //save if(cnt - (rootCnt+derivedCnt) >= 1 || (unsatPropCnt - unsatObjectProperties.size()) >= 1){ @@ -226,11 +233,52 @@ logger.info("Recomputing explanations..."); startTime = System.currentTimeMillis(); refillExplanations(unsatClasses, entity2Explanations); - refillExplanations(unsatObjectProperties, entity2Explanations); + if(computeParallel){ + refillExplanations(unsatObjectProperties, entity2Explanations); + } logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); System.gc(); } + if(!computeParallel){ + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + while(!unsatObjectProperties.isEmpty()){ + //get frequency for each axiom + Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); + + //get a sorted list of entries with the highest axiom count first + List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); + //we remove the most frequent axiom from the ontology + OWLAxiom toRemove = sortedEntries.get(0).getKey(); + removeAxiom(toRemove); + + //recompute the unsatisfiable classes + logger.info("Reclassifying..."); + startTime = System.currentTimeMillis(); + reasoner.classify(); + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); + + //recompute unsatisfiable object properties + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + + //save + if((unsatPropCnt - unsatObjectProperties.size()) >= 1){ + save("log/dbpedia_" + cnt + "cls" + unsatPropCnt + "prop.owl"); + unsatPropCnt = unsatObjectProperties.size(); + } + + //recompute explanations if necessary + logger.info("Recomputing explanations..."); + startTime = System.currentTimeMillis(); + refillExplanations(unsatObjectProperties, entity2Explanations); + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); + + System.gc(); + } + } + try { incoherentOntology.getOWLOntologyManager().saveOntology(getOntologyWithAnnotations(incoherentOntology), new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_coherent.owl"))); } catch (OWLOntologyStorageException e) { @@ -238,7 +286,6 @@ } catch (FileNotFoundException e) { e.printStackTrace(); } - System.out.println(incoherentOntology.getLogicalAxiomCount()); return getOntologyWithAnnotations(incoherentOntology); } @@ -584,17 +631,22 @@ this.numberOfJustifications = numberOfJustifications; } + public void setComputeParallel(boolean computeParallel) { + this.computeParallel = computeParallel; + } + public static void main(String[] args) throws Exception{ Logger.getLogger(RBox.class.getName()).setLevel(Level.OFF); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); - if(args.length != 3){ - System.out.println("USAGE: JustificationBasedCoherentOntologyExtractor <incoherent.owl> <numberOfJustifcations> <preferRootClasses(true|false)>"); + if(args.length != 4){ + System.out.println("USAGE: JustificationBasedCoherentOntologyExtractor <incoherent.owl> <numberOfJustifcations> <preferRootClasses(true|false)> <computeParallel(true|false)>"); System.exit(0); } String filename = args[0]; int numberOfJustifications = Integer.parseInt(args[1]); boolean preferRoots = Boolean.valueOf(args[2]); + boolean computeParallel = Boolean.valueOf(args[3]); System.out.println("Loading ontology..."); File file = new File(filename); @@ -620,6 +672,7 @@ JustificationBasedCoherentOntologyExtractor extractor = new JustificationBasedCoherentOntologyExtractor(); extractor.setNumberOfJustifications(numberOfJustifications); + extractor.setComputeParallel(computeParallel); OWLOntology coherentOntology = extractor.getCoherentOntology(schema, preferRoots); System.out.println("Coherent ontology contains " + coherentOntology.getLogicalAxiomCount() + " logical axioms."); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 20:22:18
|
Revision: 3572 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3572&view=rev Author: lorenz_b Date: 2012-02-06 20:22:07 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Added exclusion skipping to answer loading method. 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-02-06 15:27:51 UTC (rev 3571) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2012-02-06 20:22:07 UTC (rev 3572) @@ -203,7 +203,7 @@ String question; Object answer; for(Entry<Integer, String> entry : id2Query.entrySet()){ - if(testID != -1 && entry.getKey() != testID)continue; + if(testID != -1 && entry.getKey() != testID || (exclusions.contains(entry.getKey())))continue; questionId = entry.getKey(); question = entry.getValue(); try { @@ -484,8 +484,9 @@ logger.error("Template generation failed"); errorCode = "NT"; latex.addSummaryTableEntry(questionId, extractSentence(question), precision, recall, errorCode); - } catch(Exception e){ + } catch(Exception e){cnt++; e.printStackTrace(); + errorCode = "ERR"; logger.error("ERROR"); latex.addSummaryTableEntry(questionId, extractSentence(question), precision, recall, errorCode); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 15:28:02
|
Revision: 3571 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3571&view=rev Author: lorenz_b Date: 2012-02-06 15:27:51 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Added missing getter and setter methods, needed for usage of ConfigHelper. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-02-06 14:15:12 UTC (rev 3570) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/CELOE.java 2012-02-06 15:27:51 UTC (rev 3571) @@ -32,6 +32,7 @@ import org.apache.log4j.Logger; import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractLearningProblem; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentAnn; @@ -45,10 +46,12 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.Restriction; import org.dllearner.core.owl.Thing; +import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.learningproblems.PosOnlyLP; +import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; @@ -1037,4 +1040,56 @@ this.maxExecutionTimeInSecondsAfterImprovement = maxExecutionTimeInSecondsAfterImprovement; } + public boolean isSingleSuggestionMode() { + return singleSuggestionMode; + } + + public void setSingleSuggestionMode(boolean singleSuggestionMode) { + this.singleSuggestionMode = singleSuggestionMode; + } + + public int getMaxClassExpressionTests() { + return maxClassExpressionTests; + } + + public void setMaxClassExpressionTests(int maxClassExpressionTests) { + this.maxClassExpressionTests = maxClassExpressionTests; + } + + public int getMaxClassExpressionTestsAfterImprovement() { + return maxClassExpressionTestsAfterImprovement; + } + + public void setMaxClassExpressionTestsAfterImprovement( + int maxClassExpressionTestsAfterImprovement) { + this.maxClassExpressionTestsAfterImprovement = maxClassExpressionTestsAfterImprovement; + } + + public double getMaxDepth() { + return maxDepth; + } + + public void setMaxDepth(double maxDepth) { + this.maxDepth = maxDepth; + } + + public static void main(String[] args) throws Exception{ + AbstractKnowledgeSource ks = new OWLFile("../examples/family/father_oe.owl"); + ks.init(); + + AbstractReasonerComponent rc = new FastInstanceChecker(ks); + rc.init(); + + ClassLearningProblem lp = new ClassLearningProblem(rc); + lp.setClassToDescribe(new NamedClass("http://example.com/father#father")); + lp.init(); + + CELOE alg = new CELOE(lp, rc); + alg.setMaxExecutionTimeInSeconds(10); + alg.init(); + + alg.start(); + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 14:15:23
|
Revision: 3570 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3570&view=rev Author: lorenz_b Date: 2012-02-06 14:15:12 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Added CLI option to return only axioms which not already exist in KB. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-02-06 13:48:50 UTC (rev 3569) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-02-06 14:15:12 UTC (rev 3570) @@ -209,6 +209,7 @@ private int nrOfAxiomsToLearn = 10; private double threshold = 0.7; private int chunksize = 1000; + private boolean omitExistingAxioms; private boolean useInference; private SPARQLReasoner reasoner; @@ -232,7 +233,7 @@ private Set<OWLAxiom> learnedOWLAxioms; private Set<EvaluatedAxiom> learnedEvaluatedAxioms; - public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose, int chunksize, int maxExecutionTimeInSeconds) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose, int chunksize, int maxExecutionTimeInSeconds, boolean omitExistingAxioms) { this.se = se; this.resource = resource; this.verbose = verbose; @@ -241,6 +242,7 @@ this.useInference = useInference; this.chunksize = chunksize; this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; + this.omitExistingAxioms = omitExistingAxioms; try { cacheDir = "cache" + File.separator + URLEncoder.encode(se.getURL().toString(), "UTF-8"); @@ -426,6 +428,7 @@ ks2.setCacheDir(cacheDir); ks2.setRecursionDepth(2); ks2.setCloseAfterRecursion(true); + ks2.setDissolveBlankNodes(false); ks2.setSaveExtractedFragment(true); startTime = System.currentTimeMillis(); System.out.print("getting knowledge base fragment ... "); @@ -491,6 +494,7 @@ ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); ((AbstractAxiomLearningAlgorithm)learner).setLimit(chunksize); + ((AbstractAxiomLearningAlgorithm)learner).setReturnOnlyNewAxioms(omitExistingAxioms); learner.init(); if(reasoner != null){ ((AbstractAxiomLearningAlgorithm)learner).setReasoner(reasoner); @@ -809,6 +813,8 @@ "Specifies the chunk size for the query result as the approach is incrementally.").withRequiredArg().ofType(Integer.class).defaultsTo(1000); parser.acceptsAll(asList("maxExecutionTimeInSeconds"), "Specifies the max execution time for each algorithm run and each entity.").withRequiredArg().ofType(Integer.class).defaultsTo(10); + parser.acceptsAll(asList("omitExistingAxioms"), + "Specifies whether return only axioms which not already exist in the knowlegde base.").withOptionalArg().ofType(Boolean.class).defaultsTo(false); // parse options and display a message for the user in case of problems OptionSet options = null; @@ -896,7 +902,8 @@ } int chunksize = (Integer) options.valueOf("chunksize"); - int runtime = (Integer) options.valueOf("runtime"); + int maxExecutionTimeInSeconds = (Integer) options.valueOf("maxExecutionTimeInSeconds"); + boolean omitExistingAxioms = (Boolean) options.valueOf("omitExistingAxioms"); // TODO: some handling for inaccessible files or overwriting existing files File f = (File) options.valueOf("o"); @@ -907,7 +914,7 @@ System.setOut(printStream); } - Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false, chunksize, runtime); + Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false, chunksize, maxExecutionTimeInSeconds, omitExistingAxioms); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-02-06 13:48:50 UTC (rev 3569) +++ trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-02-06 14:15:12 UTC (rev 3570) @@ -81,6 +81,7 @@ private static int queryChunkSize = 1000; private static int maxExecutionTimeInSeconds = 10; private static boolean useInference = true; + private static boolean omitExistingAxioms = false; // directory for generated schemata private static String baseDir = "log/lod-enriched/"; @@ -88,7 +89,7 @@ //parameters for thread pool //Parallel running Threads(Executor) on System - private static int corePoolSize = 5; + private static int corePoolSize = 1; //Maximum Threads allowed in Pool private static int maximumPoolSize = 20; //Keep alive time for waiting threads for jobs(Runnable) @@ -189,7 +190,8 @@ File log = new File(baseDir + File.separator + "failed" + File.separator + name + ".log"); System.out.println("Enriching " + name + " using " + se.getURL()); - Enrichment e = new Enrichment(se, null, threshold, nrOfAxiomsToLearn, useInference, false, queryChunkSize, maxExecutionTimeInSeconds); + Enrichment e = new Enrichment(se, null, threshold, nrOfAxiomsToLearn, useInference, + false, queryChunkSize, maxExecutionTimeInSeconds, omitExistingAxioms); e.maxEntitiesPerType = 3; // hack for faster testing of endpoints This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 13:49:00
|
Revision: 3569 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3569&view=rev Author: lorenz_b Date: 2012-02-06 13:48:50 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Added class to merge multiple ontologies on the commandline. Added Paths: ----------- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMerger.java Added: trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMerger.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMerger.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OntologyMerger.java 2012-02-06 13:48:50 UTC (rev 3569) @@ -0,0 +1,58 @@ +package org.dllearner.scripts; + +import static java.util.Arrays.asList; + +import java.io.File; + +import joptsimple.OptionParser; +import joptsimple.OptionSet; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.util.OWLOntologyMerger; + +/** + * This class merges several ontologies into a single one. + * @author lorenz + * + */ +public class OntologyMerger { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + if(args.length <= 0){ + System.exit(0); + } + OptionParser parser = new OptionParser(); + parser.acceptsAll(asList("o", "output"), "The target output file for the merged ontology.").withRequiredArg(); + parser.acceptsAll(asList("i", "iri"), "The document IRI for the merged ontology.").withRequiredArg(); + + OptionSet os = parser.parse(args); + + String targetFile = "merged.owl"; + if(os.has("o")){ + targetFile = (String) os.valueOf("o");; + } + String documentIRI = "http://www.semanticweb.com/merged"; + if(os.has("i")){ + targetFile = (String) os.valueOf("o");; + } + + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + for(String file : os.nonOptionArguments()){ + man.loadOntologyFromOntologyDocument(new File(file)); + } + + OWLOntologyMerger merger = new OWLOntologyMerger(man); + OWLOntology merged = merger.createMergedOntology(man, IRI.create(documentIRI)); + + man.saveOntology(merged, new RDFXMLOntologyFormat(), IRI.create(targetFile)); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2012-02-06 13:14:21
|
Revision: 3568 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3568&view=rev Author: christinaunger Date: 2012-02-06 13:14:10 +0000 (Mon, 06 Feb 2012) Log Message: ----------- [tbsl] added QALD2 evaluation questions Modified Paths: -------------- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/GoldTagger.java Added Paths: ----------- trunk/components-ext/questions.txt trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged.xml trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train.xml Added: trunk/components-ext/questions.txt =================================================================== --- trunk/components-ext/questions.txt (rev 0) +++ trunk/components-ext/questions.txt 2012-02-06 13:14:10 UTC (rev 3568) @@ -0,0 +1,100 @@ +1: Give me all female Russian astronauts +2: Give me the birthdays of all actors of the television show Charmed +3: Who is the daughter of Bill Clinton married to +4: Which river does the Brooklyn Bridge cross +5: How many monarchical countries are there in Europe +6: Where did Abraham Lincoln die +7: Is the wife of President Obama called Michelle +8: Which states of Germany are governed by the Social Democratic Party +9: Which US states possess gold minerals +10: In which country does the Nile start +11: Which countries have places with more than two caves +12: Is proinsulin a protein +13: Which classis does the Millepede belong to +14: How tall is Claudia Schiffer +15: Who created Goofy +16: Give me the capitals of all countries in Africa +17: Give me all cities in New Jersey with more than 100000 inhabitants +18: Which museum exhibits The Scream by Munch +19: Is Egypts largest city also its capital +20: How many employees does IBM have +21: Which states border Illinois +22: In which country is the Limerick Lake +23: Which television shows were created by Walt Disney +24: Which mountain is the highest after the Annapurna +25: In which films directed by Garry Marshall was Julia Roberts starring +26: Which bridges are of the same type as the Manhattan Bridge +27: Was US president Jackson involved in a war +28: Which European countries have a constitutional monarchy +29: Which awards did WikiLeaks win +30: Which state of the USA has the highest population density +31: What is the currency of the Czech Republic +32: Which countries in the European Union adopted the Euro +33: What is the area code of Berlin +34: Which countries have more than two official languages +35: Who is the owner of Universal Studios +36: Through which countries does the Yenisei river flow +37: When did Finland join the EU +38: Which monarchs of the United Kingdom were married to a German +39: When was the Battle of Gettysburg +40: What is the highest mountain in Australia +41: Give me all soccer clubs in Spain +42: What are the official languages of the Philippines +43: Who is the mayor of New York City +44: Who designed the Brooklyn Bridge +45: Which telecommunications organizations are located in Belgium +46: Is Frank Herbert still alive +47: What is the highest place of Karakoram +48: Give me the homepage of Forbes +49: Give me all companies in the advertising industry +50: What did Bruce Carver die from +51: Give me all school types +52: Which presidents were born in 1945 +53: Give me all presidents of the United States +54: Who was the wife of US president Lincoln +55: Who developed the video game World of Warcraft +56: What is the official website of Tom Cruise +57: List all episodes of the first season of the HBO television series The Sopranos +58: Who produced the most films +59: Give me all people with first name Jimmy +60: Is there a video game called Battle Chess +61: Which mountains are higher than the Nanga Parbat +62: Who created Wikipedia +63: Give me all actors starring in Batman Begins +64: Which software has been developed by organizations founded in California +65: Which companies work in the aerospace industry as well as on nuclear reactor technology +66: Is Christian Bale starring in Batman Begins +67: Give me the websites of companies with more than 500000 employees +68: Which actors were born in Germany +69: Which caves have more than 3 entrances +70: Give me all films produced by Hal Roach +71: Give me all video games published by Mean Hamster Software +72: Which languages are spoken in Estonia +73: Who owns Aldi +74: Which capitals in Europe were host cities of the summer olympic games +75: Who has been the 5th president of the United States of America +76: How many films did Hal Roach produce +77: Which music albums contain the song Last Christmas +78: Give me all books written by Danielle Steel +79: Which airports are located in California USA +80: Give me all Canadian Grunge record labels +81: Which country has the most official languages +82: In which programming language is GIMP written +83: Who produced films starring Natalie Portman +84: Give me all movies with Tom Cruise +85: In which films did Julia Roberts as well as Richard Gere play +86: Give me all female German chancellors +87: Who wrote the book The pillars of the Earth +88: How many films did Leonardo DiCaprio star in +89: Give me all soccer clubs in the Premier League +90: When was Capcom founded +91: Which organizations were founded in 1950 +92: What is the highest mountain +93: Was Natalie Portman born in the United States +94: Which budget did the first movie of Zdenek Sverak have +95: How many big fires struck Paris during the Middle Ages +96: Is Jens Friebe a vegan +97: How often was Michael Jordan divorced +98: What is the most beautiful painting +99: Give me all animal species that live in the Teutoburg Forest +100: When is the movie Worst Case Scenario going to be in cinemas in the Netherlands Added: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml =================================================================== (Binary files differ) Property changes on: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged(ideal).xml ___________________________________________________________________ Added: svn:mime-type + application/xml Added: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged.xml =================================================================== (Binary files differ) Property changes on: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train-tagged.xml ___________________________________________________________________ Added: svn:mime-type + application/xml Added: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train.xml =================================================================== (Binary files differ) Property changes on: trunk/components-ext/src/main/resources/tbsl/evaluation/qald2-dbpedia-train.xml ___________________________________________________________________ Added: svn:mime-type + application/xml 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-02-06 12:40:04 UTC (rev 3567) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/Evaluation.java 2012-02-06 13:14:10 UTC (rev 3568) @@ -64,7 +64,8 @@ public class Evaluation{ - List<Integer> yagoExclusions = Arrays.asList(new Integer[]{1, 3, 6, 11, 15, 22, 23, 46}); +// List<Integer> yagoExclusions = Arrays.asList(new Integer[]{1, 3, 6, 11, 15, 22, 23, 46}); + List<Integer> exclusions = Arrays.asList(new Integer[]{1,5,8,9,16,28,30,32,38,51,52,53,74,86,94,95,96,97,98,99,100}); Map<Integer, String> evalCodes = new HashMap<Integer, String>(); private static Logger logger = Logger.getLogger(Evaluation.class); @@ -97,8 +98,10 @@ prefixMap = new HashMap<String, String>(); prefixMap.put("rdf", RDF.getURI()); prefixMap.put("rdfs", RDFS.getURI()); - prefixMap.put("onto", "http://dbpedia.org/ontology/"); - prefixMap.put("prop", "http://dbpedia.org/property/"); +// prefixMap.put("onto", "http://dbpedia.org/ontology/"); +// prefixMap.put("prop", "http://dbpedia.org/property/"); + prefixMap.put("dbo", "http://dbpedia.org/ontology/"); + prefixMap.put("dbp", "http://dbpedia.org/property/"); prefixMap.put("res", "http://dbpedia.org/resource/"); prefixMap.put("foaf", FOAF.getURI()); prefixMap.put("yago", "http://dbpedia.org/class/yago/"); @@ -323,7 +326,7 @@ int i = 0; int cnt = 0; for(Entry<Integer, String> entry : id2Question.entrySet()){//if(entry.getKey()==50)continue; - if((testID != -1 && entry.getKey() != testID) || (yagoExclusions.contains(entry.getKey())))continue; + if((testID != -1 && entry.getKey() != testID) || (exclusions.contains(entry.getKey()))) continue; try { questionId = entry.getKey(); question = entry.getValue(); Modified: trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/GoldTagger.java =================================================================== --- trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/GoldTagger.java 2012-02-06 12:40:04 UTC (rev 3567) +++ trunk/components-ext/src/test/java/org/dllearner/algorithm/tbsl/GoldTagger.java 2012-02-06 13:14:10 UTC (rev 3568) @@ -25,8 +25,8 @@ public class GoldTagger { - static String GOLD = "src/main/resources/tbsl/evaluation/dbpedia-train.xml"; - static String OUT = "target/dbpedia-train-tagged.xml"; + static String GOLD = "src/main/resources/tbsl/evaluation/qald2-dbpedia-train.xml"; + static String OUT = "target/qald2-dbpedia-train-tagged.xml"; public static void main(String[] args) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 12:40:15
|
Revision: 3567 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3567&view=rev Author: lorenz_b Date: 2012-02-06 12:40:04 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Fixed some dependencies for SOLR. Modified Paths: -------------- trunk/components-ext/pom.xml Modified: trunk/components-ext/pom.xml =================================================================== --- trunk/components-ext/pom.xml 2012-02-06 09:38:22 UTC (rev 3566) +++ trunk/components-ext/pom.xml 2012-02-06 12:40:04 UTC (rev 3567) @@ -57,7 +57,6 @@ <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> - <version>1.4.1</version> </dependency> <!--BEGIN Logging Dependencies--> @@ -66,16 +65,20 @@ <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> - <version>1.5.8</version> </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> <!--This is the bridge that ties calls to the slf4j api to the log4j framework. This is a runtime dependency for programs which wish to use log4j as their implementation.--> - <dependency> + <!-- dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.11</version> <scope>runtime</scope> - </dependency> + </dependency--> <!-- This is the concrete implementation of the log4j framework - it is a runtime dependency that needs to be used with the slf4j-log4j12 dependency --> <dependency> @@ -83,12 +86,12 @@ <artifactId>log4j</artifactId> </dependency> - <dependency> + <!-- dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.5.11</version> <scope>runtime</scope> - </dependency> + </dependency--> <!--END Logging Dependencies--> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-06 09:38:33
|
Revision: 3566 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3566&view=rev Author: lorenz_b Date: 2012-02-06 09:38:22 +0000 (Mon, 06 Feb 2012) Log Message: ----------- Saving diff. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-05 18:27:34 UTC (rev 3565) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-06 09:38:22 UTC (rev 3566) @@ -26,6 +26,7 @@ import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; @@ -56,7 +57,8 @@ public class JustificationBasedCoherentOntologyExtractor implements CoherentOntologyExtractor{ private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(JustificationBasedCoherentOntologyExtractor.class); - + private static final String DIFF_ONTOLOGY_NAME = "diff.owl"; + private int numberOfJustifications = 10; // private PelletReasoner reasoner; private IncrementalClassifier reasoner; @@ -66,7 +68,11 @@ private OWLOntology ontology; private OWLDataFactory factory; + //we store the removed axioms in it + private OWLOntology diffOntology; + private Map<OWLEntity, OWLOntology> entity2ModuleMap = new HashMap<OWLEntity, OWLOntology>(); + private Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); MessageDigest md5; @@ -94,6 +100,17 @@ this.ontology = ontology; this.incoherentOntology = getOntologyWithoutAnnotations(ontology); + File diffFile = new File(new File(ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toURI()).getParent() + "/" + DIFF_ONTOLOGY_NAME); + try {System.out.println(diffFile); + if(diffFile.exists()){ + diffOntology = manager.loadOntologyFromOntologyDocument(diffFile); + } else { + diffOntology = manager.createOntology(IRI.create("http://diff.org/")); + } + } catch (OWLOntologyCreationException e1) { + e1.printStackTrace(); + } + //only for debugging removedTransitiveAxioms = incoherentOntology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY); incoherentOntology.getOWLOntologyManager().removeAxioms(incoherentOntology, removedTransitiveAxioms); @@ -141,6 +158,7 @@ int derivedCnt = derivedUnsatClasses.size(); // Set<OWLClass> unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); int cnt = rootCnt + derivedCnt; + int unsatPropCnt = unsatObjectProperties.size(); logger.info("Detected " + cnt + " unsatisfiable classes, " + rootCnt + " of them as root."); //if the ontology is not incoherent we return it here @@ -156,7 +174,6 @@ //compute initial explanations for each unsatisfiable class logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); - Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); entity2Explanations.putAll(getInitialExplanations(unsatClasses)); entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -172,11 +189,7 @@ } //we remove the most frequent axiom from the ontology OWLAxiom toRemove = sortedEntries.get(0).getKey(); - logger.info("Removing axiom " + toRemove + "."); - man.removeAxiom(incoherentOntology, toRemove); - man.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); - removeFromExplanations(entity2Explanations, toRemove); - removeFromModules(toRemove); + removeAxiom(toRemove); //recompute the unsatisfiable classes logger.info("Reclassifying..."); @@ -202,10 +215,11 @@ logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); //save - if(cnt - (rootCnt+derivedCnt) >= 10){ + if(cnt - (rootCnt+derivedCnt) >= 1 || (unsatPropCnt - unsatObjectProperties.size()) >= 1){ cnt = rootCnt + derivedCnt; - save("log/dbpedia_" + cnt + ".owl"); + save("log/dbpedia_" + cnt + "cls" + unsatPropCnt + "prop.owl"); cnt = rootCnt + derivedCnt; + unsatPropCnt = unsatObjectProperties.size(); } //recompute explanations if necessary @@ -251,7 +265,6 @@ //compute initial explanations for each unsatisfiable class logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); - Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); entity2Explanations.putAll(getInitialExplanations(unsatClasses)); entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); @@ -267,11 +280,7 @@ } //we remove the most frequent axiom from the ontology OWLAxiom toRemove = sortedEntries.get(0).getKey(); - logger.info("Removing axiom " + toRemove + "."); - manager.removeAxiom(incoherentOntology, toRemove); - manager.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); - removeFromExplanations(entity2Explanations, toRemove); - removeFromModules(toRemove); + removeAxiom(toRemove); //recompute the unsatisfiable classes logger.info("Reclassifying..."); @@ -312,10 +321,20 @@ return getOntologyWithAnnotations(incoherentOntology); } + private void removeAxiom(OWLAxiom axiom){ + logger.info("Removing axiom " + axiom + "."); + manager.removeAxiom(incoherentOntology, axiom); + manager.addAxiom(diffOntology, axiom); + manager.applyChange(new RemoveAxiom(incoherentOntology, axiom)); + removeFromExplanations(entity2Explanations, axiom); + removeFromModules(axiom); + } + private void save(String fileName){ OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); try { toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream(fileName))); + toSave.getOWLOntologyManager().saveOntology(diffOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/diff.owl"))); } catch (OWLOntologyStorageException e) { e.printStackTrace(); } catch (FileNotFoundException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-05 18:27:40
|
Revision: 3565 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3565&view=rev Author: lorenz_b Date: 2012-02-05 18:27:34 +0000 (Sun, 05 Feb 2012) Log Message: ----------- Minor changes to use CLI options for run time and chunk size. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/AsymmetricObjectPropertyAxiomLearner.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -21,6 +21,7 @@ import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -145,7 +146,6 @@ symmetric = qs.getLiteral("symmetric").getInt(); } int asymmetric = total - symmetric; - if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new AsymmetricObjectPropertyAxiom(propertyToDescribe), computeScore(total, asymmetric), declaredAsymmetric)); @@ -154,8 +154,9 @@ } public static void main(String[] args) throws Exception{ - AsymmetricObjectPropertyAxiomLearner l = new AsymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint(new URL("http://factforge.net/sparql"))));//.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/country")); + AsymmetricObjectPropertyAxiomLearner l = new AsymmetricObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint( + new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())));//.getEndpointDBpediaLiveAKSW())); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/spouse")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -138,7 +138,6 @@ private void runSPARQL1_1_Mode() { //get properties and how often they occur - int limit = 1000; int offset = 0; String queryTemplate = "SELECT ?p COUNT(?s) AS ?count WHERE {?s ?p ?o." + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + @@ -186,7 +185,7 @@ EvaluatedAxiom evalAxiom; //first create disjoint axioms with properties which not occur and give score of 1 - for(ObjectProperty p : completeDisjointProperties){System.out.println(p); + for(ObjectProperty p : completeDisjointProperties){ if(usePropertyPopularity){ int popularity = reasoner.getPropertyCount(p); //skip if property is not used in kb @@ -205,7 +204,7 @@ //second create disjoint axioms with other properties and score 1 - (#occurence/#all) for(Entry<ObjectProperty, Integer> entry : sortByValues(property2Count)){ double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(all, entry.getValue()); - double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2; + double accuracy = (confidenceInterval[0] + confidenceInterval[1]) / 2;//System.out.println(entry + ": " + accuracy); evalAxiom = new EvaluatedAxiom(new DisjointObjectPropertyAxiom(propertyToDescribe, entry.getKey()), new AxiomScore(1 - accuracy)); axioms.add(evalAxiom); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentObjectPropertyAxiomLearner.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -128,7 +128,6 @@ private void runSPARQL1_1_Mode() { //get subjects with types - int limit = 1000; int offset = 0; String queryTemplate = "SELECT ?p (COUNT(?s) AS ?count) WHERE {?s ?p ?o." + "{SELECT ?s ?o WHERE {?s <%s> ?o.} LIMIT %d OFFSET %d}" + @@ -159,7 +158,7 @@ } if(!result.isEmpty()){ currentlyBestAxioms = buildAxioms(result); - offset += 1000; + offset += limit; } } @@ -178,9 +177,10 @@ properties.add(propertyToDescribe); properties.add(entry.getKey()); int popularity = reasoner.getPropertyCount(entry.getKey()); - int total = popularity;//Math.max(popularity, all); +// int total = popularity; + int total = Math.max(popularity, all); int success = entry.getValue();//System.out.println(entry.getKey());System.out.println(entry.getKey());System.out.println(total);System.out.println(success); - Score score = computeScore(total, success); + Score score = computeScore(total, success);//System.out.println(entry + ": " + score.getAccuracy()); evalAxiom = new EvaluatedAxiom(new EquivalentObjectPropertiesAxiom(properties),score); axioms.add(evalAxiom); } @@ -192,7 +192,7 @@ public static void main(String[] args) throws Exception{ EquivalentObjectPropertyAxiomLearner l = new EquivalentObjectPropertyAxiomLearner(new SparqlEndpointKS(new SparqlEndpoint( new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())));//.getEndpointDBpediaLiveAKSW())); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/state")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/nationality")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseObjectPropertyAxiomLearner.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -21,6 +21,7 @@ import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.SortedSet; import org.dllearner.core.AbstractAxiomLearningAlgorithm; @@ -142,7 +143,8 @@ } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint(new URL("http://dbpedia.aksw.org:8902/sparql")));//.getEndpointDBpediaLiveAKSW())); + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint( + new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList()));//.getEndpointDBpediaLiveAKSW())); SPARQLReasoner reasoner = new SPARQLReasoner(ks); reasoner.prepareSubsumptionHierarchy(); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitiveObjectPropertyAxiomLearner.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -19,7 +19,9 @@ package org.dllearner.algorithms.properties; +import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; @@ -143,7 +145,7 @@ qs = rs.next(); transitive = qs.getLiteral("transitive").getInt(); } - + System.out.println(total); if(total > 0){ currentlyBestAxioms.add(new EvaluatedAxiom(new TransitiveObjectPropertyAxiom(propertyToDescribe), computeScore(total, transitive), declaredAsTransitive)); @@ -152,9 +154,10 @@ } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpedia()); + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint( + new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); TransitiveObjectPropertyAxiomLearner l = new TransitiveObjectPropertyAxiomLearner(ks); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/subregion")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/chairman")); l.init(); l.start(); System.out.println(l.getCurrentlyBestEvaluatedAxioms(1)); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-02-05 18:25:51 UTC (rev 3564) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-02-05 18:27:34 UTC (rev 3565) @@ -84,6 +84,7 @@ protected int fetchedRows; protected long startTime; + protected int limit = 1000; public AbstractAxiomLearningAlgorithm() { existingAxioms = new TreeSet<Axiom>(new AxiomComparator()); @@ -136,6 +137,14 @@ public void start() { } + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + @Override public void init() throws ComponentInitException { ks.init(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-05 18:25:58
|
Revision: 3564 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3564&view=rev Author: lorenz_b Date: 2012-02-05 18:25:51 +0000 (Sun, 05 Feb 2012) Log Message: ----------- Added to CLI options to set query chunk size and max execution time in seconds. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-02-02 13:17:12 UTC (rev 3563) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-02-05 18:25:51 UTC (rev 3564) @@ -208,6 +208,7 @@ // some learners) private int nrOfAxiomsToLearn = 10; private double threshold = 0.7; + private int chunksize = 1000; private boolean useInference; private SPARQLReasoner reasoner; @@ -231,13 +232,15 @@ private Set<OWLAxiom> learnedOWLAxioms; private Set<EvaluatedAxiom> learnedEvaluatedAxioms; - public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose, int chunksize, int maxExecutionTimeInSeconds) { this.se = se; this.resource = resource; this.verbose = verbose; this.threshold = threshold; this.nrOfAxiomsToLearn = nrOfAxiomsToLearn; this.useInference = useInference; + this.chunksize = chunksize; + this.maxExecutionTimeInSeconds = maxExecutionTimeInSeconds; try { cacheDir = "cache" + File.separator + URLEncoder.encode(se.getURL().toString(), "UTF-8"); @@ -487,6 +490,7 @@ } ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); + ((AbstractAxiomLearningAlgorithm)learner).setLimit(chunksize); learner.init(); if(reasoner != null){ ((AbstractAxiomLearningAlgorithm)learner).setReasoner(reasoner); @@ -801,6 +805,11 @@ .withRequiredArg().ofType(File.class); parser.acceptsAll(asList("a", "annotations"), "Specifies whether to save scores as annotations.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("chunksize"), + "Specifies the chunk size for the query result as the approach is incrementally.").withRequiredArg().ofType(Integer.class).defaultsTo(1000); + parser.acceptsAll(asList("maxExecutionTimeInSeconds"), + "Specifies the max execution time for each algorithm run and each entity.").withRequiredArg().ofType(Integer.class).defaultsTo(10); + // parse options and display a message for the user in case of problems OptionSet options = null; try { @@ -886,6 +895,9 @@ maxNrOfResults = Integer.MAX_VALUE; } + int chunksize = (Integer) options.valueOf("chunksize"); + int runtime = (Integer) options.valueOf("runtime"); + // TODO: some handling for inaccessible files or overwriting existing files File f = (File) options.valueOf("o"); @@ -895,7 +907,7 @@ System.setOut(printStream); } - Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false); + Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false, chunksize, runtime); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); Modified: trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-02-02 13:17:12 UTC (rev 3563) +++ trunk/interfaces/src/main/java/org/dllearner/cli/GlobalEnrichment.java 2012-02-05 18:25:51 UTC (rev 3564) @@ -78,6 +78,8 @@ // parameters private static double threshold = 0.8; private static int nrOfAxiomsToLearn = 10; + private static int queryChunkSize = 1000; + private static int maxExecutionTimeInSeconds = 10; private static boolean useInference = true; // directory for generated schemata @@ -187,7 +189,7 @@ File log = new File(baseDir + File.separator + "failed" + File.separator + name + ".log"); System.out.println("Enriching " + name + " using " + se.getURL()); - Enrichment e = new Enrichment(se, null, threshold, nrOfAxiomsToLearn, useInference, false); + Enrichment e = new Enrichment(se, null, threshold, nrOfAxiomsToLearn, useInference, false, queryChunkSize, maxExecutionTimeInSeconds); e.maxEntitiesPerType = 3; // hack for faster testing of endpoints This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-02 13:17:22
|
Revision: 3563 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3563&view=rev Author: lorenz_b Date: 2012-02-02 13:17:12 +0000 (Thu, 02 Feb 2012) Log Message: ----------- Continued integration of debugging unsatisfiable object properties. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-01 14:31:26 UTC (rev 3562) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-02 13:17:12 UTC (rev 3563) @@ -66,7 +66,6 @@ private OWLOntology ontology; private OWLDataFactory factory; - private Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); private Map<OWLEntity, OWLOntology> entity2ModuleMap = new HashMap<OWLEntity, OWLOntology>(); private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); @@ -96,8 +95,8 @@ this.incoherentOntology = getOntologyWithoutAnnotations(ontology); //only for debugging - removedTransitiveAxioms = ontology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY); - incoherentOntology.getOWLOntologyManager().removeAxioms(ontology, removedTransitiveAxioms); + removedTransitiveAxioms = incoherentOntology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY); + incoherentOntology.getOWLOntologyManager().removeAxioms(incoherentOntology, removedTransitiveAxioms); manager = incoherentOntology.getOWLOntologyManager(); factory = manager.getOWLDataFactory(); @@ -107,8 +106,10 @@ reasoner.classify(); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - //compute the unsatisfiable object properties + //compute the unsatisfiable object properties and their corresponding modules unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Found unsatisfiable object properties: " + unsatObjectProperties.size()); + entity2ModuleMap.putAll(extractModules(unsatObjectProperties)); //start main process, either preferring root classes or not if(preferRoots){ @@ -147,20 +148,22 @@ return incoherentOntology; } //compute the logical modules for each unsatisfiable class - logger.info("Computing module for each unsatisfiable class..."); + logger.info("Computing module for each unsatisfiable entity..."); startTime = System.currentTimeMillis(); - cls2ModuleMap = extractModules(unsatClasses); + entity2ModuleMap.putAll(extractModules(unsatClasses)); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); //compute initial explanations for each unsatisfiable class logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); - Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = getInitialExplanationsForUnsatClasses(unsatClasses); + Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); + entity2Explanations.putAll(getInitialExplanations(unsatClasses)); + entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); while(!unsatClasses.isEmpty()){ //get frequency for each axiom - Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(cls2Explanations); + Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); //get a sorted list of entries with the highest axiom count first List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); @@ -172,7 +175,7 @@ logger.info("Removing axiom " + toRemove + "."); man.removeAxiom(incoherentOntology, toRemove); man.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); - removeFromExplanations(cls2Explanations, toRemove); + removeFromExplanations(entity2Explanations, toRemove); removeFromModules(toRemove); //recompute the unsatisfiable classes @@ -194,6 +197,10 @@ logger.info("Remaining unsatisfiable classes: " + (rootCnt + derivedCnt) + "(" + rootCnt + " roots)."); + //recompute unsatisfiable object properties + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + //save if(cnt - (rootCnt+derivedCnt) >= 10){ cnt = rootCnt + derivedCnt; @@ -204,7 +211,8 @@ //recompute explanations if necessary logger.info("Recomputing explanations..."); startTime = System.currentTimeMillis(); - refillExplanations(unsatClasses, cls2Explanations); + refillExplanations(unsatClasses, entity2Explanations); + refillExplanations(unsatObjectProperties, entity2Explanations); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); System.gc(); @@ -237,19 +245,20 @@ //compute the logical modules for each unsatisfiable class logger.info("Computing module for each unsatisfiable class..."); startTime = System.currentTimeMillis(); - cls2ModuleMap = extractModules(unsatClasses); + entity2ModuleMap = extractModules(unsatClasses); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); //compute initial explanations for each unsatisfiable class logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); - Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = getInitialExplanationsForUnsatClasses(unsatClasses); - Map<OWLObjectProperty, Set<Set<OWLAxiom>>> prop2Explanations = getInitialExplanationsForUnsatObjectProperties(unsatObjectProperties); + Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); + entity2Explanations.putAll(getInitialExplanations(unsatClasses)); + entity2Explanations.putAll(getInitialExplanations(unsatObjectProperties)); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); while(!unsatClasses.isEmpty()){ //get frequency for each axiom - Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(cls2Explanations); + Map<OWLAxiom, Integer> axiom2CountMap = getAxiomFrequency(entity2Explanations); //get a sorted list of entries with the highest axiom count first List<Entry<OWLAxiom, Integer>> sortedEntries = MapUtils.sortByValues(axiom2CountMap); @@ -261,7 +270,7 @@ logger.info("Removing axiom " + toRemove + "."); manager.removeAxiom(incoherentOntology, toRemove); manager.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); - removeFromExplanations(cls2Explanations, toRemove); + removeFromExplanations(entity2Explanations, toRemove); removeFromModules(toRemove); //recompute the unsatisfiable classes @@ -272,6 +281,10 @@ logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); logger.info("Remaining unsatisfiable classes: " + unsatClasses.size()); + //recompute unsatisfiable object properties + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + logger.info("Remaining unsatisfiable object properties: " + unsatObjectProperties.size()); + //save if(cnt - unsatClasses.size() >= 10){ cnt = unsatClasses.size(); @@ -281,7 +294,8 @@ //recompute explanations if necessary logger.info("Recomputing explanations..."); startTime = System.currentTimeMillis(); - refillExplanations(unsatClasses, cls2Explanations); + refillExplanations(unsatClasses, entity2Explanations); + refillExplanations(unsatObjectProperties, entity2Explanations); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); System.gc(); @@ -310,6 +324,8 @@ } private Set<OWLObjectProperty> getUnsatisfiableObjectProperties(IncrementalClassifier reasoner){ + logger.info("Computing unsatisfiable object properties..."); + long startTime = System.currentTimeMillis(); SortedSet<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(); OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); for(OWLObjectProperty p : reasoner.getRootOntology().getObjectPropertiesInSignature()){ @@ -319,19 +335,20 @@ properties.add(p); } } + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return properties; } private void removeFromModules(OWLAxiom axiom){ OWLOntology module; - for(Entry<OWLClass, OWLOntology> entry : cls2ModuleMap.entrySet()){ + for(Entry<? extends OWLEntity, OWLOntology> entry : entity2ModuleMap.entrySet()){ module = entry.getValue(); module.getOWLOntologyManager().removeAxiom(module, axiom); } } - private void removeFromExplanations(Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations, OWLAxiom axiom){ - for(Entry<OWLClass, Set<Set<OWLAxiom>>> entry : cls2Explanations.entrySet()){ + private void removeFromExplanations(Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations, OWLAxiom axiom){ + for(Entry<OWLEntity, Set<Set<OWLAxiom>>> entry : entity2Explanations.entrySet()){ for (Iterator<Set<OWLAxiom>> iterator = entry.getValue().iterator(); iterator.hasNext();) { Set<OWLAxiom> explanation = iterator.next(); if(explanation.contains(axiom)){ @@ -341,20 +358,20 @@ } } - private void refillExplanations(Set<OWLClass> unsatClasses, Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations){ - for(OWLClass unsatClass : unsatClasses){ - Set<Set<OWLAxiom>> precomputedExplanations = cls2Explanations.get(unsatClass); + private void refillExplanations(Set<? extends OWLEntity> unsatEntities, Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations){ + for(OWLEntity unsatClass : unsatEntities){ + Set<Set<OWLAxiom>> precomputedExplanations = entity2Explanations.get(unsatClass); if(precomputedExplanations == null || precomputedExplanations.size() < numberOfJustifications){ Set<Set<OWLAxiom>> newExplanations = computeExplanations(unsatClass, numberOfJustifications); - cls2Explanations.put(unsatClass, newExplanations); + entity2Explanations.put(unsatClass, newExplanations); } } } - private Map<OWLAxiom, Integer> getAxiomFrequency(Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations){ + private Map<OWLAxiom, Integer> getAxiomFrequency(Map<OWLEntity, Set<Set<OWLAxiom>>> entity2Explanations){ Map<OWLAxiom, Integer> axiom2CountMap = new HashMap<OWLAxiom, Integer>(); - for(Entry<OWLClass, Set<Set<OWLAxiom>>> entry : cls2Explanations.entrySet()){ + for(Entry<OWLEntity, Set<Set<OWLAxiom>>> entry : entity2Explanations.entrySet()){ for(Set<OWLAxiom> explanation : entry.getValue()){ for(OWLAxiom ax : explanation){ Integer cnt = axiom2CountMap.get(ax); @@ -370,28 +387,22 @@ return axiom2CountMap; } - private Map<OWLClass, Set<Set<OWLAxiom>>> getInitialExplanationsForUnsatClasses(Set<OWLClass> unsatClasses){ - Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = new HashMap<OWLClass, Set<Set<OWLAxiom>>>(); + private Map<OWLEntity, Set<Set<OWLAxiom>>> getInitialExplanations(Set<? extends OWLEntity> unsatEntities){ + Map<OWLEntity, Set<Set<OWLAxiom>>> cls2Explanations = new HashMap<OWLEntity, Set<Set<OWLAxiom>>>(); - for(OWLClass unsatClass : unsatClasses){ - Set<Set<OWLAxiom>> explanations = computeExplanations(unsatClass); - cls2Explanations.put(unsatClass, explanations); + for(OWLEntity unsatEntity : unsatEntities){ + Set<Set<OWLAxiom>> explanations = null; + if(unsatEntity instanceof OWLClass){ + explanations = computeExplanations((OWLClass) unsatEntity); + } else if(unsatEntity instanceof OWLObjectProperty){ + explanations = computeExplanations((OWLObjectProperty) unsatEntity); + } + cls2Explanations.put(unsatEntity, explanations); } return cls2Explanations; } - private Map<OWLObjectProperty, Set<Set<OWLAxiom>>> getInitialExplanationsForUnsatObjectProperties(Set<OWLObjectProperty> unsatObjProperties){ - Map<OWLObjectProperty, Set<Set<OWLAxiom>>> prop2Explanations = new HashMap<OWLObjectProperty, Set<Set<OWLAxiom>>>(); - - for(OWLObjectProperty unsatClass : unsatObjProperties){ - Set<Set<OWLAxiom>> explanations = computeExplanations(unsatClass); - prop2Explanations.put(unsatClass, explanations); - } - - return prop2Explanations; - } - private OWLOntology getOntologyWithoutAnnotations(OWLOntology ontology){ try { OWLOntologyManager man = ontology.getOWLOntologyManager(); @@ -418,20 +429,26 @@ return ontology; } - private Set<Set<OWLAxiom>> computeExplanations(OWLClass unsatClass){ - PelletExplanation expGen = new PelletExplanation(getModule(unsatClass)); - return expGen.getUnsatisfiableExplanations(unsatClass, numberOfJustifications); + private Set<Set<OWLAxiom>> computeExplanations(OWLEntity unsatEntity){ + PelletExplanation expGen = new PelletExplanation(getModule(unsatEntity)); + if(unsatEntity instanceof OWLClass){ + return expGen.getUnsatisfiableExplanations((OWLClass) unsatEntity, numberOfJustifications); + } else if(unsatEntity instanceof OWLObjectProperty){ + return expGen.getUnsatisfiableExplanations(factory.getOWLObjectExactCardinality(1, (OWLObjectProperty)unsatEntity), numberOfJustifications); + } + return null; } - private Set<Set<OWLAxiom>> computeExplanations(OWLObjectProperty unsatProp){ - PelletExplanation expGen = new PelletExplanation(getModule(unsatProp)); - return expGen.getUnsatisfiableExplanations(factory.getOWLObjectExactCardinality(1, unsatProp), numberOfJustifications); + private Set<Set<OWLAxiom>> computeExplanations(OWLEntity unsatEntity, int limit){ + PelletExplanation expGen = new PelletExplanation(getModule(unsatEntity)); + if(unsatEntity instanceof OWLClass){ + return expGen.getUnsatisfiableExplanations((OWLClass) unsatEntity, limit); + } else if(unsatEntity instanceof OWLObjectProperty){ + return expGen.getUnsatisfiableExplanations(factory.getOWLObjectExactCardinality(1, (OWLObjectProperty)unsatEntity), limit); + } + return null; } - private Set<Set<OWLAxiom>> computeExplanations(OWLClass unsatClass, int limit){ - PelletExplanation expGen = new PelletExplanation(getModule(unsatClass)); - return expGen.getUnsatisfiableExplanations(unsatClass, numberOfJustifications); - } private Set<Set<OWLAxiom>> computeExplanationsBlackBox(OWLClass unsatClass, int limit){ BlackBoxExplanation singleExpGen = new BlackBoxExplanation(incoherentOntology, new HermiTReasonerFactory(), hermitReasoner); @@ -446,33 +463,33 @@ // return expGen.getUnsatisfiableExplanations(unsatClass, NUMBER_OF_JUSTIFICATIONS); // } - private OWLOntology getModule(OWLClass cls){ - OWLOntology module = cls2ModuleMap.get(cls); - new File("log").mkdir(); - if(module == null){ - md5.reset(); - md5.update((ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toString() + cls.toStringID()).getBytes()); - String hash = MD5.asHex(md5.digest()); - String filename = "log/" + hash + ".owl"; - File file = new File(filename); - if(file.exists()){ - module = loadModule(file); - } else { - module = OntologyUtils.getOntologyFromAxioms( - ModularityUtils.extractModule(incoherentOntology, Collections.singleton((OWLEntity)cls), ModuleType.TOP_OF_BOT)); - try { - manager.saveOntology(module, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream(filename))); - } catch (OWLOntologyStorageException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - cls2ModuleMap.put(cls, module); - } - return module; - } +// private OWLOntology getModule(OWLClass cls){ +// OWLOntology module = cls2ModuleMap.get(cls); +// new File("log").mkdir(); +// if(module == null){ +// md5.reset(); +// md5.update((ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toString() + cls.toStringID()).getBytes()); +// String hash = MD5.asHex(md5.digest()); +// String filename = "log/" + hash + ".owl"; +// File file = new File(filename); +// if(file.exists()){ +// module = loadModule(file); +// } else { +// module = OntologyUtils.getOntologyFromAxioms( +// ModularityUtils.extractModule(incoherentOntology, Collections.singleton((OWLEntity)cls), ModuleType.TOP_OF_BOT)); +// try { +// manager.saveOntology(module, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream(filename))); +// } catch (OWLOntologyStorageException e) { +// e.printStackTrace(); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } +// } +// +// cls2ModuleMap.put(cls, module); +// } +// return module; +// } private OWLOntology getModule(OWLEntity entity){ OWLOntology module = entity2ModuleMap.get(entity); @@ -531,12 +548,16 @@ // return prop2ModuleMap; // } - private <T extends OWLEntity> Map<T, OWLOntology> extractModules(Set<T> entities){ - Map<T, OWLOntology> entity2ModuleMap = new HashMap<T, OWLOntology>(); - for(T entity : entities){ + private Map<OWLEntity, OWLOntology> extractModules(Set<? extends OWLEntity> entities){ + logger.info("Computing modules..."); + long startTime = System.currentTimeMillis(); + Map<OWLEntity, OWLOntology> entity2ModuleMap = new HashMap<OWLEntity, OWLOntology>(); + for(OWLEntity entity : entities){ + logger.info(" for " + entity.toStringID()); OWLOntology module = getModule(entity); entity2ModuleMap.put(entity, module); } + logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return entity2ModuleMap; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-01 14:31:35
|
Revision: 3562 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3562&view=rev Author: lorenz_b Date: 2012-02-01 14:31:26 +0000 (Wed, 01 Feb 2012) Log Message: ----------- Started integration of debugging unsatisfiable object properties. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-01 11:36:50 UTC (rev 3561) +++ trunk/components-core/src/main/java/org/dllearner/utilities/JustificationBasedCoherentOntologyExtractor.java 2012-02-01 14:31:26 UTC (rev 3562) @@ -11,6 +11,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; @@ -29,10 +31,12 @@ import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLLogicalAxiom; +import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; +import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; import org.semanticweb.owlapi.model.RemoveAxiom; import org.semanticweb.owlapi.reasoner.IllegalConfigurationException; import org.semanticweb.owlapi.reasoner.OWLReasoner; @@ -47,6 +51,7 @@ import com.clarkparsia.owlapi.explanation.HSTExplanationGenerator; import com.clarkparsia.owlapi.explanation.PelletExplanation; import com.clarkparsia.owlapiv3.OntologyUtils; +import com.clarkparsia.pellet.owlapiv3.PelletReasoner; public class JustificationBasedCoherentOntologyExtractor implements CoherentOntologyExtractor{ @@ -62,10 +67,14 @@ private OWLDataFactory factory; private Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); + private Map<OWLEntity, OWLOntology> entity2ModuleMap = new HashMap<OWLEntity, OWLOntology>(); private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); MessageDigest md5; + private Set<OWLTransitiveObjectPropertyAxiom> removedTransitiveAxioms; + private Set<OWLObjectProperty> unsatObjectProperties; + public JustificationBasedCoherentOntologyExtractor() { try { md5 = MessageDigest.getInstance("MD5"); @@ -83,25 +92,34 @@ @Override public OWLOntology getCoherentOntology(OWLOntology ontology, boolean preferRoots){ - if(preferRoots){ - return computeCoherentOntologyRootBased(ontology); - } else { - return computeCoherentOntology(ontology); - } - } - - private OWLOntology computeCoherentOntologyRootBased(OWLOntology ontology) { this.ontology = ontology; this.incoherentOntology = getOntologyWithoutAnnotations(ontology); //only for debugging - ontology.getOWLOntologyManager().removeAxioms(ontology, ontology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY)); + removedTransitiveAxioms = ontology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY); + incoherentOntology.getOWLOntologyManager().removeAxioms(ontology, removedTransitiveAxioms); + manager = incoherentOntology.getOWLOntologyManager(); + factory = manager.getOWLDataFactory(); + long startTime = System.currentTimeMillis(); reasoner = new IncrementalClassifier(incoherentOntology); reasoner.classify(); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); + //compute the unsatisfiable object properties + unsatObjectProperties = getUnsatisfiableObjectProperties(reasoner); + + //start main process, either preferring root classes or not + if(preferRoots){ + return computeCoherentOntologyRootBased(incoherentOntology); + } else { + return computeCoherentOntology(incoherentOntology); + } + } + + private OWLOntology computeCoherentOntologyRootBased(OWLOntology ontology) { + // startTime = System.currentTimeMillis(); // hermitReasoner = new Reasoner(incoherentOntology); // hermitReasoner.classifyClasses(); @@ -113,7 +131,7 @@ //compute the unsatisfiable classes logger.info("Computing root/derived unsatisfiable classes..."); - startTime = System.currentTimeMillis(); + long startTime = System.currentTimeMillis(); StructureBasedRootClassFinder rootFinder = new StructureBasedRootClassFinder(reasoner); Set<OWLClass> unsatClasses = rootFinder.getRootUnsatisfiableClasses(); Set<OWLClass> derivedUnsatClasses = rootFinder.getDerivedUnsatisfiableClasses(); @@ -179,14 +197,7 @@ //save if(cnt - (rootCnt+derivedCnt) >= 10){ cnt = rootCnt + derivedCnt; - OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); - try { - toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_" + cnt + ".owl"))); - } catch (OWLOntologyStorageException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } + save("log/dbpedia_" + cnt + ".owl"); cnt = rootCnt + derivedCnt; } @@ -211,23 +222,9 @@ } private OWLOntology computeCoherentOntology(OWLOntology ontology) { - this.ontology = ontology; - this.incoherentOntology = getOntologyWithoutAnnotations(ontology); - - //only for debugging - ontology.getOWLOntologyManager().removeAxioms(ontology, ontology.getAxioms(AxiomType.TRANSITIVE_OBJECT_PROPERTY)); - - long startTime = System.currentTimeMillis(); - reasoner = new IncrementalClassifier(incoherentOntology); - reasoner.classify(); - logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - - OWLOntologyManager man = incoherentOntology.getOWLOntologyManager(); - factory = man.getOWLDataFactory(); - //compute the unsatisfiable classes logger.info("Computing unsatisfiable classes..."); - startTime = System.currentTimeMillis(); + long startTime = System.currentTimeMillis(); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); Set<OWLClass> unsatClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); int cnt = unsatClasses.size(); @@ -247,6 +244,7 @@ logger.info("Computing initial explanations..."); startTime = System.currentTimeMillis(); Map<OWLClass, Set<Set<OWLAxiom>>> cls2Explanations = getInitialExplanationsForUnsatClasses(unsatClasses); + Map<OWLObjectProperty, Set<Set<OWLAxiom>>> prop2Explanations = getInitialExplanationsForUnsatObjectProperties(unsatObjectProperties); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); while(!unsatClasses.isEmpty()){ @@ -261,8 +259,8 @@ //we remove the most frequent axiom from the ontology OWLAxiom toRemove = sortedEntries.get(0).getKey(); logger.info("Removing axiom " + toRemove + "."); - man.removeAxiom(incoherentOntology, toRemove); - man.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); + manager.removeAxiom(incoherentOntology, toRemove); + manager.applyChange(new RemoveAxiom(incoherentOntology, toRemove)); removeFromExplanations(cls2Explanations, toRemove); removeFromModules(toRemove); @@ -277,14 +275,7 @@ //save if(cnt - unsatClasses.size() >= 10){ cnt = unsatClasses.size(); - OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); - try { - toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream("log/dbpedia_" + cnt + ".owl"))); - } catch (OWLOntologyStorageException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } + save("log/dbpedia_" + cnt + ".owl"); } //recompute explanations if necessary @@ -307,6 +298,30 @@ return getOntologyWithAnnotations(incoherentOntology); } + private void save(String fileName){ + OWLOntology toSave = getOntologyWithAnnotations(incoherentOntology); + try { + toSave.getOWLOntologyManager().saveOntology(incoherentOntology, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream(fileName))); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private Set<OWLObjectProperty> getUnsatisfiableObjectProperties(IncrementalClassifier reasoner){ + SortedSet<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(); + OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); + for(OWLObjectProperty p : reasoner.getRootOntology().getObjectPropertiesInSignature()){ +// boolean satisfiable = reasoner.isSatisfiable(f.getOWLObjectExactCardinality(1, p)); + boolean satisfiable = reasoner.isSatisfiable(f.getOWLObjectSomeValuesFrom(p, factory.getOWLThing())); + if(!satisfiable){ + properties.add(p); + } + } + return properties; + } + private void removeFromModules(OWLAxiom axiom){ OWLOntology module; for(Entry<OWLClass, OWLOntology> entry : cls2ModuleMap.entrySet()){ @@ -366,6 +381,17 @@ return cls2Explanations; } + private Map<OWLObjectProperty, Set<Set<OWLAxiom>>> getInitialExplanationsForUnsatObjectProperties(Set<OWLObjectProperty> unsatObjProperties){ + Map<OWLObjectProperty, Set<Set<OWLAxiom>>> prop2Explanations = new HashMap<OWLObjectProperty, Set<Set<OWLAxiom>>>(); + + for(OWLObjectProperty unsatClass : unsatObjProperties){ + Set<Set<OWLAxiom>> explanations = computeExplanations(unsatClass); + prop2Explanations.put(unsatClass, explanations); + } + + return prop2Explanations; + } + private OWLOntology getOntologyWithoutAnnotations(OWLOntology ontology){ try { OWLOntologyManager man = ontology.getOWLOntologyManager(); @@ -397,6 +423,11 @@ return expGen.getUnsatisfiableExplanations(unsatClass, numberOfJustifications); } + private Set<Set<OWLAxiom>> computeExplanations(OWLObjectProperty unsatProp){ + PelletExplanation expGen = new PelletExplanation(getModule(unsatProp)); + return expGen.getUnsatisfiableExplanations(factory.getOWLObjectExactCardinality(1, unsatProp), numberOfJustifications); + } + private Set<Set<OWLAxiom>> computeExplanations(OWLClass unsatClass, int limit){ PelletExplanation expGen = new PelletExplanation(getModule(unsatClass)); return expGen.getUnsatisfiableExplanations(unsatClass, numberOfJustifications); @@ -415,7 +446,7 @@ // return expGen.getUnsatisfiableExplanations(unsatClass, NUMBER_OF_JUSTIFICATIONS); // } - private OWLOntology getModule(OWLClass cls){System.out.println(cls); + private OWLOntology getModule(OWLClass cls){ OWLOntology module = cls2ModuleMap.get(cls); new File("log").mkdir(); if(module == null){ @@ -443,6 +474,35 @@ return module; } + private OWLOntology getModule(OWLEntity entity){ + OWLOntology module = entity2ModuleMap.get(entity); + new File("log").mkdir(); + if(module == null){ + md5.reset(); + md5.update((ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology).toString() + entity.toStringID()).getBytes()); + String hash = MD5.asHex(md5.digest()); + String filename = "log/" + hash + ".owl"; + File file = new File(filename); + if(file.exists()){ + module = loadModule(file); + } else { + module = OntologyUtils.getOntologyFromAxioms( + ModularityUtils.extractModule(incoherentOntology, Collections.singleton(entity), ModuleType.TOP_OF_BOT)); + try { + manager.saveOntology(module, new RDFXMLOntologyFormat(), new BufferedOutputStream(new FileOutputStream(filename))); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + entity2ModuleMap.put(entity, module); + } + return module; + } + + private OWLOntology loadModule(File file){ OWLOntology module = null; try { @@ -453,13 +513,31 @@ return module; } - private Map<OWLClass, OWLOntology> extractModules(Set<OWLClass> classes){ - Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); - for(OWLClass cls : classes){ - OWLOntology module = getModule(cls); - cls2ModuleMap.put(cls, module); +// private Map<OWLClass, OWLOntology> extractModules(Set<OWLClass> classes){ +// Map<OWLClass, OWLOntology> cls2ModuleMap = new HashMap<OWLClass, OWLOntology>(); +// for(OWLClass cls : classes){ +// OWLOntology module = getModule(cls); +// cls2ModuleMap.put(cls, module); +// } +// return cls2ModuleMap; +// } +// +// private Map<OWLObjectProperty, OWLOntology> extractModules(Set<OWLObjectProperty> objectProperties){ +// Map<OWLObjectProperty, OWLOntology> prop2ModuleMap = new HashMap<OWLObjectProperty, OWLOntology>(); +// for(OWLObjectProperty prop : objectProperties){ +// OWLOntology module = getModule(prop); +// prop2ModuleMap.put(prop, module); +// } +// return prop2ModuleMap; +// } + + private <T extends OWLEntity> Map<T, OWLOntology> extractModules(Set<T> entities){ + Map<T, OWLOntology> entity2ModuleMap = new HashMap<T, OWLOntology>(); + for(T entity : entities){ + OWLOntology module = getModule(entity); + entity2ModuleMap.put(entity, module); } - return cls2ModuleMap; + return entity2ModuleMap; } public void setNumberOfJustifications(int numberOfJustifications) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-01 11:36:56
|
Revision: 3561 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3561&view=rev Author: lorenz_b Date: 2012-02-01 11:36:50 +0000 (Wed, 01 Feb 2012) Log Message: ----------- Added renderer for justifications. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/ApproximateDebugging.java trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/ApproximateDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/ApproximateDebugging.java 2012-02-01 11:35:39 UTC (rev 3560) +++ trunk/scripts/src/main/java/org/dllearner/scripts/ApproximateDebugging.java 2012-02-01 11:36:50 UTC (rev 3561) @@ -1,30 +1,34 @@ package org.dllearner.scripts; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; import java.util.Collections; -import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import org.apache.commons.compress.compressors.CompressorInputStream; +import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; -import org.dllearner.algorithm.qtl.util.ModelGenerator; -import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; -import org.dllearner.kb.sparql.SymmetricConciseBoundedDescriptionGeneratorImpl; import org.mindswap.pellet.PelletOptions; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; @@ -35,7 +39,6 @@ import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; import org.semanticweb.owlapi.model.OWLEntity; -import org.semanticweb.owlapi.model.OWLException; import org.semanticweb.owlapi.model.OWLIndividual; import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; @@ -48,7 +51,6 @@ import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import uk.ac.manchester.cs.owlapi.modularity.ModuleType; -import weka.attributeSelection.ConsistencySubsetEval; import com.clarkparsia.modularity.ModularityUtils; import com.clarkparsia.owlapi.explanation.PelletExplanation; @@ -84,6 +86,12 @@ public ApproximateDebugging(OWLOntology schema, OWLOntology data) throws OWLOntologyCreationException { this.schema = schema; this.data = data; + System.out.println(data.getLogicalAxiomCount()); + for(OWLAxiom ax : new HashSet<OWLAxiom>(data.getLogicalAxioms())){ + if(!ax.getDataPropertiesInSignature().isEmpty()){ + man.removeAxiom(data, ax); + } + }System.out.println(data.getLogicalAxiomCount()); Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); ontologies.add(schema); @@ -181,7 +189,8 @@ logger.info("done in " + (System.currentTimeMillis()-startTime) + "ms."); logger.info("Module size: " + module.size()); reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(OntologyUtils.getOntologyFromAxioms(module)); - expGen = new PelletExplanation(reasoner); +// expGen = new PelletExplanation(reasoner); + expGen = new PelletExplanation(schema, false); logger.info("Computing explanations..."); startTime = System.currentTimeMillis(); Set<Set<OWLAxiom>> temp = expGen.getUnsatisfiableExplanations(unsatClass, 10); @@ -231,9 +240,9 @@ } public Set<Set<OWLAxiom>> computeExplanationsDefault(int limit){ - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(schema); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); reasoner.isConsistent(); - logger.info("Computing inconsistency explanations with only Pellet..."); + logger.info("Computing inconsistency explanations with Pellet only..."); long startTime = System.currentTimeMillis(); PelletExplanation expGen = new PelletExplanation(reasoner); Set<Set<OWLAxiom>> explanations = expGen.getInconsistencyExplanations(limit); @@ -312,7 +321,7 @@ for(OWLObjectProperty prop : extractObjectProperties(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)){ OWLAxiom axiom = factory.getOWLFunctionalObjectPropertyAxiom(prop); - String queryString = "SELECT * WHERE {?s <%s> ?o1. ?s <%s> ?o2. FILTER(?o1 != ?o2)}".replace("%s", prop.toStringID()); + String queryString = "SELECT DISTINCT * WHERE {?s <%s> ?o1. ?s <%s> ?o2. FILTER(?o1 != ?o2)}".replace("%s", prop.toStringID()); Query query = QueryFactory.create(queryString) ; QueryExecution qexec = QueryExecutionFactory.create(query, model) ; try { @@ -427,6 +436,7 @@ for(OWLAxiom ax : ontology.getAxioms(axiomType)){ properties.add(((OWLObjectPropertyCharacteristicAxiom)ax).getProperty().asOWLObjectProperty()); } +// properties.retainAll(data.getObjectPropertiesInSignature()); return properties; } @@ -472,6 +482,11 @@ * @throws Exception */ public static void main(String[] args) throws Exception { + if(args.length != 1){ + System.out.println("Usage: ApproximateDebugging <Schema-Ontology>"); + System.exit(0); + } + Logger.getRootLogger().setLevel(Level.INFO); Logger.getRootLogger().removeAllAppenders(); Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); @@ -487,14 +502,55 @@ Model model = cbdGen.getConciseBoundedDescription(resource, 3); OWLOntology data = convert(model); + InputStream is = new BufferedInputStream(new FileInputStream(args[0])); + CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); - OWLOntology schema = man.loadOntologyFromOntologyDocument(new File("src/main/resources/dbpedia_0.75_no_datapropaxioms.owl")); + OWLOntology schema = man.loadOntologyFromOntologyDocument(in); ApproximateDebugging debug = new ApproximateDebugging(schema, data); + + Set<Set<OWLAxiom>> explanations2 = debug.computeExplanationsDefault(3); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + PrintWriter out = new PrintWriter( System.out ); + renderer.startRendering( out ); + for(Set<OWLAxiom> exp : explanations2){ + out.flush(); + renderer.render( Collections.singleton(exp) ); + } + renderer.endRendering(); + for(Entry<AxiomType<? extends OWLAxiom>, Integer> entry : getAxiomTypeCount(explanations2).entrySet()){ + System.out.println(entry.getKey() + ": " + entry.getValue()); + } + Set<Set<OWLAxiom>> explanations1 = debug.computeInconsistencyExplanations(); - Set<Set<OWLAxiom>> explanations2 = debug.computeExplanationsDefault(500); - System.out.println(explanations1.size()); - System.out.println(explanations2.size()); + for(Set<OWLAxiom> exp : explanations1){ + System.out.println(exp); + } + + for(Entry<AxiomType<? extends OWLAxiom>, Integer> entry : getAxiomTypeCount(explanations1).entrySet()){ + System.out.println(entry.getKey() + ": " + entry.getValue()); + } +// +// System.out.println(explanations1.size()); +// System.out.println(explanations2.size()); } + + private static Map<AxiomType<? extends OWLAxiom>, Integer> getAxiomTypeCount(Set<Set<OWLAxiom>> explanations){ + Map<AxiomType<? extends OWLAxiom>, Integer> axiomType2CountMap = new HashMap<AxiomType<? extends OWLAxiom>, Integer>(); + + for(Set<OWLAxiom> exp : explanations){ + for(OWLAxiom ax : exp){ + Integer cnt = axiomType2CountMap.get(ax.getAxiomType()); + if(cnt == null){ + cnt = Integer.valueOf(0); + } + cnt = Integer.valueOf(cnt + 1); + axiomType2CountMap.put(ax.getAxiomType(), cnt); + } + } + + return axiomType2CountMap; + } } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-02-01 11:35:39 UTC (rev 3560) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-02-01 11:36:50 UTC (rev 3561) @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; @@ -29,7 +30,6 @@ import java.util.TreeSet; import java.util.prefs.Preferences; -import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; @@ -54,6 +54,7 @@ import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLException; import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLIndividual; @@ -473,16 +474,32 @@ logger.info(exp + "\n"); } Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); - for(Set<OWLAxiom> explanation : explanations){ - logger.info(explanation); - for(OWLAxiom axiom : explanation){ - Integer cnt = axiomType2CountMap.get(axiom.getAxiomType()); - if(cnt == null){ - cnt = Integer.valueOf(0); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + try { + FileWriter out = new FileWriter( "log/justifications.txt" ); + renderer.startRendering(out ); + for(Set<OWLAxiom> explanation : explanations){ + logger.info(explanation); + out.flush(); + try { + renderer.render( Collections.singleton(explanation) ); + } catch (UnsupportedOperationException e) { + e.printStackTrace(); + } catch (OWLException e) { + e.printStackTrace(); } - cnt = Integer.valueOf(cnt + 1); - axiomType2CountMap.put(axiom.getAxiomType(), cnt); + for(OWLAxiom axiom : explanation){ + Integer cnt = axiomType2CountMap.get(axiom.getAxiomType()); + if(cnt == null){ + cnt = Integer.valueOf(0); + } + cnt = Integer.valueOf(cnt + 1); + axiomType2CountMap.put(axiom.getAxiomType(), cnt); + } } + renderer.endRendering(); + } catch (IOException e) { + e.printStackTrace(); } logger.info("Axiom type count:"); for(Entry<AxiomType, Integer> entry : axiomType2CountMap.entrySet()){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-02-01 11:35:45
|
Revision: 3560 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3560&view=rev Author: lorenz_b Date: 2012-02-01 11:35:39 +0000 (Wed, 01 Feb 2012) Log Message: ----------- Added method to get all super classes. Add option to omit existing SubClassOf axioms. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2012-01-27 11:55:41 UTC (rev 3559) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/SimpleSubclassLearner.java 2012-02-01 11:35:39 UTC (rev 3560) @@ -126,7 +126,23 @@ //get existing super classes SortedSet<Description> existingSuperClasses = reasoner.getSuperClasses(classToDescribe); if(!existingSuperClasses.isEmpty()){ + SortedSet<Description> inferredSuperClasses = new TreeSet<Description>(); + for(Description assertedSup : existingSuperClasses){ + if(reasoner.isPrepared()){ + if(reasoner.getClassHierarchy().contains(assertedSup)){ + for(Description inferredSup : reasoner.getClassHierarchy().getSuperClasses(assertedSup, false)){ + inferredSuperClasses.add(inferredSup); + } + } + } else { + inferredSuperClasses.add(assertedSup); + } + } + existingSuperClasses.addAll(inferredSuperClasses); logger.info("Existing super classes: " + existingSuperClasses); + for(Description sup : existingSuperClasses){ + existingAxioms.add(new SubClassAxiom(classToDescribe, sup)); + } } Map<Individual, SortedSet<Description>> ind2Types = new HashMap<Individual, SortedSet<Description>>(); @@ -226,9 +242,10 @@ SimpleSubclassLearner l = new SimpleSubclassLearner(ks); l.setReasoner(reasoner); + l.setReturnOnlyNewAxioms(true); ConfigHelper.configure(l, "maxExecutionTimeInSeconds", 10); - l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/Olympics")); + l.setClassToDescribe(new NamedClass("http://dbpedia.org/ontology/SoccerClub")); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2012-01-27 11:55:41 UTC (rev 3559) +++ trunk/components-core/src/main/java/org/dllearner/core/owl/ClassHierarchy.java 2012-02-01 11:35:39 UTC (rev 3560) @@ -111,6 +111,20 @@ // return (TreeSet<Description>) subsumptionHierarchyDown.get(concept).clone(); // } } + + public SortedSet<Description> getSuperClasses(Description concept, boolean direct) { + SortedSet<Description> result = subsumptionHierarchyUp.get(concept); + if(result == null) { + logger.error("Query for super class of " + concept + " in subsumption hierarchy, but the class is not contained in the (downward) hierarchy, e.g. because the class does not exist or is ignored. Returning empty result instead."); + return new TreeSet<Description>(); + } + result.remove(concept); + for(Description sub : new HashSet<Description>(result)){ + result.addAll(getSuperClasses(sub, false)); + } + + return new TreeSet<Description>(result); + } /** * Computes the siblings of the specified descriptions. Siblings are all those This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-01-27 11:55:52
|
Revision: 3559 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3559&view=rev Author: lorenz_b Date: 2012-01-27 11:55:41 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Option to load bzip2 compressed. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-01-27 11:51:28 UTC (rev 3558) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-01-27 11:55:41 UTC (rev 3559) @@ -714,10 +714,11 @@ } InputStream is = new BufferedInputStream(new FileInputStream(args[0])); - CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + if(args[0].endsWith("bz2")){ + is = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + } + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(is); - OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(in); - SPARQLSampleDebugging debug = new SPARQLSampleDebugging(endpoint); // debug.checkFunctionalityViolation(ontology); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-01-27 11:51:34
|
Revision: 3558 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3558&view=rev Author: lorenz_b Date: 2012-01-27 11:51:28 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Small update. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-01-26 13:43:13 UTC (rev 3557) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-01-27 11:51:28 UTC (rev 3558) @@ -1,8 +1,9 @@ package org.dllearner.scripts; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -28,6 +29,8 @@ import java.util.TreeSet; import java.util.prefs.Preferences; +import org.apache.commons.compress.compressors.CompressorInputStream; +import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; @@ -35,7 +38,8 @@ import org.apache.log4j.SimpleLayout; import org.dllearner.algorithm.qtl.util.ModelGenerator; import org.dllearner.algorithm.qtl.util.ModelGenerator.Strategy; -import org.dllearner.core.owl.IrreflexiveObjectPropertyAxiom; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGenerator; +import org.dllearner.kb.sparql.ConciseBoundedDescriptionGeneratorImpl; import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; @@ -52,14 +56,18 @@ import org.semanticweb.owlapi.model.OWLDataProperty; import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLIndividual; import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyCharacteristicAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLOntologyManager; import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.reasoner.InferenceType; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + import com.clarkparsia.owlapi.explanation.PelletExplanation; import com.clarkparsia.owlapi.explanation.io.manchester.ManchesterSyntaxExplanationRenderer; import com.clarkparsia.pellet.owlapiv3.PelletReasoner; @@ -85,9 +93,9 @@ private ExtractionDBCache cache = new ExtractionDBCache("cache"); private int sampleSize = 10; - private int depth = 2; + private int depth = 3; private int nrOfChunks = 1; - private int maxNrOfExplanations = 20; + private int maxNrOfExplanations = 10; private Logger logger = Logger.getLogger(SPARQLSampleDebugging.class); @@ -98,6 +106,8 @@ private Connection conn; private PreparedStatement ps; + private OWLDataFactory factory = new OWLDataFactoryImpl(); + static {PelletExplanation.setup();} public SPARQLSampleDebugging(SparqlEndpoint endpoint) { @@ -184,7 +194,7 @@ for(int i = 0; i < nrOfChunks; i++){ int offset = (int)(Math.random() * max); - offset = Math.min(offset, offset-(size/nrOfChunks)); + offset = Math.min(offset, offset-(size/nrOfChunks));offset = 236242; query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT %d OFFSET %d", (size/nrOfChunks), offset); logger.info(query); @@ -236,10 +246,11 @@ private OWLOntology extractSampleModule(String resource){ logger.info("Extracting sample module..."); long startTime = System.currentTimeMillis(); - ModelGenerator modelGen = new ModelGenerator(endpoint, cache); - Model model = modelGen.createModel(resource, Strategy.CHUNKS, depth); + ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(endpoint, cache); + Model model = cbdGen.getConciseBoundedDescription(resource, 3); + OWLOntology data = convert(model); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - return convert(model); + return data; } @@ -257,7 +268,13 @@ logger.info("Computing explanations..."); long startTime = System.currentTimeMillis(); PelletExplanation expGen = new PelletExplanation(reasoner); - Set<Set<OWLAxiom>> explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); + Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(maxNrOfExplanations); + try { + explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); + } catch (Exception e) { + e.printStackTrace(); + logger.error(e); + } logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return explanations; } @@ -279,7 +296,7 @@ long startTime = System.currentTimeMillis(); logger.info("Loading reference ontology..."); OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument( - getClass().getClassLoader().getResourceAsStream("dbpedia_0.75_no_datapropaxioms.owl"));System.out.println(ontology.getLogicalAxiomCount()); + getClass().getClassLoader().getResourceAsStream("dbpedia_0.75_no_datapropaxioms.owl")); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return ontology; } @@ -435,16 +452,26 @@ OWLOntologyManager man = OWLManager.createOWLOntologyManager(); man.addOntologyChangeListener( reasoner ); Set<String> resources = extractSampleResourcesChunked(sampleSize); + Model model; for(String resource : resources){ - logger.info("Resource " + resource);resource = "http://dbpedia.org/resource/The_Man_Who_Wouldn%27t_Die"; - module = extractSampleModule(Collections.singleton(resource));computeExplanations(convert(module).add(convert(extractSampleModule(resource)))); + logger.info("###################################################################"); + logger.info("Resource " + resource);//resource = "http://dbpedia.org/resource/The_Man_Who_Wouldn%27t_Die"; + module = extractSampleModule(resource); man.addAxioms(reference, module.getABoxAxioms(true)); + man.removeAxioms(reference, reference.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)); boolean isConsistent = reasoner.isConsistent(); logger.info("Consistent: " + isConsistent); Set<Set<OWLAxiom>> explanations = null; if(!isConsistent){ explanations = computeExplanations(reasoner); + model = convert(reference); + explanations.addAll(computeInconsistencyExplanationsByAsymmetryPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByIrreflexivityPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByFunctionalityPattern(reference, model)); logger.info("Found " + explanations.size() + " explanations."); + for(Set<OWLAxiom> exp : explanations){ + logger.info(exp + "\n"); + } Map<AxiomType, Integer> axiomType2CountMap = new HashMap<AxiomType, Integer>(); for(Set<OWLAxiom> explanation : explanations){ logger.info(explanation); @@ -457,13 +484,14 @@ axiomType2CountMap.put(axiom.getAxiomType(), cnt); } } + logger.info("Axiom type count:"); for(Entry<AxiomType, Integer> entry : axiomType2CountMap.entrySet()){ logger.info(entry.getKey() + "\t: " + entry.getValue()); } } man.removeAxioms(reference, module.getABoxAxioms(true)); // writeToDB(resource, module.getLogicalAxiomCount(), isConsistent, explanations); - break; +// break; } } @@ -501,10 +529,7 @@ } finally { qexec.close() ; } } - public void checkFunctionalityViolation(){ - try { - OWLOntology ontology = loadReferenceOntology(); - + public void checkFunctionalityViolation(OWLOntology ontology){ Set<String> properties = new TreeSet<String>(); for(OWLAxiom ax : ontology.getAxioms(AxiomType.FUNCTIONAL_OBJECT_PROPERTY)){ OWLObjectProperty prop = ((OWLFunctionalObjectPropertyAxiom)ax).getProperty().asOWLObjectProperty(); @@ -526,16 +551,9 @@ } } - } catch (OWLOntologyCreationException e) { - e.printStackTrace(); - } - } - public void checkIrreflexivityViolation(){ - try { - OWLOntology ontology = loadReferenceOntology(); - + public void checkIrreflexivityViolation(OWLOntology ontology){ Set<String> properties = new TreeSet<String>(); for(OWLAxiom ax : ontology.getAxioms(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY)){ OWLObjectProperty prop = ((OWLIrreflexiveObjectPropertyAxiom)ax).getProperty().asOWLObjectProperty(); @@ -552,16 +570,9 @@ } } - } catch (OWLOntologyCreationException e) { - e.printStackTrace(); - } - } - public void checkAsymmetryViolation(){ - try { - OWLOntology ontology = loadReferenceOntology(); - + public void checkAsymmetryViolation(OWLOntology ontology){ Set<String> properties = new TreeSet<String>(); for(OWLAxiom ax : ontology.getAxioms(AxiomType.ASYMMETRIC_OBJECT_PROPERTY)){ OWLObjectProperty prop = ((OWLAsymmetricObjectPropertyAxiom)ax).getProperty().asOWLObjectProperty(); @@ -578,11 +589,102 @@ } } - } catch (OWLOntologyCreationException e) { - e.printStackTrace(); + } + + private Set<Set<OWLAxiom>> computeInconsistencyExplanationsByFunctionalityPattern(OWLOntology ontology, Model model){ + Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(); + + for(OWLObjectProperty prop : extractObjectProperties(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, ontology)){ + OWLAxiom axiom = factory.getOWLFunctionalObjectPropertyAxiom(prop); + String queryString = "SELECT DISTINCT * WHERE {?s <%s> ?o1. ?s <%s> ?o2. FILTER(?o1 != ?o2)}".replace("%s", prop.toStringID()); + Query query = QueryFactory.create(queryString) ; + QueryExecution qexec = QueryExecutionFactory.create(query, model) ; + try { + ResultSet results = qexec.execSelect(); + for (; results.hasNext();) { + Set<OWLAxiom> explanation = new HashSet<OWLAxiom>(); + explanation.add(axiom); + QuerySolution qs = results.next(); + OWLIndividual subject = factory.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); + OWLIndividual object1 = factory.getOWLNamedIndividual(IRI.create(qs.getResource("o1").getURI())); + OWLIndividual object2 = factory.getOWLNamedIndividual(IRI.create(qs.getResource("o2").getURI())); + OWLAxiom ax = factory.getOWLObjectPropertyAssertionAxiom(prop, subject, object1); + explanation.add(ax); + ax = factory.getOWLObjectPropertyAssertionAxiom(prop, subject, object2); + explanation.add(ax); + explanations.add(explanation); + } + } finally { + qexec.close(); + } } + return explanations; } + private Set<Set<OWLAxiom>> computeInconsistencyExplanationsByAsymmetryPattern(OWLOntology ontology, Model model){ + Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(); + + for(OWLObjectProperty prop : extractObjectProperties(AxiomType.ASYMMETRIC_OBJECT_PROPERTY, ontology)){ + OWLAxiom axiom = factory.getOWLAsymmetricObjectPropertyAxiom(prop); + String queryString = "SELECT * WHERE {?s <%s> ?o. ?o <%s> ?s. FILTER(?o != ?s)}".replace("%s", prop.toStringID()); + Query query = QueryFactory.create(queryString) ; + QueryExecution qexec = QueryExecutionFactory.create(query, model) ; + try { + ResultSet results = qexec.execSelect(); + for (; results.hasNext();) { + Set<OWLAxiom> explanation = new HashSet<OWLAxiom>(); + explanation.add(axiom); + QuerySolution qs = results.nextSolution(); + OWLIndividual subject = factory.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); + OWLIndividual object = factory.getOWLNamedIndividual(IRI.create(qs.getResource("o").getURI())); + OWLAxiom ax = factory.getOWLObjectPropertyAssertionAxiom(prop, subject, object); + explanation.add(ax); + ax = factory.getOWLObjectPropertyAssertionAxiom(prop, object, subject); + explanation.add(ax); + explanations.add(explanation); + } + } finally { + qexec.close(); + } + } + return explanations; + } + + private Set<Set<OWLAxiom>> computeInconsistencyExplanationsByIrreflexivityPattern(OWLOntology ontology, Model model){ + Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(); + + for(OWLObjectProperty prop : extractObjectProperties(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, ontology)){ + OWLAxiom axiom = factory.getOWLIrreflexiveObjectPropertyAxiom(prop); + String queryString = "SELECT * WHERE {?s <%s> ?s.}".replace("%s", prop.toStringID()); + Query query = QueryFactory.create(queryString) ; + QueryExecution qexec = QueryExecutionFactory.create(query, model) ; + try { + ResultSet results = qexec.execSelect(); + for (; results.hasNext();) { + Set<OWLAxiom> explanation = new HashSet<OWLAxiom>(); + explanation.add(axiom); + QuerySolution qs = results.nextSolution(); + OWLIndividual subject = factory.getOWLNamedIndividual(IRI.create(qs.getResource("s").getURI())); + OWLAxiom ax = factory.getOWLObjectPropertyAssertionAxiom(prop, subject, subject); + explanation.add(ax); + explanations.add(explanation); + } + } finally { + qexec.close(); + } + } + return explanations; + } + + private SortedSet<OWLObjectProperty> extractObjectProperties(AxiomType<? extends OWLAxiom> axiomType, OWLOntology ontology){ + SortedSet<OWLObjectProperty> properties = new TreeSet<OWLObjectProperty>(); + for(OWLAxiom ax : ontology.getAxioms(axiomType)){ + properties.add(((OWLObjectPropertyCharacteristicAxiom)ax).getProperty().asOWLObjectProperty()); + } +// properties.retainAll(data.getObjectPropertiesInSignature()); + return properties; + } + public void removeAxiomsWithNamespace(Set<String> namespaces){ } @@ -611,24 +713,28 @@ System.exit(0); } - OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(IRI.create(new File(args[0]).toURI())); + InputStream is = new BufferedInputStream(new FileInputStream(args[0])); + CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(in); + SPARQLSampleDebugging debug = new SPARQLSampleDebugging(endpoint); - debug.checkFunctionalityViolation(); - debug.checkAsymmetryViolation(); - debug.checkIrreflexivityViolation(); +// debug.checkFunctionalityViolation(ontology); +// debug.checkAsymmetryViolation(ontology); +// debug.checkIrreflexivityViolation(ontology); long s1 = System.currentTimeMillis(); debug.runOptimized(ontology); long s2 = System.currentTimeMillis()-s1; + System.out.println(s2); - long s3 = System.currentTimeMillis(); + /*long s3 = System.currentTimeMillis(); debug.run(ontology); long s4 = System.currentTimeMillis()-s3; System.out.println(s2); - System.out.println(s4); + System.out.println(s4);*/ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |