Skip to content

Natural language generation language

Notifications You must be signed in to change notification settings

gtl-alex/nalgene-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nalgene-js

Installation

As a local Node module:

npm install nalgene

Or to use the nalgene command line tool:

npm install -g nalgene

What is this?

The basic idea of Nalgene is to generate sentences based on a grammar and a set of variables. The grammar defines a recursive tree of phrases that can be generated given some variables, and the generator will expand those phrases into a sentence that makes the most use of the variables.

> nalgene examples/iot.nlg --device "office light" --state "on"
The office light is now on.

> nalgene examples/iot.nlg --asset "bitcoin" --price "$1155.33"
Bitcoin is at $1155.33.

> nalgene examples/order.nlg --food "a burger" --location "Tokyo"
You're looking for a burger in Tokyo?

> nalgene examples/order.nlg --food "a burger"
You're looking for a burger?

> nalgene examples/order.nlg
You're looking for some food?

Syntax

Phrases

Phrases represent multiple sets of tokens, where each set of tokens is a different "possibility", and each token is either a regular word or a special token. A phrase may have many possibilities for different ways to say the same sentence with different amounts of context (from variables, below).

%
    %sayHi
    %sayBye

%sayHi
    hello there
    hi

%sayBye
    %formalBye
    %informalBye

%formalBye
    farewell

%informalBye
    bye
    cya

When generating you supply an "entry phrase" to expand from, which is % by default. In this example, expanding from % would start a random walk down all the possibilities, expanding each phrase token it encounters, to generate one of "hello there", "hi", "farewell", "bye", or "cya". Generating from the specific node %informalBye would return only "bye" or "cya".

Variables

Variables are user-supplied values that also influence phrase selection.

If a phrase possibility has variables, it will only be used if all of the variables are available in the context. During generation phrases are ranked by the number of variables that match, to generate a sentence that uses the most context.

For example, with this simple grammar:

%confirmFoodSearch
    You're looking for $food in $location ?
    You're looking for some food in $location ?
    You're looking for $food ?
    You're looking for some food ?

Nalgene will generate the output that satisfies the most variables from the context:

%confirmFoodSearch $food="a burger" $location="Tokyo"
> You're looking for a burger in Tokyo?

%confirmFoodSearch $food="a burger"
> You're looking for a burger?

%confirmFoodSearch
> You're looking for some food?

Examples

examples/iot.nlg defines some responses for a conversational IoT bot:

> nalgene examples/iot.nlg --device "office light" --state "on"
The office light is now on.

> nalgene examples/iot.nlg --asset "bitcoin" --price "$1155.33"
Bitcoin is at $1155.33.

Usage

TODO: Expand

nalgene = require 'nalgene'

grammar = nalgene.parse '...'
grammar.addChild nalgene.parse.fromCSV '...'
grammar.addChild nalgene.parse.fromObject {...}
nalgene.generate grammar, {...}

About

Natural language generation language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CoffeeScript 61.3%
  • JavaScript 37.3%
  • Makefile 1.4%