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 invididual in a knowledge base / ontology.
030     * 
031     * @author Jens Lehmann
032     *
033     */
034    public class Individual implements Entity, NamedKBElement, Comparable<Individual>, Serializable {
035    
036            /**
037             * 
038             */
039            private static final long serialVersionUID = 1831526393296388784L;
040            private String name;
041    
042            
043    
044            public String getName() {
045                    return name;
046            }
047    
048        public URI getURI() {
049            return URI.create(name);
050        }   
051            
052            public Individual(String name) {
053                    this.name = name;
054            }
055            
056            public int getLength() {
057                    return 1;
058            }
059    
060            public int compareTo(Individual o) {
061                    return name.compareTo(o.name);
062            }
063            
064        @Override
065        public String toString() {
066                return name;
067        }   
068            
069        public String toString(String baseURI, Map<String,String> prefixes) {
070            return  Helper.getAbbreviatedString(name, baseURI, prefixes);
071        }
072        
073        public String toKBSyntaxString(String baseURI, Map<String,String> prefixes) {
074            return "\"" + Helper.getAbbreviatedString(name, baseURI, prefixes) + "\"";
075        }
076        
077        public String toManchesterSyntaxString(String baseURI, Map<String, String> prefixes) {
078                    return Helper.getAbbreviatedString(name, baseURI, prefixes);
079            }       
080        
081            public void accept(KBElementVisitor visitor) {
082                    visitor.visit(this);
083            }    
084            
085            @Override
086            public int hashCode() {
087                    final int prime = 31;
088                    int result = 1;
089                    result = prime * result + ((name == null) ? 0 : name.hashCode());
090                    return result;
091            }
092    
093            @Override
094            public boolean equals(Object obj) {
095                    if (this == obj)
096                            return true;
097                    if (obj == null)
098                            return false;
099                    if (getClass() != obj.getClass())
100                            return false;
101                    Individual other = (Individual) obj;
102                    if (name == null) {
103                            if (other.name != null)
104                                    return false;
105                    } else if (!name.equals(other.name))
106                            return false;
107                    return true;
108            }
109    
110    }