Логотип Wikimedia Commons Sparql

Wikimedia Commons Sparql

Сообщество
fuzheado
wikimedia-commons-sparql

Query Wikimedia Commons structured data via SPARQL — MediaInfo entities (M IDs), the depicts/copyright/licensing graph, Schema.org media metadata, and federated queries with Wikidata. Covers both the official WCQS endpoint (OAuth-authenticated) and the QLever third-party endpoint (no auth required)

Обзор

Издательfuzheado
РепозиторийWikipedia-AI-Skills
Название навыкаwikimedia-commons-sparql
Звёзды
27
Форки
10
Файлы в комплекте
3
ЛицензияMIT
Ссылки
  • Инструкции в формате Markdown

    Модель загружает файл SKILL.md по мере необходимости, поэтому токены расходуются только при подходящем запросе.

  • Работает с любой большой языковой моделью

    Навыки ИИ — это обычный Markdown, а не код для конкретного поставщика, поэтому они работают с GPT, Claude, Gemini, Grok и локальными моделями.

  • Файлы в комплекте: 3

    Скрипты, шаблоны и справочные материалы, которые модель может читать во время работы. Файлы доступны только для чтения и никогда не выполняются.

  • Открытый исходный код

    Издатель навыка на GitHub — fuzheado. Перед установкой изучите исходные материалы.

Установка

Установите навык ИИ Wikimedia Commons Sparql в TypingMind, чтобы использовать его с любой LLM, или добавьте его в другой агент, который умеет читать SKILL.md.

1

Установка в TypingMind

TypingMind устанавливает навык прямо из его папки на GitHub: читает SKILL.md, собирает файлы ресурсов и сохраняет результат локально.

  1. Откройте приложение и перейдите в раздел «Плагины → Навыки».
  2. Выберите «Установить из GitHub».
  3. Вставьте указанную ниже ссылку на папку навыка и подтвердите установку.
    https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-commons-sparql
  4. Включите навык в каждом чате, где хотите его использовать.
Плагины → Навыки → Добавить навык → По ссылке GitHub, затем вставьте ссылку на папку и нажмите «Продолжить».
2

Установка в другом агенте

Любой агент с поддержкой формата Agent Skills может использовать этот навык — скопируйте папку в каталог навыков этого агента.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fuzheado/Wikipedia-AI-Skills.git /tmp/Wikipedia-AI-Skills
mkdir -p .claude/skills
cp -r /tmp/Wikipedia-AI-Skills/.claude/skills/wikimedia-commons-sparql .claude/skills/wikimedia-commons-sparql
После копирования перезапустите Claude Code, чтобы загрузить новый навык.

Использование в TypingMind

Включите навык Wikimedia Commons Sparql в любом чате TypingMind, и дальше модель всё сделает сама. Его название и описание хранятся в системном промпте, а при появлении подходящего запроса модель сама загружает полные инструкции. Вам не нужно вызывать навык вручную, и до фактического использования он не расходует токены.

Модель сама загружает навык Wikimedia Commons Sparql, как только появляется подходящий для него запрос.

Работает с любой моделью ИИ

Навыки ИИ — это обычные инструкции в Markdown, а не код для конкретного поставщика, поэтому навык Wikimedia Commons Sparql не привязан к модели, для которой он был создан. Установите его один раз в TypingMind и используйте с GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama или локальной моделью, которую запускаете самостоятельно, — со своими ключами API.

  • Загружается только при необходимости

    Системный промпт содержит только название и описание. Инструкции загружаются при первом подходящем запросе, поэтому неиспользуемый навык не расходует токены.

  • Меняйте модели прямо в чате

    Навык состоит из инструкций, а не кода, поэтому смена модели не нарушает его работу: новая модель читает тот же файл SKILL.md.

Инструкции навыка

Это содержимое файла SKILL.md, которое загружает модель. Прочитайте его перед установкой: навык — это инструкции, которым будет следовать ваша модель.

⚠️ User-Agent required: All HTTP requests to Wikimedia endpoints need a descriptive User-Agent header. See the wikimedia-api-access skill for the correct format and rate-limiting patterns. Requests without a proper User-Agent will be blocked with HTTP 403.

