Add corpusSize function
Resolves #2
This is a bit of a hack, but it does work with old derekovecs servers.
Change-Id: I1c8f81c7341f0df71012f5991bde5edfc83dc2b0
diff --git a/NAMESPACE b/NAMESPACE
index c182313..8a1ecba 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -2,6 +2,7 @@
export("%>%")
export(collocationScores)
+export(corpusSize)
export(cosineSimilarity)
export(countbasedCollocates)
export(derekovecsApiCall)
diff --git a/R/derekovecs.R b/R/derekovecs.R
index 9120991..a55c365 100644
--- a/R/derekovecs.R
+++ b/R/derekovecs.R
@@ -48,6 +48,18 @@
derekovecsApiCall(method = "/getClassicCollocators", w = w, ...)$f1
}
+#' Get corpus size
+#'
+#' Gets the token size of the corpus used to train the model.
+#'
+#' @param w Probe word (defaults to `Test`) required for old derekovecs servers.
+#' @param ... Additional parameters to pass to the API.
+#'
+#' @return The number of tokens in the corpus.
+#' @export
+corpusSize <- function(w = "Test", ...) {
+ derekovecsApiCall(method = "/getClassicCollocators", w = w, ...)$N
+}
#' Get paradigmatic neighbours
#'
diff --git a/man/corpusSize.Rd b/man/corpusSize.Rd
new file mode 100644
index 0000000..7da9e00
--- /dev/null
+++ b/man/corpusSize.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/derekovecs.R
+\name{corpusSize}
+\alias{corpusSize}
+\title{Get corpus size}
+\usage{
+corpusSize(w = "Test", ...)
+}
+\arguments{
+\item{w}{Probe word (defaults to \code{Test}) required for old derekovecs servers.}
+
+\item{...}{Additional parameters to pass to the API.}
+}
+\value{
+The number of tokens in the corpus.
+}
+\description{
+Gets the token size of the corpus used to train the model.
+}
diff --git a/tests/testthat/test-derekovecs.R b/tests/testthat/test-derekovecs.R
index 7fd4980..d007f4e 100644
--- a/tests/testthat/test-derekovecs.R
+++ b/tests/testthat/test-derekovecs.R
@@ -38,3 +38,7 @@
expect_true(freq %>% is.numeric & freq > 0)
})
+test_that("corpusSize works", {
+ size <- corpusSize()
+ expect_true(size %>% is.numeric & size > 1000)
+})