gpt4 book ai didi

r - 如何删除缺少括号的引文部分

转载 作者:行者123 更新时间:2023-12-04 09:50:14 26 4
gpt4 key购买 nike

数据

mystring1 <- "Other work has shown that, in addition to language-general features such as a decreased speaking rate and an expanded pitch range, clear speech production involves the enhancement of the acoustic-phonetic distance between phonologically contrastive categories 􏰃e.g., Ferguson and Kewley-Port, 2002; Krause and Braida, 2004, Picheny et al, 1986; Smiljanic and Bradlow, 2005, 2007􏰀."

mystring2 <- "Other work has shown that, in addition to language-general features such as a decreased speaking rate and an expanded pitch range, clear speech production involves the enhancement of the acoustic-phonetic distance between phonologically contrastive categories 􏰃e.g., Ferguson and Kewley-Port, 2002; Krause and Braida, 2004, Picheny et al, 1986; Smiljanic and Bradlow, 2005, 2007􏰀. Therefore, reduced sensitivity to any or all of the language-specific acoustic-phonetic dimensions of contrast and clear speech enhancement would yield a diminished clear speech benefit for non-native listeners. This may appear somewhat surprising given that clear speech production was elicited in our studies by instructing the talkers to speak clearly for the sake of listeners with either a hearing impairment or from a different native language background. However, as discussed further in Bradlow and Bent 􏰃2002􏰀, the limits of clear speech as a means of enhancing non-native speech perception likely reflect the “mistuning” that characterizes spoken language communication between native and non-native speakers."

我想获得一些有关正则表达式的帮助。我得到了一些文本数据。基本上我想删除出现在句子最后一个单词和句号之间的引用部分。但是,括号不知何故丢失了。 mystring1 就是一个例子。在此示例中,我想删除 e.g., Ferguson and Kewley-Port, 2002; Krause 和 Braida,2004,Picheny 等,1986; Smiljanic 和 Bradlow,2005 年、2007 年 }。但是这句话只是一个段落中的其中一个句子。 mystring2mystring1 之后又包含三个句子。我的目标是从 mystring2 中删除引用部分。但是我没有成功;该模式正在删除比我想要的更多的文本。如何修改正则表达式模式?提前感谢您的帮助。

# This works for mystring1.
gsub(x = mystring1, pattern = "e\\.g\\.,.*[0-9]{4}(?=.)", replacement = "", perl = T)

[1] "Other work has shown that, in addition to language-general features such as a
decreased speaking rate and an expanded pitch range, clear speech production involves
the enhancement of the acoustic-phonetic distance between phonologically contrastive
categories 􏰃􏰀."

# But this pattern does not work for mystring2; gsub() removes texts more than I want.
gsub(x = mystring2, pattern = "e\\.g\\.,.*[0-9]{4}(?=.)", replacement = "", perl = T)

[1] "Other work has shown that, in addition to language-general features such as a decreased
speaking rate and an expanded pitch range, clear speech production involves the
enhancement of the acoustic-phonetic distance between phonologically contrastive
categories 􏰃􏰀, the limits of clear speech ... (I trimmed texts here) speakers."

最佳答案

我建议使用

\be\.g\.,.*?[0-9]{4}[^\w.]*(?=\.)

参见 regex demo .

详情

  • \be\.g\. - 一个完整的单词例如(\b 是一个单词边界)
  • , - 逗号
  • .*? - 除换行符以外的任何 0+ 个字符(在模式开头添加 (?s) 以使其也匹配换行符)
  • [0-9]{4} - 四位数
  • [^\w.]* - 除了单词字符和点之外的 0+ 个字符
  • (?=\.) -(与位置匹配的正前瞻) 必须紧邻当前位置的右侧。

R demo :

rx <- "\\be\\.g\\.,.*?[0-9]{4}[^\\w.]*(?=\\.)"
gsub(x = mystring1, pattern = rx, replacement = "", perl = TRUE)
## => [1] "Other work has shown that, in addition to language-general features such as a decreased speaking rate and an expanded pitch range, clear speech production involves the enhancement of the acoustic-phonetic distance between phonologically contrastive categories 􏰃."
gsub(x = mystring2, pattern = rx, replacement = "", perl = TRUE)
## => [1] "Other work has shown that, in addition to language-general features such as a decreased speaking rate and an expanded pitch range, clear speech production involves the enhancement of the acoustic-phonetic distance between phonologically contrastive categories 􏰃. Therefore, reduced sensitivity to any or all of the language-specific acoustic-phonetic dimensions of contrast and clear speech enhancement would yield a diminished clear speech benefit for non-native listeners. This may appear somewhat surprising given that clear speech production was elicited in our studies by instructing the talkers to speak clearly for the sake of listeners with either a hearing impairment or from a different native language background. However, as discussed further in Bradlow and Bent 􏰃2002􏰀, the limits of clear speech as a means of enhancing non-native speech perception likely reflect the “mistuning” that characterizes spoken language communication between native and non-native speakers."

关于r - 如何删除缺少括号的引文部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54766798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com