Keyworder.js is a simple javascript library that takes a block of text and allows the user to execute either a search for a set of keywords, strip a set of common words from the supplied text, or do both functions in one call. The common set of words to be stripped are by default the 100 most used words in English, but can be overwritten or added if desired. There are no keywords set by default, and instead need to be set if that function is wanted to be used.
The default common word list is generated from http://en.wikipedia.org/wiki/Most_common_words_in_English and are as follows:
the, be, of, to, and, in, a, that, have, I, it, for, not, on, with, he, as, you, do, at, is, this, but, his, by, from, they, we, say, her, she, or, an, we, will, my, one, all, would, there, their, what, so, up, out, if, about, who, get, which, go, me, when, make, can, like, time, no, just, him, know, take, people, into, year, your, good, some, could, them, see, other, than, then, now, look, only, come, its, over, think, also, back, after, use, two, how, our, work, first, well, way, even, new, want, because, any, these, give, day, most, us
This list of words can be overwritten or added to using the keyworder.setOptions(options) function.
Sets possible options for the library taking a javascript object.
optionscommon: An array of words that can either overwrite or add to the existing set of common words depending on theoverwriteoption.overwrite: Boolean value (default false). Used in setting the newcommonas above.keywords: An array of words that will be used in the keyword matching function.matchCase: Boolean value (default false). Used in the keyword matching function. If it is true, will only detect words in the statement that match the case of the input keywords.
####Example
keyworder.setOptions({
common: ["blue", "green", "red"],
overwrite: false,
keywords: ["yellow", "orange", "roger"],
matchCase: true
});Takes a string of text and searches through it for a matching keyword. If the matchCase variable is set to true, then it will only return values that have the same case as the keywords. Returns the values as an array object.
text: A string of text that is to be searched through for keywords.
####Example
//with matchCase on:
keyworder.setOptions({keywords:["yellow", "orange", "roger"], matchCase: true});
keyworder.keywordMatch("Roger picked up the orange pumpkin."); //returns ["orange"]
//with matchCase off:
keyworder.setOptions({matchCase: false});
keyworder.keywordMatch("Roger picked up the orange pumpkin."); //returns ["orange", "roger"]Takes a string of text and strips out the common words (as specified in the common array) from it, returning the result as a string.
text: A string of text that is to be stripped of all common words.stripPunction: Boolean value (default false) to determine how the word is returned. If true, will remove all capitalization and punctuation from the returning sentance.
####Example
//with no additional common words set:
keyworder.stripCommonWords("The yellow sun is high in the blue sky."); //returns "yellow sun high blue sky."
//with added common words:
keyworder.setOptions({common: ["blue", "green", "red"]});
keyworder.stripCommonWords("The yellow sun is high in the blue sky."); //returns "yellow sun high sky."
keyworder.stripCommonWords("The yellow sun is high in the blue sky.", true); //returns "yellow sun high sky"
//with overwritten common words:
keyworder.setOptions({common: ["blue", "green", "red"], overwrite: true});
keyworder.stripCommonWords("The yellow sun is high in the blue sky."); //returns "The yellow sun is high in the sky."Takes a string of text and first calls keyworder.stripCommonWords on it, then takes the result and calls keyworder.keywordMatch on it. Returns an array of matching keywords.
text: A string of text that is to be stripped of all common words than matched agains keywords.stripPunctuation: Boolean value that is used inkeyworder.stripCommonWords.
#####Note: Since the stripping of common words executes first, if you have a keyword that is also a common word, it will not be returned in this function call.
####Example
keyworder.setOptions({common: ["blue", "green", "red"], keywords: ["yellow", "blue", "sun"]});
keyworder.stripAndMatch("The yellow sun is high in the blue sky."); //returns ["yellow", "sun"]MIT Licensed