有道單詞本數(shù)據(jù)檢索方法

用有道保存了一些查詢過(guò)的單詞和詞組,想要對(duì)這些內(nèi)容進(jìn)行檢索。

數(shù)據(jù)清理

  1. 導(dǎo)出單詞本為文本文件,在notepad中打開。
  2. 合并行 #因?yàn)橐粋€(gè)entry分到了3-5行
    • 替換\r\n
    • 替換\n
  3. 去掉entry名 #導(dǎo)出的每個(gè)條目前都有排序編號(hào)
    • 替換\d{1,},
  4. 替換連續(xù)的多個(gè)空格為單個(gè)空格
  5. 去掉音標(biāo) #在R中會(huì)以亂碼顯示
    • 替換[.*]

導(dǎo)入R

library(tidyverse)
vocab <- readLines("input/vocabulary_youdao.txt", encoding = "UTF-8") %>% as.tibble

# extrac word according a pattern
d_ex_vocab <- function(patt) {
  library(magrittr)
  extrt <- stringr::str_extract(vocab$value, patt)
  dong_word_extract <- vocab[!is.na(extrt), ]
  if (dim(dong_word_extract)[1] == 0) 
    stop("No word extracted, plz check the spell!")
  write.csv(dong_word_extract, paste0("output/", patt, ".csv"), quote = F, row.names = F)
  return(dong_word_extract)
}

ex_word <- d_ex_vocab("取決于")
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容