如何将一个 sparql 查询的输出作为输入传递给另一个 sparql 查询

How the pass the output of one sparql query as a input to another sparql query

我正在尝试在第一个查询中使用电影名称获取 dbpedia 电影 link 并在第二个查询中传递 link 以获取类似于此 movie.For 的电影,例如Lagaan.Now 而不是在第二个查询中手动传递 link 有没有一种方法可以组合两个查询并将第一个查询的输出作为输入传递给第二个 query.i.e:the link 电影 lagaan.Also,如果第一个查询给出多个 link eg:if 我正在搜索哈利波特它将 return 多个哈利波特系列 link是这样,它也应该处理这种情况。

查询 1

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

          select distinct ?film where  {
          ?film a dbpedia-owl:Film .
          ?film rdfs:label ?label .
          filter regex( str(?label), "Lagaan", "i")
          }
          limit 10

查询 2

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
        select ?similar (count(?p) as ?similarity) where { 
          values ?movie { <http://dbpedia.org/resource/Lagaan> }
          ?similar ?p ?o ; a dbpedia-owl:Film .
          ?movie   ?p ?o .
        }
        group by ?similar ?movie
        having count(?p) > 35
        order by desc(?similarity)

已编辑查询:

  select ?film ?similar (count(?p) as ?similarity) where {

  { 
          select distinct ?film where  {
          ?film a dbpedia-owl:Film .
          ?film rdfs:label ?label .
          filter regex( str(?label), "Lagaan", "i")
          } 
  }

         ?similar ?p ?o ; a dbpedia-owl:Film .
         ?film  ?p ?o .
        }
        group by ?similar ?film
        having count(?p) > 35
        order by desc(?similarity)

更正了 Joshua Taylor 所说的查询

select ?film ?other (count(*) as ?similarity) {
  {
    select ?film where {
      ?film a dbpedia-owl:Film ; rdfs:label ?label .
      filter contains(lcase(?label),"lagaan")
    }
    limit 1
  }
  ?film ?p ?o .
  ?other a dbpedia-owl:Film ; ?p ?o .
}
group by ?film ?other
having count(?p) > 25
order by desc(?similarity)

is there a way to combine the two queries and pass the output of first query as an input to the second query.

SPARQL 1.1 定义了子查询。内部查询的结果对外部查询是可用的,所以对它们来说是"passed"。在你的情况下,你会有类似的东西:

select ?similarMovie (... as ?similarity) where {

  { #-- QUERY 1, find one or more films
    select distinct ?film where {
      #-- ...
    }
  }

  #-- QUERY 2, find films similar to ?film
  #-- ...
}