如何选择随机节点

如何选择随机节点

本文介绍了neo4j:有没有办法/如何选择随机节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索特定数量的随机节点.该图由 3 000 000 个节点组成,其中一些是源,一些是目标,一些都是.

I would like to retrieve a specific number of random nodes. The graph consists of 3 000 000 nodes where some of them are sources, some are target and some are both.

目的是检索随机源,由于我不知道如何选择随机,程序生成了从 1 到 3 000 000 的 k 个代表节点 ID 的随机数,然后丢弃所有随机选择的不是源的节点.由于这个过程比较耗时,不知道是否可以通过cypher query直接选择随机源.

The aim is to retrieve random sources and as I don't know how to select random, the program generates k random numbers from 1 to 3 000 000 which represent node IDs and then discards all randomly selected nodes that are not sources. As this procedure is time-consuming, I wonder whether it is possible to directly select random sources with cypher query.

如果选择所有来源,查询如下

In case to select all sources, the query would be the following

START t=node(*) MATCH (a)-[:LEADS_TO]->(t) RETURN a

有谁知道如何直接使用密码选择有限数量的随机节点,或者如果不可能,建议任何解决方法?

Does anyone know how would it be possible to select the limited number of random nodes directly with a cypher or, if not possible, suggest any workaround?

推荐答案

您可以使用跳过/限制来限制您的查询,以便您可以这样做

You can limit your query with skip/limit so you could do

START t=node(*)
MATCH (a)-[:LEADS_TO]->(t)
RETURN a
SKIP {randomoffset} LIMIT {randomcount}

否则,您还可以创建一组随机节点 ID,并将它们作为参数传递给 cypher 语句.

Otherwise you can also create a set of random node-id's and pass them as parameter to the cypher statement.

这篇关于neo4j:有没有办法/如何选择随机节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:26