Franz van Duns' Wikidata user page edit

I am Franz van Duns, legitimated by my main user page on Wiki Commons.

Interwiki Linking Examples edit


site management site verification
Purge this site's cache This is a user page dedicated to Wikidata only. Should you find this page on any other site, you will be viewing an unauthorised copy!

Statistics edit

No content yet

Wikidata Special Pages edit

How to connect Wikidata and Wiki Commons edit

Added initial information to the pre-existing Wikidata entry Q21233320, especially important if the category name is not exactly identical!

  • Entry "Q21233320" now sports the label Carl Zeiss Batis Sonnar T* 1.8/85, which is identical to the corresponding Wiki Commons category.
  • The original label "Zeiss Batis 1.8/85", which is somewhat abbreviated in comparison to above full name given by the manufacturer Zeiss, is retained as an alias.
  • NOTE: The connection to Wiki Commons was first established when
    (A) I added the following piece of information at the bottom of the list on the right of a Wikidata entry in the following manner:
    select frame Other sites
    type commons into the (rather small) input field
    and finally type the phraseCategory:Carl Zeiss Batis Sonnar T* 1.8/85 into the field that magically appears to the right of the previous input field .
    (B) I added the code line {{Wikidata Infobox}} to the corresponding Wiki Commons category.
    (C) I waited for 1-4 hours till the connection was established by some hidden mechanism and the individual data items were visible in the Infobox on the Wiki Commons category page.
  • This is the link to above described Wikidata entry: Special:EntityPage/Q21233320

How to Search within Wiki projects edit

The sections "Commons" and "Wikidata" contain, amongst others, a copy of my Wiki Commons User Page documentation.

  • Intent: to test whether all links that work just fine on a Commons page also function correctly without any alteration when copied to a Wikidata page, as follows.
    Answer: YES, indeed, all's fine!

Wikibooks: Manuals edit

W3.org edit

Commons edit

Wikipedia edit

Infoboxes edit

Infoboxes used in a Wikipedia article must normally relate the Wikipedia page name to an identically named Wikidata Q-item.
If this is not feasable, one may state an alternative Q-item as Infobox parameter "qid".

  • You shouldn't add sitelinks (within Wikidata Q-items) to draft articles on Wikipedia.
  • Instead you can override the Wikidata item being used.
    Example (supplied by Infrastruktur (talk) 09:43, 25 July 2023 (UTC))
{{Infobox person/Wikidata|fetchwikidata=ALL|qid=Q3380040}}

Wikidata edit

Searching within Wikidata edit

Help pages related to Search edit

Wikidata Default Search edit

The Wikidata Default Search is an input field placed near the top right of every Wikidata page. The input field contains a (looking-glass icon).

  • Usually you will find the most relevant entry/entries that apply to your search term in the drop-down list that appears as you type along. Sometimes the list remains empty.
    • The topmost entry is mostly an item, as items are regarded as most relevant, sometimes it is a property, and sometimes some other Wikidata entity.
    • CAVEAT: If an item and a property have been given identical names, ONLY the item will be displayed in the list. See below how to remedy this rare case.
  • At the bottom of the drop-down list you will always find the text "Search for pages containing your search term".
    • Choosing this bottom list item will present you a page with a list of all applicable Wikidata search results.
    • And, as to above caveat concerning identical names, now both item and property will be displayed. Usually these are the topmost entries, sometimes one is displayed further on in the list.
      This is also the result attained using #Special:Search in the following section with the default "Search in" field setting "((Main) X) and (Property X)" (explained in detail below).

Special:Search edit

  • The Special:Search page provides three input fields.
The default values are as follows:
To search for Wikidata items by their title on a given site, use Special:ItemByTitle.
  (looking-glass icon)  emptyEnter search term(s). NOTE: Quotation marks around some of the terms state "search for exactly this term".
  Advanced search:      (Sort by relevance  X)         → To set advanced search parameters and/or to change sort order, click on arrow at right, then choose required term(s).
  Search in:            ((Main)  X) and (Property  X)  → To set more or other "search in" terms, click on arrow at right, then click on treble bar (jocular: hamburger bar) icon to choose required term(s).To search for items ONLY, choose term "((Main)  X)".To search for properties ONLY, choose term "(Property  X)".To search for Query IDs ONLY (example: "Q1242555"), choose term "(Query  X)" and type the Query ID (i.e. Q1242555) in the top line.
                                                         NOTE: If this Query ID exists, it will immediately appear on a drop-down list.
  • See following example for a first impression:
  (looking-glass icon)  "encyclopedia.com ID"          → Quotation marks define "search for exactly this term".
  Advanced search:      (Sort by relevance  X)
  Search in:            (Wikidata  X)                  → Replaces the default values; these are the two namespaces ((Main)  X) and (Property  X).To set "Wikidata" ONLY, as depicted here, click on arrow at right, then click on treble bar (hamburger bar) icon to choose term.
  • Results of above example:
Results 1 – 12 of 12
  Wikidata:Property proposal/encyclopedia.com ID
  proposed at Wikidata:Property proposal/Authority control    Done: Encyclopedia.com
  ID (P11850) (Talk and documentation) By pure chance I noticed that the...
  5 KB (338 words) - 21:38, 10 July 2023

  Wikidata:Database reports/Constraint violations/P11850
  properties Special:ConstraintReport Constraint violations report for Encyclopedia.com ID
  (Discussion, uses, items, changes, related properties): identifier...
  397 bytes (122 words) - 03:00, 1 July 2023

  ... and 10 more ...

Wikidata Query - Basics edit

SERVICE wikibase:label only supplies labels for entities in the wd: namepace.
How then to provide labels for properties in the wdt: namespace?
This can be done by adding the assertion line ?prop wikibase:directClaim ?p into the query – the special predicate wikibase:directClaim connects the wd: namespace entity for the property to its wdt: namespace representation.
NOTE: It is usually also necessary to turn off the built-in query optimizer with the line hint:Query hint:optimizer "None", otherwise the query engine can find the above assertion with only 2000 results an overly seductive place to start building its result set out from, which means that statements may need to be quite carefully hand-ordered – as discussed further on the query optimization page.

Wikidata - Query optimization edit

  • Wikidata: SPARQL query service/query optimization
    The Gather, Apply, and Scatter (GAS) service provides graph traversal, graph mining, and similar classes of algorithms for SPARQL. In practical terms, it enables a series of relations to be followed through the graph; for instance the chain of father, grandfather, great-grandfather &c - tracing the father (P22) line - of a subject item, or a chain of connected railway stations through adjacent station (P197) statements. It is documented here blazegraph: RDF GAS API and here blazegraph.com: GASService.
    It is possible to look at inverse paths to a subject item, for instance, people in a matrilineal line descended from Elizabeth II (Q9682), by adding the parameter <tvar|1>gas:traversalDirection "Reverse".
    In essence, GAS takes two parameters: gas:in wd:Qnnn - the node or item from which to start, and gas:linkType wdt:Pnnn - the property to be followed. It outputs gas:out - the next item; gas:out1 - the number of hops from the input item and gas:out2 - the item immediately preceding the gas:out item in the queried chain.

Wikidata - Query examples edit

Wikidata - Wikidata Properties edit

  • Code:
  • NOTE: This query returns a list of items to which Wikidata property (Q18616576) is attributed, not the wikibase:Properties in the section Wikidata - SELECT ALL Wikibase Properties below!
  • Result examples: instance of (P31), subclass of (P279). has goal (P3712), has part(s) (P527) and many more ..., but NOT e.g. located in or next to body of water (P206), part of (P361), uses (P2283), ...

Wikidata - Properties in use for Wikidata items edit

  • Code:
  • CAVEAT: A complex and, as later realised, a sadly INCOMPLETE query that also regularly times out!! Remains here to serve as an example of an infeasable query.
    • Quite astounding, though, as it (without elimination terms) results in (2024-04-19) 12232 items, which are 302 more items than the simple query for "ALL properties"! Maybe duplicates?
    • Further analysis required.
  • Result examples: author (P50), AAA hotel ID (P8868), age of candidacy (P2998), ...

Wikidata - Wikidata Qualifier edit

  • Examples: depicts (P180), main subject (P921). title (P1476), media legend (P2096) and many more ...
  • Code:

Wikidata - Wikibase elements edit

Wikidata - Wikibase:WikibaseItems edit

  • Examples: instance of (P31), subclass of (P279). has goal (P3712), has part(s) (P527), located in or next to body of water (P206), part of (P361), uses (P2283) and many more ...
  • Code:

      Compare with: Query: all WikibaseItems - Note: this query also displays all WikibaseItems - currently (2024-04-13): 1637 items.

Wikidata - Wikibase Properties edit

Wikidata - SELECT ALL Wikibase Properties edit
  • Code:
Wikidata - SELECT Wikibase Properties of ONE or MORE Property Types edit
  • Code:
  • RESULT: The above code (when left unaltered) displays a list of all Wikibase Properties with the Property Type "wikibase:ExternalId".
    • The code contains a complete list of all Wikibase Property Types from which you may choose by (re)placing one or more comment characters.
Wikidata - SELECT ALL Wikibase Properties EXCEPT those of ONE or MORE Property Types edit
  • Code:
  • RESULT: The above code (when left unaltered) displays a list of all Wikibase Properties excluding the Property Type "wikibase:ExternalId".
    • The code contains a complete list of all Wikibase Property Types to be excluded, from which you may choose by (re)placing one or more comment characters.


Wikidata - Wikibase Property Elements edit

  • Wikibase property (E259)Contains following lists of the individual elements of a Wikibase property: Prefixes, <property>, <languageLabel>, <wdt>, <propertyTypes> (retrieved 2021-12-16).

Mediawiki HELP edit

Mediawiki API edit

Links to documentation concerning usage of wikibase:api and mwapi.

  • Refer to example 01 below, which displays how to apply a series of statements that make use of the wikibase: / mwapi: operators.

Mediawiki - API:Main page edit

Mediawiki - API:Search and discovery edit

Mediawiki - API:Search_and_discovery

Mediawiki - API:Search edit

  • API:Search
    • list=search (sr), menu: (main | query | search): srsearch, srnamespace, srlimit, sroffset, srqiprofile, srwhat, srinfo, srprop, srinterwiki, srenablerewrites, srsort
      srsearch|srnamespace|srlimit|sroffset|srqiprofile|srwhat|srinfo|srprop|srinterwiki|srenablerewrites|srsort
      srinfo: rewrittenquery, suggestion, totalhits, rewrittenquery|suggestion|totalhits
      srprop: categorysnippet, extensiondata, isfilematch, redirectsnippet, redirecttitle, sectionsnippet, sectiontitle, size, snippet, timestamp, titlesnippet, wordcount
      categorysnippet|extensiondata|isfilematch|redirectsnippet|redirecttitle|sectionsnippet|sectiontitle|size|snippet|timestamp|titlesnippet|wordcount
      Example: https://www.mediawiki.org/w/api.php?action=query&generator=search&gsrsearch=meaning&prop=info

Mediawiki - API:Query edit

  • API:Query
  • API:Querycontains links to all elements (properties, parameter names) that find use in the mwapi:
    → See chapters prop, list, meta, indexpageids, export, exportnowrap, exportschema, iwurl, continue, rawcontinue, titles, pageids, revids, generator, redirects, converttitles which enlist the appropriate parameter names.

Mediawiki - API:Lists edit

  • API:Lists
    See individual list API pages for more concrete examples of how to use lists (retrieved 2021-12-16):

Mediawiki - API:Meta edit

  • API:Meta
    See individual list API pages for more concrete examples of how to use meta (retrieved 2021-12-16):

Mediawiki - API:Properties edit

  • API:Properties
    See individual list API pages for more concrete examples of how to use lists (retrieved 2021-12-16):

Mediawiki - API:Query#Generators edit

  • API:Query#GeneratorsShort description of how to code for a generator.
  • API:Query#API_documentationScroll to chapter "Generators".
    • Values applicable for Generator: allcategories, alldeletedrevisions, allfileusages, allimages, alllinks, allpages, allredirects, allrevisions, alltransclusions, backlinks, categories, categorymembers, deletedrevisions, duplicatefiles, embeddedin, exturlusage, fileusage, images, imageusage, iwbacklinks, langbacklinks, links, linkshere, messagecollection, mostviewed, pageswithprop, prefixsearch, protectedtitles, querypage, random, recentchanges, redirects, revisions, search, templates, transcludedin, watchlist, watchlistraw, wblistentityusage.

Mediawiki - User Manual/MWAPI for 'Wikidata Query Service' edit

  • Mediawiki: Wikidata Query Service/User Manual/MWAPI
    • MediaWiki API Query Service: MediaWiki API Service allows to call out to MediaWiki API from SPARQL, and receive the results from inside the SPARQL query.
      • Service: The query is initiated by SERVICE with URL wikibase:mwapi.
      • Supported services: Currently the following services are supported (see table below, retrieved 2021-12-26).
      • NOTE: Refer to these > > examples < < that comprise various scenarios for all four services stated in the following table:
Service Inputs Outputs Description
Generator generator, prop, pprop title, item, pageid, lastrevid, timestamp Call any generator API. Use "generator" parameter to specify, and specific generator parameters to further amend the search.
Categories titles,cllimit category, title Get a list of categories on the page.
Search srsearch,srwhat,srlimit title Full-text search in wiki.
EntitySearch search,language,type,limit item,label Wikibase entity search, by title.

Required parameters are in bold. Other input parameters may also be supported – please refer to the service documentation (linked in Service column) for supported API parameters and their meaning.

Mediawiki API - Example 01 edit

 SERVICE wikibase:mwapi
 {
   bd:serviceParam  wikibase:api           "Generator" ;
                    wikibase:endpoint      "commons.wikimedia.org" ;
                    wikibase:limit         "once" ;
                    
                    mwapi:generator        "allpages" ;               # This line defines the property as "generator" and the generator parameter name as "allpages". The following parameters must all begin with the letter "g".
                    mwapi:gapfrom          ?fileTitle ;               # "mwapi:g" + parameter "apfrom" → see Documentation of allpages (ap), item "apfrom".
                    mwapi:gapnamespace     6 ;                        # "mwapi:g" + parameter "gapnamespace" → see Documentation of allpages (ap), item "gapnamespace".
                   
                    mwapi:prop             "imageinfo" ;              # This line defines the property as "prop" and the imageinfo parameter name as "imageinfo". No prefix required for the following parameters.
                    mwapi:iiprop           "dimensions" ;             # Parameter "iiprop" → see Documentation of imageinfo (ii), item "iiprop".
 
                    mwapi:gaplimit         1 .

   bd:serviceParam  mwapi:generator        "categorymembers" ;        # This line defines the property as "generator" and the generator parameter name as "categorymembers". The following parameters must all begin with the letter "g".
                    mwapi:gcmtitle         ?title ;                   # "mwapi:g" + parameter "cmtitle" → see Documentation of categorymembers (cm), item "cmtitle".
                    mwapi:gcmprop          "ids|title|type" ;         # "mwapi:g" + parameter "cmprop" → see Documentation of categorymembers (cm), item "cmprop".
                    mwapi:gcmlimit         "max" .                    # "mwapi:g" + parameter "cmlimit" → see Documentation of categorymembers (cm), item "cmlimit".

   ?size    wikibase:apiOutput  "imageinfo/ii/@size" .
   ?width   wikibase:apiOutput  "imageinfo/ii/@width" .
   ?height  wikibase:apiOutput  "imageinfo/ii/@height" .
 
   ?Xtitle wikibase:apiOutput           mwapi:title .  # "File:" + "fileTitle" 
   ?ns     wikibase:apiOutput           "@ns" .        # All instances: ns=6
 }

General Rules and Hints edit

Wikidata Query Service edit

General themes edit

  • Timeout: Timeout occurs after exactly 60 seconds if a query cannot be processed in that period of time.
  • Cache: The query code is automatically cached and, if repeated within the caching period, will return an identical result within only a fraction of a second.

Query code edit

  • Label: The Wikibase service "SERVICE wikibase:label ..." provides additional information by adding Label data to the normally available data outputs.
    The Label data for a data item "zzz" will only be displayed if the SELECT statement contains an output field named "SERVICE wikibase:label".
    NOTE: This will NOT work with the operator " > > SELECT * < < ". Instead, all desired output fields must be stated.
    EXAMPLE: SELECT ?item ?itemLabel ?file ...

Self-defined Examples edit

Query 01 edit

Query 01A edit

Search for Wikidata items where manufacturer is stated as being 'Carl Zeiss AG'.

  • Last revision : 2021-12-15.
# Enlist all Wikidata items where manufacturer is stated as being 'Carl Zeiss AG'.
# Last revision : 2021-12-15.
# Table columns: ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel (WD=Wikidata)
# NOTE: The sort order applied to the column "cameraLabel" rearranges entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", AFTER entries containing the regular set of characters. 

