Project:SPARQL/examples

Revision as of 12:42, 1 September 2023 by Elwinlhq (talk | contribs)

Here you find some SPARQL queries that you can use, and also modify or combine. To start a query from scratch, you may use this:

PREFIX qwb: <https://qichwa.wikibase.cloud/entity/>
PREFIX qdp: <https://qichwa.wikibase.cloud/prop/direct/>
PREFIX qp: <https://qichwa.wikibase.cloud/prop/>
PREFIX qps: <https://qichwa.wikibase.cloud/prop/statement/>
PREFIX qpq: <https://qichwa.wikibase.cloud/prop/qualifier/>
PREFIX qpr: <https://qichwa.wikibase.cloud/prop/reference/>
PREFIX qno: <https://qichwa.wikibase.cloud/prop/novalue/>

SELECT * WHERE {}

Try it!

Lexical Entries

# this lists all lexcial entries, with lemma and pos, ordered alphabetically by lemma
select ?entry ?lemma ?posLabel 
where {?entry a ontolex:LexicalEntry; 
                wikibase:lemma ?lemma;
                wikibase:lexicalCategory [rdfs:label ?posLabel]. 
                  filter(lang(?posLabel)="en")}
order by lcase(?lemma)

Try it!


Problematic lexical entries

# this lists all lexical entries with bracket, semicolon, or comma in the lemma sign
select ?entry ?lemma ?posLabel 
where {?entry a ontolex:LexicalEntry; 
                wikibase:lemma ?lemma;
                wikibase:lexicalCategory [rdfs:label ?posLabel]. 
                  filter(lang(?posLabel)="en")
                  filter(regex(?lemma,'[();,]'))}
order by lcase(?lemma)

Try it!


Senses and sense descriptions

#this lists entries that have senses and sense descriptions
select ?entry ?lemma ?posLabel (group_concat(concat(str(?sensegloss)," (",lang(?sensegloss),")");SEPARATOR="; ") as ?sense_descriptions)
where {

?entry a ontolex:LexicalEntry; 
       wikibase:lemma ?lemma;
       wikibase:lexicalCategory [rdfs:label ?posLabel] . filter(lang(?posLabel)="en")
?entry ontolex:sense [skos:definition ?sensegloss].

} group by ?entry ?lemma ?posLabel ?sense_descriptions
limit 100 # remove the limit and get all entries that have sense descriptions

Try it!


Dialectal lemma variants

#defaultView:BarChart
#This shows the distribution of dialectal lemma variants
PREFIX qp: <https://qichwa.wikibase.cloud/prop/>
PREFIX qps: <https://qichwa.wikibase.cloud/prop/statement/>
PREFIX qpq: <https://qichwa.wikibase.cloud/prop/qualifier/>

SELECT ?dialect ?dialectLabel (count (?variant) as ?variants)
WHERE { ?lemma qp:P16 [ qps:P16 ?variant ; qpq:P17 ?dialect ] .
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
      }
GROUP BY ?dialect ?dialectLabel ?variants ORDER BY DESC(?variants)

Try it!


Part of speech (lexical category)

Course-grained (lexical category superclasses)

#defaultView:BarChart
PREFIX qdp: <https://qichwa.wikibase.cloud/prop/direct/>

select ?pos ?posLabel (count(?entry) as ?count)
where {
?entry a ontolex:LexicalEntry; 
       wikibase:lemma ?lemma;
       wikibase:lexicalCategory ?pos_finegrained.
       ?pos_finegrained qdp:P4 ?pos. ?pos rdfs:label ?posLabel . filter(lang(?posLabel)="en")
} group by ?pos ?posLabel ?count
order by desc(?count)

Try it!

Fine-grained (lexical categories as in Runasimi Dictionary)

#defaultView:BarChart
#this shows pos distribution (fine-grained categories as in Runasimi dictionary)
select ?pos ?posLabel (count(?entry) as ?count)
where {
?entry a ontolex:LexicalEntry; 
       wikibase:lemma ?lemma;
       wikibase:lexicalCategory ?pos. ?pos rdfs:label ?posLabel . filter(lang(?posLabel)="en")
} group by ?pos ?posLabel ?count
order by desc(?count)

Try it!