Created
January 26, 2014 17:04
-
-
Save ikegami-yukino/8635810 to your computer and use it in GitHub Desktop.
性癖リストを同義語辞書用JSONにする https://dl.dropboxusercontent.com/u/49326509/Propensity.txt
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
| # -*- coding: utf-8 -*- | |
| import json | |
| import fileinput | |
| import re | |
| import codecs | |
| ''' | |
| 性癖リストを同義語辞書用JSONにする | |
| https://dl.dropboxusercontent.com/u/49326509/Propensity.txt | |
| ''' | |
| re_items = re.compile(u'(?P<representative>[^:]+):((?P<words>[^)]+))') | |
| if __name__ == '__main__': | |
| result = {} | |
| for line in fileinput.input(): | |
| line = line.decode('utf8').strip() | |
| if not u'(' in line: | |
| continue | |
| m = re_items.search(line) | |
| if m: | |
| representative = m.group('representative') | |
| for word in m.group('words').split(', '): | |
| result[word] = representative | |
| with codecs.open('propensity.json', 'w', 'utf-8') as fd: | |
| json.dump(result, fd, indent=4, sort_keys=True, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment