phonology 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,8 @@ require File.expand_path("../phonology/sound", __FILE__)
5
5
  require File.expand_path("../phonology/sound_sequence", __FILE__)
6
6
  require File.expand_path("../phonology/orthography", __FILE__)
7
7
  require File.expand_path("../phonology/rule", __FILE__)
8
+ require File.expand_path("../phonology/syllable", __FILE__)
9
+ require File.expand_path("../phonology/ipa", __FILE__)
8
10
 
9
11
  module Phonology
10
12
 
@@ -0,0 +1,11 @@
1
+ module Phonology
2
+ module IPA
3
+
4
+ extend self
5
+
6
+ def primary_stress
7
+ "\u02c8"
8
+ end
9
+
10
+ end
11
+ end
@@ -64,6 +64,14 @@ module Phonology
64
64
  true
65
65
  end
66
66
 
67
+ def syllable_initial?
68
+ syllable.onset.first == curr_sound
69
+ end
70
+
71
+ def syllable_final?
72
+ syllable.coda.last == curr_sound
73
+ end
74
+
67
75
  def initial?
68
76
  @index == 0
69
77
  end
@@ -2,11 +2,11 @@ module Phonology
2
2
 
3
3
  module SoundBase
4
4
 
5
- attr_accessor :features, :orthography, :hints
5
+ attr_accessor :features, :orthography, :hints, :syllable
6
6
  protected :features=, :hints=
7
7
 
8
8
  Features::ALL.each do |feature|
9
- class_eval(<<-EOM, __FILE__, __LINE__ +1)
9
+ class_eval(<<-EOM, __FILE__, __LINE__ + 1)
10
10
  def #{feature}?
11
11
  features.include? :#{feature}
12
12
  end
@@ -18,7 +18,7 @@ module Phonology
18
18
  end
19
19
 
20
20
  Features::CLASSES.each do |feature_class, values|
21
- class_eval(<<-EOM, __FILE__, __LINE__ +1)
21
+ class_eval(<<-EOM, __FILE__, __LINE__ + 1)
22
22
  def #{feature_class}?
23
23
  set = Features.expand(:#{feature_class})
24
24
  !set.intersection(features).empty?
@@ -138,8 +138,8 @@ module Phonology
138
138
  alias add <<
139
139
 
140
140
  # Add a feature without replacing place or manner.
141
- def add!(feature)
142
- features.add feature.to_sym
141
+ def add!(*args)
142
+ args.map {|a| features.add a.to_sym }
143
143
  self
144
144
  end
145
145
 
@@ -9,7 +9,7 @@ module Phonology
9
9
  @sounds.__send__(sym, *args, &block)
10
10
  end
11
11
 
12
- def initialize(arg)
12
+ def initialize(arg = nil)
13
13
  # String of ipa symbols
14
14
  if arg.kind_of? String
15
15
  @sounds = arg.split('').map {|letter| Sound.new(letter)}
@@ -18,6 +18,10 @@ module Phonology
18
18
  end
19
19
  end
20
20
 
21
+ def syllables(syllabifier)
22
+ @syllables ||= syllabifier.syllabify(self)
23
+ end
24
+
21
25
  def symbols
22
26
  compact.map(&:symbol).join
23
27
  end
@@ -40,6 +44,8 @@ module Phonology
40
44
  self
41
45
  end
42
46
 
43
-
47
+ def sonority
48
+ @sounds.empty? ? nil : @sounds.last.sonority
49
+ end
44
50
  end
45
51
  end
@@ -0,0 +1,62 @@
1
+ module Phonology
2
+ # @abstract
3
+ class Syllable
4
+
5
+ attr_accessor :onset, :coda, :nucleus, :stress
6
+
7
+ def initialize(sound = nil)
8
+ @onset = ::Phonology::SoundSequence.new
9
+ @nucleus = ::Phonology::SoundSequence.new
10
+ @coda = ::Phonology::SoundSequence.new
11
+ add sound if sound
12
+ end
13
+
14
+ def to_a
15
+ [onset, rime].flatten
16
+ end
17
+
18
+ def valid?
19
+ !nucleus.empty?
20
+ end
21
+
22
+ def rime
23
+ [nucleus, coda]
24
+ end
25
+
26
+ def to_s(show_stress = true)
27
+ (show_stress && stress ? IPA.primary_stress : "") + to_a.map(&:symbol).join
28
+ end
29
+
30
+ def wants?(sound)
31
+ onset_wants?(sound) or nucleus_wants?(sound) or coda_wants?(sound)
32
+ end
33
+
34
+ def onset_wants?(sound)
35
+ raise NotImplementedError
36
+ end
37
+
38
+ def nucleus_wants?(sound)
39
+ raise NotImplementedError
40
+ end
41
+
42
+ def coda_wants?(sound)
43
+ raise NotImplementedError
44
+ end
45
+
46
+ def <<(sound)
47
+ if onset_wants?(sound)
48
+ @onset << sound
49
+ elsif nucleus_wants?(sound)
50
+ @nucleus << sound
51
+ else
52
+ @coda << sound
53
+ end
54
+ sound.syllable = self
55
+ end
56
+ alias add <<
57
+
58
+ def empty?
59
+ onset.empty? && nucleus.empty? && coda.empty?
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module Phonology
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Norman Clarke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-20 00:00:00 -03:00
17
+ date: 2010-07-09 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -30,10 +30,12 @@ files:
30
30
  - lib/phonology.rb
31
31
  - lib/phonology/features.rb
32
32
  - lib/phonology/inventory.rb
33
+ - lib/phonology/ipa.rb
33
34
  - lib/phonology/orthography.rb
34
35
  - lib/phonology/rule.rb
35
36
  - lib/phonology/sound.rb
36
37
  - lib/phonology/sound_sequence.rb
38
+ - lib/phonology/syllable.rb
37
39
  - lib/phonology/version.rb
38
40
  - test/affricate_test.rb
39
41
  - test/features_test.rb
@@ -54,6 +56,7 @@ rdoc_options: []
54
56
  require_paths:
55
57
  - lib
56
58
  required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
57
60
  requirements:
58
61
  - - ">="
59
62
  - !ruby/object:Gem::Version
@@ -61,6 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
64
  - 0
62
65
  version: "0"
63
66
  required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
64
68
  requirements:
65
69
  - - ">="
66
70
  - !ruby/object:Gem::Version
@@ -70,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
74
  requirements: []
71
75
 
72
76
  rubyforge_project: "[none]"
73
- rubygems_version: 1.3.6
77
+ rubygems_version: 1.3.7
74
78
  signing_key:
75
79
  specification_version: 3
76
80
  summary: Phonology library for Ruby