编程语言
首页 > 编程语言> > 如何在python中使用SPARQLWrapper处理参数化查询中的字符串

如何在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

标签:xLab,sparql,python,SPARQLWrapper,PREFIX,字符串,skosxl,skos
来源: https://www.cnblogs.com/Mint-diary/p/15577108.html