如何在sparql中遍历列表

2024-05-12 17:50:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pmid列表,保存在一个名为ID的列表中。我想遍历该列表,并使用下面的代码获取每个pmid的引用上下文。如果我将代码中的“pmid”替换为一个值,则该代码仅适用于一个pmid。我是sparql新手,我不确定应该将占位符放在代码中的什么位置,以便能够遍历整个列表

sparql = SPARQLWrapper("http://colil.dbcls.jp/sparql")
sparql.setQuery("""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX colil: <http://purl.jp/bio/10/colil/ontology/201303#>
PREFIX dcterms: <http://purl.org/dc/elements/1.1/>
PREFIX doco: <http://purl.org/spar/doco/>
PREFIX togows: <http://togows.dbcls.jp/ontology/ncbi-pubmed#>

select ?CitationPaper ?Context where {
?CitationPaper bibo: cites? ReferencePaper .
?CitationPaper doco: contains [
  doco:contains [
    rdf:value ?Context ;
    colil:mentions ? ReferencePaper 
  ]
] .
?ReferencePaper rdfs:seeAlso [
  rdf:type colil:PubMed ;
  togows:pmid'pmid'
 
] .
}""")

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

Tags: 代码orghttp列表prefixwwwrdfsparql