给定一组 xml 记录和一组术语 $terms
。 $terms
序列中的术语是从记录集中提取的。我想统计每个段落记录中每个术语出现的次数。我使用以下代码来执行此操作:
for $record in /rec:Record
for $term in $terms
return xdmp:unquote(concat('<info>',string(count(lower-case($record/rec:paragraph )[. = lower-case($term)])), '</info>'))
对于每条记录中的每个术语,我得到的计数为 0:
示例:$term:='数学'
、$record/rec:paragraph:='数学是对数量等主题的研究'
我想要$record/rec:paragraph
中数学一词出现的次数
知道是什么导致了这个结果吗?有没有其他方法可以计算每个段落中每个术语出现的次数。
最佳答案
使用 tokenize() 将输入字符串拆分为单词标记。那么计数本身就微不足道了。例如:
let $text := 'Mathematics is the study of topics such as quantity'
let $myterms := 'mathematics'
let $wds := tokenize($text, '\s+')
for $t in $myterms
return <term name="{$t}">{count($wds[lower-case(.)=lower-case($t)])}</term>
返回:
<term nm="mathematics">1</term>
关于Xquery:计算一组记录中每个记录中某个术语的出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38445107/