我正在寻找一个好的图数据库来查找集合交集 - 采用任意两个节点并查看它们的边缘端点是否“重叠”。社会网络比喻将两个人看两个人,看他们是否连接到同一个人。查找交叉点的好图数据库(Neo4j?Pegasus?Allegro?...)
我试图让FlockDB(来自Twitter上的人)工作,因为内置了交集函数,但发现用户社区/支持方面没有太多。因此,其他图形数据库的任何建议,尤其是在我正在寻找的相交功能类型中,是否已经存在......?
我正在寻找一个好的图数据库来查找集合交集 - 采用任意两个节点并查看它们的边缘端点是否“重叠”。社会网络比喻将两个人看两个人,看他们是否连接到同一个人。查找交叉点的好图数据库(Neo4j?Pegasus?Allegro?...)
我试图让FlockDB(来自Twitter上的人)工作,因为内置了交集函数,但发现用户社区/支持方面没有太多。因此,其他图形数据库的任何建议,尤其是在我正在寻找的相交功能类型中,是否已经存在......?
这不就是长度== 2的两个节点之间的最短路径吗?
在Neo4j中,您可以使用GraphAlgoFactory的shortestPath()Finder。
这会告诉你,如果有一个连接:
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服务器控制台的Cheet Sheet中取得(在您填充数据库后用Neo4J玩的好方法):
START a = (user, name, "user_a")
MATCH (a)-[:FRIEND]->(friend)-[:FRIEND]->(friend_of_friend)
RETURN friend_of_friend
这会给你一个在另外断开的节点之间共享的节点列表。您可以将此查询传递给一个嵌入式服务器,该服务器被认为是CypherParser类。
我假设你只是在基于GraphDB的答案之后,但这种Set交集恰恰是关系数据库所面向的东西(即基于集合的计算) – cdeszaq 2012-10-02 19:19:16