Method: Mabmapper::MabXml::Document#naco_normalization

Defined in:
lib/mabmapper/mab_xml/document.rb

#naco_normalization(value) ⇒ Object

Normalize text based on the NACO rules



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mabmapper/mab_xml/document.rb', line 28

def naco_normalization(value)
  return unless value.present?

  # Downcase everything
  value.downcase!

  # Convert unicode [and accented ASCII] characters to their
  # plain-text ASCII equivalents
  Stringex::Localization.backend = :internal
  Stringex::Localization.locale = :de
  Stringex::Localization.store_translations(:de, :transliterations, {"ü" => "ue", "ä" => "ae", "ö" => "oe", "ß" => "ss"}) if Stringex::Localization.backend.translations.blank?
  value = value.to_ascii

  # Convert special chars to spaces
  value.gsub!(/[,$~^%*\/?@.:;<>{}!\(\)\-]/, ' ')

  # Convert special chars to spaces
  value.gsub!(/[\[\]\|]/, '')

  # Remove leading and trailing spaces
  value.strip!

  # Condense multiple spaces
  value.gsub!(/\s+/, ' ')

  value
end