使用 SPARQL 匹配属性集 [英] Matching attribute sets using SPARQL

查看:42
本文介绍了使用 SPARQL 匹配属性集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于使用带有 SPARQL 端点的三元组存储 (Fuseki 3.8.0) 查找匹配的 candidatepath.

This question is about finding matching candidate and path using a triple store with SPARQL endpoint (Fuseki 3.8.0).

匹配条件是candidateattribute必须包含path的所有requires代码>.在下面的最小示例数据中,匹配项应该是 candi_1path_1candi_2path_2.

The matching criteria is that the attribute's of a candidate must contain all of the requires of a path. In the minimal example data below, the matches should be candi_1 with path_1 and candi_2 with path_2.

@prefix : <http://example.com/app#> .

:candi_1
  a :candidate ;
  :attribute "A", "B", "C" .

:candi_2
  a :candidate ;
  :attribute "C", "D" .

:candi_3
  a :candidate ;
  :attribute "C", "E" .

:path_1
  a :path ;
  :requires "A", "C" .

:path_2
  a :path ;
  :requires "C", "D" .

结果应该是:

+------------+-------------+
| ?candidate | ?valid_path |
+------------+-------------+
| :candi1    | :path1      |
| :candi2    | :path2      |
+------------+-------------+

推荐答案

一种双重否定:

PREFIX : <http://example.com/app#> 

SELECT ?cand ?path
WHERE {
  ?cand a :candidate . 
  ?path a :path . 
  FILTER NOT EXISTS {
    ?path :requires ?attr .
    FILTER NOT EXISTS {
      ?cand :attribute ?attr .
    }
  }
}

上述查询的性能应该不高.也可以尝试以下方法:

The above query shouldn't be very performant. Try also the following one:

PREFIX : <http://example.com/app#> 

SELECT ?cand ?path
{
    {
    SELECT (COUNT(?attr) AS ?count) ?path ?cand
        {
        ?path a :path ; :requires ?attr .
        ?cand a :candidate ; :attribute ?attr . 
        } GROUP BY ?path ?cand
    } 
    {
    SELECT (COUNT(?attr) AS ?count) ?path
        {
        ?path a :path ; :requires ?attr .
        } GROUP BY ?path
    }
}

但是,如果存在空"候选和路径,则后一个查询不应该起作用.

However, the latter query shouldn't work if "empty" candidates and paths exist.

这篇关于使用 SPARQL 匹配属性集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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