Legis-graph - Exploring US Congress as a Graph

The Data Model


datamodel
  • The data for this example comes from Govtrack.us.

  • We have modeled US Congress (Bills, Legislators, Committees and their interactions) as a graph (see the data model diagram to the right)

Throughout these interactive Neo4j Browser guides, when you see a Cypher embedded in the document you can click it to populate the query editor:

What is the meta model for this data set?
call db.schema.visualization();

Querying The Graph


Now let’s look at some interesting queries.

Who represents NY?

// Who represents NY?
MATCH (s:State)<-[:REPRESENTS]-(l:Legislator)
WHERE s.code = "NY"
RETURN s,l

Who represents NY? - Party and legislative body

// Who represents NY? - Party and legislative body
MATCH (s:State)<-[:REPRESENTS]-(l:Legislator)
WHERE s.code = "NY"
MATCH (p:Party)<-[:IS_MEMBER_OF]-(l)-[:ELECTED_TO]->(b:Body)
RETURN s,l,p,b

Specific Legislator


Charles Schumer’s Committees

// Charles Schumer's committees
MATCH (l:Legislator) WHERE l.firstName = "Charles" AND l.lastName = "Schumer"
MATCH (l)-[:SERVES_ON]->(c:Committee)
RETURN l, c

Examine a single bill for Charles Schumer

// Examine a single bill for Charles Schumer
MATCH (l:Legislator) WHERE l.firstName = "Charles" AND l.lastName = "Schumer"
MATCH (l)-[:SERVES_ON]->(c:Committee)<-[:REFERRED_TO]-(b:Bill)
MATCH (b)-[:DEALS_WITH]->(subj:Subject)
RETURN * LIMIT 5

More Complex Traversals


Over what topics does Charles Schumer have influence?

// Over what topics does Charles Schumer have inluence?
MATCH (l:Legislator) WHERE l.firstName = "Charles" AND l.lastName = "Schumer"
MATCH (l)-[:SERVES_ON]->(c:Committee)<-[:REFERRED_TO]-(b:Bill)
MATCH (b)-[:DEALS_WITH]->(subj:Subject)
RETURN subj, collect(DISTINCT c.name) AS committees, count(*) AS num ORDER BY num DESC LIMIT 25

What are topics of bills sponsored by Charles Schumer?

// What are the topics of Bills sponsored by Charles Schumer
MATCH (l:Legislator) WHERE l.firstName = "Charles" AND l.lastName = "Schumer"
MATCH (l)<-[:SPONSORED_BY]-(b:Bill)
MATCH (b)-[:DEALS_WITH]->(subj:Subject)
RETURN subj, count(*) AS num ORDER BY num DESC LIMIT 25

In the next Neo4j Browser Guide we’ll take a step back and learn how to construct graph patterns and query out graph using Cypher.