linguine 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ linguine (0.0.4)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.10.0)
11
+ rspec-core (~> 2.10.0)
12
+ rspec-expectations (~> 2.10.0)
13
+ rspec-mocks (~> 2.10.0)
14
+ rspec-core (2.10.1)
15
+ rspec-expectations (2.10.0)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.10.1)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ linguine!
24
+ rspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ linguine
2
+ ========
@@ -0,0 +1,500 @@
1
+ the
2
+ name
3
+ of
4
+ very
5
+ to
6
+ through
7
+ and
8
+ just
9
+ a
10
+ form
11
+ in
12
+ much
13
+ is
14
+ great
15
+ it
16
+ think
17
+ you
18
+ say
19
+ that
20
+ help
21
+ he
22
+ low
23
+ was
24
+ line
25
+ for
26
+ before
27
+ on
28
+ turn
29
+ are
30
+ cause
31
+ with
32
+ same
33
+ as
34
+ mean
35
+ I
36
+ differ
37
+ his
38
+ move
39
+ they
40
+ right
41
+ be
42
+ boy
43
+ at
44
+ old
45
+ one
46
+ too
47
+ have
48
+ does
49
+ this
50
+ tell
51
+ from
52
+ sentence
53
+ or
54
+ set
55
+ had
56
+ three
57
+ by
58
+ want
59
+ hot
60
+ air
61
+ but
62
+ well
63
+ some
64
+ also
65
+ what
66
+ play
67
+ there
68
+ small
69
+ we
70
+ end
71
+ can
72
+ put
73
+ out
74
+ home
75
+ other
76
+ read
77
+ were
78
+ hand
79
+ all
80
+ port
81
+ your
82
+ large
83
+ when
84
+ spell
85
+ up
86
+ add
87
+ use
88
+ even
89
+ word
90
+ land
91
+ how
92
+ here
93
+ said
94
+ must
95
+ an
96
+ big
97
+ each
98
+ high
99
+ she
100
+ such
101
+ which
102
+ follow
103
+ do
104
+ act
105
+ their
106
+ why
107
+ time
108
+ ask
109
+ if
110
+ men
111
+ will
112
+ change
113
+ way
114
+ went
115
+ about
116
+ light
117
+ many
118
+ kind
119
+ then
120
+ off
121
+ them
122
+ need
123
+ would
124
+ house
125
+ write
126
+ picture
127
+ like
128
+ try
129
+ so
130
+ us
131
+ these
132
+ again
133
+ her
134
+ animal
135
+ long
136
+ point
137
+ make
138
+ mother
139
+ thing
140
+ world
141
+ see
142
+ near
143
+ him
144
+ build
145
+ two
146
+ self
147
+ has
148
+ earth
149
+ look
150
+ father
151
+ more
152
+ head
153
+ day
154
+ stand
155
+ could
156
+ own
157
+ go
158
+ page
159
+ come
160
+ should
161
+ did
162
+ country
163
+ my
164
+ found
165
+ sound
166
+ answer
167
+ no
168
+ school
169
+ most
170
+ grow
171
+ number
172
+ study
173
+ who
174
+ still
175
+ over
176
+ learn
177
+ know
178
+ plant
179
+ water
180
+ cover
181
+ than
182
+ food
183
+ call
184
+ sun
185
+ first
186
+ four
187
+ people
188
+ thought
189
+ may
190
+ let
191
+ down
192
+ keep
193
+ side
194
+ eye
195
+ been
196
+ never
197
+ now
198
+ last
199
+ find
200
+ door
201
+ any
202
+ between
203
+ new
204
+ city
205
+ work
206
+ tree
207
+ part
208
+ cross
209
+ take
210
+ since
211
+ get
212
+ hard
213
+ place
214
+ start
215
+ made
216
+ might
217
+ live
218
+ story
219
+ where
220
+ saw
221
+ after
222
+ far
223
+ back
224
+ sea
225
+ little
226
+ draw
227
+ only
228
+ left
229
+ round
230
+ late
231
+ man
232
+ run
233
+ year
234
+ don't
235
+ came
236
+ while
237
+ show
238
+ press
239
+ every
240
+ close
241
+ good
242
+ night
243
+ me
244
+ real
245
+ give
246
+ life
247
+ our
248
+ few
249
+ under
250
+ stop
251
+ open
252
+ ten
253
+ seem
254
+ simple
255
+ together
256
+ several
257
+ next
258
+ vowel
259
+ white
260
+ toward
261
+ children
262
+ begin
263
+ lay
264
+ got
265
+ against
266
+ walk
267
+ pattern
268
+ example
269
+ slow
270
+ ease
271
+ center
272
+ paper
273
+ love
274
+ often
275
+ person
276
+ always
277
+ money
278
+ music
279
+ serve
280
+ those
281
+ appear
282
+ both
283
+ road
284
+ mark
285
+ map
286
+ book
287
+ war
288
+ science
289
+ letter
290
+ rule
291
+ until
292
+ govern
293
+ mile
294
+ pull
295
+ river
296
+ cold
297
+ car
298
+ notice
299
+ feet
300
+ voice
301
+ care
302
+ fall
303
+ second
304
+ power
305
+ group
306
+ town
307
+ carry
308
+ fine
309
+ took
310
+ certain
311
+ rain
312
+ fly
313
+ eat
314
+ unit
315
+ room
316
+ lead
317
+ friend
318
+ cry
319
+ began
320
+ dark
321
+ idea
322
+ machine
323
+ fish
324
+ note
325
+ mountain
326
+ wait
327
+ north
328
+ plan
329
+ once
330
+ figure
331
+ base
332
+ star
333
+ hear
334
+ box
335
+ horse
336
+ noun
337
+ cut
338
+ field
339
+ sure
340
+ rest
341
+ watch
342
+ correct
343
+ color
344
+ able
345
+ face
346
+ pound
347
+ wood
348
+ done
349
+ main
350
+ beauty
351
+ enough
352
+ drive
353
+ plain
354
+ stood
355
+ girl
356
+ contain
357
+ usual
358
+ front
359
+ young
360
+ teach
361
+ ready
362
+ week
363
+ above
364
+ final
365
+ ever
366
+ gave
367
+ red
368
+ green
369
+ list
370
+ oh
371
+ though
372
+ quick
373
+ feel
374
+ develop
375
+ talk
376
+ sleep
377
+ bird
378
+ warm
379
+ soon
380
+ free
381
+ body
382
+ minute
383
+ dog
384
+ strong
385
+ family
386
+ special
387
+ direct
388
+ mind
389
+ pose
390
+ behind
391
+ leave
392
+ clear
393
+ song
394
+ tail
395
+ measure
396
+ produce
397
+ state
398
+ fact
399
+ product
400
+ street
401
+ black
402
+ inch
403
+ short
404
+ lot
405
+ numeral
406
+ nothing
407
+ class
408
+ course
409
+ wind
410
+ stay
411
+ question
412
+ wheel
413
+ happen
414
+ full
415
+ complete
416
+ force
417
+ ship
418
+ blue
419
+ area
420
+ object
421
+ half
422
+ decide
423
+ rock
424
+ surface
425
+ order
426
+ deep
427
+ fire
428
+ moon
429
+ south
430
+ island
431
+ problem
432
+ foot
433
+ piece
434
+ yet
435
+ told
436
+ busy
437
+ knew
438
+ test
439
+ pass
440
+ record
441
+ farm
442
+ boat
443
+ top
444
+ common
445
+ whole
446
+ gold
447
+ king
448
+ possible
449
+ size
450
+ plane
451
+ heard
452
+ age
453
+ best
454
+ dry
455
+ hour
456
+ wonder
457
+ better
458
+ laugh
459
+ true
460
+ thousand
461
+ during
462
+ ago
463
+ hundred
464
+ ran
465
+ am
466
+ check
467
+ remember
468
+ game
469
+ step
470
+ shape
471
+ early
472
+ yes
473
+ hold
474
+ hot
475
+ west
476
+ miss
477
+ ground
478
+ brought
479
+ interest
480
+ heat
481
+ reach
482
+ snow
483
+ fast
484
+ bed
485
+ five
486
+ bring
487
+ sing
488
+ sit
489
+ listen
490
+ perhaps
491
+ six
492
+ fill
493
+ table
494
+ east
495
+ travel
496
+ weight
497
+ less
498
+ language
499
+ morning
500
+ among
@@ -0,0 +1,42 @@
1
+ class Linguine::Scores
2
+
3
+ def self.scrabble_score(word)
4
+ score = 0
5
+ word = word.downcase
6
+
7
+ if word.size > 3
8
+ word.scan(/(a|e|i|o|u|l|n|r|s|t)/).each do
9
+ score += 1
10
+ end
11
+
12
+ word.scan(/d|g/).each do
13
+ score += 2
14
+ end
15
+
16
+ word.scan(/(b|c|m|p)/).each do
17
+ score += 3
18
+ end
19
+
20
+ word.scan(/(f|h|v|w|y)/).each do
21
+ score += 4
22
+ end
23
+
24
+ word.scan(/(k)/).each do
25
+ score += 5
26
+ end
27
+
28
+ word.scan(/(j|x)/).each do
29
+ score += 8
30
+ end
31
+
32
+ word.scan(/(q|z)/).each do
33
+ score += 10
34
+ end
35
+ else
36
+ score = 0
37
+ end
38
+
39
+ score
40
+ end
41
+
42
+ end
data/lib/linguine.rb CHANGED
@@ -1,65 +1,47 @@
1
1
  class Linguine
2
2
 
3
- attr_reader :terms
3
+ attr_reader :terms, :madlibs, :common_words
4
4
 
5
5
  def initialize(method, text)
6
- @method = method
7
- @text = text
8
- @terms = []
6
+ @method = method
7
+ @text = text
8
+ @terms = []
9
+ @madlibs = text
10
+ @common_words = []
11
+
12
+ read_common_words
9
13
 
10
14
  collect_terms
15
+ collect_madlibs
11
16
  end
12
17
 
13
18
  private
14
19
 
15
- def collect_terms
16
- @text.split(' ').each do |word|
17
- @terms << {
18
- word: word,
19
- score: scrabble_score(word)
20
- }
20
+ def read_common_words
21
+ File.open('common_words_en.txt', 'r') do |f|
22
+ while line = f.gets
23
+ @common_words << line.gsub("\n", '')
24
+ end
21
25
  end
22
- @terms.sort_by{|t| t[:score]}.reverse
23
26
  end
24
-
25
- def scrabble_score(word)
26
- score = 0
27
- word = word.downcase
28
-
29
- if word.size > 3
30
- word.scan(/(a|e|i|o|u|l|n|r|s|t)/).each do
31
- score += 1
32
- end
33
-
34
- word.scan(/d|g/).each do
35
- score += 2
36
- end
37
-
38
- word.scan(/(b|c|m|p)/).each do
39
- score += 3
40
- end
41
-
42
- word.scan(/(f|h|v|w|y)/).each do
43
- score += 4
44
- end
45
-
46
- word.scan(/(k)/).each do
47
- score += 5
48
- end
49
-
50
- word.scan(/(j|x)/).each do
51
- score += 8
52
- end
53
-
54
- word.scan(/(q|z)/).each do
55
- score += 10
27
+
28
+ def collect_terms
29
+ @text.split(' ').uniq.each do |word|
30
+ if !@common_words.include?(word)
31
+ @terms << {
32
+ word: word,
33
+ score: Linguine::Scores.scrabble_score(word)
34
+ }
56
35
  end
