4

集合の交点を見つけるための優れたグラフ データベースを探しています。任意の 2 つのノードを取得し、それらのエッジ エンドポイントが「重複」しているかどうかを調べます。ソーシャル ネットワークのアナロジーは、2 人の人物を見て、それらが同じ人物とつながっているかどうかを確認することです。

交差関数が組み込まれているため、FlockDB (Twitter の人々から) を機能させようとしましたが、ユーザー コミュニティ/サポートに関してはあまり多くないことがわかりました。特に私が探している交差機能の種類がすでに存在する場合、他のグラフデータベースの推奨事項はありますか?

4

2 に答える 2

2

長さ == 2 の 2 つのノード間の最短経路だけではありませんか?

Neo4j では、そのためにGraphAlgoFactoryの shortestPath() Finder を使用できます。

于 2011-05-09T02:25:30.027 に答える
1

これは、接続があるかどうかを示します。

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 クラスを使用して、このクエリを組み込みサーバーに渡すことができます。

于 2011-07-18T21:06:44.957 に答える