💡 Relationship to other skills:

  • This skill covers Commons-specific SPARQL — M IDs, Schema.org media predicates, and Commons property patterns. General SPARQL syntax (SELECT, FILTER, OPTIONAL, property paths), the WDQS label service (SERVICE wikibase:label), and WDQS rate limits are covered in the wikidata skill.
  • For adding, editing, and managing Structured Data on Commons (not querying it), see the wikimedia-commons-sdc skill — covers captions editing, wbcreateclaim, batch GLAM workflows, ISA Tool, OpenRefine, and constraint checking.
  • The wikimedia-commons skill covers non-SPARQL Commons access: Action API search, file upload, EXIF metadata, haswbstatement: prefix, and category navigation.
  • The wikimedia-api-strategy skill helps decide when to use SPARQL vs. the Action API vs. other methods.

What Is Commons Structured Data?

Every file on Wikimedia Commons can carry Wikibase statements — the same kind of structured, machine-readable annotations used by Wikidata. These statements describe:

  • What a file depicts (P180 — "depicts" → a Wikidata item)
  • Who created it (P170 — "creator")
  • When it was created (P571 — "inception")
  • Copyright status and license (P6216, P275)
  • Camera and capture metadata (P4082 — "captured with")
  • Digital representation of (P6243 — links a file to the Wikidata item it's a digital surrogate of)
  • And more — any Wikidata property can, in principle, be used on Commons files.

This is called Structured Data on Commons (SDC). The data is stored as MediaInfo entities, each identified by an M ID (e.g., M37200540), which is distinct from Wikidata's Q IDs.

💡 Where to find an M ID: On any Commons file page, look in the left sidebar for "Concept URI" — the link contains the M ID. Or use "Page information" — the Page ID prefixed with M is the M ID.

Two Endpoints, One Dataset

There are two SPARQL endpoints you can use to query Commons structured data:

AspectWCQS (Official)QLever (Third-Party)
URLhttps://commons-query.wikimedia.org/sparqlhttps://qlever.dev/api/wikimedia-commons
Web UIhttps://commons-query.wikimedia.org/https://qlever.dev/wikimedia-commons
AuthenticationOAuth — requires a Commons account and manual cookie extractionNone — open access
Operated byWikimedia Foundation (Search Platform team)University of Freiburg (QLever project)
StatusBeta; usage <1 query/min; may be decommissioned (see T376979)Active; updated from the mediainfo-streaming-updater.mutation.v2 stream
Data sourceWeekly dumps from dumps.wikimedia.org/other/wikibase/commonswiki/"Munged" version of the same dumps + streaming updates
Federation with WDQSSupportedSupported
Rate limitsPer authenticated user (request-based)Usual QLever rate limiting

⚠️ Practical advice: For automated tools, scripts, and programmatic access, use QLever — it requires no authentication and returns results via a standard SPARQL GET/POST endpoint. The official WCQS endpoint exists but its OAuth requirement makes it impractical for most programmatic use. The Commons SPARQL examples page itself directs users to QLever as "the way faster [alternative] which does not require login." It also contains dozens of runnable example queries you can adapt.


The M ID / MediaInfo Data Model

The biggest difference from Wikidata SPARQL is that subjects are M IDs (MediaInfo entities), not Q IDs.

ConceptWikidataCommons (MediaInfo)
Entity ID prefixQ (e.g., Q42)M (e.g., M37200540)
Subject URI patternhttp://www.wikidata.org/entity/Q42http://commons.wikimedia.org/entity/M37200540
What the entity representsAbstract concepts, people, places, thingsFiles (images, audio, video, PDFs, 3D models)
LabelsMultilingual labels and descriptionsMultilingual file captions (?file rdfs:label ?caption)
File URL predicates—schema:url, schema:contentUrl, schema:thumbnailUrl
Media metadata predicates—schema:width, schema:height, schema:encodingFormat

Finding M IDs

Method 1: By Commons file title. Use the wikibase:mwapi SERVICE (see Pattern 7: Media from a Specific Commons Category below) or construct the URI directly:

sparql
BIND(URI(CONCAT("http://commons.wikimedia.org/entity/M", ?pageid)) AS ?file)

Method 2: By known file path. The schema:url predicate matches Special:FilePath URLs:

sparql
?file schema:url <http://commons.wikimedia.org/wiki/Special:FilePath/Eiffel_Tower_from_below.jpg> .

Method 3: From PetScan or Minefield. PetScan can list Page IDs for all files in a Commons category; Minefield converts file titles to M IDs. See the Commons SPARQL page for details.


Quick Reference: What Do You Want to Do?

GoalExample Query PatternEndpoint
Find files depicting a Wikidata item?file wdt:P180 wd:Q42 .Both
Show images in a grid?file schema:url ?image . + #defaultView:ImageGridBoth
Find files by copyright status?file wdt:P6216 wd:Q50402863 . (public domain)Both
Find files by license?file wdt:P275 wd:Q50829104 . (CC0)Both
Get file dimensions?file schema:width ?w ; schema:height ?h .Both
Find files by camera model?file wdt:P4082 wd:Q649631 . (Canon EOS 5D)Both
Federated: file depicts + Wikidata labelSERVICE <https://query.wikidata.org/sparql> { ... }Both
Files in a Commons categorySERVICE wikibase:mwapi { ... wikibase:endpoint "commons.wikimedia.org" ... }Both
Count files by file typeSELECT ?encoding (COUNT(*) AS ?total) { ?file schema:encodingFormat ?encoding . } GROUP BY ?encodingBoth
Find files with point-of-view coordinates?file wdt:P1259 ?coords . (Map view)Both

Commons-Specific Properties Reference

These are the most commonly used properties for querying Commons structured data:

🔗 Core File Properties

PropertyLabelType of ValueExample Use
wdt:P180depictsWikidata Q item?file wdt:P180 wd:Q42 . (files depicting Douglas Adams)
wdt:P6243digital representation ofWikidata Q item?file wdt:P6243 wd:Q179900 . (files that are digital surrogates of Michelangelo's David)
wdt:P170creatorWikidata Q item or string?file wdt:P170 wd:Q5582 . (files created by Van Gogh)
wdt:P571inceptionDate literalFILTER(YEAR(?date) > 2020)
wdt:P7482source of fileWikidata Q item?file wdt:P7482 wd:Q74228490 . (file available on the internet)
wdt:P6216copyright statusWikidata Q item?file wdt:P6216 wd:Q50402863 . (public domain)
wdt:P275copyright licenseWikidata Q item?file wdt:P275 wd:Q50829104 . (CC0)
wdt:P4082captured withWikidata Q item (camera)?file wdt:P4082 wd:Q649631 . (Canon EOS 5D)
wdt:P1259coordinates of point of viewCoordinates literalWorks with #defaultView:Map
wdt:P2079fabrication methodWikidata Q item?file wdt:P2079 wd:Q226881 . (digital photography)
wdt:P973described at URLURL literal?file wdt:P973 ?url .

🏷️ Schema.org Media Predicates

These are not Wikidata properties — they use the Schema.org vocabulary directly in the RDF dump:

PredicateMeaningExample
schema:urlFile page URL (for #defaultView:ImageGrid)?file schema:url ?image .
schema:contentUrlDirect file download URL?file schema:contentUrl ?download .
schema:thumbnailUrlThumbnail URL?file schema:thumbnailUrl ?thumb .
schema:widthImage width in pixels?file schema:width ?w . FILTER(?w > 1000)
schema:heightImage height in pixels?file schema:height ?h .
schema:encodingFormatMIME type?file schema:encodingFormat "image/jpeg" .
schema:datePublishedPublication date?file schema:datePublished ?date .

⭐ Wikidata Properties Commonly Used on Commons Files

PropertyLabelNotes
wdt:P180depictsThe most-used property on Commons. Links to a Wikidata Q item. Qualifiers can specify: pq:P462 (color), pq:P6022 (expression/gesture/body pose), pq:P518 (applies to part)
wdt:P6243digital representation ofStronger than depicts — the file is a digital version of the item (usually for artworks)
wdt:P170creatorCan be a Q item (known Wikidata person) or use a qualifier pq:P2093 for a text string author name
wdt:P7482source of fileCommon values: Q74228490 (file available on the internet), Q548662 (original creation by uploader)

QLever: Practical Usage (Recommended Endpoint)

QLever at https://qlever.cs.uni-freiburg.de/api/wikimedia-commons is a third-party endpoint for programmatic access (it redirects; if unreachable, use the official https://commons-query.wikimedia.org/sparql). It requires no authentication and uses standard SPARQL over HTTP.

⚠️ Prefix requirement: QLever requires explicit PREFIX declarations. All examples below include the common prefixes. Copy-paste ready.

GET request (simple queries)

bash
curl -G "https://qlever.dev/api/wikimedia-commons" \
  --data-urlencode "query=PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?file WHERE { ?file wdt:P180 wd:Q42 } LIMIT 10" \
  -H "Accept: application/sparql-results+json" \
  -H "User-Agent: MyBot/1.0 (https://example.com; user@example.com)"

POST request (long queries)

bash
curl -X POST "https://qlever.dev/api/wikimedia-commons" \
  -H "Accept: application/sparql-results+json" \
  -H "User-Agent: MyBot/1.0 (https://example.com; user@example.com)" \
  -d "query=PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> SELECT ?file WHERE { ?file wdt:P180 wd:Q42 } LIMIT 10"

Python with requests

python
import requests

query = """
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT ?file WHERE {
  ?file wdt:P180 wd:Q42 .
}
LIMIT 10
"""

headers = {
    "User-Agent": "MyBot/1.0 (https://example.com; user@example.com)",
    "Accept": "application/sparql-results+json",
}
resp = requests.get(
    "https://qlever.dev/api/wikimedia-commons",
    params={"query": query},
    headers=headers,
    timeout=60,
)
resp.raise_for_status()
data = resp.json()

for binding in data["results"]["bindings"]:
    file_uri = binding["file"]["value"]
    m_id = file_uri.rsplit("/", 1)[-1]  # Extract M37200540 from URI
    print(f"{m_id}: {file_uri}")

QLever-specific notes

  • Rate limiting: standard QLever limits apply (generous for reasonable usage)
  • No OAuth, no cookies, no session management
  • The QLever web UI at https://qlever.dev/wikimedia-commons provides a WIkidata-Query-Service-like interface with "Try it!" links, example queries, and result visualization
  • Index information (last update date) is shown under the "Index Information" button in the UI
  • QLever also supports #defaultView:ImageGrid, #defaultView:Map, and other visual directives

⚠️ Required: explicit PREFIX declarations on QLever. Unlike Blazegraph (used by WCQS and WDQS), which auto-registers common Wikidata prefixes (wd:, wdt:, p:, ps:, pq:), QLever requires every prefix to be explicitly declared. All SPARQL queries sent to the QLever endpoint must include PREFIX lines. Copy the block below as a header for every QLever query:

sparql
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX commons: <http://commons.wikimedia.org/wiki/Special:FilePath/>

The examples in this skill omit prefixes for brevity (they follow the WCQS/Blazegraph convention where prefixes are auto-registered). When running them against QLever, prepend the prefix block above.


WCQS: Authentication (Official Endpoint, Use Only When Necessary)

The official WCQS at https://commons-query.wikimedia.org/sparql requires OAuth authentication. To use it programmatically, you must extract an OAuth cookie from your browser after logging in.

Obtaining the wcqsOauth cookie

  1. Visit https://commons-query.wikimedia.org/ and log in with your Commons account
  2. Open browser developer tools → Storage/Cookies → https://commons-query.wikimedia.org
  3. Find the wcqsOauth cookie — its value is a hex string pair separated by a period (e.g., b8d15147d1cfed1129f1f7f38e2acb03.9f8b5d50d1861bf2198ead63ff345c4a94986c61)
  4. Store this in an environment variable: export WCQS_AUTH_TOKEN="..."

⚠️ Cookie lifespan: The wcqsOauth cookie is valid indefinitely until you revoke the grant at Special:OAuthManageMyGrants. Logging out of Commons does not invalidate it.

Using the cookie with curl

bash
curl -X POST "https://commons-query.wikimedia.org/sparql" \
  -H "Accept: application/sparql-results+json" \
  -H "User-Agent: MyBot/1.0 (https://example.com; user@example.com)" \
  -H "Cookie: wcqsOauth=$WCQS_AUTH_TOKEN" \
  --cookie-jar /tmp/wcqs-cookies.txt \
  -L \
  -d "query=SELECT ?file WHERE { ?file wdt:P180 wd:Q42 . } LIMIT 10"

The -L flag and --cookie-jar are important — WCQS issues a wcqsSession cookie via a 307 redirect on the first request, and subsequent requests need both cookies.

Using the cookie with Python

python
from http.cookiejar import Cookie
import os
import requests
from urllib.parse import urlparse

def init_wcqs_session(token):
    """Create a requests.Session authenticated against WCQS."""
    endpoint = "https://commons-query.wikimedia.org/sparql"
    domain = urlparse(endpoint).netloc
    session = requests.Session()
    session.headers.update({
        "User-Agent": "MyBot/1.0 (https://example.com; user@example.com)",
    })
    session.cookies.set_cookie(
        Cookie(0, "wcqsOauth", token, None, False,
               domain, False, False, "/", True,
               False, None, True, None, None, {})
    )
    return session

session = init_wcqs_session(os.environ["WCQS_AUTH_TOKEN"])
resp = session.post(
    "https://commons-query.wikimedia.org/sparql",
    data={"query": "SELECT ?file WHERE { ?file wdt:P180 wd:Q42 . } LIMIT 10"},
    headers={"Accept": "application/sparql-results+json"},
)
resp.raise_for_status()
print(resp.json())

Using with Pywikibot

python
import pywikibot
from pywikibot.data import sparql

site = pywikibot.Site('commons', 'commons')
site.login()

query = """
SELECT ?item WHERE {
  ?item wdt:P180 wd:Q42 .
} LIMIT 10
"""

entity_url = 'https://commons.wikimedia.org/entity/'
endpoint = 'https://commons-query.wikimedia.org/sparql'

query_object = sparql.SparqlQuery(endpoint=endpoint, entity_url=entity_url)
data = query_object.select(query, full_data=True)

for row in data:
    page_id = int(row['item'].getID().replace('M', ''))
    pages = list(site.load_pages_from_pageids([page_id]))
    if pages:
        print(pages[0])

Core Query Patterns

Pattern 1: ImageGrid — Visual Results

The #defaultView:ImageGrid directive displays results as a visual grid of thumbnails (works in both the WCQS web UI and QLever web UI):

sparql
#defaultView:ImageGrid
SELECT ?file ?image WHERE {
  ?file wdt:P180 wd:Q42 ;       # depicts Douglas Adams
         schema:url ?image .     # file URL for thumbnail display
}

Key requirement: The query must select a variable bound to schema:url — that's what the ImageGrid view uses to render thumbnails.

Pattern 2: Map — Geolocated Files

Files with wdt:P1259 (coordinates of point of view) can be displayed on a map:

sparql
#defaultView:Map
SELECT ?file ?pov_coords ?image WHERE {
  ?file wdt:P180 wd:Q12280 ;      # depicts bridge
         wdt:P1259 ?pov_coords ;   # has point-of-view coordinates
         schema:url ?image .
}

Pattern 3: Captions (Labels for M IDs)

M IDs have multilingual captions accessible via rdfs:label or the wikibase:label SERVICE:

sparql
SELECT ?file ?fileLabel WHERE {
  ?file wdt:P180 wd:Q102231 .          # depicts rose
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
  }
}

Note: The wikibase:label SERVICE works the same way as in WDQS but returns the file caption as the label for M IDs. Captions can live in the mul default value instead of per-language entries — that is why mul is in the language list above: without it, those files come back labelled M….

⚠️ SERVICE wikibase:label is a WDQS feature — QLever rejects it (verified 2026-10-09). Against the qlever.dev/api/wikimedia-commons endpoint the same query returns HTTP 400, not an empty result. Use rdfs:label with an explicit language filter there and read mul last:

sparql
?file rdfs:label ?fileLabel . FILTER(LANG(?fileLabel) IN ("en", "mul"))

Labels are in QLever's Commons graph (37,458,840 rdfs:label triples on 2026-10-09), so a query that "has no labels" is a query using the wrong service.

Pattern 3b: Region-level depicts — qualifiers live only in SPARQL

The rectangles that say where in a file something is depicted are qualifiers (pq:P2677), and search cannot answer for them: haswbstatement:P2677 reported 1 file where SPARQL found 7,926 files / 23,561 statements (2026-10-09). The value is a geometry string — pct:x,y,width,height, in percent of the image, e.g. pct:11.271224,16.205793,19.055633,43.002592:

sparql
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?file ?pos ?depicted WHERE {
  ?file p:P180 ?st . ?st pq:P2677 ?pos . ?st ps:P180 ?depicted .
}

(For what these regions are used for — clickable zones and labelled overlays — see wikimedia-commons-sdc, and note that ImageNote boxes on file pages are a separate, unsynchronised layer: only 4.2% of notes agree with the file's structured data.)

Pattern 4: Media Metadata — Files by Dimensions

sparql
# Find square images larger than 2000×2000 pixels
SELECT ?file ?w ?h WHERE {
  ?file schema:width ?w ;
         schema:height ?h .
  FILTER(?w = ?h && ?w > 2000)
}
LIMIT 100

Pattern 5: Files by File Type

sparql
SELECT ?encoding (COUNT(*) AS ?total) WHERE {
  ?file schema:encodingFormat ?encoding .
}
GROUP BY ?encoding
ORDER BY DESC(?total)

Pattern 6: Copyright / License Analysis

sparql
# Files under CC0 license
SELECT ?file ?image WHERE {
  ?file wdt:P275 wd:Q50829104 ;   # copyright license = CC0
         schema:url ?image .
}
LIMIT 100
sparql
# Public domain files
SELECT ?file ?image WHERE {
  ?file wdt:P6216 wd:Q50402863 ;   # copyright status = public domain
         schema:url ?image .
}
LIMIT 100

Pattern 7: Media from a Specific Commons Category

Uses the wikibase:mwapi SERVICE to find all files in a Category:

sparql
# Files directly in Category:Spoken English Wikipedia
SELECT ?member WHERE {
  BIND("Category:Spoken English Wikipedia" AS ?category) .
  SERVICE wikibase:mwapi {
     bd:serviceParam wikibase:endpoint "commons.wikimedia.org";
                     wikibase:api "Generator";
                     mwapi:generator "categorymembers";
                     mwapi:gcmtype "file";
                     mwapi:gcmtitle ?category;
                     mwapi:gcmprop "title";
                     mwapi:gcmlimit "max".
     ?member wikibase:apiOutput mwapi:title.
  }
}

To construct M IDs from the MWAPI output:

sparql
SELECT ?file ?category WHERE {
  BIND("Category:Media from iNaturalist" AS ?category) .
  SERVICE wikibase:mwapi {
     bd:serviceParam wikibase:endpoint "commons.wikimedia.org";
                     wikibase:api "Generator";
                     mwapi:generator "categorymembers";
                     mwapi:gcmtype "file";
                     mwapi:gcmtitle ?category;
                     mwapi:gcmlimit "max";
                     mwapi:gcmprop "title|pageid".
     ?title wikibase:apiOutput mwapi:title .
     ?pageid wikibase:apiOutput "@pageid" .
  }
  BIND(URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
}

Federated Queries: Commons ↔ Wikidata

One of the most powerful features is federating between the Commons SPARQL endpoint and the Wikidata Query Service. This lets you find Commons files based on Wikidata properties.

Pattern A: File depicts a Wikidata item → get Wikidata label

sparql
SELECT ?file ?itemLabel WHERE {
  ?file wdt:P180 wd:Q42 .
  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
      wd:Q42 rdfs:label ?itemLabel .
    }
  }
}

Pattern B: All files depicting Van Gogh's artworks

Finds all Wikidata items where creator = Vincent van Gogh, then finds all Commons files that depict those items:

sparql
#defaultView:ImageGrid
SELECT ?image ?painting ?paintingLabel WITH {
  SELECT * {
    SERVICE <https://query.wikidata.org/sparql> {
      ?painting wdt:P170 wd:Q5582 .                          # painter = Van Gogh
      SERVICE wikibase:label {
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
        ?painting rdfs:label ?paintingLabel .
      }
    }
  }
} AS %paintings WHERE {
  INCLUDE %paintings .
  ?image wdt:P180 ?painting ;      # file depicts this painting
         schema:url ?image .
}

Pattern C: Subclass-aware — files depicting roses (and all rose subclasses)

sparql
#defaultView:ImageGrid
SELECT DISTINCT ?item ?itemLabel ?image WITH {
  SELECT ?item ?itemLabel WHERE {
    SERVICE <https://query.wikidata.org/sparql> {
      ?item wdt:P31/wdt:P279* wd:Q34687 .   # subclasses of rose
      SERVICE wikibase:label {
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
        ?item rdfs:label ?itemLabel .
      }
    }
  }
} AS %wikidataItems WHERE {
  INCLUDE %wikidataItems .
  ?file wdt:P180 ?item ;            # file depicts this rose species/variety
         schema:url ?image .
}
LIMIT 1000

