当前位置:网站首页>neo4j实现社交推荐(四)
neo4j实现社交推荐(四)
2022-06-09 08:52:00 【余生大大】
目录
前言
在前三篇中我们基础学会了怎么创建标签节点以及关联关系及设置属性的操作,本篇我们实际模拟我们的社交软件中的好友推荐、共同关注等的功能实现。
我们在实现前先考虑一下好友的关系及节点属性,人物之间存在好友关系,关系上带有关系类型及建立时间等属性
实现
创建节点
先创建几个社交用户标签的节点
create (n:SocialUser {
name:'李白'}) return n;
create (n:SocialUser {
name:'汪伦'}) return n;
create (n:SocialUser {
name:'孟浩然'}) return n;
create (n:SocialUser {
name:'杜甫'}) return n;
create (n:SocialUser {
name:'王昌龄'}) return n;
create (n:SocialUser {
name:'贺知章'}) return n;
create (n:SocialUser {
name:'高适'}) return n;
create (n:SocialUser {
name:'李阳冰'}) return n;
create (n:SocialUser {
name:'元丹丘'}) return n;
create (n:SocialUser {
name:'孔巢父'}) return n;
create (n:SocialUser {
name:'崔成甫'}) return n;
上面的都是李白的好友,所以我们指向关系不需要筛选,直接指向标签
match (a:SocialUser {
name:'李白'}),(b:SocialUser)
where b.name <> '李白' merge (a)-[:FRIEND]->(b)
return a,b
查看结果
接下来创建杜甫的好友,像李白、高适这些已经有的就不需要创建了
create (n:SocialUser {
name:'王维'}) return n;
create (n:SocialUser {
name:'严武'}) return n;
建立杜甫的好友关系
match (a:SocialUser {
name:'杜甫'}),(b:SocialUser {
name:'李白'}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
name:'杜甫'}),(b:SocialUser {
name:'高适'}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
name:'杜甫'}),(b:SocialUser {
name:'王维'}) merge (a)-[:FRIEND]->(b);
match (a:SocialUser {
name:'杜甫'}),(b:SocialUser {
name:'严武'}) merge (a)-[:FRIEND]->(b);

从图谱中可以看到高适是李白跟杜甫的共同好友,如果现在加入了一个我的元素,我同时认识李白跟杜甫,那么可以从李白跟杜甫共同关注的人中找到我可能认识的人。
但是在正式的具体的分析过程中还要加入地域、公司、性别、喜好等属性来加强推荐人的准确性。
边栏推荐
- Will testing not be replaced by development?
- Energy management and control system for industrial enterprises helps enterprises strengthen energy management and improve equipment operation efficiency
- How to use alicloud CDN to cache static websites deployed on function computing
- [redis learning 11] data persistence of distributed cache, master-slave cluster
- C指针复习
- 选择器误区
- [texstudio] [2] general picture and table presentation
- 安科瑞配电室综合监控系统实现配电室内环境的在线监测,保障配电室设备的安全运行
- [redis learning 12] sentry mechanism of distributed cache, partitioned cluster
- 2022-2028 global UAV detection and jamming system industry survey and trend analysis report
猜你喜欢
![[redis learning 13] redis builds master-slave cluster, sentinel cluster and partition cluster](/img/e9/c0911d31dc348e1f1f9c67935ce923.png)
[redis learning 13] redis builds master-slave cluster, sentinel cluster and partition cluster

Do you want to explore MySQL not in indexing?

深度解析:二十五岁做软件测试前景怎么样?

微信小程序--嘟嘟会议--会议发布和我的会议查看

Web knowledge points 123
![Esp32 learning notes [WiFi network] - 01ap & sta](/img/04/de14412d6244ec120c587d98f103aa.png)
Esp32 learning notes [WiFi network] - 01ap & sta

MySQL基础 基础认知

【Redis学习12】分布式缓存之哨兵机制,分片集群

附十七章 网络程序解读限定文章

MySQL基础 查询语句
随机推荐
Oracle locally managed tablespaces
MySQL基础 查询语句
The integrated monitoring system of ankerui distribution room realizes the online monitoring of the environment in the distribution room and ensures the safe operation of the equipment in the distribu
Remote prepayment management system helps property management solve the problem of difficult charging and statistics
10 useful flutter widgets
In depth analysis: what is the prospect of doing software testing at the age of 25?
Editor description - alternate
Business judgment logic code if statement
微信小程序开发之菜单的创建
Update and delete operations in Clickhouse of data warehouse series
Document sorting (expansion)
MySQL基础 子查询
JS window object
Qt development -- compilation of serial port assistant
Esp32 learning notes [WiFi network] - 01ap & sta
根据投影坐标裁剪影像中的目标区域(附有完整代码)
安科瑞企业微电网能效管理平台推动电网向能源互联网升级
Direct application of 10 kinds of question type explosive text title sentence patterns
FreeRtos信号量复习
MySQL uses while to batch insert data in stored procedures (performance difference between batch submission and single submission)