Coder Social home page Coder Social logo

syllable's Introduction

syllable

Build Coverage Downloads Size

Count syllables in an English word.

Contents

What is this?

This package estimates how many syllables are in an English word.

When should I use this?

Use this when you want to do fun things with natural language, like rhyming, detecting reading ease, etc.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install syllable

In Deno with esm.sh:

import {syllable} from 'https://esm.sh/syllable@5'

In browsers with esm.sh:

<script type="module">
  import {syllable} from 'https://esm.sh/syllable@5?bundle'
</script>

Use

import {syllable} from 'syllable'

syllable('syllable') // 3
syllable('unicorn') // 3
syllable('hi') // 1
syllable('hihi') // 2
syllable('mmmmmmmmmmmmmmmm') // 1
syllable('wine') // 1
syllable('bottle') // 2
syllable('wine-bottle') // 3
syllable('Åland') // 2

API

This package exports the identifier syllable. There is no default export.

syllable(value)

Get the number of syllables in value.

value

Value to check (string, required).

Returns

Syllables in value (number).

CLI

Usage: syllable [options] <words...>

Count syllables in English words

Options:

  -h, --help           output usage information
  -v, --version        output version number

Usage:

# output syllables
$ syllable syllable unicorn
# 6

# output syllables from stdin
$ echo "syllable unicorn banana" | syllable
# 9

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Related

  • automated-readability — formula to detect ease of reading according to the Automated Readability Index (1967)
  • buzzwords — list of buzzwords
  • coleman-liau — formula to detect the ease of reading a text according to the Coleman-Liau index (1975)
  • cuss — map of profane words to a rating of sureness
  • dale-chall — list of easy American-English words: The New Dale-Chall (1995)
  • dale-chall-formula — formula to find the grade level according to the (revised) Dale–Chall Readability Formula (1995)
  • fillers — list of filler words
  • flesch — formula to detect the ease of reading a text according to Flesch Reading Ease (1975)
  • flesch-kincaid — formula to detect the grade level of text according to Flesch–Kincaid Grade Level (1975)
  • gunning-fog — formula to detect the ease of reading a text according to the Gunning fog index (1952)
  • hedges — list of hedge words
  • profanities — list of profane words
  • smog-formula — formula to detect the ease of reading a text according to the SMOG (Simple Measure of Gobbledygook) formula (1969)
  • spache — list of familiar American-English words (1974)
  • spache-formula — uses a dictionary, suited for lower reading levels
  • weasels — formula to detect the grade level of text according to the (revised) Spache Readability Formula (1974)

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

Notice

Based on the syllable functionality found in Text-Statistics (PHP), in turn inspired by Lingua::EN::Syllable (Perl).

Support for word-breaks, non-ASCII characters, and many fixes added later.

License

MIT © Titus Wormer

syllable's People

Contributors

beardicus avatar greenkeeperio-bot avatar isaacbanner avatar michaelchambers avatar nikhiljha avatar sautumn avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

syllable's Issues

False positives for 1 syllable

Using this with sentencer.js to create a random phrase generator with the option to restrict the number of syllables per word.

import Sentencer from 'sentencer';
import Syllable from 'syllable';

function getWordsWithSyllables(num, words) {
    return words.filter(function(word) {
        return Syllable(word) === num;
    });
};
   
console.log(getWordsWithSyllables(1, Sentencer._adjectives));

Results in the following output:

[
  "aged",
  "ain",
  "air",
  "bar",
  "beauish", // 2 syllables
  "biped", // 2 syllables
  "bluest", // 2 syllables
  "bluish", // 2 syllables
  "bomb",
  "broch",
  "brute",
  "chill",
  "chin",
  "crooked", // 2 syllables
  "cruel",
  "crying", // 2 syllables
  "cursed",
  "cussed",
  "dam",
  "deuced",
  "dun",
  "dying", // 2 syllables
  "freest", // 2 syllables
  "gluey", // 2 syllables
  "grave",
  "here",
  "hyoid", // 2 syllables
  "jasp",
  "jet",
  "laic",
  "learned",
  "liege",
  "louvred",
  "lying", // 2 syllables
  "male",
  "man",
  "measled", // 2 syllables
  "mere",
  "meshed",
  "mis",
  "naif",
  "naive", // 2 syllables
  "pan",
  "par",
  "pass",
  "peaked",
  "prying", // 2 syllables
  "pyoid", // 2 syllables
  "said",
  "saut",
  "shredless", // 2 syllables
  "store",
  "theist", // 2 syllables
  "toey", // 2 syllables
  "treen", // 2 syllables
  "vying", // 2 syllables
  "weest" // 2 syllables
]

