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.owl;
021
022 import java.util.Collection;
023 import java.util.Iterator;
024 import java.util.SortedSet;
025 import java.util.TreeSet;
026
027 import org.dllearner.core.owl.Description;
028
029 /**
030 * A set of descriptions, which is bound by a maximum
031 * size. Can be used by algorithms to store the most promising
032 * n class descriptions.
033 *
034 * @author Jens Lehmann
035 *
036 */
037 public class DescriptionSet {
038
039 private ConceptComparator comp = new ConceptComparator();
040
041 private SortedSet<Description> set = new TreeSet<Description>(comp);
042
043 private int maxSize;
044
045 public DescriptionSet(int maxSize) {
046 this.maxSize = maxSize;
047 }
048
049 public void add(Description ed) {
050 set.add(ed);
051 if(set.size()>maxSize) {
052 Iterator<Description> it = set.iterator();
053 it.next();
054 it.remove();
055 }
056 }
057
058 public void addAll(Collection<Description> eds) {
059 for(Description ed : eds) {
060 add(ed);
061 }
062 }
063
064 /**
065 * @return the set
066 */
067 public SortedSet<Description> getSet() {
068 return set;
069 }
070
071 }