markovifyR
: R wrapper for Markovify
Ref: https://github.com/jsvine/markovify
"Markovify is a simple, extensible Markov chain generator. Right now, its main use is for building Markov models of large corpora of text, and generating random sentences from that."
This package requires Python and markovify to be installed.
To install markovify in R you can run:
system("pip install markovify")
The following functions are implemented:
generate_markovify_model:
Generates a markov modelmarkovify_text
: Generates text from a markov modelgenerate_sentence_starting_with
: Generates text, if possible, with your specified start wordgenerate_start_words
: Produces a data frame with the starting words for each input sentencedevtools::install_github("abresler/markovifyR")
options(width=120)
library(markovifyR) library(dplyr)
Here we are going to showcase how to use the package to create new Life Lessons from my favorite professor from college Peter Linneman.
data("linneman_lessons") lessons <- linneman_lessons %>% pull(textLesson) lessons %>% str()
markov_model <- generate_markovify_model( input_text = lessons, markov_state_size = 2L, max_overlap_total = 25, max_overlap_ratio = .85 )
markovify_text( markov_model = markov_model, maximum_sentence_length = NULL, output_column_name = 'textLinnemanBot', count = 25, tries = 100, only_distinct = TRUE, return_message = TRUE )
Generate random sentence starting with.
markovify_text( markov_model = markov_model, maximum_sentence_length = NULL, start_words = c("The", "You", "Life"), output_column_name = 'textLinnemanBot', count = 25, tries = 100, only_distinct = TRUE, return_message = TRUE )
Look at corpus start-words
generate_start_words(markov_model = markov_model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.