simplificator-babel 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +16 -8
- data/Rakefile +20 -2
- data/VERSION.yml +1 -1
- data/babel.gemspec +2 -2
- data/lib/babel/babel.rb +0 -1
- data/lib/babel/profile.rb +43 -36
- data/lib/babel/string_extensions.rb +2 -1
- data/lib/profiles/profile_deu.yml +13431 -11455
- data/lib/profiles/profile_eng.yml +12586 -8998
- data/lib/profiles/profile_fra.yml +13437 -10092
- data/lib/profiles/profile_ita.yml +13388 -9489
- data/lib/profiles/profile_spa.yml +13367 -9617
- data/samples/guessing.rb +3 -8
- data/test/babel_test.rb +22 -2
- data/test/profile_test.rb +26 -15
- metadata +2 -2
data/samples/guessing.rb
CHANGED
@@ -9,20 +9,15 @@ def show_languages(s)
|
|
9
9
|
puts "Possible Languages for '#{s}': \n#{s.languages[0..2].join(', ')}"
|
10
10
|
end
|
11
11
|
|
12
|
-
en =
|
12
|
+
en = 'Rainy sunday'
|
13
13
|
de = 'Regnerischer Sonntag'
|
14
14
|
fr = 'Je ne regrette rien'
|
15
15
|
sp = 'yo no soy un marinero'
|
16
16
|
|
17
|
-
texts = [en, de, fr, sp]
|
17
|
+
texts = [en, de, fr, sp, 'lago di como']
|
18
18
|
Babel.load_profiles
|
19
19
|
|
20
20
|
texts.each do |text|
|
21
21
|
guess_language text
|
22
22
|
show_languages text
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
end
|
data/test/babel_test.rb
CHANGED
@@ -1,13 +1,33 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class BabelTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
should 'identify the language' do
|
5
|
+
Babel.load_profiles
|
6
|
+
assert_equal 'deu', 'ich gehe essen'.language
|
7
|
+
assert_equal 'deu', 'guten morgen'.language
|
8
|
+
assert_equal 'deu', 'öäü'.language # :-)
|
9
|
+
assert_equal 'deu', 'du bist der jackpot meines lebens'.language
|
10
|
+
|
11
|
+
assert_equal 'eng', 'imagine there\'s no heaven'.language
|
12
|
+
assert_equal 'eng', 'then there was you'.language
|
13
|
+
assert_equal 'eng', 'small step for me'.language
|
14
|
+
assert_equal 'eng', 'let there'.language
|
15
|
+
|
16
|
+
assert_equal 'fra', 'le coq est mort'.language
|
17
|
+
assert_equal 'fra', 'garçon'.language
|
18
|
+
assert_equal 'fra', 'je ne sais pas'.language
|
19
|
+
|
20
|
+
assert_equal 'spa', 'yo no soy un marinero'.language
|
21
|
+
assert_equal 'spa', 'mucho gusto'.language
|
22
|
+
assert_equal 'ita', 'lago di como'.language
|
23
|
+
end
|
5
24
|
|
6
25
|
should 'have a test' do
|
7
|
-
fail
|
26
|
+
#fail
|
8
27
|
end
|
9
28
|
|
10
29
|
should 'not choke when registering the first' do
|
30
|
+
#puts "abc".n_grams(:pad => true)
|
11
31
|
end
|
12
32
|
|
13
33
|
end
|
data/test/profile_test.rb
CHANGED
@@ -30,13 +30,13 @@ class ProfileTest < Test::Unit::TestCase
|
|
30
30
|
profile.occured('c', 5)
|
31
31
|
profile.occured('d', 3)
|
32
32
|
|
33
|
-
profile.
|
33
|
+
profile.weigh_and_rank
|
34
34
|
|
35
|
-
assert_equal 1, profile.
|
36
|
-
assert_equal 2, profile.
|
37
|
-
assert_equal 3, profile.
|
38
|
-
assert_equal 4, profile.
|
39
|
-
assert_equal 5, profile.
|
35
|
+
assert_equal 1, profile.rank('a')
|
36
|
+
assert_equal 2, profile.rank('b')
|
37
|
+
assert_equal 3, profile.rank('c')
|
38
|
+
assert_equal 4, profile.rank('d')
|
39
|
+
assert_equal 5, profile.rank('e')
|
40
40
|
end
|
41
41
|
|
42
42
|
should 'limit' do
|
@@ -47,7 +47,7 @@ class ProfileTest < Test::Unit::TestCase
|
|
47
47
|
profile.occured('d', 3)
|
48
48
|
profile.occured('e', 1)
|
49
49
|
|
50
|
-
profile.
|
50
|
+
profile.weigh_and_rank
|
51
51
|
profile.limit(3)
|
52
52
|
|
53
53
|
assert_equal 10, profile.occurence('a')
|
@@ -58,11 +58,13 @@ class ProfileTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
|
60
60
|
should 'find the distance to another profile' do
|
61
|
+
# distance is based on weigh_and_rank which is a floating point number
|
62
|
+
# hard to test. just make some comparisons with <>
|
61
63
|
a = Profile.new
|
62
64
|
b = Profile.new
|
63
65
|
|
64
66
|
a.occured('a')
|
65
|
-
a.
|
67
|
+
a.weigh_and_rank # always rank when finished with occured(). distance is baed on rank
|
66
68
|
|
67
69
|
assert_equal 0, a.distance(a), 'distance to self is 0'
|
68
70
|
assert_equal 1, a.distance(b)
|
@@ -70,7 +72,7 @@ class ProfileTest < Test::Unit::TestCase
|
|
70
72
|
assert_equal 0, b.distance(b)
|
71
73
|
|
72
74
|
b.occured('a')
|
73
|
-
b.
|
75
|
+
b.weigh_and_rank
|
74
76
|
|
75
77
|
assert_equal 0, a.distance(a)
|
76
78
|
assert_equal 0, a.distance(b)
|
@@ -79,15 +81,14 @@ class ProfileTest < Test::Unit::TestCase
|
|
79
81
|
|
80
82
|
a.occured('b')
|
81
83
|
a.occured('c')
|
82
|
-
a.
|
84
|
+
a.weigh_and_rank
|
83
85
|
|
84
|
-
|
86
|
+
assert 2 < a.distance(b)
|
85
87
|
|
86
88
|
a.occured('d')
|
87
|
-
a.
|
88
|
-
|
89
|
-
|
90
|
-
assert_equal 8, a.distance(b)
|
89
|
+
a.weigh_and_rank
|
90
|
+
|
91
|
+
assert 3 < a.distance(b)
|
91
92
|
end
|
92
93
|
|
93
94
|
should 'learn a text' do
|
@@ -102,4 +103,14 @@ class ProfileTest < Test::Unit::TestCase
|
|
102
103
|
assert_equal 1, profile.occurence('meme')
|
103
104
|
end
|
104
105
|
|
106
|
+
should 'clean a text' do
|
107
|
+
profile = Profile.new
|
108
|
+
assert_equal '', profile.clean_text('')
|
109
|
+
assert_equal ' ', profile.clean_text(' ')
|
110
|
+
assert_equal ' ', profile.clean_text(' ')
|
111
|
+
assert_equal 'hallo', profile.clean_text('1h2a3l4l5o')
|
112
|
+
assert_equal 'no braces and brackets and curly braces', profile.clean_text('(no ({braces) [] and brackets} and curly braces[]')
|
113
|
+
|
114
|
+
end
|
115
|
+
|
105
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplificator-babel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- simplificator
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-14 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|