Skip to contents

This function takes a dataframe with glosses and returns another function that takes either an id or list of ids (if use_conditionals is FALSE) or a conditional statement (if TRUE) and runs gloss_df() on the filtered dataframe.

Usage

gloss_factory(
  glosses,
  use_conditionals = FALSE,
  id_column = "label",
  ignore_columns = NULL,
  validate = TRUE
)

Arguments

glosses

Dataframe with gloss data.

use_conditionals

Boolean. If TRUE, the returned function will use conditional statements to filter the dataframe. Otherwise, it will use ids and match them to the values in the id_column.

id_column

Name of the column with ids for filtering, if use_conditionals is FALSE.

ignore_columns

Optional character vector with names of columns that could be used for filtering but should not be provided to gloss_df().

validate

Boolean. If TRUE, running gloss_factory() will print a few informative messages about how glossr is reading the dataframe.

Value

A function.

If use_conditionals is FALSE (the default), the returned function will take a character vector or a series of character vectors with id's to filter. If id_column is "label", running that function will be the equivalent to filtering glosses based on the values in the label column.

If use_conditionals is TRUE, the returned function will take the same conditions that a dplyr::filter() would.

Examples

my_glosses <- dplyr::select(glosses, -language)
by_label <- gloss_factory(my_glosses)
#>  The following columns will be used for the gloss texts, in the following order:
#>  `source` (not aligned!)
#>  `original` and `parsed` (aligned columns)
#>  `translation` (not aligned!)
#>  The `label` column will be used for labels.

by_label("heartwarming-jp")
#> [1] "(@heartwarming-jp) **Shindo 2015:660**\n\n    _Kotae-nagara_ _otousan_ _to_ &nbsp; _okaasan_ _wa_ &nbsp; _honobonoto_ _atatakai2_ _mono_ _ni_ &nbsp; &nbsp;\n\n    reply-while &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; father &nbsp; &nbsp; &nbsp; &nbsp;and mother &nbsp; &nbsp; &nbsp; TOP heartwarming &nbsp; warm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thing &nbsp; &nbsp;with \n\n    _tsutsum-areru_ _kimochi_ _ga_ &nbsp; &nbsp; _shi-ta._ \n\n    surround-PASS &nbsp; &nbsp; feeling &nbsp; &nbsp; &nbsp; NOM do-PST &nbsp;\n\n    'While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.'"
#> attr(,"class")
#> [1] "gloss"     "character"
#> attr(,"data")
#> # A tibble: 1 × 5
#>   original                                       parsed translation label source
#>   <chr>                                          <chr>  <chr>       <chr> <chr> 
#> 1 Kotae-nagara otousan to okaasan wa honobonoto… "repl… While repl… hear… Shind…

by_label("heartwarming-jp", "languid-jp")
#> [1] "(@heartwarming-jp) **Shindo 2015:660**\n\n    _Kotae-nagara_ _otousan_ _to_ &nbsp; _okaasan_ _wa_ &nbsp; _honobonoto_ _atatakai2_ _mono_ _ni_ &nbsp; &nbsp;\n\n    reply-while &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; father &nbsp; &nbsp; &nbsp; &nbsp;and mother &nbsp; &nbsp; &nbsp; TOP heartwarming &nbsp; warm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thing &nbsp; &nbsp;with \n\n    _tsutsum-areru_ _kimochi_ _ga_ &nbsp; &nbsp; _shi-ta._ \n\n    surround-PASS &nbsp; &nbsp; feeling &nbsp; &nbsp; &nbsp; NOM do-PST &nbsp;\n\n    'While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.'"
#> [2] "(@languid-jp) **Shindo 2015:660**\n\n    _Ainiku_ &nbsp; &nbsp; &nbsp; &nbsp;_sonna_ _shumi_ _wa_ &nbsp; _nai._ &nbsp; &nbsp; &nbsp;_Tsumetai-none._ _Kedaru-souna_ _koe_ &nbsp; \n\n    unfortunately such &nbsp; &nbsp; &nbsp;interest &nbsp;TOP not.exist cold-EMPH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; languid-seem &nbsp; &nbsp; &nbsp; &nbsp;voice \n\n    _da-tta._ &nbsp; &nbsp;\n\n    COP-PST \n\n    'Unfortunately I never have such an interest. You are so cold. (Her) voice sounded languid.'"                                                                                                                                          
#> attr(,"class")
#> [1] "gloss"     "character"
#> attr(,"data")
#> # A tibble: 2 × 5
#>   original                                       parsed translation label source
#>   <chr>                                          <chr>  <chr>       <chr> <chr> 
#> 1 Kotae-nagara otousan to okaasan wa honobonoto… "repl… While repl… hear… Shind…
#> 2 Ainiku sonna shumi wa nai. Tsumetai-none. Ked… "unfo… Unfortunat… lang… Shind…

by_cond <- gloss_factory(my_glosses, use_conditional = TRUE)
#>  The following columns will be used for the gloss texts, in the following order:
#>  `source` (not aligned!)
#>  `original` and `parsed` (aligned columns)
#>  `translation` (not aligned!)
#>  The `label` column will be used for labels.
by_cond(stringr::str_ends(label, "jp"))
#> [1] "(@heartwarming-jp) **Shindo 2015:660**\n\n    _Kotae-nagara_ _otousan_ _to_ &nbsp; _okaasan_ _wa_ &nbsp; _honobonoto_ _atatakai2_ _mono_ _ni_ &nbsp; &nbsp;\n\n    reply-while &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; father &nbsp; &nbsp; &nbsp; &nbsp;and mother &nbsp; &nbsp; &nbsp; TOP heartwarming &nbsp; warm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thing &nbsp; &nbsp;with \n\n    _tsutsum-areru_ _kimochi_ _ga_ &nbsp; &nbsp; _shi-ta._ \n\n    surround-PASS &nbsp; &nbsp; feeling &nbsp; &nbsp; &nbsp; NOM do-PST &nbsp;\n\n    'While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.'"
#> [2] "(@languid-jp) **Shindo 2015:660**\n\n    _Ainiku_ &nbsp; &nbsp; &nbsp; &nbsp;_sonna_ _shumi_ _wa_ &nbsp; _nai._ &nbsp; &nbsp; &nbsp;_Tsumetai-none._ _Kedaru-souna_ _koe_ &nbsp; \n\n    unfortunately such &nbsp; &nbsp; &nbsp;interest &nbsp;TOP not.exist cold-EMPH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; languid-seem &nbsp; &nbsp; &nbsp; &nbsp;voice \n\n    _da-tta._ &nbsp; &nbsp;\n\n    COP-PST \n\n    'Unfortunately I never have such an interest. You are so cold. (Her) voice sounded languid.'"                                                                                                                                          
#> attr(,"class")
#> [1] "gloss"     "character"
#> attr(,"data")
#> # A tibble: 2 × 5
#>   original                                       parsed translation label source
#>   <chr>                                          <chr>  <chr>       <chr> <chr> 
#> 1 Kotae-nagara otousan to okaasan wa honobonoto… "repl… While repl… hear… Shind…
#> 2 Ainiku sonna shumi wa nai. Tsumetai-none. Ked… "unfo… Unfortunat… lang… Shind…