<commit_before>"""
Ego graph.

"""
#    Copyright (C) 2010 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.
__author__ = """\n""".join(['<NAME> <<EMAIL>>',
                            '<NAME> <<EMAIL>>'])
__all__ = ['ego_graph']

def ego_graph(G,n,center=True):
    """Returns induced subgraph of neighbors centered at node n. 
    
    Parameters
    ----------
    G : graph
      A NetworkX Graph or DiGraph

    n : node 
      A single node 

    center : bool, optional
      If False, do not include center node in graph 

    """
    nodes=set([n])  # add center node
    nodes.update(G.neighbors(n)) # extend with neighbors
    H=G.subgraph(nodes)
    if not center:
        H.remove_node(n)
    return  H<commit_msg>Add option to build ego graph with specified radius<commit_after>"""
Ego graph.

"""
#    Copyright (C) 2010 by 
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    <NAME> <<EMAIL>>
#    All rights reserved.
#    BSD license.
__author__ = """\n""".join(['<NAME> <<EMAIL>>',
                            '<NAME> <<EMAIL>>'])
__all__ = ['ego_graph']

import networkx as nx

def ego_graph(G,n,radius=1,center=True):
    """Returns induced subgraph of neighbors centered at node n. 
    
    Parameters
    ----------
    G : graph
      A NetworkX Graph or DiGraph

    n : node 
      A single node 

    radius : integer
      Include all neighbors of distance<=radius from n
      
    center : bool, optional
      If False, do not include center node in graph 

    """
    sp=nx.single_source_shortest_path_length(G,n,cutoff=radius)
    H=G.subgraph(sp.keys())
    if not center:
        H.remove_node(n)
    return  H
{'fraction_non_alphanumeric': 0.14402810304449648, 'fraction_numerical': 0.005269320843091335, 'mean_word_length': 2.2676864244741872, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4008562', 'n_tokens_mistral': 574, 'n_tokens_neox': 551, 'n_words': 165}