57
- else
58
- score = 0
59
36
  end
60
37
 
61
- score
38
+ @terms.sort_by{|t| t[:score]}.reverse
39
+ end
40
+
41
+ def collect_madlibs
42
+ @madlibs = @madlibs.downcase.split(' ').uniq.sort_by{rand}.join(' ').capitalize
62
43
  end
63
44
 
64
45
  end
65
46
 
47
+ require 'linguine/scores'
data/linguine.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "linguine"
6
+ s.version = '0.0.4'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Daniel Owen van Dommelen"]
9
+ s.email = ["bunny.rabbit@igotish.com"]
10
+ s.homepage = "http://rubygems.org/gems/linguine"
11
+ s.summary = ""
12
+ s.description = ""
13
+
14
+ s.rubyforge_project = "linguine"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linguine do
4
+
5
+ it 'should initialize' do
6
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
7
+ end
8
+
9
+ it 'should have a list of common words' do
10
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
11
+ @linguine.common_words.should_not be_empty
12
+ end
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linguine do
4
+
5
+ context 'madlibs' do
6
+
7
+ it 'should return a shuffled version' do
8
+ text = 'This is my text. There are many like it, but this one is mine.'
9
+ @linguine = Linguine.new(:rough, text)
10
+ @linguine.madlibs.should_not == text
11
+ end
12
+
13
+ it 'should capitalize the sentence' do
14
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
15
+ @linguine.madlibs[0].should == @linguine.madlibs[0].capitalize
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'linguine'
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linguine do
4
+
5
+ context 'collect terms' do
6
+
7
+ it 'should return a value' do
8
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
9
+ @linguine.terms.should_not be_empty
10
+ end
11
+
12
+ it 'should return a sorted list of terms' do
13
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
14
+ @linguine.terms.first.should == {word: 'This', score: 7}
15
+ end
16
+
17
+ it 'should return a unique list of terms' do
18
+ @linguine = Linguine.new(:rough, 'This is my text. There are many like it, but this one is mine.')
19
+ @linguine.terms.should == @linguine.terms.uniq
20
+ end
21
+
22
+ it 'should no add common words to the terms' do
23
+ @linguine = Linguine.new(:rough, 'war')
24
+ puts @linguine.terms
25
+ @linguine.terms.should be_empty
26
+ end
27
+
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linguine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,15 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-11 00:00:00.000000000Z
12
+ date: 2012-08-23 00:00:00.000000000Z
13
13
  dependencies: []
14
- description: Language
15
- email: bunny.rabbit@igotish.com
14
+ description: ''
15
+ email:
16
+ - bunny.rabbit@igotish.com
16
17
  executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - README.md
24
+ - common_words_en.txt
20
25
  - lib/linguine.rb
26
+ - lib/linguine/scores.rb
27
+ - linguine.gemspec
28
+ - spec/linguine_spec.rb
29
+ - spec/madlibs_spec.rb
30
+ - spec/spec_helper.rb
31
+ - spec/terms_spec.rb
21
32
  homepage: http://rubygems.org/gems/linguine
22
33
  licenses: []
23
34
  post_install_message:
@@ -37,9 +48,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
48
  - !ruby/object:Gem::Version
38
49
  version: '0'
39
50
  requirements: []
40
- rubyforge_project:
51
+ rubyforge_project: linguine
41
52
  rubygems_version: 1.8.10
42
53
  signing_key:
43
54
  specification_version: 3
44
- summary: Language
45
- test_files: []
55
+ summary: ''
56
+ test_files:
57
+ - spec/linguine_spec.rb
58
+ - spec/madlibs_spec.rb
59
+ - spec/spec_helper.rb
60
+ - spec/terms_spec.rb