加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
十指紧扣 提交于 2023-05-19 11:25 . init
import json
def get_option(ents,triples):
nodes = set()
for ent in ents:
nodes.add(ent)
triple_dict = {}
for triple in triples:
ht = triple[0],triple[2]
if ht not in triple_dict:
triple_dict[ht] = []
triple_dict[ht].append(triple[1])
nodes.add(triple[0])
nodes.add(triple[2])
with open('option.json','r',encoding='utf-8') as f:
option = json.load(f)
for node in nodes:
option['series'][0]['data'].append({'name':node})
for (head,tail) in triple_dict:
if head > tail:
curveness = 0.2
else:
curveness = -0.2
if '反向' in triple_dict[(head,tail)] or \
'实体-病历共现' in triple_dict[(head,tail)] or \
'疾病->逻辑症状' in triple_dict[(head,tail)] or \
'其他节点->病历' in triple_dict[(head,tail)]:
continue
option['series'][0]['links'].append(
{
"source": head,
"target": tail,
"symbolSize": [
5,
20
],
"label": {
# "show": True,
"formatter": '/'.join(triple_dict[(head,tail)])
},
"lineStyle": {
"width": 5,
"curveness": curveness
}
}
)
return option
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化