Skip to content

Commit

Permalink
rm magrittr as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSpannbauer committed Dec 11, 2017
1 parent fbf0e38 commit 3809424
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ URL: https://github.com/AdamSpannbauer/lexRankr/
BugReports: https://github.com/AdamSpannbauer/lexRankr/issues/
LazyData: TRUE
RoxygenNote: 6.0.1
Imports: magrittr, SnowballC, igraph, Rcpp
Imports: SnowballC, igraph, Rcpp
Depends: R (>= 2.10)
LinkingTo: Rcpp
Suggests: covr, testthat, R.rsp
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export(tokenize)
export(unnest_sentences)
export(unnest_sentences_)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
importFrom(stats,xtabs)
importFrom(utils,combn)
useDynLib(lexRankr)
5 changes: 4 additions & 1 deletion R/bind_lexrank.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
#' @param ... tokenizing options to be passed to lexRankr::tokenize. Ignored if \code{level} is "sentences"
#' @return A dataframe with an additional column of lexrank scores (column is given name lexrank)
#' @examples
#' library(magrittr)
#'
#' df <- data.frame(doc_id = 1:3,
#' text = c("Testing the system. Second sentence for you.",
#' "System testing the tidy documents df.",
#' "Documents will be parsed and lexranked."),
#' stringsAsFactors = FALSE)
#'
#' \dontrun{
#' library(magrittr)
#'
#' df %>%
#' unnest_sentences(sents, text) %>%
#' bind_lexrank(sents, doc_id, level = "sentences")
Expand All @@ -42,6 +44,7 @@
#'
#' df %>%
#' bind_lexrank(tokens, doc_id, sent_id, level = 'tokens')
#' }
#' @export
bind_lexrank_ <- function(tbl, text, doc_id, sent_id=NULL, level=c("sentences", "tokens"), threshold=.2, usePageRank=TRUE, damping=0.85, continuous=FALSE, ...) {
if(!is.data.frame(tbl)) stop("tbl must be a dataframe")
Expand Down
1 change: 0 additions & 1 deletion R/lexRank.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#' lexRank(c("This is a test.","Tests are fun.",
#' "Do you think the exam will be hard?","Is an exam the same as a test?",
#' "How many questions are going to be on the exam?"))
#' @importFrom magrittr "%>%"

#' @export
lexRank <- function(text, docId = "create", threshold=.2, n=3, returnTies=TRUE, usePageRank=TRUE, damping=0.85, continuous=FALSE, sentencesAsDocs=FALSE, removePunc=TRUE, removeNum=TRUE, toLower=TRUE, stemWords=TRUE, rmStopWords=TRUE, Verbose=TRUE){
Expand Down
1 change: 0 additions & 1 deletion R/lexRankFromSimil.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#' @references \url{http://www.cs.cmu.edu/afs/cs/project/jair/pub/volume22/erkan04a-html/erkan04a.html}
#' @examples
#' lexRankFromSimil(s1=c("d1_1","d1_1","d1_2"), s2=c("d1_2","d2_1","d2_1"), simil=c(.01,.03,.5))
#' @importFrom magrittr "%>%"

#' @export

Expand Down
1 change: 0 additions & 1 deletion R/sentenceParse.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#' sentenceParse("Bill is trying to earn a Ph.D.", "You have to have a 5.0 GPA.")
#' sentenceParse(c("Bill is trying to earn a Ph.D.", "You have to have a 5.0 GPA."),
#' docId=c("d1","d2"))
#' @importFrom magrittr "%>%"

#' @export
sentenceParse <- function(text, docId = "create") {
Expand Down
1 change: 0 additions & 1 deletion R/sentenceSimil.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ NULL
#' sentenceId=c("d1_1","d1_1","d2_1","d2_1"),
#' token=c("i", "ran", "jane", "ran"))
#' @importFrom utils combn
#' @importFrom magrittr "%>%"
#' @importFrom stats xtabs

#' @export
Expand Down
1 change: 0 additions & 1 deletion R/sentenceTokenParse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#' @examples
#' sentenceTokenParse(c("Bill is trying to earn a Ph.D.", "You have to have a 5.0 GPA."),
#' docId=c("d1","d2"))
#' @importFrom magrittr "%>%"

#' @export
sentenceTokenParse <- function(text, docId = "create", removePunc=TRUE, removeNum=TRUE, toLower=TRUE, stemWords=TRUE, rmStopWords=TRUE){
Expand Down
1 change: 0 additions & 1 deletion R/tokenize.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ utils::globalVariables(c("smart_stopwords"))
#' @examples
#' tokenize("Mr. Feeny said the test would be on Sat. At least I'm 99.9% sure that's what he said.")
#' tokenize("Bill is trying to earn a Ph.D. in his field.", rmStopWords=FALSE)
#' @importFrom magrittr "%>%"

#' @export
tokenize <- function(text, removePunc=TRUE, removeNum=TRUE, toLower=TRUE, stemWords=TRUE, rmStopWords=TRUE){
Expand Down
5 changes: 4 additions & 1 deletion R/unnest_sentences.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#' @param drop whether original input column should get dropped
#' @return A data.frame of parsed sentences and sentence ids
#' @examples
#' library(magrittr)
#'
#' df <- data.frame(doc_id = 1:3,
#' text = c("Testing the system. Second sentence for you.",
Expand All @@ -20,8 +19,12 @@
#' unnest_sentences(df, sents, text)
#' unnest_sentences_(df, "sents", "text")
#'
#' \dontrun{
#' library(magrittr)
#'
#' df %>%
#' unnest_sentences(sents, text)
#' }

#' @export
unnest_sentences_ <- function(tbl, output, input, doc_id=NULL, output_id="sent_id", drop=TRUE) {
Expand Down
5 changes: 4 additions & 1 deletion man/bind_lexrank_.Rd

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

5 changes: 4 additions & 1 deletion man/unnest_sentences_.Rd

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

21 changes: 9 additions & 12 deletions tests/testthat/test-bind_lexrank.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ test_that("correct ouput class and str", {
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE)

test_result <- df %>%
unnest_sentences(sents, text) %>%
bind_lexrank(sents, doc_id, level = 'sentences')
test_result <- unnest_sentences(df, sents, text)
test_result <- bind_lexrank(test_result, sents, doc_id, level = 'sentences')

expect_equal(dim(test_result), c(4,4))
expect_true(is.data.frame(test_result))
expect_equal(names(test_result), c("doc_id","sent_id","sents","lexrank"))

test_result <- df %>%
unnest_sentences(sents, text, drop=FALSE) %>%
bind_lexrank(sents,doc_id, level = 'sentences')
test_result <- unnest_sentences(df, sents, text, drop=FALSE)
test_result <- bind_lexrank(test_result, sents,doc_id, level = 'sentences')

expect_equal(dim(test_result), c(4,5))
expect_equal(names(test_result), c("doc_id","text","sent_id","sents","lexrank"))
Expand All @@ -35,8 +33,7 @@ test_that("correct ouput class and str", {
"tidy", "documents", "df", "documents", "will", "be", "parsed", "and", "lexranked"),
stringsAsFactors = FALSE)

test_result <- df %>%
bind_lexrank(tokens, doc_id, sent_id, "tokens")
test_result <- bind_lexrank(df, tokens, doc_id, sent_id, "tokens")

expect_equal(dim(test_result), c(19,5))
expect_equal(names(test_result), c("doc_id","sent_id","sents","tokens","lexrank"))
Expand All @@ -48,8 +45,8 @@ test_that("test input checking", {
text = c("Testing the system. Second sentence for you.",
"System testing the tidy documents df.",
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE) %>%
unnest_sentences(sents, text)
stringsAsFactors = FALSE)
df <- unnest_sentences(df, sents, text)

expect_error(bind_lexrank(df, sents, fake))
expect_error(bind_lexrank(NULL, sents, doc_id))
Expand Down Expand Up @@ -79,8 +76,8 @@ test_that("output value", {
text = c("Testing the system. Second sentence for you.",
"System testing the tidy documents df.",
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE) %>%
unnest_sentences(sents, text)
stringsAsFactors = FALSE)
df <- unnest_sentences(df, sents, text)

test_result <- bind_lexrank(df, sents, doc_id, level="sentences")
expected_result <- data.frame(doc_id = c(1L, 1L, 2L, 3L),
Expand Down
21 changes: 9 additions & 12 deletions tests/testthat/test-bind_lexrank_.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ test_that("correct ouput class and str", {
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE)

test_result <- df %>%
unnest_sentences(sents, text) %>%
bind_lexrank_("sents", "doc_id", level = 'sentences')
test_result <- unnest_sentences(df, sents, text)
test_result <- bind_lexrank_(test_result, "sents", "doc_id", level = 'sentences')

expect_equal(dim(test_result), c(4,4))
expect_true(is.data.frame(test_result))
expect_equal(names(test_result), c("doc_id","sent_id","sents","lexrank"))

test_result <- df %>%
unnest_sentences(sents, text, drop=FALSE) %>%
bind_lexrank_("sents", "doc_id", level = 'sentences')
test_result <- unnest_sentences(df, sents, text, drop=FALSE)
test_result <- bind_lexrank_(test_result, "sents", "doc_id", level = 'sentences')

expect_equal(dim(test_result), c(4,5))
expect_equal(names(test_result), c("doc_id","text","sent_id","sents","lexrank"))
Expand All @@ -35,8 +33,7 @@ test_that("correct ouput class and str", {
"tidy", "documents", "df", "documents", "will", "be", "parsed", "and", "lexranked"),
stringsAsFactors = FALSE)

test_result <- df %>%
bind_lexrank_("tokens", "doc_id", "sent_id", "tokens")
test_result <- bind_lexrank_(df, "tokens", "doc_id", "sent_id", "tokens")

expect_equal(dim(test_result), c(19,5))
expect_equal(names(test_result), c("doc_id","sent_id","sents","tokens","lexrank"))
Expand All @@ -48,8 +45,8 @@ test_that("test input checking", {
text = c("Testing the system. Second sentence for you.",
"System testing the tidy documents df.",
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE) %>%
unnest_sentences(sents, text)
stringsAsFactors = FALSE)
df <- unnest_sentences(df, sents, text)

expect_error(bind_lexrank_(df, "sents", "fake"))
expect_error(bind_lexrank_(NULL, "sents", "doc_id"))
Expand Down Expand Up @@ -79,8 +76,8 @@ test_that("output value", {
text = c("Testing the system. Second sentence for you.",
"System testing the tidy documents df.",
"Documents will be parsed and lexranked."),
stringsAsFactors = FALSE) %>%
unnest_sentences(sents, text)
stringsAsFactors = FALSE)
df <- unnest_sentences(df, sents, text)

test_result <- bind_lexrank_(df, "sents", "doc_id", level="sentences")
expected_result <- data.frame(doc_id = c(1L, 1L, 2L, 3L),
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test-sentenceTokenParse.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ test_that("All clean options TRUE", {
rmStopWords=TRUE)

expectedResultSentences <- sentenceParse(testDocs)
expectedResultTokens <- lexRankr::tokenize(testDocs) %>%
unlist() %>%
.[which(!is.na(.))]
expectedResultTokens <- unlist(lexRankr::tokenize(testDocs))
expectedResultTokens <- expectedResultTokens[which(!is.na(expectedResultTokens))]

expect_equal(testResult$sentences, expectedResultSentences)
expect_equal(testResult$tokens$token, expectedResultTokens)
Expand Down

0 comments on commit 3809424

Please sign in to comment.