Class: Phonemico::SoundFeatures
- Inherits:
-
Object
- Object
- Phonemico::SoundFeatures
- Defined in:
- lib/phonemico.rb
Instance Method Summary collapse
- #all_features ⇒ Object
- #all_phonemes ⇒ Object
- #common_features_for(phoneme1, phoneme2) ⇒ Object
- #features_for(phoneme) ⇒ Object
- #features_only_in_first(phoneme1, phoneme2) ⇒ Object
- #parse(text) ⇒ Object
- #parse_file(filename) ⇒ Object
- #phonemes_for(feature) ⇒ Object
Instance Method Details
#all_features ⇒ Object
32 33 34 |
# File 'lib/phonemico.rb', line 32 def all_features @features end |
#all_phonemes ⇒ Object
28 29 30 |
# File 'lib/phonemico.rb', line 28 def all_phonemes @hash.keys.sort end |
#common_features_for(phoneme1, phoneme2) ⇒ Object
46 47 48 49 50 |
# File 'lib/phonemico.rb', line 46 def common_features_for(phoneme1, phoneme2) features1 = features_for(phoneme1) features2 = features_for(phoneme2) features1 & features2 end |
#features_for(phoneme) ⇒ Object
36 37 38 |
# File 'lib/phonemico.rb', line 36 def features_for(phoneme) @hash[phoneme] || [] end |
#features_only_in_first(phoneme1, phoneme2) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/phonemico.rb', line 52 def features_only_in_first(phoneme1, phoneme2) features1 = features_for(phoneme1) features2 = features_for(phoneme2) unless features1 == nil features1.select do |feature| features2.include? opposite(feature) end else return nil end end |
#parse(text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/phonemico.rb', line 11 def parse(text) rows = CSV.parse(text) @features = rows.shift @features.shift # first cell is empty @hash = {} rows.each do |row| phoneme = row.shift @hash[phoneme] = [] row.each_with_index do |feature, index| value = feature + @features[index] @hash[phoneme] << value unless feature == "0" end end end |
#parse_file(filename) ⇒ Object
7 8 9 |
# File 'lib/phonemico.rb', line 7 def parse_file(filename) parse IO.read(filename) end |
#phonemes_for(feature) ⇒ Object
40 41 42 43 44 |
# File 'lib/phonemico.rb', line 40 def phonemes_for(feature) all_phonemes.select do |phoneme| @hash[phoneme].include?(feature) end end |