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

vui-custom-values-with-synonyms

v4.0.1

Published

Generate custom type values directly from code. Generate mapping functions between equivalent custom type values. Specify prompts to be used with custom values when asking for them.

Downloads

14

Readme

vui-custom-values-with-synonyms

npm package that provides ability to add custom VUI type with synonym functionality to any javascript object.

Repository

This module as well as related vui modules can be found here: https://github.com/RationalAnimal

Installation

	npm install vui-custom-values-with-synonyms --save

or, if you don't want to run unit tests on it:

	npm install vui-custom-values-with-synonyms --save --production

Summary

This project provides npm package to add custom VUI type with synonym functionality to any javascript object. Once this functionality is added then the custom types and their associated values can be added. Then you can generate custom type values directly from code for import into, for example, Amazon Alexa console. Furthermore, the use of these values is further improved because mapping functions between equivalent custom type values are automatically generated and added to the object. While the primary purpose is to add this functionality to other VUI related objects, this is NOT necessary and is purely driven by usefulness. These functions can be added to ANY object and they don't require that the target class has anything to do with VUI.

Examples

var synonyms = require("<path to vui-custom-values-with-synonyms>");
var app = {};
synonyms.addSynonymsToApp(app);

app.addCustomSlotType("vegetable",
  {
    mappingFunctionName: "mapDeliciousVegetable",
    values: [
    {
      text: "carrot"
    },
    {
      text: "russell",
      mapTo: "potato"
    },
    {
      text: "potato"
    }
  ]}
);

Dumping custom type values

One of the advantages of using this module is that you can generate the custom type (type) values directly from the code:

console.log(app.getCustomSlotTypeValues("vegetable"));

will print out all the type values for the "vegetable" custom type:

carrot
russell
potato

Synonyms and Mapping Functions

Frequently in a VUI app you will design your interactions so that your app will accept multiple versions of the same answer. For example, an ingredients question might ask for vegetables and will treat "scallion" and "green onion" values as completely equivalent. Rather than have ad hoc logic, you can simply treat them as synonyms and map them to the same value. And this module will automatically generate of mapping function whenever you add a custom type. So, after adding "vegetable" custom type such as this:

app.addCustomSlotType("vegetable",
  {
    mappingFunctionName: "mapDeliciousVegetable",
    values: [
    {
      text: "potato"
    },
    {
      text: "green onion",
      mapTo: "scallion"
    },
    {
      text: "scallion"
    }
  ]}
);

the following code

var vegetables = app.getCustomSlotTypeValues("vegetable");
console.log(app.mapDeliciousVegetable(vegetables[0]));
console.log(app.mapDeliciousVegetable(vegetables[1]));
console.log(app.mapDeliciousVegetable(vegetables[2]));

will print the mapped type values for the "vegetable" custom type:

potato
scallion
scallion

Prompts

In VUI programming there is often a need to prompt the user for selecting amongst several options. When these answers are accepted they are usually treated as a custom type - this way only a single intent is needed. With vui-custom-values-with-synonyms you can add the prompts as part of the custom type definition.

Imagine you would like to ask a user what type of movie he'd like to watch. You may define a custom type this way:

app.addCustomSlotType("moviegenre",
  {
    mappingFunctionName: "mapMovieGenre",
		values: [
			{
				text: "comedy",
				prompts: [
					{
						categories: ["DEFAULT", "datenight"],
						text: "a funny comedy to make you laugh "
					}
				]
			},
			{
				text: "drama",
				prompts: [
					{
						categories: ["DEFAULT", "datenight"],
						text: "a serious drama "
					}
				]
			},
			{
				text: "horror",
				prompts: [
					{
						categories: ["DEFAULT"],
						text: "a horror movie to scare you "
					}
				]
			}
		]
  }
);

then you can build a prompt for the user to select a genre like this:

var askUser = "What kind of a movie would you like to watch?  You can select from: ";
var defaultPrompts = app.getPrompts("moviegenre");
for(var i = 0; i < defaultPrompts.length; i++){
	askUser += defaultPrompts[i];
}

or if you want to ask the user only for the movie genres that are likely to be appropriate for a date night, you can do it like this:

var askUser = "What kind of a movie would you like to watch together?  You can select from: ";
var dateNightPrompts = app.getPrompts("moviegenre", "datenight");
for(var i = 0; i < dateNightPrompts.length; i++){
	askUser += dateNightPrompts[i];
}

Loading from JSON files

Since a custom type is defined by passing a JSON object to the addCustomSlotType(), you can easily load it from a file, e.g.:

var meats = require("./meat.json");
app.addCustomSlotType("meat", meats);

where the meat.json file contains the same text as what you'd pass to addCustomSlotType() call:

{
  "mappingFunctionName": "mapDeliciousCritters",
  "fileName": "tastycritters.txt",
  "values": [
    {
      "text": "beef"
    },
    {
      "text": "the other white meat",
      "mapTo": "pork"
    },
    {
      "text": "pork"
    }
  ]
}