rhopalic 0.0.1.pre → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/rhopalic/analysis.rb +24 -5
- data/lib/rhopalic/version.rb +1 -1
- data/rhopalic.gemspec +1 -0
- data/test/rhopalic_test.rb +10 -0
- metadata +21 -5
data/README.md
CHANGED
@@ -4,6 +4,8 @@ rhopalic
|
|
4
4
|
A Ruby library to detect rhopalic phrases in English, i.e., a phrase in which each
|
5
5
|
word contains one letter or one syllable more than the previous word.
|
6
6
|
|
7
|
+
Available as [a gem](https://rubygems.org/gems/rhopalic).
|
8
|
+
|
7
9
|
## Usage
|
8
10
|
|
9
11
|
For simple yes or no answers about whether a phrase is rhopalic:
|
data/lib/rhopalic/analysis.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'lingua'
|
2
|
+
require 'numbers_and_words'
|
2
3
|
|
3
4
|
require 'rhopalic/contractions'
|
4
5
|
require 'rhopalic/phrase'
|
@@ -18,12 +19,18 @@ module Rhopalic
|
|
18
19
|
is_letter_rhopalic = true
|
19
20
|
is_syllable_rhopalic = true
|
20
21
|
|
21
|
-
|
22
|
-
# - numbers
|
23
|
-
phrase.scan(/[[:alpha:]]+/) do
|
22
|
+
phrase.scan(/\b[[:alpha:]\d]+\b/) do
|
24
23
|
match = Regexp.last_match
|
25
24
|
word = match[0]
|
26
25
|
index = match.begin(0)
|
26
|
+
is_number = false
|
27
|
+
|
28
|
+
# Bail out on words that contain numbers, unless we can pronounce the number
|
29
|
+
# as a whole word.
|
30
|
+
word.match(/\d+/) do |match|
|
31
|
+
return nil if match[0].size != word.size
|
32
|
+
is_number = true
|
33
|
+
end
|
27
34
|
|
28
35
|
# Checking whether the previous and this word form a known contraction
|
29
36
|
# or possessive.
|
@@ -44,12 +51,24 @@ module Rhopalic
|
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
54
|
+
# If the words is a series of digits, count syllables based on spelling the
|
55
|
+
# number out, but ignore it if the number doesn't translate to a single word.
|
56
|
+
syllable_counting_word = word
|
57
|
+
if is_number
|
58
|
+
number_as_words = word.to_i.to_words
|
59
|
+
if number_as_words.match(/^\w+$/)
|
60
|
+
syllable_counting_word = number_as_words
|
61
|
+
else
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
47
66
|
if @dictionary
|
48
|
-
syllable_count = @dictionary.syllable_count(
|
67
|
+
syllable_count = @dictionary.syllable_count(syllable_counting_word)
|
49
68
|
in_dictionary.push(true) unless syllable_count.nil?
|
50
69
|
end
|
51
70
|
if !syllable_count
|
52
|
-
syllable_count = Lingua::EN::Syllable.syllables(
|
71
|
+
syllable_count = Lingua::EN::Syllable.syllables(syllable_counting_word)
|
53
72
|
in_dictionary.push(false)
|
54
73
|
end
|
55
74
|
|
data/lib/rhopalic/version.rb
CHANGED
data/rhopalic.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = 'Detects rhopalic phrases'
|
13
13
|
|
14
14
|
s.add_runtime_dependency 'lingua', '~> 0.6.2'
|
15
|
+
s.add_runtime_dependency 'numbers_and_words', '~> 0.6.0'
|
15
16
|
s.add_development_dependency 'param_test', '~> 0.0.2'
|
16
17
|
|
17
18
|
s.files = `git ls-files`.split("\n")
|
data/test/rhopalic_test.rb
CHANGED
@@ -47,6 +47,16 @@ class Rhopalic::RhopalicTest < ActiveSupport::TestCase
|
|
47
47
|
assert Rhopalic.rhopalic?(phrase)
|
48
48
|
end
|
49
49
|
|
50
|
+
param_test "phrase %s with numbers is not rhopalic",
|
51
|
+
["foo bar2", "foo 22 bar"] do |phrase|
|
52
|
+
assert !Rhopalic.rhopalic?(phrase)
|
53
|
+
end
|
54
|
+
|
55
|
+
param_test "phrase %s with numbers is rhopalic",
|
56
|
+
["1 random diacrit", "2 20 revolvers"] do |phrase|
|
57
|
+
assert Rhopalic.rhopalic?(phrase)
|
58
|
+
end
|
59
|
+
|
50
60
|
def test_analyze_phrase_not_rhopalic
|
51
61
|
assert_nil Rhopalic.analyze_phrase("three two")
|
52
62
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhopalic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nik Haldimann
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: lingua
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.6.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: numbers_and_words
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.6.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.6.0
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: param_test
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,9 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
99
|
none: false
|
84
100
|
requirements:
|
85
|
-
- - ! '
|
101
|
+
- - ! '>='
|
86
102
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
103
|
+
version: '0'
|
88
104
|
requirements: []
|
89
105
|
rubyforge_project:
|
90
106
|
rubygems_version: 1.8.23
|