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.utilities.examples; 020 021import java.util.SortedSet; 022import java.util.TreeSet; 023 024import org.jetbrains.annotations.NotNull; 025import org.semanticweb.owlapi.model.OWLIndividual; 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 */ 038public class ExampleContainer implements Comparable<ExampleContainer>{ 039 040 041 private static SortedSet<ExampleContainer> exampleSets = new TreeSet<>(); 042 043 private SortedSet<OWLIndividual> positiveExamples = new TreeSet<>(); 044 private SortedSet<OWLIndividual> negativeExamples = new TreeSet<>(); 045 046 047 public ExampleContainer(SortedSet<OWLIndividual> positiveExamples, SortedSet<OWLIndividual> 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 the example container 058 * @return 059 */ 060 public static boolean add(ExampleContainer e){ 061 return exampleSets.add(e); 062 } 063 064 @Override 065 public int compareTo(@NotNull ExampleContainer e){ 066 067 if(getNegativeExamples().equals(e.getNegativeExamples()) 068 && 069 getPositiveExamples().equals(e.getPositiveExamples())){ 070 return 0; 071 } 072 073 boolean equalPosSize = getPositiveExamples().size() == e.getPositiveExamples().size(); 074 boolean equalNegSize = getNegativeExamples().size() == e.getNegativeExamples().size(); 075 076 if(equalPosSize && !equalNegSize)return 1; 077 if(equalNegSize && !equalPosSize)return -1; 078 if(!equalPosSize && !equalNegSize)return 1; 079 080 return 1; 081 } 082 083 public SortedSet<OWLIndividual> getNegativeExamples() { 084 return negativeExamples; 085 } 086 public SortedSet<OWLIndividual> getPositiveExamples() { 087 return positiveExamples; 088 } 089}