Class: TextMetrics::Processors::French
- Defined in:
- lib/text_metrics/processors/french.rb
Constant Summary collapse
- SYLLABLE_EXCEPTIONS_PATH =
File.join(GEM_PATH, "dictionaries/french_word_syllable_exceptions.yml").freeze
- EXCEPTIONS_LOAD_MUTEX =
Mutex.new
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.syllable_exceptions ⇒ Object
Syllable counts for the words the heuristic gets wrong (derived from Lexique), loaded once and shared across all instances and threads.
Instance Method Summary collapse
-
#flesch_reading_ease ⇒ Object
French Flesch Reading Ease — the Kandel-Moles (1958) adaptation: 207 - 1.015 * (words / sentences) - 73.6 * (syllables / words).
-
#initialize(text, language: :fr, with_syllable_exceptions: true) ⇒ French
constructor
with_syllable_exceptionsis an internal toggle used by the dictionary-generation scripts to run the bare heuristic; the public API always leaves it on.
Methods inherited from Base
#characters_count, #characters_per_sentence_average, #coleman_liau_index, #flesch_kincaid_grade, #gunning_fog_index, #letters_per_word_average, #lix, #punctuation_count, #punctuation_per_sentence_average, #sentences_count, #smog_index, #syllables_count, #syllables_per_word_average, #to_h, #words_count, #words_per_punctuation_average, #words_per_sentence_average
Constructor Details
#initialize(text, language: :fr, with_syllable_exceptions: true) ⇒ French
with_syllable_exceptions is an internal toggle used by the dictionary-generation scripts to run the bare heuristic; the public API always leaves it on.
29 30 31 32 |
# File 'lib/text_metrics/processors/french.rb', line 29 def initialize(text, language: :fr, with_syllable_exceptions: true) super(text, language: language) @with_syllable_exceptions = with_syllable_exceptions end |
Class Method Details
.syllable_exceptions ⇒ Object
Syllable counts for the words the heuristic gets wrong (derived from Lexique), loaded once and shared across all instances and threads. Lazy so requiring the gem (or using only English/Levenshtein) doesn’t pay the YAML load; the mutex guarantees the file is parsed exactly once under concurrent first use, and the double check keeps the common path lock-free. The result is frozen, so concurrent reads are safe.
18 19 20 21 22 23 24 |
# File 'lib/text_metrics/processors/french.rb', line 18 def syllable_exceptions return @syllable_exceptions if @syllable_exceptions EXCEPTIONS_LOAD_MUTEX.synchronize do @syllable_exceptions ||= YAML.load_file(SYLLABLE_EXCEPTIONS_PATH).freeze end end |
Instance Method Details
#flesch_reading_ease ⇒ Object
French Flesch Reading Ease — the Kandel-Moles (1958) adaptation: 207 - 1.015 * (words / sentences) - 73.6 * (syllables / words).
36 37 38 39 40 |
# File 'lib/text_metrics/processors/french.rb', line 36 def flesch_reading_ease return 0.0 if words_count.zero? (207 - 1.015 * average_words_per_sentence - 73.6 * average_syllables_per_word).round(2) end |