Created
July 25, 2014 03:11
-
-
Save kkoch986/f3a40299855955a25795 to your computer and use it in GitHub Desktop.
Potential Categorization algorithm for Porter Stemmer
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
function categorizeGroups(token) { | |
var previous = null; | |
var current = null; | |
var string = ""; | |
for(var c in token) { | |
var ch = token[c]; | |
var next = null; | |
// Y is a special case, it is only a vowel if preceeded by a vowel. | |
if(ch === "y") { | |
if(previous.match(/[aeiou]/)) { | |
next = "C"; | |
} else { | |
next = "V"; | |
} | |
} else if(ch.match(/[^aeiou]/)) { | |
next = "C"; | |
} else { | |
next = "V"; | |
} | |
if(next != current) { | |
current = next; | |
string += current; | |
} | |
previous = ch; | |
} | |
return string; | |
} | |
// denote single consonants with a C and single vowels with a V | |
function categorizeChars(token) { | |
var previous = null; | |
var string = ""; | |
for(var c in token) { | |
var ch = token[c]; | |
var next = null; | |
// Y is a special case, it is only a vowel if preceeded by a vowel. | |
if(ch === "y") { | |
if(previous.match(/[aeiou]/)) { | |
next = "C"; | |
} else { | |
next = "V"; | |
} | |
} else if(ch.match(/[^aeiou]/)) { | |
next = "C"; | |
} else { | |
next = "V"; | |
} | |
string += next; | |
previous = ch; | |
} | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment