001 /**
002 * Copyright (C) 2007-2011, 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 */
019
020 package org.dllearner.utilities.examples;
021
022 import java.util.SortedSet;
023 import java.util.TreeSet;
024
025 import org.dllearner.core.owl.Individual;
026
027
028
029 /**
030 * A simple container for storing pos and negexamples,
031 * basically a more simple parameter or return value.
032 *
033 * It also contains static functions to test if all example sets are different.
034 *
035 * @author Sebastian Hellmann
036 *
037 */
038 public class ExampleContainer implements Comparable<ExampleContainer>{
039
040
041 private static SortedSet<ExampleContainer> exampleSets = new TreeSet<ExampleContainer>();
042
043 private SortedSet<Individual> positiveExamples = new TreeSet<Individual>();
044 private SortedSet<Individual> negativeExamples = new TreeSet<Individual>();
045
046
047 public ExampleContainer(SortedSet<Individual> positiveExamples, SortedSet<Individual> negativeExamples) {
048 super();
049 this.positiveExamples = positiveExamples;
050 this.negativeExamples = negativeExamples;
051 }
052
053
054 /**
055 * adds to a global example repository.
056 * returns false, if the set is contained already
057 * @param e
058 * @return
059 */
060 public static boolean add(ExampleContainer e){
061 return exampleSets.add(e);
062 }
063
064 public int compareTo(ExampleContainer e){
065
066 if(getNegativeExamples().equals(e.getNegativeExamples())
067 &&
068 getPositiveExamples().equals(e.getPositiveExamples())){
069 return 0;
070 }
071
072 boolean equalPosSize = false;
073 boolean equalNegSize = false;
074
075 if(getPositiveExamples().size() == e.getPositiveExamples().size()){
076 equalPosSize = true;
077 }
078 if(getNegativeExamples().size() == e.getNegativeExamples().size()){
079 equalNegSize = true;
080 }
081
082
083 if(equalPosSize && !equalNegSize)return 1;
084 if(equalNegSize && !equalPosSize)return -1;
085 if(!equalPosSize && !equalPosSize)return 1;
086
087
088 return 1;
089
090 }
091
092 public SortedSet<Individual> getNegativeExamples() {
093 return negativeExamples;
094 }
095 public SortedSet<Individual> getPositiveExamples() {
096 return positiveExamples;
097 }
098
099
100
101
102 }