Skip to content

Instantly share code, notes, and snippets.

@kkoch986
Created July 25, 2014 03:11
Show Gist options
  • Save kkoch986/f3a40299855955a25795 to your computer and use it in GitHub Desktop.
Save kkoch986/f3a40299855955a25795 to your computer and use it in GitHub Desktop.
Potential Categorization algorithm for Porter Stemmer
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