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

transcript-parser

v0.7.1

Published

Parses plaintext speech/debate/radio transcripts into JavaScript objects.

Downloads

17

Readme

transcript-parser

Build Status Coverage Status npm

Description

Parses plaintext speech/debate/radio transcripts into JavaScript objects. It is still in early development. Pull requests are welcome.

Tests can be run with npm test and a benchmark can be run with npm run benchmark. For a full coverage report using Istanbul, run npm run travis-test.

Tested for Node.js >= v4.4.6

Usage

npm install transcript-parser

'use strict';
const fs = require('fs');
const TranscriptParser = require('transcript-parser');
const tp = new TranscriptParser();

//Synchronous example
const parsed = tp.parseOneSync(fs.readFileSync('transcript.txt', 'utf8'));
console.log(parsed);

//Asynchronous example
fs.readFile('transcript.txt', (err, data) => {
  if(err) return console.error('Error:', err);
  tp.parseOne(data, (err, parsed) => {
    if(err) return console.error('Error:', err);
    console.log(parsed);
  }));
});

//Stream example
const stream = fs.createReadStream('transcript.txt', 'utf8');
tp.parseStream(stream, (err, parsed) => {
  if(err) return console.error('Error:', err);
  console.log(parsed);
});

Config

The constructor for TranscriptParser accepts a settings object.

  • removeActions
    • default: true
    • Specifies if the parser should remove actions (e.g. (APPLAUSE)).
  • removeAnnotations
    • default: true
    • Specifies if the parser should remove annotations (surrounded by []).
  • removeTimestamps
    • default: true
    • True if removeAnnotations is true
    • Specifies if the parser should remove timestamps (in the [##:##:##] format).
  • removeUnknownSpeakers
    • default: false
    • Specifies if the parser should remove lines that have no associated speaker.
    • If true, lines that have no associated speaker will be stored under the key none.
  • blacklist
    • default: []
    • A list of speakers (as strings) that the parser should ignore.
  • aliases
    • default: {}
    • A object with the real name as the key and an Array of the aliases' regular expressions as the value.
    • Example: { "Mr. Robot": [ /[A-Z\ ]*SLATER[A-Z\ ]*/ ] }
      • Renames all speakers who match the regex to "Mr. Robot".

Settings can be changed after object creation by changing the corresponding properties of tp.settings, where tp is an instance of TranscriptParser.

Documentation

.parseStream()

The parseStream() method parses a Stream and returns an object representing it.

This is the preferred method for parsing streams asynchronously as it doesn't have to load the entire transcript into memory (unlike parseOne()).

Syntax

tp.parseOneSync(stream, callback)

Parameters
  • stream
    • The Readable stream to read.
  • callback(err, data)
    • A callback to be executed on function completion or error.

.parseOneSync()

The parseOneSync() method parses a string and returns an object representing it.

Syntax

tp.parseOneSync(transcript)

Parameters
  • transcript
    • The transcript, as a string.

.parseOne()

The parseOne() method parses a string and returns an object representing it.

Syntax

tp.parseOne(transcript, callback)

Parameters
  • transcript
    • The transcript, as a string.
  • callback(err, data)
    • A callback to be exectuted on function completion or error.

.resolveAliasesSync()

The resolveAliasesSync() method resolves all aliases specified in the configuration passed to the TranscriptParser's constructor (see above).

Renames the names in the order list to match the new names in the transcript. Note that there is a signifigant performance penalty, so don't use this method unless you need it.

Syntax

tp.resolveAliasesSync(data)

Parameters
  • data
    • The transcript object after being parsed.

.resolveAliases()

The resolveAliases() method resolves all aliases specified in the configuration passed to the TranscriptParser's constructor (see above).

Renames the names in the order list to match the new names in the transcript. Note that there is a signifigant performance penalty, so don't use this method unless you need it.

Syntax

tp.resolveAliases(data, callback)

Parameters
  • data
    • The transcript object after being parsed.
  • callback(err, resolved)
    • A callback to be executed on function completion or error.

Example

Input

A: I like Node.js.
A: I also like C#.
B: I like Node.js too!
A: I especially like the Node Package Manager.

Output

{
  speaker: {
    A: [
      'I like Node.js.',
      'I also like C#.',
      'I especially like the Node Package Manager.'
    ],
    B: ['I like Node.js too!']
  },
  order: ['A', 'A', 'B', 'A']
}