Pattern D: Camera analytics — cameras used by iNaturalist contributors

sparql
SELECT DISTINCT ?capturedWith ?capturedWithLabel (COUNT(?file) AS ?counts)
WITH {
  SELECT ?file ?title WHERE {
    SERVICE wikibase:mwapi {
      bd:serviceParam wikibase:api "Generator";
                      wikibase:endpoint "commons.wikimedia.org";
                      mwapi:gcmtitle "Category:Media from iNaturalist";
                      mwapi:generator "categorymembers";
                      mwapi:gcmtype "file";
                      mwapi:gcmlimit "max".
      ?title wikibase:apiOutput mwapi:title .
      ?pageid wikibase:apiOutput "@pageid" .
    }
    BIND(URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
  }
} AS %get_files
WHERE {
  INCLUDE %get_files
  ?file wdt:P4082 ?capturedWith .
  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
      ?capturedWith rdfs:label ?capturedWithLabel .
    }
  }
}
GROUP BY ?capturedWith ?capturedWithLabel
ORDER BY DESC(?counts)

⚠️ Federation Performance Notes

  • Federated queries are slower than single-endpoint queries — expect 10-60s
  • On WCQS, the Blazegraph optimizer can interfere with federated queries. Add hints if needed:
    sparql
    hint:Query hint:optimizer "None"
    or
    sparql
    hint:Prior hint:runFirst true
  • On QLever, federation performance is generally better due to the QLever engine's design
  • For performance, consider fetching data from Wikidata first (small result set), then using VALUES to pass it to the Commons endpoint

