如何在python中使用SPARQLWrapper处理参数化查询中的字符串

from SPARQLWrapper import SPARQLWrapper, RDFXML, JSON, XML, N3
from rdflib import Graph
sparql = SPARQLWrapper("https://agrovoc.uniroma2.it/sparql")

sparql.setQuery("""
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> 
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#> 
SELECT *
WHERE { 
       
  ?subject a skos:Concept . 
  ?subject skosxl:prefLabel ?xLab . 
  ?xLab skosxl:literalForm "biomass"@en  .
} """)

sparql.setReturnFormat(JSON)
results = sparql.query().convert()
print(results)

 pip install SPARQLWrapper

posted @ 2021-11-19 14:26  薄荷味日记  阅读(210)  评论(0编辑  收藏  举报