楼主: Lisrelchen
1290 10

【独家发布】Natural:General Natural Language Facilities for Node [推广有奖]

  • 0关注
  • 62粉丝

VIP

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50154 个
通用积分
81.3228
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
natural

"Natural" is a general natural language facility for nodejs. Tokenizing, stemming, classification, phonetics, tf-idf, WordNet, string similarity, and some inflections are currently supported.

It's still in the early stages, so we're very interested in bug reports, contributions and the like.

Note that many algorithms from Rob Ellis's node-nltools are being merged into this project and will be maintained from here onward.

At the moment, most of the algorithms are English-specific, but in the long-term, some diversity will be in order. Thanks to Polyakov Vladimir, Russian stemming has been added!, Thanks to David Przybilla, Spanish stemming has been added!.

Aside from this README, the only documentation is this DZone article and here on my blog, which is a bit older.

TABLE OF CONTENTS

本帖隐藏的内容

natural-master.zip (1.54 MB)



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Facilities Language Natural General lang General Natural

本帖被以下文库推荐

沙发
Lisrelchen 发表于 2016-9-12 00:16:11 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     classifier = new natural.BayesClassifier();


  21. classifier.addDocument('my unit-tests failed.', 'software');
  22. classifier.addDocument('tried the program, but it was buggy.', 'software');
  23. classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
  24. classifier.addDocument('i need a new power supply.', 'hardware');

  25. classifier.train();

  26. console.log(classifier.classify('did the tests pass?'));
  27. console.log(classifier.classify('did you buy a new drive?'));
复制代码

使用道具

藤椅
Lisrelchen 发表于 2016-9-12 00:17:32 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     classifier = new natural.BayesClassifier();

  21. natural.BayesClassifier.load('classifier.json', null, function(err, classifier) {
  22.         console.log(classifier.classify('did the tests pass?'));
  23.     });
复制代码

使用道具

板凳
Lisrelchen 发表于 2016-9-12 00:18:00 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     classifier = new natural.BayesClassifier();


  21. classifier.addDocument('my unit-tests failed.', 'software');
  22. classifier.addDocument('tried the program, but it was buggy.', 'software');
  23. classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
  24. classifier.addDocument('i need a new power supply.', 'hardware');

  25. classifier.train();

  26. classifier.save('classifier.json', function(err, classifier) {
  27.         // the classifier is saved to the classifier.json file!
  28.     });
复制代码

使用道具

报纸
Lisrelchen 发表于 2016-9-12 00:18:44 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.   inflector = natural.CountInflector;

  21. console.log(inflector.nth(1));
  22. console.log(inflector.nth(2));
  23. console.log(inflector.nth(3));
  24. console.log(inflector.nth(4));
  25. console.log(inflector.nth(10));
  26. console.log(inflector.nth(11));
  27. console.log(inflector.nth(101));
  28. console.log(inflector.nth(102));
  29. console.log(inflector.nth(103));
  30. console.log(inflector.nth(104));
复制代码

使用道具

地板
Lisrelchen 发表于 2016-9-12 00:19:37 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     nounInflector = new natural.NounInflector();

  21. plural = nounInflector.pluralize('radius');
  22. console.log(plural);

  23. plural = nounInflector.pluralize('beer');
  24. console.log(plural);

  25. singular = nounInflector.singularize('radii');
  26. console.log(singular);

  27. singular = nounInflector.singularize('beers');
  28. console.log(singular);
复制代码

使用道具

7
Lisrelchen 发表于 2016-9-12 00:20:37 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     nounInflector = new natural.NounInflector();

  21. nounInflector.attach();

  22. console.log('beers'.singularizeNoun());
  23. console.log('radii'.singularizeNoun());

  24. console.log('beer'.pluralizeNoun());
  25. console.log('radius'.pluralizeNoun());
复制代码

使用道具

8
Lisrelchen 发表于 2016-9-12 00:21:43 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     phonetic = natural.Metaphone;

  21. var wordA = 'phonetics';
  22. var stdin = process.openStdin();
  23. stdin.setEncoding('ascii');

  24. process.stdout.write('try to enter a word that sounds like "' + wordA +'": ');

  25. stdin.on('data', function (wordB) {
  26.         if(phonetic.compare(wordA, wordB))
  27.             process.stdout.write('they sound alike!\n');
  28.         else
  29.             process.stdout.write('sorry, they don\'t sound alike.\n');

  30.         process.exit();
  31.     });
复制代码

使用道具

9
Lisrelchen 发表于 2016-9-12 00:22:09 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     phonetic = natural.Metaphone;

  21. phonetic.attach();
  22. var wordA = 'phonetics';
  23. var stdin = process.openStdin();
  24. stdin.setEncoding('ascii');

  25. process.stdout.write('try to enter a word that sounds like "' + wordA +'": ');

  26. stdin.on('data', function (wordB) {
  27.         if(wordA.soundsLike(wordB))
  28.             process.stdout.write('they sound alike!\n');
  29.         else
  30.             process.stdout.write('sorry, they don\'t sound alike.\n');
  31.        
  32.         process.exit();
  33.     });
复制代码

使用道具

10
Lisrelchen 发表于 2016-9-12 00:22:33 |只看作者 |坛友微信交流群
  1. /*
  2. Copyright (c) 2011, Chris Umbel

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.

  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */

  19. var natural = require('natural'),
  20.     phonetic = natural.DoubleMetaphone;

  21. var sentence = 'phonetic modules contain algorithms';
  22. var stdin = process.openStdin();
  23. stdin.setEncoding('ascii');
  24. phonetic.attach();
  25. process.stdout.write('enter a word that sounds like one of these, "' + sentence +'": ');

  26. words = sentence.tokenizeAndPhoneticize();

  27. function findMatch(input) {
  28.     inputSounds = input.phonetics();
  29.     console.log(inputSounds);
  30.    
  31.     for(var i = 0; i < words.length; i++) {
  32.         wordSounds = words[i];
  33.        
  34.         if(wordSounds == inputSounds) {
  35.             process.stdout.write('match found!\n');
  36.             return;
  37.         }
  38.     }

  39.     process.stdout.write('no match found.\n');
  40.     return;
  41. }

  42. stdin.on('data', function (input) {
  43.         findMatch(input);
  44.         process.exit();
  45.     });
复制代码

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-9-20 06:37