Advanced Qualifier Query Patterns

Commons statements can carry qualifiers — additional context for a statement. For example, a depicts (P180) statement can be qualified with P462 (color) or P6022 (expression/gesture/body pose).

Pattern A: Depicts + Color qualifier

sparql
# Files depicting roses + the color of the rose
SELECT ?file ?color ?image WITH {
  SELECT ?color (IRI(REPLACE(STR(SAMPLE(?photo)), "^.*/", STR(commons:))) AS ?image) WHERE {
    ?file a schema:ImageObject ;
          schema:contentUrl ?photo ;
          p:P180 [                      # statement-level path
            ps:P180 wd:Q102231 ;        # value = rose
            pq:P462 ?color              # qualifier = color
          ] .
  }
  GROUP BY ?color
} AS %roses WHERE {
  INCLUDE %roses .
  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
      ?color rdfs:label ?colorName .
    }
  }
}

Pattern B: Depicts + Gesture qualifier

sparql
# Most common gesture/expression values for depicts statements
SELECT ?count ?value ?valueLabel ?example
WITH {
  SELECT (COUNT(DISTINCT(?file)) AS ?count) ?value (SAMPLE(?file) AS ?example) WHERE {
    ?file p:P180/pq:P6022 ?value .     # qualifier path: depicts → expression/gesture
  }
  GROUP BY ?value
  ORDER BY DESC(?count)
  LIMIT 2000
} AS %values
WHERE {
  INCLUDE %values .
  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
      ?value rdfs:label ?valueLabel .
    }
  }
}
ORDER BY DESC(?count)

