npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

natural-language-flows

v0.0.1

Published

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.

Downloads

2

Readme

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 flows
var nlf = require('natural-language-flows');

// Initialize the bot
var bot = new nlf.Bot();

// Set a default non matched reply
bot.NonMatchedReply = "Sorry, I do not understand...";

// Add some bot's skills/intents with edges of contexts
bot.AddMultipleCommands([
{
    intent: 'buy-car',
    utterances: [
        "I want to {action} a {product}",
        "I should {action} a {product}",
        "Can you {action} me one {product}?"
    ],
    entities: {
        action: ['buy','have','take','give'],
        product: ['car','automobile','ferrari','sport car']
    },
    response: {
        default: 'Yes, of course! Could you tell me which model of Ferrari? (F12/GTC4/J50/California T/488 GTB)',
        context: 'car-model',
        no_need_context: true
    }
},{
    intent: 'car-model',
    utterances: [
        "{model}",
    ],
    entities: {
        model: ['F12','GTC4','J50','California T','488 GTB']
    },
    response: {
        default: 'Oh, great! Do you confirm you want to purchase it? (yes/no)',
        context: 'car-yes-no'
    }
},{
    intent: 'car-yes-no',
    utterances: [
        "{qresp}",
    ],
    entities: {
        qresp: ['yes','no']
    },
    response: {
        default: 'Sorry, could you confirm the purchase? (yes/no)',
        context: 'car-yes-no',
        conditionals: [
            {
                conditions: {qresp: 'yes'},
                resp: 'Wonderful! A great purchase!',
                context: 'buy-car'
            },
            {
                conditions: {qresp: 'no'},
                resp: "I'm sorry, do you want buy another model? (F12/GTC4/J50/California T/488 GTB)",
                context: 'car-model'
            }
        ]
    }
}]);

Start a discussion with the bot after skills' training:

// Printing the full discussion's objects
esit = bot.answer({text: 'I want to buy a ferrari', context: 'buy-car'});
console.log(esit);

esit = bot.answer({text: 'GTC4', context: esit.context});
console.log(esit);

esit = bot.answer({text: 'Maybe...', context: esit.context});
console.log(esit);

esit = bot.answer({text: 'yes', context: esit.context});
console.log(esit);

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 replies
esit = bot.answer({text: 'I want to buy a ferrari', context: 'buy-car'});
console.log('D:', esit.text);
console.log('R:', esit.reply);

esit = bot.answer({text: 'GTC4', context: esit.context});
console.log('D:', esit.text);
console.log('R:', esit.reply);

esit = bot.answer({text: 'Maybe...', context: esit.context});
console.log('D:', esit.text);
console.log('R:', esit.reply);

esit = bot.answer({text: 'no', context: esit.context});
console.log('D:', esit.text);
console.log('R:', esit.reply);

esit = bot.answer({text: 'California T', context: esit.context});
console.log('D:', esit.text);
console.log('R:', esit.reply);

esit = bot.answer({text: 'yes', context: esit.context});
console.log('D:', esit.text);
console.log('R:', esit.reply);

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!