Hello! Why are you here?
Oh, I though so. You are here for a Rust program to generate some random phrases based on books you feed it but it actually does something you did not expect it to.
😬
Well, I dunno. You:
- Give it a list of books,
- Generate a graph of words,
- Enter interactive mode,
- Click enter till it generates a funny enough phrase that you send it to your friends thinking you are funny while they start to question your friendship.
Start off by compiling the source. While in src folder, use either cargo build
or cargo build --release
if you want it to be faster (you probably want that option ngl).
After it all compiles, copy libraries.json file from root into the same directory that your compiled program is in. It will not work without it. So based on what you did, you either have to run these from the root dir:
cp src/libraries.josn target/debug/libraries.json
or
cp src/libraries.josn target/release/libraries.json
After it's compiled, you want to start up the compiled program from the console. So do that.
Immediately you will see a console list of stuff you can do in it. there is a default library with URLs already so I can show you what to do to start it up:
:build_graph
- this will download files from the links in the library and save them in a folder to later read from (or load them if they are already downloaded). After that, it builds a graph of words. This can take some time on debug, probably faster on release version.
:interactive
- enter interactive mode. Here you eiter click enter to submit an empty string (program picks a starting word at random) or put in one word and click enter to generate a sentence starting with that word.
Is it fun yet??
Let me show you how you would usually go about creating your own library and managing URLs in it 🫡
We will create a library called gibberish and put a few books in it, then use that to generate our phrases.
- Run
:print_libraries
- you can see there is one default library with 3 URLs from project Gutenberg. We will be using books from their site because they are free and it's the only thing that I wanted to use - Run
:add_library gibberish
- this will add an empty library. Verify that by running:print_libraries
again - Run
:set_library gibberish
- you will see that on the top of the options you see ---CONSOLE OPTIONS "gibberish"/Not loaded)--- instead of ---CONSOLE OPTIONS "default"/Not loaded)---. You have changed the default library you are using, letsgoooo! - Run
:add_url https://www.gutenberg.org/files/2701/2701-h/2701-h.htm
- adds new URL to the library you are using. Verify that by running:print_libraries
- Run
:add_url https://www.gutenberg.org/files/37392/37392-h/37392-h.htm
- adds another URL to the library - Run
:add_url https://www.gutenberg.org/files/17476/17476-h/17476-h.htm
- adds the last URL we wnted - Run
:print_libraries
- see your changes - Run
:fetch_data
- loads text from URLs, processes them and saves into a file - Run
:build_graph
- build a graph of words to use. At the end of this, you should see ---CONSOLE OPTIONS "gibberish"/Loaded)---, indicating that the graph is loaded and ready to use - Run
:interactive
- let it speak gibberish by pressing enter. You could also type indick
and see what it tells you since we had Moby Dick in the list of books. Hah, so funny! 🥳🥳👏🍆
Here are some of the things I got:
Equipped salesman to spend too great it is its sum of that not a coffin, mr.
Chestnuts, nor will here& ldquo; it oddly dashed.
Dick not only be a duel.
So first of all, not all of the options are yet available, but all that I listed above work. Removing libraries and URLs also works, so you can use that too.
Good question fam! Let me show you 👩💻
- Go to https://www.gutenberg.org/ebooks/search/?sort_order=random and pick or find a book
- Once you find a book, click on it, you will see a list of sources to choose from. This is important - Click on the Read this book online: HTML (as submitted)
- Copy the link form the page, for me it looks like that: https://www.gutenberg.org/files/50309/50309-h/50309-h.htm
- Paste it into
:add_url
to add it to a library - Done
Idk and idk. This project is used for me to learn Rust. It's poorly written, you will probably encounter bugs or it will just crash if you give it something I havent mention in this readme.
If you have an idea about some new features, you can start a discusson. I will not be accepting PRs, just because.
This will also probably add weird HTML characters to your output if source had some images or non-english letters but it just adds that shitpost flavour to it so yeah, it is a feature,not a bug.
Thank you to Project Gutenberg for providing a list of books in HTML5 that I can process for free, they are the real OGs.
Bye! 🎉