XQuery - 查询相邻标签

时间:2017-06-18 17:04:38

标签: xml xquery basex

我从未处理过XML数据库(或以复杂的形式查询XML),所以这个xquery对我来说都是新手。我已经阅读了Datypic书,我最初尝试将XML解析为数据库,但标签具有意义,关系数据库增加了更多的复杂性。

我有一些包含成绩单的文件和有关所用单词的详细信息,结构如下:



<text id="KBY">
  <bncDoc xml:id="KBY">
    <stext type="CONVRSN">
      <u who="KBYPSUNK">
        <w tag="UH" hw="hi" pos="INTERJ" sem="Z4" semo="|Z4|">Hi</w>
        <w tag="YEX" hw="PUNC" pos="STOP" sem="" semo="|">!</w>
      </u>
      <u who="PS10L">
        <w tag="VVGK" hw="going" pos="VERB" sem="T1:1:3" semo="|T1:1:3|">Gon</w>
        <w tag="TO" hw="to" pos="PREP" sem="Z5" semo="|Z5|">na</w>
        <w tag="RR21" hw="at" pos="ADV" sem="A13:7" semo="|A13:7;i1:2:1|">at</w>
        <w tag="RR22" hw="least" pos="ADV" sem="A13:7" semo="|A13:7;i1:2:2|A13:7|">least</w>
        <w tag="VVI" hw="stop" pos="VERB" sem="T2" semo="|T2d|S8d|M8|H4|A1:1:1|">stop</w>
        <w tag="II" hw="at" pos="PREP" sem="Z5" semo="|Z5|">at</w>
        <w tag="NP1" hw="gerald" pos="SUBST" sem="Z1" semo="|Z1m|">Gerald</w>
        <w tag="GE" hw="'s" pos="UNC" sem="Z5" semo="|Z5|">'s</w>
        <w tag="VHZ" hw="have" pos="VERB" sem="Z5" semo="|Z5|A9u|A2:2|S4|">has</w>
        <w tag="XX" hw="not" pos="ADV" sem="Z6" semo="|Z6|">n't</w>
        <w tag="PPHS1" hw="he" pos="PRON" sem="Z8" semo="|Z8m|">he</w>
        <w tag="YQUE" hw="PUNC" pos="STOP" sem="" semo="|">?</w>
      </u>
&#13;
&#13;
&#13;

琐事,我知道我可以使用以下方法查询单个单词:

&#13;
&#13;
for $w in //w
where $w = "houses"
return $w

OR

for $w in //w//text()
where $w = "houses"
return $w
&#13;
&#13;
&#13;

但是,对于我的生活,我不能弄明白我如何能够查询一个以上的术语。即&#34;有三栋房子&#34;。这将涉及检查每个单词是否相邻且不在单独的u标记中。理想情况下,我也可以在前后抓几个字。到目前为止,我假设这很难,因为结构但搜索普通文件需要&gt; 6秒和BaseX似乎非常有效。

感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

使用XQuery 1.0,您可以执行类似

的操作
<style>
.expandedMsg{
  height: 10vh;
  text-align: left;
  width: 100%;
  padding-bottom: 0.4%;
  word-wrap:break-word;
  background-color: #C1DCE6;
}
.expandedMsg img{
  height: 9vh;
  width: 9vh;

  float: left;
}

.expandTop{
  margin-left: 2px;
  font-size: 1.2vw;
  width: 100%;
  height: 100%;
}

</style>

<div class="expandedMsg">
    <img src="https://pbs.twimg.com/profile_images/378800000334311614/cdfed842c12b1964f784d03f0fdb9a30_400x400.jpeg">
    <p class="expandTop">
        <b>Title:</b> <span>dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</span>
    </p>
</div>

使用XQuery 3.0(或3.1),您可以使用新的“滑动窗口”子句,但我认为它不会使答案比上述更简单。