英文:
Solution to sequence conversion
问题
我正在qconsole中执行以下SPARQL查询,此查询已正确执行并返回了包含2346项的“solution”,用时5毫秒。
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $distinct-ids := '
SELECT DISTINCT ?itemId
WHERE {
?itemId <hasListName> ?listName .
FILTER (lcase(str(?listName)) = "test")
}
'
return sem:sparql($distinct-ids)
我的要求是,我希望将结果作为项目的“sequence”以供进一步处理,而不是“solution”。
我尝试过类似于return map:get(sem:sparql($distinct-ids), "itemId")
的操作,它可以正常工作,但花费更长的时间(90毫秒)来获取结果。
是否有其他更快地获取项目序列而不使用map:get
的方法?
英文:
I am execution below SPARQL query into qconsole, this query executed properly and returned a solution with 2346 items
, it took 5 ms
.
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy";
let $distinct-ids := '
SELECT DISTINCT ?itemId
WHERE {
?itemId <hasListName> ?listName .
FILTER (lcase(str(?listName)) = "test")
}
'
return sem:sparql($distinct-ids)
My requirement is, I want to get the result as sequence
of items for further processing instead of solution.
I tried doing something like return map:get(sem:sparql($distinct-ids), "itemId")
, and it is Woking fine but took longer time (90 ms)
to get the result.
Is there any other way that is faster to get the sequence of items without using map:get
?
答案1
得分: 1
在结果上具体迭代并为每个项目调用map:get()
与依赖于函数映射相比,是否有差异?
sem:sparql($distinct-ids) ! map:get(., "itemId")
将array
选项应用于sem:sparql()
,然后为每个项目使用json:array-values()
获取值如何?
sem:sparql($distinct-ids, (), "array") ! json:array-values(.)
英文:
Does it make a difference if you specifically iterate over the results and call map:get()
for each item instead of relying on function mapping?
sem:sparql($distinct-ids) ! map:get(., "itemId")
What about applying the array
option to sem:sparql()
, and then for each item get the value with json:array-values()
?
sem:sparql($distinct-ids, (), "array") ! json:array-values(.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论