Last active
January 15, 2018 04:32
-
-
Save ki111/8614389d32db56d7ee97102b6317ad28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.7 | |
# coding: utf-8 | |
# 辞書アプリにアクセスするためのパッケージ | |
from DictionaryServices import DCSGetTermRangeInString, DCSCopyTextDefinition | |
import csv | |
# 変数 | |
word_list = open('word-dot-eliminated.csv','r') | |
row = 0 | |
word = [] | |
count = [] | |
file = open('word-verified.csv','w') | |
# pandasが使えないのでcsvライブラリから読み込み | |
reader = csv.reader(word_list) | |
for r in reader: | |
word.append(r[0]) | |
count.append(r[1]) | |
# 辞書で検索したい単語 | |
for w in word: | |
print(row) | |
word_range = DCSGetTermRangeInString(None, w, 0) | |
# 辞書にある単語は書き込み | |
try: | |
word_definition = DCSCopyTextDefinition(None, w, word_range) | |
word_definition = word_definition.split() | |
file.write(str(word[row])+","+str(count[row])+","+str(word_definition[0].encode('utf_8'))+"\n") | |
# 辞書にない単語は書き込み | |
except IndexError: | |
print("skipped") | |
row = row + 1 | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment