+ 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 !
32 Réponses
+ 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
+ 1
nice, this did reminds my hinter editor https://code.sololearn.com/WoUjEYWDOir8/?ref=app
I'll research about for give a try :)
+ 1
I will need my word extractor :) https://code.sololearn.com/WqtvZsVN8AUH/?ref=app
+ 1
https://code.sololearn.com/cMvAGN9YGqj6/?ref=app gave it a limit so it wont get stuck in a loop
+ 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
+ 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!
+ 1
Andre wins this one. Very concise code and not so many Rubystes here ;-)
0
ya but in here...in python
sololearn dnt support urllib.request...
max limit exceeded....
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 ?
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.
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 :)
0
Here is my version - php.
https://code.sololearn.com/wmE1uVRK3Eqq/?ref=app
0
راسل
0
ؤاسلثا
0
يرسبسزبةزقظل
0
ؤرسبى
- 1
how many times a word was followed by any of its potential "followimg words"...
please explain i didnt get...
- 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....
- 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)
- 1
just copied that string😂😂😂😂