Natural language flows
A very simple prototype of Natural Language Flow builder and Natural Language Generator for bots, using edges of contexts, and based on intents/skills defined by the user.
Installation
npm install natural-language-flows
How it works
// Require the natural language flowsvar nlf = ; // Initialize the botvar bot = ; // Set a default non matched replybotNonMatchedReply = "Sorry, I do not understand..."; // Add some bot's skills/intents with edges of contextsbot;
Start a discussion with the bot after skills' training:
// Printing the full discussion's objectsesit = bot;console; esit = bot;console; esit = bot;console; esit = bot;console;
That will print the complete result object in this way:
text: 'I want to buy a ferrari' intent: true entities: action: 'buy' product: 'ferrari' reply: 'Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)' context: 'car-model' text: 'GTC4' intent: true entities: model: 'GTC4' reply: 'Oh, great! Do you confirm you want to purchase it? (yes/no)' context: 'car-yes-no' text: 'Maybe...' intent: null entities: {} reply: 'Sorry, I do not understand...' context: 'car-yes-no' text: 'yes' intent: true entities: qresp: 'yes' reply: 'Wonderful! A great purchase!' context: 'buy-car'
To print only the discussion data:
// Only discussion's repliesesit = bot;console;console; esit = bot;console;console; esit = bot;console;console; esit = bot;console;console; esit = bot;console;console; esit = bot;console;console;
That will print:
D: I want to buy a ferrari
R: Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)
D: GTC4
R: Oh, great! Do you confirm you want to purchase it? (yes/no)
D: Maybe...
R: Sorry, I do not understand...
D: no
R: I'm sorry, do you want buy another model? (F12/GTC4/J50/California T/488 GTB)
D: California T
R: Oh, great! Do you confirm you want to purchase it? (yes/no)
D: yes
R: Wonderful! A great purchase!