natural 0.2.1 → 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 (106) hide show
  1. package/.npmignore +4 -11
  2. package/README.md +156 -41
  3. package/bayes_classifier.json +1 -0
  4. package/lib/natural/brill_pos_tagger/data/Dutch/README.txt +2 -0
  5. package/lib/natural/brill_pos_tagger/data/Dutch/brill_CONTEXTRULES.jg +285 -0
  6. package/lib/natural/brill_pos_tagger/data/Dutch/brill_LEXICON.jg +11699 -0
  7. package/lib/natural/brill_pos_tagger/data/English/README.txt +8 -0
  8. package/lib/natural/brill_pos_tagger/data/English/lexicon_from_posjs.json +297827 -0
  9. package/lib/natural/brill_pos_tagger/data/English/tr_from_brill_paper.txt +10 -0
  10. package/lib/natural/brill_pos_tagger/data/English/tr_from_posjs.txt +18 -0
  11. package/lib/natural/brill_pos_tagger/lib/Brill_POS_Tagger.js +136 -0
  12. package/lib/natural/brill_pos_tagger/lib/Predicate.js +410 -0
  13. package/lib/natural/brill_pos_tagger/lib/TF_Parser.js +717 -0
  14. package/lib/natural/brill_pos_tagger/lib/TF_Parser.pegjs +55 -0
  15. package/lib/natural/brill_pos_tagger/lib/TransformationRule.js +49 -0
  16. package/lib/natural/classifiers/bayes_classifier.js +6 -5
  17. package/lib/natural/classifiers/classifier.js +3 -2
  18. package/lib/natural/classifiers/logistic_regression_classifier.js +9 -5
  19. package/lib/natural/distance/dice_coefficient.js +22 -12
  20. package/lib/natural/index.js +6 -0
  21. package/lib/natural/ngrams/ngrams.js +4 -0
  22. package/lib/natural/stemmers/stemmer.js +31 -6
  23. package/lib/natural/tokenizers/regexp_tokenizer.js +3 -3
  24. package/{examples/inflection/noun.js → lib/natural/tokenizers/sentence_tokenizer.js} +14 -10
  25. package/lib/natural/tokenizers/tokenizer_case.js +58 -0
  26. package/lib/natural/util/bag.js +1 -0
  27. package/lib/natural/wordnet/wordnet.js +2 -2
  28. package/lib/natural/wordnet/wordnet_file.js +1 -1
  29. package/lr_classifier.json +1 -0
  30. package/package.json +6 -3
  31. package/package.json~ +66 -0
  32. package/benchmarks/index.js +0 -32
  33. package/benchmarks/metaphone.js +0 -27
  34. package/benchmarks/soundex.js +0 -27
  35. package/examples/classification/basic.js +0 -35
  36. package/examples/classification/recall.js +0 -28
  37. package/examples/classification/store.js +0 -37
  38. package/examples/inflection/count.js +0 -35
  39. package/examples/inflection/noun_attach.js +0 -33
  40. package/examples/phonetics/compare.js +0 -39
  41. package/examples/phonetics/sounds_like.js +0 -40
  42. package/examples/phonetics/tokenize_and_phoneticize.js +0 -54
  43. package/examples/stemming/stem_corpus.js +0 -29
  44. package/examples/stemming/stem_word.js +0 -26
  45. package/examples/tfidf/array_example.js +0 -34
  46. package/examples/tfidf/multiple_terms.js +0 -33
  47. package/examples/tfidf/tfidf_example.js +0 -44
  48. package/io_spec/test_data/tfidf/one +0 -1
  49. package/io_spec/test_data/tfidf/two +0 -1
  50. package/io_spec/tfidf_spec.js +0 -50
  51. package/io_spec/wordnet_spec.js +0 -81
  52. package/spec/aggressive_tokenizer_es_spec.js +0 -36
  53. package/spec/aggressive_tokenizer_fr_spec.js +0 -101
  54. package/spec/aggressive_tokenizer_nl_spec.js +0 -36
  55. package/spec/aggressive_tokenizer_pt_spec.js +0 -56
  56. package/spec/aggressive_tokenizer_spec.js +0 -56
  57. package/spec/bayes_classifier_spec.js +0 -173
  58. package/spec/classifier_spec.js +0 -175
  59. package/spec/count_inflector_fr_spec.js +0 -44
  60. package/spec/count_inflector_spec.js +0 -73
  61. package/spec/dice_coefficient_spec.js +0 -26
  62. package/spec/double_metaphone_spec.js +0 -752
  63. package/spec/jaro-winkler_spec.js +0 -53
  64. package/spec/lancaster_stemmer_spec.js +0 -73
  65. package/spec/levenshtein_spec.js +0 -66
  66. package/spec/logistic_regression_classifier_spec.js +0 -122
  67. package/spec/longest_path_tree_spec.js +0 -102
  68. package/spec/metaphone_spec.js +0 -252
  69. package/spec/ngram_spec.js +0 -130
  70. package/spec/ngram_zh_spec.js +0 -122
  71. package/spec/normalizer_ja_spec.js +0 -160
  72. package/spec/normalizer_no_spec.js +0 -111
  73. package/spec/normalizer_spec.js +0 -140
  74. package/spec/noun_inflector_fr_spec.js +0 -476
  75. package/spec/noun_inflector_ja_spec.js +0 -112
  76. package/spec/noun_inflector_spec.js +0 -270
  77. package/spec/porter_stemmer_fr_spec.js +0 -101
  78. package/spec/porter_stemmer_it_spec.js +0 -44
  79. package/spec/porter_stemmer_no_spec.js +0 -143
  80. package/spec/porter_stemmer_pt_spec.js +0 -50
  81. package/spec/porter_stemmer_ru_spec.js +0 -63
  82. package/spec/porter_stemmer_spec.js +0 -182
  83. package/spec/present_verb_inflector_spec.js +0 -128
  84. package/spec/remove_diacritics_spec.js +0 -31
  85. package/spec/sentence_analyzer_spec.js +0 -277
  86. package/spec/shortest_path_tree_spec.js +0 -132
  87. package/spec/soundex_spec.js +0 -158
  88. package/spec/spellcheck_spec.js +0 -92
  89. package/spec/stemmer_ja_spec.js +0 -66
  90. package/spec/stemmer_token_spec.js +0 -161
  91. package/spec/test_data/snowball_fr.txt +0 -20402
  92. package/spec/test_data/snowball_it.txt +0 -35482
  93. package/spec/test_data/snowball_no.txt +0 -20628
  94. package/spec/test_data/snowball_pt.txt +0 -32016
  95. package/spec/test_data/tfdif_testcorpus.txt +0 -7
  96. package/spec/test_data/tfidf_document1.txt +0 -1
  97. package/spec/test_data/tfidf_document2.txt +0 -1
  98. package/spec/test_data/tfidf_document3.txt +0 -1
  99. package/spec/test_data/tfidf_document4.txt +0 -1
  100. package/spec/test_data/tfidf_teststopwords.txt +0 -1
  101. package/spec/test_data/wordnet_mini.sql +0 -95
  102. package/spec/tfidf_spec.js +0 -323
  103. package/spec/tokenizer_ja_spec.js +0 -58
  104. package/spec/transliterator_ja_spec.js +0 -103
  105. package/spec/treebank_word_tokenizer_spec.js +0 -36
  106. package/spec/trie_spec.js +0 -206
