forked from NaturalNode/natural
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalizer_ja_spec.js
More file actions
162 lines (135 loc) · 9.63 KB
/
Copy pathnormalizer_ja_spec.js
File metadata and controls
162 lines (135 loc) · 9.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright (c) 2012, Guillaume Marty
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
'use strict'
const normalizeJa = require('../lib/natural/normalizers/normalizer_ja').normalizeJa
const converters = require('../lib/natural/normalizers/normalizer_ja').converters
describe('normalizeJa', function () {
it('should fix badly formed hiragana', function () {
expect(normalizeJa('う゛か゛き゛く゛は゜ひ゜ふ゜')).toEqual('ゔがぎぐぱぴぷ')
expect(normalizeJa('ゔがぎぐぱぴぷ')).toEqual('ゔがぎぐぱぴぷ')
expect(normalizeJa('まっなか')).toEqual('まんなか')
})
it('should fix badly formed fullwidth katakana', function () {
expect(normalizeJa('ウ゛カ゛キ゛ク゛ハ゜ヒ゜フ゜')).toEqual('ヴガギグパピプ')
expect(normalizeJa('ヴガギグパピプ')).toEqual('ヴガギグパピプ')
})
it('should fix badly formed halfwidth katakana', function () {
expect(normalizeJa('ウ゛カ゛キ゛ク゛ハ゜ヒ゜フ゜')).toEqual('ヴガギグパピプ')
expect(normalizeJa('ヴガギグパピプ')).toEqual('ヴガギグパピプ')
})
it('should transform halfwidth katakana to fullwidth', function () {
expect(normalizeJa('カタカナ')).toEqual('カタカナ')
})
it('should transform fullwidth alphanumerical characters to halfwidth', function () {
expect(normalizeJa('ABC123')).toEqual('ABC123')
})
it('should transform fullwidth spaces to halfwidth', function () {
expect(normalizeJa('空 空 空')).toEqual('空 空 空')
})
it('should transform halfwidth punctuation signs to fullwidth', function () {
// Taken from http://unicode.org/cldr/trac/browser/trunk/common/main/ja.xml
expect(normalizeJa('〜 ・ ・ 、、 。。 「「 」」'))
.toEqual('〜 ・ ・ 、、 。。 「「 」」')
})
it('should transform fullwidth symbols to halfwidth', function () {
// Taken from http://unicode.org/cldr/trac/browser/trunk/common/main/ja.xml
expect(normalizeJa('‾ __ -- ‐ — ― ,, ;; :: !! ?? .. ‥ … '\ ‘ ’ "" “ ” (( )) [[ ]] {{ }} 〈 〉 《 》 『 』 【 】 〔 〕 ‖ § ¶ @@ ++ ^^ $$ ** // \\\ && ## %% ‰ † ‡ ′ ″ 〃 ※'))
.toEqual('‾ __ -- ‐ — ― ,, ;; :: !! ?? .. ‥ … '\\ ‘ ’ "" “ ” (( )) [[ ]] {{ }} 〈 〉 《 》 『 』 【 】 〔 〕 ‖ § ¶ @@ ++ ^^ $$ ** // \\\\ && ## %% ‰ † ‡ ′ ″ 〃 ※')
})
it('should replace repeat characters', function () {
expect(normalizeJa('時々刻々')).toEqual('時時刻刻')
expect(normalizeJa('甲斐々々しい')).toEqual('甲斐甲斐しい')
})
it('should replace composite symbols', function () {
expect(normalizeJa('㍼54年㋃㏪')).toEqual('昭和54年4月11日')
expect(normalizeJa('㍧〜㍬')).toEqual('15点〜20点')
expect(normalizeJa('カンパニー㍿')).toEqual('カンパニー株式会社')
expect(normalizeJa('100㌫')).toEqual('100パーセント')
expect(normalizeJa('70㌔')).toEqual('70キロ')
expect(normalizeJa('㍇')).toEqual('マンション')
})
})
const sample = 'ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ'
describe('converters', function () {
it('should all be reversible', function () {
const sample = '半角カナ(はんかくカナ)とは、JIS X 0208など片仮名を含む他の文字集合と同時に運用される場合におけるJIS X 0201の片仮名文字集合の通称である。漢字を含む文字集合で定義された片仮名に対して、半分の文字幅で表示されることが一般的であったためこのように呼ばれる。JIS X 0201で規定される8ビット符号化およびShift_JISにおいて0xA1-0xDFの範囲の1バイト文字がこれにあたる。また、Shift_JISやEUC-JPなどの符号化方式やUnicodeでも互換性の目的でこの文字集合をもっている。'
expect(converters.halfwidthToFullwidth.alphabet(converters.fullwidthToHalfwidth.alphabet(sample))).toEqual(converters.halfwidthToFullwidth.alphabet(sample))
expect(converters.fullwidthToHalfwidth.alphabet(converters.halfwidthToFullwidth.alphabet(sample))).toEqual(converters.fullwidthToHalfwidth.alphabet(sample))
expect(converters.halfwidthToFullwidth.numbers(converters.fullwidthToHalfwidth.numbers(sample))).toEqual(converters.halfwidthToFullwidth.numbers(sample))
expect(converters.fullwidthToHalfwidth.numbers(converters.halfwidthToFullwidth.numbers(sample))).toEqual(converters.fullwidthToHalfwidth.numbers(sample))
expect(converters.halfwidthToFullwidth.punctuation(converters.fullwidthToHalfwidth.punctuation(sample))).toEqual(converters.halfwidthToFullwidth.punctuation(sample))
expect(converters.fullwidthToHalfwidth.punctuation(converters.halfwidthToFullwidth.punctuation(sample))).toEqual(converters.fullwidthToHalfwidth.punctuation(sample))
expect(converters.halfwidthToFullwidth.katakana(converters.fullwidthToHalfwidth.katakana(sample))).toEqual(converters.halfwidthToFullwidth.katakana(sample))
expect(converters.fullwidthToHalfwidth.katakana(converters.halfwidthToFullwidth.katakana(sample))).toEqual(converters.fullwidthToHalfwidth.katakana(sample))
})
describe('.fullwidthToHalfwidth', function () {
describe('.alphabet', function () {
it('should transform fullwidth roman characters and space to halfwidth', function () {
expect(converters.fullwidthToHalfwidth.alphabet(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.numbers', function () {
it('should transform fullwidth numerical characters to halfwidth', function () {
expect(converters.fullwidthToHalfwidth.numbers(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.punctuation', function () {
it('should transform fullwidth punctuation signs to halfwidth', function () {
expect(converters.fullwidthToHalfwidth.punctuation(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.katakana', function () {
it('should transform fullwidth katakana to halfwidth', function () {
expect(converters.fullwidthToHalfwidth.katakana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
})
describe('.halfwidthToFullwidth', function () {
describe('.alphabet', function () {
it('should transform halfwidth roman characters and space to fullwidth', function () {
expect(converters.halfwidthToFullwidth.alphabet(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.numbers', function () {
it('should transform halfwidth numerical characters to fullwidth', function () {
expect(converters.halfwidthToFullwidth.numbers(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.punctuation', function () {
it('should transform halfwidth punctuation signs to fullwidth', function () {
expect(converters.halfwidthToFullwidth.punctuation(sample)).toEqual('ABC ABC 123123.,─.,─ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
describe('.katakana', function () {
it('should transform halfwidth katakana to fullwidth', function () {
expect(converters.halfwidthToFullwidth.katakana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱカキクケコハバパヴカキクケコハバパ')
})
})
})
describe('.hiraganaToKatakana', function () {
it('should transform hiragana to katakana', function () {
expect(converters.hiraganaToKatakana(sample)).toEqual('ABC ABC 123123.,-.,-ヴアイウエオハバパカキクケコハバパヴカキクケコハバパ')
})
})
describe('.katakanaToHiragana', function () {
it('should transform katakana to hiragana', function () {
expect(converters.katakanaToHiragana(sample)).toEqual('ABC ABC 123123.,-.,-ゔあいうえおはばぱかきくけこはばぱゔかきくけこはばぱ')
})
})
})