query,kRp.corpus-method {tm.plugin.koRpus}R Documentation

Apply query() to all texts in kRp.corpus objects

Description

This method calls query on all tagged text objects inside the given object.

Usage

## S4 method for signature 'kRp.corpus'
query(
  obj,
  var,
  query,
  rel = "eq",
  as.df = TRUE,
  ignore.case = TRUE,
  perl = FALSE,
  regexp_var = "token"
)

Arguments

obj

An object of class kRp.corpus.

var

A character string naming a column in the tagged text. If set to "regexp", grepl is called on the column specified by regexp_var.

query

A character vector (for words), regular expression, or single number naming values to be matched in the variable. Can also be a vector of two numbers to query a range of frequency data, or a list of named lists for multiple queries (see "Query lists" section of query).

rel

A character string defining the relation of the queried value and desired results. Must either be "eq" (equal, the default), "gt" (greater than), "ge" (greater of equal), "lt" (less than) or "le" (less or equal). If var="word", is always interpreted as "eq"

as.df

Logical, if TRUE, returns a data frame, otherwise an object of the input class.

ignore.case

Logical, passed through to grepl if var="regexp".

perl

Logical, passed through to grepl if var="regexp".

regexp_var

A character string naming the column to query if var="regexp".

Value

Depending on the arguments, might include whole objects, lists, single values etc.

Examples

# use readCorpus() to create an object of class kRp.corpus
# code is only run when the english language package can be loaded
if(require("koRpus.lang.en", quietly = TRUE)){
  myCorpus <- readCorpus(
    dir=file.path(
      path.package("tm.plugin.koRpus"), "examples", "corpus", "Edwards"
    ),
    hierarchy=list(
      Source=c(
        Wikipedia_prev="Wikipedia (old)",
        Wikipedia_new="Wikipedia (new)"
      )
    ),
    # use tokenize() so examples run without a TreeTagger installation
    tagger="tokenize",
    lang="en"
  )

  query(myCorpus, var="lttr", query="7", rel="gt")
} else {}

[Package tm.plugin.koRpus version 0.4-2 Index]