Exemple #1
0
def bibtex_service(lines):
    citeString = '\cite{'
    citeStringMatch = r"\\cite\{(.*?)\}"
    references = []
    for line in lines:
        if citeString in line:
            for a in list(re.finditer(citeStringMatch,line)):
                r = a.groups()[0].split(',')
                for x in r:
                    x = re.sub('\s','',x)
                    if not x in references:
                        references.append(x) 
  
    btxt_str = ''
    for x in references:
        index = None
        if re.search('.*\:\d{4}\w\w\w?',x) : index = 'texkey'
        elif re.search('.*\/\d{7}',x)      : index = 'eprint'
        elif re.search('\d{4}\.\d{4}',x)   : index = 'eprint'
        elif re.search('\w\.\w+\.\w',x) : 
            index = 'j'
            x = re.sub('\.',',',x)
        elif re.search('\w\-\w',x) : index = 'r'
        if index :
            recid_list = perform_request_search(p=x)
            if recid_list:
                bfo = BibFormatObject(recid_list[0])
                btxt_str = btxt_str + bfe_INSPIRE_bibtex.format_element(bfo)

        else :
            print '***************************************'
            print '*** I do not know what',x,'is. ***'
            print '***************************************'
    return btxt_str
Exemple #2
0
def process_references(references, output_format):
    """
    Process a list of references and convert them to a
    given output_format

    """

    btxt_str = '' # result string
    for ref in references:
        index = None
        if re.search(r'.*\:\d{4}\w\w\w?', ref):
            index = 'texkey'
        elif re.search(r'.*\/\d{7}', ref):
            index = 'eprint'
        elif re.search(r'\d{4}\.\d{4}', ref):
            index = 'eprint'
        elif re.search(r'\w\.\w+\.\w', ref):
            index = 'j'
            ref = re.sub(r'\.', ',', ref)
        elif re.search(r'\w\-\w', ref):
            index = 'r'
        if index:
            # hack to match more records
            recid_list = ''
            if index == 'texkey':
                p_to_find = '035__z:' + ref
                recid_list = perform_request_search(p=p_to_find)
                if not recid_list:
                    #try 035__a
                    p_to_find = '035__a:' + ref
                    recid_list = perform_request_search(p=p_to_find)
            else:
                p_to_find = 'find ' + index + ' ' + ref
                recid_list = perform_request_search(p=p_to_find)

            if recid_list:
                bfo = BibFormatObject(recid_list[0])
                if (output_format == 'hlxu' or
                        output_format == 'hlxe' or
                        output_format == 'hx'):
                    formated_rec = format_record(recid_list[0],
                                    output_format, 'en')
                    # update bibitem and cite if they don't match
                    if not re.search('bibitem{' + ref + '}', formated_rec):
                        ref = re.sub(',', '.', ref)
                        if output_format != 'hx':
                            #laTeX
                            formated_rec = re.sub('bibitem{(.*)}',
                                    'bibitem{' + ref + '}', formated_rec)
                            formated_rec = re.sub('cite{(.*)}',
                                            'cite{' + ref + '}', formated_rec)
                        else:
                            #bibtex
                            if not re.search(r'\@article\{' + ref + '}',
                                              formated_rec):
                                formated_rec = re.sub(r'\@article\{(.*)\,',
                                        r'@article{' + ref + ',', formated_rec)
                    btxt_str = btxt_str + formated_rec + '\n'
                else:
                    btxt_str = (btxt_str +
                                bfe_INSPIRE_bibtex.format_element(bfo) + '\n')
            else:
                btxt_str = (btxt_str + '*** Not Found: ' + ref + ' ' +
                            p_to_find + '\n\n')

    return btxt_str
Exemple #3
0
def process_references(references, output_format):
    """
    Process a list of references and convert them to a
    given output_format

    """

    btxt_str = ''  # result string
    for ref in references:
        index = None
        if re.search(r'.*\:\d{4}\w\w\w?', ref):
            index = 'texkey'
        elif re.search(r'.*\/\d{7}', ref):
            index = 'eprint'
        elif re.search(r'\d{4}\.\d{4}', ref):
            index = 'eprint'
        elif re.search(r'\w\.\w+\.\w', ref):
            index = 'j'
            ref = re.sub(r'\.', ',', ref)
        elif re.search(r'\w\-\w', ref):
            index = 'r'
        if index:
            # hack to match more records
            recid_list = ''
            if index == 'texkey':
                p_to_find = '035__z:' + ref
                recid_list = perform_request_search(p=p_to_find)
                if not recid_list:
                    #try 035__a
                    p_to_find = '035__a:' + ref
                    recid_list = perform_request_search(p=p_to_find)
            else:
                p_to_find = 'find ' + index + ' ' + ref
                recid_list = perform_request_search(p=p_to_find)

            if recid_list:
                bfo = BibFormatObject(recid_list[0])
                if (output_format == 'hlxu' or output_format == 'hlxe'
                        or output_format == 'hx'):
                    formated_rec = format_record(recid_list[0], output_format,
                                                 'en')
                    # update bibitem and cite if they don't match
                    if not re.search('bibitem{' + ref + '}', formated_rec):
                        ref = re.sub(',', '.', ref)
                        if output_format != 'hx':
                            #laTeX
                            formated_rec = re.sub('bibitem{(.*)}',
                                                  'bibitem{' + ref + '}',
                                                  formated_rec)
                            formated_rec = re.sub('cite{(.*)}',
                                                  'cite{' + ref + '}',
                                                  formated_rec)
                        else:
                            #bibtex
                            if not re.search(r'\@article\{' + ref + '}',
                                             formated_rec):
                                formated_rec = re.sub(r'\@article\{(.*)\,',
                                                      r'@article{' + ref + ',',
                                                      formated_rec)
                    btxt_str = btxt_str + formated_rec + '\n'
                else:
                    btxt_str = (btxt_str +
                                bfe_INSPIRE_bibtex.format_element(bfo) + '\n')
            else:
                btxt_str = (btxt_str + '*** Not Found: ' + ref + ' ' +
                            p_to_find + '\n\n')

    return btxt_str
