neo4j构建算法
Building on top of our previous guide on Neo4j, we are going to make full use of our knowledge and build a restaurant recommender system today. Make sure that you have a working version of Neo4j. If you are new to Neo4j, it is highly recommended to go through the following guide on The Beginner’s Guide to the Neo4j Graph Platform before you continue. At the end of the day, you should have a working web application that returns the recommended restaurants based on your input.
在以前的Neo4j指南的基础上,我们将充分利用我们的知识,并在今天建立一个餐厅推荐系统。 确保您具有Neo4j的工作版本。 如果您不熟悉Neo4j,则强烈建议您先阅读Neo4j Graph平台初学者指南中的以下指南。 在一天结束时,您应该有一个可运行的Web应用程序,该应用程序根据您的输入返回推荐的餐厅。
1.设定 (1. Setup)
Neo4j (Neo4j)
I am using Neo4j community version 4.1.1 for this tutorial. Open up a terminal and change the directory to the root folder of Neo4j. Since the root folder resides in my C drive, my working directory is as follows:
我在本教程中使用Neo4j社区版本4.1.1。 打开终端,将目录更改为Neo4j的根文件夹。 由于根文件夹位于我的C驱动器中,因此我的工作目录如下:
C:\neo4j-community-4.1.1
Change the directory into the bin folder by running the following command:
通过运行以下命令将目录更改为bin文件夹:
cd bin
Now, you can start Neo4j either as a console application or background service. For a console application, run the following command:
现在,您可以将Neo4j作为控制台应用程序或后台服务启动。 对于控制台应用程序,运行以下命令:
neo4j console
Use the following command for starting it as a background service:
使用以下命令将其作为后台服务启动:
neo4j start
You should see the following output at your console, indicating that the process has started:
您应该在控制台上看到以下输出,指示该过程已经开始:

Open up a browser and go to the following URL:
打开浏览器,然后转到以下URL:
http://localhost:7474
It will redirect you to:
它将重定向到:
http://localhost:7474/browser/
You should see the following webpage, which is the Neo4j Browser Console:
您应该看到以下网页,即Neo4j浏览器控制台:

Connect to the database using your own username and password. If you are accessing it for the first time, the credentials are as follows:
使用您自己的用户名和密码连接到数据库。 如果您是首次访问它,则凭据如下:
username
— neo4jusername
— neo4jpassword
— neo4jpassword
— neo4j
After that, you will be prompted to change the password. Once you have logged in to the database, you should see the following user interface:
之后,将提示您更改密码。 登录数据库后,应该会看到以下用户界面:

司机 (Driver)
Neo4j also comes with support for connecting to its database directly via drivers. Based on the latest version, it officially supports the following programming languages:
Neo4j还支持直接通过驱动程序连接到其数据库。 基于最新版本,它正式支持以下编程语言:
.NET
— .NET Standard 2.0.NET
— .NET Standard 2.0Java
—Java 8+ (latest patch releases).Java
Java 8+(最新修补程序版本)。JavaScript
— All LTS versions of Node.JS, specifically the 4.x and 6.x series runtime(s).Python
— CPython 3.5 and above.Python
-CPython 3.5及更高版本。Go
— Work in progress. There is no official release date at the moment.Go
-进行中。 目前没有官方发布日期。
In this tutorial, I am going to use a Python driver for our web application in FastAPI. Kindly check out the following link for more information on the installation steps for the rest of the drivers.
在本教程中,我将为FastAPI中的Web应用程序使用Python驱动程序。 请查看以下链接 ,以获取有关其余驱动程序的安装步骤的更多信息。
It is highly recommended that you create a virtual environment before the installation. Activate your virtual environment and run the following command to install the stable version of Neo4j Python Driver.
强烈建议您在安装之前创建一个虚拟环境。 激活您的虚拟环境并运行以下命令以安装Neo4j Python Driver的稳定版本。
pip install neo4j
If you are looking for the pre-release version, you should run the following command instead:
如果要查找预发行版本,则应改为运行以下命令:
pip install --pre neo4j
FastAPI (FastAPI)
As I have mentioned earlier, our web application is based on FastAPI. Feel free to modify it on your own if you are a Flask user, as you can always migrate it later on. Have a look at my previous article on Migrate Flask to FastAPI Smoothly to find out more about it. In the same terminal, run the following command:
如前所述,我们的Web应用程序基于FastAPI。 如果您是Flask用户,则可以随意对其进行修改,因为您以后可以随时进行迁移。 请参阅我以前的有关平稳地将Flask迁移到FastAPI的文章,以了解更多信息。 在同一终端上,运行以下命令:
pip install fastapi
You will need an ASGI
server as well. The recommended ASGI
server is Uvicorn
. Install it as follows:
您还将需要一台ASGI
服务器。 推荐的ASGI
服务器是Uvicorn
。 如下安装:
pip install uvicorn
用例(人员) (Use Case (Person))
Let’s list down the nodes and relationships in order to model our domain as a graph. To keep things simple and short, let’s say our main character is called Alice and she has a group of friends as follows:
让我们列出节点和关系,以便将我们的域建模为图形。 为简单起见,假设我们的主角叫爱丽丝,她有一群朋友,如下所示:
- Judy 朱迪
- Sayaka 沙耶香
- Kim Lee