Get a piece of a label
get_piece.Rd
This is a wrapper function for get_pref_suff()
, get_nouns()
, and
get_objects()
.
It returns a piece
of a row or column label.
Usage
get_piece(
labels,
piece = "all",
inf_notation = TRUE,
notation = RCLabels::notations_list,
choose_most_specific = FALSE,
prepositions = RCLabels::prepositions_list
)
Arguments
- labels
The row and column labels from which prepositional phrases are to be extracted.
- piece
The name of the item to return.
- inf_notation
A boolean that tells whether to infer notation for
x
. Default isTRUE
. Seeinfer_notation()
for details.- notation
The notation type to be used when extracting prepositions. Default is
RCLabels::notations_list
, meaning that the notation is inferred usinginfer_notation()
.- choose_most_specific
A boolean that tells whether to choose the most specific notation from
notation
when inferring notation. Default isFALSE
so that a less specific notation can be inferred. In combination withRCLabels::notations_list
, the default value ofFALSE
means thatRCLabels::bracket_notation
will be selected instead of anything more specific, such asRCLabels::from_notation
.- prepositions
A vector of strings to be treated as prepositions. Note that a space is appended to each word internally, so, e.g., "to" becomes "to ". Default is
RCLabels::prepositions_list
.
Details
piece
is typically one of
"all" (which returns
labels
directly),"pref" (for the prefixes),
"suff" (for the suffixes),
"noun" (returns the noun),
"pps" (prepositional phrases, returns prepositional phrases in full),
"prepositions" (returns a list of prepositions),
"objects" (returns a list of objects with prepositions as names), or
a preposition in
prepositions
(as a string), which will return the object of that preposition named by the preposition itself.
piece
must be a character vector of length 1.
If a piece
is missing in a label, "" (empty string) is returned.
If specifying more than one notation
, be sure the notations are in a list.
notation = c(RCLabels::bracket_notation, RCLabels::arrow_notation)
is unlikely to produce the desired result, because the notations
are concatenated together to form a long string vector.
Rather say
notation = list(RCLabels::bracket_notation, RCLabels::arrow_notation)
.
Examples
labs <- c("a [from b in c]", "d [of e in f]", "Export [of Coal from USA to MEX]")
get_piece(labs, "pref")
#> pref pref pref
#> "a" "d" "Export"
get_piece(labs, "suff")
#> suff suff suff
#> "from b in c" "of e in f" "of Coal from USA to MEX"
get_piece(labs, piece = "noun")
#> noun noun noun
#> "a" "d" "Export"
get_piece(labs, piece = "pps")
#> pps pps pps
#> "from b in c" "of e in f" "of Coal from USA to MEX"
get_piece(labs, piece = "prepositions")
#> $prepositions
#> [1] "from" "in"
#>
#> $prepositions
#> [1] "of" "in"
#>
#> $prepositions
#> [1] "of" "from" "to"
#>
get_piece(labs, piece = "objects")
#> $objects
#> from in
#> "b" "c"
#>
#> $objects
#> of in
#> "e" "f"
#>
#> $objects
#> of from to
#> "Coal" "USA" "MEX"
#>
get_piece(labs, piece = "from")
#> [[1]]
#> from
#> "b"
#>
#> [[2]]
#> from
#> ""
#>
#> [[3]]
#> from
#> "USA"
#>
get_piece(labs, piece = "in")
#> [[1]]
#> in
#> "c"
#>
#> [[2]]
#> in
#> "f"
#>
#> [[3]]
#> in
#> ""
#>
get_piece(labs, piece = "of")
#> [[1]]
#> of
#> ""
#>
#> [[2]]
#> of
#> "e"
#>
#> [[3]]
#> of
#> "Coal"
#>
get_piece(labs, piece = "to")
#> [[1]]
#> to
#> ""
#>
#> [[2]]
#> to
#> ""
#>
#> [[3]]
#> to
#> "MEX"
#>