R/detect_phrases.R

Defines functions detect_phrases

Documented in detect_phrases

#' @title Detect key phrases
#' @description Detect key phrases in a source text
#' @param text A character string containing a text to analyze, or a character vector to perform analysis separately for each element.
#' @param language A character string containing a two-letter language code. Currently \dQuote{en} and \dQuote{es} are supported.
#' @param \dots Additional arguments passed to \code{\link{comprehendHTTP}}.
#' @return A data frame
#' @examples
#' \dontrun{
#'   # simple example
#'   detect_phrases("Amazon provides web services. Jeff is their leader.")
#'   
#'   txt <-c("Amazon provides web services.",
#'           "Jeff is their leader.")
#'   detect_phrases(txt)
#' }
#' @export
detect_phrases <-
function(
  text,
  language = "en",
  ...
) {
    if (length(text) > 1L) {
        bod <- list(TextList = text, LanguageCode = language)
        out <- comprehendHTTP(action = "BatchDetectKeyPhrases", body = bod, ...)
        x <- bind_and_index(out$ResultList$Index, out$ResultList$KeyPhrases)
        return(structure(x, ErrorList = out$ErrorList))
    } else {
        bod <- list(Text = text, LanguageCode = language)
        out <- comprehendHTTP(action = "DetectKeyPhrases", body = bod, ...)
        return(cbind(Index = 0, out$KeyPhrases))
    }
}

Try the aws.comprehend package in your browser

Any scripts or data that you put into this service are public.

aws.comprehend documentation built on April 14, 2020, 6:34 p.m.