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-04-11 12:29:57
|
Revision: 3631 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3631&view=rev Author: sebastianwtr Date: 2012-04-11 12:29:50 +0000 (Wed, 11 Apr 2012) Log Message: ----------- [tbsl exploration] fixed some small bugs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -85,6 +85,8 @@ public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ HashMap<String,Float> hm = new HashMap<String,Float>(); + System.err.println("########"); + System.err.println("In search Index for Property"); // adding or set elements in Map by put method key and value pair /* @@ -100,15 +102,19 @@ String result=null; ArrayList<String> result_List = new ArrayList<String>(); result=myindex.getPropertyURI(string.toLowerCase()); + System.err.println("Result: "+result); if(result!=null){ result_List.add(result); hm.put(result, 1.0f); + System.err.println("Found uri for: "+string.toLowerCase()); } else{ + System.err.println("Didnt find uri for: "+string.toLowerCase()); result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); hm.put(result, 0.0f); } + System.err.println("########"); return result_List; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -135,12 +135,54 @@ public String getPropertyURI(String string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; + ArrayList<String> al = new ArrayList<String>(); try { rs = stat.executeQuery("select uri from property where name='"+string.toLowerCase()+"';"); - return rs.getString("uri"); + while(rs.next()){ + String result_string= rs.getString("uri"); + System.out.println("Property: "+result_string); + //check for double: + boolean found = false; + for(String s: al){ + if(s.equals(result_string))found=true; + } + if(found==false)al.add(result_string); + } + + rs = stat.executeQuery("select uri from ontology where name='"+string.toLowerCase()+"';"); + while(rs.next()){ + String result_string= rs.getString("uri"); + System.out.println("OntologyProperty: "+result_string); + //check for double: + boolean found = false; + for(String s: al){ + if(s.equals(result_string))found=true; + } + if(found==false)al.add(result_string); + } + System.out.println("Anzahl ArrayList: "+al.size()); + if(al.size()==1) return al.get(0); + //check if there is one with an ontology in it + else{ + boolean found = false; + for(String s : al){ + if(s.contains("ontology")){ + System.out.println("Return String: "+s); + found=true; + return s; + } + } + if(found==false){ + System.out.println("Return String: "+al.get(0)); + return al.get(0); + } + } + + return null; } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); + System.err.println("Error in SQLiteIndex.getProperty!!"); return null; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -227,12 +227,12 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - System.out.println("Alle Hypothesen VOR der Verarbeitung"); + /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); - + */ for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource @@ -279,14 +279,14 @@ } } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + /* System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); - + */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* @@ -327,13 +327,14 @@ * BUGFIX: Before adding Hypothesis to template check, if each Hypothesis has an uri * TODO: check all functions before */ - /*for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ + for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ for(Hypothesis h : al){ if(!h.getUri().contains("http")){ if(h.getType().contains("ISA")){ try { ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); - h.setUri(tmp.get(0)); + System.out.println("Laenge tmp: "+tmp.size()); + if(tmp.size()>0)h.setUri(tmp.get(0)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -343,7 +344,8 @@ if(h.getType().contains("RESOURCE")){ try { ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); - h.setUri(tmp.get(0)); + System.out.println("Laenge tmp: "+tmp.size()); + if(tmp.size()>0)h.setUri(tmp.get(0)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -353,8 +355,8 @@ } } } - */ - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + + /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); @@ -362,9 +364,9 @@ } System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); + */ - template.setHypothesen(final_list_set_hypothesis); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -295,6 +295,10 @@ String temp = m.group(1); temp = temp.replace("\"@en",""); temp = temp.replace("\"",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#date>",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#int>",""); + temp = temp.replace("^^<http://www.w3.org/2001/XMLSchema#number>",""); + temp = temp.replace("\"",""); //result.add(m.group(1)); result.add(temp); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -199,6 +199,7 @@ else{ //else go_on=false; go_on=true; + //go_on=false; for(String s : answer_tmp){ if(checkAnswer(s)){ boolean test = false; @@ -224,7 +225,7 @@ private static boolean checkAnswer(String answer){ - if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")) return false; + if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")||answer.contains("flickerwrappr/photos/")) return false; else return true; } 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-04-09 18:27:16 UTC (rev 3630) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-11 12:29:50 UTC (rev 3631) @@ -90,12 +90,12 @@ /*System.out.println("Please enter Path of xml File:"); line=in.readLine();*/ - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; - //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; - line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); @@ -260,6 +260,7 @@ if(i.contains("http")) input="<uri>"+i+"</uri>\n"; else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else if(i.matches("[0-9]*-[0-9][0-9]-[0-9]*"))input="<date>"+i+"</date>\n"; else input="<string>"+i+"</string>\n"; tmp+="<answer>"+input+"</answer>\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-04-09 18:27:22
|
Revision: 3630 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3630&view=rev Author: dcherix Date: 2012-04-09 18:27:16 +0000 (Mon, 09 Apr 2012) Log Message: ----------- Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-04-09 18:26:42 UTC (rev 3629) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-04-09 18:27:16 UTC (rev 3630) @@ -1,6 +1,6 @@ package org.dllearner.kb.sparql.simple; -//import org.nlp2rdf.ontology.ClassIndexer; +import org.nlp2rdf.ontology.ClassIndexer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,24 +9,28 @@ public class SchemaIndexer { private static Logger log = LoggerFactory.getLogger(SchemaIndexer.class); -// private ClassIndexer classIndexer=null; + private ClassIndexer classIndexer=null; public SchemaIndexer(){} public void init(){ -// classIndexer=new ClassIndexer(); + classIndexer=new ClassIndexer(); OntModel model = ModelFactory.createOntologyModel(); - model.read(SchemaIndexer.class.getResourceAsStream("dbpedia_3-3.6.owl"), null); -// classIndexer.index(model); + model.read(SchemaIndexer.class.getClassLoader().getResourceAsStream("dbpedia_3.6.owl"), null); + classIndexer.index(model); } public OntModel getHierarchyForURI(String classUri){ -// if(classIndexer==null){ -// this.init(); -// } -// return classIndexer.getHierarchyForClassURI(classUri); - return null; + if(classIndexer==null){ + this.init(); + } + return classIndexer.getHierarchyForClassURI(classUri); } + public static void main(String...args){ + SchemaIndexer i= new SchemaIndexer(); + System.out.println(i.getHierarchyForURI("http://dbpedia.org/ontology/Software")); + } + } \ No newline at end of file Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-09 18:26:42 UTC (rev 3629) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-04-09 18:27:16 UTC (rev 3630) @@ -1,7 +1,10 @@ package org.dllearner.kb.sparql.simple; +import java.io.File; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Set; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; @@ -11,151 +14,225 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.jamonapi.Monitor; +import com.jamonapi.MonitorFactory; @ComponentAnn(name = "efficient SPARQL fragment extractor", shortName = "sparqls", version = 0.1) public class SparqlSimpleExtractor implements KnowledgeSource { - - @ConfigOption(name = "endpointURL", description = "URL of the SPARQL endpoint", required = true) - private String endpointURL = null; - private OntModel model = null; - @ConfigOption(name = "instances", description = "List of the instances to use", required = true) - private List<String> instances = null; - @ConfigOption(name = "filters", description = "List of the filters to use", required = true) - private List<String> filters = null; - @ConfigOption(name = "recursionDepth", description = "recursion depth", required = true) - private int recursionDepth = 0; - + + @ConfigOption(name = "endpointURL", description = "URL of the SPARQL endpoint", required = true) + private String endpointURL = null; + private OntModel model = null; + @ConfigOption(name = "instances", description = "List of the instances to use", required = true) + private List<String> instances = null; + @ConfigOption(name = "filters", description = "List of the filters to use", required = true) + private List<String> filters = null; + @ConfigOption(name = "recursionDepth", description = "recursion depth", required = true) + private int recursionDepth = 0; + @ConfigOption(name = "defaultGraphURI", description = "default graph URI", required = true) - private String defaultGraphURI=null; - private OWLOntology owlOntology; - - private static Logger log = LoggerFactory.getLogger(SparqlSimpleExtractor.class); - - public SparqlSimpleExtractor() { - model = ModelFactory.createOntologyModel(); - } - - /** - * @param args - * @throws ComponentInitException - */ - public static void main(String[] args) throws ComponentInitException { - SparqlSimpleExtractor extractor = new SparqlSimpleExtractor(); - // extractor.init(); - List<String> individuals = new LinkedList<String>(); - individuals.add("People"); - individuals.add("Animals"); - extractor.setInstances(individuals); - // System.out.println(extractor.createQuery()); - } - - @Override - public void init() throws ComponentInitException { - if (endpointURL == null) { - throw new ComponentInitException("Parameter endpoint URL is required"); - } - if (instances == null) { - throw new ComponentInitException("Parameter instances is required"); - } - if (recursionDepth == 0) { - throw new ComponentInitException( - "A value bigger than 0 is required for parameter recursionDepth"); - } - ABoxQueryGenerator aGenerator = new ABoxQueryGenerator(); - QueryExecutor executor = new QueryExecutor(); - String queryString; - for (int i = 0; i < recursionDepth - 1; i++) { - queryString=aGenerator.createQuery(instances, model, filters); - log.info("SPARQL: {}", queryString); - executor.executeQuery(queryString, endpointURL, model,defaultGraphURI); - } - queryString = aGenerator.createLastQuery(instances, model, filters); - log.info("SPARQL: {}", queryString); - - executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); - TBoxQueryGenerator tGenerator = new TBoxQueryGenerator(); - queryString = tGenerator.createQuery(model, filters, instances); - executor.executeQuery(queryString, endpointURL, model,defaultGraphURI); - JenaToOwlapiConverter converter = new JenaToOwlapiConverter(); - owlOntology=converter.convert(this.model); - } - - public String getEndpointURL() { - return endpointURL; - } - - public void setEndpointURL(String endpointURL) { - this.endpointURL = endpointURL; - } - - public String getDefaultGraphURI() { + private String defaultGraphURI = null; + @ConfigOption(name = "sparqlQuery", description = "Sparql Query", required = false) + private String sparqlQuery = null; + @ConfigOption(name = "ontologyFile", description = "Ontology Schema File", required = true) + private File ontologyFile = null; + private OWLOntology owlOntology; + private SchemaIndexer indexer; + + private static Logger log = LoggerFactory + .getLogger(SparqlSimpleExtractor.class); + + public SparqlSimpleExtractor() { + model = ModelFactory.createOntologyModel(); + } + + /** + * @param args + * @throws ComponentInitException + */ + public static void main(String[] args) throws ComponentInitException { + SparqlSimpleExtractor extractor = new SparqlSimpleExtractor(); + extractor.setEndpointURL("http://live.dbpedia.org/sparql"); + extractor.setRecursionDepth(1); + extractor.setDefaultGraphURI("http://dbpedia.org"); + List<String> instances = new ArrayList<String>(7); + instances.add("http://dbpedia.org/resource/Democritus"); + instances.add("http://dbpedia.org/resource/Zeno_of_Elea"); + instances.add("http://dbpedia.org/resource/Plato"); + instances.add("http://dbpedia.org/resource/Socrates"); + instances.add("http://dbpedia.org/resource/Archytas"); + instances.add("http://dbpedia.org/resource/Pythagoras"); + instances.add("http://dbpedia.org/resource/Philolaus"); + + extractor.setInstances(instances); + extractor.init(); + List<String> individuals = new LinkedList<String>(); + individuals.add("People"); + individuals.add("Animals"); + extractor.setInstances(individuals); + // System.out.println(extractor.createQuery()); + } + + @Override + public void init() throws ComponentInitException { + if (endpointURL == null) { + throw new ComponentInitException( + "Parameter endpoint URL is required"); + } + if (instances == null) { + throw new ComponentInitException("Parameter instances is required"); + } + if (recursionDepth == 0) { + throw new ComponentInitException( + "A value bigger than 0 is required for parameter recursionDepth"); + } + if (ontologyFile == null) { + throw new ComponentInitException( + "An ontology schema description file (ontologyFile) in RDF ist required"); + } + Monitor monComp = MonitorFactory.start("Simple SPARQL Component") + .start(); + Monitor monIndexer = MonitorFactory.start("Schema Indexer").start(); + indexer = new SchemaIndexer(); + indexer.init(); + monIndexer.stop(); + + Monitor monAquery; + Monitor monQuerying; + QueryExecutor executor = new QueryExecutor(); + String queryString; + if (sparqlQuery == null) { + ABoxQueryGenerator aGenerator = new ABoxQueryGenerator(); + for (int i = 0; i < recursionDepth - 1; i++) { + monAquery = MonitorFactory.getTimeMonitor("A query generator") + .start(); + queryString = aGenerator.createQuery(instances, model, filters); + monAquery.stop(); + log.debug("SPARQL: {}", queryString); + monQuerying = MonitorFactory.start("Querying"); + executor.executeQuery(queryString, endpointURL, model, + defaultGraphURI); + monQuerying.stop(); + } + monAquery = MonitorFactory.getTimeMonitor("A query generator") + .start(); + queryString = aGenerator.createLastQuery(instances, model, filters); + monAquery.stop(); + log.debug("SPARQL: {}", queryString); + monQuerying = MonitorFactory.start("Querying"); + executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); + monQuerying.stop(); + } else { + monQuerying=MonitorFactory.getTimeMonitor("Querying").start(); + executor.executeQuery(sparqlQuery, endpointURL, model); + monQuerying.stop(); + } + + + TBoxQueryGenerator tGenerator = new TBoxQueryGenerator(); + Monitor monTquery = MonitorFactory.getTimeMonitor("T query generator") + .start(); + queryString = tGenerator.createQuery(model, filters, instances); + monTquery.stop(); + monQuerying = MonitorFactory.start("Querying"); + executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); + monQuerying.stop(); + Set<OntClass> classes = model.listClasses().toSet(); + for (OntClass ontClass : classes) { + OntModel hierarchy = indexer.getHierarchyForURI(ontClass.getURI()); + if (hierarchy != null) { + model.add(hierarchy); + log.debug("{}", model); + } + } + JenaToOwlapiConverter converter = new JenaToOwlapiConverter(); + owlOntology = converter.convert(this.model); + monComp.stop(); + log.info("*******Simple SPARQL Extractor********"); + for (Monitor monitor : MonitorFactory.getRootMonitor().getMonitors()) { + log.info("* {} *", monitor); + } + log.info("**************************************"); + } + + public String getEndpointURL() { + return endpointURL; + } + + public void setEndpointURL(String endpointURL) { + this.endpointURL = endpointURL; + } + + public String getDefaultGraphURI() { return defaultGraphURI; } public void setDefaultGraphURI(String defaultGraphURI) { this.defaultGraphURI = defaultGraphURI; - } - - public Model getModel() { - return model; - } - - public void setModel(OntModel model) { - this.model = model; - } - - /** - * @return the filters - */ - public List<String> getFilters() { - return filters; - } - - /** - * @param filters - * the filters to set - */ - public void setFilters(List<String> filters) { - this.filters = filters; - } + } - /** - * @return the instances - */ - public List<String> getInstances() { - return instances; - } + public Model getModel() { + return model; + } - /** - * @param instances the instances to set - */ - public void setInstances(List<String> instances) { - this.instances = instances; - } + public void setModel(OntModel model) { + this.model = model; + } - /** - * @return the recursionDepth - */ - public int getRecursionDepth() { - return recursionDepth; - } + /** + * @return the filters + */ + public List<String> getFilters() { + return filters; + } - /** - * @param recursionDepth the recursionDepth to set - */ - public void setRecursionDepth(int recursionDepth) { - this.recursionDepth = recursionDepth; - } + /** + * @param filters + * the filters to set + */ + public void setFilters(List<String> filters) { + this.filters = filters; + } + /** + * @return the instances + */ + public List<String> getInstances() { + return instances; + } - /** - * @return - */ - public OWLOntology getOWLOntology() { - return owlOntology; - } - + /** + * @param instances + * the instances to set + */ + public void setInstances(List<String> instances) { + this.instances = instances; + } + + /** + * @return the recursionDepth + */ + public int getRecursionDepth() { + return recursionDepth; + } + + /** + * @param recursionDepth + * the recursionDepth to set + */ + public void setRecursionDepth(int recursionDepth) { + this.recursionDepth = recursionDepth; + } + + /** + * @return + */ + public OWLOntology getOWLOntology() { + return owlOntology; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-04-09 18:26:48
|
Revision: 3629 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3629&view=rev Author: dcherix Date: 2012-04-09 18:26:42 +0000 (Mon, 09 Apr 2012) Log Message: ----------- Added Paths: ----------- trunk/components-core/src/main/java/org/nlp2rdf/ trunk/components-core/src/main/java/org/nlp2rdf/ontology/ trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java Added: trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java (rev 0) +++ trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java 2012-04-09 18:26:42 UTC (rev 3629) @@ -0,0 +1,241 @@ +/***************************************************************************/ +/* Copyright (C) 2010-2011, Sebastian Hellmann */ +/* Note: If you need parts of NLP2RDF in another licence due to licence */ +/* incompatibility, please mail hel...@in... */ +/* */ +/* This file is part of NLP2RDF. */ +/* */ +/* NLP2RDF is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU General Public License as published by */ +/* the Free Software Foundation; either version 3 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* NLP2RDF is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU General Public License */ +/* along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/***************************************************************************/ + +package org.nlp2rdf.ontology; + +import com.hp.hpl.jena.ontology.OntClass; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.ontology.OntModelSpec; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + + +/** + * Indexes an Ontology + * skips complex classes per default, this does not affect the hierarchy outcome + */ +public class ClassIndexer { + private static Logger log = LoggerFactory.getLogger(ClassIndexer.class); + + //Options + private boolean copyLabels = true; + private boolean copyComments = true; + private String language = null; + + //Not implemented + private Map<String, String> transform = new HashMap<String, String>(); + //Not implemented + private Set<String> remove = new HashSet<String>(); + + //internal variables + private Map<String, OntModel> classUriToClassHierarchy = new HashMap<String, OntModel>(); + + public ClassIndexer() { + } + + public void index(OntModel from) { + Set<OntClass> classes = from.listClasses().toSet(); + int i = 0; + for (OntClass cl : classes) { + Tree t = new Tree(cl); + classUriToClassHierarchy.put(cl.getURI(), t.toModel()); + } + + } + + /** + * @param classUri + * @return a filled OntModel with all superclasses of classUri or null, if no class is found + */ + public OntModel getHierarchyForClassURI(String classUri) { + return classUriToClassHierarchy.get(classUri); + } + + /** + * transforms namespaces + * + * @param in + * @return + */ + private String transformNamespace(String in) { + String ret = in; + for (String s : transform.keySet()) { + if (in.startsWith(s)) { + return in.replace(s, transform.get(s)); + + } + } + return ret; + } + + /** + * filters out certain namespaces + * + * @param s + * @return + */ + private boolean filterNamespace(String s) { + for (String prefix : remove) { + if (s.startsWith(prefix)) { + return true; + } + } + return false; + } + + + public boolean isCopyLabels() { + return copyLabels; + } + + public void setCopyLabels(boolean copyLabels) { + this.copyLabels = copyLabels; + } + + public boolean isCopyComments() { + return copyComments; + } + + public void setCopyComments(boolean copyComments) { + this.copyComments = copyComments; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + /** + * A simple Helper Class to convert the hierarchy + */ + private class Tree { + final String uri; + List<Tree> parents; + final String label; + final String comment; + + public Tree(OntClass me) { + this.uri = me.getURI(); + label = me.getLabel(language); + comment = me.getComment(language); + parents = new ArrayList<Tree>(); + + Set<OntClass> superClasses = me.listSuperClasses(true).toSet(); + for (OntClass s : superClasses) { + //this is were complex classes are skipped + if (s.isAnon()) { + continue; + } + log.trace(s.toString()); + parents.add(new Tree(s)); + } + } + + public OntModel toModel() { + OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, ModelFactory.createDefaultModel()); + OntClass me = model.createClass(uri); + //TODO test this for <&> + if (copyLabels && label != null) { + me.addLabel(label, language); + } + if (copyComments && comment != null) { + me.addComment(comment, language); + } + for (Tree p : parents) { + OntClass superClass = model.createClass(p.uri); + me.addSuperClass(superClass); + model.add(p.toModel()); + } + return model; + } + } + +} + +/** + public void expandSuperAndCopy(String originalClassUri) { + + String newClassUri = transform(originalClassUri); + if (isRemove(originalClassUri) || isRemove(newClassUri)) { + return; + } + + + // create initial classes + OntClass toClass = toModel.createClass(newClassUri); + OntClass fromClass = fromModel.getOntClass(originalClassUri); + + if(toClass==null || fromClass == null){ + logger.error("null occured in fromClass "+originalClassUri+" but retrieving yielded: "+fromClass ); + return; + } + + //System.out.println("begin"); + //for(OntClass cltest: fromModel.listClasses().toSet()){ + // System.out.println(cltest.getURI()); + // System.out.println(cltest.getClass().getSimpleName()); + //} + //System.out.println("end"); + + if (copyLabelsAndComments ) { + String tmp = null; + + if((tmp=fromClass.getLabel(null))!=null) {toClass.setLabel(tmp, null);} + // System.out.println(fromClass.getURI()+"has label "+tmp); + + if((tmp=fromClass.getComment(null))!=null) {toClass.setComment(tmp, null);} + // System.out.println(fromClass.getURI()+"has comment "+tmp); + } + + // get the superclasses + Set<OntClass> fromSuperclasses = fromClass.listSuperClasses(true).toSet(); + + for (OntClass fromSuperclass : fromSuperclasses) { + String newFromSuperclassUri = transform(fromSuperclass.getURI()); + if (isRemove(fromSuperclass.getURI()) || isRemove(newFromSuperclassUri)) { + continue; + } + if(fromSuperclass.isAnon()){ + continue; + } + + OntClass toSuperclass = toModel.createClass(newFromSuperclassUri); + toClass.addSuperClass(toSuperclass); + + if (copyLabelsAndComments) { + String tmp = null; + if((tmp=fromSuperclass.getLabel(null))!=null) {toSuperclass.setLabel(tmp, null);} + // System.out.println(fromSuperclass.getURI()+"has label "+tmp); + + if((tmp=fromSuperclass.getComment(null))!=null) {toSuperclass.setComment(tmp, null);} + // System.out.println(fromSuperclass.getURI()+"has comment "+tmp); + } + // System.out.println(fromSuperclass); + expandSuperAndCopy(fromSuperclass.getURI()); + } + + } **/ \ No newline at end of file Property changes on: trunk/components-core/src/main/java/org/nlp2rdf/ontology/ClassIndexer.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-04-08 20:53:13
|
Revision: 3628 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3628&view=rev Author: shadowtm Date: 2012-04-08 20:53:07 +0000 (Sun, 08 Apr 2012) Log Message: ----------- Removed the semanticservices repository as it was returning 500 Internal Error codes to developers who hadn't retrieved the pdb2rdf jars previously. These jars have been placed into the AKSW Archiva so that they can be retrieved - therefore, there is no longer a need to depend on the semanticservices repo. Modified Paths: -------------- trunk/pom.xml trunk/scripts/pom.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-04-04 15:12:31 UTC (rev 3627) +++ trunk/pom.xml 2012-04-08 20:53:07 UTC (rev 3628) @@ -390,6 +390,17 @@ <groupId>com.dumontierlab</groupId> <artifactId>pdb2rdf-parser</artifactId> <version>0.0.8</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + <!--This pom is including a modified version of Jena that is out of sync with what we're using--> + <exclusion> + <groupId>com.hp.hpl.jena</groupId> + <artifactId>jena</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>com.dumontierlab</groupId> @@ -535,30 +546,24 @@ <enabled>true</enabled> </snapshots> </repository> - <!-- This repository contains the jars for pdb2rdf --> - <repository> - <id>semanticscience.org</id> - <name>Semanticscience projects</name> - <url>http://s1.semanticscience.org:8080/nexus/content/groups/public/</url> - </repository> - - <repository> - <id>apache-repo-releases</id> - <url>https://repository.apache.org/content/repositories/releases/</url> - <releases> - <enabled>true</enabled> - </releases> -</repository> - <repository> - <id>apache-repo-snapshots</id> - <url>https://repository.apache.org/content/repositories/snapshots/</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> + + <repository> + <id>apache-repo-releases</id> + <url>https://repository.apache.org/content/repositories/releases/</url> + <releases> + <enabled>true</enabled> + </releases> + </repository> + <repository> + <id>apache-repo-snapshots</id> + <url>https://repository.apache.org/content/repositories/snapshots/</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> </repositories> <pluginRepositories> Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2012-04-04 15:12:31 UTC (rev 3627) +++ trunk/scripts/pom.xml 2012-04-08 20:53:07 UTC (rev 3628) @@ -37,18 +37,12 @@ <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> + <dependency> + <groupId>com.dumontierlab</groupId> + <artifactId>pdb2rdf-parser</artifactId> + </dependency> <dependency> <groupId>com.dumontierlab</groupId> - <artifactId>pdb2rdf-parser</artifactId> - <exclusions> - <exclusion> - <artifactId>slf4j-log4j12</artifactId> - <groupId>org.slf4j</groupId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>com.dumontierlab</groupId> <artifactId>pdb2rdf-cli</artifactId> </dependency> <dependency> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-04-04 15:12:43
|
Revision: 3627 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3627&view=rev Author: sebastianwtr Date: 2012-04-04 15:12:31 +0000 (Wed, 04 Apr 2012) Log Message: ----------- [tbsl exploration] started fixing some bugs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -61,10 +61,11 @@ /* * if isA is found and if Class has uri, get Elements */ - if(h.getType().contains("isA")&&h.getUri().contains("http")){ + if(h.getType().contains("ISA")&&h.getUri().contains("http")){ /* * TODO: improver performance, using geschicktes zwischenspeichern */ + System.out.println("Class Name: "+h.getName()+" Uri: "+h.getUri()); ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); //classes.add(el); this.addElements(el); @@ -83,6 +84,8 @@ for(ArrayList<Hypothesis> hl : hypothesenList){ for(Hypothesis h : hl){ if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ + System.out.println("Resource Name: "+h.getName()+" Uri: "+h.getUri()); + for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -8,6 +8,7 @@ private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenWordnet = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -180,6 +181,12 @@ public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { this.hypothesenLevensthein = hypothesenLevensthein; } + public ArrayList<ArrayList<Hypothesis>> getHypothesenWordnet() { + return hypothesenWordnet; + } + public void setHypothesenWordnet(ArrayList<ArrayList<Hypothesis>> hypothesenWordnet) { + this.hypothesenWordnet = hypothesenWordnet; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -104,6 +104,7 @@ String[] tmp_array = conditions1.toString().split(" -- "); for(String s: tmp_array){ //System.out.println(s); + s=s.replace("isA", "ISA"); temp_array.add(s); } condition.add(temp_array); @@ -166,6 +167,14 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + for(ArrayList<String> al : condition){ + String con_temp=""; + for(String s : al){ + con_temp+=" " + s; + } + System.out.println("Condition: "+con_temp); + } + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -179,7 +188,7 @@ String[] tmp_array = tmp.split(":"); boolean no_iaA_found=true; for(ArrayList<String> x : condition){ - if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + if(x.get(1).equals("ISA") && x.get(2).equals("?"+tmp_array[0])){ no_iaA_found=false; Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0.0); //tmp_hypothesis.printAll(); @@ -218,11 +227,11 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); + System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); for(Hypothesis x : list_of_hypothesis){ /* @@ -270,13 +279,13 @@ } } - /*System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n"); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -311,18 +320,51 @@ } } - /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + + + + /* + * BUGFIX: Before adding Hypothesis to template check, if each Hypothesis has an uri + * TODO: check all functions before + */ + /*for(ArrayList<Hypothesis> al:final_list_set_hypothesis){ + for(Hypothesis h : al){ + if(!h.getUri().contains("http")){ + if(h.getType().contains("ISA")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForClass(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + if(h.getType().contains("RESOURCE")){ + try { + ArrayList<String> tmp = Index_utils.searchIndexForResource(h.getUri(), myindex); + h.setUri(tmp.get(0)); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + } + } + } + */ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ for(Hypothesis x : lh){ x.printAll(); } } - System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n");*/ + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n"); - template.setHypothesen(final_list_set_hypothesis); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -17,7 +17,9 @@ else{ double result_nld =result/length; - return result_nld; + double result1 = 1-result_nld; + //System.out.println(orig + " " + eing +" : "+result1); + return result1; } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -20,9 +20,9 @@ } } - for(QueryPair p : qp){ + /*for(QueryPair p : qp){ p.printAll(); - } + }*/ } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -31,7 +31,12 @@ if(type.contains("LEVENSTHEIN")){ givenHypothesenList=t.getHypothesenLevensthein(); } - else{ + else if(type.contains("WORDNET")){ + givenHypothesenList=t.getHypothesenWordnet(); + } + + else { + if(!type.contains("NORMAL"))System.err.println("ATTENTION\n Given Type: "+type+" was not found in generating Queries!!\n"); givenHypothesenList=t.getHypothesen(); } @@ -48,6 +53,8 @@ if(!h.getUri().contains("http")){ addQuery=false; } + condition_new=condition_new.replace("ISA", "rdf:type"); + //just in case... condition_new=condition_new.replace("isA", "rdf:type"); global_rank=global_rank+h.getRank(); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,10 +3,14 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ServerUtil { @@ -128,10 +132,13 @@ TODO:Try with different Limits */ - String query="PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').}{?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; - + /* + * TODO: Still a not "valid" url + */ + String query="SELECT DISTINCT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} UNION {?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; + String query_final=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest(query)+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String result=""; - result = getListOfElements(query); + result = getListOfElements(query_final); return generateList(result); } @@ -197,8 +204,66 @@ result=sb.toString(); } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); + //System.out.println("Must enter a valid URL"); + System.err.println("ATTENTION\n URL not valid : "+verarbeitungsurl+"\n"); } catch (IOException e) { + System.err.println("Can not connect or timeout"); + } + finally + { + //close the connection, set all objects to null + try{ + connection.disconnect(); + } + catch (Exception e){ + System.err.println("ATTENTION\n Error in disconecting Connection to Server in getListOfElements\n "); + } + rd = null; + sb = null; + connection = null; + } + return result; + } + + public static ArrayList<String> requestAnswerFromServer(String query){ + String query_url=server_Prefix+"?default-graph-uri=&query="+createServerRequest(query)+"&format=text%2Fhtml&debug=on&timeout="; + + //System.out.println(tmp); + String result=""; + HttpURLConnection connection = null; + OutputStreamWriter wr = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + + URL serverAddress = null; + + try { + serverAddress = new URL(query_url); + //set up out communications stuff + connection = null; + + //Set up the initial connection + connection = (HttpURLConnection)serverAddress.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(timeToTimeoutOnServer); + + connection.connect(); + rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + sb = new StringBuilder(); + + while ((line = rd.readLine()) != null) + { + sb.append(line + '\n'); + } + + //System.out.println(sb.toString()); + result=sb.toString(); + + } catch (MalformedURLException e) { + System.err.println("ATTENTION\n URL not valid : "+query_url+"\n"); + } catch (IOException e) { System.out.println("Can not connect or timeout"); } finally @@ -207,11 +272,41 @@ connection.disconnect(); rd = null; sb = null; + wr = null; connection = null; } + + + + return createAnswerArray(result); + } + + private static ArrayList<String> createAnswerArray(String string){ + + 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); + String[] bla = string.split(" "); + + ArrayList<String> result= new ArrayList<String>(); + for(String s: bla){ + m=p.matcher(s); + while (m.find()) { + String temp = m.group(1); + temp = temp.replace("\"@en",""); + temp = temp.replace("\"",""); + //result.add(m.group(1)); + result.add(temp); + + } + } + + + //if (result.length()==0) result="EmtyAnswer"; + if(string.matches("true")|| string.matches("false")) result.add(string); return result; + } - } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,8 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.MalformedURLException; import java.sql.SQLException; import java.util.ArrayList; @@ -12,17 +14,27 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class MainInterface { - private int anzahlAbgeschickterQueries = 10; - public static void startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex ) throws ClassNotFoundException, SQLException, IOException{ + private static int anzahlAbgeschickterQueries = 10; + + + public static ArrayList<String> startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex, WordNet wordnet,StanfordLemmatizer lemmatiser) throws ClassNotFoundException, SQLException, IOException{ TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); ArrayList<Template> template_list = new ArrayList<Template>(); + /* + * Array List with the answers from the queries + */ + ArrayList<String> answers = new ArrayList<String>(); + /* * generate Templates! */ @@ -35,7 +47,7 @@ //generate QueryPair for(Template t : template_list){ - //t.printAll(); + t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); qp_t = Query.returnSetOfQueries(t, "NORMAL"); for(QueryPair p : qp_t){ @@ -51,15 +63,101 @@ } //sort QueryPairs - LinearSort.doSort(qp); + LinearSort.doSort(qp); + int anzahl=1; + boolean go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + System.out.println(q.getQuery()); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String line; + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + + /* * If there is no answer, start IterationMode with Levensthein */ + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"LEVENSTHEIN")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + /* + * still no answer, start IterationMode with Wordnet + */ + + if(answers.isEmpty()){ + + answers.clear(); + answers.addAll(doStart(myindex, wordnet, lemmatiser, template_list,"WORDNET")); + System.out.println("\n\n"); + System.out.println("Press Any Key to continue"); + line = in.readLine(); + } + + + + /*if(answers.isEmpty()){ + System.out.println("No answers were found with the three Modules"); + //answers.add("No answers were found with the three Modules"); + }*/ + + + /* + * return answers! + */ + + return answers; + } + + + + + + + private static ArrayList<String> doStart(SQLiteIndex myindex, WordNet wordnet, + StanfordLemmatizer lemmatiser, ArrayList<Template> template_list, String type) { + ArrayList<String> answers = new ArrayList<String>(); + ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + int anzahl; + boolean go_on; + System.out.println("No answer from direkt match, start "+type+"Modul"); for(Template t : template_list){ try{ - ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); - t.setHypothesenLevensthein(hypothesenSetList); + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),type,myindex,wordnet,lemmatiser); + if(type.contains("WORDNET"))t.setHypothesenWordnet(hypothesenSetList); + if(type.contains("LEVENSTHEIN"))t.setHypothesenLevensthein(hypothesenSetList); } catch (Exception e){ @@ -68,14 +166,13 @@ } /* - * Generate Queries for Levensthein Mode and test queries + * Generate Queries and test queries */ - qp.clear(); //generate QueryPair for(Template t : template_list){ //t.printAll(); ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); - qp_t = Query.returnSetOfQueries(t, "LEVENSTHEIN"); + qp_t = Query.returnSetOfQueries(t, type); for(QueryPair p : qp_t){ //if(!qp.contains(p)) qp.add(p); boolean contain = false; @@ -84,24 +181,57 @@ if(p_t.getQuery().contains(p.getQuery())) contain=true; } } - if(!contain)qp.add(p); + if(!contain&&checkQuery(p.getQuery()))qp.add(p); } } //sort QueryPairs LinearSort.doSort(qp); - System.out.println("Anzahl: "+qp.size()); - /* - * still no answer, start IterationMode with Wordnet - */ + anzahl=1; + go_on = true; + for(QueryPair q : qp){ + if(anzahl<anzahlAbgeschickterQueries&go_on){ + ArrayList<String> answer_tmp = new ArrayList<String>(); + answer_tmp=ServerUtil.requestAnswerFromServer(q.getQuery()); + System.out.println(q.getQuery() + " Rank: "+q.getRank()); + if(answer_tmp.isEmpty()) go_on=true; + + else{ + //else go_on=false; + go_on=true; + for(String s : answer_tmp){ + if(checkAnswer(s)){ + boolean test = false; + for(String s_t : answers){ + if(s_t.contains(s)) test=true; + } + if(!test)answers.add(s); + } + } + //if(checkAnswer(answer_tmp))answers.addAll(answer_tmp); + } + } + anzahl+=1; + } + for(String answer:answers){ + System.out.println(answer); + } - /* - * Generate Queries for Wordnet Mode and test queries. - */ + return answers; } - private void sortQueries(){ + + + private static boolean checkAnswer(String answer){ + if(answer.contains("File:")||answer.contains(".png")||answer.contains("upload.wikimedia.org")||answer.contains("dbpedia.org/datatype/")||answer.contains("http://www.w3.org/2001/XMLSchema")) return false; + else return true; } + + private static boolean checkQuery(String query){ + if(query.contains("wikiPageWiki")||query.contains("wikiPageExternal")||query.contains("wikiPageRedirects")|| query.contains("thumbnail")) return false; + else return true; + + } } 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-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,6 +1,7 @@ package org.dllearner.algorithm.tbsl.exploration.exploration_main; import java.io.BufferedReader; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -20,7 +21,10 @@ import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; +import org.ibex.nestedvm.util.Seekable.InputStream; import java.sql.Connection; import java.sql.DriverManager; @@ -57,6 +61,8 @@ BasicTemplator btemplator = new BasicTemplator(); //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + StanfordLemmatizer lemmatiser = new StanfordLemmatizer(); long stopInitTime = System.currentTimeMillis(); @@ -82,13 +88,18 @@ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - System.out.println("Please enter Path of xml File:"); - line=in.readLine(); + /*System.out.println("Please enter Path of xml File:"); + line=in.readLine();*/ + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/dbpedia-train-withoutnonparsed.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/very_small.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/berlin.xml"; + //line="/home/swalter/Dokumente/Auswertung/XMLDateien/vortragfragen.xml"; + line="/home/swalter/Dokumente/Auswertung/XMLDateien/iteration-test.xml"; //create Structs ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - ArrayList<queryInformation> list_of_resultstructs = new ArrayList<queryInformation>(); - //if you dont want to use the hints in the questions, use false + list_of_structs=generateStruct(line,true); //Start Time measuring long startTime = System.currentTimeMillis(); @@ -100,12 +111,13 @@ anzahl=anzahl+1; System.out.println(""); if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); - System.out.println("ID: "+qi.getId()); + /*System.out.println("ID: "+qi.getId()); System.out.println("Query: "+qi.getQuery()); System.out.println("Type: "+qi.getType()); - System.out.println("XMLType: "+qi.getXMLtype()); + System.out.println("XMLType: "+qi.getXMLtype());*/ String question = qi.getQuery(); - MainInterface.startQuestioning(question,btemplator,myindex); + ArrayList<String> answers=MainInterface.startQuestioning(question,btemplator,myindex,wordnet,lemmatiser); + qi.setResult(answers); } @@ -115,44 +127,28 @@ System.out.println(s.getResult()); }*/ String systemid=""; - systemid=createXML(list_of_resultstructs); - writeQueryInformation(list_of_structs,systemid); - writeTime(list_of_structs,systemid); - - //now create File with systemid for time and a file, which lists alle propertys and so on - - long timeNow = System.currentTimeMillis(); - long diff = timeNow-startTime; - String string1="Time for "+anzahl+" questions = "+diff+" ms."; - System.out.println(string1); - String string2="From "+anzahl_query_with_answers+" questions I got an answer"; - String string3=yago_querys+ " Yago Questions were skiped"; - System.out.println(string2); - System.out.println(string3); - String string4 ="Average time for one question : "+(diff/anzahl/1000)+"sek"; - File file; - FileWriter writer; - file = new File("../../generalInformation"+systemid+".txt"); - try { - writer = new FileWriter(file ,true); - writer.write(string1+"\n"+string2+"\n"+string3+"\n"+string4); - writer.flush(); - - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } + systemid=createXML(list_of_structs); + String filename_for_evaluation="/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"; + String execute = "python /home/swalter/Dokumente/Auswertung/Evaluation/Evaluation.py "+filename_for_evaluation+" 0"; + + /* + * First only for training + */ + + System.out.println("execute: "+execute); + Runtime r = Runtime.getRuntime(); + Process p = r.exec(execute); + + String open_file="/home/swalter/Dokumente/Auswertung/Evaluation/upload/out"+systemid.replace(" ", "_")+".html"; + execute ="firefox "+ open_file; + p = r.exec(execute); - System.out.println("Finished test"); - System.exit(0); - } else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); - MainInterface.startQuestioning(line,btemplator,myindex); + MainInterface.startQuestioning(line,btemplator,myindex,wordnet,lemmatiser); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! Set<String> setString = new HashSet<String>(); @@ -239,39 +235,43 @@ java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); String systemid = sdf.format(now); - + System.out.println("In createXML"); String xmlDocument=""; int counter=0; + System.out.println("Anzahl queryInformations: "+list.size()); for (queryInformation s : list){ - String tmp; - if(counter==0){ - counter=counter+1; - xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + if(!s.getResult().isEmpty()){ + String tmp; + if(counter==0){ + counter=counter+1; + xmlDocument="<?xml version=\"1.0\" ?><dataset id=\""+s.getXMLtype()+"\">"; + } + tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; + + //to get all answers only once! + Set<String> setString = new HashSet<String>(); + for(String z: s.getResult()){ + setString.add(z); + } + for(String i : setString){ + //System.out.println("i: "+i); + String input=""; + if(i.contains("http")) input="<uri>"+i+"</uri>\n"; + else if (i.contains("true")||i.contains("false")) input="<boolean>"+i+"</boolean>\n"; + else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; + else input="<string>"+i+"</string>\n"; + tmp+="<answer>"+input+"</answer>\n"; + } + tmp+="</answers></question>\n"; + xmlDocument+=tmp; } - tmp="<question id=\""+s.getId()+"\"><string>"+s.getQuery()+"</string>\n<answers>"; - //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"; - else if(i.matches("[0-9]*"))input="<number>"+i+"</number>\n"; - else input="<string>"+i+"</string>\n"; - tmp+="<answer>"+input+"</answer>\n"; - } - tmp+="</answers></question>\n"; - xmlDocument+=tmp; - } xmlDocument+="</dataset>"; File file; FileWriter writer; - file = new File("../../result"+systemid+".xml"); + file = new File("/home/swalter/Dokumente/Auswertung/ResultXml/result"+systemid.replace(" ", "_")+".xml"); try { writer = new FileWriter(file ,true); writer.write(xmlDocument); @@ -283,6 +283,7 @@ e.printStackTrace(); } + System.out.println("In createXML - Done"); return systemid; } @@ -318,18 +319,28 @@ String string=tmp; Pattern p = Pattern.compile (".*\\<question(.*)\\</question\\>.*"); Matcher m = p.matcher (string); + /* string= string.replace(" answertype=\"number\"", ""); + string= string.replace(" answertype=\"string\"", ""); + string= string.replace(" answertype=\"date\"", ""); + string= string.replace(" answertype=\"resource\"", ""); + string= string.replace(" answertype=\"boolean\"", ""); + string = string.replace(" aggregation=\"true\"", ""); + string = string.replace(" aggregation=\"false\"", ""); + string = string.replace(" onlydbo=\"false\"", ""); + string = string.replace(" onlydbo=\"true\"", "");*/ - if(string.contains("id=\"dbpedia-train\"><question")){ string=string.replace("id=\"dbpedia-train\"><question", ""); XMLType="dbpedia-train"; System.out.println("dbpedia-train"); } - if(string.contains("id=\"dbpedia-test\"><question")){ + else if(string.contains("id=\"dbpedia-test\"><question")){ string=string.replace("id=\"dbpedia-test\"><question", ""); XMLType="dbpedia-test"; //System.out.println("dbpedia-test"); } + + else XMLType="dbpedia-train"; ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); String [] bla = string.split("</question><question"); for(String s : bla){ @@ -340,7 +351,10 @@ boolean yago=false; String id=""; - Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + /* + * Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<query\\>.*"); + */ + Pattern p1= Pattern.compile("(id.*)\\</string\\>\\<keywords\\>.*"); Matcher m1 = p1.matcher(s); //System.out.println(""); while(m1.find()){ @@ -349,7 +363,15 @@ Matcher m2 = p2.matcher(m1.group(1)); while(m2.find()){ //System.out.println("Query: "+ m2.group(1)); + query=m2.group(1); + query=query.replace("<![CDATA[", ""); + query=query.replace("]]>", ""); + query=query.replace("CDATA", ""); + query=query.replace("]", ""); + query=query.replace("!", ""); + query=query.replace(">", ""); + query=query.replace("<", ""); } Pattern p3= Pattern.compile("id=\"(.*)\" answer.*"); Matcher m3 = p3.matcher(m1.group(1)); @@ -395,14 +417,14 @@ queryInformation blaquery=new queryInformation(query, id,type,fusion,aggregation,yago,XMLType,hint); if(id!=""&&id!=null) querylist.add(blaquery); } - /* for(queryInformation s : querylist){ + for(queryInformation s : querylist){ System.out.println(""); if(s.getId()==""||s.getId()==null)System.out.println("NO"); System.out.println("ID: "+s.getId()); System.out.println("Query: "+s.getQuery()); System.out.println("Type: "+s.getType()); System.out.println("XMLType: "+s.getXMLtype()); - }*/ + } return querylist; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -24,6 +24,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class testClass_new { @@ -42,6 +43,8 @@ //btemplator.UNTAGGED_INPUT = false; SQLiteIndex myindex = new SQLiteIndex(); + WordNet wordnet = new WordNet(); + TemplateBuilder testobject = new TemplateBuilder(btemplator, myindex); String filepath = "/home/swalter/Dokumente/Auswertung/"; @@ -84,7 +87,7 @@ //} - long stop_template = System.currentTimeMillis(); + /* long stop_template = System.currentTimeMillis(); long start_iteration = System.currentTimeMillis(); long time_generatingElements=0; @@ -97,7 +100,7 @@ time_part2+=t.getTime_part2(); try{ //t.getElm().printAll(); - ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN",myindex,wordnet); t.setHypothesenLevensthein(blub); //t.printAll(); @@ -106,8 +109,8 @@ } - } - long stop_iteration = System.currentTimeMillis(); + }*/ + /*long stop_iteration = System.currentTimeMillis(); System.out.println("The Iteration and Levensthein Mode took "+ (stop_iteration-start_iteration)+"ms"); System.out.println("The Iteration and Levensthein Mode took for one Template "+ (stop_iteration-start_iteration)/temp_list_result.size()+"ms"); float time_template =stop_template-start_template; @@ -120,7 +123,7 @@ System.out.println("Average Time part1 "+ (time_part1/temp_list_result.size())+"ms"); System.out.println("Average Time part2 "+ (time_part2/temp_list_result.size())+"ms"); System.out.println("Time getting Properties etc "+ (time_generatingElements)+"ms"); - System.out.println("DONE"); + System.out.println("DONE");*/ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -3,9 +3,14 @@ import java.sql.SQLException; import java.util.ArrayList; +import net.didion.jwnl.JWNLException; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; /** * Gets Elements, Condition and Hypothesen and returns HypothesenSets. @@ -23,7 +28,7 @@ * @return ArrayList<ArrayList<Hypothesis>> * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type,SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException{ boolean gotResource=true; ArrayList<ElementList> resources = new ArrayList<ElementList>(); @@ -142,10 +147,14 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,array[0],el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); + } catch (JWNLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); @@ -159,7 +168,7 @@ } - if(h.getType().contains("isA")){ + if(h.getType().contains("ISA")){ /* * TODO:Add special case, if we have only one condition but with an isA in it. */ @@ -180,7 +189,7 @@ * Dont look for line, where e.g. ?x isA ?y */ //get(1) is the middle Term and if there is an isa, than its there - if(!cl.get(1).contains("isA")){ + if(!cl.get(1).contains("ISA")){ for(String s : cl){ if(s.contains(h.getVariable())){ propertyVariableList.add(s); @@ -199,6 +208,7 @@ * Here start levenstehin, wordnet etc etc */ if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(type.contains("WORDNET"))resultHypothesenList= WordnetModule.doWordnet(propertyVariable,h_small.getName(),el.getHm(),myindex,wordnet,lemmatiser); if(!PL.contains(propertyVariable)) PL.add(propertyVariable); for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); } catch (Exception e) { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.5; + private final static double LevenstheinMin=0.85; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-03-29 16:46:49 UTC (rev 3626) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-04-04 15:12:31 UTC (rev 3627) @@ -1,8 +1,241 @@ package org.dllearner.algorithm.tbsl.exploration.modules; +import java.io.IOException; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import net.didion.jwnl.JWNLException; +import net.didion.jwnl.data.POS; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; +import org.dllearner.algorithm.tbsl.nlp.WordNet; + public class WordnetModule { - private int explorationdepthwordnet =2; + private static int explorationdepthwordnet =2; + public static ArrayList<Hypothesis> doWordnet(String variable, String property_to_compare_with, HashMap<String, String> properties, SQLiteIndex myindex,WordNet wordnet,StanfordLemmatizer lemmatiser) throws SQLException, + JWNLException { + ArrayList<Hypothesis> listOfNewHypothesen = new ArrayList<Hypothesis>(); + + System.out.println("Start Iterating Wordnet with "+property_to_compare_with+" and deept of "+explorationdepthwordnet); + ArrayList<String> semantics=new ArrayList<String>(); + ArrayList<String> tmp_semantics=new ArrayList<String>(); + ArrayList<String> result_SemanticsMatchProperties=new ArrayList<String>(); + if(property_to_compare_with.contains("_")){ + String[] fix = property_to_compare_with.split("_"); + //here add also lemmatiser + for(String s: fix) semantics.add(s); + } + else semantics.add(property_to_compare_with); + System.out.println("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; + }*/ + } + + System.out.println("tmp_semantics: "+ tmp_semantics); + Boolean goOnAfterWordnet = true; + + for(int i=0;i<=explorationdepthwordnet;i++){ + + try { + tmp_semantics=getSemantics(tmp_semantics,wordnet); + System.out.println("tmp_semantics in Iteration: "+ tmp_semantics); + if (tmp_semantics==null){ + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + else{ + //each word only one time + for(String k : tmp_semantics){ + if(!semantics.contains(k)) semantics.add(k); + } + } + + } catch (IOException e) { + + goOnAfterWordnet=false; + System.out.println("Error in searching Wordnet with word "+semantics+" \n End"); + + } + + } + if(goOnAfterWordnet==true){ + + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + key=key.replace("\"",""); + key=key.replace("@en",""); + + for(String b : semantics){ + 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); + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + } + } + } + + } + + return listOfNewHypothesen; + } + + private static ArrayList<String> getSemantics (ArrayList<String> semanticsOrig,WordNet wordnet) throws IOException, JWNLException { + ArrayList<String> result = new ArrayList<String>(); + + //System.out.println("in function get Semantics!"); + + ArrayList<String> semantics = new ArrayList<String>(); + semantics=semanticsOrig; + //also look at the stemmt part! + /*for(String s: semanticsOrig){ + String bla=lemmatiser.stem(s); + semantics.add(bla); + semantics.add(s); + }*/ + + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics"); + //System.out.println("ID :"+id); + + //add id also to the result, if its not already in there + if(!result.contains(id))result.add(id); + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + + //System.out.println("Wordnet Word: "+id); + try{ + array_relatedNouns =wordnet.getRelatedNouns(id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, id); + //System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + + } + } + catch(Exception e){ + return null; + } + + if(!result.isEmpty()) return result; + else{ + //System.out.println("Didnt find ") + /*this is the case, if the first time nothing was found. + * but sometimes wordnet doesnt find anything e.g. die place... bzt you have also die and place + * so we try to find the seperate words and test them as well + */ + try{ + for(String id :semantics){ + //System.out.println("in String id : semantics TWO"); + String[] tmp_array=id.split(" "); + //System.out.println("ID TWO:"+id); + if(tmp_array.length>=2){ + for(String advanced_id : tmp_array){ + List<String> array_relatedNouns=null; + List<String> array_bestsynonyms=null; + //add id also to the result, if its not already in there + if(!result.contains(advanced_id))result.add(advanced_id); + + try{ + array_relatedNouns =wordnet.getRelatedNouns(advanced_id); + } + catch(Exception e){ + //array_relatedNouns.clear(); + } + //System.out.println("array_relatedNouns: "+ array_relatedNouns); + //System.out.println("after relatedNouns"); + + try{ + array_bestsynonyms=wordnet.getBestSynonyms(POS.NOUN, advanced_id); + // System.out.println("array_bestsynonyms: "+ array_bestsynonyms); + } + catch(Exception e){ + // + } + + if(array_relatedNouns!=null){ + for(String i:array_relatedNouns){ + if(!result.contains(i))result.add(i); + } + } + if(array_bestsynonyms!=null){ + for(String i:array_bestsynonyms){ + if(!result.contains(i))result.add(i); + } + } + + + } + } + + } + } + catch(Exception e){ + if(result.isEmpty()) return semanticsOrig; + } + + } + + if(!result.isEmpty()) return result; + else return null; + // else{ return result;} + } + + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-29 16:47:00
|
Revision: 3626 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3626&view=rev Author: sebastianwtr Date: 2012-03-29 16:46:49 +0000 (Thu, 29 Mar 2012) Log Message: ----------- [tbsl exploration] included MainInterface and added sort function for the QueryPairs Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -31,11 +31,11 @@ private static SQLiteIndex myindex; -public TemplateBuilder() throws MalformedURLException, ClassNotFoundException, SQLException{ +public TemplateBuilder(BasicTemplator bt, SQLiteIndex sq) throws MalformedURLException, ClassNotFoundException, SQLException{ - TemplateBuilder.btemplator = new BasicTemplator(); + TemplateBuilder.btemplator = bt; //btemplator.UNTAGGED_INPUT = false; - TemplateBuilder.myindex = new SQLiteIndex(); + TemplateBuilder.myindex = sq; } Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/LinearSort.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -0,0 +1,29 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.ArrayList; + +public class LinearSort { + + public static void doSort(ArrayList<QueryPair> qp){ + + boolean change=true; + while(change){ + change=false; + for(int i = 0; i<qp.size()-1;i++){ + if(qp.get(i).getRank()<qp.get(i+1).getRank()){ + change=true; + QueryPair one = qp.get(i); + QueryPair two = qp.get(i+1); + qp.set(i, two); + qp.set(i+1, one); + } + } + } + + for(QueryPair p : qp){ + p.printAll(); + } + + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -13,8 +13,8 @@ //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; //private static String server_Prefix="http://dbpedia.org/sparql"; - //private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; + private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; private static int timeToTimeoutOnServer=30000; Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/MainInterface.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -0,0 +1,107 @@ +package org.dllearner.algorithm.tbsl.exploration.exploration_main; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.sql.SQLException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; +import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; +import org.dllearner.algorithm.tbsl.exploration.Utils.LinearSort; +import org.dllearner.algorithm.tbsl.exploration.Utils.Query; +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; + +public class MainInterface { + private int anzahlAbgeschickterQueries = 10; + public static void startQuestioning(String question,BasicTemplator btemplator,SQLiteIndex myindex ) throws ClassNotFoundException, SQLException, IOException{ + + TemplateBuilder templateObject = new TemplateBuilder(btemplator, myindex); + ArrayList<Template> template_list = new ArrayList<Template>(); + + + /* + * generate Templates! + */ + template_list=templateObject.createTemplates(question); + + /* + * generate Queries and test the first Time + */ + ArrayList<QueryPair> qp = new ArrayList<QueryPair>(); + + //generate QueryPair + for(Template t : template_list){ + //t.printAll(); + ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); + qp_t = Query.returnSetOfQueries(t, "NORMAL"); + for(QueryPair p : qp_t){ + //if(!qp.contains(p)) qp.add(p); + boolean contain = false; + for(QueryPair p_t : qp){ + if(p_t.getRank()==p.getRank()){ + if(p_t.getQuery().contains(p.getQuery())) contain=true; + } + } + if(!contain)qp.add(p); + } + } + + //sort QueryPairs + LinearSort.doSort(qp); + + /* + * If there is no answer, start IterationMode with Levensthein + */ + for(Template t : template_list){ + try{ + ArrayList<ArrayList<Hypothesis>> hypothesenSetList = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + t.setHypothesenLevensthein(hypothesenSetList); + } + catch (Exception e){ + + } + + } + + /* + * Generate Queries for Levensthein Mode and test queries + */ + qp.clear(); + //generate QueryPair + for(Template t : template_list){ + //t.printAll(); + ArrayList<QueryPair> qp_t = new ArrayList<QueryPair>(); + qp_t = Query.returnSetOfQueries(t, "LEVENSTHEIN"); + for(QueryPair p : qp_t){ + //if(!qp.contains(p)) qp.add(p); + boolean contain = false; + for(QueryPair p_t : qp){ + if(p_t.getRank()==p.getRank()){ + if(p_t.getQuery().contains(p.getQuery())) contain=true; + } + } + if(!contain)qp.add(p); + } + } + + //sort QueryPairs + LinearSort.doSort(qp); + System.out.println("Anzahl: "+qp.size()); + /* + * still no answer, start IterationMode with Wordnet + */ + + /* + * Generate Queries for Wordnet Mode and test queries. + */ + } + + + private void sortQueries(){ + + } +} 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-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/exploration_main.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -17,8 +17,10 @@ import net.didion.jwnl.JWNLException; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.SparqlObject; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; import java.sql.Connection; import java.sql.DriverManager; @@ -46,15 +48,16 @@ */ public static void main(String[] args) throws IOException, JWNLException, InterruptedException, ClassNotFoundException, SQLException { - /** - * Do the starting initializing stuff - */ + System.out.println("Starting Main File"); long startInitTime = System.currentTimeMillis(); /* - * Create Sparql Object + * Initial Index and Templator */ - SparqlObject sparql = new SparqlObject(); + BasicTemplator btemplator = new BasicTemplator(); + //btemplator.UNTAGGED_INPUT = false; + SQLiteIndex myindex = new SQLiteIndex(); + long stopInitTime = System.currentTimeMillis(); System.out.println("Time for Initialising "+(stopInitTime-startInitTime)+" ms"); @@ -74,68 +77,7 @@ System.out.println("Bye!"); System.exit(0); } - if(line.contains(":setIterationdepth")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setIterationdepth(i_zahl); - doing = false; - } - if(line.contains(":getIterationdepth")){ - System.out.println(sparql.getIterationdepth()); - doing = false; - } - if(line.contains(":setExplorationdepthwordnet")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setExplorationdepthwordnet(i_zahl); - doing = false; - } - if(line.contains(":getExplorationdepthwordnet")){ - System.out.println(sparql.getExplorationdepthwordnet()); - doing = false; - } - if(line.contains(":setNumberofanswer")){ - String[] tmp=line.split(" "); - int i_zahl = new Integer(tmp[1]).intValue(); - if(tmp.length>=2) sparql.setNumberofanswers(i_zahl); - doing = false; - } - if(line.contains(":getNumberofanswer")){ - System.out.println(sparql.getNumberofanswers()); - doing = false; - } - if(line.contains(":textfile")&& schleife==true){ - TimeZone.setDefault(TimeZone.getTimeZone("GMT")); - - - System.out.println("Please enter Path of txt. File:"); - line=in.readLine(); - - //Start Time measuring - long startTime = System.currentTimeMillis(); - String s=""; - BufferedReader in_file = new BufferedReader(new InputStreamReader(new FileInputStream(line))); - int anzahl=0; - while( null != (s = in_file.readLine()) ) { - System.out.println(s); - anzahl++; - //get each line and send it to the parser - //String query1, String id1, String type1, boolean fusion1, boolean aggregation1, boolean yago1, String XMLtype1 - queryInformation newQuery = new queryInformation(s,"0","",false,false,false,"non",false); - queryInformation result = new queryInformation(s,"0","",false,false,false,"non",false); - result=sparql.create_Sparql_query(newQuery); - ArrayList<String> ergebnis = result.getResult(); - for(String i: ergebnis){ - System.out.println(i); - } - } - long timeNow = System.currentTimeMillis(); - long diff = timeNow-startTime; - - System.out.println("Time for "+anzahl+" questions = "+diff+" ms."); - - } if(line.contains(":xml")&& schleife==true){ TimeZone.setDefault(TimeZone.getTimeZone("GMT")); @@ -154,24 +96,16 @@ int anzahl=0; int anzahl_query_with_answers=0; int yago_querys=0; - for(queryInformation s : list_of_structs){ + for(queryInformation qi : list_of_structs){ anzahl=anzahl+1; System.out.println(""); - if(s.getId()==""||s.getId()==null)System.out.println("NO"); - System.out.println("ID: "+s.getId()); - System.out.println("Query: "+s.getQuery()); - System.out.println("Type: "+s.getType()); - System.out.println("XMLType: "+s.getXMLtype()); - //queryInformation tmpquery; - //only question, which are not yago files - if(s.isYago()==true)yago_querys=yago_querys+1; - //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; - } - //} + if(qi.getId()==""||qi.getId()==null)System.out.println("NO"); + System.out.println("ID: "+qi.getId()); + System.out.println("Query: "+qi.getQuery()); + System.out.println("Type: "+qi.getType()); + System.out.println("XMLType: "+qi.getXMLtype()); + String question = qi.getQuery(); + MainInterface.startQuestioning(question,btemplator,myindex); } @@ -217,9 +151,8 @@ else if(schleife==true && doing ==true){ long startTime = System.currentTimeMillis(); - queryInformation newQuery = new queryInformation(line,"0","",false,false,false,"non",false); queryInformation result = new queryInformation(line,"0","",false,false,false,"non",false); - result= sparql.create_Sparql_query(newQuery); + MainInterface.startQuestioning(line,btemplator,myindex); ArrayList<String> ergebnis = result.getResult(); //get eacht result only once! Set<String> setString = new HashSet<String>(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -15,6 +15,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; @@ -23,6 +24,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; +import org.dllearner.algorithm.tbsl.templator.BasicTemplator; public class testClass_new { @@ -36,8 +38,12 @@ // TODO Auto-generated method stub ArrayList<Template> temp_list_result = new ArrayList<Template>(); - TemplateBuilder testobject = new TemplateBuilder(); + BasicTemplator btemplator = new BasicTemplator(); + //btemplator.UNTAGGED_INPUT = false; + SQLiteIndex myindex = new SQLiteIndex(); + TemplateBuilder testobject = new TemplateBuilder(btemplator, myindex); + String filepath = "/home/swalter/Dokumente/Auswertung/"; //String file="very_small.xml"; String file="dbpedia-train.xml"; @@ -53,7 +59,7 @@ String question ="Who is the daughter of Bill Clinton married to?"; long start_template = System.currentTimeMillis(); - //temp_list_result=testobject.createTemplates(question); + temp_list_result=testobject.createTemplates(question); Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:10:53 UTC (rev 3625) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 16:46:49 UTC (rev 3626) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.92; + private final static double LevenstheinMin=0.5; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-29 13:11:05
|
Revision: 3625 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3625&view=rev Author: sebastianwtr Date: 2012-03-29 13:10:53 +0000 (Thu, 29 Mar 2012) Log Message: ----------- [tbsl exploration] went on to implement the different Modules, especially the Iteration Module Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.92; + double lim_levensthein=0.99; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -25,6 +25,11 @@ * HashMap with name -uri pairs. */ private HashMap<String,String> hm = new HashMap<String,String>(); + + /** + * Resource or Class! + */ + //private String type public String getVariablename() { return variablename; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -11,36 +11,27 @@ * */ public class Elements { - private ArrayList<ElementList> resources = new ArrayList<ElementList>(); - private ArrayList<ElementList> classes = new ArrayList<ElementList>(); - public ArrayList<ElementList> getResources() { - return resources; + private ArrayList<ElementList> elements = new ArrayList<ElementList>(); + + public ArrayList<ElementList> getElements() { + return elements; } - public void setResources(ArrayList<ElementList> resources) { - this.resources = resources; + public void setElements(ArrayList<ElementList> resources) { + this.elements = resources; } - public ArrayList<ElementList> getClasses() { - return classes; - } - public void setClasses(ArrayList<ElementList> classes) { - this.classes = classes; - } - private void addClasses(ElementList cl) { - this.classes.add(cl); + private void addElements(ElementList cl) { + this.elements.add(cl); } - private void addResources(ElementList cl) { - this.resources.add(cl); - } - public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ /* * first all Classes! */ try { - this.setClasses(createElementsOfClasses(hypothesen)); + //this.setClasses(createElementsOfClasses(hypothesen)); + createElementsOfClasses(hypothesen); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -50,7 +41,8 @@ * second all Resources */ try { - this.setResources(createElementsOfResources(hypothesen,condition)); + //this.setResources(createElementsOfResources(hypothesen,condition)); + createElementsOfResources(hypothesen,condition); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -59,8 +51,7 @@ System.out.println("Created Elements"); } - private ArrayList<ElementList> createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ - ArrayList<ElementList> classes = new ArrayList<ElementList>(); + private void createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ /* * Iterate over all Hypothesis and look for an IsA @@ -75,17 +66,17 @@ * TODO: improver performance, using geschicktes zwischenspeichern */ ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); - classes.add(el); + //classes.add(el); + this.addElements(el); } } } - return classes; + //return classes; } - private ArrayList<ElementList> createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ - ArrayList<ElementList> resources = new ArrayList<ElementList>(); + private void createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ /* * Iterate over all Hypothesis and look for an resource */ @@ -95,11 +86,17 @@ for(ArrayList<String> cl : conditionList){ if(h.getVariable().equals(cl.get(0))) { ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); - resources.add(el); + //resources.add(el); + this.addElements(el); } if(h.getVariable().equals(cl.get(2))) { - ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); - resources.add(el); + /* + * TDO: Geht hier in die Schleife, aber die Liste wird nicht hinzugefügt.... + */ + ElementList el_left = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); + //resources.add(el); + //el_left.printAll(); + this.addElements(el_left); } } @@ -108,38 +105,30 @@ } } - return resources; + //return resources; } public void printAll(){ - System.out.println("Resources: "); - for(ElementList el: this.resources){ + System.out.println("Elements: "); + for(ElementList el: this.elements){ el.printAll(); } - System.out.println("\nClasses: "); - for(ElementList el: this.classes){ - el.printAll(); - } } public String printToString(){ String result=""; - result+="Resources: \n"; - for(ElementList el: this.resources){ + result+="Elements: \n"; + for(ElementList el: this.elements){ result+=el.printToString()+"\n"; } - result+="\nClasses: \n"; - for(ElementList el: this.classes){ - result+=el.printToString()+"\n"; - } return result; } public boolean isElementEmty(){ try { - if(this.getClasses().isEmpty()||this.getResources().isEmpty()) return true; + if(this.getElements().isEmpty()) return true; else return false; } catch (Exception e) { // TODO Auto-generated catch block Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -7,6 +7,7 @@ private ArrayList<ElementList> list_of_element_uri_pair = new ArrayList<ElementList>(); private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); + private ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; private String having; private String filter; @@ -15,8 +16,11 @@ private String question; private String queryType; private Elements elm; - private float overallTime; - private float time_Templator; + private long overallTime; + private long time_Templator; + private long time_generateElements; + private long time_part1; + private long time_part2; public String getHaving() { return having; @@ -92,6 +96,17 @@ z.printAll(); } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : hypothesenLevensthein){ + System.out.println("\nSet of HypothesenLevensthein"+anzahl+":"); + anzahl+=1; + for ( Hypothesis z : x){ + z.printAll(); + } + } + + System.out.print("\n"); System.out.println("QueryType "+queryType); System.out.println("selectTerm: "+selectTerm); @@ -107,16 +122,16 @@ public void setQuestion(String question) { this.question = question; } - public float getOverallTime() { + public long getOverallTime() { return overallTime; } - public void setOverallTime(float overallTime) { + public void setOverallTime(long overallTime) { this.overallTime = overallTime; } - public float getTime_Templator() { + public long getTime_Templator() { return time_Templator; } - public void setTime_Templator(float time_Templator) { + public void setTime_Templator(long time_Templator) { this.time_Templator = time_Templator; } public ArrayList<ElementList> getList_of_element_uri_pair() { @@ -141,6 +156,30 @@ public void setElm(Elements elm) { this.elm = elm; } + public long getTime_generateElements() { + return time_generateElements; + } + public void setTime_generateElements(long time_generateElements) { + this.time_generateElements = time_generateElements; + } + public long getTime_part1() { + return time_part1; + } + public void setTime_part1(long time_part1) { + this.time_part1 = time_part1; + } + public long getTime_part2() { + return time_part2; + } + public void setTime_part2(long time_part2) { + this.time_part2 = time_part2; + } + public ArrayList<ArrayList<Hypothesis>> getHypothesenLevensthein() { + return hypothesenLevensthein; + } + public void setHypothesenLevensthein(ArrayList<ArrayList<Hypothesis>> hypothesenLevensthein) { + this.hypothesenLevensthein = hypothesenLevensthein; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -77,6 +77,8 @@ long stop_template = System.currentTimeMillis(); for (BasicQueryTemplate bqt : querytemps) { + + long start_part1= System.currentTimeMillis(); ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); //ArrayList<ArrayList<Hypothesis>> hypotesen = new ArrayList<ArrayList<Hypothesis>>(); String selectTerm = ""; @@ -153,8 +155,10 @@ addTemplate=false; } + long stop_part1= System.currentTimeMillis(); + if(addTemplate!=false){ - + long start_part2= System.currentTimeMillis(); /* * SLOT_title: PROPERTY {title,name,label} mitfuehren @@ -162,6 +166,7 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); + template.setTime_part1(stop_part1-start_part1); boolean add_reverse_template = true; @@ -349,20 +354,34 @@ /* * Before adding Templates, generate for each Template a set of Properties and Elements */ + long start_elements = System.currentTimeMillis(); Elements elm = new Elements(template.getCondition(),template.getHypothesen()); + long stop_elements = System.currentTimeMillis(); + template.setTime_generateElements(stop_elements-start_elements); + /* * If no Elements are created, dont add Template! */ - //if(elm.isElementEmty()==false){ + long stop_part2= System.currentTimeMillis(); + template.setTime_part2(stop_part2-start_part2); + if(elm.isElementEmty()==false){ + //elm.printAll(); template.setElm(elm); resultArrayList.add(template); - //} + } if(add_reverse_template){ + start_elements = System.currentTimeMillis(); Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); - //if(elm_reverse.isElementEmty()==false){ - template.setElm(elm_reverse); + stop_elements = System.currentTimeMillis(); + template_reverse_conditions.setTime_generateElements(stop_elements-start_elements); + template_reverse_conditions.setTime_part1(stop_part1-start_part1); + template_reverse_conditions.setTime_part2(stop_part2-start_part2); + + if(elm_reverse.isElementEmty()==false){ + //elm_reverse.printAll(); + template_reverse_conditions.setElm(elm_reverse); resultArrayList.add(template_reverse_conditions); - //} + } } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -12,7 +12,7 @@ * @param t * @return */ - public static ArrayList<QueryPair> returnSetOfQueries(Template t){ + public static ArrayList<QueryPair> returnSetOfQueries(Template t, String type){ ArrayList<QueryPair> queryList = new ArrayList<QueryPair>(); /* @@ -27,7 +27,15 @@ /* * Now replacing varibale with the uri from the Hypot. */ - for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ + ArrayList<ArrayList<Hypothesis>> givenHypothesenList = new ArrayList<ArrayList<Hypothesis>>() ; + if(type.contains("LEVENSTHEIN")){ + givenHypothesenList=t.getHypothesenLevensthein(); + } + else{ + givenHypothesenList=t.getHypothesen(); + } + + for(ArrayList<Hypothesis> hypothesenList : givenHypothesenList){ String condition_new = condition; //System.out.println("New_Condition before replacing "+condition_new); double global_rank=0; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -13,8 +13,8 @@ //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; //private static String server_Prefix="http://dbpedia.org/sparql"; - private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; - //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; + //private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; private static int timeToTimeoutOnServer=30000; @@ -96,6 +96,8 @@ if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=query_property_left; String result=""; + /*System.out.println(verarbeitungsurl); + System.out.println("side: "+ side);*/ result = getListOfElements(verarbeitungsurl); return generateList(result); @@ -109,8 +111,24 @@ */ public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ + /* + PREFIX dbo: <http://dbpedia.org/ontology/> +SELECT DISTINCT ?p WHERE { + { ?x ?p ?y . } UNION { ?y ?p ?x . } + { + SELECT ?x { + ?x rdf:type dbo:Mountain . + } + LIMIT 10 + } +} +ORDER BY ?x + + + TODO:Try with different Limits + */ - String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s ?x WHERE { ?x rdf:type <"+classUri+">. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + String query="PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?s ?p WHERE {{?x ?p ?y. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').}{?y ?p ?x. ?x rdfs:label ?s. FILTER (lang(?s) = 'en').} { SELECT ?x { ?x rdf:type <"+classUri+">.}LIMIT 10}}"; String result=""; result = getListOfElements(query); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -39,69 +39,95 @@ TemplateBuilder testobject = new TemplateBuilder(); String filepath = "/home/swalter/Dokumente/Auswertung/"; - String file="very_small.xml"; - //String file="dbpedia-train.xml"; + //String file="very_small.xml"; + String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); - //String question = "Is the wife of president Obama called Michelle?"; - String question = "Who is the leader of Hamburg?"; - temp_list_result=testobject.createTemplates(question); - Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //String question = "Who is the mayor of Berlin?"; - /*for(Template t : temp_list_result){ - //t.printAll(); - try { - t.getElm().printAll(); - } catch (Exception e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - } - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); - for(QueryPair p : qp){ - tm.put(p, t.getQuestion()); - } - }*/ - for(Template t : temp_list_result){ - t.getElm().getResources(); - IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition()); - } + /* + * Original eine resource zwei properties, nachher nur noch eine Resource und eine property + */ + String question ="Who is the daughter of Bill Clinton married to?"; + long start_template = System.currentTimeMillis(); + //temp_list_result=testobject.createTemplates(question); + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - - ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - /* * Generate Templates */ - /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + /* ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); + list_of_structs=generateStruct(filepath+"XMLDateien/"+file); String result=""; for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); - try { + /*try { result+=t.getElm().printToString()+"\n"; } catch (Exception e) { // TODO Auto-generated catch block //e.printStackTrace(); - } - } + }*/ + // } - }*/ + //} + long stop_template = System.currentTimeMillis(); + + long start_iteration = System.currentTimeMillis(); + long time_generatingElements=0; + long time_part1=0; + long time_part2=0; + + for(Template t : temp_list_result){ + time_generatingElements+=t.getTime_generateElements(); + time_part1+=t.getTime_part1(); + time_part2+=t.getTime_part2(); + try{ + //t.getElm().printAll(); + ArrayList<ArrayList<Hypothesis>> blub = IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition(),"LEVENSTHEIN"); + t.setHypothesenLevensthein(blub); + + //t.printAll(); + } + catch (Exception e){ + + } + + } + long stop_iteration = System.currentTimeMillis(); + System.out.println("The Iteration and Levensthein Mode took "+ (stop_iteration-start_iteration)+"ms"); + System.out.println("The Iteration and Levensthein Mode took for one Template "+ (stop_iteration-start_iteration)/temp_list_result.size()+"ms"); + float time_template =stop_template-start_template; + float time_Templator=temp_list_result.get(0).getTime_Templator(); + System.out.println("Generating the Template took "+ time_template+"ms"); + System.out.println("Generating one Template took "+ time_template/temp_list_result.size()+"ms"); + System.out.println("Templator took "+ time_Templator+"ms"); + System.out.println("Generating the Templates Without Parser "+ (time_template-time_Templator)+"ms"); + System.out.println("Average Time getting Properties etc "+ (time_generatingElements/temp_list_result.size())+"ms"); + System.out.println("Average Time part1 "+ (time_part1/temp_list_result.size())+"ms"); + System.out.println("Average Time part2 "+ (time_part2/temp_list_result.size())+"ms"); + System.out.println("Time getting Properties etc "+ (time_generatingElements)+"ms"); + System.out.println("DONE"); + + + + /* * Create Query for each Template */ - /*Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + //Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - for(Template t : temp_list_result){ + /*for(Template t : temp_list_result){ //t.printAll(); - ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t, "LEVENSTHEIN"); for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } @@ -113,15 +139,16 @@ * Get Elements for Each Resource and Class */ - /*long stop = System.currentTimeMillis(); + /* System.out.println("Duration in ms: " + (stop - start)); writeStringToFile(result,filepath,file,start,stop); */ /* * Write Results in File */ - //writeQueriesInFile(tm,filepath,file,start,stop ); - //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + long stop = System.currentTimeMillis(); + // writeQueriesInFile(tm,filepath,file,start,stop ); + // writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -151,6 +178,22 @@ result+="%%%%%%%%%%%"+"\n"; } } + + anzahl = 1; + for(ArrayList<Hypothesis> x : t.getHypothesenLevensthein()){ + result+="\nSet of LevenstheinHypothesen"+anzahl+":\n"; + anzahl+=1; + for ( Hypothesis z : x){ + result+="%%%%%%%%%%%"+"\n"; + result+="Variable: "+z.getVariable()+"\n"; + result+="Name: "+z.getName()+"\n"; + result+="Uri: " + z.getUri()+"\n"; + result+="Type: " + z.getType()+"\n"; + result+="Rank: "+z.getRank()+"\n"; + result+="%%%%%%%%%%%"+"\n"; + } + } + result+="\n"; result+="queryType: "+t.getQueryType()+"\n"; result+="selectTerm: "+t.getSelectTerm()+"\n"; Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -21,21 +21,64 @@ * @param hypothesen * @param condition * @return ArrayList<ArrayList<Hypothesis>> + * @throws SQLException */ - public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList){ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList, String type) throws SQLException{ + boolean gotResource=true; + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + try{ + resources = elm.getElements(); + } + catch (Exception e){ + gotResource=false; + System.out.println("Didnt get any Resource"); + } + + //System.out.println("Anzahl der Resource Listen: "+resources.size()); + + ArrayList<ArrayList<Hypothesis>>finalHypothesenList = new ArrayList<ArrayList<Hypothesis>>(); + + for(ArrayList<Hypothesis> hl :givenHypothesenList){ + /* + * foundedResourcesClasses + */ + ArrayList<Hypothesis> RL = new ArrayList<Hypothesis>(); /* + * foundedProperty + */ + ArrayList<String> PL = new ArrayList<String>(); + + /* + * hypothesenListBeforSorting + */ + ArrayList<Hypothesis>HL = new ArrayList<Hypothesis>(); + + + /* + * AL abhängig von jeder einzelnen Resource R aus RL + */ + ArrayList<ArrayList<ArrayList<Hypothesis>>> ALR = new ArrayList<ArrayList<ArrayList<Hypothesis>>>(); + + + /* * First look for resources and generate List with properties */ for(Hypothesis h : hl){ + + //System.out.println("In Hypothesis Loop"); if(h.getType().contains("RESOURCE")){ /* * Get Variable from Resource */ String variable = h.getVariable(); + String name = h.getName(); + RL.add(h); + System.out.println("Found Resource"); + /* * Look in Condition for the Set, in which the variable appears */ @@ -43,11 +86,8 @@ for(ArrayList<String> cl : givenConditionList){ for(String s : cl){ if(s.contains(variable)){ - /* - * Mark Also if the Property is left or right from the Resource - */ - if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+variable); - else propertyVariableList.add(cl.get(1)+"LEFT::"+variable); + if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+name); + else propertyVariableList.add(cl.get(1)+"LEFT::"+name); } } } @@ -58,68 +98,215 @@ ArrayList<String> propertyNameList = new ArrayList<String>(); for(String s : propertyVariableList){ for(Hypothesis h_t : hl){ - //System.out.println("s in creating propertyNameList: "+s); String variable_t = s; variable_t=variable_t.replace("RIGHT", ""); variable_t=variable_t.replace("LEFT", ""); - if(h_t.getVariable().contains(variable_t)) propertyNameList.add(h_t.getName()+"::"+s); + String[] variable_t1=variable_t.split("::"); + if(h_t.getVariable().contains(variable_t1[0])){ + propertyNameList.add(h_t.getName()+"::"+s); + } } } - /* * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc */ - ArrayList<ElementList> resources = elm.getResources(); - for(String s : propertyNameList){ - String[] array = s.split("::"); - - System.out.println("s: "+s); - System.out.println("Array:"); - for(String t : array){ - System.out.println(t); + + if(gotResource){ + for(String s : propertyNameList){ + String[] array = s.split("::"); + + System.out.println("String: "+s); + /*System.out.println("Array:"); + for(String t : array){ + System.out.println(t); + }*/ + + /* + * array[0] contains name of Property + * array[1] contains LEFT/RIGHT and Variable of Property + * array[2] contains Name of Resource + */ + + String side="LEFT"; + if(array[1].contains("RIGHT")) side="RIGHT"; + + for(ElementList el : resources){ + if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ + String propertyVariable = array[1]; + propertyVariable=propertyVariable.replace("LEFT", ""); + propertyVariable=propertyVariable.replace("RIGHT", ""); + ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); + try { + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable+"::"+h.getVariable()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for(Hypothesis h_p : resultHypothesenList)HL.add(h_p); + + } + } + } - + } + + + } + + if(h.getType().contains("isA")){ + /* + * TODO:Add special case, if we have only one condition but with an isA in it. + */ + RL.add(h); + System.out.println("Found Class"); + + for(ElementList el:resources){ /* - * array[0] contains name of Property - * array[1] contains LEFT/RIGHT and Variable of Property - * array[2] contains Name of Resource + * Find the resource with the same uri as in h an then start Levensthein/Wordnet etc */ - - String side="LEFT"; - if(array[1].contains("RIGHT")) side="RIGHT"; - - for(ElementList el : resources){ - if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ - String propertyVariable = array[1]; - propertyVariable=propertyVariable.replace("LEFT", ""); - propertyVariable=propertyVariable.replace("RIGHT", ""); - ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); - try { - resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if(el.getURI().contains(h.getUri())){ + /* + * Iterate over condition and find the coressesponding variable of the Class, wich is used for the new Hypothesis + */ + ArrayList<String> propertyVariableList= new ArrayList<String>(); + for(ArrayList<String> cl : givenConditionList){ + /* + * Dont look for line, where e.g. ?x isA ?y + */ + //get(1) is the middle Term and if there is an isa, than its there + if(!cl.get(1).contains("isA")){ + for(String s : cl){ + if(s.contains(h.getVariable())){ + propertyVariableList.add(s); + } + } } + + } + for(String propertyVariable : propertyVariableList){ + for(ArrayList<Hypothesis> hl_small :givenHypothesenList){ + for(Hypothesis h_small : hl_small){ + if(h_small.getVariable().contains(propertyVariable)){ + try { + ArrayList<Hypothesis> resultHypothesenList=new ArrayList<Hypothesis>(); + /* + * Here start levenstehin, wordnet etc etc + */ + if(type.contains("LEVENSTHEIN"))resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,h_small.getName(),el.getHm()); + if(!PL.contains(propertyVariable)) PL.add(propertyVariable); + for(Hypothesis h_temp : resultHypothesenList) HL.add(h_temp); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } - for(Hypothesis h_p : resultHypothesenList) h_p.printAll(); - } + //for(Hypothesis h_p : finalHypothesenList) h_p.printAll(); + + } - } + + } + + } - /* * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case */ + + /*for(Hypothesis h : RL){ + h.printAll(); + } + + for(String s : PL){ + System.out.println("Variable P: "+s); + }*/ + + /* + * Here add new function! + */ + for(Hypothesis R : RL){ + /* + * AL, abhängig von jeder einzelnen P aus PL und R aus RL + */ + ArrayList<ArrayList<Hypothesis>> AL = new ArrayList<ArrayList<Hypothesis>>(); + + + for(String P : PL){ + if(P.contains(R.getVariable())){ + for(Hypothesis H : HL){ + if(P.contains(H.getVariable())){ + ArrayList<Hypothesis> t_h_l = new ArrayList<Hypothesis>(); + t_h_l.add(H); + t_h_l.add(R); + AL.add(t_h_l); + } + } + } + } + + ALR.add(AL); + } + + if(ALR.size()==1){ + System.out.println("ONLY One Element in ALR"); + finalHypothesenList=ALR.get(0); + System.out.println("One Element in ALR added to finalHypothesenList"); + } + if(ALR.size()==2){ + System.out.println("Two Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + } + System.out.println("Two Element in ALR added to finalHypothesenList"); + + } + + if(ALR.size()==2){ + System.out.println("Three Elements in ALR"); + for(ArrayList<Hypothesis> hl_t : ALR.get(0) ){ + for(ArrayList<Hypothesis> hl1_t : ALR.get(1) ){ + for(ArrayList<Hypothesis> hl2_t : ALR.get(2)){ + ArrayList<Hypothesis> al_t = new ArrayList<Hypothesis>(); + for(Hypothesis h_t : hl_t) al_t.add(h_t); + for(Hypothesis h_t : hl1_t) al_t.add(h_t); + for(Hypothesis h_t : hl2_t) al_t.add(h_t); + finalHypothesenList.add(al_t); + } + + } + } + System.out.println("Three Element in ALR added to finalHypothesenList"); + + } + + } + + + + System.out.println("######################DONE######################"); - return null; + return finalHypothesenList; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:09:03 UTC (rev 3624) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-29 13:10:53 UTC (rev 3625) @@ -9,7 +9,7 @@ import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; public class LevenstheinModule { - private final static double LevenstheinMin=0.8; + private final static double LevenstheinMin=0.92; public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) throws SQLException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-03-29 13:09:10
|
Revision: 3624 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3624&view=rev Author: lorenz_b Date: 2012-03-29 13:09:03 +0000 (Thu, 29 Mar 2012) Log Message: ----------- Removed dependencies to SESAME. Changed some examples by reducing execution time. Fixed Unit test to ignore SPARQL examples correctly. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java trunk/examples/carcinogenesis/train.conf trunk/examples/family-benchmark/Aunt.conf trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/components-core/pom.xml 2012-03-29 13:09:03 UTC (rev 3624) @@ -106,6 +106,10 @@ <artifactId>xercesImpl</artifactId> <groupId>xerces</groupId> </exclusion> + <exclusion> + <artifactId>any23-core</artifactId> + <groupId>org.deri.any23</groupId> + </exclusion> </exclusions> </dependency> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/DisjointClassesLearner.java 2012-03-29 13:09:03 UTC (rev 3624) @@ -21,10 +21,8 @@ import java.net.URL; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -46,11 +44,8 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; import org.dllearner.learningproblems.Heuristics; -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.model.vocabulary.RDF; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,6 +56,8 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.vocabulary.OWL2; +import com.hp.hpl.jena.vocabulary.RDF; /** * Learns disjoint classes using SPARQL queries. @@ -340,7 +337,7 @@ //secondly, create disjoint classexpressions with score 1 - (#occurence/#all) for(Entry<NamedClass, Integer> entry : sortByValues(class2Count)){ //drop classes from OWL and RDF namespace - if(entry.getKey().getName().startsWith(OWL.NAMESPACE) || entry.getKey().getName().startsWith(RDF.NAMESPACE))continue; + if(entry.getKey().getName().startsWith(OWL2.getURI()) || entry.getKey().getName().startsWith(RDF.getURI()))continue; // evalDesc = new EvaluatedDescription(entry.getKey(), // new AxiomScore(1 - (entry.getValue() / (double)all))); double[] confidenceInterval = Heuristics.getConfidenceInterval95Wald(total, entry.getValue()); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-03-29 13:09:03 UTC (rev 3624) @@ -44,9 +44,6 @@ import org.dllearner.learningproblems.Heuristics; import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.owl.AxiomComparator; -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.model.vocabulary.RDFS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -58,6 +55,9 @@ import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.util.iterator.Filter; +import com.hp.hpl.jena.vocabulary.OWL2; +import com.hp.hpl.jena.vocabulary.RDF; +import com.hp.hpl.jena.vocabulary.RDFS; /** * @author Lorenz Bühmann @@ -334,7 +334,7 @@ @Override public boolean accept(OntClass cls) { if(!cls.isAnon()){ - return cls.getURI().startsWith(OWL.NAMESPACE); + return cls.getURI().startsWith(OWL2.getURI()); } return false; } @@ -346,7 +346,7 @@ @Override public boolean accept(OntClass cls) { if(!cls.isAnon()){ - return cls.getURI().startsWith(RDFS.NAMESPACE); + return cls.getURI().startsWith(RDFS.getURI()); } return false; } @@ -358,7 +358,7 @@ @Override public boolean accept(OntClass cls) { if(!cls.isAnon()){ - return cls.getURI().startsWith(RDF.NAMESPACE); + return cls.getURI().startsWith(RDF.getURI()); } return false; } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/components-core/src/main/java/org/dllearner/utilities/StructureBasedRootClassFinder.java 2012-03-29 13:09:03 UTC (rev 3624) @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Set; -import org.apache.commons.httpclient.methods.GetMethod; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AddAxiom; import org.semanticweb.owlapi.model.AxiomType; @@ -47,10 +46,6 @@ import org.semanticweb.owlapi.reasoner.OWLReasoner; import org.semanticweb.owlapi.reasoner.OWLReasonerFactory; -import uk.ac.manchester.cs.owlapi.modularity.ModuleType; - -import com.clarkparsia.modularity.ModularityUtils; -import com.clarkparsia.owlapi.modularity.locality.LocalityClass; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; public class StructureBasedRootClassFinder implements RootClassFinder, OWLClassExpressionVisitor { Modified: trunk/examples/carcinogenesis/train.conf =================================================================== --- trunk/examples/carcinogenesis/train.conf 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/examples/carcinogenesis/train.conf 2012-03-29 13:09:03 UTC (rev 3624) @@ -355,7 +355,7 @@ "kb:d335" } -op.type = "syncrho" +op.type = "rho" op.cardinalityLimit = 5 // CELOE configuration @@ -366,7 +366,7 @@ alg.writeSearchTree = false alg.noisePercentage = 32 alg.startClass = "http://dl-learner.org/carcinogenesis#Compound" -alg.maxExecutionTimeInSeconds = 1800 +alg.maxExecutionTimeInSeconds = 100 //alg.maxClassDescriptionTests = 10000000 // PCELOE configuration Modified: trunk/examples/family-benchmark/Aunt.conf =================================================================== --- trunk/examples/family-benchmark/Aunt.conf 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/examples/family-benchmark/Aunt.conf 2012-03-29 13:09:03 UTC (rev 3624) @@ -17,7 +17,7 @@ h.type ="celoe_heuristic" h.expansionPenaltyFactor = 0.02 alg.type = "celoe" -alg.maxExecutionTimeInSeconds = 200 +alg.maxExecutionTimeInSeconds = 100 alg.terminateOnNoiseReached = true Modified: trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-27 15:09:17 UTC (rev 3623) +++ trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-29 13:09:03 UTC (rev 3624) @@ -163,13 +163,13 @@ // start example CLI start = new CLI(new File(conf)); start.init(); - start.run(); // System.out.println("algorithm: " + start.getLearningAlgorithm()); boolean isSparql = start.getKnowledgeSource() instanceof SparqlKnowledgeSource; // boolean isSparql = false; LearningAlgorithm algorithm = start.getLearningAlgorithm(); if((testGP || !(algorithm instanceof GP)) && (sparql == 0 || (sparql == 1 && isSparql) || (sparql == 2 && !isSparql) ) ) { + start.run(); started = true; // start.start(false); // test is successful if a concept was learned This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-03-27 15:09:29
|
Revision: 3623 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3623&view=rev Author: jenslehmann Date: 2012-03-27 15:09:17 +0000 (Tue, 27 Mar 2012) Log Message: ----------- several changes to be able to use the KnowledgeSource interface instead of being forced to use AbstractKnowledgeSource Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java trunk/components-core/src/main/java/org/dllearner/reasoning/DIGReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java trunk/components-core/src/main/java/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java trunk/components-core/src/main/java/org/dllearner/utilities/examples/ExampleDataCollector.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java trunk/components-core/src/test/java/org/dllearner/test/ComponentTest.java trunk/components-core/src/test/java/org/dllearner/test/junit/ELDownTests.java trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java trunk/components-core/src/test/java/org/dllearner/test/junit/TestOntologies.java trunk/interfaces/src/main/java/org/dllearner/gui/Config.java trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java trunk/scripts/src/main/java/org/dllearner/scripts/DumbLPFinder.java trunk/scripts/src/main/java/org/dllearner/scripts/NewSample.java trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java trunk/test/newcomponent/AristotlePosNeg.conf Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractReasonerComponent.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -120,7 +120,7 @@ /** * The underlying knowledge sources. */ - protected Set<AbstractKnowledgeSource> sources; + protected Set<KnowledgeSource> sources; public AbstractReasonerComponent(){ @@ -132,7 +132,7 @@ * @param sources * The underlying knowledge sources. */ - public AbstractReasonerComponent(Set<AbstractKnowledgeSource> sources) { + public AbstractReasonerComponent(Set<KnowledgeSource> sources) { this.sources = sources; } @@ -141,16 +141,16 @@ * * @return The underlying knowledge sources. */ - public Set<AbstractKnowledgeSource> getSources() { + public Set<KnowledgeSource> getSources() { return sources; } - public void setSources(Set<AbstractKnowledgeSource> sources){ + public void setSources(Set<KnowledgeSource> sources){ this.sources = sources; } - public void setSources(AbstractKnowledgeSource... sources) { - this.sources = new HashSet<AbstractKnowledgeSource>(Arrays.asList(sources)); + public void setSources(KnowledgeSource... sources) { + this.sources = new HashSet<KnowledgeSource>(Arrays.asList(sources)); } /** @@ -161,7 +161,7 @@ * @param sources * The new knowledge sources. */ - public void changeSources(Set<AbstractKnowledgeSource> sources) { + public void changeSources(Set<KnowledgeSource> sources) { this.sources = sources; } Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -79,7 +79,7 @@ "org.dllearner.kb.OWLFile", "org.dllearner.kb.SparqlEndpointKS", "org.dllearner.kb.sparql.SparqlKnowledgeSource", - "org.dllearner.kb.sparql.SparqlSimpleExtractor", + "org.dllearner.kb.sparql.simple.SparqlSimpleExtractor", "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.FuzzyPosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -1,6 +1,6 @@ package org.dllearner.kb.sparql.simple; -import org.nlp2rdf.ontology.ClassIndexer; +//import org.nlp2rdf.ontology.ClassIndexer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,22 +9,23 @@ public class SchemaIndexer { private static Logger log = LoggerFactory.getLogger(SchemaIndexer.class); - private ClassIndexer classIndexer=null; +// private ClassIndexer classIndexer=null; public SchemaIndexer(){} public void init(){ - classIndexer=new ClassIndexer(); +// classIndexer=new ClassIndexer(); OntModel model = ModelFactory.createOntologyModel(); model.read(SchemaIndexer.class.getResourceAsStream("dbpedia_3-3.6.owl"), null); - classIndexer.index(model); +// classIndexer.index(model); } public OntModel getHierarchyForURI(String classUri){ - if(classIndexer==null){ - this.init(); - } - return classIndexer.getHierarchyForClassURI(classUri); +// if(classIndexer==null){ +// this.init(); +// } +// return classIndexer.getHierarchyForClassURI(classUri); + return null; } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -27,8 +27,9 @@ private List<String> filters = null; @ConfigOption(name = "recursionDepth", description = "recursion depth", required = true) private int recursionDepth = 0; - @ConfigOption(name = "defaultGraphURI", description = "default graph URI", required = true) - private String defaultGraphURIs=null; + + @ConfigOption(name = "defaultGraphURI", description = "default graph URI", required = true) + private String defaultGraphURI=null; private OWLOntology owlOntology; private static Logger log = LoggerFactory.getLogger(SparqlSimpleExtractor.class); @@ -69,15 +70,15 @@ for (int i = 0; i < recursionDepth - 1; i++) { queryString=aGenerator.createQuery(instances, model, filters); log.info("SPARQL: {}", queryString); - executor.executeQuery(queryString, endpointURL, model,defaultGraphURIs); + executor.executeQuery(queryString, endpointURL, model,defaultGraphURI); } queryString = aGenerator.createLastQuery(instances, model, filters); log.info("SPARQL: {}", queryString); - executor.executeQuery(queryString, endpointURL, model, defaultGraphURIs); + executor.executeQuery(queryString, endpointURL, model, defaultGraphURI); TBoxQueryGenerator tGenerator = new TBoxQueryGenerator(); queryString = tGenerator.createQuery(model, filters, instances); - executor.executeQuery(queryString, endpointURL, model,defaultGraphURIs); + executor.executeQuery(queryString, endpointURL, model,defaultGraphURI); JenaToOwlapiConverter converter = new JenaToOwlapiConverter(); owlOntology=converter.convert(this.model); } @@ -90,6 +91,14 @@ this.endpointURL = endpointURL; } + public String getDefaultGraphURI() { + return defaultGraphURI; + } + + public void setDefaultGraphURI(String defaultGraphURI) { + this.defaultGraphURI = defaultGraphURI; + } + public Model getModel() { return model; } @@ -141,21 +150,8 @@ this.recursionDepth = recursionDepth; } - /** - * @return the defaultGraphURI - */ - public String getDefaultGraphURIs() { - return defaultGraphURIs; - } /** - * @param defaultGraphURI the defaultGraphURI to set - */ - public void setDefaultGraphURIs(String defaultGraphURI) { - this.defaultGraphURIs = defaultGraphURI; - } - - /** * @return */ public OWLOntology getOWLOntology() { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/DIGReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/DIGReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -40,6 +40,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.OntologyFormat; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigEntry; @@ -106,7 +107,7 @@ - public DIGReasoner(Set<AbstractKnowledgeSource> sources) { + public DIGReasoner(Set<KnowledgeSource> sources) { super(sources); try { reasonerURL = new URL("http://localhost:8081"); @@ -148,8 +149,8 @@ // "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + // "xsi:schemaLocation=\"http://dl.kr.org/dig/2003/02/lang\n" + // "http://dl-web.man.ac.uk/dig/2003/02/dig.xsd\" uri=\""+kbURI+"\">"); - for (AbstractKnowledgeSource source : sources) { - sb.append(source.toDIG(kbURI)); + for (KnowledgeSource source : sources) { + sb.append(((AbstractKnowledgeSource)source).toDIG(kbURI)); ResponseDocument rd = null; try { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastInstanceChecker.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -37,6 +37,7 @@ import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.Axiom; @@ -150,8 +151,8 @@ Map<DatatypeProperty, Map<Individual, SortedSet<Integer>>> id, Map<DatatypeProperty, TreeSet<Individual>> bdPos, Map<DatatypeProperty, TreeSet<Individual>> bdNeg, - AbstractKnowledgeSource... sources) { - super(new HashSet<AbstractKnowledgeSource>(Arrays.asList(sources))); + KnowledgeSource... sources) { + super(new HashSet<KnowledgeSource>(Arrays.asList(sources))); this.individuals = individuals; this.classInstancesPos = classInstancesPos; this.opPos = opPos; @@ -160,7 +161,7 @@ this.bdNeg = bdNeg; if(rc == null){ - rc = new OWLAPIReasoner(new HashSet<AbstractKnowledgeSource>(Arrays.asList(sources))); + rc = new OWLAPIReasoner(new HashSet<KnowledgeSource>(Arrays.asList(sources))); try { rc.init(); } catch (ComponentInitException e) { @@ -202,12 +203,12 @@ } } - public FastInstanceChecker(Set<AbstractKnowledgeSource> sources) { + public FastInstanceChecker(Set<KnowledgeSource> sources) { super(sources); } - public FastInstanceChecker(AbstractKnowledgeSource... sources) { - super(new HashSet<AbstractKnowledgeSource>(Arrays.asList(sources))); + public FastInstanceChecker(KnowledgeSource... sources) { + super(new HashSet<KnowledgeSource>(Arrays.asList(sources))); } /** @@ -270,9 +271,10 @@ logger.debug("dematerialising object properties"); for (ObjectProperty atomicRole : atomicRoles) { +// System.out.println(atomicRole + " " + rc.getPropertyMembers(atomicRole)); opPos.put(atomicRole, rc.getPropertyMembers(atomicRole)); } - + logger.debug("dematerialising datatype properties"); for (DatatypeProperty dp : booleanDatatypeProperties) { Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/FastRetrievalReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/FastRetrievalReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -28,6 +28,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.InvalidConfigOptionValueException; @@ -56,7 +57,7 @@ AbstractReasonerComponent rc; - public FastRetrievalReasoner(Set<AbstractKnowledgeSource> sources) { + public FastRetrievalReasoner(Set<KnowledgeSource> sources) { super(sources); rc = new OWLAPIReasoner(sources); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -179,7 +179,7 @@ } - public OWLAPIReasoner(Set<AbstractKnowledgeSource> sources) { + public OWLAPIReasoner(Set<KnowledgeSource> sources) { super(sources); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -42,6 +42,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigOption; @@ -177,7 +178,7 @@ private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); private boolean defaultNegation = true; - public PelletReasoner(Set<AbstractKnowledgeSource> sources) { + public PelletReasoner(Set<KnowledgeSource> sources) { super(sources); } @@ -198,7 +199,7 @@ Set<OWLOntology> allImports = new HashSet<OWLOntology>(); prefixes = new TreeMap<String, String>(); - for (AbstractKnowledgeSource source : sources) { + for (KnowledgeSource source : sources) { if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); @@ -274,7 +275,7 @@ // all other sources are converted to KB and then to an // OWL API ontology } else { - KB kb = source.toKB(); + KB kb = ((AbstractKnowledgeSource)source).toKB(); // System.out.println(kb.toString(null,null)); IRI ontologyIRI = IRI.create("http://example.com"); @@ -460,7 +461,7 @@ Set<OWLOntology> allImports = new HashSet<OWLOntology>(); prefixes = new TreeMap<String, String>(); - for (AbstractKnowledgeSource source : sources) { + for (KnowledgeSource source : sources) { if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); @@ -529,7 +530,7 @@ // all other sources are converted to KB and then to an // OWL API ontology } else { - KB kb = source.toKB(); + KB kb = ((AbstractKnowledgeSource)source).toKB(); // System.out.println(kb.toString(null,null)); IRI ontologyIRI = IRI.create("http://example.com"); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -37,6 +37,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasoningMethodUnsupportedException; import org.dllearner.core.options.BooleanConfigOption; import org.dllearner.core.options.ConfigOption; @@ -163,11 +164,11 @@ private List<OWLOntology> owlAPIOntologies = new LinkedList<OWLOntology>(); private boolean defaultNegation = true; - public ProtegeReasoner(Set<AbstractKnowledgeSource> sources) { + public ProtegeReasoner(Set<KnowledgeSource> sources) { super(sources); } - public ProtegeReasoner(Set<AbstractKnowledgeSource> sources, OWLReasoner reasoner) { + public ProtegeReasoner(Set<KnowledgeSource> sources, OWLReasoner reasoner) { this(sources); this.reasoner = reasoner; } @@ -247,7 +248,7 @@ Set<OWLOntology> allImports = new HashSet<OWLOntology>(); prefixes = new TreeMap<String, String>(); - for (AbstractKnowledgeSource source : sources) { + for (KnowledgeSource source : sources) { if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); @@ -311,7 +312,7 @@ // all other sources are converted to KB and then to an // OWL API ontology } else { - KB kb = source.toKB(); + KB kb = ((AbstractKnowledgeSource)source).toKB(); // System.out.println(kb.toString(null,null)); IRI ontologyIRI = IRI.create("http://example.com"); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -42,6 +42,7 @@ import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; @@ -177,7 +178,7 @@ } - public FuzzyOWLAPIReasoner(Set<AbstractKnowledgeSource> sources) { + public FuzzyOWLAPIReasoner(Set<KnowledgeSource> sources) { super(sources); } @@ -244,7 +245,7 @@ Set<OWLOntology> allImports = new HashSet<OWLOntology>(); prefixes = new TreeMap<String,String>(); - for(AbstractKnowledgeSource source : sources) { + for(KnowledgeSource source : sources) { if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); @@ -278,7 +279,7 @@ // all other sources are converted to KB and then to an // OWL API ontology } else { - KB kb = source.toKB(); + KB kb = ((AbstractKnowledgeSource)source).toKB(); // System.out.println(kb.toString(null,null)); IRI ontologyURI = IRI.create("http://example.com"); Modified: trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/RhoDRDown.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -309,7 +309,7 @@ } } frequentValues.put(op, frequentInds); - + } } Modified: trunk/components-core/src/main/java/org/dllearner/utilities/examples/ExampleDataCollector.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/examples/ExampleDataCollector.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/utilities/examples/ExampleDataCollector.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -35,6 +35,7 @@ import org.dllearner.algorithms.ocel.OCEL; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.reasoning.FastInstanceChecker; @@ -73,7 +74,7 @@ urls.addAll (convert(baseDir, pos)); urls.addAll (convert(baseDir, neg)); - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); try { URL add = new File(baseDir+"tiger.rdf").toURI().toURL(); // add = new File(baseDir+"new.rdf").toURI().toURL(); @@ -94,7 +95,7 @@ // la.getConfigurator().setUseAllConstructor(false); // la.getConfigurator().setUseExistsConstructor(false); la.setUseDataHasValueConstructor(true); - for(AbstractKnowledgeSource ks: tmp){ + for(KnowledgeSource ks: tmp){ ks.init(); } rc.init(); Modified: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyCloser.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -27,9 +27,9 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.ClassAssertionAxiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.EquivalentClassesAxiom; @@ -64,7 +64,7 @@ super(); this.kb = kb; this.kbFile = new KBFile(this.kb); - Set<AbstractKnowledgeSource> ks = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(this.kbFile); OWLAPIReasoner owlapi = new OWLAPIReasoner(); owlapi.setSources(ks); @@ -85,7 +85,7 @@ SimpleClock sc = new SimpleClock(); sc.printAndSet(); this.kbFile = new KBFile(this.kb); - Set<AbstractKnowledgeSource> ks = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(this.kbFile); sc.printAndSet("updating reasoner"); Modified: trunk/components-core/src/test/java/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/ComponentTest.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/test/java/org/dllearner/test/ComponentTest.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -19,20 +19,16 @@ package org.dllearner.test; -import java.io.File; import java.net.MalformedURLException; import java.util.Collections; import java.util.Set; import java.util.TreeSet; import org.dllearner.algorithms.ocel.OCEL; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; -import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Individual; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegLPStandard; @@ -55,7 +51,7 @@ // create knowledge source String example = "../examples/family/uncle.owl"; - AbstractKnowledgeSource source = new OWLFile(example); + KnowledgeSource source = new OWLFile(example); // create OWL API reasoning service with standard settings AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(source)); Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/ELDownTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/ELDownTests.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/ELDownTests.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -35,10 +35,9 @@ import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.el.ELDescriptionNode; import org.dllearner.algorithms.el.ELDescriptionTree; -import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; @@ -298,7 +297,7 @@ logger.addAppender(app); String ont = "../test/galen2.owl"; - AbstractKnowledgeSource source = new OWLFile(ont); + KnowledgeSource source = new OWLFile(ont); source.init(); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(source)); reasoner.init(); @@ -333,7 +332,7 @@ public void asTest() throws ComponentInitException, MalformedURLException { String ont = "../test/galen2.owl"; - AbstractKnowledgeSource source = new OWLFile(ont); + KnowledgeSource source = new OWLFile(ont); source.init(); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(source)); reasoner.init(); Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/RefinementOperatorTests.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -21,8 +21,6 @@ import static org.junit.Assert.assertTrue; -import java.io.File; -import java.net.MalformedURLException; import java.util.Collections; import java.util.Set; import java.util.TreeSet; @@ -30,16 +28,15 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.dllearner.algorithms.ocel.OCEL; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.owl.ClassHierarchy; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.NamedClass; -import org.dllearner.core.owl.Thing; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.PosNegLPStandard; import org.dllearner.parser.KBParser; @@ -71,7 +68,7 @@ public void rhoDRDownTest() { try { String file = "../examples/carcinogenesis/carcinogenesis.owl"; - AbstractKnowledgeSource ks = new OWLFile(file); + KnowledgeSource ks = new OWLFile(file); AbstractReasonerComponent reasoner = new OWLAPIReasoner(Collections.singleton(ks)); reasoner.init(); baseURI = reasoner.getBaseURI(); Modified: trunk/components-core/src/test/java/org/dllearner/test/junit/TestOntologies.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/test/junit/TestOntologies.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/components-core/src/test/java/org/dllearner/test/junit/TestOntologies.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -19,14 +19,12 @@ package org.dllearner.test.junit; -import java.io.File; -import java.net.MalformedURLException; import java.util.Collections; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.KB; import org.dllearner.kb.KBFile; import org.dllearner.kb.OWLFile; @@ -141,7 +139,7 @@ try { ComponentManager cm = ComponentManager.getInstance(); - AbstractKnowledgeSource source; + KnowledgeSource source; // parse KB string if one has been specified if(!kbString.isEmpty() || ont.equals(TestOntology.EMPTY)) { Modified: trunk/interfaces/src/main/java/org/dllearner/gui/Config.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/gui/Config.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/interfaces/src/main/java/org/dllearner/gui/Config.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -28,14 +28,15 @@ import org.apache.log4j.Logger; import org.dllearner.cli.Start; +import org.dllearner.core.AbstractCELA; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractCELA; -import org.dllearner.core.AbstractLearningProblem; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblemUnsupportedException; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; import org.dllearner.kb.KBFile; @@ -44,7 +45,6 @@ import org.dllearner.learningproblems.ClassLearningProblem; import org.dllearner.learningproblems.PosNegLP; import org.dllearner.learningproblems.PosOnlyLP; -import org.dllearner.parser.ParseException; /** * Config save all together used variables: ComponentManager, KnowledgeSource, @@ -215,7 +215,7 @@ */ public AbstractKnowledgeSource changeKnowledgeSource(Class<? extends AbstractKnowledgeSource> clazz) { source = cm.knowledgeSource(clazz); - Set<AbstractKnowledgeSource> sources = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(source); reasoner.changeSources(sources); // logger.debug("knowledge source " + clazz + " changed"); Modified: trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/examples/KRKModular.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -20,6 +20,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.ClassAssertionAxiom; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; @@ -249,7 +250,7 @@ ComponentManager cm = ComponentManager.getInstance(); AbstractCELA la = null; try { - Set<AbstractKnowledgeSource> sources = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> sources = new HashSet<KnowledgeSource>(); sources.add(new KBFile(kb)); FastInstanceChecker r = new FastInstanceChecker(); r.setSources(sources); @@ -485,7 +486,7 @@ public void initReasonerFact(){ KBFile kbFile = new KBFile(this.kb); - Set<AbstractKnowledgeSource> ks = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(kbFile); reasoner = new OWLAPIReasoner(ks); @@ -500,7 +501,7 @@ public void initFIC(){ KBFile kbFile = new KBFile(this.kb); - Set<AbstractKnowledgeSource> ks = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(kbFile); //System.out.println("blabla"); reasoner = new FastInstanceChecker(); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/CloseOntology.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -22,7 +22,7 @@ import java.util.HashSet; import java.util.Set; -import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.KnowledgeSource; import org.dllearner.kb.OWLFile; import org.dllearner.reasoning.OWLAPIReasoner; import org.dllearner.utilities.owl.OntologyCloserOWLAPI; @@ -60,7 +60,7 @@ // initializing reasoner OWLFile owlFile = new OWLFile(); owlFile.setURL(inputURI.toURL()); - Set<AbstractKnowledgeSource> ks = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> ks = new HashSet<KnowledgeSource>(); ks.add(owlFile); OWLAPIReasoner owlapireasoner = new OWLAPIReasoner(); owlapireasoner.setSources(ks); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/DumbLPFinder.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/DumbLPFinder.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/DumbLPFinder.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -32,9 +32,9 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.ocel.OCEL; -import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Individual; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; @@ -225,7 +225,7 @@ ks.setPredefinedEndpoint("LOCALJOSEKIBIBLE"); ks.setUseLits(true); - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); tmp.add(ks); // reasoner OWLAPIReasoner f = new OWLAPIReasoner(tmp); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/NewSample.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/NewSample.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/NewSample.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -34,10 +34,10 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.ocel.OCEL; -import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningProblemUnsupportedException; import org.dllearner.kb.OWLFile; import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; @@ -125,7 +125,7 @@ OWLFile ks = new OWLFile(); ks.setUrl(fileURL); - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); tmp.add(ks); // reasoner FastInstanceChecker f = new FastInstanceChecker(tmp); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SemanticBibleComparison.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -46,6 +46,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentManager; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Description; import org.dllearner.core.owl.Individual; import org.dllearner.gui.Config; @@ -466,7 +467,7 @@ ks.setRecursionDepth(3); } - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); tmp.add(ks); // reasoner OWLAPIReasoner f = new OWLAPIReasoner(tmp); @@ -505,7 +506,7 @@ } OWLFile ks = new OWLFile( fileURL); - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); tmp.add(ks); AbstractReasonerComponent f = null; Modified: trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/WikipediaCategoryCleaner.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -37,6 +37,7 @@ import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.Individual; import org.dllearner.kb.extraction.ExtractionAlgorithm; import org.dllearner.kb.extraction.Manager; @@ -303,7 +304,7 @@ - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); tmp.add(ks); // reasoner FastInstanceChecker f = new FastInstanceChecker(tmp); Modified: trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/scripts/src/main/java/org/dllearner/scripts/tiger/TestIterativeLearning.java 2012-03-27 15:09:17 UTC (rev 3623) @@ -26,6 +26,7 @@ import org.dllearner.core.ComponentManager; import org.dllearner.core.ComponentPool; import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.OWLFile; import org.dllearner.kb.sparql.Cache; @@ -444,8 +445,8 @@ } - private static Set<AbstractKnowledgeSource> _getOWL(Examples ex) throws Exception { - Set<AbstractKnowledgeSource> tmp = new HashSet<AbstractKnowledgeSource>(); + private static Set<KnowledgeSource> _getOWL(Examples ex) throws Exception { + Set <KnowledgeSource> tmp = new HashSet<KnowledgeSource>(); List<URL> urls = new ArrayList<URL>(); urls.add(new File(backgroundXML).toURI().toURL()); urls.addAll(ExampleDataCollector.convert(sentenceXMLFolder, ex.getPosTrain())); @@ -499,11 +500,11 @@ // } public static FastInstanceChecker _getFastInstanceChecker(Examples ex) throws Exception { - Set<AbstractKnowledgeSource> tmp = _getOWL(ex); + Set<KnowledgeSource> tmp = _getOWL(ex); // Set<KnowledgeSource> tmp = _getSPARQL(ex); FastInstanceChecker rc = new FastInstanceChecker(tmp); - for (AbstractKnowledgeSource ks : tmp) { + for (KnowledgeSource ks : tmp) { ks.init(); } rc.init(); Modified: trunk/test/newcomponent/AristotlePosNeg.conf =================================================================== --- trunk/test/newcomponent/AristotlePosNeg.conf 2012-03-27 12:45:35 UTC (rev 3622) +++ trunk/test/newcomponent/AristotlePosNeg.conf 2012-03-27 15:09:17 UTC (rev 3623) @@ -12,7 +12,7 @@ // SPARQL options sparql.type = "sparqls" sparql.endpointURL = "http://live.dbpedia.org/sparql" -sparql.defaultGraphURIs = {"http://dbpedia.org"} +sparql.defaultGraphURI = "http://dbpedia.org" sparql.recursionDepth = 1 sparql.instances = { @@ -47,3 +47,5 @@ // we use the OCEL algorithm alg.type = "ocel" alg.reasoner = reasoner +alg.learningProblem = lp + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-03-27 12:45:45
|
Revision: 3622 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3622&view=rev Author: dcherix Date: 2012-03-27 12:45:35 +0000 (Tue, 27 Mar 2012) Log Message: ----------- Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-27 10:50:33 UTC (rev 3621) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-27 12:45:35 UTC (rev 3622) @@ -19,39 +19,108 @@ package org.dllearner.reasoning; -import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +import java.io.File; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.dllearner.core.AbstractKnowledgeSource; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.AbstractKnowledgeSource; -import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.config.ConfigOption; -import org.dllearner.core.owl.*; +import org.dllearner.core.owl.Axiom; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.Datatype; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.Entity; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.KB; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.OWL2Datatype; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.TypedConstant; +import org.dllearner.core.owl.UntypedConstant; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.sparql.SparqlKnowledgeSource; -import org.dllearner.kb.sparql.SparqlSimpleExtractor; -import org.dllearner.utilities.owl.*; +import org.dllearner.kb.sparql.simple.SparqlSimpleExtractor; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.DLLearnerDescriptionConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIAxiomConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; +import org.dllearner.utilities.owl.RoleComparator; import org.semanticweb.HermiT.Reasoner.ReasonerFactory; import org.semanticweb.owlapi.apibinding.OWLManager; -import org.semanticweb.owlapi.model.*; +import org.semanticweb.owlapi.model.AddAxiom; +import org.semanticweb.owlapi.model.AddImport; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassExpression; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataRange; +import org.semanticweb.owlapi.model.OWLDatatype; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLImportsDeclaration; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLNamedObject; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyChange; +import org.semanticweb.owlapi.model.OWLOntologyChangeException; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyFormat; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; +import org.semanticweb.owlapi.model.RemoveAxiom; +import org.semanticweb.owlapi.model.UnknownOWLOntologyException; import org.semanticweb.owlapi.owllink.OWLlinkHTTPXMLReasonerFactory; import org.semanticweb.owlapi.owllink.OWLlinkReasonerConfiguration; -import org.semanticweb.owlapi.reasoner.*; +import org.semanticweb.owlapi.reasoner.FreshEntityPolicy; +import org.semanticweb.owlapi.reasoner.IndividualNodeSetPolicy; +import org.semanticweb.owlapi.reasoner.InferenceType; +import org.semanticweb.owlapi.reasoner.Node; +import org.semanticweb.owlapi.reasoner.NodeSet; +import org.semanticweb.owlapi.reasoner.NullReasonerProgressMonitor; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration; +import org.semanticweb.owlapi.reasoner.ReasonerProgressMonitor; +import org.semanticweb.owlapi.reasoner.SimpleConfiguration; import org.semanticweb.owlapi.util.SimpleIRIMapper; import org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat; import org.springframework.beans.propertyeditors.StringTrimmerEditor; + import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasonerFactory; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; -import java.io.File; -import java.net.URI; -import java.net.URL; -import java.util.*; -import java.util.Map.Entry; +import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; /** * Mapping to OWL API reasoner interface. The OWL API currently @@ -158,6 +227,10 @@ if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); owlAPIOntologies.add(ontology); + } else if(source instanceof SparqlSimpleExtractor) { + ontology=((SparqlSimpleExtractor) source).getOWLOntology(); + manager=ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); } if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof SparqlSimpleExtractor || source instanceof OWLAPIOntology) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dc...@us...> - 2012-03-27 10:50:42
|
Revision: 3621 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3621&view=rev Author: dcherix Date: 2012-03-27 10:50:33 +0000 (Tue, 27 Mar 2012) Log Message: ----------- Added Paths: ----------- trunk/test/newcomponent/ trunk/test/newcomponent/AristotlePosNeg.conf Added: trunk/test/newcomponent/AristotlePosNeg.conf =================================================================== --- trunk/test/newcomponent/AristotlePosNeg.conf (rev 0) +++ trunk/test/newcomponent/AristotlePosNeg.conf 2012-03-27 10:50:33 UTC (rev 3621) @@ -0,0 +1,49 @@ +/** + * Some people from Greece. + * Note: DBpedia is always subject to change, solutions will change over time + + * Possible Solution: + * Theorist OR (Mathematician AND Physicist) + * + * This is the same as AristotlePos.conf, but positives and negatives + */ + + +// SPARQL options +sparql.type = "sparqls" +sparql.endpointURL = "http://live.dbpedia.org/sparql" +sparql.defaultGraphURIs = {"http://dbpedia.org"} +sparql.recursionDepth = 1 + +sparql.instances = { +"http://dbpedia.org/resource/Democritus", +"http://dbpedia.org/resource/Zeno_of_Elea", +"http://dbpedia.org/resource/Plato", +"http://dbpedia.org/resource/Socrates", +"http://dbpedia.org/resource/Archytas", +"http://dbpedia.org/resource/Pythagoras", +"http://dbpedia.org/resource/Philolaus" +} + +reasoner.type = "fast instance checker" +reasoner.sources = {sparql} + + +// we want to learn from positive and negative examples +lp.type = "posNegStandard" +lp.positiveExamples = { +"http://dbpedia.org/resource/Archytas", +"http://dbpedia.org/resource/Pythagoras", +"http://dbpedia.org/resource/Philolaus" +} +lp.negativeExamples = { +"http://dbpedia.org/resource/Democritus", +"http://dbpedia.org/resource/Zeno_of_Elea", +"http://dbpedia.org/resource/Plato", +"http://dbpedia.org/resource/Socrates" +} +lp.reasoner = reasoner + +// we use the OCEL algorithm +alg.type = "ocel" +alg.reasoner = reasoner This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-03-26 12:21:35
|
Revision: 3620 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3620&view=rev Author: lorenz_b Date: 2012-03-26 12:21:24 +0000 (Mon, 26 Mar 2012) Log Message: ----------- Updated examples. Modified Paths: -------------- trunk/examples/carcinogenesis/train.conf trunk/examples/family-benchmark/Aunt.conf trunk/examples/family-benchmark/Cousin.conf trunk/examples/family-benchmark/Uncle.conf trunk/examples/father.conf Modified: trunk/examples/carcinogenesis/train.conf =================================================================== --- trunk/examples/carcinogenesis/train.conf 2012-03-26 12:19:20 UTC (rev 3619) +++ trunk/examples/carcinogenesis/train.conf 2012-03-26 12:21:24 UTC (rev 3620) @@ -1,5 +1,8 @@ prefixes = [ ("kb","http://dl-learner.org/carcinogenesis#") ] + cli.type = "org.dllearner.cli.CLI" + cli.performCrossValidation = true + // knowledge source definition ks.type = "OWL File" ks.fileName = "carcinogenesis.owl" @@ -352,17 +355,44 @@ "kb:d335" } -op.type = "rho" +op.type = "syncrho" op.cardinalityLimit = 5 -alg.type = "ocel" +// CELOE configuration +alg.type = "celoe" +h.type ="celoe_heuristic" +h.expansionPenaltyFactor = 0.02 alg.searchTreeFile = "log/carcinogenesis/searchTree.log" alg.writeSearchTree = false alg.noisePercentage = 32 alg.startClass = "http://dl-learner.org/carcinogenesis#Compound" +alg.maxExecutionTimeInSeconds = 1800 +//alg.maxClassDescriptionTests = 10000000 + +// PCELOE configuration +/*h.type ="celoe_heuristic" +h.expansionPenaltyFactor = 0.02 +h.startNodeBonus = 1.0 +alg.type = "pceloe" +alg.nrOfThreads = 4 +alg.searchTreeFile = "log/carcinogenesis/searchTree.log" +alg.writeSearchTree = false +alg.noisePercentage = 32 +alg.startClass = "http://dl-learner.org/carcinogenesis#Compound" +alg.maxExecutionTimeInSeconds = 1800 +alg.maxClassDescriptionTests = 10000000*/ + +// OCEL configuration +/*alg.type = "ocel" +alg.searchTreeFile = "log/carcinogenesis/searchTree.log" +alg.writeSearchTree = false +alg.noisePercentage = 32 +alg.startClass = "http://dl-learner.org/carcinogenesis#Compound" // store some settings to make the experiment reproducable in the future alg.negativeWeight = 0.8 alg.startNodeBonus = 1.0 alg.forceRefinementLengthIncrease = false alg.usePropernessChecks = false -alg.maxExecutionTimeInSeconds = 20 \ No newline at end of file +//alg.maxExecutionTimeInSeconds = 10 +*/ + Modified: trunk/examples/family-benchmark/Aunt.conf =================================================================== --- trunk/examples/family-benchmark/Aunt.conf 2012-03-26 12:19:20 UTC (rev 3619) +++ trunk/examples/family-benchmark/Aunt.conf 2012-03-26 12:21:24 UTC (rev 3620) @@ -14,16 +14,23 @@ op.useCardinalityRestrictions = false // CELOE cofiguration -/* h.type ="celoe_heuristic" h.expansionPenaltyFactor = 0.02 alg.type = "celoe" alg.maxExecutionTimeInSeconds = 200 alg.terminateOnNoiseReached = true -*/ + +// PCELOE cofiguration +/*h.type ="celoe_heuristic" +h.expansionPenaltyFactor = 0.02 +alg.type = "pceloe" +alg.nrOfThreads = 4 +alg.maxExecutionTimeInSeconds = 200 +alg.terminateOnNoiseReached = true*/ + // OCEL configuration -alg.type = "ocel" +// alg.type = "ocel" // Disjunctive ELTL // alg.type = "deltl" Modified: trunk/examples/family-benchmark/Cousin.conf =================================================================== --- trunk/examples/family-benchmark/Cousin.conf 2012-03-26 12:19:20 UTC (rev 3619) +++ trunk/examples/family-benchmark/Cousin.conf 2012-03-26 12:21:24 UTC (rev 3620) @@ -14,17 +14,25 @@ op.useCardinalityRestrictions = false op.useAllConstructor = false -// CELOE configuration -/* +// CELOE cofiguration h.type ="celoe_heuristic" h.expansionPenaltyFactor = 0.02 alg.type = "celoe" -alg.maxExecutionTimeInSeconds = 100 +alg.maxExecutionTimeInSeconds = 200 alg.terminateOnNoiseReached = true -*/ -alg.type = "ocel" +// PCELOE cofiguration +/*h.type ="celoe_heuristic" +h.expansionPenaltyFactor = 0.02 +alg.type = "pceloe" +alg.nrOfThreads = 4 +alg.maxExecutionTimeInSeconds = 200 +alg.terminateOnNoiseReached = true*/ + +// OCEL configuration +// alg.type = "ocel" + // Disjunctive ELTL // alg.type = "deltl" // alg.tryFullCoverage = true Modified: trunk/examples/family-benchmark/Uncle.conf =================================================================== --- trunk/examples/family-benchmark/Uncle.conf 2012-03-26 12:19:20 UTC (rev 3619) +++ trunk/examples/family-benchmark/Uncle.conf 2012-03-26 12:21:24 UTC (rev 3620) @@ -13,17 +13,25 @@ op.useCardinalityRestrictions = false // op.useAllConstructor = false -// CELOE cofiguration -/* +// CELOE configuration h.type ="celoe_heuristic" h.expansionPenaltyFactor = 0.02 alg.type = "celoe" alg.maxExecutionTimeInSeconds = 200 alg.terminateOnNoiseReached = true + + +// PCELOE configuration +/*h.type ="celoe_heuristic" +h.expansionPenaltyFactor = 0.02 +alg.type = "pceloe" +alg.nrOfThreads = 4 +alg.maxExecutionTimeInSeconds = 200 +alg.terminateOnNoiseReached = true */ // OCEL configuration -alg.type = "ocel" +// alg.type = "ocel" // Disjunctive ELTL // alg.type = "deltl" Modified: trunk/examples/father.conf =================================================================== --- trunk/examples/father.conf 2012-03-26 12:19:20 UTC (rev 3619) +++ trunk/examples/father.conf 2012-03-26 12:21:24 UTC (rev 3620) @@ -24,4 +24,5 @@ lp.negativeExamples = { "ex:heinz", "ex:anna", "ex:michelle" } // create learning algorithm to run -alg.type = "ocel" +alg1.type = "celoe" +alg2.type = "pceloe" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-03-26 12:19:30
|
Revision: 3619 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3619&view=rev Author: lorenz_b Date: 2012-03-26 12:19:20 +0000 (Mon, 26 Mar 2012) Log Message: ----------- Some changed needed to be consistent with parent pom and updated libs. Modified Paths: -------------- trunk/interfaces/pom.xml trunk/interfaces/src/main/assemble/archive.xml trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java Added Paths: ----------- trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java Removed Paths: ------------- trunk/scripts/src/main/resources/dbpedia_0.75.owl trunk/scripts/src/main/resources/dbpedia_0.75_no_datapropaxioms.owl Modified: trunk/interfaces/pom.xml =================================================================== --- trunk/interfaces/pom.xml 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/pom.xml 2012-03-26 12:19:20 UTC (rev 3619) @@ -15,7 +15,7 @@ </parent> <properties> - <release.name>1.0-beta-1</release.name> + <release.name>1.0-beta-2</release.name> </properties> <profiles> @@ -312,6 +312,7 @@ </dependency> <!--END Logging Dependencies--> + </dependencies> Modified: trunk/interfaces/src/main/assemble/archive.xml =================================================================== --- trunk/interfaces/src/main/assemble/archive.xml 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/assemble/archive.xml 2012-03-26 12:19:20 UTC (rev 3619) @@ -1,6 +1,7 @@ <assembly> <id>archive</id> <formats> + <format>zip</format> <format>tar.gz</format> <format>zip</format> </formats> @@ -33,6 +34,11 @@ <fileSet> <directory>../examples</directory> <outputDirectory>examples</outputDirectory> + <excludes> + <exclude> + **/qtl/ + </exclude> + </excludes> </fileSet> <fileSet> <directory>doc</directory> Modified: trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/java/org/dllearner/cli/CLI.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -25,6 +25,7 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import java.util.Map.Entry; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Layout; @@ -123,9 +124,12 @@ AbstractCELA la = context.getBean(AbstractCELA.class); new CrossValidation(la,lp,rs,nrOfFolds,false); } else { - knowledgeSource = context.getBeansOfType(KnowledgeSource.class).entrySet().iterator().next().getValue(); - algorithm = context.getBean(LearningAlgorithm.class); - algorithm.start(); +// knowledgeSource = context.getBeansOfType(Knowledge1Source.class).entrySet().iterator().next().getValue(); + for(Entry<String, LearningAlgorithm> entry : context.getBeansOfType(LearningAlgorithm.class).entrySet()){ + algorithm = entry.getValue(); + logger.info("Running algorithm instance \"" + entry.getKey() + "\"(" + algorithm.getClass().getSimpleName() + ")"); + algorithm.start(); + } } } Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -352,7 +352,7 @@ System.out.println(resource + " appears to be a class. Running appropriate algorithms.\n"); try { runClassLearningAlgorithms(ks, (NamedClass) resource); - } catch (Exception e) { + } catch (Exception e) {e.printStackTrace(); System.out.println(e.getCause()); } catch (Error e) { System.out.println(e.getCause()); Modified: trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java =================================================================== --- trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/interfaces/src/test/java/org/dllearner/test/junit/ExampleTests.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -81,7 +81,7 @@ // setting for SPARQL based tests (0 = no special treatment, 1 = test only SPARQL // examples, 2 = skip SPARQL tests) - int sparql = 0; + int sparql = 2; // we use a logger, which outputs few messages (warnings, errors) SimpleLayout layout = new SimpleLayout(); Modified: trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/examples/pdb/PDBIdRdfModel.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -18,6 +18,7 @@ import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; @@ -307,9 +308,9 @@ while ( residuePosition.hasNext() ) { RDFNode positionNode = residuePosition.next(); positionNodes.add(positionNode); - NodeIterator positionLabelNodes = _pdbIdModel.listObjectsOfProperty( positionNode.asResource(), hasValue ); + NodeIterator positionLabelNodes = _pdbIdModel.listObjectsOfProperty( positionNode.as(Resource.class), hasValue ); while ( positionLabelNodes.hasNext() ) { - positionLabels.add(positionLabelNodes.next().asLiteral().getInt()); + positionLabels.add(positionLabelNodes.next().as(Literal.class).getInt()); } } Added: trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/DescriptionSorter.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,60 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.util.Collection; +import java.util.Comparator; +import java.util.Set; +import java.util.TreeSet; + +import org.semanticweb.owlapi.model.OWLNamedObject; +import org.semanticweb.owlapi.model.OWLObject; + +/** + * <p>Title: </p> + * + * <p>Description: </p> + * + * <p>Copyright: Copyright (c) 2008</p> + * + * <p>Company: Clark & Parsia, LLC. <http://www.clarkparsia.com></p> + * + * @author Evren Sirin + */ +public class DescriptionSorter { + + /** + * Sorts a set of OWLObjects alphabetically based on toString values. + * Named objects always come before unnamed objects. + * + * @param set the set to sort + * @return the sorted version of the set + */ + public static <N extends OWLObject> Set<N> toSortedSet(Collection<N> set) { + Set<N> sorted = new TreeSet<N>(new Comparator<N>() { + public int compare(N o1, N o2) { + boolean named1 = o1 instanceof OWLNamedObject; + boolean named2 = o2 instanceof OWLNamedObject; + int cmp; + if (named1 && !named2) + cmp = -1; + else if (!named1 && named2) + cmp = 1; + else + cmp = o1.toString().compareTo(o2.toString()); + + if( cmp == 0 && named1 && named2) + cmp = ((OWLNamedObject) o1).getIRI().compareTo( ((OWLNamedObject) o2).getIRI() ); + + return cmp; + } + }); + sorted.addAll(set); + return sorted; + } + +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxExplanationRenderer.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,181 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLException; +import org.semanticweb.owlapi.reasoner.OWLReasoner; + +import com.clarkparsia.owlapi.explanation.io.ExplanationRenderer; +import com.clarkparsia.owlapi.explanation.io.manchester.BlockWriter; +import com.clarkparsia.owlapi.explanation.io.manchester.TextBlockWriter; + +/** + * An explanation renderer implementation that prints the axioms in the + * explanation using Manchester syntax. + * + * @author Evren Sirin + */ +public class ManchesterSyntaxExplanationRenderer implements ExplanationRenderer { + protected ManchesterSyntaxObjectRenderer renderer; + + protected BlockWriter writer; + + protected OWLAxiom currentAxiom; + + private boolean wrapLines = true; + + private boolean smartIndent = true; + + private int index; + + private OWLReasoner reasoner; + + public ManchesterSyntaxExplanationRenderer(OWLReasoner reasoner) { + this.reasoner = reasoner; + } + + /** + * {@inheritDoc} + */ + public void endRendering() { + writer.flush(); + } + + /** + * Returns the current axioms being whose explanation is being rendered or + * <code>null</code> if no axiom has been provided. + * + * @return the current axioms being whose explanation is being rendered or + * <code>null</code> if no axiom has been provided + */ + protected OWLAxiom getCurrentAxiom() { + return currentAxiom; + } + + /** + * Returns the current smart indent value. + * + * @return the current smart indent value + */ + public boolean isSmartIndent() { + return smartIndent; + } + + /** + * Returns the current line wrapping value. + * + * @return the current line wrapping value + */ + public boolean isWrapLines() { + return wrapLines; + } + + /** + * Render an explanation without the axiom header. This function is not guaranteed + * to be supported by the subclasses since an explanation renderer may rely on the + * axiom being explained to reorder the axioms or find irrelevant bits. + * + * @param explanations Set of explanations we are rendering + * @throws OWLException + * @throws IOException + * @throws UnsupportedOperationException + */ + public void render(Set<Set<OWLAxiom>> explanations) throws OWLException, + IOException, UnsupportedOperationException { + render( (OWLAxiom) null, explanations ); + } + + /** + * {@inheritDoc} + */ + public void render(OWLAxiom axiom, Set<Set<OWLAxiom>> explanations) throws OWLException, + IOException { + setCurrentAxiom( axiom ); + + if (index == 1) { + if (axiom != null) { + writer.print("Axiom: "); + axiom.accept(renderer); + writer.println(); + writer.println(); + } + if (explanations.isEmpty()) { + writer.println( "Explanation: AXIOM IS NOT ENTAILED!" ); + return; + } + writer.println("Explanation(s): "); + } + + String header = index++ + ")"; + writer.print(header); + renderSingleExplanation(explanations.iterator().next()); + writer.println(); + } + + protected void renderSingleExplanation(Set<OWLAxiom> explanation) throws OWLException, + IOException { + writer.printSpace(); + writer.printSpace(); + writer.printSpace(); + + writer.startBlock(); + + for( OWLAxiom a : explanation ) { + a.accept( renderer ); + if(reasoner.isEntailed(a)){ + writer.append("(ENTAILED)"); + } + writer.println(); + } + + writer.endBlock(); + writer.println(); + } + + protected void setCurrentAxiom(OWLAxiom currentAxiom) { + this.currentAxiom = currentAxiom; + } + + /** + * Sets the smart indent option which will align the elements of + * intersections and unions in columns when line wrapping is turned on. + * + * @param smartIndent + * the smart indent value + * @see #setWrapLines(boolean) + */ + public void setSmartIndent(boolean smartIndent) { + this.smartIndent = smartIndent; + } + + /** + * Sets the line wrapping option which will print the elements of + * intersections and unions into multiple lines. + * + * @param wrapLines + * the line wrapping value + */ + public void setWrapLines(boolean wrapLines) { + this.wrapLines = wrapLines; + } + + /** + * {@inheritDoc} + */ + public void startRendering(Writer w) { + writer = new TextBlockWriter( w ); + renderer = new ManchesterSyntaxObjectRenderer( this.writer ); + renderer.setWrapLines( isWrapLines() ); + renderer.setSmartIndent( isSmartIndent() ); + index = 1; + } +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/ManchesterSyntaxObjectRenderer.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,867 @@ +// Copyright (c) 2006 - 2008, Clark & Parsia, LLC. <http://www.clarkparsia.com> +// This source code is available under the terms of the Affero General Public License v3. +// +// Please see LICENSE.txt for full license terms, including the availability of proprietary exceptions. +// Questions, comments, or requests for clarification: lic...@cl... + +package org.dllearner.scripts; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; +import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationProperty; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLAnonymousIndividual; +import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLCardinalityRestriction; +import org.semanticweb.owlapi.model.OWLClass; +import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataAllValuesFrom; +import org.semanticweb.owlapi.model.OWLDataComplementOf; +import org.semanticweb.owlapi.model.OWLDataExactCardinality; +import org.semanticweb.owlapi.model.OWLDataHasValue; +import org.semanticweb.owlapi.model.OWLDataIntersectionOf; +import org.semanticweb.owlapi.model.OWLDataMaxCardinality; +import org.semanticweb.owlapi.model.OWLDataMinCardinality; +import org.semanticweb.owlapi.model.OWLDataOneOf; +import org.semanticweb.owlapi.model.OWLDataProperty; +import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLDataUnionOf; +import org.semanticweb.owlapi.model.OWLDatatype; +import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom; +import org.semanticweb.owlapi.model.OWLDatatypeRestriction; +import org.semanticweb.owlapi.model.OWLDeclarationAxiom; +import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom; +import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLFacetRestriction; +import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; +import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLHasKeyAxiom; +import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom; +import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLLiteral; +import org.semanticweb.owlapi.model.OWLNamedIndividual; +import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObject; +import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectComplementOf; +import org.semanticweb.owlapi.model.OWLObjectExactCardinality; +import org.semanticweb.owlapi.model.OWLObjectHasSelf; +import org.semanticweb.owlapi.model.OWLObjectHasValue; +import org.semanticweb.owlapi.model.OWLObjectIntersectionOf; +import org.semanticweb.owlapi.model.OWLObjectInverseOf; +import org.semanticweb.owlapi.model.OWLObjectMaxCardinality; +import org.semanticweb.owlapi.model.OWLObjectMinCardinality; +import org.semanticweb.owlapi.model.OWLObjectOneOf; +import org.semanticweb.owlapi.model.OWLObjectProperty; +import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; +import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; +import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom; +import org.semanticweb.owlapi.model.OWLObjectUnionOf; +import org.semanticweb.owlapi.model.OWLObjectVisitor; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLPropertyExpression; +import org.semanticweb.owlapi.model.OWLQuantifiedRestriction; +import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLSameIndividualAxiom; +import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; +import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom; +import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; +import org.semanticweb.owlapi.model.OWLUnaryPropertyAxiom; +import org.semanticweb.owlapi.model.SWRLArgument; +import org.semanticweb.owlapi.model.SWRLAtom; +import org.semanticweb.owlapi.model.SWRLBuiltInAtom; +import org.semanticweb.owlapi.model.SWRLClassAtom; +import org.semanticweb.owlapi.model.SWRLDataPropertyAtom; +import org.semanticweb.owlapi.model.SWRLDataRangeAtom; +import org.semanticweb.owlapi.model.SWRLDifferentIndividualsAtom; +import org.semanticweb.owlapi.model.SWRLIndividualArgument; +import org.semanticweb.owlapi.model.SWRLLiteralArgument; +import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom; +import org.semanticweb.owlapi.model.SWRLRule; +import org.semanticweb.owlapi.model.SWRLSameIndividualAtom; +import org.semanticweb.owlapi.model.SWRLVariable; +import org.semanticweb.owlapi.vocab.XSDVocabulary; + +import com.clarkparsia.owlapi.explanation.io.manchester.BlockWriter; +import com.clarkparsia.owlapi.explanation.io.manchester.Keyword; + +public class ManchesterSyntaxObjectRenderer implements OWLObjectVisitor { + private boolean wrapLines = true; + private boolean smartIndent = true; + + protected BlockWriter writer; + + /** + * @param writer + */ + public ManchesterSyntaxObjectRenderer(BlockWriter writer) { + this.writer = writer; + } + + public boolean isSmartIndent() { + return smartIndent; + } + + public boolean isWrapLines() { + return wrapLines; + } + + public void setSmartIndent(boolean smartIndent) { + this.smartIndent = smartIndent; + } + + public void setWrapLines(boolean wrapLines) { + this.wrapLines = wrapLines; + } + + /** + * Return the short form (local name) for a URI identifier + * + * @param theIRI + * the URI + * @return the local name part of the URI identifier + */ + protected String shortForm(IRI theIRI) { + String fragment = theIRI.getFragment(); + if( fragment != null ) { + return fragment; + } + String str = theIRI.toString(); + int lastSlashIndex = str.lastIndexOf( '/' ); + if( lastSlashIndex != -1 ) { + return str.substring( lastSlashIndex + 1, str.length() ); + } + return str; + } + + public void visit(OWLAsymmetricObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.ASYMMETRIC_PROPERTY ); + } + + public void visit(OWLClass theOWLClass) { + write( theOWLClass.getIRI() ); + } + + public void visit(OWLClassAssertionAxiom theAxiom) { + writeKeywordInfix( Keyword.TYPE, theAxiom.getIndividual(), theAxiom.getClassExpression() ); + } + + public void visit(OWLAnnotation theAnnotation) { + write( Keyword.ANNOTATION ); + writeSpace(); + write( "(" ); + write( theAnnotation.getProperty() ); + write( " " ); + write( theAnnotation.getValue() ); + write( ")" ); + } + + public void visit(OWLDataAllValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.ONLY ); + } + + public void visit(OWLDataComplementOf theDescription) { + writeKeywordPrefix( Keyword.NOT, theDescription.getDataRange() ); + } + + public void visit(OWLDataExactCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.EXACTLY ); + } + + public void visit(OWLDataMaxCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MAX ); + } + + public void visit(OWLDataMinCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MIN ); + } + + public void visit(OWLDataOneOf theDescription) { + writeEnumeration( theDescription.getValues() ); + } + + public void visit(OWLDataProperty theProperty) { + write( theProperty.getIRI() ); + } + + public void visit(OWLDataPropertyAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + } + + public void visit(OWLDataPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + public void visit(OWLDataPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + public void visit(OWLFacetRestriction theRestriction) { + write( theRestriction.getFacet().getSymbolicForm() ); + writeSpace(); + write( theRestriction.getFacetValue() ); + } + + public void visit(OWLDatatypeRestriction theRestriction) { + + write( theRestriction.getDatatype() ); + write( "[" ); + boolean first = true; + for( OWLFacetRestriction restriction : theRestriction.getFacetRestrictions() ) { + if( first ) { + first = false; + } + else { + write( "," ); + writeSpace(); + } + write( restriction ); + } + write( "]" ); + + } + + public void visit(OWLDataSomeValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.SOME ); + } + + public void visit(OWLSubDataPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom + .getSuperProperty() ); + } + + public void visit(OWLDatatype node) { + write( node.getIRI() ); + } + + public void visit(OWLDataHasValue theDescription) { + writeRestriction( theDescription.getProperty(), Keyword.VALUE, theDescription.getValue() ); + } + + public void visit(OWLDeclarationAxiom theAxiom) { + writeKeywordPrefix( Keyword.DECLARATION, theAxiom.getEntity() ); + } + + public void visit(OWLDifferentIndividualsAxiom theAxiom) { + writeNaryAxiom( theAxiom.getIndividuals(), Keyword.DIFFERENT_INDIVIDUAL, + Keyword.DIFFERENT_INDIVIDUALS ); + } + + public void visit(OWLDisjointClassesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getClassExpressions(), Keyword.DISJOINT_CLASS, + Keyword.DISJOINT_CLASSES ); + } + + public void visit(OWLDisjointDataPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.DISJOINT_PROPERTY, + Keyword.DISJOINT_PROPERTIES ); + } + + public void visit(OWLDisjointObjectPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.DISJOINT_PROPERTY, + Keyword.DISJOINT_PROPERTIES ); + } + + public void visit(OWLDisjointUnionAxiom theAxiom) { + write( theAxiom.getOWLClass() ); + writeSpace(); + write( Keyword.DISJOINT_UNION ); + writeSpace(); + writeNaryKeyword( Keyword.OR, theAxiom.getClassExpressions() ); + } + + public void visit(OWLEquivalentClassesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getClassExpressions(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_CLASSES ); + } + + public void visit(OWLEquivalentDataPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_PROPERTIES ); + } + + public void visit(OWLEquivalentObjectPropertiesAxiom theAxiom) { + writeNaryAxiom( theAxiom.getProperties(), Keyword.EQUIVALENT_TO, + Keyword.EQUIVALENT_PROPERTIES ); + } + + public void visit(OWLFunctionalDataPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.FUNCTIONAL ); + } + + public void visit(OWLFunctionalObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.FUNCTIONAL ); + } + + public void visit(OWLAnonymousIndividual theIndividual) { + write( theIndividual.getID().getID() ); + } + + public void visit(OWLNamedIndividual theIndividual) { +// write( shortForm(theIndividual.getIRI()).toUpperCase() ); + write(theIndividual.getIRI()); + } + + public void visit(OWLInverseFunctionalObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.INVERSE_FUNCTIONAL ); + } + + public void visit(OWLInverseObjectPropertiesAxiom theAxiom) { + writeKeywordInfix( Keyword.INVERSE_OF, theAxiom.getFirstProperty(), theAxiom + .getSecondProperty() ); + } + + public void visit(OWLIrreflexiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.IRREFLEXIVE ); + } + + public void visit(OWLNegativeDataPropertyAssertionAxiom theAxiom) { + write( Keyword.NOT_RELATIONSHIP ); + writeSpace(); + write( "(" ); + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + write( ")" ); + } + + public void visit(OWLNegativeObjectPropertyAssertionAxiom theAxiom) { + write( Keyword.NOT_RELATIONSHIP ); + writeSpace(); + write( "(" ); + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + write( ")" ); + } + + public void visit(OWLObjectAllValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.ONLY ); + } + + public void visit(OWLObjectComplementOf theDescription) { + writeKeywordPrefix( Keyword.NOT, theDescription.getOperand() ); + } + + public void visit(OWLObjectExactCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.EXACTLY ); + } + + public void visit(OWLObjectIntersectionOf theDescription) { + writeNaryKeyword( Keyword.AND, theDescription.getOperands() ); + } + + public void visit(OWLObjectMaxCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MAX ); + } + + public void visit(OWLObjectMinCardinality theDescription) { + writeCardinalityRestriction( theDescription, Keyword.MIN ); + } + + public void visit(OWLObjectOneOf theDescription) { + writeEnumeration( theDescription.getIndividuals() ); + } + + public void visit(OWLObjectProperty theProperty) { + write( theProperty.getIRI() ); + } + + public void visit(OWLObjectPropertyAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getObject() ); + } + + public void visit(OWLSubPropertyChainOfAxiom theAxiom) { + writeCollection( theAxiom.getPropertyChain(), " o", false ); + writeSpace(); + write( Keyword.SUB_PROPERTY_OF ); + writeSpace(); + write( theAxiom.getSuperProperty() ); + } + + public void visit(OWLObjectPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + public void visit(OWLObjectInverseOf theInverse) { + writeKeywordPrefix( Keyword.INVERSE, theInverse.getInverse() ); + } + + public void visit(OWLObjectPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + public void visit(OWLObjectHasSelf theRestriction) { + writeRestriction( theRestriction.getProperty(), Keyword.SELF ); + } + + public void visit(OWLObjectSomeValuesFrom theDescription) { + writeQuantifiedRestriction( theDescription, Keyword.SOME ); + } + + public void visit(OWLSubObjectPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom + .getSuperProperty() ); + } + + public void visit(OWLObjectUnionOf theDescription) { + writeNaryKeyword( Keyword.OR, theDescription.getOperands() ); + } + + public void visit(OWLObjectHasValue theDescription) { + writeRestriction( theDescription.getProperty(), Keyword.VALUE, theDescription.getValue() ); + } + + public void visit(OWLOntology ontology) { + write( ontology.getOntologyID().getOntologyIRI() ); + } + + public void visit(OWLReflexiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.REFLEXIVE_PROPERTY ); + } + + public void visit(OWLSameIndividualAxiom theAxiom) { + writeNaryAxiom( theAxiom.getIndividuals(), Keyword.SAME_INDIVIDUAL, + Keyword.SAME_INDIVIDUALS ); + } + + public void visit(OWLSubClassOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_CLASS_OF, theAxiom.getSubClass(), theAxiom.getSuperClass() ); + } + + public void visit(OWLSymmetricObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.SYMMETRIC ); + } + + public void visit(OWLTransitiveObjectPropertyAxiom theAxiom) { + writeUnaryPropertyAxiom( theAxiom, Keyword.TRANSITIVE ); + } + + public void visit(OWLLiteral node) { + if( node.isRDFPlainLiteral() ) { + write( "\"" ); + write( node.getLiteral() ); + write( "\"" ); + if( node.getLang() != null && !node.getLang().equals("")) { + write( "@" ); + write( node.getLang() ); + } + } + else if( node.getDatatype().getIRI().equals( XSDVocabulary.INTEGER.getIRI() ) + || node.getDatatype().getIRI().equals( XSDVocabulary.DECIMAL.getIRI() ) ) { + write( node.getLiteral() ); + } + else if( node.getDatatype().getIRI().equals( XSDVocabulary.FLOAT.getIRI() ) ) { + write( node.getLiteral() ); + write( "f" ); + } + else { + write( "\"" ); + write( node.getLiteral() ); + write( "\"" ); + write( "^^" ); + write( node.getDatatype() ); + } + } + + public void visit(SWRLLiteralArgument node) { + write( node.getLiteral() ); + } + + public void visit(SWRLIndividualArgument node) { + write( node.getIndividual() ); + } + + public void visit(SWRLVariable node) { + write( "?" ); + write( node.getIRI() ); + } + + public void visit(SWRLBuiltInAtom node) { + write( node.getPredicate() ); + write( "(" ); + for( SWRLArgument arg : node.getArguments() ) { + write( arg ); + write( " " ); + } + write( ")" ); + } + + public void visit(SWRLClassAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getArgument() ); + write( ")" ); + } + + /* + * this is all the SWRL rendering stuff that we'll provide some defaults for + * using evren's concise format stuff + */ + + public void visit(SWRLDataRangeAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getArgument() ); + write( ")" ); + } + + public void visit(SWRLDataPropertyAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + public void visit(SWRLDifferentIndividualsAtom node) { + write( "differentFrom" ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + public void visit(SWRLObjectPropertyAtom node) { + write( node.getPredicate() ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + /** + * @inheritDoc + */ + public void visit(SWRLRule rule) { + write( "Rule" ); + write( "(" ); + +// if( !rule.isAnonymous() ) { +// write( rule.getIRI() ); +// writeSpace(); +// } + + boolean first = true; + for( SWRLAtom at : rule.getBody() ) { + if( first ) + first = false; + else + write( ", " ); + write( at ); + + } + write( " -> " ); + + first = true; + for( SWRLAtom at : rule.getHead() ) { + if( first ) + first = false; + else + write( ", " ); + write( at ); + } + + write( ")" ); + } + + public void visit(SWRLSameIndividualAtom node) { + write( "sameAs" ); + write( "(" ); + write( node.getFirstArgument() ); + write( ", " ); + write( node.getSecondArgument() ); + write( ")" ); + } + + protected void writeNaryKeyword(Keyword theKeyword, Set<? extends OWLObject> theObjects) { + + theObjects = DescriptionSorter.toSortedSet( theObjects ); + + Iterator<? extends OWLObject> aIter = theObjects.iterator(); + + // write( "(" ); + + if( smartIndent ) + writer.startBlock(); + + write( aIter.next() ); + while( aIter.hasNext() ) { + if( wrapLines ) { + writeNewLine(); + } + else { + writeSpace(); + } + + if( theKeyword != null ) { + write( theKeyword ); + writeSpace(); + } + + write( aIter.next() ); + } + + if( smartIndent ) + writer.endBlock(); + + // write( ")" ); + } + + protected void writeCardinalityRestriction(OWLCardinalityRestriction<?, ?, ?> theRestriction, + Keyword theKeyword) { + if( theRestriction.isQualified() ) + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction + .getCardinality(), theRestriction.getFiller() ); + else + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction + .getCardinality() ); + } + + /** + * Render an n-ary axiom with special handling for the binary case. + * + * @param set + * objects to be rendered + * @param binary + * keyword used for binary case + * @param nary + * keyword used for n-ary case + */ + protected void writeNaryAxiom(Set<? extends OWLObject> set, Keyword binary, Keyword nary) { + Set<? extends OWLObject> sortedSet = DescriptionSorter.toSortedSet( set ); + Iterator<? extends OWLObject> aIter = sortedSet.iterator(); + + if( set.size() == 2 ) { + writeKeywordInfix( binary, aIter.next(), aIter.next() ); + } + else { + write( nary ); + write( "(" ); + + writeNaryKeyword( null, set ); + + write( ")" ); + } + } + + protected void writeQuantifiedRestriction(OWLQuantifiedRestriction<?, ?, ?> theRestriction, + Keyword theKeyword) { + writeRestriction( theRestriction.getProperty(), theKeyword, theRestriction.getFiller() ); + } + + protected void writeRestriction(OWLPropertyExpression<?, ?> theProperty, Keyword theKeyword, + Object... theArgs) { + write( "(" ); + + write( theProperty ); + writeSpace(); + write( theKeyword ); + for( Object aObject : theArgs ) { + writeSpace(); + if( aObject instanceof OWLObject ) { + write( (OWLObject) aObject ); + } + else { + write( aObject.toString() ); + } + } + + write( ")" ); + + } + + protected void writeUnaryPropertyAxiom(OWLUnaryPropertyAxiom<?> theAxiom, Keyword keyword) { + writeKeywordPrefix( keyword, theAxiom.getProperty() ); + } + + protected void writeKeywordPrefix(Keyword keyword, OWLObject arg) { + write( keyword ); + writeSpace(); +// write( "(" ); + write( arg ); +// write( ")" ); + } + + protected void writeKeywordPrefix(Keyword keyword, OWLObject arg1, OWLObject arg2) { + write( keyword ); + writeSpace(); + write( "(" ); + write( arg1 ); + writeSpace(); + write( arg2 ); + write( ")" ); + } + + protected void writeKeywordInfix(Keyword keyword, OWLObject arg1, OWLObject arg2) { + write( arg1 ); + writeSpace(); + write( keyword ); + writeSpace(); + write( arg2 ); + } + + protected void writeEnumeration(Set<? extends OWLObject> objects) { + write( Keyword.OPEN_BRACE ); + writeCollection( objects, ",", true ); + write( Keyword.CLOSE_BRACE ); + } + + protected void writeCollection(Collection<? extends OWLObject> objects, String separator, boolean sort) { + if( sort ) + objects = DescriptionSorter.toSortedSet( objects ); + boolean first = true; + for( OWLObject ind : objects ) { + if( first ) { + first = false; + } + else { + write( separator ); + writeSpace(); + } + write( ind ); + } + } + + protected void write(OWLObject object) { + object.accept( this ); + } + + protected void write(Keyword keyword) { + write( keyword.getLabel().toUpperCase() ); + } + + protected void write(String s) { + writer.print( s ); + } + + protected void write(IRI iri) { + write( shortForm( iri ) ); + } + + protected void writeNewLine() { + writer.println(); + } + + protected void writeSpace() { + write( " " ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLHasKeyAxiom theAxiom) { + write( theAxiom.getClassExpression() ); + writeSpace(); + write( Keyword.HAS_KEY ); + if( !theAxiom.getObjectPropertyExpressions().isEmpty() ) { + writeCollection( theAxiom.getObjectPropertyExpressions(), "", true ); + writeSpace(); + } + writeCollection( theAxiom.getDataPropertyExpressions(), "", true ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDatatypeDefinitionAxiom theAxiom) { + writeKeywordInfix( Keyword.EQUIVALENT_TO, theAxiom.getDatatype(), theAxiom.getDataRange() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationAssertionAxiom theAxiom) { + write( theAxiom.getSubject() ); + writeSpace(); + write( theAxiom.getProperty() ); + writeSpace(); + write( theAxiom.getValue() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLSubAnnotationPropertyOfAxiom theAxiom) { + writeKeywordInfix( Keyword.SUB_PROPERTY_OF, theAxiom.getSubProperty(), theAxiom.getSuperProperty() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationPropertyDomainAxiom theAxiom) { + writeKeywordInfix( Keyword.DOMAIN, theAxiom.getProperty(), theAxiom.getDomain() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationPropertyRangeAxiom theAxiom) { + writeKeywordInfix( Keyword.RANGE, theAxiom.getProperty(), theAxiom.getRange() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDataIntersectionOf node) { + writeNaryKeyword( Keyword.AND, node.getOperands() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLDataUnionOf node) { + writeNaryKeyword( Keyword.OR, node.getOperands() ); + } + + /** + * {@inheritDoc} + */ + public void visit(OWLAnnotationProperty property) { + write( property.getIRI() ); + } + + /** + * {@inheritDoc} + */ + public void visit(IRI iri) { + write( iri ); + } +} Added: trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java (rev 0) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OntologyCleaner.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -0,0 +1,43 @@ +package org.dllearner.scripts; + +import java.io.File; +import java.io.FileOutputStream; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLOntology; + +public class OntologyCleaner { + + /** + * @param args + */ + public static void main(String[] args) throws Exception{ + List<String> namespaces = Arrays.asList(new String[]{"http://schema.org/"}); + OWLOntology ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument( + OntologyCleaner.class.getClassLoader().getResourceAsStream("dbpedia_0.75.owl")); + + //get all entities starting with one of the declared namespaces + Set<OWLAxiom> axioms2Remove = new HashSet<OWLAxiom>(); + for(OWLAxiom axiom : ontology.getLogicalAxioms()){ + for(OWLEntity entity : axiom.getSignature()){ + for(String namespace : namespaces){ + if(entity.toStringID().startsWith(namespace)){ + axioms2Remove.add(axiom); + } + } + + } + } + OWLManager.createOWLOntologyManager().removeAxioms(ontology, axioms2Remove); + OWLManager.createOWLOntologyManager().saveOntology(ontology, new RDFXMLOntologyFormat(), new FileOutputStream(new File("src/main/resources/dbpedia_0.75_cleaned.owl"))); + + } + +} Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLEndpointMetrics.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -1,9 +1,12 @@ package org.dllearner.scripts; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; import java.net.URL; import java.util.Map; +import java.util.Map.Entry; import java.util.TreeMap; -import java.util.Map.Entry; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -18,16 +21,19 @@ import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; public class SPARQLEndpointMetrics { //parameters for thread pool //Parallel running Threads(Executor) on System - private static int corePoolSize = 1; + private static int corePoolSize = 5; //Maximum Threads allowed in Pool private static int maximumPoolSize = 20; //Keep alive time for waiting threads for jobs(Runnable) private static long keepAliveTime = 10; + + private static int queryTimeout = 30; /** * @param args @@ -84,9 +90,13 @@ ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(endpoints.size()); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue); + final BufferedWriter output = new BufferedWriter(new FileWriter("log/endpointMetrics.html", true)); + final StringBuffer sb = new StringBuffer(); - sb.append("<table border=\"1\">"); - sb.append("<tr><th>#classes</th><th>#op</th><th>#dp</th><th>#individuals</th></tr>"); + sb.append("<table border=\"1\">\n"); + sb.append("<tr><th>endpoint</th><th>#classes</th><th>#op</th><th>#dp</th><th>URL</th><th>ERROR</th></tr>\n"); + output.append(sb.toString()); + output.flush(); // perform enrichment on endpoints for(final Entry<String,SparqlEndpoint> endpoint : endpoints.entrySet()) { @@ -96,30 +106,70 @@ @Override public void run() { SparqlEndpoint se = endpoint.getValue(); + String name = endpoint.getKey(); // System.out.println(se); String filter = "FILTER()"; try { //count classes - String query = "SELECT (COUNT(DISTINCT ?type) AS ?cnt) WHERE {?s a ?type.}"; - int classCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); +// String query = "SELECT (COUNT(DISTINCT ?type) AS ?cnt) WHERE {?s a ?type.}"; +// int classCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count object properties +// query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; +// int opCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count data properties +// query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; +// int dpCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); +// +// //count individuals +// query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; +// int indCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); + String query = "SELECT DISTINCT ?type WHERE {?s a ?type. ?type a <http://www.w3.org/2002/07/owl#Class>}"; + int classCnt = countEntities(query, se); + //count object properties - query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; - int opCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); + query = "SELECT DISTINCT ?p WHERE {?s ?p ?o. ?p a <http://www.w3.org/2002/07/owl#ObjectProperty>}"; + int opCnt = countEntities(query, se); //count data properties - query = "SELECT (COUNT(DISTINCT ?p) AS ?cnt) WHERE {?s ?p ?o.}"; - int dpCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); + query = "SELECT DISTINCT ?p WHERE {?s ?p ?o. ?p a <http://www.w3.org/2002/07/owl#DatatypeProperty>}"; + int dpCnt = countEntities(query, se); //count individuals - query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; - int indCnt = new SparqlQuery(query, se).send().next().getLiteral("cnt").getInt(); +// query = "SELECT (COUNT(DISTINCT ?s) AS ?cnt) WHERE {?s a ?type.}"; +// int indCnt = executeQuery(query, se, 20).next().getLiteral("cnt").getInt(); - sb.append("<tr><td>" + classCnt + "</td><td>" + opCnt + "</td>" + "</td><td>" + dpCnt + "</td><td>" + indCnt + "</td></tr>\n"); + String line = "<tr><td>" + name + "</td><td>" + + classCnt + "</td><td>" + + opCnt + "</td><td>" + + dpCnt + "</td><td>" + + se.getURL() + "</td><td>" + + "" + "</td></tr>\n"; + + sb.append(line); + output.append(line); + output.flush(); + System.out.println(sb); } catch (Exception e) { - sb.append(""); + Throwable t = e.getCause(); + String errorCode; + if(t == null){ + errorCode = e.getClass().getSimpleName(); + } else { + errorCode = t.getMessage(); + } + String line = "<tr><td>" + name + "</td><td>-1</td><td>-1</td><td>-1</td><td>" + se.getURL() + "</td><td>" + errorCode + "</tr>\n"; + sb.append(line); + try { + output.append(line); + output.flush(); + } catch (IOException e1) { + e1.printStackTrace(); + } } } @@ -127,7 +177,39 @@ } threadPool.shutdown(); System.out.println(sb); - + } + + private static int countEntities(String baseQuery, SparqlEndpoint endpoint) throws Exception{ + int cnt = 0; + int limit = 1000; + int offset = 0; + ResultSet rs; + int tmp = 0; + do{ + String query = baseQuery + " LIMIT " + limit + " OFFSET " + offset;System.out.println(endpoint.getURL() + ": " + query); + rs = executeQuery(query, endpoint); + tmp = 0; + while(rs.hasNext()){ + rs.next(); + tmp++; + } + cnt += tmp; + offset += limit; + } while (tmp >= limit); + + return cnt; + } + + private static ResultSet executeQuery(String queryString, SparqlEndpoint endpoint) throws Exception{ + try { + QueryEngineHTTP qe = new QueryEngineHTTP(endpoint.getURL().toString(), queryString); + qe.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); + qe.setTimeout(queryTimeout * 1000); + return qe.execSelect(); + } catch (Exception e) { + throw e; + } + } } Modified: trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-03-26 12:10:46 UTC (rev 3618) +++ trunk/scripts/src/main/java/org/dllearner/scripts/SPARQLSampleDebugging.java 2012-03-26 12:19:20 UTC (rev 3619) @@ -19,6 +19,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -26,6 +27,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; +import java.util.Random; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -78,7 +80,6 @@ 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; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; import com.hp.hpl.jena.query.Query; @@ -121,6 +122,8 @@ private OWLReasoner dbpediaReasoner; private OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + private Random randomGen = new Random(2222343); + static {PelletExplanation.setup();} public SPARQLSampleDebugging(SparqlEndpoint endpoint) { @@ -160,6 +163,23 @@ } } + private Set<OWLAxiom> getBlackList(){ + Set<OWLAxiom> blacklist = new HashSet<OWLAxiom>(); + OWLAxiom ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/leaderName")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Person"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Settlement"))); + blacklist.add(ax); + ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/language")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Language"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Work"))); + blacklist.add(ax); + ax = factory.getOWLSubClassOfAxiom( + factory.getOWLObjectSomeValuesFrom(factory.getOWLObjectProperty(IRI.create("http://dbpedia.org/ontology/officialLanguage")), factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Language"))), + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Country"))); + blacklist.add(ax); + return blacklist; + } + private void writeToDB(String resource, int fragementSize, boolean consistent, Set<Set<OWLAxiom>> explanations) { try { ps.setString(1, resource); @@ -225,25 +245,19 @@ return resources; } - private Set<String> extractSampleResourcesSingle(int size){ - logger.info("Extracting " + sampleSize + " sample resources..."); + private String extractSampleResource(int maxOffset){ long startTime = System.currentTimeMillis(); - Set<String> resources = new HashSet<String>(); - String query = "SELECT COUNT(DISTINCT ?s) WHERE {?s a ?type}"; + int random = randomGen.nextInt(maxOffset); + logger.info("Extracting sample resource (" + random + ")..."); + + String query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT 1 OFFSET %d", random); ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - int max = rs.next().getLiteral(rs.getResultVars().get(0)).getInt(); + String resource = rs.next().getResource("s").getURI(); - for(int i = 0; i < size; i++){ - int random = (int)(Math.random() * max); - query = String.format("SELECT DISTINCT ?s WHERE {?s a ?type} LIMIT 1 OFFSET %d", random); - rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); - resources.add(rs.next().getResource("s").getURI()); - } - logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); - return resources; + return resource; } private OWLOntology extractSampleModule(Set<String> resources){ @@ -280,17 +294,12 @@ return explanations; } - private Set<Set<OWLAxiom>> computeExplanations(PelletReasoner reasoner){ + private Set<Set<OWLAxiom>> computeExplanations(PelletReasoner reasoner) throws Exception{ logger.info("Computing explanations..."); long startTime = System.currentTimeMillis(); PelletExplanation expGen = new PelletExplanation(reasoner); Set<Set<OWLAxiom>> explanations = new HashSet<Set<OWLAxiom>>(maxNrOfExplanations); - try { - explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); - } catch (Exception e) { - e.printStackTrace(); - logger.error(e); - } + explanations = expGen.getInconsistencyExplanations(maxNrOfExplanations); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return explanations; } @@ -387,7 +396,7 @@ } }); OWLDataFactory f = OWLManager.createOWLOntologyManager().getOWLDataFactory(); - ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(dbpediaReasoner); PrintWriter out = new PrintWriter( System.out ); for(OWLObjectProperty p : reasoner.getRootOntology().getObjectPropertiesInSignature()){ boolean satisfiable = reasoner.isSatisfiable(f.getOWLObjectExactCardinality(1, p)); @@ -427,9 +436,12 @@ } - public void run(OWLOntology reference) throws OWLOntologyCreationException{ - Set<OWLOntology> ontologies = new HashSet<OWLOntology>(); - ontologies.add(reference); + + public void computeSampleExplanations(OWLOntology reference, int nrOfExplanations) throws OWLOntologyCreationException, IOException{ + Set<Set<OWLAxiom>> sampleExplanations = new HashSet<Set<OWLAxiom>>(); + manager = reference.getOWLOntologyManager(); + manager.removeAxioms(reference, getBlackList()); + PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(reference); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); Set<OWLClass> unsatisfiableClasses = reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); @@ -438,25 +450,70 @@ logger.info("Unsatisfiable object properties(" + unsatisfiableObjectProperties.size() + "): " + unsatisfiableObjectProperties); Set<OWLDataProperty> unsatisfiableDataProperties = getUnsatisfiableDataProperties(reasoner); logger.info("Unsatisfiable data properties(" + unsatisfiableDataProperties.size() + "): " + unsatisfiableDataProperties); - OWLOntology merged; OWLOntology module; + reasoner.isConsistent(); + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + man.addOntologyChangeListener( reasoner ); + Model model; - Set<String> resources = extractSampleResourcesChunked(sampleSize); - for(String resource : resources){resource = "http://dbpedia.org/resource/Leipzig"; - logger.info("Resource " + resource); - module = extractSampleModule(Collections.singleton(resource)); - ontologies.add(module); - merged = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://merged.en"), ontologies); - reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(merged); + FileWriter out = new FileWriter( "log/alljustifications" + System.currentTimeMillis() + ".txt" ); + ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer(dbpediaReasoner); + renderer.startRendering(out ); + + String query = "SELECT COUNT(DISTINCT ?s) WHERE {?s a ?type}"; + ResultSet rs = SparqlQuery.convertJSONtoResultSet(cache.executeSelectQuery(endpoint, query)); + int maxOffset = rs.next().getLiteral(rs.getResultVars().get(0)).getInt(); + + while(sampleExplanations.size() < nrOfExplanations){ + String resource = extractSampleResource(maxOffset);//resource = "http://dbpedia.org/resource/Pigeon_%28company%29"; + logger.info("###################################################################"); + logger.info("Resource " + resource);//resource = "http://dbpedia.org/resource/The_Man_Who_Wouldn%27t_Die"; + module = extractSampleModule(resource);module.getOWLOntologyManager().removeAxioms(module, module.getAxioms(AxiomType.DATA_PROPERTY_ASSERTION)); + manager.addAxioms(reference, module.getABoxAxioms(true)); + manager.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); + explanations = new HashSet<Set<OWLAxiom>>(); + try { + explanations.addAll(computeExplanations(reasoner)); + } catch (Exception e1) { + continue; + } + model = convert(reference); + explanations.addAll(computeInconsistencyExplanationsByAsymmetryPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByIrreflexivityPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByFunctionalityPattern(reference, model)); + explanations.addAll(computeInconsistencyExplanationsByInverseFunctionalityPattern(reference, model)); logger.info("Found " + explanations.size() + " explanations."); + for(Set<OWLAxiom> exp : explanations){ + logger.info(exp + "\n"); + out.flush(); + try { + renderer.render( Collections.singleton(exp) ); + } catch (UnsupportedOperationException e) { + e.printStackTrace(); + } catch (OWLException e) { + e.printStackTrace(); + } + } + boolean addSample = true; + while(addSample){ + int rnd = 0; + if(explanations.size() > 1){ + rnd = new Random().nextInt(explanations.size()-1); + } + Set<OWLAxiom> sampleExplanation = new ArrayList<Set<OWLAxiom>>(explanations).get(rnd); + if(!containsUnsatisfiableObjectProperty(sampleExplanation)){ + sampleExplanations.add(sampleExplanation); + addSample = false; + } + + } + 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){ @@ -466,19 +523,35 @@ axiomType2CountMap.put(axiom.getAxiomType(), cnt); } } + logger.info("Axiom type count:"); for(Entry<AxiomType, Integer> entry : axiomType2CountMap.entrySet()){ logger.info(entry.getKey() + "\t: " + entry.getValue()); } } - ontologies.remove(module); - reasoner.dispose(); + man.removeAxioms(reference, module.getABoxAxioms(true)); // writeToDB(resource, module.getLogicalAxiomCount(), isConsistent, explanations); - break; } + renderer.endRendering(); + FileWriter sampleOut = new FileWriter( "log/sample_justifications" + System.currentTimeMillis() + ".txt" ); + ManchesterSyntaxExplanationRenderer sampleRenderer = new ManchesterSynta... [truncated message content] |
From: <lor...@us...> - 2012-03-26 12:10:58
|
Revision: 3618 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3618&view=rev Author: lorenz_b Date: 2012-03-26 12:10:46 +0000 (Mon, 26 Mar 2012) Log Message: ----------- Updated pom. Removed QueryEngineHTTP classes as timeout is now implemented in official JENA jar. Modified Paths: -------------- trunk/components-core/pom.xml trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java Removed Paths: ------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java Modified: trunk/components-core/pom.xml =================================================================== --- trunk/components-core/pom.xml 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/pom.xml 2012-03-26 12:10:46 UTC (rev 3618) @@ -132,6 +132,7 @@ <artifactId>log4j</artifactId> </dependency> + <!-- Latest JENA ARQ - we have to exclude XercesImpl and use an older version here because use version bei JENA leads to some errors --> <dependency> <groupId>org.apache.jena</groupId> <artifactId>jena-arq</artifactId> @@ -142,6 +143,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.6.0</version> + </dependency> <!--JSON is in Central --> <dependency> @@ -185,16 +191,6 @@ </dependency> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>jena-core</artifactId> - <exclusions> - <exclusion> - <artifactId>xercesImpl</artifactId> - <groupId>xerces</groupId> - </exclusion> - </exclusions> - </dependency> <dependency> <groupId>junit</groupId> @@ -253,5 +249,7 @@ <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> </dependency> + + </dependencies> </project> Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/celoe/PCELOE.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -66,6 +66,7 @@ import org.dllearner.refinementoperators.OperatorInverter; import org.dllearner.refinementoperators.RefinementOperator; import org.dllearner.refinementoperators.RhoDRDown; +import org.dllearner.refinementoperators.SynchronizedRhoDRDown; import org.dllearner.utilities.Files; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; @@ -295,15 +296,15 @@ // variables to it if(operator == null) { // we use a default operator and inject the class hierarchy for now - operator = new RhoDRDown(); - ((RhoDRDown)operator).setStartClass(startClass); - ((RhoDRDown)operator).setReasoner(reasoner); - ((RhoDRDown)operator).init(); + operator = new SynchronizedRhoDRDown(); + ((SynchronizedRhoDRDown)operator).setStartClass(startClass); + ((SynchronizedRhoDRDown)operator).setReasoner(reasoner); + ((SynchronizedRhoDRDown)operator).init(); } // TODO: find a better solution as this is quite difficult to debug - ((RhoDRDown)operator).setSubHierarchy(classHierarchy); - ((RhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); - ((RhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); + ((SynchronizedRhoDRDown)operator).setSubHierarchy(classHierarchy); + ((SynchronizedRhoDRDown)operator).setObjectPropertyHierarchy(reasoner.getObjectPropertyHierarchy()); + ((SynchronizedRhoDRDown)operator).setDataPropertyHierarchy(reasoner.getDatatypePropertyHierarchy()); // operator = new RhoDRDown(reasoner, classHierarchy, startClass, configurator); @@ -996,6 +997,7 @@ return heuristic; } + @Autowired(required=false) public void setHeuristic(OEHeuristicRuntime heuristic) { this.heuristic = heuristic; } @@ -1052,12 +1054,18 @@ } // chose best node according to heuristics + if(logger.isDebugEnabled()){ + logger.debug("Get next node to expand..."); + } nextNode = getNextNodeToExpand(); if(nextNode != null){ int horizExp = nextNode.getHorizontalExpansion(); // apply operator Monitor mon = MonitorFactory.start("refineNode"); + if(logger.isDebugEnabled()){ + logger.debug("Refining node..."); + } TreeSet<Description> refinements = refineNode(nextNode); mon.stop(); @@ -1081,6 +1089,9 @@ // System.out.println("potentially adding " + refinement + " to search tree as child of " + nextNode + " " + new Date()); Monitor mon2 = MonitorFactory.start("addNode"); + if(logger.isDebugEnabled()){ + logger.debug("Add node..."); + } addNode(refinement, nextNode); mon2.stop(); // adding nodes is potentially computationally expensive, so we have 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-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointObjectPropertyAxiomLearner.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -215,10 +215,12 @@ public static void main(String[] args) throws Exception{ DisjointObjectPropertyAxiomLearner l = new DisjointObjectPropertyAxiomLearner(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/stateOfOrigin")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); - System.out.println(l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE)); + for(EvaluatedAxiom ax : l.getCurrentlyBestEvaluatedAxioms(Integer.MAX_VALUE)){ + System.out.println(ax); + } } } Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/InverseFunctionalObjectPropertyAxiomLearner.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -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; @@ -166,9 +168,10 @@ } public static void main(String[] args) throws Exception{ - SparqlEndpointKS ks = new SparqlEndpointKS(SparqlEndpoint.getEndpointDBpediaLiveAKSW()); + SparqlEndpointKS ks = new SparqlEndpointKS(new SparqlEndpoint( + new URL("http://dbpedia.aksw.org:8902/sparql"), Collections.singletonList("http://dbpedia.org"), Collections.<String>emptyList())); InverseFunctionalObjectPropertyAxiomLearner l = new InverseFunctionalObjectPropertyAxiomLearner(ks); - l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/starring")); + l.setPropertyToDescribe(new ObjectProperty("http://dbpedia.org/ontology/profession")); l.setMaxExecutionTimeInSeconds(10); l.init(); l.start(); Modified: trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/core/AbstractAxiomLearningAlgorithm.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -38,7 +38,6 @@ import org.dllearner.core.owl.NamedClass; import org.dllearner.kb.LocalModelBasedSparqlEndpointKS; import org.dllearner.kb.SparqlEndpointKS; -import org.dllearner.kb.sparql.ExtendedQueryEngineHTTP; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.learningproblems.AxiomScore; @@ -220,7 +219,7 @@ logger.info("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); @@ -236,7 +235,7 @@ logger.info("Sending query\n{} ...", query); if(ks.isRemote()){ SparqlEndpoint endpoint = ((SparqlEndpointKS) ks).getEndpoint(); - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); queryExecution.setDefaultGraphURIs(endpoint.getDefaultGraphURIs()); Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -50,7 +50,7 @@ // components must be listed here if they should be supported in interfaces // (CLI, GUI, Web Service) and scripts (HTML documentation generator) private static List<String> componentClassNames = new ArrayList<String> ( Arrays.asList(new String[]{ - "org.dllearner.algorithms.celoe.CELOE", + "org.dllearner.algorithms.celoe.CELOE", "org.dllearner.algorithms.celoe.PCELOE", "org.dllearner.algorithms.el.ELLearningAlgorithm", "org.dllearner.algorithms.el.ELLearningAlgorithmDisjunctive", @@ -91,6 +91,7 @@ "org.dllearner.algorithms.ocel.MultiHeuristic", "org.dllearner.algorithms.celoe.OEHeuristicRuntime", "org.dllearner.refinementoperators.RhoDRDown", + "org.dllearner.refinementoperators.SynchronizedRhoDRDown", } )); private static Collection<Class<? extends Component>> components; private static BidiMap<Class<? extends Component>, String> componentNames; Deleted: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtendedQueryEngineHTTP.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -1,408 +0,0 @@ -/** - * Copyright (C) 2007-2011, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.dllearner.kb.sparql; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.hp.hpl.jena.query.ARQ; -import com.hp.hpl.jena.query.Dataset; -import com.hp.hpl.jena.query.Query; -import com.hp.hpl.jena.query.QueryExecution; -import com.hp.hpl.jena.query.QueryFactory; -import com.hp.hpl.jena.query.QuerySolution; -import com.hp.hpl.jena.query.ResultSet; -import com.hp.hpl.jena.query.ResultSetFactory; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.sparql.engine.http.HttpParams; -import com.hp.hpl.jena.sparql.engine.http.Params; -import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; -import com.hp.hpl.jena.sparql.graph.GraphFactory; -import com.hp.hpl.jena.sparql.resultset.XMLInput; -import com.hp.hpl.jena.sparql.util.Context; -import com.hp.hpl.jena.util.FileManager; - -/** - * Created by Claus Stadler - * Date: Oct 25, 2010 - * Time: 10:15:31 PM - */ -class DisconnectorThread - extends Thread { - private static final Logger logger = LoggerFactory.getLogger(DisconnectorThread.class); - - private HttpQuery connection; - - private long timeOut; - - private boolean canceled = false; - - public DisconnectorThread(HttpQuery connection, long timeOut) { - this.connection = connection; - this.timeOut = timeOut; - } - - public void run() { - synchronized (this) { - - while(!canceled && connection.getConnection() == null) { - //logger.trace("Waiting for connection..."); - - try { - this.wait(500l); - } catch (InterruptedException e) { - } - } - - long startTime = System.currentTimeMillis(); - - long remaining; - while (!canceled && (remaining = (timeOut - (System.currentTimeMillis() - startTime))) > 0) { - logger.trace("Forced disconnect in " + remaining + "ms"); - try { - this.wait(remaining); - } catch (InterruptedException e) { - } - } - - if (!canceled && connection.getConnection() != null) { - logger.warn("Disconnecting Http connection since a sparql query is taking too long"); - connection.getConnection().disconnect(); - canceled = true; - } - } - } - - public void cancel() { - synchronized (this) { - if(!this.canceled) { - logger.trace("Disconnect cancelled"); - } - - this.canceled = true; - this.notify(); - } - } -} - -/** - * A QueryEngineHTTP that is capable of closing connections after a given timeout. - * - * Jena now provides one on its own - */ -public class ExtendedQueryEngineHTTP - implements QueryExecution { - private static Logger log = LoggerFactory.getLogger(QueryEngineHTTP.class); - - public static final String QUERY_MIME_TYPE = "application/sparql-query"; - String queryString; - String service; - Context context = null; - - - long timeOut = 0l; - - public void setTimeOut(long timeOut) { - this.timeOut = timeOut; - } - - public long getTimeOut() { - return timeOut; - } - - - //Params - Params params = null; - - // Protocol - List<String> defaultGraphURIs = new ArrayList<String>(); - List<String> namedGraphURIs = new ArrayList<String>(); - private String user = null; - private char[] password = null; - - // Releasing HTTP input streams is important. We remember this for SELECT, - // and will close when the engine is closed - private InputStream retainedConnection = null; - - public ExtendedQueryEngineHTTP(String serviceURI, Query query) { - this(serviceURI, query.toString()); - } - - public ExtendedQueryEngineHTTP(String serviceURI, String queryString) { - this.queryString = queryString; - service = serviceURI; - // Copy the global context to freeze it. - context = new Context(ARQ.getContext()); - } - -// public void setParams(Params params) -// { this.params = params ; } - - // Meaning-less - - public void setFileManager(FileManager fm) { - throw new UnsupportedOperationException("FileManagers do not apply to remote query execution"); - } - - public void setInitialBinding(QuerySolution binding) { - throw new UnsupportedOperationException("Initial bindings not supported for remote queries"); - } - - public void setInitialBindings(ResultSet table) { - throw new UnsupportedOperationException("Initial bindings not supported for remote queries"); - } - - /** - * @param defaultGraphURIs The defaultGraphURIs to set. - */ - public void setDefaultGraphURIs(List<String> defaultGraphURIs) { - this.defaultGraphURIs = defaultGraphURIs; - } - - /** - * @param namedGraphURIs The namedGraphURIs to set. - */ - public void setNamedGraphURIs(List<String> namedGraphURIs) { - this.namedGraphURIs = namedGraphURIs; - } - - public void addParam(String field, String value) { - if (params == null) - params = new Params(); - params.addParam(field, value); - } - - /** - * @param defaultGraph The defaultGraph to add. - */ - public void addDefaultGraph(String defaultGraph) { - if (defaultGraphURIs == null) - defaultGraphURIs = new ArrayList<String>(); - defaultGraphURIs.add(defaultGraph); - } - - /** - * @param name The URI to add. - */ - public void addNamedGraph(String name) { - if (namedGraphURIs == null) - namedGraphURIs = new ArrayList<String>(); - namedGraphURIs.add(name); - } - - /** - * Set user and password for basic authentication. - * After the request is made (one of the exec calls), the application - * can overwrite the password array to remove details of the secret. - * - * @param user - * @param password - */ - public void setBasicAuthentication(String user, char[] password) { - this.user = user; - this.password = password; - } - - private InputStream doTimedExec(HttpQuery httpQuery) { - DisconnectorThread stopTask = null; - if (timeOut > 0) { - stopTask = new DisconnectorThread(httpQuery, timeOut); -// stopTask.start(); - } - - InputStream in; - try { - in = httpQuery.exec(); - } - finally { - if (stopTask != null) { - stopTask.cancel(); - } - } - - return in; - } - - - public ResultSet execSelect() { - HttpQuery httpQuery = makeHttpQuery(); - // TODO Allow other content types. - httpQuery.setAccept(HttpParams.contentTypeResultsXML); - - InputStream in = httpQuery.exec(); - - - ResultSet rs = ResultSetFactory.fromXML(in); - retainedConnection = in; // This will be closed on close() - return rs; - } - - public Model execConstruct() { - return execConstruct(GraphFactory.makeJenaDefaultModel()); - } - - public Model execConstruct(Model model) { - return execModel(model); - } - - public Model execDescribe() { - return execDescribe(GraphFactory.makeJenaDefaultModel()); - } - - public Model execDescribe(Model model) { - return execModel(model); - } - - private Model execModel(Model model) { - HttpQuery httpQuery = makeHttpQuery(); - httpQuery.setAccept(HttpParams.contentTypeRDFXML); - InputStream in = doTimedExec(httpQuery); - model.read(in, null); - return model; - } - - public boolean execAsk() { - HttpQuery httpQuery = makeHttpQuery(); - httpQuery.setAccept(HttpParams.contentTypeResultsXML); - InputStream in = doTimedExec(httpQuery); - boolean result = XMLInput.booleanFromXML(in); - // Ensure connection is released - try { - in.close(); - } - catch (java.io.IOException e) { - log.warn("Failed to close connection", e); - } - return result; - } - - public Context getContext() { - return context; - } - - private HttpQuery makeHttpQuery() { - HttpQuery httpQuery = new HttpQuery(service); - httpQuery.setTimeOut((int)timeOut); - httpQuery.addParam(HttpParams.pQuery, queryString); - - for (Iterator<String> iter = defaultGraphURIs.iterator(); iter.hasNext();) { - String dft = iter.next(); - httpQuery.addParam(HttpParams.pDefaultGraph, dft); - } - for (Iterator<String> iter = namedGraphURIs.iterator(); iter.hasNext();) { - String name = iter.next(); - httpQuery.addParam(HttpParams.pNamedGraph, name); - } - - if (params != null) - httpQuery.merge(params); - - httpQuery.setBasicAuthentication(user, password); - return httpQuery; - } - - public void abort() { - } - - public void close() { - if (retainedConnection != null) { - try { - retainedConnection.close(); - } - catch (java.io.IOException e) { - log.warn("Failed to close connection", e); - } - finally { - retainedConnection = null; - } - } - } - - @Override - public void setTimeout(long timeout, TimeUnit timeoutUnits) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void setTimeout(long timeout) { - this.timeOut = timeout; - } - - @Override - public void setTimeout(long timeout1, TimeUnit timeUnit1, long timeout2, TimeUnit timeUnit2) { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void setTimeout(long timeout1, long timeout2) { - //To change body of implemented methods use File | Settings | File Templates. - } - -// public boolean isActive() { return false ; } - - @Override - public String toString() { - HttpQuery httpQuery = makeHttpQuery(); - return "GET " + httpQuery.toString(); - } - - public Dataset getDataset() { - return null; - } - - @Override - public Query getQuery() { - return QueryFactory.create(queryString); - } -} - -/* - * (c) Copyright 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/ExtractionDBCache.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -19,22 +19,29 @@ package org.dllearner.kb.sparql; +import java.io.ByteArrayOutputStream; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.dllearner.utilities.Helper; + import com.hp.hpl.jena.query.ResultSetFactory; import com.hp.hpl.jena.query.ResultSetRewindable; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; -import org.aksw.commons.jena.ExtendedQueryEngineHTTP; -import org.dllearner.utilities.Helper; -import java.io.ByteArrayOutputStream; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.sql.*; - /** * The class is used to cache information about resources to a database. * Provides the connection to an H2 database in a light weight, configuration free @@ -127,8 +134,8 @@ // System.out.println("Posing new query"); // String endpoint = "http://139.18.2.37:8890/sparql"; - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), query); - queryExecution.setTimeOut(maxExecutionTimeInSeconds * 1000); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : endpoint.getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } @@ -187,8 +194,8 @@ } else { mon.start(); // System.out.println("no-cache"); - ExtendedQueryEngineHTTP queryExecution = new ExtendedQueryEngineHTTP(endpoint.getURL().toString(), query); - queryExecution.setTimeOut(maxExecutionTimeInSeconds * 1000); + QueryEngineHTTP queryExecution = new QueryEngineHTTP(endpoint.getURL().toString(), query); + queryExecution.setTimeout(maxExecutionTimeInSeconds * 1000); for (String dgu : endpoint.getDefaultGraphURIs()) { queryExecution.addDefaultGraph(dgu); } Deleted: trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java 2012-03-23 14:53:07 UTC (rev 3617) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/HttpQuery.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -1,419 +0,0 @@ -/** - * Copyright (C) 2007-2011, Jens Lehmann - * - * This file is part of DL-Learner. - * - * DL-Learner is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * DL-Learner is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.dllearner.kb.sparql; - -/* - * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP - * [See end of file] - */ - - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.commons.codec.binary.Base64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.hp.hpl.jena.query.ARQ; -import com.hp.hpl.jena.shared.JenaException; -import com.hp.hpl.jena.sparql.ARQInternalErrorException; -import com.hp.hpl.jena.sparql.engine.http.HttpParams; -import com.hp.hpl.jena.sparql.engine.http.Params; -import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; -import com.hp.hpl.jena.sparql.util.Convert; -import com.hp.hpl.jena.util.FileUtils; - -/** Create an execution object for performing a query on a model - * over HTTP. This is the main protocol engine for HTTP query. - * There are higher level classes for doing a query and presenting - * the results in an API fashion. - * - * If the query string is large, then HTTP POST is used. */ -public class HttpQuery extends Params -{ - static final Logger log = LoggerFactory.getLogger(HttpQuery.class.getName()) ; - - /** The definition of "large" queries */ - // Not final so that other code can change it. - static public /*final*/ int urlLimit = 2*1024 ; - - String serviceURL ; - - String contentTypeResult = HttpParams.contentTypeResultsXML ; - HttpURLConnection httpConnection = null ; - - // An object indicate no value associated with parameter name - final static Object noValue = new Object() ; - String user = null ; - char[] password = null ; - - int responseCode = 0; - String responseMessage = null ; - boolean forcePOST = false ; - String queryString = null ; - - private int timeOut = 0; - - public void setTimeOut(int timeOut){ - this.timeOut = timeOut; - } - - //static final String ENC_UTF8 = "UTF-8" ; - - /** Create a execution object for a whole model GET - * @param serviceURL The model - */ - - public HttpQuery(String serviceURL) - { - init(serviceURL) ; - } - - - /** Create a execution object for a whole model GET - * @param url The model - */ - - public HttpQuery(URL url) - { - init(url.toString()) ; - } - - - private void init(String serviceURL) - { - if ( log.isTraceEnabled()) - log.trace("URL: "+serviceURL) ; - - if ( serviceURL.indexOf('?') >= 0 ) - throw new QueryExceptionHTTP(-1, "URL already has a query string ("+serviceURL+")") ; - - this.serviceURL = serviceURL ; - } - - private String getQueryString() - { - if ( queryString == null ) - queryString = super.httpString() ; - return queryString ; - } - - public HttpURLConnection getConnection() { return httpConnection ; } - - /** Set the content type (Accept header) for the results - */ - - public void setAccept(String contentType) - { - contentTypeResult = contentType ; - } - - public void setBasicAuthentication(String user, char[] password) - { - this.user = user ; - this.password = password ; - } - - /** Return whether this request will go by GET or POST - * @return boolean - */ - public boolean usesPOST() - { - if ( forcePOST ) - return true ; - String s = getQueryString() ; - - return serviceURL.length()+s.length() >= urlLimit ; - } - - /** Force the use of HTTP POST for the query operation - */ - - public void setForcePOST() - { - forcePOST = true ; - } - - /** Execute the operation - * @return Model The resulting model - * @throws QueryExceptionHTTP - */ - public InputStream exec() throws QueryExceptionHTTP - { - try { - if (usesPOST()) - return execPost(); - return execGet(); - } catch (QueryExceptionHTTP httpEx) - { - log.trace("Exception in exec", httpEx); - throw httpEx; - } - catch (JenaException jEx) - { - log.trace("JenaException in exec", jEx); - throw jEx ; - } - } - - private InputStream execGet() throws QueryExceptionHTTP - { - URL target = null ; - String qs = getQueryString() ; - - ARQ.getHttpRequestLogger().trace(qs) ; - - try { - if ( count() == 0 ) - target = new URL(serviceURL) ; - else - target = new URL(serviceURL+"?"+qs) ; - } - catch (MalformedURLException malEx) - { throw new QueryExceptionHTTP(0, "Malformed URL: "+malEx) ; } - log.trace("GET "+target.toExternalForm()) ; - - try - { - httpConnection = (HttpURLConnection) target.openConnection(); - httpConnection.setRequestProperty("Accept", contentTypeResult) ; - httpConnection.setReadTimeout(timeOut); - int x = httpConnection.getReadTimeout() ; - - // By default, following 3xx redirects is true - //conn.setFollowRedirects(true) ; - basicAuthentication(httpConnection) ; - - httpConnection.setDoInput(true); - httpConnection.connect(); - try - { - return execCommon(); - } - catch (QueryExceptionHTTP qEx) - { - // Back-off and try POST if something complain about long URIs - // Broken - if (qEx.getResponseCode() == 414 /*HttpServletResponse.SC_REQUEST_URI_TOO_LONG*/ ) - return execPost(); - throw qEx; - } - } - catch (java.net.ConnectException connEx) - { throw new QueryExceptionHTTP(QueryExceptionHTTP.NoServer, "Failed to connect to remote server"); } - catch (IOException ioEx) - { throw new QueryExceptionHTTP(ioEx); } - } - - private InputStream execPost() throws QueryExceptionHTTP - { - URL target = null; - try { target = new URL(serviceURL); } - catch (MalformedURLException malEx) - { throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx); } - log.trace("POST "+target.toExternalForm()) ; - - ARQ.getHttpRequestLogger().trace(target.toExternalForm()) ; - - try - { - httpConnection = (HttpURLConnection) target.openConnection(); - httpConnection.setRequestMethod("POST") ; - httpConnection.setRequestProperty("Accept", contentTypeResult) ; - httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded") ; - basicAuthentication(httpConnection) ; - httpConnection.setDoOutput(true) ; - - boolean first = true ; - OutputStream out = httpConnection.getOutputStream() ; - for ( Iterator<Pair> iter = pairs().listIterator() ; iter.hasNext() ; ) - { - if ( ! first ) - out.write('&') ; - first = false ; - Pair p = iter.next() ; - out.write(p.getName().getBytes()) ; - out.write('=') ; - String x = p.getValue() ; - x = Convert.encWWWForm(x) ; - out.write(x.getBytes()) ; - ARQ.getHttpRequestLogger().trace("Param: "+x) ; - } - out.flush() ; - httpConnection.connect() ; - return execCommon() ; - } - catch (java.net.ConnectException connEx) - { throw new QueryExceptionHTTP(-1, "Failed to connect to remote server"); } - catch (IOException ioEx) - { throw new QueryExceptionHTTP(ioEx); } - } - - private void basicAuthentication(HttpURLConnection httpConnection2) - { - // Do basic authentication : do directly, not via an Authenticator, because it - // avoids an extra round trip (Java normally does the request without authetication, - // then reties with) - - if ( user != null || password != null) - { - try - { - if ( user == null || password == null ) - log.warn("Only one of user/password is set") ; - // We want: "Basic user:password" except user:password is base 64 encoded. - // Build string, get as UTF-8, bytes, translate to base 64. - StringBuffer x = new StringBuffer() ; - byte b[] = x.append(user).append(":").append(password).toString().getBytes("UTF-8") ; - String y = Base64.encodeBase64String(b); - httpConnection.setRequestProperty("Authorization", "Basic "+y) ; - // Overwrite any password details we copied. - // Still leaves the copy in the HTTP connection. But this only basic auth. - for ( int i = 0 ; i < x.length() ; i++ ) x.setCharAt(i, '*') ; - for ( int i = 0 ; i < b.length ; i++ ) b[i] = (byte)0 ; - } catch (UnsupportedEncodingException ex) - { - // Can't happen - UTF-8 is required of all Java platforms. - throw new ARQInternalErrorException("UTF-8 is broken on this platform", ex) ; - } - } - } - - - private InputStream execCommon() throws QueryExceptionHTTP - { - try { - responseCode = httpConnection.getResponseCode() ; - responseMessage = Convert.decWWWForm(httpConnection.getResponseMessage()) ; - - // 1xx: Informational - // 2xx: Success - // 3xx: Redirection - // 4xx: Client Error - // 5xx: Server Error - - if ( 300 <= responseCode && responseCode < 400 ) - throw new QueryExceptionHTTP(responseCode, responseMessage) ; - - // Other 400 and 500 - errors - - if ( responseCode >= 400 ) - throw new QueryExceptionHTTP(responseCode, responseMessage) ; - - // Request suceeded - //httpConnection.setReadTimeout(10) ; - InputStream in = httpConnection.getInputStream() ; - - if ( false ) - { - // Dump the header - Map<String,List<String>> map = httpConnection.getHeaderFields() ; - for ( Iterator<String> iter = map.keySet().iterator() ; iter.hasNext() ; ) - { - String k = iter.next(); - List<String> v = map.get(k) ; - System.out.println(k+" = "+v) ; - } - } - - // Dump response body - if ( false ) - { - StringBuffer b = new StringBuffer(1000) ; - byte[] chars = new byte[1000] ; - while(true) - { - int x = in.read(chars) ; - if ( x < 0 ) break ; - b.append(new String(chars, 0, x, FileUtils.encodingUTF8)) ; - } - System.out.println(b.toString()) ; - System.out.flush() ; - // Reset - in = new ByteArrayInputStream(b.toString().getBytes(FileUtils.encodingUTF8)) ; - } - - - // +++ WORKAROUND for badly behaved apps. - // Apps sometimes call QueryExecution.close straight after .execSelect. - // that results in some resuls being seen, not all of them => XMl parse errors. -// byte[] bytes = IO.readWholeFile(in) ; -// in = new ByteArrayInputStream(bytes) ; - // +++ - - return in ; - } - catch (IOException ioEx) - { - throw new QueryExceptionHTTP(ioEx) ; - } - catch (JenaException rdfEx) - { - throw new QueryExceptionHTTP(rdfEx) ; - } - } - - @Override - public String toString() - { - String s = httpString() ; - if ( s != null && s.length() > 0 ) - return serviceURL+"?"+s ; - return serviceURL ; - } -} - -/* - * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Hewlett-Packard Development Company, LP - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - Added: trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/refinementoperators/SynchronizedRhoDRDown.java 2012-03-26 12:10:46 UTC (rev 3618) @@ -0,0 +1,1713 @@ +/** + * Copyright (C) 2007-2011, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.dllearner.refinementoperators; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; + +import org.apache.log4j.Logger; +import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.Component; +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.config.BooleanEditor; +import org.dllearner.core.config.ConfigOption; +import org.dllearner.core.options.CommonConfigOptions; +import org.dllearner.core.owl.BooleanValueRestriction; +import org.dllearner.core.owl.ClassHierarchy; +import org.dllearner.core.owl.Constant; +import org.dllearner.core.owl.DataRange; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DatatypePropertyHierarchy; +import org.dllearner.core.owl.DatatypeSomeRestriction; +import org.dllearner.core.owl.Description; +import org.dllearner.core.owl.DoubleMaxValue; +import org.dllearner.core.owl.DoubleMinValue; +import org.dllearner.core.owl.Individual; +import org.dllearner.core.owl.Intersection; +import org.dllearner.core.owl.NamedClass; +import org.dllearner.core.owl.Negation; +import org.dllearner.core.owl.Nothing; +import org.dllearner.core.owl.ObjectAllRestriction; +import org.dllearner.core.owl.ObjectCardinalityRestriction; +import org.dllearner.core.owl.ObjectMaxCardinalityRestriction; +import org.dllearner.core.owl.ObjectMinCardinalityRestriction; +import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.ObjectPropertyExpression; +import org.dllearner.core.owl.ObjectPropertyHierarchy; +import org.dllearner.core.owl.ObjectQuantorRestriction; +import org.dllearner.core.owl.ObjectSomeRestriction; +import org.dllearner.core.owl.ObjectValueRestriction; +import org.dllearner.core.owl.StringValueRestriction; +import org.dllearner.core.owl.Thing; +import org.dllearner.core.owl.Union; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.owl.ConceptComparator; +import org.dllearner.utilities.owl.ConceptTransformation; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * A downward refinement operator, which makes use of domains + * and ranges of properties. The operator is currently under + * development. Its aim is to span a much "cleaner" and smaller search + * tree compared to RhoDown by omitting many class descriptions, + * which are obviously too weak, because they violate + * domain/range restrictions. Furthermore, it makes use of disjoint + * classes in the knowledge base. + * + * TODO Some of the code has moved to {@link Utility} in a modified + * form to make it accessible for implementations of other refinement + * operators. These utility methods may be completed and carefully + * integrated back later. + * + * @author Jens Lehmann + * + */ +@ComponentAnn(name = "synchronized rho refinement operator", shortName = "syncrho", version = 0.8) +public class SynchronizedRhoDRDown extends RefinementOperatorAdapter implements Component { + + private static Logger logger = Logger + .getLogger(SynchronizedRhoDRDown.class); + + private AbstractReasonerComponent reasoner; + + // hierarchies + private ClassHierarchy subHierarchy; + private ObjectPropertyHierarchy objectPropertyHierarchy; + private DatatypePropertyHierarchy dataPropertyHierarchy; + + // domains and ranges + private Map<ObjectProperty,Description> opDomains = new TreeMap<ObjectProperty,Description>(); + private Map<DatatypeProperty,Description> dpDomains = new TreeMap<DatatypeProperty,Description>(); + private Map<ObjectProperty,Description> opRanges = new TreeMap<ObjectProperty,Description>(); + + // maximum number of fillers for eeach role + private Map<ObjectProperty,Integer> maxNrOfFillers = new TreeMap<ObjectProperty,Integer>(); + // limit for cardinality restrictions (this makes sense if we e.g. have compounds with up to + // more than 200 atoms but we are only interested in atoms with certain characteristics and do + // not want something like e.g. >= 204 hasAtom.NOT Carbon-87; which blows up the search space + private int cardinalityLimit = 5; + + // start concept (can be used to start from an arbitrary concept, needs + // to be Thing or NamedClass), note that when you use e.g. Compound as + // start class, then the algorithm should start the search with class + // Compound (and not with Thing), because otherwise concepts like + // NOT Carbon-87 will be returned which itself is not a subclass of Compound + private Description startClass = new Thing(); + + // the length of concepts of top refinements, the first values is + // for refinements of \rho_\top(\top), the second one for \rho_A(\top) + private int topRefinementsLength = 0; + private Map<NamedClass, Integer> topARefinementsLength = new TreeMap<NamedClass, Integer>(); + // M is finite and this value is the maximum length of any value in M + private static int mMaxLength = 4; + + // the sets M_\top and M_A + private Map<Integer,SortedSet<Description>> m = new TreeMap<Integer,SortedSet<Description>>(); + private Map<NamedClass,Map<Integer,SortedSet<Description>>> mA = new TreeMap<NamedClass,Map<Integer,SortedSet<Description>>>(); + + // @see MathOperations.getCombos + private Map<Integer, List<List<Integer>>> combos = new HashMap<Integer, List<List<Integer>>>(); + + // refinements of the top concept ordered by length + private Map<Integer, SortedSet<Description>> topRefinements = Collections.synchronizedSortedMap(new TreeMap<Integer, SortedSet<Description>>()); + private Map<NamedClass,Map<Integer, SortedSet<Description>>> topARefinements = Collections.synchronizedSortedMap(new TreeMap<NamedClass,Map<Integer, SortedSet<Description>>>()); + + // cumulated refinements of top (all from length one to the specified length) + private Map<Integer, TreeSet<Description>> topRefinementsCumulative = Collections.synchronizedMap(new HashMap<Integer, TreeSet<Description>>()); + private Map<NamedClass,Map<Integer, TreeSet<Description>>> topARefinementsCumulative = Collections.synchronizedSortedMap(new TreeMap<NamedClass,Map<Integer, TreeSet<Description>>>()); + + // app_A set of applicable properties for a given class (separate for + // object properties, boolean datatypes, and double datatypes) + private Map<NamedClass, Set<ObjectProperty>> appOP = new TreeMap<NamedClass, Set<ObjectProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appBD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appDD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + private Map<NamedClass, Set<DatatypeProperty>> appSD = new TreeMap<NamedClass, Set<DatatypeProperty>>(); + + // most general applicable properties + private Map<NamedClass,Set<ObjectProperty>> mgr = new TreeMap<NamedClass,Set<ObjectProperty>>(); + private Map<NamedClass,Set<DatatypeProperty>> mgbd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); + private Map<NamedClass,Set<DatatypeProperty>> mgdd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); + private Map<NamedClass,Set<DatatypeProperty>> mgsd = new TreeMap<NamedClass,Set<DatatypeProperty>>(); + + // concept comparator + private ConceptComparator conceptComparator = new ConceptComparator(); + + // splits for double datatype properties in ascening order + private Map<DatatypeProperty,List<Double>> splits = new TreeMap<DatatypeProperty,List<Double>>(); + private int maxNrOfSplits = 10; + + // data structure for a simple frequent pattern matching preprocessing phase + private int frequencyThreshold = CommonConfigOptions.valueFrequencyThresholdDefault; + private Map<ObjectProperty, Map<Individual, Integer>> valueFrequency = new HashMap<ObjectProperty, Map<Individual, Integer>>(); + // data structure with identified frequent values + private Map<ObjectProperty, Set<Individual>> frequentValues = new HashMap<ObjectProperty, Set<Individual>>(); + // frequent data values + private Map<DatatypeProperty, Set<Constant>> frequentDataValues = new HashMap<DatatypeProperty, Set<Constant>>(); + private Map<DatatypeProperty, Map<Constant, Integer>> dataValueFrequency = new HashMap<DatatypeProperty, Map<Constant, Integer>>(); + private boolean useDataHasValueConstructor = false; + + // statistics + public long mComputationTimeNs = 0; + public long topComputationTimeNs = 0; + + @ConfigOption(name = "applyAllFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean applyAllFilter = true; + + @ConfigOption(name = "applyExistsFilter", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean applyExistsFilter = true; + + @ConfigOption(name = "useAllConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useAllConstructor = true; + + @ConfigOption(name = "useExistsConstructor", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useExistsConstructor = true; + + @ConfigOption(name = "useHasValueConstructor", defaultValue="false", propertyEditorClass = BooleanEditor.class) + private boolean useHasValueConstructor = false; + + @ConfigOption(name = "useCardinalityRestrictions", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useCardinalityRestrictions = true; + + @ConfigOption(name = "useNegation", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useNegation = true; + + @ConfigOption(name = "useBooleanDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useBooleanDatatypes = true; + + @ConfigOption(name = "useDoubleDatatypes", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean useDoubleDatatypes = true; + + @ConfigOption(name = "useStringDatatypes", defaultValue="false", propertyEditorClass = BooleanEditor.class) + private boolean useStringDatatypes = false; + + @ConfigOption(name = "disjointChecks", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean disjointChecks = true; + + @ConfigOption(name = "instanceBasedDisjoints", defaultValue="true", propertyEditorClass = BooleanEditor.class) + private boolean instanceBasedDisjoints = true; + + @ConfigOption(name = "dropDisjuncts", defaultValue="false", propertyEditorClass = BooleanEditor.class) + private boolean dropDisjuncts = false; + + // caches for reasoner queries + private Map<Description,Map<Description,Boolean>> cachedDisjoints = new TreeMap<Description,Map<Description,Boolean>>(conceptComparator); + +// private Map<NamedClass,Map<NamedClass,Boolean>> abDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); +// private Map<NamedClass,Map<NamedClass,Boolean>> notABDisjoint = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); +// private Map<NamedClass,Map<NamedClass,Boolean>> notABMeaningful = new TreeMap<NamedClass,Map<NamedClass,Boolean>>(); + + private boolean isInitialised = false; + + public SynchronizedRhoDRDown() { + + } + +// public RhoDRDown(AbstractReasonerComponent reasoningService) { +//// this(reasoningService, reasoningService.getClassHierarchy(), null, true, true, true, true, true, 3, true, true, true, true, null); +// this.reasoner = reasoningService; +// this.subHierarchy = reasoner.getClassHierarchy(); +// init(); +// } + + // TODO constructor which takes a RhoDRDownConfigurator object; + // this should be an interface implemented e.g. by ExampleBasedROLComponentConfigurator; + // the goal is to use the configurator system while still being flexible enough to + // use one refinement operator in several learning algorithms +// public RhoDRDown(AbstractReasonerComponent reasoningService, ClassHierarchy subHierarchy, boolean applyAllFilter, boolean applyExistsFilter, boolean useAllConstructor, +// boolean useExistsConstructor, boolean useHasValueConstructor, int valueFrequencyThreshold, boolean useCardinalityRestrictions,boolean useNegation, boolean useBooleanDatatypes, boolean useDoubleDatatypes, NamedClass startClass, +// int cardinalityLimit, boolean useStringDatatypes, boolean instanceBasedDisjoints) { +// this.reasoner = reasoningService; +// this.subHierarchy = subHierarchy; +// this.applyAllFilter = applyAllFilter; +// this.applyExistsFilter = applyExistsFilter; +// this.useAllConstructor = useAllConstructor; +// this.useExistsConstructor = useExistsConstructor; +// this.useHasValueConstructor = useHasValueConstructor; +// this.frequencyThreshold = valueFrequencyThreshold; +// this.useCardinalityRestrictions = useCardinalityRestrictions; +// this.cardinalityLimit = cardinalityLimit; +// this.useNegation = useNegation; +// this.useBooleanDatatypes = useBooleanDatatypes; +// this.useDoubleDatatypes = useDoubleDatatypes; +// this.useStringDatatypes = useStringDatatypes; +// this.instanceBasedDisjoints = instanceBasedDisjoints; +// if(startClass != null) { +// this.startClass = startClass; +// } +// init(); +// } + +// subHierarchy = rs.getClassHierarchy(); + public void init() throws ComponentInitException { + if(isInitialised) { + throw new ComponentInitException("Refinement operator cannot be nitialised twice."); + } +// System.out.println("subHierarchy: " + subHierarchy); +// System.out.println("object properties: " + ); + + // query reasoner for domains and ranges + // (because they are used often in the operator) + for(ObjectProperty op : reasoner.getObjectProperties()) { + opDomains.put(op, reasoner.getDomain(op)); + opRanges.put(op, reasoner.getRange(op)); + + if(useHasValueConstructor) { + // init + Map<Individual, Integer> opMap = new TreeMap<Individual, Integer>(); + valueFrequency.put(op, opMap); + + // sets ordered by corresponding individual (which we ignore) + Collection<SortedSet<Individual>> fillerSets = reasoner.getPropertyMembers(op).values(); + for(SortedSet<Individual> fillerSet : fillerSets) { + for(Individual i : fillerSet) { +// System.out.println("op " + op + " i " + i); + Integer value = opMap.get(i); + + if(value != null) { + opMap.put(i, value+1); + } else { + opMap.put(i, 1); + } + } + } + + // keep only frequent patterns + Set<Individual> frequentInds = new TreeSet<Individual>(); + for(Individual i : opMap.keySet()) { + if(opMap.get(i) >= frequencyThreshold) { + frequentInds.add(i); +// break; + } + } + frequentValues.put(op, frequentInds); + + } + + } + + for(DatatypeProperty dp : reasoner.getDatatypeProperties()) { + dpDomains.put(dp, reasoner.getDomain(dp)); + + if(useDataHasValueConstructor) { + Map<Constant, Integer> dpMap = new TreeMap<Constant, Integer>(); + dataValueFrequency.put(dp, dpMap); + + // sets ordered by corresponding individual (which we ignore) + Collection<SortedSet<Constant>> fillerSets = reasoner.getDatatypeMembers(dp).values(); + for(SortedSet<Constant> fillerSet : fillerSets) { + for(Constant i : fillerSet) { +// System.out.println("op " + op + " i " + i); + Integer value = dpMap.get(i); + + if(value != null) { + dpMap.put(i, value+1); + } else { + dpMap.put(i, 1); + } + } + } + + // keep only frequent patterns + Set<Constant> frequentInds = new TreeSet<Constant>(); + for(Constant i : dpMap.keySet()) { + if(dpMap.get(i) >= frequencyThreshold) { + logger.trace("adding value "+i+", because "+dpMap.get(i) +">="+frequencyThreshold); + frequentInds.add(i); + } + } + frequentDataValues.put(dp, frequentInds); + } + } + + // we do not need the temporary set anymore and let the + // garbage collector take c... [truncated message content] |
From: <dc...@us...> - 2012-03-23 14:53:14
|
Revision: 3617 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3617&view=rev Author: dcherix Date: 2012-03-23 14:53:07 +0000 (Fri, 23 Mar 2012) Log Message: ----------- TODO: * Resolve a problem with the OWLAPIReasoner. * Separate Filters in A- and T-Box filters * Schema Indexer with axioms Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/JenaToOwlapiConverter.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,91 @@ +/** + * + */ +package org.dllearner.kb.sparql.simple; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import com.hp.hpl.jena.ontology.Individual; +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.util.iterator.ExtendedIterator; + +/** + * @author didierc + * + */ +public class ABoxQueryGenerator { + public String createQuery(List<String> individuals, OntModel model, List<String> filters) { + StringBuilder builder = new StringBuilder(); + builder.append("CONSTRUCT {?s ?p ?o} "); + builder.append("{ ?s ?p ?o ."); + List<String> curIndividuals; + if (model.isEmpty()) { + curIndividuals = individuals; + } else { + curIndividuals = this.difference(individuals, this.getIndividualsFromModel(model)); + } + builder.append(" FILTER (?s IN( "); + for (String individual : curIndividuals) { + builder.append("<"); + builder.append(individual); + builder.append(">"); + builder.append(", "); + } + builder.deleteCharAt(builder.length() - 2); + builder.append("))"); + if (filters != null) { + for (String filter : filters) { + builder.append("filter"); + } + } + builder.append("}"); + return builder.toString(); + } + + public String createLastQuery(List<String> individuals, OntModel model, List<String> filters) { + StringBuilder builder = new StringBuilder(); + builder.append("CONSTRUCT {?s ?p ?o . ?o a ?class} "); + builder.append("{ ?s ?p ?o ."); + builder.append("?o a ?class"); + List<String> curIndividuals; + if (model.isEmpty()) { + curIndividuals = individuals; + } else { + curIndividuals = this.difference(individuals, this.getIndividualsFromModel(model)); + } + builder.append(" FILTER ( ?s IN( "); + for (String individual : curIndividuals) { + builder.append("<"); + builder.append(individual); + builder.append(">"); + builder.append(", "); + } + builder.deleteCharAt(builder.length() - 2); + builder.append(")). "); + if (filters != null) { + for (String filter : filters) { + builder.append(filter); + builder.append(". "); + } + } + builder.append("}"); + return builder.toString(); + } + + private List<String> getIndividualsFromModel(OntModel model) { + ExtendedIterator<Individual> iterator = model.listIndividuals(); + LinkedList<String> result = new LinkedList<String>(); + while (iterator.hasNext()) { + result.add(iterator.next().getURI()); + } + return result; + } + + public List<String> difference(List<String> a, List<String> b) { + ArrayList<String> result = new ArrayList<String>(b); + result.removeAll(a); + return result; + } +} Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/ABoxQueryGenerator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/JenaToOwlapiConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/JenaToOwlapiConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/JenaToOwlapiConverter.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,46 @@ +package org.dllearner.kb.sparql.simple; + +import java.io.StringReader; +import java.io.StringWriter; + +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.ReaderDocumentSource; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.rdf.model.Model; + +/** + * + * @author Didier Cherix + * + */ +public class JenaToOwlapiConverter { + + private static Logger log = LoggerFactory.getLogger(JenaToOwlapiConverter.class); + + /** + * + * @param model + * @return + */ + public OWLOntology convert(Model model) { + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + OWLOntology ontology=null; + try { + StringWriter writer = new StringWriter(); + model.write(writer); + StringBuffer stringBuffer = writer.getBuffer(); + ReaderDocumentSource documentSource = new ReaderDocumentSource(new StringReader( + stringBuffer.toString())); + ontology = manager.loadOntologyFromOntologyDocument(documentSource); + } catch (OWLOntologyCreationException e) { + log.error(e.getMessage(), e); + } + return ontology; + } + +} Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/JenaToOwlapiConverter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,39 @@ +/** + * + */ +package org.dllearner.kb.sparql.simple; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; + +/** + * @author didierc + * + */ +public class QueryExecutor { + + private static Logger log=LoggerFactory.getLogger(QueryExecutor.class); + + public OntModel executeQuery(String queryString, String endpoint, OntModel model) { + Query query = QueryFactory.create(queryString); + log.debug("Jena Query: ", query); + QueryExecution qExec = QueryExecutionFactory.sparqlService(endpoint, query); + qExec.execConstruct(model); + return model; + } + + public OntModel executeQuery(String queryString, String endpoint, OntModel model, String defaultGraphURI) { + Query query = QueryFactory.create(queryString); + log.debug("Jena Query: ", query); + QueryExecution qExec = QueryExecutionFactory.sparqlService(endpoint, query, defaultGraphURI); + log.debug("Qexec: {}",qExec); + qExec.execConstruct(model); + return model; + } +} Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/QueryExecutor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,31 @@ +package org.dllearner.kb.sparql.simple; + +import org.nlp2rdf.ontology.ClassIndexer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.ModelFactory; + +public class SchemaIndexer { + private static Logger log = LoggerFactory.getLogger(SchemaIndexer.class); + private ClassIndexer classIndexer=null; + + public SchemaIndexer(){} + + public void init(){ + classIndexer=new ClassIndexer(); + OntModel model = ModelFactory.createOntologyModel(); + model.read(SchemaIndexer.class.getResourceAsStream("dbpedia_3-3.6.owl"), null); + classIndexer.index(model); + } + + public OntModel getHierarchyForURI(String classUri){ + if(classIndexer==null){ + this.init(); + } + return classIndexer.getHierarchyForClassURI(classUri); + } + + +} \ No newline at end of file Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SchemaIndexer.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java (from rev 3609, trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java) =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/SparqlSimpleExtractor.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,165 @@ +package org.dllearner.kb.sparql.simple; + +import java.util.LinkedList; +import java.util.List; + +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.config.ConfigOption; +import org.semanticweb.owlapi.model.OWLOntology; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; + +@ComponentAnn(name = "efficient SPARQL fragment extractor", shortName = "sparqls", version = 0.1) +public class SparqlSimpleExtractor implements KnowledgeSource { + + @ConfigOption(name = "endpointURL", description = "URL of the SPARQL endpoint", required = true) + private String endpointURL = null; + private OntModel model = null; + @ConfigOption(name = "instances", description = "List of the instances to use", required = true) + private List<String> instances = null; + @ConfigOption(name = "filters", description = "List of the filters to use", required = true) + private List<String> filters = null; + @ConfigOption(name = "recursionDepth", description = "recursion depth", required = true) + private int recursionDepth = 0; + @ConfigOption(name = "defaultGraphURI", description = "default graph URI", required = true) + private String defaultGraphURIs=null; + private OWLOntology owlOntology; + + private static Logger log = LoggerFactory.getLogger(SparqlSimpleExtractor.class); + + public SparqlSimpleExtractor() { + model = ModelFactory.createOntologyModel(); + } + + /** + * @param args + * @throws ComponentInitException + */ + public static void main(String[] args) throws ComponentInitException { + SparqlSimpleExtractor extractor = new SparqlSimpleExtractor(); + // extractor.init(); + List<String> individuals = new LinkedList<String>(); + individuals.add("People"); + individuals.add("Animals"); + extractor.setInstances(individuals); + // System.out.println(extractor.createQuery()); + } + + @Override + public void init() throws ComponentInitException { + if (endpointURL == null) { + throw new ComponentInitException("Parameter endpoint URL is required"); + } + if (instances == null) { + throw new ComponentInitException("Parameter instances is required"); + } + if (recursionDepth == 0) { + throw new ComponentInitException( + "A value bigger than 0 is required for parameter recursionDepth"); + } + ABoxQueryGenerator aGenerator = new ABoxQueryGenerator(); + QueryExecutor executor = new QueryExecutor(); + String queryString; + for (int i = 0; i < recursionDepth - 1; i++) { + queryString=aGenerator.createQuery(instances, model, filters); + log.info("SPARQL: {}", queryString); + executor.executeQuery(queryString, endpointURL, model,defaultGraphURIs); + } + queryString = aGenerator.createLastQuery(instances, model, filters); + log.info("SPARQL: {}", queryString); + + executor.executeQuery(queryString, endpointURL, model, defaultGraphURIs); + TBoxQueryGenerator tGenerator = new TBoxQueryGenerator(); + queryString = tGenerator.createQuery(model, filters, instances); + executor.executeQuery(queryString, endpointURL, model,defaultGraphURIs); + JenaToOwlapiConverter converter = new JenaToOwlapiConverter(); + owlOntology=converter.convert(this.model); + } + + public String getEndpointURL() { + return endpointURL; + } + + public void setEndpointURL(String endpointURL) { + this.endpointURL = endpointURL; + } + + public Model getModel() { + return model; + } + + public void setModel(OntModel model) { + this.model = model; + } + + /** + * @return the filters + */ + public List<String> getFilters() { + return filters; + } + + /** + * @param filters + * the filters to set + */ + public void setFilters(List<String> filters) { + this.filters = filters; + } + + /** + * @return the instances + */ + public List<String> getInstances() { + return instances; + } + + /** + * @param instances the instances to set + */ + public void setInstances(List<String> instances) { + this.instances = instances; + } + + /** + * @return the recursionDepth + */ + public int getRecursionDepth() { + return recursionDepth; + } + + /** + * @param recursionDepth the recursionDepth to set + */ + public void setRecursionDepth(int recursionDepth) { + this.recursionDepth = recursionDepth; + } + + /** + * @return the defaultGraphURI + */ + public String getDefaultGraphURIs() { + return defaultGraphURIs; + } + + /** + * @param defaultGraphURI the defaultGraphURI to set + */ + public void setDefaultGraphURIs(String defaultGraphURI) { + this.defaultGraphURIs = defaultGraphURI; + } + + /** + * @return + */ + public OWLOntology getOWLOntology() { + return owlOntology; + } + +} Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java 2012-03-23 14:53:07 UTC (rev 3617) @@ -0,0 +1,35 @@ +/** + * + */ +package org.dllearner.kb.sparql.simple; + +import java.util.List; + +import com.hp.hpl.jena.ontology.OntModel; + +/** + * @author didierc + * + */ +public class TBoxQueryGenerator { + public String createQuery(OntModel model, List<String> filters, List<String> individuals) { + StringBuilder builder = new StringBuilder("CONSTRUCT { ?example a ?class . } "); + builder.append("{ ?example a ?class . "); + builder.append("Filter ( ?example IN("); + for (String individual : individuals) { + builder.append("<"); + builder.append(individual); + builder.append(">"); + builder.append(", "); + } + builder.deleteCharAt(builder.length() - 2); + builder.append("))."); + if (filters != null) { + for (String filter : filters) { + builder.append(filter); + } + } + builder.append("}"); + return builder.toString(); + } +} Property changes on: trunk/components-core/src/main/java/org/dllearner/kb/sparql/simple/TBoxQueryGenerator.java ___________________________________________________________________ Added: svn:mime-type + text/plain This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-20 15:21:12
|
Revision: 3616 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3616&view=rev Author: sebastianwtr Date: 2012-03-20 15:21:00 +0000 (Tue, 20 Mar 2012) Log Message: ----------- [tbsl exploration] started implemanting the main interation function/module Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.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/Template.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.88; + double lim_levensthein=0.92; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub @@ -76,8 +76,8 @@ while(rs.next()){ if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; @@ -101,8 +101,8 @@ //System.out.println("Next: "+rs.getString("uri")); if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; @@ -185,8 +185,8 @@ while(rs.next()){ if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ result.add(rs.getString("uri")); - System.out.print(rs.getString("name")); - System.out.print(" "+rs.getString("uri")+"\n"); + /*System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n");*/ } } return result; Copied: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java (from rev 3613, trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java) =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,73 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.util.HashMap; + +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; + + +/** + * + * @author swalter + * + */ +public class ElementList { + + /** + * Name of the variable, e.g. ?y0 + */ + private String variablename; + + /** + * URI of the Resource or Class, which was used for getting the depending elements with the uri + */ + private String uri; + /** + * HashMap with name -uri pairs. + */ + private HashMap<String,String> hm = new HashMap<String,String>(); + public String getVariablename() { + return variablename; + } + public void setVariablename(String variablename) { + this.variablename = variablename; + } + public HashMap<String,String> getHm() { + return hm; + } + public void setHm(HashMap<String,String> hm) { + this.hm = hm; + } + public String getURI() { + return uri; + } + public void setURI(String resourceURI) { + this.uri = resourceURI; + } + + public ElementList(String name_new, String resource, HashMap<String,String> hm){ + this.setHm(hm); + this.setURI(resource); + this.setVariablename(name_new); + } + + public void printAll(){ + System.out.println("Name: "+this.getVariablename()); + System.out.println("URI: "+this.getURI()); + System.out.println("List of Elements:"); + for(String key : this.hm.keySet()){ + System.out.println( key + ": "+this.hm.get(key)); + } + } + + public String printToString(){ + String result=""; + result+="Name: "+this.getVariablename()+"\n"; + result+="URI: "+this.getURI()+"\n"; + result+="List of Elements:"+"\n"; + for(String key : this.hm.keySet()){ + result+=key + ": "+this.hm.get(key)+"\n"; + } + + return result; + } +} Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/ElementList_new.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -1,49 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Sparql; - -import java.util.HashMap; - -/** - * - * @author swalter - * - */ -public class ElementList_new { - - /** - * Name of the variable, e.g. ?y0 - */ - private String variablename; - - /** - * URI of the Resource or Class, which was used for getting the depending elements with the uri - */ - private String resourceURI; - /** - * HashMap with name -uri pairs. - */ - private HashMap<String,String> hm = new HashMap<String,String>(); - public String getVariablename() { - return variablename; - } - public void setVariablename(String variablename) { - this.variablename = variablename; - } - public HashMap<String,String> getHm() { - return hm; - } - public void setHm(HashMap<String,String> hm) { - this.hm = hm; - } - public String getResourceURI() { - return resourceURI; - } - public void setResourceURI(String resourceURI) { - this.resourceURI = resourceURI; - } - - public ElementList_new(String variable, String resource, HashMap<String,String> hm){ - this.setHm(hm); - this.setResourceURI(resource); - this.setVariablename(variable); - } -} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Elements.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,153 @@ +package org.dllearner.algorithm.tbsl.exploration.Sparql; + +import java.io.IOException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; + +/** + * Creates Set of Classes and Resources with their properties + * @author swalter + * + */ +public class Elements { + private ArrayList<ElementList> resources = new ArrayList<ElementList>(); + private ArrayList<ElementList> classes = new ArrayList<ElementList>(); + public ArrayList<ElementList> getResources() { + return resources; + } + public void setResources(ArrayList<ElementList> resources) { + this.resources = resources; + } + public ArrayList<ElementList> getClasses() { + return classes; + } + public void setClasses(ArrayList<ElementList> classes) { + this.classes = classes; + } + + private void addClasses(ElementList cl) { + this.classes.add(cl); + } + + private void addResources(ElementList cl) { + this.resources.add(cl); + } + + public Elements(ArrayList<ArrayList<String>> condition, ArrayList<ArrayList<Hypothesis>> hypothesen){ + + /* + * first all Classes! + */ + try { + this.setClasses(createElementsOfClasses(hypothesen)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + /* + * second all Resources + */ + try { + this.setResources(createElementsOfResources(hypothesen,condition)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + System.out.println("Created Elements"); + } + + private ArrayList<ElementList> createElementsOfClasses(ArrayList<ArrayList<Hypothesis>> hypothesenList) throws IOException{ + ArrayList<ElementList> classes = new ArrayList<ElementList>(); + + /* + * Iterate over all Hypothesis and look for an IsA + */ + for(ArrayList<Hypothesis> hl : hypothesenList){ + for(Hypothesis h : hl){ + /* + * if isA is found and if Class has uri, get Elements + */ + if(h.getType().contains("isA")&&h.getUri().contains("http")){ + /* + * TODO: improver performance, using geschicktes zwischenspeichern + */ + ElementList el = new ElementList(h.getName(),h.getUri(),ServerUtil.getElementsForGivenClass(h.getUri())); + classes.add(el); + } + } + } + + return classes; + } + + + private ArrayList<ElementList> createElementsOfResources(ArrayList<ArrayList<Hypothesis>> hypothesenList,ArrayList<ArrayList<String>> conditionList) throws IOException{ + ArrayList<ElementList> resources = new ArrayList<ElementList>(); + /* + * Iterate over all Hypothesis and look for an resource + */ + for(ArrayList<Hypothesis> hl : hypothesenList){ + for(Hypothesis h : hl){ + if(h.getType().contains("RESOURCE")&&h.getUri().contains("http")){ + for(ArrayList<String> cl : conditionList){ + if(h.getVariable().equals(cl.get(0))) { + ElementList el = new ElementList(h.getName()+"RIGHT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "RIGHT")); + resources.add(el); + } + if(h.getVariable().equals(cl.get(2))) { + ElementList el = new ElementList(h.getName()+"LEFT",h.getUri(),ServerUtil.getPropertiesForGivenResource(h.getUri(), "LEFT")); + resources.add(el); + } + } + + + } + } + } + + return resources; + } + + + public void printAll(){ + System.out.println("Resources: "); + for(ElementList el: this.resources){ + el.printAll(); + } + System.out.println("\nClasses: "); + for(ElementList el: this.classes){ + el.printAll(); + } + } + + public String printToString(){ + String result=""; + result+="Resources: \n"; + for(ElementList el: this.resources){ + result+=el.printToString()+"\n"; + } + result+="\nClasses: \n"; + for(ElementList el: this.classes){ + result+=el.printToString()+"\n"; + } + return result; + } + + + public boolean isElementEmty(){ + try { + if(this.getClasses().isEmpty()||this.getResources().isEmpty()) return true; + else return false; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return true; + } + } + +} + + Modified: 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 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -4,7 +4,7 @@ public class Hypothesis { private String variable; private String uri; -private float rank; +private double rank; private String name; /** @@ -24,14 +24,14 @@ public void setVariable(String variable) { this.variable = variable; } -public float getRank() { +public double getRank() { return rank; } -public void setRank(float rank) { +public void setRank(double rank) { this.rank = rank; } -public Hypothesis(String variable, String name, String uri, String type, float rank){ +public Hypothesis(String variable, String name, String uri, String type, double rank){ this.setRank(rank); this.setVariable(variable); this.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-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -585,8 +585,8 @@ // GetRessourcePropertys property = new GetRessourcePropertys(); try { - propertiesleft=ServerUtil.sendServerPropertyRequest(s,"LEFT"); - propertiesright=ServerUtil.sendServerPropertyRequest(s,"RIGHT"); + propertiesleft=ServerUtil.getPropertiesForGivenResource(s,"LEFT"); + propertiesright=ServerUtil.getPropertiesForGivenResource(s,"RIGHT"); } catch (Exception e){ @@ -720,7 +720,7 @@ //gets Propertys left or right from the resource! try { - properties=ServerUtil.sendServerPropertyRequest(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); + properties=ServerUtil.getPropertiesForGivenResource(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); if (properties==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -848,8 +848,8 @@ //Get Properties for Resource in condition One and Two from Server try { - propertiesOne=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); - propertiesTwo=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); + propertiesOne=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + propertiesTwo=ServerUtil.getPropertiesForGivenResource(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); if (propertiesOne==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -4,7 +4,7 @@ public class Template { - private ArrayList<ElementList_new> list_of_element_uri_pair = new ArrayList<ElementList_new>(); + private ArrayList<ElementList> list_of_element_uri_pair = new ArrayList<ElementList>(); private ArrayList<ArrayList<String>> condition = new ArrayList<ArrayList<String>>(); private ArrayList<ArrayList<Hypothesis>> hypothesen = new ArrayList<ArrayList<Hypothesis>>(); private String selectTerm; @@ -14,6 +14,7 @@ private String limit; private String question; private String queryType; + private Elements elm; private float overallTime; private float time_Templator; @@ -118,14 +119,14 @@ public void setTime_Templator(float time_Templator) { this.time_Templator = time_Templator; } - public ArrayList<ElementList_new> getList_of_element_uri_pair() { + public ArrayList<ElementList> getList_of_element_uri_pair() { return list_of_element_uri_pair; } - public void setList_of_element_uri_pair(ArrayList<ElementList_new> list_of_element_uri_pair) { + public void setList_of_element_uri_pair(ArrayList<ElementList> list_of_element_uri_pair) { this.list_of_element_uri_pair = list_of_element_uri_pair; } - public void addToList_of_element_uri_pair(ElementList_new newElement) { + public void addToList_of_element_uri_pair(ElementList newElement) { this.list_of_element_uri_pair.add(newElement); } public String getQueryType() { @@ -134,6 +135,12 @@ public void setQueryType(String queryType) { this.queryType = queryType; } + public Elements getElm() { + return elm; + } + public void setElm(Elements elm) { + this.elm = elm; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -176,7 +176,7 @@ for(ArrayList<String> x : condition){ if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ no_iaA_found=false; - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0.0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); @@ -185,23 +185,10 @@ */ add_reverse_template = false; } - /* - * Make sure you don't have the case that a class is left of an isA - */ - /*else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[0])){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); - } - else if(!x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0]) ){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); - }*/ } if(no_iaA_found){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0.0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); } @@ -211,7 +198,7 @@ String tmp= slot.toString().replace(" PROPERTY {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0], tmp_array[1],tmp_array[1], "PROPERTY", 0.0); list_of_hypothesis.add(tmp_hypothesis); } @@ -219,7 +206,7 @@ String tmp= slot.toString().replace(" RESOURCE {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "RESOURCE", 0); + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "RESOURCE", 0.0); list_of_hypothesis.add(tmp_hypothesis); } } @@ -256,12 +243,12 @@ for(Hypothesis h : list_of_hypothesis){ if (h.getUri().equals(x.getUri())){ if(s!=null){ - Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1); + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1.0); new_list.add(new_h); //new_h.printAll(); } else{ - Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1); + Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1.0); new_list.add(new_h); //new_h.printAll(); } @@ -297,10 +284,6 @@ for(Hypothesis h : x){ - //h.printAll(); - - //only if you have a Property or an Unspec, which still has no http:/dbpedia etc - //if(h.getType().contains("PROPERTY") || (h.getType().contains("UNSPEC")&& !h.getUri().contains("http"))){ if(h.getType().contains("PROPERTY")){ ArrayList<String> result= new ArrayList<String>(); try { @@ -313,15 +296,8 @@ } if(!result.isEmpty()){ h.setUri(result.get(0)); - h.setRank(1); + h.setRank(0.0); } - - /* else{ - String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase().replace(" ", "_"); - - h.setUri(tmp); - h.setRank(0); - }*/ } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -369,9 +345,25 @@ template_reverse_conditions.setCondition(condition_reverse_new); template_reverse_conditions.setHypothesen(template.getHypothesen()); - - resultArrayList.add(template); - if(add_reverse_template) resultArrayList.add(template_reverse_conditions); + + /* + * Before adding Templates, generate for each Template a set of Properties and Elements + */ + Elements elm = new Elements(template.getCondition(),template.getHypothesen()); + /* + * If no Elements are created, dont add Template! + */ + //if(elm.isElementEmty()==false){ + template.setElm(elm); + resultArrayList.add(template); + //} + if(add_reverse_template){ + Elements elm_reverse = new Elements(template_reverse_conditions.getCondition(),template_reverse_conditions.getHypothesen()); + //if(elm_reverse.isElementEmty()==false){ + template.setElm(elm_reverse); + resultArrayList.add(template_reverse_conditions); + //} + } } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -30,7 +30,7 @@ for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ String condition_new = condition; //System.out.println("New_Condition before replacing "+condition_new); - float global_rank=0; + double global_rank=0; boolean addQuery=true; for(Hypothesis h : hypothesenList){ condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -2,17 +2,17 @@ public class QueryPair { private String Query; - private float rank; + private double rank; public String getQuery() { return Query; } public void setQuery(String query) { Query = query; } - public float getRank() { + public double getRank() { return rank; } - public void setRank(float rank) { + public void setRank(double rank) { this.rank = rank; } @@ -21,7 +21,7 @@ System.out.println("Rank :"+this.getRank()); } - public QueryPair(String query_new, float rank_new){ + public QueryPair(String query_new, double rank_new){ this.setQuery(query_new); this.setRank(rank_new); } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -73,30 +73,82 @@ /** - * Get an uri and saves the properties of this resource - * @param vergleich + * Uses an URI to get the properties of this resource + * @param uri * @return * @throws IOException */ - public static HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) throws IOException{ + public static HashMap<String,String> getPropertiesForGivenResource(String uri, String side) throws IOException{ - String vergleichorig = vergleich; - String tmp_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String query_property_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+uri+">. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String query_property_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+uri+"> ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String tmp_both=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.} UNION {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String query_property_leftANDright=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+uri+">. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') } UNION {<"+uri+"> ?p ?y. ?p rdfs:label ?s. FILTER (lang(?s) = 'en') }}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; String verarbeitungsurl=null; /*Original*/ - if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; - if(side.contains("LEFT")) verarbeitungsurl=tmp_left; - if(side.contains("BOTH")) verarbeitungsurl=tmp_both; + if(side.contains("RIGHT")) verarbeitungsurl=query_property_right; + if(side.contains("LEFT")) verarbeitungsurl=query_property_left; + if(side.contains("BOTH")) verarbeitungsurl=query_property_leftANDright; - if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; + if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=query_property_left; String result=""; + result = getListOfElements(verarbeitungsurl); + + return generateList(result); + } + + /** + * Uses an URI of a Class to get the Elements of the Class and the related URIs + * @param classUri + * @return + * @throws IOException + */ + public static HashMap<String,String> getElementsForGivenClass(String classUri) throws IOException{ + + + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?s ?x WHERE { ?x rdf:type <"+classUri+">. ?x rdfs:label ?s. FILTER (lang(?s) = 'en') }"; + + String result=""; + result = getListOfElements(query); + + return generateList(result); + } + + + + + + + private static HashMap<String, String> generateList(String result) { + HashMap<String,String> hm = new HashMap<String,String>(); + result=result.replace("<th>s</th>",""); + result=result.replace("<th>p</th>",""); + result=result.replace("<table class=\"sparql\" border=\"1\">",""); + result=result.replace("<tr>",""); + result=result.replace("</tr>",""); + result=result.replace("\n", ""); + result=result.replace(" ", ""); + result=result.replaceFirst("<td>", ""); + + + String[] tmp_array=result.split("</td><td>"); + + for(int i =1; i<=tmp_array.length-2;i=i+2) { + hm.put(tmp_array[i-1].toLowerCase(), tmp_array[i]); + } + + return hm; + } + + + + private static String getListOfElements(String verarbeitungsurl) { + + String result=""; HttpURLConnection connection = null; BufferedReader rd = null; StringBuilder sb = null; @@ -139,25 +191,9 @@ sb = null; connection = null; } - - HashMap<String,String> hm = new HashMap<String,String>(); - result=result.replace("<th>s</th>",""); - result=result.replace("<th>p</th>",""); - result=result.replace("<table class=\"sparql\" border=\"1\">",""); - result=result.replace("<tr>",""); - result=result.replace("</tr>",""); - result=result.replace("\n", ""); - result=result.replace(" ", ""); - result=result.replaceFirst("<td>", ""); - - - String[] tmp_array=result.split("</td><td>"); - - for(int i =1; i<=tmp_array.length-2;i=i+2) { - hm.put(tmp_array[i-1].toLowerCase(), tmp_array[i]); - } - - return hm; + return result; } + + } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-18 21:44:30 UTC (rev 3615) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -15,12 +15,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; import org.dllearner.algorithm.tbsl.exploration.Utils.Query; import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; +import org.dllearner.algorithm.tbsl.exploration.modules.IterationModule; public class testClass_new { @@ -37,28 +39,35 @@ TemplateBuilder testobject = new TemplateBuilder(); String filepath = "/home/swalter/Dokumente/Auswertung/"; - //String file="very_small.xml"; - String file="dbpedia-train.xml"; + String file="very_small.xml"; + //String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); - /* - * TODO: WHy is there no Hypothese for the question: "Who is the mayor of Berlin?" - */ - /*String question = "Is the wife of president Obama called Michelle?"; - //String question = "Who is the mayor of Berlin?"; - //temp_list_result=testobject.createTemplates(question); + + //String question = "Is the wife of president Obama called Michelle?"; + String question = "Who is the leader of Hamburg?"; + temp_list_result=testobject.createTemplates(question); Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); - for(Template t : temp_list_result){ + /*for(Template t : temp_list_result){ //t.printAll(); + try { + t.getElm().printAll(); + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } + }*/ + for(Template t : temp_list_result){ + t.getElm().getResources(); + IterationModule.doIteration(t.getElm(),t.getHypothesen(),t.getCondition()); } - writeQueriesInFile(tm,filepath,file,start,stop );*/ @@ -67,20 +76,28 @@ /* * Generate Templates */ - list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + String result=""; for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); + try { + result+=t.getElm().printToString()+"\n"; + } catch (Exception e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + } } - } + }*/ + /* * Create Query for each Template */ - Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + /*Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); for(Template t : temp_list_result){ //t.printAll(); @@ -88,7 +105,7 @@ for(QueryPair p : qp){ tm.put(p, t.getQuestion()); } - } + }*/ @@ -96,14 +113,14 @@ * Get Elements for Each Resource and Class */ - long stop = System.currentTimeMillis(); + /*long stop = System.currentTimeMillis(); System.out.println("Duration in ms: " + (stop - start)); - + writeStringToFile(result,filepath,file,start,stop); */ /* * Write Results in File */ - writeQueriesInFile(tm,filepath,file,start,stop ); + //writeQueriesInFile(tm,filepath,file,start,stop ); //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -177,14 +194,23 @@ for(QueryPair key : tm.keySet()){ result+=tm.get(key)+": "+key.getQuery()+" "+key.getRank()+"\n"; } - + result+="OverAll Time: "+(stop-start)+"ms\n"; bw.write(result); bw.flush(); bw.close(); } + private static void writeStringToFile(String result,String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Sonstiges"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + bw.write(result); + bw.flush(); + bw.close(); + } + + private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/IterationModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,127 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +import java.sql.SQLException; +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.ElementList; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Elements; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; + +/** + * Gets Elements, Condition and Hypothesen and returns HypothesenSets. + * Also the different Modules, like Levensthein, Wordnet are used here. + * @author swalter + * + */ +public class IterationModule { + + /** + * returns ArrayList<ArrayList<Hypothesis>> which than can be added using + * @param elm + * @param hypothesen + * @param condition + * @return ArrayList<ArrayList<Hypothesis>> + */ + public static ArrayList<ArrayList<Hypothesis>> doIteration(Elements elm,ArrayList<ArrayList<Hypothesis>> givenHypothesenList,ArrayList<ArrayList<String>> givenConditionList){ + + for(ArrayList<Hypothesis> hl :givenHypothesenList){ + + /* + * First look for resources and generate List with properties + */ + for(Hypothesis h : hl){ + if(h.getType().contains("RESOURCE")){ + /* + * Get Variable from Resource + */ + String variable = h.getVariable(); + + /* + * Look in Condition for the Set, in which the variable appears + */ + ArrayList<String> propertyVariableList = new ArrayList<String>(); + for(ArrayList<String> cl : givenConditionList){ + for(String s : cl){ + if(s.contains(variable)){ + /* + * Mark Also if the Property is left or right from the Resource + */ + if(s.equals(cl.get(0))) propertyVariableList.add(cl.get(1)+"RIGHT::"+variable); + else propertyVariableList.add(cl.get(1)+"LEFT::"+variable); + } + } + } + + /* + * Now get for each found Property the Name + */ + ArrayList<String> propertyNameList = new ArrayList<String>(); + for(String s : propertyVariableList){ + for(Hypothesis h_t : hl){ + //System.out.println("s in creating propertyNameList: "+s); + String variable_t = s; + variable_t=variable_t.replace("RIGHT", ""); + variable_t=variable_t.replace("LEFT", ""); + if(h_t.getVariable().contains(variable_t)) propertyNameList.add(h_t.getName()+"::"+s); + + } + } + + /* + * Now find for each Property the list of Propertys of the resource in Elements and compare with Levensthein/Wordnet etc + */ + ArrayList<ElementList> resources = elm.getResources(); + for(String s : propertyNameList){ + String[] array = s.split("::"); + + System.out.println("s: "+s); + System.out.println("Array:"); + for(String t : array){ + System.out.println(t); + } + + /* + * array[0] contains name of Property + * array[1] contains LEFT/RIGHT and Variable of Property + * array[2] contains Name of Resource + */ + + String side="LEFT"; + if(array[1].contains("RIGHT")) side="RIGHT"; + + for(ElementList el : resources){ + if(el.getVariablename().contains(array[2]) && el.getVariablename().contains(side)){ + String propertyVariable = array[1]; + propertyVariable=propertyVariable.replace("LEFT", ""); + propertyVariable=propertyVariable.replace("RIGHT", ""); + ArrayList<Hypothesis> resultHypothesenList = new ArrayList<Hypothesis>(); + try { + resultHypothesenList= LevenstheinModule.doLevensthein(propertyVariable,array[0],el.getHm()); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + for(Hypothesis h_p : resultHypothesenList) h_p.printAll(); + + } + } + + } + + } + } + + + + /* + * Iterate over all "founded" properties and generate new Hypothesensets, using the "old" resource and isA case + */ + } + + return null; + + } + + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/LevenstheinModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,41 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; + +public class LevenstheinModule { + private final static double LevenstheinMin=0.8; + + public static ArrayList<Hypothesis> doLevensthein(String variable, String property_to_compare_with, HashMap<String, String> properties) + throws SQLException { + ArrayList<Hypothesis> listOfNewHypothesen= new ArrayList<Hypothesis>(); + + + //iterate over properties + for (Entry<String, String> entry : properties.entrySet()) { + String key = entry.getKey(); + key=key.replace("\"",""); + key=key.replace("@en",""); + String value = entry.getValue(); + + //compare property gotten from the resource with the property from the original query + double nld=Levenshtein.nld(property_to_compare_with.toLowerCase(), key); + + //if(nld>=LevenstheinMin||key.contains(lemmatiser.stem(property_to_compare_with))||property_to_compare_with.contains(lemmatiser.stem(key))){ + + if(nld>=LevenstheinMin){ + Hypothesis h = new Hypothesis(variable, key, value, "PROPERTY", nld); + listOfNewHypothesen.add(h); + } + + } + + return listOfNewHypothesen; + } + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/modules/WordnetModule.java 2012-03-20 15:21:00 UTC (rev 3616) @@ -0,0 +1,8 @@ +package org.dllearner.algorithm.tbsl.exploration.modules; + +public class WordnetModule { + + private int explorationdepthwordnet =2; + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-18 21:44:37
|
Revision: 3615 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3615&view=rev Author: sebastianwtr Date: 2012-03-18 21:44:30 +0000 (Sun, 18 Mar 2012) Log Message: ----------- [tbsl exploration] improved some functions Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.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/exploration_main/testClass_new.java Added Paths: ----------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -2,6 +2,8 @@ import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; public class Index_utils { @@ -15,7 +17,7 @@ */ public static ArrayList<String> searchIndex(String string, int fall, SQLiteIndex myindex) throws SQLException{ - String originalString=string; + string=string.replace("_", " "); string=string.replace("-", " "); string=string.replace(".", " "); @@ -54,8 +56,8 @@ public static ArrayList<String> searchIndexForResource(String string, SQLiteIndex myindex) throws SQLException{ - - string=string.replace("_", " "); + HashMap<String,Float> hm = new HashMap<String,Float>(); +string=string.replace("_", " "); string=string.replace("-", " "); string=string.replace(".", " "); String result=null; @@ -82,6 +84,15 @@ } public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ + HashMap<String,Float> hm = new HashMap<String,Float>(); + + // adding or set elements in Map by put method key and value pair + /* + * + * // autoboxing takes care of that. +map.put(23, 2.5f); +map.put(64, 4.83f); + */ string=string.replace("_", " "); string=string.replace("-", " "); @@ -91,14 +102,17 @@ result=myindex.getPropertyURI(string.toLowerCase()); if(result!=null){ result_List.add(result); + hm.put(result, 1.0f); } else{ result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + hm.put(result, 0.0f); } return result_List; + //return hm; } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -19,7 +19,7 @@ public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; - double lim_levensthein=0.84; + double lim_levensthein=0.88; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub 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-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -28,8 +28,8 @@ import net.didion.jwnl.data.POS; import org.dllearner.algorithm.tbsl.exploration.Index.SQLiteIndex; -import org.dllearner.algorithm.tbsl.exploration.Utils.GetRessourcePropertys; import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; +import org.dllearner.algorithm.tbsl.exploration.Utils.ServerUtil; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; import org.dllearner.algorithm.tbsl.nlp.WordNet; import org.dllearner.algorithm.tbsl.sparql.BasicQueryTemplate; @@ -582,11 +582,11 @@ if(tmpcounter <=number_of_x_used){ HashMap<String,String> propertiesleft = new HashMap<String, String>(); HashMap<String,String> propertiesright = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); + // GetRessourcePropertys property = new GetRessourcePropertys(); try { - propertiesleft=property.getPropertys(s,"LEFT",timeToTimeoutOnServer); - propertiesright=property.getPropertys(s,"RIGHT",timeToTimeoutOnServer); + propertiesleft=ServerUtil.sendServerPropertyRequest(s,"LEFT"); + propertiesright=ServerUtil.sendServerPropertyRequest(s,"RIGHT"); } catch (Exception e){ @@ -709,7 +709,6 @@ HashMap<String,String> properties = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; @@ -721,7 +720,7 @@ //gets Propertys left or right from the resource! try { - properties=property.getPropertys(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty,timeToTimeoutOnServer); + properties=ServerUtil.sendServerPropertyRequest(queryObject.getHashValue(resource.toLowerCase()),sideOfProperty); if (properties==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); @@ -844,14 +843,13 @@ } HashMap<String,String> propertiesOne = new HashMap<String, String>(); HashMap<String,String> propertiesTwo = new HashMap<String, String>(); - GetRessourcePropertys property = new GetRessourcePropertys(); Boolean goOnAfterProperty = true; //Get Properties for Resource in condition One and Two from Server try { - propertiesOne=property.getPropertys(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne,timeToTimeoutOnServer); - propertiesTwo=property.getPropertys(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo,timeToTimeoutOnServer); + propertiesOne=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceOne.toLowerCase(),0),sideOfPropertyOne); + propertiesTwo=ServerUtil.sendServerPropertyRequest(getUriFromIndex(resourceTwo.toLowerCase(),0),sideOfPropertyTwo); if (propertiesOne==null){ System.out.println("Begin:\n"+query +"\nError in getting Properties \n End"); Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Template.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -13,6 +13,7 @@ private String OrderBy; private String limit; private String question; + private String queryType; private float overallTime; private float time_Templator; @@ -49,7 +50,7 @@ } - public Template(ArrayList<ArrayList<String>>condition_new, String having_new, String filter_new, String SelectTerm_new, String OrderBy_new, String limit_new, String question_new){ + public Template(ArrayList<ArrayList<String>>condition_new, String queryType_new, String having_new, String filter_new, String SelectTerm_new, String OrderBy_new, String limit_new, String question_new){ this.setCondition(condition_new); this.setHaving(having_new); this.setFilter(filter_new); @@ -57,6 +58,7 @@ this.setLimit(limit_new); this.setSelectTerm(SelectTerm_new); this.setQuestion(question_new); + this.setQueryType(queryType_new); } public ArrayList<ArrayList<String>> getCondition() { return condition; @@ -90,6 +92,7 @@ } } System.out.print("\n"); + System.out.println("QueryType "+queryType); System.out.println("selectTerm: "+selectTerm); System.out.println("having: "+having); System.out.println("filter: "+filter); @@ -125,6 +128,12 @@ public void addToList_of_element_uri_pair(ElementList_new newElement) { this.list_of_element_uri_pair.add(newElement); } + public String getQueryType() { + return queryType; + } + public void setQueryType(String queryType) { + this.queryType = queryType; + } } Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -160,7 +160,7 @@ * SLOT_title: PROPERTY {title,name,label} mitfuehren */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit,question); + Template template = new Template(condition,bqt.getQt().toString(), having, filter, selectTerm,OrderBy, limit,question); boolean add_reverse_template = true; @@ -226,12 +226,12 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - /*System.out.println("Alle Hypothesen VOR der Verarbeitung"); + /* System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ x.printAll(); } - System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); - */ + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n");*/ + for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource @@ -258,16 +258,19 @@ if(s!=null){ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), s, h.getType(), 1); new_list.add(new_h); + //new_h.printAll(); } else{ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), 1); new_list.add(new_h); + //new_h.printAll(); } } else{ Hypothesis new_h = new Hypothesis(h.getVariable(),h.getName(), h.getUri(), h.getType(), h.getRank()); new_list.add(new_h); + //new_h.printAll(); } } final_list_set_hypothesis.add(new_list); @@ -275,8 +278,14 @@ } } + /*System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung"); + for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ + for(Hypothesis x : lh){ + x.printAll(); + } + } + System.out.println("Alle Hypothesen nach der ERSTEN Verarbeitung - Done \n\n");*/ - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /* @@ -288,7 +297,7 @@ for(Hypothesis h : x){ - + //h.printAll(); //only if you have a Property or an Unspec, which still has no http:/dbpedia etc //if(h.getType().contains("PROPERTY") || (h.getType().contains("UNSPEC")&& !h.getUri().contains("http"))){ @@ -321,11 +330,23 @@ } } + /*System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung"); + for(ArrayList<Hypothesis> lh : final_list_set_hypothesis){ + for(Hypothesis x : lh){ + x.printAll(); + } + } + + System.out.println("Alle Hypothesen nach der ZWEITEN Verarbeitung - Done \n\n");*/ + + + + template.setHypothesen(final_list_set_hypothesis); - Template template_reverse_conditions = new Template(template.getCondition(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); + Template template_reverse_conditions = new Template(template.getCondition(),template.getQueryType(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); @@ -353,9 +374,13 @@ if(add_reverse_template) resultArrayList.add(template_reverse_conditions); } } - /*for(Template temp : resultArrayList){ + + /*System.out.println("Nach allen Verarbeitungsschritten:"); + for(Template temp : resultArrayList){ temp.printAll(); - }*/ + } + + System.out.println("Nach allen Verarbeitungsschritten - DONE");*/ return resultArrayList; } } Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -1,159 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; - - -public class 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: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{ - - return sendServerPropertyRequest(element,side, timeToTimeoutOnServer); - - - - } - - /** - * Get an uri and saves the properties of this resource - * @param vergleich - * @return - * @throws IOException - */ - private HashMap<String,String> sendServerPropertyRequest(String vergleich, String side, int timeToTimeoutOnServer) throws IOException{ - - String vergleichorig = vergleich; - - String tmp_left=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - - String tmp_right=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - - String tmp_both=Prefix+"?default-graph-uri=&query="+createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.} UNION {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; - String verarbeitungsurl=null; - - /*Original*/ - if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; - if(side.contains("LEFT")) verarbeitungsurl=tmp_left; - if(side.contains("BOTH")) verarbeitungsurl=tmp_both; - - if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; - - String result=""; - HttpURLConnection connection = null; - BufferedReader rd = null; - StringBuilder sb = null; - String line = null; - - URL serverAddress = null; - - try { - serverAddress = new URL(verarbeitungsurl); - //set up out communications stuff - connection = null; - - //Set up the initial connection - connection = (HttpURLConnection)serverAddress.openConnection(); - connection.setRequestMethod("GET"); - connection.setDoOutput(true); - connection.setReadTimeout(timeToTimeoutOnServer); - - connection.connect(); - rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); - sb = new StringBuilder(); - - while ((line = rd.readLine()) != null) - { - sb.append(line + '\n'); - } - - result=sb.toString(); - - } catch (MalformedURLException e) { - System.out.println("Must enter a valid URL"); - } catch (IOException e) { - System.out.println("Can not connect or timeout"); - } - finally - { - //close the connection, set all objects to null - connection.disconnect(); - rd = null; - sb = null; - connection = null; - } - - HashMap<String,String> hm = new HashMap<String,String>(); - result=result.replace("<th>s</th>",""); - result=result.replace("<th>p</th>",""); - result=result.replace("<table class=\"sparql\" border=\"1\">",""); - result=result.replace("<tr>",""); - result=result.replace("</tr>",""); - result=result.replace("\n", ""); - result=result.replace(" ", ""); - result=result.replaceFirst("<td>", ""); - - - String[] tmp_array=result.split("</td><td>"); - - for(int i =1; i<=tmp_array.length-2;i=i+2) { - hm.put(tmp_array[i-1].toLowerCase(), tmp_array[i]); - } - - return hm; - } - - - - - - private String createServerRequest(String query){ - String anfrage=null; - anfrage=removeSpecialKeys(query); - anfrage=anfrage.replace("<","<"); - anfrage=anfrage.replace("%gt;",">"); - anfrage=anfrage.replace("&","&"); - //anfrage=anfrage.replaceAll("#>","%23%3E%0D%0A%"); - anfrage=anfrage.replace("#","%23"); - anfrage=anfrage.replace(" ","+"); - anfrage=anfrage.replace("/","%2F"); - anfrage=anfrage.replace(":","%3A"); - anfrage=anfrage.replace("?","%3F"); - anfrage=anfrage.replace("$","%24"); - //anfrage=anfrage.replaceAll("F>+","F%3E%0D%0A"); - anfrage=anfrage.replace(">","%3E"); - anfrage=anfrage.replace("<","%3C"); - anfrage=anfrage.replace("\"","%22"); - anfrage=anfrage.replace("\n","%0D%0A%09"); - anfrage=anfrage.replace("%%0D%0A%09","%09"); - anfrage=anfrage.replace("=","%3D"); - anfrage=anfrage.replace("@","%40"); - anfrage=anfrage.replace("&","%26"); - anfrage=anfrage.replace("(","%28"); - anfrage=anfrage.replace(")","%29"); - anfrage=anfrage.replace("%3E%0D%0A%25","%3E"); - //anfrage=anfrage.replaceAll("\n",".%0D%0A%09"); - return anfrage; - } - - private String removeSpecialKeys(String query){ - query=query.replace("\\",""); - //query=query.replaceAll("\a",""); - query=query.replace("\b",""); - query=query.replace("\f",""); - query=query.replace("\r",""); - query=query.replace("\t",""); - // query=query.replaceAll("\v",""); - return query; - } - -} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Query.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,63 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.util.ArrayList; + +import org.dllearner.algorithm.tbsl.exploration.Sparql.Hypothesis; +import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; + +public class Query { + + /** + * Creates Queries + * @param t + * @return + */ + public static ArrayList<QueryPair> returnSetOfQueries(Template t){ + + ArrayList<QueryPair> queryList = new ArrayList<QueryPair>(); + /* + * TODO: Generate a Query for each Hypothesenset, replacing the variable in the condition with the uri from the hypothesenset in <> + */ + String condition=""; + for(ArrayList<String> conditionList :t.getCondition()){ + for(String s : conditionList) condition+=s+" "; + //to End a triple of variables + condition+="."; + } + /* + * Now replacing varibale with the uri from the Hypot. + */ + for(ArrayList<Hypothesis> hypothesenList : t.getHypothesen()){ + String condition_new = condition; + //System.out.println("New_Condition before replacing "+condition_new); + float global_rank=0; + boolean addQuery=true; + for(Hypothesis h : hypothesenList){ + condition_new=condition_new.replace(h.getVariable(), "<"+h.getUri()+">"); + /* + * Dont create a Query with variables, which dont have a correct uri + */ + if(!h.getUri().contains("http")){ + addQuery=false; + } + condition_new=condition_new.replace("isA", "rdf:type"); + global_rank=global_rank+h.getRank(); + } + //System.out.println("New_Condition after replacing "+condition_new); + String query="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+t.getQueryType()+" "+t.getSelectTerm()+" WHERE {"+ condition_new+" "+ t.getFilter()+"}"+t.getOrderBy()+" "+t.getHaving() +" "+t.getLimit(); + QueryPair qp = new QueryPair(query,global_rank); + if(addQuery)queryList.add(qp); + } + + + return queryList; + } + + /*public static QueryPair getBestQuery(Template t){ + ArrayList<QueryPair> qp = returnSetOfQueries(t); + + + return ; + }*/ + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/QueryPair.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,30 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +public class QueryPair { + private String Query; + private float rank; + public String getQuery() { + return Query; + } + public void setQuery(String query) { + Query = query; + } + public float getRank() { + return rank; + } + public void setRank(float rank) { + this.rank = rank; + } + + public void printAll(){ + System.out.println("Query :"+this.getQuery()); + System.out.println("Rank :"+this.getRank()); + } + + public QueryPair(String query_new, float rank_new){ + this.setQuery(query_new); + this.setRank(rank_new); + } + + +} Added: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java (rev 0) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/ServerUtil.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -0,0 +1,163 @@ +package org.dllearner.algorithm.tbsl.exploration.Utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; + +public class ServerUtil { + + + //String static server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://dbpedia.org/sparql"; + private static String server_Prefix="http://greententacle.techfak.uni-bielefeld.de:5171/sparql"; + //private static String server_Prefix="http://purpurtentacle.techfak.uni-bielefeld.de:8890/sparql"; + + private static int timeToTimeoutOnServer=30000; + + + public static String createServerRequest(String query){ + String anfrage=null; + anfrage=removeSpecialKeys(query); + anfrage=anfrage.replace("<","<"); + anfrage=anfrage.replace("%gt;",">"); + anfrage=anfrage.replace("&","&"); + //anfrage=anfrage.replaceAll("#>","%23%3E%0D%0A%"); + anfrage=anfrage.replace("#","%23"); + anfrage=anfrage.replace(" ","+"); + anfrage=anfrage.replace("/","%2F"); + anfrage=anfrage.replace(":","%3A"); + anfrage=anfrage.replace("?","%3F"); + anfrage=anfrage.replace("$","%24"); + //anfrage=anfrage.replaceAll("F>+","F%3E%0D%0A"); + anfrage=anfrage.replace(">","%3E"); + anfrage=anfrage.replace("<","%3C"); + anfrage=anfrage.replace("\"","%22"); + anfrage=anfrage.replace("\n","%0D%0A%09"); + anfrage=anfrage.replace("%%0D%0A%09","%09"); + anfrage=anfrage.replace("=","%3D"); + anfrage=anfrage.replace("@","%40"); + anfrage=anfrage.replace("&","%26"); + anfrage=anfrage.replace("(","%28"); + anfrage=anfrage.replace(")","%29"); + anfrage=anfrage.replace("%3E%0D%0A%25","%3E"); + //anfrage=anfrage.replaceAll("\n",".%0D%0A%09"); + return anfrage; + } + + private static String removeSpecialKeys(String query){ + query=query.replace("\\",""); + //query=query.replaceAll("\a",""); + query=query.replace("\b",""); + query=query.replace("\f",""); + query=query.replace("\r",""); + query=query.replace("\t",""); + // query=query.replaceAll("\v",""); + return query; + } + + public static String getServer_Prefix() { + return server_Prefix; + } + + public static int getTimeToTimeoutOnServer() { + return timeToTimeoutOnServer; + } + + public static void setTimeToTimeoutOnServer(int timeToTimeoutOnServer) { + ServerUtil.timeToTimeoutOnServer = timeToTimeoutOnServer; + } + + + /** + * Get an uri and saves the properties of this resource + * @param vergleich + * @return + * @throws IOException + */ + public static HashMap<String,String> sendServerPropertyRequest(String vergleich, String side) throws IOException{ + + String vergleichorig = vergleich; + + String tmp_left=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + + String tmp_right=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + + String tmp_both=ServerUtil.getServer_Prefix()+"?default-graph-uri=&query="+ServerUtil.createServerRequest("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?s ?p WHERE {{?y ?p <"+vergleichorig+">. ?p rdfs:label ?s.} UNION {<"+vergleichorig+"> ?p ?y. ?p rdfs:label ?s.}}")+"%0D%0A&format=text%2Fhtml&debug=on&timeout="; + String verarbeitungsurl=null; + + /*Original*/ + if(side.contains("RIGHT")) verarbeitungsurl=tmp_right; + if(side.contains("LEFT")) verarbeitungsurl=tmp_left; + if(side.contains("BOTH")) verarbeitungsurl=tmp_both; + + if(!side.contains("LEFT") && !side.contains("RIGHT")) verarbeitungsurl=tmp_left; + + String result=""; + HttpURLConnection connection = null; + BufferedReader rd = null; + StringBuilder sb = null; + String line = null; + + URL serverAddress = null; + + try { + serverAddress = new URL(verarbeitungsurl); + //set up out communications stuff + connection = null; + + //Set up the initial connection + connection = (HttpURLConnection)serverAddress.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(getTimeToTimeoutOnServer()); + + connection.connect(); + rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + sb = new StringBuilder(); + + while ((line = rd.readLine()) != null) + { + sb.append(line + '\n'); + } + + result=sb.toString(); + + } catch (MalformedURLException e) { + System.out.println("Must enter a valid URL"); + } catch (IOException e) { + System.out.println("Can not connect or timeout"); + } + finally + { + //close the connection, set all objects to null + connection.disconnect(); + rd = null; + sb = null; + connection = null; + } + + HashMap<String,String> hm = new HashMap<String,String>(); + result=result.replace("<th>s</th>",""); + result=result.replace("<th>p</th>",""); + result=result.replace("<table class=\"sparql\" border=\"1\">",""); + result=result.replace("<tr>",""); + result=result.replace("</tr>",""); + result=result.replace("\n", ""); + result=result.replace(" ", ""); + result=result.replaceFirst("<td>", ""); + + + String[] tmp_array=result.split("</td><td>"); + + for(int i =1; i<=tmp_array.length-2;i=i+2) { + hm.put(tmp_array[i-1].toLowerCase(), tmp_array[i]); + } + + return hm; + } + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-15 11:10:37 UTC (rev 3614) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-18 21:44:30 UTC (rev 3615) @@ -10,6 +10,8 @@ import java.io.InputStreamReader; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,6 +19,8 @@ import org.dllearner.algorithm.tbsl.exploration.Sparql.Template; import org.dllearner.algorithm.tbsl.exploration.Sparql.TemplateBuilder; import org.dllearner.algorithm.tbsl.exploration.Sparql.queryInformation; +import org.dllearner.algorithm.tbsl.exploration.Utils.Query; +import org.dllearner.algorithm.tbsl.exploration.Utils.QueryPair; public class testClass_new { @@ -37,22 +41,33 @@ String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); + /* + * TODO: WHy is there no Hypothese for the question: "Who is the mayor of Berlin?" + */ + /*String question = "Is the wife of president Obama called Michelle?"; + //String question = "Who is the mayor of Berlin?"; + //temp_list_result=testobject.createTemplates(question); - //String question = "Is the wife of president Obama called Michelle?"; - String question = "Who is the mayor of Berlin?"; - temp_list_result=testobject.createTemplates(question); + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + for(Template t : temp_list_result){ - t.printAll(); + //t.printAll(); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + for(QueryPair p : qp){ + tm.put(p, t.getQuestion()); + } } + writeQueriesInFile(tm,filepath,file,start,stop );*/ + ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); /* * Generate Templates */ - /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); + list_of_structs=generateStruct(filepath+"XMLDateien/"+file); for(queryInformation s : list_of_structs){ ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); @@ -60,9 +75,23 @@ temp_list_result.add(t); } - }*/ + } + /* + * Create Query for each Template + */ + Map<QueryPair,String> tm = new HashMap<QueryPair, String>(); + for(Template t : temp_list_result){ + //t.printAll(); + ArrayList<QueryPair> qp = Query.returnSetOfQueries(t); + for(QueryPair p : qp){ + tm.put(p, t.getQuestion()); + } + } + + + /* * Get Elements for Each Resource and Class */ @@ -74,7 +103,8 @@ /* * Write Results in File */ - writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + writeQueriesInFile(tm,filepath,file,start,stop ); + //writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); } @@ -105,6 +135,7 @@ } } result+="\n"; + result+="queryType: "+t.getQueryType()+"\n"; result+="selectTerm: "+t.getSelectTerm()+"\n"; result+="having: "+t.getHaving()+"\n"; result+="filter: "+t.getFilter()+"\n"; @@ -130,7 +161,31 @@ bw.flush(); bw.close(); } + + + private static void writeQueriesInFile(Map<QueryPair,String> tm, String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Queries"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + String result=""; + /* + * for(String key : map.keySet()) + { + System.out.print("Key: " + key + " - "); + System.out.print("Value: " + map.get(key) + "\n"); + } + */ + for(QueryPair key : tm.keySet()){ + result+=tm.get(key)+": "+key.getQuery()+" "+key.getRank()+"\n"; + } + bw.write(result); + bw.flush(); + bw.close(); + } + + + + private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); String XMLType=null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-15 11:10:48
|
Revision: 3614 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3614&view=rev Author: sebastianwtr Date: 2012-03-15 11:10:37 +0000 (Thu, 15 Mar 2012) Log Message: ----------- [tbsl exploration] removed error in generating templates Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-15 03:22:33 UTC (rev 3613) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-15 11:10:37 UTC (rev 3614) @@ -172,26 +172,40 @@ String tmp= slot.toString().replace(" UNSPEC {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); + boolean no_iaA_found=true; for(ArrayList<String> x : condition){ if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + no_iaA_found=false; Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); /* - * if you have already found an isA -Class-Pair, you dont have to creat the up-side-down, because it will be false + * if you have already found an isA -Class-Pair, you don't have to create the up-side-down, because it will be false */ add_reverse_template = false; } /* - * Make sure you dont have the case that a class is left of an isA + * Make sure you don't have the case that a class is left of an isA */ - else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[0])){ - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "UNSPEC", 0); + /*else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[0])){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); + //tmp_hypothesis.printAll(); + list_of_hypothesis.add(tmp_hypothesis); + } + else if(!x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0]) ){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); //tmp_hypothesis.printAll(); list_of_hypothesis.add(tmp_hypothesis); - } + }*/ } + + if(no_iaA_found){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "PROPERTY", 0); + //tmp_hypothesis.printAll(); + list_of_hypothesis.add(tmp_hypothesis); + } + } if(slot.toString().contains("PROPERTY")){ String tmp= slot.toString().replace(" PROPERTY {", ""); @@ -212,7 +226,13 @@ ArrayList<ArrayList<Hypothesis>> final_list_set_hypothesis = new ArrayList<ArrayList<Hypothesis>>(); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + /*System.out.println("Alle Hypothesen VOR der Verarbeitung"); for(Hypothesis x : list_of_hypothesis){ + x.printAll(); + } + System.out.println("Alle Hypothesen VOR der Verarbeitung - Done \n\n"); + */ + for(Hypothesis x : list_of_hypothesis){ /* * TODO: Change if ISA only ask classes, else resource */ @@ -268,9 +288,11 @@ for(Hypothesis h : x){ + //only if you have a Property or an Unspec, which still has no http:/dbpedia etc - if(h.getType().contains("PROPERTY") || (h.getType().contains("UNSPEC")&& !h.getUri().contains("http"))){ + //if(h.getType().contains("PROPERTY") || (h.getType().contains("UNSPEC")&& !h.getUri().contains("http"))){ + if(h.getType().contains("PROPERTY")){ ArrayList<String> result= new ArrayList<String>(); try { if(hm.containsKey(h.getUri().toLowerCase())){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-03-15 03:22:39
|
Revision: 3613 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3613&view=rev Author: shadowtm Date: 2012-03-15 03:22:33 +0000 (Thu, 15 Mar 2012) Log Message: ----------- Updated OWLManager instantiation so that it would use a separate OWLDataFactory per thread rather than the shared static one - this could cause problems in a multithreaded environment. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-15 03:17:12 UTC (rev 3612) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-15 03:22:33 UTC (rev 3613) @@ -45,6 +45,7 @@ import org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat; import org.springframework.beans.propertyeditors.StringTrimmerEditor; import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasonerFactory; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import java.io.File; import java.net.URI; @@ -130,8 +131,8 @@ stringDatatypeProperties = new TreeSet<DatatypeProperty>(); individuals = new TreeSet<Individual>(); - // create OWL API ontology manager - manager = OWLManager.createOWLOntologyManager(); + // create OWL API ontology manager - make sure we use a new data factory so that we don't default to the static one which can cause problems in a multi threaded environment. + manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); // it is a bit cumbersome to obtain all classes, because there // are no reasoner queries to obtain them => hence we query them This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-03-15 03:17:19
|
Revision: 3612 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3612&view=rev Author: shadowtm Date: 2012-03-15 03:17:12 +0000 (Thu, 15 Mar 2012) Log Message: ----------- Updated SparqlKnowledgeSource and SparqlSimpleExtractor to implement the OWLOntologyKnowledgeSource interface in clean up the code within the reasoners. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java Added Paths: ----------- trunk/components-core/src/test/java/org/dllearner/kb/sparql/ trunk/components-core/src/test/java/org/dllearner/kb/sparql/SparqlKnowledgeSourceTest.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlKnowledgeSource.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -47,6 +47,7 @@ import org.dllearner.core.options.StringTupleListConfigOption; import org.dllearner.core.options.URLConfigOption; import org.dllearner.core.owl.KB; +import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.aquisitors.SparqlTupleAquisitor; import org.dllearner.kb.aquisitors.SparqlTupleAquisitorImproved; import org.dllearner.kb.aquisitors.TupleAquisitor; @@ -60,11 +61,14 @@ import org.dllearner.utilities.Files; import org.dllearner.utilities.JamonMonitorLogger; import org.dllearner.utilities.datastructures.StringTuple; +import org.dllearner.utilities.owl.OntologyToByteConverter; +import org.dllearner.utilities.owl.SimpleOntologyToByteConverter; import org.dllearner.utilities.statistics.SimpleClock; import org.semanticweb.owlapi.model.OWLOntology; import com.jamonapi.Monitor; import com.jamonapi.MonitorFactory; +import org.semanticweb.owlapi.model.OWLOntologyManager; /** * Represents the SPARQL Endpoint Component. @@ -74,12 +78,14 @@ * @author Sebastian Hellmann */ @ComponentAnn(name = "SPARQL endpoint fragment", shortName = "sparqlfrag", version = 0.5) -public class SparqlKnowledgeSource extends AbstractKnowledgeSource { +public class SparqlKnowledgeSource extends AbstractKnowledgeSource implements OWLOntologyKnowledgeSource{ private ProgressMonitor mon; private static final boolean debugExitAfterExtraction = false; // switches + private byte[] ontologyBytes; + private OntologyToByteConverter converter = new SimpleOntologyToByteConverter(); // private SparqlKnowledgeSourceConfigurator configurator; @@ -107,7 +113,6 @@ private URL ontologyFragmentURL; - private OWLOntology fragment; private Manipulator manipulator = null; @@ -337,9 +342,10 @@ }*/ extractionTime.stop(); - - fragment = m.getOWLAPIOntologyForNodes(seedNodes, saveExtractedFragment); - + // Do this so that we can support the OWLOntologyKnowledgeSource + // and can be thread safe. + OWLOntology fragment = m.getOWLAPIOntologyForNodes(seedNodes, saveExtractedFragment); + ontologyBytes = getConverter().convert(fragment); logger.info("Finished collecting fragment. needed "+extractionTime.getLastValue()+" ms"); @@ -362,8 +368,13 @@ System.exit(0); } } - - public List<Node> extractParallel(){ + + @Override + public OWLOntology createOWLOntology(OWLOntologyManager manager) { + return getConverter().convert(ontologyBytes, manager); + } + + public List<Node> extractParallel(){ return null; } @@ -537,10 +548,6 @@ return ontologyFragmentURL; } - public OWLOntology getOWLAPIOntology() { - return fragment; - } - public boolean isUseCache() { return useCache; } @@ -733,6 +740,39 @@ this.cacheDir = cacheDir; } - + /** + * Get the OntologyToByteConverter associated with this object. + * + * @return The OntologyToByteConverter associated with this object. + */ + public OntologyToByteConverter getConverter() { + return converter; + } + /** + * Set the OntologyToByteConverter associated with this object. + * + * @param converter the OntologyToByteConverter to associate with this object. + */ + public void setConverter(OntologyToByteConverter converter) { + this.converter = converter; + } + + /** + * Accessor for getting the Ontology Bytes + * + * @return Get the underlying ontology bytes. + */ + byte[] getOntologyBytes() { + return ontologyBytes; + } + + /** + * Set the ontology bytes. + * + * @param ontologyBytes The byte array representation of the fragment. + */ + void setOntologyBytes(byte[] ontologyBytes) { + this.ontologyBytes = ontologyBytes; + } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -6,9 +6,12 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.config.ConfigOption; +import org.dllearner.kb.OWLOntologyKnowledgeSource; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; @ComponentAnn(name="efficient SPARQL fragment extractor", shortName="sparqls", version=0.1) -public class SparqlSimpleExtractor implements KnowledgeSource { +public class SparqlSimpleExtractor implements KnowledgeSource, OWLOntologyKnowledgeSource { @ConfigOption(name="endpointURL", description="URL of the SPARQL endpoint", required=true) private URL endpointURL = null; @@ -38,5 +41,10 @@ public void setEndpointURL(URL endpointURL) { this.endpointURL = endpointURL; } - + + @Override + public OWLOntology createOWLOntology(OWLOntologyManager manager) { + //TODO Update this to return an ontology representation of what the reasoners should work with. Build with the passed in manager instance. + return null; + } } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -161,14 +161,6 @@ if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof SparqlSimpleExtractor || source instanceof OWLAPIOntology) { - if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } else if(source instanceof SparqlSimpleExtractor) { - // TODO - } - directImports.addAll(ontology.getImportsDeclarations()); try { // imports includes the ontology itself Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -209,13 +209,6 @@ || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source) - .getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } - // imports includes the ontology itself Set<OWLOntology> imports = manager .getImportsClosure(ontology); @@ -477,12 +470,6 @@ || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } - // imports includes the ontology itself Set<OWLOntology> imports = manager .getImportsClosure(ontology); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -258,12 +258,6 @@ || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } - classes.addAll(ontology.getClassesInSignature(true)); owlObjectProperties.addAll(ontology.getObjectPropertiesInSignature(true)); owlDatatypeProperties.addAll(ontology.getDataPropertiesInSignature(true)); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -253,12 +253,6 @@ if(source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } - // imports includes the ontology itself Set<OWLOntology> imports = manager.getImportsClosure(ontology); allImports.addAll(imports); Added: trunk/components-core/src/test/java/org/dllearner/kb/sparql/SparqlKnowledgeSourceTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/kb/sparql/SparqlKnowledgeSourceTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/kb/sparql/SparqlKnowledgeSourceTest.java 2012-03-15 03:17:12 UTC (rev 3612) @@ -0,0 +1,53 @@ +package org.dllearner.kb.sparql; + +import org.dllearner.utilities.owl.SimpleOntologyToByteConverter; +import org.junit.Test; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/14/12 + * Time: 9:02 PM + * + * Basic test to test some components of the SparqlKnowledgeSource + */ +public class SparqlKnowledgeSourceTest { + + private OWLOntology createOntology() throws OWLOntologyCreationException, IOException { + // Set up the ontology here and hide its manager - the test needs to use a different ontology manager on reconstitution + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + Resource owlFile = new ClassPathResource("/org/dllearner/kb/owl-api-ontology-data.owl"); + return manager.loadOntologyFromOntologyDocument(owlFile.getInputStream()); + } + + + @Test + public void testMethods() throws Exception { + OWLOntology ontology = createOntology(); + assertNotNull(ontology); + + SparqlKnowledgeSource testSubject = new SparqlKnowledgeSource(); + testSubject.setOntologyBytes(new SimpleOntologyToByteConverter().convert(ontology)); + + OWLOntology result = testSubject.createOWLOntology(OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl())); + + assertNotNull(result); + assertNotSame(ontology,result); + + // Basic Equality Check - for some reason axiom count is different - the result looks more complete than the original. + assertEquals(ontology.getIndividualsInSignature().size(), result.getIndividualsInSignature().size()); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-03-15 02:34:14
|
Revision: 3611 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3611&view=rev Author: shadowtm Date: 2012-03-15 02:34:07 +0000 (Thu, 15 Mar 2012) Log Message: ----------- Added support of the OWLAPIOntology to implement the OWLOntologyKnowledgeSource interface to provide thread safe access to its underlying ontology. Also added a convenience class in support of this which can convert an OWL Ontology to a byte array and back again. Using this we can ensure disconnection occurs from OWL Ontology Managers. Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/OWLAPIOntology.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyToByteConverter.java trunk/components-core/src/main/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverter.java trunk/components-core/src/test/java/org/dllearner/kb/ trunk/components-core/src/test/java/org/dllearner/kb/OWLAPIOntologyTest.java trunk/components-core/src/test/java/org/dllearner/utilities/ trunk/components-core/src/test/java/org/dllearner/utilities/owl/ trunk/components-core/src/test/java/org/dllearner/utilities/owl/OntologyToByteConverterTest.java trunk/components-core/src/test/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverterTest.java trunk/components-core/src/test/resources/org/ trunk/components-core/src/test/resources/org/dllearner/ trunk/components-core/src/test/resources/org/dllearner/kb/ trunk/components-core/src/test/resources/org/dllearner/kb/owl-api-ontology-data.owl trunk/components-core/src/test/resources/org/dllearner/utilities/ trunk/components-core/src/test/resources/org/dllearner/utilities/owl/ trunk/components-core/src/test/resources/org/dllearner/utilities/owl/byte-conversion-data.owl Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLAPIOntology.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLAPIOntology.java 2012-03-14 17:27:16 UTC (rev 3610) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLAPIOntology.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -21,57 +21,45 @@ import java.io.File; import java.net.URI; -import java.util.Iterator; -import java.util.Set; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.OntologyFormat; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.InvalidConfigOptionValueException; import org.dllearner.core.owl.KB; -import org.semanticweb.owlapi.model.OWLClass; -import org.semanticweb.owlapi.model.OWLDataProperty; -import org.semanticweb.owlapi.model.OWLNamedIndividual; -import org.semanticweb.owlapi.model.OWLObjectProperty; -import org.semanticweb.owlapi.model.OWLOntology; +import org.dllearner.utilities.owl.OntologyToByteConverter; +import org.dllearner.utilities.owl.SimpleOntologyToByteConverter; +import org.semanticweb.owlapi.model.*; -public class OWLAPIOntology extends AbstractKnowledgeSource { +/** + * This class provides a wrapper around a single OWL Ontology. However, due to threading issues it is not safe + * to allow access to ontologies created with an Ontology Manager which we do not control. + */ +public class OWLAPIOntology extends AbstractKnowledgeSource implements OWLOntologyKnowledgeSource{ - private OWLOntology ontology; - private Set<OWLOntology> ontologies; - private Set<OWLClass> classes; - private Set<OWLObjectProperty> prop; - private Set<OWLDataProperty> dataProp; - private Set<OWLNamedIndividual> individuals; + private byte[] ontologyBytes; + private OntologyToByteConverter converter = new SimpleOntologyToByteConverter(); + - public OWLAPIOntology() { - this(null); - } + public OWLAPIOntology(OWLOntology onto) { + ontologyBytes = converter.convert(onto); + } - public OWLAPIOntology(OWLOntology onto) - { - this.ontology = onto; - classes = ontology.getClassesInSignature(); - prop = ontology.getObjectPropertiesInSignature(); - dataProp = ontology.getDataPropertiesInSignature(); - individuals = ontology.getIndividualsInSignature(); - } - public static String getName() { return "OWL API Ontology"; } - - @Override + + @Override + public OWLOntology createOWLOntology(OWLOntologyManager manager) { + return converter.convert(ontologyBytes, manager); + } + + @Override public <T> void applyConfigEntry(ConfigEntry<T> entry) throws InvalidConfigOptionValueException { } - public OWLOntology getOWLOntolgy() - { - return ontology; - } - @Override public KB toKB() { @@ -95,45 +83,22 @@ { return null; } - - public void setOWLOntologies(Set<OWLOntology> onto) { - ontologies = onto; - System.out.println("ONTO: " + ontologies); - Iterator<OWLOntology> it = ontologies.iterator(); - while(it.hasNext()) { - OWLOntology ont = it.next(); - if(ont.getClassesInSignature() != null) { - classes.addAll(ont.getClassesInSignature()); - } - if(ont.getObjectPropertiesInSignature() != null) { - prop.addAll(ont.getObjectPropertiesInSignature()); - } - if(ont.getDataPropertiesInSignature() != null) { - dataProp.addAll(ont.getDataPropertiesInSignature()); - } - if(ont.getIndividualsInSignature() != null) { - individuals.addAll(ont.getIndividualsInSignature()); - } - } - } - - public Set<OWLOntology> getOWLOnntologies() { - return ontologies; - } - - public Set<OWLClass> getOWLClasses() { - return classes; - } - - public Set<OWLObjectProperty> getOWLObjectProperies() { - return prop; - } - - public Set<OWLDataProperty> getOWLDataProperies() { - return dataProp; - } - - public Set<OWLNamedIndividual> getOWLIndividuals() { - return individuals; - } + + /** + * Get the OntologyToByteConverter associated with this object. + * + * @return The OntologyToByteConverter associated with this object. + */ + public OntologyToByteConverter getConverter() { + return converter; + } + + /** + * Set the OntologyToByteConverter associated with this object. + * + * @param converter the OntologyToByteConverter to associate with this object. + */ + public void setConverter(OntologyToByteConverter converter) { + this.converter = converter; + } } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-14 17:27:16 UTC (rev 3610) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -161,11 +161,7 @@ if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof SparqlSimpleExtractor || source instanceof OWLAPIOntology) { - if (source instanceof OWLAPIOntology) { - ontology = ((OWLAPIOntology) source).getOWLOntolgy(); - manager = ontology.getOWLOntologyManager(); - owlAPIOntologies.add(ontology); - } else if (source instanceof SparqlKnowledgeSource) { + if (source instanceof SparqlKnowledgeSource) { ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); manager = ontology.getOWLOntologyManager(); owlAPIOntologies.add(ontology); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-14 17:27:16 UTC (rev 3610) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/PelletReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -22,7 +22,6 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -78,6 +77,7 @@ import org.dllearner.core.owl.UntypedConstant; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; @@ -200,35 +200,30 @@ for (AbstractKnowledgeSource source : sources) { + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + } + if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - URL url = null; - if (source instanceof OWLFile) { - url = ((OWLFile) source).getURL(); - } -// try { + if (source instanceof SparqlKnowledgeSource) { + ontology = ((SparqlKnowledgeSource) source) + .getOWLAPIOntology(); + manager = ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); + } - if (source instanceof OWLAPIOntology) { - ontology = ((OWLAPIOntology) source).getOWLOntolgy(); - manager = ontology.getOWLOntologyManager(); - } else if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source) - .getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - } else { - ontology = manager.loadOntologyFromOntologyDocument(IRI.create(url)); - } - - owlAPIOntologies.add(ontology); - // imports includes the ontology itself - Set<OWLOntology> imports = manager - .getImportsClosure(ontology); - allImports.addAll(imports); - loadedOntologies.addAll(imports); - // System.out.println(imports); - classes.addAll(ontology.getClassesInSignature(true)); + // imports includes the ontology itself + Set<OWLOntology> imports = manager + .getImportsClosure(ontology); + allImports.addAll(imports); + loadedOntologies.addAll(imports); + + // System.out.println(imports); + classes.addAll(ontology.getClassesInSignature(true)); owlObjectProperties.addAll(ontology.getObjectPropertiesInSignature(true)); owlDatatypeProperties.addAll(ontology.getDataPropertiesInSignature(true)); owlIndividuals.addAll(ontology.getIndividualsInSignature(true)); @@ -474,42 +469,26 @@ for (AbstractKnowledgeSource source : sources) { + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + } if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - URL url = null; - if (source instanceof OWLFile) { - url = ((OWLFile) source).getURL(); - } -// try { + if (source instanceof SparqlKnowledgeSource) { + ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); + manager = ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); + } - if (source instanceof OWLAPIOntology) { - ontology = ((OWLAPIOntology) source).getOWLOntolgy(); - manager = ontology.getOWLOntologyManager(); - } else if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - } else { - try { - ontology = manager.loadOntologyFromOntologyDocument(IRI.create(url - .toURI())); - } catch (OWLOntologyCreationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - owlAPIOntologies.add(ontology); - // imports includes the ontology itself - Set<OWLOntology> imports = manager - .getImportsClosure(ontology); - allImports.addAll(imports); - loadedOntologies.addAll(imports); - // System.out.println(imports); + // imports includes the ontology itself + Set<OWLOntology> imports = manager + .getImportsClosure(ontology); + allImports.addAll(imports); + loadedOntologies.addAll(imports); + // System.out.println(imports); classes.addAll(ontology.getClassesInSignature(true)); owlObjectProperties.addAll(ontology.getObjectPropertiesInSignature(true)); owlDatatypeProperties.addAll(ontology.getDataPropertiesInSignature(true)); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-14 17:27:16 UTC (rev 3610) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/ProtegeReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -20,8 +20,6 @@ package org.dllearner.reasoning; import java.io.File; -import java.net.URISyntaxException; -import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -73,6 +71,7 @@ import org.dllearner.core.owl.UntypedConstant; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.utilities.Helper; import org.dllearner.utilities.owl.ConceptComparator; @@ -250,36 +249,22 @@ for (AbstractKnowledgeSource source : sources) { + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + } + if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - URL url = null; - if (source instanceof OWLFile) { - url = ((OWLFile) source).getURL(); - } -// try { + if (source instanceof SparqlKnowledgeSource) { + ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); + manager = ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); + } - if (source instanceof OWLAPIOntology) { - ontology = ((OWLAPIOntology) source).getOWLOntolgy(); - } else if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - } else { - try { - ontology = manager.loadOntologyFromOntologyDocument(IRI.create(url - .toURI())); - } catch (OWLOntologyCreationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - owlAPIOntologies.add(ontology); - classes.addAll(ontology.getClassesInSignature(true)); + classes.addAll(ontology.getClassesInSignature(true)); owlObjectProperties.addAll(ontology.getObjectPropertiesInSignature(true)); owlDatatypeProperties.addAll(ontology.getDataPropertiesInSignature(true)); owlIndividuals.addAll(ontology.getIndividualsInSignature(true)); Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-14 17:27:16 UTC (rev 3610) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/fuzzydll/FuzzyOWLAPIReasoner.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -22,7 +22,6 @@ import java.io.File; import java.net.MalformedURLException; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.util.Collection; import java.util.Collections; @@ -66,6 +65,7 @@ import org.dllearner.core.owl.fuzzydll.FuzzyIndividual; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; +import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.reasoning.ReasonerType; import org.dllearner.utilities.owl.ConceptComparator; @@ -74,7 +74,6 @@ import org.dllearner.utilities.owl.OWLAPIConverter; import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.dllearner.utilities.owl.RoleComparator; -import org.semanticweb.HermiT.Reasoner.ReasonerFactory; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AddAxiom; import org.semanticweb.owlapi.model.IRI; @@ -246,53 +245,43 @@ prefixes = new TreeMap<String,String>(); for(AbstractKnowledgeSource source : sources) { - + + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + } + if(source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - URL url=null; - if(source instanceof OWLFile){ - url = ((OWLFile)source).getURL(); - } - try { - - if(source instanceof OWLAPIOntology) { - ontology = ((OWLAPIOntology)source).getOWLOntolgy(); - } else if (source instanceof SparqlKnowledgeSource) { - ontology = ((SparqlKnowledgeSource)source).getOWLAPIOntology(); - manager = ontology.getOWLOntologyManager(); - } else { - ontology = manager.loadOntologyFromOntologyDocument(IRI.create(url.toURI())); - } - - owlAPIOntologies.add(ontology); - // imports includes the ontology itself - Set<OWLOntology> imports = manager.getImportsClosure(ontology); - allImports.addAll(imports); + if (source instanceof SparqlKnowledgeSource) { + ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); + manager = ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); + } + + // imports includes the ontology itself + Set<OWLOntology> imports = manager.getImportsClosure(ontology); + allImports.addAll(imports); // System.out.println(imports); - for(OWLOntology ont : imports) { - classes.addAll(ont.getClassesInSignature()); - owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); - owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); - owlIndividuals.addAll(ont.getIndividualsInSignature()); - } - - // if several knowledge sources are included, then we can only - // guarantee that the base URI is from one of those sources (there - // can't be more than one); but we will take care that all prefixes are - // correctly imported - OWLOntologyFormat format = manager.getOntologyFormat(ontology); - if(format instanceof PrefixOWLOntologyFormat) { - prefixes.putAll(((PrefixOWLOntologyFormat)format).getPrefixName2PrefixMap()); - baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); - prefixes.remove(""); - } - - } catch (OWLOntologyCreationException e) { - e.printStackTrace(); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - // all other sources are converted to KB and then to an + for (OWLOntology ont : imports) { + classes.addAll(ont.getClassesInSignature()); + owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); + owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); + owlIndividuals.addAll(ont.getIndividualsInSignature()); + } + + // if several knowledge sources are included, then we can only + // guarantee that the base URI is from one of those sources (there + // can't be more than one); but we will take care that all prefixes are + // correctly imported + OWLOntologyFormat format = manager.getOntologyFormat(ontology); + if (format instanceof PrefixOWLOntologyFormat) { + prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); + baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); + prefixes.remove(""); + } + + // all other sources are converted to KB and then to an // OWL API ontology } else { KB kb = source.toKB(); Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyToByteConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyToByteConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/OntologyToByteConverter.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,37 @@ +package org.dllearner.utilities.owl; + +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/14/12 + * Time: 7:30 PM + * <p/> + * Interface to allow the conversion of an OWL Ontology into a byte array and back. + * <p/> + * The purpose of the interface is to allow the association of an OWLOntology object with a specified OWLOntologyManager. + * <p/> + * If someone hands us an OWLOntology, we may not want to use the associated OWLOntologyManager. Rather, we can serialize it out + * to a byte array and then read it back in with a different OWLOntologyManager. + */ +public interface OntologyToByteConverter { + + /** + * Convert the ontology into a byte array. + * + * @param ontology The ontology to convert to a byte array. + * @return The byte array representing the ontology + */ + byte[] convert(OWLOntology ontology); + + /** + * Convert bytes into an Ontology registered with manager. + * + * @param bytes The bytes to convert to an OWLOntology + * @param manager The Ontology Manager to load the ontology with. + * @return The ontology derived from bytes. + */ + OWLOntology convert(byte[] bytes, OWLOntologyManager manager); +} Added: trunk/components-core/src/main/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverter.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverter.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverter.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,55 @@ +package org.dllearner.utilities.owl; + +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 java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/13/12 + * Time: 6:24 PM + * + * A Byte Array based implementation of the OntologyToByteConverter interface. + */ +public class SimpleOntologyToByteConverter implements OntologyToByteConverter { + + @Override + public byte[] convert(OWLOntology ontology) { + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + OWLOntologyManager manager = ontology.getOWLOntologyManager(); + try { + manager.saveOntology(ontology,baos); + baos.close(); + } catch (OWLOntologyStorageException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return baos.toByteArray(); + } + + @Override + public OWLOntology convert(byte[] bytes, OWLOntologyManager manager) { + + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + + try { + OWLOntology ontology = manager.loadOntologyFromOntologyDocument(bais); + bais.close(); + return ontology; + } catch (OWLOntologyCreationException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} Added: trunk/components-core/src/test/java/org/dllearner/kb/OWLAPIOntologyTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/kb/OWLAPIOntologyTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/kb/OWLAPIOntologyTest.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,47 @@ +package org.dllearner.kb; + +import org.junit.Test; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import java.io.IOException; + +import static org.junit.Assert.*; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/14/12 + * Time: 7:57 PM + */ +public class OWLAPIOntologyTest { + + private OWLOntology createOntology() throws OWLOntologyCreationException, IOException { + // Set up the ontology here and hide its manager - the test needs to use a different ontology manager on reconstitution + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + Resource owlFile = new ClassPathResource("/org/dllearner/kb/owl-api-ontology-data.owl"); + return manager.loadOntologyFromOntologyDocument(owlFile.getInputStream()); + } + + + @Test + public void testMethods() throws Exception { + OWLOntology ontology = createOntology(); + assertNotNull(ontology); + + OWLAPIOntology testSubject = new OWLAPIOntology(ontology); + + OWLOntology result = testSubject.createOWLOntology(OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl())); + + assertNotNull(result); + assertNotSame(ontology,result); + + // Basic Equality Check - for some reason axiom count is different - the result looks more complete than the original. + assertEquals(ontology.getIndividualsInSignature().size(), result.getIndividualsInSignature().size()); + } +} Added: trunk/components-core/src/test/java/org/dllearner/utilities/owl/OntologyToByteConverterTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/utilities/owl/OntologyToByteConverterTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/utilities/owl/OntologyToByteConverterTest.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,56 @@ +package org.dllearner.utilities.owl; + +import org.junit.Test; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/14/12 + * Time: 7:29 PM + * + * Test the interface level apis for the ontology to byte converter. + */ +public abstract class OntologyToByteConverterTest { + + public abstract OntologyToByteConverter getInstance(); + + private OWLOntology createOntology() throws OWLOntologyCreationException, IOException { + // Set up the ontology here and hide its manager - the test needs to use a different ontology manager on reconstitution + OWLOntologyManager manager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + Resource owlFile = new ClassPathResource("/org/dllearner/utilities/owl/byte-conversion-data.owl"); + return manager.loadOntologyFromOntologyDocument(owlFile.getInputStream()); + } + + @Test + public void testConversion() throws Exception { + OntologyToByteConverter converter = getInstance(); + OWLOntology ontology = createOntology(); + assertNotNull(ontology); + + byte[] bytes = converter.convert(ontology); + + assertNotNull(bytes); + assertTrue(bytes.length > 0); + + // Use a new manager so that the IRIs don't get messed up + OWLOntologyManager newManager = OWLManager.createOWLOntologyManager(new OWLDataFactoryImpl()); + OWLOntology result = converter.convert(bytes, newManager); + assertNotNull(result); + + // Basic Equality Check - for some reason axiom count is different - the result looks more complete than the original. + assertEquals(ontology.getIndividualsInSignature().size(), result.getIndividualsInSignature().size()); + } +} Added: trunk/components-core/src/test/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverterTest.java =================================================================== --- trunk/components-core/src/test/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverterTest.java (rev 0) +++ trunk/components-core/src/test/java/org/dllearner/utilities/owl/SimpleOntologyToByteConverterTest.java 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,17 @@ +package org.dllearner.utilities.owl; + +/** + * Created by IntelliJ IDEA. + * User: Chris Shellenbarger + * Date: 3/13/12 + * Time: 6:28 PM + * + * Test instance for a particular implementation. + */ +public class SimpleOntologyToByteConverterTest extends OntologyToByteConverterTest{ + + @Override + public OntologyToByteConverter getInstance() { + return new SimpleOntologyToByteConverter(); + } +} Added: trunk/components-core/src/test/resources/org/dllearner/kb/owl-api-ontology-data.owl =================================================================== --- trunk/components-core/src/test/resources/org/dllearner/kb/owl-api-ontology-data.owl (rev 0) +++ trunk/components-core/src/test/resources/org/dllearner/kb/owl-api-ontology-data.owl 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns="http://example.com/father#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xml:base="http://example.com/father"> + <owl:Ontology rdf:about=""/> + <owl:Class rdf:ID="female"/> + <owl:Class rdf:ID="male"> + <owl:equivalentClass> + <owl:Class> + <owl:complementOf rdf:resource="#female"/> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + <owl:ObjectProperty rdf:ID="hasChild"/> + <male rdf:ID="markus"> + <hasChild> + <female rdf:ID="anna"> + <hasChild> + <male rdf:ID="heinz"/> + </hasChild> + </female> + </hasChild> + </male> + <male rdf:ID="stefan"> + <hasChild rdf:resource="#markus"/> + </male> + <female rdf:ID="michelle"/> + <male rdf:ID="martin"> + <hasChild rdf:resource="#heinz"/> + </male> +</rdf:RDF> Added: trunk/components-core/src/test/resources/org/dllearner/utilities/owl/byte-conversion-data.owl =================================================================== --- trunk/components-core/src/test/resources/org/dllearner/utilities/owl/byte-conversion-data.owl (rev 0) +++ trunk/components-core/src/test/resources/org/dllearner/utilities/owl/byte-conversion-data.owl 2012-03-15 02:34:07 UTC (rev 3611) @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<rdf:RDF + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:xsd="http://www.w3.org/2001/XMLSchema#" + xmlns="http://example.com/father#" + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" + xmlns:owl="http://www.w3.org/2002/07/owl#" + xml:base="http://example.com/father"> + <owl:Ontology rdf:about=""/> + <owl:Class rdf:ID="female"/> + <owl:Class rdf:ID="male"> + <owl:equivalentClass> + <owl:Class> + <owl:complementOf rdf:resource="#female"/> + </owl:Class> + </owl:equivalentClass> + </owl:Class> + <owl:ObjectProperty rdf:ID="hasChild"/> + <male rdf:ID="markus"> + <hasChild> + <female rdf:ID="anna"> + <hasChild> + <male rdf:ID="heinz"/> + </hasChild> + </female> + </hasChild> + </male> + <male rdf:ID="stefan"> + <hasChild rdf:resource="#markus"/> + </male> + <female rdf:ID="michelle"/> + <male rdf:ID="martin"> + <hasChild rdf:resource="#heinz"/> + </male> +</rdf:RDF> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <seb...@us...> - 2012-03-14 17:27:24
|
Revision: 3610 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3610&view=rev Author: sebastianwtr Date: 2012-03-14 17:27:16 +0000 (Wed, 14 Mar 2012) Log Message: ----------- [tbsl exploration] added some functions Modified Paths: -------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.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/TemplateBuilder.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java Removed Paths: ------------- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/Index_utils.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -50,7 +50,113 @@ return result_List; } + + +public static ArrayList<String> searchIndexForResource(String string, SQLiteIndex myindex) throws SQLException{ + + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String result=null; + ArrayList<String> result_List = new ArrayList<String>(); + result=myindex.getResourceURI(string.toLowerCase()); + if(result!=null){ + result_List.add(result); + } + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getResourceURILike(s.toLowerCase(), string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + return result_List; + } + +public static ArrayList<String> searchIndexForProperty(String string, SQLiteIndex myindex) throws SQLException{ + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String result=null; + ArrayList<String> result_List = new ArrayList<String>(); + result=myindex.getPropertyURI(string.toLowerCase()); + if(result!=null){ + result_List.add(result); + } + else{ + result_List.add("http://dbpedia.org/ontology/"+string.toLowerCase().replace(" ", "_")); + } + + + + return result_List; } + + + +public static ArrayList<String> searchIndexForClass(String string, SQLiteIndex myindex) throws SQLException{ + + /* + * TODO: also return a rank, if you find a direct match, give back 1, if you find a part match, give back for example 0.3 if you have a string you can split in 3 + */ + string=string.replace("_", " "); + string=string.replace("-", " "); + string=string.replace(".", " "); + String tmp1=null; + String tmp2 = null; + ArrayList<String> result_List = new ArrayList<String>(); + + tmp1=myindex.getontologyClassURI(string.toLowerCase()); + tmp2=myindex.getYagoURI(string.toLowerCase()); + if(tmp1!=null){ + result_List.add(tmp1); + } + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getontologyClassURILike(s.toLowerCase(),string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + if(tmp2!=null) { + result_List.add(tmp2); + } + /* + * if nothing is found, also try the like operator for each part of the string + */ + else{ + ArrayList<String> tmp_List = new ArrayList<String>(); + String[] array_tmp= string.split(" "); + for(String s : array_tmp){ + if(s.length()>4) tmp_List=myindex.getYagoURILike(s.toLowerCase(),string.toLowerCase()); + for(String st : tmp_List){ + result_List.add(st); + } + } + + } + + + + return result_List; + } + + + + +} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Index/SQLiteIndex.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -13,11 +13,13 @@ import java.sql.Statement; import java.util.ArrayList; +import org.dllearner.algorithm.tbsl.exploration.Utils.Levenshtein; import org.dllearner.algorithm.tbsl.nlp.StanfordLemmatizer; public class SQLiteIndex { private Connection conn; StanfordLemmatizer lemma; + double lim_levensthein=0.84; public SQLiteIndex() throws ClassNotFoundException, SQLException { // TODO Auto-generated constructor stub @@ -63,17 +65,20 @@ } - public ArrayList<String> getResourceURILike(String string) throws SQLException{ + public ArrayList<String> getResourceURILike(String string, String original_string) throws SQLException{ /* while(rs.next()) {*/ Statement stat = conn.createStatement(); ResultSet rs; ArrayList<String> result= new ArrayList<String>(); try { - rs = stat.executeQuery("select uri from resource where name like'"+string.toLowerCase()+"%';"); + rs = stat.executeQuery("select * from resource where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { @@ -84,17 +89,21 @@ } - public ArrayList<String> getYagoURILike(String string) throws SQLException{ + public ArrayList<String> getYagoURILike(String string, String original_string) throws SQLException{ /* while(rs.next()) {*/ Statement stat = conn.createStatement(); ResultSet rs; ArrayList<String> result= new ArrayList<String>(); try { - rs = stat.executeQuery("select uri from yago where name like'"+string.toLowerCase()+"%';"); + rs = stat.executeQuery("select * from yago where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + //System.out.println("Next: "+rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { @@ -167,15 +176,18 @@ } - public ArrayList<String> getontologyClassURILike(String string) throws SQLException{ + public ArrayList<String> getontologyClassURILike(String string, String original_string) throws SQLException{ Statement stat = conn.createStatement(); ResultSet rs; ArrayList<String> result= new ArrayList<String>(); try { - rs = stat.executeQuery("select uri from ontologyClass where name like'"+string.toLowerCase()+"%';"); + rs = stat.executeQuery("select * from ontologyClass where name like'"+string.toLowerCase()+"%';"); while(rs.next()){ - System.out.println("Next: "+rs.getString("uri")); - result.add(rs.getString("uri")); + if(Levenshtein.nld(rs.getString("name"), original_string)>lim_levensthein){ + result.add(rs.getString("uri")); + System.out.print(rs.getString("name")); + System.out.print(" "+rs.getString("uri")+"\n"); + } } return result; } catch (Exception e) { Modified: 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 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/Hypothesis.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,6 +1,5 @@ package org.dllearner.algorithm.tbsl.exploration.Sparql; -import edu.stanford.nlp.io.EncodingPrintWriter.out; public class Hypothesis { private String variable; 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-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/SparqlObject.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1780,7 +1780,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getResourceURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getResourceURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ @@ -1830,7 +1830,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getontologyClassURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getontologyClassURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ @@ -1866,7 +1866,7 @@ /* * Third try lemmatised with like */ - ArrayList<String> tmp=myindex.getYagoURILike(lemmatiser.stem(string.toLowerCase())); + ArrayList<String> tmp=myindex.getYagoURILike(lemmatiser.stem(string.toLowerCase()),string); double highestNLD=0; String bestWord=""; try{ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Sparql/TemplateBuilder.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -161,7 +161,10 @@ */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Template template = new Template(condition, having, filter, selectTerm,OrderBy, limit,question); - //TODO: Iterate over slots + + boolean add_reverse_template = true; + + ArrayList<Hypothesis> list_of_hypothesis = new ArrayList<Hypothesis>(); for(Slot slot : bqt.getSlots()){ //System.out.println("Slot: "+slot.toString()); @@ -169,9 +172,26 @@ String tmp= slot.toString().replace(" UNSPEC {", ""); tmp=tmp.replace("}",""); String[] tmp_array = tmp.split(":"); - Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "UNSPEC", 0); - //tmp_hypothesis.printAll(); - list_of_hypothesis.add(tmp_hypothesis); + for(ArrayList<String> x : condition){ + if(x.get(1).equals("isA") && x.get(2).equals("?"+tmp_array[0])){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "ISA", 0); + //tmp_hypothesis.printAll(); + list_of_hypothesis.add(tmp_hypothesis); + + /* + * if you have already found an isA -Class-Pair, you dont have to creat the up-side-down, because it will be false + */ + add_reverse_template = false; + } + /* + * Make sure you dont have the case that a class is left of an isA + */ + else if (!x.get(1).equals("isA") && x.get(0).equals("?"+tmp_array[0])){ + Hypothesis tmp_hypothesis = new Hypothesis("?"+tmp_array[0],tmp_array[1], tmp_array[1], "UNSPEC", 0); + //tmp_hypothesis.printAll(); + list_of_hypothesis.add(tmp_hypothesis); + } + } } if(slot.toString().contains("PROPERTY")){ String tmp= slot.toString().replace(" PROPERTY {", ""); @@ -193,13 +213,18 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for(Hypothesis x : list_of_hypothesis){ - if(x.getType().contains("RESOURCE")|| x.getType().contains("UNSPEC") ){ + /* + * TODO: Change if ISA only ask classes, else resource + */ + if(x.getType().contains("RESOURCE")|| x.getType().contains("UNSPEC")|| x.getType().contains("ISA") ){ ArrayList<String> result= new ArrayList<String>(); try { - /* here I have to check the hypothesis if I have an isA in my Condition, - * if so, only look up Yago and OntologyClass. - */ - result = Index_utils.searchIndex(x.getUri(), 3, myindex); + if(x.getType().contains("ISA")){ + result = Index_utils.searchIndexForClass(x.getUri(), myindex); + } + else{ + result = Index_utils.searchIndexForResource(x.getUri(), myindex); + } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -252,7 +277,7 @@ result.add(hm.get(h.getUri().toLowerCase())); } else{ - result = Index_utils.searchIndex(h.getUri(), 1, myindex); + result = Index_utils.searchIndexForProperty(h.getUri(), myindex); if(!result.isEmpty())hm.put(h.getUri().toLowerCase(),result.get(0)); } if(!result.isEmpty()){ @@ -260,12 +285,12 @@ h.setRank(1); } - else{ + /* else{ String tmp = "http://dbpedia.org/ontology/"+h.getUri().toLowerCase().replace(" ", "_"); h.setUri(tmp); h.setRank(0); - } + }*/ } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -278,18 +303,18 @@ - //TODO: Take Template like it is and change Condition Template template_reverse_conditions = new Template(template.getCondition(), template.getHaving(), template.getFilter(), template.getSelectTerm(), template.getOrderBy(), template.getLimit(), template.getQuestion()); - //= template; ArrayList<ArrayList<String>> condition_template_reverse_conditions = template_reverse_conditions.getCondition(); ArrayList<ArrayList<String>> condition_reverse_new= new ArrayList<ArrayList<String>>(); - for (ArrayList<String> x : condition_template_reverse_conditions){ - ArrayList<String> new_list = new ArrayList<String>(); - new_list.add(x.get(2)); - new_list.add(x.get(1)); - new_list.add(x.get(0)); - condition_reverse_new.add(new_list); + if(add_reverse_template){ + for (ArrayList<String> x : condition_template_reverse_conditions){ + ArrayList<String> new_list = new ArrayList<String>(); + new_list.add(x.get(2)); + new_list.add(x.get(1)); + new_list.add(x.get(0)); + condition_reverse_new.add(new_list); + } } long stop = System.currentTimeMillis(); @@ -303,7 +328,7 @@ template_reverse_conditions.setHypothesen(template.getHypothesen()); resultArrayList.add(template); - resultArrayList.add(template_reverse_conditions); + if(add_reverse_template) resultArrayList.add(template_reverse_conditions); } } /*for(Template temp : resultArrayList){ Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/GetRessourcePropertys.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,18 +1,12 @@ package org.dllearner.algorithm.tbsl.exploration.Utils; import java.io.BufferedReader; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; public class GetRessourcePropertys { Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/Levenshtein.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -2,7 +2,6 @@ import java.lang.Math; -import java.math.BigDecimal; public class Levenshtein { @@ -12,10 +11,8 @@ //System.out double length=Math.max(orig.length(),eing.length()); - //if distance between both is zero, then the NLD must be one - //but because they are equal, return a very high value, so that that query will be taken. if(result==0.0 ){ - return 10.0; + return 1.0; } else{ Deleted: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/Utils/SparqlFilter.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -1,54 +0,0 @@ -package org.dllearner.algorithm.tbsl.exploration.Utils; - -import java.util.HashMap; - -public class SparqlFilter { - public void create_Sparql_who(String string,HashMap<String, String> hm){ - // string=string.replaceAll("?", ""); - String[] array= string.split(" "); - //schauen ob erstes Wort ein who ist! - if(array[0].contains("who")){ - int position=0; - for(int i=0;i<array.length;i++){ - if (array[i].contains("of")){ - position=i; - break; - } - } - String vor_of=array[position-1]; - String nach_of=""; - //wenn nur ein element hinter of kommt - if(array.length-position-1==1){ - nach_of=array[position+1]; - } - else{ - for(int i=position+1; i<array.length;i++){ - //nach_of=nach_of+array[i]+" "; - nach_of=(nach_of.concat(array[i])).concat(" "); - } - - //letztes leerzeichen loeschen - nach_of = nach_of.substring(0, nach_of.length()-1); - } - String uri_vor_of=" "; - String uri_nach_of=" "; - - uri_vor_of=hm.get(vor_of); - uri_nach_of=hm.get(nach_of); - if(uri_vor_of!=null && uri_nach_of!=null){ - uri_nach_of=uri_nach_of.replace("Category:", ""); - uri_nach_of=uri_nach_of.replace("category:", ""); - - - String anfrage=null; - anfrage="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>select ?x where { <"+uri_nach_of+"> <"+uri_vor_of+"> ?x.}"; - - } - else{ - //System.out.println("Nothing to do"); - } - - } - - } -} Modified: trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java =================================================================== --- trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-13 10:19:10 UTC (rev 3609) +++ trunk/components-ext/src/main/java/org/dllearner/algorithm/tbsl/exploration/exploration_main/testClass_new.java 2012-03-14 17:27:16 UTC (rev 3610) @@ -32,38 +32,60 @@ TemplateBuilder testobject = new TemplateBuilder(); - String dateiname = "/home/swalter/Dokumente/Auswertung/"; + String filepath = "/home/swalter/Dokumente/Auswertung/"; + //String file="very_small.xml"; + String file="dbpedia-train.xml"; long start = System.currentTimeMillis(); //String question = "Is the wife of president Obama called Michelle?"; - /*String question = "Which bridges are of the same type as the Manhattan Bridge?"; - temp_list_result=testobject.createTemplates(question);*/ + String question = "Who is the mayor of Berlin?"; + temp_list_result=testobject.createTemplates(question); + for(Template t : temp_list_result){ + t.printAll(); + } ArrayList<queryInformation> list_of_structs = new ArrayList<queryInformation>(); - //if you dont want to use the hints in the questions, use false - list_of_structs=generateStruct(dateiname+"XMLDateien/dbpedia-train_small.xml"); - System.out.println("Start Templating"); + + /* + * Generate Templates + */ + /*list_of_structs=generateStruct(filepath+"XMLDateien/"+file); for(queryInformation s : list_of_structs){ - System.out.println("In For Schleife"); ArrayList<Template> temp_list = new ArrayList<Template>(); temp_list=testobject.createTemplates(s.getQuery().replace("<[CDATA[", "").replace("]]>", "")); for(Template t : temp_list){ temp_list_result.add(t); } - } + }*/ + /* + * Get Elements for Each Resource and Class + */ + long stop = System.currentTimeMillis(); System.out.println("Duration in ms: " + (stop - start)); - - String result =""; + + /* + * Write Results in File + */ + writeTemplatesInFile(temp_list_result,filepath,file,start,stop ); + + } + + + private static void writeTemplatesInFile(ArrayList<Template> temp_list_result, String filepath,String given_file, float start, float stop ) throws IOException{ + File file = new File(filepath+"Ausgabe"+stop+given_file.replace(".xml", "")+".txt"); + BufferedWriter bw = new BufferedWriter(new FileWriter(file)); + int anzahl1 =1; for(Template t: temp_list_result){ //t.printAll(); + String result =""; result+="###### Template ######\n"; result+="question: "+t.getQuestion()+"\n"; result+="condition: "+t.getCondition()+"\n"; @@ -91,24 +113,24 @@ result+="Overalltime: "+t.getOverallTime()+"ms\n"; result+="Time for Templator: "+t.getTime_Templator()+"ms\n"; result+="////////////////////////////////////////////////////////////////////\n\n\n"; + bw.write(result+"\n"); + //bw.flush(); + System.out.println("Done "+anzahl1); + anzahl1 +=1; + } - + String result=""; result+="Time over generating All Templates: "+(stop-start)+"ms\n"; result+="Average Time for one Template: "+((stop-start)/temp_list_result.size())+"ms\n"; result+="Overall created Templates: "+temp_list_result.size(); //System.out.println(result); - File file = new File(dateiname+"Ausgabe"+stop+".txt"); - BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(result); bw.flush(); bw.close(); - } - - private static ArrayList<queryInformation> generateStruct(String filename) { System.out.println("In generate Struct"); String XMLType=null; @@ -158,13 +180,13 @@ } ArrayList<queryInformation> querylist = new ArrayList<queryInformation>(); if(string.contains("</question><question")){ - System.out.println("true"); + //System.out.println("true"); } else System.out.println("false"); String [] bla = string.split("</question><question"); - System.out.println(bla.length); + //System.out.println(bla.length); for(String s : bla){ - System.out.println("in bla"); + //System.out.println("in bla"); String query=""; String type=""; boolean fusion=false; @@ -181,7 +203,7 @@ Pattern p2= Pattern.compile(".*><string>(.*)"); Matcher m2 = p2.matcher(m1.group(1)); while(m2.find()){ - System.out.println("Query: "+ m2.group(1)); + //System.out.println("Query: "+ m2.group(1)); query=m2.group(1).replace("<![CDATA[", ""); query=query.replace("CDATA", ""); query=query.replace("CDATA", ""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2012-03-13 10:19:20
|
Revision: 3609 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3609&view=rev Author: jenslehmann Date: 2012-03-13 10:19:10 +0000 (Tue, 13 Mar 2012) Log Message: ----------- started new SPARQL component Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java trunk/scripts/src/main/java/org/dllearner/scripts/OxtractorHelper.java Added Paths: ----------- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java trunk/test/sparql/new_component/ trunk/test/sparql/new_component/AristotlePos.conf Modified: trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-12 04:28:22 UTC (rev 3608) +++ trunk/components-core/src/main/java/org/dllearner/core/AnnComponentManager.java 2012-03-13 10:19:10 UTC (rev 3609) @@ -79,6 +79,7 @@ "org.dllearner.kb.OWLFile", "org.dllearner.kb.SparqlEndpointKS", "org.dllearner.kb.sparql.SparqlKnowledgeSource", + "org.dllearner.kb.sparql.SparqlSimpleExtractor", "org.dllearner.learningproblems.PosNegLPStandard", "org.dllearner.learningproblems.FuzzyPosNegLPStandard", "org.dllearner.learningproblems.PosOnlyLP", Added: trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java (rev 0) +++ trunk/components-core/src/main/java/org/dllearner/kb/sparql/SparqlSimpleExtractor.java 2012-03-13 10:19:10 UTC (rev 3609) @@ -0,0 +1,42 @@ +package org.dllearner.kb.sparql; + +import java.net.URL; + +import org.dllearner.core.ComponentAnn; +import org.dllearner.core.ComponentInitException; +import org.dllearner.core.KnowledgeSource; +import org.dllearner.core.config.ConfigOption; + +@ComponentAnn(name="efficient SPARQL fragment extractor", shortName="sparqls", version=0.1) +public class SparqlSimpleExtractor implements KnowledgeSource { + + @ConfigOption(name="endpointURL", description="URL of the SPARQL endpoint", required=true) + private URL endpointURL = null; + + public SparqlSimpleExtractor() { + + } + + @Override + public void init() throws ComponentInitException { + // TODO Auto-generated method stub + + } + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + + public URL getEndpointURL() { + return endpointURL; + } + + public void setEndpointURL(URL endpointURL) { + this.endpointURL = endpointURL; + } + +} Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-12 04:28:22 UTC (rev 3608) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-13 10:19:10 UTC (rev 3609) @@ -26,12 +26,14 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.AbstractKnowledgeSource; import org.dllearner.core.AbstractReasonerComponent; +import org.dllearner.core.KnowledgeSource; import org.dllearner.core.config.ConfigOption; import org.dllearner.core.owl.*; import org.dllearner.kb.OWLAPIOntology; import org.dllearner.kb.OWLFile; import org.dllearner.kb.OWLOntologyKnowledgeSource; import org.dllearner.kb.sparql.SparqlKnowledgeSource; +import org.dllearner.kb.sparql.SparqlSimpleExtractor; import org.dllearner.utilities.owl.*; import org.semanticweb.HermiT.Reasoner.ReasonerFactory; import org.semanticweb.owlapi.apibinding.OWLManager; @@ -150,14 +152,14 @@ Set<OWLImportsDeclaration> directImports = new HashSet<OWLImportsDeclaration>(); - for (AbstractKnowledgeSource source : sources) { + for (KnowledgeSource source : sources) { if (source instanceof OWLOntologyKnowledgeSource) { ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); owlAPIOntologies.add(ontology); } - if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { + if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof SparqlSimpleExtractor || source instanceof OWLAPIOntology) { if (source instanceof OWLAPIOntology) { ontology = ((OWLAPIOntology) source).getOWLOntolgy(); @@ -167,6 +169,8 @@ ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); manager = ontology.getOWLOntologyManager(); owlAPIOntologies.add(ontology); + } else if(source instanceof SparqlSimpleExtractor) { + // TODO } directImports.addAll(ontology.getImportsDeclarations()); @@ -204,7 +208,7 @@ } else { //KB Files - KB kb = source.toKB(); + KB kb = ((AbstractKnowledgeSource)source).toKB(); if (!(source instanceof OWLOntologyKnowledgeSource)) { //Not sure if this will ever get hit, but leaving in for backward compatibility. Modified: trunk/scripts/src/main/java/org/dllearner/scripts/OxtractorHelper.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/OxtractorHelper.java 2012-03-12 04:28:22 UTC (rev 3608) +++ trunk/scripts/src/main/java/org/dllearner/scripts/OxtractorHelper.java 2012-03-13 10:19:10 UTC (rev 3609) @@ -57,8 +57,8 @@ */ public static void main(String[] args) { OxtractorHelper oh = new OxtractorHelper("http://live.dbpedia.org/sparql","http://dbpedia.org"); - System.out.println(oh.getInstances("http://dbpedia.org/resource/Category:Cities_in_Saxony")); - System.out.println(oh.getCategories("room")); +// System.out.println(oh.getInstances("http://dbpedia.org/resource/Category:Cities_in_Saxony")); + System.out.println(oh.getCategories("Kitchen")); } } Added: trunk/test/sparql/new_component/AristotlePos.conf =================================================================== --- trunk/test/sparql/new_component/AristotlePos.conf (rev 0) +++ trunk/test/sparql/new_component/AristotlePos.conf 2012-03-13 10:19:10 UTC (rev 3609) @@ -0,0 +1,49 @@ +/** + * Some people from Greece. + * Note: DBpedia is always subject to change, solutions will change over time + + * Possible Solution: + * Theorist OR (Mathematician AND Physicist) + * + * This is the same as AristotlePosNeg.conf, but positives only + */ + +// SPARQL options +sparql.type = "sparqls" +sparql.endpointURL = "http://live.dbpedia.org/sparql" + +/* +sparql.defaultGraphURIs = {"http://dbpedia.org"} +sparql.recursionDepth = 1 +//TODOREFACTOR check if predefinedFilter works at all +//predefined filter (1 = YAGO based learning) +sparql.predefinedFilter = "YAGO" +sparql.instances = { +"http://dbpedia.org/resource/Democritus", +"http://dbpedia.org/resource/Zeno_of_Elea", +"http://dbpedia.org/resource/Plato", +"http://dbpedia.org/resource/Socrates", +"http://dbpedia.org/resource/Archytas", +"http://dbpedia.org/resource/Pythagoras", +"http://dbpedia.org/resource/Philolaus" +} +*/ + +reasoner.type = "fast instance checker" +reasoner.sources = {sparql} + +// we want to learn from positive examples only +lp.type = "positive only learning problem" +lp.positiveExamples = { +"http://dbpedia.org/resource/Archytas", +"http://dbpedia.org/resource/Pythagoras", +"http://dbpedia.org/resource/Philolaus" +} + +lp.reasoner = reasoner + +// we use the OCEL algorithm +alg.type = "ocel" +alg.reasoner = reasoner +alg.learningProblem = lp + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sha...@us...> - 2012-03-12 04:28:29
|
Revision: 3608 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3608&view=rev Author: shadowtm Date: 2012-03-12 04:28:22 +0000 (Mon, 12 Mar 2012) Log Message: ----------- Modified interface to require the passing in of the OWL Manager so that a common manager instance could be used for OWLFiles and KBFiles. This will assist with multithreading in a threaded environment (webserver). Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java trunk/components-core/src/main/java/org/dllearner/kb/OWLOntologyKnowledgeSource.java trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java Modified: trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2012-03-12 02:14:08 UTC (rev 3607) +++ trunk/components-core/src/main/java/org/dllearner/kb/KBFile.java 2012-03-12 04:28:22 UTC (rev 3608) @@ -64,7 +64,6 @@ @ConfigOption(name = "fileName", description = "relative or absolute path to KB file") private String fileName; - private OWLOntology owlOntology; /** * Default constructor (needed for reflection in ComponentManager). @@ -112,7 +111,6 @@ kb = KBParser.parseKBFile(f); } - owlOntology = createOWLOntology(kb); logger.trace("KB File " + getUrl() + " parsed successfully."); } else { throw new ComponentInitException("No URL option or kb object given. Cannot initialise KBFile component."); @@ -127,16 +125,9 @@ } } - /** - * Create the OWL Ontology. - * - * @param kb The kb to create the ontology on top of. - * @return The OWL Ontology - */ - private OWLOntology createOWLOntology(KB kb) { - //This call is potentially dangerous in a multi-threaded(web) environment - I believe it returns a singleton instance - // There are ways around this, but getting it to work single threaded first. - OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); + @Override + public OWLOntology createOWLOntology(OWLOntologyManager manager) { + IRI ontologyURI = IRI.create("http://example.com"); OWLOntology ontology; try { @@ -151,10 +142,10 @@ } /* - * (non-Javadoc) - * - * @see org.dllearner.core.KnowledgeSource#toDIG() - */ + * (non-Javadoc) + * + * @see org.dllearner.core.KnowledgeSource#toDIG() + */ @Override public String toDIG(URI kbURI) { return DIGConverter.getDIGString(kb, kbURI).toString(); @@ -202,9 +193,4 @@ public void setFileName(String fileName) { this.fileName = fileName; } - - @Override - public OWLOntology getOWLOntology() { - return owlOntology; - } } Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2012-03-12 02:14:08 UTC (rev 3607) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLFile.java 2012-03-12 04:28:22 UTC (rev 3608) @@ -22,6 +22,7 @@ import java.io.File; import java.net.MalformedURLException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.Collection; import java.util.LinkedList; @@ -33,7 +34,6 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.OntologyFormat; import org.dllearner.core.OntologyFormatUnsupportedException; -import org.dllearner.core.config.ListStringEditor; import org.dllearner.core.options.ConfigEntry; import org.dllearner.core.options.ConfigOption; import org.dllearner.core.options.InvalidConfigOptionValueException; @@ -41,6 +41,10 @@ import org.dllearner.core.owl.KB; import org.dllearner.reasoning.OWLAPIDIGConverter; import org.dllearner.utilities.URLencodeUTF8; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; /** * @author Jens Lehmann @@ -49,7 +53,7 @@ * SH: I added SPARQL capabilities. Either URL is set directly or the basedir and filename is set or the URL and the SPARQL query is set */ @ComponentAnn(name = "OWL File", shortName = "owlfile", version = 0.9) -public class OWLFile extends AbstractKnowledgeSource { +public class OWLFile extends AbstractKnowledgeSource implements OWLOntologyKnowledgeSource { private static Logger logger = Logger.getLogger(OWLFile.class); @@ -133,9 +137,22 @@ throw new RuntimeException(e); } } + } + @Override + public OWLOntology createOWLOntology(OWLOntologyManager manager) { + try { + OWLOntology ontology = manager.loadOntologyFromOntologyDocument(IRI.create(getURL().toURI())); + return ontology; + } catch (OWLOntologyCreationException e) { + throw new RuntimeException(e); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + /* * (non-Javadoc) * Modified: trunk/components-core/src/main/java/org/dllearner/kb/OWLOntologyKnowledgeSource.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/kb/OWLOntologyKnowledgeSource.java 2012-03-12 02:14:08 UTC (rev 3607) +++ trunk/components-core/src/main/java/org/dllearner/kb/OWLOntologyKnowledgeSource.java 2012-03-12 04:28:22 UTC (rev 3608) @@ -1,6 +1,7 @@ package org.dllearner.kb; import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyManager; /** * Created by IntelliJ IDEA. @@ -12,11 +13,11 @@ */ public interface OWLOntologyKnowledgeSource { - /** - * Get the OWL Ontology that this object represents. + * Create an OWL Ontology associated with the specified manager. * - * @return The OWL ontology that this object represents. + * @param manager The manager to associate the new ontology with. + * @return The result ontology */ - public OWLOntology getOWLOntology(); + public OWLOntology createOWLOntology(OWLOntologyManager manager); } Modified: trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-12 02:14:08 UTC (rev 3607) +++ trunk/components-core/src/main/java/org/dllearner/reasoning/OWLAPIReasoner.java 2012-03-12 04:28:22 UTC (rev 3608) @@ -46,7 +46,6 @@ import java.io.File; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.util.*; import java.util.Map.Entry; @@ -153,25 +152,23 @@ for (AbstractKnowledgeSource source : sources) { + if (source instanceof OWLOntologyKnowledgeSource) { + ontology = ((OWLOntologyKnowledgeSource) source).createOWLOntology(manager); + owlAPIOntologies.add(ontology); + } + if (source instanceof OWLFile || source instanceof SparqlKnowledgeSource || source instanceof OWLAPIOntology) { - URL url = null; - if (source instanceof OWLFile) { - url = ((OWLFile) source).getURL(); - } - try { - if (source instanceof OWLAPIOntology) { ontology = ((OWLAPIOntology) source).getOWLOntolgy(); manager = ontology.getOWLOntologyManager(); + owlAPIOntologies.add(ontology); } else if (source instanceof SparqlKnowledgeSource) { ontology = ((SparqlKnowledgeSource) source).getOWLAPIOntology(); manager = ontology.getOWLOntologyManager(); - } else { - ontology = manager.loadOntologyFromOntologyDocument(IRI.create(url.toURI())); + owlAPIOntologies.add(ontology); } - owlAPIOntologies.add(ontology); directImports.addAll(ontology.getImportsDeclarations()); try { // imports includes the ontology itself @@ -180,33 +177,28 @@ allImports.addAll(imports); // System.out.println(imports); - for (OWLOntology ont : imports) { - classes.addAll(ont.getClassesInSignature()); - owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); - owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); - owlIndividuals.addAll(ont.getIndividualsInSignature()); - } - - } catch (UnknownOWLOntologyException uooe) { - logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); + for (OWLOntology ont : imports) { + classes.addAll(ont.getClassesInSignature()); + owlObjectProperties.addAll(ont.getObjectPropertiesInSignature()); + owlDatatypeProperties.addAll(ont.getDataPropertiesInSignature()); + owlIndividuals.addAll(ont.getIndividualsInSignature()); } - // if several knowledge sources are included, then we can only - // guarantee that the base URI is from one of those sources (there - // can't be more than one); but we will take care that all prefixes are - // correctly imported - OWLOntologyFormat format = manager.getOntologyFormat(ontology); - if (format instanceof PrefixOWLOntologyFormat) { - prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); - baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); - prefixes.remove(""); - } + } catch (UnknownOWLOntologyException uooe) { + logger.error("UnknownOWLOntologyException occured, imports were not loaded! This is a bug, which has not been fixed yet."); + } - } catch (OWLOntologyCreationException e) { - throw new RuntimeException(e); - } catch (URISyntaxException e) { - throw new RuntimeException(e); + // if several knowledge sources are included, then we can only + // guarantee that the base URI is from one of those sources (there + // can't be more than one); but we will take care that all prefixes are + // correctly imported + OWLOntologyFormat format = manager.getOntologyFormat(ontology); + if (format instanceof PrefixOWLOntologyFormat) { + prefixes.putAll(((PrefixOWLOntologyFormat) format).getPrefixName2PrefixMap()); + baseURI = ((PrefixOWLOntologyFormat) format).getDefaultPrefix(); + prefixes.remove(""); } + // all other sources are converted to KB and then to an // OWL API ontology } else { @@ -214,12 +206,8 @@ //KB Files KB kb = source.toKB(); - if(source instanceof OWLOntologyKnowledgeSource){ - ontology = ((OWLOntologyKnowledgeSource) source).getOWLOntology(); - } else { - -// System.out.println(kb.toString(null,null)); - + if (!(source instanceof OWLOntologyKnowledgeSource)) { + //Not sure if this will ever get hit, but leaving in for backward compatibility. IRI ontologyURI = IRI.create("http://example.com"); ontology = null; try { @@ -228,8 +216,9 @@ throw new RuntimeException(e); } OWLAPIAxiomConvertVisitor.fillOWLOntology(manager, ontology, kb); + owlAPIOntologies.add(ontology); } - owlAPIOntologies.add(ontology); + allImports.add(ontology); atomicConcepts.addAll(kb.findAllAtomicConcepts()); atomicRoles.addAll(kb.findAllAtomicRoles()); @@ -238,6 +227,8 @@ } } try { + //The following line illustrates a problem with using different OWLOntologyManagers. This can manifest itself if we have multiple sources who were created with different manager instances. + //ontology = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); ontology = manager.createOntology(IRI.create("http://dl-learner/all"), new HashSet<OWLOntology>(owlAPIOntologies)); //we have to add all import declarations manually here, because this are no axioms List<OWLOntologyChange> addImports = new ArrayList<OWLOntologyChange>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |