从字符串列表中,确定哪些是人名,哪些不是

从字符串列表中,确定哪些是人名,哪些不是,第1张

概述我有一个类似下面的矢量,并希望确定列表中的哪些元素是人名,哪些不是.我发现了humaniformat包,它可以格式化名称,但遗憾的是并不能确定字符串是否实际上是一个名称.我还发现了一些用于实体提取的包,但它们似乎需要实际的文本来进行词性标注,而不是单个名称. 例 pkd.names.quotes <- c("Mr. Rick Deckard", # Name 我有一个类似下面的矢量,并希望确定列表中的哪些元素是人名,哪些不是.我发现了humaniformat包,它可以格式化名称,但遗憾的是并不能确定字符串是否实际上是一个名称.我还发现了一些用于实体提取的包,但它们似乎需要实际的文本来进行词性标注,而不是单个名称.

pkd.names.quotes <- c("Mr. Rick Deckard",# name                      "Do AndroIDs Dream of Electric Sheep",# Not a name                      "Roy Batty",# name                       "How much is an electric ostrich?",# Not a name                      "My schedule for today Lists a six-hour self-accusatory depression.",# Not a name                      "Upon him the contempt of three planets descended.",# Not a name                      "J.F. Sebastian",# name                      "Harry Bryant",# name                      "goat class",# Not a name                      "Holden,Dave",# name                      "Leon Kowalski",# name                      "Dr. Eldon Tyrell") # name
解决方法 这是一种方法.美国人口普查局列出了一个姓氏列表>在其数据库中100次(有频率):全部152,000.如果使用完整列表,则所有字符串都有一个名称.例如,“class”,“him”和“the”是某些语言的名称(不知道哪种语言).同样,有许多名字列表(见 this post).

下面的代码抓住了2000年人口普查中的所有姓氏,并列出了所引用帖子的名字,然后是每个列表中最常见的10,000个子集,组合并清理列表,并将其用作tm包中的字典识别哪些字符串包含名称.您可以通过更改freq变量来控制“灵敏度”(freq = 10,000似乎可以生成您想要的结果).

url <- "http://www2.census.gov/topics/genealogy/2000surnames/names.zip"tf <- tempfile()download.file(url,tf,mode="wb")                     # download archive of surname datafiles    <- unzip(tf,exdir=tempdir())               # unzips and returns a vector of file namessurnames <- read.csv(files[grepl("\.csv$",files)])  # 152,000 surnames occurring >100 timesurl <- "http://deron.meranda.us/data/census-derived-all-first.txt"firstnames <- read.table(url(url),header=FALSE)freq <- 10000dict  <- unique(c(tolower(surnames$name[1:freq]),tolower(firstnames$V1[1:freq])))library(tm)corp <- Corpus(VectorSource(pkd.names.quotes))tdm  <- TermdocumentMatrix(corp,control=List(tolower=TRUE,dictionary=dict))m    <- as.matrix(tdm)m    <- m[rowSums(m)>0,]m#            Docs# Terms       1 2 3 4 5 6 7 8 9 10 11 12#   bryant    0 0 0 0 0 0 0 1 0  0  0  0#   dave      0 0 0 0 0 0 0 0 0  1  0  0#   deckard   1 0 0 0 0 0 0 0 0  0  0  0#   eldon     0 0 0 0 0 0 0 0 0  0  0  1#   harry     0 0 0 0 0 0 0 1 0  0  0  0#   kowalski  0 0 0 0 0 0 0 0 0  0  1  0#   leon      0 0 0 0 0 0 0 0 0  0  1  0#   rick      1 0 0 0 0 0 0 0 0  0  0  0#   roy       0 0 1 0 0 0 0 0 0  0  0  0#   sebastian 0 0 0 0 0 0 1 0 0  0  0  0#   tyrell    0 0 0 0 0 0 0 0 0  0  0  1which(colSums(m)>0)#  1  3  7  8 10 11 12
总结

以上是内存溢出为你收集整理的从字符串列表中,确定哪些是人名,哪些不是全部内容,希望文章能够帮你解决从字符串列表中,确定哪些是人名,哪些不是所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1137379.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存