View source: R/generic_reshape.r
select_nodes | R Documentation |
Apply tquery to initiate reshape operations
select_nodes( tokens, tquery, fill = TRUE, fill_only_first = TRUE, .one_per_sentence = FALSE, .order = 1 )
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. |
A tokenIndex with a .nodes attribute, that enables the use of reshape operations on the selected nodes
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() }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.