001package org.gbif.api.util;
002
003public class TermNormalizationUtils {
004
005  /**
006   * This normalization is used to generate the avro schemas of the verbatim extensions tables in
007   * downloadTables->XmlToAvscGeneratorMojo and hence the same normalization has to be used when
008   * populating the tables(pipelines->VerbatimExtensionsInterpretationPipeline) and when downloading
009   * these extensions from ES(occurrence->DownloadDwcaActor).
010   */
011  public static String normalizeFieldName(String name) {
012    String normalizedNamed = name.toLowerCase().trim()
013      .replace("-", "")
014      .replace("_", "")
015      .replace(":", "_");
016    if (Character.isDigit(normalizedNamed.charAt(0))) {
017      return '_' + normalizedNamed;
018    }
019    return normalizedNamed;
020  }
021}