具有大量 UNION 的 SPARQL 查询的替代方案 [英] Alternatives to SPARQL query with lots of UNIONs

查看:55
本文介绍了具有大量 UNION 的 SPARQL 查询的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Virtuoso 中存储了一些命名图,我想从提供的列表中找到匹配最多术语的图.

I have some named graphs stored in Virtuoso, and I want to find the one that matches the highest number of terms from a provided list.

我的查询以编程方式构建,如下所示:

My query is constructed programatically and looks like this:

SELECT DISTINCT ?graph (count(DISTINCT ?match) as ?matches)
WHERE {
  GRAPH ?graph {
    {?match rdf:label "term 1"} 
     UNION {?match rdf:label "term 2"} 
     UNION {?match rdf:label "term 3"}
     ...
  }
}
ORDER BY DESC(?matches)

每个术语都变成另一个 UNION 子句.

Each term becomes another UNION clause.

有没有更好的方法来做到这一点?查询变得又长又难看,很快,Virtuoso 会抱怨词条太多.

Is there a better way to do this? The query gets long and ugly fast, and Virtuoso complains when there are too many terms.

推荐答案

(it's rdfs:label)

(it's rdfs:label)

另一种写法是:

{ ?match rdfs:label ?X . FILTER (?x in ("term 1", "term 2", "term 3")) }

或(SPARQL 1.0)

or (SPARQL 1.0)

{ ?match rdfs:label ?X . FILTER ( ?x = "term 1" || ?x = "term 2" || ?x = "term 3" )  }

这篇关于具有大量 UNION 的 SPARQL 查询的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