glam/.opencode/rules/wikidata-mapping-verification-rule.md

2.8 KiB

Wikidata Mapping Verification Rule

Rule: Always Verify Wikidata Mappings Using Authenticated Tools

When adding or reviewing Wikidata mappings (wd:Qxxxxx), you MUST verify the entity exists and is semantically appropriate using the available tools.

Verification Methods (in order of preference)

1. Wikidata SPARQL Query (Primary)

Use wikidata-authenticated_execute_sparql to verify entity labels and descriptions:

SELECT ?item ?itemLabel ?itemDescription WHERE {
  VALUES ?item { wd:Q38723 wd:Q2385804 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

2. Wikidata Metadata API

Use wikidata-authenticated_get_metadata to retrieve label and description:

entity_id: Q38723
language: en

3. Web Search as Fallback

If authenticated tools fail, use linkup_linkup-search or exa_web_search_exa:

query: "Wikidata Q38723 higher education institution"

Common Errors to Avoid

Error Example Fix
Wrong QID Q600875 (a person) for "academic program" Q600134 (course)
Too broad Q35120 (entity) for specific class Use appropriate subclass
Too narrow Q3918 (university) for general academic institution Use Q38723 (higher education institution)
Different concept Q416703 (museum building) for museum organization Use appropriate organizational class

Verification Checklist

Before committing any Wikidata mapping:

  • QID exists (not 404)
  • Label matches expected concept
  • Description confirms semantic alignment
  • Mapping specificity follows Rule 63 (exact/broad/narrow/close)
  • Not a duplicate of another mapping in the same class

Example Verification

WRONG:

# Q600875 was not verified - it's actually a person
close_mappings:
  - wd:Q600875  # Juan Lindolfo Cuestas - President of Uruguay!

CORRECT:

# Verified via SPARQL: Q600134 = "course"
close_mappings:
  - wd:Q600134  # program of study, or unit of teaching

SPARQL Query Template

SELECT ?item ?itemLabel ?itemDescription ?itemAltLabel WHERE {
  VALUES ?item { wd:Q38723 }
  OPTIONAL { ?item skos:altLabel ?itemAltLabel. FILTER(LANG(?itemAltLabel) = "en") }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Batch Verification

For multiple QIDs in a file, verify all at once:

SELECT ?item ?itemLabel ?itemDescription WHERE {
  VALUES ?item { wd:Q38723 wd:Q2385804 wd:Q600134 wd:Q3918 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Integration with Other Rules

This rule complements:

  • Rule 63 (mapping-specificity-hypernym-rule.md): Determines mapping type (exact/broad/narrow)
  • no-hallucinated-ontology-references.md: Prevents fake ontology terms
  • verified-ontology-terms.md: General ontology verification