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

使用Jena-Fuseki联邦查询诺贝尔奖SPARQL端点返回text/html错误

解决Jena-Fuseki联邦查询诺贝尔奖端点的Content-Type错误问题

问题核心

诺贝尔奖的SPARQL端点中,snorql是网页查询界面,默认返回HTML格式;即使是纯API端点sparql,也可能因请求参数缺失返回非标准格式,而Fuseki的联邦查询要求端点返回SPARQL标准结果格式(如application/sparql-results+xml或application/sparql-results+json)。

可行解决方案

1. 用正确端点并强制指定结果格式

  • 仅使用纯API端点https://data.nobelprize.org/sparql,放弃snorql网页端点。
  • 在SERVICE子句中通过URL参数强制端点返回标准格式:
    SELECT ?winner ?name WHERE {
      SERVICE <https://data.nobelprize.org/sparql?format=application/sparql-results+json> {
        ?winner a nobel:Laureate ;
                rdfs:label ?name .
        ?prize nobel:laureate ?winner ;
               nobel:year "1901"^^xsd:integer .
      }
    }
    

2. 临时修改Fuseki支持HTML格式(不推荐)

若端点无法返回标准格式,可修改Fuseki配置文件fuseki.ttl,添加对text/html的结果格式支持:

prefix fuseki: <http://jena.apache.org/fuseki#>

fuseki:Server fuseki:endpoint [
    fuseki:name "/ds" ;
    fuseki:serviceQuery "query" ;
    fuseki:serviceUpdate "update" ;
    fuseki:serviceUpload "upload" ;
    fuseki:serviceReadWriteGraphStore "data" ;
    fuseki:serviceReadGraphStore "get" ;
    fuseki:resultFormats "application/sparql-results+xml" , "application/sparql-results+json" , "text/html"
] .

修改后重启Fuseki,此方案仅作应急,可能引发其他兼容性问题。

3. 直接用Wikidata查询诺奖数据

既然跨端点联邦查询受阻,可直接在Wikidata中获取1901年诺奖得主数据,无需依赖诺贝尔奖端点:

SELECT ?winner ?winnerLabel ?prizeLabel WHERE {
  ?prize wdt:P31 wd:Q7191 ;
         wdt:P585 ?date ;
         wdt:P166 ?winner .
  FILTER(YEAR(?date) = 1901)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

4. 检查Fuseki联邦功能状态

确认fuseki.ttl中已启用联邦查询:

fuseki:Server fuseki:allowFederatedQueries true .

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 08:30:03