Path syntax summary

PathMeaning
?file wdt:P180 wd:Q42File has a direct depicts statement with value Q42
?file p:P180 ?statementBind the depicts statement node (to then access qualifiers)
?statement ps:P180 wd:Q42The statement node's value is Q42
?statement pq:P462 ?colorThe statement node's qualifier is color = ?color
?file p:P180/pq:P6022 ?valueShorthand: navigate from file through statement to qualifier

Practical Limitations

WCQS Limitations

  • Beta status: No stability, interface, or backward-compatibility guarantees
  • Weekly reloads: Data reloaded every Monday from Sunday dumps; service is down ~4 hours during reload
  • HTTP URIs: MediaInfo concept URIs are still HTTP, not HTTPS (may change — see T258590)
  • No prefix support: URI prefixes for Commons-specific data don't work yet — use full URIs
  • No autocomplete: Autocomplete for Commons entities doesn't work in the WCQS web UI

QLever Limitations

  • Third-party service: Not operated by WMF — no SLO, no operational guarantees
  • Index freshness: Updates depend on the QLever project's ingestion pipeline
  • Different query engine: QLever's SPARQL implementation has some differences from Blazegraph — certain complex queries may behave differently

Common to Both

  • 1.5 billion triples/year growth — data volumes will continue increasing
  • MediaInfo vocabulary is a subset of the full Wikidata property space — not all properties are equally populated on Commons files
  • The query you write may need to use a random sample (bd:sample SERVICE on WCQS) to avoid timeouts on large result sets

