Add functions wordEmbedding and frequencyRank
Change-Id: Ic08c9660e3085d46143af8c4dfd32cfb2eca2aca
diff --git a/NAMESPACE b/NAMESPACE
index bcf44e9..0a2f0f6 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -5,8 +5,10 @@
export(cosineSimilarity)
export(countbasedCollocates)
export(derekovecsServer)
+export(frequencyRank)
export(paradigmaticNeighbours)
export(syntagmaticNeighbours)
+export(wordEmbedding)
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 53efb67..721d79d 100644
--- a/R/derekovecs.R
+++ b/R/derekovecs.R
@@ -48,6 +48,32 @@
derekovecsApiCall("", word = word, json = 1, ...)$list[[1]]
}
+#' Get word embedding
+#'
+#' Get the normalized embedding vector of a word from the derekovecs model.
+#'
+#' @param word The word to get the paradigmatic neighbours for.
+#' @param ... Additional parameters to pass to the API.
+#' @return Normalized embedding vector of the given word.
+#' @export
+#'
+wordEmbedding <- function(word = "Test", ...) {
+ derekovecsApiCall("", word = word, n=1, json = 1, ...)[["list"]][[1]][["vector"]][[1]]
+}
+
+#' Get frequency rank
+#'
+#' Gets the frequency rank of a word in the training data.
+#'
+#' @param word The word to get the frequency rank of.
+#' @param ... Additional parameters to pass to the API.
+#' @return Frequency rank.
+#' @export
+#'
+frequencyRank <- function(word = "Test", ...) {
+ derekovecsApiCall("/getWord", w = word, ...)$frequencyRank
+}
+
#' Get collocation scores
#'
#' Calculate the association scores between a node (target word) and words in a window around the it.
diff --git a/man/frequencyRank.Rd b/man/frequencyRank.Rd
new file mode 100644
index 0000000..9f2d970
--- /dev/null
+++ b/man/frequencyRank.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/derekovecs.R
+\name{frequencyRank}
+\alias{frequencyRank}
+\title{Get frequency rank}
+\usage{
+frequencyRank(word = "Test", ...)
+}
+\arguments{
+\item{word}{The word to get the frequency rank of.}
+
+\item{...}{Additional parameters to pass to the API.}
+}
+\value{
+Frequency rank.
+}
+\description{
+Gets the frequency rank of a word in the training data.
+}
diff --git a/man/wordEmbedding.Rd b/man/wordEmbedding.Rd
new file mode 100644
index 0000000..1edbcd8
--- /dev/null
+++ b/man/wordEmbedding.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/derekovecs.R
+\name{wordEmbedding}
+\alias{wordEmbedding}
+\title{Get word embedding}
+\usage{
+wordEmbedding(word = "Test", ...)
+}
+\arguments{
+\item{word}{The word to get the paradigmatic neighbours for.}
+
+\item{...}{Additional parameters to pass to the API.}
+}
+\value{
+Normalized embedding vector of the given word.
+}
+\description{
+Get the normalized embedding vector of a word from the derekovecs model.
+}