Exemple #4
0
      r = a.groups()[0].split(',')
      for x in r:
        x = re.sub('\s','',x)
        if not x in references:
          references.append(x) 
exit()

bibFile = open('file.bib', 'w')
for x in references:
  index = None
  if re.search('.*\:\d{4}\w\w\w?',x) : index = 'texkey'
  elif re.search('.*\/\d{7}',x)      : index = 'eprint'
  elif re.search('\d{4}\.\d{4}',x)   : index = 'eprint'
  elif re.search('\w\.\w+\.\w',x) : 
    index = 'j'
    x = re.sub('\.',',',x)
  elif re.search('\w\-\w',x) : index = 'r'
  if index :
    #print 'find',index,x,'in INSPIRE'
    recid_list = perform_request_search(p=x)
    if recid_list:
         bfo = BibFormatObject(recid_list[0])
         btxt_str = bfe_INSPIRE_bibtex.format_element(bfo)
         print btxt_str

  else :
    print '***************************************'
    print '*** I do not know what',x,'is. ***'
    print '***************************************'
bibFile.close()
Exemple #5
0
def process_references(references, output_format):
    """
    Process a list of references and convert them to a
    given output_format

    """

    btxt_str = '' # result string
    nfmsg = '*** Not Found with lookup:'
    nsmsg = '*** Non-standard form, no INSPIRE lookup performed ***'
    for ref in references:
        index = None
        if re.search(r'.*\:\d{4}\w\w\w?', ref):
            index = 'texkey'
        elif re.search(r'.*\/\d{7}', ref):
            index = 'eprint'
        elif re.search(r'\d{4}\.\d{4,5}', ref):
            index = 'eprint'
        elif re.search(r'\w\.\w+\.\w', ref):
            index = 'j'
            ref = re.sub(r'\.', ',', ref)
        elif re.search(r'\w\-\w', ref):
            index = 'r'
        if index:
            # hack to match more records
            recid_list = ''
            if index == 'texkey':
                p_to_find = '035__z:' + ref
                recid_list = perform_request_search(p=p_to_find)
                if not recid_list:
                    #try 035__a
                    p_to_find = '035__a:' + ref
                    recid_list = perform_request_search(p=p_to_find)
            else:
                p_to_find = 'find ' + index + ' ' + ref
                recid_list = perform_request_search(p=p_to_find)

            if recid_list:
                bfo = BibFormatObject(recid_list[0])
                if (output_format == 'hlxu' or
                        output_format == 'hlxe' or
                        output_format == 'hx'):
                    formated_rec = format_record(recid_list[0], \
                                                 output_format, 'en')
                    # update bibitem and cite if they don't match
                    if not re.search('bibitem{' + re.escape(ref) + '}', formated_rec):
                        ref = re.sub(',', '.', ref)
                        if output_format != 'hx':
                            #laTeX
                            formated_rec = re.sub('bibitem{(.*)}', \
                                                  'bibitem{' + ref + '}', \
                                                  formated_rec)
                            formated_rec = re.sub('cite{(.*)}', \
                                                  'cite{' + ref + '}', \
                                                  formated_rec)
                        else:
                            #bibtex
                            if not re.search(r'\@article\{' + re.escape(ref) + '}', \
                                             formated_rec):
                                formated_rec = re.sub(r'\@article\{(.*)\,', \
                                                      r'@article{' + ref + ',', \
                                                      formated_rec)
                    btxt_str = btxt_str + formated_rec + '\n'
                else:
                    btxt_str = btxt_str + \
                                bfe_INSPIRE_bibtex.format_element(bfo) + '\n'
            else:
                if output_format == 'hx':
                    btxt_str = btxt_str + \
                               '<div class="%s">\n@MISC{%s,\n\t%s \'%s\'\n}\n</div>\n' \
                               % ('notfound', ref, nfmsg, p_to_find,)
                else:
                    btxt_str = btxt_str + \
                               '<div class="%s">\\bibitem{%s}\n\t%s \'%s\'\n</div>\n' \
                               % ('notfound', ref, nfmsg, p_to_find,)
        else:
            if output_format == 'hx':
                btxt_str = btxt_str + \
                           '<div class="%s">\n@MISC{%s,\n\t%s\n}\n</div>\n' \
                           % ('nonstandard', ref, nsmsg,)
            else:
                btxt_str = btxt_str + \
                           '<div class="%s">\\bibitem{%s}\n\t%s\n</div>\n' \
                           % ('nonstandard', ref, nsmsg,)

    return btxt_str