我有一个注释语料库的任务,共指解决。你能告诉我如何从xml文件中提取数据吗。我做了以下工作,但没有工作。你知道吗
from lxml import objectify
import pandas as pd
xml = objectify.parse(open('Dari_Coref_2_coref_level.xml'))
root = xml.getroot()
df = pd.DataFrame(columns='markable')
for i in range(0, 2):
obj = root.getchildren()[i].getchildren()
row = dict(zip(['markable'], [obj[0].text]))
row_s = pd.Series(row)
row_s.name = i
df = df.append(row_s)
print(df)
我的xml文件的结构如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE markables SYSTEM "markables.dtd">
<markables xmlns="www.eml.org/NameSpaces/coref">
<markable id="markable_1" span="word_1..word_4" mentiontype="ne"
coref_class="set_1" mmax_level="coref" coreftype="ident" />
<markable id="markable_3" span="word_33..word_34" mentiontype="ne"
coref_class="set_2" mmax_level="coref" coreftype="ident" />
<markable id="markable_2" span="word_5..word_9" mentiontype="np"
coref_class="set_1" mmax_level="coref" coreftype="ident" />
<markable id="markable_5" span="word_89..word_90" mentiontype="np"
coref_class="set_3" mmax_level="coref" coreftype="ident" />
<markable id="markable_4" span="word_35..word_44" mentiontype="np"
coref_class="set_2" mmax_level="coref" coreftype="ident" />
<markable id="markable_7" span="word_124..word_126" mentiontype="ne"
coref_class="set_4" mmax_level="coref" coreftype="ident" />
<markable id="markable_6" span="word_91..word_95" mentiontype="np"
coref_class="set_3" mmax_level="coref" coreftype="ident" />
</markables>
试试这个
Xpath语法教程:https://www.w3schools.com/xml/xpath_syntax.asp
相关问题 更多 >
编程相关推荐