Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created October 26, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipepser/5d8c3571da29019ef73a187ab1f77edb to your computer and use it in GitHub Desktop.
Save cipepser/5d8c3571da29019ef73a187ab1f77edb to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"io"
"log"
"math/rand"
"os"
"strings"
"time"
)
func main() {
f, err := os.Open("../data/q81.out.txt")
defer f.Close()
if err != nil {
panic(err)
}
corpus := []string{}
r := bufio.NewReaderSize(f, 4096)
for {
l, _, err := r.ReadLine()
if err == io.EOF {
break
}
if err != nil {
panic(err)
}
tokens := strings.Split(string(l), " ")
for _, t := range tokens {
corpus = append(corpus, t)
}
}
fw, err := os.Create("../data/q82.out.txt")
if err != nil {
log.Fatal(err)
}
defer fw.Close()
rand.Seed(time.Now().UnixNano())
for i, c := range corpus {
d := rand.Intn(5) + 1
for j := 1; j <= d; j++ {
if i-j+1 > 0 {
fw.WriteString(c + "\t" + corpus[i-j])
fw.WriteString("\n")
}
}
for j := 1; j <= d; j++ {
if i+j < len(corpus) {
fw.WriteString(c + "\t" + corpus[i+j])
fw.WriteString("\n")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment