0

我试图弄清楚如何在 XML 文档中搜索某个块(块?字符串?我是新手……)并返回其余的……块?我目前正在使用 XStream 作为我的处理程序,但找不到任何关于做如此具体的事情的 tut。

这是代码示例(500,000 次):

<conversation>
    <input>HELLO</input>
    <response>
        <text>HELLO MATE</text>
        <hits>2</hits>
    </response>
    <response>
        <text>HOLA</text>
        <hits>1</hits>
    </response>
</conversation>

<conversation>
    <input>HOW ARE YOU</input>
    <response>
        <text>I AM GOOD</text>
        <hits>4</hits>
    </response>
    <response>
        <text>IM FINE</text>
        <hits>5</hits>
    </response>
</conversation>

它会搜索输入(例如,你好吗),然后返回命中率最高的响应块。我认为这是一个简单的操作,但我的搜索一无所获。谢谢小伙伴们!

4

1 回答 1

0

在 XQuery 1.0 中,这将是

declare variable $search as external;
let $c := //conversation[$input eq $search]
for $r in $c/response
where $r/hits = max($c/response/hits)
return $r
于 2013-09-21T08:32:58.667 回答