An Overview Of Neo4j - Uniroma1.it

2y ago
12 Views
2 Downloads
822.58 KB
27 Pages
Last View : 1m ago
Last Download : 2m ago
Upload by : Julia Hutchens
Transcription

Data Management for Data ScienceMaster of Science in Data ScienceFacoltà di Ing. dell'Informazione, Informatica e StatisticaSapienza Università di RomaAA 2018/2019An Overview of Neo4jDomenico LemboDipartimento di Ingegneria Informatica,Automatica e Gestionale A. Ruberti

NEO4J: OverviewNeo4j: uses a graph model for data representation. supports full ACID transactions. comes with a powerful, human readable graph query language. provides a powerful traversal framework for high-speed graph queries. can be used in embedded mode (the db is incorporated in the application), orserver mode, the db is a process in itself which can be accessed through RESTInterface. does not allow for sharding, then the entire graph must be stored in a singlemachine (at the moment, Neo4j supports cache sharding, which allows fordirecting queries to instances that only have certain parts of the cachepreloaded).

NEO4J: Data ModelNeo4j is entirely implemented in Java. Neo4j's data model is a Property Graph,consists of labeled nodes and relationships each with properties, that ischaracterized by the following elements: Nodes are just data records, usually denoting entities (e.g., individuals). Relationships connect two nodes. Properties are simple key-value pairs. Properties can be attached to both nodesand relationships

Nodes in NEO4J Every node can have different properties

Relationships in NEO4J Every relationship has a direction

Properties in NEO4J

Labels in NEO4J Used to represent roles played by objects (said in other terms they indicatecategories node objects belong to) Every node can have zero or more labels

Paths in NEO4J It is one or more nodes with connecting relationships

Traversal in NEO4J A Traversal is how you query a Graph, navigating from starting nodes to relatednodes according to an algorithm.

NEO4J: Example of Data Model Tom Hanks is an Actor. Ron Howard is a Director. “The DaVinci Code” is a movie. Directors and Actors are Persons. Tom Hanks has an acting role in “The DaVinci Code” “The DaVinci Code” is directed by Ron Howard The role of Tom Hanks in “The DaVinci Code” is Robert Langdon Tom Hanks knows Ron Howard since 1987.

Example: NodesABC

Example: RelationshipsAKNOWSBACTED INDIRECTEDC

Example: Propertiesname: Tom HanksAACTED INKNOWSroles: [Robert Langdon]since: 1987Bname: Ron HowardDIRECTEDCtitle: The DaVinci Code

Example: LabelsPERSONACTORname: Tom HanksAKNOWSACTED INroles: [Robert Langdon]since: 1987MOVIEBDIRECTEDname: Ron HowardCtitle: The DaVinci CodePERSONDIRECTOR

NEO4J: Storage NEO4J uses native graph storage, which is optimized and designed forstoring and managing graphs. Coherently, it adopts a native graphprocessing: it leverages index-free adjacency, meaning that connectednodes physically “point” to each other in the database. Neo4j integrates an indexing service based on Lucene that allows to storenodes referring to a label, and then access to the iterator of nodes. There areserver plugins that allow to automatically index nodes. It is finally provided with an indexing service based on the timestamp thatallows to obtain the nodes corresponding to a time and a date included in acertain range

NEO4J: Cypher’s introductionCypher is a declarative, SQL inspired language for describing patterns ingraphs. It allows us to describe what we want to select, insert, update or deletefrom a graph database without requiring us to describe exactly how to do it.Cypher uses ASCII-Art* to represent patterns.*ASCII-Art is a graphic design technique that uses computers for presentationand consists of pictures pieced together from the 95 printable (from a total of128) characters defined by the ASCII - American Standard Code forInformation Interchange (from Wikipedia)

NO4J: Nodes in CypherABThe translation in cypher is:C(A)(B)(C)

NEO4J: Relationships in CypherAKNOWSBThe translation in cypher is:ACTED INDIRECTEDC(B)-[:DIRECTED]- (C)(A)-[:ACTED IN]- (C)(A)-[:KNOWS]- (B)

NO4J: Properties in Cyphername: Tom HanksAACTED INKNOWSroles: [Robert Langdon]since: 1987Bname: Ron HowardThe translation in cypher is:DIRECTEDCtitle: The DaVinci Code(A {name:"Tom Hanks"} )(B {name:"Ron Howard"} )(C {title:"The DaVinciCode"} )(A)-[:ACTED IN {roles:["Robert Langdon"]}]- (C)(A)-[:KNOWS {since:1987}]- (B)

NEO4J: Labels in CypherPERSONACTORname: Tom HanksAKNOWSACTED INroles: [Robert Langdon]since: 1987MOVIEBDIRECTEDname: Ron HowardCtitle: The DaVinci CodePERSONDIRECTORThe translation in cypher is:(A :PERSON)(B :PERSON)(C :MOVIE)(A :ACTOR)(B :DIRECTOR)

NEO4J: Cypher’s query structureQuerying the graph MATCH: Primary way of getting data from the database.WHERE: Filters the results.RETURN: Returns and projects result data.ORDER BY: Sorts the query result.SKIP/LIMIT: Paginates the query result.Updating the graph CREATE: Creates nodes and relationships.DELETE: Removes nodes, relationships.SET: Updates properties and labels.REMOVE: Removes properties and labels.FOREACH: Performs updating actions once per element in a list, e.g.,returned by a match.

