<commit_before>#!/usr/bin/env python
import xml.etree.ElementTree as ET
import StringIO, sys, getopt, re, string, urllib

def _myCap(text):
    def commonWords(x):
        if x.lower() in ['in', 'and', 'of']: return x.lower()
        else: return string.capitalize(x)
    return ' '.join(map(commonWords,text.split()))

def shortenFirstName(s):
    s = s.strip().split(',')
    last = s[0]

    # remainder
    remainder = s[1].strip()

    # see if we get a first name and initials
    first = None
    tmp = remainder.split(' ')
    if len(tmp) == 2:
	first = tmp[0][0]+'.'+tmp[1]
	if first[-1] != '.': first += '.'
    elif re.compile('[A-Z]\.').match(remainder):
	first = remainder
    elif re.compile('[A-Z]\.[A-Z]\.').match(remainder):
	first = remainder
    elif re.compile('[A-Z]\.[A-Z]').match(remainder):
	first = remiander+'.'
    elif len(remainder) > 4:
	first = remainder[0]+'.'
    else: first = remainder[0]+'.'
    
    return (first, last.encode('ascii', 'ignore'))

class Publication:
    def __init__(self, authorList,
		 title,
		 journal,
		 year,
		 volume,
		 pages,
                 kwds = None,
		 url = None,
		 abstract = None):
        self.index = -1
	self.authors = authorList

	self.title = title
	self.journal = journal

	self.volume = volume

	self.year = year
	self.pages = pages

	self.startPage = pages.split('-')[0]
	if self.startPage == '': self.startPage = 0
	else: 
            try:
                self.startPage = int(self.startPage)
            except ValueError: ## some idiotic alphanumeric page number!
                pass

	self.abstract = abstract
	self.url = url

        self.kwds = kwds

        self.myself = None

    def __str__(self):
	authors = [ '%s, %s' % (l,f) for f,l in self.authors]
	s = """
	%s
	%s
	%s %s %s %s
	""" % (self.title, 
	       '; '.join(authors), self.journal, 
	       self.year, self.volume, self.pages)
	return s

    def setMyself(self, name):
        self.myself = name
        
    def getKeywords(self): return self.kwds

    def isPublished(self):
	if self.volume in ['submitted',  'in press', 'ASAP']: return False
	else: return True

    def formatJournal(self, mode = 'latex'):
        if self.journal is not None and self.journal != '':
            if mode == 'latex':
                return '\\textit{%s}' % (self.journal)
            elif mode == 'html':
                return '<i>%s</i>' % (self.journal.replace("\&","&"))
        else: return ''
    
    def getPaperDiv(self, id = None, show_abstract = False):
	label = ''
	doi = None

	if self.url and self.url.find('http://dx.doi.org') >= 0:
	    doi = self.url.replace('http://dx.doi.org/', '')
	    label = 'DOI'
	elif self.url: 
	    doi = self.url
	    label = 'Link'

	s = StringIO.StringIO()
	s.write("<div class='paper'>\n")
        #s.write("<div class='serial'>%d</div>\n" % (id))
	s.write("<div class='ptitle'><span class='pubindex'>%d.</span> %s</div>\n" % (self.index, self.title.replace('{','').replace('}','')))
	s.write("<div class='pdetails'>\n")
	s.write("<div class='pauthor'>\n")

	## find the index of Guha in the author list
	authors = []
	for first, last in self.authors:
	    if last.find(self.myself) != -1:
		authors.append('<span class="lead">%s, %s</span>' % (last, first))
	    else: authors.append('%s, %s' % (last, first))
	authors = '; '.join(authors)
	s.write('%s\n</div>\n' % (authors))

        if self.journal != "":
            self.journal += ","
            
	if not self.isPublished():
	    s.write("<div class='pjournal'>%s, <b>%s</b>, %s</div>\n" % (self.formatJournal('html'), self.year, self.volume))
	else:
	    s.write("<div class='pjournal'>%s, <b>%s</b>, <i>%s</i>, %s</div>\n" % (self.formatJournal('html'), self.year, self.volume, self.pages))	    
	s.write("<div class='pmisc'>\n")
        if show_abstract:
            toggletext = '''[ <a href="javascript:toggleLayer('abstract%d');">Abstract</a> ]''' % (id)
        else:
           toggletext = ''
           
	if label == 'DOI':
	    s.write("""
	    %s
	    [DOI <a href="%s">%s</a> ]
	    """ % (toggletext, self.url, doi))
	elif label == 'Link':
	    s.write("""
	    %s
	    [ <a href="%s">Link</a> ]
	    """ % (toggletext, self.url))
        if show_abstract:
            s.write("<div id='abstract%d' class='absdiv'>%s</div>\n\n" % (id, self.abstract))
	s.write("</div>\n</div>\n</div>\n")


	return s.getvalue()

