Created
October 26, 2017 14:06
-
-
Save cipepser/5d8c3571da29019ef73a187ab1f77edb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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