load_relationships.go 846 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package main
  2. import (
  3. "bufio"
  4. "encoding/csv"
  5. "fmt"
  6. "io"
  7. "log"
  8. "os"
  9. "github.com/gomodule/redigo/redis"
  10. rg "github.com/maguec/redisgraph-go"
  11. )
  12. func main() {
  13. csvFile, _ := os.Open("p2p-Gnutella04.txt")
  14. reader := csv.NewReader(bufio.NewReader(csvFile))
  15. reader.Comma = '\t'
  16. reader.LazyQuotes = true
  17. for {
  18. line, error := reader.Read()
  19. if error == io.EOF {
  20. break
  21. } else if error != nil {
  22. log.Print(error)
  23. } else {
  24. conn, _ := redis.Dial("tcp", "localhost:6379")
  25. graph := rg.Graph{}.New("Reddit", conn)
  26. query := fmt.Sprintf("MATCH (u:User {RedditId:'u%s'}), (v:User {RedditId:'u%s'}) CREATE (u)-[d:CONTACTED]->(v)", line[0], line[1])
  27. _, jerr := graph.Query(query)
  28. if jerr != nil {
  29. fmt.Println(jerr)
  30. fmt.Println(line)
  31. fmt.Println(query)
  32. os.Exit(1)
  33. }
  34. graph.Flush()
  35. conn.Close()
  36. }
  37. }
  38. }