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] "(@heartwarming-jp) **Shindo 2015:660**\n\n _Kotae-nagara_ _otousan_ _to_ _okaasan_ _wa_ _honobonoto_ _atatakai2_ _mono_ _ni_ \n\n reply-while father and mother TOP heartwarming warm thing with \n\n _tsutsum-areru_ _kimochi_ _ga_ _shi-ta._ \n\n surround-PASS feeling NOM do-PST \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_ _okaasan_ _wa_ _honobonoto_ _atatakai2_ _mono_ _ni_ \n\n reply-while father and mother TOP heartwarming warm thing with \n\n _tsutsum-areru_ _kimochi_ _ga_ _shi-ta._ \n\n surround-PASS feeling NOM do-PST \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_ _sonna_ _shumi_ _wa_ _nai._ _Tsumetai-none._ _Kedaru-souna_ _koe_ \n\n unfortunately such interest TOP not.exist cold-EMPH languid-seem voice \n\n _da-tta._ \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_ _okaasan_ _wa_ _honobonoto_ _atatakai2_ _mono_ _ni_ \n\n reply-while father and mother TOP heartwarming warm thing with \n\n _tsutsum-areru_ _kimochi_ _ga_ _shi-ta._ \n\n surround-PASS feeling NOM do-PST \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_ _sonna_ _shumi_ _wa_ _nai._ _Tsumetai-none._ _Kedaru-souna_ _koe_ \n\n unfortunately such interest TOP not.exist cold-EMPH languid-seem voice \n\n _da-tta._ \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…