序列转换解决方案

huangapple go评论42阅读模式
英文:

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 &quot;1.0-ml&quot;;
import module namespace sem = &quot;http://marklogic.com/semantics&quot; at &quot;/MarkLogic/semantics.xqy&quot;;

let $distinct-ids := &#39;
  SELECT DISTINCT ?itemId 
  WHERE {
    ?itemId &lt;hasListName&gt; ?listName .
    FILTER (lcase(str(?listName)) = &quot;test&quot;)
  }
&#39;

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), &quot;itemId&quot;), 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(., &quot;itemId&quot;)

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, (), &quot;array&quot;) ! json:array-values(.)

huangapple
  • 本文由 发表于 2023年7月24日 18:33:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753621.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定