
cts:correlation( $value1 as cts:reference, $value2 as cts:reference, [$options as xs:string*], [$query as cts:query?], [$forest-ids as xs:unsignedLong*] ) as xs:double?
Returns the frequency-weighted correlation given a 2-way co-occurrence.
The co-occurrence is formed from the specified value lexicons.
This function works like math:correlation except each pair
in the input lexicons is counted cts:frequency times. This
function performs the calculation in parallel in all data nodes then
aggregates the values.
xquery version "1.0-ml";
(:
This query assumes range indexes with positions are
configured in the database for both xval and yval. It
generates some sample data and then performs the
aggregation in a separate transaction.
:)
for $i in 1 to 10
let $j := 2 * $i
return
xdmp:document-insert(fn:concat($i, ".xml"),
<a><xval>{$i}</xval>{
for $a in 1 to $i
return <yval>{$j}</yval>
}</a>
);
cts:correlation(
cts:element-reference(xs:QName("yval")),
cts:element-reference(xs:QName("xval")),
("item-frequency"))
=> 1
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.