Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

articulate-nlg

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

articulate-nlg - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

2

package.json
{
"name": "articulate-nlg",
"version": "1.0.10",
"version": "1.0.11",
"description": "A natural language generator (NLG) that articulates concepts as words, phrases, and sentences.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -7,3 +7,3 @@ [![Build Status](https://travis-ci.org/justinmahar/articulate-nlg.svg?branch=master)](https://travis-ci.org/justinmahar/articulate-nlg) [![codecov](https://codecov.io/gh/justinmahar/articulate-nlg/branch/master/graph/badge.svg)](https://codecov.io/gh/justinmahar/articulate-nlg)

This [TypeScript](https://www.typescriptlang.org/) project is [available in JavaScript via npm](https://www.npmjs.com/package/articulate-nlg) as a CommonJS import.
This [TypeScript](https://www.typescriptlang.org/) project is [available in JavaScript via npm](https://www.npmjs.com/package/articulate-nlg) as an ES6 or CommonJS import.

@@ -18,2 +18,8 @@ ## Installation

ES6 import:
```js
import Persona from "articulate-nlg";
```
CommonJS import:

@@ -28,2 +34,3 @@

In short:
- Define "personas" that have vocabularies which can randomly generate coherent text.

@@ -42,3 +49,4 @@ - Vocabularies use keys that represent concepts, and values that represent the text to be generated.

```js
const Persona = require("articulate-nlg").default;
// ES6 import. CommonJS import available, too. See above.
import Persona from "articulate-nlg";

@@ -52,3 +60,3 @@ // Here we have the greet, master, emoji, and welcome-home concepts.

master:
"{{#params.name}}{{#capitalize}}{{params.name}}{{/capitalize}}{{/params.name}}{{^params.name}}bringer of food{{/params.name}}",
"{{#params.name}}{{#capitalize}}{{params.name}}{{/capitalize}}{{/params.name}}{{^params.name}}bringer of food{{/params.name}}",

@@ -58,3 +66,3 @@ emoji: "{{#choose}}👅|🐶|🐾|💩|🐩|🐕‍{{/choose}}",

"welcome-home":
"{{#capitalize}}{{>greet}}{{/capitalize}}! Welcome home, {{>master}}! {{>emoji}}"
"{{#capitalize}}{{>greet}}{{/capitalize}}! Welcome home, {{>master}}! {{>emoji}}"
};

@@ -88,7 +96,7 @@

// You can pass parameters, too. These are referenced using: {{params.keyName}}
console.log(max.articulate("{{params.keyName}}", { "blah": "heyyyooo" }));
console.log(max.articulate("{{params.keyName}}", { blah: "heyyyooo" }));
// "heyyyooo"
// Params can be used in the vocab, too. Here, the master concept uses a name if provided.
console.log(max.articulate("master", { "name": "justin" }));
console.log(max.articulate("master", { name: "justin" }));
// "Justin"

@@ -111,5 +119,5 @@

- `capitalize`: Capitalizes the first letter of the contents after rendering it.
- `{{#capitalize}}`: Capitalizes the first letter of the contents after rendering it.
- `{{#capitalize}}hello{{/capitalize}}` -> `Hello`
- `choose`: Chooses one of the items at random.
- `{{#choose}}`: Chooses one of the items at random.
- `{{#choose}}apple|orange|starfruit{{/choose}}` -> Randomly selects `apple`, `orange`, `starfruit`.

@@ -122,5 +130,33 @@ - Items are separated by `|` pipes.

You cannot nest the same function wrapper within itself. This is a limitation of the underlying template engine, Mustache.js. If you need to nest them, create a separate vocab key/value and where you'd like to nest it, reference it like so: `{{>nameOfVocabKey}}`.
### Vocab Helpers
The class `VocabHelpers` contains helper functions that create the function wrapper templates shown above. You can use these to make vocabs easier to define.
- `capitalize(text:string)` - Creates a template for capitalization.
- `choose(texts:(string|{v:value,w:weight})[])` - Creates a template for random choice. Takes an array of strings or weighted objects in the format `{v: value, w: weight}`.
Example:
```js
import Persona, { VocabHelpers } from "articulate-nlg";
const choose = VocabHelpers.choose;
const capitalize = VocabHelpers.capitalize;
let greeterVocab = {
// This creates the string: "{{#capitalize}}{{#choose}}hi|hello|heyooo=10{{/choose}}{{/capitalize}}"
greet: capitalize(choose(["hi", "hello", { v: "heyooo", w: 10 }]))
};
let greeter = new Persona(greeterVocab);
greeter.articulate("greet");
// Outputs "hi" (1/12 chance), "hello" (1/12 chance), or "heyooo" (10/12 chance).
```
Again, you cannot nest the same function wrapper in itself. If, say, you need to nest `choose()` within `choose()`, you should create a separate vocab key with the function and reference it in the original one like so: `{{>nameOfVocabKey}}`.
## TypeScript Support
This is a TypeScript project, so type definitions are available in: `dist/index.d.ts`.
This is a TypeScript project. Type definitions are available in: `dist/index.d.ts`.

@@ -127,0 +163,0 @@ ## ISC License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc