问题描述
我似乎无法使用Quanteda的qwic
获得所需的输出。这是我尝试过的:
library(quanteda)
library(tidyverse)
给出此文字
text <- "This is a phone number: 222-222-2222. Here's another phone number...(111)111 1111. This -- 333-3333 -- aint a complete phone number."
这里是一个正则表达式,可以匹配大多数美国电话号码以及号码两侧的任何字符
regex.phone1 <- "\\D\\(?\\d{3}\\)?[.\\s-]?\\s*\\d{3}[.\\s-]?\\s*[.\\s-]*\\d{4}\\D"
它与此处的第一个数字匹配,这意味着正则表达式正在按预期工作。
regmatches(text,regexpr(regex.phone1,text))
" 222-222-2222."
但是kwic没有任何匹配项。 这个:
kwic(
x = text,pattern = regex.phone1,window = 5,valuetype = "regex",case_insensitive = TRUE
) %>%
as_tibble
返回:
A tibble: 0 x 7
… with 7 variables: docname <chr>,from <int>,to <int>,pre <chr>,keyword <chr>,post <chr>,pattern <fct>
我希望它与所有电话号码匹配,在这种情况下为:
“ 222-222-2222”。
“。((111)111 1111。”
(并将它们以显示前,后和更多内容的kwic输出的正常形式显示)。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)