Help with SPARQL query - searching children of multiple concepts

36 views
Skip to first unread message

Kehan Harman

unread,
Apr 6, 2021, 12:34:18 AM4/6/21
to Getty Vocabularies as Linked Open Data
Hi All,
I'm trying to perform a search in an application API and I'd like to be able to filter where a parent term (gvp:broaderExtended) is one of two different values:

SELECT ?ID ?TermPrefLabel ?Parents ?ParentsFull {
?ID a skos:Concept; luc:term "place"; skos:inScheme aat: ; gvp:broaderExtended aat:300261086 ;
gvp:prefLabelGVP [xl:literalForm ?TermPrefLabel].
{?ID gvp:parentStringAbbrev ?Parents}
{?ID gvp:parentString ?ParentsFull}
{?ID gvp:displayOrder ?Order}
} LIMIT 100

What I can't work out how to do is to perform the above search has a gvp:broaderExtended of aat:300261086 OR aat:300264550

I've seen references to filter and subselects in http://vocab.getty.edu/queries?toc=Indian_and_Pakistani_Architectural_Groups&query=SELECT+%3FID+%3FTermPrefLabel+%3FParents+%3FParentsFull+%3Fx+%3Ffacet+%7B%0A%09%3FID+a+skos%3AConcept%3B+luc%3Aterm+%22place%22%3B+skos%3AinScheme+aat%3A+%3B%0A++++++++++%0A%0A%09gvp%3AprefLabelGVP+%5Bxl%3AliteralForm+%3FTermPrefLabel%5D.%0A%09%7B%3FID+gvp%3AparentStringAbbrev+%3FParents%7D%0A%09%7B%3FID+gvp%3AparentString+%3FParentsFull%7D%0A%09%7B%3FID+gvp%3AdisplayOrder+%3FOrder%7D%0A++++filter+exists+%7B%3Fx+gvp%3AbroaderExtended+%3Ffacet.%0A++++filter+%28%3Ffacet+in+%28aat%3A300264550%2C+aat%3A300261086%29%29%7D%0A%7D+LIMIT+100&implicit=true&equivalent=false#Indian_and_Pakistani_Architectural_Groups but I don't know the first place to start with these queries.

I come from an SQL background but this is a jump too far for me to work out.

Thanks in advance for your help.


Kehan Harman

unread,
Apr 6, 2021, 11:10:37 PM4/6/21
to Getty Vocabularies as Linked Open Data
I think I've worked this out:

SELECT  * {
?ID a skos:Concept ;
luc:term "place";
skos:inScheme aat: ;
gvp:prefLabelGVP [ xl:literalForm ?TermPrefLabel ] .
?ID gvp:broaderExtended ?Extended
{ ?ID gvp:parentStringAbbrev ?Parents }
{ ?ID gvp:parentString ?ParentsFull }
{ ?ID gvp:displayOrder ?Order }
FILTER (?Extended IN (aat:300261086, aat:300264550))
}
LIMIT 100

Vladimir Alexiev

unread,
Apr 20, 2021, 4:53:54 AM4/20/21
to Kehan Harman, Getty Vocabularies as Linked Open Data

FILTER after the clauses works because the query optimizer knows how to reorder the clauses and to treat this filter as VALUES.
However, it's better style to use VALUES and to always put first the "most known" things (clauses that have most bound parts).
Also, you don't need to use extra brackets unless you need OPTIONAL.
(In fact, in some repositories this will slow the query down because each bracketed pattern is treated as an independent subquery)
Adding some indentation, I'd write the query this way:

SELECT  * {
  VALUES ?Extended {aat:300261086 aat:300264550}
  ?ID a skos:Concept ;
    skos:inScheme aat: ;
    gvp:broaderExtended ?Extended ;
    luc:term "place";
    gvp:prefLabelGVP/xl:literalForm ?TermPrefLabel ;
    gvp:parentStringAbbrev ?Parents ;
    gvp:parentString ?ParentsFull ;

    gvp:displayOrder ?Order
} LIMIT 100


Cheers!
Reply all
Reply to author
Forward
0 new messages