English is weird! Admittedly, I had to look up the pronunciation for a number of these.

[aeiouy]nse$

'expanse', 'tense', 'expense', 'rinse', 'response'

PR forthcoming

Use div class instead of textarea

I'm using a wysiwyg editor and it doesn't use textarea. Your index.js code works great if I target a textarea, but as soon as I change the querySelector to a class, like .myeditor, then E is no longer a function according to my console error.

The index.js file I'm trying to use is from the demo: https://words.github.io/syllable/index.js

I know this isn't an "issue" and github isn't necessarily meant for support like this but I thought I'd give this a shot.

Feature request: syllablize()

Hi, Words team,

I appreciate your work. The syllable module is super good.

However, I wish to syllable have this function for creating readability texts.

syllablize('beautiful') // output: ['beau', 'ti', 'ful']

I think it's not too hard to create this function with your algorithm.

Thank you so much!

Best regards,
Vien Dinh.

Option to get the actual syllables

apologies if this is a silly question as I haven't looked at how the code works, but would it be possible to return the actual syllables, rather than just the count?

node.js: "syllable unicorn" produces 5 instead of 6 inside shell

The following in node.js on 10.36 and 12.2:
console.log("syllable unicorn", syllable("syllable unicorn"));
produces 5 instead of the correct 6 like in the shell directly.

My current solution is to just split the string by spaces and add up the values to find the total syllables in the line.

My experience with NLP is limited, so at the moment I'm not quite sure what went wrong where, but I'll dig through and see what I can find.

Thanks for the npm module! It's been the best I've found so far.

Oneway is three syllables instead of 2

I think it's because of

// Count multiple consonants.
parts = value.split(/[^aeiouy]+/)

and ay is counted as a vowel split, so we ended up with
parts [ 'o', 'e', 'ay' ]

There's no consonant before the o.

-rbed should be one syllable

Waterbed, riverbed, featherbed, etc are compound words, and thus exceptions.

See: disturbed, barbed, herbed, absorbed.

real/deal/really have too many syllables

"Real" counts as 2—should be 1
"Deal" counts as 2—should be 1
"Really" counts as 3—should be 2

There may be similar words affected that I didn't catch.

ERR_REQUIRE_ESM: Must use import (I am using import)

Getting this:

Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/syllable/index.js from extendToMinimumLength.ts not supported.
Instead change the require of index.js in extendToMinimumLength.ts to a dynamic import() which is available in all CommonJS modules.

But I am using import?

Contractions are not counted correctly

Hi! We noticed that contractions aren't handled properly. A few examples:

that's -> 2 (should be 1)
they're -> 2 (should be 1)
aren't -> 3 (should be 1)

Let me know if you have any thoughts on how to account for contractions!

Thanks,
Aviv (Engineering Lead at Flocabulary)

Does not account for re- prefix in some cases.

reuse -> 1
reimpose -> 2

Works for some cases:
realign -> 3

This was being propped up by the test cases including the failing words ending in -shed or -sed, which #20 solves, so I only noticed this now.

Unfortunately, just triggering on re- doesn't work, since there are plenty of valid words that start with re- that aren't using it as a prefix.

Make syllable work in browser?

I wasn't able to make this work in the browser (because normalize-strings uses require).

I was able to browserify it but it was a bit tricky, the command I used is as follows:

browserify index.js -p esmify -s syllable -o syllable-browser.js

That creates a global variable called syllable that you can use like syllable.syllable(word). Not the most elegant but just wanted something quick and dirty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.