当前位置:网站首页>Example explanation: move graph explorer to jupyterlab
Example explanation: move graph explorer to jupyterlab
2022-07-01 19:45:00 【Huawei cloud developer Alliance】
Abstract : be based on Graph Explorer stay Jupyter Explore the map on , It can greatly reduce the coding cost , Enrich JupyterLab Data expressiveness .
This article is shared from Huawei cloud community 《 take Graph Explorer Move on JupyterLab: Use GES4Jupyter Connect GES And explore the map 》, author : Mayfly and sea .
GES4Jupyter It can be used in JupyterLab Connect to access GES And visual tools . Part of the tool is encapsulated GES Business interface , And provide visualization of the returned data . Based on the tool in Jupyter Explore the map on , It can greatly reduce the coding cost , Enrich JupyterLab Data expressiveness .
One 、 Prepare before use
1. Huawei cloud account
You need to register a Huawei cloud account before using Huawei cloud services . Through this account , Just pay for the services you use , You can use all Huawei cloud services .
To register a Huawei cloud account, click :《 Introduction to Huawei cloud registration 》
After successful registration, you can automatically log in to Huawei cloud , You need to complete “ Real name authentication ” The service can be used normally .
2. OBS Object storage service
OBS Object storage service (Object Storage Service),GES take OBS Import data as a data source .
If you want to import data into the graph engine service GES, You need to upload to OBS. Details refer to : Huawei cloud engine service GES actual combat —— Map creation
3. GES Figure Engine Services
Use GES4Jupyter front , You need to create one in the graph engine service console GES Figure example , And import data . The data source used in this example is the covid-19 patient tracking data set v2, It can be downloaded from AI Gallery Download . Details refer to : Huawei graphics engine documentation - Quick start and Huawei cloud image engine service GES actual combat —— Map creation
4. Get call GES Business API Required parameters
call GES API Need to enter token Authentication information , The authentication capability relies on the Huawei cloud unified identity authentication service IAM. obtain Token User name and password required 、 Information such as the area where the map is located . View details : Huawei graphics engine documentation - Business API Authentication and call GES Service business API Acquisition of relevant parameters
Two 、 Use GES4Jupyter Connect GES service
Enter from the Huawei cloud homepage ModelArts Console , Click on CodeLab Create a new one Jupyter Notebook, And wait for resource initialization .
Create a new one Notebook, Use the following code to get GES4Jupyter Program and resource files .
import moxing as mox
mox.file.copy('obs://obs-aigallery-zc/GES/ges4jupyter/beta/ges4jupyter.py', 'ges4jupyter.py')
mox.file.copy('obs://obs-aigallery-zc/GES/ges4jupyter/beta/ges4jupyter.html', 'ges4jupyter.html')
stay Notebook After entering the code in , Configure this text as code , Then click the run button on the left , And wait for the run to complete .
Click on the top left “+” No. new code snippet , Enter the following code snippet and run , complete GES4Jupyter The initialization .
from ges4jupyter import GESConfig, GES4Jupyter, read_csv_config
eip = ''
project_id = ''
graph_name = ''
iam_url = ''
user_name = ''
password = ''
domain_name = ''
project_name = ''
port = 80
eip, project_id, graph_name, iam_url, user_name, password, domain_name, project_name, port = read_csv_config('cn_north_4_graph.csv')
config = GESConfig(eip, project_id, graph_name,
iam_url = iam_url,
user_name = user_name,
password = password,
domain_name = domain_name,
project_name = project_name,
port = port)
ges_util = GES4Jupyter(config, True);
The meanings of the fields involved in the above code are basically divided into two categories , A brief introduction :
- Is used to construct API Parameters of :eip,projectId,graph_name, port These four parameters are involved in the construction of the business face request url.eip And graph_name The two parameters are easy to obtain in drawing creation ,port The parameter defaults to 80, When safe mode is turned on, it is 443, About projectId, Refer to the official website of the graph engine - Get the project id, Get items from the graph console according to the region to which the graph belongs id.
- Used when requesting API Pre acquisition token Parameters of :iam_url, user_name, password, domain_name,project_name,GES4Jupyter These four parameters will be used to get token, And then in use api To authenticate , For relevant parameters, please refer to : Huawei graphics engine documentation - Business API Authentication and call GES Service business API Acquisition of relevant parameters
In addition to manually entering these parameters , You can also construct a parameter as csv Upload the file to CodeLab platform , Then execute the diagram read_csv_config Method , One click access to all parameters .
As shown in the figure, it is an example file of a figure with Beijing IV area , The key information ( Such as ip、projectId、 Title 、 Account name 、 password 、iam Sub account name ) Hidden by mosaics .
For the newly created graph , Use the following code snippet to create a point edge index , Easy to use cypher:
print(' Start creating point index :')
job_id = ges_util.build_vertex_index()
job_result = ges_util.get_job(job_id)
if 'errorCode' not in job_result:
for i in range(100):
if job_result['status'] == 'success':
break
else:
time.sleep(1)
job_result = ges_util.get_job(job_id)
print(' Point index creation completed ')
print(' Start creating edge index :')
job_id = ges_util.build_edge_index()
job_result = ges_util.get_job(job_id)
if 'errorCode' not in job_result:
for i in range(100):
if job_result['status'] == 'success':
break
else:
time.sleep(1)
job_result = ges_util.get_job(job_id)
print(' Edge index creation completed ')
If it's bigger , And not based on label The demands of filtering , You can also turn off cypher Index switch of .
ges_util.cypher_query("call dbms.parameter('needNodeIndex', false)");
ges_util.cypher_query("call dbms.parameter('needEdgeIndex', false)");
perform summary Method to see the point edge distribution :