Tooling

🔧 Commons SPARQL Quick Query (scripts/commons-sparql-query.sh)

Run a SPARQL query against the QLever Commons endpoint and display results:

bash
./scripts/commons-sparql-query.sh "SELECT ?file WHERE { ?file wdt:P180 wd:Q42 } LIMIT 10"
./scripts/commons-sparql-query.sh --ql "SELECT ?file WHERE { ?file wdt:P180 wd:Q42 } LIMIT 10"

📚 Commons SPARQL Patterns Reference (references/commons-sparql-patterns.md)

Deep reference including:

  • All Commons Wikibase properties with their data types and usage
  • Pre-built query patterns for common tasks
  • Catalogs-specific queries
  • GLAM workflow queries
  • Performance optimization for federated queries

🐍 Commons SPARQL Inspector (assets/commons-sparql-inspector.py)

A Python tool to inspect Commons structured data — find M IDs by file title, query depicts/copyright/camera data, and display results as formatted output.

Файлы в комплекте

Модель читает эти файлы по мере необходимости, пока навык загружен. Они доступны только для чтения и никогда не выполняются.

Часто задаваемые вопросы

Что делает навык ИИ Wikimedia Commons Sparql?

Query Wikimedia Commons structured data via SPARQL — MediaInfo entities (M IDs), the depicts/copyright/licensing graph, Schema.org media metadata, and federated queries with Wikidata. Covers both the official WCQS endpoint (OAuth-authenticated) and the QLever third-party endpoint (no auth required)

