Add wordFrequency function
Resolves #1
Change-Id: Ifba8630d09559c1c3c31343fbdc3c849dae7d4ca
diff --git a/NAMESPACE b/NAMESPACE
index cc83af3..c182313 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -13,6 +13,7 @@
export(syntagmaticNeighbours)
export(vocabSize)
export(wordEmbedding)
+export(wordFrequency)
importFrom(httr2,req_perform)
importFrom(httr2,req_url_path_append)
importFrom(httr2,req_url_query)
diff --git a/R/derekovecs.R b/R/derekovecs.R
index 5d61f2c..9120991 100644
--- a/R/derekovecs.R
+++ b/R/derekovecs.R
@@ -35,6 +35,20 @@
derekovecsApiCall(method = "/getClassicCollocators", w = w, ...)$collocates
}
+#' Get word frequency
+#'
+#' Gets the absolute frequency of a word in the corpus.
+#'
+#' @param w The word to get the frequency of.
+#' @param ... Additional parameters to pass to the API.
+#'
+#' @return The absolute frequency of the word.
+#' @export
+wordFrequency <- function(w = "Test", ...) {
+ derekovecsApiCall(method = "/getClassicCollocators", w = w, ...)$f1
+}
+
+
#' Get paradigmatic neighbours
#'
#' Get the paradigmatic neighbours of a word in the derekovecs model.
diff --git a/man/wordFrequency.Rd b/man/wordFrequency.Rd
new file mode 100644
index 0000000..a77dd8b
--- /dev/null
+++ b/man/wordFrequency.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/derekovecs.R
+\name{wordFrequency}
+\alias{wordFrequency}
+\title{Get word frequency}
+\usage{
+wordFrequency(w = "Test", ...)
+}
+\arguments{
+\item{w}{The word to get the frequency of.}
+
+\item{...}{Additional parameters to pass to the API.}
+}
+\value{
+The absolute frequency of the word.
+}
+\description{
+Gets the absolute frequency of a word in the corpus.
+}
diff --git a/tests/testthat/test-derekovecs.R b/tests/testthat/test-derekovecs.R
index 25778cf..7fd4980 100644
--- a/tests/testthat/test-derekovecs.R
+++ b/tests/testthat/test-derekovecs.R
@@ -32,3 +32,9 @@
rank <- frequencyRank("Test")
expect_true(rank %>% is.numeric & rank > 0)
})
+
+test_that("wordFrequency works", {
+ freq <- wordFrequency("Test")
+ expect_true(freq %>% is.numeric & freq > 0)
+})
+