name-parser/src/main/java/org/gbif/nameparser/ParsingJob.java
/**
   * Carefully normalizes a scientific name trying to maintain the original as close as possible.
   * In particular the string is normalized by:
   * - adding commas in front of years
   * - trims whitespace around hyphens
   * - pads whitespace around &
   * - adds whitespace after dots following a genus abbreviation, rank marker or author name
   * - keeps whitespace before opening and after closing brackets
   * - removes whitespace inside brackets
   * - removes whitespace before commas
   * - normalized hybrid marker to be the ascii multiplication sign
   * - removes whitespace between hybrid marker and following name part in case it is NOT a hybrid formula
   * - trims the string and replaces multi whitespace with single space
   * - capitalizes all only uppercase words (authors are often found in upper case only)
   *
   * @param name To normalize
   *
   * @return The normalized name
   */
Carefully normalizes a scientific name trying to maintain the original as close as possible.

@param name To normalize

@return The normalized name
Carefully normalizes a scientific name trying to maintain the original as close as possible . @param name To normalize @return The normalized name
String normalize(String name) throws InterruptedException {
    if (name == null) {
      return null;
    }
    if (Thread.currentThread().isInterrupted()) {
      throw new InterruptedException("Interrupted!");
    }
    name = StringUtils.replaceChars(name, "¡", "i");
    Matcher m = matcherInterruptable(FORM_SPECIALIS, name);
    if (m.find()) {
      name = m.replaceAll("fsp");
    }
    m = matcherInterruptable(SENSU_LATU, name);
    if (m.find()) {
      name = m.replaceAll("sl");
    }
    name = replAllInterruptable(NORM_YEAR, name,"$1");
    m = matcherInterruptable(NORM_IMPRINT_YEAR, name);
    if (m.find()) {
      LOG.debug("Imprint year {} removed", m.group(2));
      name = m.replaceAll("$1");
    }
    name = replAllInterruptable(REPL_UNDERSCORE, name," ");
    m = matcherInterruptable(NORM_PUNCTUATIONS, name);
    if (m.find()) {
      name = m.replaceAll("$1");
    }
    name = replAllInterruptable(NORM_AND, name,"&");
    m = matcherInterruptable(COMMA_AFTER_BASYEAR, name);
    if (m.find()) {
      name = m.replaceFirst("$1)");
    }
    m = matcherInterruptable(NORM_BRACKETS_OPEN, name);
    if (m.find()) {
      name = m.replaceAll("$1");
    }
    m = matcherInterruptable(NORM_BRACKETS_CLOSE, name);
    if (m.find()) {
      name = m.replaceAll("$1");
    }
    m = matcherInterruptable(NORM_HYBRIDS_GENUS, name);
    if (m.find()) {
      name = m.replaceFirst("×$1");
    }
    m = matcherInterruptable(NORM_HYBRIDS_EPITH, name);
    if (m.find()) {
      name = m.replaceFirst("$1 ×$2");
    }
    m = matcherInterruptable(NORM_HYBRIDS_FORMULA, name);
    if (m.find()) {
      name = m.replaceAll(" × ");
    }
    m = matcherInterruptable(NORM_ANON, name);
    if (m.find()) {
      name = m.replaceFirst("Anon.");
    }
    m = matcherInterruptable(NORM_UPPERCASE_WORDS, name);
    if (m.find()) {
      StringBuffer sb = new StringBuffer();
      m.appendReplacement(sb, m.group(1) + m.group(2).toLowerCase());
      while (m.find()) {
        m.appendReplacement(sb, m.group(1) + m.group(2).toLowerCase());
      }
      m.appendTail(sb);
      name = sb.toString();
    }
    m = matcherInterruptable(NORM_LOWERCASE_BINOMIAL, name);
    if (m.find()) {
      name = m.replaceFirst(StringUtils.capitalize(m.group(1)) + " " + m.group(2));
    }
    name = replAllInterruptable(NORM_WHITESPACE, name," ");
    return StringUtils.trimToEmpty(name);
  }
