Advertisement
obernardovieira

Basic Interaction With Neo4j (Graph Database)

Mar 12th, 2016
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from py2neo import authenticate, Graph
  2.  
  3. #
  4. authenticate("localhost:7474", "neo4j", "mypass")
  5. #
  6. graph = Graph("http://localhost:7474/db/data/")
  7. cypher = graph.cypher
  8.  
  9. def novaPessoa(nome, idade) :
  10.  
  11.     cypher.execute("CREATE (a:Pessoa {nome:{n},idade:{i}})", n = nome, i = idade)
  12.     return
  13.  
  14. def novaRelacaoConhece(nome1, nome2, desde) :
  15.  
  16.     cypher.execute("MATCH (a:Pessoa {nome : {n1}}), (b:Pessoa {nome : {n2}})\
  17.                    CREATE (a)-[:CONHECE {desde: {d}}]->(b)", n1 = nome1, n2 = nome2, d = desde)
  18.     return
  19.  
  20. novaPessoa("Eu", 20)
  21. novaPessoa("Ela", 20)
  22. novaRelacaoConhece("Eu", "Ela", 2016)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement