Graph Tools
By Andreas Kuczera
What are Graph databases?
Characteristics of graph databases
- NoSQL
- optimized for transactional performance: Native graph processing benefits traversal performance, but at the expense of making some queries that don’t use traversals difficult or memory intensive.
- advantages: performance, flexibility, agility:
- performance increase when dealing with connected data
- schema free: extremely flexible, additive data model
- mode of delivery aligned with today’s agile software delivery practices
The labeled property graph model
Example graph: Charlemagne, Einhard and a book
Explanation
- The graph shows a node with the label “Person” and the property “Name” on top which has the value “Charlemagne”.
- Below, to the left, there is another node with the label “Person” by the name of Einhard.
- Below, to the right, there is a node with the label “Buch” (book) and the property “Titel” (title) which has the value “Vita Karoli Magni”.
- The edges indicate through their labels that Charlemagne knew Einhart, that Einhard wrote the book “Vita Karoli Magni” ca. 828-830 and that Charlemagne is mentioned in this book.
Software: Neo4j
- Download: https://neo4j.com/download/
- Or use a Sandbox
- Start Neo4j-Desktop or use browser interface (http://localhost:7474):
- At the top left, there is information about the structure of the database and some sample commands. The third tab contains the documentation
- The input field for the commands is located in the area on the right; below, the window where results are shown
- First login with neo4j/neo4j. Then assign your own password. Remember the password!
- Query language: cypher
Practice makes perfect
cypher commands
cypher refcard
My first node
// creates a node
CREATE (n);
// creates a node and returns it
CREATE (n) RETURN *;
// creates a node with a label and returns the result
CREATE (n:Person) RETURN *;
// creates a node with a label and an attribute and returns the result
CREATE (n:Person {name:'Andreas'}) RETURN *;
// creates a node with a label and an attribute, if it doesn't exist yet, and returns the result
MERGE (n:Person {name:'Andreas'}) RETURN *;
// Adds the attribute "placeOfBirth" to a node with the attribute "name:Andreas"
MATCH (n:Person {name:'Andreas'}) SET n.placeOfBirth = 'Giessen' RETURN *;
Relation and evaluation
// Creates an edge between two nodes, if it doesn't already exist, and returns the nodes and the edge
MATCH (n1:Person {name:'Andreas'})
MATCH (n2:Person {name:'Torsten'})
MERGE (n1)-[:KNOWS]->(n2)
RETURN *;
// names and ranks the places of birth of persons by frequency, order descending
MATCH (n:Person)
RETURN n.placeOfBirth, count(*) as count, collect(n.surname) as surname
ORDER BY count DESC;
Literature
- KUCZERA, Andreas: Graphentechnologien in den Digitalen Geisteswissenschaften. Modellierung – Import – Exploration (Online-Publikation). (2018)
- KUCZERA, Andreas: Graphentechnologien in den Digitalen Geisteswissenschaften, in: ABI Technik 2017; 37(3): 179–196
- KUCZERA, Andreas: Das Deutsche Textarchiv in der Graphenwelt, in: Mittelalter. Interdisziplinäre Forschung und Rezeptionsgeschichte, 04.04.2017.
- KUCZERA, Andreas: Digital Editions beyond XML – Graph-based Digital Editions, in: HistoInformatics 2016 - The 3rd HistoInformatics Workshop. Proceedings of the 3rd HistoInformatics Workshop on Computational History (HistoInformatics 2016), hrsg. von Marten Düring, Adam Jatowt, Johannes Preiser-Kappeller, co-located with Digital Humanities 2016 conference (DH 2016), Krakow, Poland, July 11, 2016, S. 37-46.
- KUCZERA, Andreas: Endcoding and Presenting Historical Biographical Data with Graph Data Bases. In: CO:OP. The Creative Archives’ and Users’ Network. Marburg (2016).
- KUCZERA, Andreas: Graphbasierte digitale Editionen, in: Mittelalter. Interdisziplinäre Forschung und Rezeptionsgeschichte, 19. April 2016.
- KUCZERA, Andreas: Graphdatenbanken für Historiker. Netzwerke in den Registern der Regesten Kaiser Friedrichs III. mit neo4j und Gephi, in: Mittelalter. Interdisziplinäre Forschung und Rezeptionsgeschichte, 05.05.2015.
- HUNGER, Michael: neo4j - Eine Graphdatenbank für alle. 2014