-
-
Save micheee/360afe2284ea89cf1f15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $results := | |
( | |
let $keywords := ('Money order', 'Creditcard', 'Personal Check') | |
for $keyword in $keywords | |
for $item score $s in doc('xmark')//item[ | |
payment contains text {$keyword} all words using stemming using case sensitive | |
] (: As expected, I'm not sure what 'score' does. The definition in the BaseX documentation uses the defined term in the definition, so it's very unclear. :) | |
(: the score is an internal ranking of hits, similar to TF/IDF (term frequency / inverted document frequency), in short: terms that are contained often in a node but rare among all nodes are more important than terms that are generally contained in almost all nodes :) | |
order by $s descending | |
return <item ranking= '{ $s }'>{ $item/payment/text() }</item> | |
) | |
(: $s is unclear to me because score is. :) | |
for $result in $results | |
group by $val := $result/text() (: $val is undeclared. Where did you find this? :) | |
(: $val is assigned as part of the grouping specification, we group by $result/text() and name this variable $val :) | |
order by $result[1]/@ranking descending | |
return $result[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let $keywords := ('Cash', 'Personal Check') | |
for $keyword in $keywords | |
return <keyword name="{$keyword}"> (: This is actually unnecessary, as one of the returned rows contains the keyword. :) | |
{ | |
for $result in //item/payment | |
group by $payment-method := $result/text() (: $payment-method is an undefined variable. How does BaseX know where it is referenced from/what it corresponds to? :) | |
(: sorry, my bad: $payment-method will contain the text() value of each payment item found in //item/payment :) | |
order by count($result) descending (: Why do you want to count them? :) | |
(: we return the most often used payment method first:) | |
return element {"item"} { (: What's an 'element'? I'm trying to return the values of 'person', 'payment type', 'amount', etc. :) | |
(: the element operation constructs an XML element node, in this case: | |
an <item /> with an attribute count -> e.g. <item count="1" /> | |
:) | |
attribute {"count"} {count($result)}, (: What's an attribute? Would this be like lang="eng" in <cd lang="eng"></cd>? :) | |
$payment-method | |
}[. contains text {$keyword} phrase] (: What contains it? :) | |
}</keyword> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment