Project:SPARQL/examples: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 177: Line 177:
   OPTIONAL { ?item wdt:P27 ?val_2 . } # Homosaurus Version 2
   OPTIONAL { ?item wdt:P27 ?val_2 . } # Homosaurus Version 2
   OPTIONAL { ?item wdt:P26 ?val_3 . } # Homosaurus Version 3
   OPTIONAL { ?item wdt:P26 ?val_3 . } # Homosaurus Version 3
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
</sparql>
== Visualization Queries ==
=== Graphs ===
==== Subclass tree for a class entity ====
This query returns a graph of the subclass tree for the class of animals (Q4243). It uses the service wikibase:label to return the labels in your default language or in English.
<sparql tryit="1">PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Graph
SELECT ?item ?itemLabel ?linkTo {
  wd:Q4243 wdt:P2* ?item
  OPTIONAL { ?item wdt:P2 ?linkTo }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
}