SELECT DISTINCT ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel    # WD=Wikidata   # NOTE: combining 'wdt:P279*' with '?subclassOf': 215 items, with '?subclassOfLabel': only 209 items!
WHERE {

  ?WDitem wdt:P176 wd:Q282186 .                      # Manufacturer (P176): Carl Zeiss AG (Q282186) # RESULT / 2021-12-15 => 15

#  ?WDitem wdt:P31 ?instanceOfLabel                   # Display ONLY those items that have an 'instance of (P31)' entry
  OPTIONAL {?WDitem wdt:P31 ?instanceOf . }          # IF PRESENT retrieve a value for 'instance of (P31)'  # NOTE: Adding this term to the query raises RESULT from 15 to 18 

#  OPTIONAL {?WDitem wdt:P279* ?subclassOf . }        # IF PRESENT retrieve a value for 'subclass of (P279*)'  # NOTE: Adding this term to the query raises RESULT from 15 to 209/215 items. These represent all sub-subclasse!
  OPTIONAL {?WDitem wdt:P279 ?subclassOf . }         # IF PRESENT retrieve a value for 'subclass of (P279)'  # NOTE: Adding this term to the query keeps RESULT at 18
 
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
 
ORDER BY ASC(UCASE(?WDitemLabel)) ASC(UCASE(?instanceOfLabel))

Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.

Query 01B edit

Search for both cameras and subclasses of cameras within WikiData.

  • Last revision 2021-12-15.
# Find all instances of (P31) and all subclasses of (P279*) of both camera (Q15328) and digital camera model (Q20741022) within WikiData.
# Last revision :  2021-12-15.
# Query makes use of UNION operator.
# Table columns with explanations:  ?camera ?cameraLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image (hyperlink only) ?massLabel ?WPENarticle (WPEN=Wikipedia:en) ?WPDEarticle (WPDE=Wikipedia:de)
# NOTE:  The sort order applied to the column "cameraLabel" displays entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", first after all entries containing the regular set of characters.

SELECT DISTINCT ?camera ?cameraLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image ?massLabel ?WPENarticle ?WPDEarticle
WHERE {
#  ?camera wdt:P31/wdt:P279* wd:Q15328 .              # instance of (P31) or subclass(es) of (P279*):  camera (Q15328)
#  ?camera wdt:P31/wdt:P279* wd:Q20741022 .           # instance of (P31) or subclass(es) of (P279*):  digital camera model (Q20741022)

  {?camera wdt:P31/wdt:P279* wd:Q15328 . }          # instance of (P31) or subclass(es) of (P279*):  camera (Q15328)
  UNION
  {?camera wdt:P31/wdt:P279* wd:Q20741022 . }       # instance of (P31) or subclass(es) of (P279*):  digital camera model (Q20741022)

  OPTIONAL {?camera wdt:P176 ?manufacturer . }       # manufacturer (P176)
  OPTIONAL {?camera wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?camera wdt:P279 ?subclassOf . }         # subclass of (P279) NOTE: Adding this term to the query raises RESULT from 1578 to 1635 !
  OPTIONAL {?camera wdt:P18 ?image . }               # image (P18)
  OPTIONAL {?camera wdt:P2067 ?mass . }              # mass (P2067)
 
  OPTIONAL {?WPENarticle schema:about ?camera .      #  has a Wikipedia:en article
            ?WPENarticle schema:isPartOf <https://en.wikipedia.org/> .
            ?ENsitelink ^schema:name ?WPENarticle . }

  OPTIONAL {?WPDEarticle schema:about ?camera .      #  has a Wikipedia:de article
            ?WPDEarticle schema:isPartOf <https://de.wikipedia.org/> .
            ?DEsitelink ^schema:name ?WPDEarticle . }
 
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?cameraLabel))   # ASC(UCASE(?camera))
  • Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.

Query 01C edit

How to implement a UNION statement.

Minimal Version edit

Insert the following code into the editing space provided on the site [1].

# Find all instances of camera within WikiData via "UNION of EXIF data".
#   This query collects via "UNION" operator all instances of "Exifmodel ( P2009 )", of "EXIFmanufacturer ( P2010 )", and of categoryPicturesTakenWith ( P2033 ).
# The basic idea of how to use the UNION operator was derived from the page Commons:Database_reports/Cameras.
# NOTE: The resulting query table does not display the image, only the link to the image.
 
