Ejemplo n.º 1
0
def customizations(record):
    record = bib_type(record)
    record = author(record)
    record = editor(record)
    record = journal(record)
    record = keyword(record)
    record = link(record)
    record = page_double_hyphen(record)
    record = doi(record)
    return record
Ejemplo n.º 2
0
 def __init__(self, data_: dict):
     data_ = bib_custom.convert_to_unicode(data_)
     for k, v in data_.items():
         if isinstance(v, str):
             data_[k] = v.replace('<br>', '').strip()
     data_ = handle_authors(data_)
     data_ = handle_pages(data_)
     data_ = bib_custom.type(data_)
     data_ = bib_custom.doi(data_)
     super().__init__(self)
     self.data = data_
     for field in set.union(self.required_fields, self.optional_fields):
         self[field] = self.data.get(field, None)
Ejemplo n.º 3
0
def bibtex_cleaner(entry):
    entry = clean.keyword(entry)
    if entry.get('keyword'):
        entry['keyword'] = ','.join(entry['keyword']).lower()
    # print(entry.get('keyword'))
    entry = clean.page_double_hyphen(entry)
    entry = clean.convert_to_unicode(entry)
    # entry = clean.add_plaintext_fields(entry)

    entry = clean.link(entry)
    entry = clean.doi(entry)
    # print(entry.get('keyword'))

    return entry
Ejemplo n.º 4
0
def customizations(record):
    """Use some functions delivered by the library

    :param record: a record
    :returns: -- customized record

    """
    record = bc.convert_to_unicode(record)
    record = bc.type(record)  # lowercase
    record = bc.author(record)
    record = bc.editor(record)
    record = bc.journal(record)
    record = bc.keyword(record)
    record = bc.link(record)
    record = bc.page_double_hyphen(record)
    record = bc.doi(record)
    return record
Ejemplo n.º 5
0
def customizations(record):
    """Use some functions delivered by the library

    :param record: a record
    :returns: -- customized record

    """
    record = bc.convert_to_unicode(record)
    record = bc.type(record)    # lowercase
    record = bc.author(record)
    record = bc.editor(record)
    record = bc.journal(record)
    record = bc.keyword(record)
    record = bc.link(record)
    record = bc.page_double_hyphen(record)
    record = bc.doi(record)
    return record
Ejemplo n.º 6
0
 def actual_annotate(record):
     """Follows visitor design-pattern to modify BibTeX records
 
     :param record: the record
     :type record: `dict`
 
     :returns the modified record
     :rtype `dict`
     """
     record = try_x_times(retry)(doi_from_record)(record)
     if not record:
         raise TypeError('record expected to have value')
     record = doi(record)  # adds DOI url link
     if 'link' in record:
         if 'url' in record['link'] and record['link']['url']:
             record['howpublished'] = '\url{' + '{}'.format(
                 record['link']['url']) + '}'
         del record['link']
     record = eprint_from_record(record)
     pp(record)
     return record
Ejemplo n.º 7
0
def custom(record):
    record = c.type(record)
    record = c.author(record)
    record = c.editor(record)
    record = c.journal(record)
    record = c.keyword(record)
    record = c.link(record)
    record = c.doi(record)
    tags = set()

    if 'tags' in record:
        tags.update([i.strip() for i in re.split(',|;', record["tags"].replace('\n', ''))])
    if "keywords" in record:
        tags.update([i.strip() for i in re.split(',|;', record["keywords"].replace('\n', ''))])
    if "mendeley-tags" in record:
        tags.update([i.strip() for i in re.split(',|;', record["mendeley-tags"].replace('\n', ''))])

    record['tags'] = tags
    record['p_authors'] = []
    if 'author' in record:
        record['p_authors'] = [c.splitname(x, False) for x in record['author']]
    return record
def clean_full(record):
    record = c.type(record)
    record = c.author(record)
    record = c.editor(record)
    record = c.journal(record)
    record = c.keyword(record)
    record = c.link(record)
    record = c.doi(record)
    tags = set()

    if 'tags' in record:
        tags.update([
            i.strip()
            for i in re.split(',|;', record["tags"].replace('\n', ''))
        ])
    if "keywords" in record:
        tags.update([
            i.strip()
            for i in re.split(',|;', record["keywords"].replace('\n', ''))
        ])
    if "mendeley-tags" in record:
        tags.update([
            i.strip()
            for i in re.split(',|;', record["mendeley-tags"].replace('\n', ''))
        ])

    record['tags'] = tags
    record['p_authors'] = []

    if 'author' in record:
        record['p_authors'] += [x.split(' and ') for x in record['author']]

    if 'editor' in record:
        record['p_authors'] += [
            c.splitname(x, False) for x in record['editor']
        ]

    return record
Ejemplo n.º 9
0
def customize(record):
    def fix_newlines(record):
        for key, value in record.items():
            if key in 'url':
                record[key] = value.replace("\n", "")
            if key not in ('author', 'url', 'editor'):
                value = value.replace("\n", " ")
                record[key] = value.replace(r"\par", "\n\n")
        return record

    record = fix_newlines(record)
    record = customization.type(record)
    record = customization.convert_to_unicode(record)

    def split_author(record):
        if 'author' in record:
            authors = []
            for author in record['author']:
                lastname, firstname = author.split(", ")
                authors.append(Author(firstname, lastname))
            record['author'] = authors
        return record

    def parse_kind(kind, record):
        if kind in record and record[kind]:
            remove_translate_table = str.maketrans('', '', ', .')
            # record_id determines the name of the PDF
            # it's been hard-coded in the view:
            # layouts/partials/publications_icons.html
            # ----> this might want to be refactored
            record_id = record[kind].translate(remove_translate_table)
            record[kind] = {'name': record[kind], 'ID': record_id}
        return record

    record = customization.author(record)
    record = customization.journal(record)
    record = customization.keyword(record)
    record = customization.link(record)
    record = customization.doi(record)
    record = customization.page_double_hyphen(record)
    record = split_author(record)

    for kind in ('booktitle', 'series'):
        record = parse_kind(kind, record)

    def pdf_is_there(record):
        #print(record["ID"])
        filename = record["ID"] + ".pdf"
        path_to_file = os.path.join(LOCAL_PDF_VAULT, filename)
        print(path_to_file)
        if os.path.isfile(path_to_file):
            print("\t PDF found!")
        else:
            print("\t NO PDF!!!")
            record["paper"] = "no"
        return record

    if ("paper" in record.keys() and record["paper"] == "yes"):
        #print(record)
        return pdf_is_there(record)

    return record