Skip to content

Instantly share code, notes, and snippets.

@ikegami-yukino
Created January 26, 2014 17:04
Show Gist options
  • Select an option

  • Save ikegami-yukino/8635810 to your computer and use it in GitHub Desktop.

Select an option

Save ikegami-yukino/8635810 to your computer and use it in GitHub Desktop.
性癖リストを同義語辞書用JSONにする https://dl.dropboxusercontent.com/u/49326509/Propensity.txt
# -*- 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