3、 ... and 、 Use GES4Jupyter Call the business interface and visualize it
GES4Jupyter Support calling cypher sentence , And visualize cypher Result . After initialization is complete GES4Jupyter after , Use the following code to execute and visualize cypher Inquire about :
cypher_result = ges_util.cypher_query("match (n)-[r]->(m) return n,r,m limit 10",formats=['row','graph']);
ges_util.format_cypher_result(cypher_result)
stay Notebook Enter this code in , Click on the run , You can see Notebook Medium effect :

meanwhile , The tool also provides additional tabs , Not only can you see the visualization Graph structure , You can also see the table data 、 And the original json data .

GES4Jupyter It also provides the ability to gremlin The point and edge data returned by the language are visualized .
gremlin_result = ges_util.gremlin_query("g.V().outE().bothV().path().limit(2)");
ges_util.format_gremlin_result(gremlin_result)

meanwhile , about ges Of path-query Interface , When the returned data is tree When the format ,GES4Jupyter Can also provide better support .
result = ges_util.path_query({
"repeat": [
{
"operator": "bothV",
"vertex_filter": {
"property_filter": {
"leftvalue": {
"id": ""
},
"predicate": "NOTIN",
"rightvalue": {
"value": [" Beijing "]
}
}
}
}
],
"until": [
{
"vertex_filter": {
"property_filter": {
"leftvalue": {
"id": ""
},
"predicate": "=",
"rightvalue": {
"value": [" mesozoic-cenozoic "]
}
}
}
}
],
"times": 5,
"queryType": "Tree",
"vertices": [" Beijing case 2"]
})
ges_util.format_path_query(result)

Four 、 There are more cases available on the official website of the graph engine GES4Jupyter Hands on experience
The data set of this article is taken from the official website of Huawei cloud image engine “ Trace of new crown patients ” Data sets ,notebook The code is taken from “ Trace of new crown patients ” Case study , On the official website of graph engine , There are other hands-on practices , Matching ModelArts Of CodeLab, Can achieve “ Open the box ”, Provide a wealth of scenes to get to know the map with you 、 Understanding diagram 、 Use the figure .

Reference items :https://github.com/merqurio/neo4jupyter
Click to follow , The first time to learn about Huawei's new cloud technology ~
边栏推荐
- Introduction and installation of crunch, and making password dictionary with crunch
- 解决VSCode下载慢或下载失败的问题
- Opencv video quality detection -- sharpness detection
- ddr4测试-2
- Cookie和Session的相关概念
- 新增订单如何防止重复提交
- Actual combat of flutter - fast implementation of audio and video call application
- 【无标题】
- Live HLS protocol
- js三元表达式复杂条件判断
猜你喜欢
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
How to use console Log print text?
uni-app微信小程序一键登录获取权限功能
P2433 【深基1-2】小学数学 N 合一
Uni app product classification
Why must we move from Devops to bizdevops?
Oracle physical architecture
Regular expression =regex=regular expression
Crunch简介、安装,使用Crunch制作密码字典
Uni app wechat applet one click login to obtain permission function
随机推荐
IPv4地址、子网掩码、网关
类加载机制
简版拼多多商品数据
GC garbage collection
Botu V16 obtains the system time and converts it into a string
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
微信小程序 navigator点击后有阴影 ,去掉navigator阴影效果
Live HLS protocol
servlet知识点
面试题 16.16. 部分排序-双指针法
HLS4ML进入方法
axure不显示元件库
Wechat applet realizes keyword highlighting
Interview question 16.16 Partial sorting - Double finger needling
uni-app商品分类
【无标题】
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
ModSim基本使用(Modbus模拟器)
2022/6/8-2022/6/12
After studying 11 kinds of real-time chat software, I found that they all have these functions