python_code/consolidate_data.py
def create_edge_sublist(court_name, master_cited_as_key):
    """
    Given a court name (and a corresponding consolidation file) and a master edge list, create_edge_sublist will create
    a citations.csv file in the court's directory, representing the subset of edges in which both nodes are in
    court_name's court.
    """

    court_dir = data_dir + r'/%s' % court_name
    court_data = helper_functions.csv_to_list(court_dir,
                                              'consolidation.csv', 1, 0)

    print 'finding IDs in court...'
    citation_ids_in_court = []
    for row in court_data:
        opinion_id = int(row[0])
        citation_ids_in_court.append(opinion_id)

    edge_sublist = [['citing', 'cited']]
    num_ids = len(citation_ids_in_court)
    id = 0
    for opinion_id in citation_ids_in_court:
        try:
            list_of_citers = master_cited_as_key[opinion_id]
        except KeyError:
            list_of_citers = []

        for citer in list_of_citers:
            if citer in citation_ids_in_court:
                edge_sublist.append([citer, opinion_id])

        id += 1
        if id % 1000 == 0:
            print '%s of %s IDs checked (%s)' % (id, num_ids, float(id)/num_ids)

    helper_functions.list_to_csv(court_dir + r'/citations_sublist.csv', edge_sublist)

    Given a court name (and a corresponding consolidation file) and a master edge list, create_edge_sublist will create
    a citations.csv file in the court's directory, representing the subset of edges in which both nodes are in
    court_name's court.
    
Given a court name (and a corresponding consolidation file) and a master edge list, create_edge_sublist will create
a citations.csv file in the court's directory, representing the subset of edges in which both nodes are in
court_name's court.
Given a court name ( and a corresponding consolidation file ) and a master edge list create_edge_sublist will create a citations . csv file in the court ' s directory representing the subset of edges in which both nodes are in court_name ' s court .
def create_edge_sublist(court_name, master_cited_as_key):
    court_dir = data_dir + r'/%s' % court_name
    court_data = helper_functions.csv_to_list(court_dir,
                                              'consolidation.csv', 1, 0)
    print 'finding IDs in court...'
    citation_ids_in_court = []
    for row in court_data:
        opinion_id = int(row[0])
        citation_ids_in_court.append(opinion_id)
    edge_sublist = [['citing', 'cited']]
    num_ids = len(citation_ids_in_court)
    id = 0
    for opinion_id in citation_ids_in_court:
        try:
            list_of_citers = master_cited_as_key[opinion_id]
        except KeyError:
            list_of_citers = []
        for citer in list_of_citers:
            if citer in citation_ids_in_court:
                edge_sublist.append([citer, opinion_id])
        id += 1
        if id % 1000 == 0:
            print '%s of %s IDs checked (%s)' % (id, num_ids, float(id)/num_ids)
    helper_functions.list_to_csv(court_dir + r'/citations_sublist.csv', edge_sublist)
def create_edge_sublist ( court_name , master_cited_as_key ) : court_dir = data_dir + r'/%s' % court_name court_data = helper_functions . csv_to_list ( court_dir , 'consolidation.csv' , 1 , 0 ) print 'finding IDs in court...' citation_ids_in_court = [ ] for row in court_data : opinion_id = int ( row [ 0 ] ) citation_ids_in_court . append ( opinion_id ) edge_sublist = [ [ 'citing' , 'cited' ] ] num_ids = len ( citation_ids_in_court ) id = 0 for opinion_id in citation_ids_in_court : try : list_of_citers = master_cited_as_key [ opinion_id ] except KeyError : list_of_citers = [ ] for citer in list_of_citers : if citer in citation_ids_in_court : edge_sublist . append ( [ citer , opinion_id ] ) id += 1 if id % 1000 == 0 : print '%s of %s IDs checked (%s)' % ( id , num_ids , float ( id ) / num_ids ) helper_functions . list_to_csv ( court_dir + r'/citations_sublist.csv' , edge_sublist )
Given a court name (and a corresponding consolidation file) and a master edge list, create_edge_sublist will create
a citations.csv file in the court's directory, representing the subset of edges in which both nodes are in
court_name's court.
Given a court name ( and a corresponding consolidation file ) and a master edge list create_edge_sublist will create a citations . csv file in the court ' s directory representing the subset of edges in which both nodes are in court_name ' s court .
"""
    Given a court name (and a corresponding consolidation file) and a master edge list, create_edge_sublist will create
    a citations.csv file in the court's directory, representing the subset of edges in which both nodes are in
    court_name's court.
    """
court_name
master_cited_as_key