I want a lot of data structure examples in cypher real world ones
Assistant
Social Network Graph
In this example, we'll create a graph to represent a social network using Cypher. This graph will contain nodes representing users and relationships representing connections between users.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
CREATE (user1:User {name: 'Alice'}), (user2:User {name: 'Bob'}), (user3:User {name: 'Charlie'})
CREATE (user1)-[:FOLLOWS]->(user2), (user1)-[:FOLLOWS]->(user3), (user2)-[:FOLLOWS]->(user3)
MATCH (user:User) WHERE id(user) = 1 OR id(user) = 2 OR id(user) = 3
MATCH (user)-[:FOLLOWS*0..2]-(other:User)
WITH user, collect(DISTINCT other) AS followers
ORDER BY length(path) desc
MATCH (user)-[:POSTED*0..2]->(post:Post)
WITH user, followers, collect(DISTINCT post) AS posts
ORDER BY size(posts) desc
WITH user, followers, size(posts) as total_posts, size(followers) as num_followers
MATCH (user)-[:POSTED*0..2]->(post:Post {score: 10})
WITH user, followers, total_posts, num_followers, count(post) as popular_posts
ORDER BY popular_posts desc
In this query, we create nodes for Alice, Bob, and Charlie, and then create relationships between them representing follow relationships. We then use Cypher's Path Patterns to find users who follow Alice, Bob, or Charlie, and collect all the nodes in the path. We then find all the posts for each user and their followers, and calculate the total number of posts and followers. We then find all posts with a score of 10 and count them to determine how many popular posts each user has.
Product and Category Catalog
In this example, we'll create a graph to represent a product and category catalog using Cypher. This graph will contain nodes representing products, categories, and relationships representing category-product associations.
Here's the Cyp
User
I want a lot of data structure examples in cypher real world ones precise the nodes their attributes and the relationship
Assistant
Social Network Graph
In this example, we'll create a graph to represent a social network using Cypher. This graph will contain nodes representing users, relationships representing connections between users, and properties to store additional attributes such as user names, profile images, and descriptions.
Here's the Cypher query:
cypher
CREATE (user1:User {name: 'Alice', profileImage: 'https://example.com/alice.jpg', description: 'Software Engineer'})
CREATE (user2:User {name: 'Bob', profileImage: 'https://example.com/bob.jpg', description: 'Data Scientist'})
CREATE (user3:User {name: 'Charlie', profileImage: 'https://example.com/charlie.jpg', description: 'Product Manager'})
CREATE (user1)-[:FOLLOWS]->(user2)
CREATE (user1)-[:FOLLOWS]->(user3)
CREATE (user2)-[:FOLLOWS]->(user3)
MATCH (user:User) WHERE id(user) = 1 OR id(user) = 2 OR id(user) = 3
MATCH (user)-[:FOLLOWS*0..2]-(other:User)
WITH user, collect(DISTINCT other) AS followers
ORDER BY length(path) DESC
MATCH (user)-[:POSTED*0..2]->(post:Post)
WITH user, followers, collect(DISTINCT post) AS posts
ORDER BY size(posts) DESC
WITH user, followers, size(posts) AS total_posts, size(followers) AS num_followers
MATCH (user)-[:POSTED*0..2]->(post:Post {score: 10})
WITH user, followers, total_posts, num_followers, count(post) AS popular_posts
ORDER BY popular_posts DESC
In this query, we create nodes for Alice, Bob, and Charlie, each with a name, profileImage, and description property. We then create relationships between users representing follow relationships. We use Cypher's Path Patterns to find users who follow Alice, Bob, or Charlie, and collect all the nodes in the path. We then find all the posts for each user and their followers, and calculate the total number of posts and followers. We then find all posts with a score of 10 and count them to determine how many popular posts each user has.
Product and Category Catalog
In this example, we'll create a graph to represent a product and category catalog using Cypher. This graph will contain nodes representing products, categories, and relationships representing category-product associations.
Here's the Cypher query:
cypher
CREATE (category1:Category {name: 'Electronics'})
CREATE (category2:Category {name: 'Clothing'})
CREATE (category3:Category {name: 'Food'})
CREATE (product1:Product {name: 'Smartwatch', price: 200, category: category1})
CREATE (product2:Product {name: 'T-Shirt', price: 50, category: category2})
CREATE (product3:Product {name: 'Coffee', price: 15, category: category3})
CREATE (product1)-[:HAS_CATEGORY]->(category1)
CREATE (product2)-[:HAS_CATEGORY]->(category2)
CREATE (product3)-[:HAS_CATEGORY]->(category3)
MATCH (product:Product)
WITH product, collect(DISTINCT category = (product)-[:HAS_CATEGORY]->(:Category)) AS categories
WITH product, reduce(set = [], category in categories | case category.name when 'Electronics' then set | 'Electronics' when 'Clothing' then set | 'Clothing' when 'Food' then set | 'Food' else set end) as categories_list
ORDER BY length(categories_list) DESC
In this query, we create nodes for three categories and three products. Each product node has a name, price, and category property, which is a reference to the