From: <jen...@us...> - 2011-08-04 14:15:52
|
Revision: 2996 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2996&view=rev Author: jenslehmann Date: 2011-08-04 14:15:46 +0000 (Thu, 04 Aug 2011) Log Message: ----------- ctd. evaluation script, including database connection Modified Paths: -------------- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java trunk/scripts/pom.xml trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java Added Paths: ----------- trunk/scripts/db_settings.ini.dist Property Changed: ---------------- trunk/scripts/ Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/DisjointPropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -4,12 +4,14 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.kb.SparqlEndpointKS; +@ComponentAnn(name="disjoint property axiom learner") public class DisjointPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private String propertyToDescribe; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/EquivalentPropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -4,12 +4,14 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.configurators.Configurator; import org.dllearner.core.owl.Axiom; import org.dllearner.kb.SparqlEndpointKS; +@ComponentAnn(name="equivalent property axiom learner") public class EquivalentPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private String propertyToDescribe; Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/FunctionalPropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -6,6 +6,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -26,6 +27,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; +@ComponentAnn(name="functional property axiom learner") public class FunctionalPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(FunctionalPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyDomainAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -16,6 +16,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -39,6 +40,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +@ComponentAnn(name="property domain axiom learner") public class PropertyDomainAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(PropertyDomainAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/PropertyRangeAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -14,6 +14,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -36,6 +37,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; +@ComponentAnn(name="property range learner") public class PropertyRangeAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(PropertyRangeAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/ReflexivePropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -6,6 +6,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -26,6 +27,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; +@ComponentAnn(name="reflexive property learner") public class ReflexivePropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(ReflexivePropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/SymmetricPropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -6,6 +6,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -26,6 +27,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL2; +@ComponentAnn(name="symmetric property learner") public class SymmetricPropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(SymmetricPropertyAxiomLearner.class); Modified: trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java =================================================================== --- trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/components-core/src/main/java/org/dllearner/algorithms/properties/TransitivePropertyAxiomLearner.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -6,6 +6,7 @@ import org.dllearner.core.AxiomLearningAlgorithm; import org.dllearner.core.AbstractComponent; +import org.dllearner.core.ComponentAnn; import org.dllearner.core.ComponentInitException; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.config.ConfigOption; @@ -27,6 +28,7 @@ import com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP; import com.hp.hpl.jena.vocabulary.OWL; +@ComponentAnn(name="transitive property learner") public class TransitivePropertyAxiomLearner extends AbstractComponent implements AxiomLearningAlgorithm { private static final Logger logger = LoggerFactory.getLogger(TransitivePropertyAxiomLearner.class); Property changes on: trunk/scripts ___________________________________________________________________ Modified: svn:ignore - target log scripts.iml .classpath .project .settings + target log scripts.iml .classpath .project .settings db_settings.ini Added: trunk/scripts/db_settings.ini.dist =================================================================== --- trunk/scripts/db_settings.ini.dist (rev 0) +++ trunk/scripts/db_settings.ini.dist 2011-08-04 14:15:46 UTC (rev 2996) @@ -0,0 +1,9 @@ +[database] +; the server, where the mysql database is located +server = localhost +; the user, that has rights to access the navigator database +user = username +; the password of that user +pass = password +; the name of the used database +name = database_name \ No newline at end of file Modified: trunk/scripts/pom.xml =================================================================== --- trunk/scripts/pom.xml 2011-08-04 14:12:59 UTC (rev 2995) +++ trunk/scripts/pom.xml 2011-08-04 14:15:46 UTC (rev 2996) @@ -55,5 +55,9 @@ <groupId>org.aksw.commons</groupId> <artifactId>sparql</artifactId> </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + </dependency> </dependencies> </project> 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-04 14:12:59 UTC (rev 2995) +++ trunk/scripts/src/main/java/org/dllearner/scripts/evaluation/EnrichmentEvaluation.java 2011-08-04 14:15:46 UTC (rev 2996) @@ -19,15 +19,31 @@ */ package org.dllearner.scripts.evaluation; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.TreeSet; +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; import org.dllearner.algorithms.properties.SubPropertyOfAxiomLearner; +import org.dllearner.algorithms.properties.SymmetricPropertyAxiomLearner; +import org.dllearner.algorithms.properties.TransitivePropertyAxiomLearner; import org.dllearner.core.AxiomLearningAlgorithm; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.EvaluatedAxiom; import org.dllearner.core.LearningAlgorithm; @@ -36,6 +52,8 @@ import org.dllearner.kb.SparqlEndpointKS; import org.dllearner.kb.sparql.SparqlEndpoint; import org.dllearner.kb.sparql.SparqlQuery; +import org.ini4j.IniPreferences; +import org.ini4j.InvalidFileFormatException; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; @@ -62,16 +80,79 @@ private int maxDataProperties = 3; private int maxClasses = 3; private List<Class<? extends AxiomLearningAlgorithm>> objectPropertyAlgorithms; + private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; + private PreparedStatement ps; public EnrichmentEvaluation() { + initDBConnection(); + objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); +// 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(FunctionalPropertyAxiomLearner.class); + dataPropertyAlgorithms.add(PropertyDomainAxiomLearner.class); + dataPropertyAlgorithms.add(PropertyRangeAxiomLearner.class); // ? + dataPropertyAlgorithms.add(SubPropertyOfAxiomLearner.class); } - public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + private void initDBConnection(){ + try { + String iniFile = "db_settings.ini"; + Preferences prefs = new IniPreferences(new FileReader(iniFile)); + String dbServer = prefs.node("database").get("server", null); + 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); + ps = conn.prepareStatement("INSERT INTO evaluation (" + + "entity, algorithm, axiom, score ) " + + "VALUES(?,?,?,?)"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (InvalidFileFormatException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void writeToDB( + String entity, String algorithm, String axiom, double score){ + try { + ps.setString(1, entity); + ps.setString(2, algorithm); + ps.setString(3, axiom); + ps.setDouble(4, score); + + ps.executeUpdate(); + } catch (SQLException e) { + logger.error("Error while writing to DB.",e); + e.printStackTrace(); + } + } + + public void start() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { + ComponentManager cm = ComponentManager.getInstance(); // create DBpedia Live knowledge source @@ -80,6 +161,7 @@ Set<ObjectProperty> properties = getAllObjectProperties(se); SparqlEndpointKS ks = new SparqlEndpointKS(se); + ks.init(); for(Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { int objectProperties = 0; @@ -88,15 +170,20 @@ // 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); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); + learner.init(); // learner.setPropertyToDescribe(property); // learner.setMaxExecutionTimeInSeconds(10); - System.out.println("Applying " + ComponentManager.getName(learner) + " on " + property + " ... "); + String algName = ComponentManager.getName(learner); + System.out.println("Applying " + algName + " on " + property + " ... "); learner.start(); List<EvaluatedAxiom> learnedAxioms = learner.getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - for(EvaluatedAxiom learnedAxiom : learnedAxioms) { - // TODO: put this in some data structure - System.out.println(learnedAxiom); + if(learnedAxioms == null) { + writeToDB(property.toString(), algName, "NULL", 0); + } else { + for(EvaluatedAxiom learnedAxiom : learnedAxioms) { + writeToDB(property.toString(), algName, learnedAxiom.getAxiom().toString(), learnedAxiom.getScore().getAccuracy()); + } } objectProperties++; if(objectProperties > maxObjectProperties) { @@ -133,7 +220,7 @@ } - public static void main(String[] args) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + public static void main(String[] args) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ComponentInitException { 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. |