Neo4j - Rede de relacionamentos baseada em grafos
-
Upload
evandro-venancio -
Category
Technology
-
view
688 -
download
0
description
Transcript of Neo4j - Rede de relacionamentos baseada em grafos
![Page 1: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/1.jpg)
[email protected] @evenancio evenancio.wordpress.com linkedin.com/in/evandrovenancio
![Page 2: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/2.jpg)
O que é um Grafo ???
Vértice = NóArco = Relacionamento
Vértice A Vértice B
arco
![Page 3: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/3.jpg)
Santos Rodovia dos Imigrantes
São Bernardo do Campo
Rodovia dos Imigrantes
São Paulo
![Page 4: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/4.jpg)
Santos São Bernardo do
Campo
São Paulo
[:imigrantes]
[:imigr
antes]
![Page 5: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/5.jpg)
As pontes de Königsberg
1736Leonhard Euler
![Page 6: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/6.jpg)
#Big Data tools
#Data Center and Cloud Software
#Technology of the Year
SOME FEATURES• Totalmente Transacional (ACID)• Tem controle de concorrência• Armazenamento próprio baseado em discos• Escalável para múltiplas máquinas• Possui uma linguagem intuitiva (Cypher)• Possui interface RESTFul• Possui API nativa em Java• Pode ser distribuído como um servidor Standalone• Pode ser embutido na aplicação
![Page 7: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/7.jpg)
![Page 8: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/8.jpg)
![Page 9: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/9.jpg)
Let’s to play ???
#The Smith Family lab#
![Page 10: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/10.jpg)
John Smithour hero
Dad Mom
bastardbro
sister
beautifulwife
my children
my cousin
![Page 11: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/11.jpg)
CYPHER – Creating the Smith family -> 11 nodes
CREATE (dad:People {name:"Joseph Smith", datebirth: 1961 })CREATE (mom:People {name:"Joan Smith", datebirth: 1963 })CREATE (me:People {name:"John Smith", datebirth: 1982 })CREATE (sister:People {name:"Josephine Smith", datebirth: 1986 })CREATE (bro:People {name:"Jonathan Smith", datebirth: 1994 })CREATE (wife:People {name:"Jennifer K. L. Smith", datebirth: 1984 })CREATE (children1:People {name:"Jen-El Smith", datebirth: 2005 })CREATE (children2:People {name:"Jil-El Smith", datebirth: 2007 })CREATE (children3:People {name:"Juju-El Smith", datebirth: 2011 })CREATE (children4:People {name:"Jor-El Smith", datebirth: 2013 })CREATE (cousin:People {name:"Cousine Smith Oliver", datebirth: 2013 })
![Page 12: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/12.jpg)
![Page 13: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/13.jpg)
CYPHER – Creating the basic relationship between the Smiths 1/2
MATCH (dad:People {name:"Joseph Smith" })MATCH (mom:People {name:"Joan Smith" })MATCH (me:People {name:"John Smith" })MATCH (sister:People {name:"Josephine Smith" })MATCH (bro:People {name:"Jonathan Smith" })CREATE (me)-[:IS_SON_OF]->(dad)CREATE (me)-[:IS_SON_OF]->(mom)CREATE (sister)-[:IS_SON_OF]->(dad)CREATE (sister)-[:IS_SON_OF]->(mom)CREATE (bro)-[:IS_SON_OF]->(dad)
![Page 14: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/14.jpg)
![Page 15: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/15.jpg)
CYPHER – Creating the basic relationship between the Smiths 2/2
MATCH (sister:People {name:"Josephine Smith" })MATCH (cousin:People {name:"Cousine Smith Oliver" })MATCH (me:People {name:"John Smith" })MATCH (wife:People {name:"Jennifer K. L. Smith" })MATCH (children1:People {name:"Jen-El Smith" })MATCH (children2:People {name:"Jil-El Smith" })MATCH (children3:People {name:"Juju-El Smith" })MATCH (children4:People {name:"Jor-El Smith" })CREATE (cousin)-[:IS_SON_OF]->(sister)CREATE (me)-[:IS_MARRIED_WITH]->(wife)CREATE (children1)-[:IS_SON_OF]->(me)CREATE (children2)-[:IS_SON_OF]->(me)CREATE (children2)-[:IS_SON_OF]->(wife)CREATE (children3)-[:IS_SON_OF]->(me)CREATE (children3)-[:IS_SON_OF]->(wife)CREATE (children4)-[:IS_SON_OF]->(me)CREATE (children4)-[:IS_SON_OF]->(wife)
![Page 16: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/16.jpg)
![Page 17: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/17.jpg)
SOME QUESTIONS!!!1) Quem são os pais de John Smith?MATCH (me:People {name:"John Smith" })MATCH (me)-[:IS_SON_OF]->(parents)RETURN parents.name
2) Quem são os filhos de John Smith?MATCH (me:People {name:"John Smith" })MATCH (me)<-[:IS_SON_OF]-(children)RETURN children.name
3) Quem são os irmãos de John Smith?MATCH (me:People {name:"John Smith" })MATCH (me)-[:IS_SON_OF]->(parents)<-[:IS_SON_OF]-(brothers)RETURN DISTINCT brothers.name
4) Quem são os irmãos de John Smith do mesmo pai e da mesma mãe?MATCH (me:People {name:"John Smith" })MATCH (me)-[:IS_SON_OF]->(parents)<-[:IS_SON_OF]-(brothers)WITH me, brothers, count(parents) as parents_countWHERE parents_count = length(me-[:IS_SON_OF]->())RETURN brothers.name
![Page 18: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/18.jpg)
5) Quem são os primos de Cousine?
MATCH (cousin:People {name:"Cousine Smith Oliver" })MATCH (cousin)-[:IS_SON_OF]->(mysister)MATCH (mysister)-[:IS_SON_OF]->(ourparents)<-[:IS_SON_OF]-(brothers_of_my_sister)MATCH (brothers_of_my_sister)<-[:IS_SON_OF]-(sons_of_brothers_of_my_sister)RETURN DISTINCT sons_of_brothers_of_my_sister.name
Para finalizar, vamos deixar um pouco mais complexo!
![Page 19: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/19.jpg)
6) Quem são os primos de Cousine que torcem para o Chelsea?
6.1 – Creating NodesMATCH (children1:People {name:"Jen-El Smith" })MATCH (children4:People {name:"Jor-El Smith” })CREATE (chelsea:SoccerTeam { name: “Chelsea”})CREATE (children1)-[:IS_FAN_OF]->(chelsea)CREATE (children4)-[:IS_FAN_OF]->(chelsea)
6.2 - QueryMATCH (cousin:People {name:"Cousine Smith Oliver" })MATCH (cousin)-[:IS_SON_OF]->(mysister)MATCH (mysister)-[:IS_SON_OF]->(ourparents)<-[:IS_SON_OF]-(brothers_of_my_sister)MATCH (brothers_of_my_sister)<-[:IS_SON_OF]-(sons_of_brothers_of_my_sister)MATCH (sons_of_brothers_of_my_sister)-[:IS_FAN_OF]->(soccer_team)WHERE soccer_team.name = "Chelsea"
![Page 20: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/20.jpg)
![Page 21: Neo4j - Rede de relacionamentos baseada em grafos](https://reader035.fdocumentos.tips/reader035/viewer/2022062405/55860457d8b42a3d6b8b46df/html5/thumbnails/21.jpg)
[email protected] @evenancio evenancio.wordpress.com linkedin.com/in/evandrovenancio