Skip to content

fix(models): Corrige o idioma das versões de tradução dos resumos#1076

Merged
robertatakenaka merged 1 commit intoscieloorg:masterfrom
robertatakenaka:corrige_sps_models_v2_abstract
Feb 2, 2026
Merged

fix(models): Corrige o idioma das versões de tradução dos resumos#1076
robertatakenaka merged 1 commit intoscieloorg:masterfrom
robertatakenaka:corrige_sps_models_v2_abstract

Conversation

@robertatakenaka
Copy link
Copy Markdown
Member

@robertatakenaka robertatakenaka commented Feb 2, 2026

Descrição

Esta alteração aprimora a extração de resumos no módulo XMLAbstracts. Anteriormente, o idioma era definido de forma estática através de self.lang. Agora, o código tenta primeiro obter o idioma diretamente do atributo xml:lang do nó XML específico e utiliza o self.lang apenas como valor padrão (fallback).

Motivação

Em documentos XML JATS, é comum haver múltiplos resumos (ex: original e traduções). Cada nó <abstract> pode carregar seu próprio atributo de idioma. Esta mudança garante que a classe Abstract seja instanciada com o idioma correto de cada nó, evitando que traduções sejam marcadas incorretamente com o idioma principal do artigo.

Mudanças Principais

  • Local: packtools/sps/models/v2/abstract.py
  • Lógica: Implementação de busca do atributo {http://www.w3.org/XML/1998/namespace}lang via XPath/LXML antes de recorrer ao atributo de classe.

Tipo de Alteração

  • Bug fix (correção de uma funcionalidade que não estava operando corretamente)
  • New feature (nova funcionalidade)
  • Breaking change (correção ou funcionalidade que pode quebrar compatibilidade)
  • Documentation (mudança em documentação)

Como testar?

  1. Utilize um XML que contenha resumos em múltiplos idiomas (ex: pt e en).
  2. Instancie XMLAbstracts.
  3. Verifique se a lista de objetos retornada por self.xmltree.xpath(xpath) reflete os idiomas individuais de cada nó e não apenas o idioma global definido no construtor.

Copilot AI review requested due to automatic review settings February 2, 2026 18:03
@robertatakenaka robertatakenaka changed the title fix(models): ix: ensure abstract language is correctly identified fro… fix(models): Corrige o idioma das versões de tradução dos resumos Feb 2, 2026
@robertatakenaka robertatakenaka merged commit 6a96c39 into scieloorg:master Feb 2, 2026
6 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjusts abstract language detection so each abstract can be tagged with the correct language instead of always using the document-level xml:lang.

Changes:

  • Update XMLAbstracts.get_abstracts() to prefer the abstract node’s xml:lang over XMLAbstracts.lang when building Abstract objects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 241 to +242
node,
self.lang,
node.get("{http://www.w3.org/XML/1998/namespace}lang") or self.lang,
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The lang selection here still fails for abstracts inside a when the element itself does not have xml:lang (xml:lang is inherited in XML). In that common case (see file header example and tests/samples/article-abstract-en-sub-articles-pt-es.xml), this code falls back to self.lang (main article language) and mislabels the sub-article abstract language.

Consider deriving the effective language from the closest ancestor-or-self that declares xml:lang (e.g., via XPath ancestor-or-self::*[@xml:lang][1]) and only then falling back to the document/root language.

Copilot uses AI. Check for mistakes.
Comment on lines 239 to +242
for node in self.xmltree.xpath(xpath):
abstract = Abstract(
node,
self.lang,
node.get("{http://www.w3.org/XML/1998/namespace}lang") or self.lang,
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

This change introduces/updates language resolution behavior for XMLAbstracts.get_abstracts, but there are currently no tests covering XMLAbstracts (only Abstract.text). Adding a unit test that parses a small XML with both and a … case would prevent regressions in language detection.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants