Pengantar Natural Language Processing di R
Kasey Jones
Research Data Scientist
NLP:
Topik yang dibahas:
words <- c("DW-40", "Mike's Oil", "5w30", "Joe's Gas", "Unleaded", "Plus-89")
# Menemukan digit
grep("\\d", words, value = TRUE)
[1] 1 3 6
# Menemukan apostrof
grep("\\'", words, value = TRUE)
[1] "Mike's Oil" "Joe's Gasoline"
| Pola | Kecocokan Teks | Contoh R | Contoh Teks |
|---|---|---|---|
| \w | Huruf/angka mana pun | gregexpr(pattern ='\w', <text>) | a |
| \d | Digit mana pun | gregexpr(pattern ='\d', text) | 1 |
| \w+ | Huruf/angka sepanjang apa pun | gregexpr(pattern ='\w+', text) | word |
| \d+ | Digit sepanjang apa pun | gregexpr(pattern ='\d+', text) | 1234 |
| \s | Spasi | gregexpr(pattern ='\s', text) | ' ' |
| \S | Bukan spasi | gregexpr(pattern ='\S', text) | word |
| Fungsi | Tujuan | Sintaks |
|---|---|---|
| grep | Menemukan kecocokan pola dalam vektor | grep(pattern ='\w', x = <vector>, value = F) |
| gsub | Mengganti semua kecocokan string/vektor | gsub(pattern ='\d+', replacement = "", x = <vector>) |
Pengantar Natural Language Processing di R