-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtoken.test.js
More file actions
76 lines (69 loc) · 2.35 KB
/
token.test.js
File metadata and controls
76 lines (69 loc) · 2.35 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
import spacy from '../src'
import { Doc, Token } from '../src/tokens'
import { text, words, spaces, attrs } from './util'
jest.mock('../src/language')
const nlp = spacy.load('en_core_web_sm')
test('allows manual construction', async () => {
const doc = await nlp(text)
const token = new Token(doc, words[7], spaces[7], attrs.tokens[7])
expect(token).toBeInstanceOf(Token)
expect(token.text).toBe('about')
})
test('allows indexing from Doc', async () => {
const doc = await nlp(text)
const token = doc[7]
expect(token.text).toBe('about')
})
test('has Token attributes', async () => {
const doc = await nlp(text)
const token = doc[7]
expect(token.length).toBe(5)
expect(token.toString()).toBe('about')
expect(token.text).toBe('about')
expect(token.textWithWs).toBe('about ')
expect(token.whitespace).toBe(' ')
expect(token.orth).toBe(942632335873952620)
expect(token.i).toBe(7)
expect(token.entType).toBe('')
expect(token.entIob).toBe('O')
expect(token.lemma).toBe('about')
expect(token.norm).toBe('about')
expect(token.lower).toBe('about')
expect(token.shape).toBe('xxxx')
expect(token.prefix).toBe('a')
expect(token.suffix).toBe('out')
expect(token.pos).toBe('ADP')
expect(token.tag).toBe('IN')
expect(token.dep).toBe('prep')
expect(token.isAlpha).toBe(true)
expect(token.isAscii).toBe(true)
expect(token.isDigit).toBe(false)
expect(token.isLower).toBe(true)
expect(token.isUpper).toBe(false)
expect(token.isTitle).toBe(false)
expect(token.isPunct).toBe(false)
expect(token.isLeftPunct).toBe(false)
expect(token.isRightPunct).toBe(false)
expect(token.isSpace).toBe(false)
expect(token.isBracket).toBe(false)
expect(token.isCurrency).toBe(false)
expect(token.likeUrl).toBe(false)
expect(token.likeNum).toBe(false)
expect(token.likeEmail).toBe(false)
expect(token.isOov).toBe(true)
expect(token.isStop).toBe(true)
expect(token.isSentStart).toBe(null)
})
test('has parent Doc', async () => {
const doc = await nlp(text)
const token = doc[7]
expect(token.doc).toBeInstanceOf(Doc)
expect(token.doc).toBe(doc)
})
test('has head', async () => {
const doc = await nlp(text)
const head = doc[7].head
expect(head).toBeInstanceOf(Token)
expect(head.i).toBe(6)
expect(head.text).toBe('sentence')
})