words / syllable Goto Github PK
View Code? Open in Web Editor NEWCount syllables in an English word
Home Page: https://words.github.io/syllable/
License: MIT License
Count syllables in an English word
Home Page: https://words.github.io/syllable/
License: MIT License
syllable('wine'); //=> 1
syllable('bottle'); //=> 2
syllable('wine-bottle'); //=> 4, should be 3
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)
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.
ex:
"based" -> 2
"mixed" -> 2
"banished" -> 3
"shadowed" -> 3
Create -> 1, Creative -> 2, Creativity -> 4
Examples:
someone
something
somewhat
somebody
sometime
somewise
It looks like they all count exactly one extra syllable.
"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.
Waterbed, riverbed, featherbed, etc are compound words, and thus exceptions.
See: disturbed, barbed, herbed, absorbed.
Lot to unpack, but:
horseradishes - 6
horse radishes - 5
radishes - 4
radishe OR radises - 3
Hope this is helpful. Please ignore, if not.
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?
awe should be 1 appears to be 2
awesome should be 2 appears to be 3
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.
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.
https://www.howmanysyllables.com/words/snuffleupagus
5
But:
$ syllable Snuffleupagus
4
I am trying to modify your module slightly to get an array with the syllables, not just the amount. Could you point me in the right direction?
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.
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.
'expanse', 'tense', 'expense', 'rinse', 'response'
PR forthcoming
The pronunciation shows the 2 syllables.
https://www.merriam-webster.com/dictionary/anxious
https://www.dictionary.com/browse/anxious?s=t
Will try to add a PR
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?
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.