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

copy_nodes

Copy nodes


Description

Copy nodes

Usage

copy_nodes(
  .tokens,
  node,
  new,
  subset = NULL,
  keep_relation = TRUE,
  copy_fill = FALSE,
  subset_fill = NULL,
  only_new = NULL
)

Arguments

.tokens

A tokenIndex in which nodes are selected with select_nodes.

node

The name of the node that is to be copied

new

The name given to the copy

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.

keep_relation

If FALSE, remove relation (making node a root)

copy_fill

If TRUE, also copy the fill

subset_fill

A subset on the fill nodes. Can only directly use token column. For example, use pos == 'VERB' to copy only verbs

only_new

If TRUE, direct fill children will only be copied to to_node if it does not already have nodes of this relation. This is a good heuristic for dealing with argument drop.

Value

A tokenIndex with a .nodes attribute

Examples

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

tq = tquery(label='object', relation='dobj')
            
tokens2 = select_nodes(tokens, tq)
selected_nodes(tokens2)

copy_nodes(tokens2, 'object', 'new_object')

tokens3 = copy_nodes(tokens2, 'object', 'new_object', copy_fill=TRUE)


if (interactive()) plot_tree(tokens3, token, pos)

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.