CYPHER SCRIPTCREATE (TheDaVinciCode:Movie {title:'The Da Vinci Code', released:2006,tagline:'Break The Codes'})CREATE (TomH:Person:Actor {name:'Tom Hanks', born:1956})CREATE (RonH:Person:Director {name:'Ron Howard', born:1954})CREATE (TomH)-[:ACTED IN {roles:['Dr. Robert Langdon']}]- (TheDaVinciCode)CREATE (RonH)-[:DIRECTED]- (TheDaVinciCode)CREATE (TomH)-[:KNOWS {since:1987}]- (RonH)

EXAMPLE QUERY IN CYPHERReturn the titles of the films where Tom Hanks acted in and directed by Ron HowardMATCH (node1)-[:ACTED IN]- (node2) -[:DIRECTED]-(node3)WHERE node1.name "Tom Hanks" AND node3.name "Ron Howard"RETURN node2.title as titleAlternative FormulationMATCH (node1:Person {name:"Tom Hanks"})-[:ACTED IN]- (node2) [:DIRECTED]-(node3 {name:"Ron Howard"})RETURN node2.title as title

WHERE CLAUSE (basics)You can use the boolean operators AND, OR, XOR and NOTMATCH (n)WHERE n.name 'Peter' XOR (n.age 30 AND n.name 'Timothy')OR NOT (n.name 'Timothy' OR n.name 'Peter')RETURN n.name, n.ageTo filter nodes by label, write a label predicate after the WHEREkeyword using WHERE n:foo.MATCH (n)WHERE n:SwedishRETURN n.name, n.age

EXAMPLE UPDATING in NEO4JCreate a node Person for Tom Hanks with name attribute:CREATE (n:Person { name:"Tom Hanks" });Delete a node with name attribute "Tom Hanks" if it exists:MATCH (n { name:"Tom Hanks" }) DELETE nUpdate a node with name attribute "Tom Hanks" with the attribute age 63:MATCH (n { name:"Tom Hanks" }) SET n.age 63

Othe commands in CypherID: allows to retrieve a node with a certain neo4j assigned identifiercount(rel/node/prop): add up the number of occurrencesmin(n.prop): get the lowest valuemax(n.prop): get the highest valuesum(n.prop): get the sum of numeric valuesavg(n.prop): get the average of a numeric valueDISTINCT: remove duplicatescollect(n.prop): collects all the values into a listExamples:MATCH (s) WHERE ID(s) 100 RETURN sMATCH (n:Person) RETURN count(*)MATCH (n:Person) RETURN avg(n.age)MATCH (n:Person) RETURN collect(n.born)

CreditsThese Slides for the most are adapted by the original slide of a student projectcarried out by Giulio Ganino.The main bibliographic sources used for their preparation are:www.neo4j.org/Ian Robinson, Jim Webber, and Emil Eifrem, Graph DatabasesJonas Partner, Aleksa Vukotic, and Nicki Watt. Neo4j in Action. 2012

NEO4J: Overview Neo4j: uses a graph model for data representation. supports full ACID transactions. comes with a powerful, human readable graph query language. provides a powerful traversal framework for high-speed graph queries. can be used in embedded mode (the db is incorporated in the application), or server mode

Related Documents:

Neo4j i About the Tutorial Neo4j is one of the popular Graph Databases and Cypher Query Language (CQL). Neo4j is written in Java Language. This tutorial explains the basics of Neo4j, Java with Neo4j, and Spring DATA with Neo4j. The tutorial is divided into sections such as Neo4j Introduction, Neo4j CQL, Neo4j CQL Functions, Neo4j Admin, etc.File Size: 1MB

This is the reference manual for Neo4j version 1.9.M04, written by the Neo4j Team. The main parts of the manual are: Part I, “Introduction”—introducing graph database concepts and Neo4j. Part II, “Tutorials”—learn how to use Neo4j. Part III, “Reference”—detailed information on Neo4j.

Bases de données graphes : comparaison de NEO4J et OrientDB Nicolas Vergnes 2 Neo4J (version 2.1.7) 2.1 Présentation Neo4J est un SGBD orienté graphe de la famille NoSQL crée en 2000 par la société Neo Technology. Neo4J est sous licence GPLv3 sous la dénomination de Community Edition. La version commerciale sera abordée dans le chapitre 2.3

This book is a practical guide to getting started with graph algorithms for developers and data scientists who have experience using Apache Spark or Neo4j. Although our algorithm examples utilize the Spark and Neo4j platforms, this book will also be help‐ ful for understanding more general graph concepts, regardless of your choice of

Neo4j was created with Java, therefore will run on any platform with Java installed, however the Neo4j team has simplified installation by providing easy installation packages for popular platform (e.g. a .dmg for Mac, a .deb

Neo4j Neo4j is a graph database that uses property graphdata model with a query language called Cypher In graph database domain, there is no standard query language (yet). Many vendor-dependent flavors SPARQLfor RDF Cypher, Gremlin,

Neo4j – Hey! This is why I am a Graph Database. The fundamental units that form a graph are nodes and relationships. In Neo4j, both nodes and relationships can contain properties. Nodes are often used to represent entities, but depending on the d

Alex Rider [7] Horowitz, Anthony Walker Books Ltd (2008) Rating: Product Description Alex Rider bites back. Splashing down off the coast of Australia, Alex is soon working undercover - this time for ASIS, the Australian Secret Service - on a mission to infiltrate the criminal underworld of South-East Asia: the ruthless world of the Snakehead. Faced with an old enemy and .