r - quanteda (R) 中的 kwic 不能识别正则表达式模式中的多个单词
问题描述
我正在尝试识别文本中的正则表达式模式,但 kwic() 不能识别长度超过一个单词的正则表达式短语。我尝试使用phrase()
,但这也不起作用。
给你举个例子:
mycorpus = corpus(bla$`TEXT` )
foo = kwic(mycorpus, pattern = "\\bno\\b", window = 10, valuetype = "regex" ) #gives 1959 obs.
foo = kwic(mycorpus, pattern = "\\bno\\b\\s{0,5}\\w+", window = 10, valuetype = "regex" ) #gives 0 obs.
foo = kwic(mycorpus, pattern = "no\\sother", window = 10, valuetype = "regex" ) #gives 0 obs. even though it should find 3 phrases
即使文本中有多种模式需要识别。
谢谢您的帮助!
解决方案
那是因为 kwic 搜索令牌,并且令牌不再包含空格。要搜索 quanteda 视为“短语”的标记序列,请将模式包装在phrase()
. (另见?phrase
。)
library("quanteda")
## Package version: 2.0.0
txt <- "one two three four five"
# no match
kwic(txt, "one\\stwo", valuetype = "regex", window = 1)
## kwic object with 0 rows
# match
kwic(txt, phrase("one two"), valuetype = "regex", window = 1)
##
## [text1, 1:2] | one two | three
推荐阅读
- spring - Spring Integration Mail Google IMAP 如何设置收件箱的检查频率
- java - java求矩形和正方形的面积
- c# - WPF - 对象的列表到 DataGrid 中自己的组合框列
- android - 神秘错误:导航到另一个 React Native 视图并返回后,React Native 视图损坏(但没有崩溃)
- dspace - 如何使用 Mirage2 作为主题在侧边栏计数中应用徽章
- javascript - 无法从组件反应中调用函数
- c++ - OpenCL get_global_id 结果错误
- intellij-idea - Intellij 中的远程调试未连接到 wildfy 应用程序服务器(不是本地运行的 tomcat)
- python - 澄清 tf.Session() 作用域 TensorFlow
- javascript - 编写一个函数来打印总和,它接受这个 wa 中的参数: sum(2)(3) 并输出 5