A chatbot trained on Jedi wisdom, this is. Given a question, it finds the most relevant answer with the force. Blah blah blah
library(ggplot2)
library(plotly)
library(dplyr)
library(readr)
library(stringdist)
Input
input_data <- read_lines("input.txt")
head(input_data)
## [1] "Fear leads to anger" "Anger leads to hate"
## [3] "Hate leads to suffering" "Patience you must have"
## [5] "The greatest teacher, failure is" "Pass on what you have learned"
length(input_data)
## [1] 82
response
response_data <- read_lines("response.txt")
head(response_data)
## [1] "Anger leads to hate"
## [2] "Hate leads to suffering"
## [3] "The dark side that is."
## [4] "Train yourself to let go of everything you fear to lose."
## [5] "The greatest teacher, failure is."
## [6] "Jedi must share knowledge."
length(response_data)
## [1] 82
Ensure 1 input to 1 response
if (length(input_data) != length(response_data)) {
stop("Dark side lurks: input and response must have the same number of lines.")
}
yeoda_quotes <- tibble(
input = input_data,
response = response_data
)
head(yeoda_quotes)
## # A tibble: 6 × 2
## input response
## <chr> <chr>
## 1 Fear leads to anger Anger leads to hate
## 2 Anger leads to hate Hate leads to suffering
## 3 Hate leads to suffering The dark side that is.
## 4 Patience you must have Train yourself to let go of everything you f…
## 5 The greatest teacher, failure is The greatest teacher, failure is.
## 6 Pass on what you have learned Jedi must share knowledge.
wisdom_plot <- ggplot(yeoda_quotes, aes(x = input, y = response)) +
geom_point(color = "green", size = 4) +
labs(title = "Wisdom Map",
x = "Jedi Question",
y = "yeoda’s Response") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
plotly::ggplotly(wisdom_plot)