Skip to content

Commit 8c9508d

Browse files
committed
Fix get_journal() when journal is a KGProxy (issue + volume case)
1 parent 12ac0f2 commit 8c9508d

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

builder/additional_methods/ScholarlyArticle.py.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
volume = issue_or_volume
1010
issue = None
1111
journal = volume.is_part_of
12-
assert isinstance(journal, Periodical)
12+
if not isinstance(journal, Periodical):
13+
journal = journal.resolve(client, release_status=self.release_status)
1314
retval = [journal]
1415
if with_volume:
1516
retval.append(volume)
@@ -38,6 +39,5 @@
3839
title += "."
3940
journal_name = journal.name if journal else ""
4041
volume_number = f"{volume.volume_number}: " if (volume and volume.volume_number != "placeholder") else ""
41-
return (
42-
f"{author_str} ({self.publication_date.year}). {title} {journal_name}, {volume_number}{self.pagination or ''}."
43-
)
42+
year = self.publication_date.year if self.publication_date else "unpublished?"
43+
return f"{author_str} ({year}). {title} {journal_name}, {volume_number}{self.pagination or ''}."

fairgraph/openminds/publications/scholarly_article.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def get_journal(self, client, with_volume=False, with_issue=False):
114114
volume = issue_or_volume
115115
issue = None
116116
journal = volume.is_part_of
117-
assert isinstance(journal, Periodical)
117+
if not isinstance(journal, Periodical):
118+
journal = journal.resolve(client, release_status=self.release_status)
118119
retval = [journal]
119120
if with_volume:
120121
retval.append(volume)
@@ -143,4 +144,5 @@ def get_citation_string(self, client):
143144
title += "."
144145
journal_name = journal.name if journal else ""
145146
volume_number = f"{volume.volume_number}: " if (volume and volume.volume_number != "placeholder") else ""
146-
return f"{author_str} ({self.publication_date.year}). {title} {journal_name}, {volume_number}{self.pagination or ''}."
147+
year = self.publication_date.year if self.publication_date else "unpublished?"
148+
return f"{author_str} ({year}). {title} {journal_name}, {volume_number}{self.pagination or ''}."

test/test_openminds_publication.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import datetime
2+
import pytest
23
import fairgraph.openminds.core as omcore
34
import fairgraph.openminds.publications as ompub
5+
from fairgraph.kgproxy import KGProxy
6+
from fairgraph.caching import object_cache
47

58

69
def test_get_journal():
@@ -25,6 +28,34 @@ def test_get_journal():
2528
assert article.get_citation_string(client=None) == expected
2629

2730

31+
def test_get_journal_with_issue_proxy_journal():
32+
"""When data comes from the KG, volume.is_part_of is a KGProxy, not a resolved Periodical.
33+
get_journal() should resolve the proxy rather than failing the isinstance assertion."""
34+
periodical_id = "https://kg.ebrains.eu/api/instances/00000000-0000-0000-0000-000000000001"
35+
jphysiol = ompub.Periodical(name="The Journal of Physiology", id=periodical_id)
36+
object_cache[periodical_id] = jphysiol
37+
38+
try:
39+
journal_proxy = KGProxy(ompub.Periodical, periodical_id)
40+
volume = ompub.PublicationVolume(is_part_of=journal_proxy, volume_number="117")
41+
issue = ompub.PublicationIssue(is_part_of=volume, issue_number="4")
42+
article = ompub.ScholarlyArticle(
43+
name="A quantitative description of membrane current and its application to conduction and excitation in nerve",
44+
authors=[
45+
omcore.Person(given_name="AL", family_name="Hodgkin"),
46+
omcore.Person(given_name="AF", family_name="Huxley"),
47+
],
48+
is_part_of=issue,
49+
publication_date=datetime.date(1952, 8, 1),
50+
pagination="500–44",
51+
)
52+
assert article.get_journal(client=None) == jphysiol
53+
assert article.get_journal(client=None, with_volume=True) == (jphysiol, volume)
54+
assert article.get_journal(client=None, with_volume=True, with_issue=True) == (jphysiol, volume, issue)
55+
finally:
56+
del object_cache[periodical_id]
57+
58+
2859
def test_get_journal_no_issue():
2960
jphysiol = ompub.Periodical(name="The Journal of Physiology")
3061
volume = ompub.PublicationVolume(is_part_of=jphysiol, volume_number="117")

0 commit comments

Comments
 (0)