wey-gu / NebulaGraph-NX

Manipulation of graphs in NebulaGraph using the NetworkX API.
Apache License 2.0
3 stars 0 forks source link

Why does NebulaGraph-NX only read edge information, when the input should be a graph? #5

Open jiagh2010 opened 4 months ago

jiagh2010 commented 4 months ago

Why does NebulaGraph-nx only read edge information, when the input should be a graph?】

config = NebulaGraphConfig(
    space="basketballplayer",
    graphd_hosts="127.0.0.1:9669",
    metad_hosts="127.0.0.1:9559",
    user = "root",
    password = "nebula"
)

reader = NebulaReader(
    edges=["follow", "serve"],
    properties=[["degree"], ["start_year", "end_year"]],
    nebula_config=config, limit=10000)

g = reader.read()

pr = nx.pagerank(
    g, alpha=0.85,
    max_iter=100,
    tol=1e-06,
    weight='degree')
print(pr)
wey-gu commented 3 weeks ago

@jiagh2010 I added a NebulaQueryReader for such use cases, please give a try :)

NebulaReader is for scan whole graph of data while NebulaQueryReader is for construct any query into nx object

from ng_nx import NebulaQueryReader
from ng_nx.utils import NebulaGraphConfig

config = NebulaGraphConfig(
    space="demo_basketballplayer",
    graphd_hosts="127.0.0.1:9669",
    metad_hosts="127.0.0.1:9559"
)

reader = NebulaQueryReader(nebula_config=config)

# Execute a custom query
query = "MATCH p=(v:player{name:'Tim Duncan'})-[e:follow*1..3]->(v2) RETURN p"
g = reader.read(query)

close via #7