forked from NaturalNode/natural
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordPunctTokenizer_spec.js
More file actions
57 lines (49 loc) · 3.37 KB
/
Copy pathWordPunctTokenizer_spec.js
File metadata and controls
57 lines (49 loc) · 3.37 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
/*
Copyright (c) 2018, Hugo W.L. ter Doest
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 natural = require('../lib/natural')
const tokenizer = new natural.WordPunctTokenizer()
const sentences = [
'Knot: geldpers aanzetten is paardenmiddel voor half procent inflatie',
'De president van De Nederlandsche Bank, Klaas Knot, vindt de geldinjectie in de Europese economie van ruim 1.100 miljard euro veel te hoog voor het beoogde resultaat: een half procent inflatie in 2016.',
"'Oftewel 50 basispunten, dat zijn heel dure basispunten', zei Knot donderdag in de Tweede Kamer.",
'Door: Robert Giebels 5 februari 2015, 21:55 Bron: ANP',
'De financiële specialisten onder de Kamerleden hadden Knot gevraagd uitleg te geven over het ECB-besluit van 22 januari.;',
'Hoe gaat de tokenizer om met? vraagtekens ?',
'Verbindingsstreepje in een woord: ECB-besluit',
'Gedachtestreepje in een zin met spaties eromheen - dit is de gedachte na het streepje ! '
]
const expectedResults = [
['Knot', ':', 'geldpers', 'aanzetten', 'is', 'paardenmiddel', 'voor', 'half', 'procent', 'inflatie'],
['De', 'president', 'van', 'De', 'Nederlandsche', 'Bank', ',', 'Klaas', 'Knot', ',', 'vindt', 'de', 'geldinjectie', 'in', 'de', 'Europese', 'economie', 'van', 'ruim', '1.100', 'miljard', 'euro', 'veel', 'te', 'hoog', 'voor', 'het', 'beoogde', 'resultaat', ':', 'een', 'half', 'procent', 'inflatie', 'in', '2016.'],
["'", 'Oftewel', '50', 'basispunten', ',', 'dat', 'zijn', 'heel', 'dure', 'basispunten', "'", ',', 'zei', 'Knot', 'donderdag', 'in', 'de', 'Tweede', 'Kamer', '.'],
['Door', ':', 'Robert', 'Giebels', '5', 'februari', '2015', ',', '21', ':', '55', 'Bron', ':', 'ANP'],
['De', 'financiële', 'specialisten', 'onder', 'de', 'Kamerleden', 'hadden', 'Knot', 'gevraagd', 'uitleg', 'te', 'geven', 'over', 'het', 'ECB-besluit', 'van', '22', 'januari', '.', ';'],
['Hoe', 'gaat', 'de', 'tokenizer', 'om', 'met', '?', 'vraagtekens', '?'],
['Verbindingsstreepje', 'in', 'een', 'woord', ':', 'ECB-besluit'],
['Gedachtestreepje', 'in', 'een', 'zin', 'met', 'spaties', 'eromheen', '-', 'dit', 'is', 'de', 'gedachte', 'na', 'het', 'streepje', '!']
]
describe('Word Punctuation Tokenizer', function () {
it('should correctly tokenize words and punctuation symbols', function () {
sentences.forEach((sentence, index) => {
const result = tokenizer.tokenize(sentence)
expect(result).toEqual(expectedResults[index])
})
})
})