kg_topology_toolbox.utils.node_degrees_and_rels

kg_topology_toolbox.utils.node_degrees_and_rels(df, column, n_entity, return_relation_list)[source]

Aggregate edges by head/tail node and compute associated statistics.

Parameters:
  • df (DataFrame) – Dataframe of (h,r,t) triples.

  • column (str) – Name of the column used to aggregate edges.

  • n_entity (int) – Total number of entities in the graph.

  • return_relation_list (bool) – If True, return the list of unique relations types in the set of aggregated edges.

Return type:

DataFrame

Returns:

The result DataFrame, indexed on the IDs of the graph entities, with columns:

  • degree (int): Number of triples in the aggregation.

  • unique_rel (int): Number of distinct relation types

    in the set of aggregated edges.

  • rel_list (Optional[list]): List of unique relation types

    in the set of aggregated edges. Only returned if return_relation_list = True.