<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[IVRYN Notes]]></title><description><![CDATA[IVRYN Notes]]></description><link>https://ivryn.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 29 Oct 2026 20:22:34 GMT</lastBuildDate><atom:link href="https://ivryn.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[What broke when we generated daily trivia from Wikidata]]></title><description><![CDATA[Five Wikidata pitfalls we measured while generating daily quizzes: mul labels, SPARQL timeouts, ranked values, unfair facts and Commons thumbnails.]]></description><link>https://ivryn.hashnode.dev/what-broke-when-we-generated-daily-trivia-from-wikidata</link><guid isPermaLink="true">https://ivryn.hashnode.dev/what-broke-when-we-generated-daily-trivia-from-wikidata</guid><category><![CDATA[Wikidata]]></category><category><![CDATA[SPARQL]]></category><category><![CDATA[Python]]></category><category><![CDATA[#OpenData]]></category><dc:creator><![CDATA[Victor Laybats]]></dc:creator><pubDate>Fri, 23 Oct 2026 16:09:07 GMT</pubDate><content:encoded><![CDATA[<p>I wanted daily quizzes whose answers anyone can check, so every question on <a href="https://playwikicards.com/trivia-questions/">our trivia pages</a> is generated from a Wikidata fact, and every answer links back to its Wikidata item. Twenty questions a day, capitals, flags, rivers, literary works, films, events, championship winners.</p>
<p>The quiz part was easy. The data part was not. Here is what broke, measured on 23 October 2026, and what we changed.</p>
<h2>1. Nearly one famous person in five had no English or French label</h2>
<p>Since 2024 Wikidata stores many proper names once, under a label for all languages (<code>mul</code>), instead of repeating them in every language. A query that asks for <code>lang(?label) = "en"</code> silently drops those items.</p>
<p>On a sample of the 200 most-read people of our card catalogue, 36 had no English or no French label: George Washington, Barack Obama, William Shakespeare and Novak Djokovic among them. Juneau, the capital of Alaska, only had the <code>mul</code> label, so Alaska disappeared from our US states quiz.</p>
<p>The fix is a fallback chain:</p>
<pre><code class="language-sparql">OPTIONAL { ?x rdfs:label ?fr  FILTER(lang(?fr)  = "fr") }
OPTIONAL { ?x rdfs:label ?en  FILTER(lang(?en)  = "en") }
OPTIONAL { ?x rdfs:label ?mul FILTER(lang(?mul) = "mul") }
BIND(COALESCE(?fr, ?mul, ?en) AS ?labelFr)
BIND(COALESCE(?en, ?mul) AS ?labelEn)
</code></pre>
<h2>2. Scanning a whole class times out</h2>
<p>The public SPARQL service stops a query after 60 seconds. "Every mountain with its elevation" or "every novel with its author" ended in an HTTP 504 or in a truncated JSON body, depending on the load of the service.</p>
<p>What works: start from a list of known items. We map our most-read Wikipedia articles to their Wikidata ids through the Wikipedia API (<code>prop=pageprops&amp;ppprop=wikibase_item</code>, 50 titles per call), then query them with <code>VALUES ?x { ... }</code> in batches of 100 ids. We also write the output after each kind of fact, so one failure no longer loses the others.</p>
<h2>3. The Nile was 2,850 km long</h2>
<p>Many items carry several values for one property. The Nile has 6,650 km with a preferred rank and also 2,850 km with a normal rank. The Amazon has 6,400 km with a preferred rank and four other values, from 3,690 to 6,992 km. A median of all values makes "which river is the longest?" wrong.</p>
<pre><code class="language-sparql">?x p:P2043 ?st .
?st psn:P2043/wikibase:quantityAmount ?length ;
    wikibase:rank ?rank .
FILTER(?rank != wikibase:DeprecatedRank)
</code></pre>
<p>We keep preferred-rank values when they exist, drop items whose remaining values disagree by more than 12 %, and only compare four rivers when the first is at least 15 % longer than the second. The Nile and the Amazon, about 4 % apart, are never the two candidates of the same question.</p>
<h2>4. True in Wikidata, unfair in a quiz</h2>
<ul>
<li>Pop songs often record a single co-writer as composer: Wikidata gives RedOne for Poker Face, which he wrote with Lady Gaga. We removed music.</li>
<li>"Discoverer" also applies to places: Persepolis would be credited to a Spanish diplomat. Anything with coordinates is out of the discoveries.</li>
<li>Franchises keep their current name for past titles: Super Bowl XI (1977) is won by the Las Vegas Raiders, who were the Oakland Raiders then. American leagues only use editions from 2000.</li>
<li>Oceania exists twice (Oceania and Insular Oceania), which left Tuvalu without a continent. We merge them.</li>
<li>Capitals with an internationally disputed status are never asked, and are marked in the list of capitals.</li>
<li>A wrong answer is never a prefix of the right one, so "Rugby" never sits next to "Rugby union".</li>
</ul>
<h2>5. Commons refuses 320 px thumbnails</h2>
<p>Flags and locator maps are Wikimedia Commons thumbnails. A width of 320 px returns HTTP 400 with "Use thumbnail sizes listed on <a href="https://w.wiki/GHai">https://w.wiki/GHai</a>", while 120, 250, 330 and 500 px are served:</p>
<pre><code class="language-python">import hashlib, urllib.parse

def thumb(name, width=330):
    n = name.replace(" ", "_")
    h = hashlib.md5(n.encode()).hexdigest()
    q = urllib.parse.quote(n)
    ext = ".png" if n.lower().endswith(".svg") else ""
    return f"https://upload.wikimedia.org/wikipedia/commons/thumb/{h[0]}/{h[:2]}/{q}/{width}px-{q}{ext}"
</code></pre>
<h2>The result</h2>
<p>Sixteen quiz pages, twenty questions a day each, every answer with its source. The cleaned fact set is open data (CC0) <a href="https://github.com/laybatsvictor-cyber/ivryn-open-research/tree/main/datasets/wikicards-wikidata-trivia-facts">on GitHub</a>, and the full write-up with the French version is <a href="https://playwikicards.com/how-the-quizzes-are-made/">on our site</a>.</p>
<p>If you build on Wikidata, I would love to hear about the quirks I missed.</p>
]]></content:encoded></item></channel></rss>