Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-24-2018 12:06 AM
Sorry I'm new to the graph database world so my question could be a bit dumb but I'm trying to learn... I've used RDF triplestores in the past and I'm looking into property graphs since the main selling point compared to triplestores seems to be simplicity and a more elegant model that doesn't require blank nodes or other unintuitive constructs to model data.
Let's say I have 3 nodes, "Alice", "Titanic", and "Odeon Movie Theater". If I want to express "Alice watched Titanic on 20th Nov, 2000" it's easy, I make a new link from "Alice" to "Titanic" with a new property "when: 20th Nov, 2000". If however I want to express "Alice watched Titanic on 20th Nov, 2000 at the Odeon Movie Theater", how do I model this? I make a link from "Alice" to "Titanic", add the property "when: 20th Nov, 2000", but where do I add the link to the "Odeon Movie Theater"? Can I use a link to another node as a property? Something like this
Alice --watched--> Titanic
:when "20th Nov, 2000"
:where--> Odeon Movie Theater
or do I have to create a new intermediate node for linking? In this case, how is this any better or simpler than the RDF model?
Thank you!
11-24-2018 11:08 AM
yes you can do that or you can ad one more property as place and set the theater name .
11-24-2018 11:20 AM
Hi,
Try this:
CREATE (n:Name {name:"Alice"})
CREATE (m:Movie {title:"Titanic"})
CREATE (t:Theater {name:"Odeon Movie Theater"})
CREATE (n)-[:THEATER {on:"20th Nov.2000"}]->(t)
CREATE (t)-[:WATCHED]->(m)
This helps to add other movies that Alice watches in the same theater or different theaters and different movies.
Hope this helps,
-Kamal
11-24-2018 01:08 PM
You would typically model this as a new node, like a :MovieViewing node, which could contain properties (such as the date of the viewing), and have relationships between the :MovieViewing node to all of the :Person nodes who attended the viewing, the :Theater of the viewing, and the :Movie being viewed.
Neo4j isn't a hypergraph, which allows relationships to link to > 1 nodes, so this is typically the most sensible option.
You may find this article useful for looking at the differences between graph databases (labeled property graphs, in the article) and RDF triplestores.
All the sessions of the conference are now available online