Skip to content

Commit

Permalink
output captured
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Jul 19, 2019
1 parent a35ec1e commit 6ff8db9
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
env
.gitignore
^README\.Rmd$
model
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
env
model
18 changes: 13 additions & 5 deletions R/deps.R → R/funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,41 @@ install_stanfordnlp <- function(method = "auto", conda = "auto") {
#' Download a language pack.
#'
#' @param lang Model language.
#'
#' @param dir Path to directory where to save model.
#'
#' @examples
#' \dontrun{
#' download_model()
#' }
#'
#' @export
download_model <- function(lang = "en"){
stanfordnlp$download(lang)
download_model <- function(lang = "en", dir = NULL){
if(is.null(dir))
stanfordnlp$download(lang)
else
stanfordnlp$download(lang, dir)
}

#' Pipeline
#'
#' Create a pipeline.
#'
#' @inheritParams download_model
#' @param ... Parameters (all optional), see details.
#'
#' @details
#' \itemize{
#' \item{\code{lang}: Model language.}
#' \item{\code{treebank}: Treebank code from \url{https://stanfordnlp.github.io/stanfordnlp/models.html}..}
#' \item{\code{treebank}: Treebank code from \url{https://stanfordnlp.github.io/stanfordnlp/models.html}.}
#' \item{\code{processors}: Processors to use \code{tokenize,mwt,pos,lemma,depparse}.}
#' \item{\code{models_dir}: Directory where model is stored.}
#' \item{\code{use_gpu}: Boolean indicating whether to use the machine's GPU.}
#' }
#'
#' @examples
#' \dontrun{
#' nlp <- create_pipeline()
#' doc <- nlp("Barack Obama was born in Hawaii.")
#' doc$sentences[[0]]$print_dependencies()
#' }
#'
#' @export
Expand Down
1 change: 0 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
stanfordnlp <- NULL

.onLoad <- function(libname, pkgname) {
# use superassignment to update global reference to scipy
stanfordnlp <<- reticulate::import("stanfordnlp", delay_load = TRUE)
}
18 changes: 13 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ remotes::install_github("news-r/stanfordnlp")

Reproduction of [quick example](https://stanfordnlp.github.io/stanfordnlp/installation_usage.html)

```{r}
```{r, eval=FALSE}
library(stanfordnlp)
download_model(lang = "en")
pipeline <- create_pipeline()
doc <- pipeline("Barack Obama was born in Hawaii. He was elected president in 2008.")
doc$sentences[[1]]$print_dependencies()
```

```{r, echo=FALSE}
library(stanfordnlp)
reticulate::use_virtualenv("./env")
# Quick Example from site
# https://stanfordnlp.github.io/stanfordnlp/installation_usage.html
download_model(lang = "en")
pipeline <- create_pipeline()
doc <- pipeline("Barack Obama was born in Hawaii. He was elected president in 2008.")
doc$sentences[[1]]$print_dependencies()
pipeline <- create_pipeline(models_dir = "model")
doc <- pipeline("Barack Obama was born in Hawaii. He was elected president in 2008.")
cat(reticulate::py_capture_output(doc$sentences[[1]]$print_dependencies()))
```
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ example](https://stanfordnlp.github.io/stanfordnlp/installation_usage.html)
``` r
library(stanfordnlp)

reticulate::use_virtualenv("./env")

# Quick Example from site
# https://stanfordnlp.github.io/stanfordnlp/installation_usage.html
download_model(lang = "en")
pipeline <- create_pipeline()
doc <- pipeline("Barack Obama was born in Hawaii. He was elected president in 2008.")
doc <- pipeline("Barack Obama was born in Hawaii. He was elected president in 2008.")
doc$sentences[[1]]$print_dependencies()
```

#> ('Barack', '4', 'nsubj:pass')
#> ('Obama', '1', 'flat')
#> ('was', '4', 'aux:pass')
#> ('born', '0', 'root')
#> ('in', '6', 'case')
#> ('Hawaii', '4', 'obl')
#> ('.', '4', 'punct')
12 changes: 10 additions & 2 deletions man/create_pipeline.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/download_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/install_stanfordnlp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ff8db9

Please sign in to comment.