代码之家  ›  专栏  ›  技术社区  ›  Vikram Karthic

通过在闪亮的应用程序文本框中键入的文本显示匹配的句子

  •  0
  • Vikram Karthic  · 技术社区  · 7 年前

    我试过了 kwic

    require(quanteda)
    require(tm)
    data(crude, package = "tm")
    mycorpus <- corpus(crude)
    
    kwic(mycorpus, "company") # Pass the words from the text box corpus
    

    请求帮助。。。

    1 回复  |  直到 7 年前
        1
  •  0
  •   mpadge    7 年前

    我想你要的是,

    table(kwic(mycorpus, phrase, join = FALSE)$keyword)
    

    哪里 phrase 只是随着输入更多的术语而加长。(需要 quanteda >= 0.99 ,其中还包括 函数,此处可能有用。)对于更一般的匹配,您可以转换语料库和所有输入的术语(以不断加长的方式) )进入标记词干

    mystems <- corpus(crude) %>% texts() %>% tokens() %>% tokens_wordstem()
    phrase <- tokens(phrase, remove_punct = TRUE, remove_symbols = TRUE) %>%
        tokens_wordstem(language = "greek") %>% # or whatever
        as.character()
    

    table(kwic(mystems, phrase, join = FALSE)$keyword) 应该做同样的事情,但只匹配词干,而不是精确的单词。如果您想要与每个文档匹配的字数,那么 *apply purrr::map() )也会提取出来。