From: <jen...@us...> - 2011-08-11 12:56:51
|
Revision: 3031 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3031&view=rev Author: jenslehmann Date: 2011-08-11 12:56:45 +0000 (Thu, 11 Aug 2011) Log Message: ----------- improved formatting in enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 11:40:11 UTC (rev 3030) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 12:56:45 UTC (rev 3031) @@ -26,6 +26,7 @@ import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; +import java.text.DecimalFormat; import java.util.LinkedList; import java.util.List; @@ -81,6 +82,7 @@ public class Enrichment { private static Logger logger = Logger.getLogger(Enrichment.class); + private DecimalFormat df = new DecimalFormat("##0.0"); // enrichment parameters private SparqlEndpoint se; @@ -161,7 +163,7 @@ maxExecutionTimeInSeconds); learner.init(); String algName = ComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + resource + " ... "); + System.out.print("Applying " + algName + " on " + resource + " ... "); long startTime = System.currentTimeMillis(); try { learner.start(); @@ -172,12 +174,10 @@ } } long runtime = System.currentTimeMillis() - startTime; - System.out.println("runtime: " + runtime + "ms"); + System.out.println("done in " + runtime + "ms"); List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - System.out.println("suggested axiom: " + learnedAxiom); - } + System.out.println(prettyPrint(learnedAxioms)); } } else if(resource instanceof DatatypeProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { @@ -188,7 +188,7 @@ maxExecutionTimeInSeconds); learner.init(); String algName = ComponentManager.getName(learner); - System.out.println("Applying " + algName + " on " + resource + " ... "); + System.out.print("Applying " + algName + " on " + resource + " ... "); long startTime = System.currentTimeMillis(); try { learner.start(); @@ -199,12 +199,10 @@ } } long runtime = System.currentTimeMillis() - startTime; - System.out.println("runtime: " + runtime + "ms"); + System.out.println("done in " + runtime + "ms"); List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - for (EvaluatedAxiom learnedAxiom : learnedAxioms) { - System.out.println("suggested axiom: " + learnedAxiom); - } + System.out.println(prettyPrint(learnedAxioms)); } } else if(resource instanceof NamedClass) { throw new Error("not implemented"); @@ -214,13 +212,34 @@ } } + private String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { + String str = "suggested axioms and their score in percent:\n"; + if(learnedAxioms.isEmpty()) { + return "no axiom suggested"; + } else { + for (EvaluatedAxiom learnedAxiom : learnedAxioms) { + str += " " + prettyPrint(learnedAxiom) + "\n"; + } + } + return str; + } + + private String prettyPrint(EvaluatedAxiom axiom) { + double acc = axiom.getScore().getAccuracy() * 100; + String accs = df.format(acc); + if(acc<10d) { accs = " " + accs; } + if(acc<100d) { accs = " " + accs; } + String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, prefixes); + return str; + } + public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); - logger.removeAllAppenders(); - logger.addAppender(consoleAppender); - logger.setLevel(Level.WARN); + Logger.getRootLogger().removeAllAppenders(); + Logger.getRootLogger().addAppender(consoleAppender); + Logger.getRootLogger().setLevel(Level.WARN); OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); @@ -277,6 +296,10 @@ } } + if(!options.hasArgument("endpoint")) { + System.out.println("Please specify a SPARQL endpoint (using the -e option)."); + } + boolean verbose = (Boolean) options.valueOf("v"); Enrichment e = new Enrichment(se, resource, verbose); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-11 14:34:12
|
Revision: 3036 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3036&view=rev Author: jenslehmann Date: 2011-08-11 14:34:06 +0000 (Thu, 11 Aug 2011) Log Message: ----------- improvements of enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 14:33:45 UTC (rev 3035) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 14:34:06 UTC (rev 3036) @@ -156,53 +156,11 @@ } else { if(resource instanceof ObjectProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", resource); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - String algName = ComponentManager.getName(learner); - System.out.print("Applying " + algName + " on " + resource + " ... "); - long startTime = System.currentTimeMillis(); - try { - learner.start(); - } catch (Exception e) { - e.printStackTrace(); - if(e.getCause() instanceof SocketTimeoutException){ - System.out.println("Query timed out (endpoint possibly too slow)."); - } - } - long runtime = System.currentTimeMillis() - startTime; - System.out.println("done in " + runtime + "ms"); - List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - System.out.println(prettyPrint(learnedAxioms)); + applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof DatatypeProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", resource); - ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", - maxExecutionTimeInSeconds); - learner.init(); - String algName = ComponentManager.getName(learner); - System.out.print("Applying " + algName + " on " + resource + " ... "); - long startTime = System.currentTimeMillis(); - try { - learner.start(); - } catch (Exception e) { - e.printStackTrace(); - if(e.getCause() instanceof SocketTimeoutException){ - System.out.println("Query timed out (endpoint possibly too slow)."); - } - } - long runtime = System.currentTimeMillis() - startTime; - System.out.println("done in " + runtime + "ms"); - List<EvaluatedAxiom> learnedAxioms = learner - .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); - System.out.println(prettyPrint(learnedAxioms)); + applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof NamedClass) { throw new Error("not implemented"); @@ -212,10 +170,36 @@ } } + private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks) throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + AxiomLearningAlgorithm learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + ConfigHelper.configure(learner, "propertyToDescribe", resource); + ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", + maxExecutionTimeInSeconds); + learner.init(); + String algName = ComponentManager.getName(learner); + System.out.print("Applying " + algName + " on " + resource + " ... "); + long startTime = System.currentTimeMillis(); + try { + learner.start(); + } catch (Exception e) { + e.printStackTrace(); + if(e.getCause() instanceof SocketTimeoutException){ + System.out.println("Query timed out (endpoint possibly too slow)."); + } + } + long runtime = System.currentTimeMillis() - startTime; + System.out.println("done in " + runtime + "ms"); + List<EvaluatedAxiom> learnedAxioms = learner + .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); + System.out.println(prettyPrint(learnedAxioms)); + return learnedAxioms; + } + private String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { String str = "suggested axioms and their score in percent:\n"; if(learnedAxioms.isEmpty()) { - return "no axiom suggested"; + return " no axiom suggested"; } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { str += " " + prettyPrint(learnedAxiom) + "\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-11 16:01:40
|
Revision: 3037 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3037&view=rev Author: jenslehmann Date: 2011-08-11 16:01:34 +0000 (Thu, 11 Aug 2011) Log Message: ----------- added class learning to enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 14:34:06 UTC (rev 3036) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-11 16:01:34 UTC (rev 3037) @@ -21,14 +21,20 @@ import static java.util.Arrays.asList; +import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URL; import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -55,21 +61,39 @@ import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; +import org.dllearner.core.AbstractReasonerComponent; 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.LearningProblemUnsupportedException; 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.Entity; +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.gui.Config; +import org.dllearner.gui.ConfigSave; 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.kb.sparql.SparqlQuery; +import org.dllearner.learningproblems.ClassLearningProblem; +import org.dllearner.learningproblems.PosNegLPStandard; +import org.dllearner.reasoning.FastInstanceChecker; +import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.CommonPrefixMap; +import org.dllearner.utilities.Helper; +import org.dllearner.utilities.datastructures.Datastructures; +import org.dllearner.utilities.datastructures.SortedSetTuple; +import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import com.hp.hpl.jena.query.ResultSet; @@ -133,7 +157,8 @@ classAlgorithms.add(CELOE.class); } - public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + @SuppressWarnings("unchecked") + public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException { // sanity check that endpoint/graph returns at least one triple String query = "SELECT * WHERE {?s ?p ?o} LIMIT 1"; @@ -147,9 +172,11 @@ SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); + // common helper objects + SPARQLTasks st = new SPARQLTasks(se); + if(resource == null) { // TODO: automatically run over all resources if no specific resource was specified - SPARQLTasks st = new SPARQLTasks(se); st.getAllClasses(); st.getAllDataProperties(); st.getAllObjectProperties(); @@ -163,17 +190,88 @@ applyLearningAlgorithm(algorithmClass, ks); } } else if(resource instanceof NamedClass) { - throw new Error("not implemented"); + for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { + if(algorithmClass == CELOE.class) { + applyCELOE(ks, false); + applyCELOE(ks, true); + } else { + applyLearningAlgorithm((Class<AxiomLearningAlgorithm>)algorithmClass, ks); + } + } } else { throw new Error("The type " + resource.getClass() + " of resource " + resource + " cannot be handled by this enrichment tool."); } } } + private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, boolean equivalence) throws ComponentInitException, LearningProblemUnsupportedException { + SPARQLTasks st = new SPARQLTasks(se); + + // get instances of class as positive examples + SPARQLReasoner sr = new SPARQLReasoner(ks); + SortedSet<Individual> posExamples = sr.getIndividuals((NamedClass)resource); + SortedSet<String> posExStr = Helper.getStringSet(posExamples); + + // get negative examples via various strategies + AutomaticNegativeExampleFinderSPARQL finder = new AutomaticNegativeExampleFinderSPARQL(posExStr, st, null); + SortedSet<String> negExStr = finder.getNegativeExamples(50, false); + SortedSet<Individual> negExamples = Helper.getIndividualSet(negExStr); + SortedSetTuple<Individual> examples = new SortedSetTuple<Individual>(posExamples, negExamples); + + 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().setUseLits(false); + ks2.getConfigurator().setUseCacheDatabase(true); + ks2.getConfigurator().setRecursionDepth(1); + ks2.getConfigurator().setCloseAfterRecursion(true); +// ks2.getConfigurator().setSaveExtractedFragment(true); + + + ks.init(); + + AbstractReasonerComponent rc = cm.reasoner(FastInstanceChecker.class, ks); + rc.init(); + + // TODO: super class learning + ClassLearningProblem lp = cm.learningProblem(ClassLearningProblem.class, rc); +// lp.setPositiveExamples(posExamples); +// lp.setNegativeExamples(negExamples); + lp.getConfigurator().setType("equivalence"); + lp.getConfigurator().setAccuracyMethod("fmeasure"); + lp.getConfigurator().setUseApproximations(false); + lp.init(); + + + CELOE la = cm.learningAlgorithm(CELOE.class, lp, rc); + CELOEConfigurator cc = la.getConfigurator(); + cc.setMaxExecutionTimeInSeconds(100); + cc.setNoisePercentage(20); + la.init(); + la.start(); + + // convert the result to axioms (to make it compatible with the other algorithms) + TreeSet<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(); + for(EvaluatedDescription learnedDescription : learnedDescriptions) { + Axiom axiom = new EquivalentClassesAxiom((NamedClass) resource, learnedDescription.getDescription()); + } + + // TODO: further axiom conversion + + cm.freeAllComponents(); + return null; + } + private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks) throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { AxiomLearningAlgorithm learner = algorithmClass.getConstructor( SparqlEndpointKS.class).newInstance(ks); - ConfigHelper.configure(learner, "propertyToDescribe", resource); + if(classAlgorithms.contains(algorithmClass)) { + ConfigHelper.configure(learner, "classToDescribe", resource); + } else { + ConfigHelper.configure(learner, "propertyToDescribe", resource); + } ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); learner.init(); @@ -217,7 +315,7 @@ return str; } - public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { + public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException { SimpleLayout layout = new SimpleLayout(); ConsoleAppender consoleAppender = new ConsoleAppender(layout); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-15 07:33:30
|
Revision: 3039 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3039&view=rev Author: lorenz_b Date: 2011-08-15 07:33:24 +0000 (Mon, 15 Aug 2011) Log Message: ----------- Continued enrichment output. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 07:30:18 UTC (rev 3038) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 07:33:24 UTC (rev 3039) @@ -23,10 +23,13 @@ import java.io.File; import java.io.IOException; +import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.net.SocketTimeoutException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; +import java.util.ArrayList; import java.text.DecimalFormat; import java.util.Arrays; import java.util.HashSet; @@ -63,6 +66,7 @@ import org.dllearner.algorithms.properties.TransitiveObjectPropertyAxiomLearner; import org.dllearner.core.AbstractReasonerComponent; 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; @@ -90,11 +94,21 @@ import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.CommonPrefixMap; +import org.dllearner.utilities.EnrichmentVocabulary; +import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAxiom; +import org.semanticweb.owlapi.model.OWLDataFactory; +import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.util.DefaultPrefixManager; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; +import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; +import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; +import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxPrefixNameShortFormProvider; + import com.hp.hpl.jena.query.ResultSet; /** @@ -188,6 +202,7 @@ } else if(resource instanceof DatatypeProperty) { for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks); + } } else if(resource instanceof NamedClass) { for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { @@ -291,6 +306,8 @@ List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn); System.out.println(prettyPrint(learnedAxioms)); + + toRDF(learnedAxioms, learner, ks); return learnedAxioms; } @@ -392,5 +409,51 @@ } } + + public void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks){ + List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); + + OWLDataFactory f = new OWLDataFactoryImpl(); + + String id = "";//TODO + OWLIndividual ind = f.getOWLNamedIndividual(IRI.create(id)); + + OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); + axioms.add(ax1); + + String algorithmName = algorithm.getClass().getAnnotation(ComponentAnn.class).name(); + OWLAxiom ax2 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, + ind, f.getOWLNamedIndividual(IRI.create(algorithmName))); + axioms.add(ax2); + + try { + OWLAxiom ax3 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasInput, + ind, f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL()))); + axioms.add(ax3); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + for(EvaluatedAxiom evAx : evalAxioms){ + axioms.addAll(evAx.toRDF()); + } + + + printManchesterOWLSyntax(axioms); + } + + private void printManchesterOWLSyntax(List<OWLAxiom> axioms){ + System.out.println("ENRICHMENT["); + StringWriter sw = new StringWriter(); + ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer( + sw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); + + for(OWLAxiom ax : axioms){ + sw.getBuffer().setLength(0); + ax.accept(r); + System.out.println(sw.toString()); + } + System.out.println("]"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-15 12:56:19
|
Revision: 3042 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3042&view=rev Author: lorenz_b Date: 2011-08-15 12:56:13 +0000 (Mon, 15 Aug 2011) Log Message: ----------- Added more output types. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 09:05:43 UTC (rev 3041) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 12:56:13 UTC (rev 3042) @@ -42,6 +42,7 @@ import joptsimple.OptionParser; import joptsimple.OptionSet; +import org.aksw.commons.jena_owlapi.Conversion; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -95,10 +96,13 @@ import org.dllearner.reasoning.SPARQLReasoner; import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.EnrichmentVocabulary; +import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLOntology; +import org.semanticweb.owlapi.model.OWLOntologyCreationException; import org.semanticweb.owlapi.util.DefaultPrefixManager; import org.dllearner.utilities.Helper; import org.dllearner.utilities.datastructures.Datastructures; @@ -110,6 +114,8 @@ import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxPrefixNameShortFormProvider; import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; /** * Command Line Interface for Enrichment. @@ -332,6 +338,92 @@ return str; } + /* + * Generates list of OWL axioms. + */ + private void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks){ + List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); + + OWLDataFactory f = new OWLDataFactoryImpl(); + + String id = "http://dl-learner.org#enrichment";//TODO create a unique identifier for a particular suggestion + OWLIndividual ind = f.getOWLNamedIndividual(IRI.create(id)); + + OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); + axioms.add(ax1); + + String algorithmName = "http://dl-learner.org#" + algorithm.getClass().getAnnotation(ComponentAnn.class).name().replace(" ", "_"); + OWLAxiom ax2 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, + ind, f.getOWLNamedIndividual(IRI.create(algorithmName))); + axioms.add(ax2); + + try { + OWLAxiom ax3 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasInput, + ind, f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL()))); + axioms.add(ax3); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + + for(EvaluatedAxiom evAx : evalAxioms){ + axioms.addAll(evAx.toRDF()); + } + + + printManchesterOWLSyntax(axioms); +// printTurtleSyntax(axioms); +// printNTriplesSyntax(axioms); + } + + /* + * Write axioms in Manchester OWL Syntax. + */ + private void printManchesterOWLSyntax(List<OWLAxiom> axioms){ + System.out.println("ENRICHMENT["); + StringWriter sw = new StringWriter(); + ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer( + sw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); + + for(OWLAxiom ax : axioms){ + sw.getBuffer().setLength(0); + ax.accept(r); + System.out.println(sw.toString()); + } + System.out.println("]"); + } + + /* + * Write axioms in Turtle syntax. + */ + private void printTurtleSyntax(List<OWLAxiom> axioms){ + try { + System.out.println("ENRICHMENT["); + Model model = ModelFactory.createDefaultModel(); + Conversion.OWLAPIOntology2JenaModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)), model); + model.write(System.out, "TURTLE"); + System.out.println("]"); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /* + * Write axioms in Turtle syntax. + */ + private void printNTriplesSyntax(List<OWLAxiom> axioms){ + try { + System.out.println("ENRICHMENT["); + Model model = ModelFactory.createDefaultModel(); + Conversion.OWLAPIOntology2JenaModel(OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)), model); + model.write(System.out, "N-TRIPLES"); + System.out.println("]"); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public static void main(String[] args) throws IOException, ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException { SimpleLayout layout = new SimpleLayout(); @@ -410,50 +502,5 @@ } - public void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks){ - List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); - - OWLDataFactory f = new OWLDataFactoryImpl(); - - String id = "";//TODO - OWLIndividual ind = f.getOWLNamedIndividual(IRI.create(id)); - - OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); - axioms.add(ax1); - - String algorithmName = algorithm.getClass().getAnnotation(ComponentAnn.class).name(); - OWLAxiom ax2 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, - ind, f.getOWLNamedIndividual(IRI.create(algorithmName))); - axioms.add(ax2); - - try { - OWLAxiom ax3 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasInput, - ind, f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL()))); - axioms.add(ax3); - } catch (URISyntaxException e) { - e.printStackTrace(); - } - - for(EvaluatedAxiom evAx : evalAxioms){ - axioms.addAll(evAx.toRDF()); - } - - - printManchesterOWLSyntax(axioms); - } - - private void printManchesterOWLSyntax(List<OWLAxiom> axioms){ - System.out.println("ENRICHMENT["); - StringWriter sw = new StringWriter(); - ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer( - sw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); - - for(OWLAxiom ax : axioms){ - sw.getBuffer().setLength(0); - ax.accept(r); - System.out.println(sw.toString()); - } - System.out.println("]"); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-15 19:15:26
|
Revision: 3047 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3047&view=rev Author: jenslehmann Date: 2011-08-15 19:15:20 +0000 (Mon, 15 Aug 2011) Log Message: ----------- small fix Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 14:48:54 UTC (rev 3046) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-15 19:15:20 UTC (rev 3047) @@ -82,6 +82,7 @@ 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; @@ -277,7 +278,12 @@ TreeSet<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(); List<EvaluatedAxiom> evaluatedAxioms = new LinkedList<EvaluatedAxiom>(); for(EvaluatedDescription learnedDescription : learnedDescriptions) { - Axiom axiom = new EquivalentClassesAxiom((NamedClass) resource, learnedDescription.getDescription()); + Axiom axiom; + if(equivalence) { + axiom = new EquivalentClassesAxiom((NamedClass) resource, learnedDescription.getDescription()); + } else { + axiom = new SubClassAxiom((NamedClass) resource, learnedDescription.getDescription()); + } Score score = lp.computeScore(learnedDescription.getDescription()); evaluatedAxioms.add(new EvaluatedAxiom(axiom, score)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-08-17 08:41:42
|
Revision: 3056 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3056&view=rev Author: lorenz_b Date: 2011-08-17 08:41:36 +0000 (Wed, 17 Aug 2011) Log Message: ----------- Continued enrichment vocabulary and more readable output. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 08:26:33 UTC (rev 3055) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 08:41:36 UTC (rev 3056) @@ -24,16 +24,19 @@ import java.io.IOException; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; +import java.math.BigInteger; import java.net.MalformedURLException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; @@ -45,6 +48,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; +import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat; import org.dllearner.algorithms.DisjointClassesLearner; import org.dllearner.algorithms.SimpleSubclassLearner; import org.dllearner.algorithms.celoe.CELOE; @@ -99,12 +103,19 @@ import org.dllearner.utilities.datastructures.SortedSetTuple; import org.dllearner.utilities.examples.AutomaticNegativeExampleFinderSPARQL; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.OWLOntologyDocumentTarget; +import org.semanticweb.owlapi.io.SystemOutDocumentTarget; import org.semanticweb.owlapi.model.IRI; +import org.semanticweb.owlapi.model.OWLAnnotation; import org.semanticweb.owlapi.model.OWLAxiom; import org.semanticweb.owlapi.model.OWLDataFactory; import org.semanticweb.owlapi.model.OWLIndividual; +import org.semanticweb.owlapi.model.OWLOntology; import org.semanticweb.owlapi.model.OWLOntologyCreationException; +import org.semanticweb.owlapi.model.OWLOntologyManager; +import org.semanticweb.owlapi.model.OWLOntologyStorageException; import org.semanticweb.owlapi.util.DefaultPrefixManager; +import org.semanticweb.owlapi.vocab.OWLRDFVocabulary; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; import uk.ac.manchester.cs.owl.owlapi.mansyntaxrenderer.ManchesterOWLSyntaxObjectRenderer; @@ -124,7 +135,11 @@ private static Logger logger = Logger.getLogger(Enrichment.class); private DecimalFormat df = new DecimalFormat("##0.0"); + private static final String DEFAULT_NS = "http://localhost:8080/"; + //used to generate unique random identifiers + private SecureRandom random = new SecureRandom(); + // enrichment parameters private SparqlEndpoint se; private Entity resource; @@ -351,54 +366,104 @@ * Generates list of OWL axioms. */ private void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks){ + toRDF(evalAxioms, algorithm, ks, null); + } + + private void toRDF(List<EvaluatedAxiom> evalAxioms, LearningAlgorithm algorithm, SparqlEndpointKS ks, String defaultNamespace){ + if(defaultNamespace == null || defaultNamespace.isEmpty()){ + defaultNamespace = DEFAULT_NS; + } List<OWLAxiom> axioms = new ArrayList<OWLAxiom>(); OWLDataFactory f = new OWLDataFactoryImpl(); - String id = "http://dl-learner.org#enrichment";//TODO create a unique identifier for a particular suggestion - OWLIndividual ind = f.getOWLNamedIndividual(IRI.create(id)); + //create instance for suggestion set + String suggestionSetID = defaultNamespace + generateId(); + OWLIndividual ind = f.getOWLNamedIndividual(IRI.create(suggestionSetID)); + //add type SuggestionSet + OWLAxiom ax = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.SuggestionSet, ind); + axioms.add(ax); - OWLAxiom ax1 = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.Suggestion, ind); - axioms.add(ax1); - String algorithmName = "http://dl-learner.org#" + algorithm.getClass().getAnnotation(ComponentAnn.class).name().replace(" ", "_"); - OWLAxiom ax2 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, - ind, f.getOWLNamedIndividual(IRI.create(algorithmName))); - axioms.add(ax2); + //create instance for algorithm run + String algorithmRunID = defaultNamespace + generateId(); + OWLIndividual algorithmRunInd = f.getOWLNamedIndividual(IRI.create(algorithmRunID)); + //add type AlgorithmRun + ax = f.getOWLClassAssertionAxiom(EnrichmentVocabulary.AlgorithmRun, algorithmRunInd); + axioms.add(ax); + //generate instance for algorithm + String algorithmName = algorithm.getClass().getAnnotation(ComponentAnn.class).name(); + String algorithmID = "http://dl-learner.org#" + algorithmName.replace(" ", "_"); + OWLIndividual algorithmInd = f.getOWLNamedIndividual(IRI.create(algorithmID)); + //add label to algorithm instance + OWLAnnotation labelAnno = f.getOWLAnnotation( + f.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI()), + f.getOWLLiteral(algorithmName)); + ax = f.getOWLAnnotationAssertionAxiom(algorithmInd.asOWLNamedIndividual().getIRI(), labelAnno); + axioms.add(ax); + //add algorithm instance to algorithm run instance + ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.usedAlgorithm, + algorithmRunInd, algorithmInd); + axioms.add(ax); + //add Parameters to algorithm run instance + //TODO + //add used input to algorithm run instance try { - OWLAxiom ax3 = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasInput, - ind, f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL()))); - axioms.add(ax3); - } catch (URISyntaxException e) { - e.printStackTrace(); + ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasInput, + algorithmRunInd, f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL()))); + } catch (URISyntaxException e1) { + e1.printStackTrace(); } + axioms.add(ax); + //add algorithm run instance to suggestion set instance via ObjectProperty creator + ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.creator, + ind, algorithmRunInd); + axioms.add(ax); + + //add suggestions to suggestions set + Entry<OWLIndividual, List<OWLAxiom>> ind2Axioms; for(EvaluatedAxiom evAx : evalAxioms){ - axioms.addAll(evAx.toRDF()); + ind2Axioms = evAx.toRDF(defaultNamespace).entrySet().iterator().next(); + ax = f.getOWLObjectPropertyAssertionAxiom(EnrichmentVocabulary.hasSuggestion, ind, ind2Axioms.getKey()); + axioms.add(ax); + axioms.addAll(ind2Axioms.getValue()); } - printManchesterOWLSyntax(axioms); + printManchesterOWLSyntax(axioms, defaultNamespace); // printTurtleSyntax(axioms); // printNTriplesSyntax(axioms); } + private String generateId(){ + return new BigInteger(130, random).toString(32); + } + /* * Write axioms in Manchester OWL Syntax. */ - private void printManchesterOWLSyntax(List<OWLAxiom> axioms){ - System.out.println("ENRICHMENT["); - StringWriter sw = new StringWriter(); - ManchesterOWLSyntaxObjectRenderer r = new ManchesterOWLSyntaxObjectRenderer( - sw, new ManchesterOWLSyntaxPrefixNameShortFormProvider(new DefaultPrefixManager())); - - for(OWLAxiom ax : axioms){ - sw.getBuffer().setLength(0); - ax.accept(r); - System.out.println(sw.toString()); + private void printManchesterOWLSyntax(List<OWLAxiom> axioms, String defaultNamespace){ + try { + System.out.println("ENRICHMENT["); + + OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget(); + ManchesterOWLSyntaxOntologyFormat manSyntaxFormat = new ManchesterOWLSyntaxOntologyFormat(); + manSyntaxFormat.setDefaultPrefix(defaultNamespace); + + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + OWLOntology ontology = man.createOntology(new HashSet<OWLAxiom>(axioms), IRI.create(defaultNamespace + "enrichment")); + OWLManager.createOWLOntologyManager().saveOntology(ontology, manSyntaxFormat, new SystemOutDocumentTarget()); + + + + System.out.println("]"); + } catch (OWLOntologyCreationException e) { + e.printStackTrace(); + } catch (OWLOntologyStorageException e) { + e.printStackTrace(); } - System.out.println("]"); } /* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-17 18:45:45
|
Revision: 3064 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3064&view=rev Author: jenslehmann Date: 2011-08-17 18:45:39 +0000 (Wed, 17 Aug 2011) Log Message: ----------- minor parameter adjustment Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 18:38:28 UTC (rev 3063) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 18:45:39 UTC (rev 3064) @@ -295,8 +295,8 @@ CELOE la = cm.learningAlgorithm(CELOE.class, lp, rc); CELOEConfigurator cc = la.getConfigurator(); - cc.setMaxExecutionTimeInSeconds(100); - cc.setNoisePercentage(20); + cc.setMaxExecutionTimeInSeconds(10); + cc.setNoisePercentage(25); la.init(); System.out.print("running CELOE ... "); la.start(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-08-18 07:25:13
|
Revision: 3065 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3065&view=rev Author: jenslehmann Date: 2011-08-18 07:25:06 +0000 (Thu, 18 Aug 2011) Log Message: ----------- work on full enrichment (not for a specific class/property but the whole knowledge base) Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-17 18:45:39 UTC (rev 3064) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-08-18 07:25:06 UTC (rev 3065) @@ -132,6 +132,26 @@ */ public class Enrichment { + // data structure for holding the result of an algorithm run + private class AlgorithmRun { + + private LearningAlgorithm algorithm; + private List<EvaluatedAxiom> axioms; + + public AlgorithmRun(LearningAlgorithm algorithm, List<EvaluatedAxiom> axioms) { + this.algorithm = algorithm; + this.axioms = axioms; + } + + public LearningAlgorithm getAlgorithm() { + return algorithm; + } + + public List<EvaluatedAxiom> getAxioms() { + return axioms; + } + } + private static Logger logger = Logger.getLogger(Enrichment.class); private DecimalFormat df = new DecimalFormat("##0.0"); private static final String DEFAULT_NS = "http://localhost:8080/"; @@ -156,6 +176,9 @@ private List<Class<? extends AxiomLearningAlgorithm>> dataPropertyAlgorithms; private List<Class<? extends LearningAlgorithm>> classAlgorithms; + // list of generated axioms while script is running + + private CommonPrefixMap prefixes = new CommonPrefixMap(); public Enrichment(SparqlEndpoint se, Entity resource, boolean verbose) { @@ -188,6 +211,7 @@ classAlgorithms.add(CELOE.class); } + @SuppressWarnings("unchecked") public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { // sanity check that endpoint/graph returns at least one triple @@ -206,44 +230,66 @@ SPARQLTasks st = new SPARQLTasks(se); if(resource == null) { - // TODO: automatically run over all resources if no specific resource was specified - st.getAllClasses(); - st.getAllDataProperties(); - st.getAllObjectProperties(); + // loop over all entities and call appropriate algorithms + Set<NamedClass> classes = st.getAllClasses(); + for(NamedClass nc : classes) { + runClassLearningAlgorithms(ks, nc); + } + Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); + for(ObjectProperty property : objectProperties) { + runObjectPropertyAlgorithms(ks, property); + } + Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); + for(DatatypeProperty property : dataProperties) { + runDataPropertyAlgorithms(ks, property); + } } else { if(resource instanceof ObjectProperty) { System.out.println(resource + " appears to be an object property. Running appropriate algorithms."); - for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { - applyLearningAlgorithm(algorithmClass, ks); - } + runObjectPropertyAlgorithms(ks, (ObjectProperty) resource); } else if(resource instanceof DatatypeProperty) { System.out.println(resource + " appears to be a data property. Running appropriate algorithms."); - for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { - applyLearningAlgorithm(algorithmClass, ks); - - } + runDataPropertyAlgorithms(ks, (DatatypeProperty) resource); } else if(resource instanceof NamedClass) { System.out.println(resource + " appears to be a class. Running appropriate algorithms."); - for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { - if(algorithmClass == CELOE.class) { - applyCELOE(ks, false); - applyCELOE(ks, true); - } else { -// applyLearningAlgorithm((Class<AxiomLearningAlgorithm>)algorithmClass, ks); - } - } + runClassLearningAlgorithms(ks, (NamedClass) resource); } else { throw new Error("The type " + resource.getClass() + " of resource " + resource + " cannot be handled by this enrichment tool."); } } } - private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, boolean equivalence) throws ComponentInitException, LearningProblemUnsupportedException, MalformedURLException { + @SuppressWarnings("unchecked") + private void runClassLearningAlgorithms(SparqlEndpointKS ks, NamedClass nc) throws ComponentInitException { + System.out.println(resource + " appears to be a class. Running appropriate algorithms."); + for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { + if(algorithmClass == CELOE.class) { + applyCELOE(ks, nc, false); + applyCELOE(ks, nc, true); + } else { + applyLearningAlgorithm((Class<AxiomLearningAlgorithm>)algorithmClass, ks, nc); + } + } + } + + private void runObjectPropertyAlgorithms(SparqlEndpointKS ks, ObjectProperty property) throws ComponentInitException { + for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { + applyLearningAlgorithm(algorithmClass, ks, property); + } + } + + private void runDataPropertyAlgorithms(SparqlEndpointKS ks, DatatypeProperty property) throws ComponentInitException { + for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { + applyLearningAlgorithm(algorithmClass, ks, property); + } + } + + private List<EvaluatedAxiom> applyCELOE(SparqlEndpointKS ks, NamedClass nc, boolean equivalence) throws ComponentInitException { // SPARQLTasks st = new SPARQLTasks(se); // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); - SortedSet<Individual> posExamples = sr.getIndividuals((NamedClass)resource, 20); + SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); SortedSet<String> posExStr = Helper.getStringSet(posExamples); // get negative examples via various strategies @@ -257,7 +303,7 @@ // use own implementation of negative example finder System.out.print("finding negatives ... "); AutomaticNegativeExampleFinderSPARQL2 finder = new AutomaticNegativeExampleFinderSPARQL2(ks.getEndpoint()); - SortedSet<String> negExStr = finder.getNegativeExamples(resource.getName(), posExStr); + 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); @@ -286,21 +332,30 @@ ClassLearningProblem lp = cm.learningProblem(ClassLearningProblem.class, rc); // lp.setPositiveExamples(posExamples); // lp.setNegativeExamples(negExamples); - lp.getConfigurator().setClassToDescribe(resource.getURI().toURL()); + 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 = cm.learningAlgorithm(CELOE.class, lp, rc); + 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"); + System.out.println("done"); // convert the result to axioms (to make it compatible with the other algorithms) TreeSet<? extends EvaluatedDescription> learnedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(); @@ -308,9 +363,9 @@ for(EvaluatedDescription learnedDescription : learnedDescriptions) { Axiom axiom; if(equivalence) { - axiom = new EquivalentClassesAxiom((NamedClass) resource, learnedDescription.getDescription()); + axiom = new EquivalentClassesAxiom(nc, learnedDescription.getDescription()); } else { - axiom = new SubClassAxiom((NamedClass) resource, learnedDescription.getDescription()); + axiom = new SubClassAxiom(nc, learnedDescription.getDescription()); } Score score = lp.computeScore(learnedDescription.getDescription()); evaluatedAxioms.add(new EvaluatedAxiom(axiom, score)); @@ -321,19 +376,24 @@ return evaluatedAxioms; } - private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks) throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { - AxiomLearningAlgorithm learner = algorithmClass.getConstructor( - SparqlEndpointKS.class).newInstance(ks); + private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks, Entity entity) throws ComponentInitException { + AxiomLearningAlgorithm learner = null; + try { + learner = algorithmClass.getConstructor( + SparqlEndpointKS.class).newInstance(ks); + } catch (Exception e) { + e.printStackTrace(); + } if(classAlgorithms.contains(algorithmClass)) { - ConfigHelper.configure(learner, "classToDescribe", resource); + ConfigHelper.configure(learner, "classToDescribe", entity); } else { - ConfigHelper.configure(learner, "propertyToDescribe", resource); + ConfigHelper.configure(learner, "propertyToDescribe", entity); } ConfigHelper.configure(learner, "maxExecutionTimeInSeconds", maxExecutionTimeInSeconds); learner.init(); String algName = AnnComponentManager.getName(learner); - System.out.print("Applying " + algName + " on " + resource + " ... "); + System.out.print("Applying " + algName + " on " + entity + " ... "); long startTime = System.currentTimeMillis(); try { learner.start(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-09-01 12:31:36
|
Revision: 3205 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3205&view=rev Author: jenslehmann Date: 2011-09-01 12:31:30 +0000 (Thu, 01 Sep 2011) Log Message: ----------- updated enrichment script with new inference option Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 06:46:21 UTC (rev 3204) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 12:31:30 UTC (rev 3205) @@ -662,6 +662,8 @@ parser.acceptsAll(asList("t", "threshold"), "Confidence threshold for suggestions. Set it to a value between 0 and 1.").withOptionalArg() .ofType(Double.class).defaultsTo(0.7); + parser.acceptsAll(asList("i", "inference"), + "Specifies whether to use inference. If yes, the schema will be loaded into a reasoner and used for computing the scores.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); // parse options and display a message for the user in case of problems OptionSet options = null; @@ -704,6 +706,7 @@ if(!options.hasArgument("endpoint")) { System.out.println("Please specify a SPARQL endpoint (using the -e option)."); + System.exit(0); } boolean verbose = (Boolean) options.valueOf("v"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-01 17:45:59
|
Revision: 3208 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3208&view=rev Author: lorenz_b Date: 2011-09-01 17:45:52 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Added more output format options - up to now: turtle, rdf, n-triples Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 17:10:43 UTC (rev 3207) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 17:45:52 UTC (rev 3208) @@ -723,33 +723,37 @@ // print output in correct format if(options.has("f")) { // TODO: handle other formats + List<AlgorithmRun> runs = e.getAlgorithmRuns(); + List<OWLAxiom> axioms = new LinkedList<OWLAxiom>(); + for(AlgorithmRun run : runs) { + axioms.addAll(e.toRDF(run.getAxioms(), run.getAlgorithm(), run.getParameters(), ks)); + } + Model model = e.getModel(axioms); if(options.valueOf("f").equals("turtle")) { - List<AlgorithmRun> runs = e.getAlgorithmRuns(); - List<OWLAxiom> axioms = new LinkedList<OWLAxiom>(); - for(AlgorithmRun run : runs) { - axioms.addAll(e.toRDF(run.getAxioms(), run.getAlgorithm(), run.getParameters(), ks)); + if(options.has("o")) { + model.write(new FileOutputStream(f), "TURTLE"); + } else { + System.out.println("ENRICHMENT["); + model.write(System.out, "N-TRIPLES"); + System.out.println("]"); } - Model model = e.getModel(axioms); - for(Statement st : model.listStatements().toList()){ - System.out.println("--------------------"); -// System.out.println(st); - if(st.getSubject().isResource()){ - System.out.println(st.getSubject()); - } - System.out.println(st.getPredicate()); - if(st.getObject().isResource()){ - - } - System.out.println(st.getObject()); + } else if(options.valueOf("f").equals("rdf")){ + if(options.has("o")) { + model.write(new FileOutputStream(f), "RDF/XML"); + } else { + System.out.println("ENRICHMENT["); + model.write(System.out, "N-TRIPLES"); + System.out.println("]"); } + } else if(options.valueOf("f").equals("n-triples")){ if(options.has("o")) { - model.write(new FileOutputStream(f)); + model.write(new FileOutputStream(f), "N-TRIPLES"); } else { System.out.println("ENRICHMENT["); - model.write(System.out); + model.write(System.out, "N-TRIPLES"); System.out.println("]"); } - } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-01 17:48:55
|
Revision: 3209 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3209&view=rev Author: lorenz_b Date: 2011-09-01 17:48:48 +0000 (Thu, 01 Sep 2011) Log Message: ----------- Small fix. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 17:45:52 UTC (rev 3208) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 17:48:48 UTC (rev 3209) @@ -734,7 +734,7 @@ model.write(new FileOutputStream(f), "TURTLE"); } else { System.out.println("ENRICHMENT["); - model.write(System.out, "N-TRIPLES"); + model.write(System.out, "TURTLE"); System.out.println("]"); } } else if(options.valueOf("f").equals("rdf")){ @@ -742,7 +742,7 @@ model.write(new FileOutputStream(f), "RDF/XML"); } else { System.out.println("ENRICHMENT["); - model.write(System.out, "N-TRIPLES"); + model.write(System.out, "RDF/XML"); System.out.println("]"); } } else if(options.valueOf("f").equals("n-triples")){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-09-01 18:51:25
|
Revision: 3210 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3210&view=rev Author: jenslehmann Date: 2011-09-01 18:51:19 +0000 (Thu, 01 Sep 2011) Log Message: ----------- several improvements in enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 17:48:48 UTC (rev 3209) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 18:51:19 UTC (rev 3210) @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; import java.net.MalformedURLException; @@ -247,9 +248,12 @@ SPARQLTasks st = new SPARQLTasks(se); if(resource == null) { + System.out.println("TEST"); + // loop over all entities and call appropriate algorithms Set<NamedClass> classes = st.getAllClasses(); for(NamedClass nc : classes) { + System.out.println(nc); runClassLearningAlgorithms(ks, nc); } Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); @@ -262,13 +266,13 @@ } } else { if(resource instanceof ObjectProperty) { - System.out.println(resource + " appears to be an object property. Running appropriate algorithms."); + System.out.println(resource + " appears to be an object property. Running appropriate algorithms.\n"); runObjectPropertyAlgorithms(ks, (ObjectProperty) resource); } else if(resource instanceof DatatypeProperty) { - System.out.println(resource + " appears to be a data property. Running appropriate algorithms."); + System.out.println(resource + " appears to be a data property. Running appropriate algorithms.\n"); runDataPropertyAlgorithms(ks, (DatatypeProperty) resource); } else if(resource instanceof NamedClass) { - System.out.println(resource + " appears to be a class. Running appropriate algorithms."); + System.out.println(resource + " appears to be a class. Running appropriate algorithms.\n"); runClassLearningAlgorithms(ks, (NamedClass) resource); } else { throw new Error("The type " + resource.getClass() + " of resource " + resource + " cannot be handled by this enrichment tool."); @@ -278,7 +282,7 @@ @SuppressWarnings("unchecked") private void runClassLearningAlgorithms(SparqlEndpointKS ks, NamedClass nc) throws ComponentInitException { - System.out.println(resource + " appears to be a class. Running appropriate algorithms."); +// System.out.println("Running algorithms for class " + nc); for (Class<? extends LearningAlgorithm> algorithmClass : classAlgorithms) { if(algorithmClass == CELOE.class) { applyCELOE(ks, nc, false); @@ -290,12 +294,14 @@ } private void runObjectPropertyAlgorithms(SparqlEndpointKS ks, ObjectProperty property) throws ComponentInitException { +// System.out.println("Running algorithms for object property " + property); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : objectPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks, property); } } private void runDataPropertyAlgorithms(SparqlEndpointKS ks, DatatypeProperty property) throws ComponentInitException { +// System.out.println("Running algorithms for data property " + property); for (Class<? extends AxiomLearningAlgorithm> algorithmClass : dataPropertyAlgorithms) { applyLearningAlgorithm(algorithmClass, ks, property); } @@ -435,7 +441,7 @@ private String prettyPrint(List<EvaluatedAxiom> learnedAxioms) { String str = "suggested axioms and their score in percent:\n"; if(learnedAxioms.isEmpty()) { - return " no axiom suggested"; + return " no axiom suggested\n"; } else { for (EvaluatedAxiom learnedAxiom : learnedAxioms) { str += " " + prettyPrint(learnedAxiom) + "\n"; @@ -590,7 +596,7 @@ try { OWLOntology ontology = OWLManager.createOWLOntologyManager().createOntology(new HashSet<OWLAxiom>(axioms)); // String s = new org.aksw.commons.owlapi.StringConverter(ontology).toStringAsRDFXML();System.out.println(s); - String s = new org.aksw.commons.owlapi.StringConverter(ontology).toStringAsTurtle();System.out.println(s); + String s = new org.aksw.commons.owlapi.StringConverter(ontology).toStringAsTurtle(); //System.out.println(s); ByteArrayInputStream bs = new ByteArrayInputStream(s.getBytes()); model.read(bs, "", "TURTLE"); } catch (OWLOntologyCreationException e) { @@ -646,7 +652,7 @@ OptionParser parser = new OptionParser(); parser.acceptsAll(asList("h", "?", "help"), "Show help."); - parser.acceptsAll(asList("v", "verbose"), "Verbosity level.").withOptionalArg().ofType(Boolean.class).defaultsTo(false); +// parser.acceptsAll(asList("v", "verbose"), "Verbosity level.").withOptionalArg().ofType(Boolean.class).defaultsTo(false); parser.acceptsAll(asList("e", "endpoint"), "SPARQL endpoint URL to be used.") .withRequiredArg().ofType(URL.class); parser.acceptsAll(asList("g", "graph"), @@ -656,8 +662,9 @@ "The resource for which enrichment axioms should be suggested.").withOptionalArg().ofType(URI.class); parser.acceptsAll(asList("o", "output"), "Specify a file where the output can be written.") .withOptionalArg().ofType(File.class); + // TODO: other interestig formats: html, manchester, sparul parser.acceptsAll(asList("f", "format"), - "Format of the generated output (plain, html, rdf/xml, turtle, manchester, sparul).").withOptionalArg() + "Format of the generated output (plain, rdf/xml, turtle, n-triples).").withOptionalArg() .ofType(String.class).defaultsTo("plain"); parser.acceptsAll(asList("t", "threshold"), "Confidence threshold for suggestions. Set it to a value between 0 and 1.").withOptionalArg() @@ -709,20 +716,25 @@ System.exit(0); } - boolean verbose = (Boolean) options.valueOf("v"); +// boolean verbose = (Boolean) options.valueOf("v"); double threshold = (Double) options.valueOf("t"); - Enrichment e = new Enrichment(se, resource, threshold, verbose); + // TODO: some handling for inaccessible files or overwriting existing files + File f = (File) options.valueOf("o"); + + // if plain and file option is given, redirect System.out to a file + if(options.has("o") && (!options.has("f") || options.valueOf("f").equals("plain"))) { + PrintStream printStream = new PrintStream(new FileOutputStream(f)); + System.setOut(printStream); + } + + Enrichment e = new Enrichment(se, resource, threshold, false); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); - // TODO: some handling for inaccessible files or overwriting existing files - File f = (File) options.valueOf("o"); - // print output in correct format if(options.has("f")) { - // TODO: handle other formats List<AlgorithmRun> runs = e.getAlgorithmRuns(); List<OWLAxiom> axioms = new LinkedList<OWLAxiom>(); for(AlgorithmRun run : runs) { @@ -737,7 +749,7 @@ model.write(System.out, "TURTLE"); System.out.println("]"); } - } else if(options.valueOf("f").equals("rdf")){ + } else if(options.valueOf("f").equals("rdf/xml")){ if(options.has("o")) { model.write(new FileOutputStream(f), "RDF/XML"); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-09-01 18:59:41
|
Revision: 3211 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3211&view=rev Author: jenslehmann Date: 2011-09-01 18:59:35 +0000 (Thu, 01 Sep 2011) Log Message: ----------- added field to better be able to test full enrichment Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 18:51:19 UTC (rev 3210) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-01 18:59:35 UTC (rev 3211) @@ -181,6 +181,10 @@ // max. execution time for each learner for each entity private int maxExecutionTimeInSeconds = 10; + // restrict tested number of entities per type (only for testing purposes); + // should be set to 0 in production mode + private int maxEntitiesPerType = 0; + // number of axioms which will be learned/considered (only applies to // some learners) private int nrOfAxiomsToLearn = 10; @@ -252,17 +256,31 @@ // loop over all entities and call appropriate algorithms Set<NamedClass> classes = st.getAllClasses(); + int entities = 0; for(NamedClass nc : classes) { - System.out.println(nc); - runClassLearningAlgorithms(ks, nc); + runClassLearningAlgorithms(ks, nc); + entities++; + if(entities > maxEntitiesPerType) { + break; + } } + entities = 0; Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); for(ObjectProperty property : objectProperties) { - runObjectPropertyAlgorithms(ks, property); + runObjectPropertyAlgorithms(ks, property); + entities++; + if(entities > maxEntitiesPerType) { + break; + } } + entities = 0; Set<DatatypeProperty> dataProperties = st.getAllDataProperties(); for(DatatypeProperty property : dataProperties) { - runDataPropertyAlgorithms(ks, property); + runDataPropertyAlgorithms(ks, property); + entities++; + if(entities > maxEntitiesPerType) { + break; + } } } else { if(resource instanceof ObjectProperty) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-02 07:22:33
|
Revision: 3219 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3219&view=rev Author: lorenz_b Date: 2011-09-02 07:22:27 +0000 (Fri, 02 Sep 2011) Log Message: ----------- Improved enrichment output for CELOE. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 06:51:19 UTC (rev 3218) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 07:22:27 UTC (rev 3219) @@ -389,13 +389,13 @@ la.setMaxExecutionTimeInSeconds(10); la.setNoisePercentage(25); la.init(); - System.out.print("running CELOE ... "); + System.out.print("running CELOE (for " + (equivalence ? "EquivalentClasses" : "SubClasses)") + "... "); 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>(); + List<EvaluatedAxiom> learnedAxioms = new LinkedList<EvaluatedAxiom>(); for(EvaluatedDescription learnedDescription : learnedDescriptions) { Axiom axiom; if(equivalence) { @@ -404,11 +404,12 @@ axiom = new SubClassAxiom(nc, learnedDescription.getDescription()); } Score score = lp.computeScore(learnedDescription.getDescription()); - evaluatedAxioms.add(new EvaluatedAxiom(axiom, score)); + learnedAxioms.add(new EvaluatedAxiom(axiom, score)); } + System.out.println(prettyPrint(learnedAxioms)); - algorithmRuns.add(new AlgorithmRun(CELOE.class, evaluatedAxioms, ConfigHelper.getConfigOptionValuesString(la))); - return evaluatedAxioms; + algorithmRuns.add(new AlgorithmRun(CELOE.class, learnedAxioms, ConfigHelper.getConfigOptionValuesString(la))); + return learnedAxioms; } private List<EvaluatedAxiom> applyLearningAlgorithm(Class<? extends AxiomLearningAlgorithm> algorithmClass, SparqlEndpointKS ks, Entity entity) throws ComponentInitException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-02 09:23:51
|
Revision: 3226 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3226&view=rev Author: lorenz_b Date: 2011-09-02 09:23:45 +0000 (Fri, 02 Sep 2011) Log Message: ----------- Added default prefix. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 09:19:50 UTC (rev 3225) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 09:23:45 UTC (rev 3226) @@ -608,6 +608,7 @@ } catch (OWLOntologyCreationException e) { e.printStackTrace(); } + model.setNsPrefix("enr", "http://www.dl-learner.org/enrichment.owl#"); return model; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-02 12:03:04
|
Revision: 3232 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3232&view=rev Author: lorenz_b Date: 2011-09-02 12:02:58 +0000 (Fri, 02 Sep 2011) Log Message: ----------- Added timestamp to enrichment output Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 12:01:29 UTC (rev 3231) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-02 12:02:58 UTC (rev 3232) @@ -36,6 +36,7 @@ import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -522,6 +523,9 @@ ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.parameterValue, paramInd, entry.getValue().toString()); axioms.add(ax); } + //add timestamp + ax = f.getOWLDataPropertyAssertionAxiom(EnrichmentVocabulary.timestamp, algorithmRunInd, System.currentTimeMillis()); + axioms.add(ax); //add used input to algorithm run instance try { OWLNamedIndividual knowldegeBaseInd = f.getOWLNamedIndividual(IRI.create(ks.getEndpoint().getURL())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-13 09:54:25
|
Revision: 3251 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3251&view=rev Author: lorenz_b Date: 2011-09-13 09:54:19 +0000 (Tue, 13 Sep 2011) Log Message: ----------- Small update. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-13 09:52:14 UTC (rev 3250) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-13 09:54:19 UTC (rev 3251) @@ -106,6 +106,7 @@ import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.Helper; +import org.dllearner.utilities.PrefixCCMap; import org.dllearner.utilities.datastructures.Datastructures; import org.dllearner.utilities.datastructures.SetManipulation; import org.dllearner.utilities.datastructures.SortedSetTuple; @@ -201,7 +202,7 @@ // list of generated axioms while script is running private List<AlgorithmRun> algorithmRuns; - private CommonPrefixMap prefixes = new CommonPrefixMap(); +// private CommonPrefixMap prefixes = new CommonPrefixMap(); // cache for SparqKnowledgeSource SparqlKnowledgeSource ksCached; @@ -479,7 +480,7 @@ String accs = df.format(acc); if(accs.length()==3) { accs = " " + accs; } if(accs.length()==4) { accs = " " + accs; } - String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, prefixes); + String str = accs + "%\t" + axiom.getAxiom().toManchesterSyntaxString(null, PrefixCCMap.getInstance()); return str; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jen...@us...> - 2011-09-14 17:45:03
|
Revision: 3264 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3264&view=rev Author: jenslehmann Date: 2011-09-14 17:44:57 +0000 (Wed, 14 Sep 2011) Log Message: ----------- improved exception handling in enrichment script Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-14 14:29:01 UTC (rev 3263) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-14 17:44:57 UTC (rev 3264) @@ -36,7 +36,6 @@ import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -46,6 +45,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import joptsimple.OptionException; import joptsimple.OptionParser; import joptsimple.OptionSet; @@ -103,7 +103,6 @@ import org.dllearner.learningproblems.Heuristics.HeuristicType; import org.dllearner.reasoning.FastInstanceChecker; import org.dllearner.reasoning.SPARQLReasoner; -import org.dllearner.utilities.CommonPrefixMap; import org.dllearner.utilities.EnrichmentVocabulary; import org.dllearner.utilities.Helper; import org.dllearner.utilities.PrefixCCMap; @@ -130,6 +129,7 @@ import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.sparql.engine.http.QueryExceptionHTTP; /** * Command Line Interface for Enrichment. @@ -242,17 +242,8 @@ algorithmRuns = new LinkedList<AlgorithmRun>(); } - @SuppressWarnings("unchecked") public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { - - // sanity check that endpoint/graph returns at least one triple - String query = "SELECT * WHERE {?s ?p ?o} LIMIT 1"; - SparqlQuery sq = new SparqlQuery(query, se); - ResultSet q = sq.send(); - while (q.hasNext()) { - q.next(); - } - + // instantiate SPARQL endpoint wrapper component SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); @@ -721,16 +712,47 @@ System.out.println(); System.out.println(addHelp); // main script - } else { - // create SPARQL endpoint object - URL endpoint = (URL) options.valueOf("endpoint"); - URI graph = (URI) options.valueOf("graph"); + } 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 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 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>()); + // sanity check that endpoint/graph returns at least one triple + String query = "SELECT * WHERE {?s ?p ?o} LIMIT 1"; + SparqlQuery sq = new SparqlQuery(query, se); + try { + ResultSet q = sq.send(); + while (q.hasNext()) { + q.next(); + } + } catch(QueryExceptionHTTP e) { + System.out.println("Endpoint not reachable (check spelling)."); + System.exit(0); + } + // map resource to correct type Entity resource = null; if(options.valueOf("resource") != null) { @@ -740,11 +762,6 @@ } } - if(!options.hasArgument("endpoint")) { - System.out.println("Please specify a SPARQL endpoint (using the -e option)."); - System.exit(0); - } - boolean useInference = (Boolean) options.valueOf("i"); // boolean verbose = (Boolean) options.valueOf("v"); double threshold = (Double) options.valueOf("t"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-15 08:15:59
|
Revision: 3268 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3268&view=rev Author: lorenz_b Date: 2011-09-15 08:15:48 +0000 (Thu, 15 Sep 2011) Log Message: ----------- Added new method for guessing entity type of a resource. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-15 08:13:12 UTC (rev 3267) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-15 08:15:48 UTC (rev 3268) @@ -365,6 +365,7 @@ ks2.setUseCacheDatabase(true); ks2.setRecursionDepth(2); ks2.setCloseAfterRecursion(true); + ks2.setSaveExtractedFragment(true); startTime = System.currentTimeMillis(); System.out.print("getting knowledge base fragment ... "); ks2.init(); @@ -756,7 +757,7 @@ // map resource to correct type Entity resource = null; if(options.valueOf("resource") != null) { - resource = new SPARQLTasks(se).guessResourceType(((URI)options.valueOf("resource")).toString()); + resource = new SPARQLTasks(se).guessResourceType(((URI)options.valueOf("resource")).toString(), true); if(resource == null) { throw new IllegalArgumentException("Could not determine the type (class, object property or data property) of input resource " + options.valueOf("resource")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-09-16 20:20:58
|
Revision: 3277 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3277&view=rev Author: lorenz_b Date: 2011-09-16 20:20:52 +0000 (Fri, 16 Sep 2011) Log Message: ----------- Added option to save all learned axioms into a ontology file by using the parameter -s. Fixed bug which always led to only one visited entity per type, if no resource was explicitly given. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-16 20:17:22 UTC (rev 3276) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-09-16 20:20:52 UTC (rev 3277) @@ -21,10 +21,12 @@ import static java.util.Arrays.asList; +import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; @@ -83,6 +85,7 @@ import org.dllearner.core.EvaluatedDescription; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblemUnsupportedException; +import org.dllearner.core.OntologyFormat; import org.dllearner.core.Score; import org.dllearner.core.config.ConfigHelper; import org.dllearner.core.config.ConfigOption; @@ -110,7 +113,12 @@ 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.OWLAPIAxiomConvertVisitor; +import org.dllearner.utilities.owl.OWLAPIConverter; +import org.dllearner.utilities.owl.OWLAPIDescriptionConvertVisitor; import org.semanticweb.owlapi.apibinding.OWLManager; +import org.semanticweb.owlapi.io.RDFXMLOntologyFormat; import org.semanticweb.owlapi.io.SystemOutDocumentTarget; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotation; @@ -183,8 +191,8 @@ private int maxExecutionTimeInSeconds = 10; // restrict tested number of entities per type (only for testing purposes); - // should be set to 0 in production mode - private int maxEntitiesPerType = 0; + // should be set to -1 in production mode + private int maxEntitiesPerType = -1; // number of axioms which will be learned/considered (only applies to // some learners) @@ -208,6 +216,8 @@ SparqlKnowledgeSource ksCached; AbstractReasonerComponent rcCached; + private Set<OWLAxiom> learnedOWLAxioms; + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, boolean useInference, boolean verbose) { this.se = se; this.resource = resource; @@ -240,6 +250,8 @@ classAlgorithms.add(CELOE.class); algorithmRuns = new LinkedList<AlgorithmRun>(); + + learnedOWLAxioms = new HashSet<OWLAxiom>(); } public void start() throws ComponentInitException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, LearningProblemUnsupportedException, MalformedURLException { @@ -248,6 +260,13 @@ SparqlEndpointKS ks = new SparqlEndpointKS(se); ks.init(); + // common helper objects + SPARQLTasks st = new SPARQLTasks(se); + + //check if endpoint supports SPARQL 1.1 + boolean supportsSPARQL_1_1 = st.supportsSPARQL_1_1(); + ks.setSupportsSPARQL_1_1(supportsSPARQL_1_1); + if(useInference){ reasoner = new SPARQLReasoner(ks); System.out.print("Precomputing subsumption hierarchy ... "); @@ -256,9 +275,6 @@ System.out.println("done in " + (System.currentTimeMillis() - startTime) + " ms"); } - // common helper objects - SPARQLTasks st = new SPARQLTasks(se); - if(resource == null) { // loop over all entities and call appropriate algorithms @@ -267,16 +283,16 @@ for(NamedClass nc : classes) { runClassLearningAlgorithms(ks, nc); entities++; - if(entities > maxEntitiesPerType) { + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { break; - } + } } entities = 0; Set<ObjectProperty> objectProperties = st.getAllObjectProperties(); for(ObjectProperty property : objectProperties) { runObjectPropertyAlgorithms(ks, property); entities++; - if(entities > maxEntitiesPerType) { + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { break; } } @@ -285,9 +301,9 @@ for(DatatypeProperty property : dataProperties) { runDataPropertyAlgorithms(ks, property); entities++; - if(entities > maxEntitiesPerType) { + if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { break; - } + } } } else { if(resource instanceof ObjectProperty) { @@ -449,8 +465,12 @@ System.out.println("done in " + runtime + " ms"); List<EvaluatedAxiom> learnedAxioms = learner .getCurrentlyBestEvaluatedAxioms(nrOfAxiomsToLearn, threshold); - System.out.println(prettyPrint(learnedAxioms)); + System.out.println(prettyPrint(learnedAxioms)); + for(EvaluatedAxiom evAx : learnedAxioms){ + learnedOWLAxioms.add(OWLAPIAxiomConvertVisitor.convertAxiom(evAx.getAxiom())); + } + algorithmRuns.add(new AlgorithmRun(learner.getClass(), learnedAxioms, ConfigHelper.getConfigOptionValues(learner))); return learnedAxioms; } @@ -626,6 +646,18 @@ return model; } + private OWLOntology getGeneratedOntology(){ + OWLOntology ontology = null; + try { + OWLOntologyManager man = OWLManager.createOWLOntologyManager(); + ontology = man.createOntology(learnedOWLAxioms); + } catch (OWLOntologyCreationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return ontology; + } + /* * Write axioms in Turtle syntax. */ @@ -692,7 +724,8 @@ .ofType(Double.class).defaultsTo(0.7); parser.acceptsAll(asList("i", "inference"), "Specifies whether to use inference. If yes, the schema will be loaded into a reasoner and used for computing the scores.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); - + parser.acceptsAll(asList("s", "serialize"), "Specify a file where the ontology with all axioms can be written.") + .withRequiredArg().ofType(File.class); // parse options and display a message for the user in case of problems OptionSet options = null; try { @@ -822,7 +855,19 @@ } } } + //serialize ontology + if(options.has("s")){ + File file = (File)options.valueOf("s"); + try { + OWLOntology ontology = e.getGeneratedOntology(); + OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); + OWLManager.createOWLOntologyManager().saveOntology(ontology, new RDFXMLOntologyFormat(), os); + } catch (OWLOntologyStorageException e1) { + throw new Error("Could not save ontology."); + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-15 14:36:45
|
Revision: 3404 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3404&view=rev Author: lorenz_b Date: 2011-11-15 14:36:34 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Changed script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-11-14 22:08:32 UTC (rev 3403) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-11-15 14:36:34 UTC (rev 3404) @@ -23,6 +23,7 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -218,11 +219,12 @@ private Set<OWLAxiom> learnedOWLAxioms; - public Enrichment(SparqlEndpoint se, Entity resource, double threshold, boolean useInference, boolean verbose) { + public Enrichment(SparqlEndpoint se, Entity resource, double threshold, int nrOfAxiomsToLearn, boolean useInference, boolean verbose) { this.se = se; this.resource = resource; this.verbose = verbose; this.threshold = threshold; + this.nrOfAxiomsToLearn = nrOfAxiomsToLearn; this.useInference = useInference; objectPropertyAlgorithms = new LinkedList<Class<? extends AxiomLearningAlgorithm>>(); @@ -722,6 +724,9 @@ parser.acceptsAll(asList("t", "threshold"), "Confidence threshold for suggestions. Set it to a value between 0 and 1.").withOptionalArg() .ofType(Double.class).defaultsTo(0.7); + parser.acceptsAll(asList("l", "limit"), + "Maximum number of returned axioms per axiom type. Set it to -1 if all axioms above the threshold should be returned.").withOptionalArg() + .ofType(Integer.class).defaultsTo(10); parser.acceptsAll(asList("i", "inference"), "Specifies whether to use inference. If yes, the schema will be loaded into a reasoner and used for computing the scores.").withOptionalArg().ofType(Boolean.class).defaultsTo(true); parser.acceptsAll(asList("s", "serialize"), "Specify a file where the ontology with all axioms can be written.") @@ -806,6 +811,10 @@ boolean useInference = (Boolean) options.valueOf("i"); // boolean verbose = (Boolean) options.valueOf("v"); double threshold = (Double) options.valueOf("t"); + int maxNrOfResults = (Integer) options.valueOf("l"); + if(maxNrOfResults == -1){ + maxNrOfResults = Integer.MAX_VALUE; + } // TODO: some handling for inaccessible files or overwriting existing files File f = (File) options.valueOf("o"); @@ -816,7 +825,7 @@ System.setOut(printStream); } - Enrichment e = new Enrichment(se, resource, threshold, useInference, false); + Enrichment e = new Enrichment(se, resource, threshold, maxNrOfResults, useInference, false); e.start(); SparqlEndpointKS ks = new SparqlEndpointKS(se); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-11-15 20:14:46
|
Revision: 3405 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3405&view=rev Author: lorenz_b Date: 2011-11-15 20:14:39 +0000 (Tue, 15 Nov 2011) Log Message: ----------- Added workaround for CELOE for the case that the class is empty, e.g. also not found by the reasoner which will cause a ComponentInitException. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-11-15 14:36:34 UTC (rev 3404) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-11-15 20:14:39 UTC (rev 3405) @@ -39,6 +39,7 @@ import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -283,7 +284,11 @@ Set<NamedClass> classes = st.getAllClasses(); int entities = 0; for(NamedClass nc : classes) { - runClassLearningAlgorithms(ks, nc); + try { + runClassLearningAlgorithms(ks, nc); + } catch (Exception e) { + e.printStackTrace(); + } entities++; if(maxEntitiesPerType != -1 && entities > maxEntitiesPerType) { break; @@ -355,6 +360,10 @@ // get instances of class as positive examples SPARQLReasoner sr = new SPARQLReasoner(ks); SortedSet<Individual> posExamples = sr.getIndividuals(nc, 20); + if(posExamples.isEmpty()){ + System.out.println("Skipping CELOE because class " + nc.toString() + " is empty."); + return Collections.emptyList(); + } SortedSet<String> posExStr = Helper.getStringSet(posExamples); // use own implementation of negative example finder This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lor...@us...> - 2011-12-01 21:44:24
|
Revision: 3463 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3463&view=rev Author: lorenz_b Date: 2011-12-01 21:44:18 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Added new algorithms to enrichment script. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-12-01 14:27:28 UTC (rev 3462) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-12-01 21:44:18 UTC (rev 3463) @@ -62,6 +62,7 @@ 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; @@ -71,6 +72,7 @@ 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.ObjectPropertyDomainAxiomLearner; import org.dllearner.algorithms.properties.ObjectPropertyRangeAxiomLearner; import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; @@ -237,7 +239,9 @@ objectPropertyAlgorithms.add(ObjectPropertyRangeAxiomLearner.class); objectPropertyAlgorithms.add(SubObjectPropertyOfAxiomLearner.class); objectPropertyAlgorithms.add(SymmetricObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(AsymmetricObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(InverseObjectPropertyAxiomLearner.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-12-02 09:51:26
|
Revision: 3465 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=3465&view=rev Author: lorenz_b Date: 2011-12-02 09:51:19 +0000 (Fri, 02 Dec 2011) Log Message: ----------- Added algorithms. Modified Paths: -------------- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java Modified: trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java =================================================================== --- trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-12-01 22:06:17 UTC (rev 3464) +++ trunk/interfaces/src/main/java/org/dllearner/cli/Enrichment.java 2011-12-02 09:51:19 UTC (rev 3465) @@ -73,8 +73,10 @@ 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; +import org.dllearner.algorithms.properties.ReflexiveObjectPropertyAxiomLearner; import org.dllearner.algorithms.properties.SubDataPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SubObjectPropertyOfAxiomLearner; import org.dllearner.algorithms.properties.SymmetricObjectPropertyAxiomLearner; @@ -242,6 +244,8 @@ objectPropertyAlgorithms.add(AsymmetricObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(TransitiveObjectPropertyAxiomLearner.class); objectPropertyAlgorithms.add(InverseObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(ReflexiveObjectPropertyAxiomLearner.class); + objectPropertyAlgorithms.add(IrreflexiveObjectPropertyAxiomLearner.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. |