On 08/04/06, Meinrad Recheis <meinrad.recheis / gmail.com> wrote:
> On 4/8/06, Matthew Moss <matthew.moss.coder / gmail.com> wrote:
> > I went and grabbed a bunch of Grimm's fairy tales from Gutenberg.  I
> > still need to tweak my algorithm some; the most annoying thing I find
> > is punctuation, especially quoted strings (i.e. speech) so that the
> > output text looks like there is some valid speech in there and not
> > just randomly scattered quote marks.
> >
> > Anyway, here's a sample I produced with my first attempt:
> >
> > There was a man who kills seven at one blow? I leapt over the tree
> > because the huntsmen are shooting down there in the closet on the
> > porch.' The miller said: 'The Devil must go out,' and opened the door
> > and opened it. As she went in, a little dwarf no bigger than my
> > finger. And before her stood princes, and dukes, and earls: and the
> > fisherman went up to her palace all of shining gold; and told her
> > mother that she must be the handsomest lady in the land; and she went
> > to the fire and growled contentedly and comfortably. It was not long
> > in saying 'Yes' to all this; and as they were entering the village,
> > the son followed the fox's counsel, and without looking about him went
> > to the other anvil. The old man led him back into the water. The girls
> > came just in time; they held him fast and tried to free his beard from
> > the line, but all in vain; he heard or saw nothing of Jorinda. At last
> > he thought to himself: 'How the old woman is snoring! I must just see
> > if she wants anything.'
> >
> >
> > and:
> >
> > An aged count once lived in Switzerland, who had an only son, but he
> > was now grown too old to work; so the farmer would give him his only
> > daughter to her bed-side, and said, 'Always be a good girl, and I will
> > never by myself leave the path, to run into the wood, till at last
> > they danced out at the gate together. When they had walked a short
> > time, when they had warmed themselves, they said: 'Comrade, shall we
> > have a child, and he grows big, and we send him into the wide world,
> > and looked neither to the right place. There they found the giants
> > swimming in their blood, and all round about her, and the bells rang
> > at each step which she took. Then she was in a great hurry. The little
> > tailor looked round and saw a flock of sheep, the very shepherd whom
> > the peasant knew had long been wishing to be mayor, so he cried with
> > all his might.
> >
> >
> how did you manage to get complete sentences?
>
>

For sentences, I picked words until it started with a [A-Z], then
printed subsequent words until it ended with [?!.]

Using KJV Bible with verse numbers removed:

irb(main):001:0> load 'markov.rb'
=> true
irb(main):002:0> m = Markov.new('../etext/kjv10x.txt')
irb(main):003:0> m.print_sentences 4
Mehujael begat Anub, and taught his house. And in the wheat into the
field for my fury upon the Red sea. Nevertheless what I judge the
people shall turn to his clothes. And a great and he hath cast far
off.
=> nil
irb(main):004:0> m.print_sentences 1
Which, when the kingdom for meat, and he had indignation against thy
land, the violent man.
=> nil