def _genLatexEntry(pub, color, id=None):
    entry = ''
    authors = []
    for first, last in pub.authors:
	if last.find(pub.myself) != -1:
	    authors.append('\\textbf{%s, %s}' % (last, first))
	else:
            if color:
                authors.append('\\textcolor[rgb]{0.6, 0.6, 0.6}{%s, %s}' % (last, first))
            else:
                authors.append('%s, %s' % (last, first))
    authors = '; '.join(authors)

    ## Set up URL
    if pub.url:
        labelstr = '''\\href{%s}{%d}.''' % (pub.url, id)
    else: labelstr = '%d.' % (id)
    labelstr = str(id)+"."

    if not pub.isPublished():
	entry = """\\entry*[%s] \\raggedright{%s; ``%s'', %s, \\textbf{%s}, %s}""" % \
	    (labelstr, authors, pub.title, pub.formatJournal('latex'), pub.year, pub.volume)
    else:<commit_msg>Correct punctuation for journal titles in html output<commit_after>#!/usr/bin/env python
import xml.etree.ElementTree as ET
import StringIO, sys, getopt, re, string, urllib

def _myCap(text):
    def commonWords(x):
        if x.lower() in ['in', 'and', 'of']: return x.lower()
        else: return string.capitalize(x)
    return ' '.join(map(commonWords,text.split()))

def shortenFirstName(s):
    s = s.strip().split(',')
    last = s[0]

    # remainder
    remainder = s[1].strip()

    # see if we get a first name and initials
    first = None
    tmp = remainder.split(' ')
    if len(tmp) == 2:
	first = tmp[0][0]+'.'+tmp[1]
	if first[-1] != '.': first += '.'
    elif re.compile('[A-Z]\.').match(remainder):
	first = remainder
    elif re.compile('[A-Z]\.[A-Z]\.').match(remainder):
	first = remainder
    elif re.compile('[A-Z]\.[A-Z]').match(remainder):
	first = remiander+'.'
    elif len(remainder) > 4:
	first = remainder[0]+'.'
    else: first = remainder[0]+'.'
    
    return (first, last.encode('ascii', 'ignore'))

