-
Notifications
You must be signed in to change notification settings - Fork 50
/
creat_graph.py
38 lines (30 loc) · 1.07 KB
/
creat_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from getpass import getpass
from camel.storages import Neo4jGraph
from camel.agents import KnowledgeGraphAgent
from camel.loaders import UnstructuredIO
from dataloader import load_high
import argparse
from data_chunk import run_chunk
from utils import *
def creat_metagraph(args, content, gid, n4j):
# Set instance
uio = UnstructuredIO()
kg_agent = KnowledgeGraphAgent()
whole_chunk = content
if args.grained_chunk == True:
content = run_chunk(content)
else:
content = [content]
for cont in content:
element_example = uio.create_element_from_text(text=cont)
ans_str = kg_agent.run(element_example, parse_graph_elements=False)
# print(ans_str)
graph_elements = kg_agent.run(element_example, parse_graph_elements=True)
graph_elements = add_ge_emb(graph_elements)
graph_elements = add_gid(graph_elements, gid)
n4j.add_graph_elements(graph_elements=[graph_elements])
if args.ingraphmerge:
merge_similar_nodes(n4j, gid)
add_sum(n4j, whole_chunk, gid)
return n4j