<commit_before>import os
from collections import namedtuple
from datetime import datetime
from json import loads

from scopus.utils import get_content

CITATION_OVERVIEW_DIR = os.path.expanduser('~/.scopus/citation_overview')

if not os.path.exists(CITATION_OVERVIEW_DIR):
    os.makedirs(CITATION_OVERVIEW_DIR)


class CitationOverview(object):

    @property
    def authors(self):
        """A list of namedtuples storing author information,
        where each namedtuple corresponds to one author.
        The information in each namedtuple is (name surname initials id url).
        All entries are strings.
        """
        out = []
        order = 'name surname initials id url'
        auth = namedtuple('Author', order)
        for author in self.citeInfoMatrix.get('author'):
            author = {k.split(":", 1)[-1]: v for k, v in author.items()}
            new = auth(name=author.get('index-name'),
                       surname=author.get('surname'),
                       initials=author.get('initials'),
                       id=author.get('authid'),
                       url=author.get('author-url'))
            out.append(new)
        return out

    @property
    def cc(self):
        """List of tuples of yearly number of citations
        for specified years."""
        _years = range(self.start, self.end+1)
        return list(zip(_years, [d.get('$') for d in self.citeInfoMatrix['cc']]))

    @property
    def citationType_long(self):
        """Type (long version) of the abstract (e.g. article, review)."""
        return self.citeInfoMatrix.get('citationType', {}).get('$')

    @property
    def citationType_short(self):
        """Type (short version) of the abstract (e.g. ar, re)."""
        return self.citeInfoMatrix.get('citationType', {}).get('@code')

    @property
    def doi(self):
        """Document Object Identifier (DOI) of the abstract."""
        return self.identifierlegend.get('doi')

    @property
    def endingPage(self):
        """Ending page."""
        return self.citeInfoMatrix.get('endingPage')

    @property
    def h_index(self):
        """h-index of ciations of the abstract (according to Scopus)."""
        return self.hindex<commit_msg>Fix AttributeError when there are no total citations<commit_after>import os
from collections import namedtuple
from datetime import datetime
from json import loads

from scopus.utils import get_content

CITATION_OVERVIEW_DIR = os.path.expanduser('~/.scopus/citation_overview')

if not os.path.exists(CITATION_OVERVIEW_DIR):
    os.makedirs(CITATION_OVERVIEW_DIR)


class CitationOverview(object):

    @property
    def authors(self):
        """A list of namedtuples storing author information,
        where each namedtuple corresponds to one author.
        The information in each namedtuple is (name surname initials id url).
        All entries are strings.
        """
        out = []
        order = 'name surname initials id url'
        auth = namedtuple('Author', order)
        for author in self.citeInfoMatrix.get('author'):
            author = {k.split(":", 1)[-1]: v for k, v in author.items()}
            new = auth(name=author.get('index-name'),
                       surname=author.get('surname'),
                       initials=author.get('initials'),
                       id=author.get('authid'),
                       url=author.get('author-url'))
            out.append(new)
        return out

    @property
    def cc(self):
        """List of tuples of yearly number of citations
        for specified years."""
        _years = range(self.start, self.end+1)
        try:
            return list(zip(_years, [d.get('$') for d in self.citeInfoMatrix['cc']]))
        except AttributeError:  # No citations
            list(zip(_years, [0]*len(_years)))

    @property
    def citationType_long(self):
        """Type (long version) of the abstract (e.g. article, review)."""
        return self.citeInfoMatrix.get('citationType', {}).get('$')

    @property
    def citationType_short(self):
        """Type (short version) of the abstract (e.g. ar, re)."""
        return self.citeInfoMatrix.get('citationType', {}).get('@code')

    @property
    def doi(self):
        """Document Object Identifier (DOI) of the abstract."""
        return self.identifierlegend.get('doi')

    @property
    def endingPage(self):
        """Ending page."""
        return self.citeInfoMatrix.get('endingPage')

    @property
    def h_index(self):
        """h-index of ciations of the abstract (according to Scopus)."""
        return self.hindex
{'fraction_non_alphanumeric': 0.12238219895287958, 'fraction_numerical': 0.0015270506108202443, 'mean_word_length': 2.5134099616858236, 'pattern_counts': {'":': 2, '<': 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': '4305197', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1259, 'n_words': 367}