gomarkov
1.0.0
텍스트 데이터를위한 Markov 체인 구현.
Markov 체인에 대해 자세히 알아볼 수 있습니다.
package main
import (
"github.com/mb-14/gomarkov"
"fmt"
"strings"
"io/ioutil"
"encoding/json"
)
func main () {
//Create a chain of order 2
chain := gomarkov . NewChain ( 2 )
//Feed in training data
chain . Add ( strings . Split ( "I want a cheese burger" , " " ))
chain . Add ( strings . Split ( "I want a chilled sprite" , " " ))
chain . Add ( strings . Split ( "I want to go to the movies" , " " ))
//Get transition probability of a sequence
prob , _ := chain . TransitionProbability ( "a" , [] string { "I" , "want" })
fmt . Println ( prob )
//Output: 0.6666666666666666
//You can even generate new text based on an initial seed
chain . Add ( strings . Split ( "Mother should I build the wall?" , " " ))
chain . Add ( strings . Split ( "Mother should I run for President?" , " " ))
chain . Add ( strings . Split ( "Mother should I trust the government?" , " " ))
next , _ := chain . Generate ([] string { "should" , "I" })
fmt . Println ( next )
//The chain is JSON serializable
jsonObj , _ := json . Marshal ( chain )
err := ioutil . WriteFile ( "model.json" , jsonObj , 0644 )
if err != nil {
fmt . Println ( err )
}
}Gibberish 사용자 이름 검출기
가짜 hackernews 포스트 생성기
포켓몬 이름 생성기