SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Public transportation of
São Paulo in a
graph database
IGOR ROZANI
Igor Rozani
@IgorRozani
IgorRozaniIgorRozani
IgorRozani
Table of contents
What’s this project?
The database
Query examples
Q&A
The Hunger Games
What’s this project?
What’s this project?
Query examples
• Which lines does a company own?
• What station is part of which line?
• How many stations have each line?
• What is the shortest way between stations?
Which lines does a company own?
MATCH (c:Company)-[:OWN]-(l:Line)
WITH c, l
ORDER BY l.number, l.name
WITH c, collect(CASE WHEN l.number IS NULL
THEN l.name ELSE l.number + ' - ' + l.name
END) as lines
RETURN c.name AS Company, lines AS Lines
ORDER BY c.name
Company Lines
"CPTM" ["7 - Ruby", "8 - Diamond",
"9 - Emerald", "10 -
Turquoise", "11 - Coral", "12
- Sapphire", "13 - Jade",
"Airport Connect", "Airport
Express", "Touristic
Express"]
... ...
"ViaMobilidade" ["5 - Lilac"]
"ViaQuatro" ["4 - Yellow"]
What station is part of which line?
MATCH (l:Line)-[:PART_OF]-(s)
RETURN l.name AS Line, collect(s.name) AS Stations
Line Stations
"Blue" ["Jabaquara", "Tiradentes", "Praça da Árvore", "Portuguesa - Tietê", "Luz", "São Bento",
"Carandiru", "Parada Inglesa", "São Judas", "Saúde", "Paraíso", "Conceição", "Liberdade",
"Jardim São Paulo - Ayrton Senna", "São Joaquim", "Santa Cruz", "Vergueiro", "Armênia",
"Sé", "Ana Rosa", "Santana", "Tucuruvi", "Vila Mariana"]
"Green" ["Trianon-Masp", "Vila Prudente", "Chácara Klabin", "Santuário Nossa senhora de Fátima -
Sumaré", "Ana Rosa", "Clínicas", "Santos Imigrantes", "Vila Madalena", "Paraíso",
"Brigadeiro", "Consoloação", "Alto do Ipiranga", "Tamanduateí", "Sacomã"]
"Red" ["Anhangabaú", "Artur Alvim", "Bresser - Mooca", "Guilermina - Esperança", "Mal.
Deodoro", "Belém", "Pedro II", "Tatuapé", "República", "Patriarca", "Carrão", "Sé", "Penha",
"Corinthians - Itaquera", "Vila Matilde", "Brás", "Palmeiras - Barra Funda", "Santa Cecília"]
How many stations have each line?
MATCH (l:Line)-[:PART_OF]-(s)
WITH l, count(s) as qtd
RETURN l.name as Line, qtd
ORDER BY qtd DESC
Line qtd
"Blue" 23
"Diamond" 20
"Red" 18
"Emerald" 18
"Lilac" 17
... ...
"Diamond - Operational Extension" 3
"Jade" 3
"Orca Shuttle Service" 2
"Airport Express" 2
What is the shortest way between
stations?
What is the shortest way between
stations?
Directions
["Grajaú", "Primavera - Interlagos", "Autódromo", "Jurubatuba", "Socorro", "Santo
Amaro", "Granja Julieta", "Morumbi", "Brooklin“, "Diadema", "Piraporinha", "São
Bernardo", "Santo André", "Capuava", "Mauá", "Guapituba", "Ribeirão Pires", "Rio Grande da
Serra"]
MATCH x = shortestPath((s1{name:"Grajaú"})-[:CONNECT*]-(s2{name:"Rio Grande da Serra"}))
RETURN EXTRACT(n IN NODES(x) | n.name) AS Directions
What is the shortest way between
stations?
What is the shortest way between
stations?
MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da Serra"}),
p = shortestPath((s1)-[:CONNECT*]-(s2))
WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train' OR x.transport='metro')
RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions
Directions
["Grajaú", "Primavera - Interlagos", "Autódromo", "Jurubatuba", "Socorro", "Santo Amaro",
"Largo Treze", "Adolpho Pinheiro", "Alto da Boa Vista", "Borba Gato", "Brooklin", "Campo Belo",
"Eucaliptos", "Moema", "AACD - Servidor", "Hospital São Paulo", "Vila Mariana", "Chácara
Klabin", "Santos Imigrantes", "Alto do Ipiranga", "Sacomã", "Tamanduateí", "São Caetano do
Sul", "Utinga", "Prefeito Saladino", "Santo André", "Capuava", "Mauá", "Guapituba", "Ribeirão
Pires", "Rio Grande da Serra"]
What is the shortest way between
stations?
Learn more about it
This project is available on GitHub.
https://github.com/IgorRozani/Public-Transport-SP-Graph-Database
Q&A
Thank you!
The Hunger Games
1 - Which of the following options is not a node label in
the project?
A) MetroStation B) PointOfInterest C) Connect
2 - What does the following query do?
MATCH (n) WHERE n.hasBikeAttachingPost = true OR
n.hasBikeParkingTerminal = true
RETURN n.name ORDER BY n.name DESC
A) Get all nodes that have true in the property
"hasBikeAttachingPost" or "hasBikeParkingTerminal" and
return the property "name" sorted by descending order
B) Get all nodes that have true in the property
"hasBikeAttachingPost" and "hasBikeParkingTerminal"
and return the property "name" sorted by descending
order
C) Get all nodes that have true in the property
"hasBikeAttachingPost" or "hasBikeParkingTerminal" and
return the property "name" sorted by ascending order
3 - Which of the queries can get the shortest path between
two stations, using only train transport?
A) MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da
Serra"}),
p = shortestPath((s1)-[:CONNECT*]-(s2))
WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train')
RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions
B) MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da
Serra"}), p = shortestPath((s1)-[:CONNECT*]-(s2))
WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train'
OR x.transport='metro')
RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions
C) MATCH x = shortestPath((s1{name:"Grajaú"})-[:CONNECT*]-
(s2{name:"Rio Grande da Serra"}))
RETURN EXTRACT(n IN NODES(x) | n.name) AS Directions
Answer here: http://r.neo4j.com/hunger-games

