select_nodes: Apply tquery to initiate reshape operations

View source: R/generic_reshape.r

select_nodesR Documentation

Apply tquery to initiate reshape operations

Description

Apply tquery to initiate reshape operations

Usage

select_nodes(
  tokens,
  tquery,
  fill = TRUE,
  fill_only_first = TRUE,
  .one_per_sentence = FALSE,
  .order = 1
)

Arguments

tokens

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

tquery

A tquery that selects and labels the nodes that are used in the reshape operations

fill

Logical, should fill be used?

fill_only_first

Logical, should a node only be filled once, with the nearest (first) labeled node?

.one_per_sentence

If true, only one match per sentence is used, giving priority to paterns closest to the root (or fartest from the root if .order = -1). This is sometimes necessary to deal with recursion.

.order

If .one_per_sentence is used, .order determines whether the paterns closest to (1) or farthest away (-1) are used.

Value

A tokenIndex with a .nodes attribute, that enables the use of reshape operations on the selected nodes

Examples

tokens = tokens_spacy[tokens_spacy$doc_id == 'text4',]

## use a tquery to label the nodes that you want to manipulate
tq = tquery(relation = "relcl", label = "relative_clause")

## apply query to select nodes
tokens2 = select_nodes(tokens, tq) 

## as an example, we make the parent of the relative_clause
## nodes NA, effectively cutting of the relcl from the tree
tokens2 = mutate_nodes(tokens2, "relative_clause", parent=NA)

tokens2


if (interactive()) plot_tree(tokens2)

## this is designed to work nicely with magrittr piping
if (interactive()) {
tokens %>%
  select_nodes(tq) %>%
  mutate_nodes("relative_clause", parent=NA) %>%
  plot_tree()
}


rsyntax documentation built on June 7, 2022, 9:07 a.m.