Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sparql CONSTRUCT with DISTINCT

PREFIX content: <http://example.com/content#>
construct { ?s content:field ?o}
WHERE { ?s content:field ?o }

90% of all the ?o I get here are the same URI <http://example.com/name>.

I'm trying to find a way to filter out all quads that have the same value for ?o, so in the end I get a list of quads which are unique by its ?o

I tried DISTINCT ?o CONSTRUCT{...} but from what I saw you cant use DISTINCT on a CONSTRUCT.

How would you filter the returned list of quads

like image 999
ueeieiie Avatar asked Sep 16 '26 11:09

ueeieiie


1 Answers

I'm trying to find a way to filter out all quads that have the same value for ?o, so in the end I get a list of quads which are unique by its ?o

if it does not matter which exact value is bound to ?s, then a sub-select with a group by ?o is the way to go. Use (SAMPLE(?s) as ?subj) e.g. something like: `

PREFIX content: <http://example.com/content#>
construct { ?s content:field ?o}
WHERE { 
    { select ?o (SAMPLE(?subj) as ?s) 
        { ?subj content:field ?o } 
    group by ?o 
    } 
}

`

like image 140
Damyan Ognyanov Avatar answered Sep 21 '26 02:09

Damyan Ognyanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!