Weitere ähnliche Inhalte

Kürzlich hochgeladen

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Kürzlich hochgeladen (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Public Transport São Paulo in a graph database

  • 1. Public transportation of São Paulo in a graph database IGOR ROZANI
  • 3. Table of contents What’s this project? The database Query examples Q&A The Hunger Games
  • 5.
  • 7.
  • 8. Query examples • Which lines does a company own? • What station is part of which line? • How many stations have each line? • What is the shortest way between stations?
  • 9. Which lines does a company own? MATCH (c:Company)-[:OWN]-(l:Line) WITH c, l ORDER BY l.number, l.name WITH c, collect(CASE WHEN l.number IS NULL THEN l.name ELSE l.number + ' - ' + l.name END) as lines RETURN c.name AS Company, lines AS Lines ORDER BY c.name Company Lines "CPTM" ["7 - Ruby", "8 - Diamond", "9 - Emerald", "10 - Turquoise", "11 - Coral", "12 - Sapphire", "13 - Jade", "Airport Connect", "Airport Express", "Touristic Express"] ... ... "ViaMobilidade" ["5 - Lilac"] "ViaQuatro" ["4 - Yellow"]
  • 10. What station is part of which line? MATCH (l:Line)-[:PART_OF]-(s) RETURN l.name AS Line, collect(s.name) AS Stations Line Stations "Blue" ["Jabaquara", "Tiradentes", "Praça da Árvore", "Portuguesa - Tietê", "Luz", "São Bento", "Carandiru", "Parada Inglesa", "São Judas", "Saúde", "Paraíso", "Conceição", "Liberdade", "Jardim São Paulo - Ayrton Senna", "São Joaquim", "Santa Cruz", "Vergueiro", "Armênia", "Sé", "Ana Rosa", "Santana", "Tucuruvi", "Vila Mariana"] "Green" ["Trianon-Masp", "Vila Prudente", "Chácara Klabin", "Santuário Nossa senhora de Fátima - Sumaré", "Ana Rosa", "Clínicas", "Santos Imigrantes", "Vila Madalena", "Paraíso", "Brigadeiro", "Consoloação", "Alto do Ipiranga", "Tamanduateí", "Sacomã"] "Red" ["Anhangabaú", "Artur Alvim", "Bresser - Mooca", "Guilermina - Esperança", "Mal. Deodoro", "Belém", "Pedro II", "Tatuapé", "República", "Patriarca", "Carrão", "Sé", "Penha", "Corinthians - Itaquera", "Vila Matilde", "Brás", "Palmeiras - Barra Funda", "Santa Cecília"]
  • 11. How many stations have each line? MATCH (l:Line)-[:PART_OF]-(s) WITH l, count(s) as qtd RETURN l.name as Line, qtd ORDER BY qtd DESC Line qtd "Blue" 23 "Diamond" 20 "Red" 18 "Emerald" 18 "Lilac" 17 ... ... "Diamond - Operational Extension" 3 "Jade" 3 "Orca Shuttle Service" 2 "Airport Express" 2
  • 12. What is the shortest way between stations?
  • 13. What is the shortest way between stations? Directions ["Grajaú", "Primavera - Interlagos", "Autódromo", "Jurubatuba", "Socorro", "Santo Amaro", "Granja Julieta", "Morumbi", "Brooklin“, "Diadema", "Piraporinha", "São Bernardo", "Santo André", "Capuava", "Mauá", "Guapituba", "Ribeirão Pires", "Rio Grande da Serra"] MATCH x = shortestPath((s1{name:"Grajaú"})-[:CONNECT*]-(s2{name:"Rio Grande da Serra"})) RETURN EXTRACT(n IN NODES(x) | n.name) AS Directions
  • 14. What is the shortest way between stations?
  • 15. What is the shortest way between stations? MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da Serra"}), p = shortestPath((s1)-[:CONNECT*]-(s2)) WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train' OR x.transport='metro') RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions Directions ["Grajaú", "Primavera - Interlagos", "Autódromo", "Jurubatuba", "Socorro", "Santo Amaro", "Largo Treze", "Adolpho Pinheiro", "Alto da Boa Vista", "Borba Gato", "Brooklin", "Campo Belo", "Eucaliptos", "Moema", "AACD - Servidor", "Hospital São Paulo", "Vila Mariana", "Chácara Klabin", "Santos Imigrantes", "Alto do Ipiranga", "Sacomã", "Tamanduateí", "São Caetano do Sul", "Utinga", "Prefeito Saladino", "Santo André", "Capuava", "Mauá", "Guapituba", "Ribeirão Pires", "Rio Grande da Serra"]
  • 16. What is the shortest way between stations?
  • 17. Learn more about it This project is available on GitHub. https://github.com/IgorRozani/Public-Transport-SP-Graph-Database
  • 18. Q&A
  • 20. The Hunger Games 1 - Which of the following options is not a node label in the project? A) MetroStation B) PointOfInterest C) Connect 2 - What does the following query do? MATCH (n) WHERE n.hasBikeAttachingPost = true OR n.hasBikeParkingTerminal = true RETURN n.name ORDER BY n.name DESC A) Get all nodes that have true in the property "hasBikeAttachingPost" or "hasBikeParkingTerminal" and return the property "name" sorted by descending order B) Get all nodes that have true in the property "hasBikeAttachingPost" and "hasBikeParkingTerminal" and return the property "name" sorted by descending order C) Get all nodes that have true in the property "hasBikeAttachingPost" or "hasBikeParkingTerminal" and return the property "name" sorted by ascending order 3 - Which of the queries can get the shortest path between two stations, using only train transport? A) MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da Serra"}), p = shortestPath((s1)-[:CONNECT*]-(s2)) WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train') RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions B) MATCH (s1{name:"Grajaú"}), (s2{name:"Rio Grande da Serra"}), p = shortestPath((s1)-[:CONNECT*]-(s2)) WHERE ALL (x IN RELATIONSHIPS(p) WHERE x.transport='train' OR x.transport='metro') RETURN EXTRACT(n IN NODES(p) | n.name) AS Directions C) MATCH x = shortestPath((s1{name:"Grajaú"})-[:CONNECT*]- (s2{name:"Rio Grande da Serra"})) RETURN EXTRACT(n IN NODES(x) | n.name) AS Directions Answer here: http://r.neo4j.com/hunger-games