1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package main
- import (
- "bufio"
- "encoding/csv"
- "fmt"
- "io"
- "log"
- "os"
- "github.com/gomodule/redigo/redis"
- rg "github.com/maguec/redisgraph-go"
- )
- func main() {
- csvFile, _ := os.Open("p2p-Gnutella04.txt")
- reader := csv.NewReader(bufio.NewReader(csvFile))
- reader.Comma = '\t'
- reader.LazyQuotes = true
- for {
- line, error := reader.Read()
- if error == io.EOF {
- break
- } else if error != nil {
- log.Print(error)
- } else {
- conn, _ := redis.Dial("tcp", "localhost:6379")
- graph := rg.Graph{}.New("Reddit", conn)
- query := fmt.Sprintf("MATCH (u:User {RedditId:'u%s'}), (v:User {RedditId:'u%s'}) CREATE (u)-[d:CONTACTED]->(v)", line[0], line[1])
- _, jerr := graph.Query(query)
- if jerr != nil {
- fmt.Println(jerr)
- fmt.Println(line)
- fmt.Println(query)
- os.Exit(1)
- }
- graph.Flush()
- conn.Close()
- }
- }
- }
|