get_piece: Get a piece of a label

View source: R/extractors.R

get_pieceR Documentation

Get a piece of a label

Description

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 is TRUE. See infer_notation() for details.

notation

The notation type to be used when extracting prepositions. Default is RCLabels::notations_list, meaning that the notation is inferred using infer_notation().

choose_most_specific

A boolean that tells whether to choose the most specific notation from notation when inferring notation. Default is FALSE so that a less specific notation can be inferred. In combination with RCLabels::notations_list, the default value of FALSE means that RCLabels::bracket_notation will be selected instead of anything more specific, such as RCLabels::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).

Value

A piece of labels.

Examples

labs <- c("a [from b in c]", "d [of e in f]", "Export [of Coal from USA to MEX]")
get_piece(labs, "pref")
get_piece(labs, "suff")
get_piece(labs, piece = "noun")
get_piece(labs, piece = "pps")
get_piece(labs, piece = "prepositions")
get_piece(labs, piece = "objects")
get_piece(labs, piece = "from")
get_piece(labs, piece = "in")
get_piece(labs, piece = "of")
get_piece(labs, piece = "to")

RCLabels documentation built on May 29, 2024, 5:56 a.m.