class Publication:
    def __init__(self, authorList,
		 title,
		 journal,
		 year,
		 volume,
		 pages,
                 kwds = None,
		 url = None,
		 abstract = None):
        self.index = -1
	self.authors = authorList

	self.title = title
	self.journal = journal

	self.volume = volume

	self.year = year
	self.pages = pages

	self.startPage = pages.split('-')[0]
	if self.startPage == '': self.startPage = 0
	else: 
            try:
                self.startPage = int(self.startPage)
            except ValueError: ## some idiotic alphanumeric page number!
                pass

	self.abstract = abstract
	self.url = url

        self.kwds = kwds

        self.myself = None

    def __str__(self):
	authors = [ '%s, %s' % (l,f) for f,l in self.authors]
	s = """
	%s
	%s
	%s %s %s %s
	""" % (self.title, 
	       '; '.join(authors), self.journal, 
	       self.year, self.volume, self.pages)
	return s

    def setMyself(self, name):
        self.myself = name
        
    def getKeywords(self): return self.kwds

    def isPublished(self):
	if self.volume in ['submitted',  'in press', 'ASAP']: return False
	else: return True

    def formatJournal(self, mode = 'latex'):
        if self.journal is not None and self.journal != '':
            if mode == 'latex':
                return '\\textit{%s}' % (self.journal)
            elif mode == 'html':
                return '<i>%s</i>' % (self.journal.replace("\&","&"))
        else: return ''
    
    def getPaperDiv(self, id = None, show_abstract = False):
	label = ''
	doi = None

	if self.url and self.url.find('http://dx.doi.org') >= 0:
	    doi = self.url.replace('http://dx.doi.org/', '')
	    label = 'DOI'
        elif self.url and self.url.find('rxiv') >= 0:
            doi = self.url
            label = 'Preprint'
	elif self.url: 
	    doi = self.url
	    label = 'Link'

	s = StringIO.StringIO()
	s.write("<div class='paper'>\n")
        #s.write("<div class='serial'>%d</div>\n" % (id))
	s.write("<div class='ptitle'><span class='pubindex'>%d.</span> %s</div>\n" % (self.index, self.title.replace('{','').replace('}','')))
	s.write("<div class='pdetails'>\n")
	s.write("<div class='pauthor'>\n")

	## find the index of Guha in the author list
	authors = []
	for first, last in self.authors:
	    if last.find(self.myself) != -1:
		authors.append('<span class="lead">%s, %s</span>' % (last, first))
	    else: authors.append('%s, %s' % (last, first))
	authors = '; '.join(authors)
	s.write('%s\n</div>\n' % (authors))

        if self.journal != "":
            self.journal += ","

	if not self.isPublished():
	    s.write("<div class='pjournal'>%s <b>%s</b>, %s</div>\n" % (self.formatJournal('html'), self.year, self.volume))
	else:
	    s.write("<div class='pjournal'>%s <b>%s</b>, <i>%s</i>, %s</div>\n" % (self.formatJournal('html'), self.year, self.volume, self.pages))	    
	s.write("<div class='pmisc'>\n")
        if show_abstract:
            toggletext = '''[ <a href="javascript:toggleLayer('abstract%d');">Abstract</a> ]''' % (id)
        else:
           toggletext = ''
           
	if label == 'DOI':
	    s.write("""
	    %s
	    [DOI <a href="%s">%s</a> ]
	    """ % (toggletext, self.url, doi))
	elif label in ['Link','Preprint']:
	    s.write("""
	    %s
	    [ <a href="%s">%s</a> ]
	    """ % (toggletext, self.url, label))
        if show_abstract:
            s.write("<div id='abstract%d' class='absdiv'>%s</div>\n\n" % (id, self.abstract))
	s.write("</div>\n</div>\n</div>\n")


	return s.getvalue()

def _genLatexEntry(pub, color, id=None):
    entry = ''
    authors = []
    for first, last in pub.authors:
	if last.find(pub.myself) != -1:
	    authors.append('\\textbf{%s, %s}' % (last, first))
	else:
            if color:
                authors.append('\\textcolor[rgb]{0.6, 0.6, 0.6}{%s, %s}' % (last, first))
            else:
                authors.append('%s, %s' % (last, first))
    authors = '; '.join(authors)

    ## Set up URL
    if pub.url:
        labelstr = '''\\href{%s}{%d}.''' % (pub.url, id)
    else: labelstr = '%d.' % (id)
    labelstr = str(id)+"."

    if not pub.isPublished():
	entry = """\\entry*[%s] \\raggedright{%s; ``%s'', %s, \\textbf{%s}, %s}""" % \
	    (labelstr, authors, pub.title, pub.formatJournal('latex'), pub.year, pub.volume)
    else:
{'fraction_non_alphanumeric': 0.20499142693846448, 'fraction_numerical': 0.004286530767765289, 'mean_word_length': 2.514897890860395, 'pattern_counts': {'":': 2, '<': 75, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3766476', 'n_tokens_mistral': 3940, 'n_tokens_neox': 3739, 'n_words': 847}