Module: TextMetrics
- Defined in:
- lib/text_metrics/version.rb,
lib/text_metrics.rb,
lib/text_metrics/levenshtein.rb,
lib/text_metrics/processors/base.rb,
lib/text_metrics/processors/french.rb,
lib/text_metrics/processors/american_english.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Levenshtein, Processors Classes: Error
Constant Summary collapse
- DEFAULT_LANGUAGE =
:en_us- PROCESSORS =
{ en_us: Processors::AmericanEnglish, fr: Processors::French }.freeze
- VERSION =
"1.0.0"
Class Method Summary collapse
-
.distance(text, other) ⇒ Object
Raw Levenshtein edit distance between two texts.
-
.new(text, language: DEFAULT_LANGUAGE) ⇒ Object
Build an analyzer for
textin the givenlanguage(:en_us or :fr). -
.similarity(text, other) ⇒ Object
Levenshtein similarity between two texts, as a 0–100 score (100.0 == identical).
Class Method Details
.distance(text, other) ⇒ Object
Raw Levenshtein edit distance between two texts.
26 27 28 |
# File 'lib/text_metrics.rb', line 26 def self.distance(text, other) Levenshtein.distance(text, other) end |
.new(text, language: DEFAULT_LANGUAGE) ⇒ Object
Build an analyzer for text in the given language (:en_us or :fr). Returns the language-specific processor, which exposes every metric and #to_h.
20 21 22 23 |
# File 'lib/text_metrics.rb', line 20 def self.new(text, language: DEFAULT_LANGUAGE) language = resolve_language(language) PROCESSORS.fetch(language).new(text, language: language) end |
.similarity(text, other) ⇒ Object
Levenshtein similarity between two texts, as a 0–100 score (100.0 == identical).
31 32 33 |
# File 'lib/text_metrics.rb', line 31 def self.similarity(text, other) Levenshtein.similarity(text, other) end |