Databases Reference
In-Depth Information
Creating the Shakespeare Graph
To create the Shakespeare graph shown in Figure 3-6 , we use CREATE to build the overall
structure. This statement is executed by the Cypher runtime within a single transaction
such that once the statement has executed, we can be confident the graph is present in
its entirety in the database. If the transaction fails, no part of the graph will be present
in the database. As we might expect, Cypher has a humane and visual way of building
graphs:
CREATE (shakespeare { firstname: 'William' , lastname: 'Shakespeare' }),
(juliusCaesar { title: 'Julius Caesar' }),
(shakespeare)-[:WROTE_PLAY { year: 1599 }]->(juliusCaesar),
(theTempest { title: 'The Tempest' }),
(shakespeare)-[:WROTE_PLAY { year: 1610}]->(theTempest),
(rsc { name: 'RSC' }),
(production1 { name: 'Julius Caesar' }),
(rsc)-[:PRODUCED]->(production1),
(production1)-[:PRODUCTION_OF]->(juliusCaesar),
(performance1 { date: 20120729 }),
(performance1)-[:PERFORMANCE_OF]->(production1),
(production2 { name: 'The Tempest' }),
(rsc)-[:PRODUCED]->(production2),
(production2)-[:PRODUCTION_OF]->(theTempest),
(performance2 { date: 20061121 }),
(performance2)-[:PERFORMANCE_OF]->(production2),
(performance3 { date: 20120730 }),
(performance3)-[:PERFORMANCE_OF]->(production1),
(billy { name: 'Billy' }),
(review { rating: 5, review: 'This was awesome!' }),
(billy)-[:WROTE_REVIEW]->(review),
(review)-[:RATED]->(performance1),
(theatreRoyal { name: 'Theatre Royal' }),
(performance1)-[:VENUE]->(theatreRoyal),
(performance2)-[:VENUE]->(theatreRoyal),
(performance3)-[:VENUE]->(theatreRoyal),
(greyStreet { name: 'Grey Street' }),
(theatreRoyal)-[:STREET]->(greyStreet),
(newcastle { name: 'Newcastle' }),
(greyStreet)-[:CITY]->(newcastle),
(tyneAndWear { name: 'Tyne and Wear' }),
(newcastle)-[:COUNTY]->(tyneAndWear),
(england { name: 'England' }),
(tyneAndWear)-[:COUNTRY]->(england),
(stratford { name: 'Stratford upon Avon' }),
(stratford)-[:COUNTRY]->(england),
(rsc)-[:BASED_IN]->(stratford),
(shakespeare)-[:BORN_IN]->stratford
The preceding Cypher code does two different things: it creates nodes (and their prop‐
erties), and relates nodes (with relationship properties where necessary). For example,
CREATE (shakespeare { firstname: 'William', lastname: 'Shakespeare', _la
Search WWH ::




Custom Search