ruby_rhymes 0.1.1 → 0.1.2

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.md CHANGED
@@ -1,20 +1,18 @@
1
1
  # RubyRhymes
2
- RubyRhymes is a gem quite sublime
3
- for poets who haven't much time
4
- you provide it a string
5
- then it does its own thing
6
- and returns a number of rhymes
7
-
8
2
  RubyRhymes is a gem that makes auto-generating terrible poetry a breeze. You use it roughly like so:
9
3
 
10
4
  >> "RubyGems... is a gem quite sublime!".to_phrase.flat_rhymes
11
5
  => ["anticrime", "beim", "chime", "climb", "clime", "crime", ...]
12
6
 
7
+ ## Recent Changes
8
+ - Added `.last_word` to get the word in the phrase that was used for rhyming
9
+
13
10
  ## Requirements
14
11
  Tested with Ruby 1.8.7
15
12
 
16
13
  ## Installation
17
- TODO
14
+
15
+ gem install ruby_rhymes
18
16
 
19
17
  ## Usage
20
18
  The easiest thing to do is embrace the String abuse:
@@ -55,7 +53,7 @@ If you're not afraid of multiple pronunciations, you can call `.rhymes` instead
55
53
 
56
54
  ## Props
57
55
 
58
- - [Thomas](https://github.com/thomas-kielbus, "github"), the co-author extraordinaire
56
+ - [Thomas](https://github.com/thomas-kielbus "github"), the co-author extraordinaire and Andre, my muse
59
57
  - The dictionaries, which is really what matters, came from [Brian Langenberger](http://rhyme.sourceforge.net/index.html "Rhyme Dictionary"), whose work was based on a [CMU Pronouncing Dictionary](http://www.speech.cs.cmu.edu/cgi-bin/cmudict CMU Dictionary).
60
58
  - The syllable counter for words that aren't in the dictionary comes from the source made available by [Russell McVeigh](http://www.russellmcveigh.info/content/html/syllablecounter.php "PHP Syllable Counter"). I just ported the PHP.
61
59
 
@@ -65,6 +63,8 @@ In essence we have three dictionaries available
65
63
  - _multiple.txt_ : Word to pronunciation-encoding (ex. TOMATO => TOMATO TOMATO(2))
66
64
  - _words.txt_ : Pronunciation-encoding to syllable rhyme key and syllable count (ex. TOMATO => \2R 3)
67
65
  - _rhymes.txt_ : Rhyme-key to pronunciation-encodings of words that rhyme with it (ex. \2R => POTATO SAITO TOMATO)
68
- from here on, it's fairly intuative what needs to be done. `multiple.txt` is only has keys when the word actually has multiple pronunciations, so _CAT_ will yield nothing there, meaning we can continue to to check in `words.txt`.
69
66
 
70
- ## TODO
67
+ from here on, it's fairly intuitive what needs to be done. `multiple.txt` is only has keys when the word actually has multiple pronunciations, so _CAT_ will yield nothing there, meaning we can continue to check in `words.txt`.
68
+
69
+ ## TODO
70
+ - treat numbers with respect
@@ -0,0 +1,641 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: Phrase
8
+
9
+ &mdash; Documentation by YARD 0.7.2
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="_index.html">Index (P)</a> &raquo;
37
+
38
+
39
+ <span class="title">Phrase</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Class: Phrase
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+ <dt class="r1">Inherits:</dt>
68
+ <dd class="r1">
69
+ <span class="inheritName">Object</span>
70
+
71
+ <ul class="fullTree">
72
+ <li>Object</li>
73
+
74
+ <li class="next">Phrase</li>
75
+
76
+ </ul>
77
+ <a href="#" class="inheritanceTree">show all</a>
78
+
79
+ </dd>
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ <dt class="r2 last">Defined in:</dt>
90
+ <dd class="r2 last">lib/ruby_rhymes.rb<span class="defines">,<br />
91
+ lib/syllable_arrays.rb</span>
92
+ </dd>
93
+
94
+ </dl>
95
+ <div class="clear"></div>
96
+
97
+ <h2>Overview</h2><div class="docstring">
98
+ <div class="discussion">
99
+ <p>
100
+ this class is the gateway to generating exciting poetry. Use it like this:
101
+ </p>
102
+ <p>
103
+ &gt;&gt; phrase = &quot;to be or not to beer&quot;.to_phrase &gt;&gt;
104
+ phrase.flat_rhymes
105
+ </p>
106
+ <h1>&gt; [&quot;adhere&quot;, &quot;alvear&quot;, &quot;amir&quot;, &#8230;]</h1>
107
+ <p>
108
+ &gt;&gt; &quot;to be or not to beer&quot;.to_phrase.syllables
109
+ </p>
110
+ <h1>&gt; 6</h1>
111
+
112
+
113
+ </div>
114
+ </div>
115
+ <div class="tags">
116
+
117
+ </div><h2>Defined Under Namespace</h2>
118
+ <p class="children">
119
+
120
+
121
+
122
+
123
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Phrase/Pronunciation.html" title="Phrase::Pronunciation (class)">Pronunciation</a></span>, <span class='object_link'><a href="Phrase/Pronunciations.html" title="Phrase::Pronunciations (class)">Pronunciations</a></span>
124
+
125
+
126
+ </p>
127
+
128
+
129
+
130
+
131
+
132
+
133
+ <h2>
134
+ Instance Method Summary
135
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
136
+ </h2>
137
+
138
+ <ul class="summary">
139
+
140
+ <li class="public ">
141
+ <span class="summary_signature">
142
+
143
+ <a href="#dict%3F-instance_method" title="#dict? (instance method)">- (Boolean) <strong>dict?</strong> </a>
144
+
145
+
146
+
147
+ </span>
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+ <span class="summary_desc"><div class='inline'><p>
157
+ returns whether the last word in the phrase a dictionary word (useful to
158
+ know before calling rhymes and rhyme_keys).
159
+ </p>
160
+ </div></span>
161
+
162
+ </li>
163
+
164
+
165
+ <li class="public ">
166
+ <span class="summary_signature">
167
+
168
+ <a href="#flat_rhymes-instance_method" title="#flat_rhymes (instance method)">- (Object) <strong>flat_rhymes</strong> </a>
169
+
170
+
171
+
172
+ </span>
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+ <span class="summary_desc"><div class='inline'><p>
182
+ return a flat array of rhymes, rather than by pronunciation.
183
+ </p>
184
+ </div></span>
185
+
186
+ </li>
187
+
188
+
189
+ <li class="public ">
190
+ <span class="summary_signature">
191
+
192
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (Phrase) <strong>initialize</strong>(phrase) </a>
193
+
194
+
195
+
196
+ </span>
197
+
198
+ <span class="note title constructor">constructor</span>
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ <span class="summary_desc"><div class='inline'><p>
208
+ A new instance of Phrase.
209
+ </p>
210
+ </div></span>
211
+
212
+ </li>
213
+
214
+
215
+ <li class="public ">
216
+ <span class="summary_signature">
217
+
218
+ <a href="#rhyme_key-instance_method" title="#rhyme_key (instance method)">- (Object) <strong>rhyme_key</strong> </a>
219
+
220
+
221
+
222
+ </span>
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+ <span class="summary_desc"><div class='inline'><p>
232
+ returns the first rhyme key or nil.
233
+ </p>
234
+ </div></span>
235
+
236
+ </li>
237
+
238
+
239
+ <li class="public ">
240
+ <span class="summary_signature">
241
+
242
+ <a href="#rhyme_keys-instance_method" title="#rhyme_keys (instance method)">- (Object) <strong>rhyme_keys</strong> </a>
243
+
244
+
245
+
246
+ </span>
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+ <span class="summary_desc"><div class='inline'><p>
256
+ returns the rhyme keys associated with this word (useful in matching with
257
+ other words to see if they rhyme).
258
+ </p>
259
+ </div></span>
260
+
261
+ </li>
262
+
263
+
264
+ <li class="public ">
265
+ <span class="summary_signature">
266
+
267
+ <a href="#rhymes-instance_method" title="#rhymes (instance method)">- (Object) <strong>rhymes</strong> </a>
268
+
269
+
270
+
271
+ </span>
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+ <span class="summary_desc"><div class='inline'><p>
281
+ returns a map from rhyme key to a list of rhyming words in that key.
282
+ </p>
283
+ </div></span>
284
+
285
+ </li>
286
+
287
+
288
+ <li class="public ">
289
+ <span class="summary_signature">
290
+
291
+ <a href="#syllables-instance_method" title="#syllables (instance method)">- (Object) <strong>syllables</strong> </a>
292
+
293
+
294
+
295
+ </span>
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+ <span class="summary_desc"><div class='inline'><p>
305
+ returns the number of syllables in the phrase.
306
+ </p>
307
+ </div></span>
308
+
309
+ </li>
310
+
311
+
312
+ </ul>
313
+
314
+
315
+ <div id="constructor_details" class="method_details_list">
316
+ <h2>Constructor Details</h2>
317
+
318
+ <div class="method_details first">
319
+ <p class="signature first" id="initialize-instance_method">
320
+
321
+ - (<tt><span class='object_link'><a href="" title="Phrase (class)">Phrase</a></span></tt>) <strong>initialize</strong>(phrase)
322
+
323
+
324
+
325
+ </p><div class="docstring">
326
+ <div class="discussion">
327
+ <p>
328
+ A new instance of Phrase
329
+ </p>
330
+
331
+
332
+ </div>
333
+ </div>
334
+ <div class="tags">
335
+
336
+ </div><table class="source_code">
337
+ <tr>
338
+ <td>
339
+ <pre class="lines">
340
+
341
+
342
+ 14
343
+ 15
344
+ 16
345
+ 17
346
+ 18
347
+ 19
348
+ 20</pre>
349
+ </td>
350
+ <td>
351
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 14</span>
352
+
353
+ <span class='def def kw'>def</span> <span class='initialize identifier id'>initialize</span><span class='lparen token'>(</span><span class='phrase identifier id'>phrase</span><span class='rparen token'>)</span>
354
+ <span class='@phrase_tokens ivar id'>@phrase_tokens</span> <span class='assign token'>=</span> <span class='Phrase constant id'>Phrase</span><span class='dot token'>.</span><span class='clean_and_tokenize identifier id'>clean_and_tokenize</span><span class='lparen token'>(</span><span class='phrase identifier id'>phrase</span><span class='rparen token'>)</span>
355
+
356
+ <span class='comment val'># [[p1a,p1b],[p2],p3]</span>
357
+ <span class='@pronunciations ivar id'>@pronunciations</span> <span class='assign token'>=</span> <span class='@phrase_tokens ivar id'>@phrase_tokens</span><span class='dot token'>.</span><span class='map identifier id'>map</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='pt identifier id'>pt</span><span class='bitor op'>|</span> <span class='Pronunciations constant id'>Pronunciations</span><span class='dot token'>.</span><span class='get_pronunciations identifier id'>get_pronunciations</span><span class='lparen token'>(</span><span class='pt identifier id'>pt</span><span class='rparen token'>)</span><span class='rbrace token'>}</span> <span class='comment val'>#pronunciation objects</span>
358
+ <span class='@last_word_pronunciation ivar id'>@last_word_pronunciation</span> <span class='assign token'>=</span> <span class='@pronunciations ivar id'>@pronunciations</span><span class='dot token'>.</span><span class='last identifier id'>last</span>
359
+ <span class='end end kw'>end</span>
360
+ </pre>
361
+ </td>
362
+ </tr>
363
+ </table>
364
+ </div>
365
+
366
+ </div>
367
+
368
+
369
+ <div id="instance_method_details" class="method_details_list">
370
+ <h2>Instance Method Details</h2>
371
+
372
+
373
+ <div class="method_details first">
374
+ <p class="signature first" id="dict?-instance_method">
375
+
376
+ - (<tt>Boolean</tt>) <strong>dict?</strong>
377
+
378
+
379
+
380
+ </p><div class="docstring">
381
+ <div class="discussion">
382
+ <p>
383
+ returns whether the last word in the phrase a dictionary word (useful to
384
+ know before calling rhymes and rhyme_keys)
385
+ </p>
386
+
387
+
388
+ </div>
389
+ </div>
390
+ <div class="tags">
391
+ <h3>Returns:</h3>
392
+ <ul class="return">
393
+
394
+ <li>
395
+
396
+
397
+ <span class='type'>(<tt>Boolean</tt>)</span>
398
+
399
+
400
+
401
+ </li>
402
+
403
+ </ul>
404
+
405
+ </div><table class="source_code">
406
+ <tr>
407
+ <td>
408
+ <pre class="lines">
409
+
410
+
411
+ 38
412
+ 39
413
+ 40</pre>
414
+ </td>
415
+ <td>
416
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 38</span>
417
+
418
+ <span class='def def kw'>def</span> <span class='dict? fid id'>dict?</span>
419
+ <span class='@last_word_pronunciation ivar id'>@last_word_pronunciation</span><span class='dot token'>.</span><span class='first identifier id'>first</span><span class='dot token'>.</span><span class='dict? fid id'>dict?</span>
420
+ <span class='end end kw'>end</span>
421
+ </pre>
422
+ </td>
423
+ </tr>
424
+ </table>
425
+ </div>
426
+
427
+ <div class="method_details ">
428
+ <p class="signature " id="flat_rhymes-instance_method">
429
+
430
+ - (<tt>Object</tt>) <strong>flat_rhymes</strong>
431
+
432
+
433
+
434
+ </p><div class="docstring">
435
+ <div class="discussion">
436
+ <p>
437
+ return a flat array of rhymes, rather than by pronunciation
438
+ </p>
439
+
440
+
441
+ </div>
442
+ </div>
443
+ <div class="tags">
444
+
445
+ </div><table class="source_code">
446
+ <tr>
447
+ <td>
448
+ <pre class="lines">
449
+
450
+
451
+ 49
452
+ 50
453
+ 51</pre>
454
+ </td>
455
+ <td>
456
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 49</span>
457
+
458
+ <span class='def def kw'>def</span> <span class='flat_rhymes identifier id'>flat_rhymes</span>
459
+ <span class='rhymes identifier id'>rhymes</span><span class='dot token'>.</span><span class='empty? fid id'>empty?</span> <span class='integer val'>? </span><span class='lbrack token'>[</span><span class='rbrack token'>]</span> <span class='colon op'>:</span> <span class='@rhymes ivar id'>@rhymes</span><span class='dot token'>.</span><span class='values identifier id'>values</span><span class='dot token'>.</span><span class='flatten identifier id'>flatten</span>
460
+ <span class='end end kw'>end</span>
461
+ </pre>
462
+ </td>
463
+ </tr>
464
+ </table>
465
+ </div>
466
+
467
+ <div class="method_details ">
468
+ <p class="signature " id="rhyme_key-instance_method">
469
+
470
+ - (<tt>Object</tt>) <strong>rhyme_key</strong>
471
+
472
+
473
+
474
+ </p><div class="docstring">
475
+ <div class="discussion">
476
+ <p>
477
+ returns the first rhyme key or nil
478
+ </p>
479
+
480
+
481
+ </div>
482
+ </div>
483
+ <div class="tags">
484
+
485
+ </div><table class="source_code">
486
+ <tr>
487
+ <td>
488
+ <pre class="lines">
489
+
490
+
491
+ 28
492
+ 29
493
+ 30</pre>
494
+ </td>
495
+ <td>
496
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 28</span>
497
+
498
+ <span class='def def kw'>def</span> <span class='rhyme_key identifier id'>rhyme_key</span>
499
+ <span class='rhyme_keys identifier id'>rhyme_keys</span><span class='dot token'>.</span><span class='first identifier id'>first</span>
500
+ <span class='end end kw'>end</span>
501
+ </pre>
502
+ </td>
503
+ </tr>
504
+ </table>
505
+ </div>
506
+
507
+ <div class="method_details ">
508
+ <p class="signature " id="rhyme_keys-instance_method">
509
+
510
+ - (<tt>Object</tt>) <strong>rhyme_keys</strong>
511
+
512
+
513
+
514
+ </p><div class="docstring">
515
+ <div class="discussion">
516
+ <p>
517
+ returns the rhyme keys associated with this word (useful in matching with
518
+ other words to see if they rhyme)
519
+ </p>
520
+
521
+
522
+ </div>
523
+ </div>
524
+ <div class="tags">
525
+
526
+ </div><table class="source_code">
527
+ <tr>
528
+ <td>
529
+ <pre class="lines">
530
+
531
+
532
+ 23
533
+ 24
534
+ 25</pre>
535
+ </td>
536
+ <td>
537
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 23</span>
538
+
539
+ <span class='def def kw'>def</span> <span class='rhyme_keys identifier id'>rhyme_keys</span>
540
+ <span class='@last_word_pronunciation ivar id'>@last_word_pronunciation</span><span class='dot token'>.</span><span class='map identifier id'>map</span><span class='lparen token'>(</span><span class='bitand op'>&amp;</span><span class='symbol val'>:rhyme_key</span><span class='rparen token'>)</span><span class='dot token'>.</span><span class='compact identifier id'>compact</span><span class='orop op'>||</span><span class='lbrack token'>[</span><span class='rbrack token'>]</span>
541
+ <span class='end end kw'>end</span>
542
+ </pre>
543
+ </td>
544
+ </tr>
545
+ </table>
546
+ </div>
547
+
548
+ <div class="method_details ">
549
+ <p class="signature " id="rhymes-instance_method">
550
+
551
+ - (<tt>Object</tt>) <strong>rhymes</strong>
552
+
553
+
554
+
555
+ </p><div class="docstring">
556
+ <div class="discussion">
557
+ <p>
558
+ returns a map from rhyme key to a list of rhyming words in that key
559
+ </p>
560
+
561
+
562
+ </div>
563
+ </div>
564
+ <div class="tags">
565
+
566
+ </div><table class="source_code">
567
+ <tr>
568
+ <td>
569
+ <pre class="lines">
570
+
571
+
572
+ 43
573
+ 44
574
+ 45
575
+ 46</pre>
576
+ </td>
577
+ <td>
578
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 43</span>
579
+
580
+ <span class='def def kw'>def</span> <span class='rhymes identifier id'>rhymes</span>
581
+ <span class='@rhymes ivar id'>@rhymes</span> <span class='assign token'>=</span> <span class='load_rhymes identifier id'>load_rhymes</span> <span class='if if_mod kw'>if</span> <span class='@rhymes ivar id'>@rhymes</span><span class='dot token'>.</span><span class='nil? fid id'>nil?</span>
582
+ <span class='@rhymes ivar id'>@rhymes</span>
583
+ <span class='end end kw'>end</span>
584
+ </pre>
585
+ </td>
586
+ </tr>
587
+ </table>
588
+ </div>
589
+
590
+ <div class="method_details ">
591
+ <p class="signature " id="syllables-instance_method">
592
+
593
+ - (<tt>Object</tt>) <strong>syllables</strong>
594
+
595
+
596
+
597
+ </p><div class="docstring">
598
+ <div class="discussion">
599
+ <p>
600
+ returns the number of syllables in the phrase
601
+ </p>
602
+
603
+
604
+ </div>
605
+ </div>
606
+ <div class="tags">
607
+
608
+ </div><table class="source_code">
609
+ <tr>
610
+ <td>
611
+ <pre class="lines">
612
+
613
+
614
+ 33
615
+ 34
616
+ 35</pre>
617
+ </td>
618
+ <td>
619
+ <pre class="code"><span class="info file"># File 'lib/ruby_rhymes.rb', line 33</span>
620
+
621
+ <span class='def def kw'>def</span> <span class='syllables identifier id'>syllables</span>
622
+ <span class='@pronunciations ivar id'>@pronunciations</span><span class='dot token'>.</span><span class='map identifier id'>map</span><span class='lbrace token'>{</span><span class='bitor op'>|</span><span class='p identifier id'>p</span><span class='bitor op'>|</span> <span class='p identifier id'>p</span><span class='dot token'>.</span><span class='first identifier id'>first</span><span class='dot token'>.</span><span class='num_syllables identifier id'>num_syllables</span><span class='rbrace token'>}</span><span class='dot token'>.</span><span class='inject identifier id'>inject</span><span class='lparen token'>(</span><span class='symbol val'>:+</span><span class='rparen token'>)</span>
623
+ <span class='end end kw'>end</span>
624
+ </pre>
625
+ </td>
626
+ </tr>
627
+ </table>
628
+ </div>
629
+
630
+ </div>
631
+
632
+ </div>
633
+
634
+ <div id="footer">
635
+ Generated on Tue Oct 11 20:47:07 2011 by
636
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
637
+ 0.7.2 (ruby-1.8.7).
638
+ </div>
639
+
640
+ </body>
641
+ </html>