H commited on
Commit
b4db54e
·
1 Parent(s): dc34855

Fix component PubMed (#2192)

Browse files

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

Files changed (1) hide show
  1. agent/component/pubmed.py +13 -5
agent/component/pubmed.py CHANGED
@@ -49,11 +49,19 @@ class PubMed(ComponentBase, ABC):
49
  pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList']
50
  pubmedcnt = ET.fromstring(
51
  Entrez.efetch(db='pubmed', id=",".join(pubmedids), retmode="xml").read().decode("utf-8"))
52
- pubmed_res = [{"content": 'Title:' + child.find("MedlineCitation").find("Article").find(
53
- "ArticleTitle").text + '\nUrl:<a href=" https://pubmed.ncbi.nlm.nih.gov/' + child.find(
54
- "MedlineCitation").find("PMID").text + '">' + '</a>\n' + 'Abstract:' + child.find(
55
- "MedlineCitation").find("Article").find("Abstract").find("AbstractText").text} for child in
56
- pubmedcnt.findall("PubmedArticle")]
 
 
 
 
 
 
 
 
57
  except Exception as e:
58
  return PubMed.be_output("**ERROR**: " + str(e))
59
 
 
49
  pubmedids = Entrez.read(Entrez.esearch(db='pubmed', retmax=self._param.top_n, term=ans))['IdList']
50
  pubmedcnt = ET.fromstring(
51
  Entrez.efetch(db='pubmed', id=",".join(pubmedids), retmode="xml").read().decode("utf-8"))
52
+ pubmed_res = []
53
+ for child in pubmedcnt.findall("PubmedArticle"):
54
+ if child.find("MedlineCitation").find("Article").find("ArticleTitle").text:
55
+ title_tmp = 'Title:' + child.find("MedlineCitation").find("Article").find("ArticleTitle").text
56
+ else:
57
+ title_tmp = 'Title:' + "".join(
58
+ [childtitle.text for childtitle in
59
+ child.find("MedlineCitation").find("Article").find("ArticleTitle")])
60
+ url_tmp = '\nUrl:<a href=" https://pubmed.ncbi.nlm.nih.gov/' + child.find("MedlineCitation").find(
61
+ "PMID").text + '">' + '</a>'
62
+ abstract_tmp = '\nAbstract:' + child.find("MedlineCitation").find("Article").find("Abstract").find(
63
+ "AbstractText").text
64
+ pubmed_res.append({"content": title_tmp + url_tmp + abstract_tmp})
65
  except Exception as e:
66
  return PubMed.be_output("**ERROR**: " + str(e))
67