This R script provides a helper function to take a dataframe, and build a proper
rasa NLU training file in JSON format. This would be helpful for when you want to:
- export records from a database
- import the training data file into the webapp found here: https://rasahq.github.io/rasa-nlu-trainer/
- tag your data with the tool and export
- re-import the JSON into R and associate with the database ID
Export data in an order that we can match back to our original file. This is not shown, but the order is preserved so it's just a matter of aligning the data once it is tagged from the webapp and read in from the JSON file.
Build a dataset and write a JSON data file that can imported into https://rasahq.github.io/rasa-nlu-trainer/
dat = data.frame(id = 1:3, text = c("test 1", "i like turtles", "where are you"))
write_rasa_nlu(dat)
From here, tag your data and read back into R and align the records 1:1. Typically, you would save out the raw file, and correlate the tagged data from above with each row of that raw file.
## bring in the data trained from the webapp
x = fromJSON("~/Downloads/2018-07-train.json", flatten = TRUE)
y = x$rasa_nlu_data$common_examples
glimpse(y)
Which assumes above that you exported the JSON file from rasa-nlu-trainer to your default downloads directory on your local machine.
and merge
z = y %>% rename(text2 = text)
msgs = cbind(dat, z)
glimpse(msgs)