Skip to content

Instantly share code, notes, and snippets.

@atrisovic
Last active February 1, 2018 10:27
Show Gist options
  • Select an option

  • Save atrisovic/3caea219e9a345a66a902250e7a018fd to your computer and use it in GitHub Desktop.

Select an option

Save atrisovic/3caea219e9a345a66a902250e7a018fd to your computer and use it in GitHub Desktop.
Author counter - analysis of bibtex files
from __future__ import division
import bibtexparser
from bibtexparser.bparser import BibTexParser
from bibtexparser.customization import homogeneize_latex_encoding
alist=[]
with open('bibfile.bib') as bibtex_file:
parser = BibTexParser()
parser.customization = homogeneize_latex_encoding
bib_database = bibtexparser.load(bibtex_file, parser=parser)
for entry in bib_database.entries:
alist.append(entry["author"].replace('\n', ' '))
nn = len(alist) # number of papers
print "Number of papers: " + str(nn)
# find separate names
all = " and ".join(alist)
names = all.split(" and ")
# sorted list of all authors
# for n in sorted(names):
# print n
print "Number of authors: " + str(len(names))
total_number_of_a = len(names)
print "Average number of authors per paper: " + str(total_number_of_a/nn)
## unique names
fin_names = set(names)
fin_names = list(fin_names)
# List of unique names
#for name in sorted(fin_names):
# print name.encode("utf-8")
print "Number of unique authors in total: "+ str(len(fin_names))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment