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.Comparator;
023
024 import org.dllearner.core.EvaluatedDescription;
025
026 /**
027 * Comparator for evaluated descriptions, which orders them by
028 * accuracy as first criterion, length as second criterion, and
029 * syntactic structure as third criterion.
030 *
031 * @author Jens Lehmann
032 *
033 */
034 public class EvaluatedDescriptionComparator implements Comparator<EvaluatedDescription> {
035
036 ConceptComparator cc = new ConceptComparator();
037
038 /* (non-Javadoc)
039 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
040 */
041 @Override
042 public int compare(EvaluatedDescription ed1, EvaluatedDescription ed2) {
043 double acc1 = ed1.getAccuracy();
044 double acc2 = ed2.getAccuracy();
045 if(acc1 > acc2)
046 return 1;
047 else if(acc1 < acc2)
048 return -1;
049 else {
050 int length1 = ed1.getDescriptionLength();
051 int length2 = ed2.getDescriptionLength();
052 if(length1 < length2)
053 return 1;
054 else if(length1 > length2)
055 return -1;
056 else
057 return cc.compare(ed1.getDescription(), ed2.getDescription());
058 }
059 }
060
061 }