Skip to content

Instantly share code, notes, and snippets.

@yuitest
Last active August 29, 2015 14:16
Show Gist options
  • Save yuitest/5e8b758cf6632565714e to your computer and use it in GitHub Desktop.
Save yuitest/5e8b758cf6632565714e to your computer and use it in GitHub Desktop.
digraph G {
"ま" -> "い"
"え" -> "か"
"ん" -> "き"
"き" -> "ま"
"え" -> "る"
"い" -> "じ"
"か" -> "き"
"ん" -> "さ"
"じ" -> "ま"
"ん" -> "G"
"じ" -> "ん"
"る" -> "い"
"さ" -> "い"
"S" -> "る"
"ん" -> "じ"
"か" -> "ま"
"じ" -> "か"
"ま" -> "さ"
"ば" -> "ん"
"い" -> "ん"
"る" -> "か"
"い" -> "ば"
"S" -> "い"
"じ" -> "ば"
"き" -> "じ"
"S" -> "き"
"ん" -> "い"
"ま" -> "え"
"さ" -> "じ"
"か" -> "る"
"S" -> "じ"
"ん" -> "ば"
"い" -> "ま"
"る" -> "じ"
"か" -> "ん"
"ん" -> "か"
"S" -> "ま"
"ま" -> "じ"
"S" -> "さ"
"ば" -> "い"
"か" -> "え"
"る" -> "さ"
"き" -> "え"
"S" -> "え"
"き" -> "ん"
"S" -> "か"
"い" -> "き"
"ん" -> "ま"
"さ" -> "ん"
"ま" -> "ん"
"ん" -> "え"
"S" -> "ば"
"ば" -> "る"
"え" -> "ん"
"る" -> "き"
}
/* version: v10.55.26 */
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))
@yuitest
Copy link
Author

yuitest commented Mar 11, 2015

いちおう Python 3.4 で動作。 2.7 で動くかは試してない。

@yuitest
Copy link
Author

yuitest commented Mar 11, 2015

@yuitest
Copy link
Author

yuitest commented Mar 11, 2015

エスケープ考慮してません。
たとえば """ や改行を含む文字列だとたぶん正しい形式で出力しません。

必要な方は自分で対応してください…・。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment