当前位置:网站首页>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 ~
边栏推荐
- 自定义插入页面标签以及实现类似通讯录的首字母搜索
- Difference between redo and undo
- ddr4测试-2
- uni-app微信小程序一键登录获取权限功能
- 采集抖音视频
- JS ternary expression complex condition judgment
- Interview questions for audio and video positions in Dachang -- today's headline
- Audio and video, encoding and decoding related e-books, gadgets, packaged for free!
- PowerDesigner设计Name和Comment 替换
- 宝,运维100+服务器很头疼怎么办?用行云管家!
猜你喜欢
GC垃圾回收
JVM memory model
类加载机制
Crunch简介、安装,使用Crunch制作密码字典
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
How to use console Log print text?
P2433 [deep foundation 1-2] primary school mathematics n in one
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
Shell高级进阶
MySQl的基本使用
随机推荐
DDR4 test-2
Collation of open source protocols of open source frameworks commonly used in Web Development
Object creation
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
torch. nn. functional. Interpolate function
ffmpeg 错误码
Regular expression =regex=regular expression
较真儿学源码系列-InheritableThreadLocal(逐行源码带你分析作者思路)
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
P2433 【深基1-2】小学数学 N 合一
Shell advanced
对象的创建
Axure does not display catalogs
Uni app wechat applet one click login to obtain permission function
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
Brpc understanding
一文读懂C语言中的结构体
118. 杨辉三角
【AI服务器搭建】CUDA环境