<commit_before>import os
import sys
import textwrap
import time
import xml.etree.ElementTree as ET
from collections import Counter, namedtuple
from operator import itemgetter

from .scopus_api import ScopusAbstract
from .scopus_search import ScopusSearch
from .scopus_affiliation import ScopusAffiliation
from scopus.utils import download, get_content, get_encoded_text, ns

SCOPUS_AUTHOR_DIR = os.path.expanduser('~/.scopus/author')

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


class ScopusAuthor(object):
    @property
    def author_id(self):
        """The scopus id for the author."""
        return self._author_id

    @property
    def orcid(self):
        """The author's ORCID."""
        return self._orcid

    @property
    def hindex(self):
        """The author hindex"""
        return self._hindex

    @property
    def ndocuments(self):
        """Number of documents authored (excludes book chapters and notes)."""
        return self._ndocuments

    @property
    def ncited_by(self):
        """Total number of citing authors."""
        return self._ncited_by

    @property
    def citation_count(self):
        """Total number of citing items."""
        return self._citation_count

    @property
    def ncoauthors(self):
        """Total number of coauthors."""
        return self._ncoauthors

    @property
    def current_affiliation(self):
        """Current affiliation according to scopus."""
        return self._current_affiliation

    @property
    def affiliation_history(self):
        """List of ScopusAffiliation objects."""
        return self._affiliation_history

    @property
    def date_created(self):
        """Date the Scopus record was created."""
        return self._date_created

    @property
    def firstname(self):
        """Author first name."""
        return self._firstname

    @property
    def lastname(self):
        """Author last name."""
        return self._lastname

    @property
    def name(self):
        """Author name."""
        return self._name

    @property
    def scopus_url(self):
        """URL to the author's profile page."""
        return self._scopus_url

    @property
    def citedby_url(self):
        """URL to Scopus page of citing papers."""
        return self._citedby_url

    @property
    def coauthor_url(self):
        """URL to Scopus coauthor page."""
        return self._coauthor_url

    @property
    def subject_areas(self):
        """List of tuples of author subject areas in the form
        (area, frequency, abbreviation, code), where frequency is the
        number of publications in this subject area.
        """
        freqs = self._subject_freq
        return [(a.text, freqs[int(a.get("code"))], a.get("abbrev"), a.get("code"))
                for a in self._area_elements]

    @property
    def publication_history(self):
        """List of tuples of authored publications in the form
        (title, abbreviation, type, issn), where issn is only given
        for journals.
        """
        hist = []
        for pub in self._pub_hist:
            try:
                issn = pub.find("issn").text
            except AttributeError:
                issn = None
            hist.append((pub.find("sourcetitle").text,
                         pub.find("sourcetitle-abbrev").text,
                         pub.get("type"), issn))
        return hist

    def __init__(self, author_id, refresh=False, refresh_aff=False, level=1):
        """Class to represent a Scopus Author query by the scopus-id.

        Parameters
        ----------
        author_id : str or int
            The ID of the author to search for.

        refresh : bool (optional, default=False)
            Whether to refresh the cached file (if it exists) or not.

        refresh_aff : bool (optional, default=False)<commit_msg>Fix bug while reading journal abbrevation<commit_after>import os
import sys
import textwrap
import time
import xml.etree.ElementTree as ET
from collections import Counter, namedtuple
from operator import itemgetter

from .scopus_api import ScopusAbstract
from .scopus_search import ScopusSearch
from .scopus_affiliation import ScopusAffiliation
from scopus.utils import download, get_content, get_encoded_text, ns

SCOPUS_AUTHOR_DIR = os.path.expanduser('~/.scopus/author')

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


class ScopusAuthor(object):
    @property
    def author_id(self):
        """The scopus id for the author."""
        return self._author_id

    @property
    def orcid(self):
        """The author's ORCID."""
        return self._orcid

    @property
    def hindex(self):
        """The author hindex"""
        return self._hindex

    @property
    def ndocuments(self):
        """Number of documents authored (excludes book chapters and notes)."""
        return self._ndocuments

    @property
    def ncited_by(self):
        """Total number of citing authors."""
        return self._ncited_by

    @property
    def citation_count(self):
        """Total number of citing items."""
        return self._citation_count

    @property
    def ncoauthors(self):
        """Total number of coauthors."""
        return self._ncoauthors

    @property
    def current_affiliation(self):
        """Current affiliation according to scopus."""
        return self._current_affiliation

    @property
    def affiliation_history(self):
        """List of ScopusAffiliation objects."""
        return self._affiliation_history

    @property
    def date_created(self):
        """Date the Scopus record was created."""
        return self._date_created

    @property
    def firstname(self):
        """Author first name."""
        return self._firstname

    @property
    def lastname(self):
        """Author last name."""
        return self._lastname

    @property
    def name(self):
        """Author name."""
        return self._name

    @property
    def scopus_url(self):
        """URL to the author's profile page."""
        return self._scopus_url

    @property
    def citedby_url(self):
        """URL to Scopus page of citing papers."""
        return self._citedby_url

    @property
    def coauthor_url(self):
        """URL to Scopus coauthor page."""
        return self._coauthor_url

    @property
    def subject_areas(self):
        """List of tuples of author subject areas in the form
        (area, frequency, abbreviation, code), where frequency is the
        number of publications in this subject area.
        """
        freqs = self._subject_freq
        return [(a.text, freqs[int(a.get("code"))], a.get("abbrev"), a.get("code"))
                for a in self._area_elements]

    @property
    def publication_history(self):
        """List of tuples of authored publications in the form
        (title, abbreviation, type, issn), where issn is only given
        for journals.  abbreviation and issn may be None.
        """
        hist = []
        for pub in self._pub_hist:
            try:
                issn = pub.find("issn").text
            except AttributeError:
                issn = None
            try:
                abbr = pub.find("sourcetitle-abbrev").text
            except AttributeError:
                abbr = None
            hist.append((pub.find("sourcetitle").text, abbr,
                         pub.get("type"), issn))
        return hist

    def __init__(self, author_id, refresh=False, refresh_aff=False, level=1):
        """Class to represent a Scopus Author query by the scopus-id.

        Parameters
        ----------
        author_id : str or int
            The ID of the author to search for.

        refresh : bool (optional, default=False)
            Whether to refresh the cached file (if it exists) or not.

        refresh_aff : bool (optional, default=False)
{'fraction_non_alphanumeric': 0.09577571990359, 'fraction_numerical': 0.00025371051630090067, 'mean_word_length': 2.309823677581864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5360345', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2114, 'n_words': 681}