Learn R Programming

rsyntax (version 0.1.0)

apply_queries: Apply queries created with tquery

Description

Apply queries created with tquery

Usage

apply_queries(
  tokens,
  ...,
  as_chain = FALSE,
  block = NULL,
  check = FALSE,
  fill = TRUE,
  verbose = FALSE
)

Arguments

tokens

A tokenIndex data.table, or any data.frame coercible with as_tokenindex.

...

tqueries, as created with tquery. Can also be a list with tquery functions. It is recommended to use named arguments/lists, to name the tqueries.

as_chain

If TRUE, Nodes that have already been assigned assigned earlier in the chain will be ignored (see 'block' argument).

block

Optionally, specify ids (doc_id - sentence - token_id triples) where find_nodes will stop (ignoring the id and recursive searches through the id). Can also be a data.table returned by (a previous) apply_queries, in which case all ids are blocked.

check

If TRUE, return a warning if nodes occur in multiple patterns, which could indicate that the find_nodes query is not specific enough.

fill

If TRUE (default) the fill nodes are added. Otherwise these are ignored, even if the queries include fill()

verbose

If TRUE, report progress (only useful if multiple queries are used)

Value

A data.table in which each row is a node for which all conditions are satisfied, and each column is one of the linked nodes (parents / children) with names as specified in the label argument.

Examples

Run this code
# NOT RUN {
## spacy tokens for: Mary loves John, and Mary was loved by John
tokens = tokens_spacy[tokens_spacy$doc_id == 'text3',]

## two simple example tqueries
passive = tquery(pos = "VERB*", label = "predicate",
                 children(relation = c("agent"), label = "subject"))
active =  tquery(pos = "VERB*", label = "predicate",
                 children(relation = c("nsubj", "nsubjpass"), label = "subject"))

nodes = apply_queries(tokens, pas=passive, act=active)
nodes
# }

Run the code above in your browser using DataLab