Same Community

Supported Graph Characteristics

Unweighted edges

Directed edges

Undirected edges

Homogeneous vertex types

Heterogeneous vertex types

Algorithm link: Same Community

The Same Community algorithm is a simple boolean algorithm to check whether two vertices share the same community labeling.

This algorithm takes two vertices as input, returning 1 if the two vertices are in the same community, and returning 0 if they are not in the same community.

Notes

The algorithm assumes that a community ID is stored in an integer attribute on each vertex. For this to happen, usually a Community Detection algorithm is run to create such community IDs.

This algorithm ignores edge weights.

Specifications

CREATE QUERY tg_same_community(VERTEX v_source VERTEX v_target, STRING
    communityAttribute)

Parameters

Name Description Default value

VERTEX v_source

The first vertex to compare.

N/A

VERTEX v_target

The second vertex to compare with the first.

N/A

STRING communityAttribute

The vertex attribute used to store a vertex’s community ID.

(A blank string)

Output

  • Returns 1 if the two vertices are in the same community.

  • Returns 0 if the two vertices are not in the same community.

Time complexity

The algorithm has a time complexity of \$O(1)\$.

Example

Suppose we have the following vertices:

same community ex

Their community IDs were generated by running the Weakly Connected Components algorithm on the graph. If we run the algorithm between Kevin and Jenny, we get 1 because the two vertices are in the same community as indicated by their community attribute:

  • Query

  • Result

RUN QUERY tg_same_community (("Jenny", "person"), ("Kevin", "person"), "community")
{
  "error": false,
  "message": "",
  "version": {
    "schema": 2,
    "edition": "enterprise",
    "api": "v2"
  },
  "results": [{"1": 1}]
}