Skip to content

Commit

Permalink
Move most of syllable into Phonology lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed May 21, 2010
1 parent 1ced25e commit 1f0aa3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 60 deletions.
47 changes: 2 additions & 45 deletions lib/spanish/syllable.rb
@@ -1,37 +1,5 @@
# @TODO
# Problem words: insubstancialidad, descouella
module Spanish
class Syllable

attr_accessor :onset, :coda, :nucleus, :stress

def initialize(sound = nil)
@onset = []
@nucleus = []
@coda = []
add sound if sound
end

def to_a
[onset, rime].flatten
end

def valid?
!nucleus.empty?
end

def rime
[nucleus, coda]
end

def to_s
string = to_a.map(&:symbol).join
(stress ? "\u02c8" : "") + string
end

def wants?(sound)
onset_wants?(sound) or nucleus_wants?(sound) or coda_wants?(sound)
end
class Syllable < ::Phonology::Syllable

def onset_wants?(sound)
if !nucleus.empty? || sound.vocalic?
Expand Down Expand Up @@ -66,18 +34,7 @@ def coda_wants?(sound)

def <<(sound)
@stress = true if sound.hints.include?(:primary_stress)
if onset_wants?(sound)
@onset << sound
elsif nucleus_wants?(sound)
@nucleus << sound
else
@coda << sound
end
end
alias add <<

def empty?
onset.empty? && nucleus.empty? && coda.empty?
super
end

def self.apply_stress(syllables)
Expand Down
29 changes: 14 additions & 15 deletions test/syllabification_test.rb
Expand Up @@ -3,41 +3,40 @@

class SyllabificationTest < Test::Unit::TestCase

include Phonology
include Spanish

test "should add consonant to empty onset" do
s = Syllable.new
assert s.onset_wants? Sound.new("t")
assert s.onset_wants? Sound.new("l")
assert s.onset_wants? Sound.new("w")
assert s.onset_wants? Phonology::Sound.new("t")
assert s.onset_wants? Phonology::Sound.new("l")
assert s.onset_wants? Phonology::Sound.new("w")
end

test "should not add vowel to empty onsent" do
s = Syllable.new
assert !s.onset_wants?(Sound.new("o"))
assert !s.onset_wants?(Phonology::Sound.new("o"))
end

test "can append consonant to onset if liquid" do
s = Syllable.new
s.onset << Sound.new("t")
assert s.onset_wants? Sound.new("l")
assert s.onset_wants? Sound.new("ɾ")
s.onset << Phonology::Sound.new("t")
assert s.onset_wants? Phonology::Sound.new("l")
assert s.onset_wants? Phonology::Sound.new("ɾ")
end

test "can append consonant to onset if approximant" do
s = Syllable.new
s.onset << Sound.new("k")
assert s.onset_wants? Sound.new("w")
s.onset << Phonology::Sound.new("k")
assert s.onset_wants? Phonology::Sound.new("w")
end

test "can not append sound to onset if non-liquid and non-approximant" do
s = Syllable.new
s.onset << Sound.new("k")
assert !s.onset_wants?(Sound.new("n"))
assert !s.onset_wants?(Sound.new("r"))
assert !s.onset_wants?(Sound.new("s"))
assert !s.onset_wants?(Sound.new("a"))
s.onset << Phonology::Sound.new("k")
assert !s.onset_wants?(Phonology::Sound.new("n"))
assert !s.onset_wants?(Phonology::Sound.new("r"))
assert !s.onset_wants?(Phonology::Sound.new("s"))
assert !s.onset_wants?(Phonology::Sound.new("a"))
end

end

0 comments on commit 1f0aa3b

Please sign in to comment.