2017-01-05 12:09:48 +00:00
|
|
|
# coding: utf-8
|
2015-01-30 05:44:29 +00:00
|
|
|
"""Test that token.idx correctly computes index into the original string."""
|
|
|
|
|
2017-01-05 12:10:51 +00:00
|
|
|
|
2015-01-30 05:44:29 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
2015-06-07 15:24:49 +00:00
|
|
|
def test_simple_punct(en_tokenizer):
|
2017-01-05 12:10:51 +00:00
|
|
|
text = "to walk, do foo"
|
2015-06-07 15:24:49 +00:00
|
|
|
tokens = en_tokenizer(text)
|
2015-01-30 05:44:29 +00:00
|
|
|
assert tokens[0].idx == 0
|
|
|
|
assert tokens[1].idx == 3
|
|
|
|
assert tokens[2].idx == 7
|
|
|
|
assert tokens[3].idx == 9
|
|
|
|
assert tokens[4].idx == 12
|
|
|
|
|
|
|
|
|
2015-06-07 15:24:49 +00:00
|
|
|
def test_complex_punct(en_tokenizer):
|
2017-01-05 12:10:51 +00:00
|
|
|
text = "Tom (D., Ill.)!"
|
2015-06-07 15:24:49 +00:00
|
|
|
tokens = en_tokenizer(text)
|
2015-01-30 05:44:29 +00:00
|
|
|
assert tokens[0].idx == 0
|
|
|
|
assert len(tokens[0]) == 3
|
|
|
|
assert tokens[1].idx == 4
|
|
|
|
assert len(tokens[1]) == 1
|
|
|
|
assert tokens[2].idx == 5
|
|
|
|
assert len(tokens[2]) == 2
|
|
|
|
assert tokens[3].idx == 7
|
|
|
|
assert len(tokens[3]) == 1
|
|
|
|
assert tokens[4].idx == 9
|
|
|
|
assert len(tokens[4]) == 4
|
|
|
|
assert tokens[5].idx == 13
|
|
|
|
assert tokens[6].idx == 14
|