# 스탠포드 품사 태깅 프로그램(zip) 다운로드 경로 : https://nlp.stanford.edu/software/tagger.shtml#Download
import nltk
nltk.download('punkt')
## 1. 품사 태깅하기
from nltk.tag import StanfordPOSTagger
from nltk.tokenize import word_tokenize
STANFORD_POS_MODEL_PATH = 'F:/1_Study/1_BigData/7_FirstML/stanford-postagger-full-2020-11-17/models/english-bidirectional-distsim.tagger'
STANFORD_POS_JAR_PATH = 'F:/1_Study/1_BigData/7_FirstML/stanford-postagger-full-2020-11-17/stanford-postagger-4.2.0.jar'
pos_tagger = StanfordPOSTagger(STANFORD_POS_MODEL_PATH, STANFORD_POS_JAR_PATH)
text = 'One day in November 2016, the two authors of this book, Seungyeon and Youngjoo, had a coffer at Red Back cafe, which is very popular place in Mountain View.'
tokens = word_tokenize(text)
print(tokens) # 쪼개진 토큰을 출력합니다.
print()
print(pos_tagger.tag(tokens)) # 품사 태깅을 하고 그 결과를 출력합니다.
# 동사, 명사만 추출
noun_and_verbs = []
for token in pos_tagger.tag(tokens):
if token[1].startswith('V') or token[1].startswith('N'):
noun_and_verbs.append(token[0])
print(', '.join(noun_and_verbs))
출처 : 처음 배우는 머신러닝 : 기초부터 모델링, 실전 예제, 문제 해결까지
'데이터분석 > Python' 카테고리의 다른 글
머신러닝 Example by Python - 이미지 데이터를 이용한 K-평균 군집화 (이미지 인식 시스템) (0) | 2022.01.14 |
---|---|
머신러닝 Example by Python - 고유명사 태깅 시스템 만들기 (문서 분류) (0) | 2022.01.14 |
머신러닝 Example by Python - 토픽 모델 시스템 만들기 (문서 분류) (0) | 2022.01.14 |
머신러닝 Example by Python - 스팸 문자 필터 만들기 (문서 분류) (0) | 2022.01.14 |
머신러닝 Example by Python - 구매 이력 테이터를 이용한 사용자 그룹 만들기 (0) | 2022.01.14 |