维基数据SPARQL查询:单语文本属性P1813过滤无结果问题排查
Hey there! Let's break down why adding that FILTER clause is causing your query to return no results, even though you know matching values exist.
The Root Issue
You mentioned that property wdt:P1813 (alias) is a monolingual text property. Unlike multilingual text properties in Wikidata, monolingual text values don't carry explicit language tags in the same way. When you use FILTER(?v1 = "GNU AGPL"@en), you're asking to match a string that has an explicit English language tag—but the monolingual text values for P1813 likely don't have this tag attached (or their language is set to an empty string, depending on how Wikidata stores them). That's why the equality check fails.
Fixes to Try
Here are a couple of simple adjustments to make your filter work:
Remove the language tag from the string
Since monolingual text doesn't rely on explicit language tags for matching, just compare the raw string:SELECT DISTINCT ?i ?iLabel ?v1 WHERE { ?i wdt:P31 wd:Q7603. ?i wdt:P1813 ?v1. FILTER(?v1 = "GNU AGPL") SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". } } LIMIT 100Use the
STR()function to extract the raw string
If you want to be explicit about comparing the text content (ignoring any potential language metadata), wrap?v1inSTR():SELECT DISTINCT ?i ?iLabel ?v1 WHERE { ?i wdt:P31 wd:Q7603. ?i wdt:P1813 ?v1. FILTER(STR(?v1) = "GNU AGPL") SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". } } LIMIT 100Verify the language of your values first
If you're still unsure, run a quick query to check what language (if any) is associated with the P1813 values:SELECT DISTINCT ?i ?iLabel ?v1 (LANG(?v1) AS ?valueLanguage) WHERE { ?i wdt:P31 wd:Q7603. ?i wdt:P1813 ?v1. SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". } } LIMIT 100For monolingual text properties,
?valueLanguagewill often return an empty string, confirming why the@entag was breaking your filter.
内容的提问来源于stack exchange,提问作者Keanu Paik

