-
Notifications
You must be signed in to change notification settings - Fork 23
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
Rossi-Luciano
wants to merge
2
commits into
scieloorg:master
Choose a base branch
from
Rossi-Luciano:convert_to_scielo_citation_format
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.