Skip to content

Instantly share code, notes, and snippets.

@jexp
Created March 20, 2014 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jexp/9663638 to your computer and use it in GitHub Desktop.
Save jexp/9663638 to your computer and use it in GitHub Desktop.
Football Premier League UK example by @markhneedham

Premier Football League

GraphGist for Mark Needhams Football Domain Examples

premier league

football domain

Creating a Match

CREATE (arsenal:Team {name: "Arsenal"})
CREATE (manUtd:Team  {name: "Manchester United"})
CREATE (game:Game {name: "Arsenal vs Man Utd"})

CREATE (game)-[:home_team]->(manUtd)
CREATE (game)-[:away_team]->(arsenal)

Find Arsenal’s away matches

MATCH (team:Team)<-[:away_team]-(game)
WHERE team.name = "Arsenal"
RETURN game

Evolving the Graph: Include Player Stats

football player

Adding Robin Van Persie

MATCH (game:Game)-[:home_team]->(home:Team),
      (game)-[:away_team]->(away)
WHERE home.name = "Manchester United"
AND away.name = "Arsenal"
CREATE (rvp:Player {name: "Robin van Persie"})
CREATE (rvp)-[:played]->(stats {goals: 1})
CREATE (stats)-[:in]->(game)
CREATE (stats)-[:for]->(home)
RETURN rvp, stats

Find the top scorer

MATCH (player:Player)-[:played]->(stats)
RETURN player.name,
       SUM(stats.goals) AS goals
ORDER BY goals DESC
LIMIT 10

Evolving the Graph: Adding Location

football location

Let’s look at the cypher patterns first

(:Player)-[:played]->(playerStats)
(playerStats)-[:for]->(:Team)
(:Player)-[:comes_from]->(:Country)

Use them to add an example to the graph

CREATE (c:Country {code:"NL"})
WITH c
MATCH (p:Player {name:"Robin van Persie"})
CREATE (c)<-[:comes_from]-(p)

And then build the query from those patterns.

Find Dutch players who represented Manchester United

MATCH (player:Player)-[:comes_from]->(country),
      (player)-[:played]->(stats)-[:for]->(team)
WHERE country.code = "NL"
AND team.name = "Manchester United"
RETURN player.name, COUNT(player) AS count

More Examples

  • Top away goal scorers

  • Goals scored in each month by Michu

  • Tottenham results when Bale scores

  • Which players only score when a game is televised?

  • What did Rooney do in April?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment