From 55d7398b7efdca47adb6ac40523e24f7e10361ea Mon Sep 17 00:00:00 2001 From: Luciano Rossi Date: Tue, 3 Dec 2024 13:13:25 -0300 Subject: [PATCH 1/2] Adiciona 'SciELOCitationConverter' --- .../sps/formats/scielo_citation_index.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packtools/sps/formats/scielo_citation_index.py diff --git a/packtools/sps/formats/scielo_citation_index.py b/packtools/sps/formats/scielo_citation_index.py new file mode 100644 index 000000000..d99cbe27b --- /dev/null +++ b/packtools/sps/formats/scielo_citation_index.py @@ -0,0 +1,50 @@ +from lxml import etree as ET + +from packtools.sps.models.article_and_subarticles import ArticleAndSubArticles + + +class SciELOCitationConverter: + def __init__(self, xml_tree): + self.xml_tree = xml_tree + self.article = ArticleAndSubArticles(self.xml_tree) + + def create_articles_tag(self): + if not (dtd_version := self.article.main_dtd_version): + raise ValueError("dtd-version is required") + + NSMAP = {"xsi": "http://www.w3.org/2001/XMLSchema-instance"} + schema_location = ( + "https://raw.githubusercontent.com/scieloorg/articles_meta/" + "master/tests/xsd/scielo_sci/ThomsonReuters_publishing.xsd" + ) + articles = ET.Element( + "articles", + nsmap=NSMAP, + attrib={ + "{http://www.w3.org/2001/XMLSchema-instance}schemaLocation": schema_location, + "dtd-version": dtd_version + } + ) + + return articles + + def create_article_tag(self): + if not (article_lang := self.article.main_lang): + raise ValueError("article lang is required") + if not (article_type := self.article.main_article_type): + raise ValueError("article type is required") + article = ET.Element( + "article", + attrib={ + "lang_id": article_lang, + "article-type": article_type + } + ) + + return article + + def create_article_citation_index(self): + article_citation_index = self.create_articles_tag() + article_citation_index.append(self.create_article_tag()) + + return article_citation_index From f478e9a548d909ce3253a552e30ffae3039ec861 Mon Sep 17 00:00:00 2001 From: Luciano Rossi Date: Tue, 3 Dec 2024 13:13:43 -0300 Subject: [PATCH 2/2] Adiciona testes --- .../sps/formats/test_scielo_citation_index.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/sps/formats/test_scielo_citation_index.py diff --git a/tests/sps/formats/test_scielo_citation_index.py b/tests/sps/formats/test_scielo_citation_index.py new file mode 100644 index 000000000..bf72e9758 --- /dev/null +++ b/tests/sps/formats/test_scielo_citation_index.py @@ -0,0 +1,55 @@ +from unittest import TestCase +import lxml.etree as ET + +from packtools.sps.utils import xml_utils +from packtools.sps.formats.scielo_citation_index import SciELOCitationConverter + + +class SciELOCitationConverterTest(TestCase): + def setUp(self): + self.xml_tree = xml_utils.get_xml_tree('tests/sps/fixtures/standard_scielo_xml/S0080-62342022000100445_JATS.xml') + + def test_articles(self): + self.maxDiff = None + expected = ( + '' + ) + obtained = SciELOCitationConverter(self.xml_tree).create_articles_tag() + + obtained_str = ET.tostring(obtained, encoding="utf-8").decode("utf-8") + + self.assertEqual(expected, obtained_str) + + def test_article(self): + self.maxDiff = None + expected = ( + '
' + ) + obtained = SciELOCitationConverter(self.xml_tree).create_article_tag() + + obtained_str = ET.tostring(obtained, encoding="utf-8").decode("utf-8") + + self.assertEqual(expected, obtained_str) + + def test_article_citation_index(self): + self.maxDiff = None + expected = ( + '' + '
' + '' + ) + obtained = SciELOCitationConverter(self.xml_tree).create_article_citation_index() + + obtained_str = ET.tostring(obtained, encoding="utf-8").decode("utf-8") + + self.assertEqual(expected, obtained_str) + + + +