Class: AnyStyle::Normalizer::Locale
- Inherits:
-
AnyStyle::Normalizer
- Object
- AnyStyle::Normalizer
- AnyStyle::Normalizer::Locale
- Defined in:
- lib/anystyle/normalizer/locale.rb
Instance Attribute Summary
Attributes inherited from AnyStyle::Normalizer
Instance Method Summary collapse
-
#initialize ⇒ Locale
constructor
A new instance of Locale.
- #normalize(item, **opts) ⇒ Object
Methods inherited from AnyStyle::Normalizer
#append, #detect_language, #detect_scripts, #doi_extract, #each_value, #keys_for, #map_values, #name, #skip?
Constructor Details
#initialize ⇒ Locale
Returns a new instance of Locale.
7 8 9 10 11 |
# File 'lib/anystyle/normalizer/locale.rb', line 7 def initialize if defined?(::CLD3) @ld = ::CLD3::NNetLanguageIdentifier.new(0, 1000) end end |
Instance Method Details
#normalize(item, **opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/anystyle/normalizer/locale.rb', line 13 def normalize(item, **opts) sample = item.values_at( :title, :'container-title', :'collection-title', :location, :journal, :publisher, :note ).flatten.compact.join(' ') return item if sample.empty? language = detect_language(sample) scripts = detect_scripts(sample) item[:language] ||= language.to_s unless language.nil? item[:scripts] ||= scripts unless scripts.nil? item end |