001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.vocabulary;
017
018import com.google.common.base.Strings;
019
020/**
021 * A short classification of scientific name strings used in Checklist Bank.
022 */
023public enum NameType {
024
025  /**
026   * A scientific latin name that might contain authorship but is not any of the other name types below (virus, hybrid, cultivar, etc).
027   */
028  SCIENTIFIC,
029
030  /**
031   * A virus name.
032   */
033  VIRUS,
034
035  /**
036   * A hybrid <b>formula</b> (not a hybrid name).
037   */
038  HYBRID,
039
040  /**
041   * A scientific name with some informal addition like "cf." or indetermined like Abies spec.
042   */
043  INFORMAL,
044
045  /**
046   * A cultivated plant name.
047   */
048  CULTIVAR,
049
050  /**
051   * Candidatus is a component of the taxonomic name for a bacterium that cannot be maintained in a
052   * Bacteriology Culture Collection. It is an interim taxonomic status for noncultivable organisms.
053   * An example would be "Candidatus Phytoplasma allocasuarinae".
054   * This can be abbreviated to "Ca. Phytoplasma allocasuarinae".
055   *
056   * @see <a href="http://en.wikipedia.org/wiki/Candidatus">wikipedia</a>
057   * @see <a href="http://www.bacterio.cict.fr/candidatus.html">J.P. Euz├ęby</a>
058   *
059   */
060  CANDIDATUS,
061
062  /**
063   * Operational Taxonomic Unit.
064   * An OTU is a pragmatic definition to group individuals by similarity, equivalent to but not necessarily in line
065   * with classical Linnaean taxonomy or modern Evolutionary taxonomy.
066   *
067   * A OTU usually refers to clusters of organisms, grouped by DNA sequence similarity of a specific taxonomic marker gene.
068   * In other words, OTUs are pragmatic proxies for "species" at different taxonomic levels.
069   *
070   * Sequences can be clustered according to their similarity to one another,
071   * and operational taxonomic units are defined based on the similarity threshold (usually 97% similarity) set by the researcher.
072   * Typically, OTU's are based on similar 16S rRNA sequences.
073   */
074  OTU,
075
076  /**
077   * Doubtful whether this is a scientific name at all.
078   */
079  DOUBTFUL,
080
081  /**
082   * A placeholder name like "incertae sedis" or "unknown genus".
083   */
084  PLACEHOLDER,
085
086  /**
087   * Surely not a scientific name of any kind.
088   */
089  NO_NAME;
090
091  /**
092   * Case insensitive lookup of a name type by its name that does not throw an exception but returns null
093   * for not found name types.
094   *
095   * @param nameType case insensitive name of name type
096   *
097   * @return the matching NameType or null
098   */
099  public static NameType fromString(String nameType) {
100    if (!Strings.isNullOrEmpty(nameType)) {
101      try {
102        return valueOf(nameType.toUpperCase().trim());
103      } catch (IllegalArgumentException e) {
104        // swallow
105      }
106    }
107    return null;
108  }
109
110  /**
111   * @return true if the type of name is included in the GBIF backbone
112   */
113  public boolean isBackboneType() {
114    return this == SCIENTIFIC || this == VIRUS || this == DOUBTFUL;
115  }
116
117  /**
118   * @return true if the GBIF name parser can parse such a name into a ParsedName instance
119   */
120  public boolean isParsable() {
121    return this == SCIENTIFIC || this == INFORMAL || this == CULTIVAR || this == CANDIDATUS || this == DOUBTFUL;
122  }
123
124}