From: <jen...@us...> - 2011-08-03 14:49:42
|
Revision: 2981 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2981&view=rev Author: jenslehmann Date: 2011-08-03 14:49:36 +0000 (Wed, 03 Aug 2011) Log Message: ----------- ctd. evaluation script Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-03 14:01:03 UTC (rev 2980) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-03 14:49:36 UTC (rev 2981) @@ -1,5 +1,5 @@ /** - * Copyright (C) 2007-2008, Jens Lehmann + * Copyright (C) 2007-2011, Jens Lehmann * * This file is part of DL-Learner. * @@ -19,18 +19,20 @@ */ package org.dllearner.scripts.evaluation; +import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.aksw.commons.sparql.sparqler.SelectPaginated; -import org.aksw.commons.sparql.sparqler.Sparqler; -import org.aksw.commons.sparql.sparqler.SparqlerHttp; +import org.apache.log4j.Logger; import org.dllearner.algorithms.properties.SubPropertyOfAxiomLearner; +import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlQuery; import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; /** * Evaluation of enrichment algorithms on DBpedia (Live). @@ -40,9 +42,20 @@ */ public class EnrichmentEvaluation { + private static Logger logger = Logger.getLogger(EnrichmentEvaluation.class); + // max. execution time for each learner for each entity private int maxExecutionTimeInSeconds = 10; + // number of axioms which will be learned/considered (only applies to + // some learners) + private int nrOfAxiomsToLearn = 10; + + // can be used to only evaluate a part of DBpedia + private int maxObjectProperties = 3; + private int maxDataProperties = 3; + private int maxClasses = 3; + public EnrichmentEvaluation() { } @@ -57,21 +70,36 @@ SparqlEndpointKS ks = new SparqlEndpointKS(se); - SubPropertyOfAxiomLearner learner = new SubPropertyOfAxiomLearner(ks); - learner.setMaxExecutionTimeInSeconds(10); + int objectProperties = 0; + for(ObjectProperty property : properties) { + SubPropertyOfAxiomLearner learner = new SubPropertyOfAxiomLearner(ks); + learner.setPropertyToDescribe(property); + learner.setMaxExecutionTimeInSeconds(10); + learner.start(); + List<EvaluatedAxiom> learnedAxioms = learner.getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + for(EvaluatedAxiom learnedAxiom : learnedAxioms) { + // TODO: put this in some data structure + System.out.println(learnedAxiom); + } + objectProperties++; + if(objectProperties > maxObjectProperties) { + break; + } + } } private void getAllClasses() { - - - } private Set<ObjectProperty> getAllObjectProperties(SparqlEndpoint se) { Set<ObjectProperty> properties = new TreeSet<ObjectProperty>(); - Sparqler x = new SparqlerHttp(se.getURL().toString()); - SelectPaginated q = new SelectPaginated(x, "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:ObjectProperty}", 1000); + String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:ObjectProperty}"; + SparqlQuery sq = new SparqlQuery(query, se); + // Claus' API +// Sparqler x = new SparqlerHttp(se.getURL().toString()); +// SelectPaginated q = new SelectPaginated(x, , 1000); + ResultSet q = sq.send(); while(q.hasNext()) { QuerySolution qs = q.next(); System.out.println(qs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-05 13:02:52
|
Revision: 3005 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3005&view=rev Author: jenslehmann Date: 2011-08-05 13:02:46 +0000 (Fri, 05 Aug 2011) Log Message: ----------- enrichment evaluation script automatically creates SQL table Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 12:54:20 UTC (rev 3004) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 13:02:46 UTC (rev 3005) @@ -27,6 +27,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.sql.Statement; import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -34,8 +35,6 @@ import java.util.prefs.Preferences; import org.apache.log4j.Logger; -import org.dllearner.algorithms.properties.DisjointPropertyAxiomLearner; -import org.dllearner.algorithms.properties.EquivalentPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalPropertyAxiomLearner; import org.dllearner.algorithms.properties.PropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.PropertyRangeAxiomLearner; @@ -46,7 +45,6 @@ import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; @@ -119,6 +117,14 @@ String url = "jdbc:mysql://"+dbServer+"/"+dbName; Connection conn = DriverManager.getConnection(url, dbUser, dbPass); + + Statement s = conn.createStatement (); + s.executeUpdate ("DROP TABLE IF EXISTS evaluation"); + s.executeUpdate ( + "CREATE TABLE evaluation (" + + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," + + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE)"); + s.close(); ps = conn.prepareStatement("INSERT INTO evaluation (" + "entity, algorithm, axiom, score ) " + "VALUES(?,?,?,?)"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-05 13:25:33
|
Revision: 3006 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3006&view=rev Author: jenslehmann Date: 2011-08-05 13:25:27 +0000 (Fri, 05 Aug 2011) Log Message: ----------- HTML output for eval script; recording runtime Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 13:02:46 UTC (rev 3005) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 13:25:27 UTC (rev 3006) @@ -19,6 +19,7 @@ */ package org.dllearner.scripts.evaluation; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -26,6 +27,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; +import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.LinkedList; @@ -50,6 +52,7 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import org.dllearner.utilities.Files; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; @@ -60,51 +63,52 @@ * Evaluation of enrichment algorithms on DBpedia (Live). * * @author Jens Lehmann - * + * */ public class EnrichmentEvaluation { private static Logger logger = Logger.getLogger(EnrichmentEvaluation.class); - + // max. execution time for each learner for each entity private int maxExecutionTimeInSeconds = 10; - + // number of axioms which will be learned/considered (only applies to // some learners) private int nrOfAxiomsToLearn = 10; - + // can be used to only evaluate a part of DBpedia private int maxObjectProperties = 3; private int maxDataProperties = 3; private int maxClasses = 3; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; - + + private Connection conn; private PreparedStatement ps; - + public EnrichmentEvaluation() { initDBConnection(); - + objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); + // objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); + // objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); objectPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); objectPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); objectPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); objectPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); objectPropertyAlgorithms.add(SymmetricPropertyAxiomLearner.class); objectPropertyAlgorithms.add(TransitivePropertyAxiomLearner.class); - + dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// dataPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); -// dataPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); + // dataPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); + // dataPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); dataPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); dataPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); dataPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); // ? - dataPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); + dataPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); } - - private void initDBConnection(){ + + private void initDBConnection() { try { String iniFile = "db_settings.ini"; Preferences prefs = new IniPreferences(new FileReader(iniFile)); @@ -112,22 +116,19 @@ String dbName = "enrichment"; String dbUser = prefs.node("database").get("user", null); String dbPass = prefs.node("database").get("pass", null); - + Class.forName("com.mysql.jdbc.Driver"); - String url = - "jdbc:mysql://"+dbServer+"/"+dbName; - Connection conn = DriverManager.getConnection(url, dbUser, dbPass); - - Statement s = conn.createStatement (); - s.executeUpdate ("DROP TABLE IF EXISTS evaluation"); - s.executeUpdate ( - "CREATE TABLE evaluation (" - + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," - + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE)"); + String url = "jdbc:mysql://" + dbServer + "/" + dbName; + conn = DriverManager.getConnection(url, dbUser, dbPass); + + Statement s = conn.createStatement(); + s.executeUpdate("DROP TABLE IF EXISTS evaluation"); + s.executeUpdate("CREATE TABLE evaluation (" + + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," + + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20))"); s.close(); - ps = conn.prepareStatement("INSERT INTO evaluation (" + - "entity, algorithm, axiom, score ) " + - "VALUES(?,?,?,?)"); + ps = conn.prepareStatement("INSERT INTO evaluation (" + + "entity, algorithm, axiom, score, runtime_ms ) " + "VALUES(?,?,?,?,?)"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { @@ -140,96 +141,142 @@ e.printStackTrace(); } } - - private void writeToDB( - String entity, String algorithm, String axiom, double score){ + + private void writeToDB(String entity, String algorithm, String axiom, double score, long runTime) { try { ps.setString(1, entity); ps.setString(2, algorithm); ps.setString(3, axiom); ps.setDouble(4, score); - + ps.setLong(5, runTime); + ps.executeUpdate(); } catch (SQLException e) { - logger.error("Error while writing to DB.",e); + logger.error("Error while writing to DB.", e); e.printStackTrace(); } - + } - - public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { - + + public void start() throws IllegalArgumentException, SecurityException, InstantiationException, + IllegalAccessException, InvocationTargetException, NoSuchMethodException, + ComponentInitException { + ComponentManager cm = ComponentManager.getInstance(); - + // create DBpedia Live knowledge source SparqlEndpoint se = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); - + Set<ObjectProperty> properties = getAllObjectProperties(se); - + SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); - - for(Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { + + for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; - for(ObjectProperty property : properties) { + for (ObjectProperty property : properties) { // dynamically invoke constructor with SPARQL knowledge source - AxiomLearningAlgorithm learner = algorithmClass.getConstructor(SparqlEndpointKS.class).newInstance(ks); + AxiomLearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); learner.init(); -// learner.setPropertyToDescribe(property); -// learner.setMaxExecutionTimeInSeconds(10); + // learner.setPropertyToDescribe(property); + // learner.setMaxExecutionTimeInSeconds(10); String algName = ComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + property + " ... "); + System.out.println("Applying " + algName + " on " + property + " ... "); + long startTime = System.currentTimeMillis(); learner.start(); - List<EvaluatedAxiom> learnedAxioms = learner.getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if(learnedAxioms == null) { - writeToDB(property.toString(), algName, "NULL", 0); + long runTime = System.currentTimeMillis() - startTime; + List<EvaluatedAxiom> learnedAxioms = learner + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + if (learnedAxioms == null) { + writeToDB(property.toString(), algName, "NULL", 0, runTime); } else { - for(EvaluatedAxiom learnedAxiom : learnedAxioms) { - writeToDB(property.toString(), algName, learnedAxiom.getAxiom().toString(), learnedAxiom.getScore().getAccuracy()); + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + double score = learnedAxiom.getScore().getAccuracy(); + if (Double.isNaN(score)) { + score = -1; + } + writeToDB(property.toString(), algName, learnedAxiom.getAxiom().toString(), + score, runTime); } } objectProperties++; - if(objectProperties > maxObjectProperties) { + if (objectProperties > maxObjectProperties) { break; } } - } - + } + } - + private void getAllClasses() { } - + private Set<ObjectProperty> getAllObjectProperties(SparqlEndpoint se) { Set<ObjectProperty> properties = new TreeSet<ObjectProperty>(); String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:ObjectProperty}"; SparqlQuery sq = new SparqlQuery(query, se); // Claus' API -// Sparqler x = new SparqlerHttp(se.getURL().toString()); -// SelectPaginated q = new SelectPaginated(x, , 1000); + // Sparqler x = new SparqlerHttp(se.getURL().toString()); + // SelectPaginated q = new SelectPaginated(x, , 1000); ResultSet q = sq.send(); - while(q.hasNext()) { - QuerySolution qs = q.next(); - properties.add(new ObjectProperty(qs.getResource("p").getURI())); - } - return properties; + while (q.hasNext()) { + QuerySolution qs = q.next(); + properties.add(new ObjectProperty(qs.getResource("p").getURI())); + } + return properties; } - + public void printResultsPlain() { - + } - + public void printResultsLaTeX() { - + } - - public static void main(String[] args) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { + + public String printHTMLTable() throws SQLException { + StringBuffer sb = new StringBuffer(); + Statement s = conn.createStatement(); + s.executeQuery("SELECT * FROM evaluation"); + java.sql.ResultSet rs = s.getResultSet(); + + ResultSetMetaData md = rs.getMetaData(); + int count = md.getColumnCount(); + sb.append("<table border=1>"); + sb.append("<tr>"); + for (int i = 1; i <= count; i++) { + sb.append("<th>"); + sb.append(md.getColumnLabel(i)); + sb.append("</th>"); + } + sb.append("</tr>"); + while (rs.next()) { + sb.append("<tr>"); + for (int i = 1; i <= count; i++) { + sb.append("<td>"); + sb.append(rs.getString(i)); + sb.append("</td>"); + } + sb.append("</tr>"); + } + sb.append("</table>"); + rs.close(); + s.close(); + return sb.toString(); + } + + public static void main(String[] args) throws IllegalArgumentException, SecurityException, + InstantiationException, IllegalAccessException, InvocationTargetException, + NoSuchMethodException, ComponentInitException, SQLException { EnrichmentEvaluation ee = new EnrichmentEvaluation(); ee.start(); - ee.printResultsPlain(); + // ee.printResultsPlain(); + Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); } - + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-05 13:47:14
|
Revision: 3009 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3009&view=rev Author: jenslehmann Date: 2011-08-05 13:47:08 +0000 (Fri, 05 Aug 2011) Log Message: ----------- improved eval script output Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 13:33:42 UTC (rev 3008) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-05 13:47:08 UTC (rev 3009) @@ -30,8 +30,10 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.prefs.Preferences; @@ -83,12 +85,19 @@ private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; + private String baseURI = "http://dbpedia.org/resource/"; + private Map<String,String> prefixes; + private Connection conn; private PreparedStatement ps; public EnrichmentEvaluation() { initDBConnection(); + prefixes = new HashMap<String,String>(); + prefixes.put("dbp","http://dbpedia.org/property/"); + prefixes.put("dbo","http://dbpedia.org/ontology/"); + objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); // objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); // objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); @@ -193,14 +202,14 @@ List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); if (learnedAxioms == null) { - writeToDB(property.toString(), algName, "NULL", 0, runTime); + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { double score = learnedAxiom.getScore().getAccuracy(); if (Double.isNaN(score)) { score = -1; } - writeToDB(property.toString(), algName, learnedAxiom.getAxiom().toString(), + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), score, runTime); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-08 06:01:33
|
Revision: 3011 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3011&view=rev Author: lorenz_b Date: 2011-08-08 06:01:26 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Small modification. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-08 06:00:16 UTC (rev 3010) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-08 06:01:26 UTC (rev 3011) @@ -24,6 +24,8 @@ import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.net.SocketException; +import java.net.SocketTimeoutException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -39,6 +41,7 @@ import java.util.prefs.Preferences; import org.apache.log4j.Logger; +import org.dllearner.algorithms.properties.EquivalentPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalPropertyAxiomLearner; import org.dllearner.algorithms.properties.PropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.PropertyRangeAxiomLearner; @@ -79,7 +82,7 @@ private int nrOfAxiomsToLearn = 10; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 3; + private int maxObjectProperties = 0; private int maxDataProperties = 3; private int maxClasses = 3; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; @@ -100,7 +103,7 @@ objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); // objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); - // objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); objectPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); objectPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); objectPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); @@ -122,7 +125,7 @@ String iniFile = "db_settings.ini"; Preferences prefs = new IniPreferences(new FileReader(iniFile)); String dbServer = prefs.node("database").get("server", null); - String dbName = "enrichment"; + String dbName = prefs.node("database").get("name", null); String dbUser = prefs.node("database").get("user", null); String dbPass = prefs.node("database").get("pass", null); @@ -170,7 +173,7 @@ public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { - + long overallStartTime = System.currentTimeMillis(); ComponentManager cm = ComponentManager.getInstance(); // create DBpedia Live knowledge source @@ -197,11 +200,20 @@ String algName = ComponentManager.getName(learner); System.out.println("Applying " + algName + " on " + property + " ... "); long startTime = System.currentTimeMillis(); - learner.start(); + boolean timeout = false; + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } + } long runTime = System.currentTimeMillis() - startTime; List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if (learnedAxioms == null) { + if(timeout){ + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { @@ -219,6 +231,7 @@ } } } + System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-10 06:53:26
|
Revision: 3021 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3021&view=rev Author: lorenz_b Date: 2011-08-10 06:53:19 +0000 (Wed, 10 Aug 2011) Log Message: ----------- Extended evaluation script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-09 15:47:19 UTC (rev 3020) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-10 06:53:19 UTC (rev 3021) @@ -24,7 +24,6 @@ import java.io.FileReader; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.net.SocketException; import java.net.SocketTimeoutException; import java.sql.Connection; import java.sql.DriverManager; @@ -41,13 +40,20 @@ import java.util.prefs.Preferences; import org.apache.log4j.Logger; +import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; +import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.DisjointPropertyAxiomLearner; +import org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner; import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.EquivalentPropertyAxiomLearner; +import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalPropertyAxiomLearner; import org.dllearner.algorithms.properties.PropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.PropertyRangeAxiomLearner; +import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SubPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SymmetricPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitivePropertyAxiomLearner; @@ -57,6 +63,8 @@ import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; +import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; @@ -86,9 +94,9 @@ private int nrOfAxiomsToLearn = 10; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 0; - private int maxDataProperties = 3; - private int maxClasses = 3; + private int maxObjectProperties = 10; + private int maxDataProperties = 10; + private int maxClasses = 10; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -107,7 +115,7 @@ prefixes.put("dbo","http://dbpedia.org/ontology/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - // objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); objectPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); objectPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); @@ -117,12 +125,12 @@ objectPropertyAlgorithms.add(TransitivePropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - // dataPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); - // dataPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); - dataPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); - dataPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); - dataPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); // ? - dataPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); + dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); + dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); + dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); classAlgorithms.add(DisjointClassesLearner.class); @@ -189,11 +197,20 @@ // create DBpedia Live knowledge source SparqlEndpoint se = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); - Set<ObjectProperty> properties = getAllObjectProperties(se); - SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); + + evaluateObjectProperties(ks); + + evaluateDataProperties(ks); + + System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); + } + + private void evaluateObjectProperties(SparqlEndpointKS ks)throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + Set<ObjectProperty> properties = getAllObjectProperties(ks.getEndpoint()); + for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; for (ObjectProperty property : properties) { @@ -241,11 +258,58 @@ } } } - System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); - } + + private void evaluateDataProperties(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + Set<DatatypeProperty> properties = getAllDataProperties(ks.getEndpoint()); - private void getAllClasses() { + for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { + int dataProperties = 0; + for (DatatypeProperty property : properties) { + + // dynamically invoke constructor with SPARQL knowledge source + AxiomLearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + // learner.setPropertyToDescribe(property); + // learner.setMaxExecutionTimeInSeconds(10); + String algName = ComponentManager.getName(learner); + System.out.println("Applying " + algName + " on " + property + " ... "); + long startTime = System.currentTimeMillis(); + boolean timeout = false; + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } + } + long runTime = System.currentTimeMillis() - startTime; + List<EvaluatedAxiom> learnedAxioms = learner + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + if(timeout){ + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + double score = learnedAxiom.getScore().getAccuracy(); + if (Double.isNaN(score)) { + score = -1; + } + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), + score, runTime); + } + } + dataProperties++; + if (maxDataProperties != 0 && dataProperties > maxDataProperties) { + break; + } + } + } } private Set<ObjectProperty> getAllObjectProperties(SparqlEndpoint se) { @@ -262,6 +326,36 @@ } return properties; } + + private Set<DatatypeProperty> getAllDataProperties(SparqlEndpoint se) { + Set<DatatypeProperty> properties = new TreeSet<DatatypeProperty>(); + String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?p WHERE {?p a owl:DatatypeProperty}"; + SparqlQuery sq = new SparqlQuery(query, se); + // Claus' API + // Sparqler x = new SparqlerHttp(se.getURL().toString()); + // SelectPaginated q = new SelectPaginated(x, , 1000); + ResultSet q = sq.send(); + while (q.hasNext()) { + QuerySolution qs = q.next(); + properties.add(new DatatypeProperty(qs.getResource("p").getURI())); + } + return properties; + } + + private Set<NamedClass> getAllClasses(SparqlEndpoint se) { + Set<NamedClass> classes = new TreeSet<NamedClass>(); + String query = "PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT ?c WHERE {?c a owl:Class}"; + SparqlQuery sq = new SparqlQuery(query, se); + // Claus' API + // Sparqler x = new SparqlerHttp(se.getURL().toString()); + // SelectPaginated q = new SelectPaginated(x, , 1000); + ResultSet q = sq.send(); + while (q.hasNext()) { + QuerySolution qs = q.next(); + classes.add(new NamedClass(qs.getResource("c").getURI())); + } + return classes; + } public void printResultsPlain() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-11 06:40:43
|
Revision: 3026 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3026&view=rev Author: lorenz_b Date: 2011-08-11 06:40:37 +0000 (Thu, 11 Aug 2011) Log Message: ----------- Changes in eval script needed because of refactoring. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-10 14:19:01 UTC (rev 3025) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-11 06:40:37 UTC (rev 3026) @@ -40,23 +40,24 @@ import java.util.prefs.Preferences; import org.apache.log4j.Logger; +import org.dllearner.algorithms.DisjointClassesLearner; +import org.dllearner.algorithms.SimpleSubclassLearner; +import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; -import org.dllearner.algorithms.properties.DisjointPropertyAxiomLearner; +import org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner; -import org.dllearner.algorithms.DisjointClassesLearner; -import org.dllearner.algorithms.SimpleSubclassLearner; -import org.dllearner.algorithms.celoe.CELOE; -import org.dllearner.algorithms.properties.EquivalentPropertyAxiomLearner; +import org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; -import org.dllearner.algorithms.properties.FunctionalPropertyAxiomLearner; -import org.dllearner.algorithms.properties.PropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.FunctionalObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.PropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; -import org.dllearner.algorithms.properties.SubPropertyOfAxiomLearner; -import org.dllearner.algorithms.properties.SymmetricPropertyAxiomLearner; -import org.dllearner.algorithms.properties.TransitivePropertyAxiomLearner; +import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; +import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; @@ -115,14 +116,15 @@ prefixes.put("dbo","http://dbpedia.org/ontology/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - objectPropertyAlgorithms.add(DisjointPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(EquivalentPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(FunctionalPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); + objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); objectPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); - objectPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); - objectPropertyAlgorithms.add(SymmetricPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(TransitivePropertyAxiomLearner.class); + objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); + objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-11 14:33:53
|
Revision: 3035 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3035&view=rev Author: lorenz_b Date: 2011-08-11 14:33:45 +0000 (Thu, 11 Aug 2011) Log Message: ----------- Small changes. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-11 14:31:41 UTC (rev 3034) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-11 14:33:45 UTC (rev 3035) @@ -137,6 +137,8 @@ classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); classAlgorithms.add(CELOE.class); + + initDBConnection(); } private void initDBConnection() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-19 11:12:58
|
Revision: 3072 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3072&view=rev Author: lorenz_b Date: 2011-08-19 11:12:51 +0000 (Fri, 19 Aug 2011) Log Message: ----------- Continued eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-19 11:07:00 UTC (rev 3071) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-19 11:12:51 UTC (rev 3072) @@ -19,12 +19,16 @@ */ package org.dllearner.scripts.evaluation; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; import java.net.SocketTimeoutException; +import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -38,14 +42,14 @@ import java.util.Set; import java.util.prefs.Preferences; +import org.apache.commons.compress.compressors.CompressorException; +import org.apache.commons.compress.compressors.CompressorInputStream; +import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; -import org.apache.velocity.context.EvaluateContext; -import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; -import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; @@ -57,19 +61,17 @@ import org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.IrreflexiveObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; -import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentInitException; -import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedAxiom; -import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.owl.DatatypeProperty; @@ -80,9 +82,18 @@ import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.Files; +import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; +import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.reasoner.InferenceType; +import org.semanticweb.owlapi.reasoner.OWLReasoner; +import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; + /** * Evaluation of enrichment algorithms on DBpedia (Live). * @@ -103,7 +114,7 @@ // can be used to only evaluate a part of DBpedia private int maxObjectProperties = 0; private int maxDataProperties = 0; - private int maxClasses = 0; + private int maxClasses = 10; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -113,6 +124,9 @@ private Connection conn; private PreparedStatement ps; + + private OWLOntology dbPediaOntology; + private OWLReasoner reasoner; public EnrichmentEvaluation() { @@ -121,25 +135,25 @@ prefixes.put("dbo","http://dbpedia.org/ontology/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); - objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); - objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); - objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.class); - objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); +// objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); +// objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); +// objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); - dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); - dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); - dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); - dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); - dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); +// dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); +// dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); +// dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); +// dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); +// dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); +// dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); // classAlgorithms.add(DisjointClassesLearner.class); @@ -147,6 +161,7 @@ // classAlgorithms.add(CELOE.class); initDBConnection(); + loadDBpediaOntology(); } private void initDBConnection() { @@ -381,7 +396,7 @@ double score = learnedAxiom.getScore().getAccuracy(); if (Double.isNaN(score)) { score = -1; - } + }System.out.println(learnedAxiom.getAxiom().toManchesterSyntaxString(algName, prefixes) + ":" + isEntailed(learnedAxiom)); writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), score, runTime); } @@ -440,10 +455,36 @@ s.close(); return sb.toString(); } + + private boolean isEntailed(EvaluatedAxiom evalAxiom){ + OWLAxiom axiom = OWLAPIConverter.getOWLAPIAxiom(evalAxiom.getAxiom()); + boolean entailed = reasoner.isEntailed(axiom); + return entailed; + } + + /** + * Loads DBpedia ontology from remote URL and initializes the reasoner. + */ + private void loadDBpediaOntology(){ + try { + URL url = new URL("http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl.bz2"); + InputStream is = new BufferedInputStream(url.openStream()); + CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is); + dbPediaOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(in); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (CompressorException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + } - public static void main(String[] args) throws IllegalArgumentException, SecurityException, - InstantiationException, IllegalAccessException, InvocationTargetException, - NoSuchMethodException, ComponentInitException, SQLException, IOException { + public static void main(String[] args) throws Exception { EnrichmentEvaluation ee = new EnrichmentEvaluation(); ee.start(); // ee.printResultsPlain(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-22 13:54:48
|
Revision: 3091 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3091&view=rev Author: lorenz_b Date: 2011-08-22 13:54:38 +0000 (Mon, 22 Aug 2011) Log Message: ----------- Added column in evaluation database table, which declares whether the learned axiom was entailed by the knowledge base before. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-22 13:21:34 UTC (rev 3090) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-22 13:54:38 UTC (rev 3091) @@ -35,6 +35,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -72,6 +73,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; +import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.owl.DatatypeProperty; @@ -80,6 +82,7 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.learningproblems.AxiomScore; import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.Files; import org.dllearner.utilities.owl.OWLAPIConverter; @@ -181,10 +184,10 @@ s.executeUpdate("DROP TABLE IF EXISTS evaluation"); s.executeUpdate("CREATE TABLE evaluation (" + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," - + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20))"); + + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); s.close(); ps = conn.prepareStatement("INSERT INTO evaluation (" - + "entity, algorithm, axiom, score, runtime_ms ) " + "VALUES(?,?,?,?,?)"); + + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { @@ -198,13 +201,14 @@ } } - private void writeToDB(String entity, String algorithm, String axiom, double score, long runTime) { + private void writeToDB(String entity, String algorithm, String axiom, double score, long runTime, boolean entailed) { try { ps.setString(1, entity); ps.setString(2, algorithm); ps.setString(3, axiom); ps.setDouble(4, score); ps.setLong(5, runTime); + ps.setBoolean(6, entailed); ps.executeUpdate(); } catch (SQLException e) { @@ -270,9 +274,9 @@ List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); if(timeout){ - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { double score = learnedAxiom.getScore().getAccuracy(); @@ -280,7 +284,7 @@ score = -1; } writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), - score, runTime); + score, runTime, isEntailed(learnedAxiom)); } } objectProperties++; @@ -330,9 +334,9 @@ List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); if(timeout){ - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { - writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); + writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { double score = learnedAxiom.getScore().getAccuracy(); @@ -340,7 +344,7 @@ score = -1; } writeToDB(property.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), - score, runTime); + score, runTime, isEntailed(learnedAxiom)); } } dataProperties++; @@ -384,25 +388,31 @@ } } long runTime = System.currentTimeMillis() - startTime; + List<EvaluatedAxiom> learnedAxioms = null; if(learner instanceof AxiomLearningAlgorithm){ - List<EvaluatedAxiom> learnedAxioms = ((AxiomLearningAlgorithm)learner) + learnedAxioms = ((AxiomLearningAlgorithm)learner) .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if(timeout){ - writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime); - } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { - writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime); - } else { - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - double score = learnedAxiom.getScore().getAccuracy(); - if (Double.isNaN(score)) { - score = -1; - }System.out.println(learnedAxiom.getAxiom().toManchesterSyntaxString(algName, prefixes) + ":" + isEntailed(learnedAxiom)); - writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), - score, runTime); + } else if(learner instanceof AbstractCELA){ + learnedAxioms = new ArrayList<EvaluatedAxiom>(); + List<? extends EvaluatedDescription> learnedDescriptions = ((AbstractCELA)learner).getCurrentlyBestEvaluatedDescriptions(nrOfAxiomsToLearn); + for(EvaluatedDescription learnedDescription : learnedDescriptions){ + //TODO create axioms and differ between equivalent and subclass mode in CELOE + learnedAxioms.add(new EvaluatedAxiom(null, new AxiomScore(learnedDescription.getAccuracy()))); + } + } + if(timeout){ + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); + } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + double score = learnedAxiom.getScore().getAccuracy(); + if (Double.isNaN(score)) { + score = -1; } + writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes) .toString(), algName, learnedAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes), + score, runTime, isEntailed(learnedAxiom)); } - } else if(learner instanceof AbstractCELA){ - } classesCnt++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-23 14:48:08
|
Revision: 3101 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3101&view=rev Author: lorenz_b Date: 2011-08-23 14:48:02 +0000 (Tue, 23 Aug 2011) Log Message: ----------- Continued eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-23 13:12:01 UTC (rev 3100) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-23 14:48:02 UTC (rev 3101) @@ -50,27 +50,12 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; -import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; -import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; -import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; -import org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner; -import org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; -import org.dllearner.algorithms.properties.FunctionalObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.IrreflexiveObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; -import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; -import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; -import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; -import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; -import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; @@ -159,7 +144,7 @@ // dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); -// classAlgorithms.add(DisjointClassesLearner.class); + classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); // classAlgorithms.add(CELOE.class); @@ -181,11 +166,11 @@ conn = DriverManager.getConnection(url, dbUser, dbPass); Statement s = conn.createStatement(); - s.executeUpdate("DROP TABLE IF EXISTS evaluation"); - s.executeUpdate("CREATE TABLE evaluation (" - + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," - + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); - s.close(); +// s.executeUpdate("DROP TABLE IF EXISTS evaluation"); +// s.executeUpdate("CREATE TABLE evaluation (" +// + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," +// + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); +// s.close(); ps = conn.prepareStatement("INSERT INTO evaluation (" + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (ClassNotFoundException e) { @@ -431,8 +416,31 @@ } - public void printResultsLaTeX() { - + public void printResultsLaTeX() throws Exception{ + double threshold = 0.9; + + for(Class<? extends LearningAlgorithm> algo : classAlgorithms){ + String algoName = algo.getAnnotation(ComponentAnn.class).name(); + //compute average number of suggestions above threshold + PreparedStatement ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); + ps.setString(1, algoName); + ps.setDouble(2, threshold); + java.sql.ResultSet rs = ps.executeQuery(); + rs.next();System.out.println(rs.getDouble(1)); + int avgSuggestionsAboveThreshold = rs.getInt(1); + + //compute average runtime + ps = conn.prepareStatement("SELECT AVG(runtime_ms) FROM evaluation WHERE algorithm=?"); + ps.setString(1, algoName); + rs = ps.executeQuery(); + rs.next(); + int avgRuntimeInMilliseconds = rs.getInt(1); + + //compute + + System.out.println(algoName + "-" + avgSuggestionsAboveThreshold + "-" + avgRuntimeInMilliseconds); + } + } public String printHTMLTable() throws SQLException { @@ -496,8 +504,9 @@ public static void main(String[] args) throws Exception { EnrichmentEvaluation ee = new EnrichmentEvaluation(); - ee.start(); +// ee.start(); // ee.printResultsPlain(); + ee.printResultsLaTeX(); Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); FileAppender app = new FileAppender(new SimpleLayout(), "log/enrichmentEvalErrors.log"); Logger.getRootLogger().setLevel(Level.ERROR); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-24 09:14:17
|
Revision: 3107 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3107&view=rev Author: lorenz_b Date: 2011-08-24 09:14:11 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Continued eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-24 04:53:25 UTC (rev 3106) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-24 09:14:11 UTC (rev 3107) @@ -52,6 +52,15 @@ import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; +import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; +import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.IrreflexiveObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; +import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; +import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AbstractCELA; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; @@ -100,9 +109,9 @@ private int nrOfAxiomsToLearn = 10; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 0; - private int maxDataProperties = 0; - private int maxClasses = 10; + private int maxObjectProperties = 3; + private int maxDataProperties = 3; + private int maxClasses = 3; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -129,19 +138,19 @@ // objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); // objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); // objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); -// objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); -// objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); + objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); // dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); // dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); -// dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); -// dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); -// dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); -// dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); + dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); + dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); + dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); classAlgorithms.add(DisjointClassesLearner.class); @@ -165,14 +174,6 @@ String url = "jdbc:mysql://" + dbServer + "/" + dbName; conn = DriverManager.getConnection(url, dbUser, dbPass); - Statement s = conn.createStatement(); -// s.executeUpdate("DROP TABLE IF EXISTS evaluation"); -// s.executeUpdate("CREATE TABLE evaluation (" -// + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," -// + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); -// s.close(); - ps = conn.prepareStatement("INSERT INTO evaluation (" - + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { @@ -185,6 +186,22 @@ e.printStackTrace(); } } + + private void dropAndCreateTable(){ + try { + Statement s = conn.createStatement(); + s.executeUpdate("DROP TABLE IF EXISTS evaluation"); + s.executeUpdate("CREATE TABLE evaluation (" + + "id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY," + + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); + s.close(); + + ps = conn.prepareStatement("INSERT INTO evaluation (" + + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); + } catch (SQLException e) { + e.printStackTrace(); + } + } private void writeToDB(String entity, String algorithm, String axiom, double score, long runTime, boolean entailed) { try { @@ -206,6 +223,8 @@ public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { + dropAndCreateTable(); + long overallStartTime = System.currentTimeMillis(); // ComponentManager cm = ComponentManager.getInstance(); @@ -385,7 +404,7 @@ learnedAxioms.add(new EvaluatedAxiom(null, new AxiomScore(learnedDescription.getAccuracy()))); } } - if(timeout){ + if(timeout && learnedAxioms.isEmpty()){ writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); @@ -419,26 +438,82 @@ public void printResultsLaTeX() throws Exception{ double threshold = 0.9; - for(Class<? extends LearningAlgorithm> algo : classAlgorithms){ + List<Class<? extends LearningAlgorithm>> algorithms = new ArrayList<Class<? extends LearningAlgorithm>>(); + algorithms.addAll(classAlgorithms); + algorithms.addAll(objectPropertyAlgorithms); + algorithms.addAll(dataPropertyAlgorithms); + + for(Class<? extends LearningAlgorithm> algo : algorithms){ String algoName = algo.getAnnotation(ComponentAnn.class).name(); + + //get number of entities + ps = conn.prepareStatement("SELECT COUNT(DISTINCT entity) FROM evaluation WHERE algorithm=?"); + ps.setString(1, algoName); + java.sql.ResultSet rs = ps.executeQuery(); + rs.next(); + int overallNumberOfEntities = rs.getInt(1); + + //get number of entities with empty result + ps = conn.prepareStatement("SELECT COUNT(DISTINCT entity) FROM evaluation WHERE algorithm=? AND axiom=?"); + ps.setString(1, algoName); + ps.setString(2, "NULL"); + rs = ps.executeQuery(); + rs.next(); + int numberOfEntitiesWithEmptyResult = rs.getInt(1); + + //get number of entities with timout + ps = conn.prepareStatement("SELECT COUNT(DISTINCT entity) FROM evaluation WHERE algorithm=? AND axiom=?"); + ps.setString(1, algoName); + ps.setString(2, "TIMEOUT"); + rs = ps.executeQuery(); + rs.next(); + int numberOfEntitiesWithTimeout = rs.getInt(1); + //compute average number of suggestions above threshold PreparedStatement ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); ps.setString(1, algoName); ps.setDouble(2, threshold); - java.sql.ResultSet rs = ps.executeQuery(); - rs.next();System.out.println(rs.getDouble(1)); - int avgSuggestionsAboveThreshold = rs.getInt(1); + rs = ps.executeQuery(); + rs.next(); + double avgSuggestionsAboveThreshold = rs.getDouble(1); //compute average runtime - ps = conn.prepareStatement("SELECT AVG(runtime_ms) FROM evaluation WHERE algorithm=?"); + ps = conn.prepareStatement("SELECT AVG(runtime) FROM (SELECT MAX(runtime_ms) AS runtime FROM evaluation WHERE algorithm=?) AS A"); ps.setString(1, algoName); rs = ps.executeQuery(); rs.next(); - int avgRuntimeInMilliseconds = rs.getInt(1); + double avgRuntimeInMilliseconds = rs.getDouble(1); - //compute + //compute ratio for complete timeouts + double timeoutRatio = (double)numberOfEntitiesWithTimeout / overallNumberOfEntities; - System.out.println(algoName + "-" + avgSuggestionsAboveThreshold + "-" + avgRuntimeInMilliseconds); + //compute avg. score + ps = conn.prepareStatement("SELECT AVG(avg) FROM (SELECT AVG(score) AS avg FROM evaluation WHERE algorithm=? AND score >= ? GROUP BY entity) AS A"); + ps.setString(1, algoName); + ps.setDouble(2, threshold); + rs = ps.executeQuery(); + rs.next(); + double avgScore= rs.getDouble(1); + + //compute avg. max. score + ps = conn.prepareStatement("SELECT AVG(max) FROM (SELECT MAX(score) AS max FROM evaluation WHERE algorithm=? AND score>=? GROUP BY entity) AS A"); + ps.setString(1, algoName); + ps.setDouble(2, threshold); + rs = ps.executeQuery(); + rs.next(); + double avgMaxScore = rs.getDouble(1); + + System.out.println("###############"); + System.out.println(algoName); + System.out.println("Overall entities: " + overallNumberOfEntities); + System.out.println("Overall entities with emtpy result: " + numberOfEntitiesWithEmptyResult); + System.out.println("Overall entities with emtpy timeout: " + numberOfEntitiesWithTimeout); + System.out.println("Avg. #Suggestions above t: " + avgSuggestionsAboveThreshold); + System.out.println("Avg. runtime in ms: " + avgRuntimeInMilliseconds); + System.out.println("Timeout ratio: " + timeoutRatio); + System.out.println("Avg. score: " + avgScore); + System.out.println("Avg. max. score: " + avgMaxScore); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-25 12:18:03
|
Revision: 3123 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3123&view=rev Author: lorenz_b Date: 2011-08-25 12:17:57 +0000 (Thu, 25 Aug 2011) Log Message: ----------- Continued eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-25 12:16:46 UTC (rev 3122) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-25 12:17:57 UTC (rev 3123) @@ -32,14 +32,19 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.prefs.Preferences; @@ -52,10 +57,19 @@ import org.apache.log4j.SimpleLayout; import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; +import org.dllearner.algorithms.celoe.CELOE; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; +import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.FunctionalObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.IrreflexiveObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; +import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; @@ -70,7 +84,9 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.config.ConfigHelper; +import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; +import org.dllearner.core.owl.DisjointClassesAxiom; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; import org.dllearner.kb.SparqlEndpointKS; @@ -79,16 +95,28 @@ import org.dllearner.learningproblems.AxiomScore; import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.Files; +import org.dllearner.utilities.owl.DLLearnerAxiomConvertVisitor; import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.model.AxiomType; +import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClassAxiom; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataPropertyAxiom; +import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; +import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; + import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; /** @@ -100,6 +128,13 @@ public class EnrichmentEvaluation { private static Logger logger = Logger.getLogger(EnrichmentEvaluation.class); + + // max. number of attempts per algorithm and entity, because to many queries + // in a short time could cause blocking by the endpoint + private final int maxAttempts = 3; + + //delay between 2 attempts + private final int delayInMilliseconds = 10000; // max. execution time for each learner for each entity private int maxExecutionTimeInSeconds = 10; @@ -107,6 +142,11 @@ // number of axioms which will be learned/considered (only applies to // some learners) private int nrOfAxiomsToLearn = 10; + + // only axioms with a score above this threshold will be considered + private double threshold = 0.7; + + private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia();//getEndpointDBpediaLiveAKSW(); // can be used to only evaluate a part of DBpedia private int maxObjectProperties = 3; @@ -124,6 +164,7 @@ private OWLOntology dbPediaOntology; private OWLReasoner reasoner; + private OWLDataFactory factory = new OWLDataFactoryImpl(); public EnrichmentEvaluation() { @@ -132,12 +173,12 @@ prefixes.put("dbo","http://dbpedia.org/ontology/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); -// objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); -// objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); + objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(ObjectPropertyDomainAxiomLearner.class); + objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); @@ -145,8 +186,8 @@ objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); -// dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); dataPropertyAlgorithms.add(DataPropertyRangeAxiomLearner.class); @@ -222,22 +263,25 @@ public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, - ComponentInitException { + ComponentInitException, InterruptedException { dropAndCreateTable(); long overallStartTime = System.currentTimeMillis(); // ComponentManager cm = ComponentManager.getInstance(); // create DBpedia Live knowledge source - SparqlEndpoint se = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); - SparqlEndpointKS ks = new SparqlEndpointKS(se); + SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); evaluateObjectProperties(ks); +// +// Thread.sleep(10000); evaluateDataProperties(ks); +// Thread.sleep(10000); +// evaluateClasses(ks); System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); @@ -264,20 +308,36 @@ // learner.setPropertyToDescribe(property); // learner.setMaxExecutionTimeInSeconds(10); algName = AnnComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + property + " ... "); - long startTime = System.currentTimeMillis(); - boolean timeout = false; - try { - learner.start(); - } catch (Exception e) { - if(e.getCause() instanceof SocketTimeoutException){ - timeout = true;throw e; + + int attempt = 0; + long startTime = 0; + boolean timeout = true; + while(timeout && attempt++ < maxAttempts){ + timeout = false; + if(attempt > 1){ + try { + Thread.sleep(delayInMilliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + System.out.println("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); + startTime = System.currentTimeMillis(); + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } else { + e.printStackTrace(); + } + } } + long runTime = System.currentTimeMillis() - startTime; List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if(timeout){ + if(timeout && learnedAxioms.isEmpty()){ writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); @@ -324,20 +384,36 @@ // learner.setPropertyToDescribe(property); // learner.setMaxExecutionTimeInSeconds(10); algName = AnnComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + property + " ... "); - long startTime = System.currentTimeMillis(); - boolean timeout = false; - try { - learner.start(); - } catch (Exception e) { - if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; + + int attempt = 0; + long startTime = 0; + boolean timeout = true; + while(timeout && attempt++ < maxAttempts){ + timeout = false; + if(attempt > 1){ + try { + Thread.sleep(delayInMilliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + System.out.println("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); + startTime = System.currentTimeMillis(); + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } else { + e.printStackTrace(); + } + } } + long runTime = System.currentTimeMillis() - startTime; List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - if(timeout){ + if(timeout && learnedAxioms.isEmpty()){ writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { writeToDB(property.toManchesterSyntaxString(baseURI, prefixes), algName, "NULL", 0, runTime, false); @@ -381,16 +457,32 @@ // learner.setPropertyToDescribe(property); // learner.setMaxExecutionTimeInSeconds(10); String algName = AnnComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + cls + " ... "); - long startTime = System.currentTimeMillis(); - boolean timeout = false; - try { - learner.start(); - } catch (Exception e) { - if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; + + int attempt = 0; + long startTime = 0; + boolean timeout = true; + while(timeout && attempt++ < maxAttempts){ + timeout = false; + if(attempt > 1){ + try { + Thread.sleep(delayInMilliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + System.out.println("Applying " + algName + " on " + cls + " ... (Attempt " + attempt + ")"); + startTime = System.currentTimeMillis(); + try { + learner.start(); + } catch (Exception e) { + if(e.getCause() instanceof SocketTimeoutException){ + timeout = true; + } else { + e.printStackTrace(); + } + } } + long runTime = System.currentTimeMillis() - startTime; List<EvaluatedAxiom> learnedAxioms = null; if(learner instanceof AxiomLearningAlgorithm){ @@ -436,13 +528,21 @@ } public void printResultsLaTeX() throws Exception{ - double threshold = 0.9; - List<Class<? extends LearningAlgorithm>> algorithms = new ArrayList<Class<? extends LearningAlgorithm>>(); algorithms.addAll(classAlgorithms); algorithms.addAll(objectPropertyAlgorithms); algorithms.addAll(dataPropertyAlgorithms); + //create view which contains only entries without TIMEOUT and NULL + PreparedStatement ps = conn.prepareStatement("CREATE OR REPLACE VIEW evaluation_cleaned AS (SELECT * FROM evaluation WHERE axiom != ? AND axiom != ?)"); + ps.setString(1, "NULL"); + ps.setString(2, "TIMEOUT"); + ps.execute(); + + StringBuilder table1 = new StringBuilder(); + table1.append("\\begin{tabulary}{\\textwidth}{LCCCCC}\\toprule\n"); + table1.append(" algorithm & Avg. \\#suggestions & Avg. runtime in ms & timeout in \\% & Avg. score & Avg. maximum score\\\\\\midrule\n"); + for(Class<? extends LearningAlgorithm> algo : algorithms){ String algoName = algo.getAnnotation(ComponentAnn.class).name(); @@ -470,12 +570,12 @@ int numberOfEntitiesWithTimeout = rs.getInt(1); //compute average number of suggestions above threshold - PreparedStatement ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); + ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); ps.setString(1, algoName); ps.setDouble(2, threshold); rs = ps.executeQuery(); rs.next(); - double avgSuggestionsAboveThreshold = rs.getDouble(1); + double avgSuggestionsAboveThreshold = round(rs.getDouble(1)); //compute average runtime ps = conn.prepareStatement("SELECT AVG(runtime) FROM (SELECT MAX(runtime_ms) AS runtime FROM evaluation WHERE algorithm=?) AS A"); @@ -485,38 +585,154 @@ double avgRuntimeInMilliseconds = rs.getDouble(1); //compute ratio for complete timeouts - double timeoutRatio = (double)numberOfEntitiesWithTimeout / overallNumberOfEntities; + double timeoutRatio = round((double)numberOfEntitiesWithTimeout / overallNumberOfEntities); //compute avg. score - ps = conn.prepareStatement("SELECT AVG(avg) FROM (SELECT AVG(score) AS avg FROM evaluation WHERE algorithm=? AND score >= ? GROUP BY entity) AS A"); + ps = conn.prepareStatement("SELECT AVG(avg) FROM (SELECT AVG(score) AS avg FROM evaluation_cleaned WHERE algorithm=? AND score >= ? GROUP BY entity) AS A"); ps.setString(1, algoName); ps.setDouble(2, threshold); rs = ps.executeQuery(); rs.next(); - double avgScore= rs.getDouble(1); + double avgScore = round(rs.getDouble(1)); //compute avg. max. score - ps = conn.prepareStatement("SELECT AVG(max) FROM (SELECT MAX(score) AS max FROM evaluation WHERE algorithm=? AND score>=? GROUP BY entity) AS A"); + ps = conn.prepareStatement("SELECT AVG(max) FROM (SELECT MAX(score) AS max FROM evaluation_cleaned WHERE algorithm=? AND score>=? GROUP BY entity) AS A"); ps.setString(1, algoName); ps.setDouble(2, threshold); rs = ps.executeQuery(); rs.next(); - double avgMaxScore = rs.getDouble(1); + double avgMaxScore = round(rs.getDouble(1)); System.out.println("###############"); System.out.println(algoName); System.out.println("Overall entities: " + overallNumberOfEntities); System.out.println("Overall entities with emtpy result: " + numberOfEntitiesWithEmptyResult); System.out.println("Overall entities with emtpy timeout: " + numberOfEntitiesWithTimeout); - System.out.println("Avg. #Suggestions above t: " + avgSuggestionsAboveThreshold); + System.out.println("Avg. \\#Suggestions above t: " + avgSuggestionsAboveThreshold); System.out.println("Avg. runtime in ms: " + avgRuntimeInMilliseconds); System.out.println("Timeout ratio: " + timeoutRatio); System.out.println("Avg. score: " + avgScore); System.out.println("Avg. max. score: " + avgMaxScore); + table1. + append(algoName.replace("learner", "").trim()).append(" & "). + append(avgSuggestionsAboveThreshold).append(" & "). + append(avgRuntimeInMilliseconds).append(" & "). + append(timeoutRatio).append(" & "). + append(avgScore).append(" & "). + append(avgMaxScore). + append("\\\\\n"); + } + table1.append("\\bottomrule\n\\end{tabulary}"); + System.out.println(table1.toString()); + + + //get all axiomtypes and corresponding algorithm + Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = new HashMap<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>>(); + axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class, CELOE.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{CELOE.class})); + axiomType2Algorithm.put(AxiomType.DISJOINT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DisjointClassesLearner.class})); + + axiomType2Algorithm.put(AxiomType.SUB_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubObjectPropertyOfAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_OBJECT_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyDomainAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyRangeAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.TRANSITIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{TransitiveObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseFunctionalObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.SYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SymmetricObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.REFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ReflexiveObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{IrreflexiveObjectPropertyAxiomLearner.class})); + + axiomType2Algorithm.put(AxiomType.SUB_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubDataPropertyOfAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_DATA_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentDataPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyDomainAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyRangeAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.FUNCTIONAL_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + + // get all entities in database because we compute recall only for axioms of entities which we have tested + // we use only entities for which triples in the endpoint are contained + java.sql.ResultSet rs = conn.prepareStatement("SELECT DISTINCT entity FROM evaluation WHERE axiom != 'NULL'").executeQuery(); + Set<OWLEntity> entities = new HashSet<OWLEntity>(); + IRI iri; + while(rs.next()){ + iri = IRI.create("http://dbpedia.org/ontology/" + rs.getString(1).substring(4)); + if(dbPediaOntology.containsClassInSignature(iri)){ + entities.add(factory.getOWLClass(iri)); + } else if(dbPediaOntology.containsObjectPropertyInSignature(iri)){ + entities.add(factory.getOWLObjectProperty(iri)); + } else if(dbPediaOntology.containsDataPropertyInSignature(iri)){ + entities.add(factory.getOWLDataProperty(iri)); + } + } + + //compute for each axiom type the recall + for(Entry<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> entry : axiomType2Algorithm.entrySet()){ + AxiomType<? extends OWLAxiom> type = entry.getKey(); + algorithms = entry.getValue(); + + int found = 0; + int all = 0; + for(OWLAxiom axiom : dbPediaOntology.getAxioms(type)){ + if(isRelevantAxiom(axiom, entities)){ + all++; + if(existsInDatabase(axiom)){ + found++; + } else { + System.out.println(axiom); + } + } + } + System.out.println(type.getName() + ": " + found + "/" + all); + } } + + private boolean isRelevantAxiom(OWLAxiom axiom, Set<OWLEntity> entities){ + if(axiom instanceof OWLObjectPropertyAxiom){ + return containsOneOf(axiom.getObjectPropertiesInSignature(), entities); + } else if(axiom instanceof OWLDataPropertyAxiom){ + return containsOneOf(axiom.getDataPropertiesInSignature(), entities); + } else if(axiom instanceof OWLSubClassOfAxiom){ + return entities.contains(((OWLSubClassOfAxiom) axiom).getSubClass()); + } else if(axiom instanceof OWLDisjointClassesAxiom){ + return containsOneOf(axiom.getClassesInSignature(), entities); + } + return false; + } + + private <T> boolean containsOneOf(Collection<? extends T> c1, Collection<? extends T> c2){ + for(T element : c2){ + if(c1.contains(element)){ + return true; + } + } + return false; + } + + private boolean existsInDatabase(OWLAxiom ax){ + //if axiom contains owl:Thing it is trivially contained, so we can return TRUE here + if(ax.getClassesInSignature().contains(factory.getOWLThing())){ + return true; + } + try { + Axiom axiom = DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(ax); + PreparedStatement ps = conn.prepareStatement("SELECT axiom FROM evaluation WHERE axiom = ?"); + ps.setString(1, axiom.toManchesterSyntaxString(baseURI, prefixes)); + ResultSet rs = ps.executeQuery(); + boolean exists = rs.next(); + ps.close(); + return exists; + } catch (SQLException e) { + e.printStackTrace(); + } + return false; + } + + private double round(double value){ + return Math.round( value * 100. ) / 100.; + } public String printHTMLTable() throws SQLException { StringBuffer sb = new StringBuffer(); @@ -579,7 +795,7 @@ public static void main(String[] args) throws Exception { EnrichmentEvaluation ee = new EnrichmentEvaluation(); -// ee.start(); + ee.start(); // ee.printResultsPlain(); ee.printResultsLaTeX(); Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-25 15:09:20
|
Revision: 3124 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3124&view=rev Author: lorenz_b Date: 2011-08-25 15:09:12 +0000 (Thu, 25 Aug 2011) Log Message: ----------- Continued eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-25 12:17:57 UTC (rev 3123) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-25 15:09:12 UTC (rev 3124) @@ -44,6 +44,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.Map.Entry; import java.util.Set; import java.util.prefs.Preferences; @@ -76,25 +78,42 @@ import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AbstractCELA; +import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; +import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; +import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.Score; import org.dllearner.core.config.ConfigHelper; +import org.dllearner.core.configurators.CELOEConfigurator; import org.dllearner.core.owl.Axiom; import org.dllearner.core.owl.DatatypeProperty; import org.dllearner.core.owl.DisjointClassesAxiom; +import org.dllearner.core.owl.EquivalentClassesAxiom; +import org.dllearner.core.owl.Individual; import org.dllearner.core.owl.NamedClass; import org.dllearner.core.owl.ObjectProperty; +import org.dllearner.core.owl.SubClassAxiom; import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; +import org.dllearner.kb.sparql.SparqlKnowledgeSource; import org.dllearner.learningproblems.AxiomScore; +import org.dllearner.learningproblems.ClassLearningProblem; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.Files; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.datastructures.SetManipulation; +import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL2; import org.dllearner.utilities.owl.DLLearnerAxiomConvertVisitor; import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; @@ -149,9 +168,9 @@ private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia();//getEndpointDBpediaLiveAKSW(); // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 3; - private int maxDataProperties = 3; - private int maxClasses = 3; + private int maxObjectProperties = 10; + private int maxDataProperties = 10; + private int maxClasses = 10; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -288,12 +307,12 @@ } - private void evaluateObjectProperties(SparqlEndpointKS ks)throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + private void evaluateObjectProperties(SparqlEndpointKS ks)throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<ObjectProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllObjectProperties(); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; - + Thread.sleep(10000); String algName = ""; for (ObjectProperty property : properties) { @@ -326,8 +345,9 @@ try { learner.start(); } catch (Exception e) { + timeout = true; if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; + } else { e.printStackTrace(); } @@ -364,12 +384,12 @@ } } - private void evaluateDataProperties(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + private void evaluateDataProperties(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<DatatypeProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { int dataProperties = 0; - + Thread.sleep(10000); String algName = ""; for (DatatypeProperty property : properties) { @@ -402,8 +422,9 @@ try { learner.start(); } catch (Exception e) { + timeout = true; if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; + } else { e.printStackTrace(); } @@ -439,11 +460,12 @@ } } - private void evaluateClasses(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException{ + private void evaluateClasses(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { int classesCnt = 0; + Thread.sleep(10000); for (NamedClass cls : classes) { try{ @@ -475,8 +497,9 @@ try { learner.start(); } catch (Exception e) { + timeout = true; if(e.getCause() instanceof SocketTimeoutException){ - timeout = true; + } else { e.printStackTrace(); } @@ -489,12 +512,7 @@ learnedAxioms = ((AxiomLearningAlgorithm)learner) .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); } else if(learner instanceof AbstractCELA){ - learnedAxioms = new ArrayList<EvaluatedAxiom>(); - List<? extends EvaluatedDescription> learnedDescriptions = ((AbstractCELA)learner).getCurrentlyBestEvaluatedDescriptions(nrOfAxiomsToLearn); - for(EvaluatedDescription learnedDescription : learnedDescriptions){ - //TODO create axioms and differ between equivalent and subclass mode in CELOE - learnedAxioms.add(new EvaluatedAxiom(null, new AxiomScore(learnedDescription.getAccuracy()))); - } + learnedAxioms = applyCELOE(ks, cls, false); } if(timeout && learnedAxioms.isEmpty()){ writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); @@ -522,7 +540,88 @@ } } } + + private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, NamedClass nc, boolean equivalence) throws ComponentInitException { + // get instances of class as positive examples + SPARQLReasoner sr = new SPARQLReasoner(ks); + SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + SortedSet<String> posExStr = Helper.getStringSet(posExamples); + + // get negative examples via various strategies + System.out.print("finding negatives ... "); + AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); + SortedSet<String> negExStr = finder.getNegativeExamples(nc.getName(), posExStr); + negExStr = SetManipulation.fuzzyShrink(negExStr, 20); + SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + + System.out.println("done (" + negExStr.size()+ ")"); + + ComponentManager cm = ComponentManager.getInstance(); + SparqlKnowledgeSource ks2 = cm.knowledgeSource(SparqlKnowledgeSource.class); + ks2.getConfigurator().setInstances(Datastructures.individualSetToStringSet(examples.getCompleteSet())); + ks2.getConfigurator().setUrl(ks.getEndpoint().getURL()); + ks2.getConfigurator().setDefaultGraphURIs(new TreeSet<String>(ks.getEndpoint().getDefaultGraphURIs())); + ks2.getConfigurator().setUseLits(false); + ks2.getConfigurator().setUseCacheDatabase(true); + ks2.getConfigurator().setRecursionDepth(2); + ks2.getConfigurator().setCloseAfterRecursion(true); +// ks2.getConfigurator().setSaveExtractedFragment(true); + System.out.println("getting fragment ... "); + ks2.init(); + System.out.println("done"); + + AbstractReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, ks2); + rc.init(); + + // TODO: super class learning + ClassLearningProblem lp = cm.learningProblem(ClassLearningProblem.class, rc); +// lp.setPositiveExamples(posExamples); +// lp.setNegativeExamples(negExamples); + try { + lp.getConfigurator().setClassToDescribe(nc.getURI().toURL()); + } catch (MalformedURLException e1) { + e1.printStackTrace(); + } + lp.getConfigurator().setType("equivalence"); + lp.getConfigurator().setAccuracyMethod("fmeasure"); + lp.getConfigurator().setUseApproximations(false); + lp.getConfigurator().setMaxExecutionTimeInSeconds(10); + lp.init(); + + CELOE la = null; + try { + la = cm.learningAlgorithm(CELOE.class, lp, rc); + } catch (LearningProblemUnsupportedException e) { + e.printStackTrace(); + } + CELOEConfigurator cc = la.getConfigurator(); + cc.setMaxExecutionTimeInSeconds(10); + cc.setNoisePercentage(25); + la.init(); + System.out.print("running CELOE ... "); + la.start(); + System.out.println("done"); + + // convert the result to axioms (to make it compatible with the other algorithms) + List<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(threshold); + List<EvaluatedAxiom> evaluatedAxioms = new LinkedList<EvaluatedAxiom>(); + for(EvaluatedDescription learnedDescription : learnedDescriptions) { + Axiom axiom; + if(equivalence) { + axiom = new EquivalentClassesAxiom(nc, learnedDescription.getDescription()); + } else { + axiom = new SubClassAxiom(nc, learnedDescription.getDescription()); + } + Score score = lp.computeScore(learnedDescription.getDescription()); + evaluatedAxioms.add(new EvaluatedAxiom(axiom, score)); + } + + cm.freeAllComponents(); + return evaluatedAxioms; + } + public void printResultsPlain() { } @@ -540,7 +639,7 @@ ps.execute(); StringBuilder table1 = new StringBuilder(); - table1.append("\\begin{tabulary}{\\textwidth}{LCCCCC}\\toprule\n"); + table1.append("\\begin{tabulary}{\\textwidth}{LRRRRR}\\toprule\n"); table1.append(" algorithm & Avg. \\#suggestions & Avg. runtime in ms & timeout in \\% & Avg. score & Avg. maximum score\\\\\\midrule\n"); for(Class<? extends LearningAlgorithm> algo : algorithms){ @@ -615,7 +714,7 @@ System.out.println("Avg. max. score: " + avgMaxScore); table1. - append(algoName.replace("learner", "").trim()).append(" & "). + append(algoName.replace("axiom learner", "").trim()).append(" & "). append(avgSuggestionsAboveThreshold).append(" & "). append(avgRuntimeInMilliseconds).append(" & "). append(timeoutRatio).append(" & "). @@ -624,33 +723,19 @@ append("\\\\\n"); } - table1.append("\\bottomrule\n\\end{tabulary}"); System.out.println(table1.toString()); - //get all axiomtypes and corresponding algorithm - Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = new HashMap<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>>(); - axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class, CELOE.class})); - axiomType2Algorithm.put(AxiomType.EQUIVALENT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{CELOE.class})); - axiomType2Algorithm.put(AxiomType.DISJOINT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DisjointClassesLearner.class})); + //second part of evaluation - axiomType2Algorithm.put(AxiomType.SUB_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubObjectPropertyOfAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.EQUIVALENT_OBJECT_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyDomainAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyRangeAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.TRANSITIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{TransitiveObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseFunctionalObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.SYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SymmetricObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.REFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ReflexiveObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{IrreflexiveObjectPropertyAxiomLearner.class})); + StringBuilder table2 = new StringBuilder(); + table2.append("\\begin{tabulary}{\\textwidth}{LCCCCC}\\toprule\n"); + table2.append("& & & \\multicolumn{3}{c}{Estimated precision} \\\\\n"); + table2.append(" axiom type & recall & additional axioms & no & maybe & yes \\\\\\midrule\n"); - axiomType2Algorithm.put(AxiomType.SUB_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubDataPropertyOfAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.EQUIVALENT_DATA_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentDataPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyDomainAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyRangeAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.FUNCTIONAL_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + //get all axiomtypes and corresponding algorithm + Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = getAxiomTypesWithLearningAlgorithms(); // get all entities in database because we compute recall only for axioms of entities which we have tested // we use only entities for which triples in the endpoint are contained @@ -668,7 +753,7 @@ } } - //compute for each axiom type the recall + //compute recall for each axiom type for(Entry<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> entry : axiomType2Algorithm.entrySet()){ AxiomType<? extends OWLAxiom> type = entry.getKey(); algorithms = entry.getValue(); @@ -685,10 +770,41 @@ } } } + table2. + append(type.getName()).append(" & "). + append(found + "/" + all ).append(" & & & & \\\\\n"); System.out.println(type.getName() + ": " + found + "/" + all); } + + table2.append("\\end{tabulary}"); + System.out.println(table2.toString()); } + private Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> getAxiomTypesWithLearningAlgorithms(){ + Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = new HashMap<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>>(); + axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class, CELOE.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{CELOE.class})); + axiomType2Algorithm.put(AxiomType.DISJOINT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DisjointClassesLearner.class})); + + axiomType2Algorithm.put(AxiomType.SUB_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubObjectPropertyOfAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_OBJECT_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyDomainAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyRangeAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.TRANSITIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{TransitiveObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseFunctionalObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.SYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SymmetricObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.REFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ReflexiveObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{IrreflexiveObjectPropertyAxiomLearner.class})); + + axiomType2Algorithm.put(AxiomType.SUB_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubDataPropertyOfAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.EQUIVALENT_DATA_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentDataPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyDomainAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.DATA_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DataPropertyRangeAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.FUNCTIONAL_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + return axiomType2Algorithm; + } + private boolean isRelevantAxiom(OWLAxiom axiom, Set<OWLEntity> entities){ if(axiom instanceof OWLObjectPropertyAxiom){ return containsOneOf(axiom.getObjectPropertiesInSignature(), entities); @@ -731,7 +847,7 @@ } private double round(double value){ - return Math.round( value * 100. ) / 100.; + return Math.round( value * 10. ) / 10.; } public String printHTMLTable() throws SQLException { @@ -793,9 +909,11 @@ } } - public static void main(String[] args) throws Exception { + public static void main(String[] args) throws Exception + + { EnrichmentEvaluation ee = new EnrichmentEvaluation(); - ee.start(); +// ee.start(); // ee.printResultsPlain(); ee.printResultsLaTeX(); Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-27 14:39:54
|
Revision: 3139 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3139&view=rev Author: lorenz_b Date: 2011-08-27 14:39:48 +0000 (Sat, 27 Aug 2011) Log Message: ----------- Added additional axiom column to table. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-27 12:12:38 UTC (rev 3138) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-27 14:39:48 UTC (rev 3139) @@ -50,6 +50,7 @@ import java.util.Set; import java.util.prefs.Preferences; +import org.apache.commons.collections.SetUtils; import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; @@ -702,17 +703,6 @@ rs.next(); double avgMaxScore = round(rs.getDouble(1)); - System.out.println("###############"); - System.out.println(algoName); - System.out.println("Overall entities: " + overallNumberOfEntities); - System.out.println("Overall entities with emtpy result: " + numberOfEntitiesWithEmptyResult); - System.out.println("Overall entities with emtpy timeout: " + numberOfEntitiesWithTimeout); - System.out.println("Avg. \\#Suggestions above t: " + avgSuggestionsAboveThreshold); - System.out.println("Avg. runtime in ms: " + avgRuntimeInMilliseconds); - System.out.println("Timeout ratio: " + timeoutRatio); - System.out.println("Avg. score: " + avgScore); - System.out.println("Avg. max. score: " + avgMaxScore); - table1. append(algoName.replace("axiom learner", "").trim()).append(" & "). append(avgSuggestionsAboveThreshold).append(" & "). @@ -753,27 +743,40 @@ } } + + //compute recall for each axiom type + ps = conn.prepareStatement("SELECT axiom FROM evaluation WHERE algorithm=? AND score>=?"); for(Entry<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> entry : axiomType2Algorithm.entrySet()){ AxiomType<? extends OWLAxiom> type = entry.getKey(); algorithms = entry.getValue(); - int found = 0; - int all = 0; - for(OWLAxiom axiom : dbPediaOntology.getAxioms(type)){ - if(isRelevantAxiom(axiom, entities)){ - all++; - if(existsInDatabase(axiom)){ - found++; - } else { - System.out.println(axiom); - } - } + ps.setString(1, algorithms.get(0).getAnnotation(ComponentAnn.class).name()); + ps.setDouble(2, threshold); + + //get all found axioms for specific axiom type + Set<String> foundAxioms = new TreeSet<String>(); + rs = ps.executeQuery(); + while(rs.next()){ + foundAxioms.add(rs.getString(1)); } + + + Set<String> relevantAxioms = getRelevantAxioms(type, entities); + + Set<String> notFoundAxioms = org.mindswap.pellet.utils.SetUtils.difference(relevantAxioms, foundAxioms); + + Set<String> additionalAxioms = org.mindswap.pellet.utils.SetUtils.difference(foundAxioms, relevantAxioms); + + int total = relevantAxioms.size(); + int found = total-notFoundAxioms.size(); + table2. append(type.getName()).append(" & "). - append(found + "/" + all ).append(" & & & & \\\\\n"); - System.out.println(type.getName() + ": " + found + "/" + all); + append( found + "/" + total ).append(" & "). + append(additionalAxioms.size()). + append(" & & & \\\\\n"); + System.out.println(type.getName() + ": " + found + "/" + total); } table2.append("\\end{tabulary}"); @@ -805,6 +808,19 @@ return axiomType2Algorithm; } + private Set<String> getRelevantAxioms(AxiomType<? extends OWLAxiom> axiomType, Set<OWLEntity> entities){ + Set<String> relevantAxioms = new HashSet<String>(); + for(OWLAxiom axiom : dbPediaOntology.getAxioms(axiomType)){ + if(!axiom.getClassesInSignature().contains(factory.getOWLThing())){ + if(isRelevantAxiom(axiom, entities)){ + String axiomString = DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(axiom).toManchesterSyntaxString(baseURI, prefixes); + relevantAxioms.add(axiomString); + } + } + } + return relevantAxioms; + } + private boolean isRelevantAxiom(OWLAxiom axiom, Set<OWLEntity> entities){ if(axiom instanceof OWLObjectPropertyAxiom){ return containsOneOf(axiom.getObjectPropertiesInSignature(), entities); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-29 09:11:44
|
Revision: 3157 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3157&view=rev Author: lorenz_b Date: 2011-08-29 09:11:38 +0000 (Mon, 29 Aug 2011) Log Message: ----------- Added method to get latest DBpedia ontology from SPARQL endpoint. Writing missed axioms into folder evaluation/missed/ and additional axioms into evaluation/additional/ . Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-29 08:52:56 UTC (rev 3156) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-29 09:11:38 UTC (rev 3157) @@ -21,6 +21,8 @@ import java.io.BufferedInputStream; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; @@ -50,6 +52,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import java.util.prefs.Preferences; @@ -131,12 +134,20 @@ import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; +import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import org.semanticweb.owlapi.reasoner.InferenceType; import org.semanticweb.owlapi.reasoner.OWLReasoner; +import org.semanticweb.owlapi.reasoner.ReasonerInterruptedException; +import org.semanticweb.owlapi.reasoner.TimeOutException; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory; +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.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; /** * Evaluation of enrichment algorithms on DBpedia (Live). @@ -171,7 +182,7 @@ // can be used to only evaluate a part of DBpedia private int maxObjectProperties = 10; private int maxDataProperties = 10; - private int maxClasses = 10; + private int maxClasses = 3; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -295,12 +306,12 @@ SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); - evaluateObjectProperties(ks); +// evaluateObjectProperties(ks); // // Thread.sleep(10000); - - evaluateDataProperties(ks); - +// +// evaluateDataProperties(ks); +// // Thread.sleep(10000); // evaluateClasses(ks); @@ -748,7 +759,7 @@ //compute recall for each axiom type - ps = conn.prepareStatement("SELECT axiom FROM evaluation WHERE algorithm=? AND score>=?"); + ps = conn.prepareStatement("SELECT axiom, entailed, score FROM evaluation WHERE algorithm=? AND score>=?"); for(Entry<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> entry : axiomType2Algorithm.entrySet()){ AxiomType<? extends OWLAxiom> type = entry.getKey(); algorithms = entry.getValue(); @@ -758,21 +769,35 @@ //get all found axioms for specific axiom type Set<String> foundAxioms = new TreeSet<String>(); + Map<String, Double> foundAndNotEntailedAxioms = new TreeMap<String, Double>(); rs = ps.executeQuery(); + String axiom; + boolean entailed; + double score; while(rs.next()){ - foundAxioms.add(rs.getString(1)); + axiom = rs.getString(1); + entailed = rs.getBoolean(2); + score = rs.getDouble(3); + + foundAxioms.add(axiom); + if(!entailed){ + foundAndNotEntailedAxioms.put(axiom, score); + } } - + //get all axioms in the reference ontology for a specific axiom type Set<String> relevantAxioms = getRelevantAxioms(type, entities); + //compute the axioms which are in the reference ontology, but not be computed by the learning algorithm + Set<String> missedAxioms = org.mindswap.pellet.utils.SetUtils.difference(relevantAxioms, foundAxioms); + System.out.println(missedAxioms); + //compute the additional found axioms which were not entailed + for(String relAxiom : relevantAxioms){ + foundAndNotEntailedAxioms.remove(relAxiom); + } + Set<String> additionalAxioms = foundAndNotEntailedAxioms.keySet(); - Set<String> notFoundAxioms = org.mindswap.pellet.utils.SetUtils.difference(relevantAxioms, foundAxioms); - System.out.println(notFoundAxioms); - - Set<String> additionalAxioms = org.mindswap.pellet.utils.SetUtils.difference(foundAxioms, relevantAxioms); - int total = relevantAxioms.size(); - int found = total-notFoundAxioms.size(); + int found = total - missedAxioms.size(); table2. append(type.getName()).append(" & "). @@ -782,22 +807,56 @@ System.out.println(type.getName() + ": " + found + "/" + total); - //write additional axioms into file - writeToDisk(type, additionalAxioms); + //write additional axioms with score into file + writeToDisk(type, foundAndNotEntailedAxioms); + //write missed axioms into file + writeToDisk(type, missedAxioms); } table2.append("\\end{tabulary}"); System.out.println(table2.toString()); } + private void writeToDisk(AxiomType<? extends OWLAxiom> axiomType, Map<String, Double> axiomsWithAccurracy){ + String fileName = axiomType.getName().replaceAll(" ", "_") + ".txt"; + + BufferedWriter out = null; + try { + File dir = new File("evaluation/additional"); + if(!dir.exists()){ + dir.mkdirs(); + } + + File file = new File(dir + File.separator + fileName); + if(!file.exists()){ + file.createNewFile(); + } + out = new BufferedWriter(new FileWriter(file)); + for(Entry<String, Double> entry : axiomsWithAccurracy.entrySet()){ + out.write(entry.getKey() + " (" + round(entry.getValue())*100 + "%)"); + out.newLine(); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if(out != null){ + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + private void writeToDisk(AxiomType<? extends OWLAxiom> axiomType, Set<String> axioms){ String fileName = axiomType.getName().replaceAll(" ", "_") + ".txt"; BufferedWriter out = null; try { - File dir = new File("evaluation"); + File dir = new File("evaluation/missed"); if(!dir.exists()){ - dir.mkdir(); + dir.mkdirs(); } File file = new File(dir + File.separator + fileName); @@ -963,6 +1022,41 @@ e.printStackTrace(); } } + + private void loadCurrentDBpediaOntology(){ + int limit = 1000; + int offset = 0; + String query = "CONSTRUCT {?s ?p ?o.} WHERE {?s ?p ?o} LIMIT %d OFFSET %d"; + Model model = ModelFactory.createDefaultModel(); + + QueryExecution qExec; + Model newModel; + boolean repeat = true; + while(repeat){ + repeat = false; + qExec = QueryExecutionFactory.sparqlService("http://live.dbpedia.org/sparql", QueryFactory.create(String.format(query, limit, offset)), "http://live.dbpedia.org/ontology"); + newModel = qExec.execConstruct(); + model.add(newModel); + repeat = newModel.size() > 0; + offset += limit; + } + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + model.write(baos, "RDF/XML"); + ByteArrayInputStream bs = new ByteArrayInputStream(baos.toByteArray()); + dbPediaOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(bs); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + } catch (TimeOutException e) { + e.printStackTrace(); + } catch (InconsistentOntologyException e) { + e.printStackTrace(); + } catch (ReasonerInterruptedException e) { + e.printStackTrace(); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } + } public static void main(String[] args) throws Exception This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-31 07:35:15
|
Revision: 3176 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3176&view=rev Author: lorenz_b Date: 2011-08-31 07:35:09 +0000 (Wed, 31 Aug 2011) Log Message: ----------- Small changes in script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-31 07:34:25 UTC (rev 3175) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-31 07:35:09 UTC (rev 3176) @@ -180,9 +180,9 @@ // private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 10; - private int maxDataProperties = 10; - private int maxClasses = 3; + private int maxObjectProperties = 20; + private int maxDataProperties = 0; + private int maxClasses = 0; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -226,10 +226,11 @@ dataPropertyAlgorithms.add(SubDataPropertyOfAxiomLearner.class); classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); - classAlgorithms.add(DisjointClassesLearner.class); +// classAlgorithms.add(CELOE.class); +// classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); -// classAlgorithms.add(CELOE.class); + initDBConnection(); loadDBpediaOntology(); } @@ -260,7 +261,7 @@ } } - private void dropAndCreateTable(){ + public void dropAndCreateTable(){ try { Statement s = conn.createStatement(); s.executeUpdate("DROP TABLE IF EXISTS evaluation"); @@ -296,24 +297,21 @@ public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException { - dropAndCreateTable(); +// dropAndCreateTable(); long overallStartTime = System.currentTimeMillis(); -// ComponentManager cm = ComponentManager.getInstance(); - // create DBpedia Live knowledge source - SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); // evaluateObjectProperties(ks); // -// Thread.sleep(10000); +// Thread.sleep(20000); // // evaluateDataProperties(ks); // -// Thread.sleep(10000); -// +// Thread.sleep(20000); + evaluateClasses(ks); System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); @@ -483,51 +481,58 @@ for (NamedClass cls : classes) { try{ - // dynamically invoke constructor with SPARQL knowledge source - LearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "classToDescribe", cls.toString()); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - // learner.setPropertyToDescribe(property); - // learner.setMaxExecutionTimeInSeconds(10); - String algName = AnnComponentManager.getName(learner); - - int attempt = 0; - long startTime = 0; - boolean timeout = true; - while(timeout && attempt++ < maxAttempts){ - timeout = false; - if(attempt > 1){ + List<EvaluatedAxiom> learnedAxioms = null; + long startTime = System.currentTimeMillis(); + boolean timeout = false; + String algName; + if(algorithmClass == CELOE.class){ + algName = CELOE.class.getSimpleName(); + System.out.println("Applying " + algName + " on " + cls + " ... "); + learnedAxioms = applyCELOE(ks, cls, false); + } else { + + // dynamically invoke constructor with SPARQL knowledge source + LearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "classToDescribe", cls.toString()); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + // learner.setPropertyToDescribe(property); + // learner.setMaxExecutionTimeInSeconds(10); + algName = AnnComponentManager.getName(learner); + int attempt = 0; + + timeout = true; + while(timeout && attempt++ < maxAttempts){ + timeout = false; + if(attempt > 1){ + try { + Thread.sleep(delayInMilliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + System.out.println("Applying " + algName + " on " + cls + " ... (Attempt " + attempt + ")"); + startTime = System.currentTimeMillis(); try { - Thread.sleep(delayInMilliseconds); - } catch (InterruptedException e) { - e.printStackTrace(); + learner.start(); + } catch (Exception e) { + timeout = true; + if(e.getCause() instanceof SocketTimeoutException){ + + } else { + e.printStackTrace(); + } } } - System.out.println("Applying " + algName + " on " + cls + " ... (Attempt " + attempt + ")"); - startTime = System.currentTimeMillis(); - try { - learner.start(); - } catch (Exception e) { - timeout = true; - if(e.getCause() instanceof SocketTimeoutException){ - - } else { - e.printStackTrace(); - } - } + learnedAxioms = ((AxiomLearningAlgorithm)learner) + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); } + long runTime = System.currentTimeMillis() - startTime; - List<EvaluatedAxiom> learnedAxioms = null; - if(learner instanceof AxiomLearningAlgorithm){ - learnedAxioms = ((AxiomLearningAlgorithm)learner) - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - } else if(learner instanceof AbstractCELA){ - learnedAxioms = applyCELOE(ks, cls, false); - } + if(timeout && learnedAxioms.isEmpty()){ writeToDB(cls.toManchesterSyntaxString(baseURI, prefixes), algName, "TIMEOUT", 0, runTime, false); } else if (learnedAxioms == null || learnedAxioms.isEmpty()) { @@ -1062,6 +1067,7 @@ { EnrichmentEvaluation ee = new EnrichmentEvaluation(); + ee.dropAndCreateTable(); ee.start(); // ee.printResultsPlain(); ee.printResultsLaTeX(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-31 13:52:47
|
Revision: 3189 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3189&view=rev Author: lorenz_b Date: 2011-08-31 13:52:41 +0000 (Wed, 31 Aug 2011) Log Message: ----------- Some small changes. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-31 13:52:34 UTC (rev 3188) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-31 13:52:41 UTC (rev 3189) @@ -123,6 +123,7 @@ import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; +import org.semanticweb.HermiT.Reasoner; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; @@ -181,7 +182,7 @@ // private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 20; + private int maxObjectProperties = 0; private int maxDataProperties = 0; private int maxClasses = 0; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; @@ -206,7 +207,7 @@ prefixes.put("yago", "http://dbpedia.org/class/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); +// objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); @@ -233,7 +234,7 @@ initDBConnection(); - loadDBpediaOntology(); + loadCurrentDBpediaOntology2(); } private void initDBConnection() { @@ -248,6 +249,9 @@ Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://" + dbServer + "/" + dbName; conn = DriverManager.getConnection(url, dbUser, dbPass); + + ps = conn.prepareStatement("INSERT INTO evaluation (" + + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (ClassNotFoundException e) { e.printStackTrace(); @@ -271,8 +275,6 @@ + "entity VARCHAR(200), algorithm VARCHAR(100), axiom VARCHAR(500), score DOUBLE, runtime_ms INT(20), entailed BOOLEAN)"); s.close(); - ps = conn.prepareStatement("INSERT INTO evaluation (" - + "entity, algorithm, axiom, score, runtime_ms, entailed ) " + "VALUES(?,?,?,?,?,?)"); } catch (SQLException e) { e.printStackTrace(); } @@ -308,7 +310,7 @@ // evaluateObjectProperties(ks); // // Thread.sleep(20000); -// + // evaluateDataProperties(ks); // // Thread.sleep(20000); @@ -1006,6 +1008,8 @@ private boolean isEntailed(EvaluatedAxiom evalAxiom){ OWLAxiom axiom = OWLAPIConverter.getOWLAPIAxiom(evalAxiom.getAxiom()); boolean entailed = reasoner.isEntailed(axiom); +// System.out.println(evalAxiom.getAxiom().toManchesterSyntaxString(baseURI, prefixes)); +// System.out.println(entailed); return entailed; } @@ -1049,21 +1053,41 @@ offset += limit; } try { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - model.write(baos, "RDF/XML"); - ByteArrayInputStream bs = new ByteArrayInputStream(baos.toByteArray()); - dbPediaOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(bs); + dbPediaOntology = convert(model); reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + System.out.println(reasoner.getSuperClasses( + factory.getOWLClass(IRI.create("http://dbpedia.org/ontology/Actor")), false).getFlattened()); } catch (TimeOutException e) { e.printStackTrace(); } catch (InconsistentOntologyException e) { e.printStackTrace(); } catch (ReasonerInterruptedException e) { e.printStackTrace(); + } + } + + private void loadCurrentDBpediaOntology2(){ + System.out.println("Loading schema ..."); + SPARQLReasoner r = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + dbPediaOntology = convert(r.loadSchema()); + System.out.println("Preparing reasoner ..."); + reasoner = new Reasoner(dbPediaOntology); +// reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); + reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + } + + private OWLOntology convert(Model model){ + OWLOntology ontology = null; + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + model.write(baos, "RDF/XML"); + ByteArrayInputStream bs = new ByteArrayInputStream(baos.toByteArray()); + ontology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(bs); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } + return ontology; } public static void main(String[] args) throws Exception This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-01 06:46:27
|
Revision: 3204 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3204&view=rev Author: lorenz_b Date: 2011-09-01 06:46:21 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Change: Write only the best 100 axioms for each type into file. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-09-01 04:22:12 UTC (rev 3203) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-09-01 06:46:21 UTC (rev 3204) @@ -43,6 +43,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -217,7 +219,7 @@ objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); - dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); +// dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); @@ -486,7 +488,7 @@ boolean timeout = false; String algName; if(algorithmClass == CELOE.class){ - algName = CELOE.class.getSimpleName(); + algName = CELOE.class.getAnnotation(ComponentAnn.class).name(); System.out.println("Applying " + algName + " on " + cls + " ... "); learnedAxioms = applyCELOE(ks, cls, false); } else { @@ -839,9 +841,16 @@ file.createNewFile(); } out = new BufferedWriter(new FileWriter(file)); - for(Entry<String, Double> entry : axiomsWithAccurracy.entrySet()){ + + //sort by values and write only the first 100 + int i = 0; + for(Entry<String, Double> entry : sortByValues(axiomsWithAccurracy)){ + i++; out.write(entry.getKey() + " (" + round(entry.getValue())*100 + "%)"); out.newLine(); + if(i == 100){ + break; + } } } catch (IOException e) { e.printStackTrace(); @@ -888,6 +897,18 @@ } } + protected <K, V extends Comparable<V>> List<Entry<K, V>> sortByValues(Map<K, V> map){ + List<Entry<K, V>> entries = new ArrayList<Entry<K, V>>(map.entrySet()); + Collections.sort(entries, new Comparator<Entry<K, V>>() { + + @Override + public int compare(Entry<K, V> o1, Entry<K, V> o2) { + return o2.getValue().compareTo(o1.getValue()); + } + }); + return entries; + } + private Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> getAxiomTypesWithLearningAlgorithms(){ Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = new LinkedHashMap<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>>(); axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class, CELOE.class})); @@ -899,7 +920,7 @@ axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_DOMAIN, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyDomainAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.OBJECT_PROPERTY_RANGE, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ObjectPropertyRangeAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.TRANSITIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{TransitiveObjectPropertyAxiomLearner.class})); - axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalDataPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseFunctionalObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.SYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SymmetricObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.REFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ReflexiveObjectPropertyAxiomLearner.class})); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-04-30 10:17:52
|
Revision: 3670 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3670&view=rev Author: lorenz_b Date: 2012-04-30 10:17:46 +0000 (Mon, 30 Apr 2012) Log Message: ----------- Modified eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-04-30 09:04:11 UTC (rev 3669) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-04-30 10:17:46 UTC (rev 3670) @@ -84,6 +84,7 @@ import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; +import org.dllearner.core.AbstractAxiomLearningAlgorithm; import org.dllearner.core.AbstractReasonerComponent; import org.dllearner.core.AnnComponentManager; import org.dllearner.core.AxiomLearningAlgorithm; @@ -306,15 +307,15 @@ SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); -// evaluateObjectProperties(ks); -// -// Thread.sleep(20000); + evaluateObjectProperties(ks); + Thread.sleep(20000); + // evaluateDataProperties(ks); // // Thread.sleep(20000); - evaluateClasses(ks); +// evaluateClasses(ks); System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); @@ -344,8 +345,7 @@ int attempt = 0; long startTime = 0; boolean timeout = true; - while(timeout && attempt++ < maxAttempts){ - timeout = false; + while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { System.out.println("Got timeout. Waiting " + delayInMilliseconds + " ms ..."); @@ -358,8 +358,8 @@ startTime = System.currentTimeMillis(); try { learner.start(); + timeout = false; } catch (Exception e) { - timeout = true; if(e.getCause() instanceof SocketTimeoutException){ } else { @@ -422,8 +422,7 @@ int attempt = 0; long startTime = 0; boolean timeout = true; - while(timeout && attempt++ < maxAttempts){ - timeout = false; + while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { Thread.sleep(delayInMilliseconds); @@ -435,8 +434,8 @@ startTime = System.currentTimeMillis(); try { learner.start(); + timeout = false; } catch (Exception e) { - timeout = true; if(e.getCause() instanceof SocketTimeoutException){ } else { @@ -506,8 +505,7 @@ int attempt = 0; timeout = true; - while(timeout && attempt++ < maxAttempts){ - timeout = false; + while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { Thread.sleep(delayInMilliseconds); @@ -519,17 +517,12 @@ startTime = System.currentTimeMillis(); try { learner.start(); + timeout = false; } catch (Exception e) { - timeout = true; - if(e.getCause() instanceof SocketTimeoutException){ - - } else { - e.printStackTrace(); - } + e.printStackTrace(); } } - learnedAxioms = ((AxiomLearningAlgorithm)learner) - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + learnedAxioms = ((AxiomLearningAlgorithm)learner).getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); } @@ -1090,8 +1083,8 @@ SPARQLReasoner r = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); dbPediaOntology = convert(r.loadSchema()); System.out.println("Preparing reasoner ..."); - reasoner = new Reasoner(dbPediaOntology); -// reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); +// reasoner = new Reasoner(dbPediaOntology); + reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-04-30 11:59:37
|
Revision: 3672 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3672&view=rev Author: lorenz_b Date: 2012-04-30 11:59:31 +0000 (Mon, 30 Apr 2012) Log Message: ----------- Modified eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-04-30 10:19:21 UTC (rev 3671) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-04-30 11:59:31 UTC (rev 3672) @@ -24,7 +24,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -125,6 +127,7 @@ import org.ini4j.InvalidFileFormatException; import org.semanticweb.HermiT.Reasoner; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; @@ -135,6 +138,7 @@ import org.semanticweb.owlapi.model.OWLObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; import org.semanticweb.owlapi.reasoner.InconsistentOntologyException; import org.semanticweb.owlapi.reasoner.InferenceType; @@ -178,7 +182,7 @@ // only axioms with a score above this threshold will be considered private double threshold = 0.7; - private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpediaLiveAKSW(); + private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); // private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); // can be used to only evaluate a part of DBpedia @@ -229,7 +233,7 @@ classAlgorithms = new LinkedList<Class<? extends LearningAlgorithm>>(); // classAlgorithms.add(CELOE.class); -// classAlgorithms.add(DisjointClassesLearner.class); + classAlgorithms.add(DisjointClassesLearner.class); classAlgorithms.add(SimpleSubclassLearner.class); @@ -307,7 +311,7 @@ SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); - evaluateObjectProperties(ks); +// evaluateObjectProperties(ks); Thread.sleep(20000); @@ -315,7 +319,7 @@ // // Thread.sleep(20000); -// evaluateClasses(ks); + evaluateClasses(ks); System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); @@ -1079,9 +1083,30 @@ } private void loadCurrentDBpediaOntology2(){ - System.out.println("Loading schema ..."); - SPARQLReasoner r = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); - dbPediaOntology = convert(r.loadSchema()); + dbPediaOntology = null; + try { + dbPediaOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new FileInputStream(new File("evaluation/currentDBpediaSchema.owl"))); + } catch (OWLOntologyCreationException e1) { + e1.printStackTrace(); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + if(dbPediaOntology == null){ + System.out.println("Loading schema ..."); + SPARQLReasoner r = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); + dbPediaOntology = convert(r.loadSchema()); + try { + new File("evaluation").mkdir(); + new File("evaluation/currentDBpediaSchema.owl").createNewFile(); + OWLManager.createOWLOntologyManager().saveOntology(dbPediaOntology, new RDFXMLOntologyFormat(), new FileOutputStream(new File("evaluation/currentDBpediaSchema.owl"))); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } System.out.println("Preparing reasoner ..."); // reasoner = new Reasoner(dbPediaOntology); reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-02 09:27:00
|
Revision: 3674 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3674&view=rev Author: lorenz_b Date: 2012-05-02 09:26:50 +0000 (Wed, 02 May 2012) Log Message: ----------- Made script more flexible from command line and added algorithms. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-01 07:53:23 UTC (rev 3673) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-02 09:26:50 UTC (rev 3674) @@ -19,7 +19,10 @@ */ package org.dllearner.scripts.evaluation; +import static java.util.Arrays.asList; + import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -31,9 +34,11 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketTimeoutException; +import java.net.URI; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; @@ -60,6 +65,10 @@ import java.util.TreeSet; import java.util.prefs.Preferences; +import joptsimple.OptionException; +import joptsimple.OptionParser; +import joptsimple.OptionSet; + import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; @@ -70,14 +79,17 @@ import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.celoe.CELOE; +import org.dllearner.algorithms.properties.AsymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.DataPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.DisjointDataPropertyAxiomLearner; +import org.dllearner.algorithms.properties.DisjointObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.EquivalentDataPropertyAxiomLearner; import org.dllearner.algorithms.properties.EquivalentObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalDataPropertyAxiomLearner; import org.dllearner.algorithms.properties.FunctionalObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.InverseFunctionalObjectPropertyAxiomLearner; +import org.dllearner.algorithms.properties.InverseObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.IrreflexiveObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.ObjectPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; @@ -107,6 +119,7 @@ import org.dllearner.core.owl.ObjectProperty; import org.dllearner.core.owl.SubClassAxiom; import org.dllearner.kb.SparqlEndpointKS; +import org.dllearner.kb.sparql.ExtractionDBCache; import org.dllearner.kb.sparql.SPARQLTasks; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlKnowledgeSource; @@ -125,7 +138,6 @@ import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; -import org.semanticweb.HermiT.Reasoner; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; @@ -182,13 +194,12 @@ // only axioms with a score above this threshold will be considered private double threshold = 0.7; - private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); -// private SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); + private SparqlEndpoint endpoint; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 0; - private int maxDataProperties = 0; - private int maxClasses = 0; + private int maxObjectProperties = 1; + private int maxDataProperties = 1; + private int maxClasses = 1; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -202,16 +213,19 @@ private OWLOntology dbPediaOntology; private OWLReasoner reasoner; private OWLDataFactory factory = new OWLDataFactoryImpl(); - - public EnrichmentEvaluation() { - + + private SPARQLReasoner sparqlReasoner; + + public EnrichmentEvaluation(SparqlEndpoint endpoint) { + this.endpoint = endpoint; + prefixes = new HashMap<String,String>(); prefixes.put("dbp","http://dbpedia.org/property/"); prefixes.put("dbo","http://dbpedia.org/ontology/"); prefixes.put("yago", "http://dbpedia.org/class/"); objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(DisjointObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(EquivalentObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(FunctionalObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(InverseFunctionalObjectPropertyAxiomLearner.class); @@ -219,12 +233,14 @@ objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(AsymmetricObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(InverseObjectPropertyAxiomLearner.class); dataPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); -// dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(DisjointDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(EquivalentDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(FunctionalDataPropertyAxiomLearner.class); dataPropertyAlgorithms.add(DataPropertyDomainAxiomLearner.class); @@ -301,26 +317,36 @@ } - public void start() throws IllegalArgumentException, SecurityException, InstantiationException, + public void start(boolean runClassAlgorithms, boolean runObjectPropertyAlgorithms, boolean runDataPropertyAlgorithms) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException { -// dropAndCreateTable(); long overallStartTime = System.currentTimeMillis(); SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); ks.init(); -// evaluateObjectProperties(ks); + sparqlReasoner = new SPARQLReasoner(ks); + sparqlReasoner.setCache(new ExtractionDBCache("cache")); + sparqlReasoner.prepareSubsumptionHierarchy(); Thread.sleep(20000); + if(runClassAlgorithms){ + evaluateClasses(ks); + } -// evaluateDataProperties(ks); -// -// Thread.sleep(20000); + Thread.sleep(20000); - evaluateClasses(ks); + if(runObjectPropertyAlgorithms){ + evaluateObjectProperties(ks); + } + Thread.sleep(20000); + + if(runDataPropertyAlgorithms){ + evaluateDataProperties(ks); + } + System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); } @@ -338,6 +364,7 @@ // dynamically invoke constructor with SPARQL knowledge source AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); + ((AbstractAxiomLearningAlgorithm)learner).setReasoner(sparqlReasoner); ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); @@ -390,7 +417,7 @@ } } objectProperties++; - if (maxObjectProperties != 0 && objectProperties > maxObjectProperties) { + if (maxObjectProperties != 0 && objectProperties == maxObjectProperties) { break; } @@ -410,11 +437,12 @@ Thread.sleep(10000); String algName = ""; for (DatatypeProperty property : properties) { - + Thread.sleep(1000); try{ // dynamically invoke constructor with SPARQL knowledge source AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); + ((AbstractAxiomLearningAlgorithm)learner).setReasoner(sparqlReasoner); ConfigHelper.configure(learner, "propertyToDescribe", property.toString()); ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); @@ -466,7 +494,7 @@ } } dataProperties++; - if (maxDataProperties != 0 && dataProperties > maxDataProperties) { + if (maxDataProperties != 0 && dataProperties == maxDataProperties) { break; } @@ -499,6 +527,7 @@ // dynamically invoke constructor with SPARQL knowledge source LearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); + ((AbstractAxiomLearningAlgorithm)learner).setReasoner(sparqlReasoner); ConfigHelper.configure(learner, "classToDescribe", cls.toString()); ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); @@ -548,7 +577,7 @@ } classesCnt++; - if (maxClasses != 0 && classesCnt > maxClasses) { + if (maxClasses != 0 && classesCnt == maxClasses) { break; } @@ -689,7 +718,7 @@ int numberOfEntitiesWithTimeout = rs.getInt(1); //compute average number of suggestions above threshold - ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); + ps = conn.prepareStatement("SELECT AVG(cnt) FROM (SELECT entity, COUNT(DISTINCT axiom) AS cnt FROM (SELECT * FROM evaluation WHERE algorithm=? AND score >=?) AS A GROUP BY entity) AS B"); ps.setString(1, algoName); ps.setDouble(2, threshold); rs = ps.executeQuery(); @@ -734,6 +763,7 @@ } table1.append("\\bottomrule\n\\end{tabulary}"); System.out.println(table1.toString()); + write2Disk(table1.toString(), "evaluation/table1.tex"); //second part of evaluation @@ -821,6 +851,7 @@ table2.append("\\end{tabulary}"); System.out.println(table2.toString()); + write2Disk(table2.toString(), "evaluation/table2.tex"); } private void writeToDisk(AxiomType<? extends OWLAxiom> axiomType, Map<String, Double> axiomsWithAccurracy){ @@ -862,6 +893,19 @@ } } + private void write2Disk(String content, String file){ + try { + new File(file).createNewFile(); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + bos.write(content.getBytes()); + bos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + private void writeToDisk(AxiomType<? extends OWLAxiom> axiomType, Set<String> axioms){ String fileName = axiomType.getName().replaceAll(" ", "_") + ".txt"; @@ -920,8 +964,10 @@ axiomType2Algorithm.put(AxiomType.FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{FunctionalObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.INVERSE_FUNCTIONAL_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseFunctionalObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.SYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SymmetricObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.ASYMMETRIC_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{AsymmetricObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.REFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{ReflexiveObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.IRREFLEXIVE_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{IrreflexiveObjectPropertyAxiomLearner.class})); + axiomType2Algorithm.put(AxiomType.INVERSE_OBJECT_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{InverseObjectPropertyAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.SUB_DATA_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubDataPropertyOfAxiomLearner.class})); axiomType2Algorithm.put(AxiomType.EQUIVALENT_DATA_PROPERTIES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{EquivalentDataPropertyAxiomLearner.class})); @@ -1127,18 +1173,99 @@ } public static void main(String[] args) throws Exception - + { - EnrichmentEvaluation ee = new EnrichmentEvaluation(); - ee.dropAndCreateTable(); - ee.start(); - // ee.printResultsPlain(); - ee.printResultsLaTeX(); - Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); - FileAppender app = new FileAppender(new SimpleLayout(), "log/enrichmentEvalErrors.log"); - Logger.getRootLogger().setLevel(Level.ERROR); - Logger.getRootLogger().removeAllAppenders(); - Logger.getRootLogger().addAppender(app); + OptionParser parser = new OptionParser(); + parser.acceptsAll(asList("h", "?", "help"), "Show help."); + parser.acceptsAll(asList("e", "endpoint"), + "SPARQL endpoint URL to be used.").withRequiredArg() + .ofType(URL.class); + parser.acceptsAll(asList("g", "graph"), + "URI of default graph for queries on SPARQL endpoint.") + .withOptionalArg().ofType(URI.class); + parser.acceptsAll(asList("c", "classes"), + "Run class axiom algorithms") + .withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("o", "objectProperties"), + "Run object property axiom algorithms") + .withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("d", "dataProperties"), + "Run data property axiom algorithms") + .withOptionalArg().ofType(Boolean.class).defaultsTo(true); + parser.acceptsAll(asList("drop"), + "Drop and create tables where data for evaluation is stored.") + .withOptionalArg().ofType(Boolean.class).defaultsTo(false); + + + // parse options and display a message for the user in case of problems + OptionSet options = null; + try { + options = parser.parse(args); + } catch (Exception e) { + System.out.println("Error: " + e.getMessage() + + ". Use -? to get help."); + System.exit(0); + } + + // print help screen + if (options.has("?")) { + parser.printHelpOn(System.out); + // main script + } else { + // check that endpoint was specified + if (!options.hasArgument("endpoint")) { + System.out + .println("Please specify a SPARQL endpoint (using the -e option)."); + System.exit(0); + } + + // create SPARQL endpoint object (check that indeed a URL was given) + URL endpoint = null; + try { + endpoint = (URL) options.valueOf("endpoint"); + } catch (OptionException e) { + System.out + .println("The specified endpoint appears not to be a proper URL."); + System.exit(0); + } + URI graph = null; + try { + graph = (URI) options.valueOf("graph"); + } catch (OptionException e) { + System.out + .println("The specified graph appears not to be a proper URL."); + System.exit(0); + } + + LinkedList<String> defaultGraphURIs = new LinkedList<String>(); + if (graph != null) { + defaultGraphURIs.add(graph.toString()); + } + + SparqlEndpoint se = new SparqlEndpoint(endpoint, defaultGraphURIs, + new LinkedList<String>()); + + boolean runClassAlgorithms = (Boolean) options.valueOf("classes"); + boolean runObjectPropertyAlgorithms = (Boolean) options.valueOf("objectProperties"); + boolean runDataPropertyAlgorithms = (Boolean) options.valueOf("dataProperties"); + + boolean dropTables = (Boolean) options.valueOf("drop"); + + EnrichmentEvaluation ee = new EnrichmentEvaluation(se); + if(dropTables){ + ee.dropAndCreateTable(); + } + ee.start(runClassAlgorithms, runObjectPropertyAlgorithms, runDataPropertyAlgorithms); + // ee.printResultsPlain(); + ee.printResultsLaTeX(); + Files.createFile(new File("enrichment_eval.html"), + ee.printHTMLTable()); + FileAppender app = new FileAppender(new SimpleLayout(), + "log/enrichmentEvalErrors.log"); + Logger.getRootLogger().setLevel(Level.ERROR); + Logger.getRootLogger().removeAllAppenders(); + Logger.getRootLogger().addAppender(app); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-02 15:00:26
|
Revision: 3676 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3676&view=rev Author: lorenz_b Date: 2012-05-02 14:53:12 +0000 (Wed, 02 May 2012) Log Message: ----------- Modified eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-02 14:52:45 UTC (rev 3675) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-02 14:53:12 UTC (rev 3676) @@ -197,9 +197,9 @@ private SparqlEndpoint endpoint; // can be used to only evaluate a part of DBpedia - private int maxObjectProperties = 1; - private int maxDataProperties = 1; - private int maxClasses = 1; + private int maxObjectProperties = 0; + private int maxDataProperties = 0; + private int maxClasses = 0; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; @@ -328,7 +328,9 @@ sparqlReasoner = new SPARQLReasoner(ks); sparqlReasoner.setCache(new ExtractionDBCache("cache")); + sparqlReasoner.setUseCache(true); sparqlReasoner.prepareSubsumptionHierarchy(); + sparqlReasoner.precomputeClassPopularity(); Thread.sleep(20000); if(runClassAlgorithms){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-02 20:44:14
|
Revision: 3679 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3679&view=rev Author: lorenz_b Date: 2012-05-02 20:44:08 +0000 (Wed, 02 May 2012) Log Message: ----------- Small modification to avoid loading YAGO schema. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-02 20:44:00 UTC (rev 3678) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-02 20:44:08 UTC (rev 3679) @@ -34,7 +34,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.SocketTimeoutException; @@ -138,6 +137,9 @@ import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; +import org.semanticweb.HermiT.Configuration; +import org.semanticweb.HermiT.Reasoner; +import org.semanticweb.HermiT.examples.HermiTConfigurations; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; @@ -1156,7 +1158,9 @@ } } System.out.println("Preparing reasoner ..."); -// reasoner = new Reasoner(dbPediaOntology); +// Configuration conf = new Configuration(); +// conf.ignoreUnsupportedDatatypes = true; +// reasoner = new Reasoner(conf, dbPediaOntology); reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2012-05-03 14:43:15
|
Revision: 3684 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3684&view=rev Author: lorenz_b Date: 2012-05-03 14:43:04 +0000 (Thu, 03 May 2012) Log Message: ----------- Modified eval script. Modified Paths: -------------- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Modified: trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java =================================================================== --- trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-03 14:42:31 UTC (rev 3683) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2012-05-03 14:43:04 UTC (rev 3684) @@ -71,6 +71,7 @@ import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.apache.log4j.ConsoleAppender; import org.apache.log4j.FileAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -137,18 +138,18 @@ import org.dllearner.utilities.owl.OWLAPIConverter; import org.ini4j.IniPreferences; import org.ini4j.InvalidFileFormatException; -import org.semanticweb.HermiT.Configuration; -import org.semanticweb.HermiT.Reasoner; -import org.semanticweb.HermiT.examples.HermiTConfigurations; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.model.AxiomType; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLDataProperty; import org.semanticweb.owlapi.model.OWLDataPropertyAxiom; import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; import org.semanticweb.owlapi.model.OWLEntity; +import org.semanticweb.owlapi.model.OWLObjectProperty; import org.semanticweb.owlapi.model.OWLObjectPropertyAxiom; import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; @@ -332,35 +333,33 @@ sparqlReasoner.setCache(new ExtractionDBCache("cache")); sparqlReasoner.setUseCache(true); sparqlReasoner.prepareSubsumptionHierarchy(); - sparqlReasoner.precomputeClassPopularity(); + sparqlReasoner.precomputePopularity(); - Thread.sleep(20000); if(runClassAlgorithms){ evaluateClasses(ks); + Thread.sleep(20000); } - Thread.sleep(20000); - if(runObjectPropertyAlgorithms){ evaluateObjectProperties(ks); + Thread.sleep(20000); } - Thread.sleep(20000); - if(runDataPropertyAlgorithms){ evaluateDataProperties(ks); } - System.out.println("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); + logger.info("Overall runtime: " + (System.currentTimeMillis()-overallStartTime)/1000 + "s."); } private void evaluateObjectProperties(SparqlEndpointKS ks)throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<ObjectProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllObjectProperties(); + logger.info("Evaluating " + properties.size() + " object properties..."); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; - Thread.sleep(10000); + Thread.sleep(5000); String algName = ""; for (ObjectProperty property : properties) { @@ -383,13 +382,13 @@ while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { - System.out.println("Got timeout. Waiting " + delayInMilliseconds + " ms ..."); + logger.warn("Got timeout. Waiting " + delayInMilliseconds + " ms ..."); Thread.sleep(delayInMilliseconds); } catch (InterruptedException e) { e.printStackTrace(); } } - System.out.println("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); + logger.info("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); startTime = System.currentTimeMillis(); try { learner.start(); @@ -435,10 +434,10 @@ private void evaluateDataProperties(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<DatatypeProperty> properties = new SPARQLTasks(ks.getEndpoint()).getAllDataProperties(); - + logger.info("Evaluating " + properties.size() + " data properties..."); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { int dataProperties = 0; - Thread.sleep(10000); + Thread.sleep(5000); String algName = ""; for (DatatypeProperty property : properties) { Thread.sleep(1000); @@ -461,12 +460,13 @@ while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { + logger.warn("Got timeout. Waiting " + delayInMilliseconds + " ms ..."); Thread.sleep(delayInMilliseconds); } catch (InterruptedException e) { e.printStackTrace(); } } - System.out.println("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); + logger.info("Applying " + algName + " on " + property + " ... (Attempt " + attempt + ")"); startTime = System.currentTimeMillis(); try { learner.start(); @@ -511,10 +511,10 @@ private void evaluateClasses(SparqlEndpointKS ks) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException, InterruptedException{ Set<NamedClass> classes = new SPARQLTasks(ks.getEndpoint()).getAllClasses(); - + logger.info("Evaluating " + classes.size() + " classes..."); for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { int classesCnt = 0; - Thread.sleep(10000); + Thread.sleep(5000); for (NamedClass cls : classes) { try{ @@ -524,7 +524,7 @@ String algName; if(algorithmClass == CELOE.class){ algName = CELOE.class.getAnnotation(ComponentAnn.class).name(); - System.out.println("Applying " + algName + " on " + cls + " ... "); + logger.info("Applying " + algName + " on " + cls + " ... "); learnedAxioms = applyCELOE(ks, cls, false); } else { @@ -545,12 +545,13 @@ while(((AbstractAxiomLearningAlgorithm)learner).isTimeout() && attempt++ < maxAttempts){ if(attempt > 1){ try { + logger.warn("Got timeout. Waiting " + delayInMilliseconds + " ms ..."); Thread.sleep(delayInMilliseconds); } catch (InterruptedException e) { e.printStackTrace(); } } - System.out.println("Applying " + algName + " on " + cls + " ... (Attempt " + attempt + ")"); + logger.info("Applying " + algName + " on " + cls + " ... (Attempt " + attempt + ")"); startTime = System.currentTimeMillis(); try { learner.start(); @@ -783,16 +784,22 @@ // get all entities in database because we compute recall only for axioms of entities which we have tested // we use only entities for which triples in the endpoint are contained java.sql.ResultSet rs = conn.prepareStatement("SELECT DISTINCT entity FROM evaluation WHERE axiom != 'NULL'").executeQuery(); - Set<OWLEntity> entities = new HashSet<OWLEntity>(); + Set<OWLEntity> allEntities = new HashSet<OWLEntity>(); + Set<OWLEntity> classes = new HashSet<OWLEntity>(); + Set<OWLEntity> objectProperties = new HashSet<OWLEntity>(); + Set<OWLEntity> dataProperties = new HashSet<OWLEntity>(); IRI iri; while(rs.next()){ iri = IRI.create("http://dbpedia.org/ontology/" + rs.getString(1).substring(4)); if(dbPediaOntology.containsClassInSignature(iri)){ - entities.add(factory.getOWLClass(iri)); + allEntities.add(factory.getOWLClass(iri)); + classes.add(factory.getOWLClass(iri)); } else if(dbPediaOntology.containsObjectPropertyInSignature(iri)){ - entities.add(factory.getOWLObjectProperty(iri)); + allEntities.add(factory.getOWLObjectProperty(iri)); + objectProperties.add(factory.getOWLObjectProperty(iri)); } else if(dbPediaOntology.containsDataPropertyInSignature(iri)){ - entities.add(factory.getOWLDataProperty(iri)); + allEntities.add(factory.getOWLDataProperty(iri)); + dataProperties.add(factory.getOWLDataProperty(iri)); } } @@ -800,9 +807,17 @@ //compute recall for each axiom type ps = conn.prepareStatement("SELECT axiom, entailed, score FROM evaluation WHERE algorithm=? AND score>=?"); + Set<OWLEntity> entities = null; for(Entry<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> entry : axiomType2Algorithm.entrySet()){ AxiomType<? extends OWLAxiom> type = entry.getKey(); algorithms = entry.getValue(); + if(classAlgorithms.containsAll(algorithms)){ + entities = classes; + } else if(objectPropertyAlgorithms.containsAll(algorithms)){ + entities = objectProperties; + } else if(dataPropertyAlgorithms.containsAll(algorithms)){ + entities = dataProperties; + } ps.setString(1, algorithms.get(0).getAnnotation(ComponentAnn.class).name()); ps.setDouble(2, threshold); @@ -826,10 +841,9 @@ } //get all axioms in the reference ontology for a specific axiom type - Set<String> relevantAxioms = getRelevantAxioms(type, entities); + Set<String> relevantAxioms = getRelevantAxioms2(type, entities); //compute the axioms which are in the reference ontology, but not be computed by the learning algorithm Set<String> missedAxioms = org.mindswap.pellet.utils.SetUtils.difference(relevantAxioms, foundAxioms); - System.out.println(missedAxioms); //compute the additional found axioms which were not entailed for(String relAxiom : relevantAxioms){ foundAndNotEntailedAxioms.remove(relAxiom); @@ -956,8 +970,8 @@ private Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> getAxiomTypesWithLearningAlgorithms(){ Map<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>> axiomType2Algorithm = new LinkedHashMap<AxiomType<? extends OWLAxiom>, List<Class<? extends LearningAlgorithm>>>(); - axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class, CELOE.class})); - axiomType2Algorithm.put(AxiomType.EQUIVALENT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{CELOE.class})); + axiomType2Algorithm.put(AxiomType.SUBCLASS_OF, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SimpleSubclassLearner.class}));//, CELOE.class})); +// axiomType2Algorithm.put(AxiomType.EQUIVALENT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{CELOE.class})); axiomType2Algorithm.put(AxiomType.DISJOINT_CLASSES, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{DisjointClassesLearner.class})); axiomType2Algorithm.put(AxiomType.SUB_OBJECT_PROPERTY, Arrays.asList((Class<? extends LearningAlgorithm>[])new Class[]{SubObjectPropertyOfAxiomLearner.class})); @@ -994,6 +1008,31 @@ return relevantAxioms; } + private Set<String> getRelevantAxioms2(AxiomType<? extends OWLAxiom> axiomType, Set<OWLEntity> entities){ + Set<String> relevantAxioms = new HashSet<String>(); + if(entities.isEmpty()){ + return relevantAxioms; + } + Set<OWLAxiom> entityAxioms = new HashSet<OWLAxiom>(); + for(OWLEntity entity : entities){ + if(entity.isOWLDataProperty()){ + entityAxioms.addAll(dbPediaOntology.getAxioms((OWLDataProperty)entity)); + } else if(entity.isOWLObjectProperty()){ + entityAxioms.addAll(dbPediaOntology.getAxioms((OWLObjectProperty)entity)); + } else if(entity.isOWLClass()){ + entityAxioms.addAll(dbPediaOntology.getAxioms((OWLClass)entity)); + } + } + + for(OWLAxiom axiom : entityAxioms){ + if(axiom.getAxiomType() == axiomType && !axiom.getClassesInSignature().contains(factory.getOWLThing())){ + String axiomString = DLLearnerAxiomConvertVisitor.getDLLearnerAxiom(axiom).toManchesterSyntaxString(baseURI, prefixes); + relevantAxioms.add(axiomString); + } + } + return relevantAxioms; + } + private boolean isRelevantAxiom(OWLAxiom axiom, Set<OWLEntity> entities){ if(axiom instanceof OWLObjectPropertyAxiom){ return containsOneOf(axiom.getObjectPropertiesInSignature(), entities); @@ -1139,10 +1178,10 @@ } catch (OWLOntologyCreationException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { - e1.printStackTrace(); + } if(dbPediaOntology == null){ - System.out.println("Loading schema ..."); + logger.info("Loading schema ..."); SPARQLReasoner r = new SPARQLReasoner(new SparqlEndpointKS(endpoint)); dbPediaOntology = convert(r.loadSchema()); try { @@ -1157,12 +1196,14 @@ e.printStackTrace(); } } - System.out.println("Preparing reasoner ..."); + + logger.info("Preparing reasoner ..."); // Configuration conf = new Configuration(); // conf.ignoreUnsupportedDatatypes = true; // reasoner = new Reasoner(conf, dbPediaOntology); reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); + logger.info("done."); } private OWLOntology convert(Model model){ @@ -1178,9 +1219,24 @@ return ontology; } - public static void main(String[] args) throws Exception - - { + public static void main(String[] args) throws Exception { + Logger.getRootLogger().setLevel(Level.INFO); + Logger.getRootLogger().removeAllAppenders(); + + FileAppender app = new FileAppender(new SimpleLayout(), + "evaluation/errors.log"); + app.setThreshold(Level.ERROR); + Logger.getRootLogger().addAppender(app); + + FileAppender app2 = new FileAppender(new SimpleLayout(), + "evaluation/enrichment.log"); + app2.setThreshold(Level.INFO); + Logger.getRootLogger().addAppender(app); + + ConsoleAppender consApp = new ConsoleAppender(new SimpleLayout()); + Logger.getRootLogger().addAppender(consApp); + + OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); parser.acceptsAll(asList("e", "endpoint"), @@ -1266,11 +1322,9 @@ ee.printResultsLaTeX(); Files.createFile(new File("enrichment_eval.html"), ee.printHTMLTable()); - FileAppender app = new FileAppender(new SimpleLayout(), - "log/enrichmentEvalErrors.log"); - Logger.getRootLogger().setLevel(Level.ERROR); - Logger.getRootLogger().removeAllAppenders(); - Logger.getRootLogger().addAppender(app); + + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |