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.LinkedList;
023
024 import org.dllearner.core.owl.Description;
025 import org.dllearner.core.owl.ObjectProperty;
026 import org.dllearner.core.owl.ObjectSomeRestriction;
027 import org.dllearner.core.owl.Thing;
028
029 /**
030 * A property context is a utility class which specifies the
031 * position of constructs with respect to properties of a
032 * construct in a class description. For instance, the A
033 * in \exists r.\exists s.A occurs in property context [r,s].
034 *
035 * @author Jens Lehmann
036 *
037 */
038 public class PropertyContext extends LinkedList<ObjectProperty> implements Comparable<PropertyContext> {
039
040 private static final long serialVersionUID = -4403308689522524077L;
041
042 /* (non-Javadoc)
043 * @see java.lang.Comparable#compareTo(java.lang.Object)
044 */
045 @Override
046 public int compareTo(PropertyContext context) {
047 // we first distinguish on size - simpler contexts come first
048 int diff = context.size() - size();
049 if(diff != 0) {
050 return diff;
051 }
052
053 for(int i=0; i<size(); i++) {
054 int cmp = get(i).getName().compareTo(context.get(i).getName());
055 if(cmp != 0) {
056 return cmp;
057 }
058 }
059
060 return 0;
061 }
062
063 /**
064 * Transforms context [r,s] to \exists r.\exists s.\top.
065 * @return A description with existential quantifiers and \top corresponding
066 * to the context.
067 */
068 public Description toExistentialContext() {
069 Description d = Thing.instance;
070 for(int i = size()-1; i>=0; i--) {
071 d = new ObjectSomeRestriction(get(i), d);
072 }
073 return d;
074 }
075
076 }