SPARQL OR 过滤器指令有优先权吗?

Is there priority in a SPARQL OR filter instruction?

我想知道在 OR 过滤器 SPARQL 指令中单词的顺序是给出还是改变了优先级。例如

FILTER( regex(STR(?keywords), "test1", "i")
        || regex(STR(?keywords), "test2", "i")
        || regex(STR(?keywords), "test3", "i")
        || regex(STR(?keywords), "test4", "i")
        || regex(STR(?keywords), "test5", "i") )

这个查询是否表明 test1 在结果筛选中比 test2 具有更高的优先级?换句话说,它会影响结果的顺序吗?如果我将结果限制为 20,例如低于总数(假设 60),我会先得到 test1 的结果,然后再得到 test2 ?

如果没有,有没有办法建立这样的优先级?

Does this query indicates that test1 has more priority than test2 in the filtering the results ? in other words, does it affect the order of the results? in case where I am limiting the results to 20 for example which is lower than the total (let's say 60), will I get the results of test1 first and then test2 ?

当查询末尾没有 order by 时,未指定顺序,因此实现当然可以根据 filter 更改顺序,但这似乎不太可能,至少不是以任何明显的方式。当你问 "will I get the results of test1 first and then test2," 时,它表明对 filter 的作用有点误解。 Filter 是一种指定结果必须满足的某些条件才能包含在结果集中的方法。从概念上讲,在 filter 之前,工作结果集中有一个结果列表,然后对每个结果应用 filter 测试,并且保留满足测试的那些。在任何有意义的意义上都没有 test1 或 test2 的 "results"。应用测试的不同方式可能会影响排序,例如,取决于它是否:

final results = {}
for (result in working results) 
  for (testi in tests)
    if result passes test
      add result to final results

final results = {}
for (testi in tests)
  for (result in working results) 
    if result passes test
      add result to final results

由于最终结果是 ,您最终会得到相同的集,但由于结果最终以列表形式提供,因此可以想象这可能会影响order 你会看到结果。但正如我上面所说,你不太可能通过这种方式获得任何可靠、有意义的差异。

if not, is there a way to establish such a priority?

如果你想以某种方式排序结果,你需要弄清楚如何获得该优先级,然后你可以按它排序。例如,在您的情况下,您可以执行以下操作:

select ?keywords {
  values ?test { "test1" "test2" "test3" }
  #-- get a binding for ?keywords...
  filter regex(str(?keywords), ?test)
}
order by ?test

在这种情况下,由于 ?test 的值具有可靠的排序,您可以根据 ?test[=41 的值对结果进行排序=] 匹配。当然,如果 ?keywords 匹配多个 ?test 的值,你会在结果中多次看到它。

如果条件不像字符串那么简单,您仍然可以使用来指定优先级:

select ?keywords {
  values (?test ?priority) { ("test1" 3) ("test2" 0) ("test3" 5)}
  #-- get a binding for ?keywords...
  filter regex(str(?keywords), ?test)
}
order by ?priority