2017-08-03 23 views
2

SPARQLクエリを使用して、グラフストア内で一意の値の組み合わせを検索しています。しかし、私は成功しません。SPARQL固有の値の組み合わせを計算する

基本的に私が何をしようとするものである:

a b c 
e f g 
e r t 
a b c 
k l m 
e f g 
a b c 


result: 
a b c | 3 
e f g | 2 
e r t | 1 
k l m | 1 

はdistincts、グループby`sとサブクエリで、いくつかの構造をしようとしましたが、私は成功いけません。

最終試してみてください。

SELECT (count (*) as ?n){ 
     SELECT DISTINCT ?value1 ?value2 ?value3 WHERE { 
     ?instance vocab:relate ?value1 . 
     ?instance vocab:relate ?value2 . 
     ?instance vocab:relate ?value3 . 
     } 
    } 

RDF:

<http://test.example.com/instance1> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/c> , <http://test.example.com/b> , <http://test.example.com/a> . 

<http://test.example.com/instance6> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/g> , <http://test.example.com/f> , <http://test.example.com/e> . 

<http://test.example.com/instance4> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/c> , <http://test.example.com/b> , <http://test.example.com/a> . 

<http://test.example.com/instance2> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/g> , <http://test.example.com/f> , <http://test.example.com/e> . 

<http://test.example.com/instance7> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/c> , <http://test.example.com/b> , <http://test.example.com/a> . 

<http://test.example.com/instance5> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/m> , <http://test.example.com/l> , <http://test.example.com/k> . 

<http://test.example.com/instance3> 
     a  <http://test.example.com#Instance> ; 
     <http://vocab.example.com/relate> 
       <http://test.example.com/t> , <http://test.example.com/r> , <http://test.example.com/e> . 
+1

私は、あなたは、単に 'FILTER(?をvalue1 AKSW

+0

最初の投稿にRDFを追加しました – user3599600

答えて

4

AKSW's commentが上のスポットです:あなたはすべての異なる可能な方法を考慮していないような値に発注条件を追加する必要があります値を順序付けること。また、RDFは、あなたが、そう

:a :p :c, :c, :d 

ので、適切な比較は、重複したトリプルなしであるため、<=とは対照的に、<ある

:a :p :c, :d 

と同じである、トリプルを「複製」がないことを覚えておいてください=ケースは決してありません。また、値はIRIであるため、文字列の値を<と比較する前に取得する必要がありますが、str関数がそれを処理します。

prefix v: <http://vocab.example.com/> 
prefix : <http://test.example.com/> 

select ?a ?b ?c (count(distinct ?i) as ?count) where { 
    ?i v:relate ?a, ?b, ?c . 
    filter (str(?a) < str(?b) && str(?b) < str(?c)) 
} 
group by ?a ?b ?c 
------------------------ 
| a | b | c | count | 
======================== 
| :a | :b | :c | 3  | 
| :e | :f | :g | 2  | 
| :e | :r | :t | 1  | 
| :k | :l | :m | 1  | 
------------------------ 
+0

ありがとうございます。 – user3599600

関連する問題