当前位置:网站首页>实例讲解将Graph Explorer搬上JupyterLab
实例讲解将Graph Explorer搬上JupyterLab
2022-07-01 18:38:00 【InfoQ】

一、使用前准备
1. 华为云账号
2. OBS 对象存储服务
3. GES 图引擎服务
4. 获取调用 GES 业务面 API 必备的参数
二、使用 GES4Jupyter 连接 GES 服务

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')

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);
- 用于构造 API 的参数:eip,projectId,graph_name, port 这四个参数都参与构造了业务面请求的 url。eip 与 graph_name 两个参数在创图时容易获得,port 参数默认为 80,开启安全模式时为 443,关于 projectId,可参考图引擎官网文档 - 获取项目 id,从图控制台根据图所属的区域来获取项目 id。
- 用于在请求 API 前获取 token 的参数:iam_url, user_name, password, domain_name,project_name,GES4Jupyter 会使用这四个参数获取 token,进而在使用 api 时进行鉴权,相关参数获取请参考:华为图引擎文档 - 业务面 API 认证鉴权和调用 GES 服务业务面 API 相关参数的获取

print('开始创建点索引:')
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('点索引创建完成')
print('开始创建边索引:')
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('边索引创建完成')
ges_util.cypher_query("call dbms.parameter('needNodeIndex', false)");
ges_util.cypher_query("call dbms.parameter('needEdgeIndex', false)");

三、使用 GES4Jupyter 调用业务面接口并进行可视化
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)


gremlin_result = ges_util.gremlin_query("g.V().outE().bothV().path().limit(2)");
ges_util.format_gremlin_result(gremlin_result)

result = ges_util.path_query({
"repeat": [
{
"operator": "bothV",
"vertex_filter": {
"property_filter": {
"leftvalue": {
"id": ""
},
"predicate": "NOTIN",
"rightvalue": {
"value": ["北京"]
}
}
}
}
],
"until": [
{
"vertex_filter": {
"property_filter": {
"leftvalue": {
"id": ""
},
"predicate": "=",
"rightvalue": {
"value": ["额济纳旗"]
}
}
}
}
],
"times": 5,
"queryType": "Tree",
"vertices": ["北京病例2"]
})
ges_util.format_path_query(result)

四、图引擎官网有更多案例可以使用 GES4Jupyter 上手体验

边栏推荐
- R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
- Lumiprobe Lumizol RNA 提取试剂解决方案
- [CF559E]Gerald and Path
- Image acquisition and playback of coaxpress high speed camera based on pxie interface
- Reading notes series "modern methods of C language programming" -- Chapter 2
- 因子分析怎么计算权重?
- 12种数据量纲化处理方式
- 研究了11种实时聊天软件,我发现都具备这些功能…
- Regular expression
- Leetcode203 移除链表元素
猜你喜欢
Principal component calculation weight
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Privacy sandbox is finally coming
Basic concepts of binary tree
Leetcode-21 combines two ordered linked lists
解决方案:可以ping别人,但是别人不能ping我
Bernoulli distribution (a discrete distribution)
Find all missing numbers in the array
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
Blue Bridge Cup real topic: the shortest circuit
随机推荐
每周推薦短視頻:警惕“現象”與“問題”相互混淆
R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息
code
Li Kou daily question - Day 32 -589 N × Preorder traversal of tree
Blue Bridge Cup real topic: the shortest circuit
[CF559E]Gerald and Path
Lumiprobe biomolecular quantification - qudye Protein Quantification Kit
Blue Bridge Cup real question: score statistics
Operating system interview assault
Operation of cmake under win
Static timing analysis (STA) in ic/fpga design
Reading notes series "modern methods of C language programming" -- Chapter 2
Roll out! Enlightenment!
关于企业中台规划和 IT 架构微服务转型
Rust language - cargo, crates io
Livedata postvalue will "lose" data
The R language cartools package divides the data, the scale function scales the data, the KNN function of the class package constructs the k-nearest neighbor classifier, and the table function calcula
Sum of three numbers
Relational database management system of easyclick
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder