将自然语言语料库的R-XML转换为数据框架
我正在使用XML包处理R中的XML文件。我的最终目标是创建一个包含以下信息的数据框架将自然语言语料库的R-XML转换为数据框架,xml,r,nlp,Xml,R,Nlp,我正在使用XML包处理R中的XML文件。我的最终目标是创建一个包含以下信息的数据框架 LUWPOS LUWDictionaryForm LUWLemma OrthographicTranscription PhoneticTranscription PlainOrthographicTranscription Devoiced MoraID ToneClass MoraID 動詞 ダイスル 題する 題し ダイシ 題し 1 3 accent 1 LUWPOS、LUWDictionaryForm、
LUWPOS LUWDictionaryForm LUWLemma OrthographicTranscription PhoneticTranscription PlainOrthographicTranscription Devoiced MoraID ToneClass MoraID
動詞 ダイスル 題する 題し ダイシ 題し 1 3 accent 1
LUWPOS、LUWDictionaryForm、LUWLemma是LUW节点的ATT。正字法,拼音法,正字法都是在SUW,LUW的女儿。Devoiced位于电话节点中,是SUW的后代。MoraID是Mora节点的att,它是Phone的祖母。ToneClass是节点XJToBILabelTone的一个属性,它是Phone的后代。第二个冰碛是XJToBILabelTone最接近的祖先,包含音调等级=重音。
甚至不是所有的电话节点都包含att。在这种情况下,我不需要第一个MoraID。当XJToBILabelTone不包含ToneClass=“accent”时,我也不需要第二个MoraID
到目前为止,我可以做到以下几点:
doc= xmlInternalTreeParse(file="A01F0122.xml") #opens the file
luw <- xpathSApply(doc, "//LUW", xmlAttrs) #extracts the attributes of the node LUW
df <- data.frame(Reduce(rbind, luw)) #creates the dataframe
它包含了我想要的一些信息,但我不知道如何获得LUW的后代
<?xml version="1.0" encoding="UTF-8"?>
<Talk TalkID="A01F0122" SpeakerID="463" SpeakerBirthPlace="神奈川県" SpeakerBirthGeneration="70to74" SpeakerSex="女">
<TalkComment>
<Comment CommentStrings="講演ID:A01F0122"/>
<Comment CommentStrings=""/>
<Comment CommentStrings=""/>
</TalkComment>
<IPU IPUID="0001" IPUStartTime="00000.312" IPUEndTime="00001.973" Channel="L">
<LUW LUWID="9" LUWPOS="動詞" IsNewLine="1" LineID="006" LUWDictionaryForm="ダイスル" LUWLemma="題する" LUWConjugateType="サ行変格" LUWConjugateForm="連用形">
<SUW SUWID="1" ColumnID="001" SUWDictionaryForm="ダイスル" SUWLemma="題する" SUWConjugateForm="連用形" SUWConjugateType="サ行変格" SUWConjugateForm2="連用形" SUWConjugateType2="サ行変格" SUWPOS="動詞" OrthographicTranscription="題し" PhoneticTranscription="ダイシ" PlainOrthographicTranscription="題し" APID="7" Dep_BunsetsuUnitID="6" Dep_ModifieeBunsetsuUnitID="7">
<TransSUW TransSUWID="1">
<Mora MoraEntity="ダ" MoraID="1" PerceivedAcc="1">
<Phoneme PhonemeEntity="d" PhonemeID="1">
<Phone PhoneID="1" PhoneEntity="SclS" PhoneClass="others" PhoneStartTime="6.188682" PhoneEndTime="6.19458"/>
<Phone PhoneID="2" PhoneEntity="d" PhoneClass="consonant" PhoneStartTime="6.19458" PhoneEndTime="6.207031"/>
</Phoneme>
<Phoneme PhonemeEntity="a" PhonemeID="2">
<Phone PhoneID="1" PhoneEntity="a" PhoneClass="vowel" PhoneStartTime="6.207031" PhoneEndTime="6.317124">
<XJToBILabelTone Time="6.212447" F0="209.865" ToneClass="IBT">%L</XJToBILabelTone>
<XJToBILabelTone Time="6.275146" F0="195.496" ToneClass="accent">A</XJToBILabelTone>
</Phone>
</Phoneme>
</Mora>
<Mora MoraEntity="イ" MoraID="2">
<Phoneme PhonemeEntity="i" PhonemeID="1">
<Phone PhoneID="1" PhoneEntity="i" PhoneClass="vowel" PhoneStartTime="6.317124" PhoneEndTime="6.361029"/>
</Phoneme>
</Mora>
<Mora MoraEntity="シ" MoraID="3">
<Phoneme PhonemeEntity="sj" PhonemeID="1">
<Phone PhoneID="1" PhoneEntity="sj" PhoneClass="consonant" PhoneStartTime="6.361029" PhoneEndTime="6.406245" EndTimeUncertain="1"/>
</Phoneme>
<Phoneme PhonemeEntity="i" PhonemeID="2">
<Phone PhoneID="1" PhoneEntity="i" PhoneClass="vowel" Devoiced="1" PhoneStartTime="6.406245" PhoneEndTime="6.451461" StartTimeUncertain="1">
<XJToBILabelWord Time="6.451461" PerceivedAccPos="1">daisji</XJToBILabelWord>
<XJToBILabelBreak Time="6.451461">1</XJToBILabelBreak>
</Phone>
</Phoneme>
</Mora>
</TransSUW>
</SUW>
</LUW>
<LUW LUWID="10" LUWPOS="助詞" IsNewLine="0" LineID="006" LUWDictionaryForm="テ" LUWLemma="て" LUWMiscPOSInfo1="接続助詞">
<SUW SUWID="1" ColumnID="005" SUWDictionaryForm="テ" SUWLemma="て" SUWMiscPOSInfo1="接続助詞" SUWPOS="助詞" OrthographicTranscription="て" PhoneticTranscription="テ" PlainOrthographicTranscription="て" APID="7">
<TransSUW TransSUWID="1">
<Mora MoraEntity="テ" MoraID="1">
<Phoneme PhonemeEntity="t" PhonemeID="1">
<Phone PhoneID="1" PhoneEntity="SclS" PhoneClass="others" PhoneStartTime="6.451461" PhoneEndTime="6.484228">
<XJToBILabelTone Time="6.451887" ToneClass="LTBPM" F0Uncertain="1">L%</XJToBILabelTone>
</Phone>
<Phone PhoneID="2" PhoneEntity="t" PhoneClass="consonant" PhoneStartTime="6.484228" PhoneEndTime="6.497334"/>
</Phoneme>
<Phoneme PhonemeEntity="e" PhonemeID="2">
<Phone PhoneID="1" PhoneEntity="e" PhoneClass="vowel" PhoneStartTime="6.497334" PhoneEndTime="6.565485">
<XJToBILabelTone Time="6.536170" F0="245.046" ToneClass="Pointer">pH</XJToBILabelTone>
<XJToBILabelWord Time="6.565485" PerceivedAccPos="0">te</XJToBILabelWord>
<XJToBILabelBreak Time="6.565485">1</XJToBILabelBreak>
</Phone>
</Phoneme>
</Mora>
</TransSUW>
</SUW>
</LUW>
</IPU>
</Talk>
%L
A.
大寺
1.
L%
酸碱度
te
1.
(这不是一个解决方案,但对一种继续操作的方法提供了一些指导。在SO中,将代码粘贴到注释中并不是最佳选择)
应考虑列表操作路径与XML路径路由。
# get the XML doc as a list of nested lists
doc.list <- xmlToList(doc)
# inspect it
str(doc.list)
# get the LUW nested list to make it easier to process
luw.list <- dl$IPU$LUW
# inspect it
str(luw.list)
# look at the attributes
str(luw.list$.attrs)
# inspect the SUM node
str(luw.list$SUW)
#以嵌套列表的形式获取XML文档
文件清单
# get the XML doc as a list of nested lists
doc.list <- xmlToList(doc)
# inspect it
str(doc.list)
# get the LUW nested list to make it easier to process
luw.list <- dl$IPU$LUW
# inspect it
str(luw.list)
# look at the attributes
str(luw.list$.attrs)
# inspect the SUM node
str(luw.list$SUW)