-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
76 lines (54 loc) · 2.13 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# rflashtext
<!-- badges: start -->
[![R-CMD-check](https://github.com/AbrJA/rflashtext/workflows/R-CMD-check/badge.svg)](https://cran.r-project.org/web/checks/check_results_rflashtext.html)
[![Grand-total](https://cranlogs.r-pkg.org/badges/grand-total/rflashtext)](https://github.com/AbrJA/rflashtext/actions)
[![Per-month](https://cranlogs.r-pkg.org/badges/rflashtext)](https://CRAN.R-project.org/package=rflashtext)
<!-- badges: end -->
_rflashtext_ **can be used to find and replace words in a given text with only one pass over the document.**
It's a R implementation of the [FlashText algorithm](https://arxiv.org/abs/1711.00046) and it's inspired on the python library [flashtext](https://github.com/vi3k6i5/flashtext).
## Installation
You can install the released version of rflashtext from [CRAN](https://CRAN.R-project.org/package=rflashtext) with:
``` r
install.packages("rflashtext")
```
And the development version from [GitHub](https://github.com/AbrJA/rflashtext) with:
```r
install.packages("devtools")
devtools::install_github("AbrJA/rflashtext")
```
## Example
This is a basic example which shows you how to use the API:
### New processor
```{r new}
library(rflashtext)
processor <- KeywordProcessor$new(keys = c("NY", "LA"), words = c("New York", "Los Angeles"))
processor$show_trie()
```
### Add keys-words to processor
```{r add}
processor$add_keys_words(keys = c("TX", "CA"), words = c("Texas", "California"))
processor$show_trie()
```
### Find keys in a sentence
```{r}
words_found <- processor$find_keys(sentences = c("I live in LA and I like NY", "Have you been in TX?"))
words_found
data.table::rbindlist(words_found)
```
### Replace keys in a sentence
```{r}
processor$replace_keys(sentences = c("I live in LA and I like NY", "Have you been in TX?"))
```
To see more details about the performance of the algorithm, click [here](https://github.com/AbrJA/rflashtext_benchmark).