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