Package Exports
- sentence-engine
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sentence-engine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sentence-engine
This is a straightforward sentence generator which takes a template and a vocabulary that may be sorted in any way desired. It runs on Node.js.
Features
- Unbound vocabulary; define use case-specific categories or adhere to conventional keywords
- Object-oriented
- Lightweight
Usage
Install
> npm i sentence-engineImport & Use
// import:
const Sentence = require('sentence-engine')
// initialize Sentence object, here with no arguments:
let sentence1 = Sentence()
console.log(sentence1) // <-- outputs "Sentence { }" (object instance)
console.log(sentence1.get()) // <-- outputs "hello, world" (generated sentence string)Calling Sentence() creates an object of a Sentence class which will store a template, vocabulary, and a set of options. In the case above we pass no arguments and the object is simply given some default values and resolve to "hello, world". See Sentence.js for the class implementation.
By passing a template and/or vocabulary, the sentence engine becomes much more powerful. See examples below.
let template = 'This is {a-adjective} template.'
let vocabulary = {
adjective: ['awesome', 'bad', 'great', 'repulsive']
}
console.log(Sentence(template, vocabulary).get()) // <-- might output "This is an awesome template"In the above example, we pass a single template. We can also pass several templates for the engine to choose between.
let templates = [
'This is {a-adjective} template.',
'This template is {adjective}.'
]
console.log(Sentence(templates, vocabulary).get())Some use cases may want to store the instance of the Sentence object in a variable for later use. Doing this allows the object generate a new sentence with the arguments that were passed initially.
let sentence = Sentence(templates, vocabulary) // Sentence constructor initializes itself with generate()
sentence.generate() // user may call generate method to recreate the sentence on the objectExamples
Development
Early stages and likely to see fundamental changes.
Contributing
Sure!
Background
The package is inspired by the TV show Better Off Ted's episode S2E8 "The Impertence of Communicationizing", and started off as a proof-of-concept for the insult formula introduced in the episode.