Created
November 4, 2018 11:55
-
-
Save harukaeru/4d799d14e6c1a9c6c21683dcc8f99bb2 to your computer and use it in GitHub Desktop.
Assemble data for Anki from normalized TSV file specialized in Weblio.
This file contains hidden or 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
# python toAnki.py /path/to/your_tsv_file.tsv | |
import re | |
import sys | |
alphabet = r'[A-Za-z ,\.\[\]"\']' | |
alphabet = re.compile(alphabet) | |
quotation = r'- .*$' | |
quotation = re.compile(quotation) | |
lines = open(sys.argv[1]).readlines() | |
out = open(sys.argv[1] + '.converted.tsv', 'w') | |
for line in lines: | |
array_line = line.replace('\n', '').split('\t') | |
word = array_line[0] | |
pronunciation = array_line[1] | |
meaning = array_line[2].replace(' ', ' ').replace(' ', ' ') | |
sentence = array_line[3] | |
en = '' | |
ja = '' | |
for i, c in enumerate(sentence): | |
if not alphabet.match(c): | |
en = sentence[:i] | |
ja = sentence[i:] | |
break | |
ja = quotation.sub('', ja) | |
front = word + '<br />' + pronunciation | |
back = ( | |
'<span style="font-size: 12px">' + meaning + | |
'</span><br /><br />' + | |
'<span style="font-size: 12px">' + en + '<br />' + ja + '</span>' | |
) | |
out.write(front + '\t' + back + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should see the code in https://gist.github.com/harukaeru/6048361a11473b9678138e636e24de96 before you execute this code because it depends on that.