Skip to content

Instantly share code, notes, and snippets.

@valefranz
Last active October 19, 2018 10:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save valefranz/b6a3833a7ec042f77e31 to your computer and use it in GitHub Desktop.
Save valefranz/b6a3833a7ec042f77e31 to your computer and use it in GitHub Desktop.
Neo4j Example of a bibliographic network based on DBLP data

This example can be run here: http://graphgist.neo4j.com/#!/gists/b6a3833a7ec042f77e31 If you use the code or images, please cite: Valentina Franzoni, https://gist.github.com/valefranz/b6a3833a7ec042f77e31

First step: create some authors

//CREATE authors, with name as a property
CREATE
(Author2:Person {name:'Jiming Liu'}),
(Author3:Person {name:'Yuanxi Li'}),
(Author4:Person {name:'Alfredo Milani'}),

//CREATE publications, with title as a property
(Publication4:JournalPaper {title:'Intelligent Social Media Indexing and Sharing Using an Adaptive Indexing Search Engine'}),
(Journal2: Journal {journalName: 'ACM Transaction on Intelligent System Technologies'});

MATCH n RETURN n

Second step: create a relationship

MATCH (P: JournalPaper), (J:Journal) WHERE
P.title = 'Intelligent Social Media Indexing and Sharing Using an Adaptive Indexing Search Engine'
AND
J.journalName = 'ACM Transaction on Intelligent System Technologies'
CREATE
//CREATE relationships between publications and journal
(P)-[:publishedIn {year:2012 }]->(J);
MATCH n RETURN n

Third step, create some more data

MATCH (n)-[r]->m DELETE r;
MATCH n DELETE n;

//CREATE authors, with name as a property
CREATE
(Author1:Person {name:'Valentina Franzoni'}),
(Author2:Person {name:'Jiming Liu'}),
(Author3:Person {name:'Yuanxi Li'}),
(Author4:Person {name:'Alfredo Milani'}),
(Author5:Person {name:'Valentina Poggioni'}),
(Author6:Person {name:'Fabiana Zollo'}),
(Author7:Person {name:'Aris Anagnostopoulos'}),
(Author8:Person {name:'Osvaldo Gervasi'}),
(Author9:Person {name:'Stefano Leonardi'}),
(Author10:Person {name:'Alberto Marchetti Spaccamela'}),
//CREATE publications, with title as a property
(Publication1:ConferencePaper {title:'Set Similarity Measures for Images Based on Collective Knowledge'}),
(Publication2:JournalPaper {title:'Heuristic semantic walk for concept chaining in collaborative networks'}),
(Publication3:ConferencePaper {title:'Automated Classification of Book Blurbs According to the Emotional Tags of the Social Network Zazie'}),
(Publication4:JournalPaper {title:'Intelligent Social Media Indexing and Sharing Using an Adaptive Indexing Search Engine'}),
(Publication5:JournalPaper {title:'Guidelines for Web Usability and Accessibility on the Nintendo Wii'}),
(Publication6:JournalPaper {title:'Experimental evaluation of pheromone models in ACOPlan'}),
(Publication7:ConferencePaper {title:'Viral Misinformation: The Role of Homophily and Polarization'}),
(Publication8:ConferencePaper {title:'Constant Integrality Gap LP Formulations of Unsplittable Flow on a Path'}),
(Publication9:ConferencePaper {title:'Parallel scheduling problems in next generation wireless networks'}),
(Publication10:JournalPaper {title:'X3DMMS an X3DOM tool for molecular and material sciences'}),
(Journal1: Journal {journalName: 'Lecture Notes in Computer Science'}),
(Journal2: Journal {journalName: 'ACM Transaction on Intelligent System Technologies'}),
(Journal3: Journal {journalName: 'International Journal of Web Services'}),

//CREATE relations of authorship between authors and papers, showing year
(Author1)-[:isAuthorOf ]->(Publication1),(Author3)-[:isAuthorOf ]->(Publication1),(Author4)-[:isAuthorOf ]->(Publication1),
(Author1)-[:isAuthorOf ]->(Publication2),(Author4)-[:isAuthorOf ]->(Publication2),
(Author1)-[:isAuthorOf ]->(Publication3),(Author5)-[:isAuthorOf ]->(Publication3),(Author6)-[:isAuthorOf ]->(Publication3),
(Author3)-[:isAuthorOf ]->(Publication4),(Author4)-[:isAuthorOf ] ->(Publication4),(Author2)-[:isAuthorOf ]->(Publication4),
(Author1)-[:isAuthorOf ]->(Publication5),(Author8)-[:isAuthorOf ]->(Publication5),
(Author4)-[:isAuthorOf ]->(Publication6),(Author5)-[:isAuthorOf ]->(Publication6),
(Author6)-[:isAuthorOf ]->(Publication7),(Author7)-[:isAuthorOf ]->(Publication7),
(Author7)-[:isAuthorOf ]->(Publication8),(Author9)-[:isAuthorOf ]->(Publication8),
(Author9)-[:isAuthorOf ]->(Publication9),(Author10)-[:isAuthorOf ]->(Publication9),
(Author6)-[:isAuthorOf ]->(Publication10),(Author8)-[:isAuthorOf ]->(Publication10),

//CREATE relationships between publications and journal
(Publication1)-[:publishedIn {year:2015 }]->(Journal1),
(Publication2)-[:publishedIn {year:2014 }]->(Journal3),
(Publication3)-[:publishedIn {year:2014 }]->(Journal1),
(Publication4)-[:publishedIn {year:2012 }]->(Journal2),
(Publication5)-[:publishedIn {year:2009 }]->(Journal1),
(Publication6)-[:publishedIn {year:2011 }]->(Journal2);
MATCH n RETURN n

Fourth step: exploit some path functions

//qui
//MATCH (a) where a.name="Yuanxi Li" or a.name="Jiming Liu"
MATCH p=(a)-[:isAuthorOf*..2]-(b) where a.name="Yuanxi Li" and b.name="Jiming Liu"
RETURN nodes(p)
//a qui
//MATCH n RETURN n

End of the brief experiment.

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