首页 > 解决方案 > 将 PubMed 的作者和隶属关系与 Python 匹配

问题描述

我有一个脚本,它根据出版物的 PubMed ID (PMID) 从 PubMed 中提取各种信息。我想匹配作者和附属机构,现在它不能正确地做到这一点,所以有些名字我得到了错误的附属机构。他们都有一个编号,因此例如,如果您查找 PMID:26432775(链接:https ://pubmed.ncbi.nlm.nih.gov/26432775/ ),名称后面有一个 1,隶属关系前有一个 1属于那个人。

现在,我得到了帕多瓦大学帕多瓦大学内科-DIM 代谢疾病帕特里克·基思-海因斯单元的组合,意大利帕多瓦。

那是不对的。有谁知道我可以如何修复我的 python 脚本?

def parse(self, response):
    pmid = response.request.meta["pmid"]
    title = response.css("h1.heading-title").extract()[0]
    title = h.handle(title)
    title = title.replace("#", "")
    doi = response.css("span.citation-doi::text").extract_first().split(":")[-1]
    epubDate = response.css("span.secondary-date::text").extract_first()
    if not epubDate:
        epubDate = ""
    citation = response.css("span.cit::text").extract_first()
    journal = response.css("div.journal-actions.dropdown-block > button::text").extract_first()

    lists = response.css("div.authors-list")[0]
    authorsList = lists.css("span.authors-list-item > a::text").extract()
    authorsText = ", ".join(authorsList)

    affiliationsList = response.css("div.affiliations > ul > li::text").extract()
    affiliationsText = ", ".join(affiliationsList)

    pmcid = response.css("span.identifier.pmc > a::text").extract_first()
    if not pmcid:
        pmcid = ""

    terms = response.css("div#mesh-terms > ul > li > div > button::text").extract()
    terms = [term.strip() for term in terms]
    terms = ", ".join(terms)

    for author, affiliation in zip(authorsList, affiliationsList):
        yield {
            "PMID": pmid,
            "Author": author.strip(),
            "Affiliation": affiliation.strip(),
        }

    # abstract = ""
    abstract = h.handle(response.css("div.abstract-content").extract()[0])
    # print(abstract)
    if abstract:
        abstract = abstract.replace("*", "")
    else:
        abstract = ""

    row = [pmid, pmcid.strip(), title.strip(), doi.strip(),
           journal.strip(), epubDate.strip(), citation.strip(),
           authorsText.strip(), terms.strip(), abstract.strip()]

    writer.writerow(row)

标签: pythonmatchingpubmed

解决方案


推荐阅读