NodeJS bindings for the Rust module 'markov'
  • Rust 56.4%
  • JavaScript 43.6%
Find a file
2022-03-26 16:50:13 +00:00
.idea test: add files for testing with jest 2020-04-16 17:59:35 +01:00
lib fix(typings): generate functions typed as void 2020-04-18 01:09:17 +01:00
native refactor: rename exports 2020-04-16 17:58:52 +01:00
test test: add files for testing with jest 2020-04-16 17:59:35 +01:00
.editorconfig initial commit 2020-04-15 23:29:55 +01:00
.gitignore initial commit 2020-04-15 23:29:55 +01:00
.npmignore feat: initial release 2020-04-16 20:57:32 +01:00
.releaserc ci: include github release plugin 2020-04-17 23:59:22 +01:00
.travis.yml ci: fix not skipping cleanup 2020-04-16 22:52:46 +01:00
package.json chore(release): 1.0.1 [skip ci] 2020-04-18 00:19:15 +00:00
README.md docs(readme): link to markov module 2020-04-17 23:59:02 +01:00
yarn.lock chore(deps): bump minimist from 1.2.5 to 1.2.6 2022-03-26 12:53:44 +00:00

markov-rs

Build Status

Node bindings for the Rust crate markov.

This currently only offers a string markov chain, and a subsection of (arguably) the most useful methods. Typescript typings are included.

Installation

This package requires Rust to be installed. Several Linux distros offer it in their official repos, or you can grab it from here.

You will also require gcc, make, and python installed for node-gyp to do its business. In most cases you probably will.

Usage

Import the package:

// vanilla node
const StringChain = require('markov-rs').StringChain;

// typescript
import { StringChain } from 'markov-rs';

Then create a new instance:

const chain = new StringChain();

// or to create a chain of specific order:
const chain = new StringChain(2);

// or to load a previously saved chain:
const chain = new StringChain('./path/to/chain.mko');

And start using it:

console.log(chain.isEmpty()) // -> true

// then populate:
chain.feedString('here is a sentence.');

// or populate using a file.
// The file should contain a sentence per line.
chain.feedFile('./path/to/text/file.txt');

// to generate from your chain:
const sentence = chain.generateString();

// to guarantee it starts with a token:
const promptedSentence = chain.generateStringFromToken('here');

// and to save it to disk to be loaded again later:
chain.save('./path/to/chain.mko');