【发布时间】:2018-02-22 22:43:23
【问题描述】:
我正在处理主要以英语为主要内容的文本文档库(每个存储为一个字符串),但包括一些西班牙语文档和一些以英语和西班牙语重复相同信息的文档。我使用了cld2 和cld3 包(它们在R 中实现了Chrome 的语言检测功能)来估计语料库中每个字符串中包含的语言。我的目标是处理所有包含英语和西班牙语文本的字符串,以便保留英语部分并删除西班牙语部分。
这是我正在使用的三个字符串的示例:
mixed.language.strings <- c("Department of Cultural Affairs and Special Events: Today will be the First Annual Mariachi and Folklorico Festival! Local groups begin at 1:00pm and world renowned headliners start at 3:00pm. It will be located in Millennium Park. Invite your friends, family, and neighbors to participate in this FREE event! \nEnjoy the weather on this beautiful Sunday! \n ************** \n Departamento de Asuntos Culturales y Eventos Especiales: Hoy será el Primer Festival Anual de Mariachi y Balet Folklórico! Los grupos locales comienzan a las 1:00 pm y los grupos de renombre mundial empiezan a las 3:00 pm. Será en el Millennium Park. Inviten a su familia, amigo@s, y vecin@s a este evento completamente GRATIS!",
"Call or walk into our office for information on the Emergency Heating Repair Program which provides eligible low-income, owner-occupied homes grants for a new heating system.\n\nLlame o visite nuestra oficina para más información sobre un programa de la Ciudad ofreciendo dinero hacía la reparación o instalación de sistemas de calefacción. Dueños de casa de ingresos bajos son elegibles. \n\n 3476 S. Archer Ave. \n (773) 523-8250",
"Join me and other local elected officials for a workshop on appealing your property taxes. Homes in West & South townships of Cook County are currently eligible to appeal. See flier for more info, or call my office at 773-523-8250.\n\nLos invito a un taller sobre el proceso de apalear sus impuestos de propiedad. Hogares en los West y East “townships” del Condado de Cook son elegibles ahora para apalear sus impuestos. Por favor refiéranse al volante añadido a este mensaje, o llame mi oficina al 773-523-8250, para más información."
)
据我所知,cld2 和 cld3 可以估计字符串中包含的语言,但不能根据语言提取字符串的部分内容。
R 中是否有不同的包,我可以使用它来识别每种语言中每个字符串的部分,并据此将字符串分成两部分?
谢谢!抱歉,如果不清楚;这是我第一次发帖。
【问题讨论】:
-
在三个示例字符串中,看起来语言转换都是换行符分隔的。总是这样吗?也许您可以在换行符上将字符串分解为子字符串,并只保留看起来只有英文的子字符串。