apply_queries: Apply queries created with tquery

Description Usage Arguments Value Examples

View source: R/syntax_rules.r

Description

Apply queries created with tquery

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
apply_queries(
  tokens,
  ...,
  as_chain = FALSE,
  block = NULL,
  check = FALSE,
  fill = TRUE,
  return_wide = FALSE,
  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()

return_wide

If TRUE, return nodes in wide format.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## 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

rsyntax documentation built on June 13, 2021, 9:07 a.m.