gpt4 book ai didi

rdf - 将 freebase MQL 转换为 SPARQL

转载 作者:行者123 更新时间:2023-12-05 01:01:18 24 4
gpt4 key购买 nike

遵循 freebase MQL 为每个艺术家查找 5 位艺术家和 50 张专辑。

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

第一次尝试 - 没有子查询

我可以这样写 SPARQL:
SELECT ?artist ?album
WHERE
{
?artist :type :/music/artist .
?artist :album ?album
}
LIMIT n

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

第二次尝试 - 使用子查询(不确定这是否正常工作)

以下子查询看起来像工作。
SELECT ?artist ?album
WHERE
{
?artist :album ?album .
{
SELECT ?artist
WHERE
{
?artist :type :/music/artist
}
LIMIT k
}
}
LIMIT n

但我不知道如何指定 k , n为每 5 位艺术家获得 50 张专辑。

一些带有端点的数据
  • SPARQL 端点:http://dbpedia.org/sparql

  • 谁能写 SPARQL哪个打印 5 位艺术家和他们为每个艺术家的 5 幅画?

    下面的查询打印艺术家和他们的油漆没有 LIMIT结果。
    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我在 a chat 中进行了一些讨论,这可能最终与 Max 采取的方法相同。不过,我认为它更具可读性。它有 15 位艺术家的专辑,每张专辑最多 5 张专辑。如果您希望能够包含没有任何专辑的艺术家,则需要将某些部分设为可选。

    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 results

    关于rdf - 将 freebase MQL 转换为 SPARQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28380482/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com