Skip to main content

マルコフ連鎖を使った文章自動生成プログラム+CLI

Project description

Text Generator

Release Package PyPI version

マルコフ連鎖を使った文章自動生成プログラム(日本語のみ)

インストール

1. 事前に mecab をセットアップしておく

  • Mac:
brew install mecab
brew install mecab-ipadic
  • Linux(Ubuntu):
sudo apt install mecab libmecab-dev mecab-ipadic-utf8 -y

2. TextGenerator-cliを PyPI からダウンロード

pip install TextGenerator-cli

ヘルプ

$ textgen
usage: textgen [-h] [-V] {prepare,p,generate,g,help,h} ...

マルコフ連鎖を使った文章自動生成プログラム

positional arguments:
  {prepare,p,generate,g,help,h}
    prepare (p)         モデルをテキストから作成(chain.db)
    generate (g)        文章を生成する
    help (h)            ヘルプを表示する

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
$ textgen p -h
usage: textgen prepare [-h] [FILE [FILE ...]]

positional arguments:
  FILE        テキストファイル(指定がなければstdin)

optional arguments:
  -h, --help  show this help message and exit
$ textgen g -h
usage: textgen generate [-h] [-n NL] [-l BYTE] [-t LIMIT]

optional arguments:
  -h, --help            show this help message and exit
  -n NL, --num_line NL  生成する文数(>=0)
  -l BYTE, --length BYTE
                        指定したbyte数以下のものが生成されるまで試行(>=0)
  -t LIMIT, --try_limit LIMIT
                        試行回数の上限(>=0)

使い方

# 吾輩は猫であるを青空文庫からダウンロード
$ curl 'http://pubserver2.herokuapp.com/api/v0.1/books/789/content?format=txt' -o wagahai.txt
# モデル作成
$ textgen p wagahai.txt
# 文数2で生成
$ textgen g 2
従って人間らしい行動を二週間継続するなら白髪だって伝染しているかとの諺《ことわざ》になるそうだ面白いじゃありませんか、今戸焼の狸《たぬき》からしていいでしょう」漆桶《み》がある。

Fork 元

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TextGenerator-cli-0.1.2.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

TextGenerator_cli-0.1.2-py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page