<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
Bibliographic database backed by a bibtex file.
"""

import bibtexparser
from .. import texutils

from .base import BasePub
from .adsdb import ADSBibDB


class BibTexDB(object):
    """Bibliographic Database derived from a bibtex file."""
    def __init__(self, path):
        super(BibTexDB, self).__init__()
        self._filepath = path
        with open(path) as bibtex_file:
            bibtex_str = bibtex_file.read()
        self._db = bibtexparser.loads(bibtex_str)

    def __getitem__(self, bibkey):
        return BibTexPub(self._db.entries_dict[bibkey])


class BibTexPub(BasePub):
    """A publication backed by bibtex."""
    def __init__(self, pub_dict):
        super(BibTexPub, self).__init__()
        self._data = pub_dict
        # FIXME does it make sense to embed a connection to ADSBibDB in
        # each bibtex publication instance???
        self._ads_db = ADSBibDB()
        self._ads_pub = None

    def __getitem__(self, key):
        return self._data[key]

    def _get_ads_pub(self):
        """Get the representation for the publication via ADS."""
        if self._ads_pub is None:
            self._ads_pub = self._ads_db[self.bibcode]
        return self._ads_pub

    @property<commit_msg>Use ADS cache within BibTeXDB<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
Bibliographic database backed by a bibtex file.
"""

import bibtexparser
from .. import texutils

from .base import BasePub
from .adsdb import ADSBibDB


class BibTexDB(object):
    """Bibliographic Database derived from a bibtex file."""
    def __init__(self, path, ads_cache=None):
        super(BibTexDB, self).__init__()
        self._filepath = path
        with open(path) as bibtex_file:
            bibtex_str = bibtex_file.read()
        self._db = bibtexparser.loads(bibtex_str)
        self._ads_cache = ads_cache

    def __getitem__(self, bibkey):
        return BibTexPub(self._db.entries_dict[bibkey],
                         ads_cache=self._ads_cache)


class BibTexPub(BasePub):
    """A publication backed by bibtex."""
    def __init__(self, pub_dict, ads_cache=None):
        super(BibTexPub, self).__init__()
        self._data = pub_dict
        # FIXME does it make sense to embed a connection to ADSBibDB in
        # each bibtex publication instance???
        self._ads_db = ADSBibDB(cache=ads_cache)
        self._ads_pub = None

    def __getitem__(self, key):
        return self._data[key]

    def _get_ads_pub(self):
        """Get the representation for the publication via ADS."""
        if self._ads_pub is None:
            self._ads_pub = self._ads_db[self.bibcode]
        return self._ads_pub

    @property
{'fraction_non_alphanumeric': 0.09628812936420433, 'fraction_numerical': 0.000735023888276369, 'mean_word_length': 2.770083102493075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3184613', 'n_tokens_mistral': 888, 'n_tokens_neox': 830, 'n_words': 230}