1.0.0 • Published 3 years ago
suggestion-tree v1.0.0
suggestion-tree
Give SuggestionTree some sequence, and it can provide suggestions to follow other sequences based on that source.
Installation
npm install suggestion-tree
Usage
import SuggestionTree from 'suggestion-tree';
// Start with an array to serve as the suggestion source
// In the below example we split a string into an array of words.
const tokens = 'the greatest example text ever written by the greatest person.'.split(' ');
// Create a new tree
const sTree = new SuggestionTree(tokens);
// Returns either 'example' or 'person', randomly
sTree.getSuggestionFor(['the', 'greatest']);
// Returns 'written'
sTree.getSuggestionFor(['ever']);
// Serialize as JSON string
const stringified = sTree.toJSONString();
// De-serialize a SuggestionTree
// Returns a new SuggestionTree object
const deStringified = SuggestionTree.parseJSON(stringified);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
1.0.0
3 years ago