R로 배우는 자연어 처리 입문
Kasey Jones
Research Data Scientist
NLP:
다루는 주제:
words <- c("DW-40", "Mike's Oil", "5w30", "Joe's Gas", "Unleaded", "Plus-89")
# 숫자 찾기
grep("\\d", words, value = TRUE)
[1] 1 3 6
# 아포스트로피 찾기
grep("\\'", words, value = TRUE)
[1] "Mike's Oil" "Joe's Gasoline"
| 패턴 | 일치 텍스트 | R 예시 | 텍스트 예시 |
|---|---|---|---|
| \w | 영숫자 문자 | gregexpr(pattern ='\w', <text>) | a |
| \d | 숫자 | gregexpr(pattern ='\d', text) | 1 |
| \w+ | 임의 길이의 영숫자 | gregexpr(pattern ='\w+', text) | word |
| \d+ | 임의 길이의 숫자 | gregexpr(pattern ='\d+', text) | 1234 |
| \s | 공백 | gregexpr(pattern ='\s', text) | ' ' |
| \S | 비공백 문자 | gregexpr(pattern ='\S', text) | word |
| 함수 | 목적 | 구문 |
|---|---|---|
| grep | 벡터에서 패턴 일치 찾기 | grep(pattern ='\w', x = <vector>, value = F) |
| gsub | 문자열/벡터의 모든 일치 항목 치환 | gsub(pattern ='\d+', replacement = "", x = <vector>) |
R로 배우는 자연어 처리 입문