Exemplo n.º 1
0
    def __call__ (self, rec):
        from bibtexparser.customization import author, type, convert_to_unicode
        rec = type (convert_to_unicode (rec))

        for key in rec.keys ():
            val = rec.get (key)
            val = (val
                   .replace ('{\\nbsp}', nbsp)
                   .replace ('``', u'“')
                   .replace ("''", u'”'))
            rec[key] = val

        if 'journal' in rec:
            rec['journal'] = _bib_journals.get (rec['journal'].lower (),
                                                rec['journal'])

        rec = author (rec)

        if 'author' in rec:
            newauths = []

            for idx, text in enumerate (rec['author']):
                text = text.replace ('{', '').replace ('}', '').replace ('~', ' ')
                surname, rest = text.split (',', 1)
                if surname.lower () == self.mylsurname:
                    rec['wl_mypos'] = unicode (idx + 1)
                newauths.append (rest + ' ' + surname.replace (' ', '_'))

            rec['author'] = '; '.join (newauths)

        rec['wl_cite'] = _bib_cite (rec)
        return rec
Exemplo n.º 2
0
    def __call__(self, rec):
        from bibtexparser.customization import author, type, convert_to_unicode

        rec = type(convert_to_unicode(rec))

        for key in rec.keys():
            val = rec.get(key)
            val = val.replace("{\\nbsp}", nbsp).replace("``", u"“").replace("''", u"”")
            rec[key] = val

        if "journal" in rec:
            rec["journal"] = _bib_journals.get(rec["journal"].lower(), rec["journal"])

        rec = author(rec)

        if "author" in rec:
            newauths = []

            for idx, text in enumerate(rec["author"]):
                text = text.replace("{", "").replace("}", "").replace("~", " ")
                surname, rest = text.split(",", 1)
                if surname.lower() == self.mylsurname:
                    rec["wl_mypos"] = unicode(idx + 1)
                newauths.append(rest + " " + surname.replace(" ", "_"))

            rec["author"] = "; ".join(newauths)

        rec["wl_cite"] = _bib_cite(rec)
        return rec
Exemplo n.º 3
0
def _customizations(record):
    """
    Bibtexparser customizations that are applied to every entry found in the .bib files
    """
    record = convert_to_unicode(record)
    record = type(record)    # make the entry types lower-case
    record = author(record)  # split the authors into a list
    record = editor(record)  # split the editors into a list
    return record
Exemplo n.º 4
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)
Exemplo n.º 5
0
def td_biblio_customization(record):
    """
    Customize BibTex records parsing
    """
    # Convert crapy things to latex
    record = to_latex(record)
    # and then to unicode
    record = bp_customization.convert_to_unicode(record)
    record = bp_customization.type(record)
    record = bp_customization.author(record)
    record = bp_customization.editor(record)
    record = bp_customization.page_double_hyphen(record)

    return record
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
def customizations(record):
    """Use some functions delivered by the library

    Args:
        record (dict): record dict.

    Returns: record (dict): the modified record
    """
    record = bibcus.type(record)
    record = bibcus.author(record)
    #record = bibcus.editor(record)
    #record = bibcus.journal(record)
    record = bibcus.keyword(record)
    #record = bibcus.link(record)
    record = bibcus.page_double_hyphen(record)
    #record = bibcus.doi(record)
    record = splitFields(record, 'folder')
    record = splitFields(record, 'url', '\n')
    record = splitFields(record, 'file', ',|;|\n')
    record = getPublication(record)
    return record
Exemplo n.º 9
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
Exemplo n.º 11
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
 def test_type3(self):
     record = {'type': 'journal'}
     result = type(record)
     expected = {'type': 'journal'}
     self.assertEqual(result, expected)
 def test_type2(self):
     record = {'type': 'BoOk'}
     result = type(record)
     expected = {'type': 'book'}
     self.assertEqual(result, expected)
 def test_type1(self):
     record = {'type': 'ARTICLE'}
     result = type(record)
     expected = {'type': 'article'}
     self.assertEqual(result, expected)