phonology 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phonology/inventory.rb +18 -12
- data/lib/phonology/sound_sequence.rb +4 -0
- data/lib/phonology/syllable.rb +1 -1
- data/lib/phonology/version.rb +1 -1
- data/test/sound_test.rb +2 -1
- metadata +5 -2
data/lib/phonology/inventory.rb
CHANGED
@@ -10,16 +10,22 @@ module Phonology
|
|
10
10
|
# Get an instance, building its set from a list IPA characters.
|
11
11
|
def self.from_ipa(*chars)
|
12
12
|
chars = chars.flatten.map {|char| char.unpack("U*")}
|
13
|
-
new Features::SETS.select {|key, val| chars.include? val}
|
13
|
+
new Hash[Features::SETS.select {|key, val| chars.include? val}]
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(sets)
|
17
17
|
@sets = sets
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if RUBY_VERSION < "1.9"
|
21
|
+
# Given an IPA symbol, return a corresponding set of distinctive features.
|
22
|
+
def features(symbol)
|
23
|
+
@sets.index(symbol.unpack("U*"))
|
24
|
+
end
|
25
|
+
else
|
26
|
+
def features(symbol)
|
27
|
+
@sets.key(symbol.unpack("U*"))
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
# Given a set of features, return an IPA symbol
|
@@ -41,31 +47,31 @@ module Phonology
|
|
41
47
|
# features.
|
42
48
|
def with(*features)
|
43
49
|
pos, neg = mangle_args(*features)
|
44
|
-
self.class.new(@sets.select do |key, val|
|
50
|
+
self.class.new(Hash[@sets.select do |key, val|
|
45
51
|
!key.intersection(pos).empty?
|
46
|
-
end).without_any(neg)
|
52
|
+
end]).without_any(neg)
|
47
53
|
end
|
48
54
|
|
49
55
|
# Return feature sets that include all of the given features
|
50
56
|
def with_all(*features)
|
51
57
|
pos, neg = mangle_args(*features)
|
52
|
-
self.class.new(@sets.select do |key, val|
|
58
|
+
self.class.new(Hash[@sets.select do |key, val|
|
53
59
|
pos.subset?(key)
|
54
|
-
end).without_any(neg)
|
60
|
+
end]).without_any(neg)
|
55
61
|
end
|
56
62
|
|
57
63
|
# Return an instance of Sounds whose sets exclude any of the given
|
58
64
|
# features.
|
59
65
|
def without(*features)
|
60
66
|
features = setify(*features)
|
61
|
-
self.class.new @sets.select {|key, val| !features.subset?(key)}
|
67
|
+
self.class.new Hash[@sets.select {|key, val| !features.subset?(key)}]
|
62
68
|
end
|
63
69
|
|
64
70
|
# Return an instance of Sounds whose sets exclude all of the given
|
65
71
|
# features.
|
66
72
|
def without_any(*features)
|
67
73
|
features = setify(*features)
|
68
|
-
self.class.new @sets.select {|key, val| key.intersection(features).empty?}
|
74
|
+
self.class.new Hash[@sets.select {|key, val| key.intersection(features).empty?}]
|
69
75
|
end
|
70
76
|
|
71
77
|
private
|
@@ -73,7 +79,7 @@ module Phonology
|
|
73
79
|
def mangle_args(*args)
|
74
80
|
pos = setify(*args)
|
75
81
|
neg = extract_negations(pos)
|
76
|
-
[pos.select {|f| f !~ /\A(non_|un)/}.compact.to_set, neg]
|
82
|
+
[pos.select {|f| f.to_s !~ /\A(non_|un)/}.compact.to_set, neg]
|
77
83
|
end
|
78
84
|
|
79
85
|
def setify(*args)
|
@@ -81,7 +87,7 @@ module Phonology
|
|
81
87
|
end
|
82
88
|
|
83
89
|
def extract_negations(set)
|
84
|
-
Features.expand(*set.map {|feat| feat =~ /\A(non_|un)([a-z_]*)\z/ && $2.to_sym}.compact)
|
90
|
+
val = Features.expand(*set.map {|feat| feat.to_s =~ /\A(non_|un)([a-z_]*)\z/ && $2.to_sym}.compact)
|
85
91
|
end
|
86
92
|
|
87
93
|
end
|
data/lib/phonology/syllable.rb
CHANGED
data/lib/phonology/version.rb
CHANGED
data/test/sound_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require File.expand_path("../test_helper", __FILE__)
|
2
3
|
|
3
4
|
class SoundTest < Test::Unit::TestCase
|
@@ -49,7 +50,7 @@ class SoundTest < Test::Unit::TestCase
|
|
49
50
|
test "should add/remove rounding" do
|
50
51
|
sound = Sound.new("a")
|
51
52
|
sound << :rounded
|
52
|
-
assert_equal "
|
53
|
+
assert_equal "ɶ", sound.symbol
|
53
54
|
sound >> :rounded
|
54
55
|
assert_equal "a", sound.symbol
|
55
56
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phonology
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Norman Clarke
|
@@ -60,6 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
61
|
requirements:
|
61
62
|
- - ">="
|
62
63
|
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
63
65
|
segments:
|
64
66
|
- 0
|
65
67
|
version: "0"
|
@@ -68,6 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
70
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
71
74
|
segments:
|
72
75
|
- 0
|
73
76
|
version: "0"
|