首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用美汤解析Grobid .tei.xml输出

用美汤解析Grobid .tei.xml输出
EN

Stack Overflow用户
提问于 2018-10-01 23:31:14
回答 1查看 460关注 0票数 3

我正在尝试使用Beautiful Soup从使用Grobid生成的.tei.xml文件中提取元素。

我可以使用以下命令获取标题:

代码语言:javascript
复制
titles = soup.findAll('title')

访问“较低级别”元素的正确语法是什么?(作者/所属单位等)

这是作为Grobid输出的tei.xml文件的一部分:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 /data/grobid-0.5.1/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
        <teiHeader xml:lang="en">
                <encodingDesc>
                        <appInfo>
                                <application version="0.5.1-SNAPSHOT" ident="GROBID" when="2018-08-15T14:51+0000">
                                        <ref target="https://github.com/kermitt2/grobid">GROBID - A machine learning software for extracting information from scholarly documents</ref>
                                </application>
                        </appInfo>
                </encodingDesc>
                <fileDesc>
                        <titleStmt>
                                <title level="a" type="main">The Role of Artificial Intelligence in Software Engineering</title>
                        </titleStmt>
                        <publicationStmt>
                                <publisher/>
                                <availability status="unknown"><licence/></availability>
                        </publicationStmt>
                        <sourceDesc>
                                <biblStruct>
                                        <analytic>
                                                <author>
                                                        <persName xmlns="http://www.tei-c.org/ns/1.0"><forename type="first">Mark</forename><surname>Harman</surname></persName>
                                                        <affiliation key="aff0">
                                                                <orgName type="department">CREST Centre</orgName>
                                                                <orgName type="institution">University College London</orgName>
                                                                <address>
                                                                        <addrLine>Malet Place</addrLine>
                                                                        <postCode>WC1E 6BT</postCode>
                                                                        <settlement>London</settlement>
                                                                        <country key="GB">UK</country>
                                                                </address>
                                                        </affiliation>
                                                </author>
                                                <title level="a" type="main">The Role of Artificial Intelligence in Software Engineering</title>
                                        </analytic>
                                        <monogr>
                                                <imprint>
                                                        <date/>
                                                </imprint>
                                        </monogr>
                                </biblStruct>
                        </sourceDesc>
                </fileDesc>'

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-10-02 22:54:21

BeautifulSoup将节点小写,下面是一些示例:

代码语言:javascript
复制
title = soup.html.body.teiheader.filedesc.analytic.title.string

for author in soup.html.body.teiheader.filedesc.sourcedesc.find_all('author'):
    tag_or_none = author.persname.forename
    first_affiliation = author.affiliation

还有see the BeautifulSoup documentation,它涵盖了所有内容。

我现在正在解决一个类似的问题,并寻求合作。如果你想组队,请告诉我-- sof@nconnor.com

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52594370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档