String normalize ( String name ) throws InterruptedException { if ( name == null ) { return null ; } if ( Thread . currentThread ( ) . isInterrupted ( ) ) { throw new InterruptedException ( "Interrupted!" ) ; } name = StringUtils . replaceChars ( name , "¡", i") ; Matcher m = matcherInterruptable ( FORM_SPECIALIS , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( "fsp" ) ; } m = matcherInterruptable ( SENSU_LATU , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( "sl" ) ; } name = replAllInterruptable ( NORM_YEAR , name , "$1" ) ; m = matcherInterruptable ( NORM_IMPRINT_YEAR , name ) ; if ( m . find ( ) ) { LOG . debug ( "Imprint year {} removed" , m . group ( 2 ) ) ; name = m . replaceAll ( "$1" ) ; } name = replAllInterruptable ( REPL_UNDERSCORE , name , " " ) ; m = matcherInterruptable ( NORM_PUNCTUATIONS , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( "$1" ) ; } name = replAllInterruptable ( NORM_AND , name , "&" ) ; m = matcherInterruptable ( COMMA_AFTER_BASYEAR , name ) ; if ( m . find ( ) ) { name = m . replaceFirst ( "$1)" ) ; } m = matcherInterruptable ( NORM_BRACKETS_OPEN , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( "$1" ) ; } m = matcherInterruptable ( NORM_BRACKETS_CLOSE , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( "$1" ) ; } m = matcherInterruptable ( NORM_HYBRIDS_GENUS , name ) ; if ( m . find ( ) ) { name = m . replaceFirst ( "×$1") ; } m = matcherInterruptable ( NORM_HYBRIDS_EPITH , name ) ; if ( m . find ( ) ) { name = m . replaceFirst ( "$1 ×$2") ; } m = matcherInterruptable ( NORM_HYBRIDS_FORMULA , name ) ; if ( m . find ( ) ) { name = m . replaceAll ( " × ") ; } m = matcherInterruptable ( NORM_ANON , name ) ; if ( m . find ( ) ) { name = m . replaceFirst ( "Anon." ) ; } m = matcherInterruptable ( NORM_UPPERCASE_WORDS , name ) ; if ( m . find ( ) ) { StringBuffer sb = new StringBuffer ( ) ; m . appendReplacement ( sb , m . group ( 1 ) + m . group ( 2 ) . toLowerCase ( ) ) ; while ( m . find ( ) ) { m . appendReplacement ( sb , m . group ( 1 ) + m . group ( 2 ) . toLowerCase ( ) ) ; } m . appendTail ( sb ) ; name = sb . toString ( ) ; } m = matcherInterruptable ( NORM_LOWERCASE_BINOMIAL , name ) ; if ( m . find ( ) ) { name = m . replaceFirst ( StringUtils . capitalize ( m . group ( 1 ) ) + " " + m . group ( 2 ) ) ; } name = replAllInterruptable ( NORM_WHITESPACE , name , " " ) ; return StringUtils . trimToEmpty ( name ) ; }
Carefully normalizes a scientific name trying to maintain the original as close as possible.
Carefully normalizes a scientific name trying to maintain the original as close as possible .
// translate some very similar characters that sometimes get misused instead of real letters // normalise usage of rank marker with 2 dots, i.e. forma specialis and sensu latu // cleanup years // remove imprint years. See ICZN §22A.2.3 http://www.iczn.org/iczn/index.jsp?nfv=&article=22 // replace underscores // normalise punctuations removing any adjacent space // normalise different usages of ampersand, and, et &amp; to always use & // remove commans after basionym brackets // no whitespace before and after brackets, keeping the bracket style // normalize hybrid markers // capitalize Anonymous author // capitalize all entire upper case words // Capitalize potential owercase genus in binomials // finally whitespace and trimming