2011-05-06 3 views
4

두 세트의 노드를 가져 와서 해당 에지 종점이 "겹치는 지 여부"를 확인하는 좋은 그래프 데이터베이스를 찾고 있습니다. 소셜 네트워크 유추는 두 사람을 두 번 봐서 그들이 같은 사람과 연결되어 있는지 확인합니다.교차점을 찾기위한 좋은 그래프 데이터베이스 (Neo4j? Pegasus? Allegro? ...)

교차 기능이 내장되어 있기 때문에 FlockDB (Twitter의 사람들로부터)를 얻으려고했지만 사용자 커뮤니티/지원과 관련하여 많은 부분이 발견되지 않았습니다. 따라서 다른 그래프 데이터베이스의 권장 사항, 특히 내가 찾고있는 교차 기능의 종류가 이미 존재하는 경우 ...?

+0

당신은 GraphDB 기반 답변 이후라고 가정하고 있지만이 종류의 교차 설정은 관계형 DB가 지향하는 것입니다 (예 : 집합 기반 계산) – cdeszaq

답변

2

길이 == 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 
    } 
} 

이 코드는 약간 거친이며, 훨씬 쉽게 연결이있는 경우

1

이 당신에게 말할 것이다 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 클래스를 고려한 임베디드 서버에 전달할 수 있습니다.

관련 문제