Skip to content

Commit 5010b37

Browse files
authored
Merge pull request #86 from mpacer/neater_elements
Neater elements
2 parents 61b25b3 + 6e4745c commit 5010b37

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

allofplos/article_class.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def journal(self):
939939
journal = Journal.doi_to_journal(self.doi)
940940
else:
941941
journal_meta = self.root.xpath('/article/front/journal-meta')[0]
942-
journal = Journal(self.doi, journal_meta).parse_plos_journal()
942+
journal = str(Journal(journal_meta))
943943
return journal
944944

945945
@property
@@ -1015,12 +1015,11 @@ def revdate(self):
10151015
dates = self.get_dates()
10161016
return dates['updated']
10171017

1018+
@property
10181019
def license(self):
10191020
"""Return dictionary of CC license information from the license field."""
10201021
permissions = self.root.xpath('/article/front/article-meta/permissions')[0]
1021-
lic = License(permissions, self.doi)
1022-
1023-
return lic.license()
1022+
return dict(License(permissions, self.doi))
10241023

10251024
@property
10261025
def contributors(self):

allofplos/elements/journal.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
class Journal():
55
"""For parsing the journal name element of articles, as well as converting DOIs to journal names."""
66

7-
def __init__(self, doi, journal_meta_element):
7+
def __init__(self, journal_meta_element):
88
"""Initialize an instance of the journal class."""
9-
self.doi = doi
109
self.element = journal_meta_element
1110

1211
@staticmethod
@@ -29,6 +28,11 @@ def doi_to_journal(doi):
2928
])
3029

3130
return next(value for key, value in journal_map.items() if key in doi)
31+
32+
def __str__(self):
33+
"""Provides str(Journal()) style access to Journal().parse_plos_journal.
34+
"""
35+
return self.parse_plos_journal()
3236

3337
def parse_plos_journal(self, caps_fixed=True):
3438
"""For an individual PLOS article, get the journal it was published in from the article XML.

allofplos/elements/license.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ def __init__(self, permissions_element, doi):
2323
"""Initialize an instance of the license class."""
2424
self.element = permissions_element
2525
self.doi = doi
26-
26+
27+
def __iter__(self):
28+
"""Provides the ability to cast License as a dictionary using
29+
dict(License(…)).
30+
31+
Returns a generator of (key, value) tuples, which when passed into
32+
dict(), will create the appropriate dictionary.
33+
"""
34+
return ((key, value) for key, value in self.license.items())
35+
36+
@property
2737
def license(self):
28-
"""Return dictionary of CC license information from the license field."""
38+
"""Dictionary of CC license information from the article license field.
39+
"""
2940
lic = ''
3041
cc_link = ''
3142
copy_year = ''

allofplos/tests/test_unittests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def test_class_doi1(self):
105105
self.assertEqual(article.url, "http://journals.plos.org/plosone/article/file?id=10.1371/journal.pone.0185809&type=manuscript", 'url does not transform correctly for {}'.format(article.doi))
106106
self.assertEqual(article.word_count, 6646, 'word_count does not transform correctly for {}'.format(article.doi))
107107
self.assertEqual(article.taxonomy, {'heading': [('Research Article',)], 'Discipline-v3': [('Biology and life sciences', 'Organisms', 'Eukaryota', 'Animals', 'Invertebrates', 'Arthropoda', 'Insects'), ('Earth sciences', 'Seasons'), ('Earth sciences', 'Geography', 'Human geography', 'Land use'), ('Social sciences', 'Human geography', 'Land use'), ('Biology and life sciences', 'Ecology', 'Ecological metrics', 'Biomass (ecology)'), ('Ecology and environmental sciences', 'Ecology', 'Ecological metrics', 'Biomass (ecology)'), ('Ecology and environmental sciences', 'Conservation science'), ('Biology and life sciences', 'Ecology', 'Plant ecology', 'Plant communities', 'Grasslands'), ('Ecology and environmental sciences', 'Ecology', 'Plant ecology', 'Plant communities', 'Grasslands'), ('Biology and life sciences', 'Plant science', 'Plant ecology', 'Plant communities', 'Grasslands'), ('Ecology and environmental sciences', 'Terrestrial environments', 'Grasslands'), ('Biology and life sciences', 'Ecology', 'Ecological metrics', 'Species diversity'), ('Ecology and environmental sciences', 'Ecology', 'Ecological metrics', 'Species diversity'), ('Biology and life sciences', 'Organisms', 'Eukaryota', 'Plants', 'Herbs')]}, "Taxonomy not retrieved as expected for {0}".format(article.doi))
108+
self.assertEqual(article.license, {'license': 'CC-BY 4.0', 'license_link': 'https://creativecommons.org/licenses/by/4.0/', 'copyright_holder': 'Hallmann et al', 'copyright_year': 2017}, 'license does not transform correctly for {}'.format(article.doi))
108109

109110
def test_example_doi(self):
110111
"""Tests the methods and properties of the Article class
@@ -183,6 +184,7 @@ def test_example_doi2(self):
183184
self.assertEqual(article.type_, "retraction", 'type_ does not transform correctly for {}'.format(article.doi))
184185
self.assertEqual(article.url[:100], "http://journals.plos.org/plosone/article/file?id=10.1371/annotation/3155a3e9-5fbe-435c-a07a-e9a4846e", 'url does not transform correctly for {}'.format(article.doi))
185186
self.assertEqual(article.word_count, 129, 'word_count does not transform correctly for {}'.format(article.doi))
187+
self.assertEqual(article.license, {'license': 'CC-BY 4.0', 'license_link': 'https://creativecommons.org/licenses/by/4.0/', 'copyright_holder': '', 'copyright_year': 2012}, 'license does not transform correctly for {}'.format(article.doi))
186188

187189
def test_proofs(self):
188190
"""Tests whether uncorrected proofs and VOR updates are being detected correctly."""

0 commit comments

Comments
 (0)