NLTK 라이브러리를 이용한 문장, 단어 나누기.

  • 기존의 제공되는 split()의 경우. 단어에 .이 포함되어 토큰이 형성. NLTK의 경우 나눠줌.
  • United States와 같은 단어를 한 토큰으로 만듬.


import nltk


sent = "This is an unstructed data analysis. Prof. Geum is happly to teach this. United States"

s = nltk.tokenize.sent_tokenize(sent)

print(s)


w = nltk.tokenize.word_tokenize(sent)

print(w)


# tokenize 와 split 차이.  .이 한 토큰에 같이 들어옴.

print(sent.split())

 

# 네임드 엔티티의 경우 단어를 잘끊어줌.

# 미국의 경우 합쳐서 한 토큰으로



+ Recent posts