margopher

Random Text Generator

  • 所有者: aonemd/margopher
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

margopher

Build Status

Markov chain random text generator

How it Works

TL;DR You give it some text, it gives you a random (and sane) chunk out of this text.

Basically margopher is based on Markov chain statistical model, except that it
starts by choosing a random prefix from the states dictionary to ensure more
randomness.

It starts by parsing the input text and putting it into states dictionary then
starts generating the output sentence.

The generator will keep generating words till it encounters a terminal word (a
word that ends in any of .,:;?!)

States is a map contains prefix as keys and suffix as values.

Prefix is an array of two consecutive words from the original text.

Suffix is a slice of all the words that occur after a given prefix.

Installation

go get github.com/aonemd/margopher

Usage

  1. Import the package
import "github.com/aonemd/margopher"
  1. Create new margopher object
m := margopher.New()
  1. Read input text using one of three parsing methods:
  • ReadText(text string)
text := "Cats are nice. Cats love pizza, and Cats hates dogs."
fmt.Println(m.ReadText(text))
  • ReadFile(filePath string)
filePath := "../file.txt"
fmt.Println(m.ReadFile(filePath))
  • ReadURL(url string)
url := "https://github.com/aonemd/margopher"
fmt.Println(m.ReadURL(url))
  1. You can see the input parsed into a dictionary of States using margopher.StateDictionary():
  • It returns a dicitonary of this signature map[[2]string][]string.
  • The words are unordered because Go maps do not keep order.
fmt.Println(m.StateDictionary())

Feedback

I wrote this simple project particularly to learn Go so any feedback is more
than welcome. If you have any, please open an issue or send a pull request.

License

See LICENSE.

主要指標

概覽
名稱與所有者aonemd/margopher
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-08-28 22:38:57
推送於2019-01-16 19:24:14
最后一次提交2019-01-16 21:23:21
發布數1
最新版本名稱v1 (發布於 )
第一版名稱v1 (發布於 )
用户参与
星數42
關注者數1
派生數4
提交數51
已啟用問題?
問題數1
打開的問題數1
拉請求數1
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?