gabbler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .rvmrc
@@ -0,0 +1,2 @@
1
+ 0.1.0
2
+ - Initial Release.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gabbler (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.6.0)
11
+ rspec-core (~> 2.6.0)
12
+ rspec-expectations (~> 2.6.0)
13
+ rspec-mocks (~> 2.6.0)
14
+ rspec-core (2.6.0)
15
+ rspec-expectations (2.6.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.6.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ gabbler!
24
+ rspec (>= 2.6.0)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Michael Dvorkin
2
+ twitter.com/mid
3
+ %w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ ## Gabbler ##
2
+ Gabbler is a Ruby library that generates pseudo-random phrases. Any coherent
3
+ text file with adequate number of sentences could serve as Gabbler's training
4
+ set. Once trained, Gabbler produces pseudo-random sentences based on the
5
+ original text.
6
+
7
+ ### Installation ###
8
+ # Installing as Ruby gem
9
+ $ gem install gabbler
10
+
11
+ # Cloning the repository
12
+ $ git clone git://github.com/michaeldv/gabbler.git
13
+
14
+ ### Usage Example ###
15
+
16
+ $ cat > holmes.rb
17
+ require "gabbler" # Require the gem.
18
+ gabbler = Gabbler.new # Create new Gabbler instance.
19
+ story = File.read("./sample/holmes.txt") # Read first chapter of 'A study in Scarlet'.
20
+ gabbler.learn(story) # Make Gabbler learn about Sherlock Holmes.
21
+ 10.times { puts gabbler.sentence } # Generate ten pseudo-rando sentences.
22
+ gabbler.unlearn! # Forget Sherlock Holmes.
23
+ gabbler.learn(story.reverse) # Teach Gabbler about semloH kcolrehS.
24
+ puts gabbler.sentence # .dezama eB
25
+ ^D
26
+ $ ruby holmes.rb
27
+ This is very piquant.
28
+ You perceive that the resulting mixture has the appearance of pure water.
29
+ How on earth did you know that?
30
+ If you like, we shall drive round together after luncheon.
31
+ Now we have the Sherlock Holmes' test, and there will no longer be any difficulty.
32
+ I followed, however, with many other officers who were in the enemy's country.
33
+ This was a lofty chamber, lined and littered with countless bottles.
34
+ My companion smiled an enigmatical smile.
35
+ Did you never ask him what he was going in for?
36
+ So is the microscopic examination for blood corpuscles.
37
+ senil esoht no repap a trats thgim uoY.
38
+
39
+ ### Running Specs ###
40
+
41
+ $ gem install rspec # RSpec 2.x is the requirement.
42
+ $ rake spec # Run the entire spec suite.
43
+
44
+ ### Note on Patches/Pull Requests ###
45
+ * Fork the project on Github.
46
+ * Make your feature addition or bug fix.
47
+ * Add specs for it, making sure $ rake spec is all green.
48
+ * Commit, do not mess with Rakefile, version, or history.
49
+ * Send me a pull request.
50
+
51
+ ### License ###
52
+
53
+ Copyright (c) 2011 Michael Dvorkin
54
+ twitter.com/mid
55
+ %w(mike dvorkin.net) * "@" || %w(mike fatfreecrm.com) * "@"
56
+ Released under the MIT license. See LICENSE file for details.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2011 Michael Dvorkin
2
+ #
3
+ # Gabbler is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ require File.dirname(__FILE__) + '/gabbler/generator'
7
+ require File.dirname(__FILE__) + '/gabbler/version'
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2011 Michael Dvorkin
2
+ #
3
+ # Gabbler is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ unless [].respond_to?(:sample)
7
+ class Array
8
+ def sample # Comes with Ruby 1.9+
9
+ self[rand(size)]
10
+ end
11
+ end
12
+ end
13
+
14
+ class Gabbler
15
+ def initialize(options = {})
16
+ @depth = options[:depth] || 2
17
+ unlearn!
18
+ end
19
+
20
+ # Split text into sentences and add them all to the dictionary.
21
+ #----------------------------------------------------------------------------
22
+ def learn(text)
23
+ text.split(/([.!?])/).each_slice(2) do |sentence, terminator|
24
+ add_to_dictionary(sentence, terminator || '.')
25
+ end
26
+ end
27
+
28
+ # Reset internal data in case one needs to re-learn new training set.
29
+ #----------------------------------------------------------------------------
30
+ def unlearn!
31
+ @dictionary, @start = {}, []
32
+ end
33
+
34
+ # Generate one pseudo-random sentence.
35
+ #----------------------------------------------------------------------------
36
+ def sentence
37
+ words = @start.sample # Pick random word, then keep appending connected words.
38
+ while next_word = next_word_for(words[-@depth, @depth])
39
+ words << next_word
40
+ end
41
+ words[0..-2].join(" ") + words.last # Format the sentence.
42
+ end
43
+
44
+ private
45
+
46
+ # Add given sentence to the dictionary.
47
+ #----------------------------------------------------------------------------
48
+ def add_to_dictionary(sentence, terminator)
49
+ words = sentence.scan(/[\w',-]+/) # Split sentence to words.
50
+ if words.size > @depth # Go on if the sentence is long enogh.
51
+ words << terminator # Treat sentence terminator as another word.
52
+ @start << words[0, @depth] # This becomes another starting point.
53
+ words.size.times do |i|
54
+ sequence = words[i, @depth + 1]
55
+ if sequence.size == @depth + 1 # Full sequence?
56
+ @dictionary[sequence[0, @depth]] ||= []
57
+ @dictionary[sequence[0, @depth]] << sequence[-1]
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ # Return random connected word or nil if there is none.
64
+ #----------------------------------------------------------------------------
65
+ def next_word_for(words)
66
+ @dictionary[words].sample if @dictionary[words]
67
+ end
68
+ end
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2011 Michael Dvorkin
2
+ #
3
+ # Gabbler is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ class Gabbler
7
+ def self.version
8
+ '0.1.0'
9
+ end
10
+ end
@@ -0,0 +1,144 @@
1
+ Sir Arthur Conan Doyle: A Study in Scarlet.
2
+
3
+ In the year 1878 I took my degree of Doctor of Medicine of the University of London, and proceeded to Netley to go through the course prescribed for
4
+ surgeons in the army. Having completed my studies there, I was duly attached to the Fifth Northumberland Fusiliers as Assistant Surgeon. The
5
+ regiment was stationed in India at the time, and before I could join it, the second Afghan war had broken out. On landing at Bombay, I learned that
6
+ my corps had advanced through the passes, and was already deep in the enemy's country. I followed, however, with many other officers who were in the
7
+ same situation as myself, and succeeded in reaching Candahar in safety, where I found my regiment, and at once entered upon my new duties.
8
+
9
+ The campaign brought honours and promotion to many, but for me it had nothing but misfortune and disaster. I was removed from my brigade and attached to the Berkshires, with whom I served at the fatal battle of Maiwand. There I was struck on the shoulder by a Jezail bullet, which shattered the bone and grazed the subclavian artery. I should have fallen into the hands of the murderous Ghazis had it not been for the devotion and courage shown by Murray, my orderly, who threw me across a pack-horse, and succeeded in bringing me safely to the British lines.
10
+
11
+ Worn with pain, and weak from the prolonged hardships which I had undergone, I was removed, with a great train of wounded sufferers, to the base hospital at Peshawar. Here I rallied, and had already improved so far as to be able to walk about the wards, and even to bask a little upon the verandah, when I was struck down by enteric fever, that curse of our Indian possessions. For months my life was despaired of, and when at last I came to myself and became convalescent, I was so weak and emaciated that a medical board determined that not a day should be lost in sending me back to England. I was dispatched, accordingly, in the troopship "Orontes," and landed a month later on Portsmouth jetty, with my health irretrievably ruined, but with permission from a paternal government to spend the next nine months in attempting to improve it.
12
+
13
+ I had neither kith nor kin in England, and was therefore as free as air -- or as free as an income of eleven shillings and sixpence a day will permit a man to be. Under such circumstances, I naturally gravitated to London, that great cesspool into which all the loungers and idlers of the Empire are irresistibly drained. There I stayed for some time at a private hotel in the Strand, leading a comfortless, meaningless existence, and spending such money as I had, considerably more freely than I ought. So alarming did the state of my finances become, that I soon realized that I must either leave the metropolis and rusticate somewhere in the country, or that I must make a complete alteration in my style of living. Choosing the latter alternative, I began by making up my mind to leave the hotel, and to take up my quarters in some less pretentious and less expensive domicile.
14
+
15
+ On the very day that I had come to this conclusion, I was standing at the Criterion Bar, when some one tapped me on the shoulder, and turning round I recognized young Stamford, who had been a dresser under me at Barts. The sight of a friendly face in the great wilderness of London is a pleasant thing indeed to a lonely man. In old days Stamford had never been a particular crony of mine, but now I hailed him with enthusiasm, and he, in his turn, appeared to be delighted to see me. In the exuberance of my joy, I asked him to lunch with me at the Holborn, and we started off together in a hansom.
16
+
17
+ "Whatever have you been doing with yourself, Watson?" he asked in undisguised wonder, as we rattled through the crowded London streets. "You are as thin as a lath and as brown as a nut."
18
+
19
+ I gave him a short sketch of my adventures, and had hardly concluded it by the time that we reached our destination.
20
+
21
+ "Poor devil!" he said, commiseratingly, after he had listened to my misfortunes. "What are you up to now?"
22
+
23
+ "Looking for lodgings," I answered. "Trying to solve the problem as to whether it is possible to get comfortable rooms at a reasonable price."
24
+
25
+ "That's a strange thing," remarked my companion; "you are the second man to-day that has used that expression to me."
26
+
27
+ "And who was the first?" I asked.
28
+
29
+ "A fellow who is working at the chemical laboratory up at the hospital. He was bemoaning himself this morning because he could not get someone to go halves with him in some nice rooms which he had found, and which were too much for his purse."
30
+
31
+ "By Jove!" I cried, "if he really wants someone to share the rooms and the expense, I am the very man for him. I should prefer having a partner to being alone."
32
+
33
+ Young Stamford looked rather strangely at me over his wine-glass. "You don't know Sherlock Holmes yet," he said; "perhaps you would not care for him as a constant companion."
34
+
35
+ "Why, what is there against him?"
36
+
37
+ "Oh, I didn't say there was anything against him. He is a little queer in his ideas -- an enthusiast in some branches of science. As far as I know he is a decent fellow enough."
38
+
39
+ "A medical student, I suppose?" said I.
40
+
41
+ "No -- I have no idea what he intends to go in for. I believe he is well up in anatomy, and he is a first-class chemist; but, as far as I know, he has never taken out any systematic medical classes. His studies are very desultory and eccentric, but he has amassed a lot of out-of-the way knowledge which would astonish his professors."
42
+
43
+ "Did you never ask him what he was going in for?" I asked.
44
+
45
+ "No; he is not a man that it is easy to draw out, though he can be communicative enough when the fancy seizes him."
46
+
47
+ "I should like to meet him," I said. "If I am to lodge with anyone, I should prefer a man of studious and quiet habits. I am not strong enough yet to stand much noise or excitement. I had enough of both in Afghanistan to last me for the remainder of my natural existence. How could I meet this friend of yours?"
48
+
49
+ "He is sure to be at the laboratory," returned my companion. "He either avoids the place for weeks, or else he works there from morning to night. If you like, we shall drive round together after luncheon."
50
+
51
+ "Certainly," I answered, and the conversation drifted away into other channels.
52
+
53
+ As we made our way to the hospital after leaving the Holborn, Stamford gave me a few more particulars about the gentleman whom I proposed to take as a fellow-lodger.
54
+
55
+ "You mustn't blame me if you don't get on with him," he said; "I know nothing more of him than I have learned from meeting him occasionally in the laboratory. You proposed this arrangement, so you must not hold me responsible."
56
+
57
+ "If we don't get on it will be easy to part company," I answered. "It seems to me, Stamford," I added, looking hard at my companion, "that you have some reason for washing your hands of the matter. Is this fellow's temper so formidable, or what is it? Don't be mealy-mouthed about it."
58
+
59
+ "It is not easy to express the inexpressible," he answered with a laugh. "Holmes is a little too scientific for my tastes -- it approaches to cold-bloodedness. I could imagine his giving a friend a little pinch of the latest vegetable alkaloid, not out of malevolence, you understand, but simply out of a spirit of inquiry in order to have an accurate idea of the effects. To do him justice, I think that he would take it himself with the same readiness. He appears to have a passion for definite and exact knowledge."
60
+
61
+ "Very right too."
62
+
63
+ "Yes, but it may be pushed to excess. When it comes to beating the subjects in the dissecting-rooms with a stick, it is certainly taking rather a bizarre shape."
64
+
65
+ "Beating the subjects!"
66
+
67
+ "Yes, to verify how far bruises may be produced after death. I saw him at it with my own eyes."
68
+
69
+ "And yet you say he is not a medical student?"
70
+
71
+ "No. Heaven knows what the objects of his studies are. But here we are, and you must form your own impressions about him." As he spoke, we turned down a narrow lane and passed through a small side-door, which opened into a wing of the great hospital. It was familiar ground to me, and I needed no guiding as we ascended the bleak stone staircase and made our way down the long corridor with its vista of whitewashed wall and dun-coloured doors. Near the further end a low arched passage branched away from it and led to the chemical laboratory.
72
+
73
+ This was a lofty chamber, lined and littered with countless bottles. Broad, low tables were scattered about, which bristled with retorts, test-tubes, and little Bunsen lamps, with their blue flickering flames. There was only one student in the room, who was bending over a distant table absorbed in his work. At the sound of our steps he glanced round and sprang to his feet with a cry of pleasure. "I've found it! I've found it," he shouted to my companion, running towards us with a test-tube in his hand. "I have found a re-agent which is precipitated by haemoglobin, and by nothing else." Had he discovered a gold mine, greater delight could not have shone upon his features.
74
+
75
+ "Dr. Watson, Mr. Sherlock Holmes," said Stamford, introducing us.
76
+
77
+ "How are you?" he said cordially, gripping my hand with a strength for which I should hardly have given him credit. "You have been in Afghanistan, I perceive."
78
+
79
+ "How on earth did you know that?" I asked in astonishment.
80
+
81
+ "Never mind," said he, chuckling to himself. "The question now is about hoemoglobin. No doubt you see the significance of this discovery of mine?"
82
+
83
+ "It is interesting, chemically, no doubt," I answered, "but practically ----"
84
+
85
+ "Why, man, it is the most practical medico-legal discovery for years. Don't you see that it gives us an infallible test for blood stains. Come over here now!" He seized me by the coat-sleeve in his eagerness, and drew me over to the table at which he had been working. "Let us have some fresh blood," he said, digging a long bodkin into his finger, and drawing off the resulting drop of blood in a chemical pipette. "Now, I add this small quantity of blood to a litre of water. You perceive that the resulting mixture has the appearance of pure water. The proportion of blood cannot be more than one in a million. I have no doubt, however, that we shall be able to obtain the characteristic reaction." As he spoke, he threw into the vessel a few white crystals, and then added some drops of a transparent fluid. In an instant the contents assumed a dull mahogany colour, and a brownish dust was precipitated to the bottom of the glass jar.
86
+
87
+ "Ha! ha!" he cried, clapping his hands, and looking as delighted as a child with a new toy. "What do you think of that?"
88
+
89
+ "It seems to be a very delicate test," I remarked.
90
+
91
+ "Beautiful! beautiful! The old Guiacum test was very clumsy and uncertain. So is the microscopic examination for blood corpuscles. The latter is valueless if the stains are a few hours old. Now, this appears to act as well whether the blood is old or new. Had this test been invented, there are hundreds of men now walking the earth who would long ago have paid the penalty of their crimes."
92
+
93
+ "Indeed!" I murmured.
94
+
95
+ "Criminal cases are continually hinging upon that one point. A man is suspected of a crime months perhaps after it has been committed. His linen or clothes are examined, and brownish stains discovered upon them. Are they blood stains, or mud stains, or rust stains, or fruit stains, or what are they? That is a question which has puzzled many an expert, and why? Because there was no reliable test. Now we have the Sherlock Holmes' test, and there will no longer be any difficulty."
96
+
97
+
98
+ His eyes fairly glittered as he spoke, and he put his hand over his heart and bowed as if to some applauding crowd conjured up by his imagination.
99
+
100
+ "You are to be congratulated," I remarked, considerably surprised at his enthusiasm.
101
+
102
+ "There was the case of Von Bischoff at Frankfort last year. He would certainly have been hung had this test been in existence. Then there was Mason of Bradford, and the notorious Muller, and Lefevre of Montpellier, and Samson of new Orleans. I could name a score of cases in which it would have been decisive."
103
+
104
+ "You seem to be a walking calendar of crime," said Stamford with a laugh. "You might start a paper on those lines. Call it the `Police News of the Past.'"
105
+
106
+ "Very interesting reading it might be made, too," remarked Sherlock Holmes, sticking a small piece of plaster over the prick on his finger. "I have to be careful," he continued, turning to me with a smile, "for I dabble with poisons a good deal." He held out his hand as he spoke, and I noticed that it was all mottled over with similar pieces of plaster, and discoloured with strong acids.
107
+
108
+ "We came here on business," said Stamford, sitting down on a high three-legged stool, and pushing another one in my direction with his foot. "My friend here wants to take diggings, and as you were complaining that you could get no one to go halves with you, I thought that I had better bring you together."
109
+
110
+ Sherlock Holmes seemed delighted at the idea of sharing his rooms with me. "I have my eye on a suite in Baker Street," he said, "which would suit us down to the ground. You don't mind the smell of strong tobacco, I hope?"
111
+
112
+ "I always smoke `ship's' myself," I answered.
113
+
114
+ "That's good enough. I generally have chemicals about, and occasionally do experiments. Would that annoy you?"
115
+
116
+ "By no means."
117
+
118
+ "Let me see -- what are my other shortcomings. I get in the dumps at times, and don't open my mouth for days on end. You must not think I am sulky when I do that. Just let me alone, and I'll soon be right. What have you to confess now? It's just as well for two fellows to know the worst of one another before they begin to live together."
119
+
120
+ I laughed at this cross-examination. "I keep a bull pup," I said, "and I object to rows because my nerves are shaken, and I get up at all sorts of ungodly hours, and I am extremely lazy. I have another set of vices when I'm well, but those are the principal ones at present."
121
+
122
+ "Do you include violin-playing in your category of rows?" he asked, anxiously.
123
+
124
+ "It depends on the player," I answered. "A well-played violin is a treat for the gods -- a badly-played one ----"
125
+
126
+ "Oh, that's all right," he cried, with a merry laugh. "I think we may consider the thing as settled -- that is, if the rooms are agreeable to you."
127
+
128
+ "When shall we see them?"
129
+
130
+ "Call for me here at noon to-morrow, and we'll go together and settle everything," he answered.
131
+
132
+ "All right -- noon exactly," said I, shaking his hand.
133
+
134
+ We left him working among his chemicals, and we walked together towards my hotel.
135
+
136
+ "By the way," I asked suddenly, stopping and turning upon Stamford, "how the deuce did he know that I had come from Afghanistan?"
137
+
138
+ My companion smiled an enigmatical smile. "That's just his little peculiarity," he said. "A good many people have wanted to know how he finds things out."
139
+
140
+ "Oh! a mystery is it?" I cried, rubbing my hands. "This is very piquant. I am much obliged to you for bringing us together. `The proper study of mankind is man,' you know."
141
+
142
+ "You must study him, then," Stamford said, as he bade me good-bye. "You'll find him a knotty problem, though. I'll wager he learns more about you than you about him. Good-bye."
143
+
144
+ "Good-bye," I answered, and strolled on to my hotel, considerably interested in my new acquaintance.
@@ -0,0 +1,62 @@
1
+ # Copyright (c) 2011 Michael Dvorkin
2
+ #
3
+ # Gabbler is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
7
+
8
+ describe "Testing Gabbler" do
9
+ it "should generate a sentence" do
10
+ gabbler = Gabbler.new
11
+ gabbler.learn('The quick brown fox jumps over the lazy dog.')
12
+ gabbler.sentence.should == 'The quick brown fox jumps over the lazy dog.'
13
+ end
14
+
15
+ it "should create the dictionary" do
16
+ gabbler = Gabbler.new
17
+ gabbler.learn('The quick brown fox jumps over the lazy dog. The quick red fox? The quick red fox runs!')
18
+ dictionary = gabbler.instance_variable_get("@dictionary")
19
+
20
+ dictionary.keys.size.should == 11
21
+ dictionary.keys.should include [ "The", "quick" ] # 1st sentence.
22
+ dictionary.keys.should include [ "quick", "brown" ]
23
+ dictionary.keys.should include [ "brown", "fox" ]
24
+ dictionary.keys.should include [ "fox", "jumps" ]
25
+ dictionary.keys.should include [ "jumps", "over" ]
26
+ dictionary.keys.should include [ "over", "the" ]
27
+ dictionary.keys.should include [ "the", "lazy" ]
28
+ dictionary.keys.should include [ "lazy", "dog" ]
29
+ dictionary.keys.should include [ "quick", "red" ] # 2nd sentence
30
+ dictionary.keys.should include [ "red", "fox" ]
31
+ dictionary.keys.should include [ "fox", "runs" ] # 3rd sentence
32
+
33
+ dictionary[[ "The", "quick" ]].should == [ "brown", "red", "red" ]
34
+ dictionary[[ "brown", "fox" ]].should == [ "jumps" ]
35
+ dictionary[[ "fox", "jumps" ]].should == [ "over" ]
36
+ dictionary[[ "jumps", "over" ]].should == [ "the" ]
37
+ dictionary[[ "lazy", "dog" ]].should == [ "." ]
38
+ dictionary[[ "over", "the" ]].should == [ "lazy" ]
39
+ dictionary[[ "quick", "brown" ]].should == [ "fox" ]
40
+ dictionary[[ "the", "lazy" ]].should == [ "dog" ]
41
+ dictionary[[ "quick", "red" ]].should == [ "fox", "fox" ]
42
+ dictionary[[ "red", "fox" ]].should == [ "?", "runs" ]
43
+ dictionary[[ "fox", "runs" ]].should == [ "!" ]
44
+ end
45
+
46
+ it "should note start of sentences" do
47
+ gabbler = Gabbler.new
48
+ gabbler.learn('The quick brown fox jumps over the lazy dog. Lorem ipsum dolor sit ame? Proin aliquet metus eu tellus!')
49
+
50
+ start = gabbler.instance_variable_get("@start")
51
+ start.should == [ %w(The quick), %w(Lorem ipsum), %w(Proin aliquet) ]
52
+ end
53
+
54
+ it "should be able to unlearn" do
55
+ gabbler = Gabbler.new
56
+ gabbler.learn('The quick brown fox jumps over the lazy dog.')
57
+ gabbler.unlearn!
58
+
59
+ gabbler.instance_variable_get("@dictionary").should == {}
60
+ gabbler.instance_variable_get("@start").should == []
61
+ end
62
+ end
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2011 Michael Dvorkin
2
+ #
3
+ # Gabbler is freely distributable under the terms of MIT license.
4
+ # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
5
+ #------------------------------------------------------------------------------
6
+ $:.unshift(File.dirname(__FILE__))
7
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'gabbler'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gabbler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Dvorkin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70340235923700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.6.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70340235923700
25
+ description: Generate pseudo-random phrases using Markov chains
26
+ email: mike@dvorkin.net
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - CHANGELOG
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - LICENSE
35
+ - Rakefile
36
+ - README.md
37
+ - lib/gabbler/generator.rb
38
+ - lib/gabbler/version.rb
39
+ - lib/gabbler.rb
40
+ - sample/holmes.txt
41
+ - spec/gabbler_spec.rb
42
+ - spec/spec_helper.rb
43
+ - .gitignore
44
+ homepage: http://github.com/michaeldv/gabbler
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: gabbler
64
+ rubygems_version: 1.8.11
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Generate pseudo-random phrases using Markov chains
68
+ test_files:
69
+ - spec/gabbler_spec.rb
70
+ - spec/spec_helper.rb