Marklogic:从元素单词词典中获取单词计数
我有两个示例XML文件,如下所示: abc.xmlMarklogic:从元素单词词典中获取单词计数,marklogic,Marklogic,我有两个示例XML文件,如下所示: abc.xml <data> <text>i am a test user and doing testing here more and more. What are you doing?</text> <data> <data> <text>We are a doing nothing here you can say it time pass. what are you doing
<data>
<text>i am a test user and doing testing here more and more. What are you doing?</text>
<data>
<data>
<text>We are a doing nothing here you can say it time pass. what are you doing?</text>
<data>
我是一个测试用户,在这里做测试越来越多。你在做什么?
def.xml
<data>
<text>i am a test user and doing testing here more and more. What are you doing?</text>
<data>
<data>
<text>We are a doing nothing here you can say it time pass. what are you doing?</text>
<data>
我们是一个无所事事的人,你可以说时间流逝了。你在做什么?
现在我已经为
元素创建了元素单词词典。我对以下方面感兴趣:
for $w in cts:element-words(xs:QName('text'))
return
element word {
attribute count {
xdmp:estimate(cts:search(doc(), cts:word-query($w))
},
$w }
这应该很快,但要获得实际的单词数而不仅仅是片段数,我认为您可能需要检查每个片段,这可能会非常慢:
sum(
cts:search(doc(), cts:word-query($w))/cts:highlight(.,
cts:word-query($w),<match/>)/count(//match)
)
如果您启用了URI词典,那么您可以通过迭代
cts:URI()
而不是doc()
并将该值作为第四个参数传递给cts:element-values()
,而不是调用文档上的xdmp:node-URI
,进一步优化2)但它给了我错误的结果:我是一个测试用户,在这里做测试越来越多。你在做什么?我们是一个无所事事的人,你可以说时间流逝了。你在做什么?我在这里期望的是单个单词计数,比如在我的例子中“2次”做“3次”等等。你确定你有一个元素单词词典,而不是元素范围索引吗?范围索引是值词典,而不是单词词典,因此它们存储每个元素的完整值,而不是单个单词。这就是您的输出所表明的。我已经在上面创建了[元素词词典和元素范围索引]。我还尝试删除它的元素范围索引,但在这种情况下,上面的查询给我错误。因为cts:元素值需要元素范围索引。有人能帮我吗?没有找到任何优化的solution@user1660340看看更新后的解决方案。使用cts:element words
而不是cts:element values
应该可以解决这个问题。我尝试了更新的解决方案,但得到的所有单词的计数为“0”。:(整个链接都在讨论获取元素/元素属性值及其计数(使用cts:frequency)或获取唯一单词等,但我希望获取唯一单词,以及该单词在给定uri或整个数据库中的出现情况。