''' Created on May 2, 2020 @author: Brett Paufler (c) Copyright Brett Paufler Must Import ALL to Work load_data requires CASE, OPINION ''' ###################################### # # Re-Define Our Objects # CASE & Opinion # ###################################### from collections import namedtuple OPINION = namedtuple( typename='OPINION', field_names=[ 'type', 'author', 'joining', 'good', 'pages' ]) CASE = namedtuple( typename='CASE', field_names=[ 'R', 'Date', 'Docket', 'Name', 'Worthy', 'Opinions', ]) ########################################## # # Retrieve Previous Pickle # ######################################### from pickle import loads def load_data(): pickle_file_path = './/input//2018_judges_pickle.txt' with open(pickle_file_path, 'r') as f: raw_text = f.read() all_cases = loads(raw_text) return all_cases ############################################## # # Bag_O_Judges # Ordered, Counter # ############################################## from collections import Counter, OrderedDict #The following OrderedCounter Class is a Straight Cut and Paste #docs.python.org/2/library/collections.html class OrderedCounter(Counter, OrderedDict): 'Counter that remembers the order elements are first encountered' def __repr__(self): return '%s(%r)' % (self.__class__.__name__, OrderedDict(self)) def __reduce__(self): return self.__class__, (OrderedDict(self),) def Bag_O_Judges(): '''Returns an Initialized OrderedDictionary Preset with the Judges in Order of Seniority Works as a Counter But Retains Order''' JUDGES_BY_SENIORITY = [ 'Roberts', 'Thomas', 'Ginsburg', 'Breyer', 'Alito', 'Sotomayor', 'Kagan', 'Gorsuch', 'Kavanaugh'] bag_judges = OrderedCounter() for judge in JUDGES_BY_SENIORITY: bag_judges[judge] = 0 return bag_judges #print Bag_O_Judges() #b = Bag_O_Judges() #b.update(['Roberts', 'Roberts']) #print b