odin 0.0.4

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.
Files changed (64) hide show
  1. data/.gitignore +19 -0
  2. data/.rvmrc +1 -0
  3. data/.travis.yml +2 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +26 -0
  6. data/HISTORY.md +102 -0
  7. data/LICENSE.md +10 -0
  8. data/README.md +46 -0
  9. data/Rakefile +69 -0
  10. data/app/controllers/grammar_checker.rb +51 -0
  11. data/check_grammar.rb +24 -0
  12. data/configure +9 -0
  13. data/images/atn_diagram.graffle +0 -0
  14. data/images/atn_diagram.pdf +0 -0
  15. data/images/odin-ff6.gif +0 -0
  16. data/lang/en/adjectives.rb +388 -0
  17. data/lang/en/atn.rb +102 -0
  18. data/lang/en/closed_class_words.rb +206 -0
  19. data/lang/en/data.rb +1086 -0
  20. data/lang/en/noun_inflections.rb +76 -0
  21. data/lang/en/noun_inflector_test_cases.rb +235 -0
  22. data/lang/en/pronoun_inflector_test_cases.rb +14 -0
  23. data/lang/en/verbs.rb +648 -0
  24. data/lang/iso639.rb +405 -0
  25. data/lib/array.rb +15 -0
  26. data/lib/atn.rb +82 -0
  27. data/lib/augmented_transition_network.rb +146 -0
  28. data/lib/dumper.rb +44 -0
  29. data/lib/noun_inflector.rb +283 -0
  30. data/lib/odin.rb +3 -0
  31. data/lib/odin/version.rb +3 -0
  32. data/lib/parts_of_speech.rb +402 -0
  33. data/lib/star.rb +23 -0
  34. data/lib/string.rb +99 -0
  35. data/lib/string_bracketing.rb +100 -0
  36. data/lib/word.rb +69 -0
  37. data/lib/word_net.rb +265 -0
  38. data/odin.gemspec +27 -0
  39. data/simple_atn/README.md +45 -0
  40. data/simple_atn/Rakefile +9 -0
  41. data/simple_atn/array.rb +15 -0
  42. data/simple_atn/augmented_transition_network.rb +146 -0
  43. data/simple_atn/augmented_transition_network_test.rb +113 -0
  44. data/simple_atn/english.rb +161 -0
  45. data/simple_atn/string.rb +63 -0
  46. data/test/fixtures/alice.txt +3594 -0
  47. data/test/fixtures/art.txt +7 -0
  48. data/test/fixtures/both.txt +1 -0
  49. data/test/fixtures/existing.txt +0 -0
  50. data/test/fixtures/existing.txt.checked.html +0 -0
  51. data/test/fixtures/grammar_checker.css +4 -0
  52. data/test/fixtures/grammatical.txt +1 -0
  53. data/test/fixtures/ungrammatical.txt +1 -0
  54. data/test/functional/grammar_checker_test.rb +64 -0
  55. data/test/integration/en/word_and_noun_inflector_test.rb +29 -0
  56. data/test/test_helper.rb +82 -0
  57. data/test/unit/atn_test.rb +240 -0
  58. data/test/unit/noun_inflector_test.rb +249 -0
  59. data/test/unit/pronoun_inflector_test.rb +17 -0
  60. data/test/unit/star_test.rb +24 -0
  61. data/test/unit/string_bracketing_test_module.rb +70 -0
  62. data/test/unit/string_test.rb +92 -0
  63. data/test/unit/word_test.rb +15 -0
  64. metadata +223 -0
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__)/'..'/'test_helper'
2
+ require File.dirname(__FILE__)/'..'/'..'/'lang'/'en'/'pronoun_inflector_test_cases.rb' # TODO no "en"
3
+
4
+ class PronounInflectorTest < Test::Unit::TestCase
5
+ include ClosedClassWords
6
+ include PronounInflectorTestCases
7
+
8
+ # @@SingularPronouns.each do |singular|
9
+ # define_method "test_#{singular}_singular" do
10
+ # assert(Word.new(singular).singular?)
11
+ # end
12
+ # end
13
+
14
+ def test_truth
15
+ assert_equal(true, true)
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__)/'..'/'test_helper'
2
+
3
+ class StarTest < Test::Unit::TestCase
4
+ def setup
5
+ @test_words = ['one', 'two', 'three']
6
+ @star = Star.new('one', 'two', 'three')
7
+ end
8
+
9
+ def test_identify_fragment
10
+ assert_raise(FragmentException) do
11
+ @test_words.length.times do
12
+ @star.next
13
+ end
14
+ end
15
+ end
16
+
17
+ def test_identify_not_a_fragment
18
+ assert_nothing_raised(FragmentException) do
19
+ (@test_words.length - 1).times do
20
+ @star.next
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ module StringBracketingTests
2
+ # TITLE:
3
+ #
4
+ # String Bracketing Extensoins
5
+ #
6
+ # SUMMARY:
7
+ #
8
+ # String extension methods which enclose on unenclose a striong.
9
+ #
10
+ # CREDITS:
11
+ #
12
+ # - Thomas Sawyer
13
+
14
+ def test_bracket
15
+ assert_equal( '#X#', 'X'.bracket('#') )
16
+ assert_equal( 'xX!', 'X'.bracket('x','!') )
17
+ assert_equal( '{X}', 'X'.bracket('{','}') )
18
+ assert_equal( '<X>', 'X'.bracket('<') )
19
+ assert_equal( '(X)', 'X'.bracket('(') )
20
+ assert_equal( '[X]', 'X'.bracket('[') )
21
+ assert_equal( '{X}', 'X'.bracket('{') )
22
+ end
23
+
24
+ def test_bracket!
25
+ a = 'X' ; a.bracket!('#')
26
+ assert_equal( '#X#', a )
27
+ a = 'X' ; a.bracket!('x','!')
28
+ assert_equal( 'xX!', a )
29
+ a = 'X' ; a.bracket!('{','}')
30
+ assert_equal( '{X}', a )
31
+ a = 'X' ; a.bracket!('<')
32
+ assert_equal( '<X>', a )
33
+ a = 'X' ; a.bracket!('(')
34
+ assert_equal( '(X)', a )
35
+ a = 'X' ; a.bracket!('[')
36
+ assert_equal( '[X]', a )
37
+ a = 'X' ; a.bracket!('{')
38
+ assert_equal( '{X}', a )
39
+ end
40
+
41
+ def test_quote_01
42
+ a = "hi"
43
+ assert_raises( ArgumentError ) { a.quote(1,2) }
44
+ end
45
+
46
+ def test_quote_02
47
+ a = "hi"
48
+ assert_equal( %{'hi'}, a.quote )
49
+ end
50
+
51
+ def test_quote_03
52
+ a = "hi"
53
+ assert_equal( %{"hi"}, a.quote(:d) )
54
+ assert_equal( %{"hi"}, a.quote(:double) )
55
+ end
56
+
57
+ def test_quote_04
58
+ a = "hi"
59
+ assert_equal( %{'hi'}, a.quote(:s) )
60
+ assert_equal( %{'hi'}, a.quote(:single) )
61
+ end
62
+
63
+ def test_quote_05
64
+ a = "hi"
65
+ assert_equal( %{`hi`}, a.quote(:b) )
66
+ assert_equal( %{`hi`}, a.quote(:back) )
67
+ end
68
+
69
+ # end of String Bracketing Extensoins
70
+ end
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__)/'..'/'test_helper'
2
+ require File.dirname(__FILE__)/'string_bracketing_test_module'
3
+
4
+ class StringTest < Test::Unit::TestCase
5
+ include StringBracketingTests
6
+
7
+ def setup
8
+ @test_sentences = []
9
+ @test_sentences << @only_period_sentence = "This has no punctuation except for a period."
10
+ @test_sentences << @contraction_sentence = "Shouldn't we also test with contractions?"
11
+ @test_sentences << "Hello, John."
12
+ @test_sentences << "How are you?"
13
+ @test_sentences << "How are you?!"
14
+ @test_sentences << "Hello, world!"
15
+ @test_sentences << @ellipsis_and_apostrophe_sentence = "That's odd..."
16
+ @test_sentences << "Program exited."
17
+ @test_sentences << "Hey guys..."
18
+ @test_sentences << "Looks good, the with_index is the option I was looking for..."
19
+ @test_sentences << "just looked so messy having to declare a counter variable in a view..."
20
+ @test_sentences << "thanks!"
21
+ @test_sentences << "But a much cleaner solution would be to not test for whether the method was called but whether logged-out users can access the controller."
22
+ @test_sentences << "Because what you're really trying to test is whether certain users can visit certain pages, right?"
23
+ @test_sentences << "So just check for that."
24
+ @test_sentences << "Then you can change the implementation (rename or replace the before filter) later and your tests won't break."
25
+ end
26
+
27
+ def test_minus
28
+ assert_equal("fbar", "foobar" - "oo")
29
+ assert_equal("pia pia!", "pizza pizza!" - "zz")
30
+ assert_equal("", "letters" - /[a-z]+/)
31
+ end
32
+
33
+ def test_normalize
34
+ assert_equal("hello, world.", "Hello, world!".normalize)
35
+ assert_equal("how are you.", "How are you?".normalize)
36
+ assert_equal("how are you.", "How are you?!".normalize)
37
+ assert_equal("that's odd.", "That's odd...".normalize)
38
+ end
39
+
40
+ def test_each_sentence
41
+ corpus = @test_sentences.join(" ")
42
+ index = 0
43
+ corpus.sentences.each do |sentence|
44
+ assert_equal(@test_sentences[index], sentence)
45
+ index += 1
46
+ end
47
+ end
48
+
49
+ def test_no_words_in_empty_string
50
+ assert_equal(0, "".words.length)
51
+ end
52
+
53
+ def test_no_words_in_whitespace_string
54
+ assert_equal(0, " ".words.length)
55
+ assert_equal(0, " ".words.length)
56
+ assert_equal(0, " ".words.length)
57
+ assert_equal(0, "\t".words.length)
58
+ end
59
+
60
+ def test_whitespace_then_character_string
61
+ assert_equal(1, " A".words.length)
62
+ assert_equal(2, " A B".words.length)
63
+ assert_equal(2, " A B".words.length)
64
+ end
65
+
66
+ def test_words_in_a_sentence_with_no_punctuation
67
+ no_punctuation_sentence = "This sentence does not even have a period"
68
+ expected_words = ["This", "sentence", "does", "not", "even", "have", "a" ,"period"]
69
+ assert_equal(expected_words, no_punctuation_sentence.words)
70
+ end
71
+
72
+ def test_words_in_a_sentence_with_only_a_period
73
+ expected_words = ['This', 'has', 'no', 'punctuation', 'except', 'for', 'a', 'period']
74
+ assert_equal(expected_words, @only_period_sentence.words)
75
+ end
76
+
77
+ def test_each_word_with_contraction
78
+ expected_words = ['Shouldn\'t', 'we', 'also', 'test', 'with', 'contractions']
79
+ assert_equal(expected_words, @contraction_sentence.words)
80
+ end
81
+
82
+ # "grammatical?" tested in atn_test.rb
83
+
84
+ def test_check_grammar
85
+ # TODO
86
+ # output = "The old man loves you. The man the apples.".check_grammar do |sentence|
87
+ # "<ungrammatical message=\"\" suggestion=\"\">#{sentence}</ungrammatical>"
88
+ # end
89
+ #
90
+ # puts output
91
+ end
92
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__)/'..'/'test_helper'
2
+
3
+ class WordTest < Test::Unit::TestCase
4
+ def test_simple_instantiation
5
+ content = "foobar"
6
+ test = Word.new(content)
7
+ assert_equal(content, test)
8
+ end
9
+
10
+ def test_multiword_instantiation
11
+ assert_raise(Word::FormatException) do
12
+ Word.new("This has spaces.")
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
11
+ platform: ruby
12
+ authors:
13
+ - Benjamin Oakes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 13
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 1
33
+ version: 2.0.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: english
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 0
47
+ - 1
48
+ version: "0.1"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: facets
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 5
60
+ segments:
61
+ - 2
62
+ - 2
63
+ - 1
64
+ version: 2.2.1
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: linguistics
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 7
76
+ segments:
77
+ - 1
78
+ - 0
79
+ - 8
80
+ version: 1.0.8
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 49
92
+ segments:
93
+ - 0
94
+ - 8
95
+ - 7
96
+ version: 0.8.7
97
+ type: :development
98
+ version_requirements: *id005
99
+ description: A parser for human languages.
100
+ email:
101
+ - hello@benjaminoakes.com
102
+ executables: []
103
+
104
+ extensions: []
105
+
106
+ extra_rdoc_files: []
107
+
108
+ files:
109
+ - .gitignore
110
+ - .rvmrc
111
+ - .travis.yml
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - HISTORY.md
115
+ - LICENSE.md
116
+ - README.md
117
+ - Rakefile
118
+ - app/controllers/grammar_checker.rb
119
+ - check_grammar.rb
120
+ - configure
121
+ - images/atn_diagram.graffle
122
+ - images/atn_diagram.pdf
123
+ - images/odin-ff6.gif
124
+ - lang/en/adjectives.rb
125
+ - lang/en/atn.rb
126
+ - lang/en/closed_class_words.rb
127
+ - lang/en/data.rb
128
+ - lang/en/noun_inflections.rb
129
+ - lang/en/noun_inflector_test_cases.rb
130
+ - lang/en/pronoun_inflector_test_cases.rb
131
+ - lang/en/verbs.rb
132
+ - lang/iso639.rb
133
+ - lib/array.rb
134
+ - lib/atn.rb
135
+ - lib/augmented_transition_network.rb
136
+ - lib/dumper.rb
137
+ - lib/noun_inflector.rb
138
+ - lib/odin.rb
139
+ - lib/odin/version.rb
140
+ - lib/parts_of_speech.rb
141
+ - lib/star.rb
142
+ - lib/string.rb
143
+ - lib/string_bracketing.rb
144
+ - lib/word.rb
145
+ - lib/word_net.rb
146
+ - odin.gemspec
147
+ - simple_atn/README.md
148
+ - simple_atn/Rakefile
149
+ - simple_atn/array.rb
150
+ - simple_atn/augmented_transition_network.rb
151
+ - simple_atn/augmented_transition_network_test.rb
152
+ - simple_atn/english.rb
153
+ - simple_atn/string.rb
154
+ - test/fixtures/alice.txt
155
+ - test/fixtures/art.txt
156
+ - test/fixtures/both.txt
157
+ - test/fixtures/existing.txt
158
+ - test/fixtures/existing.txt.checked.html
159
+ - test/fixtures/grammar_checker.css
160
+ - test/fixtures/grammatical.txt
161
+ - test/fixtures/ungrammatical.txt
162
+ - test/functional/grammar_checker_test.rb
163
+ - test/integration/en/word_and_noun_inflector_test.rb
164
+ - test/test_helper.rb
165
+ - test/unit/atn_test.rb
166
+ - test/unit/noun_inflector_test.rb
167
+ - test/unit/pronoun_inflector_test.rb
168
+ - test/unit/star_test.rb
169
+ - test/unit/string_bracketing_test_module.rb
170
+ - test/unit/string_test.rb
171
+ - test/unit/word_test.rb
172
+ homepage: http://github.com/benjaminoakes/odin
173
+ licenses: []
174
+
175
+ post_install_message:
176
+ rdoc_options: []
177
+
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ hash: 3
195
+ segments:
196
+ - 0
197
+ version: "0"
198
+ requirements: []
199
+
200
+ rubyforge_project: odin
201
+ rubygems_version: 1.8.11
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: A parser for human languages.
205
+ test_files:
206
+ - test/fixtures/alice.txt
207
+ - test/fixtures/art.txt
208
+ - test/fixtures/both.txt
209
+ - test/fixtures/existing.txt
210
+ - test/fixtures/existing.txt.checked.html
211
+ - test/fixtures/grammar_checker.css
212
+ - test/fixtures/grammatical.txt
213
+ - test/fixtures/ungrammatical.txt
214
+ - test/functional/grammar_checker_test.rb
215
+ - test/integration/en/word_and_noun_inflector_test.rb
216
+ - test/test_helper.rb
217
+ - test/unit/atn_test.rb
218
+ - test/unit/noun_inflector_test.rb
219
+ - test/unit/pronoun_inflector_test.rb
220
+ - test/unit/star_test.rb
221
+ - test/unit/string_bracketing_test_module.rb
222
+ - test/unit/string_test.rb
223
+ - test/unit/word_test.rb