기본적인 토크나이저가 준비되었으므로 이디스 워튼의 소설 전체에 적용해 보겠습니다.
preprocessed = re.split(r'([,.:;?_!"()\']|--|\s)', raw_text)
preprocessed = [item.strip() for item in preprocessed if item.strip()]
print(len(preprocessed))
이 print 명령은 4690을 출력합니다. 이는 (공백을 제외한) 텍스트에 있는 토큰의 개수입니다. 눈으로 확인해 보기 위해 처음 30개의 토큰을 출력해 보죠.
print(preprocessed[:30])
출력 결과를 보면 모든 단어와 특수 문자가 분리되어 있으므로 이 토크나이저가 텍스트를 잘 처리한 것 같습니다.
['I', 'HAD', 'always', 'thought', 'Jack', 'Gisburn', 'rather', 'a', 'cheap', 'genius', '--', 'though', 'a', 'good', 'fellow', 'enough', '--', 'so', 'it', 'was', 'no', 'great', 'surprise', 'to', 'me', 'to', 'hear', 'that', ',', 'in']