最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Obsidian 英語(yǔ)生詞自動(dòng)引用自單詞庫(kù)

2023-06-11 09:11 作者:Pascalt  | 我要投稿
  1. from nltk.tokenize import word_tokenize
  2. from nltk.stem import WordNetLemmatizer
  3. from nltk.corpus import wordnet
  4. from nltk import pos_tag
  5. from pathlib import Path
  6. import pandas as pd
  7. import re


  8. def get_wordnet_pos(treebank_tag):
  9. if treebank_tag.startswith('J'):
  10. return wordnet.ADJ
  11. elif treebank_tag.startswith('V'):
  12. return wordnet.VERB
  13. elif treebank_tag.startswith('N'):
  14. return wordnet.NOUN
  15. elif treebank_tag.startswith('R'):
  16. return wordnet.ADV
  17. else:
  18. return None

  19. def main():
  20. obsidian_path = Path("C:/Users/insil/Desktop/英語(yǔ)") # obsidian倉(cāng)庫(kù)
  21. idx = obsidian_path / '首字母索引'
  22. article = obsidian_path / '閱讀理解 1.md'
  23. lemmatizer = WordNetLemmatizer()

  24. study_words = set()
  25. for i in idx.glob('*.md'):
  26. with open(i, encoding='utf-8') as f:
  27. words = f.readlines()
  28. words = pd.Series(words)
  29. words_df = words.str.extract(r' \[(?P<flag>\s)\] \[\[(?P<word>\w+)\]\]')
  30. words_df.dropna(inplace=True)
  31. words_set = set(words_df['word'])
  32. study_words = study_words.union(words_set)

  33. with open(article, 'r', encoding='utf-8') as f:
  34. txt = f.readlines()
  35. for p in range(len(txt)):
  36. if txt[p] != '\n':
  37. txt[p] = re.sub(r'\]\]', '', txt[p])
  38. txt[p] = re.sub(r'\[\[(\w+)\|', '', txt[p])
  39. txt_words2 = word_tokenize(txt[p])
  40. txt_words = word_tokenize(txt[p].lower())
  41. txt_words = pos_tag(txt_words)
  42. for word in range(len(txt_words)):
  43. if get_wordnet_pos(txt_words[word][1]):
  44. w = lemmatizer.lemmatize(txt_words[word][0], get_wordnet_pos(txt_words[word][1]))
  45. else:
  46. w = txt_words[word][1]
  47. if w in study_words:
  48. txt_words2[word] = f'[[{w}|{txt_words2[word]}]]'
  49. res = ' '.join(txt_words2)
  50. res += '\n'
  51. txt[p] = res
  52. with open(article, 'w', encoding='utf-8') as f:
  53. f.write(''.join(txt))


  54. if __name__ == '__main__':
  55. main()

Obsidian 英語(yǔ)生詞自動(dòng)引用自單詞庫(kù)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
囊谦县| 大同县| 甘德县| 兴仁县| 新邵县| 交城县| 若羌县| 乌兰察布市| 蒲江县| 东城区| 辉县市| 修武县| 湟源县| 阜新| 澎湖县| 长兴县| 中江县| 呼伦贝尔市| 乐平市| 靖边县| 亳州市| 瓮安县| 黄龙县| 中牟县| 大英县| 潼关县| 报价| 罗定市| 太白县| 宝清县| 建瓯市| 甘洛县| 新蔡县| 洪江市| 罗源县| 绥宁县| 永城市| 阜宁县| 张家港市| 泗洪县| 兴海县|