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
@@ -1,137 +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 stemmer = require('../lib/natural/stemmers/porter_stemmer');
24
-
25
- describe('porter_stemmer', function() {
26
- it('should perform step 1a', function() {
27
- expect(stemmer.step1a('caresses')).toBe('caress');
28
- expect(stemmer.step1a('ponies')).toBe('poni');
29
- expect(stemmer.step1a('ties')).toBe('ti');
30
- expect(stemmer.step1a('caress')).toBe('caress');
31
- expect(stemmer.step1a('cats')).toBe('cat');
32
- });
33
-
34
- it('should perform step 1b', function() {
35
- expect(stemmer.step1b('feed')).toBe('feed');
36
- expect(stemmer.step1b('agreed')).toBe('agree');
37
- expect(stemmer.step1b('plastered')).toBe('plaster');
38
- expect(stemmer.step1b('bled')).toBe('bled');
39
- expect(stemmer.step1b('motoring')).toBe('motor');
40
- expect(stemmer.step1b('sing')).toBe('sing');
41
- });
42
-
43
- it('should perform step 1c', function() {
44
- expect(stemmer.step1c('happy')).toBe('happi');
45
- expect(stemmer.step1c('sky')).toBe('sky');
46
- });
47
-
48
- it('should perform step 2', function() {
49
- expect(stemmer.step2('relational')).toBe('relate');
50
- expect(stemmer.step2('conditional')).toBe('condition');
51
- expect(stemmer.step2('rational')).toBe('rational');
52
- expect(stemmer.step2('valenci')).toBe('valence');
53
- expect(stemmer.step2('hesitanci')).toBe('hesitance');
54
- expect(stemmer.step2('digitizer')).toBe('digitize');
55
- expect(stemmer.step2('conformabli')).toBe('conformable');
56
- expect(stemmer.step2('radicalli')).toBe('radical');
57
- expect(stemmer.step2('differentli')).toBe('different');
58
- expect(stemmer.step2('vileli')).toBe('vile');
59
- expect(stemmer.step2('analogousli')).toBe('analogous');
60
- expect(stemmer.step2('vietnamization')).toBe('vietnamize');
61
- expect(stemmer.step2('predication')).toBe('predicate');
62
- expect(stemmer.step2('operator')).toBe('operate');
63
- expect(stemmer.step2('feudalism')).toBe('feudal');
64
- expect(stemmer.step2('decisiveness')).toBe('decisive');
65
- expect(stemmer.step2('hopefulness')).toBe('hopeful');
66
- expect(stemmer.step2('callousness')).toBe('callous');
67
- expect(stemmer.step2('formaliti')).toBe('formal');
68
- expect(stemmer.step2('sensitiviti')).toBe('sensitive');
69
- expect(stemmer.step2('sensibiliti')).toBe('sensible');
70
- });
71
-
72
- it('should perform step 3', function() {
73
- expect(stemmer.step3('triplicate')).toBe('triplic');
74
- expect(stemmer.step3('formative')).toBe('form');
75
- expect(stemmer.step3('formalize')).toBe('formal');
76
- expect(stemmer.step3('electriciti')).toBe('electric');
77
- expect(stemmer.step3('electrical')).toBe('electric');
78
- expect(stemmer.step3('hopeful')).toBe('hope');
79
- expect(stemmer.step3('goodness')).toBe('good');
80
- });
81
-
82
- it('should perform step 4', function() {
83
- expect(stemmer.step4('revival')).toBe('reviv');
84
- expect(stemmer.step4('allowance')).toBe('allow');
85
- expect(stemmer.step4('inference')).toBe('infer');
86
- expect(stemmer.step4('airliner')).toBe('airlin');
87
- expect(stemmer.step4('gyroscopic')).toBe('gyroscop');
88
- expect(stemmer.step4('adjustable')).toBe('adjust');
89
- expect(stemmer.step4('defensible')).toBe('defens');
90
- expect(stemmer.step4('irritant')).toBe('irrit');
91
- expect(stemmer.step4('replacement')).toBe('replac');
92
- expect(stemmer.step4('adjustment')).toBe('adjust');
93
- expect(stemmer.step4('dependent')).toBe('depend');
94
- expect(stemmer.step4('adoption')).toBe('adopt');
95
- expect(stemmer.step4('homologou')).toBe('homolog');
96
- expect(stemmer.step4('communism')).toBe('commun');
97
- expect(stemmer.step4('activate')).toBe('activ');
98
- expect(stemmer.step4('angulariti')).toBe('angular');
99
- expect(stemmer.step4('homologous')).toBe('homolog');
100
- expect(stemmer.step4('effective')).toBe('effect');
101
- expect(stemmer.step4('bowdlerize')).toBe('bowdler');
102
- });
103
-
104
- it('should perform step 5a', function() {
105
- expect(stemmer.step5a('probate')).toBe('probat');
106
- expect(stemmer.step5a('rate')).toBe('rate');
107
- expect(stemmer.step5a('cease')).toBe('ceas');
108
- });
109
-
110
- it('should perform step5b', function() {
111
- expect(stemmer.step5b('controll')).toBe('control');
112
- expect(stemmer.step5b('roll')).toBe('roll');
113
- });
114
-
115
- it('should perform complete stemming', function() {
116
- expect(stemmer.stem('scoring')).toBe('score');
117
- expect(stemmer.stem('scored')).toBe('score');
118
- expect(stemmer.stem('scores')).toBe('score');
119
- expect(stemmer.stem('score')).toBe('score');
120
- expect(stemmer.stem('SCORING')).toBe('score');
121
- expect(stemmer.stem('SCORED')).toBe('score');
122
- expect(stemmer.stem('SCORES')).toBe('score');
123
- expect(stemmer.stem('SCORE')).toBe('score');
124
- expect(stemmer.stem('nationals')).toBe('nation');
125
- expect(stemmer.stem('doing')).toBe('do');
126
- });
127
-
128
- it('should perform stem animated to anim', function() {
129
- expect(stemmer.stem('animated')).toBe('anim');
130
- });
131
-
132
- it('should tokenize and stem attached', function() {
133
- stemmer.attach();
134
- expect('scoring stinks'.tokenizeAndStem()).toEqual(['score', 'stink']);
135
- expect('SCORING STINKS'.tokenizeAndStem()).toEqual(['score', 'stink']);
136
- });
137
- });
@@ -1,125 +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 VerbInflector = require('../lib/natural/inflectors/present_verb_inflector'),
24
- inflector = new VerbInflector ();
25
-
26
- describe('present verb inflector', function() {
27
- describe('singularization', function() {
28
- it('should singularize regular ES forms', function() {
29
- expect(inflector.singularize('catch')).toBe('catches');
30
- expect(inflector.singularize('do')).toBe('does');
31
- expect(inflector.singularize('go')).toBe('goes');
32
- });
33
-
34
- it('should handle [CS]HES forms', function () {
35
- expect(inflector.singularize('cash')).toBe('cashes');
36
- expect(inflector.singularize('ach')).toBe('aches');
37
- });
38
-
39
- it('should ignore XES forms', function() {
40
- expect(inflector.singularize('annex')).toBe('annexes');
41
- });
42
-
43
- it('should handle SSES forms', function() {
44
- expect(inflector.singularize('access')).toBe('accesses');
45
- });
46
-
47
- it('should ignore ZZES forms', function() {
48
- expect(inflector.singularize('buzz')).toBe('buzzes');
49
- });
50
-
51
- it('should singularize regular S forms', function() {
52
- expect(inflector.singularize('claim')).toBe('claims');
53
- expect(inflector.singularize('drink')).toBe('drinks');
54
- expect(inflector.singularize('become')).toBe('becomes');
55
- });
56
-
57
- it('should singularize irregular forms', function() {
58
- expect(inflector.singularize('are')).toBe('is');
59
- expect(inflector.singularize('were')).toBe('was');
60
- });
61
-
62
- it('should singularize ies forms', function() {
63
- expect(inflector.singularize('fly')).toBe('flies');
64
- expect(inflector.singularize('try')).toBe('tries');
65
- });
66
-
67
- it('should handle ambiguous forms', function() {
68
- expect(inflector.singularize('will')).toBe('will');
69
- });
70
- });
71
-
72
- describe('pluralization', function() {
73
- it('should pluralize regular ES forms', function() {
74
- expect(inflector.pluralize('catches')).toBe('catch');
75
- expect(inflector.pluralize('does')).toBe('do');
76
- expect(inflector.pluralize('goes')).toBe('go');
77
- });
78
-
79
- it('should handle [CS]HES forms', function () {
80
- expect(inflector.pluralize('cashes')).toBe('cash');
81
- expect(inflector.pluralize('aches')).toBe('ach');
82
- });
83
-
84
- it('should handle XES forms', function() {
85
- expect(inflector.pluralize('annexes')).toBe('annex');
86
- });
87
-
88
- it('should handle SSES forms', function() {
89
- expect(inflector.pluralize('accesses')).toBe('access');
90
- });
91
-
92
- it('should handle ZZES forms', function() {
93
- expect(inflector.pluralize('buzzes')).toBe('buzz');
94
- });
95
-
96
- it('should pluralize regular S forms that done drop e', function() {
97
- expect(inflector.pluralize('becomes')).toBe('become');
98
- });
99
-
100
- it('should pluralize regular S forms', function() {
101
- expect(inflector.pluralize('drinks')).toBe('drink');
102
- expect(inflector.pluralize('claims')).toBe('claim');
103
- });
104
-
105
- it('should pluralize irregular forms', function() {
106
- expect(inflector.pluralize('was')).toBe('were');
107
- expect(inflector.pluralize('is')).toBe('are');
108
- });
109
-
110
- it('should pluralize ies forms', function() {
111
- expect(inflector.pluralize('flies')).toBe('fly');
112
- expect(inflector.pluralize('tries')).toBe('try');
113
- });
114
-
115
- it('should handle ambiguous forms', function() {
116
- expect(inflector.pluralize('will')).toBe('will');
117
- });
118
- });
119
-
120
- describe('should pluralize and singularize string from patch', function() {
121
- inflector.attach();
122
- expect('becomes'.pluralizePresentVerb()).toBe('become');
123
- expect('become'.singularizePresentVerb()).toBe('becomes');
124
- });
125
- });
@@ -1,29 +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 SentenceAnalyzer = require('../lib/natural/analyzers/sentence_analyzer');
24
-
25
- describe('sentence analyzer', function() {
26
- it('should load', function() {
27
- var analyzer = new SentenceAnalyzer(null, function() { });
28
- });
29
- });
@@ -1,132 +0,0 @@
1
- /*
2
- Copyright (c) 2014, Lee Wenzhu
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
- 'use strict';
23
-
24
- var SPT = require('../lib/natural/util/shortest_path_tree'),
25
- Topological = require('../lib/natural/util/topological'),
26
- EdgeWeightedDigraph = require('../lib/natural/util/edge_weighted_digraph');
27
-
28
- describe("shortest path tree", function() {
29
- var digraph = new EdgeWeightedDigraph();
30
- digraph.add(5,4,0.35);
31
- digraph.add(4,7,0.37);
32
- digraph.add(5,7,0.28);
33
- digraph.add(5,1,0.32);
34
- digraph.add(4,0,0.38);
35
- digraph.add(0,2,0.26);
36
- digraph.add(3,7,0.39);
37
- digraph.add(1,3,0.29);
38
- digraph.add(7,2,0.34);
39
- digraph.add(6,2,0.40);
40
- digraph.add(3,6,0.52);
41
- digraph.add(6,0,0.58);
42
- digraph.add(6,4,0.93);
43
- describe("edge weighted digraph normal operations", function() {
44
- it("should get the numbers of vertexs", function() {
45
- expect(digraph.v()).toBe(8);
46
- });
47
- it("should get the numbers of edges", function() {
48
- expect(digraph.e()).toBe(13);
49
- });
50
- it("should print all item in digraph", function() {
51
- expect(digraph.toString()).toBe('0 -> 2, 0.26\n' +
52
- '1 -> 3, 0.29\n' +
53
- '3 -> 7, 0.39\n' +
54
- '3 -> 6, 0.52\n' +
55
- '4 -> 7, 0.37\n' +
56
- '4 -> 0, 0.38\n' +
57
- '5 -> 4, 0.35\n' +
58
- '5 -> 7, 0.28\n' +
59
- '5 -> 1, 0.32\n' +
60
- '6 -> 2, 0.4\n' +
61
- '6 -> 0, 0.58\n' +
62
- '6 -> 4, 0.93\n' +
63
- '7 -> 2, 0.34');
64
- });
65
- });
66
-
67
- describe("topo sort for digraph", function() {
68
- it("should sort all the vertexs", function() {
69
- var topoSort = new Topological(digraph);
70
- expect(topoSort.isDAG()).toBe(true);
71
- expect(topoSort.order()).toEqual([ 5, 1, 3, 6, 4, 7, 0, 2 ]);
72
- });
73
- });
74
-
75
- describe("shortest path tree normal operations", function() {
76
- var lpt = new SPT(digraph, 5);
77
- expect(lpt.hasPathTo(0)).toBe(true);
78
- expect(lpt.hasPathTo(1)).toBe(true);
79
- expect(lpt.hasPathTo(2)).toBe(true);
80
- expect(lpt.hasPathTo(3)).toBe(true);
81
- expect(lpt.hasPathTo(4)).toBe(true);
82
- expect(lpt.hasPathTo(5)).toBe(false);
83
- expect(lpt.hasPathTo(6)).toBe(true);
84
- expect(lpt.hasPathTo(7)).toBe(true);
85
- expect(lpt.pathTo(0)).toEqual([ 5, 4, 0 ]);
86
- expect(lpt.pathTo(1)).toEqual([ 5, 1 ]);
87
- expect(lpt.pathTo(2)).toEqual([ 5, 7, 2 ]);
88
- expect(lpt.pathTo(3)).toEqual([ 5, 1, 3 ]);
89
- expect(lpt.pathTo(4)).toEqual([ 5, 4 ]);
90
- expect(lpt.pathTo(5)).toEqual([ ]);
91
- expect(lpt.pathTo(6)).toEqual([ 5, 1, 3, 6 ]);
92
- expect(lpt.pathTo(7)).toEqual([ 5, 7 ]);
93
- expect(lpt.getDistTo(0)).toBe(0.73);
94
- expect(lpt.getDistTo(1)).toBe(0.32);
95
- expect(lpt.getDistTo(2)).toBe(0.62);
96
- expect(lpt.getDistTo(3)).toBe(0.61);
97
- expect(lpt.getDistTo(4)).toBe(0.35);
98
- expect(lpt.getDistTo(5)).toBe(0);
99
- expect(lpt.getDistTo(6)).toBe(1.13);
100
- expect(lpt.getDistTo(7)).toBe(0.28);
101
- });
102
-
103
- /**
104
- * Check the issue #150
105
- **/
106
- describe("lightest weight path", function(){
107
- it("should find the lightest weight path", function(){
108
- var digraph = new EdgeWeightedDigraph();
109
-
110
- digraph.add(1,3,0.29);
111
- digraph.add(1,6,0);
112
- digraph.add(3,6,0);
113
-
114
- var spt = new SPT(digraph, 1);
115
- var path = spt.pathTo(6);
116
- expect(path).toEqual([1,6]);
117
- });
118
- it("should find the lightest weight path", function(){
119
- var digraph = new EdgeWeightedDigraph();
120
-
121
- digraph.add(1,3,-1);
122
- digraph.add(1,6,0);
123
- digraph.add(3,6,0);
124
-
125
- var spt = new SPT(digraph, 1);
126
- var path = spt.pathTo(6);
127
- var hasPath = spt.hasPathTo(6);
128
- expect(hasPath).toBe(true);
129
- expect(path).toEqual([1,3,6]);
130
- });
131
- });
132
- });
@@ -1,154 +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 soundex = require('../lib/natural/phonetics/soundex');
24
-
25
- describe('soundex', function() {
26
- describe('transformLipps', function() {
27
- it('should replace B, F, P, and V with 1', function() {
28
- expect(soundex.transformLipps('bopper')).toBe('1o11er');
29
- expect(soundex.transformLipps('valumf')).toBe('1alum1');
30
- });
31
- });
32
-
33
- describe('transformThroats', function() {
34
- it('should replace C, G, J, K, Q, S, X, Z with 2', function() {
35
- expect(soundex.transformLipps('bopper')).toBe('1o11er');
36
- expect(soundex.transformLipps('valumf')).toBe('1alum1');
37
- });
38
- });
39
-
40
- describe('transformTongue', function() {
41
- it('should replace D and T with 3', function() {
42
- expect(soundex.transformToungue('dat')).toBe('3a3');
43
- });
44
- });
45
-
46
- describe('transformL', function() {
47
- it('should replace L with 4', function() {
48
- expect(soundex.transformL('lala')).toBe('4a4a');
49
- });
50
- });
51
-
52
- describe('transformHum', function() {
53
- it('should replace M and N with 5', function() {
54
- expect(soundex.transformHum('mummification')).toBe('5u55ificatio5');
55
- });
56
- });
57
-
58
- describe('transformR', function() {
59
- it('should replace R with 6', function() {
60
- expect(soundex.transformR('render')).toBe('6ende6');
61
- });
62
- });
63
-
64
- describe('condense', function() {
65
- it('sound condense sequences', function() {
66
- expect(soundex.condense('11222556')).toBe('1256');
67
- });
68
-
69
- it('sound condense sequences around H and W', function() {
70
- expect(soundex.condense('113w355')).toBe('135');
71
- });
72
-
73
- it('sound drop irrelevant H and W', function() {
74
- expect(soundex.condense('phonetics')).toBe('ponetics');
75
- expect(soundex.condense('towering')).toBe('toering');
76
- });
77
- });
78
-
79
- describe('padRight0', function() {
80
- it('sound padd zeros on the right to a lenght of 3', function() {
81
- expect(soundex.padRight0('1')).toBe('100');
82
- expect(soundex.padRight0('11')).toBe('110');
83
- expect(soundex.padRight0('111')).toBe('111');
84
- });
85
- });
86
-
87
- it('should not code the first character', function() {
88
- expect(soundex.process('render').charAt(0)).toBe('R');
89
- });
90
-
91
- it('should pad right with zeros', function() {
92
- expect(soundex.process('super')).toBe('S160');
93
- expect(soundex.process('butt')).toBe('B300');
94
- expect(soundex.process('a')).toBe('A000');
95
- });
96
-
97
- it('should pad right with zeros', function() {
98
- expect(soundex.process('but')).toBe('B300');
99
- });
100
-
101
- it('should perform soundex', function() {
102
- expect(soundex.process('BLACKBERRY')).toBe('B421');
103
- expect(soundex.process('blackberry')).toBe('B421');
104
- expect(soundex.process('calculate')).toBe('C424');
105
- expect(soundex.process('CALCULATE')).toBe('C424');
106
- expect(soundex.process('fox')).toBe('F200');
107
- expect(soundex.process('FOX')).toBe('F200');
108
- expect(soundex.process('jump')).toBe('J510');
109
- expect(soundex.process('JUMP')).toBe('J510');
110
- expect(soundex.process('phonetics')).toBe('P532');
111
- expect(soundex.process('PHONETICS')).toBe('P532');
112
-
113
- });
114
-
115
- it('should perform soundex via compare method', function() {
116
- expect(soundex.compare('ant', 'and')).toBeTruthy();
117
- expect(soundex.compare('ant', 'anne')).toBeFalsy();
118
- expect(soundex.compare('band', 'bant')).toBeTruthy();
119
- expect(soundex.compare('band', 'gand')).toBeFalsy();
120
- });
121
-
122
- it('should perform soundex via attached soundsLike String patch', function() {
123
- soundex.attach();
124
- expect('ant'.soundsLike('ant')).toBeTruthy();
125
- expect('ant'.soundsLike('anne')).toBeFalsy();
126
- expect('band'.soundsLike('bant')).toBeTruthy();
127
- expect('band'.soundsLike('gand')).toBeFalsy();
128
- });
129
-
130
- it('should return string phonetics with string patch', function() {
131
- soundex.attach();
132
- expect('phonetics'.phonetics()).toBe('P532');
133
- expect('PHONETICS'.phonetics()).toBe('P532');
134
- });
135
-
136
- it('should tokenize and return string phonetics with string patch', function() {
137
- soundex.attach();
138
- expect('phonetics'.tokenizeAndPhoneticize()).toEqual(['P532']);
139
- expect('phonetics jump'.tokenizeAndPhoneticize()).toEqual(['P532', 'J510']);
140
- expect('phonetics jump calculate'.tokenizeAndPhoneticize()).toEqual(['P532', 'J510', 'C424']);
141
- });
142
-
143
- it('should max out at four characters long by default', function() {
144
- expect(soundex.process('supercalifragilisticexpialidocious').length).toBe(4);
145
- });
146
-
147
- it('should truncate to specified length if maxLength passed', function() {
148
- expect(soundex.process('supercalifragilisticexpialidocious', 8).length).toBe(8);
149
- });
150
-
151
- it('should handle a maxLength beyond code length', function() {
152
- expect(soundex.process('JUMP', 8)).toBe('J510');
153
- });
154
- });
@@ -1,66 +0,0 @@
1
- /*
2
- Copyright (c) 2012, Guillaume Marty
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 StemmerJa = require('../lib/natural/stemmers/stemmer_ja');
24
- var stemmer = new StemmerJa();
25
-
26
- var test = ['コピー', 'コーヒー', 'タクシー', 'パーティー', 'パーティ', 'ヘルプ・センター'];
27
- var testResult = ['コピー', 'コーヒ', 'タクシ', 'パーティ', 'パーティ', 'ヘルプ・センタ'];
28
- var text = '明後日パーティーに行く予定がある。図書館で資料をコピーしました。';
29
-
30
- describe('StemmerJa', function() {
31
- it('should stem words', function() {
32
- for (var i = 0; i < test.length; i++) {
33
- expect(stemmer.stem(test[i])).toBe(testResult[i]);
34
- }
35
- });
36
-
37
- it('should not tokenize halfwidth katakana', function() {
38
- expect(stemmer.stem('タクシー')).toEqual('タクシー');
39
- });
40
-
41
- it('should tokenize, stem and exclude stop words (default behavior)', function() {
42
- var tokens = [
43
- '明後日', 'パーティ', '行く', '予定', // パーティー should be stemmed
44
- '図書館', '資料', 'コピー', 'まし'];
45
- expect(stemmer.tokenizeAndStem(text)).toEqual(tokens);
46
- expect(stemmer.tokenizeAndStem(text, false)).toEqual(tokens);
47
- });
48
-
49
- it('should tokenize, stem and keep stop words', function() {
50
- expect(stemmer.tokenizeAndStem(text, true)).toEqual([
51
- '明後日', 'パーティ', 'に', '行く', '予定', 'が', 'ある',
52
- '図書館', 'で', '資料', 'を', 'コピー', 'し', 'まし', 'た']);
53
- });
54
-
55
- it('should attach new methods to String', function() {
56
- stemmer.attach();
57
- expect('コーヒー'.stem()).toEqual('コーヒ');
58
- expect('コピー'.stem()).toEqual('コピー');
59
- expect('図書館で資料をコピーしました。'.tokenizeAndStem()).toEqual([
60
- '図書館', '資料', 'コピー', 'まし']);
61
- expect('図書館で資料をコピーしました。'.tokenizeAndStem(false)).toEqual([
62
- '図書館', '資料', 'コピー', 'まし']);
63
- expect('図書館で資料をコピーしました。'.tokenizeAndStem(true)).toEqual([
64
- '図書館', 'で', '資料', 'を', 'コピー', 'し', 'まし', 'た']);
65
- });
66
- });