natural 0.1.28 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/.editorconfig +7 -0
  2. package/.npmignore +4 -11
  3. package/README.md +190 -50
  4. package/bayes_classifier.json +1 -0
  5. package/lib/natural/analyzers/sentence_analyzer.js +8 -5
  6. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  7. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  8. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  9. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  10. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  11. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  12. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  13. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  14. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  15. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  16. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  17. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  18. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  19. package/lib/natural/classifiers/classifier.js +3 -2
  20. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  21. package/lib/natural/distance/dice_coefficient.js +22 -12
  22. package/lib/natural/distance/jaro-winkler_distance.js +13 -8
  23. package/lib/natural/index.js +6 -0
  24. package/lib/natural/inflectors/present_verb_inflector.js +1 -0
  25. package/lib/natural/ngrams/ngrams.js +6 -0
  26. package/lib/natural/normalizers/normalizer_ja.js +26 -8
  27. package/lib/natural/phonetics/double_metaphone.js +9 -4
  28. package/lib/natural/phonetics/metaphone.js +4 -0
  29. package/lib/natural/phonetics/soundex.js +11 -7
  30. package/lib/natural/spellcheck/spellcheck.js +80 -0
  31. package/lib/natural/stemmers/porter_stemmer.js +90 -62
  32. package/lib/natural/stemmers/porter_stemmer_fr.js +8 -3
  33. package/lib/natural/stemmers/porter_stemmer_pt.js +302 -0
  34. package/lib/natural/stemmers/stemmer.js +31 -6
  35. package/lib/natural/stemmers/stemmer_pt.js +65 -0
  36. package/lib/natural/stemmers/token.js +163 -0
  37. package/lib/natural/tfidf/tfidf.js +49 -18
  38. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  39. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  40. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  41. package/lib/natural/util/bag.js +1 -0
  42. package/lib/natural/util/stopwords_pt.js +136 -0
  43. package/lib/natural/wordnet/wordnet.js +2 -2
  44. package/lib/natural/wordnet/wordnet_file.js +1 -1
  45. package/lr_classifier.json +1 -0
  46. package/package.json +7 -4
  47. package/package.json~ +66 -0
  48. package/benchmarks/index.js +0 -32
  49. package/benchmarks/metaphone.js +0 -27
  50. package/benchmarks/soundex.js +0 -27
  51. package/examples/classification/basic.js +0 -35
  52. package/examples/classification/recall.js +0 -28
  53. package/examples/classification/store.js +0 -37
  54. package/examples/inflection/count.js +0 -35
  55. package/examples/inflection/noun_attach.js +0 -33
  56. package/examples/phonetics/compare.js +0 -39
  57. package/examples/phonetics/sounds_like.js +0 -40
  58. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  59. package/examples/stemming/stem_corpus.js +0 -29
  60. package/examples/stemming/stem_word.js +0 -26
  61. package/examples/tfidf/array_example.js +0 -34
  62. package/examples/tfidf/multiple_terms.js +0 -33
  63. package/examples/tfidf/tfidf_example.js +0 -44
  64. package/io_spec/test_data/tfidf/one +0 -1
  65. package/io_spec/test_data/tfidf/two +0 -1
  66. package/io_spec/tfidf_spec.js +0 -50
  67. package/io_spec/wordnet_spec.js +0 -81
  68. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  69. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  70. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  71. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  72. package/spec/aggressive_tokenizer_spec.js +0 -56
  73. package/spec/bayes_classifier_spec.js +0 -173
  74. package/spec/classifier_spec.js +0 -91
  75. package/spec/count_inflector_fr_spec.js +0 -44
  76. package/spec/count_inflector_spec.js +0 -73
  77. package/spec/dice_coefficient_spec.js +0 -26
  78. package/spec/double_metaphone_spec.js +0 -743
  79. package/spec/jaro-winkler_spec.js +0 -53
  80. package/spec/lancaster_stemmer_spec.js +0 -73
  81. package/spec/levenshtein_spec.js +0 -66
  82. package/spec/logistic_regression_classifier_spec.js +0 -122
  83. package/spec/longest_path_tree_spec.js +0 -102
  84. package/spec/metaphone_spec.js +0 -247
  85. package/spec/ngram_spec.js +0 -130
  86. package/spec/ngram_zh_spec.js +0 -122
  87. package/spec/normalizer_ja_spec.js +0 -154
  88. package/spec/normalizer_no_spec.js +0 -111
  89. package/spec/normalizer_spec.js +0 -118
  90. package/spec/noun_inflector_fr_spec.js +0 -476
  91. package/spec/noun_inflector_ja_spec.js +0 -112
  92. package/spec/noun_inflector_spec.js +0 -270
  93. package/spec/porter_stemmer_fr_spec.js +0 -101
  94. package/spec/porter_stemmer_it_spec.js +0 -44
  95. package/spec/porter_stemmer_no_spec.js +0 -143
  96. package/spec/porter_stemmer_ru_spec.js +0 -63
  97. package/spec/porter_stemmer_spec.js +0 -137
  98. package/spec/present_verb_inflector_spec.js +0 -125
  99. package/spec/sentence_analyzer_spec.js +0 -29
  100. package/spec/shortest_path_tree_spec.js +0 -132
  101. package/spec/soundex_spec.js +0 -154
  102. package/spec/stemmer_ja_spec.js +0 -66
  103. package/spec/test_data/snowball_fr.txt +0 -20402
  104. package/spec/test_data/snowball_it.txt +0 -35482
  105. package/spec/test_data/snowball_no.txt +0 -20628
  106. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  107. package/spec/test_data/tfidf_document1.txt +0 -1
  108. package/spec/test_data/tfidf_document2.txt +0 -1
  109. package/spec/test_data/tfidf_document3.txt +0 -1
  110. package/spec/test_data/tfidf_document4.txt +0 -1
  111. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  112. package/spec/test_data/wordnet_mini.sql +0 -95
  113. package/spec/tfidf_spec.js +0 -198
  114. package/spec/tokenizer_ja_spec.js +0 -58
  115. package/spec/transliterator_ja_spec.js +0 -103
  116. package/spec/treebank_word_tokenizer_spec.js +0 -36
  117. package/spec/trie_spec.js +0 -206
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "natural",
3
3
  "description": "General natural language (tokenizing, stemming (English, Russian, Spanish), classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.",
