npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

predictive

v0.0.3

Published

Simple library for generating 'predictive,' ebooks-esque text using word pairs

Downloads

8

Readme

predictive

Simple library for generating predictive, ebooks-esque text using word pairs. This began as a rewrite of nodeEbot, but dropped and added enough features to become its own thing.

Add to your project's package.json or install with npm install predictive

You could use it to make tweets:

var predictive = require('predictive');

var options = {
  files: [
    "path/to/text1.txt",
    "path/to/text2.txt"
  ],
  break_text_on: "\n",
  lines_to_output: 1,
  characters_per_line: 140,
  select_next: "random"
}

predictive.generate(options,function(text){
  console.log(text);
});

Sample output, using Seinfeld and Game of Thrones scripts as text inputs (see examples folder):

JORAH: Ser Jorah Mormont of Bear Island. I served your father from his chess board.

Or something bigger:

var predictive = require('predictive');

var options = {
  files: [
    "path/to/text1.txt",
    "path/to/text2.txt"
  ],
  break_text_on: "\n",
  lines_to_output: 10,
  sentences_per_line: 3,
  select_next: "random"
}

predictive.generate(options,function(text){
  console.log(text);
});

Sample output, again using Seinfeld and Game of Thrones scripts as text inputs:

GEORGE: Why couldn't you have to help us here in New York Health Club]
RAMSAY: Why? Winterfell is yours.
SEPTA MORDANE: Enough!
EXT. SANSA’S ROOM - MORNING
ELAINE: No, you don't wear the ribbon. We are travelling together. In each other’s company.
SPARROW: A sinner comes before you with a squad of guardsmen to escort you to start a marriage. We are the lords of small matters here.
ELAINE: It isn't?
JERRY: But see look at them..
PHARMACIST: Did you make it up. That is why it is still laughing)
THEON: I’ve come to meet?

Here are all the options

| Option | Type | Required | Default | Description | | -------------------- |:---------------:|:------------------------:|:---------------:|:-------------| | files | Array | Yes | null | The relative path to the text to input. Supports txt (recommended), csv and json. I haven't done much testing with csv or json. Should work though! Let me know. | break_text_on | String | For txt file(s) | "\n" | For an efficient and robust corpus, input text needs to be broken up into discrete lines. If you're inputting text with no line breaks, consider using punctuation here. | csv_field | String | For csv file(s) | 0 | The field in your csv file from which text should be ingested. | json_field | String | For json file(s) | 0 | The field in your json file from which text should be ingested. Your json input should probably be flat. | lines_to_output | Integer | - | 10 | Number of lines of generated text to output. Line breaks will be appended to outputted text. | characters_per_line| Integer | - | -1 (no limit) | Limit the number of characters for each line. Will often cutoff sentences at weird places. | words_per_line | Integer | - | -1 (no limit) | Limit the number of words for each line. Will often cutoff sentences at weird places. | sentences_per_line | Integer | - | -1 (no limit) | Number of sentences for each line. Sentences will be terminated by defined punctuation (see below). | punctuation | Array | - | [".","!","?"] | Which characters should denote the end of a sentence. | startwords | Array | - | - | An array of words to start each generated sentence with. Must be words that exist in corpus. If not defined, predictive will use the first word on each sentence in corpus. | select_next | String | - | "random" | Method to use for selecting the next word in sentence generation. See options below.

select_next options:

"random" (recommended) during line generation, selects the next word from an array of relevant word pairs at random.

"most_frequent" during line generation, selects the next word from an array of relevant word pairs by the word that occurs most frequently after current one.

"least_frequent" during line generation, selects the next word from an array of relevant word pairs by the word that occurs least frequently after current one.