markovchaingo

package module
v0.0.0-...-9c4851b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 2 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Markov Chain Go

Markov chain implemented in go.

Usage

We get a MarkovChainGo struct with the New function:

package main

import "github.com/Keftcha/markovchaingo"

mcg = markogchaingo.New("<connection_string>")

mcg will now be of type Base which is an interface to your database.

For example, if you want to use a map[[2]string][]string data structure as your database, your connection string must be "in-memory://_".
You also can choosing to store your data un a json with the connection string "file:///path/to/my/file.json".

Then, the mcg struct will have two methods, Learn and Talk.

The Learn method

The Learn method is use to learn from a sentence.

func (mcg *MarkovChainGo) Learn(text string) error {
    [...]
}

It could return an error.

The Talk method

The Talk method is used to generate a sentence from what it learn.

func (mcg *MarkovChainGo) Talk() (string, error) {
    [...]
}

It return a string and may be an error.

Connection string

Database type Connection string pattern Example
In memory map[[2]string][]string data structure in-memory://<whatever you want> in-memory://_
Json file://<path to file> file://./data/sentences.json

Contribute

If you want to add your database, be pleased.

First you need to add your package in the ./database/ directory.
If you add a mackage for PostgreSQL (for example) please name it portgresqldatabase (in a directory of the same name).

In your package put at least two files:

  • db.go, which is the implementation of your struct that implement the Base interface
  • db_test.go, which is unit test of your struct and his methods

If you add other files, please, make unit test on them.

Then, don't forget to add your case in the ./database/get.go file.
So we will be able to choose it in term of our connection string.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MarkovChainGo

type MarkovChainGo struct {
	// contains filtered or unexported fields
}

MarkovChainGo struct

func New

func New(connectionString string) *MarkovChainGo

New return a pointer to a new instance of MarkovChainGo

func (*MarkovChainGo) Learn

func (mcg *MarkovChainGo) Learn(text string) error

Learn will learn from the given text

func (*MarkovChainGo) Talk

func (mcg *MarkovChainGo) Talk() (string, error)

Talk return a random sentence

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL