001/**
002 * Copyright (C) 2007 - 2016, Jens Lehmann
003 *
004 * This file is part of DL-Learner.
005 *
006 * DL-Learner is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * DL-Learner is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.dllearner.learningproblems;
020
021import java.util.Map;
022import java.util.Set;
023import java.util.SortedSet;
024import java.util.TreeSet;
025import java.util.stream.Collectors;
026
027import com.google.common.collect.Sets;
028import org.dllearner.core.AbstractClassExpressionLearningProblem;
029import org.dllearner.core.AbstractReasonerComponent;
030import org.dllearner.core.ComponentInitException;
031import org.dllearner.core.config.ConfigOption;
032import org.dllearner.core.owl.fuzzydll.FuzzyIndividual;
033import org.dllearner.utilities.Helper;
034import org.semanticweb.owlapi.model.OWLIndividual;
035import org.semanticweb.owlapi.model.OWLNamedIndividual;
036
037/**
038 * @author Jens Lehmann
039 *
040 */
041public abstract class FuzzyPosNegLP extends AbstractClassExpressionLearningProblem<ScorePosNeg<OWLNamedIndividual>> {
042        
043        @ConfigOption()
044        protected SortedSet<OWLIndividual> positiveExamples;
045        @ConfigOption()
046        protected SortedSet<OWLIndividual> negativeExamples;
047
048        protected SortedSet<OWLIndividual> allExamples;
049        @ConfigOption()
050        protected SortedSet<FuzzyIndividual> fuzzyExamples;
051
052        protected double percentPerLengthUnit = 0.05;
053        protected double totalTruth = 0;
054        
055        public FuzzyPosNegLP() {}
056        
057        public FuzzyPosNegLP(AbstractReasonerComponent reasoningService) {
058                super(reasoningService);
059        }
060        
061        /*
062         * (non-Javadoc)
063         * 
064         * @see org.dllearner.core.Component#init()
065         */
066        @Override
067        public void init() throws ComponentInitException {
068                // commented by Josue as now there's no need of + and - examples (more code need to be deleted in this sense)
069                // allExamples = Helper.union(positiveExamples, negativeExamples);
070
071                // sanity check whether examples are contained in KB
072                Helper.checkIndividuals(reasoner, Sets.union(Sets.union(positiveExamples, negativeExamples), fuzzyExamples));
073
074                initialized = true;
075        }
076        
077        public SortedSet<OWLIndividual> getNegativeExamples() {
078                return negativeExamples;
079        }
080
081        public SortedSet<OWLIndividual> getPositiveExamples() {
082                return positiveExamples;
083        }
084        
085        public void setNegativeExamples(SortedSet<OWLIndividual> set) {
086                this.negativeExamples=set;
087        }
088
089        public void setPositiveExamples(SortedSet<OWLIndividual> set) {
090                this.positiveExamples=set;
091        }
092
093        public double getPercentPerLengthUnit() {
094                return percentPerLengthUnit;
095        }
096
097        public SortedSet<FuzzyIndividual> getFuzzyExamples() {
098                return fuzzyExamples;
099        }
100
101        public void setFuzzyExamples(SortedSet<FuzzyIndividual> fuzzyExamples) {
102                this.fuzzyExamples = fuzzyExamples;
103        }
104
105        public void setFuzzyExamples(Map<OWLIndividual, Double> fuzzyEx) {
106                fuzzyExamples = fuzzyEx.entrySet().stream()
107                                .map(e -> new FuzzyIndividual(e.getKey().toStringID(), e.getValue()))
108                                .collect(Collectors.toCollection(TreeSet::new));
109        }
110
111
112        
113}