Last active
August 29, 2015 14:16
-
-
Save yuitest/5e8b758cf6632565714e to your computer and use it in GitHub Desktop.
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
digraph G { | |
"ま" -> "い" | |
"え" -> "か" | |
"ん" -> "き" | |
"き" -> "ま" | |
"え" -> "る" | |
"い" -> "じ" | |
"か" -> "き" | |
"ん" -> "さ" | |
"じ" -> "ま" | |
"ん" -> "G" | |
"じ" -> "ん" | |
"る" -> "い" | |
"さ" -> "い" | |
"S" -> "る" | |
"ん" -> "じ" | |
"か" -> "ま" | |
"じ" -> "か" | |
"ま" -> "さ" | |
"ば" -> "ん" | |
"い" -> "ん" | |
"る" -> "か" | |
"い" -> "ば" | |
"S" -> "い" | |
"じ" -> "ば" | |
"き" -> "じ" | |
"S" -> "き" | |
"ん" -> "い" | |
"ま" -> "え" | |
"さ" -> "じ" | |
"か" -> "る" | |
"S" -> "じ" | |
"ん" -> "ば" | |
"い" -> "ま" | |
"る" -> "じ" | |
"か" -> "ん" | |
"ん" -> "か" | |
"S" -> "ま" | |
"ま" -> "じ" | |
"S" -> "さ" | |
"ば" -> "い" | |
"か" -> "え" | |
"る" -> "さ" | |
"き" -> "え" | |
"S" -> "え" | |
"き" -> "ん" | |
"S" -> "か" | |
"い" -> "き" | |
"ん" -> "ま" | |
"さ" -> "ん" | |
"ま" -> "ん" | |
"ん" -> "え" | |
"S" -> "ば" | |
"ば" -> "る" | |
"え" -> "ん" | |
"る" -> "き" | |
} | |
/* version: v10.55.26 */ | |
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
unique_words = frozenset(( | |
'さいばんいん', | |
'さいばんかん', | |
'さんばるかん', | |
'さんばいまん', | |
'さいばいまん', | |
'ばんさんかん', | |
'ばいきんまん', | |
'るいじんえん', | |
'ばるさん', | |
'かんばん', | |
'まいばん', | |
'ばんばん', | |
'きんえん', | |
'ばんきん', | |
'えかきまじん', | |
'えんばん', | |
'さんじかん', | |
'えんじん', | |
'かんじん', | |
'いんさん', | |
'かるかん', | |
'きえるじかん', | |
'かまえるきじまさん', | |
'かえん', | |
'さじん', | |
'じばん', | |
)) | |
unique_unigrams = frozenset(char for word in unique_words for char in word) | |
unique_bigrams = frozenset((bigram for bigrams in (zip('S' + word, word + 'G') | |
for word in unique_words) for bigram in bigrams)) | |
graphviz_content = '\n'.join(('"{}" -> "{}"'.format(*bigram) | |
for bigram in unique_bigrams)) | |
TEMPLATE = '''\ | |
digraph G {{ | |
{} | |
}} | |
/* version: v{}.{}.{} */ | |
''' | |
versions = len(unique_unigrams), len(unique_bigrams), len(unique_words) | |
print(TEMPLATE.format(graphviz_content, *versions)) |
エスケープ考慮してません。
たとえば """ や改行を含む文字列だとたぶん正しい形式で出力しません。
必要な方は自分で対応してください…・。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
いちおう Python 3.4 で動作。 2.7 で動くかは試してない。