Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Create SciELO Citation Index converter #770

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
50 changes: 50 additions & 0 deletions packtools/sps/formats/scielo_citation_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from lxml import etree as ET

from packtools.sps.models.article_and_subarticles import ArticleAndSubArticles


class SciELOCitationConverter:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano não precisa usar classes como no articlemeta. Pode ser funções como tem sido feito. Também não precisa se limitar a uma classe, lembrando que 1 classe representa objetos. Então, pode-se ter uma classe para autores, para afiliações, etc.

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano vamos considerar que 1 artigo por XML, o usuário da classe ou do módulo, montará o Xml inteiro.

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
55 changes: 55 additions & 0 deletions tests/sps/formats/test_scielo_citation_index.py
Original file line number Diff line number Diff line change
@@ -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 = (
'<articles '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'xsi:schemaLocation="https://raw.githubusercontent.com/scieloorg/articles_meta/master/tests/xsd/scielo_sci/ThomsonReuters_publishing.xsd" '
'dtd-version="1.1"/>'
)
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 = (
'<article lang_id="en" article-type="research-article"/>'
)
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 = (
'<articles '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
'xsi:schemaLocation="https://raw.githubusercontent.com/scieloorg/articles_meta/master/tests/xsd/scielo_sci/ThomsonReuters_publishing.xsd" '
'dtd-version="1.1">'
'<article lang_id="en" article-type="research-article"/>'
'</articles>'
)
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)