Skip to contents

Accepts a character string, a path to a text file, or a tibble with a text column, and returns a tidy one-row-per-sentence tibble ready for scoring. The language is auto-detected with the cld3 package when available; otherwise the lang argument is required.

Usage

syn_read_text(x, lang = NULL, text_col = "text", call = rlang::caller_env())

Arguments

x

A single character string, a character vector, a path to an existing .txt file, or a tibble/data frame containing a text column.

lang

Language code, one of "de", "en", "fr". If NULL (the default), the language is auto-detected via cld3. If cld3 is not installed and lang is NULL, an error is raised.

text_col

When x is a tibble, the name of the column holding text.

call

The calling environment, for error reporting. Experts only.

Value

A tibble::tibble() with columns sentence_id (integer), sentence (character), and lang (character), plus a lang attribute. Empty input returns a zero-row tibble of the same type.

See also

syn_score() for the next step.

Other reading functions: syn_example_text()

Examples

syn_read_text("A short tale. It has two sentences.", lang = "en")
#> # A tibble: 2 × 3
#>   sentence_id sentence              lang 
#>         <int> <chr>                 <chr>
#> 1           1 A short tale.         en   
#> 2           2 It has two sentences. en