我在 BaseX 编辑器中有以下 XQuery 代码,但它在 if 子句中出错,说明
不完整的 FLWOR 表达式:期待“返回”
我尝试使用的代码:
import module namespace functx = 'http://www.functx.com';
declare namespace file = "http://expath.org/ns/file";
let $root := 'E:\basex-index-testing\sonar-small\index'
let $ds := file:dir-separator()
(: get files in sonar-small database :)
for $f in db:list('sonar-small')
(: remove *.xml from doc name :)
let $corpus := substring($f, 1, string-length($f) - 4)
for $alpino in db:open('sonar-small', $f)/treebank/alpino_ds
(: make sure tree has sentence element :)
where count($alpino/sentence) > 0
let $sentenceId := data($alpino/@id)
for $node in $alpino//node
(: make sure there are less than 500 descendants,
less than 100 and more than 0 children :)
where count($node//node) < 500 and count($node/node) > 0
and count($node/node) < 100
let $catTop := data($node/@cat)
(: create indexing pattern based on node's direct children :)
let $childrenRelCat := ()
for $child in $node/node
let $childRel := data($child/@rel)
(: use children's cat or pt attribute, default to '' :)
let $childCat := data($child/(@cat, @pt, '')[1])
(: concatenate childrenRelCat sequence (append to list) :)
let $childrenRelCat := ($childrenRelCat,
string-join(($childRel, $childCat), '%'))
let $bf := string-join(functx:sort($childrenRelCat), '_')
let $sent := <tree id="{$sentenceId}">{$node}</tree>
let $dir := concat($root, $ds, $catTop)
(: this if-clause throws an error: missing return statement,
incomplete FWLOR:)
if (file:exists($dir) and file:is-dir($dir))
then ()
else file:create-dir($dir)
(: append subtree to pattern-file :)
file:append($dir || $bf || '-index.xml', $sent)
(: doesn't have to return anything, but FWLOR demands it... :)
return $f
在 XQuery 如何评估表达式或期望它们被排序的方式上,我似乎遗漏了一些重要的东西。上面的代码有什么问题?
(这个问题的标题几乎相同,但那里提供的答案没有帮助,因为该 OP 的代码中存在另一个错误。)