4
- "version": "0.1.28",
4
+ "version": "0.4.0",
5
5
  "homepage": "https://github.com/NaturalNode/natural",
6
6
  "repository": {
7
7
  "type": "git",
@@ -12,8 +12,9 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "sylvester": ">= 0.0.12",
15
- "apparatus": ">= 0.0.6",
16
- "underscore": ">=1.3.1"
15
+ "apparatus": ">= 0.0.9",
16
+ "underscore": ">=1.3.1",
17
+ "log4js": "*"
17
18
  },
18
19
  "devDependencies": {
19
20
  "uubench": "0.0.x",
@@ -22,6 +23,7 @@
22
23
  "scripts": {
23
24
  "test": "NODE_PATH=. node_modules/jasmine-node/bin/jasmine-node spec/"
24
25
  },
26
+ "license": "MIT",
25
27
  "author": "Chris Umbel <chris@chrisumbel.com>",
26
28
  "keywords": [
27
29
  "natural",
@@ -42,7 +44,8 @@
42
44
  "double",
43
45
  "jaro-winkler",
44
46
  "levenshtein",
45
- "distance"
47
+ "distance",
48
+ "tagger"
46
49
  ],
47
50
  "main": "./lib/natural/index.js",
48
51
  "maintainers": [
package/package.json~ ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "natural",
3
+ "description": "General natural language (tokenizing, stemming (English, Russian, Spanish), classification, inflection, phonetics, tfidf, WordNet, jaro-winkler, Levenshtein distance, Dice's Coefficient) facilities for node.",
4
+ "version": "0.3.0",
5
+ "homepage": "https://github.com/NaturalNode/natural",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git://github.com/NaturalNode/natural.git"
9
+ },
10
+ "engines": {
11
+ "node": ">=0.4.10"
12
+ },
13
+ "dependencies": {
14
+ "sylvester": ">= 0.0.12",
15
+ "apparatus": ">= 0.0.9",
16
+ "underscore": ">=1.3.1",
17
+ "log4js": "*"
18
+ },
19
+ "devDependencies": {
20
+ "uubench": "0.0.x",
21
+ "jasmine-node": "~1.13.1"
22
+ },
23
+ "scripts": {
24
+ "test": "NODE_PATH=. node_modules/jasmine-node/bin/jasmine-node spec/"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Chris Umbel <chris@chrisumbel.com>",
28
+ "keywords": [
29
+ "natural",
30
+ "language",
31
+ "porter",
32
+ "lancaster",
33
+ "stemmer",
34
+ "bayes",
35
+ "classifier",
36
+ "phonetic",
37
+ "metaphone",
38
+ "inflector",
39
+ "wordnet",
40
+ "tf-idf",
41
+ "logistic",
42
+ "regression",
43
+ "doublemetaphone",
44
+ "double",
45
+ "jaro-winkler",
46
+ "levenshtein",
47
+ "distance",
48
+ "tagger"
49
+ ],
50
+ "main": "./lib/natural/index.js",
51
+ "maintainers": [
52
+ {
53
+ "name": "Chris Umbel",
54
+ "email": "chris@chrisumbel.com",
55
+ "web": "http://www.chrisumbel.com"
56
+ },
57
+ {
58
+ "name": "Rob Ellis",
59
+ "email": "rob@silentrob.me"
60
+ },
61
+ {
62
+ "name": "Ken Koch",
63
+ "email": "kkoch986@gmail.com"
64
+ }
65
+ ]
66
+ }
@@ -1,32 +0,0 @@
1
-
2
- /**
3
- * Module dependencies.
4
- */
5
-
6
- var uubench = require('uubench')
7
- , natural = require('../');
8
-
9
- fs = require('fs');
10
- metaphone = natural.Metaphone.process;
11
- soundex = natural.SoundEx.process;
12
-
13
- suite = new uubench.Suite({
14
- start: function(){
15
- console.log();
16
- },
17
-
18
- result: function(name, stats){
19
- var persec = 1000 / stats.elapsed
20
- , ops = stats.iterations * persec;
21
- console.log(' \033[90m%s : \033[36m%s \033[90mops/s\033[0m', name, ops | 0);
22
- },
23
-
24
- done: function(){
25
- console.log();
26
- }
27
- });
28
-
29
- require('./metaphone');
30
- require('./soundex');
31
-
32
- suite.run();
@@ -1,27 +0,0 @@
1
-
2
- // single word
3
-
4
- suite.bench('metaphone() word', function(next){
5
- metaphone('stephen');
6
- next();
7
- });
8
-
9
- // small body of text
10
-
11
- var words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/);
12
- suite.bench('metaphone() small', function(next){
13
- for (var i = 0, len = words.length; i < len; ++i) {
14
- metaphone(words[i]);
15
- }
16
- next();
17
- });
18
-
19
- // medium body of text
20
-
21
- var words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/);
22
- suite.bench('metaphone() medium', function(next){
23
- for (var i = 0, len = words2.length; i < len; ++i) {
24
- metaphone(words2[i]);
25
- }
26
- next();
27
- });
@@ -1,27 +0,0 @@
1
-
2
- // single word
3
-
4
- suite.bench('soundex() word', function(next){
5
- soundex('stephen');
6
- next();
7
- });
8
-
9
- // small body of text
10
-
11
- var words = fs.readFileSync('lib/natural/index.js', 'utf8').split(/\W+/);
12
- suite.bench('soundex() small', function(next){
13
- for (var i = 0, len = words.length; i < len; ++i) {
14
- soundex(words[i]);
15
- }
16
- next();
17
- });
18
-
19
- // medium body of text
20
-
21
- var words2 = fs.readFileSync('README.md', 'utf8').split(/\W+/);
22
- suite.bench('soundex() medium', function(next){
23
- for (var i = 0, len = words2.length; i < len; ++i) {
24
- soundex(words2[i]);
25
- }
26
- next();
27
- });
@@ -1,35 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- classifier = new natural.BayesClassifier();
25
-
26
-
27
- classifier.addDocument('my unit-tests failed.', 'software');
28
- classifier.addDocument('tried the program, but it was buggy.', 'software');
29
- classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
30
- classifier.addDocument('i need a new power supply.', 'hardware');
31
-
32
- classifier.train();
33
-
34
- console.log(classifier.classify('did the tests pass?'));
35
- console.log(classifier.classify('did you buy a new drive?'));
@@ -1,28 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- classifier = new natural.BayesClassifier();
25
-
26
- natural.BayesClassifier.load('classifier.json', null, function(err, classifier) {
27
- console.log(classifier.classify('did the tests pass?'));
28
- });
@@ -1,37 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- classifier = new natural.BayesClassifier();
25
-
26
-
27
- classifier.addDocument('my unit-tests failed.', 'software');
28
- classifier.addDocument('tried the program, but it was buggy.', 'software');
29
- classifier.addDocument('the drive has a 2TB capacity.', 'hardware');
30
- classifier.addDocument('i need a new power supply.', 'hardware');
31
-
32
- classifier.train();
33
-
34
- classifier.save('classifier.json', function(err, classifier) {
35
- // the classifier is saved to the classifier.json file!
36
- });
37
-
@@ -1,35 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- inflector = natural.CountInflector;
25
-
26
- console.log(inflector.nth(1));
27
- console.log(inflector.nth(2));
28
- console.log(inflector.nth(3));
29
- console.log(inflector.nth(4));
30
- console.log(inflector.nth(10));
31
- console.log(inflector.nth(11));
32
- console.log(inflector.nth(101));
33
- console.log(inflector.nth(102));
34
- console.log(inflector.nth(103));
35
- console.log(inflector.nth(104));
@@ -1,33 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- nounInflector = new natural.NounInflector();
25
-
26
- nounInflector.attach();
27
-
28
- console.log('beers'.singularizeNoun());
29
- console.log('radii'.singularizeNoun());
30
-
31
- console.log('beer'.pluralizeNoun());
32
- console.log('radius'.pluralizeNoun());
33
-
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- phonetic = natural.Metaphone;
25
-
26
- var wordA = 'phonetics';
27
- var stdin = process.openStdin();
28
- stdin.setEncoding('ascii');
29
-
30
- process.stdout.write('try to enter a word that sounds like "' + wordA +'": ');
31
-
32
- stdin.on('data', function (wordB) {
33
- if(phonetic.compare(wordA, wordB))
34
- process.stdout.write('they sound alike!\n');
35
- else
36
- process.stdout.write('sorry, they don\'t sound alike.\n');
37
-
38
- process.exit();
39
- });
@@ -1,40 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- phonetic = natural.Metaphone;
25
-
26
- phonetic.attach();
27
- var wordA = 'phonetics';
28
- var stdin = process.openStdin();
29
- stdin.setEncoding('ascii');
30
-
31
- process.stdout.write('try to enter a word that sounds like "' + wordA +'": ');
32
-
33
- stdin.on('data', function (wordB) {
34
- if(wordA.soundsLike(wordB))
35
- process.stdout.write('they sound alike!\n');
36
- else
37
- process.stdout.write('sorry, they don\'t sound alike.\n');
38
-
39
- process.exit();
40
- });
@@ -1,54 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- phonetic = natural.DoubleMetaphone;
25
-
26
- var sentence = 'phonetic modules contain algorithms';
27
- var stdin = process.openStdin();
28
- stdin.setEncoding('ascii');
29
- phonetic.attach();
30
- process.stdout.write('enter a word that sounds like one of these, "' + sentence +'": ');
31
-
32
- words = sentence.tokenizeAndPhoneticize();
33
-
34
- function findMatch(input) {
35
- inputSounds = input.phonetics();
36
- console.log(inputSounds);
37
-
38
- for(var i = 0; i < words.length; i++) {
39
- wordSounds = words[i];
40
-
41
- if(wordSounds == inputSounds) {
42
- process.stdout.write('match found!\n');
43
- return;
44
- }
45
- }
46
-
47
- process.stdout.write('no match found.\n');
48
- return;
49
- }
50
-
51
- stdin.on('data', function (input) {
52
- findMatch(input);
53
- process.exit();
54
- });
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- stemmer = natural.PorterStemmer;
25
-
26
- stemmer.attach();
27
-
28
- console.log('i stemmed words.'.tokenizeAndStem());
29
- console.log('i stemmed words.'.tokenizeAndStem(true));
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- stemmer = natural.LancasterStemmer;
25
-
26
- console.log(stemmer.stem('stemming'));
@@ -1,34 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Rob Ellis, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- TfIdf = natural.TfIdf,
25
- tfidf = new TfIdf();
26
-
27
- tfidf.addDocument(['document', 'about', 'node']);
28
- tfidf.addDocument(['document', 'about', 'ruby']);
29
- tfidf.addDocument(['document', 'about', 'ruby', 'node']);
30
- tfidf.addDocument(['document', 'about', 'node', 'node']);
31
-
32
- tfidf.tfidfs(['node', 'ruby'], function(i, measure) {
33
- console.log('document #' + i + ' is ' + measure);
34
- });
@@ -1,33 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Rob Ellis, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- TfIdf = natural.TfIdf,
25
- tfidf = new TfIdf();
26
-
27
- tfidf.addDocument('this document is about node.');
28
- tfidf.addDocument('this document is about ruby.');
29
- tfidf.addDocument('this document is about ruby and node.');
30
-
31
- tfidf.tfidfs('node ruby', function(i, measure) {
32
- console.log('document #' + i + ' is ' + measure);
33
- });
@@ -1,44 +0,0 @@
1
- /*
2
- Copyright (c) 2011, Rob Ellis, Chris Umbel
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy
5
- of this software and associated documentation files (the "Software"), to deal
6
- in the Software without restriction, including without limitation the rights
7
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the Software is
9
- furnished to do so, subject to the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be included in
12
- all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
- THE SOFTWARE.
21
- */
22
-
23
- var natural = require('natural'),
24
- TfIdf = natural.TfIdf,
25
- tfidf = new TfIdf();
26
-
27
- tfidf.addDocument('this document is about node.');
28
- tfidf.addDocument('this document is about ruby.');
29
- tfidf.addDocument('this document is about ruby and node.');
30
- tfidf.addDocument('this document is about node. it has node examples');
31
-
32
- console.log('node --------------------------------');
33
- tfidf.tfidfs('node', function(i, measure) {
34
- console.log('document #' + i + ' is ' + measure);
35
- });
36
-
37
- console.log('ruby --------------------------------');
38
- tfidf.tfidfs('ruby', function(i, measure) {
39
- console.log('document #' + i + ' is ' + measure);
40
- });
41
-
42
- console.log('-------------------------------------');
43
- console.log(tfidf.tfidf('ruby', 0));
44
- console.log(tfidf.tfidf('ruby', 1));