https://github.com/jakestanger/markov-rs
NodeJS bindings for the Rust module 'markov'
https://github.com/jakestanger/markov-rs
bindings markov node rust
Last synced: about 1 month ago
JSON representation
NodeJS bindings for the Rust module 'markov'
- Host: GitHub
- URL: https://github.com/jakestanger/markov-rs
- Owner: JakeStanger
- Created: 2020-04-15T22:29:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T03:34:29.000Z (over 3 years ago)
- Last Synced: 2025-02-26T22:37:44.690Z (over 1 year ago)
- Topics: bindings, markov, node, rust
- Language: Rust
- Size: 744 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# markov-rs
[](https://travis-ci.com/JakeStanger/markov-rs)
Node bindings for the Rust crate [markov](https://docs.rs/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](https://www.rust-lang.org/learn/get-started).
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:
```ts
// vanilla node
const StringChain = require('markov-rs').StringChain;
// typescript
import { StringChain } from 'markov-rs';
```
Then create a new instance:
```ts
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:
```ts
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');
```