当前位置:网站首页>Neo4j realizes social recommendation (4)

Neo4j realizes social recommendation (4)

2022-06-09 09:29:00 Great for the rest of my life

Catalog

Preface

In the first three chapters, we learned how to Create a label node as well as Connections And Set properties The operation of , In this article, we actually simulate... In our social software Friend recommendation 、 Pay close attention to And so on .

Let's consider the relationship of friends and node attributes before implementation , There are good friends between the characters , The relationship has attributes such as relationship type and establishment time

Realization

Create nodes

First create a few nodes for social user tags

create (n:SocialUser {
    name:' Li Bai '}) return n;
create (n:SocialUser {
    name:' Wang Lun '}) return n;
create (n:SocialUser {
    name:' meng haoran '}) return n;
create (n:SocialUser {
    name:' Du Fu '}) return n;
create (n:SocialUser {
    name:' wang changling '}) return n;
create (n:SocialUser {
    name:' he zhizhang '}) return n;
create (n:SocialUser {
    name:' Gao Shi '}) return n;
create (n:SocialUser {
    name:' Li Yangbing '}) return n;
create (n:SocialUser {
    name:' Yuan Danqiu '}) return n;
create (n:SocialUser {
    name:' Kong Chaofu '}) return n;
create (n:SocialUser {
    name:' Cuichengfu '}) return n;

The above are all Li Bai's friends , So we don't need to filter the pointing relationship , Point directly to the label

match (a:SocialUser {
    name:' Li Bai '}),(b:SocialUser) 
    where b.name <> ' Li Bai ' merge (a)-[:FRIEND]->(b) 
    	return a,b

View results
 Insert picture description here

Next, create Dufu's friend , Like Li Bai 、 There is no need to create Gaoshi

create (n:SocialUser {
    name:' Wang wei '}) return n;
create (n:SocialUser {
    name:' Yan Wu '}) return n;

Establish a good friend relationship with Dufu

match (a:SocialUser {
    name:' Du Fu '}),(b:SocialUser {
    name:' Li Bai '}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
    name:' Du Fu '}),(b:SocialUser {
    name:' Gao Shi '}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
    name:' Du Fu '}),(b:SocialUser {
    name:' Wang wei '}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
    name:' Du Fu '}),(b:SocialUser {
    name:' Yan Wu '}) merge (a)-[:FRIEND]->(b);

 Insert picture description here
It can be seen from the manual that Gao Shi is a mutual friend of Li Bai and Dufu , If you add an element of me now , I know Li Bai and Dufu at the same time , Li Bai and Dufu Pay close attention to Among the people who found People I may know .
But in the process of formal and specific analysis, regions should be added 、 company 、 Gender 、 Preferences and other attributes to enhance the accuracy of the recommender .

原网站

版权声明
本文为[Great for the rest of my life]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206090851581382.html