@@ -1,130 +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 NGrams = require('../lib/natural/ngrams/ngrams');
24
-
25
- describe('ngrams', function() {
26
- it('should bigram a string via ngrams', function() {
27
- expect(NGrams.ngrams('these are some words', 2)).toEqual([['these', 'are'],
28
- ['are', 'some' ], ['some', 'words']]);
29
- });
30
-
31
- it('should bigram an array via ngrams', function() {
32
- expect(NGrams.ngrams(['these', 'are', 'some', 'words'], 2)).toEqual([['these', 'are'],
33
- ['are', 'some' ], ['some', 'words']]);
34
- });
35
-
36
- it('should trigram a string via ngrams', function() {
37
- expect(NGrams.ngrams('these are some words', 3)).toEqual([['these', 'are', 'some'],
38
- ['are', 'some', 'words']]);
39
- });
40
-
41
- it('should trigram an array via ngrams', function() {
42
- expect(NGrams.ngrams(['these', 'are', 'some', 'words'], 3)).toEqual([['these', 'are', 'some'],
43
- ['are', 'some', 'words']]);
44
- });
45
-
46
- describe('bigrams', function() {
47
- it('should bigram a string', function() {
48
- expect(NGrams.bigrams('these are some words')).toEqual([['these', 'are'],
49
- ['are', 'some' ], ['some', 'words']]);
50
- });
51
-
52
- it('should bigram an array', function() {
53
- expect(NGrams.bigrams(['these', 'are', 'some', 'words'])).toEqual([['these', 'are'],
54
- ['are', 'some' ], ['some', 'words']]);
55
- });
56
- });
57
-
58
- describe('trigrams', function() {
59
- it('should bigram a string', function() {
60
- expect(NGrams.trigrams('these are some words')).toEqual([['these', 'are', 'some'],
61
- ['are', 'some', 'words']]);
62
- });
63
-
64
- it('should bigram an array', function() {
65
- expect(NGrams.trigrams(['these', 'are', 'some', 'words'])).toEqual([['these', 'are', 'some'],
66
- ['are', 'some', 'words']]);
67
- });
68
- });
69
-
70
- // New Start/End Symbols Feature
71
- it('should bigram a string with start and end symbols', function() {
72
- expect(NGrams.ngrams('these are some words', 2, "[start]", "[end]")).toEqual([
73
- ['[start]', 'these'],
74
- ['these', 'are'],
75
- ['are', 'some' ],
76
- ['some', 'words'],
77
- ['words', '[end]']
78
- ]);
79
- });
80
-
81
- it('should bigram a string with start symbols only', function() {
82
- expect(NGrams.ngrams('these are some words', 2, "[start]")).toEqual([
83
- ['[start]', 'these'],
84
- ['these', 'are'],
85
- ['are', 'some' ],
86
- ['some', 'words']
87
- ]);
88
- });
89
-
90
-
91
- it('should bigram a string with end symbols only', function() {
92
- expect(NGrams.ngrams('these are some words', 2, null, "[end]")).toEqual([
93
- ['these', 'are'],
94
- ['are', 'some' ],
95
- ['some', 'words'],
96
- ['words', '[end]']
97
- ]);
98
- });
99
-
100
- it('should trigram a string with start and end symbols', function() {
101
- expect(NGrams.ngrams('these are some words', 3, '[start]', '[end]')).toEqual([
102
- ['[start]', '[start]', 'these'],
103
- ['[start]', 'these', 'are'],
104
- ['these', 'are', 'some'],
105
- ['are', 'some', 'words'],
106
- ['some', 'words', '[end]'],
107
- ['words', '[end]', '[end]']
108
- ]);
109
- });
110
-
111
- it('should 4-gram a string with start and end symbols', function() {
112
- expect(NGrams.ngrams('these are some words', 4, '[start]', '[end]')).toEqual([
113
- ['[start]', '[start]', '[start]', 'these'],
114
- ['[start]', '[start]', 'these', 'are'],
115
- ['[start]', 'these', 'are', 'some'],
116
- ['these', 'are', 'some', 'words'],
117
- ['are', 'some', 'words', '[end]'],
118
- ['some', 'words', '[end]', '[end]'],
119
- ['words', '[end]', '[end]', '[end]']
120
- ]);
121
- });
122
-
123
- it('should use french tokenizer', function(){
124
- var T = require('../lib/natural/tokenizers/aggressive_tokenizer_fr');
125
- var t = new T();
126
- NGrams.setTokenizer(t);
127
- expect(NGrams.ngrams('Un Éléphant rouge', 2)).toEqual([['Un', 'Éléphant'],
128
- ['Éléphant', 'rouge' ]]);
129
- });
130
- });
@@ -1,122 +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
-
23
- var NGramsZH = require('../lib/natural/ngrams/ngrams_zh');
24
-
25
- describe('ngrams', function() {
26
- it('should bigram a string via ngrams', function() {
27
- expect(NGramsZH.ngrams('中文文本测试', 2)).toEqual([['中', '文'],
28
- ['文', '文' ], ['文', '本'], ['本','测'], ['测', '试']]);
29
- });
30
-
31
- it('should bigram an array via ngrams', function() {
32
- expect(NGramsZH.ngrams(['中','文','文','本','测','试'], 2)).toEqual([['中', '文'],
33
- ['文', '文' ], ['文', '本'], ['本','测'], ['测', '试']]);
34
- });
35
-
36
- it('should trigram a string via ngrams', function() {
37
- expect(NGramsZH.ngrams('中文文本测试', 3)).toEqual([['中', '文', '文'],
38
- ['文', '文', '本'],['文','本','测'],['本','测','试']]);
39
- });
40
-
41
- it('should trigram an array via ngrams', function() {
42
- expect(NGramsZH.ngrams(['中','文','文','本','测','试'], 3)).toEqual([['中', '文', '文'],
43
- ['文', '文', '本'],['文','本','测'],['本','测','试']]);
44
- });
45
-
46
- describe('bigrams', function() {
47
- it('should bigram a string', function() {
48
- expect(NGramsZH.bigrams('中文文本测试')).toEqual([['中', '文'],
49
- ['文', '文' ], ['文', '本'], ['本','测'], ['测', '试']]);
50
- });
51
-
52
- it('should bigram an array', function() {
53
- expect(NGramsZH.bigrams(['中','文','文','本','测','试'])).toEqual([['中', '文'],
54
- ['文', '文' ], ['文', '本'], ['本','测'], ['测', '试']]);
55
- });
56
- });
57
-
58
- describe('trigrams', function() {
59
- it('should trigram a string', function() {
60
- expect(NGramsZH.ngrams('中文文本测试', 3)).toEqual([['中', '文', '文'],
61
- ['文', '文', '本'],['文','本','测'],['本','测','试']]);
62
- });
63
-
64
- it('should bigram an array', function() {
65
- expect(NGramsZH.ngrams(['中','文','文','本','测','试'], 3)).toEqual([['中', '文', '文'],
66
- ['文', '文', '本'],['文','本','测'],['本','测','试']]);
67
- });
68
- });
69
-
70
- it('should bigram a string with start and end symbols', function() {
71
- expect(NGramsZH.ngrams('中文测试', 2, "[start]", "[end]")).toEqual([
72
- ['[start]', '中'],
73
- ['中', '文'],
74
- ['文', '测' ],
75
- ['测', '试'],
76
- ['试', '[end]']
77
- ]);
78
- });
79
-
80
- it('should bigram a string with start symbols only', function() {
81
- expect(NGramsZH.ngrams('中文测试', 2, "[start]")).toEqual([
82
- ['[start]', '中'],
83
- ['中', '文'],
84
- ['文', '测' ],
85
- ['测', '试']
86
- ]);
87
- });
88
-
89
-
90
- it('should bigram a string with end symbols only', function() {
91
- expect(NGramsZH.ngrams('中文测试', 2, null, "[end]")).toEqual([
92
- ['中', '文'],
93
- ['文', '测' ],
94
- ['测', '试'],
95
- ['试', '[end]']
96
- ]);
97
- });
98
-
99
- it('should trigram a string with start and end symbols', function() {
100
- expect(NGramsZH.ngrams('中文测试', 3, '[start]', '[end]')).toEqual([
101
- ['[start]', '[start]', '中'],
102
- ['[start]', '中', '文'],
103
- ['中', '文', '测'],
104
- ['文', '测', '试'],
105
- ['测', '试', '[end]'],
106
- ['试', '[end]', '[end]']
107
- ]);
108
- });
109
-
110
- it('should 4-gram a string with start and end symbols', function() {
111
- expect(NGramsZH.ngrams('中文测试', 4, '[start]', '[end]')).toEqual([
112
- ['[start]', '[start]', '[start]', '中'],
113
- ['[start]', '[start]', '中', '文'],
114
- ['[start]', '中', '文', '测'],
115
- ['中', '文', '测', '试'],
116
- ['文', '测', '试', '[end]'],
117
- ['测', '试', '[end]', '[end]'],
118
- ['试', '[end]', '[end]', '[end]']
119
- ]);
120
- });
121
-
122
- });
@@ -1,160 +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 normalize_ja = require('../lib/natural/normalizers/normalizer_ja').normalize_ja;
24
- var converters = require('../lib/natural/normalizers/normalizer_ja').converters;
25
-
26
- describe('normalize_ja', function() {
27
- it('should fix badly formed hiragana', function() {
28
- expect(normalize_ja('う゛か゛き゛く゛は゜ひ゜ふ゜')).toEqual('ゔがぎぐぱぴぷ');
29
- expect(normalize_ja('ゔがぎぐぱぴぷ')).toEqual('ゔがぎぐぱぴぷ');
30
- expect(normalize_ja('まっなか')).toEqual('まんなか');
31
- });
32
-
33
- it('should fix badly formed fullwidth katakana', function() {
34
- expect(normalize_ja('ウ゛カ゛キ゛ク゛ハ゜ヒ゜フ゜')).toEqual('ヴガギグパピプ');
35
- expect(normalize_ja('ヴガギグパピプ')).toEqual('ヴガギグパピプ');
36
- });
37
-
38
- it('should fix badly formed halfwidth katakana', function() {
39
- expect(normalize_ja('ウ゛カ゛キ゛ク゛ハ゜ヒ゜フ゜')).toEqual('ヴガギグパピプ');
40
- expect(normalize_ja('ヴガギグパピプ')).toEqual('ヴガギグパピプ');
41
- });
42
-
43
- it('should transform halfwidth katakana to fullwidth', function() {
44
- expect(normalize_ja('カタカナ')).toEqual('カタカナ');
45
- });
46
-
47
- it('should transform fullwidth alphanumerical characters to halfwidth', function() {
48
- expect(normalize_ja('ABC123')).toEqual('ABC123');
49
- });
50
-
51
- it('should transform fullwidth spaces to halfwidth', function() {
52
- expect(normalize_ja('空 空 空')).toEqual('空 空 空');
53
- });
54
-
55
- it('should transform halfwidth punctuation signs to fullwidth', function() {
56
- // Taken from http://unicode.org/cldr/trac/browser/trunk/common/main/ja.xml
57
- expect(normalize_ja('〜 ・ ・ 、、 。。 「「 」」'))
58
- .toEqual('〜 ・ ・ 、、 。。 「「 」」');
59
- });
60
-
61
- it('should transform fullwidth symbols to halfwidth', function() {
62
- // Taken from http://unicode.org/cldr/trac/browser/trunk/common/main/ja.xml
63
- expect(normalize_ja('‾ __ -- ‐ — ― ,, ;; :: !! ?? .. ‥ … '\ ‘ ’ "" “ ” (( )) [[ ]] {{ }} 〈 〉 《 》 『 』 【 】 〔 〕 ‖ § ¶ @@ ++ ^^ $$ ** // \\\ && ## %% ‰ † ‡ ′ ″ 〃 ※'))
64
- .toEqual('‾ __ -- ‐ — ― ,, ;; :: !! ?? .. ‥ … '\\ ‘ ’ "" “ ” (( )) [[ ]] {{ }} 〈 〉 《 》 『 』 【 】 〔 〕 ‖ § ¶ @@ ++ ^^ $$ ** // \\\\ && ## %% ‰ † ‡ ′ ″ 〃 ※');
65
- });
66
-
67
- it('should replace repeat characters', function() {
68
- expect(normalize_ja('時々刻々')).toEqual('時時刻刻');
69
- expect(normalize_ja('甲斐々々しい')).toEqual('甲斐甲斐しい');
70
- });
71
-
72
- it('should replace composite symbols', function() {
73
- expect(normalize_ja('㍼54年㋃㏪')).toEqual('昭和54年4月11日');
74
- expect(normalize_ja('㍧〜㍬')).toEqual('15点〜20点');
75
- expect(normalize_ja('カンパニー㍿')).toEqual('カンパニー株式会社');
76
- expect(normalize_ja('100㌫')).toEqual('100パーセント');
77
- expect(normalize_ja('70㌔')).toEqual('70キロ');
78
- expect(normalize_ja('㍇')).toEqual('マンション');
79
- });
80
- });
81
-
82
- var sample = 'ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ';
83
-
84
- describe('converters', function() {
85
- it('should all be reversible', function() {
86
- var sample = '半角カナ(はんかくカナ)とは、JIS X 0208など片仮名を含む他の文字集合と同時に運用される場合におけるJIS X 0201の片仮名文字集合の通称である。漢字を含む文字集合で定義された片仮名に対して、半分の文字幅で表示されることが一般的であったためこのように呼ばれる。JIS X 0201で規定される8ビット符号化およびShift_JISにおいて0xA1-0xDFの範囲の1バイト文字がこれにあたる。また、Shift_JISやEUC-JPなどの符号化方式やUnicodeでも互換性の目的でこの文字集合をもっている。';
87
- expect(converters.halfwidthToFullwidth.alphabet(converters.fullwidthToHalfwidth.alphabet(sample))).toEqual(converters.halfwidthToFullwidth.alphabet(sample));
88
- expect(converters.fullwidthToHalfwidth.alphabet(converters.halfwidthToFullwidth.alphabet(sample))).toEqual(converters.fullwidthToHalfwidth.alphabet(sample));
89
- expect(converters.halfwidthToFullwidth.numbers(converters.fullwidthToHalfwidth.numbers(sample))).toEqual(converters.halfwidthToFullwidth.numbers(sample));
90
- expect(converters.fullwidthToHalfwidth.numbers(converters.halfwidthToFullwidth.numbers(sample))).toEqual(converters.fullwidthToHalfwidth.numbers(sample));
91
- expect(converters.halfwidthToFullwidth.punctuation(converters.fullwidthToHalfwidth.punctuation(sample))).toEqual(converters.halfwidthToFullwidth.punctuation(sample));
92
- expect(converters.fullwidthToHalfwidth.punctuation(converters.halfwidthToFullwidth.punctuation(sample))).toEqual(converters.fullwidthToHalfwidth.punctuation(sample));
93
- expect(converters.halfwidthToFullwidth.katakana(converters.fullwidthToHalfwidth.katakana(sample))).toEqual(converters.halfwidthToFullwidth.katakana(sample));
94
- expect(converters.fullwidthToHalfwidth.katakana(converters.halfwidthToFullwidth.katakana(sample))).toEqual(converters.fullwidthToHalfwidth.katakana(sample));
95
- });
96
-
97
- describe('.fullwidthToHalfwidth', function() {
98
- describe('.alphabet', function() {
99
- it('should transform fullwidth roman characters and space to halfwidth', function() {
100
- expect(converters.fullwidthToHalfwidth.alphabet(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
101
- });
102
- });
103
-
104
- describe('.numbers', function() {
105
- it('should transform fullwidth numerical characters to halfwidth', function() {
106
- expect(converters.fullwidthToHalfwidth.numbers(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
107
- });
108
- });
109
-
110
- describe('.punctuation', function() {
111
- it('should transform fullwidth punctuation signs to halfwidth', function() {
112
- expect(converters.fullwidthToHalfwidth.punctuation(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
113
- });
114
- });
115
-
116
- describe('.katakana', function() {
117
- it('should transform fullwidth katakana to halfwidth', function() {
118
- expect(converters.fullwidthToHalfwidth.katakana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
119
- });
120
- });
121
- });
122
-
123
- describe('.halfwidthToFullwidth', function() {
124
- describe('.alphabet', function() {
125
- it('should transform halfwidth roman characters and space to fullwidth', function() {
126
- expect(converters.halfwidthToFullwidth.alphabet(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
127
- });
128
- });
129
-
130
- describe('.numbers', function() {
131
- it('should transform halfwidth numerical characters to fullwidth', function() {
132
- expect(converters.halfwidthToFullwidth.numbers(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
133
- });
134
- });
135
-
136
- describe('.punctuation', function() {
137
- it('should transform halfwidth punctuation signs to fullwidth', function() {
138
- expect(converters.halfwidthToFullwidth.punctuation(sample)).toEqual('ABC ABC 123123.,─.,─ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
139
- });
140
- });
141
-
142
- describe('.katakana', function() {
143
- it('should transform halfwidth katakana to fullwidth', function() {
144
- expect(converters.halfwidthToFullwidth.katakana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ');
145
- });
146
- });
147
- });
148
-
149
- describe('.hiraganaToKatakana', function() {
150
- it('should transform hiragana to katakana', function() {
151
- expect(converters.hiraganaToKatakana(sample)).toEqual('ABC ABC 123123.,-.,-ヴアイウエオハバパカキクケコハバパヴカキクケコハバパ');
152
- });
153
- });
154
-
155
- describe('.katakanaToHiragana', function() {
156
- it('should transform katakana to hiragana', function() {
157
- expect(converters.katakanaToHiragana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱかきくけこはばぱゔかきくけこはばぱ');
158
- });
159
- });
160
- });
@@ -1,111 +0,0 @@
1
- /*
2
- Copyright (c) 2014, Kristoffer Brabrand
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 normalizer = require("../lib/natural/normalizers/normalizer_no.js");
24
-
25
- describe('normalizer_no', function() {
26
-
27
- /**
28
- * Test character normalization
29
- **/
30
- describe("Normalization of diacritical marks", function(){
31
- it("should leave uppercase and lowercase ä's untouched", function() {
32
- expect(normalizer.remove_diacritics('ä')).toBe('ä');
33
- expect(normalizer.remove_diacritics('Ä')).toBe('Ä');
34
- });
35
-
36
- it("should leave uppercase and lowercase ö's untouched", function() {
37
- expect(normalizer.remove_diacritics('ö')).toBe('ö');
38
- expect(normalizer.remove_diacritics('Ö')).toBe('Ö');
39
- });
40
-
41
- it("should leave uppercase and lowercase ü's untouched", function() {
42
- expect(normalizer.remove_diacritics('ü')).toBe('ü');
43
- expect(normalizer.remove_diacritics('Ü')).toBe('Ü');
44
- });
45
-
46
- it("should correctly normalize uppercase and lowercase a's with grave accents", function(){
47
- expect(normalizer.remove_diacritics('à')).toBe('a');
48
- expect(normalizer.remove_diacritics('À')).toBe('A');
49
- });
50
-
51
- it("should correctly normalize uppercase and lowercase a's with acute accents", function(){
52
- expect(normalizer.remove_diacritics('á')).toBe('a');
53
- expect(normalizer.remove_diacritics('Á')).toBe('A');
54
- });
55
-
56
- it("should correctly normalize uppercase and lowercase a's with circumflex accents", function(){
57
- expect(normalizer.remove_diacritics('â')).toBe('a');
58
- expect(normalizer.remove_diacritics('Â')).toBe('A');
59
- });
60
-
61
- it("should correctly normalize uppercase and lowercase c's with cedillas", function(){
62
- expect(normalizer.remove_diacritics('ç')).toBe('c');
63
- expect(normalizer.remove_diacritics('Ç')).toBe('C');
64
- });
65
-
66
- it("should correctly normalize uppercase and lowercase e's with grave accents", function(){
67
- expect(normalizer.remove_diacritics('è')).toBe('e');
68
- expect(normalizer.remove_diacritics('È')).toBe('E');
69
- });
70
-
71
- it("should correctly normalize uppercase and lowercase e's with acute accents", function(){
72
- expect(normalizer.remove_diacritics('é')).toBe('e');
73
- expect(normalizer.remove_diacritics('É')).toBe('E');
74
- });
75
-
76
- it("should correctly normalize uppercase and lowercase e's with circumflex accents", function(){
77
- expect(normalizer.remove_diacritics('ê')).toBe('e');
78
- expect(normalizer.remove_diacritics('Ê')).toBe('E');
79
- });
80
-
81
- it("should correctly normalize uppercase and lowercase i's with circumflex accents", function(){
82
- expect(normalizer.remove_diacritics('î')).toBe('i');
83
- expect(normalizer.remove_diacritics('Î')).toBe('I');
84
- });
85
-
86
- it("should correctly normalize uppercase and lowercase n's with tildes", function(){
87
- expect(normalizer.remove_diacritics('ñ')).toBe('n');
88
- expect(normalizer.remove_diacritics('Ñ')).toBe('N');
89
- });
90
-
91
- it("should correctly normalize uppercase and lowercase o's with acute accents", function(){
92
- expect(normalizer.remove_diacritics('ó')).toBe('o');
93
- expect(normalizer.remove_diacritics('Ó')).toBe('O');
94
- });
95
-
96
- it("should correctly normalize uppercase and lowercase o's with circumflex accents", function(){
97
- expect(normalizer.remove_diacritics('ô')).toBe('o');
98
- expect(normalizer.remove_diacritics('Ô')).toBe('O');
99
- });
100
-
101
- it("should correctly normalize uppercase and lowercase u's with circumflex accents", function(){
102
- expect(normalizer.remove_diacritics('û')).toBe('u');
103
- expect(normalizer.remove_diacritics('Û')).toBe('U');
104
- });
105
-
106
- it("should correctly normalize uppercase and lowercase s's with caron/wedge accents", function(){
107
- expect(normalizer.remove_diacritics('š')).toBe('s');
108
- expect(normalizer.remove_diacritics('Š')).toBe('S');
109
- });
110
- });
111
- });