Зачем использовать Wikimedia Commons Sparql в TypingMind?

Потому что вы устанавливаете навык один раз и используете его с любой моделью. Wikimedia Commons Sparql — это обычный текст в формате Markdown, а не код для конкретного поставщика, поэтому один и тот же навык работает с GPT-5, Claude, Gemini, Grok или локальной моделью. Вы можете менять модель прямо во время чата, и навык продолжит работать. TypingMind использует ваши собственные ключи API, поэтому вы платите поставщикам напрямую, а не оформляете подписку с оплатой за каждое место. Ваши навыки и чаты остаются в вашем собственном хранилище.

Как установить Wikimedia Commons Sparql в TypingMind?

В TypingMind откройте «Плагины → Навыки → Установить из GitHub» и вставьте https://github.com/fuzheado/Wikipedia-AI-Skills/tree/main/.claude/skills/wikimedia-commons-sparql. TypingMind прочитает файл SKILL.md, включит сопутствующие файлы в пакет и установит навык, который можно включать отдельно для каждого чата.

Какие модели ИИ могут использовать Wikimedia Commons Sparql?

Любая модель, которую вы подключите в TypingMind. Навыки ИИ — это обычные инструкции в формате Markdown, а не код для конкретного поставщика, поэтому GPT, Claude, Gemini, Grok и локальные модели могут загружать этот навык, когда запрос ему соответствует.

