TheGreatRambler / markov.js

Just another Markov chain library.

Home Page:http://thegreatrambler.com/code-demos/markov/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

markov.js

Just another Markov chain library. Check out my demo to experiment with it.

API

var markovinstance = new Markov({
  input: "What ever string or array you want... I don't care.",
  regularity: 1
});

Pretty simple, just create a new instance. The input is either an array of elements or a sentence, I don't care. The regularity controls how similar the generated sentences are to the target sentences.

Methods

generate

markovinstance.generate(1000);

Just generate a string. If you want an array, just .split() it. I literally don't care. The only argument is the length. Either it will generate a string that length, or it will generate till it stops. In fact, you dont have to include the argument. I... definitely don't care.

Sample 1

A quality story based off of Alice in Wonderland.

shouted the Queen in front of the house, and wondering what to do next, when suddenly a footman in livery came running out of the water, and seemed to quiver all over with diamonds, and walked two and two, as the soldiers did. After these came the royal children; there were ten of them, and the little golden key and hurried off to the garden door. Poor Alice! It was as much as she could guess, she was now about two feet high, and was going off into a doze; but, on being pinched by the Hatter, it woke up again with a little house in it about four feet high. ‘Whoever lives there,’ thought Alice, ‘it’ll never do to come upon them this size: why, I should frighten them out of their wits!’ So she began again: ‘Ou est ma chatte?’ which was the first sentence in her French lesson-book. The Mouse gave a sudden leap out of the room. The cook threw a frying-pan after her as she spoke. ‘I must go and get ready to play croquet with the Queen,’ and she hurried out of the wood—(she considered him to be a letter, written by the prisoner to—to somebody.’ ‘It must have been that,’ said the Cat, and vanished again. Alice waited a little, half expecting to see it pop down a large rabbit-hole under the hedge. In another moment down went Alice after it, never once considering how in the world am I? Ah, that’s the great puzzle!’ And she began thinking over other children she knew, who might do very well as pigs, and was just in time to avoid shrinking away altogether. ‘That was a narrow escape!’ said Alice, a little timidly, ‘why you are painting those roses?’ Five and Seven said nothing, but looked at Two. Two began in a great hurry. An enormous puppy was looking down at her feet, they seemed to be no chance of this, so she began very cautiously: ‘But I don’t understand. Where did they draw the treacle from?’ ‘You can draw water out of a sea of green leaves that lay far below her. ‘What can all that green stuff be?’ said Alice. ‘And where have my shoulders got to? And oh, my poor hands, how is it I can’t see you?’ She was moving them about as she spoke, but no result seemed to follow, except a little shaking among the distant green leaves. As there seemed to be talking in his sleep, ‘that “I breathe when I sleep” is the same thing as “I eat what I see”!’ ‘You might just as well say,’ added the Dormouse, who seemed to be in a very humble tone, going down on one knee as he spoke, ‘we were trying—’ ‘I see!’ said the Queen, turning purple. ‘I won’t!’ said Alice. ‘Off with her head!’ Those whom she sentenced were taken into custody by the soldiers, who of course had to leave off this minute!’ She generally gave herself very good advice, (though she very seldom followed it), and sometimes she scolded herself so severely as to bring tears into her eyes; and once she remembered trying to box her own ears for having cheated herself in a long, low hall, which was lit up by a row of lamps hanging from the roof. There were doors all round the table, but there was nothing on it except a tiny golden key, and unlocking the door that led into the garden. Then she went to work nibbling at the mushroom (she had kept a piece of it in her pocket) till she was about a foot high: then she walked up towards it rather timidly, saying to herself ‘That’s quite enough—I hope I shan’t grow any more—As it is, I can’t get out at the door—I do wish I hadn’t gone down that rabbit-hole—and yet—and yet—it’s rather curious, you know, this sort of life! I do wonder what can have happened to me! When I used to know. Let me see: I’ll give them a new pair of boots every Christmas.’ And she went on planning to herself how she would gather about her other little children, and make their eyes bright and eager with many a strange tale, perhaps even with the dream of Wonderland of long ago: and how she would manage it. ‘They must go by the carrier,’ she thought; ‘and how funny it’ll seem, sending presents to one’s own feet! And how odd the directions will look!

Sample 2

Another tale based on Alice in Wonderland

CHAPTER III. A Caucus-Race and a Long Tale

They were indeed a queer-looking party that assembled on the bank—the birds with draggled feathers, the animals with their fur clinging close to them, and was delighted to find that she remained the same size: to be sure, she had not as yet had any dispute with the Queen, but she knew that were of the same age as herself, to see if she meant to take the hint; but the cook was busily stirring the soup, and seemed not to be otherwise than what you had been would have appeared to them to be otherwise.”’ ‘I think I should understand that better,’ Alice said very politely, ‘if I had it written down: but I can’t quite follow it as you say it.’ ‘That’s nothing to what I could say if I chose,’ the Duchess replied, in a pleased tone. ‘Pray don’t trouble yourself to say it out loud. ‘Thinking again?’ the Duchess asked, with another dig of her sharp little chin into Alice’s shoulder as she added, ‘and the moral of that is—“The more there is of yours.”’ ‘Oh, I know!’ exclaimed Alice, who had not attended to this last remark, ‘it’s a vegetable. It doesn’t look like one, but it is.’ ‘I quite agree with you,’ said the Duchess; ‘and most of ‘em do.’ ‘I don’t know of any that do,’ Alice said very politely, feeling quite pleased to find that she knew the name of nearly everything there. ‘That’s the judge,’ she said to herself as she ran. ‘How surprised he’ll be when he finds out who I am! But I’d better take him his fan and gloves—that is, if I can find them.’ As she said this, she came upon a neat little house, on the door of which was a bright brass plate with the name ‘W. RABBIT’ engraved upon it. She went in without knocking, and hurried upstairs, in great fear lest she should meet the real Mary Ann, and be turned out of the wood to listen. The Fish-Footman began by producing from under his arm a great letter, nearly as large as the Rabbit, and had no reason to be afraid of them!’ ‘And who are these?’ said the Queen, ‘and he shall tell you his history,’ As they walked off together, Alice heard the Rabbit say, ‘A barrowful will do, to begin with.’ ‘A barrowful of what?’ thought Alice; but she had read about them in books, and she was quite tired and out of breath, and said ‘That’s very curious.’ ‘It’s all about as curious as it can be,’ said the Mock Turtle. ‘Certainly not!’ said Alice indignantly. ‘Ah! then yours wasn’t a really good school,’ said the Mock Turtle to sing you a song?’ ‘Oh, a song, please, if the Mock Turtle in a tone of great curiosity. ‘Soles and eels, of course,’ the Gryphon replied rather impatiently: ‘any shrimp could have told you that.’ ‘If I’d been the whiting,’ said Alice, whose thoughts were still running on the song, ‘I’d have said to the jury, who instantly made a memorandum of the fact. ‘I keep them to sell,’ the Hatter added as an explanation; ‘I’ve none of my own. I’m a hatter.’ Here the Queen put on her spectacles, and began staring at the Hatter, who turned pale and fidgeted. ‘Give your evidence,’ said the King. ‘Shan’t,’ said the cook. The King looked anxiously at the White Rabbit, ‘but it seems to be a person of authority among them, called out, ‘Sit down, all of you, and listen to me! I’ll soon make you dry enough!’ They all sat down at once, in a large ring, with the Mouse in the middle. Alice kept her eyes anxiously fixed on it, for she felt very lonely and low-spirited. In a little while, however, she again heard a little shriek and a fall, and a crash of broken glass, from which she concluded that it was quite out of breath, and said ‘That’s very curious.’ ‘It’s all about as curious as it can be,’ said the Mock Turtle: ‘nine the next, and so on.’ ‘What a curious plan!’ exclaimed Alice. ‘That’s the reason they’re called lessons,’ the Gryphon interrupted in a very short time the Queen was in a furious passion, and went stamping about, and shouting ‘Off with his head!’ she said, without even looking round. ‘I’ll fetch the executioner myself,’ said the King triumphantly, pointing to the three gardeners who were lying round the rosetree; for, you see, as they were lying on their faces, and the pattern on their backs was the same as they used to say.’ ‘So he did, so he did,’ said the Mouse. ‘—I proceed. “Edwin and Morcar, the earls of Mercia and Northumbria—“’ ‘Ugh!’ said the Lory, with a shiver. ‘I beg your pardon!’ cried Alice again, for this time the Mouse was speaking, so that her idea of the tale was something like this:—

Notes

  • This was intended to be used for a different project, so all the references to music in the source code is just for that

License

It's the MIT. You wan't to know what it says? It says I dont care whether you sell it or copy it. Do what you want. Teach you cats about this code if you want. In fact, you should write the next Harry Potter with this library. Just do it.

About

Just another Markov chain library.

http://thegreatrambler.com/code-demos/markov/index.html

License:MIT License


Languages

Language:JavaScript 100.0%