markov-rs
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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');

Package Sidebar

Install

npm i markov-rs

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

23.7 kB

Total Files

9

Last publish

Collaborators

  • jakestanger