问题描述
有没有更好的方法可以从自由文本中提取专有名词(例如“London”、“John Smith”、“Gulf of Carpentaria”)?
也就是像
这样的函数proper_nouns <- function(text_input) {
# ...
}
这样它就会从文本输入中提取专有名词列表。
示例
这是一组 7 个文本输入(有些简单,有些难):
text_inputs <- c("a rainy London day","do you know John Smith?","sail the Adriatic",# tougher examples
"Hey Tom,where's Fred?" # more than one proper noun in the sentence
"Hi Lisa,I'm Joan." # more than one proper noun in the sentence,separated by capitalized word
"sail the Gulf of Carpentaria",# proper noun containing an uncapitalized word
"The great Joost van der Westhuizen." # proper noun containing two uncapitalized words
)
这是这样的函数、规则集或 AI 应该返回的内容:
proper_nouns(text_inputs)
[[1]]
[1] "London"
[[2]]
[1] "John Smith"
[[3]]
[1] "Adriatic"
[[4]]
[1] "Tom" "Fred"
[[5]]
[1] "Lisa" "Joan"
[[6]]
[1] "Gulf of Carpentaria"
[[7]]
[1] "Joost van der Westhuizen"
问题:简单的正则表达式不完美
考虑一些简单的正则表达式规则,它们有明显的缺陷:
-
规则:使用大写单词,除非它们是句子中的第一个单词(通常会大写)。问题:会在句首遗漏专有名词。
-
规则:假设连续的大写单词是同一个专有名词的一部分(多部分专有名词,如
"John Smith"
)。问题:"Gulf of Carpentaria"
会被遗漏,因为它之间有一个未大写的单词。- 人名中包含非大写单词的类似问题,例如
"Joost van der Westhuizen"
。
- 人名中包含非大写单词的类似问题,例如
问题
我目前最好的方法是简单地使用上面的正则表达式,并且成功率很低。有没有更好或更准确的方法从 R 中的文本中提取专有名词?如果我能在真实文本上获得 80-90% 的准确率,那就太好了。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)