string_to_ipa 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/string_to_ipa.rb +64 -43
- data/lib/string_to_ipa/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 913bd1a32bf3ef6fa569939bcc164f43554b56f6
|
4
|
+
data.tar.gz: b39270079e8e9c778e03b4127ce89b9849f38525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e57f432dd52244f69521097d533ba9cd3a999b001e16b698edf6686223490dfc22dfcd40f193bbdbda842f4cc29fe76fadd73bcc57fcc993a918010c14b98996
|
7
|
+
data.tar.gz: 63aed0f3640a4edf02672f69a1120104140e498c1ac36c9c65569c8b369eeffed6d6b86d584e42f7286084469e0a78f99e73c5ba6166574292c0e7eb2c2be767
|
data/README.md
CHANGED
@@ -20,12 +20,26 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
**#to_ipa**
|
24
|
+
|
23
25
|
To convert a string to the International Phonetic Alphabet:
|
24
26
|
|
25
27
|
```ruby
|
26
28
|
"yay".to_ipa
|
27
29
|
=> "jˈeɪ"
|
28
30
|
```
|
31
|
+
If the string isn't in the database, calling `.to_ipa` simply returns the original string.
|
32
|
+
|
33
|
+
**#to_word**
|
34
|
+
|
35
|
+
To convert the phonetic version of a word to the American English spelling:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
"jˈeɪ".to_word
|
39
|
+
=> "yay"
|
40
|
+
```
|
41
|
+
|
42
|
+
Likewise, if the phonetic spelling isn't in the database, calling `.to_word` will return the phonetic spelling.
|
29
43
|
|
30
44
|
## Contributing
|
31
45
|
|
@@ -49,4 +63,4 @@ The [Carnegie Mellon University Pronouncing Dictionary](http://www.speech.cs.cmu
|
|
49
63
|
|
50
64
|
*This work was supported in part by funding from the Defense Advanced Research Projects Agency, the Office of Naval Research and the National Science Foundation of the United States of America, and by member companies of the Carnegie Mellon Sphinx Speech Consortium. We acknowledge the contributions of many volunteers to the expansion and improvement of this dictionary.*
|
51
65
|
|
52
|
-
*THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY 'AS IS' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*
|
66
|
+
*THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY 'AS IS' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*
|
data/lib/string_to_ipa.rb
CHANGED
@@ -1,72 +1,93 @@
|
|
1
1
|
require "string_to_ipa/version"
|
2
2
|
require "sqlite3"
|
3
|
+
require "pry"
|
3
4
|
|
4
5
|
module StringToIpa
|
5
|
-
DATABASE = SQLite3::Database.new("ipagem.db")
|
6
|
-
|
7
|
-
DATABASE.results_as_hash = true
|
8
|
-
DATABASE.execute( "PRAGMA encoding = \"UTF-16\"" );
|
9
|
-
|
10
6
|
class Phonetic
|
11
7
|
attr_accessor :word, :phonetic
|
12
8
|
attr_reader :id
|
13
|
-
|
9
|
+
|
14
10
|
def initialize(options)
|
15
|
-
@word = options[
|
16
|
-
@phonetic = options[
|
17
|
-
@id = options[
|
11
|
+
@word = options[:word]
|
12
|
+
@phonetic = options[:phonetic]
|
13
|
+
@id = options[:id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ipa
|
17
|
+
phonetic = database.execute("SELECT phonetic from phonetics where word = ?", @word.upcase)
|
18
|
+
|
19
|
+
if phonetic == []
|
20
|
+
return @word
|
21
|
+
else
|
22
|
+
return phonetic[0]["phonetic"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_word
|
27
|
+
word = database.execute("SELECT word from phonetics where phonetic = ?", @phonetic)
|
28
|
+
|
29
|
+
if word == []
|
30
|
+
return @phonetic
|
31
|
+
else
|
32
|
+
return word[0]["word"].downcase
|
33
|
+
end
|
18
34
|
end
|
19
|
-
|
35
|
+
|
20
36
|
def insert
|
21
|
-
|
22
|
-
@id =
|
37
|
+
database.execute("INSERT INTO phonetics (word, phonetic) VALUES (?, ?)", @word, @phonetic)
|
38
|
+
@id = database.last_insert_row_id
|
23
39
|
end
|
24
|
-
|
25
|
-
def save
|
40
|
+
|
41
|
+
def save
|
26
42
|
attributes = []
|
27
|
-
|
28
|
-
instance_variables.each do |i|
|
29
|
-
attributes << i.to_s.delete("@")
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
attributes.each do |a|
|
43
|
+
|
44
|
+
instance_variables.each do |i|
|
45
|
+
attributes << i.to_s.delete("@")
|
46
|
+
end
|
47
|
+
|
48
|
+
query_hash = {}
|
49
|
+
|
50
|
+
attributes.each do |a|
|
36
51
|
value = self.send(a)
|
37
|
-
query_hash[a] = value
|
38
|
-
end
|
52
|
+
query_hash[a] = value
|
53
|
+
end
|
39
54
|
|
40
55
|
query_hash.each do |key, value|
|
41
|
-
|
42
|
-
end
|
56
|
+
database.execute("UPDATE phonetics SET #{key} = ? WHERE id = #{@id}", value)
|
57
|
+
end
|
43
58
|
end
|
44
|
-
|
59
|
+
|
45
60
|
def delete
|
46
|
-
|
61
|
+
database.execute("DELETE FROM phonetics WHERE id = #{@id}")
|
47
62
|
end
|
48
|
-
|
49
|
-
|
63
|
+
|
50
64
|
def self.find(s_id)
|
51
|
-
result =
|
52
|
-
|
65
|
+
result = database.execute("SELECT * FROM phonetics WHERE id = #{s_id}")[0]
|
53
66
|
self.new(result)
|
54
67
|
end
|
55
|
-
|
56
|
-
end
|
57
68
|
|
69
|
+
private
|
70
|
+
|
71
|
+
def database
|
72
|
+
@database ||= begin
|
73
|
+
db = SQLite3::Database.new(File.join(File.expand_path(File.dirname(__FILE__)), "..", "ipagem.db"))
|
74
|
+
db.results_as_hash = true
|
75
|
+
db.execute( "PRAGMA encoding = \"UTF-16\"" )
|
76
|
+
db
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
58
81
|
end
|
59
82
|
|
83
|
+
|
60
84
|
class String
|
61
85
|
def to_ipa
|
62
|
-
|
63
|
-
|
64
|
-
if phonetic == []
|
65
|
-
return self
|
66
|
-
else
|
67
|
-
return phonetic[0]["phonetic"]
|
68
|
-
end
|
69
|
-
|
86
|
+
StringToIpa::Phonetic.new(word: self).to_ipa
|
70
87
|
end
|
71
88
|
|
89
|
+
|
90
|
+
def to_word
|
91
|
+
StringToIpa::Phonetic.new(phonetic: self).to_word
|
92
|
+
end
|
72
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_to_ipa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hilary Stohs-Krause
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.4.8
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: A minimalist gem that converts a string to the International Phonetic Alphabet.
|