Define a Neo4J Database Schema - sitcomlab/IPED-Toolkit GitHub Wiki
- Steps for efficient data creation
- 1. General
- 2. Locations
- 3. Videos
- 4. Overlays
- 5. Relationships
- 6. Relationship Weighting
STEPS for efficient data creation
i) Check if database is empty (optional)
Use Command 1.1
ii) Create Locations
Use command 2.4 or 2.5
iii) Create Videos
Use command 3.4 or 3.5
iv) Create Overlays (optional)
Use command 4.4 or 4.5
v) Create ID-lists for up-coming relationships
Use command 2.2 (for all Location-IDs) Use command 3.2 (for all Video-IDs) Use command 4.2 (for all Overlay-IDs)
vi) Create Relationships between Locations
Use command 5.2.1 for only one direction Use command 5.2.2 for both directions
vii) Create Relationships between Locations and Videos
Use command 5.3.1
viii) Create Relationships between Locations and Overlays (optional)
Use command 5.4.1
ix) Get a Relationship-ID-list for up-coming relationship-weighting
Use command 5.1.1 for (for all Relationships between Locations) Use command 5.1.2 for (for all Relationships between a Location and a Video) Use command 5.1.3 for (for all Relationships between a Locations and an Overlay)
x) Create weights for Relationships (e.g. intents) (optional)
Use command 6.1.3
1. GENERAL
1.1 Select everything
MATCH n RETURN n
1.2 Select everything, but show only the IDs and names
MATCH n RETURN ID(n) AS ID, n.name AS name
2. LOCATIONS
2.1 Select all Locations
MATCH (l:Location) RETURN l
2.2 Get a list with all Location-IDs
MATCH (l:Location) RETURN ID(l) AS lID, l.name AS Name, l.description AS Description, l.tags AS Tags, l.lat AS Latitude, l.lon AS Longitude
2.3 Select a Location by ID
MATCH (l:Location) WHERE ID(l)=0 RETURN l
2.4 Create a single Location
- For empty tags please use
tags:[]
instead - Description can be empty, please use
description :""
instead
CREATE (l:Location {name:"NAME", description:"DESCRIPTION", tags: ["TAG1", "TAG2"], lat:51.96944882545107, lon:7.595720887184142 }) RETURN l
2.5 Create multiple Locations
If you want to add more locations with a single command and not one location by one, please use these command instead:
CREATE (l1:Location {name:"NAME", description:"DESCRIPTION", tags: ["TAG1", "TAG2"], lat:51.96944882545107, lon:7.595720887184142 })
CREATE (l2:Location {name:"NAME", description:"DESCRIPTION", tags: [], lat:51.96944882545107, lon:7.595720887184142 })
...
2.6 Edit a Location by ID
MATCH (l:Location) WHERE ID(l)=0 SET l.name="NAME" RETURN l
2.7 Delete a Location by ID
MATCH (l:Location) WHERE ID(l)=0 DELETE l
3. VIDEOS
3.1 Select all Videos
MATCH (v:Video) RETURN v
3.2 Get a list with all Video-IDs
MATCH (v:Video) RETURN ID(v) AS vID, v.name AS Name, v.description AS Description, v.date AS Date, v.url AS URL
3.3 Select a Video by ID
MATCH (v:Video) WHERE ID(v)=2 RETURN v
3.4 Create a single Video
- Date can be empty, please use
date :""
instead - Description can be empty, please use
description :""
instead - URL have to be the prefix
url:"/media/video/
+ YOUR FILENAME +"
but without any FILE-suffix e.g..mp4
CREATE (v:Video {name:"NAME", description:"DESCRIPTION", date: "", url:"/media/video/FILENAME"}) RETURN v
3.5 Create multiple Videos
If you want to add more videos with a single command and not one video by one, please use these command instead:
CREATE (v1:Video {name: "Schlossplatz", url: "/media/video/task01", description: "Schlossplatz bei Tag", date: "", tags:[]})
CREATE (v2:Video {name: "Frauenstraße", url: "/media/video/task02", description: "Frauenstraße bei Tag", date: "", tags:[]})
...
3.6 Edit a Video by ID
MATCH (v:Video) WHERE ID(v)=2 SET v.name="NAME" RETURN v
3.7 Delete a Video by ID
MATCH (v:Video) WHERE ID(v)=2 DELETE v
4. OVERLAYS
4.1 Select all Overlays
MATCH (o:Overlay) RETURN o
4.2 Get a list with all Overlay-IDs
- not done yet -
4.3 Select an Overlay by ID
MATCH (o:Overlay) WHERE ID(o)=3 RETURN o
4.4 Create a single Overlay
- not done yet -
4.5 Create multiple Overlays
- not done yet -
4.6 Edit an Overlay by ID
MATCH (o:Overlay) WHERE ID(v)=3 SET o.name="NAME" RETURN o
4.7 Delete an Overlay by ID
MATCH (o:Overlay) WHERE ID(o)=3 DELETE o
5. RELATIONSHIPS
5.1 General
5.1.1 Get a list with all Relationship-IDs between Locations
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) RETURN l1.name AS From, ID(r) AS rID, l2.name AS To
5.2.1 Get a list with all Relationship-IDs between Locations and Videos
MATCH (l:Location)<-[r:wasRecordedAt]-(v:Video) RETURN ID(r) AS rID, l.name AS Location, v.name AS Related Video
5.3.1 Get a list with all Relationship-IDs between Locations and Overlays
MATCH (l:Location)<-[r:locatedAt]-(o:Overlay) RETURN ID(r) AS rID, l.name AS Location, o.name AS Related Overlays
5.2 Between Locations
5.2.1 Create a single Relationship between two Locations (only in one direction) by their IDs
MATCH (l1:Location), (l2:Location) WHERE ID(l1)=0 AND ID(l2)=1 CREATE UNIQUE (l1)-[:relatedTo]->(l2) RETURN l1.name AS From, ID(r) AS rID, l2.name AS To
5.2.2 Create two Relationships between two Locations (both directions) by their IDs
MATCH (l1:Location), (l2:Location) WHERE ID(l1)=0 AND ID(l2)=1 CREATE (l1)-[r:relatedTo]-(l2) RETURN l1.name AS From, ID(r) AS rID, l2.name AS To
5.2.3 Show all Relationships from one Location
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) WHERE ID(l1)=0 RETURN l1.name AS From, ID(r) AS rID, l2.name AS To
5.2.4 Delete a Relationship between two Locations by Location-IDs
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) WHERE ID(l1)=0 AND ID(l2)=1 DELETE r
5.2.5 Delete a Relationship between two Locations by Relationship-ID
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) WHERE ID(r)=100 DELETE r
5.3 Between Locations and Videos
5.3.1 Create a single Relationship between a Location and a Video by their IDs
MATCH (l:Location), (v:Video) WHERE ID(l)=0 AND ID(v)=2 CREATE UNIQUE (v)-[r:wasRecordedAt]->(l) RETURN ID(r) AS rID, l.name AS Location, v.name AS Video
5.3.2 Show a Relationship between a Location and a Video
MATCH (l:Location)<-[r:wasRecordedAt]-(v:Video) WHERE ID(l)=0 RETURN ID(r) AS rID, l.name AS Location, v.name AS Related Video
5.3.3 Delete a Relationship between a Location and a Video by their IDs
MATCH (l:Location)<-[r:wasRecordedAt]-(v:Video) WHERE ID(l)=0 AND ID(v)=2 DELETE r
5.3.4 Delete a Relationship between a Location and a Video by Relationship-ID
MATCH (l:Location)<-[r:wasRecordedAt]-(v:Video) WHERE ID(r)=100 DELETE r
5.4 Between Locations and Overlays
5.4.1 Create a single Relationship between a Location and an Overlay by their IDs
MATCH (l:Location), (o:Overlay) WHERE ID(l)=0 AND ID(o)=3 CREATE UNIQUE (o)-[r:locatedAt]->(l) RETURN ID(r) AS rID, l.name AS Location, o.name AS Overlay
5.4.2 Show a Relationship between a Location and an Overlay
MATCH (l:Location)<-[r:locatedAt]-(o:Overlay) WHERE ID(l)=0 RETURN ID(r) AS rID, l.name AS Location, v.name AS Related Overlay
5.4.3 Delete a Relationship between a Location and an Overlay by their IDs
MATCH (l:Location)<-[r:locatedAt]-(o:Overlay) WHERE ID(l)=0 AND ID(o)=3 DELETE r
5.4.4 Delete a Relationship between a Location and an Overlay by Relationship-ID
MATCH (l:Location)<-[r:locatedAt]-(o:Overlay) WHERE ID(r)=100 DELETE r
6. RELATIONSHIP-WEIGHTING
6.1. For Locations (e.g. Intents)
6.1.1 Show weights from Relationships
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) RETURN r
6.1.2 Create weights by Location-IDs
MATCH (l1:Location)-[r:relatedTo]->(l2:Location) WHERE ID(l1)=0 AND ID(l2)=1 SET r.intents=["INTENT1", "INTENT2"] RETURN r
6.1.3 Create weights by Relationship-ID
MATCH (l1:Location)-[r:relatedTo]-(l2:Location) WHERE ID(r)=100 SET r.intents=["INTENT1", "INTENT2"] RETURN r