def test_get_page_artid_handles_page_range(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] record = { 'publication_info': [ { 'page_end': '588', 'page_start': '579', }, ], } assert validate(record['publication_info'], subschema) is None expected = '579-588' result = LiteratureReader(record).get_page_artid() assert expected == result
def test_keywords(): schema = load_schema('hep') subschema = schema['properties']['keywords'] record = { 'keywords': [ { 'schema': 'INSPIRE', 'value': 'CKM matrix', }, ], } assert validate(record['keywords'], subschema) is None expected = ['CKM matrix'] result = LiteratureReader(record).keywords assert expected == result
def test_get_page_range_not_artid(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] record = { 'publication_info': [ { 'page_end': '432', 'page_start': '402', "artid": "18184", }, ], } assert validate(record['publication_info'], subschema) is None expected = '402-432' result = LiteratureReader(record).get_page_artid() assert expected == result
def test_arxiv_id(): schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] record = { 'arxiv_eprints': [ { 'categories': [ 'hep-th', 'hep-ph', ], 'value': '1612.08928', }, ], } assert validate(record['arxiv_eprints'], subschema) is None expected = '1612.08928' result = LiteratureReader(record).arxiv_id assert expected == result
def test_is_published(): schema = load_schema('hep') dois_schema = schema['properties']['dois'] publication_info_schema = schema['properties']['publication_info'] record = { 'dois': [ { 'value': '10.1016/0029-5582(61)90469-2' }, ], 'publication_info': [ { 'journal_title': 'Nucl.Phys.' }, ], } assert validate(record['dois'], dois_schema) is None assert validate(record['publication_info'], publication_info_schema) is None assert LiteratureReader(record).is_published
def test_inspire_categories(): schema = load_schema('hep') subschema = schema['properties']['inspire_categories'] record = { 'inspire_categories': [ { 'term': 'Experiment-HEP' }, { 'term': 'Quantum Physics' }, { 'term': 'Condensed Matter' }, ], } assert validate(record['inspire_categories'], subschema) is None expected = ['Experiment-HEP', 'Quantum Physics', 'Condensed Matter'] result = LiteratureReader(record).inspire_categories assert expected == result
def get_note(self, data): notices = ("erratum", "addendum") entries = [ entry for entry in get_value(data, "publication_info", []) if entry.get("material") in notices ] if not entries: return None note_strings = [ text_type("{field}: {journal} {volume}, {pages} {year}").format( field=entry["material"].title(), journal=entry.get("journal_title"), volume=entry.get("journal_volume"), pages=LiteratureReader.get_page_artid_for_publication_info( entry, "--"), year="({})".format(entry["year"]) if "year" in entry else "", ).strip() for entry in entries ] note_string = "[" + ", ".join(note_strings) + "]" note_string = re.sub(" +", " ", note_string) return latex_encode(re.sub(",,", ",", note_string))
def get_pages(self, data): return LiteratureReader.get_page_artid_for_publication_info( BibTexCommonSchema.get_best_publication_info(data), "--")
def doi(self): """Get DOI of a record.""" return LiteratureReader(self.record).doi
def journal_title(self): """Get record's journal title.""" return LiteratureReader(self.record).journal_title