1. 学ぶ
  2. /
  3. コース
  4. /
  5. spaCy로 배우는 Advanced NLP

Connected

演習

데이터 구조 모범 사례

이 예시의 코드는 텍스트를 분석해 모든 고유 명사를 수집하려고 합니다. 고유 명사 다음에 오는 토큰이 동사라면, 그 동사도 함께 추출해야 합니다. doc 객체는 이미 만들어져 있습니다.

# Get all tokens and part-of-speech tags
pos_tags = [token.pos_ for token in doc]

for index, pos in enumerate(pos_tags):
    # Check if the current token is a proper noun
    if pos == 'PROPN':
        # Check if the next token is a verb
        if pos_tags[index + 1] == 'VERB':
            print('Found a verb after a proper noun!')

指示1 / 2

undefined XP
    1
    2

質問

왜 이 코드는 좋지 않을까요?

選択肢