{"id":37794129,"url":"https://github.com/cpl/markov","last_synced_at":"2026-01-16T15:19:01.249Z","repository":{"id":68060657,"uuid":"177911071","full_name":"cpl/markov","owner":"cpl","description":"A markov chain generator for text in Golang.","archived":false,"fork":false,"pushed_at":"2025-04-04T19:48:41.000Z","size":1472,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T20:32:45.949Z","etag":null,"topics":["fun","golang-package","markov","markov-chain"],"latest_commit_sha":null,"homepage":"https://cpl.li/2019/markov-chains-go/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-27T03:24:36.000Z","updated_at":"2025-04-04T19:48:44.000Z","dependencies_parsed_at":"2024-06-20T16:33:15.042Z","dependency_job_id":"c04e181a-64c4-48b9-bd13-0d88a0e82006","html_url":"https://github.com/cpl/markov","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cpl/markov","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpl%2Fmarkov","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpl%2Fmarkov/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpl%2Fmarkov/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpl%2Fmarkov/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpl","download_url":"https://codeload.github.com/cpl/markov/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpl%2Fmarkov/sbom","scorecard":{"id":306656,"data":{"date":"2025-08-11","repo":{"name":"github.com/cpl/markov","commit":"54fbef181a2da0d90b700de0ee864bca1e36314b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T22:13:10.075Z","repository_id":68060657,"created_at":"2025-08-17T22:13:10.075Z","updated_at":"2025-08-17T22:13:10.075Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fun","golang-package","markov","markov-chain"],"created_at":"2026-01-16T15:19:01.168Z","updated_at":"2026-01-16T15:19:01.239Z","avatar_url":"https://github.com/cpl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markov Chains in Go\n\n[![Go Report Card](https://goreportcard.com/badge/cpl.li/go/markov)](https://goreportcard.com/report/cpl.li/go/markov)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4.svg?)](https://godoc.org/cpl.li/go/markov)\n\nIf you don't know what a Markov Chain is I recommend reading up on it and checking out this [visual explanation](http://setosa.io/ev/markov-chains/). To put it simply, Markov Chain represent probabilistic state changes inside a Finite-State-Machine. The state transition probabilities can be easily represented as a matrix but in practice (software) that leaves lots of entries being 0 and taking up memory, so a more elegant solution is a nested hash map.\n\nIn the code above the following are used:\n\n```go\n// represents a grouping of individual words\n// eg: []string{\"I\", \"am\", \"Alex\"}, this can be extracted\n// from an original string of any form or shape:\n// \"I am Alex\", \"I   am  Alex\", \"I:am:Alex\"\n// and it's all up to the caller to split their strings into sequences\ntype Sequence []string\n```\n\n\n```go\n// a pairs represents a possible transition between a sequence of n words\n// and the next (single) word\n// the Current sequence must be of an equal lenght to the chain pair size\n// meaning you can't have some transitions for 2-grouped words and 1-grouped words\ntype Pair struct {\n\tCurrent Sequence\n\tNext    string\n}\n```\n\n```go\n// by having a\ntype transitionMap map[string]int\n// and then nested inside\nfrequencyMatrix map[string]transitionMap\n// we generate our mapping of all encountered\n// sequences to their respective next word\n// and the number of times this occurs\n```\n\nOnce your wrap your head around these structures, the rest of the functions are easy to understand.\n\n## Examples\n\nThe text below was generated on a 2-paired sequence chain with a student movie script as input.\n\n```text\nYou know I can't KEN I understand. KEN opens the door to\na soaking wet KEN, who stands on the pink scissors and\npicks them up, toying with them. KEN glances around for\nhis wallet. DEBRA (Comforting) There's nothing to be\nembarrassed about you know. Lots of people it happens.\nKEN grunts. KEN Yeah. The bird chirps from its cage in\nthe corner. KEN tries to scream but is unable to pull in\noxygen. The pressure in his ears begins to burst as the\nbathtub overflows. 29. A figure appears above him,\nblurry through the water.\n```\n\n\n## Download \u0026 Install\n\nIf you have Go installed, you can simply run:\n\n```shell\ngo get cpl.li/go/markov/markov-cli\n```\n\n## Usage\n\nI provided an example main function with `stdin` input and basic flag parsing for generating n words from the input data.\n\n```go\npackage main\n\nimport (\n\t\"flag\"\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"strings\"\n\n\t\"cpl.li/go/markov\"\n)\n\nfunc main() {\n\t// handle flags\n\tmaxWords := flag.Int(\"words\", 100, \"max words to generate (default 100)\")\n\tpairSize := flag.Int(\"pairs\", 2, \"size of a word pair (default 2)\")\n\tflag.Parse()\n\n\tc := NewChain(*pairSize) // create markov chain\n\n\t// read stdin\n\tdata, err := ioutil.ReadAll(os.Stdin)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// give data as sequence to chain model\n\tc.Add(strings.Fields(string(data)))\n\n\tb := c.NewBuilder(nil)             // create builder on top of chain\n\tb.Generate(*maxWords - c.PairSize) // generate new words\n\tfmt.Println(b.String())            // print end product\n}\n```\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpl%2Fmarkov","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpl%2Fmarkov","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpl%2Fmarkov/lists"}