as_square_brace: Conver parser Output to Square Braces

Description Usage Arguments Value Note Examples

Description

Many tree parsers (e.g., online, LaTeX, etc.) require square braces in the parse. These functions prepare the parse for use in other plotting venues.

Usage

1
2
3

Arguments

x

A parse vector from parser.

...

ignored.

Value

as_square_brace - returns a vector appropriate for use in a many online parse tree generators.

as_square_brace_latex - returns a cat vector appropriate for use in a LaTeX document.

Note

When using as_square_brace_latex, the user will need to add the following LaTeX packages to the document: qtree, color, xcolor. Additionally, the user will need to add the code chunk, \newenvironment{dummy}{}{}, to the preamble.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
## Not run: 
## pass `as_square_brace` to an online parse tree:
## http://yohasebe.com/rsyntaxtree
if(!exists('parse_ann')) {
    parse_ann <- parse_annotator()
}
x <- parser("Really, I like chocolate because it is good.", parse_ann)
xsquared <- as_square_brace(x)

## get tree from web
if (!require("pacman")) install.packages("pacman"); library(pacman)
p_load_gh("ropensci/RSelenium")
p_load(XML, RSelenium)

# download Selenium Server, if not already present
checkForServer(); Sys.sleep(2)

# Open a remote browser
remDr <- remoteDriver(
    remoteServerAddr = "localhost",
    port = 4444,
    browserName = "firefox"
)

## MIGHT NEED:
## RSelenium::startServer()

remDr$open()

## Now we pass the url from above and the page is opened
remDr$navigate("http://yohasebe.com/rsyntaxtree/")

webElem <- remDr$findElement("css", "textarea[id='data']")
webElem$clearElement()
webElem$sendKeysToElement(list(xsquared)); Sys.sleep(.5)


webElem2 <- remDr$findElement("css", "button[id='draw_png']")
webElem2$clickElement()

## LaTeX Version
## copy .Rmd from parser package
treeloc <- system.file("extra_files/testtree.Rmd", package = "parsent")
file.copy(treeloc, getwd())

## look at .Rmd
file.edit("testtree.Rmd")

## render .Rmd file
p_load(rmarkdown)
rmarkdown::render("testtree.Rmd")

## End(Not run)

trinker/parsent documentation built on May 31, 2019, 9:41 p.m.