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.core.owl;
021
022 import java.net.URI;
023 import java.util.Map;
024
025 import org.dllearner.utilities.Helper;
026
027 /**
028 * Represents an object property in a knowledge base / ontology,
029 * e.g. "hasChild".
030 *
031 * @author Jens Lehmann
032 *
033 */
034 public class ObjectProperty extends ObjectPropertyExpression implements Property, Comparable<ObjectProperty>{
035
036 /**
037 *
038 */
039 private static final long serialVersionUID = -3343070247923446690L;
040
041 public ObjectProperty(String name) {
042 super(name);
043 }
044
045 public int getLength() {
046 return 1;
047 }
048
049 public URI getURI() {
050 return URI.create(name);
051 }
052
053 @Override
054 public String toString() {
055 return name;
056 }
057
058 public String toString(String baseURI, Map<String,String> prefixes) {
059 return Helper.getAbbreviatedString(name, baseURI, prefixes) ;
060 }
061
062 public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) {
063 return "\"" + Helper.getAbbreviatedString(name, baseURI, prefixes) + "\"";
064 }
065
066 public void accept(KBElementVisitor visitor) {
067 visitor.visit(this);
068 }
069
070 public int compareTo(ObjectProperty o) {
071 return name.compareTo(o.name);
072 }
073
074 @Override
075 public boolean equals(Object nc) {
076 // standard equals code - always return true for object identity and
077 // false if classes differ
078 if(nc == this) {
079 return true;
080 } else if(getClass() != nc.getClass()) {
081 return false;
082 }
083 // compare on URIs
084 return ((ObjectProperty)nc).name.equals(name);
085 }
086
087 @Override
088 public int hashCode() {
089 return name.hashCode();
090 }
091
092 /* (non-Javadoc)
093 * @see org.dllearner.core.owl.KBElement#toManchesterSyntaxString(java.lang.String, java.util.Map)
094 */
095 @Override
096 public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
097 return Helper.getAbbreviatedString(name, baseURI, prefixes);
098 }
099 }