用于查找交叉点的良好图形数据库(Neo4j?Pegasus?Allegro?...)

发布于 2024-11-06 01:15:31 字数 200 浏览 0 评论 0原文

我正在寻找一个好的图形数据库来查找集合交集 - 取任意两个节点并查看它们的边缘端点是否“重叠”。社交网络类比是两个人观察两个人,看看他们是否连接到同一个人。

我尝试让 FlockDB(来自 Twitter 的人员)正常工作,因为交集函数是内置的,但发现在用户社区/支持方面没有太多。那么其他图形数据库的任何建议,特别是在我正在寻找的交叉功能已经存在的情况下......?

I'm looking for a good graph database for finding set intersections -- taking any two nodes and looking at whether their edge endpoints "overlap." Social network analogy would be two look at two people and see whether they are are connected to the same people.

I've tried to get FlockDB (from the folks at Twitter) working, because intersection functions are built in, but found there wasn't much in terms of user community/support. So any recommendations of other graph databases, especially where the kind of intersection functionality I'm looking for already exists...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原谅过去的我 2024-11-13 01:15:31

这不是两个长度== 2的节点之间的最短路径吗?

在 Neo4j 中,您可以使用 GraphAlgoFactory 中的shortestPath() Finder为此。

Isn't that just the shortest paths between the two nodes with length == 2 ?

In Neo4j you can use the shortestPath() Finder from the GraphAlgoFactory for that.

清风夜微凉 2024-11-13 01:15:31

这会告诉你是否存在联系:

Node from_node = index.get("guid", "user_a").getSingle();
Node to_node = index.get("guid", "user_b").getSingle();
if(from_node != null && to_node != null) {
  RelationshipExpander expander = Traversal.expanderForAllTypes(Direction.BOTH);
  PathFinder<Path> finder = GraphAlgoFactory.shortestPath(expander, 2);
  if(finder.findSinglePath(from_node, to_node) != null) {
    //Connected by at least 1 common friend
  } else {
    //Too far apart or not connected at all
  }
}

这会告诉你谁是共同的朋友:

Node from_node = index.get("guid", "user_a").getSingle();
Node to_node = index.get("guid", "user_b").getSingle();
if(from_node != null && to_node != null) {
  RelationshipExpander expander = Traversal.expanderForAllTypes(Direction.BOTH);
  PathFinder<Path> finder = GraphAlgoFactory.shortestPath(expander, 2);
  Iterable<Path> paths = finder.findAllPaths(from_node, to_node);
  if(paths != null) {
    for(Path path : paths) {
      Relationship relationship = path.relationships().iterator().next();
      Node friend_of_friend = relationship.getEndNode();
    }
  } else {
    //Too far apart or not connected at all
  }
}

这段代码有点粗糙,用 Cypher 更容易表达(取自 Neo4J Server 控制台中的 Cheet Sheet(这是一种很好的方法)填充数据库后使用 Neo4J):

START a = (user, name, "user_a")
MATCH (a)-[:FRIEND]->(friend)-[:FRIEND]->(friend_of_friend)
RETURN friend_of_friend

这将为您提供在其他断开连接的节点之间共享的节点列表,您可以通过 CypherParser 类将此查询传递给嵌入式服务器。

This would tell you if there is a connection:

Node from_node = index.get("guid", "user_a").getSingle();
Node to_node = index.get("guid", "user_b").getSingle();
if(from_node != null && to_node != null) {
  RelationshipExpander expander = Traversal.expanderForAllTypes(Direction.BOTH);
  PathFinder<Path> finder = GraphAlgoFactory.shortestPath(expander, 2);
  if(finder.findSinglePath(from_node, to_node) != null) {
    //Connected by at least 1 common friend
  } else {
    //Too far apart or not connected at all
  }
}

This would tell you who are the common friends are:

Node from_node = index.get("guid", "user_a").getSingle();
Node to_node = index.get("guid", "user_b").getSingle();
if(from_node != null && to_node != null) {
  RelationshipExpander expander = Traversal.expanderForAllTypes(Direction.BOTH);
  PathFinder<Path> finder = GraphAlgoFactory.shortestPath(expander, 2);
  Iterable<Path> paths = finder.findAllPaths(from_node, to_node);
  if(paths != null) {
    for(Path path : paths) {
      Relationship relationship = path.relationships().iterator().next();
      Node friend_of_friend = relationship.getEndNode();
    }
  } else {
    //Too far apart or not connected at all
  }
}

This code is a little rough and is much easier to express in Cypher (taken from the Cheet Sheet in the Neo4J Server console (great way to play with Neo4J after you populate a database):

START a = (user, name, "user_a")
MATCH (a)-[:FRIEND]->(friend)-[:FRIEND]->(friend_of_friend)
RETURN friend_of_friend

This will give you a list of the nodes shared between to otherwise disconnected nodes. You can pass this query to an embedded server thought the CypherParser class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文