Со сколькими моделями ИИ можно использовать Wikimedia Commons Sparql?

С любым количеством. В TypingMind вы можете использовать Wikimedia Commons Sparql с любой моделью, которая поддерживает навыки, в том числе с GPT, Claude, Gemini, Grok, DeepSeek, Mistral и Llama. Для этого вы используете собственные ключи API.

Бесплатен ли навык ИИ Wikimedia Commons Sparql?

Да. Навык опубликован на GitHub по лицензии MIT. Издатель — fuzheado. Вы платите только своему поставщику ИИ за использованные токены.

Что такое навыки ИИ?

Навык ИИ — это набор инструкций, которыми модель ИИ может пользоваться каждый раз, когда ей нужно выполнить конкретную задачу. Он соответствует открытому формату Agent Skills: файл SKILL.md с названием и описанием, а также любые скрипты, шаблоны или справочные файлы, которые могут понадобиться модели. Модель читает инструкции, только когда ваш запрос соответствует навыку, поэтому установленный навык ничего не стоит, пока не используется.

Чем навыки ИИ отличаются от плагинов и серверов MCP?

Плагин или сервер MCP даёт модели новые инструменты, которые она может вызывать: при вызове где-то выполняется код и возвращает результат. Навык ИИ, напротив, даёт модели знания и описывает порядок действий: как подойти к задаче, какие шаги выполнить и каким должен быть хороший результат. Навыки — это обычный текст в формате Markdown, поэтому им не нужны сервер, ключ API или среда выполнения, и они работают с любой моделью.

Все

Создайте своё рабочее пространство с ИИ прямо сейчас

Подпишитесь на нашу рассылку, чтобы узнавать о новых функциях и предстоящих розыгрышах 👇