繁体   English   中英

Xpath:如何获取我选择的节点的父节点?

[英]Xpath: how to get a parent node of my selected node?

我在获取所选节点的父节点时遇到问题。 我正在使用查询:// t [@ lemma =“ de”]。 但我想获取其中包含的元素。 我对xpath不太了解。 现在,我使用两个查询来尝试解决问题,但是我认为这不是必需的。 我的xml:

<?xml version="1.0" encoding="UTF-8"?>
<xml>
    <corpus> 
        <body>
            <s id="s16" ref="16" source="Running text" forest="1" text="DECLARARAL A Extinção da Punibilidade do Réu, Em Razão da Prescrição da Pretensão Punitiva, Fulcro Em os ARTIGOS 107, Inciso IV, Combinado Com O ARTIGO 109, Inciso VI (Redação Anterior à Lei Nº.">
                <graph root="s16_500">
                    <terminals>
                        <t id="s16_1" word="DECLARARAL" lemma="DECLARARAL" pos="prop" morph="--" extra="cjt-head cjt-head-X" />
                        <t id="s16_2" word="A" lemma="o" pos="art" morph="F S" extra="artd" />
                        <t id="s16_3" word="Extinção" lemma="Extinção" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_4" word="de" lemma="de" pos="prp" morph="--" extra="sam-" />
                        <t id="s16_5" word="a" lemma="o" pos="art" morph="F S" extra="-sam artd" />
                        <t id="s16_6" word="Punibilidade" lemma="punibilidade" pos="n" morph="F S" extra="prop percep-f" />
                        <t id="s16_7" word="de" lemma="de" pos="prp" morph="--" extra="sam-" />
                        <t id="s16_8" word="o" lemma="o" pos="art" morph="M S" extra="-sam artd" />
                        <t id="s16_9" word="Réu" lemma="réu" pos="n" morph="M S" extra="prop H" />
                        <t id="s16_10" word="," lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_11" word="Em_Razão" lemma="Em_Razão" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_12" word="de" lemma="de" pos="prp" morph="--" extra="sam-" />
                        <t id="s16_13" word="a" lemma="o" pos="art" morph="F S" extra="-sam artd" />
                        <t id="s16_14" word="Prescrição" lemma="prescrição" pos="n" morph="F S" extra="prop conv" />
                        <t id="s16_15" word="de" lemma="de" pos="prp" morph="--" extra="sam-" />
                        <t id="s16_16" word="a" lemma="o" pos="art" morph="F S" extra="-sam artd" />
                        <t id="s16_17" word="Pretensão_Punitiva" lemma="Pretensão_Punitiva" pos="prop" morph="--" extra="--" />
                        <t id="s16_18" word="," lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_19" word="Fulcro" lemma="fulcro" pos="n" morph="M S" extra="cjt-X part-build Labs" />
                        <t id="s16_20" word="Em" lemma="em" pos="prp" morph="--" extra="sam-" />
                        <t id="s16_21" word="os" lemma="o" pos="art" morph="M P" extra="artd -sam" />
                        <t id="s16_22" word="ARTIGOS_107" lemma="ARTIGOS_107" pos="prop" morph="--" extra="--" />
                        <t id="s16_23" word="," lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_24" word="Inciso_IV" lemma="Inciso_IV" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_25" word="," lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_26" word="Combinado_Com" lemma="Combinado_Com" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_27" word="O" lemma="o" pos="art" morph="M S" extra="artd" />
                        <t id="s16_28" word="ARTIGO_109" lemma="ARTIGO_109" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_29" word="," lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_30" word="Inciso_VI" lemma="Inciso_VI" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_31" word="(" lemma="--" pos="pu" morph="--" extra="--" />
                        <t id="s16_32" word="Redação_Anterior_Ã_Lei_Nº" lemma="Redação_Anterior_Ã_Lei_Nº" pos="prop" morph="--" extra="cjt-X" />
                        <t id="s16_33" word="." lemma="--" pos="pu" morph="--" extra="--" />
                    </terminals>

                    <nonterminals>
                        <nt id="s16_500" cat="s">
                            <edge label="X" idref="s16_501" />
                        </nt>
                        <nt id="s16_501" cat="par">
                            <edge label="CJT" idref="s16_1" />
                            <edge label="CJT" idref="s16_502" />
                            <edge label="PU" idref="s16_10" />
                            <edge label="CJT" idref="s16_507" />
                            <edge label="PU" idref="s16_18" />
                            <edge label="CJT" idref="s16_512" />
                            <edge label="PU" idref="s16_23" />
                            <edge label="CJT" idref="s16_24" />
                            <edge label="PU" idref="s16_25" />
                            <edge label="CJT" idref="s16_26" />
                            <edge label="CJT" idref="s16_515" />
                            <edge label="PU" idref="s16_29" />
                            <edge label="CJT" idref="s16_30" />
                            <edge label="PU" idref="s16_31" />
                            <edge label="CJT" idref="s16_32" />
                            <edge label="PU" idref="s16_33" />
                        </nt>
                        <nt id="s16_502" cat="np">
                            <edge label="DN" idref="s16_2" />
                            <edge label="H" idref="s16_3" />
                            <edge label="DN" idref="s16_503" />
                        </nt>
                        <nt id="s16_503" cat="pp">
                            <edge label="H" idref="s16_4" />
                            <edge label="DP" idref="s16_504" />
                        </nt>
                        <nt id="s16_504" cat="np">
                            <edge label="DN" idref="s16_5" />
                            <edge label="H" idref="s16_6" />
                            <edge label="DN" idref="s16_505" />
                        </nt>
                        <nt id="s16_505" cat="pp">
                            <edge label="H" idref="s16_7" />
                            <edge label="DP" idref="s16_506" />
                        </nt>
                        <nt id="s16_506" cat="np">
                            <edge label="DN" idref="s16_8" />
                            <edge label="H" idref="s16_9" />
                        </nt>
                        <nt id="s16_507" cat="np">
                            <edge label="H" idref="s16_11" />
                            <edge label="DN" idref="s16_508" />
                        </nt>
                        <nt id="s16_508" cat="pp">
                            <edge label="H" idref="s16_12" />
                            <edge label="DP" idref="s16_509" />
                        </nt>
                        <nt id="s16_509" cat="np">
                            <edge label="DN" idref="s16_13" />
                            <edge label="H" idref="s16_14" />
                            <edge label="DN" idref="s16_510" />
                        </nt>
                        <nt id="s16_510" cat="pp">
                            <edge label="H" idref="s16_15" />
                            <edge label="DP" idref="s16_511" />
                        </nt>
                        <nt id="s16_511" cat="np">
                            <edge label="DN" idref="s16_16" />
                            <edge label="H" idref="s16_17" />
                        </nt>
                        <nt id="s16_512" cat="np">
                            <edge label="H" idref="s16_19" />
                            <edge label="DN" idref="s16_513" />
                        </nt>
                        <nt id="s16_513" cat="pp">
                            <edge label="H" idref="s16_20" />
                            <edge label="DP" idref="s16_514" />
                        </nt>
                        <nt id="s16_514" cat="np">
                            <edge label="DN" idref="s16_21" />
                            <edge label="H" idref="s16_22" />
                        </nt>
                        <nt id="s16_515" cat="np">
                            <edge label="DN" idref="s16_27" />
                            <edge label="H" idref="s16_28" />
                        </nt>
                    </nonterminals>
                </graph> 
            </s>
        </body>
    </corpus>
</xml>

有人能帮我吗?

您可以这样获得父节点:

//t[@lemma="de"]/..

就像Unix shell一样:

cd ..

代表父目录的更改目录

根据您的评论:

我只需要在t[@lemma = 'de']条件下的标签<s>

在这种情况下,您需要的是

//s[graph/terminals/t/@lemma = 'de']

如果集合中的任何节点具有所需的值,则其中一侧为节点集的=比较将成功。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM