** CHALLENGE: Simple almost human speakbot ** | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

** CHALLENGE: Simple almost human speakbot **

The goal of the challenge is to use the 500 first lines of http://www.gutenberg.org/cache/epub/1952/pg1952.txt to build a "Markov table" ( containing how many times any word was followed by any of its potential "following words"). Dot "." need to be considered as a word). This table can be quite big so you need to think about the right way to do it. Once you have this table you can generate almost human sentences : start with a dot, print randomly a following word & iterate. Make the best looking code !

27th Aug 2017, 5:16 PM
VcC
VcC - avatar
32 Answers
+ 1
New version that can run on Sololearn Code Playground (doesn't pull text from Project Gutenberg directly): https://code.sololearn.com/c80p4MH1NdIm/?ref=app
28th Aug 2017, 7:08 PM
André
André - avatar
+ 1
nice, this did reminds my hinter editor https://code.sololearn.com/WoUjEYWDOir8/?ref=app I'll research about for give a try :)
27th Aug 2017, 7:20 PM
ysraelcon
ysraelcon - avatar
+ 1
I will need my word extractor :) https://code.sololearn.com/WqtvZsVN8AUH/?ref=app
27th Aug 2017, 10:40 PM
ysraelcon
ysraelcon - avatar
+ 1
https://code.sololearn.com/cMvAGN9YGqj6/?ref=app gave it a limit so it wont get stuck in a loop
27th Aug 2017, 10:54 PM
Izi Lior Katie
Izi Lior Katie - avatar
+ 1
mine, I also give a limit because words by itself don't get stop unless it has more words so one stablish when occurrence 1. I like this bot :) note: I know it isn't the best looking code 😁 https://code.sololearn.com/WaFXqRzaA6aw/?ref=app
28th Aug 2017, 1:50 AM
ysraelcon
ysraelcon - avatar
+ 1
Wow ... like the challenge!!! I'll give it a try! BTW: BE AWARE of using the link (gutenberg.org) for URL opening if you're not a US-citizen! They block your IP and might charge you for it (due to copyrights). (at least that's what they wrote on their home-page) I'm not from US therefore I just copied the text into my source-code!
28th Aug 2017, 6:29 AM
Julian Fechner
Julian Fechner - avatar
+ 1
Andre wins this one. Very concise code and not so many Rubystes here ;-)
28th Aug 2017, 7:54 PM
VcC
VcC - avatar
0
ya but in here...in python sololearn dnt support urllib.request... max limit exceeded....
27th Aug 2017, 5:37 PM
sayan chandra
sayan chandra - avatar
0
eh, for example: "hello world! hello world." if I start with hello, the probability of the follower be "world" is 1, and now with world the probability of the follower be "!" is 0.5 and be "." 0.5. . so we have to do something as it for every word ?
27th Aug 2017, 8:42 PM
ysraelcon
ysraelcon - avatar
0
My response in Ruby: https://code.sololearn.com/cFZ3aQKjcJrS/?ref=app As a warning, it DOES NOT work in Sololearn's Code Playground - the script will need to be copy-and-pasted and tried on a computer running Ruby. It takes the first 500 lines directly from the Project Gutenberg website, and Sololearn denies the permission to access the site from Code Playground. It is a base 1 Markov model. The output text is sometimes accidentally almost poetic. Some examples: Great makes by as bushes convolutions -- but undertaking I. No my stimulating to baby a long, and greater before fancy. It can kept you tell and shapes dear much figure, or weir. Old-paper wall-somersault just not I.
28th Aug 2017, 6:31 PM
André
André - avatar
0
@VcC re: "Can you put the first line directly in a variable so that we can test it ?" Sorry, not sure what you mean - the first line requiring the 'open-uri' module? I can make a second version that has the text as a variable instead of accessing it directly from the page if that's what you mean - give me a minute, it will just (unfortunately) no longer be only 26 lines or so of actual code :)
28th Aug 2017, 6:53 PM
André
André - avatar
28th Aug 2017, 7:58 PM
VcC
VcC - avatar
0
راسل
1st Sep 2017, 7:23 PM
‎محمود ابوزيدجظظظ‎
‎محمود ابوزيدجظظظ‎ - avatar
0
ؤاسلثا
1st Sep 2017, 7:23 PM
‎محمود ابوزيدجظظظ‎
‎محمود ابوزيدجظظظ‎ - avatar
0
يرسبسزبةزقظل
1st Sep 2017, 7:23 PM
‎محمود ابوزيدجظظظ‎
‎محمود ابوزيدجظظظ‎ - avatar
0
ؤرسبى
1st Sep 2017, 7:23 PM
‎محمود ابوزيدجظظظ‎
‎محمود ابوزيدجظظظ‎ - avatar
- 1
how many times a word was followed by any of its potential "followimg words"... please explain i didnt get...
27th Aug 2017, 5:31 PM
sayan chandra
sayan chandra - avatar
- 1
Your markov chain tells you for each word in the original text what the possible followers are and the number for each. Using this you can pick a follower for any word. If you start with . (dot), pick a follower, the a follower's follower and so on your program will generate an almost human looking sentence ! You can feed this programm with any base ( could be the Us president's tweets or a programmers joke database). Good challenge to practice URL opening and file analysis....
27th Aug 2017, 5:35 PM
VcC
VcC - avatar
- 1
Indeed urllib does not work... Ok i'll accept answers puting the 500 lines in a variable ! For non python you can use url related functions ( google them)
27th Aug 2017, 5:41 PM
VcC
VcC - avatar
- 1
just copied that string😂😂😂😂
27th Aug 2017, 5:47 PM
sayan chandra
sayan chandra - avatar