- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像下面这样的向量,想确定列表中的哪些元素是人名,哪些不是。我找到了 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 data
files <- unzip(tf, exdir=tempdir()) # unzips and returns a vector of file names
surnames <- read.csv(files[grepl("\\.csv$",files)]) # 152,000 surnames occurring >100 times
url <- "http://deron.meranda.us/data/census-derived-all-first.txt"
firstnames <- read.table(url(url), header=FALSE)
freq <- 10000
dict <- 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 1
which(colSums(m)>0)
# 1 3 7 8 10 11 12
关于r - 从字符串列表中,确定哪些是人名,哪些不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32545180/
我有一个 TextView 对象,其目的是输入一个人的名字。我看了here并看到 textPersonName 是一种输入类型。所以我选择了那个输入类型,认为它会做我想要的。 但是,这种输入类型不将首
我有一个 PHP 脚本,应该检查“有效”的人名,但最近破解了带有空格的名称,因此我们向验证器添加了空格。 除了这样做之外,有没有办法向 CakePHP 的验证器添加黑名单以阻止所有“无效”字符,而不是
我有很多字符串,如下所示, 伊斯兰堡:首席大法官 Iftikhar Muhammad Chaudhry 说国民账户 卡拉奇,7 月 24 日 -- 警方声称已分别逮捕数名嫌疑人 ALUM KULAM,
我是一名优秀的程序员,十分优秀!