001/**
002 * This file is part of LEAP.
003 *
004 * LEAP was implemented as a plugin of DL-Learner http://dl-learner.org, but
005 * some components can be used as stand-alone.
006 *
007 * LEAP is free software; you can redistribute it and/or modify it under the
008 * terms of the GNU General Public License as published by the Free Software
009 * Foundation; either version 3 of the License, or (at your option) any later
010 * version.
011 *
012 * LEAP is distributed in the hope that it will be useful, but WITHOUT ANY
013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
014 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License along with
017 * this program. If not, see <http://www.gnu.org/licenses/>.
018 *
019 */
020package org.dllearner.core.probabilistic.unife;
021
022import java.io.File;
023import java.io.IOException;
024import java.math.BigDecimal;
025import java.util.Map;
026import java.util.Set;
027import org.dllearner.core.AbstractLearningProblem;
028import org.dllearner.core.KnowledgeSource;
029import org.dllearner.core.LearningAlgorithm;
030import org.dllearner.core.LearningProblem;
031import org.dllearner.core.StoppableLearningAlgorithm;
032import org.dllearner.core.config.ConfigOption;
033import org.semanticweb.owlapi.model.OWLAxiom;
034import org.springframework.beans.factory.annotation.Autowired;
035
036/**
037 * Abstract component representing a parameter Learner. A parameter learner
038 * computes the probabilistic value of a single axiom
039 *
040 * @author Giuseppe Cota
041 */
042public abstract class AbstractParameterLearningAlgorithm implements ParameterLearningAlgorithm, StoppableLearningAlgorithm {
043
044    protected boolean isRunning = false;
045    protected boolean stop = false;
046
047    /**
048     * set of all the theories
049     */
050    //protected Set<KnowledgeSource> sources;
051    /**
052     * File URI (String) containing the target axioms, whose parameters we want
053     * to learn
054     */
055    //protected String targetAxioms;
056    protected Set<OWLAxiom> targetAxioms;
057    protected AbstractLearningProblem learningProblem;
058
059    @ConfigOption(description = "Force the reduction of the number of individuals in the initial ontology", defaultValue = "false")
060    protected boolean reduceOntology = false;
061
062    public AbstractParameterLearningAlgorithm() {
063
064    }
065
066    /**
067     *
068     * @param learningProblem
069     * @param targetAxioms target axioms in manchester syntax
070     */
071//    public AbstractLearningParameter(AbstractLearningProblem learningProblem, String targetAxioms){
072//        this.sources=learningProblem.getReasoner().getSources();
073//        this.targetAxioms=targetAxioms;
074//        this.learningProblem=learningProblem;
075//    }
076    public AbstractParameterLearningAlgorithm(AbstractLearningProblem learningProblem, Set<OWLAxiom> targetAxioms) {
077        //this.sources = learningProblem.getReasoner().getSources();
078        this.targetAxioms = targetAxioms;
079        this.learningProblem = learningProblem;
080    }
081
082    /**
083     * Sets the target axioms of which want to learn the parameters.
084     *
085     * @param targetAxioms
086     */
087    public void setTargetAxioms(Set<OWLAxiom> targetAxioms) {
088        this.targetAxioms = targetAxioms;
089    }
090
091    /**
092     * Gets the target axioms.
093     *
094     * @return target axioms
095     */
096    public Set<OWLAxiom> getTargetAxioms() {
097        return targetAxioms;
098    }
099
100    /**
101     * Gets the probabilistic parameter of an axiom
102     *
103     * @param ax
104     * @return the probabilistic parameter of the axiom
105     */
106    public abstract BigDecimal getParameter(OWLAxiom ax) throws ParameterLearningException;
107
108    /**
109     * Gets the map of the time in milliseconds spent by various algorithms.
110     *
111     * @return
112     */
113    public abstract Map<String, Long> getTimeMap();
114
115//    /**
116//     * Gets the knowledge sources used by this parameters learner
117//     *
118//     * @return the underlying knowledge sources
119//     */
120//    public Set<KnowledgeSource> getSources() {
121//        return sources;
122//    }
123//
124//    /**
125//     * Method to change the knowledge sources underlying the parameter learner.
126//     * Changes only the knowledge sources contained in this class. Does not
127//     * affect other classes
128//     *
129//     * @param sources The new knowledge sources.
130//     */
131//    public void changeSources(Set<KnowledgeSource> sources) {
132//        this.sources = sources;
133//    }
134
135    /**
136     * Gets the target axioms whose parameters we want to learn
137     *
138     * @return the underlying target axioms
139     */
140//    public String getTargetAxioms() {
141//        return targetAxioms;
142//    }
143    /**
144     * Changes the target axioms underlying the parameter learner
145     *
146     * @param the underlying target axioms
147     */
148//    public void changeTargetAxioms(String targetAxioms) {
149//        this.targetAxioms = targetAxioms;
150//    }
151    /**
152     * The learning problem variable, which must be used by all learning
153     * algorithm implementations.
154     */
155    @Override
156    public AbstractLearningProblem getLearningProblem() {
157        return learningProblem;
158    }
159
160    @Override
161    @Autowired
162    public void setLearningProblem(LearningProblem learningProblem) {
163        this.learningProblem = (AbstractLearningProblem) learningProblem;
164    }
165
166    @Override
167    public boolean isRunning() {
168        return isRunning;
169    }
170
171    @Override
172    public void stop() {
173        stop = true;
174    }
175
176}