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.algorithms.pattern; 020 021import java.util.Arrays; 022import java.util.Comparator; 023import java.util.List; 024 025import org.semanticweb.owlapi.model.OWLClassExpression; 026import org.semanticweb.owlapi.util.OWLObjectTypeIndexProvider; 027 028import uk.ac.manchester.cs.owl.owlapi.OWLClassExpressionImpl; 029import uk.ac.manchester.cs.owl.owlapi.OWLClassImpl; 030import uk.ac.manchester.cs.owl.owlapi.OWLObjectAllValuesFromImpl; 031import uk.ac.manchester.cs.owl.owlapi.OWLObjectComplementOfImpl; 032import uk.ac.manchester.cs.owl.owlapi.OWLObjectExactCardinalityImpl; 033import uk.ac.manchester.cs.owl.owlapi.OWLObjectHasValueImpl; 034import uk.ac.manchester.cs.owl.owlapi.OWLObjectIntersectionOfImpl; 035import uk.ac.manchester.cs.owl.owlapi.OWLObjectMaxCardinalityImpl; 036import uk.ac.manchester.cs.owl.owlapi.OWLObjectMinCardinalityImpl; 037import uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl; 038import uk.ac.manchester.cs.owl.owlapi.OWLObjectUnionOfImpl; 039 040public class OWLClassExpressionOrderingComparator implements Comparator<OWLClassExpression> { 041 042 private static final List<Class<? extends OWLClassExpressionImpl>> ordering = Arrays.asList( 043 OWLClassImpl.class, 044 OWLObjectSomeValuesFromImpl.class, 045 OWLObjectAllValuesFromImpl.class, 046 OWLObjectComplementOfImpl.class, 047 OWLObjectIntersectionOfImpl.class, 048 OWLObjectUnionOfImpl.class, 049 OWLObjectHasValueImpl.class, 050 OWLObjectMinCardinalityImpl.class, 051 OWLObjectMaxCardinalityImpl.class, 052 OWLObjectExactCardinalityImpl.class 053 ); 054 055 private final OWLObjectTypeIndexProvider indexProvider = new OWLObjectTypeIndexProvider(); 056 057 @Override 058 public int compare(OWLClassExpression o1, OWLClassExpression o2) { 059 int diff = ordering.indexOf(o1.getClass()) - ordering.indexOf(o2.getClass()); 060 if(diff == 0){ 061 return o1.compareTo(o2); 062 } else { 063 return diff; 064 } 065 } 066 067}