Skip to contents

Transliterate a text file and output to another text file.

Usage

norm_transliteration(
  file_input,
  file_output,
  method = c("greek_letter-name", "any-ascii"),
  custom
)

Arguments

file_input

Directory/Path to the input file.

file_output

Directory/Path to the out file. No need to create the file in advance. A file with the specified name will be created.

method

A character vector specifying the transliteration rules in order. Defaults to a recommended rule combination - c("greek_letter-name", "any-ascii"). See stringi::stri_trans_general() documentation for more rules in the database. Custom rules are also allowed (see examples).

custom

Logical. A logical vector (with the same length as method) specifying whether the corresponding transliteration rule is a custom rule or not. Optional if none of the rules is custom (i.e., Defaults to an all-FALSE vector.).

Details

Transliteration rule "greek_letter-name" transliterates common Greek letters to their names (e.g., α to alpha, β to beta). See ls_greek_letter_to_name() for the complete list of transformations.

All rules in stringi::stri_trans_general() are applicable as a rule in method here. For example, "any-ascii" is to transform all scripts to ASCII format. See stringi::stri_trans_general() documentation for more details.

See Example 3 and the last example in stringi::stri_trans_general() for instrucstions to construct custom rules.

Examples

# An example input file has been put in extdata/
# We use system.file() to output the path to this example file
input <- system.file("extdata", "example_norm_trans.bib", package = "RefDeduR")
# The input file looks like this.
#> author = {Whitman, C. P., Álvarez-Fraga, L. and Pérez, A á ä},
#> title = {β-α-β structural motif},
#> Ϛ

# Specify the path to the output file. Here I put it in the same directory but you can modify the path to wherever you want to store the output file.
output <- system.file("extdata", "output.bib", package = "RefDeduR")


# Example 1: default setting
norm_transliteration(input, output, method = c("greek_letter-name", "any-ascii"))
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
# For demonstration purpose, output.bib will look like this.
#> author = {Whitman, C. P., Alvarez-Fraga, L. and Perez, A a a},
#> title = {beta-alpha-beta structural motif},
#> Ϛ


# Example 2: use other transliteration rules in the database
norm_transliteration(input, output, method = c("Greek-en_US/UNGEGN", "any-ascii"))
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
# For demonstration purpose, output.bib will look like this.
#> author = {Whitman, C. P., Alvarez-Fraga, L. and Perez, A a a},
#> title = {b-a-b structural motif},
#> Ϛ


# Example 3: use custom transliteration rules
id_custom <- "
\u03DA > 'Stigma';
\u03E0 > 'Sampi';
"  # Note that every transliteration needs to be accompanied by a semicolon, including the last line.

norm_transliteration(input, output, method = c("greek_letter-name", id_custom, "any-ascii"), custom = c(FALSE, TRUE, FALSE))
#> Warning: file("") only supports open = "w+" and open = "w+b": using the former
# For demonstration purpose, output.bib will look like this.
#> author = {Whitman, C. P., Alvarez-Fraga, L. and Perez, A a a},
#> title = {beta-alpha-beta structural motif},
#> Stigma