Created
July 18, 2016 21:14
-
-
Save skorytnicki/bd74d76e9e974d84ed858f5141496d04 to your computer and use it in GitHub Desktop.
Approximate the number of syllabes in the string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// coursera NLP lesson 02.04 | |
// approximating number of syllables in a string | |
function countSyllables(s) { | |
'use strict'; | |
var k = 0; | |
if (s.length < 1) return k; | |
s = s.toLowerCase(); | |
s = s.replace(/\W+/g, ""); | |
s = s.replace(/[aeiou]/ig,'\~'); | |
s = s.replace(/[qwrtypsdfghjklzxcvbnm]/ig,'C'); | |
// lol, not tested it yet | |
// count occurencies of VC in a given string | |
while (s.length > 1) { | |
let i = s.indexOf('~C'); | |
if (i == -1) break; | |
k = k+1; | |
s = s.substr(i+2,s.length); | |
} | |
return k; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment