本文介绍了将freebase MQL转换为SPARQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在freebase之后,MQL会找到5位艺术家和每位艺术家50张专辑.

following freebase MQL finds 5 artists and 50 albums for each artists.

[{
  "type" : "/music/artist",
  "name":null,
  "album" : [{
    "name" : null,
    "count":null,
    "limit":50
  }],
  "limit":5
}]

第一次尝试-没有子查询

我可以这样写SPARQL:

first try - without a subquery

I can write SPARQL like this:

SELECT ?artist ?album
WHERE
{
    ?artist :type :/music/artist .
    ?artist :album ?album
}
LIMIT n

但是,我不知道应该指定多少n,因为据我所知SPARQL没有层次结构.

but, I don't know how many n should be specified because SPARQL has no hierarchy as far as I know.

下面的子查询看起来很正常.

Following sub-query looks like working.

SELECT ?artist ?album
WHERE
{
    ?artist :album ?album .
    {
        SELECT ?artist
        WHERE
        {
            ?artist :type :/music/artist
        }
        LIMIT k
    }
}
LIMIT n

但是我不知道如何指定kn来为每5位艺术家获得50张专辑.

But I don't know how to specify k, n to get 50 albums foreach 5 artists.

有人可以写SPARQL来为每位艺术家打印5位艺术家及其5幅画吗?

Could anyone write SPARQL which print 5 artists and their 5 painting for each artists?

下面的查询将打印艺术家及其绘画,而没有得到LIMIT结果.

Below query prints artists and their paints without LIMITing result.

PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
PREFIX prop:<http://dbpedia.org/property/>

SELECT ?painting ?artist
WHERE
{
    ?painting prop:artist ?artist .
    {
        SELECT ?artist
        {
            ?artist rdf:type dbpedia-owl:Artist.
        }
    }
}

谢谢.

推荐答案

Max ,我在其中进行了一些讨论聊天,这可能最终与Max相同拿.我认为它更具可读性.它可以为15位歌手提供专辑,每张专辑最多可以包含5张专辑.如果您希望能够包含没有专辑的艺术家,则需要将某些部分设为可选.

Max and I had a bit of discussion in a chat, and this might end up being the same approach that Max took. I think it's a bit more readable, though. It gets 15 artists with albums, and up to 5 albums for each one. If you want to be able to include artists without any albums, you'd need to make some parts optional.

select ?artist ?album {
  #-- select 15 bands that have albums (i.e., 
  #-- such that they are the artist *of* something).
  {
    select distinct ?artist { 
      ?artist a dbpedia-owl:Band ;
              ^dbpedia-owl:artist []
    }
    limit 15
  }

  #-- grab ordered pairs (x,y) (where y > x) of their
  #-- albums.  By asking how many x's for each y, we
  #-- get just the first n y's.
  ?artist ^dbpedia-owl:artist ?album, ?album_
  filter ( ?album_ <= ?album ) 
}
group by ?artist ?album
having count(?album_) <= 5 #-- take up 5 albums for each artist
order by ?artist ?album

SPARQL结果

这篇关于将freebase MQL转换为SPARQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 23:36