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.algorithms.refinement;
021    
022    import java.util.Comparator;
023    
024    import org.dllearner.utilities.owl.ConceptComparator;
025    
026    /**
027     * Der Comparator ist stable, weil er nur nach covered negatives,
028     * Konzeptlänge und Konzeptstring vergleicht, die sich während des Algorithmus nicht
029     * ändern können.
030     * 
031     * @author jl
032     *
033     */
034    public class NodeComparatorStable implements Comparator<Node> {
035    
036            ConceptComparator conceptComparator = new ConceptComparator();
037            
038            // implementiert 
039            public int compare(Node n1, Node n2) {
040                    
041                    // sicherstellen, dass Qualität ausgewertet wurde
042                    if(n1.isQualityEvaluated() && n2.isQualityEvaluated()) {
043                            if(!n1.isTooWeak() && !n2.isTooWeak()) {
044                                    if(n1.getCoveredNegativeExamples()<n2.getCoveredNegativeExamples()) 
045                                            return 1;
046                                    else if(n1.getCoveredNegativeExamples()>n2.getCoveredNegativeExamples())
047                                            return -1;
048                                    else {
049                                            //TODO: es wäre geringfügig effizienter die Länge nicht mehrfach zu berechnen
050                                            if(n1.getConcept().getLength()<n2.getConcept().getLength())
051                                                    return 1;
052                                            else if(n1.getConcept().getLength()>n2.getConcept().getLength())
053                                                    return -1;
054                                            else
055                                                    return conceptComparator.compare(n1.getConcept(), n2.getConcept());
056                                    }
057                            } else
058                                    return conceptComparator.compare(n1.getConcept(), n2.getConcept());
059                    }
060                    
061                    throw new RuntimeException("Cannot compare nodes, which have no evaluated quality or are too weak.");
062            }
063    
064            // alle NodeComparators führen zur gleichen Ordnung
065            @Override               
066            public boolean equals(Object o) {
067                    return (o instanceof NodeComparatorStable);
068            }
069    
070    }