Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A program to generate RDF file that can then be ingested into dgraph. #35

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions scripts/data_generator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"flag"
"fmt"
"math/rand"
"time"
"strings"
"bufio"
"os"
)

const charset = "abcdefghijklmnopqrtuvwxyz" + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var seededRand* rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))

func randomString(length int) string {
b := make([] byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}

func main() {
types := flag.String("types", "string", "comma-separated list of types to be generated")
totalSize := flag.Int("total-size", 1 * 1024 * 1024 * 1024, "total size of data that should be generated")
stringLength := flag.Int("string-length", 1024, "length of the string to generate; ignore if string type is not specified")
repeatSubjects := flag.Int("repeat-subjects", 1, "Number of times to repeat the subject")
outputFile := flag.String("output", "out.rdf", "Output file to write the RDF document")

flag.Parse()

typesArray := strings.Split(*types, ",")

for _, typeg := range typesArray {
switch typeg {
case "string":
break
default:
fmt.Printf("Type %s not supported. Ignored\n", typeg)
}
}

fmt.Println("types:", *types)
fmt.Println("total size:", *totalSize)
fmt.Println("string length:", *stringLength)
fmt.Println("repeat subjects:", *repeatSubjects)
fmt.Println("output:", *outputFile)

f, _ := os.Create(*outputFile)
w := bufio.NewWriter(f)

for generatedLength, subjectNumber, uid := 1, 1, 1; generatedLength < *totalSize; generatedLength += *stringLength * *repeatSubjects {
for i := 0; i < *repeatSubjects; i++ {
fmt.Fprintf(w, "<0x%x> <Predicate-%d> \"%s\".\n", uid, subjectNumber, randomString(*stringLength))
uid++
}
subjectNumber++
}
}