Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion publication/utils/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_abstracts(self):
continue
yield {"language": lang, "text": text}
except Exception as e:
return []
return

def get_keywords(self):
for lang, keywords in (
Expand Down
95 changes: 95 additions & 0 deletions publication/utils/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,98 @@ def test_get_contribs_with_no_contribs(self):

self.assertEqual(result["names"], [])
self.assertEqual(result["collabs"], [])


class XMLArticleGetAbstractsTest(TestCase):
def test_get_abstracts_with_p_tag(self):
xml_string = """<article xml:lang="en">
<front>
<article-meta>
<abstract>
<title>Abstract</title>
<p>Simple abstract with a p tag.</p>
</abstract>
<trans-abstract xml:lang="pt">
<title>Resumo</title>
<p>Resumo simples com uma tag p.</p>
</trans-abstract>
</article-meta>
</front>
</article>"""

article_xml = _create_xml_article(xml_string)
result = list(article_xml.get_abstracts())

self.assertEqual(
result,
[
{"language": "en", "text": "Simple abstract with a p tag."},
{"language": "pt", "text": "Resumo simples com uma tag p."},
],
)

def test_get_abstracts_with_sections(self):
xml_string = """<article xml:lang="en">
<front>
<article-meta>
<abstract>
<title>Abstract</title>
<sec><title>Objective:</title><p>obj text.</p></sec>
<sec><title>Method:</title><p>method text.</p></sec>
</abstract>
</article-meta>
</front>
</article>"""

article_xml = _create_xml_article(xml_string)
result = list(article_xml.get_abstracts())

self.assertEqual(len(result), 1)
self.assertEqual(result[0]["language"], "en")
self.assertEqual(
result[0]["text"], "Objective: obj text. Method: method text."
)

def test_get_abstracts_without_p_wrapper_regression_issue_1031(self):
"""Regression test for scieloorg/scms-upload#1031: legacy migrated
XML (e.g. URY collection) may have abstract text sitting directly
under <abstract>/<trans-abstract>, not wrapped in <p>. Extraction
for this case lives in packtools (scieloorg/packtools#1272,
released in 4.16.11); this test only confirms it comes through
get_abstracts() transparently."""
xml_string = """<article xml:lang="es">
<front>
<article-meta>
<abstract>
<title>Resumen:</title> Texto do resumo sem tag p.
</abstract>
<trans-abstract xml:lang="en">
<title>Abstract:</title> Abstract text without a p tag.
</trans-abstract>
</article-meta>
</front>
</article>"""

article_xml = _create_xml_article(xml_string)
result = list(article_xml.get_abstracts())

self.assertEqual(
result,
[
{"language": "es", "text": "Texto do resumo sem tag p."},
{"language": "en", "text": "Abstract text without a p tag."},
],
)

def test_get_abstracts_with_no_abstract(self):
xml_string = """<article xml:lang="en">
<front>
<article-meta>
</article-meta>
</front>
</article>"""

article_xml = _create_xml_article(xml_string)
result = list(article_xml.get_abstracts())

self.assertEqual(result, [])
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ iso639-lang==2.6.3 # Mantendo versão maior
# SciELO Specific Packages
# ========================================
# Using specific versions for stability
-e git+https://github.com/scieloorg/packtools.git@4.16.8#egg=packtools
-e git+https://github.com/scieloorg/packtools.git@4.16.11#egg=packtools
-e git+https://github.com/scieloorg/scielo_scholarly_data#egg=scielo_scholarly_data
-e git+https://github.com/scieloorg/opac_schema.git@v2.66#egg=opac_schema
-e git+https://github.com/scieloorg/scielo_migration.git@1.10.8#egg=scielo_classic_website
Expand Down