SELECT DISTINCT ?camera ?cameraLabel ?cameraImage ?manufacturerLabel
WHERE
{
  { ?camera wdt:P2009 ?dummy0 . } UNION { ?camera wdt:P2010 ?dummy1 . } UNION { ?camera wdt:P2033 ?dummy2 . } 

  OPTIONAL {?camera wdt:P18 ?cameraImage . }    # item image (P18)
  OPTIONAL {?camera wdt:P176 ?manufacturer . }    # manufacturer ( P176 )

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?manufacturerLabel

Detailed Version edit

Insert the following code into the editing space provided on the site [2].

# Find all instances of camera within WikiData via "UNION of EXIF data".
#   This query collects via "UNION" operator all instances of "Exifmodel ( P2009 )", of "EXIFmanufacturer ( P2010 )", and of categoryPicturesTakenWith ( P2033 ).
# The basic idea of how to use the UNION operator was derived from the page Commons:Database_reports/Cameras.
# NOTE: The resulting query table does not display the image, only the link to the image.

SELECT DISTINCT ?camera ?cameraLabel ?cameraImage ?manufacturerLabel ?instanceOfLabel ?EXIFmodel ?EXIFmanufacturer ?massLabel ?article ?categoryPicturesTakenWithLabel ?inception ?partOfSeries
WHERE 
{ 
  { ?camera wdt:P2009 ?dummy0 . } UNION { ?camera wdt:P2010 ?dummy1 . } UNION { ?camera wdt:P2033 ?dummy2 . } 
#  { ?camera wdt:P2009 ?dummy0 . }             # Herewith only cameras, no lenses!                            
  OPTIONAL {?camera wdt:P176 ?manufacturer . }    # manufacturer ( P176 )
  OPTIONAL {?camera wdt:P31 ?instanceOf . }    # instance of ( P31 )
  OPTIONAL {?camera wdt:P18 ?cameraImage . }    # image (P18)
  OPTIONAL {?camera wdt:P2067 ?mass . }  # mass ( P2067 )
  OPTIONAL {?camera wdt:P2009 ?EXIFmodel . }  # EXIFmodel ( P2009 )
  OPTIONAL {?camera wdt:P2010 ?EXIFmanufacturer . }  # EXIFmanufacturer ( P2010 )
  OPTIONAL {?camera wdt:P2033 ?categoryPicturesTakenWith . }  # categoryPicturesTakenWith ( P2033 )
  
  OPTIONAL {?article schema:about ?camera .    #  has a Wikipedia article
            ?article schema:isPartOf <https://en.wikipedia.org/> .
            ?sitelink ^schema:name ?article . }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?cameraLabel

Corresponding Template edit

Wikidata list - Coding example edit

Insert the following code into a page on Wikidata, Wiki Commons, or a Userpage on Wikipedia (code is invalid on [3]).

  • NOTE: All instances of and must be removed to enable activation of the code.
{{Wikidata list
|sparql=SELECT ?item WHERE { { ?item wdt:P2009 ?dummy0 . } UNION { ?item wdt:P2010 ?dummy1 . } UNION { ?item wdt:P2033 ?dummy2 . } } 
|sort=label
|columns=p18,label:Camera,p176,P571,p2033,P2009,P2010,p179
}}

{{Wikidata list end}}

Wikidata list - Result of above Coding example edit

This is a permanent copy of the result of the above code, reduced to two entries (of about 2,000).

  • The table on the Userpage from which this copy was taken is NOT permanent - it will be updated every 24 hrs. by the template "Wikidata list".

 


This list is periodically updated by a bot. Manual changes to the list will be removed on the next update!

WDQS | PetScan | TABernacle | Find images | Recent changes | Query: SELECT ?item WHERE { { ?item wdt:P2009 ?dummy0 . } UNION { ?item wdt:P2010 ?dummy1 . } UNION { ?item wdt:P2033 ?dummy2 . } }
image Camera manufacturer inception category for pictures taken with camera Exif model Exif make part of the series
 
507SH Sharp Corporation Category:Taken with Sharp Aquos 507SH 507SH SHARP
 
AQUOS CRYSTAL Y2 403SH Sharp Corporation Category:Taken with SoftBank Sharp Aquos Crystal 2 403SH 403SH SHARP
End of automatically generated list.

Query 02 edit

#Wikidata Entries with manufacturer=Carl Zeiss AG (P176=Q282186) AND image captured with: Sony α7R IV (P4082=Q65976324)
#Configured 2020-07

SELECT DISTINCT ?idExtension ?extension ?idExtensionLabel ?idCamera
WHERE
{
	?idExtension wdt:P176 wd:Q282186;   # manufacturer ( P176 ): Carl Zeiss AG ( Q282186 )
	             wdt:P279 wd:Q192234    # subclass of ( P279 ): camera lens ( Q192234 )
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?extension

Query 02A edit

  1. Wikidata Entries with "is a ( P31 ): prime lens ( Q631962 )" AND "manufacturer ( P176 ): Carl Zeiss AG ( Q282186 ) or by Canon ( Q62621 )"
  2. Configured 2021-02
# Choose between lenses manufactured by Carl Zeiss AG ( Q282186 ) or by Canon ( Q62621 ).

SELECT DISTINCT ?lens ?lensLabel ?lensImage ?massLabel ?focallengthLabel ?article
WHERE
{
  ?lens wdt:P31 wd:Q631962 .            # is a ( P31 ): prime lens ( Q631962 )
#  ?lens wdt:P31 wd:Q21233320 .  # is a ( P31 ): Carl Zeiss Batis Sonnar T* 1.8/85 (Q21233320) 
#  ?lens wdt:P279 wd:Q631962 .            # subclass of ( P279 ): prime lens ( Q631962 )
#  ?lens wdt:P4082 wd:Q65976324 .  # image captured with ( P4082 ): Sony α7R IV ( Q65976324 )
#  ?lens wdt:P279 wd:Q192234 .  # subclass of ( P279 ): camera lens ( Q192234 )

  ?lens wdt:P176 wd:Q282186 .  # manufacturer ( P176 ): Carl Zeiss AG ( Q282186 )
#  ?lens wdt:P176 wd:Q62621 .  # manufacturer ( P176 ): Canon ( Q62621 )
  
  OPTIONAL {?lens wdt:P18 ?lensImage . }    # image (P18)
  OPTIONAL {?lens wdt:P2067 ?mass . }  # mass ( P2067 )
  OPTIONAL {?lens wdt:P2151 ?focallength . }  # focal length ( P2151 )
  
  OPTIONAL {?article schema:about ?lens .    #  has a Wikipedia article
            ?article schema:isPartOf <https://en.wikipedia.org/> .
            ?sitelink ^schema:name ?article . }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?lensLabel

Query 02B edit

Search for instances of a camera lens within WikiData.

  • Last revision 2021-12-15.
  • NOTE: This query reveals only a small fraction of all lenses stored within WikiData! See #Query 02C.
  • RESULT: 2021-12-15: 31 items when column ?subclassOf is included, 28 items without column ?subclassOf.
# Find all 'instances of (P31)' a 'camera lens (Q192234)' within WikiData.
# Last revision:  2021-12-15.
# Table columns with explanations:  ?lens ?lensLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image (hyperlink only) ?massLabel ?focallengthLabel ?WPENarticle (WPEN=Wikipedia:en) ?WPDEarticle (WPDE=Wikipedia:de)
# NOTE:  The sort order applied to the column "lensLabel" displays entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", first after all entries containing the regular set of characters.
# NOTE:  This query reveals only a small fraction of all lenses stored within WikiData!

SELECT DISTINCT ?lens ?lensLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image ?massLabel ?focallengthLabel ?WPENarticle ?WPDEarticle  # WPEN/WPDE = Wikipedia:en/de
WHERE {
  ?lens wdt:P31 wd:Q192234 .            # instance of (P31): camera lens (Q192234)   # RESULT => 28 items
  
  OPTIONAL {?lens wdt:P176 ?manufacturer . }       # manufacturer (P176)
  OPTIONAL {?lens wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?lens wdt:P279 ?subclassOf . }         # subclass of (P279)   # NOTE: Adding this term to the query raises RESULT from 28 to 31 items due to 3 entries having two subclass entries, which are dutily displayed as separate items.
  OPTIONAL {?lens wdt:P18 ?image . }           # image (P18)
  OPTIONAL {?lens wdt:P2067 ?mass . }              # mass (P2067)
  OPTIONAL {?lens wdt:P2151 ?focallength . }       # focal length (P2151)
  
  OPTIONAL {?WPENarticle schema:about ?lens .      #  has a Wikipedia:en article
            ?WPENarticle schema:isPartOf <https://en.wikipedia.org/> .
            ?WPENsitelink ^schema:name ?WPENarticle . }
   
  OPTIONAL {?WPDEarticle schema:about ?lens .      #  has a Wikipedia:de article
            ?WPDEarticle schema:isPartOf <https://de.wikipedia.org/> .
            ?WPDEsitelink ^schema:name ?WPDEarticle . }
 
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?lensLabel))

Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.

Query 02C edit

Search for subclasses of an 'objective' (which has a greatly extended scope compared to 'camera lens') within WikiData.

  • Last revision 2021-12-15.
  • NOTE: This query should reveal all lenses stored within WikiData! CAVEAT: Lenses erraneously not classified as one of the subclasses of 'objective' will remain excluded from this list.
  • RESULT: 2021-12-15: 469 DISTINCT items when only columns ?lens and ?lensLabel are shown; 667 items when the following 7 columns are also displayed.
# Find all 'subclasses of (P279*)' an 'objective (Q3880557)' within WikiData.
# Last revision:  2021-12-15.
# Table columns with explanations:  ?lens ?lensLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image (hyperlink only) ?massLabel ?focallengthLabel ?WPENarticle (WPEN=Wikipedia:en) ?WPDEarticle (WPDE=Wikipedia:de)
# NOTE:  The sort order applied to the column "lensLabel" displays entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", first after all entries containing the regular set of characters.
# NOTE:  This query should reveal all lenses stored within WikiData!  CAVEAT: Lenses erraneously not classified as one of the subclasses of 'objective' will remain excluded from this list.

SELECT DISTINCT ?lens ?lensLabel ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image ?massLabel ?WPENarticle ?WPDEarticle  # RESULT => 2021-12-15: 667 items
#SELECT DISTINCT ?lens ?lensLabel   # ?manufacturerLabel ?instanceOfLabel ?subclassOfLabel ?image ?massLabel ?WPENarticle ?WPDEarticle  # RESULT => 2021-12-15: 469 items
WHERE {
#  {?lens wdt:P31/wdt:P279* wd:Q192234 . }             # instance of (P31) or subclass(es) of (P279*):  camera lens (Q192234)  # RESULT => only 42 items
#  {?lens wdt:P31/wdt:P279* wd:Q3880557 . }             # instance of (P31) or subclass(es) of (P279*):  objective (Q3880557)  # RESULT => only 49 items
  {?lens wdt:P279* wd:Q3880557 . }       # subclass(es) of (P279*):  objective (Q3880557)  # RESULT => 2021-12-15: 469 items when only columns ?lens and ?lensLabel are shown; 667 items when the following 7 columns are also displayed.

  OPTIONAL {?lens wdt:P176 ?manufacturer . }       # manufacturer (P176)
  OPTIONAL {?lens wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?lens wdt:P279 ?subclassOf . }         # subclass of (P279) NOTE: Adding this term to the query raises RESULT from 1578 to 1635 !
  OPTIONAL {?lens wdt:P18 ?image . }               # image (P18)
  OPTIONAL {?lens wdt:P2067 ?mass . }              # mass (P2067)
 
  OPTIONAL {?WPENarticle schema:about ?lens .      #  has a Wikipedia:en article
            ?WPENarticle schema:isPartOf <https://en.wikipedia.org/> .
            ?ENsitelink ^schema:name ?WPENarticle . }

  OPTIONAL {?WPDEarticle schema:about ?lens .      #  has a Wikipedia:de article
            ?WPDEarticle schema:isPartOf <https://de.wikipedia.org/> .
            ?DEsitelink ^schema:name ?WPDEarticle . }
 
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?lensLabel))  ASC(UCASE(?subclassOfLabel))

Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.

Query 02D edit

  1. Wikidata Entries with "is a ( P31 ): objective ( Q3880557 ) or of any of its subclasses".
  2. Note that some entries are listed 2-6x, due to multiple entries for manufacturer and/or focallength.
  3. Configured 2021-02
# Find all instances of objective ( Q3880557 ) and all subclasses within WikiData. 

SELECT DISTINCT ?lens ?lensLabel ?manufacturerLabel ?instanceOfLabel ?lensImage ?massLabel ?focallengthLabel ?article
WHERE
{
#  ?lens wdt:P31 wd:Q192234 .            # is a ( P31 ): camera lens ( Q192234 )
  ?lens wdt:P31/wdt:P279* wd:Q3880557 .  # is a ( P31 ) / subclass of (or instance of) ( P279 ):  objective ( Q3880557 )

  OPTIONAL {?lens wdt:P176 ?manufacturer . }    # manufacturer ( P176 )
  OPTIONAL {?lens wdt:P31 ?instanceOf . }    # instance of ( P31 )
  OPTIONAL {?lens wdt:P18 ?lensImage . }    # image (P18)
  OPTIONAL {?lens wdt:P2067 ?mass . }  # mass ( P2067 )
  OPTIONAL {?lens wdt:P2151 ?focallength . }  # focal length ( P2151 )
  
  OPTIONAL {?article schema:about ?lens .    #  has a Wikipedia article
            ?article schema:isPartOf <https://en.wikipedia.org/> .
            ?sitelink ^schema:name ?article . }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?lensLabel

Query 03 edit

How to display values of qualifiers.

Query 03A edit

# Wikidata query for manufacturer = Sony (Q41187) AND is a ( P31 ) / subclass of (or instance of) ( P279 ): camera model (Q20888659)
# Plus optional display of 2 qualifiers, if existent. 
# Configured 2021-11-16
 
SELECT DISTINCT ?item ?itemLabel ?serialNumberLabel ?totalProducedLabel ?connectedPart # ?dateofCommercializationLabel ?referenceURLLabel ?connectedPart
WHERE
{
   ?item wdt:P31/wdt:P279* wd:Q20888659 .  # is a ( P31 ) / subclass of (or instance of) ( P279 ): camera model (Q20888659) 
   ?item  wdt:P176 wd:Q41187 . # Sony (Q41187)

#  Of no succes, because dateofCommercialization is a VALUE. Will strive to find a solution!
#    OPTIONAL {?item p:P5204 ?node01 .          # date of commercialization (P5204)
#    ?node01 ps:P5204 ?dateofCommercialization??? .            # date of commercialization (P5204): ???value???
#    ?node01 pq:P854 ?referenceURL .  }    # reference URL (P854)

# No value found for this selection, but keep for further experiments:
   OPTIONAL {?item p:P527 ?node01 .          # has part ( P527 )
    ?node01 ps:P527 wd:Q205722 .            # has part ( P527 ): lens mount (Q205722)
    ?node01 pq:P2935 ?connectedPart .  }    # connector ( P2935 )

#  The only values found for the following 2 qualifiers are both for model Sony ZV-1:
    OPTIONAL {?item p:P176 ?node01 .          # manufacturer (P176)
    ?node01 ps:P176 wd:Q41187 .            # manufacturer (P176):  Sony (Q41187) 
    ?node01 pq:P2598 ?serialNumber .  }    #  serial number (P2598) 
  
    OPTIONAL {?item p:P176 ?node02 .          # manufacturer (P176)
    ?node02 ps:P176 wd:Q41187 .            # manufacturer (P176):  Sony (Q41187) 
    ?node02 pq:P1092 ?totalProduced .  }    #   total produced (P1092)  
   
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC (?serialNumberLabel)

Query 03B edit

Created code on Tue, 2021-11-16.

  • Display values of qualifiers embedded in a certain statement, if any exist.
# Search for subclass of (P31) OR instance of (P279): objective (Q3880557) and display amongst other data the values of qualifiers embedded in the "has part (P527)" statement, if any exist.
#
# Query presents values "Sony E-mount" and "2" for each one of 3 values stated for the property "has part ( P527 )".
# What I would prefer is that the value "Sony E-mount" should only be displayed in the row in which "hasPartLabel = lens mount (Q205722)" 
#   and the value "2" should only be displayed in the row in which "hasPartLabel = lens cover ( Q2011752 )". 
# Configured 2021-11-16

SELECT DISTINCT ?item ?itemLabel ?manufacturerLabel ?inception ?hasPart ?hasPartLabel ?connectedPartLabel  ?quantityLabel ?node
WHERE {
#  hint:Query hint:optimizer "None" .

  ?item wdt:P31/wdt:P279* wd:Q3880557 .  # is a ( P31 ) / subclass of (or instance of) ( P279 ): objective (Q3880557)
#  ?item wdt:P31/wdt:P279* wd:Q192234 .  # is a ( P31 ) / subclass of (or instance of) ( P279 ): camera lens (Q192234)
#  ?item wdt:P31/wdt:P279* wd:Q631962 .  # is a ( P31 ) / subclass of (or instance of) ( P279 ): prime lens (Q631962)
#  ?item wdt:P176 wd:Q41187 .  # manufacturer ( P176 ): Sony ( Q41187 )
 
  OPTIONAL {?item wdt:P571 ?inception . }    # inception ( P571 )
  OPTIONAL {?item wdt:P176 ?manufacturer . }    # manufacturer ( P176 )
  OPTIONAL {?item wdt:P527 ?hasPart . }   # has part ( P527 )
  OPTIONAL {?item p:P527 ?node01 .          # has part ( P527 )
    ?node01 ps:P527 wd:Q205722 .            # has part ( P527 ): lens mount (Q205722)
    ?node01 pq:P2935 ?connectedPart .  }    # connector ( P2935 )

  OPTIONAL {?item p:P527 ?node02 .          # has part ( P527 )
    ?node02 ps:P527 wd:Q2011752 .           # has part ( P527 ):  lens cover ( Q2011752 ) 
    ?node02 pq:P1114 ?quantity .  }         # quantity ( P1114 )

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?inception)

LIMIT 100

Query 04 edit

#defaultView:Map
SELECT ?item ?itemLabel ?placeofbirth ?coord ?dob
WHERE {
?item wdt:P27 wd:Q948.                  # country of citizenship ( P27) : Tunisia
?item wdt:P21 wd:Q6581072.              # sex ( P21 ): female ( Q6581072 ) or male ( Q6581097 )
?item wdt:P31 wd:Q5.                    # is a ( P31 ): human ( Q5 )
?item wdt:P106/wdt:P279 wd:Q36180.      # occupation ( P106 ) / subclass of ( P279 ): author ( Q36180 )
OPTIONAL {?item wdt:P19 ?placeofbirth.  # place of birth ( P19 )
?placeofbirth wdt:P625 ?coord }         # geographical coordinates
OPTIONAL {?item wdt:P569 ?dob.}         # date of birth ( P569 )
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr, ar ,en". }
}

Query 05 edit

SELECT ?item ?itemLabel ?instagram ?coordinates WHERE {
  ?item wdt:P31/wdt:P279* wd:Q33506 .
  ?item wdt:P2003 ?instagram .
  ?item wdt:P625 ?coordinates .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } .
}

Query 06 edit

  • One of the following statements also contains a property used in this query!
    • statement "notable work" ( P800 ) // item "The Lord of the Rings trilogy" ( Q190214 )
      "character role ( P453 ): Bilbo Baggins ( Q185737 )
SELECT DISTINCT ?actor ?actorLabel ?role ?roleLabel ?image
WHERE {
  ?movie wdt:P179 wd:Q190214 . # movie is part of Peter Jackson's LotR trilogy
  ?movie p:P161 ?actorStatement . # movie has actors cast
  ?actorStatement ps:P161 ?actor . # of which we get the Qid
  OPTIONAL { ?actor wdt:P18 ?image } . # and an image if one is declared
  ?actorStatement pq:P453 ?role . # the actors were cast as given roles
  ?role wdt:P31 wd:Q74359 . # roles that happen to be that of Hobbits
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 06A edit

Simplified query, now reduced to the query parts concerning "role" ( )

SELECT DISTINCT ?role ?roleLabel
WHERE {
  ?actorStatement pq:P453 ?role . # the actors were cast as given roles
  ?role wdt:P31 wd:Q74359 . # roles that happen to be that of Hobbits
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 06B edit

Altered "cast members" to "executive producer":

SELECT DISTINCT ?movie ?movieLabel ?actor ?actorLabel ?role ?roleLabel ?image ?producer ?producerLabel
WHERE {
  ?movie wdt:P179 wd:Q190214 . # movie is part of Peter Jackson's LotR trilogy
#  ?movie p:P161 ?actorStatement . # cast members (P161 )
#  ?actorStatement ps:P161 ?actor . # of which we get the Qid
  ?movie p:P1431 ?producerStatement . # executive producer ( P1431 )
  ?producerStatement ps:P1431 ?producer . # of which we get the Qid
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 06C edit

See: F:\_DATA\_PICS\_HowTo\WikiData_Query\WikiData_Query_Prefixes.png

Defined prefixes, beginning with "p" (NOTE: No other single-letter prefixes allowed)

 ?birthPlace p:P17 wd:Q193619 .   => No matching records found.
 ?birthPlace pq:P17 wd:Q193619 .  => 20 results    (list of persons containing place of birth)
   e.g. wds:Q65553541-08558dbd-442f-20ce-02fb-b382f6124420 ==> place of birth // Polokwane, sourcing circumstances: near, country: Union of South Africa
 ?birthPlace pr:P17 wd:Q193619 .  => No matching records found.
 ?birthPlace ps:P17 wd:Q193619 .  => 181 results   (list  of locomotives, companies, etc.)
   e.g. 	wds:Q7565666-80722cc9-4a85-2518-b5d7-8bc2bafdbf95 ==> country // Union of South Africa

Defined prefixes, beginning with "w" (NOTE: No other letter after "prefix "w" allowed):

 ?item wd:P585 wd:1832 .   =>  No matching records found.

Defined prefixes, beginning with "wd" (NOTE: No other letter after "prefix "wd" allowed):

 ?item wds:P585 wd:1832 .   =>  No matching records found.
 ?item wdt:P585 wd:1832 .   =>  No matching records found.
 ?item wdv:P585 wd:1832 .   =>  No matching records found.

WARNING for invalid prefixes: "QName 'pz:P17' uses an undefined prefix"

Query 07 edit

New attempt at combining two individual query lines:

SELECT DISTINCT ?item ?itemLabel ?role ?roleLabel # ?role ?roleLabel # ?actorStatement 
WHERE {
#   ?role ps:P69 wd:Q677993 . # educated at: University of South Africa => query of ONLY this line: 260 results
   ?item wdt:P512 wd:Q1765120 . # academic degree: Bachelor of Arts => query of ONLY this line: 1459 results
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 08 edit

Some tries at data concerning Barack Obama:

SELECT DISTINCT ?item ?itemLabel ?placeofbirth ?placeofbirthLabel ?dob # ?role ?roleLabel # ?role ?roleLabel # ?actorStatement 
WHERE {
# Barack Obama:
 ?item wdt:P27 wd:Q30 .           # country of citizenship ( P27) : USA
 ?item wdt:P21 wd:Q6581097 .      # male ( female: wd:Q6581072 )
 ?item wdt:P31 wd:Q5 .            # is a ( P31 ): human ( Q5 )
 ?item wdt:P69 wd:Q49088 .        # educated at: Columbia University => first 4 lines: 3775 results, including: Obama
# ?item wdt:P106 wd:Q28532974 .    # occupation ( P106 ): community organizer ( Q28532974 ) => first 4 lines + only this line: 0 result
# ?item wdt:P734 wd:Q5280414 .     # family name ( P734 ): Obama ( Q5280414 ) => first 4 lines + only this line: 1 result: Obama
# ?item wdt:P735 wd:Q18643532 .    # qiven name ( P735 ): Barack ( Q18643532 ) => first 4 lines + only this line: 1 result: Obama
# ?item wdt:P735 wd:Q27101961 .    # given name ( P735 ): Hussein ( Q27101961 ) => first 4 lines + only this line: 0 result
# ?item wdt:P19 wd:Q6366688 .      # place of birth ( P19 ): Kapiolani Medical Center for Women and Children ( Q6366688 ) => first 4 lines + only this line: 1 result: Obama
# ?item wdt:P551 wd:Q35525 .       # residence ( P551 ): White House ( Q35525 ) => first 4 lines + only this line: 0 result
# ?item wdt:P551 wd:Q1297 .        # residence ( P551 ): Chicago ( Q1297 ) => first 4 lines + only this line: 4 results, but NOT Obama

# ?item wdt:P39 wd:Q11696 .        # position held ( P39 ): President of the United States ( Q11696 ) => first 4 lines + only this line: 2 results, including: Obama
# ?item wdt:P1365 wd:Q207 .        # replaces ( P1365 ): George W. Bush ( Q207 ) => first 4 lines + only this line (also tried varoius prefixes: all 0 result

# ?item wdt:P1429 wd:Q1273495 .    # has pet ( P1429 ): Bo ( Q1273495 ) => first 4 lines + only this line: 1 result: Obama
 ?item wdt:P1429 wd:Q1273495 .    # has pet ( P1429 ): Sunny ( Q14744025 ) => first 4 lines + only this line: 1 result: Obama

#OPTIONAL {?item wdt:P19 ?placeofbirth . }
# OPTIONAL {?item wdt:P19 ?placeofbirth .
# ?placeofbirth wdt:P625 ?coord . }
# OPTIONAL {?item wdt:P19 ?placeofbirth .
# ?placeofbirth wdt:P31 ?institutionLabel . }    # instance of ( P31 ): hospital ( Q16917 )
 OPTIONAL {?item wdt:P569 ?dateofbirth .
 ?dateofbirth wdt:P31 ?dob . }    # date of birth ( P31 ): 4 August 1961 ( --- )
  
# Ernest Greenwood (Only for comparison tests, also an USA politician):
# ?item wdt:P106 wd:Q82955 .   # occupation ( P106 ): politician ( Q82955 )
# ?item wdt:P106 wd:Q37226 .   # occupation ( P106 ): teacher ( Q37226 )
# ?item wdt:P19 wd:Q163 .      # place of birth ( P19 ): Yorkshire ( Q163 )
  
OPTIONAL {?item wdt:P19 ?placeofbirth.}
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 08A edit

Now able to display "?placeofbirth , ?person , ?birthname":

SELECT DISTINCT ?person ?personLabel ?placeofbirth ?placeofbirthLabel ?dob ?dobLabel ?birthname ?occupation ?occupationLabel    # ?role ?roleLabel # ?role ?roleLabel ?coord ?institutionLabel 
WHERE {
# Barack Obama:
 ?person wdt:P27 wd:Q30 .           # country of citizenship ( P27) : USA
 ?person wdt:P21 wd:Q6581097 .      # male ( female: wd:Q6581072 )
 ?person wdt:P31 wd:Q5 .            # is a ( P31 ): human ( Q5 )
 ?person wdt:P69 wd:Q49088 .        # educated at: Columbia University => first 4 lines: 3775 results, including: Obama
# ?person wdt:P106 wd:Q28532974 .    # occupation ( P106 ): community organizer ( Q28532974 ) => first 4 lines + only this line: 0 result
 ?person wdt:P734 wd:Q5280414 .     # family name ( P734 ): Obama ( Q5280414 ) => first 4 lines + only this line: 1 result: Obama
# ?person wdt:P735 wd:Q18643532 .    # qiven name ( P735 ): Barack ( Q18643532 ) => first 4 lines + only this line: 1 result: Obama
# ?person wdt:P735 wd:Q27101961 .    # given name ( P735 ): Hussein ( Q27101961 ) => first 4 lines + only this line: 0 result
# ?person wdt:P19 wd:Q6366688 .      # place of birth ( P19 ): Kapiolani Medical Center for Women and Children ( Q6366688 ) => first 4 lines + only this line: 1 result: Obama
# ?person wdt:P551 wd:Q35525 .       #  residence ( P551 ): White House ( Q35525 ) => first 4 lines + only this line: 0 result
# ?person wdt:P551 wd:Q1297 .        #  residence ( P551 ): Chicago ( Q1297 ) => first 4 lines + only this line: 4 results, but NOT Obama

 ?person p:P106 ?occupationStatement . # occupation ( P106 )
 ?occupationStatement ps:P106 ?occupation . # of which we get the Qid

# ?person wdt:P39 wd:Q11696 .        # position held ( P39 ): President of the United States ( Q11696 ) => first 4 lines + only this line: 2 results, including: Obama
# ?person wdt:P1365 wd:Q207 .        # replaces ( P1365 ): George W. Bush ( Q207 ) => first 4 lines + only this line (also tried varoius prefixes: all 0 result

# ?person wdt:P1429 wd:Q1273495 .    #  has pet ( P1429 ): Bo ( Q1273495 ) => first 4 lines + only this line: 1 result: Obama
# ?person wdt:P1429 wd:Q1273495 .    #  has pet ( P1429 ): Sunny ( Q14744025 ) => first 4 lines + only this line: 1 result: Obama

 OPTIONAL {?person wdt:P19 ?placeofbirth . }
 OPTIONAL {?person wdt:P569 ?dob . }
 OPTIONAL {?person wdt:P1477 ?birthname . }  # birth name ( P1477 )
  
# OPTIONAL {?person wdt:P19 ?placeofbirth .
# ?placeofbirth wdt:P625 ?coord . }
# OPTIONAL {?person wdt:P19 ?placeofbirth . 
# ?placeofbirth wdt:P31 ?institutionLabel . }    # instance of ( P31 ): hospital ( Q16917 )
# OPTIONAL {?person wdt:P569 ?dateofbirth . 
# ?dateofbirth wdt:P31 ?dob . }    # date of birth ( P31 ): 4 August 1961 ( --- )
  
# Ernest Greenwood (Only for comparison tests, also an USA politician):
# ?person wdt:P106 wd:Q82955 .   # occupation ( P106 ): politician ( Q82955 )
# ?person wdt:P106 wd:Q37226 .   # occupation ( P106 ): teacher ( Q37226 )
# ?person wdt:P19 wd:Q163 .      # place of birth ( P19 ): Yorkshire ( Q163 )
  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query 09 edit

Find all instances of a plant within Wikidata

  • Show content or link to: ?plantLabel ?plantImageLabel ?commonscategory(Label) ?article
SELECT DISTINCT ?plant ?plantLabel ?plantImageLabel ?commonscategory ?commonscategoryLabel ?article #  ?wikimediacategory ?focallengthLabel
WHERE
{
  ?plant wdt:P31 wd:Q756 .                               # is a ( P31 ):  plant ( Q756 ) 
#  ?plant wdt:P180 wd:Q149414 .                           # depicts ( P180 ): Rhipsalideae ( Q149414 ) # 0 results
  OPTIONAL {?plant wdt:P18 ?plantImage . }               # image (P18)
  OPTIONAL {?plant wdt:P373 ?commonscategory . }         # commons category ( P373 )
#  OPTIONAL {?plant wd:Q4167836 ?wikimediacategory . }    # Wikimedia category (Q4167836) ==> doesn't work this way!!
  OPTIONAL {?article schema:about ?plant .               #  has a Wikipedia article
            ?article schema:isPartOf <https://en.wikipedia.org/> .
            ?sitelink ^schema:name ?article . }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?plantLabel

Query 10 edit

Example Plaques in Aberdeen.

SELECT ?plaque ?subjectLabel ?plaqueLabel ?plaqueImage ?occupationLabel ?coordinates ?DoB ?DoD ?article
{
  ?plaque wdt:P31 wd:Q721747 .                  # instance of (P31): commemorative plaque (Q721747)
  ?plaque wdt:P131 wd:Q62274582 .               # located in (P131): Aberdeen City (Q62274582)
  ?plaque wdt:P547 ?subject .                   # commemorates ( P547 )
  ?subject wdt:P31 wd:Q5 .                      # instance of ( P31 ): human ( Q5 ) 
  ?subject wdt:P21 wd:Q6581072 .                # gender of ( P21 ): female ( Q6581072 )
  ?subject wdt:P106 ?occupation .               # occupation ( P106 )
  ?occupation wdt:P31/wdt:P279* wd:Q66811410 .  # occupation (P31) / subclass of (or instance of) ( P279 ): the medical profession ( Q66811410 )
  OPTIONAL {?plaque wdt:P18 ?plaqueImage . }    # image (P18)
  OPTIONAL {?plaque wdt:P625 ?coordinates . }   # geographical coordinates ( P625  )
  OPTIONAL {?subject wdt:P569 ?DoB . }          # Date of birth ( P569 )
  OPTIONAL {?subject wdt:P570 ?DoD . }          # Date of death ( P570 )
  OPTIONAL {?article schema:about ?subject .    #  has a Wikipedia article
            ?article schema:isPartOf <https://en.wikipedia.org/> .
            ?sitelink ^schema:name ?article . }
  
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?subjectLabel

Query 11 edit

# Title: "Locations of hillforts that are in the Atlas"
# The following query uses these:
#   Items: hillfort (Q744099)  View with Reasonator View with SQID
#   Properties: instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, coordinate location (P625)  View with Reasonator View with SQID, Atlas of Hillforts ID (P4102)  View with Reasonator View with SQID, image (P18)  View with Reasonator View with SQID
#   Features: Map (Q24515275)  View with Reasonator View with SQID

# defaultView:Map
SELECT ?label 
      (SAMPLE(?coord) AS ?where) 
       ?subj 
      (?typeLabel AS ?layer)
       ?image
      (URI(CONCAT("https://hillforts.arch.ox.ac.uk/?query=Atlas_of_Hillforts_4166_0%2CMain_Atlas_Number%2C",?atlas)) AS ?atlaslink)

WHERE
{ ?subj wdt:P31/wdt:P279? ?type ;                        
        wdt:P625 ?coord ;
        wdt:P31 ?type ;
        wdt:P4102  ?atlas ;
        rdfs:label ?label filter (lang(?label) = "en") .
 
  OPTIONAL{ ?subj wdt:P18 ?image } 
            ?type wdt:P279? wd:Q744099 ;
            rdfs:label ?typeLabel filter (lang(?typeLabel) = "en")
                
} GROUP BY ?label ?subj ?typeLabel ?image ?atlas

Query 12 edit

Query 12A - Querying a class tree edit

Extracted from Wikidata:SPARQL query service/queries#Querying a class tree.

# Find class ?tree0 (in this case Q875538) for a given class.
  # what properties are registered as normally applying
  # to it, or to a super-class of it
  # Query generated by Template:PropertyForThisType

SELECT ?class ?classname ?property ?propertyname 
WHERE 
{
  ?tree0 (wdt:P279)*      ?class .
  BIND   (wd:Q875538  AS  ?tree0)
 
  ?class wdt:P1963        ?property .

  SERVICE wikibase:label
  {
    bd:serviceParam wikibase:language "en" .
    ?class     rdfs:label  ?classname .
    ?property  rdfs:label  ?propertyname .
  }
}

ORDER BY ?propertyname

Query 12B - Properties representing a technical standard edit

Search for all properties with a value representing a technical standard.

  • NOTE: I haven't yet figured out where and when one may make use of the operator "wikibase:directClaim".
# Find properties with a value representing a technical standard.

SELECT DISTINCT ?propertyRel ?propertyRelLabel ?propertyItem ?propertyItemLabel  # ?itemLabel
WHERE 
{
  ?item          ?propertyRel          ?standard.
  ?standard      wdt:P31               wd:Q317623.
  ?propertyItem  wikibase:directClaim  ?propertyRel

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ASC(UCASE(?propertyItemLabel))

Query 12C - Get all Values of all Properties for a Wikidata Item edit

Search for all values of all properties for a Wikidata item.

  • NOTES:
    • Uses "VALUES" operator.
    • Uses "rdfs:label".
# Search for all values of all properties for a Wikidata item.

SELECT ?item ?itemname ?property ?propertyname ?value
WHERE
{
  VALUES ?item {wd:Q52}.  # When this line is executed alone, the result has on value: item "wd:Q52", itemname "Wikipedia"
  ?item ?property ?value.  # Value(s) attributed to each property , e.g.the item Wikipedia (Q52) has a property "described by source (P1343)", which in turn has multiple values: "Larousse Encyclopedia online (Q17329836)", "Encyclopædia Britannica (Q455)", and two more.
                           # 2024-05-23: 1288 results in 1067 ms
  
  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
    ?item  rdfs:label  ?itemname .
    ?property  rdfs:label  ?propertyname .
  }
}

# ORDER BY ASC(UCASE(?property))
ORDER BY ASC(UCASE(?value))

## LIMIT 20


Query 12D_a - Search / compare corresponding values of all properties for two (or more) Wikidata items edit

Search for and compare corresponding values of all properties for two (or more) Wikidata items.

  • NOTES:
    • Uses "VALUES" operator.
    • Uses "rdfs:label".
    • Optionally displays property labels wherever applicable.
    • Choose SORT ORDER that suits you best in how identical properties are placed ajacent to each other within the table.
  • Challenge:
    • Select those "propertyItemnames" that are only stated for one of the two items.
  • CAVEAT:
    • If multiple values exist within a statement and one is set to "preferred" status all other values are ignored in this query!
# Search for and compare corresponding values of all properties for two (or more) Wikidata items.
# 
#   The SORT ORDER "ASC(xsd:integer(STRAFTER(STR(?property), 'P')))" ensures that identical properties are placed ajacent to each other within the table AND that all occurrances of a statement (e.g. P31) are placed adjacent.
#     Properties that do NOT apply to the above stated SORT ORDER conversion statement are placed at the top of the list.
#   The SORT ORDER "DESC(UCASE(?propertyItemname))" ensures that identical properties are placed ajacent to each other within the table.
#     The properties that apply to the above stated SORT ORDER statement are placed at the top of the list, albeit in DESC order.
#   Choose which of these two variants suits you best. 
# 
#   The "label" of each property (only extant for properties stated as "wdt:Pnnnn") is optionally displayed in the column "propertyItemname". 
#     This enables one to quickly identify the meaning of that property.
# 
#   Next challenge: select those "propertyItemnames" that are only stated for one of the items. 
#     Example: "user manual URL (P2078)" is only stated for "Fujifilm GFX100S (Q105102556)".

SELECT ?item ?itemname ?property ?propertyname ?propertyItemname ?value
WHERE
{
  VALUES ?item {wd:Q105102556 wd:Q125960897}.  # When this line is executed alone, the result has two values: item "wd:Q105102556", itemname "Fujifilm GFX100S"; item "wd:Q125960897", itemname "Fujifilm GFX100S II".
  ?item ?property ?value.  # Value(s) attributed to each property , e.g. the item Fujifilm GFX100S (Q105102556) has a property "rdfs:label", which in this case has two values.
                           # 2024-05-23: 103 results in 350 ms; 2024-05-24: 102 results in 442 ms (NOTE: raised one of two "followed by (P156)" values for Fujifilm GFX100S (Q105102556) to "preferred" status today. The other value is now ignored!
  
  OPTIONAL { ?propertyItem  wikibase:directClaim  ?property . } # Retrieve "?propertyItem" of "?property".
  
  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
    ?item  rdfs:label  ?itemname .
    ?property  rdfs:label  ?propertyname .
    ?propertyItem  rdfs:label  ?propertyItemname .
  }
}

# ORDER BY DESC(UCASE(?propertyItemname))
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))

## LIMIT 20


Query 12D_b - Search for properties contained in the first of two Wikidata items, but not in the second edit

Search for properties contained in the first of two Wikidata items, but not in the second.

  • NOTES:
    • This is the first attempt at the challenge presented in Query 12D_a. It does not yet reflect the opposite view as to what the second item contains that is missing in the first.
    • Uses "FILTER NOT EXISTS" operator.
# Search for properties contained in the first of two Wikidata items, but not in the second.
#   This example: item 01: Fujifilm GFX100S (Q105102556), item 02: Fujifilm GFX100S II (Q125960897).
#   RESULTS:  2024-05-24: 10 results in 186 ms; checked result values: YES, all 10 are missing in item 02.

SELECT
  ?p ?pLabel   (SAMPLE(?url) as ?url_comp2)
WHERE
{
  # hint:Query hint:optimizer "None".

  BIND( wd:Q105102556 as ?comp1)   ## Fujifilm GFX100S (Q105102556)
  BIND( wd:Q125960897 as ?comp2)   ## Fujifilm GFX100S II (Q125960897)

  ?comp1 ?wdt ?v .
  ?p wikibase:directClaim ?wdt .
  ?p wikibase:propertyType ?WBpropertyType 
     
  FILTER NOT EXISTS { ?comp2 ?wdt [] }
  OPTIONAL { ?p wdt:P1630 ?f }
  BIND(uri(REPLACE(?f,"\\$1",?v)) as ?url)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

GROUP BY ?p ?pLabel
ORDER BY ?pLabel

Query 12D_c - Search for Properties Contained in the First of two Wikidata items, but not in the Second edit

Search for properties contained in the first of two Wikidata items, but not in the second.

  • NOTES:
    • This is the second attempt at the challenge presented in Query 12D_a. It does not yet reflect the opposite view as to what the second item contains that is missing in the first.
      But it does now indicate to which item the data set belongs; refer to columns: ?item ?itemLabel.
    • Uses "FILTER NOT EXISTS" operator.
# Search for properties contained in the first of two Wikidata items, but not in the second.
#   This example: item 01: Fujifilm GFX100S (Q105102556), item 02: Fujifilm GFX100S II (Q125960897).
#   RESULTS:  2024-05-25: 17 results in 142 ms, of which 7 are duplicates; checked result values: YES, all 17 are missing in item 02.
# NOTE:
#   Columns "?item1" and "?item1Label" indicate to which item the retrieved properties are attributed.

SELECT
  # DISTINCT  ?item ?itemLabel ?property ?propertyLabel ?propertyItem ?propertyItemLabel ?WBpropertyType           ## 2024-05-25: 10 results in 132 ms
  DISTINCT  ?item ?itemLabel ?property ?propertyLabel ?propertyItem ?propertyItemLabel ?WBpropertyType ?value  ## Including column "?value" displays a data set for each value, i.e. multiple sets for properties with multiple values; 2024-05-25: 17 results in 287 ms 
  # ?propertyItem ?propertyItemLabel # (SAMPLE(?url) as ?url_comp2)
WHERE
{
  # hint:Query hint:optimizer "None".

  BIND( wd:Q105102556 as ?item1)   ## Fujifilm GFX100S (Q105102556)
  BIND( wd:Q125960897 as ?item2)   ## Fujifilm GFX100S II (Q125960897)
  
  ?item1 ?property ?value .                                ## Retrieve all properties and all values of "?item1".  2024-05-25: 69 results in 215 ms
  ?propertyItem wikibase:directClaim ?property .           ## Retrieve "?propertyItem" of "?property". This reduces the result set.  2024-05-25: 28 results in 308 ms 
  ?propertyItem wikibase:propertyType ?WBpropertyType .    ## Retrieve "?WBpropertyType" from "?propertyItem". This further reduces the result set.  2024-05-25: 17 results in 142 ms 

  FILTER NOT EXISTS { ?item2 ?property [] }   ## Disregard if "?property" is also attributed to "?item2".
  
  BIND(?item1 as ?item)   ## Copy content of "?item1" to column "?item".
  
  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
  }
}
##-## GROUP BY ?propertyItem ?propertyItemLabel    # GROUP BY only accepted when SELECT contains no other variables than "?propertyItem ?propertyItemLabel" (see also "SELECT DISTINCT") # 2024-05-25: 10 results in 135 ms 
ORDER BY ?propertyItemLabel

Query 12D_d - Compare properties contained in two Wikidata items, but display only those that occur in only one of the two edit

Compare properties contained in two Wikidata items, but display only those properties that occur in only one of these two items, not in both.

  • NOTES:
    • EUREKA! This is the final and successful attempt at the challenge presented in Query 12D_a. The result displays all properties that occur in only one of these two items, not in both.
      Moreover each data set indicates not only which item it belongs to (columns: ?item ?itemLabel), but also the property type (?WBpropertyType) and the property's value (?value).
    • A separate column "?valueLabel" displays the label of each value, notably also exposing the labels of derived values of the form "?value = wd:Qnnnn".
    • Uses "FILTER NOT EXISTS" and "UNION "operators.
# Compare properties contained in two Wikidata items, but display only those properties that occur in only one of these two items, not in both.
#   This example:  item 01: Fujifilm GFX100 II (Q122731264),  item 02: Fujifilm GFX100S (Q105102556).
#   RESULTS:  2024-05-25: 17 results in 236 ms, of which 14 are from "?item1" (Q122731264) and 3 from "?item2" (Q105102556); checked result values: YES, all 14 / 3 are not defined for the other item.
# NOTE:
#   Columns "?item" and "?itemLabel" indicate which item each retrieved property is attributed to.
#   A separate column "?valueLabel" displays the label of each value, notably also exposing the labels of derived values of the form "?value = wd:Qnnnn".
#   In this example the chosen SORT ORDER places the data sets for "?item1 = Fujifilm GFX100 II" ahead of those for "?item2 = Fujifilm GFX100S".
#   Uses "FILTER NOT EXISTS" and "UNION "operators.

SELECT
  # DISTINCT  ?item ?itemLabel ?property ?propertyLabel ?propertyItem ?propertyItemLabel ?WBpropertyType           ## 2024-05-25: 10 results in 132 ms
  # DISTINCT  ?item ?itemLabel ?propertyItem ?propertyItemLabel ?WBpropertyType ?value  ## Including column "?value" displays a data set for each value, i.e. multiple sets for properties with multiple values; 2024-05-25: 17 results in 287 ms 
  DISTINCT  ?item ?itemLabel ?propertyItem ?itemLabelext ?propertyItemLabel ?valueLabel ?value ?WBpropertyType   ## Including column "?value" displays a data set for each value, i.e. multiple sets for properties with multiple values; the column "?valueLabel" displays the label of each value, especially of "?value = wd:Qnnnn" ;  2024-05-25: 64 results in 361 ms 
  # ?propertyItem ?propertyItemLabel # (SAMPLE(?url) as ?url_comp2)
WHERE
{
  # hint:Query hint:optimizer "None".

  BIND( wd:Q122731264 as ?item1)   ##  Fujifilm GFX100 II (Q122731264)
  BIND( wd:Q105102556 as ?item2)   ##  Fujifilm GFX100S (Q105102556)
  
  ## Establish a UNION to aggregate those property-related data sets found (a) only within "?item1" or (b) only within "?item2".
  {
    ?item1 ?property ?value .                                ## Retrieve all properties and all values of "?item1".  2024-05-25: 35 results in 234 ms, 29 for "?item1".
    ?propertyItem wikibase:directClaim ?property .           ## Retrieve "?propertyItem" of "?property".  This reduces the result set. 2024-05-25: 17 results in 244 ms, 14 for "?item1".
    ?propertyItem wikibase:propertyType ?WBpropertyType .    ## Retrieve "?WBpropertyType" from "?propertyItem". This may further reduce the result set to those with a property defined as "wdt:Pnnnn" (propertyLabel expanded as "http://www.wikidata.org/prop/direct/Pnnnn").  2024-05-25: 17 results in 236 ms, 14 for "?item1".
 
    FILTER NOT EXISTS { ?item2 ?property [] }   ## Disregard if "?property" is also attributed to "?item2".
  
    BIND(?item1 as ?item)   ## Copy content of "?item1" to column "?item".
    # BIND(CONCAT("  ", STR(?itemLabel)) AS ?itemLabelext)   ## Prepend an empty marker to "?itemLabel" to visually separate data sets.
    BIND(CONCAT("", "1", "" ) AS ?itemLabelext)   ## Prepend a marker to "?itemLabel" to visually separate data sets in a separate column.
  }
  UNION
  {
    ?item2 ?property ?value .                                ## Retrieve all properties and all values of "?item2".  2024-05-25: 35 results in 234 ms, 6 for "?item2.
    ?propertyItem wikibase:directClaim ?property .           ## Retrieve "?propertyItem" of "?property". This reduces the result set.  2024-05-25: 17 results in 244 ms, 3 for "?item2". 
    ?propertyItem wikibase:propertyType ?WBpropertyType .    ## Retrieve "?WBpropertyType" from "?propertyItem". This may further reduce the result set to those with a property defined as "wdt:Pnnnn" (propertyLabel expanded as "http://www.wikidata.org/prop/direct/Pnnnn").  2024-05-25: 17 results in 236 ms, 3 for "?item2". 

    FILTER NOT EXISTS { ?item1 ?property [] }   ## Disregard if "?property" is also attributed to "?item1".
  
    BIND(?item2 as ?item)   ## Copy content of "?item2" to column "?item".
    BIND(CONCAT("_", "2", "_" ) AS ?itemLabelext)   ## Prepend a marker to "?itemLabel" to visually separate data sets in a separate column.
  }
  
  OPTIONAL ## Retrieve English label of the "?value". This is required to additionally expose the labels of derived values of the form "?value = wd:Qnnnn".
  {
    ?value rdfs:label ?valueLabel .  ## Retrieve all labels of the above "?value" as "?valueLabel". NOTE: retrieves all language variants.
    FILTER (LANG(?valueLabel)="en")  ## Single out the English label only.
  }

  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
  }
}

##-## GROUP BY ?propertyItem ?propertyItemLabel    # GROUP BY only accepted when SELECT contains no other variables than "?propertyItem ?propertyItemLabel" (see also "SELECT DISTINCT") # 2024-05-25: 10 results in 135 ms 
ORDER BY ASC(UCASE(?itemLabel)) ASC(UCASE(?propertyItemLabel))

Query 12D_e - Compare properties contained in two Wikidata items, but display only those properties that occur in both of these two items edit

Compare properties contained in two Wikidata items, but display only those properties that occur in both of these two items.

  • NOTES:
    • EUREKA AGAIN! This is the reverse query to the challenge presented in Query 12D_a. The result displays all properties that occur in both of these two items, not just in one.
      Moreover each data set indicates not only which item it belongs to (columns: ?item ?itemLabel), but also the property's value (?value) and, chosing the appropriate "SELECT DISTINCT" clause, also the property type (?WBpropertyType).
    • Added column "?itemLabelext" with easy to discern values to aid discerning whether a data set belongs to item1 or item2. Especially of importance for items named very similarly, such as Fujifilm GFXnnn cameras.
    • A separate column "?valueLabel" displays the label of each value, notably also exposing the labels of all derived values of the form "?value = wd:Qnnnn".
    • Uses "FILTER EXISTS" and "UNION "operators.
# Compare properties contained in two Wikidata items, but display only those properties that occur in both of these two items.
#   This example:  item 01: Fujifilm GFX100 II (Q122731264),  item 02: Fujifilm GFX100S (Q105102556).
#   RESULTS:  2024-05-25: 64 results in 953 ms (belonging to 18 different properties), of which 39 are from "?item1" (Q122731264) and 25 from "?item2" (Q105102556); checked result values: YES, all 18 properties occur in both items, but only a few of the 64 "?valueLabels" are identical, such as "has part(s)	= Fujifilm G-mount".
# NOTE:
#   Columns "?item" and "?itemLabel" indicate which item each retrieved property is attributed to.
#   A separate column "?valueLabel" displays the label of each value, notably also exposing the labels of values of the form "?value = wd:Qnnnn".
#   In this example the chosen SORT ORDER arranges the contents of "?propertyItemLabel" in alphabetical order. These are in turn alphabetically grouped by the second SORT ORDER term "?valueLabel"; identical values are then again grouped by "?itemLabel". 
#   Uses "FILTER EXISTS" and "UNION "operators.

SELECT
  # DISTINCT  ?item ?itemLabel ?propertyItem ?itemLabelext ?propertyItemLabel ?value                               ## Including column "?value" displays a data set for each value, i.e. multiple sets for properties with multiple values; 2024-05-25: 64 results in 361 ms 
  DISTINCT  ?item ?itemLabel ?propertyItem ?itemLabelext ?propertyItemLabel ?valueLabel ?value ?WBpropertyType   ## Including column "?value" displays a data set for each value, i.e. multiple sets for properties with multiple values; the column "?valueLabel" displays the label of each value, especially of "?value = wd:Qnnnn" ;  2024-05-25: 64 results in 361 ms 
  # ?propertyItem ?propertyItemLabel # (SAMPLE(?url) as ?url_comp2)
WHERE
{
  # hint:Query hint:optimizer "None".

  BIND( wd:Q122731264 as ?item1)   ##  Fujifilm GFX100 II (Q122731264)
  BIND( wd:Q105102556 as ?item2)   ##  Fujifilm GFX100S (Q105102556)
  
  ## Establish a UNION to aggregate those property-related data sets found both within "?item1" and "?item2".
  {
    ?item1 ?property ?value .                                ## Retrieve all properties and all values of "?item1".
    ?propertyItem wikibase:directClaim ?property .           ## Retrieve "?propertyItem" of "?property".  This reduces the result set.
    ?propertyItem wikibase:propertyType ?WBpropertyType .    ## Retrieve "?WBpropertyType" from "?propertyItem". This may further reduce the result set to those with a property defined as "wdt:Pnnnn" (propertyLabel expanded as "http://www.wikidata.org/prop/direct/Pnnnn").

    FILTER EXISTS { ?item2 ?property [] }   ## Disregard if "?property" is also attributed to "?item2".
  
    BIND(?item1 AS ?item)   ## Copy content of "?item1" to column "?item".
    # BIND(CONCAT("  ", STR(?itemLabel)) AS ?itemLabelext)   ## Prepend an empty marker to "?itemLabel" to visually separate data sets.
    BIND(CONCAT("", "1", "" ) AS ?itemLabelext)   ## Prepend a marker to "?itemLabel" to visually separate data sets in a separate column.
  }
  UNION
  {
    ?item2 ?property ?value .                                ## Retrieve all properties and all values of "?item2".
    ?propertyItem wikibase:directClaim ?property .           ## Retrieve "?propertyItem" of "?property". This reduces the result set.
    ?propertyItem wikibase:propertyType ?WBpropertyType .    ## Retrieve "?WBpropertyType" from "?propertyItem". This may further reduce the result set to those with a property defined as "wdt:Pnnnn" (propertyLabel expanded as "http://www.wikidata.org/prop/direct/Pnnnn").

    FILTER EXISTS { ?item1 ?property [] }   ## Disregard if "?property" is also attributed to "?item1".
  
    BIND(?item2 AS ?item)   ## Copy content of "?item2" to column "?item".
    BIND(CONCAT("_", "2", "_" ) AS ?itemLabelext)   ## Prepend a marker to "?itemLabel" to visually separate data sets in a separate column.
  }

  OPTIONAL ## Retrieve English label of the "?value". This is required to additionally expose the labels of derived values of the form "?value = wd:Qnnnn".
  {
    ?value rdfs:label ?valueLabel .  ## Retrieve the label of the above "?value" as "?valueLabel". NOTE: retrieves all language variants.
    FILTER (LANG(?valueLabel)="en")  ## Single out the English label only.
  }

  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
  }
}

ORDER BY ASC(UCASE(?propertyItemLabel)) ASC(UCASE(?valueLabel)) ASC(UCASE(?itemLabel))  ## Example: "?propertyItemLabel = has part(s)" occurs 11x, within which "?valueLabel = Fujifilm G-mount, image sensor, image stabilization" each occcur twice and are duly placed side-by-side via alphabetic sort.

Query 12E - List all properties / corresponding labels of instance of an online encyclopedia (Q615699) edit

Display a list of all properties (and their corresponding labels in plain text) that are used by any item that is an "instance of" an "online encyclopedia (Q615699)".

  • NOTES: --NONE--
# Display a list of all properties (and their corresponding labels in plain text) that are used by any item that is an "instance of" an "online encyclopedia (Q615699)".

SELECT DISTINCT ?propertyRel ?propertyRelLabel ?propertyItem ?propertyItemLabel  # ?itemLabel
WHERE 
{
  ?item                    ?propertyRel          ?onlineEncyclopedia .
  ?onlineEncyclopedia      wdt:P31               wd:Q615699 .
  ?propertyItem            wikibase:directClaim  ?propertyRel .

  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
  }
}

ORDER BY ASC(UCASE(?propertyItemLabel))

# LIMIT 20

Query 12F - Display a list of all properties and labels used by any (sub)instance of an item edit

Display a list of all properties (and their corresponding labels in plain text) that are used by any item that is an "(sub)instance of" an "online encyclopedia (Q615699)".

  • NOTES: --NONE--
# Display a list of all properties (and their corresponding labels in plain text) that are used by any item that is an "(sub)instance of" an "online encyclopedia (Q615699)".
#  NOTE: For some obscure reason this list is obviously incomplete for "digital camera model (Q20741022)"!
#        E.g. the properties (see propertyItemLabel) "inception (P571)", "manufacturer (P176)", "Exif make (P2010)"´, and many more are woefully missing.

### SELECT DISTINCT ?itemLabel ?propertyRel ?propertyRelLabel ?propertyItem ?propertyItemLabel  # ?itemLabel
SELECT DISTINCT ?propertyRel ?propertyRelLabel ?propertyItem ?propertyItemLabel  # ?itemLabel
WHERE 
{
  ?item                    ?propertyRel          ?itemsInstancesOf .
  # ?itemsInstancesOf      wdt:P31               wd:Q615699 .    # Online Encyclopedia (Q615699) - 2024-05-23: 102 results in 15349 ms
  ?itemsInstancesOf        wdt:P31*              wd:Q20741022 .  # digital camera model (Q20741022) - 2024-05-23: 24 results in 796 ms
  ?propertyItem            wikibase:directClaim  ?propertyRel .

  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
  SERVICE wikibase:label 
  { 
    bd:serviceParam wikibase:language "en". # Get label in English
  }
}

ORDER BY ASC(UCASE(?propertyItemLabel))
### ORDER BY ASC(UCASE(?ItemLabel))

# LIMIT 20

Query 13 edit

Properties: Search for all properties defined within Wikibase.

Query 13A - all ENGLISH properties edit

  • The definitive List of all ENGLISH language properties definded within Wikibase!
    • These properties defined in Wikibase are used in a similar way within all Wikimedia projects, notably within Wikidata and Wikimedia Commons.
  • When are properties required?
  • (A) Wiki Commons / Upload:
    • As the last step when uploading a new file to Wiki Commons one is prompted to add structured data referring to the contents of the uploaded file.
    • Even for native English speakers it is often quite difficult to come up with the appropriate term that leads to the label of the desired property.
    • Some property labels sport alternative common terms (propertyAltLabel) that are automatically converted into the master property label.
    • Example: manufacturing process, cooking method, by means, by method, fabrication process, made by, etc. lead to property label fabrication method and thus to its property identifier P2079.
  • (B) Wiki Commons / Structured data:
    • Adding new properties to a Wikimedia Commons item or adding a qualifier to an existing Wikimedia Commons property can sometimes be quite frustrating as the structure checking mechanism will time after time annonunce "Potential issues - allowed entity types constraint - The property YYYY should not be used on this type of entity, the only valid entity type is Wikibase ZZZZ."
    • Just sort the table according to column "WBpropertyType" and flip pages until you find all results corresponding to the entity type "Wikibase:ZZZZ".
    • Note: As the query results in a rather unwieldy table with well over 9000 entries you may alternatively make use of query 13C and supplant the line
      "?property wikibase:propertyType wikibase:WikibaseItem ." with
      "?property wikibase:propertyType wikibase:ZZZZ .".
      This whittles the result table down to a manageable size containing just the property type mentioned in the above "Potential issues" warning.
  • I extracted the basic scheme for this query from the page Wikidata:SPARQL_query_service/queries/examples#Wikibase_predicates. Many thanks!
  • RESULTS: 2021-12-04: 9389 items / 2021-12-12: 9414 items / 2024-04-13: 11787 items.
# List of all properties described within Wikibase. Displays P-number and label for each entry, together with corresponding property type, description, and aliases, if provided.
# NOTE: This query returns only the ENGLISH language version of Wikibase properties.
# Click on column headers to change sort order. Note: the initial sort treats upper case, lower case, and diacritical letters alike. This is not true for subsequent sorts.
# The optional prefix "WB" for all identifiers refers to WikiBase.

SELECT ?WBpropertyType ?WBproperty ?WBpropertyLabel ?WBpropertyDescription ?WBpropertyAltLabel
WHERE
{
  ?WBproperty wikibase:propertyType ?WBpropertyType .       # RESULT => 2021-12-19: 9432 items.

  # SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Get label in your language, if it exists, otherwise the English label is provided
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # Get label in English
}

# #### Alternative ORDER statements that treat upper case, lower case, and diacritical letters alike. Choose between ASCending od DESCending order.
#      Remove "hash = #" character from desired ORDER statement and place in front of current ORDER statement. Note: only one active ORDER statement allowed. 
# ORDER BY ASC(UCASE(?WBpropertyType))                         # Order column WBpropertyType
# ORDER BY ASC(xsd:integer(STRAFTER(STR(?WBproperty), 'P')))   # Order column WBproperty 
ORDER BY ASC(UCASE(?WBpropertyLabel))                        # Order column WBpropertyLabel, ASC
# ORDER BY DESC(UCASE(?WBpropertyLabel))                       # Order column WBpropertyLabel, DESC
# ORDER BY ASC(UCASE(?WBpropertyDescription))                  # Order column WBpropertyDescription
  • Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.

Query 13B edit

  • Counts the number of instances of each "WBpropertyType":
    WBpropertyType = wikibase:ExternalId, wikibase:WikibaseItem, wikibase:Quantity, etc.
#Properties grouped by their type with number of properties
SELECT (COUNT(?property) as ?pcount ) ?WBpropertyType WHERE {
  
  ?property rdf:type               wikibase:Property.
  ?property wikibase:propertyType  ?WBpropertyType.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

GROUP BY ?WBpropertyType
ORDER BY DESC(?pcount)

Query 13C edit

  • Lists all instances with "WBpropertyType = wikibase:WikibaseItem".
  • One just needs to switch the comment preceding the "?WBproperty" statement on thre desired line (see also: query in section #Query 13B).
SELECT ?WBproperty  ?WBpropertyType ?WBpropertyLabel ?WBpropertyDescription ?WBpropertyAltLabel   WHERE {

  ?WBproperty wikibase:propertyType ?WBpropertyType .
  ?WBproperty rdf:type wikibase:Property.
#  ?WBproperty wikibase:propertyType wikibase:ExternalId .
  ?WBproperty wikibase:propertyType wikibase:WikibaseItem .
#  ?WBproperty wikibase:propertyType wikibase:Quantity .
#  ?WBproperty wikibase:propertyType wikibase:String .
#  ?WBproperty wikibase:propertyType wikibase:Url .
#  ?WBproperty wikibase:propertyType wikibase:CommonsMedia .
#  ?WBproperty wikibase:propertyType wikibase:Time .
#  ?WBproperty wikibase:propertyType wikibase:Monolingualtext .
#  ?WBproperty wikibase:propertyType wikibase:Math .
#  ?WBproperty wikibase:propertyType wikibase:WikibaseProperty .
  
#  ?WBproperty wikibase:propertyType wikibase:WikibaseSense .
#  ?WBproperty wikibase:propertyType wikibase:WikibaseLexeme .
#  ?WBproperty wikibase:propertyType wikibase:GlobeCoordinate .
#  ?WBproperty wikibase:propertyType wikibase:WikibaseForm .
#  ?WBproperty wikibase:propertyType wikibase:MusicalNotation .
#  ?WBproperty wikibase:propertyType wikibase:TabularData .
#  ?WBproperty wikibase:propertyType wikibase:GeoShape .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

 ORDER BY ASC(UCASE(?WBpropertyLabel))
# ORDER BY DESC(UCASE(?WBpropertyLabel))

Query 13D - ALL properties in ALL languages edit

Retrieve ALL properties in ALL languages as defined for Wikibase.

# List of all properties described within Wikibase. Displays P-number, property type and label for each entry. Also propertyAltLabel if "skos:altLabel" is activated.
# Last revision: 2021-12-19
# NOTE 01: This query retrieves ALL properties in ALL languages as defined for Wikibase.
# NOTE 02: SORTING via "ORDER BY" seems to apply to the combination <language>:<WBpropertyLabel>, not to the property label alone. E.g. "SKYPE" is placed at 15th position, due to the sort order presumably operating on the phrase  "Zulu:SKYPE".
# Click on column headers to change sort order. Note: the initial sort treats upper case, lower case, and diacritical letters alike. This is not true for subsequent sorts.
# The optional prefix "WB" for all identifiers refers to WikiBase.

SELECT DISTINCT
  ?WBproperty
  ?WBpropertyType
  ?WBpropertyLabel
  ?WBpropertyAltLabel
WHERE
{
  ?property a wikibase:Property ;
              rdfs:label ?WBpropertyLabel ;
              wikibase:propertyType ?WBpropertyType .          # Retrieves ALL properties in ALL languages as defined for Wikibase  # RESULT => 2021-12-19: 197564 items; 30 min. later: 197559  items.

#  OPTIONAL {?WBproperty skos:altLabel ?WBpropertyAltLabel .}  # This statement causes a timeout
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  # This statement once caused a timeout, not so later on with c. 32 sec. processing time.
}

ORDER BY DESC(UCASE(?WBpropertyLabel))                       # Order column WBpropertyLabel  # NOTE: SORTING seems to apply to the combination <language>:<WBpropertyLabel>, not to the property label alone. E.g. SKYPE is placed at 15th position, presumably as Zulu:SKYPE.
SELECT ?WBpropertyType ?WBproperty ?WBpropertyLabel ?WBpropertyDescription ?WBpropertyAltLabel
WHERE
{
  
  ?WBproperty wikibase:propertyType ?WBpropertyType .       # RESULT => 2021-12-19: 9432 items.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Query 13E - COUNT and GROUP BY edit

Combination of "wikibase:propertyType" and functions COUNT and GROUP BY.

# Properties grouped by their type with number of properties
SELECT (COUNT(?property) as ?pcount ) ?WBpropertyType 
WHERE 
{
  ?property rdf:type               wikibase:Property.
  ?property wikibase:propertyType  ?WBpropertyType.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

GROUP BY ?WBpropertyType
ORDER BY DESC(?pcount)

Query 13Z edit

  • Will also find out how to find the "propertyLabel" for any alternative designation (see "propertyAltLabel").
  • Example: query for "propertyAltLabel = production process" and find corresponding "propertyLabel = fabrication method".
    property: wd:P2079
    WBpropertyType: wikibase:WikibaseItem
    propertyLabel: fabrication method
    propertyDescription: method, process or technique used to grow, cook, weave, build, assemble, manufacture the item
    propertyAltLabel: manufacturing process, cooking method, assembly method, assembly process, by means, by method, creation method, fabrication process, made by, manufacturing method, method of assembly, method of cooking, method of fabrication, method of preparation, method used, preparation method, process used, produced by, produced using, production method, production process, technique used, technology used
  • Will try to check for class derivation of "wd:P1684 wikibase:Monolingualtext inscription".
    Aha, found: "wd:P2096 wikibase:Monolingualtext media legend".

Query 14 edit

Subsections contain links to documentation pages spread over a slew of Wikimedia projects.

Query 14A - Wikidata documentation edit

Query 14B - Wikibooks documentation edit

Query 14C - Wikimedia Commons documentation edit

Query 14D - XYZ edit

Query 15 edit

More about Wikidata Items.

Query 15A - Native Label (P1705) edit

SELECT ?WDProperty ?WDPropertyLabel ?WDresult ?WDresultLabel
WHERE {

  ?WDProperty wdt:P1705 ?WDresult .       # native label (P1705): all results => RESULT: see LIMIT

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

# ORDER BY ASC(UCASE(?WDPropertyLabel))   # NOTE: using "ORDER BY" causes timeout!
LIMIT 100

Query 15B - Wikimedia Commons (Q565) edit

SELECT ?WDProperty ?WDPropertyLabel
WHERE {

  ?WDProperty wdt:P31  wd:Q565 .       # instance of (P31): Wikimedia Commons (Q565) => RESULT: 10
#  ?WDProperty wdt:P279  wd:Q565 .      # subclass of (P279): Wikimedia Commons (Q565) => RESULT: 0 

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ASC(UCASE(?WDPropertyLabel))
# LIMIT 30

Query 15C - Wikidata property (P1687) edit

SELECT ?WDProperty ?WDPropertyLabel ?WDResult ?WDResultLabel
WHERE {

  ?WDProperty wdt:P1687  ?WDResult .       # Wikidata property (P1687) all results => RESULT: 10126
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ASC(UCASE(?WDPropertyLabel))
# LIMIT 30

Query 15D - type of Wikidata property (Q107649491) edit

SELECT ?WDProperty ?WDPropertyLabel
WHERE {

  ?WDProperty wdt:P31  wd:Q107649491 .   # instance of (P31): type of Wikidata property (Q107649491) => RESULT: 517
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ASC(UCASE(?WDPropertyLabel))
# LIMIT 30

Query 15E - Wikidata property for items about organizations (Q18608993) edit

SELECT ?WDProperty ?WDPropertyLabel ?WDresult ?WDresultLabel
WHERE { 

  ?WDProperty wdt:P31/wdt:P279* wd:Q18608993 . # Wikidata property for items about organizations (Q18608993) 
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

ORDER BY ASC(UCASE(?WDPropertyLabel))
# LIMIT 30

Query 16 edit

Query 16A edit

# Select all items with manufacturer (P176) = Carl Zeiss AG (Q282186) that have a subclass entry.
# NOTE: Using the WITH statement.

SELECT DISTINCT ?item ?itemLabel ?instanceOfLabel ?subclassOfLabel
WITH
{
  SELECT ?item
  WHERE
  {
    {?item wdt:P176 wd:Q282186 . }   # manufacturer (P176): Carl Zeiss AG (Q282186)
    {?item wdt:P279 ?subclassOf . } # subclass of (P279)  
  }
  # LIMIT 50
}
AS %with_subclass_entry
WHERE
{
  INCLUDE %with_subclass_entry

  OPTIONAL {?item wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?item wdt:P279 ?subclassOf . }         # subclass of (P279)   # NOTE: Adding this term to the query raises RESULT from 28 to 31 items due to 3 entries having two subclass entries, which are dutily displayed as separate items.
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

ORDER BY ?itemLabel

LIMIT 50

Query 16B edit

Search for items where manufacturer is stated as being 'Carl Zeiss AG', ignoring those items that have a valid 'subclass of' entry.

  • Last revision 2021-12-15.
  • NOTE: This query construct is very versatile. One usage is to reveal items LACKING a valid entry for a Wikidata property.
  • RESULT: 2021-12-15: 6 items (all with a valid 'subclass of' entry) when operator 'MINUS' is active, 12 items when operator 'MINUS' is deactivated (all without a valid 'subclass of' entry).
# Enlist all Wikidata items where manufacturer is stated as being 'Carl Zeiss AG', ignoring those items that have a valid 'subclass of' entry. 
#   This query construct is very versatile. One usage is to reveal items LACKING a valid entry for a Wikidata property.
# Query makes use of MINUS operator in combination with a subquery.
# Last revision : 2021-12-15.
# Table columns: ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel (WD=Wikidata)
# NOTE: The sort order applied to the column "cameraLabel" rearranges entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", AFTER entries containing the regular set of characters. 

SELECT DISTINCT ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel
WHERE
{
  {?WDitem wdt:P176 wd:Q282186 . }   # manufacturer (P176): Carl Zeiss AG (Q282186)

  OPTIONAL {?WDitem wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?WDitem wdt:P279 ?subclassOf . }         # subclass of (P279)   # NOTE: Adding this term to the query raises RESULT from 28 to 31 items due to 3 entries having two subclass entries, which are dutily displayed as separate items.

  MINUS            # NOTE: deactivating this line (by inserting a preceding "#") will display ONLY those entries with a valid 'subclass of' entry.
  {
    SELECT ?WDitem
    WHERE
    {
      {?WDitem wdt:P176 wd:Q282186 . }   # manufacturer (P176): Carl Zeiss AG (Q282186)
      {?WDitem wdt:P279 ?subclassOf . } # subclass of (P279)  
    }
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

ORDER BY ASC(UCASE(?WDitemLabel))

# LIMIT 50

Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.


Query 16C edit

Search for Wikidata items identified as lenses. Also contains a currently deactivated MINUS statement that enables removing certain items from the attained result.

  • Last revision 2021-12-15.
  • NOTE: This query construct is very versatile. One usage is to reveal items LACKING a valid entry for a Wikidata property.
    Just reactivate the operator 'MINUS' by removing the preceding "#", then type the the desired statement on one or many new lines within the embedded SELECT statement.
    The three mutually exclusive and currently deactivated examples should give you a head start.
  • RESULT: 2021-12-15: 670 items when operator 'MINUS' is inactive, 480 items when both the operator 'MINUS' and the statement '{?WDitem wdt:P31 ?instanceOf . }' ONLY are activated.
# Enlist all Wikidata items identified as lenses. Also contains a currently deactivated MINUS statement that enables removing certain items from the attained result.
#   This query construct is very versatile. One usage is to reveal items LACKING a valid entry for a Wikidata property.
# Query makes use of MINUS operator in combination with a subquery.
# Last revision : 2021-12-15.
# Table columns: ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel (WD=Wikidata)
# NOTE: The sort order applied to the column "WDitemLabel" rearranges entries containing foreign characters, such as "umlauts" or Greek characters, e.g. "Sony α7R IV", AFTER entries containing the regular set of characters. 

SELECT DISTINCT ?WDitem ?WDitemLabel ?instanceOfLabel ?subclassOfLabel
WHERE
{
  # This tiple UNION between four statements intends to extract all and every Wikidata item which can identified as a lens.
  {?WDitem wdt:P279* wd:Q3880557 . }                 # subclass(es) of (P279*):  objective (Q3880557)  # RESULT => 2021-12-15: 469 items when only columns ?lens and ?lensLabel are shown; 648 items when the columns ?instanceOfLabel ?subclassOfLabel are also displayed.
  UNION
  {?WDitem wdt:P31 wd:Q631962 . }                    # instance of (P31):  prime lens (Q631962)          # RESULT => 2021-12-15: 651 items
  UNION
  {?WDitem wdt:P31 wd:Q516461 . }                    # instance of (P31):  telephoto lens (Q516461)        # RESULT => 2021-12-15: 651 items 
  UNION
  {?WDitem wdt:P31 wd:Q192234 . }                    # instance of (P31):  camera lens (Q192234)           # RESULT => 2021-12-15: 670 items 
  
  OPTIONAL {?WDitem wdt:P31 ?instanceOf . }          # instance of (P31)
  OPTIONAL {?WDitem wdt:P279 ?subclassOf . }         # subclass of (P279)   # NOTE: Adding this term to the query raises RESULT from 28 to 31 items due to 3 entries having two subclass entries, which are dutily displayed as separate items.

  # MINUS statement enables removing certain items from the above attained result. In this case it is shown in combination with an embedded SELECT statement.
#  MINUS            # NOTE: deactivating this line (by inserting a preceding "#") will display ONLY those entries with a valid 'subclass of' entry.
  {
    SELECT ?WDitem
    WHERE
    {
#      {?WDitem wdt:P176 wd:Q282186 . }   # manufacturer (P176): Carl Zeiss AG (Q282186)     # Activate both this line and the MINUS statement to remove all items with manufacturer 'Carl Zeiss AG'.
#      {?WDitem wdt:P31 ?instanceOf . }   # instance of (P31)      # Activate both this line and the MINUS statement to remove all items that contain a valid 'instance of' value.
#      {?WDitem wdt:P279 ?subclassOf . }  # subclass of (P279)     # Activate both this line and the MINUS statement to remove all items that contain a valid 'subclass of' value.  
    }
  }

  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?WDitemLabel))

# LIMIT 50

Try it! (links to WQS = Wikidata Query Service) → To execute statement within WQS, press [CTRL-ENTER] or click on white triangle within left icon bar.


  • Test of template:
SELECT ?property ?propertyType ?propertyLabel ?propertyDescription ?propertyAltLabel WHERE {
  ?property wikibase:propertyType ?propertyType .
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))
Try it!


Query 16D edit

Search for Wikidata items containing the requested string (stated behind the statement beginning with 'mwapi:srsearch "') that have neither an 'instance of (P31)' nor a 'subclass of (P279)' statement.

  • Last revision 2021-12-16.
  • Example of a simple search for a specific STRING in combination with certain restrictions.
# Find all Wikidata items containing the string stated behind the statement beginning with 'mwapi:srsearch "' that have neither an 'instance of (P31)' nor a 'subclass of (P279)' statement.
# Example of a search for a specific STRING in combination with certain restrictions. 

SELECT DISTINCT ?item ?itemLabel 
WHERE
{
  hint:Query hint:optimizer "None" .
  
  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:api "Search" ;
                    wikibase:endpoint "www.wikidata.org" ;
#                    mwapi:srsearch "airport -haswbstatement:P31 -haswbstatement:P279" . # RESULT: 2021-12-16 58 items.
#                    mwapi:srsearch "Zeiss -haswbstatement:P31 -haswbstatement:P279" .   # RESULT: 2021-12-16 35 items.
#                    mwapi:srsearch "Sony -haswbstatement:P31 -haswbstatement:P279" .    # RESULT: 2021-12-16 336 items.
#                    mwapi:srsearch "Dortmund -haswbstatement:P31 -haswbstatement:P279" .   # RESULT: 2021-12-16 38 items.
#                    mwapi:srsearch "camera -haswbstatement:P31 -haswbstatement:P279" .   # RESULT: 2021-12-16 519 items.
#                    mwapi:srsearch "objective -haswbstatement:P31 -haswbstatement:P279" .   # RESULT: 2021-12-16 92 items.
                    mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279" .   # RESULT: 2021-12-16 197 items.
    ?title wikibase:apiOutput mwapi:title . 
  }

  BIND(IRI(CONCAT(STR(wd:), ?title)) AS ?item) 

  # Add any other requirements here

  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

# LIMIT 10    # LIMIT not necessary, as RESULTS: 2021-12-16 => all less than a few 1000 items.

Query 17 edit

Examples demonstrating use of various operators.

Query 17A edit

Retrieve all humans with at least one 'child' statement defined as "no value".

  • NOTE: Demonstrates use of 'wdno:' = 'no value' operator.
# Retrieve all humans with at least one 'child' statement defined as "no value".
# Demonstrates use of 'wdno:' = 'no value' operator.

SELECT ?human ?humanLabel 
WHERE
{
  ?human wdt:P31 wd:Q5 .                 # instance of (P31) humanm (Q5)

#  ?human p:P27 ?CoC .                    # with (at least one) 'country of citizenship (P27)' (abbrev. CoC) statement.
#  ?CoC rdf:type wdno:P27 .               # where the 'country of citizenship (P27)' statement is defined to be "no value".
 
  ?human p:P40 ?child .                  # with (at least one) 'child (P40)' statement.
  ?child rdf:type wdno:P40 .             # of which at least one 'child (P40)' statement is defined as 'no value'.

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?humanLabel))

Query 18 edit

Search for all Wikidata items that display the image stated in ENCODE_FOR_URI('...') term.

  • Last revision: 2021-12-17
  • The function cascade "BIND(IRI(CONCAT('...', ENCODE_FOR_URI('...'))) AS ?url) is required to construct a correctly URL-encoded term for the variable ?url. The IRI function adds the "<...>" parentheses.
# Find all Wikidata items that display the image stated in ENCODE_FOR_URI('...') term.
# Note that URL of the filename must be URL encoded. See example "EXAMPLE: URL-encoded term, ...".
# Last revision: 2021-12-17
# The function cascade "BIND(IRI(CONCAT('...', ENCODE_FOR_URI('...'))) AS ?url) is required to construct a correctly URL-encoded term for the variable ?url. The IRI function adds the "<...>" parentheses. 

SELECT ?item ?itemLabel ?urlLabel ?comm
WHERE
{
  ?item ?instanceOf ?url .
  BIND(wdt:P18 AS ?instanceOf).

  BIND(IRI(CONCAT('http://commons.wikimedia.org/wiki/Special:FilePath/', ENCODE_FOR_URI('Sony A77.jpg'))) AS ?url) .  # RESULT: 2021-12-17: 2 items

  # #### EXAMPLE 01: URL-encoded term, enclosed in "<...>" parentheses. This is also the result of the preceding statement using multiple functions:
  #      BIND(<http://commons.wikimedia.org/wiki/Special:FilePath/Sony%20A77.jpg> AS ?url) .                                 

  # #### EXAMPLE 02: Optional statement derived from page "https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples#List_of_small_monuments_with_link_to_Commons_category_(either_from_sitelink_and_P373)".
  #      Show external link to a Commons page, if any such link present.
  OPTIONAL 
  {
    ?comm schema:about ?item ;
          schema:isPartOf <https://commons.wikimedia.org/> . 
  }                            # RESULT: 2021-12-17: 1 entry in column '?comm' = <https://commons.wikimedia.org/wiki/Category:Sony_SLT-A77>

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

ORDER BY ASC(UCASE(?itemLabel))

LIMIT 100

Query 19 edit

Examples using the "wikibase:mwapi".

Query 19A - Members of Wikipedia category page edit

Search for all category members (see column subcat) that are enlisted on the page of the Wikipedia category that the initial Wikidata item's property "topic's main category (P910)" refers to.

  • Last revision: 2021-12-18
# Find all category members (column subcat) that are enlisted on the page of the wikipedia category that the initial Wikidata item's property "topic's main category (P910)" refers to.
#   And also display the identifiers of the Wikidata items (not all pages have one), based on the link named "Wikidata item", situated on the rightmost navigation bar of each Wikidata page.
# Last revision: 2021-12-18
# Uses the "wikibase:api".
# NOTE 01: This query processes not only subcategories, but also all pages and files found on the Wikipedia category page.
#          The column "ns" contains the value of an identifier named "@ns" that discriminates between Wikipedia page types.
#          E.g. @ns=0 is presumably a Wikipedia page, @ns=6 a file, @ns=14 seems to be a Wikipedia category. (Must verify this when I discover the corresponding documentation).
# NOTE 02: Page redirection is not supported! See results for initial "still camera (Q313600)".
# NOTE 03: Use of "SERVICE wikibase:label ..." suppresses all items that do not have a value in column "item".
# EXAMPLES pepared for use as initial Wikidata item:  digital camera (Q62927), still camera (Q313600), Parking facilities (Q7361750) 

# SELECT *
SELECT ?category ?link ?title ?subcat ?file ?ns ?item ?itemLabel 
WHERE 
{
  wd:Q62927 wdt:P910 ?category .         # digital camera (Q62927) : topic's main category (P910)    # RESULT: 2021-12-18:55 items 
#  wd:Q313600 wdt:P910 ?category .        # still camera (Q313600) : topic's main category (P910)    # RESULT: 2021-12-18:110 items
#  wd:Q6501349 wdt:P910 ?category .       # Parking lot (Q6501349): topic's main category (P910)     # RESULT: 2021-12-18:13 items
#  wdt:P910 wd:Q6501349 ?category .       # topic's main category (P910): Parking lot (Q6501349)     # NOTE / Warning: this is the WRONG order within statement! # RESULT: 2021-12-18:0 items
  
  ?link schema:about ?category ; 
        schema:isPartOf <https://en.wikipedia.org/> ; 
        schema:name ?title .

  SERVICE wikibase:mwapi
  {
    bd:serviceParam  wikibase:api        "Generator" .
    bd:serviceParam  wikibase:endpoint   "en.wikipedia.org" .
   
    bd:serviceParam  mwapi:generator     "categorymembers" .
    bd:serviceParam  mwapi:gcmtitle      ?title .
    bd:serviceParam  mwapi:gcmprop       "ids|title|type" .
    bd:serviceParam  mwapi:gcmlimit      "max" .
    
    bd:serviceParam  wikibase:limit      1000 .
 
    # The following statements process all subcategories, pages, and files found on the Wikipedia site stated as the initial site's "topic's main category (P910)".
    #   ?subcat now contains the title of the subcategory, page or file.
    ?subcat wikibase:apiOutput           mwapi:title .
    #   ?ns now contains an identifier "@ns" that discriminates between Wikipedia page types. E.g. @ns=0 is presumably a Wikipedia page, @ns=6 a file, @ns=14 seems to be a Wikipedia category.
    ?ns     wikibase:apiOutput           "@ns" . 
    #   ?item now contains the Wikidata item, based on the link named "Wikidata item", situated on the rightmost navigation bar. NOTE: redirection is not supported.
    ?item   wikibase:apiOutputItem       mwapi:item .
  }
  
  BIND (URI(CONCAT('https://en.wikipedia.org/wiki/', ?subcat)) AS ?file)
  
# The following SERVICE statement reduces the result count by those 5 items that do not have a value in column "item".  # RESULT: 2021-12-18:105 items
#  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }     
}

ORDER BY ASC(UCASE(?subcat))

Query 19B - Image dimensions edit

Search for the image(s) referred to on the image property of each selected Wikidata page and display certain dimensional values.

  • Last revision: 2021-12-18
# Retrieve certain dimensional values of the image referred to on the image property of each selected Wikidata page.
# Last revision: 2021-12-18
# Uses the "wikibase:api".
#   General idea of using so called "Allpages generator" derived from  phab:T157798#5919648).

SELECT ?item ?itemLabel ?fileTitle ?image ?size ?width ?height ?Xtitle ?ns  # ?Xitem
WHERE
{
#  BIND(wd:Q42 AS ?item)
#  ?item wdt:P176 wd:Q282186 .                      # Manufacturer (P176): Carl Zeiss AG (Q282186) # RESULT => 2021-12-18: 10 items
#  ?item wdt:P176 wd:Q41187 .                       # Manufacturer (P176): Sony (Q41187) # RESULT => 2021-12-18: 164 items
#  ?item wdt:P120 wd:Q1295 .                        # contains administrative territorial entity (P120):  Dortmund (Q1295)  # RESULT => 2021-12-18: 0 items, because all "Stadtteile" lack an image, even Aplerbeck!
  ?item wdt:P31 wd:Q707813 .                        # Instance of (P31):  Hanseatic city (Q707813) # RESULT => 2021-12-18: 219 items with an image   # This statement alone: ONLY 215, due to a number of multiple images (for Aizpute (2x),  Attendorn (2x), ... Dinante (5x), ...) !

  ?item wdt:P18 ?image .                           # RESULT / 2021-12-17 => 10

  BIND(STRAFTER(wikibase:decodeUri(STR(?image)), "http://commons.wikimedia.org/wiki/Special:FilePath/") AS ?fileTitle) . 

  SERVICE wikibase:mwapi
 {
    bd:serviceParam wikibase:api           "Generator" ;
                    wikibase:endpoint      "commons.wikimedia.org" ;
                    wikibase:limit         "once" ;
                    
                    mwapi:generator        "allpages" ;
                    mwapi:gapfrom          ?fileTitle ;
                    mwapi:gapnamespace     6 ;                        # NS_FILE (= name space / file)
                    
                    mwapi:prop             "imageinfo" ;
                    mwapi:iiprop           "dimensions" ;
                    mwapi:gaplimit         1 .

    ?size    wikibase:apiOutput  "imageinfo/ii/@size" .
    ?width   wikibase:apiOutput  "imageinfo/ii/@width" .
    ?height  wikibase:apiOutput  "imageinfo/ii/@height" .
  
#    ?Xtitle wikibase:apiOutput           mwapi:title .  # Superfluous information: "File:" + "fileTitle" 
    ?ns     wikibase:apiOutput           "@ns" .        # All instances: ns=6
#    ?Xitem   wikibase:apiOutputItem       mwapi:item .  # Remains empty for some reason.
  }

  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

Query 20 edit

Query 20A - Files within a category page edit

 # Find links to all files enlisted within a category page

 SELECT ?file ?title ?fileTitle ?url
 WHERE
 { 
   SERVICE wikibase:mwapi
   {
     bd:serviceParam wikibase:api       "Generator" .
     bd:serviceParam wikibase:endpoint  "commons.wikimedia.org" .
     
     bd:serviceParam mwapi:generator    "categorymembers" .
 #    bd:serviceParam mwapi:gcmtitle     "Category:Historia Naturalis van Rudolf II" .   # RESULT => 2021-12-19: 909 items
 #    bd:serviceParam mwapi:gcmtitle     "Category:Historia Naturalis van Rudolf II, T IV" .   # RESULT => 2021-12-19: 19 items
     bd:serviceParam mwapi:gcmtitle     "Category:Sony Alpha" .   # RESULT => 2021-12-19: 6 items
     
     bd:serviceParam mwapi:gcmtype      "file" .
     bd:serviceParam mwapi:gcmlimit     "max" .
     
     ?title wikibase:apiOutput          mwapi:title .
     ?pageid wikibase:apiOutput         "@pageid" .
   }
 
   BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
   BIND(STRAFTER(STR(?title), "File:") AS ?fileTitle) .   # NOTE: Use of function "wikibase:decodeUri()" removes "+" sign in file name!
   BIND(IRI(CONCAT('http://commons.wikimedia.org/wiki/Special:FilePath/', ENCODE_FOR_URI(?fileTitle))) AS ?url) .
 }

Query 20B - XYZ edit

Query 21 edit

Query 21A - mwapi - page banner edit

Search for property 'page banner (P948)' declared within item 'Norway (Q20)' and display some values.

# Find the property 'page banner (P948)' for item 'Norway (Q20)' and display some values.
# Last revision: 2021-12-22

SELECT ?image ?filename ?license ?artist ?licenseurl ?Credit ?Categories ?DateTimeOriginal ?ImageDescription
WHERE 
{
  wd:Q20 wdt:P948 ?image . # The item 'Norway (Q20)' currently displays exactly one property 'page banner (P948)', which in turn contains a link to an '?image'.

  # Transform the image (contains full path) for use in the Commons API by removing the path and applying "wikibase:decodeUri".
  BIND(wikibase:decodeUri(STRAFTER(STR(?image), "http://commons.wikimedia.org/wiki/Special:FilePath/")) AS ?filename)

  # Call to the Wikimedia Commons API (mwapi) .
  SERVICE wikibase:mwapi 
  {
    bd:serviceParam wikibase:endpoint "commons.wikimedia.org" ;
                    wikibase:api "Generator" ;
                    mwapi:generator "allpages" ;
                    mwapi:prop "imageinfo" ;
                    mwapi:iiprop "extmetadata" ;
                    mwapi:gapfrom ?filename ;
                    mwapi:gapto ?filename ;
                    mwapi:gapnamespace "6" .

    # Extract values by appplying "wikibase:apiOutput".
    #   DateTime|DateTimeOriginal|ImageDescription|License|LicenseShortName|UsageTerms|LicenseUrl|Credit|Artist|GPSLatitude|GPSLongitude|Categories|Permission
    ?license wikibase:apiOutput "imageinfo/ii/extmetadata/LicenseShortName/@value" .
    ?artist wikibase:apiOutput "imageinfo/ii/extmetadata/Artist/@value" .
    ?licenseurl wikibase:apiOutput "imageinfo/ii/extmetadata/LicenseUrl/@value" .                    
    ?Credit wikibase:apiOutput "imageinfo/ii/extmetadata/Credit/@value" .                    
    ?Categories wikibase:apiOutput "imageinfo/ii/extmetadata/Categories/@value" .                    
    ?DateTimeOriginal wikibase:apiOutput "imageinfo/ii/extmetadata/DateTimeOriginal/@value" .                    
    ?ImageDescription wikibase:apiOutput "imageinfo/ii/extmetadata/ImageDescription/@value" .                    
  }
}

ORDER BY ASC(UCASE(?filename))

LIMIT 20

Query 22 edit

Query 22A - mwapi - digital camera models by Sony edit

Search for 'digital camera model' by 'manufacturer: Sony' and display some properties.

  • This is the first step towards displaying more information, which will later be derived via appropriate APIs from Wikimedia Commons and/or Wikipedia.
# Find 'digital camera model' by 'manufacturer: Sony' and display some properties.

SELECT ?camera ?camera_date ?instanceOf ?image ?imageLabel ?filename
WHERE
{
#  # ##### Statement SET_01 #####
#  ?camera wdt:P31 wd:Q20741022 .                        # instance of (P31): digital camera model (Q20741022) # RESULT SET_01 => 1295 items
#  ?camera wdt:P571 ?camera_date .                       # inception (P571) # RESULT SET_01 => reduced to 665 items 

  # ##### Statement SET_02 #####
  ?camera wdt:P31 wd:Q20741022 .                        # instance of (P31): digital camera model (Q20741022) # RESULT SET_01 => 173 items
  ?camera wdt:P176 wd:Q41187 .                          # manufacturer (P176): Sony (Q41187) # RESULT SET_02 => 306 items

  OPTIONAL { ?camera wdt:P571 ?camera_date . }          # inception (P571) # RESULT SET_02 => 306 items
#  ?camera wdt:P571 ?camera_date .                       # inception (P571) # RESULT SET_02 => reduced to 130 items # E.g.: model "Sony α7R IV (Q65976324)" doesn't have an "inception (P571)" property and is thus eliminated.

  OPTIONAL {?camera wdt:P31 ?instanceOf . }             # instance of (P31) # RESULT SET_01 => now 669 items
  OPTIONAL {?camera wdt:P18 ?image . }                  # image (P18)  #  RESULT SET_01 => now 673 items

  # Transform the image (which still contains full path) for use in the Commons API by removing the path and applying "wikibase:decodeUri" to the remaining filename.
  BIND(wikibase:decodeUri(STRAFTER(STR(?image), "http://commons.wikimedia.org/wiki/Special:FilePath/")) AS ?filename)

  
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?filename))
# ORDER BY ASC(xsd:integer(STRAFTER(STR(?file), 'Q')))

Query 22B - mwapi - Using API:SEARCH edit

Search for Wiki Commons items containing the string(s) stated behind the statement beginning with 'mwapi:srsearch "' in combination with search qualifiers.

# Find all Wiki Commons items containing the string(s) stated behind the statement beginning with 'mwapi:srsearch "' in combination with search qualifiers.
#   Search qualifiers explained: "haswbstatement:P31" => EXISTS 'instance of (P31)' statement; -haswbstatement:P279 => NOT EXISTS 'subclass of (P279)' statement.
# This is an example of a search for a specific STRING in combination with certain restrictions (i.e. search qualifiers). 

SELECT DISTINCT ?item ?itemLabel ?title
WHERE
{
  hint:Query hint:optimizer "None" .
  
  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:api "Search" ;
#                    wikibase:endpoint "www.wikidata.org" ;        # With mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279"  RESULT => 196 items
                    wikibase:endpoint "commons.wikimedia.org" ;  # With mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279"  RESULT => 200 items
                    
#                    mwapi:srsearch "airport -haswbstatement:P31 -haswbstatement:P279" ; # RESULT: 2021-12-16 58 items.
#                    mwapi:srsearch "Zeiss -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 35 items.
#                    mwapi:srsearch "Sony -haswbstatement:P31 -haswbstatement:P279" ;    # RESULT: 2021-12-16 336 items.
#                    mwapi:srsearch "Dortmund -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 38 items.
#                    mwapi:srsearch "camera -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 519 items.
#                    mwapi:srsearch "objective -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 92 items.
#                    mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 197 / 2021-12-23 196 items.
#                    mwapi:srsearch "-haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-23 9754 items.
#                    mwapi:srsearch "lens Sony -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT:  2021-12-23 9973 items.
#                    mwapi:srsearch "Sony haswbstatement:P31" ;   # RESULT: 2021-12-23 9727 items.
#                    mwapi:srsearch "Sony haswbstatement:P279" ;   # RESULT: 2021-12-23 0 items.
#                    mwapi:srsearch "Sony haswbstatement:P180" ;   # RESULT: 2021-12-23 288 items.
#                    mwapi:srsearch "Sony haswbstatement:P180=Q20653320" ;   # RESULT: 2021-12-23 1 item.
#                    mwapi:srsearch "Sony haswbstatement:P4082" ;   # captured with (P4082)   # RESULT: 2021-12-23 2247 items / 384 items with FILTER "FILE:SONY A".  
#                    mwapi:srsearch "Sony haswbstatement:P4082=Q42421205" ;   # captured with (P4082): Sony α7R III (Q42421205)    # RESULT: 2021-12-23: 5 items with FILTER "FILE:SONY A".  
                    mwapi:srsearch "Sony haswbstatement:P4082=Q42421205[P2789=Q4576564]" ;   # captured with (P4082):  Sony α7R III (Q42421205) [connects with (P2789): adapter (Q4576564)]   # RESULT: 2021-12-23: 1 item with FILTER "FILE:SONY A".  
#                    mwapi:srsearch "haswbstatement:P4082=Q42421205[P2789=Q4576564]" ;   # captured with (P4082):  Sony α7R III (Q42421205) [connects with (P2789): adapter (Q4576564)]   # RESULT: 2021-12-23: 1 item with FILTER "FILE:SONY A".  
#                    mwapi:srsearch "haswbstatement:P6731=Q63348069" ;   # Commons quality assessment (P6731): Wikimedia Commons quality image (Q63348069)    # RESULT: 2021-12-23: 2 items with FILTER "FILE:SONY A". 
                                                                        # Hmmmm, doesn't include "File:Sony Alpha 7R IV body with Canon MP-E 65mm F2.8 1-5x macro lens (fully extended).jpg"! Maybe too many results at this level???
                                                                        # 9785 items with  FILTER "FILE:SONY A" deactivated, but still ONLY 2x "Sony A".
                    
                    mwapi:srnamespace    6 .                                           # define srnamespace 6  # RESULT (with lens): 2021-12-22 9627 items.

    ?title wikibase:apiOutput mwapi:title . 
  }

  ##### www.wikidata.org #####
#  BIND(IRI(CONCAT(STR(wd:), ?title)) AS ?item) 

  ##### commons.wikimedia.org #####
#  BIND (IRI (CONCAT ("http://commons.wikimedia.org/wiki/Special:FilePath/", STR (?title))) AS ?item) .
#  BIND (IRI (CONCAT ("http://commons.wikimedia.org/wiki/", STR (?title))) AS ?item) .    # https://commons.wikimedia.org/wiki/Bokeh
#  BIND (IRI (CONCAT ("http://commons.wikimedia.org/wiki/Category:", STR (?title))) AS ?item) .    # https://commons.wikimedia.org/wiki/Category:Bokeh
  BIND (IRI (CONCAT ("http://commons.wikimedia.org/wiki/", STR (?title))) AS ?item) .    # https://commons.wikimedia.org/wiki/File:2013-365-170_Bokeh_Dreams_(9088508377).jpg

#  FILTER (STRSTARTS ( UCASE (?title ), "FILE:SONY A" )) .   # ?title: "FILE:SONY...": reduced to 644 items


  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

# LIMIT 10    # LIMIT not necessary, as RESULTS: 2021-12-16 => all less than a few 1000 items.

Query 22C - mwapi - Values for Hanseatic cities edit

Search for dimensional and other values of the Wiki Commons image referred to on the image property of each selected Wikidata page.

# Retrieve certain dimensional values of the Wiki Commons image referred to on the image property of each selected Wikidata page.
# Last revision: 2021-12-18
# Uses the "wikibase:api".
#   General idea of using so called "Allpages generator" derived from  phab:T157798#5919648).

SELECT ?item ?itemLabel ?postalCode ?file ?fileTitle ?title ?image ?size ?width ?height ?ns ?pageid ?url ?artist ?licenseurl ?license ?inception ?creator    # ?Xitem ?Xtitle
WHERE
{
#  BIND(wd:Q42 AS ?item)
#  ?item wdt:P176 wd:Q282186 .                      # Manufacturer (P176): Carl Zeiss AG (Q282186) # RESULT => 2021-12-18: 10 items
#  ?item wdt:P176 wd:Q41187 .                      # Manufacturer (P176): Sony (Q41187) # RESULT => 2021-12-18: 164 items
#  ?item wdt:P120 wd:Q1295 .                      # contains administrative territorial entity (P120):  Dortmund (Q1295)  # RESULT => 2021-12-18: 0 items, because all "Stadtteile" lack an image, even Aplerbeck!
  ?item wdt:P31 wd:Q707813 .                      # Instance of (P31):  Hanseatic city (Q707813) # RESULT => 2021-12-18: 219 items / 2021-12-23: 220 items with an image   # This statement alone: ONLY 215, due to a number of multiple images (for Aizpute (2x), Attendorn (2x), ... Dinante (5x), ...) !

  ?item wdt:P18 ?image .                           # RESULT / 2021-12-17 => 10
  
  ?item wdt:P281 ?postalCode .                    # postal code (P281)
  FILTER (STRSTARTS ( UCASE (?postalCode ), "44" )) .   # ?postalCode: "44..": reduced to 6 items
#  FILTER (STRSTARTS ( UCASE (?postalCode ), "59" )) .   # ?postalCode: "59...": reduced to 35 items

  FILTER (CONTAINS ( UCASE (STR (?image )), "BOCHUM" ) || CONTAINS ( UCASE (STR (?image )), "DORTMUND")) .   # FILTER (CONTAINS ...): reduced to 2 items
#  FILTER ( UCASE (STR (?image )) IN ("BOCHUM", "DORTMUND" ) ) .   # FILTER (CONTAINS ...): 0 items doesn't work correctly yet

  BIND (STRAFTER (wikibase:decodeUri (STR (?image) ), "http://commons.wikimedia.org/wiki/Special:FilePath/") AS ?fileTitle ) . 

  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:api           "Generator" ;
                    wikibase:endpoint      "commons.wikimedia.org" ;
                    wikibase:limit         "once" ;
                    
                    mwapi:generator        "allpages" ;
                    mwapi:gapfrom          ?fileTitle ;
                    mwapi:gapnamespace     6 ;                        # NS_FILE (= name space / file)
                    
                    mwapi:prop             "imageinfo" ;
                    mwapi:iiprop           "dimensions|url|extmetadata" ; # size or dimensions: Adds the size of the file in bytes and the height, width and page count (if applicable).
                                                                          # url: Gives URL to the file and the description page. If the file has been revision deleted, a filehidden property will be returned.
                                                                          # extmetadata: Lists formatted metadata combined from multiple sources. Results are HTML formatted. If the file has been revision deleted, a filehidden property will be returned.
                    mwapi:gaplimit         1 .

    ?title wikibase:apiOutput mwapi:title .
    ?pageid  wikibase:apiOutput  "@pageid" .
    ?size    wikibase:apiOutput  "imageinfo/ii/@size" .
    ?width   wikibase:apiOutput  "imageinfo/ii/@width" .
    ?height  wikibase:apiOutput  "imageinfo/ii/@height" .
    ?url  wikibase:apiOutput     "imageinfo/ii/@url" .
    ?artist  wikibase:apiOutput "imageinfo/ii/extmetadata/Artist/@value" .
    ?licenseurl wikibase:apiOutput "imageinfo/ii/extmetadata/LicenseUrl/@value" .                    
    ?license wikibase:apiOutput "imageinfo/ii/extmetadata/LicenseShortName/@value" .
    ?inception wikibase:apiOutput "imageinfo/ii/extmetadata/Inception/@value" .   # 
    ?creator wikibase:apiOutput "imageinfo/ii/extmetadata/Creator/@value" .

   
#    ?Xtitle wikibase:apiOutput           mwapi:title .  # Superfluous information: "File:" + "fileTitle" 
    ?ns     wikibase:apiOutput           "@ns" .        # All instances: ns=6
#    ?Xitem   wikibase:apiOutputItem       mwapi:item .  # Remains empty for some reason.

    BIND (URI (CONCAT ('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
    BIND (IRI (CONCAT (STR (wd:), ?title)) AS ?item) 
    BIND (IRI (CONCAT ('http://commons.wikimedia.org/wiki/Special:FilePath/', ENCODE_FOR_URI ('Sony A77.jpg'))) AS ?url) .  # RESULT: 2021-12-17: 2 items

  }
  
#  bd:serviceParam wikibase:api         "Search" ;
#                  wikibase:endpoint    "commons.wikimedia.org" ;
#                  mwapi:srsearch       "Bochum" ;                                     # search for string "Bochum"  # RESULT: 2021-12-22 0 items.
#                  mwapi:srnamespace    6 ;                                            # define srnamespace 6  # RESULT: 2021-12-22 0 items.
#                  mwapi:srprop         "extensiondata" .                              # define srprop "extensiondata"  # RESULT: 2021-12-22 0 items.
#                  mwapi:srsearch       "haswbstatement:P571" .                        # inception (P571) RESULT: 2021-12-22 0 items.
#                  mwapi:srsearch       "-haswbstatement:P31 -haswbstatement:P279" .   # inception (P571) RESULT: 2021-12-22 0 items.

                    
                    
#  OPTIONAL {?WPENarticle schema:about ?lens .      #  has a Wikipedia:en article
#            ?WPENarticle schema:isPartOf <https://en.wikipedia.org/> .
#            ?ENsitelink ^schema:name ?WPENarticle . }


#  ?file wdt:P180 ?depicts .
#  ?file wdt:P6216 ?depicts .  # copyright status (P6216)

  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

Query 23 edit

Query 23A - wikibase:directClaim edit

Search for all instances of family name "Booth" that have have the property "Art UK artist ID" and display all properties of that item both as "propID" and as "propIDLabel".

# Find all instances of family name "Booth" that have have the property "Art UK artist ID".
#   Of all instances found, display all properties as "propID" and "propIDLabel".
# Last revision 2021-12-25.
# NOTE: demonstrates use of operator "wikibase:directClaim" to display not only the ID but also the label (!!) of a property.
# NOTE: all instances of COUNT for "identifiers found most often on items with Art UK artist ID (P1367)" are currently DEACTIVATED.

SELECT ?propID ?propIDLabel ?prop_ArtUK_ArtistID_Value ?item ?itemLabel ?p ?id     # ?count 
WHERE 
{
  {
    SELECT ?propID  ?prop_ArtUK_ArtistID_Value ?item ?p ?id     # (COUNT(DISTINCT ?item) AS ?count)
    WHERE 
    {
      hint:Query hint:optimizer "None" .
          
      ?item wdt:P734 wd:Q13156704 .                  # family name (P734): Booth (Q13156704)     # RESULT => 2021-12-25: 121 items
            
      ?item wdt:P1367 ?prop_ArtUK_ArtistID_Value .   # Art UK artist ID (P1367)                  # NOTE: e.g. Tony Booth (Q2852815) - English actor (1931-2017) has many properties, but not P1367, thus discluded.
      ?item ?p ?id .
      ?propID wikibase:directClaim ?p .              # "?p" is IDENTICAL to "propID".            # RESULT => 2021-12-25: 1275 items without "family name: Booth".
      
#      {?propID wdt:P31 wd:Q19847637}  # Wikidata property representing a unique identifier
#         UNION                                                                             # RESULT => 2021-12-25: 5555 items
#      {?propID wdt:P31 wd:Q19595382}  # Wikidata property for authority control for people
    }  
#   GROUP BY ?propID
  }
           
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" . }
} 

# ORDER BY DESC (?count)
ORDER BY ASC (?prop_ArtUK_ArtistID_Value)

Query 24 edit

Why can WikiData not recognise commons:Category:Distrails? edit

  • TEST: commons:Category:Distrails - OK, works fine here
  • But, when working on dissipation trail (Q118612485), which I initiated this afternoon, one must note that neither Commons gallery, nor Commons category, nor topic's main category allow any entry of "Distrails" or "Category:Distrails".
Now, after some editing, even the previously valid phrases "Contrail" and/or "Contrails" are rejected in all above stated Commons fields.
  • Note that similar entries are valid in the WikiData topic contrail (Q207546).
  • Maybe I'll have to wait overnight till WikiData's asynchronous processing has applied.
    YEAH! Two hours later both Commons gallery and Commons category have accepted their corresponding "Distrail / Distrails" entries.
  • But, ..., topic's main category stubbornly refuses to accept the valid entry "Category:Distrails", but would accept "Category:Contrails".
Also SOLVED: First had to create a WikiData category "Category:Distrails" with category's main topic, then I could set topic's main category to "Category:Distrails".

Query 25 edit

Query 25A - described by source "encyclopedia.com" edit

Find all instances within WikiData which contain a statement "described by source", with source "encyclopedia.com".

SELECT ?item ?itemLabel 
WHERE  
{
  ?item wdt:P1343 wd:Q48968006. # described by source (P1343) encyclopedia.com (Q48968006)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
}

Query 25B - property usage "Encyclopedia.com ID" edit

Find all instances within WikiData which use the property "Encyclopedia.com ID" (P11850) and display the corresponding label

SELECT ?item ?itemLabel 
WHERE  
{
  ?item wdt:P11850 ?value. #  Encyclopedia.com ID (P11850)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
}

Query 26 - Property used as a statement edit

Find all usages of property P10726 AS a statement

# This query finds all usages of property P10726 AS a statement.
#
# Important note: most SPARQL users don't need such level of complication!
# If you want to get only concrete values with best rank, replace body with something like:
# ?item wdt:P10726 ?value.

SELECT ?item ?itemLabel ?statement ?rank ?snacktype ?value
{
  ?item p:P10726 ?statement .
  ?statement wikibase:rank ?rank .
  OPTIONAL { ?statement ps:P10726 ?dbvalue }

  BIND(COALESCE(IF(wikibase:isSomeValue(?dbvalue), "unknown", "concrete"), "novalue") AS ?snacktype)
  BIND(IF(wikibase:isSomeValue(?dbvalue), "", ?dbvalue) AS ?value)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
LIMIT 1000

Query 27 edit

Query 27A - British Politicians/Building Queries edit

Taken from the Wikidata page Wikidata:WikiProject_British_Politicians/Building_Queries.

NOTE: Left out some initial, very simple examples.

  • The main reason to use this slightly more complicated "position statement" syntax, rather than the simple wdt:, is to allow us to access the statement's qualifiers.
    These are values attached to the main statement to improve or extend it in some way.
 ?person wdt:P31 wd:Q5 . ?person p:P39 ?ps . ?ps ps:P39 wd:Q77685926 .
 ?ps pq:P580 ?start .
  • RESULT: This goes into the position statement ?ps to find the start time qualifier ?start (note the pq: prefix).
  • You will note that we have been looking at the specific period member of the 58th Parliament of the United Kingdom (Q77685926).
    The data model used for the UK is constructed on a "per-Parliament" basis, where each position refers to the specific Parliamentary term.
    We can select a range of these by using a more detailed query:
 ?person wdt:P31 wd:Q5 . ?person p:P39 ?ps . 
 ?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 .

NOTE: Leaving out reams of increasingly complex queries to attain the final statement, as below:

  • We could link two sets of queries together to find MPs who were serving before 1997, and are still in Parliament today.
SELECT DISTINCT ?person ?personLabel (MIN(?start2) as ?first) ?seatLabel ?partyLabel ?start WHERE
 {
   ?person wdt:P31 wd:Q5 . ?person p:P39 ?ps . 
   ?ps ps:P39 ?term . ?term wdt:P279 wd:Q16707842 .
   ?ps pq:P580 ?start . ?ps pq:P4100 ?party . ?ps pq:P768 ?seat . 
   FILTER NOT EXISTS { ?ps pq:P582 ?end } .
   
   ?person p:P39 ?ps2 . ?ps2 ps:P39 ?term2 . ?term2 wdt:P279 wd:Q16707842 .
   ?ps2 pq:P580 ?start2 .
   FILTER(?start2 < "1997-05-01T00:00:00Z"^^xsd:dateTime) .
   
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
 } group by ?person ?personLabel ?seatLabel ?partyLabel ?start
Try it!
  • This approach seems at first glance to be running two independent queries (?ps and ?ps2), but this is intentional.
    We use multiple variables because the value for ?ps/?term that matches "current term" will of course not be the same as ?ps2/?term2, "term before 1997".
    But because both are linked to ?person, it will only return records that match on both aspects.
  • We use "<" rather than "<=" because we want terms which existed before 1 May 1997; using <= would include anyone first elected then.
  • Finally, the use of (MIN(?start2) as ?first) is a way to find out when they first entered parliament. ?start2 is the start date on the "earlier" terms, the before-1997 ones.
    MIN(?start2) selects the lowest value of ?start2 for each person, and then binds it to a new variable name.
    Note that when using MIN (or any other aggregator, like SAMPLE above) you need to group by all elements which are not being aggregated - hence the last line.

Query 28 edit

Query 28A - Viewing angle of subject edit

Excerpt from: Wikidata:Project chat/Archive/2023/05#Viewing angle of subject

Query 29 edit

Query 29A - XYZ edit

Query 30 edit

Retrieve information from within Wikidata reference statements. Here embedded within a "property - qualifier" statement.

Query 30A - Properties that are defined as "qualifier only" but are used in references edit

  • Query example [4], section "Properties that are defined as "qualifier only" but are used in references".
  • Retrieves information from within Wikidata reference statements embedded within a "property - qualifier" statement.
  • Last revision 2021-12-24
  • QUERY:
# Properties that are defined as "qualifier only" but are used in references.
SELECT ?entity ?claim ?prop ?statement ?o ?ref
WHERE
{
	?prop wdt:P31 wd:Q15720608 .
	?prop wikibase:reference ?propClaim .
	?ref ?propClaim ?o .
	?statement prov:wasDerivedFrom ?ref .
	?entity ?claim ?statement .
}
LIMIT 10000
  • RESULT
    • 1 of 10000 Wikidata items:
entity:     wd:Q161545	                                         South Schleswig Voter Federation (Q161545)
claim:      p:P159                                              headquarters location (P159) 
prop:       wd:P7668                                            file page (P7668) => contained within a reference of statement "headquarters location (P159): Flensburg (Q3798)"
statement:  wds:Q161545-960BCB1F-3493-4D6D-A61A-B30E9880B560
o:          6                                                   value of "file page"
ref:        wdref:897b6a54f53062e32d6ddcd515c333b567a11eee
headquarters location  Flensburg
                       ▼ 1 reference
                       reference URL:      https://www.bundeswahlleiter.de/dam/jcr/bbc9c62c-36d3-44a4-80b5-5970017229c9/ssw.pdf
                       retrieved:          9 July 2021
                       stated in:          Q2054326
                       file page:          6
                       section, verse, paragraph, or clause:     § 1 Absatz 2 Satz 1
                       publication date:   15 September 2018

Query 30B - mwapi:srsearch - various search phrases edit

  • Search for Wikidata items via "mwapi:srsearch" that (a) contain the initial search phrase and (b) conform to any following statements.
  • Last revision 2021-12-24
  • QUERY:
# Find all Wikidata items that (a) contain the search phrase and (b) conform to these statements for simultaneously missing parameters "lens -haswbstatement:P31 -haswbstatement:P279".
# NOTE: This statement also finds lengthier phrases that begin with the word "lens..." and also phrases that only have foreign (non-English) language labels.

SELECT DISTINCT ?item ?title ?titleLabel ?itemLabel ?ns ?pageid ?snippet 
WHERE
{
  SERVICE wikibase:mwapi
  {
    ##### SET_01 #####
    #####   Search phrase and statements for missing parameters all in one statement: "lens -haswbstatement:P31 -haswbstatement:P279"
    ##### NOTE: This statement also finds lengthier phrases that begin with the word "lens..." and also phrases that only have foreign (non-English) language labels.
    bd:serviceParam wikibase:api "Search" ; 
                   wikibase:endpoint "www.wikidata.org" ;        # With mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279"  RESULT => 196 items
                    
                    mwapi:srsearch "lens -haswbstatement:P31 -haswbstatement:P279" ;   # RESULT: 2021-12-16 197 / 2021-12-23 196 items.
#                    mwapi:srsearch "inlabel:\""\"" ;                              # RESULT: 2021-12-24 85 items.
#                    mwapi:srsearch "inlabel:sony" ;                                    # RESULT: 2021-12-24 2854 items.
#                    mwapi:srsearch "insource:\"sony alpha\" -haswbstatement:P31" ;     # RESULT: 2021-12-24 2 items.
#                    mwapi:srsearch "insource:\"sony alpha\" -haswbstatement:P279" ;    # RESULT: 2021-12-24 28 items.
#                    mwapi:srsearch "insource:\"sony α\" -haswbstatement:P279" ;    # RESULT: 2021-12-24 14 items.
#                    mwapi:srsearch "insource:\"/sony alpha α/\" -haswbstatement:P279" ;    # RESULT: 2021-12-24 1 items.  # identical to insource:\"/sony (alpha|α)/\"
#                    mwapi:srsearch "insource:/sony" ;                                  # RESULT: 2021-12-24 3423 items.
#                    mwapi:srsearch "insource:/sony/" ;                                 # RESULT: 2021-12-24 2352 items.
#                    mwapi:srsearch "sony" ;                                            # RESULT: 2021-12-24 4186 items.
#                    mwapi:srsearch "sony alpha" ;                                      # RESULT: 2021-12-24 84 items.
#                    mwapi:srsearch "hastemplate:\"infobox newspaper\"" ;               # hastemplate ONLY for queries on Wikimedia Commons, NOT on Wikidata.
#                    mwapi:srsearch "insource:\"sony alpha\" -haswbstatement:P279  hasdescription:de" ;    # RESULT: 2021-12-24 11 items.
#                    mwapi:srsearch "insource:\"sony alpha\" -haswbstatement:P279  hasdescription:de haslabel:de" ;    # RESULT: 2021-12-24 6 1items.
                    
                    mwapi:srnamespace    0 .                                           # define srnamespace 0  # RESULT (with lens): 2021-12-24 196 items.

    ?snippet        wikibase:apiOutput           "@snippet" .            # @snippet is a XML string that contains the results of the mwapi:srsearch.
    ?ns             wikibase:apiOutput           "@ns" .                 # RESULT: All instances: ns=0
#    ?description    wikibase:apiOutput           "@description" .        # RESULT: No values
    ?pageid         wikibase:apiOutput           "@pageid" .
#    ?Zitem          wikibase:apiOutputItem       mwapi:item .           # NOT valid in this context, requires "wikibase:api "Generator"".
    ?item           wikibase:apiOutputItem        mwapi:title . 
#    ?description    wikibase:apiOutput            mwapi:label .        # RESULT: No values

    ?title          wikibase:apiOutput             mwapi:title . 
   }

#  ##### www.wikidata.org #####
#  BIND(IRI(CONCAT(STR(wd:), ?title)) AS ?item)   # Replaced by "?item wikibase:apiOutputItem mwapi:title" above.

  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

# LIMIT 10    # LIMIT not necessary, as RESULTS: 2021-12-16 => all less than a few 1000 items.

Query 30C - mwapi:srsearch with FILTER NOT EXISTS edit

  • Search for Wikidata items via "mwapi:srsearch" that (a) contain the initial search phrase and (b) conform to any following statements.
  • Last revision 2021-12-24
  • QUERY:
# Find all Wikidata items that (a) contain the search phrase and (b) conform to these statements for simultaneously missing parameters in 2 "FILTER(NOT EXISTS {..." statements.
# NOTE: The statement (mwapi:srsearch "lens") ONLY finds items which contain the EXACT phrase "lens" within an English language label OR description OR image
#       The variations "lens-shaped" and "single-lens" are also acccepted, whereas e.g. a word such as "lenses" is rejected.
# NOTE: The number of selected files varies from call to call, even within 30 minutes!
#       Whenever 123 items are displayed as opposed to 122 this is the additional result: "wd:Q24909455 | Pentax DA 18-270mm lens | Q24909455".

SELECT DISTINCT ?item ?itemLabel ?title
WHERE
{
  SERVICE wikibase:mwapi
  {
    #####   Search phrase and statements for missing parameters in separate statements:
    #####     Search phrase: "lens"
    #####     Declaration of missing parameters: two separate statements: "FILTER(NOT EXISTS {..."
    ##### NOTE: This statement ONLY finds items which contain the EXACT phrase "lens" within an English language label OR description OR image (lens-shaped, single-lens also acccepted).
    bd:serviceParam wikibase:api "Search" ; 
                    wikibase:endpoint "www.wikidata.org" ; 
                    
                    mwapi:srsearch "lens" ;                       # RESULT: 2021-12-24 9529 items. # With 2x "FILTER(NOT EXISTS {..."  RESULT => 2021-12-24: 123, 2 hrs. later 124, 6 hrs. later 122/123 items
                                                                  # RESULT => 2021-12-25: 122 / 30 min. later 123 items 
#                    mwapi:srsearch "insource:\"lens\"" ;          # RESULT: 2021-12-24 7 items with 2x "FILTER(NOT EXISTS {...".
#                    mwapi:srsearch "insource:\"/lens/\"" ;        # RESULT: 2021-12-24 7 items with 2x "FILTER(NOT EXISTS {...". 
#                    mwapi:srsearch "insource:\"/Sony alpha/\"" ;  # RESULT: 2021-12-24 0 items with 2x "FILTER(NOT EXISTS {...".
#                    mwapi:srsearch "insource:\"/Sony/\"" ;  # RESULT: 2021-12-24 330 items with 2x "FILTER(NOT EXISTS {...".
#                    mwapi:srsearch "inlabel:\"lens\"" ;           # RESULT: 2021-12-24 4 items.
#                    mwapi:srsearch "inlabel:lens" ;               # RESULT: 2021-12-24 4 items.
                    mwapi:srnamespace    0 .                      # define srnamespace 0  # RESULT (with lens): 2021-12-24 196 items.

      ?title wikibase:apiOutput mwapi:title . 
   }

  ##### www.wikidata.org #####
  BIND(IRI(CONCAT(STR(wd:), ?title)) AS ?item) 

  FILTER(NOT EXISTS {
     ?item wdt:P31 ?instance_of .  # instance of (P31 )
  } )
 
  FILTER(NOT EXISTS {
     ?item wdt:P279 ?subclass_of .  # subclass_of (P279)
  } )
                   
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

ORDER BY ASC(UCASE(?itemLabel))

# LIMIT 10    # LIMIT not necessary, as RESULTS: 2021-12-16 => all less than a few 1000 items.

Query 99 edit

  • This code snippet was retrieved from the "Community Wishlist Survey 2021".
    • Problem: Wikidata Query and ListeriBot currently only knows "label", and "description" as standard item columns; "alias" is not recognised yet as a valid item header variable.
    • Who would benefit: Everyone that automatically generates (Wikipedia) tables based on a Wikidata Query.
    • Proposed solution: Add a pseudo-column "alias" that is automatically and transparently available for any individual query.
    • More comments: Currently this can be simulated by explicitly adding a SPARQL variable ?alias as:
OPTIONAL 
{
  ?item skos:altLabel ?alias.
  FILTER((LANG(?alias)) = "de")
}
  • This makes the Wikidata Query unnecessary complex, and leads to redundant user code in all Wikidata/LysteriaBot queries

Created new Wikidata items edit

Created the following items on Mon, 2024-05-27:

NOTE: these two Fujinon lenses had been created before:
  Fujifilm (correct: Fujinon) GF 23mm F4 R LM WR
  Fujifilm (correct: Fujinon) GF 120mm F4 R LM OIS WR Macro

Created by me on 024-05-27:
  Fujinon GF 30mm F3.5 R WR
  Fujinon GF 30mm F5.6 T/S
  Fujinon GF 45mm F2.8 R WR

  Fujinon GF 50mm F3.5 R LM WR
  Fujinon GF 55mm F1.7 R WR
  Fujinon GF 63mm F2.8 R WR

  Fujinon GF 80mm F1.7 R WR
  Fujinon GF 110mm F2 R LM WR
  Fujinon GF 110mm F5.6 T/S Macro

  Fujinon GF 250mm F4 R LM OIS WR
  Fujinon GF 500mm F5.6 R LM OIS WR

  Fujinon GF 20-35mm F4 R WR
  Fujinon GF 32-64mm F4 R LM WR
  Fujinon GF 35-70mm F4.5-5.6 WR 	

  Fujinon GF 45-100mm F4 R LM OIS WR
  Fujinon GF 100-200mm F5.6 R LM OIS WR

  Fujinon GF 1.4X TC WR