ueeieiie
ueeieiie

Reputation: 1562

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

Upvotes: 3

Views: 1664

Answers (1)

Damyan Ognyanov
Damyan Ognyanov

Reputation: 786

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 
    } 
}

`

Upvotes: 1

Related Questions