def line_per_theory(theory, terms): '''(str, List[str]) -> str Generate a row of data for the theory. Return a string containing that data. ''' bibs = [] for term in terms: try: bibs.append( bib_utils.get_bib( os.sep.join(['ALL', '{},{}.bib'.format(theory, term)]))) except FileNotFoundError: pass bib = bib_utils.merge_bibs(bibs) occurrences = len(bib.entries_dict) bibs = [] for term in terms: try: bibs.append( bib_utils.get_bib( os.sep.join(['CSE', '{},{}.bib'.format(theory, term)]))) except FileNotFoundError: pass bib = bib_utils.merge_bibs(bibs) cs_occurrences = len(bib.entries_dict) venue_counts = bib_utils.get_venue_counts(bib) print(theory, venue_counts) venue_counts = venue_counts[:min(3, len(venue_counts))] top_venues = '; '.join( ['{} ({})'.format(*venue) for venue in venue_counts if venue[1] > 3]) return '{} & {} & {} & {} \\\\'.format(theory, occurrences, cs_occurrences, top_venues)
def line_per_search(theory, terms): '''(str, List[str]) -> List[str] Generate a row of data for each term in the list of search strings terms. Return a list containing the rows generated. ''' body_list = [] for term in terms: try: bib = bib_utils.get_bib( os.sep.join(['ALL', '{},{}.bib'.format(theory, term)])) occurrences = len(bib.entries_dict) venue_counts = bib_utils.get_venue_counts(bib) venue_counts = venue_counts[:min(3, len(venue_counts))] top_venues = '; '.join([ '{} ({})'.format(*venue) for venue in venue_counts if venue[1] > 5 ]) except FileNotFoundError: occurrences = 'Running' top_venues = '...' try: bib = bib_utils.get_bib( os.sep.join(['CSE', '{},{}.bib'.format(theory, term)])) cs_occurrences = len(bib.entries_dict) except FileNotFoundError: cs_occurrences = 'Running' body_list.append('{} & {} & {} & {} & {} \\\\'.format( theory, term, occurrences, cs_occurrences, top_venues)) return body_list
def gen_crosstab(theory_terms_d, typ): '''(Dict[str: str], str) -> str Return a latex table that represents the crosstab of theories. ''' theory_bibs_d = OrderedDict() for (theory, terms) in theory_terms_d.items(): bibs = [] for term in terms: try: bibs.append(bib_utils.get_bib(os.sep.join([typ, '{},{}.bib'.format(theory, term)]))) except FileNotFoundError: pass bib = bib_utils.merge_bibs(bibs) venues = bib_utils.get_venues(bib) # Just in case we want venues later papers = bib_utils.extract_paper_list(bib) theory_bibs_d[theory] = (papers, venues) body = [] counter = 1 to_remove = [] for (theory, data) in theory_bibs_d.items(): row = [theory] papers = data[0] any_data = False for (theory_compare, comp_data) in theory_bibs_d.items(): if theory != theory_compare: intersection = len(papers.intersection(comp_data[0])) if intersection > 0: any_data = True row.append(str(intersection)) else: row.append('') else: row.append('-') if not any_data: to_remove.append(counter) counter += 1 body.append(row) # Removing any rows with no data for index in to_remove[::-1]: for row in body: row.pop(index) body.pop(index - 1) format_str = 'l' * (len(body) + 1) header = 'Theory (id) & {}'.format('&'.join([str(i + 1) for i in range(len(body))])) body = ['{} ({}) & {}\\\\'.format(row[0], count + 1, '&'.join(row[1:])) for (count, row) in enumerate(body)] return table_str.format(format_str, header, '\n'.join(body))
total_occurrences += len(series_d[series]) venue_list.append('& {} & {} &\\\\'.format(series, len(series_d[series]))) # Fenceposting -- but inserting at front to allow for rowspan series = related_series[0] total_occurrences += len(series_d[series]) venue_list.insert(0, '\\multirow{{{}}}{{*}}{{{}}} & {} & {} & \\multirow{{{}}}{{*}}{{{}}}\\\\'\ .format(len(related_series), venue, series, len(series_d[series]), len(related_series), total_occurrences)) body_list.extend(venue_list) return table_str.format(format_str, header_str, '\n'.join(body_list), label) if __name__ == '__main__': from docopt import docopt arguments = docopt(__doc__) analysis_name = arguments.get('<analysis_name>') bibfiles = arguments.get('<bibfile>') bibs = [bib_utils.get_bib(bibfile) for bibfile in bibfiles] # Burning space! merged_bib = bib_utils.merge_bibs(bibs) output_fname = os.sep.join([OUTPUT_FOLDER, '{}.tex'.format(analysis_name)]) open(output_fname, 'w').write( gen_venue_occurrence_table(merged_bib, analysis_name.replace('_', '\\_')))