Class: Rhopalic::Dictionary
- Inherits:
-
Object
- Object
- Rhopalic::Dictionary
- Defined in:
- lib/rhopalic/dictionary.rb
Overview
A dictionary that maps words to of syllables. Can be passed into Rhopalic::Analysis to improve accuracy of syllable detection. Input is a pronunciation file in the format of the CMU pronunciation dictionary. See www.speech.cs.cmu.edu/cgi-bin/cmudict for details. The latest dictionary file from CMU should work out of the box.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input_source) ⇒ Dictionary
constructor
Initializes a dictionary from an enumerable source of dictionary entries, e.g., an open dictionary file.
- #syllable_count(word) ⇒ Object
Constructor Details
#initialize(input_source) ⇒ Dictionary
Initializes a dictionary from an enumerable source of dictionary entries, e.g., an open dictionary file.
21 22 23 24 |
# File 'lib/rhopalic/dictionary.rb', line 21 def initialize(input_source) @input_source = input_source make_dictionary end |
Class Method Details
.from_file(filename) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rhopalic/dictionary.rb', line 11 def self.from_file(filename) dict = nil File.open(filename) do |file| dict = Dictionary.new(file) end dict end |
Instance Method Details
#syllable_count(word) ⇒ Object
26 27 28 |
# File 'lib/rhopalic/dictionary.rb', line 26 def syllable_count(word) @syllable_counts[word.upcase] || nil end |