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 * Represents an atomic concept in a knowledge base / ontology,
030 * e.g. "car", "person".
031 *
032 * @author Jens Lehmann
033 *
034 */
035 public class NamedClass extends Description implements Entity, NamedKBElement, Comparable<NamedClass>, Serializable {
036
037 /**
038 *
039 */
040 private static final long serialVersionUID = -2316344469212256752L;
041 private String name;
042
043 public NamedClass(String name) {
044 this.name = name;
045 }
046
047 public NamedClass(URI uri) {
048 this.name = uri.toString();
049 }
050
051 public String getName() {
052 return name;
053 }
054
055 public URI getURI() {
056 return URI.create(name);
057 }
058
059 public int getLength() {
060 return 1;
061 }
062
063 @Override
064 public int getArity() {
065 return 0;
066 }
067
068 public String toString(String baseURI, Map<String,String> prefixes) {
069 return Helper.getAbbreviatedString(name, baseURI, prefixes);
070 }
071
072 public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) {
073 return "\"" + Helper.getAbbreviatedString(name, baseURI, prefixes) + "\"";
074 }
075
076 /* (non-Javadoc)
077 * @see org.dllearner.core.owl.Description#accept(org.dllearner.core.owl.DescriptionVisitor)
078 */
079 @Override
080 public void accept(DescriptionVisitor visitor) {
081 visitor.visit(this);
082 }
083
084 public void accept(KBElementVisitor visitor) {
085 visitor.visit(this);
086 }
087
088 /* (non-Javadoc)
089 * @see org.dllearner.core.owl.Description#toManchesterSyntaxString(java.lang.String, java.util.Map)
090 */
091 @Override
092 public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
093 return Helper.getAbbreviatedString(name, baseURI, prefixes);
094 }
095
096 public int compareTo(NamedClass o) {
097 return name.compareTo(o.name);
098 }
099
100 @Override
101 public int hashCode() {
102 final int prime = 31;
103 int result = 1;
104 result = prime * result + ((name == null) ? 0 : name.hashCode());
105 return result;
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj)
111 return true;
112 if (obj == null)
113 return false;
114 if (getClass() != obj.getClass())
115 return false;
116 NamedClass other = (NamedClass) obj;
117 if (name == null) {
118 if (other.name != null)
119 return false;
120 } else if (!name.equals(other.name))
121 return false;
122 return true;
123 }
124
125
126 }