get_phrase_type: Grab of Highest Level Phrases

Description Usage Arguments Value Examples

Description

Grab the highest level phrases and corresponding sub-phrases and words. This parse uses a tree/list approach that is less prone to surprises than the get_phrase_type_regex regex approach.

Usage

1
get_phrase_type(x, phrase)

Arguments

x

A parsed character string or list (see parser).

phrase

A phrase type to extract phrases and corresponding words (see http://www.surdeanu.info/mihai/teaching/ista555-spring15/readings/PennTreebankConstituents.html for more on phrase types).

Value

Returns a list of character vectors of extracted phrases.

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
54
## Not run: 
txt <- c(
    "Really, I like chocolate because it is good. It smells great.",
    "Robots are rather evil and most are devoid of decency.",
    "He is my friend.",
    "Clifford the big red dog ate my lunch.",
    "Professor Johns can not teach",
    "",
    NA
)

parse_ann <- parse_annotator()
(x <- parser(txt, parse_ann))

get_phrase_type(x, "VP")
get_phrase_type(x, "NP")
get_phrase_type(x, "V")

## With `get_phrase_type_regex` as a dplyr chain
library(dplyr)
x %>%
    get_phrase_type("NP") %>%
    lapply(get_phrase_type_regex, "(PRP|NN)") %>%
    lapply(unlist)

## get the words
get_leaves(get_phrase_type(x, "NP"))

## As a dplyr chain
library(dplyr)
x %>%
    get_phrase_type("NP") %>%
    get_leaves()

## Subject
get_phrase_type(x, "NP") %>%
    take() %>%
    get_leaves()

## Predicate Verb
get_phrase_type_regex(x, "VP") %>%
    take() %>%
    get_phrase_type_regex("(VB|MD)") %>%
    take() %>%
    get_leaves()

## Direct Object
get_phrase_type_regex(x, "VP") %>%
    take() %>%
    get_phrase_type_regex("NP") %>%
    take() %>%
    get_leaves()

## End(Not run)

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