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.core.owl;
020
021import java.util.Set;
022import java.util.SortedMap;
023import java.util.SortedSet;
024import java.util.TreeSet;
025
026import org.semanticweb.owlapi.model.OWLObjectProperty;
027import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
028
029import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl;
030
031/**
032 * Represents a hierarchy of object properties (roles in Description Logics).
033 * 
034 * @author Jens Lehmann
035 *
036 */
037public class ObjectPropertyHierarchy extends AbstractHierarchy<OWLObjectProperty>{
038        
039        private static final OWLObjectProperty OWL_TOP_OBJECT_PROPERTY = new OWLObjectPropertyImpl(
040                        OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.getIRI());
041        private static final OWLObjectProperty OWL_BOTTOM_OBJECT_PROPERTY = new OWLObjectPropertyImpl(
042                        OWLRDFVocabulary.OWL_BOTTOM_OBJECT_PROPERTY.getIRI());
043
044        public ObjectPropertyHierarchy(
045                        SortedMap<OWLObjectProperty, SortedSet<OWLObjectProperty>> roleHierarchyUp,
046                        SortedMap<OWLObjectProperty, SortedSet<OWLObjectProperty>> roleHierarchyDown) {
047                super(roleHierarchyUp, roleHierarchyDown);
048        }
049        
050        public SortedSet<OWLObjectProperty> getMoreGeneralRoles(OWLObjectProperty role) {
051                return new TreeSet<>(getParents(role));
052        }
053        
054        public SortedSet<OWLObjectProperty> getMoreSpecialRoles(OWLObjectProperty role) {
055                return new TreeSet<>(getChildren(role));
056        }
057        
058        public boolean isSubpropertyOf(OWLObjectProperty subProperty, OWLObjectProperty superProperty) {
059                return isChildOf(subProperty, superProperty);
060        }       
061
062        /**
063         * @return The most general roles.
064         */
065        public SortedSet<OWLObjectProperty> getMostGeneralRoles() {
066                return getMostGeneralEntities();
067        }
068
069        /**
070         * @return The most special roles.
071         */
072        public SortedSet<OWLObjectProperty> getMostSpecialRoles() {
073                return getMostSpecialEntities();
074        }
075
076        /* (non-Javadoc)
077         * @see org.dllearner.core.owl.AbstractHierarchy#getTopConcept()
078         */
079        @Override
080        public OWLObjectProperty getTopConcept() {
081                return OWL_TOP_OBJECT_PROPERTY;
082        }
083
084        /* (non-Javadoc)
085         * @see org.dllearner.core.owl.AbstractHierarchy#getBottomConcept()
086         */
087        @Override
088        public OWLObjectProperty getBottomConcept() {
089                return OWL_BOTTOM_OBJECT_PROPERTY;
090        }
091        
092        /* (non-Javadoc)
093         * @see org.dllearner.core.owl.AbstractHierarchy#toString(java.util.SortedMap, org.semanticweb.owlapi.model.OWLObject, int)
094         */
095        @Override
096        protected String toString(SortedMap<OWLObjectProperty, SortedSet<OWLObjectProperty>> hierarchy,
097                        OWLObjectProperty prop, int depth) {
098                String str = "";
099                for (int i = 0; i < depth; i++)
100                        str += "  ";
101                str += prop.toString() + "\n";
102                Set<OWLObjectProperty> tmp;
103                if(prop.isTopEntity()) {
104                        tmp = getMostGeneralRoles();
105                } else {
106                        tmp  = hierarchy.get(prop);
107                }
108                
109                if (tmp != null) {
110                        for (OWLObjectProperty c : tmp)
111                                str += toString(hierarchy, c, depth + 1);
112                }
113                return str;
114        }
115        
116        @Override
117        public ObjectPropertyHierarchy clone() {
118                return new ObjectPropertyHierarchy(getHierarchyUp(), getHierarchyDown());               
119        }
120}