Skip to content

Commit 8fdcda1

Browse files
committed
Retrieve formatted citation
Addresses #423.
1 parent 067330d commit 8fdcda1

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

scholarly/data_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class BibEntry(TypedDict, total=False):
119119
:param number: NA number of a publication
120120
:param pages: range of pages
121121
:param publisher: The publisher's name
122+
:param citation: Formatted citation string, usually containing journal name, volume and page numbers (source: AUTHOR_PUBLICATION_ENTRY)
122123
:param pub_url: url of the website providing the publication
123124
"""
124125
pub_type: str
@@ -133,6 +134,7 @@ class BibEntry(TypedDict, total=False):
133134
number: str
134135
pages: str
135136
publisher: str
137+
citation: str
136138

137139

138140
class Mandate(TypedDict, total=False):

scholarly/publication_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ def _citation_pub(self, __data, publication: Publication):
127127
and len(year.text) > 0):
128128
publication['bib']['pub_year'] = year.text.strip()
129129

130+
author_citation = __data.find_all('div', class_='gs_gray')
131+
try:
132+
citation = author_citation[1].text
133+
except IndexError:
134+
citation = ""
135+
publication['bib']['citation'] = citation
136+
130137
return publication
131138

132139
def get_publication(self, __data, pubtype: PublicationSource)->Publication:

test_module.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,22 @@ def test_full_title(self):
501501
self.assertEqual(pub['bib']['title'],
502502
u'Evaluation of toxicity of Dichlorvos (Nuvan) to fresh water fish Anabas testudineus and possible modulation by crude aqueous extract of Andrographis paniculata: A preliminary investigation')
503503

504+
self.assertEqual(pub['bib']['citation'], "")
505+
506+
for i in range(len(author['publications'])):
507+
if author['publications'][i]['author_pub_id'] == 'Xxjj6IsAAAAJ:ldfaerwXgEUC':
508+
pub_index = i
509+
self.assertGreaterEqual(i, 0)
510+
# elided title
511+
self.assertEqual(author['publications'][pub_index]['bib']['title'],
512+
u'Evaluation of toxicity of Dichlorvos (Nuvan) to fresh water fish Anabas testudineus and possible modulation by crude aqueous extract of Andrographis paniculata: A preliminary …')
513+
# full text
514+
pub = scholarly.fill(author['publications'][pub_index])
515+
self.assertEqual(pub['bib']['title'],
516+
u'Evaluation of toxicity of Dichlorvos (Nuvan) to fresh water fish Anabas testudineus and possible modulation by crude aqueous extract of Andrographis paniculata: A preliminary …')
517+
518+
self.assertEqual(pub['bib']['citation'], "Journal of Fisheries and Life Sciences 5 (2), 74-84, 2020")
519+
504520
def test_author_organization(self):
505521
"""
506522
"""
@@ -590,6 +606,7 @@ def test_related_articles_from_author(self):
590606
scholarly.fill(author, sections=['basics', 'publications'])
591607
pub = author['publications'][0]
592608
self.assertEqual(pub['bib']['title'], 'Prospect theory: An analysis of decision under risk')
609+
self.assertEqual(pub['bib']['citation'], 'Handbook of the fundamentals of financial decision making: Part I, 99-127, 2013')
593610
related_articles = scholarly.get_related_articles(pub)
594611
# Typically, the same publication is returned as the most related article
595612
same_article = next(related_articles)

0 commit comments

Comments
 (0)