subset_nodes: Subset a select_nodes selection

View source: R/generic_reshape.r

subset_nodesR Documentation

Subset a select_nodes selection

Description

Enables more control in reshape operations

Usage

subset_nodes(.tokens, subset, copy = TRUE)

Arguments

.tokens

A tokenIndex in which nodes are selected with select_nodes.

subset

A subset expression (that evaluates to a logical vector). The token column for each labeled node in the tquery can be referred to as label$column.

copy

If TRUE, make a deep copy of .tokens. Use if output does not overwrite .tokens

Value

A tokenIndex with a .nodes attribute

Examples

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

## use a tquery to label the nodes that you want to manipulate
tq = tquery(label='verb', children(relation='nsubj'))

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

selected_nodes(tokens2)$nodes
tokens2 = subset_nodes(tokens2, verb$relation == 'ROOT')
selected_nodes(tokens2)$nodes

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