001package org.dllearner.examples; 002 003import java.io.File; 004import java.util.HashSet; 005import java.util.Set; 006 007import org.dllearner.algorithms.celoe.CELOE; 008import org.dllearner.core.ComponentInitException; 009import org.dllearner.core.KnowledgeSource; 010import org.dllearner.kb.OWLFile; 011import org.dllearner.learningproblems.PosNegLPStandard; 012import org.dllearner.reasoning.ClosedWorldReasoner; 013import org.semanticweb.owlapi.model.IRI; 014import org.semanticweb.owlapi.model.OWLIndividual; 015 016import com.google.common.collect.Sets; 017 018import uk.ac.manchester.cs.owl.owlapi.OWLNamedIndividualImpl; 019 020/** 021 * This class should exemplify how to run CELOE programmatically, i.e. by 022 * creating all components explicitly in Java. This example runs the same 023 * experiment as the examples/father.conf does. 024 */ 025public class CELOEUsageExample { 026 static File familyExamplesDir = new File("../examples"); 027 static String uriPrefix = "http://example.com/father#"; 028 029 public static void main(String[] args) throws ComponentInitException { 030 /* Define the knowledge source 031 * > ks.type = "OWL File" 032 * > ks.fileName = "father.owl" 033 */ 034 OWLFile ks = new OWLFile(); 035 ks.setFileName(familyExamplesDir.getAbsolutePath() + "/father.owl"); 036 ks.init(); 037 038 /* Set up the reasoner 039 * > reasoner.type = "closed world reasoner" 040 * > reasoner.sources = { ks } 041 */ 042 ClosedWorldReasoner reasoner = new ClosedWorldReasoner(); 043 044 // create { ks }, i.e. a set containing ks 045 Set<KnowledgeSource> sources = new HashSet<>(); 046 sources.add(ks); 047 048 reasoner.setSources(sources); 049 reasoner.init(); 050 051 /* Set up the learning problem 052 * > lp.type = "posNegStandard" 053 * > lp.positiveExamples = { "ex:stefan", "ex:markus", "ex:martin" } 054 * > lp.negativeExamples = { "ex:heinz", "ex:anna", "ex:michelle" } 055 */ 056 PosNegLPStandard lp = new PosNegLPStandard(reasoner); 057 058 HashSet<OWLIndividual> posExamples = Sets.newHashSet( 059 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "stefan")), 060 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "markus")), 061 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "martin")) 062 ); 063 lp.setPositiveExamples(posExamples); 064 065 HashSet<OWLIndividual> negExamples = Sets.newHashSet( 066 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "heinz")), 067 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "anna")), 068 new OWLNamedIndividualImpl(IRI.create(uriPrefix + "michelle")) 069 ); 070 lp.setNegativeExamples(negExamples); 071 072 lp.init(); 073 074 /* Set up the learning algorithm 075 * > alg.type = "celoe" 076 * > alg.maxExecutionTimeInSeconds = 1 077 */ 078 CELOE alg = new CELOE(); 079 alg.setMaxExecutionTimeInSeconds(1); 080 081 // This 'wiring' is not part of the configuration file since it is 082 // done automatically when using bin/cli. However it has to be done explicitly, 083 // here. 084 alg.setLearningProblem(lp); 085 alg.setReasoner(reasoner); 086 087 alg.init(); 088 089 alg.start(); 090 } 091}