library(dplyr)
library(markovifyR)
library(furrr)
library(knitr)
library(gridExtra)



tidy_anime <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-04-23/tidy_anime.csv")

text <- tidy_anime %>% select(title_english, genre) %>%
  filter(genre == "Action", !is.na(title_english)) %>%
  distinct() %>%
  pull(title_english)

markov_model3 <-
  generate_markovify_model(
    input_text = text,
    markov_state_size = 2L,
    max_overlap_total = 15,
    max_overlap_ratio = .3)

markov_model5<-
  generate_markovify_model(
    input_text = text,
    markov_state_size = 2L,
    max_overlap_total = 15,
    max_overlap_ratio = .5)

markov_model8<-
  generate_markovify_model(
    input_text = text,
    markov_state_size = 2L,
    max_overlap_total = 15,
    max_overlap_ratio = .8)

x3<-markovify_text(
  markov_model = markov_model3,
  count = 100,
  maximum_sentence_length = 1500L,
  output_column_name = 'AnimeTitle_3',
  tries = 100,
  only_distinct = TRUE,
  return_message = TRUE
)

x5<-markovify_text(
  markov_model = markov_model5,
  count = 100,
  maximum_sentence_length = 1500L,
  output_column_name = 'AnimeTitle_5',
  tries = 100,
  only_distinct = TRUE,
  return_message = TRUE
)

x8<-markovify_text(
  markov_model = markov_model8,
  count = 100,
  maximum_sentence_length = 1500L,
  output_column_name = 'AnimeTitle_8',
  tries = 100,
  only_distinct = TRUE,
  return_message = TRUE
)
x3_p<-x3 %>% slice(1:20)
knitr::kable(x5 %>% slice(1:20))
idRow AnimeTitle_5
1 Magi: Adventure of Dai!
2 Pokemon the Movie: Fade to Black
3 The Fleet of the Legendary Heroes
4 The Last: Naruto the Movie 2 -Bonds-
5 A Certain Magical Index the Movie: Decisive Battle!
6 Utawarerumono: The False Songstress
7 Land of the Phantom
8 Fist of the Dead
9 Sakura Wars: School of the Heroic Knight
10 Arpeggio of Blue Water - The Wyvern Arrives
11 Berserk: The Golden Age Arc I - The Laughing Man
12 The Irregular at Magic High School DxD BorN
13 Fafner of the Evils
14 Sakura Wars: School of the End: Vampire Reign
15 Sword Art Online the Movie 2: Confront
16 Horizon in the Sky
17 X - The Torn-Up Wyvern Picture Drama
18 Naruto: Shippuden the Movie 2: The Castle of Cagliostro
19 Valkisas:The Wings of the Dragon Kings
20 The Rising of the Stars II
knitr::kable(x8 %>% slice(1:20))
idRow AnimeTitle_8
1 The Last: Naruto the Movie 3: Guardians of the Heroes: Trails in the Big City
2 Nura: Rise of the Divine Demon
3 Cross Ange: Rondo of Princesses
4 Star Blazers: Space Battleship Yamato: In the Name of Love
5 Berserk: The Golden Age Arc III - The Egg of the Re’Union
6 Seven Senses of the End: The Beginning of the King
7 Moribito - Guardian of Darkness
8 Fafner of the World
9 Nura: Rise of Technovore
10 Dragon Ball: Curse of the Heroes: Trails in the Shell 2.0
11 Crest of the Super Fighter
12 Original Dirty Pair: Project Eden
13 Persona 3 the Movie: The Power of Us
14 Riddle Story of Chinese Gods
15 Godzilla: Planet of the North Star 2
16 Sanko and the Jewel of Life
17 Road to Ninja: Naruto the Movie 3: Swords of an Honorable Ruler
18 Last Exile: Fam, the Silver Moon
19 City Hunter: The Secret of the Super Galaxy
20 Seven Senses of the Blue Sky