Introducere în Prelucrarea Limbajului Natural în R
Kasey Jones
Research Data Scientist
NLP:
Subiecte acoperite:
words <- c("DW-40", "Mike's Oil", "5w30", "Joe's Gas", "Unleaded", "Plus-89")
# Finding Digits
grep("\\d", words, value = TRUE)
[1] 1 3 6
# Finding Apostrophes
grep("\\'", words, value = TRUE)
[1] "Mike's Oil" "Joe's Gasoline"
| Șablon | Potriviri text | Exemplu R | Exemplu text |
|---|---|---|---|
| \w | Orice caracter alfanumeric | gregexpr(pattern ='\w', <text>) | a |
| \d | Orice cifră | gregexpr(pattern ='\d', text) | 1 |
| \w+ | Alfanumeric de orice lungime | gregexpr(pattern ='\w+', text) | word |
| \d+ | Cifre de orice lungime | gregexpr(pattern ='\d+', text) | 1234 |
| \s | Spații | gregexpr(pattern ='\s', text) | ' ' |
| \S | Orice caracter non-spațiu | gregexpr(pattern ='\S', text) | word |
| Funcție | Scop | Sintaxă |
|---|---|---|
| grep | Găsește potrivirile șablonului într-un vector | grep(pattern ='\w', x = <vector>, value = F) |
| gsub | Înlocuiește toate potrivirile dintr-un șir/vector | gsub(pattern ='\d+', replacement = "", x = <vector>) |
Introducere în Prelucrarea Limbajului Natural în R