You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于DBPedia构建关联疾病与医学专科的SPARQL查询

Extending Your SPARQL Query to Get Disease-Medical Specialty Mappings

Great question! Since you're already comfortable pulling a list of diseases from DBpedia, extending that query to include associated medical specialties is straightforward once you know the right property to use.

First, let's break down what you need: DBpedia uses the dbo:medicalSpecialty property to link instances of dbo:Disease to their corresponding dbo:MedicalSpecialty entities. To make the results human-readable (instead of just URIs), we'll also pull in the rdfs:label for both diseases and specialties.

Here's the modified query:

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?disease ?diseaseLabel ?specialty ?specialtyLabel
WHERE {
  ?disease a dbo:Disease ;
           dbo:medicalSpecialty ?specialty .
  ?disease rdfs:label ?diseaseLabel .
  ?specialty rdfs:label ?specialtyLabel .
  FILTER(LANG(?diseaseLabel) = "en")
  FILTER(LANG(?specialtyLabel) = "en")
}
ORDER BY ?diseaseLabel

Key changes explained:

  • Added dbo:medicalSpecialty ?specialty to the WHERE clause: this creates the link between each disease and its associated medical specialty.
  • Included rdfs:label for both ?disease and ?specialty: this returns the human-friendly name instead of just the DBpedia URI (like http://dbpedia.org/resource/Diabetes_mellitus).
  • Added FILTER(LANG(...)): ensures we only get English labels (adjust the language code if you need labels in another language).
  • Changed ORDER BY to ?diseaseLabel: sorts results by the readable disease name instead of the URI, which is easier to scan.

Handling diseases without a linked specialty

Some diseases in DBpedia might not have an associated medical specialty yet. If you want to include all diseases (even those without a specialty), use the OPTIONAL clause to make that part of the query non-required:

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?disease ?diseaseLabel ?specialty ?specialtyLabel
WHERE {
  ?disease a dbo:Disease .
  ?disease rdfs:label ?diseaseLabel .
  FILTER(LANG(?diseaseLabel) = "en")
  OPTIONAL {
    ?disease dbo:medicalSpecialty ?specialty .
    ?specialty rdfs:label ?specialtyLabel .
    FILTER(LANG(?specialtyLabel) = "en")
  }
}
ORDER BY ?diseaseLabel

In this version, diseases without a specialty will still appear in the results, with ?specialty and ?specialtyLabel showing as empty values.

内容的提问来源于stack exchange,提问作者eandrews8

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:41:16