diff options
author | Rogan Creswick <creswick@gmail.com> | 2013-06-14 17:38:33 -0700 |
---|---|---|
committer | Rogan Creswick <creswick@gmail.com> | 2013-06-14 17:38:33 -0700 |
commit | 68e9ba60559fe08c923fa5eebb2f6b4d27b74d9e (patch) | |
tree | 5047224d1e6c2ddd61785460ab7983ab4e16ccf5 /exampleData | |
parent | 2c3b25addc2bc8b1cb91eb6e708119ea47379e68 (diff) |
fixed some traversal issues with fiveui.query and the uigoerfive rule
Diffstat (limited to 'exampleData')
-rw-r--r-- | exampleData/ruleSets/language-processing/natural/upGoerFive-gen.js | 2371 | ||||
-rw-r--r-- | exampleData/ruleSets/language-processing/natural/upGoerFive.js | 5 |
2 files changed, 1191 insertions, 1185 deletions
diff --git a/exampleData/ruleSets/language-processing/natural/upGoerFive-gen.js b/exampleData/ruleSets/language-processing/natural/upGoerFive-gen.js index dc8b318..2162fbe 100644 --- a/exampleData/ruleSets/language-processing/natural/upGoerFive-gen.js +++ b/exampleData/ruleSets/language-processing/natural/upGoerFive-gen.js @@ -148,6 +148,9 @@ var getTextNodesIn = function (node, includeWhitespaceNodes) { var textNodes = [], whitespace = /^\s*$/; function getTextNodes(node) { + if ($(node).attr('id') == 'fiveui-top') { + return; + } if (node.nodeType == 3) { if (includeWhitespaceNodes || !whitespace.test(node.nodeValue)) { textNodes.push(node); @@ -179,7 +182,7 @@ var markWords = function(obj, report) { _.each(toks, function(tok) { if (isCommonWord(tok) || isPunctuation(tok) || _.isNumber(tok)) { - rawObj.append(tok + ' '); + rawObj.append(' ' + tok + ' '); } else { var newObj = $("<span>"+tok+"</span> "); rawObj.append(newObj); @@ -1419,196 +1422,6 @@ SoundEx.condense = condense; SoundEx.padRight0 = padRight0; })() -},{"./phonetic":44}],4:[function(require,module,exports){ -(function(){/* -Copyright (c) 2011, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -var Phonetic = require('./phonetic'); - -function dedup(token) { - return token.replace(/([^c])\1/g, '$1'); -} - -function dropInitialLetters(token) { - if(token.match(/^(kn|gn|pn|ae|wr)/)) - return token.substr(1, token.length - 1); - - return token; -} - -function dropBafterMAtEnd(token) { - return token.replace(/mb$/, 'm'); -} - -function cTransform(token) { - token = token.replace(/([^s]|^)(c)(h)/g, '$1x$3').trim(); - token = token.replace(/cia/g, 'xia'); - token = token.replace(/c(i|e|y)/g, 's$1'); - token = token.replace(/c/g, 'k'); - - return token; -} - -function dTransform(token) { - token = token.replace(/d(ge|gy|gi)/g, 'j$1'); - token = token.replace(/d/g, 't'); - - return token; -} - -function dropG(token) { - token = token.replace(/gh(^$|[^aeiou])/g, 'h$1'); - token = token.replace(/g(n|ned)$/g, '$1'); - - return token; -} - -function transformG(token) { - token = token.replace(/([^g]|^)(g)(i|e|y)/g, '$1j$3'); - token = token.replace(/gg/g, 'g'); - token = token.replace(/g/g, 'k'); - - return token; -} - -function dropH(token) { - return token.replace(/([aeiou])h([^aeiou])/g, '$1$2'); -} - -function transformCK(token) { - return token.replace(/ck/g, 'k'); -} -function transformPH(token) { - return token.replace(/ph/g, 'f'); -} - -function transformQ(token) { - return token.replace(/q/g, 'k'); -} - -function transformS(token) { - return token.replace(/s(h|io|ia)/g, 'x$1'); -} - -function transformT(token) { - token = token.replace(/t(ia|io)/g, 'x$1'); - token = token.replace(/th/, '0'); - - return token; -} - -function dropT(token) { - return token.replace(/tch/g, 'ch'); -} - -function transformV(token) { - return token.replace(/v/g, 'f'); -} - -function transformWH(token) { - return token.replace(/^wh/, 'w'); -} - -function dropW(token) { - return token.replace(/w([^aeiou]|$)/g, '$1'); -} - -function transformX(token) { - token = token.replace(/^x/, 's'); - token = token.replace(/x/g, 'ks'); - return token; -} - -function dropY(token) { - return token.replace(/y([^aeiou]|$)/g, '$1'); -} - -function transformZ(token) { - return token.replace(/z/, 's'); -} - -function dropVowels(token) { - return token.charAt(0) + token.substr(1, token.length).replace(/[aeiou]/g, ''); -} - -var Metaphone = new Phonetic(); -module.exports = Metaphone; - -Metaphone.process = function(token, maxLength) { - maxLength == maxLength || 32; - token = token.toLowerCase(); - token = dedup(token); - token = dropInitialLetters(token); - token = dropBafterMAtEnd(token); - token = transformCK(token); - token = cTransform(token); - token = dTransform(token); - token = dropG(token); - token = transformG(token); - token = dropH(token); - token = transformPH(token); - token = transformQ(token); - token = transformS(token); - token = transformX(token); - token = transformT(token); - token = dropT(token); - token = transformV(token); - token = transformWH(token); - token = dropW(token); - token = dropY(token); - token = transformZ(token); - token = dropVowels(token); - - token.toUpperCase(); - if(token.length >= maxLength) - token = token.substring(0, maxLength); - - return token.toUpperCase(); -}; - -// expose functions for testing -Metaphone.dedup = dedup; -Metaphone.dropInitialLetters = dropInitialLetters; -Metaphone.dropBafterMAtEnd = dropBafterMAtEnd; -Metaphone.cTransform = cTransform; -Metaphone.dTransform = dTransform; -Metaphone.dropG = dropG; -Metaphone.transformG = transformG; -Metaphone.dropH = dropH; -Metaphone.transformCK = transformCK; -Metaphone.transformPH = transformPH; -Metaphone.transformQ = transformQ; -Metaphone.transformS = transformS; -Metaphone.transformT = transformT; -Metaphone.dropT = dropT; -Metaphone.transformV = transformV; -Metaphone.transformWH = transformWH; -Metaphone.dropW = dropW; -Metaphone.transformX = transformX; -Metaphone.dropY = dropY; -Metaphone.transformZ = transformZ; -Metaphone.dropVowels = dropVowels; - -})() },{"./phonetic":44}],5:[function(require,module,exports){ (function(){/* Copyright (c) 2011, Chris Umbel @@ -2118,6 +1931,196 @@ DoubleMetaphone.process = process; DoubleMetaphone.isVowel = isVowel; })() +},{"./phonetic":44}],4:[function(require,module,exports){ +(function(){/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var Phonetic = require('./phonetic'); + +function dedup(token) { + return token.replace(/([^c])\1/g, '$1'); +} + +function dropInitialLetters(token) { + if(token.match(/^(kn|gn|pn|ae|wr)/)) + return token.substr(1, token.length - 1); + + return token; +} + +function dropBafterMAtEnd(token) { + return token.replace(/mb$/, 'm'); +} + +function cTransform(token) { + token = token.replace(/([^s]|^)(c)(h)/g, '$1x$3').trim(); + token = token.replace(/cia/g, 'xia'); + token = token.replace(/c(i|e|y)/g, 's$1'); + token = token.replace(/c/g, 'k'); + + return token; +} + +function dTransform(token) { + token = token.replace(/d(ge|gy|gi)/g, 'j$1'); + token = token.replace(/d/g, 't'); + + return token; +} + +function dropG(token) { + token = token.replace(/gh(^$|[^aeiou])/g, 'h$1'); + token = token.replace(/g(n|ned)$/g, '$1'); + + return token; +} + +function transformG(token) { + token = token.replace(/([^g]|^)(g)(i|e|y)/g, '$1j$3'); + token = token.replace(/gg/g, 'g'); + token = token.replace(/g/g, 'k'); + + return token; +} + +function dropH(token) { + return token.replace(/([aeiou])h([^aeiou])/g, '$1$2'); +} + +function transformCK(token) { + return token.replace(/ck/g, 'k'); +} +function transformPH(token) { + return token.replace(/ph/g, 'f'); +} + +function transformQ(token) { + return token.replace(/q/g, 'k'); +} + +function transformS(token) { + return token.replace(/s(h|io|ia)/g, 'x$1'); +} + +function transformT(token) { + token = token.replace(/t(ia|io)/g, 'x$1'); + token = token.replace(/th/, '0'); + + return token; +} + +function dropT(token) { + return token.replace(/tch/g, 'ch'); +} + +function transformV(token) { + return token.replace(/v/g, 'f'); +} + +function transformWH(token) { + return token.replace(/^wh/, 'w'); +} + +function dropW(token) { + return token.replace(/w([^aeiou]|$)/g, '$1'); +} + +function transformX(token) { + token = token.replace(/^x/, 's'); + token = token.replace(/x/g, 'ks'); + return token; +} + +function dropY(token) { + return token.replace(/y([^aeiou]|$)/g, '$1'); +} + +function transformZ(token) { + return token.replace(/z/, 's'); +} + +function dropVowels(token) { + return token.charAt(0) + token.substr(1, token.length).replace(/[aeiou]/g, ''); +} + +var Metaphone = new Phonetic(); +module.exports = Metaphone; + +Metaphone.process = function(token, maxLength) { + maxLength == maxLength || 32; + token = token.toLowerCase(); + token = dedup(token); + token = dropInitialLetters(token); + token = dropBafterMAtEnd(token); + token = transformCK(token); + token = cTransform(token); + token = dTransform(token); + token = dropG(token); + token = transformG(token); + token = dropH(token); + token = transformPH(token); + token = transformQ(token); + token = transformS(token); + token = transformX(token); + token = transformT(token); + token = dropT(token); + token = transformV(token); + token = transformWH(token); + token = dropW(token); + token = dropY(token); + token = transformZ(token); + token = dropVowels(token); + + token.toUpperCase(); + if(token.length >= maxLength) + token = token.substring(0, maxLength); + + return token.toUpperCase(); +}; + +// expose functions for testing +Metaphone.dedup = dedup; +Metaphone.dropInitialLetters = dropInitialLetters; +Metaphone.dropBafterMAtEnd = dropBafterMAtEnd; +Metaphone.cTransform = cTransform; +Metaphone.dTransform = dTransform; +Metaphone.dropG = dropG; +Metaphone.transformG = transformG; +Metaphone.dropH = dropH; +Metaphone.transformCK = transformCK; +Metaphone.transformPH = transformPH; +Metaphone.transformQ = transformQ; +Metaphone.transformS = transformS; +Metaphone.transformT = transformT; +Metaphone.dropT = dropT; +Metaphone.transformV = transformV; +Metaphone.transformWH = transformWH; +Metaphone.dropW = dropW; +Metaphone.transformX = transformX; +Metaphone.dropY = dropY; +Metaphone.transformZ = transformZ; +Metaphone.dropVowels = dropVowels; + +})() },{"./phonetic":44}],6:[function(require,module,exports){ (function(){/* Copyright (c) 2012, Alexy Maslenninkov @@ -2577,7 +2580,41 @@ PorterStemmer.step5a = step5a; PorterStemmer.step5b = step5b; })() -},{"./stemmer":45}],9:[function(require,module,exports){ +},{"./stemmer":45}],8:[function(require,module,exports){ +/*
+Copyright (c) 2011, Chris Umbel
+Farsi Porter Stemmer by Fardin Koochaki <me@fardinak.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+var Stemmer = require('./stemmer_fa');
+
+var PorterStemmer = new Stemmer();
+module.exports = PorterStemmer;
+
+// disabled stemming for Farsi
+// Farsi stemming will be supported soon
+PorterStemmer.stem = function(token) {
+ return token;
+}; +},{"./stemmer_fa":46}],9:[function(require,module,exports){ /* Copyright (c) 2012, Polyakov Vladimir, Chris Umbel @@ -2730,41 +2767,7 @@ PorterStemmer.stem = function(token) { return head + superlativeResult; }; -},{"./stemmer_ru":46}],8:[function(require,module,exports){ -/*
-Copyright (c) 2011, Chris Umbel
-Farsi Porter Stemmer by Fardin Koochaki <me@fardinak.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-var Stemmer = require('./stemmer_fa');
-
-var PorterStemmer = new Stemmer();
-module.exports = PorterStemmer;
-
-// disabled stemming for Farsi
-// Farsi stemming will be supported soon
-PorterStemmer.stem = function(token) {
- return token;
-}; -},{"./stemmer_fa":47}],10:[function(require,module,exports){ +},{"./stemmer_ru":47}],10:[function(require,module,exports){ /* Copyright (c) 2012, David Przybilla, Chris Umbel @@ -2988,7 +2991,83 @@ PorterStemmer.stem = function(token) { }; -},{"./stemmer_es":48}],11:[function(require,module,exports){ +},{"./stemmer_es":48}],12:[function(require,module,exports){ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var Stemmer = require('./stemmer'); +var ruleTable = require('./lancaster_rules').rules; + +function acceptable(candidate) { + if (candidate.match(/^[aeiou]/)) + return (candidate.length > 1); + else + return (candidate.length > 2 && candidate.match(/[aeiouy]/)); +} + +// take a token, look up the applicatble rule section and attempt some stemming! +function applyRuleSection(token, intact) { + var section = token.substr( - 1); + var rules = ruleTable[section]; + + if (rules) { + for (var i = 0; i < rules.length; i++) { + if ((intact || !rules[i].intact) + // only apply intact rules to intact tokens + && token.substr(0 - rules[i].pattern.length) == rules[i].pattern) { + // hack off only as much as the rule indicates + var result = token.substr(0, token.length - rules[i].size); + + // if the rules wants us to apply an appendage do so + if (rules[i].appendage) + result += rules[i].appendage; + + if (acceptable(result)) { + token = result; + + // see what the rules wants to do next + if (rules[i].continuation) { + // this rule thinks there still might be stem left. keep at it. + // since we've applied a change we'll pass false in for intact + return applyRuleSection(result, false); + } else { + // the rule thinks we're done stemming. drop out. + return result; + } + } + } + } + } + + return token; +} + +var LancasterStemmer = new Stemmer(); +module.exports = LancasterStemmer; + +LancasterStemmer.stem = function(token) { + return applyRuleSection(token.toLowerCase(), true); +} +},{"./stemmer":45,"./lancaster_rules":49}],11:[function(require,module,exports){ /*
Copyright (c) 2012, Leonardo Fenu, Chris Umbel
@@ -3222,83 +3301,7 @@ PorterStemmer.stem = function(token) { return token.toLowerCase();
}; -},{"./stemmer_it":49}],12:[function(require,module,exports){ -/* -Copyright (c) 2011, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -var Stemmer = require('./stemmer'); -var ruleTable = require('./lancaster_rules').rules; - -function acceptable(candidate) { - if (candidate.match(/^[aeiou]/)) - return (candidate.length > 1); - else - return (candidate.length > 2 && candidate.match(/[aeiouy]/)); -} - -// take a token, look up the applicatble rule section and attempt some stemming! -function applyRuleSection(token, intact) { - var section = token.substr( - 1); - var rules = ruleTable[section]; - - if (rules) { - for (var i = 0; i < rules.length; i++) { - if ((intact || !rules[i].intact) - // only apply intact rules to intact tokens - && token.substr(0 - rules[i].pattern.length) == rules[i].pattern) { - // hack off only as much as the rule indicates - var result = token.substr(0, token.length - rules[i].size); - - // if the rules wants us to apply an appendage do so - if (rules[i].appendage) - result += rules[i].appendage; - - if (acceptable(result)) { - token = result; - - // see what the rules wants to do next - if (rules[i].continuation) { - // this rule thinks there still might be stem left. keep at it. - // since we've applied a change we'll pass false in for intact - return applyRuleSection(result, false); - } else { - // the rule thinks we're done stemming. drop out. - return result; - } - } - } - } - } - - return token; -} - -var LancasterStemmer = new Stemmer(); -module.exports = LancasterStemmer; - -LancasterStemmer.stem = function(token) { - return applyRuleSection(token.toLowerCase(), true); -} -},{"./lancaster_rules":50,"./stemmer":45}],13:[function(require,module,exports){ +},{"./stemmer_it":50}],13:[function(require,module,exports){ /* Copyright (c) 2012, Guillaume Marty @@ -3438,45 +3441,7 @@ StemmerJa.prototype.attach = function() { module.exports = StemmerJa; -},{"../tokenizers/tokenizer_ja":21,"../util/stopwords_ja":51}],16:[function(require,module,exports){ -/* -Copyright (c) 2011, Chris Umbel,David Przybilla - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -var Tokenizer = require('./tokenizer'), - util = require('util'); - -var AggressiveTokenizer = function() { - Tokenizer.call(this); -}; -util.inherits(AggressiveTokenizer, Tokenizer); - -module.exports = AggressiveTokenizer; - -AggressiveTokenizer.prototype.tokenize = function(text) { - // break a string up into an array of tokens by anything non-word - return this.trim(text.split(/\W+/)); -}; - -},{"util":40,"./tokenizer":52}],14:[function(require,module,exports){ +},{"../tokenizers/tokenizer_ja":21,"../util/stopwords_ja":51}],14:[function(require,module,exports){ /*
Copyright (c) 2011, Chris Umbel
Farsi Aggressive Tokenizer by Fardin Koochaki <me@fardinak.com>
@@ -3526,6 +3491,44 @@ AggressiveTokenizer.prototype.tokenize = function(text) { return this.clearEmptyString(text.split(/\s+/));
};
+},{"util":40,"./tokenizer":52}],16:[function(require,module,exports){ +/* +Copyright (c) 2011, Chris Umbel,David Przybilla + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var Tokenizer = require('./tokenizer'), + util = require('util'); + +var AggressiveTokenizer = function() { + Tokenizer.call(this); +}; +util.inherits(AggressiveTokenizer, Tokenizer); + +module.exports = AggressiveTokenizer; + +AggressiveTokenizer.prototype.tokenize = function(text) { + // break a string up into an array of tokens by anything non-word + return this.trim(text.split(/\W+/)); +}; + },{"util":40,"./tokenizer":52}],15:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -5207,7 +5210,7 @@ exports.replacer = replacer; exports.flip = flip;
exports.merge = merge;
-},{}],50:[function(require,module,exports){ +},{}],49:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -5999,59 +6002,6 @@ exports.rules = { }; -},{}],52:[function(require,module,exports){ -/* -Copyright (c) 2011, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -/** - * \@todo Use .bind() in Tokenizer.prototype.attach(). - */ - -var Tokenizer = function() { -}; - -Tokenizer.prototype.trim = function(array) { - if (array[array.length - 1] == '') - array.pop(); - - if (array[0] == '') - array.shift(); - - return array; -}; - -// Expose an attach function that will patch String with new methods. -Tokenizer.prototype.attach = function() { - var self = this; - - String.prototype.tokenize = function() { - return self.tokenize(this); - } -}; - -Tokenizer.prototype.tokenize = function() {}; - -module.exports = Tokenizer; - },{}],51:[function(require,module,exports){ // Original copyright: /* @@ -6113,6 +6063,59 @@ var words = ['の', 'に', 'は', 'を', 'た', 'が', 'で', 'て', 'と', 'し // tell the world about the noise words. module.exports = words; +},{}],52:[function(require,module,exports){ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/** + * \@todo Use .bind() in Tokenizer.prototype.attach(). + */ + +var Tokenizer = function() { +}; + +Tokenizer.prototype.trim = function(array) { + if (array[array.length - 1] == '') + array.pop(); + + if (array[0] == '') + array.shift(); + + return array; +}; + +// Expose an attach function that will patch String with new methods. +Tokenizer.prototype.attach = function() { + var self = this; + + String.prototype.tokenize = function() { + return self.tokenize(this); + } +}; + +Tokenizer.prototype.tokenize = function() {}; + +module.exports = Tokenizer; + },{}],53:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -6896,67 +6899,7 @@ module.exports = function() { }; })() -},{"../util/stopwords":32,"../tokenizers/aggressive_tokenizer":18}],46:[function(require,module,exports){ -/* -Copyright (c) 2012, Polyakov Vladimir, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -var stopwords = require('../util/stopwords_ru'); -var Tokenizer = require('../tokenizers/aggressive_tokenizer_ru'); - -module.exports = function() { - var stemmer = this; - - stemmer.stem = function(token) { - return token; - }; - - stemmer.tokenizeAndStem = function(text, keepStops) { - var stemmedTokens = []; - - new Tokenizer().tokenize(text).forEach(function(token) { - if (keepStops || stopwords.words.indexOf(token) == -1) { - var resultToken = token.toLowerCase(); - if (resultToken.match(new RegExp('[а-яё0-9]+', 'gi'))) { - resultToken = stemmer.stem(resultToken); - } - stemmedTokens.push(resultToken); - } - }); - - return stemmedTokens; - }; - - stemmer.attach = function() { - String.prototype.stem = function() { - return stemmer.stem(this); - }; - - String.prototype.tokenizeAndStem = function(keepStops) { - return stemmer.tokenizeAndStem(this, keepStops); - }; - }; -} - -},{"../tokenizers/aggressive_tokenizer_ru":15,"../util/stopwords_ru":56}],45:[function(require,module,exports){ +},{"../util/stopwords":32,"../tokenizers/aggressive_tokenizer":18}],45:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -7019,7 +6962,7 @@ module.exports = function() { }; } -},{"../util/stopwords":32,"../tokenizers/aggressive_tokenizer":18}],47:[function(require,module,exports){ +},{"../util/stopwords":32,"../tokenizers/aggressive_tokenizer":18}],46:[function(require,module,exports){ /*
Copyright (c) 2011, Chris Umbel
Farsi Stemmer by Fardin Koochaki <me@fardinak.com>
@@ -7075,7 +7018,67 @@ module.exports = function() { };
}
-},{"../util/stopwords_fa":57,"../tokenizers/aggressive_tokenizer_fa":14}],48:[function(require,module,exports){ +},{"../util/stopwords_fa":56,"../tokenizers/aggressive_tokenizer_fa":14}],47:[function(require,module,exports){ +/* +Copyright (c) 2012, Polyakov Vladimir, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var stopwords = require('../util/stopwords_ru'); +var Tokenizer = require('../tokenizers/aggressive_tokenizer_ru'); + +module.exports = function() { + var stemmer = this; + + stemmer.stem = function(token) { + return token; + }; + + stemmer.tokenizeAndStem = function(text, keepStops) { + var stemmedTokens = []; + + new Tokenizer().tokenize(text).forEach(function(token) { + if (keepStops || stopwords.words.indexOf(token) == -1) { + var resultToken = token.toLowerCase(); + if (resultToken.match(new RegExp('[а-яё0-9]+', 'gi'))) { + resultToken = stemmer.stem(resultToken); + } + stemmedTokens.push(resultToken); + } + }); + + return stemmedTokens; + }; + + stemmer.attach = function() { + String.prototype.stem = function() { + return stemmer.stem(this); + }; + + String.prototype.tokenizeAndStem = function(keepStops) { + return stemmer.tokenizeAndStem(this, keepStops); + }; + }; +} + +},{"../util/stopwords_ru":57,"../tokenizers/aggressive_tokenizer_ru":15}],48:[function(require,module,exports){ /* Copyright (c) 2012, David Przybilla, Chris Umbel @@ -7135,7 +7138,7 @@ module.exports = function() { }; } -},{"../util/stopwords_es":58,"../tokenizers/aggressive_tokenizer_es":16}],49:[function(require,module,exports){ +},{"../util/stopwords_es":58,"../tokenizers/aggressive_tokenizer_es":16}],50:[function(require,module,exports){ var stopwords = require('../util/stopwords_it');
var Tokenizer = require('../tokenizers/aggressive_tokenizer_it');
@@ -11387,7 +11390,7 @@ IndexFile.prototype._findAt = findAt; module.exports = IndexFile; })(require("__browserify_buffer").Buffer) -},{"fs":42,"util":40,"./wordnet_file":63,"__browserify_buffer":61}],57:[function(require,module,exports){ +},{"fs":42,"util":40,"./wordnet_file":63,"__browserify_buffer":61}],56:[function(require,module,exports){ /*
Copyright (c) 2011, Chris Umbel
Farsi Stop Words by Fardin Koochaki <me@fardinak.com>
@@ -11427,7 +11430,7 @@ var words = [ // tell the world about the noise words.
exports.words = words;
-},{}],56:[function(require,module,exports){ +},{}],57:[function(require,module,exports){ /* Copyright (c) 2011, Polyakov Vladimir, Chris Umbel @@ -11470,6 +11473,44 @@ var words = [ // tell the world about the noise words. exports.words = words; +},{}],58:[function(require,module,exports){ +/* +Copyright (c) 2011, David Przybilla, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +// a list of commonly used words that have little meaning and can be excluded +// from analysis. +var words = [ + 'a','un','el','ella','y','sobre','de','la','que','en', + 'los','del','se','las','por','un','para','con','no', + 'una','su','al','lo','como','más','pero','sus','le', + 'ya','o','porque','cuando','muy','sin','sobre','también', + 'me','hasta','donde','quien','desde','nos','durante','uno', + 'ni','contra','ese','eso','mí','qué','otro','él','cual', + 'poco','mi','tú','te','ti','sí', + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_']; + +// tell the world about the noise words. +exports.words = words; + },{}],59:[function(require,module,exports){ /*
Copyright (c) 2011, David Przybilla, Chris Umbel
@@ -11524,44 +11565,6 @@ var words = [ // tell the world about the noise words.
exports.words = words;
-},{}],58:[function(require,module,exports){ -/* -Copyright (c) 2011, David Przybilla, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -// a list of commonly used words that have little meaning and can be excluded -// from analysis. -var words = [ - 'a','un','el','ella','y','sobre','de','la','que','en', - 'los','del','se','las','por','un','para','con','no', - 'una','su','al','lo','como','más','pero','sus','le', - 'ya','o','porque','cuando','muy','sin','sobre','también', - 'me','hasta','donde','quien','desde','nos','durante','uno', - 'ni','contra','ese','eso','mí','qué','otro','él','cual', - 'poco','mi','tú','te','ti','sí', - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_']; - -// tell the world about the noise words. -exports.words = words; - },{}],63:[function(require,module,exports){ (function(Buffer){/* Copyright (c) 2011, Chris Umbel @@ -11634,9 +11637,9 @@ WordNetFile.appendLineChar = appendLineChar; module.exports = WordNetFile; })(require("__browserify_buffer").Buffer) -},{"fs":42,"path":65,"util":40,"__browserify_buffer":61}],20:[function(require,module,exports){ +},{"fs":42,"path":65,"util":40,"__browserify_buffer":61}],22:[function(require,module,exports){ /* -Copyright (c) 2011, Rob Ellis, Chris Umbel +Copyright (c) 2011, Chris Umbel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -11657,60 +11660,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var Tokenizer = require('./tokenizer'), - util = require("util"), - _ = require('underscore')._; - -var contractions2 = [ - /(.)('ll|'re|'ve|n't|'s|'m|'d)\b/ig, - /\b(can)(not)\b/ig, - /\b(D)('ye)\b/ig, - /\b(Gim)(me)\b/ig, - /\b(Gon)(na)\b/ig, - /\b(Got)(ta)\b/ig, - /\b(Lem)(me)\b/ig, - /\b(Mor)('n)\b/ig, - /\b(T)(is)\b/ig, - /\b(T)(was)\b/ig, - /\b(Wan)(na)\b/ig]; - -var contractions3 = [ - /\b(Whad)(dd)(ya)\b/ig, - /\b(Wha)(t)(cha)\b/ig -]; +var PorterStemmer = require('../stemmers/porter_stemmer'), +util = require('util'), +Classifier = require('./classifier'), +ApparatusBayesClassifier = require('apparatus').BayesClassifier; -var TreebankWordTokenizer = function() { +var BayesClassifier = function(stemmer) { + Classifier.call(this, new ApparatusBayesClassifier(), stemmer); }; -util.inherits(TreebankWordTokenizer, Tokenizer); - -TreebankWordTokenizer.prototype.tokenize = function(text) { - contractions2.forEach(function(regexp) { - text = text.replace(regexp,"$1 $2"); - }); - - contractions3.forEach(function(regexp) { - text = text.replace(regexp,"$1 $2 $3"); - }); +util.inherits(BayesClassifier, Classifier); - // most punctuation - text = text.replace(/([^\w\.\'\-\/\+\<\>,&])/g, " $1 "); +function restore(classifier, stemmer) { + classifier = Classifier.restore(classifier, stemmer); + classifier.__proto__ = BayesClassifier.prototype; + classifier.classifier = ApparatusBayesClassifier.restore(classifier.classifier); - // commas if followed by space - text = text.replace(/(,\s)/g, " $1"); + return classifier; +} - // single quotes if followed by a space - text = text.replace(/('\s)/g, " $1"); +function load(filename, stemmer, callback) { + Classifier.load(filename, function(err, classifier) { + callback(err, restore(classifier, stemmer)); + }); +} - // periods before newline or end of string - text = text.replace(/\. *(\n|$)/g, " . "); - - return _.without(text.split(/\s+/), ''); -}; +BayesClassifier.restore = restore; +BayesClassifier.load = load; -module.exports = TreebankWordTokenizer; +module.exports = BayesClassifier; -},{"util":40,"./tokenizer":52,"underscore":66}],19:[function(require,module,exports){ +},{"util":40,"../stemmers/porter_stemmer":7,"./classifier":60,"apparatus":66}],19:[function(require,module,exports){ /* Copyright (c) 2011, Rob Ellis, Chris Umbel @@ -11798,9 +11778,9 @@ var WordPunctTokenizer = function(options) { util.inherits(WordPunctTokenizer, RegexpTokenizer); exports.WordPunctTokenizer = WordPunctTokenizer; -},{"util":40,"./tokenizer":52,"underscore":66}],22:[function(require,module,exports){ +},{"util":40,"./tokenizer":52,"underscore":67}],20:[function(require,module,exports){ /* -Copyright (c) 2011, Chris Umbel +Copyright (c) 2011, Rob Ellis, Chris Umbel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -11821,37 +11801,60 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var PorterStemmer = require('../stemmers/porter_stemmer'), -util = require('util'), -Classifier = require('./classifier'), -ApparatusBayesClassifier = require('apparatus').BayesClassifier; +var Tokenizer = require('./tokenizer'), + util = require("util"), + _ = require('underscore')._; -var BayesClassifier = function(stemmer) { - Classifier.call(this, new ApparatusBayesClassifier(), stemmer); -}; +var contractions2 = [ + /(.)('ll|'re|'ve|n't|'s|'m|'d)\b/ig, + /\b(can)(not)\b/ig, + /\b(D)('ye)\b/ig, + /\b(Gim)(me)\b/ig, + /\b(Gon)(na)\b/ig, + /\b(Got)(ta)\b/ig, + /\b(Lem)(me)\b/ig, + /\b(Mor)('n)\b/ig, + /\b(T)(is)\b/ig, + /\b(T)(was)\b/ig, + /\b(Wan)(na)\b/ig]; -util.inherits(BayesClassifier, Classifier); +var contractions3 = [ + /\b(Whad)(dd)(ya)\b/ig, + /\b(Wha)(t)(cha)\b/ig +]; -function restore(classifier, stemmer) { - classifier = Classifier.restore(classifier, stemmer); - classifier.__proto__ = BayesClassifier.prototype; - classifier.classifier = ApparatusBayesClassifier.restore(classifier.classifier); +var TreebankWordTokenizer = function() { +}; - return classifier; -} +util.inherits(TreebankWordTokenizer, Tokenizer); -function load(filename, stemmer, callback) { - Classifier.load(filename, function(err, classifier) { - callback(err, restore(classifier, stemmer)); +TreebankWordTokenizer.prototype.tokenize = function(text) { + contractions2.forEach(function(regexp) { + text = text.replace(regexp,"$1 $2"); + }); + + contractions3.forEach(function(regexp) { + text = text.replace(regexp,"$1 $2 $3"); }); -} -BayesClassifier.restore = restore; -BayesClassifier.load = load; + // most punctuation + text = text.replace(/([^\w\.\'\-\/\+\<\>,&])/g, " $1 "); -module.exports = BayesClassifier; + // commas if followed by space + text = text.replace(/(,\s)/g, " $1"); -},{"util":40,"../stemmers/porter_stemmer":7,"./classifier":60,"apparatus":67}],23:[function(require,module,exports){ + // single quotes if followed by a space + text = text.replace(/('\s)/g, " $1"); + + // periods before newline or end of string + text = text.replace(/\. *(\n|$)/g, " . "); + + return _.without(text.split(/\s+/), ''); +}; + +module.exports = TreebankWordTokenizer; + +},{"util":40,"./tokenizer":52,"underscore":67}],23:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -11913,7 +11916,7 @@ LogisticRegressionClassifier.load = load; module.exports = LogisticRegressionClassifier; -},{"util":40,"../stemmers/porter_stemmer":7,"./classifier":60,"apparatus":67}],65:[function(require,module,exports){ +},{"util":40,"../stemmers/porter_stemmer":7,"./classifier":60,"apparatus":66}],65:[function(require,module,exports){ (function(process){function filter (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { @@ -12091,128 +12094,7 @@ exports.relative = function(from, to) { }; })(require("__browserify_process")) -},{"__browserify_process":43}],30:[function(require,module,exports){ -/* -Copyright (c) 2011, Rob Ellis, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -var _ = require("underscore")._, - Tokenizer = require('../tokenizers/regexp_tokenizer').WordTokenizer, - tokenizer = new Tokenizer(), - stopwords = require('../util/stopwords').words, - fs = require('fs'); - -function buildDocument(text, key) { - var stopOut; - - if(typeof text === 'string') { - text = tokenizer.tokenize(text.toLowerCase()); - stopOut = true; - } else if(!_.isArray(text)) { - return text; - stopOut = false; - } - - return text.reduce(function(document, term) { - if(!stopOut || stopwords.indexOf(term) < 0) - document[term] = (document[term] ? document[term] + 1 : 1); - - return document; - }, {__key: key}); -} - -function tf(term, document) { - return document[term] ? document[term]: 0; -} - -function documentHasTerm(term, document) { - return document[term] && document[term] > 0; -} - -function TfIdf(deserialized) { - if(deserialized) - this.documents = deserialized.documents; - else - this.documents = []; -} - -module.exports = TfIdf; -TfIdf.tf = tf; - -TfIdf.prototype.idf = function(term) { - var docsWithTerm = this.documents.reduce(function(count, document) { - return count + (documentHasTerm(term, document) ? 1 : 0); - }, 1); - - return Math.log(this.documents.length + 1 / docsWithTerm /* inited to 1 so - no addition needed */); -}; - -TfIdf.prototype.addDocument = function(document, key) { - this.documents.push(buildDocument(document, key)); -}; - -TfIdf.prototype.addFileSync = function(path, encoding, key) { - if(encoding) - encoding = 'UTF-8'; - - var document = fs.readFileSync(path, 'UTF-8'); - this.documents.push(buildDocument(document, key)); -}; - -TfIdf.prototype.tfidf = function(terms, d) { - var _this = this; - - if(!_.isArray(terms)) - terms = tokenizer.tokenize(terms.toString().toLowerCase()); - - return terms.reduce(function(value, term) { - return value + (tf(term, _this.documents[d]) * _this.idf(term)); - }, 0.0); -}; - -TfIdf.prototype.listTerms = function(d) { - var terms = []; - - for(var term in this.documents[d]) { - terms.push({term: term, tfidf: this.tfidf(term, d)}) - } - - return terms.sort(function(x, y) { return y.tfidf - x.tfidf }); -} - -TfIdf.prototype.tfidfs = function(terms, callback) { - var tfidfs = new Array(this.documents.length); - - for(var i = 0; i < this.documents.length; i++) { - tfidfs[i] = this.tfidf(terms, i); - - if(callback) - callback(i, tfidfs[i], this.documents[i].__key); - } - - return tfidfs; -}; - -},{"fs":42,"../tokenizers/regexp_tokenizer":19,"../util/stopwords":32,"underscore":66}],33:[function(require,module,exports){ +},{"__browserify_process":43}],33:[function(require,module,exports){ /* Copyright (c) 2011, Rob Ellis, Chris Umbel @@ -12268,7 +12150,7 @@ var ngrams = function(sequence, n) { } -},{"../tokenizers/regexp_tokenizer":19,"underscore":66}],31:[function(require,module,exports){ +},{"../tokenizers/regexp_tokenizer":19,"underscore":67}],31:[function(require,module,exports){ /* Copyright (c) 2011, Rob Ellis, Chris Umbel @@ -12443,7 +12325,128 @@ Sentences.prototype.type = function(callback) { module.exports = Sentences; -},{"underscore":66}],66:[function(require,module,exports){ +},{"underscore":67}],30:[function(require,module,exports){ +/* +Copyright (c) 2011, Rob Ellis, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var _ = require("underscore")._, + Tokenizer = require('../tokenizers/regexp_tokenizer').WordTokenizer, + tokenizer = new Tokenizer(), + stopwords = require('../util/stopwords').words, + fs = require('fs'); + +function buildDocument(text, key) { + var stopOut; + + if(typeof text === 'string') { + text = tokenizer.tokenize(text.toLowerCase()); + stopOut = true; + } else if(!_.isArray(text)) { + return text; + stopOut = false; + } + + return text.reduce(function(document, term) { + if(!stopOut || stopwords.indexOf(term) < 0) + document[term] = (document[term] ? document[term] + 1 : 1); + + return document; + }, {__key: key}); +} + +function tf(term, document) { + return document[term] ? document[term]: 0; +} + +function documentHasTerm(term, document) { + return document[term] && document[term] > 0; +} + +function TfIdf(deserialized) { + if(deserialized) + this.documents = deserialized.documents; + else + this.documents = []; +} + +module.exports = TfIdf; +TfIdf.tf = tf; + +TfIdf.prototype.idf = function(term) { + var docsWithTerm = this.documents.reduce(function(count, document) { + return count + (documentHasTerm(term, document) ? 1 : 0); + }, 1); + + return Math.log(this.documents.length + 1 / docsWithTerm /* inited to 1 so + no addition needed */); +}; + +TfIdf.prototype.addDocument = function(document, key) { + this.documents.push(buildDocument(document, key)); +}; + +TfIdf.prototype.addFileSync = function(path, encoding, key) { + if(encoding) + encoding = 'UTF-8'; + + var document = fs.readFileSync(path, 'UTF-8'); + this.documents.push(buildDocument(document, key)); +}; + +TfIdf.prototype.tfidf = function(terms, d) { + var _this = this; + + if(!_.isArray(terms)) + terms = tokenizer.tokenize(terms.toString().toLowerCase()); + + return terms.reduce(function(value, term) { + return value + (tf(term, _this.documents[d]) * _this.idf(term)); + }, 0.0); +}; + +TfIdf.prototype.listTerms = function(d) { + var terms = []; + + for(var term in this.documents[d]) { + terms.push({term: term, tfidf: this.tfidf(term, d)}) + } + + return terms.sort(function(x, y) { return y.tfidf - x.tfidf }); +} + +TfIdf.prototype.tfidfs = function(terms, callback) { + var tfidfs = new Array(this.documents.length); + + for(var i = 0; i < this.documents.length; i++) { + tfidfs[i] = this.tfidf(terms, i); + + if(callback) + callback(i, tfidfs[i], this.documents[i].__key); + } + + return tfidfs; +}; + +},{"fs":42,"../tokenizers/regexp_tokenizer":19,"../util/stopwords":32,"underscore":67}],67:[function(require,module,exports){ (function(){// Underscore.js 1.4.4 // http://underscorejs.org // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. @@ -13850,13 +13853,13 @@ exports.path = require('path').join(__dirname, "dict"); exports.files = require('fs').readdirSync(exports.path);
})("/node_modules/WNdb") -},{"path":65,"fs":42}],67:[function(require,module,exports){ +},{"path":65,"fs":42}],66:[function(require,module,exports){ exports.BayesClassifier = require('./classifier/bayes_classifier'); exports.LogisticRegressionClassifier = require('./classifier/logistic_regression_classifier'); exports.KMeans = require('./clusterer/kmeans'); -},{"./classifier/bayes_classifier":69,"./clusterer/kmeans":70,"./classifier/logistic_regression_classifier":71}],69:[function(require,module,exports){ +},{"./classifier/bayes_classifier":69,"./classifier/logistic_regression_classifier":70,"./clusterer/kmeans":71}],69:[function(require,module,exports){ /* Copyright (c) 2011, Chris Umbel @@ -14064,127 +14067,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var Sylvester = require('sylvester'), -Matrix = Sylvester.Matrix, -Vector = Sylvester.Vector; - -function KMeans(Observations) { - if(!Observations.elements) - Observations = $M(Observations); - - this.Observations = Observations; -} - -// create an initial centroid matrix with initial values between -// 0 and the max of feature data X. -function createCentroids(k) { - var Centroid = []; - var maxes = this.Observations.maxColumns(); - //console.log(maxes); - - for(var i = 1; i <= k; i++) { - var centroid = []; - - for(var j = 1; j <= this.Observations.cols(); j++) { - centroid.push(Math.random() * maxes.e(j)); - } - - Centroid.push(centroid); - } - - //console.log(centroid) - - return $M(Centroid); -} - -// get the euclidian distance between the feature data X and -// a given centroid matrix C. -function distanceFrom(Centroids) { - var distances = []; - - for(var i = 1; i <= this.Observations.rows(); i++) { - var distance = []; - - for(var j = 1; j <= Centroids.rows(); j++) { - distance.push(this.Observations.row(i).distanceFrom(Centroids.row(j))); - } - - distances.push(distance); - } - - return $M(distances); -} - -// categorize the feature data X into k clusters. return a vector -// containing the results. -function cluster(k) { - var Centroids = this.createCentroids(k); - var LastDistances = Matrix.Zero(this.Observations.rows(), this.Observations.cols()); - var Distances = this.distanceFrom(Centroids); - var Groups; - - while(!(LastDistances.eql(Distances))) { - Groups = Distances.minColumnIndexes(); - LastDistances = Distances; - - var newCentroids = []; - - for(var i = 1; i <= Centroids.rows(); i++) { - var centroid = []; - - for(var j = 1; j <= Centroids.cols(); j++) { - var sum = 0; - var count = 0; - - for(var l = 1; l <= this.Observations.rows(); l++) { - if(Groups.e(l) == i) { - count++; - sum += this.Observations.e(l, j); - } - } - - centroid.push(sum / count); - } - - newCentroids.push(centroid); - } - - Centroids = $M(newCentroids); - Distances = this.distanceFrom(Centroids); - } - - return Groups; -} - -KMeans.prototype.createCentroids = createCentroids; -KMeans.prototype.distanceFrom = distanceFrom; -KMeans.prototype.cluster = cluster; - -module.exports = KMeans; - -},{"sylvester":73}],71:[function(require,module,exports){ -/* -Copyright (c) 2011, Chris Umbel - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - var util = require('util'), Classifier = require('./classifier'); @@ -14352,7 +14234,128 @@ LogisticRegressionClassifier.restore = restore; module.exports = LogisticRegressionClassifier; -},{"util":40,"./classifier":72,"sylvester":73}],73:[function(require,module,exports){ +},{"util":40,"./classifier":72,"sylvester":73}],71:[function(require,module,exports){ +/* +Copyright (c) 2011, Chris Umbel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +var Sylvester = require('sylvester'), +Matrix = Sylvester.Matrix, +Vector = Sylvester.Vector; + +function KMeans(Observations) { + if(!Observations.elements) + Observations = $M(Observations); + + this.Observations = Observations; +} + +// create an initial centroid matrix with initial values between +// 0 and the max of feature data X. +function createCentroids(k) { + var Centroid = []; + var maxes = this.Observations.maxColumns(); + //console.log(maxes); + + for(var i = 1; i <= k; i++) { + var centroid = []; + + for(var j = 1; j <= this.Observations.cols(); j++) { + centroid.push(Math.random() * maxes.e(j)); + } + + Centroid.push(centroid); + } + + //console.log(centroid) + + return $M(Centroid); +} + +// get the euclidian distance between the feature data X and +// a given centroid matrix C. +function distanceFrom(Centroids) { + var distances = []; + + for(var i = 1; i <= this.Observations.rows(); i++) { + var distance = []; + + for(var j = 1; j <= Centroids.rows(); j++) { + distance.push(this.Observations.row(i).distanceFrom(Centroids.row(j))); + } + + distances.push(distance); + } + + return $M(distances); +} + +// categorize the feature data X into k clusters. return a vector +// containing the results. +function cluster(k) { + var Centroids = this.createCentroids(k); + var LastDistances = Matrix.Zero(this.Observations.rows(), this.Observations.cols()); + var Distances = this.distanceFrom(Centroids); + var Groups; + + while(!(LastDistances.eql(Distances))) { + Groups = Distances.minColumnIndexes(); + LastDistances = Distances; + + var newCentroids = []; + + for(var i = 1; i <= Centroids.rows(); i++) { + var centroid = []; + + for(var j = 1; j <= Centroids.cols(); j++) { + var sum = 0; + var count = 0; + + for(var l = 1; l <= this.Observations.rows(); l++) { + if(Groups.e(l) == i) { + count++; + sum += this.Observations.e(l, j); + } + } + + centroid.push(sum / count); + } + + newCentroids.push(centroid); + } + + Centroids = $M(newCentroids); + Distances = this.distanceFrom(Centroids); + } + + return Groups; +} + +KMeans.prototype.createCentroids = createCentroids; +KMeans.prototype.distanceFrom = distanceFrom; +KMeans.prototype.cluster = cluster; + +module.exports = KMeans; + +},{"sylvester":73}],73:[function(require,module,exports){ (function(global){// Copyright (c) 2011, Chris Umbel exports.Vector = require('./vector'); @@ -14367,7 +14370,7 @@ exports.Line.Segment = require('./line.segment'); exports.Sylvester = require('./sylvester'); })(window) -},{"./vector":74,"./matrix":75,"./line":76,"./plane":77,"./line.segment":78,"./sylvester":79}],79:[function(require,module,exports){ +},{"./vector":74,"./matrix":75,"./plane":76,"./line":77,"./line.segment":78,"./sylvester":79}],79:[function(require,module,exports){ // Copyright (c) 2011, Chris Umbel, James Coglan // This file is required in order for any other classes to work. Some Vector methods work with the // other Sylvester classes and are useless unless they are included. Other classes such as Line and @@ -14826,239 +14829,6 @@ module.exports = Vector; },{"./sylvester":79,"./matrix":75}],76:[function(require,module,exports){ // Copyright (c) 2011, Chris Umbel, James Coglan -var Vector = require('./vector'); -var Matrix = require('./matrix'); -var Plane = require('./plane'); -var Sylvester = require('./sylvester'); - -// Line class - depends on Vector, and some methods require Matrix and Plane. - -function Line() {} -Line.prototype = { - - // Returns true if the argument occupies the same space as the line - eql: function(line) { - return (this.isParallelTo(line) && this.contains(line.anchor)); - }, - - // Returns a copy of the line - dup: function() { - return Line.create(this.anchor, this.direction); - }, - - // Returns the result of translating the line by the given vector/array - translate: function(vector) { - var V = vector.elements || vector; - return Line.create([ - this.anchor.elements[0] + V[0], - this.anchor.elements[1] + V[1], - this.anchor.elements[2] + (V[2] || 0) - ], this.direction); - }, - - // Returns true if the line is parallel to the argument. Here, 'parallel to' - // means that the argument's direction is either parallel or antiparallel to - // the line's own direction. A line is parallel to a plane if the two do not - // have a unique intersection. - isParallelTo: function(obj) { - if (obj.normal || (obj.start && obj.end)) { return obj.isParallelTo(this); } - var theta = this.direction.angleFrom(obj.direction); - return (Math.abs(theta) <= Sylvester.precision || Math.abs(theta - Math.PI) <= Sylvester.precision); - }, - - // Returns the line's perpendicular distance from the argument, - // which can be a point, a line or a plane - distanceFrom: function(obj) { - if (obj.normal || (obj.start && obj.end)) { return obj.distanceFrom(this); } - if (obj.direction) { - // obj is a line - if (this.isParallelTo(obj)) { return this.distanceFrom(obj.anchor); } - var N = this.direction.cross(obj.direction).toUnitVector().elements; - var A = this.anchor.elements, B = obj.anchor.elements; - return Math.abs((A[0] - B[0]) * N[0] + (A[1] - B[1]) * N[1] + (A[2] - B[2]) * N[2]); - } else { - // obj is a point - var P = obj.elements || obj; - var A = this.anchor.elements, D = this.direction.elements; - var PA1 = P[0] - A[0], PA2 = P[1] - A[1], PA3 = (P[2] || 0) - A[2]; - var modPA = Math.sqrt(PA1*PA1 + PA2*PA2 + PA3*PA3); - if (modPA === 0) return 0; - // Assumes direction vector is normalized - var cosTheta = (PA1 * D[0] + PA2 * D[1] + PA3 * D[2]) / modPA; - var sin2 = 1 - cosTheta*cosTheta; - return Math.abs(modPA * Math.sqrt(sin2 < 0 ? 0 : sin2)); - } - }, - - // Returns true iff the argument is a point on the line, or if the argument - // is a line segment lying within the receiver - contains: function(obj) { - if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } - var dist = this.distanceFrom(obj); - return (dist !== null && dist <= Sylvester.precision); - }, - - // Returns the distance from the anchor of the given point. Negative values are - // returned for points that are in the opposite direction to the line's direction from - // the line's anchor point. - positionOf: function(point) { - if (!this.contains(point)) { return null; } - var P = point.elements || point; - var A = this.anchor.elements, D = this.direction.elements; - return (P[0] - A[0]) * D[0] + (P[1] - A[1]) * D[1] + ((P[2] || 0) - A[2]) * D[2]; - }, - - // Returns true iff the line lies in the given plane - liesIn: function(plane) { - return plane.contains(this); - }, - - // Returns true iff the line has a unique point of intersection with the argument - intersects: function(obj) { - if (obj.normal) { return obj.intersects(this); } - return (!this.isParallelTo(obj) && this.distanceFrom(obj) <= Sylvester.precision); - }, - - // Returns the unique intersection point with the argument, if one exists - intersectionWith: function(obj) { - if (obj.normal || (obj.start && obj.end)) { return obj.intersectionWith(this); } - if (!this.intersects(obj)) { return null; } - var P = this.anchor.elements, X = this.direction.elements, - Q = obj.anchor.elements, Y = obj.direction.elements; - var X1 = X[0], X2 = X[1], X3 = X[2], Y1 = Y[0], Y2 = Y[1], Y3 = Y[2]; - var PsubQ1 = P[0] - Q[0], PsubQ2 = P[1] - Q[1], PsubQ3 = P[2] - Q[2]; - var XdotQsubP = - X1*PsubQ1 - X2*PsubQ2 - X3*PsubQ3; - var YdotPsubQ = Y1*PsubQ1 + Y2*PsubQ2 + Y3*PsubQ3; - var XdotX = X1*X1 + X2*X2 + X3*X3; - var YdotY = Y1*Y1 + Y2*Y2 + Y3*Y3; - var XdotY = X1*Y1 + X2*Y2 + X3*Y3; - var k = (XdotQsubP * YdotY / XdotX + XdotY * YdotPsubQ) / (YdotY - XdotY * XdotY); - return Vector.create([P[0] + k*X1, P[1] + k*X2, P[2] + k*X3]); - }, - - // Returns the point on the line that is closest to the given point or line/line segment - pointClosestTo: function(obj) { - if (obj.start && obj.end) { - // obj is a line segment - var P = obj.pointClosestTo(this); - return (P === null) ? null : this.pointClosestTo(P); - } else if (obj.direction) { - // obj is a line - if (this.intersects(obj)) { return this.intersectionWith(obj); } - if (this.isParallelTo(obj)) { return null; } - var D = this.direction.elements, E = obj.direction.elements; - var D1 = D[0], D2 = D[1], D3 = D[2], E1 = E[0], E2 = E[1], E3 = E[2]; - // Create plane containing obj and the shared normal and intersect this with it - // Thank you: http://www.cgafaq.info/wiki/Line-line_distance - var x = (D3 * E1 - D1 * E3), y = (D1 * E2 - D2 * E1), z = (D2 * E3 - D3 * E2); - var N = [x * E3 - y * E2, y * E1 - z * E3, z * E2 - x * E1]; - var P = Plane.create(obj.anchor, N); - return P.intersectionWith(this); - } else { - // obj is a point - var P = obj.elements || obj; - if (this.contains(P)) { return Vector.create(P); } - var A = this.anchor.elements, D = this.direction.elements; - var D1 = D[0], D2 = D[1], D3 = D[2], A1 = A[0], A2 = A[1], A3 = A[2]; - var x = D1 * (P[1]-A2) - D2 * (P[0]-A1), y = D2 * ((P[2] || 0) - A3) - D3 * (P[1]-A2), - z = D3 * (P[0]-A1) - D1 * ((P[2] || 0) - A3); - var V = Vector.create([D2 * x - D3 * z, D3 * y - D1 * x, D1 * z - D2 * y]); - var k = this.distanceFrom(P) / V.modulus(); - return Vector.create([ - P[0] + V.elements[0] * k, - P[1] + V.elements[1] * k, - (P[2] || 0) + V.elements[2] * k - ]); - } - }, - - // Returns a copy of the line rotated by t radians about the given line. Works by - // finding the argument's closest point to this line's anchor point (call this C) and - // rotating the anchor about C. Also rotates the line's direction about the argument's. - // Be careful with this - the rotation axis' direction affects the outcome! - rotate: function(t, line) { - // If we're working in 2D - if (typeof(line.direction) == 'undefined') { line = Line.create(line.to3D(), Vector.k); } - var R = Matrix.Rotation(t, line.direction).elements; - var C = line.pointClosestTo(this.anchor).elements; - var A = this.anchor.elements, D = this.direction.elements; - var C1 = C[0], C2 = C[1], C3 = C[2], A1 = A[0], A2 = A[1], A3 = A[2]; - var x = A1 - C1, y = A2 - C2, z = A3 - C3; - return Line.create([ - C1 + R[0][0] * x + R[0][1] * y + R[0][2] * z, - C2 + R[1][0] * x + R[1][1] * y + R[1][2] * z, - C3 + R[2][0] * x + R[2][1] * y + R[2][2] * z - ], [ - R[0][0] * D[0] + R[0][1] * D[1] + R[0][2] * D[2], - R[1][0] * D[0] + R[1][1] * D[1] + R[1][2] * D[2], - R[2][0] * D[0] + R[2][1] * D[1] + R[2][2] * D[2] - ]); - }, - - // Returns a copy of the line with its direction vector reversed. - // Useful when using lines for rotations. - reverse: function() { - return Line.create(this.anchor, this.direction.x(-1)); - }, - - // Returns the line's reflection in the given point or line - reflectionIn: function(obj) { - if (obj.normal) { - // obj is a plane - var A = this.anchor.elements, D = this.direction.elements; - var A1 = A[0], A2 = A[1], A3 = A[2], D1 = D[0], D2 = D[1], D3 = D[2]; - var newA = this.anchor.reflectionIn(obj).elements; - // Add the line's direction vector to its anchor, then mirror that in the plane - var AD1 = A1 + D1, AD2 = A2 + D2, AD3 = A3 + D3; - var Q = obj.pointClosestTo([AD1, AD2, AD3]).elements; - var newD = [Q[0] + (Q[0] - AD1) - newA[0], Q[1] + (Q[1] - AD2) - newA[1], Q[2] + (Q[2] - AD3) - newA[2]]; - return Line.create(newA, newD); - } else if (obj.direction) { - // obj is a line - reflection obtained by rotating PI radians about obj - return this.rotate(Math.PI, obj); - } else { - // obj is a point - just reflect the line's anchor in it - var P = obj.elements || obj; - return Line.create(this.anchor.reflectionIn([P[0], P[1], (P[2] || 0)]), this.direction); - } - }, - - // Set the line's anchor point and direction. - setVectors: function(anchor, direction) { - // Need to do this so that line's properties are not - // references to the arguments passed in - anchor = Vector.create(anchor); - direction = Vector.create(direction); - if (anchor.elements.length == 2) {anchor.elements.push(0); } - if (direction.elements.length == 2) { direction.elements.push(0); } - if (anchor.elements.length > 3 || direction.elements.length > 3) { return null; } - var mod = direction.modulus(); - if (mod === 0) { return null; } - this.anchor = anchor; - this.direction = Vector.create([ - direction.elements[0] / mod, - direction.elements[1] / mod, - direction.elements[2] / mod - ]); - return this; - } -}; - -// Constructor function -Line.create = function(anchor, direction) { - var L = new Line(); - return L.setVectors(anchor, direction); -}; - -// Axes -Line.X = Line.create(Vector.Zero(3), Vector.i); -Line.Y = Line.create(Vector.Zero(3), Vector.j); -Line.Z = Line.create(Vector.Zero(3), Vector.k); - -module.exports = Line; - -},{"./vector":74,"./matrix":75,"./plane":77,"./sylvester":79}],77:[function(require,module,exports){ -// Copyright (c) 2011, Chris Umbel, James Coglan // Plane class - depends on Vector. Some methods require Matrix and Line. var Vector = require('./vector'); var Matrix = require('./matrix'); @@ -15333,7 +15103,240 @@ Plane.fromPoints = function(points) { module.exports = Plane; -},{"./vector":74,"./matrix":75,"./line":76,"./sylvester":79}],78:[function(require,module,exports){ +},{"./vector":74,"./matrix":75,"./line":77,"./sylvester":79}],77:[function(require,module,exports){ +// Copyright (c) 2011, Chris Umbel, James Coglan +var Vector = require('./vector'); +var Matrix = require('./matrix'); +var Plane = require('./plane'); +var Sylvester = require('./sylvester'); + +// Line class - depends on Vector, and some methods require Matrix and Plane. + +function Line() {} +Line.prototype = { + + // Returns true if the argument occupies the same space as the line + eql: function(line) { + return (this.isParallelTo(line) && this.contains(line.anchor)); + }, + + // Returns a copy of the line + dup: function() { + return Line.create(this.anchor, this.direction); + }, + + // Returns the result of translating the line by the given vector/array + translate: function(vector) { + var V = vector.elements || vector; + return Line.create([ + this.anchor.elements[0] + V[0], + this.anchor.elements[1] + V[1], + this.anchor.elements[2] + (V[2] || 0) + ], this.direction); + }, + + // Returns true if the line is parallel to the argument. Here, 'parallel to' + // means that the argument's direction is either parallel or antiparallel to + // the line's own direction. A line is parallel to a plane if the two do not + // have a unique intersection. + isParallelTo: function(obj) { + if (obj.normal || (obj.start && obj.end)) { return obj.isParallelTo(this); } + var theta = this.direction.angleFrom(obj.direction); + return (Math.abs(theta) <= Sylvester.precision || Math.abs(theta - Math.PI) <= Sylvester.precision); + }, + + // Returns the line's perpendicular distance from the argument, + // which can be a point, a line or a plane + distanceFrom: function(obj) { + if (obj.normal || (obj.start && obj.end)) { return obj.distanceFrom(this); } + if (obj.direction) { + // obj is a line + if (this.isParallelTo(obj)) { return this.distanceFrom(obj.anchor); } + var N = this.direction.cross(obj.direction).toUnitVector().elements; + var A = this.anchor.elements, B = obj.anchor.elements; + return Math.abs((A[0] - B[0]) * N[0] + (A[1] - B[1]) * N[1] + (A[2] - B[2]) * N[2]); + } else { + // obj is a point + var P = obj.elements || obj; + var A = this.anchor.elements, D = this.direction.elements; + var PA1 = P[0] - A[0], PA2 = P[1] - A[1], PA3 = (P[2] || 0) - A[2]; + var modPA = Math.sqrt(PA1*PA1 + PA2*PA2 + PA3*PA3); + if (modPA === 0) return 0; + // Assumes direction vector is normalized + var cosTheta = (PA1 * D[0] + PA2 * D[1] + PA3 * D[2]) / modPA; + var sin2 = 1 - cosTheta*cosTheta; + return Math.abs(modPA * Math.sqrt(sin2 < 0 ? 0 : sin2)); + } + }, + + // Returns true iff the argument is a point on the line, or if the argument + // is a line segment lying within the receiver + contains: function(obj) { + if (obj.start && obj.end) { return this.contains(obj.start) && this.contains(obj.end); } + var dist = this.distanceFrom(obj); + return (dist !== null && dist <= Sylvester.precision); + }, + + // Returns the distance from the anchor of the given point. Negative values are + // returned for points that are in the opposite direction to the line's direction from + // the line's anchor point. + positionOf: function(point) { + if (!this.contains(point)) { return null; } + var P = point.elements || point; + var A = this.anchor.elements, D = this.direction.elements; + return (P[0] - A[0]) * D[0] + (P[1] - A[1]) * D[1] + ((P[2] || 0) - A[2]) * D[2]; + }, + + // Returns true iff the line lies in the given plane + liesIn: function(plane) { + return plane.contains(this); + }, + + // Returns true iff the line has a unique point of intersection with the argument + intersects: function(obj) { + if (obj.normal) { return obj.intersects(this); } + return (!this.isParallelTo(obj) && this.distanceFrom(obj) <= Sylvester.precision); + }, + + // Returns the unique intersection point with the argument, if one exists + intersectionWith: function(obj) { + if (obj.normal || (obj.start && obj.end)) { return obj.intersectionWith(this); } + if (!this.intersects(obj)) { return null; } + var P = this.anchor.elements, X = this.direction.elements, + Q = obj.anchor.elements, Y = obj.direction.elements; + var X1 = X[0], X2 = X[1], X3 = X[2], Y1 = Y[0], Y2 = Y[1], Y3 = Y[2]; + var PsubQ1 = P[0] - Q[0], PsubQ2 = P[1] - Q[1], PsubQ3 = P[2] - Q[2]; + var XdotQsubP = - X1*PsubQ1 - X2*PsubQ2 - X3*PsubQ3; + var YdotPsubQ = Y1*PsubQ1 + Y2*PsubQ2 + Y3*PsubQ3; + var XdotX = X1*X1 + X2*X2 + X3*X3; + var YdotY = Y1*Y1 + Y2*Y2 + Y3*Y3; + var XdotY = X1*Y1 + X2*Y2 + X3*Y3; + var k = (XdotQsubP * YdotY / XdotX + XdotY * YdotPsubQ) / (YdotY - XdotY * XdotY); + return Vector.create([P[0] + k*X1, P[1] + k*X2, P[2] + k*X3]); + }, + + // Returns the point on the line that is closest to the given point or line/line segment + pointClosestTo: function(obj) { + if (obj.start && obj.end) { + // obj is a line segment + var P = obj.pointClosestTo(this); + return (P === null) ? null : this.pointClosestTo(P); + } else if (obj.direction) { + // obj is a line + if (this.intersects(obj)) { return this.intersectionWith(obj); } + if (this.isParallelTo(obj)) { return null; } + var D = this.direction.elements, E = obj.direction.elements; + var D1 = D[0], D2 = D[1], D3 = D[2], E1 = E[0], E2 = E[1], E3 = E[2]; + // Create plane containing obj and the shared normal and intersect this with it + // Thank you: http://www.cgafaq.info/wiki/Line-line_distance + var x = (D3 * E1 - D1 * E3), y = (D1 * E2 - D2 * E1), z = (D2 * E3 - D3 * E2); + var N = [x * E3 - y * E2, y * E1 - z * E3, z * E2 - x * E1]; + var P = Plane.create(obj.anchor, N); + return P.intersectionWith(this); + } else { + // obj is a point + var P = obj.elements || obj; + if (this.contains(P)) { return Vector.create(P); } + var A = this.anchor.elements, D = this.direction.elements; + var D1 = D[0], D2 = D[1], D3 = D[2], A1 = A[0], A2 = A[1], A3 = A[2]; + var x = D1 * (P[1]-A2) - D2 * (P[0]-A1), y = D2 * ((P[2] || 0) - A3) - D3 * (P[1]-A2), + z = D3 * (P[0]-A1) - D1 * ((P[2] || 0) - A3); + var V = Vector.create([D2 * x - D3 * z, D3 * y - D1 * x, D1 * z - D2 * y]); + var k = this.distanceFrom(P) / V.modulus(); + return Vector.create([ + P[0] + V.elements[0] * k, + P[1] + V.elements[1] * k, + (P[2] || 0) + V.elements[2] * k + ]); + } + }, + + // Returns a copy of the line rotated by t radians about the given line. Works by + // finding the argument's closest point to this line's anchor point (call this C) and + // rotating the anchor about C. Also rotates the line's direction about the argument's. + // Be careful with this - the rotation axis' direction affects the outcome! + rotate: function(t, line) { + // If we're working in 2D + if (typeof(line.direction) == 'undefined') { line = Line.create(line.to3D(), Vector.k); } + var R = Matrix.Rotation(t, line.direction).elements; + var C = line.pointClosestTo(this.anchor).elements; + var A = this.anchor.elements, D = this.direction.elements; + var C1 = C[0], C2 = C[1], C3 = C[2], A1 = A[0], A2 = A[1], A3 = A[2]; + var x = A1 - C1, y = A2 - C2, z = A3 - C3; + return Line.create([ + C1 + R[0][0] * x + R[0][1] * y + R[0][2] * z, + C2 + R[1][0] * x + R[1][1] * y + R[1][2] * z, + C3 + R[2][0] * x + R[2][1] * y + R[2][2] * z + ], [ + R[0][0] * D[0] + R[0][1] * D[1] + R[0][2] * D[2], + R[1][0] * D[0] + R[1][1] * D[1] + R[1][2] * D[2], + R[2][0] * D[0] + R[2][1] * D[1] + R[2][2] * D[2] + ]); + }, + + // Returns a copy of the line with its direction vector reversed. + // Useful when using lines for rotations. + reverse: function() { + return Line.create(this.anchor, this.direction.x(-1)); + }, + + // Returns the line's reflection in the given point or line + reflectionIn: function(obj) { + if (obj.normal) { + // obj is a plane + var A = this.anchor.elements, D = this.direction.elements; + var A1 = A[0], A2 = A[1], A3 = A[2], D1 = D[0], D2 = D[1], D3 = D[2]; + var newA = this.anchor.reflectionIn(obj).elements; + // Add the line's direction vector to its anchor, then mirror that in the plane + var AD1 = A1 + D1, AD2 = A2 + D2, AD3 = A3 + D3; + var Q = obj.pointClosestTo([AD1, AD2, AD3]).elements; + var newD = [Q[0] + (Q[0] - AD1) - newA[0], Q[1] + (Q[1] - AD2) - newA[1], Q[2] + (Q[2] - AD3) - newA[2]]; + return Line.create(newA, newD); + } else if (obj.direction) { + // obj is a line - reflection obtained by rotating PI radians about obj + return this.rotate(Math.PI, obj); + } else { + // obj is a point - just reflect the line's anchor in it + var P = obj.elements || obj; + return Line.create(this.anchor.reflectionIn([P[0], P[1], (P[2] || 0)]), this.direction); + } + }, + + // Set the line's anchor point and direction. + setVectors: function(anchor, direction) { + // Need to do this so that line's properties are not + // references to the arguments passed in + anchor = Vector.create(anchor); + direction = Vector.create(direction); + if (anchor.elements.length == 2) {anchor.elements.push(0); } + if (direction.elements.length == 2) { direction.elements.push(0); } + if (anchor.elements.length > 3 || direction.elements.length > 3) { return null; } + var mod = direction.modulus(); + if (mod === 0) { return null; } + this.anchor = anchor; + this.direction = Vector.create([ + direction.elements[0] / mod, + direction.elements[1] / mod, + direction.elements[2] / mod + ]); + return this; + } +}; + +// Constructor function +Line.create = function(anchor, direction) { + var L = new Line(); + return L.setVectors(anchor, direction); +}; + +// Axes +Line.X = Line.create(Vector.Zero(3), Vector.i); +Line.Y = Line.create(Vector.Zero(3), Vector.j); +Line.Z = Line.create(Vector.Zero(3), Vector.k); + +module.exports = Line; + +},{"./vector":74,"./matrix":75,"./plane":76,"./sylvester":79}],78:[function(require,module,exports){ // Copyright (c) 2011, Chris Umbel, James Coglan // Line.Segment class - depends on Line and its dependencies. @@ -15461,7 +15464,7 @@ Line.Segment.create = function(v1, v2) { module.exports = Line.Segment; -},{"./line":76,"./vector":74}],75:[function(require,module,exports){ +},{"./line":77,"./vector":74}],75:[function(require,module,exports){ // Copyright (c) 2011, Chris Umbel, James Coglan // Matrix class - depends on Vector. @@ -16903,131 +16906,7 @@ module.exports.jsMatrixToFortranArray = jsMatrixToFortranArray; module.exports.fortranArrayToJSArray = fortranArrayToJSArray; module.exports.fortranIntArrayToJSArray = fortranIntArrayToJSArray; -},{"node-ffi":83}],84:[function(require,module,exports){ -(function(Buffer){var ffi = require('./ffi') - , util = require('util') - , Pointer = module.exports = ffi.Bindings.Pointer - -/** - * `attach()` is used for tracking dependencies among pointers to prevent - * garbage collection. - */ - -Pointer.prototype.attach = function attach (friend) { - if (!Array.isArray(friend.__attached)) { - friend.__attached = [] - } - friend.__attached.push(this) -} - -/** - * Creates and returns a new Pointer that points to the same `address` as this - * pointer. Usefor for when you want to use a pointer as in iterator, but still - * want to retain this original pointer's address for use. - * - * The returned Pointer's `free` variable is set to `false` by default. - * - * @return {Pointer} A new Pointer independent of this one, but points to the same `address`. - */ - -Pointer.prototype.clone = function clone () { - return this.seek(0) -} - -/** - * This wraps _putPointer so it supports direct Struct writing. - */ - -Pointer.prototype.putPointer = function putPointer (ptr, seek) { - var p = ptr && 'pointer' in ptr ? ptr.pointer : ptr - return this._putPointer(p, seek) -} - -/** - * Custom inspect() function for easier inspecting of Pointers in the REPL - */ - -Pointer.prototype.inspect = function inspect (depth, hidden, colors) { - return '<Pointer address="' - + util.inspect(this.address, hidden, depth - 1, colors) - +'" allocated="' - + util.inspect(this.allocated, hidden, depth - 1, colors) - +'" free="' - + util.inspect(this.free, hidden, depth - 1, colors) - +'">' -} - -/** - * Returns `true` if the given argument is a `Pointer` instance. - * Returns `false` otherwise. - * - * @param {Object} p A pointer object (possibly...) - * @return {Boolean} `true` if the object is a `Pointer` instance - */ - -Pointer.isPointer = function isPointer (p) { - return p instanceof Pointer -} - -/** - * Allocates a pointer big enough to fit *type* and *value*, writes the value, - * and returns it. - */ - -Pointer.alloc = function alloc (type, value) { - var size = type == 'string' - ? Buffer.byteLength(value, 'utf8') + 1 - : ffi.sizeOf(type) - - // malloc() the buffer - var ptr = new Pointer(size) - - // write the value - ptr['put' + ffi.TYPE_TO_POINTER_METHOD_MAP[type]](value) - - if (type == 'string') { - // XXX: consider removing this string special case. it's dumb. - // we have to actually build an "in-between" pointer for strings - var dptr = new ffi.Pointer(ffi.Bindings.TYPE_SIZE_MAP.pointer) - ptr.attach(dptr) // save it from garbage collection - dptr.putPointer(ptr) - return dptr - } - - return ptr -} - -/** - * Appends the `NON_SPECIFIC_TYPES` to the `TYPE_TO_POINTER_METHOD_MAP` by - * discovering the method suffix by type size. - */ - -Object.keys(ffi.NON_SPECIFIC_TYPES).forEach(function (type) { - var method = ffi.NON_SPECIFIC_TYPES[type] - , suffix = ffi.TYPE_TO_POINTER_METHOD_MAP[type] - - if (!suffix) { - // No hard mapping, determine by size - var size = ffi.sizeOf(type) - , szFunc = ffi.SIZE_TO_POINTER_METHOD_MAP[size] - , signed = type !== 'byte' && type != 'size_t' && type[0] != 'u' - suffix = (signed ? '' : 'U') + szFunc - } - - ffi.TYPE_TO_POINTER_METHOD_MAP[type] = suffix - - Pointer.prototype['put' + method] = Pointer.prototype['put' + suffix] - Pointer.prototype['get' + method] = Pointer.prototype['get' + suffix] -}) - -/** - * Define the `NULL` pointer. Used internally in other parts of node-ffi. - */ - -Pointer.NULL = new Pointer(0) - -})(require("__browserify_buffer").Buffer) -},{"util":40,"./ffi":83,"__browserify_buffer":61}],83:[function(require,module,exports){ +},{"node-ffi":83}],83:[function(require,module,exports){ var ffi = module.exports ffi.Bindings = require('bindings')('ffi_bindings.node') @@ -17215,7 +17094,131 @@ ffi.FFI_TYPE = ffi.Struct([ ]) -},{"./pointer":84,"./cif":85,"./foreign_function":86,"./dynamic_library":87,"./library":88,"./callback":89,"./struct":90,"./errno":91,"bindings":92}],85:[function(require,module,exports){ +},{"./pointer":84,"./cif":85,"./foreign_function":86,"./dynamic_library":87,"./library":88,"./callback":89,"./struct":90,"./errno":91,"bindings":92}],84:[function(require,module,exports){ +(function(Buffer){var ffi = require('./ffi') + , util = require('util') + , Pointer = module.exports = ffi.Bindings.Pointer + +/** + * `attach()` is used for tracking dependencies among pointers to prevent + * garbage collection. + */ + +Pointer.prototype.attach = function attach (friend) { + if (!Array.isArray(friend.__attached)) { + friend.__attached = [] + } + friend.__attached.push(this) +} + +/** + * Creates and returns a new Pointer that points to the same `address` as this + * pointer. Usefor for when you want to use a pointer as in iterator, but still + * want to retain this original pointer's address for use. + * + * The returned Pointer's `free` variable is set to `false` by default. + * + * @return {Pointer} A new Pointer independent of this one, but points to the same `address`. + */ + +Pointer.prototype.clone = function clone () { + return this.seek(0) +} + +/** + * This wraps _putPointer so it supports direct Struct writing. + */ + +Pointer.prototype.putPointer = function putPointer (ptr, seek) { + var p = ptr && 'pointer' in ptr ? ptr.pointer : ptr + return this._putPointer(p, seek) +} + +/** + * Custom inspect() function for easier inspecting of Pointers in the REPL + */ + +Pointer.prototype.inspect = function inspect (depth, hidden, colors) { + return '<Pointer address="' + + util.inspect(this.address, hidden, depth - 1, colors) + +'" allocated="' + + util.inspect(this.allocated, hidden, depth - 1, colors) + +'" free="' + + util.inspect(this.free, hidden, depth - 1, colors) + +'">' +} + +/** + * Returns `true` if the given argument is a `Pointer` instance. + * Returns `false` otherwise. + * + * @param {Object} p A pointer object (possibly...) + * @return {Boolean} `true` if the object is a `Pointer` instance + */ + +Pointer.isPointer = function isPointer (p) { + return p instanceof Pointer +} + +/** + * Allocates a pointer big enough to fit *type* and *value*, writes the value, + * and returns it. + */ + +Pointer.alloc = function alloc (type, value) { + var size = type == 'string' + ? Buffer.byteLength(value, 'utf8') + 1 + : ffi.sizeOf(type) + + // malloc() the buffer + var ptr = new Pointer(size) + + // write the value + ptr['put' + ffi.TYPE_TO_POINTER_METHOD_MAP[type]](value) + + if (type == 'string') { + // XXX: consider removing this string special case. it's dumb. + // we have to actually build an "in-between" pointer for strings + var dptr = new ffi.Pointer(ffi.Bindings.TYPE_SIZE_MAP.pointer) + ptr.attach(dptr) // save it from garbage collection + dptr.putPointer(ptr) + return dptr + } + + return ptr +} + +/** + * Appends the `NON_SPECIFIC_TYPES` to the `TYPE_TO_POINTER_METHOD_MAP` by + * discovering the method suffix by type size. + */ + +Object.keys(ffi.NON_SPECIFIC_TYPES).forEach(function (type) { + var method = ffi.NON_SPECIFIC_TYPES[type] + , suffix = ffi.TYPE_TO_POINTER_METHOD_MAP[type] + + if (!suffix) { + // No hard mapping, determine by size + var size = ffi.sizeOf(type) + , szFunc = ffi.SIZE_TO_POINTER_METHOD_MAP[size] + , signed = type !== 'byte' && type != 'size_t' && type[0] != 'u' + suffix = (signed ? '' : 'U') + szFunc + } + + ffi.TYPE_TO_POINTER_METHOD_MAP[type] = suffix + + Pointer.prototype['put' + method] = Pointer.prototype['put' + suffix] + Pointer.prototype['get' + method] = Pointer.prototype['get' + suffix] +}) + +/** + * Define the `NULL` pointer. Used internally in other parts of node-ffi. + */ + +Pointer.NULL = new Pointer(0) + +})(require("__browserify_buffer").Buffer) +},{"util":40,"./ffi":83,"__browserify_buffer":61}],85:[function(require,module,exports){ var ffi = require('./ffi') /** diff --git a/exampleData/ruleSets/language-processing/natural/upGoerFive.js b/exampleData/ruleSets/language-processing/natural/upGoerFive.js index 47b5c9e..def179c 100644 --- a/exampleData/ruleSets/language-processing/natural/upGoerFive.js +++ b/exampleData/ruleSets/language-processing/natural/upGoerFive.js @@ -147,6 +147,9 @@ var getTextNodesIn = function (node, includeWhitespaceNodes) { var textNodes = [], whitespace = /^\s*$/; function getTextNodes(node) { + if ($(node).attr('id') == 'fiveui-top') { + return; + } if (node.nodeType == 3) { if (includeWhitespaceNodes || !whitespace.test(node.nodeValue)) { textNodes.push(node); @@ -178,7 +181,7 @@ var markWords = function(obj, report) { _.each(toks, function(tok) { if (isCommonWord(tok) || isPunctuation(tok) || _.isNumber(tok)) { - rawObj.append(tok + ' '); + rawObj.append(' ' + tok + ' '); } else { var newObj = $("<span>"+tok+"</span> "); rawObj.append(newObj); |