Esempio n. 1
0
    def publication_date(self):
        """(Partial) date of publication.

        Returns:
            partial_date (inspire_utils.date.PartialDate): publication date
        """
        try:
            return PartialDate.loads(get_value(self.record, 'imprints.date[0]') or get_publication_date(self.record))
        except ValueError:
            return None
Esempio n. 2
0
 def _get_datetime(value):
     d_value = force_single_element(value.get('d', ''))
     if d_value:
         try:
             date = PartialDate.loads(d_value)
         except ValueError:
             return d_value
         else:
             datetime_ = datetime(year=date.year, month=date.month, day=date.day)
             return datetime_.isoformat()
Esempio n. 3
0
    def publication_date(self):
        """(Partial) date of publication.

        Returns:
            partial_date (inspire_utils.date.PartialDate): publication date
        """
        try:
            return PartialDate.loads(
                get_value(self.record, 'imprints.date[0]')
                or get_publication_date(self.record))
        except ValueError:
            return None
Esempio n. 4
0
    def publication_date(self):
        """(Partial) date of publication.

        Returns:
            partial_date (inspire_utils.date.PartialDate): publication date
        """
        try:
            return PartialDate.loads(
                get_value(self.record, "imprints.date[0]")
                or LiteratureReader(self.record).publication_date)
        except ValueError:
            return None
Esempio n. 5
0
    def get_date(data, doc_type):
        publication_year = BibTexCommonSchema.get_best_publication_info(
            data).get("year")
        thesis_date = get_value(data, "thesis_info.date")
        imprint_date = get_value(data, "imprints.date[0]")

        if doc_type.endswith("thesis"):
            date_choice = thesis_date or publication_year or imprint_date
        else:
            date_choice = publication_year or thesis_date or imprint_date

        if date_choice:
            return PartialDate.loads(str(date_choice))
Esempio n. 6
0
    def get_date(data, doc_type):

        publication_year = BibTexCommonSchema.get_best_publication_info(
            data).get("year")
        thesis_date = get_value(data, "thesis_info.date")
        imprint_date = get_value(data, "imprints.date[0]")
        earliest_date = data.earliest_date
        date_map = {
            "mastersthesis": thesis_date,
            "phdthesis": thesis_date,
            "book": imprint_date,
            "inbook": imprint_date,
        }
        date_choice = date_map.get(
            doc_type) or publication_year or earliest_date
        if date_choice:
            return PartialDate.loads(str(date_choice))
Esempio n. 7
0
def get_date(data, doc_type):
    """Return a publication/thesis/imprint date.

    Args:
      data (dict): INSPIRE literature record to be serialized
      doc_type (text_type): BibTeX document type, as reported by `bibtex_document_type`

    Returns:
        PartialDate: publication date for a record.
    """
    publication_year = get_best_publication_info(data).get('year')
    thesis_date = get_value(data, 'thesis_info.date')
    imprint_date = get_value(data, 'imprints.date[0]')

    if doc_type.endswith('thesis'):
        date_choice = thesis_date or publication_year or imprint_date
    else:
        date_choice = publication_year or thesis_date or imprint_date

    if date_choice:
        return PartialDate.loads(str(date_choice))
Esempio n. 8
0
def get_date(data, doc_type):
    """Return a publication/thesis/imprint date.

    Args:
      data (dict): INSPIRE literature record to be serialized
      doc_type (text_type): BibTeX document type, as reported by `bibtex_document_type`

    Returns:
        PartialDate: publication date for a record.
    """
    publication_year = get_best_publication_info(data).get('year')
    thesis_date = get_value(data, 'thesis_info.date')
    imprint_date = get_value(data, 'imprints.date[0]')

    if doc_type.endswith('thesis'):
        date_choice = thesis_date or publication_year or imprint_date
    else:
        date_choice = publication_year or thesis_date or imprint_date

    if date_choice:
        return PartialDate.loads(str(date_choice))
Esempio n. 9
0
    def get_date(date_node):
        """Extract a date from a date node.

        Returns:
            PartialDate: the parsed date.
        """
        iso_string = date_node.xpath('./@iso-8601-date').extract_first()
        iso_date = PartialDate.loads(iso_string) if iso_string else None

        year = date_node.xpath('string(./year)').extract_first()
        month = date_node.xpath('string(./month)').extract_first()
        day = date_node.xpath('string(./day)').extract_first()
        date_from_parts = PartialDate.from_parts(year, month, day) if year else None

        string_date = date_node.xpath('string(./string-date)').extract_first()
        try:
            parsed_date = PartialDate.parse(string_date)
        except ValueError:
            parsed_date = None

        date = get_first([iso_date, date_from_parts, parsed_date])
        return date
Esempio n. 10
0
    def get_date(date_node):
        """Extract a date from a date node.

        Returns:
            PartialDate: the parsed date.
        """
        iso_string = date_node.xpath('./@iso-8601-date').extract_first()
        iso_date = PartialDate.loads(iso_string) if iso_string else None

        year = date_node.xpath('string(./year)').extract_first()
        month = date_node.xpath('string(./month)').extract_first()
        day = date_node.xpath('string(./day)').extract_first()
        date_from_parts = PartialDate.from_parts(year, month, day) if year else None

        string_date = date_node.xpath('string(./string-date)').extract_first()
        try:
            parsed_date = PartialDate.parse(string_date)
        except ValueError:
            parsed_date = None

        date = get_first([iso_date, date_from_parts, parsed_date])
        return date
Esempio n. 11
0
def test_partial_date_loads():
    expected = PartialDate(1686, 6)

    assert expected == PartialDate.loads('1686-06')
Esempio n. 12
0
# or submit itself to any jurisdiction.
"""Author builder class and related code."""

from __future__ import absolute_import, division, print_function

from inspire_utils.date import normalize_date, PartialDate
from inspire_utils.helpers import force_list
from inspire_utils.name import normalize_name
from inspire_utils.record import get_value

from ..utils import EMPTIES, filter_empty_parameters, load_schema

RANKS = load_schema('elements/rank')['enum']
RANKS.append(None)
INSTITUTION_RANK_TO_PRIORITY = {rank: -idx for (idx, rank) in enumerate(RANKS)}
EARLIEST_DATE = PartialDate.loads('1000')


class AuthorBuilder(object):
    """Author record builder."""
    def __init__(self, author=None, source=None):
        if author is None:
            author = {
                '_collections': ['Authors'],
            }
        self.obj = author
        self.source = source

    def _ensure_field(self, field_name, value):
        if field_name not in self.obj:
            self.obj[field_name] = value
Esempio n. 13
0
def test_loads_validate_dates_month():
    with pytest.raises(ValueError):
        PartialDate.loads('2015-1-10')
Esempio n. 14
0
def test_loads_validate_dates_month_when_month_is_00():
    with pytest.raises(ValueError):
        PartialDate.loads('2015-00')
Esempio n. 15
0
def test_loads_validate_dates_day():
    with pytest.raises(ValueError):
        PartialDate.loads('2015-10-1')