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 theid_column
.- id_column
Name of the column with ids for filtering, if
use_conditionals
isFALSE
.- 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
, runninggloss_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] "\\ex\\label{heartwarming-jp} \\begingl \\glpreamble Shindo 2015:660// \\gla Kotae-nagara otousan to okaasan wa honobonoto atatakai2 mono ni tsutsum-areru kimochi ga shi-ta.// \\glb reply-while father and mother \\textsc{top} heartwarming warm thing with surround-\\textsc{pass} feeling \\textsc{nom} do-\\textsc{pst}// \\glft \"While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.\"// \n \\endgl \\xe \n"
#> 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] "\\ex\\label{heartwarming-jp} \\begingl \\glpreamble Shindo 2015:660// \\gla Kotae-nagara otousan to okaasan wa honobonoto atatakai2 mono ni tsutsum-areru kimochi ga shi-ta.// \\glb reply-while father and mother \\textsc{top} heartwarming warm thing with surround-\\textsc{pass} feeling \\textsc{nom} do-\\textsc{pst}// \\glft \"While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.\"// \n \\endgl \\xe \n"
#> [2] "\\ex\\label{languid-jp} \\begingl \\glpreamble Shindo 2015:660// \\gla Ainiku sonna shumi wa nai. Tsumetai-none. Kedaru-souna koe da-tta.// \\glb unfortunately such interest \\textsc{top} not.exist cold-\\textsc{emph} languid-seem voice \\textsc{cop-pst}// \\glft \"Unfortunately I never have such an interest. You are so cold. (Her) voice sounded languid.\"// \n \\endgl \\xe \n"
#> 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] "\\ex\\label{heartwarming-jp} \\begingl \\glpreamble Shindo 2015:660// \\gla Kotae-nagara otousan to okaasan wa honobonoto atatakai2 mono ni tsutsum-areru kimochi ga shi-ta.// \\glb reply-while father and mother \\textsc{top} heartwarming warm thing with surround-\\textsc{pass} feeling \\textsc{nom} do-\\textsc{pst}// \\glft \"While replying (to your question), Father and Mother felt like they were surrounded by something heart warming.\"// \n \\endgl \\xe \n"
#> [2] "\\ex\\label{languid-jp} \\begingl \\glpreamble Shindo 2015:660// \\gla Ainiku sonna shumi wa nai. Tsumetai-none. Kedaru-souna koe da-tta.// \\glb unfortunately such interest \\textsc{top} not.exist cold-\\textsc{emph} languid-seem voice \\textsc{cop-pst}// \\glft \"Unfortunately I never have such an interest. You are so cold. (Her) voice sounded languid.\"// \n \\endgl \\xe \n"
#> 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…