DBPedia SPARQL查询仅返回表头无结果问题求助
Got it, let's figure out why your SPARQL query is returning only headers with no results on DBpedia. Here are the key issues and fixes to get it working:
1. Duplicate Triple & Exact String Matching Problem
You’ve repeated the ?disease rdfs:label ?diseasename triple twice—this is redundant, but the real blocker is your exact string filter. DBpedia’s disease labels typically use title case (like "Brain Tumor"@en) instead of the lowercase "t" in your "Brain tumor" filter. This strict exact match won’t align with the actual data stored in the dataset, hence no results.
2. Fixes to Try
Option 1: Match the Exact Title-Cased Label
Update your filter to match DBpedia’s standard label formatting:
PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?diseasename ?personname WHERE { ?disease a dbo:Disease . ?person dbo:deathCause ?disease . ?person rdfs:label ?personname FILTER (lang(?personname) = "en"). ?disease rdfs:label ?diseasename FILTER (lang(?diseasename) = "en" && ?diseasename = "Brain Tumor") }
Option 2: Case-Insensitive Matching (More Flexible)
If you want to avoid worrying about capitalization, use a regex filter with the case-insensitive flag:
PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?diseasename ?personname WHERE { ?disease a dbo:Disease . ?person dbo:deathCause ?disease . ?person rdfs:label ?personname FILTER (lang(?personname) = "en"). ?disease rdfs:label ?diseasename FILTER (lang(?diseasename) = "en" && regex(?diseasename, "^brain tumor$", "i")) }
3. Quick Sanity Check
Before running the full query, confirm the disease exists in DBpedia with a simpler test:
PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?disease ?diseasename WHERE { ?disease a dbo:Disease . ?disease rdfs:label ?diseasename FILTER (lang(?diseasename) = "en" && regex(?diseasename, "brain tumor", "i")) }
This will verify that DBpedia has entries for the disease you’re targeting, which is a good pre-check before adding the person/death cause logic.
内容的提问来源于stack exchange,提问作者Rita Isabel Torres De Sousa

