{"id":21842784,"url":"https://github.com/davidemiceli/natural-language-flows","last_synced_at":"2025-04-14T12:04:52.185Z","repository":{"id":57308922,"uuid":"77915749","full_name":"davidemiceli/natural-language-flows","owner":"davidemiceli","description":"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.","archived":false,"fork":false,"pushed_at":"2017-01-03T15:26:36.000Z","size":7,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T01:11:29.299Z","etag":null,"topics":["artificial-intelligence","bot","natural-language-processing","nlp"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidemiceli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T12:35:32.000Z","updated_at":"2020-04-09T20:27:01.000Z","dependencies_parsed_at":"2022-09-14T17:53:12.202Z","dependency_job_id":null,"html_url":"https://github.com/davidemiceli/natural-language-flows","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemiceli%2Fnatural-language-flows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemiceli%2Fnatural-language-flows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemiceli%2Fnatural-language-flows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidemiceli%2Fnatural-language-flows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidemiceli","download_url":"https://codeload.github.com/davidemiceli/natural-language-flows/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248794573,"owners_count":21162614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","bot","natural-language-processing","nlp"],"created_at":"2024-11-27T22:13:07.652Z","updated_at":"2025-04-14T12:04:52.153Z","avatar_url":"https://github.com/davidemiceli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Natural language flows\nA 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.\n\n## Installation\n```\nnpm install natural-language-flows\n```\n\nOr use it into the browser:\n```\n\u003cscript type=\"text/javascript\" src=\"lib/natural-language-flows.js\"\u003e\u003c/script\u003e\n\n```\n\n## How it works\n\nInitialize on node.js\n```javascript\n// Require the natural language flows\nvar nlf = require('natural-language-flows');\n\n// Initialize the bot\nvar bot = new nlf.Bot();\n```\n\nInitialize on the browser\n```javascript\n// Initialize the bot\nvar bot = new Bot();\n```\n\nUse it adding skills/intents\n```javascript\n// Set a default non matched reply\nbot.NonMatchedReply = \"Sorry, I do not understand...\";\n\n// Add some bot's skills/intents with edges of contexts\nbot.AddMultipleCommands([\n{\n    intent: 'buy-car',\n    utterances: [\n        \"I want to {action} a {product}\",\n        \"I should {action} a {product}\",\n        \"Can you {action} me one {product}?\"\n    ],\n    entities: {\n        action: ['buy','have','take','give'],\n        product: ['car','automobile','ferrari','sport car']\n    },\n    response: {\n        default: 'Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)',\n        context: 'car-model',\n        no_need_context: true\n    }\n},{\n    intent: 'car-model',\n    utterances: [\n        \"{model}\",\n    ],\n    entities: {\n        model: ['F12','GTC4','J50','California T','488 GTB']\n    },\n    response: {\n        default: 'Oh, great! Do you confirm you want to purchase it? (yes/no)',\n        context: 'car-yes-no'\n    }\n},{\n    intent: 'car-yes-no',\n    utterances: [\n        \"{qresp}\",\n    ],\n    entities: {\n        qresp: ['yes','no']\n    },\n    response: {\n        default: 'Sorry, could you confirm the purchase? (yes/no)',\n        context: 'car-yes-no',\n        conditionals: [\n            {\n                conditions: {qresp: 'yes'},\n                resp: 'Wonderful! A great purchase!',\n                context: 'buy-car'\n            },\n            {\n                conditions: {qresp: 'no'},\n                resp: \"I'm sorry, do you want buy another model? (F12/GTC4/J50/California T/488 GTB)\",\n                context: 'car-model'\n            }\n        ]\n    }\n}]);\n```\n\nStart a discussion with the bot after skills' training:\n\n```javascript\n// Printing the full discussion's objects\nesit = bot.answer({text: 'I want to buy a ferrari', context: 'buy-car'});\nconsole.log(esit);\n\nesit = bot.answer({text: 'GTC4', context: esit.context});\nconsole.log(esit);\n\nesit = bot.answer({text: 'Maybe...', context: esit.context});\nconsole.log(esit);\n\nesit = bot.answer({text: 'yes', context: esit.context});\nconsole.log(esit);\n```\n\nThat will print the complete result object in this way:\n```javascript\n{ text: 'I want to buy a ferrari',\n  intent: true,\n  entities: { action: [ 'buy' ], product: [ 'ferrari' ] },\n  reply: 'Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)',\n  context: 'car-model' }\n{ text: 'GTC4',\n  intent: true,\n  entities: { model: [ 'GTC4' ] },\n  reply: 'Oh, great! Do you confirm you want to purchase it? (yes/no)',\n  context: 'car-yes-no' }\n{ text: 'Maybe...',\n  intent: null,\n  entities: {},\n  reply: 'Sorry, I do not understand...',\n  context: 'car-yes-no' }\n{ text: 'yes',\n  intent: true,\n  entities: { qresp: [ 'yes' ] },\n  reply: 'Wonderful! A great purchase!',\n  context: 'buy-car' }\n```\n\nTo print only the discussion data:\n\n```javascript\n// Only discussion's replies\nesit = bot.answer({text: 'I want to buy a ferrari', context: 'buy-car'});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n\nesit = bot.answer({text: 'GTC4', context: esit.context});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n\nesit = bot.answer({text: 'Maybe...', context: esit.context});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n\nesit = bot.answer({text: 'no', context: esit.context});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n\nesit = bot.answer({text: 'California T', context: esit.context});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n\nesit = bot.answer({text: 'yes', context: esit.context});\nconsole.log('D:', esit.text);\nconsole.log('R:', esit.reply);\n```\n\nThat will print:\n\n```\nD: I want to buy a ferrari\nR: Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)\nD: GTC4\nR: Oh, great! Do you confirm you want to purchase it? (yes/no)\nD: Maybe...\nR: Sorry, I do not understand...\nD: no\nR: I'm sorry, do you want buy another model? (F12/GTC4/J50/California T/488 GTB)\nD: California T\nR: Oh, great! Do you confirm you want to purchase it? (yes/no)\nD: yes\nR: Wonderful! A great purchase!\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidemiceli%2Fnatural-language-flows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidemiceli%2Fnatural-language-flows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidemiceli%2Fnatural-language-flows/lists"}