001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021 022package org.biojava.nbio.ontology; 023 024import org.biojava.nbio.ontology.utils.Annotation; 025 026import java.util.Arrays; 027import java.util.Set; 028import java.util.TreeSet; 029 030 031/** 032 * A term in an ontology which identifies another ontology. 033 * 034 * <p> 035 * This Term type has an associated ontology. It is meant to represent that 036 * ontology so that you can reason over them. For example, you could add 037 * information to an Ontology containing an OntologyTerm stating how the 038 * OntologyTerm's Ontology relates to other entities. This allows 039 * classifications of Ontologies to be built. You could say that GO is a 040 * biological ontology, as is SO or perhaps declare something about the source 041 * of the information. 042 * </p> 043 * 044 * @author Thomas Down 045 * @author Matthew Pocock 046 * @since 1.4 047 */ 048 049public interface OntologyTerm extends Term { 050 /** 051 * Get the remote ontology referenced by this term 052 */ 053 054 @Override 055 public Ontology getOntology(); 056 057 /** 058 * Simple in-memory implementation of a remote ontology term. 059 * 060 * This can be used to implement Ontology.importTerm 061 */ 062 063 public final static class Impl 064 065 implements OntologyTerm, java.io.Serializable { 066 067 private static final long serialVersionUID = 1L; 068 private final Ontology ontology; 069 private final Ontology target; 070 071 private Set synonyms; 072 073 public Impl(Ontology ontology, Ontology target) { 074 this(ontology, target, null); 075 } 076 077 public Impl(Ontology ontology, Ontology target, Object[] synonyms) { 078 if (ontology == null) { 079 throw new NullPointerException("The ontology may not be null"); 080 } 081 if (target == null) { 082 throw new NullPointerException("The targetted ontology may not be null"); 083 } 084 this.ontology = ontology; 085 this.target = target; 086 087 this.synonyms = new TreeSet(); 088 if (synonyms!=null) this.synonyms.addAll(Arrays.asList(synonyms)); 089 } 090 091 @Override 092 public void addSynonym(Object synonym) { 093 this.synonyms.add(synonym); 094 } 095 096 @Override 097 public void removeSynonym(Object synonym) { 098 this.synonyms.remove(synonym); 099 } 100 101 @Override 102 public Object[] getSynonyms() { 103 return this.synonyms.toArray(); 104 } 105 106 @Override 107 public String getName() { 108 return target.getName(); 109 } 110 111 @Override 112 public String getDescription() { 113 return target.getDescription(); 114 } 115 @Override 116 public void setDescription(String description) { 117 target.setDescription(description); 118 } 119 120 @Override 121 public Ontology getOntology() { 122 return ontology; 123 } 124 125 public Ontology getTargetOntology() { 126 return target; 127 } 128 129 @Override 130 public String toString() { 131 return "Remote ontology: " + getName(); 132 } 133 134 @Override 135 public Annotation getAnnotation() { 136 return Annotation.EMPTY_ANNOTATION; 137 } 138 139 140 } 141}