Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

## 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

Extract Semantic Relations from Text by Querying and Reshaping Syntax

v0.1.1
GPL-3
Authors
Kasper Welbers and Wouter van Atteveldt
Initial release
2020-10-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.