Ver código fonte

Fix component PubMed (#2195)

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.11.0
H 1 ano atrás
pai
commit
1d2c081710
Nenhuma conta vinculada ao e-mail do autor do commit
1 arquivos alterados com 11 adições e 15 exclusões
  1. 11
    15
      agent/component/pubmed.py

+ 11
- 15
agent/component/pubmed.py Ver arquivo

# #
from abc import ABC from abc import ABC
from Bio import Entrez from Bio import Entrez
import re
import pandas as pd import pandas as pd
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from agent.settings import DEBUG from agent.settings import DEBUG
try: try:
Entrez.email = self._param.email Entrez.email = self._param.email
pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList'] pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList']
pubmedcnt = ET.fromstring(
Entrez.efetch(db='pubmed', id=",".join(pubmedids), retmode="xml").read().decode("utf-8"))
pubmed_res = []
for child in pubmedcnt.findall("PubmedArticle"):
if child.find("MedlineCitation").find("Article").find("ArticleTitle").text:
title_tmp = 'Title:' + child.find("MedlineCitation").find("Article").find("ArticleTitle").text
else:
title_tmp = 'Title:' + "".join(
[childtitle.text for childtitle in
child.find("MedlineCitation").find("Article").find("ArticleTitle")])
url_tmp = '\nUrl:<a href=" https://pubmed.ncbi.nlm.nih.gov/' + child.find("MedlineCitation").find(
"PMID").text + '">' + '</a>'
abstract_tmp = '\nAbstract:' + child.find("MedlineCitation").find("Article").find("Abstract").find(
"AbstractText").text
pubmed_res.append({"content": title_tmp + url_tmp + abstract_tmp})
pubmedcnt = ET.fromstring(re.sub(r'<(/?)b>|<(/?)i>', '', Entrez.efetch(db='pubmed', id=",".join(pubmedids),
retmode="xml").read().decode(
"utf-8")))
pubmed_res = [{"content": 'Title:' + child.find("MedlineCitation").find("Article").find(
"ArticleTitle").text + '\nUrl:<a href=" https://pubmed.ncbi.nlm.nih.gov/' + child.find(
"MedlineCitation").find("PMID").text + '">' + '</a>\n' + 'Abstract:' + (
child.find("MedlineCitation").find("Article").find("Abstract").find(
"AbstractText").text if child.find("MedlineCitation").find(
"Article").find("Abstract") else "No abstract available")} for child in
pubmedcnt.findall("PubmedArticle")]
except Exception as e: except Exception as e:
return PubMed.be_output("**ERROR**: " + str(e)) return PubMed.be_output("**ERROR**: " + str(e))



Carregando…
Cancelar
Salvar