如何将一个sparql查询的输出作为输入传递给另一个sparql查询 [英] How the pass the output of one sparql query as a input to another sparql query

查看:107
本文介绍了如何将一个sparql查询的输出作为输入传递给另一个sparql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用第一个查询中的电影名称获取dbpedia电影链接,并在第二个查询中传递该链接以获取类似于该电影的电影。例如,Lagaan.Now,而不是在第二个中手动传递链接查询有一种方法可以组合两个查询,并将第一个查询的输出作为输入传递给第二个查询。即:电影lagaan的链接。此外,如果第一个查询给出了多个链接,例如:如果我正在搜索哈利·波特它将返回多个哈利·波特系列链接,因此,它也应处理该情况。

I am trying get the dbpedia movie link using the movie name in the first query and pass that link in the second query to get the movies similar to this movie.For e.g Lagaan.Now instead of passing the link manually in the second query is there a way to combine the two queries and pass the output of first query as an input to the second query.i.e:the link of the movie lagaan.Also,if the first query gives multiple links eg:if i am searching for Harry potter it will return multiple harry potter series links so,it should handle that case as well.

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



Query 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所说

corrected query as told by 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定义子查询。内部查询的结果可用于外部查询,因此它们被传递给它们。在您的情况下,您可能会遇到以下问题:

SPARQL 1.1 defines subqueries. The results of inner queries are available to outer queries, so they are "passed" to them. In your case, you would have something along the lines of:

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

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

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

这篇关于如何将一个sparql查询的输出作为输入传递给另一个sparql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