Convert freebase MQL to SPARQL

after freebase MQL finds 5 artists and 50 albums for each artist.

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

first attempt - no subquery

I can write SPARQL as follows:

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

but I don’t know how much nshould be indicated, because SPARQL does not have a hierarchy as far as I know.

second attempt - with a subquery (not sure if this works correctly)

The next subquery looks like it works.

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

But I do not know how to specify k, nto receive 50 albums for artists 5.

Some endpoint data

Can someone write SPARQLthat prints 5 artists and their 5 paintings for each artist?

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.
        }
    }
}

.

+4
2

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 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

+3

, , - , SPARQL ( , , , m ;)):

- SPARQL , .

, .

LIMIT k (k = 5) 2- 5 , , n 50 ( ) 50 5 , 50/, . .

EDIT: / , (-) 50 ( title IRI sort)

PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
PREFIX prop:<http://dbpedia.org/property/>
SELECT ?artist ?outputAlbum
WHERE 
{
    {
        SELECT ?artist (MAX(str(?album1)) as ?maxedAlbum)
        WHERE {
            ?album1 prop:artist ?artist .
            ?album2 prop:artist ?artist .
            FILTER (str(?album2) < str(?album1))
        } 
        GROUP BY ?artist 
        HAVING count(?album2)<= 50
        LIMIT 5
    } 
    ?outputAlbum prop:artist ?artist .
    FILTER (str(?outputAlbum) < str(?maxedAlbum))
}

2: , , , - ( re "gime) dbpedia ( ). - , , - - ):

PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
PREFIX prop:<http://dbpedia.org/property/>
SELECT ?artist ?outputAlbum ?maxedCount ?inferredCrossJoinCount
WHERE 
{
    {
        SELECT ?artist (MAX(str(?album1)) as ?maxedAlbum) (count(distinct ?album2) as ?maxedCount) (count(?album2) as ?inferredCrossJoinCount)
        WHERE {
            ?artist rdf:type dbpedia-owl:Artist .
            ?album1 ?p ?artist .
            ?album2 ?p ?artist .
            FILTER (sameTerm(?p, prop:artist))
            FILTER (str(?album1) < str(?album2))
        } 
        GROUP BY ?artist 
        #HAVING count(?album2)<= 50
        LIMIT 5
    } 
    ?outputAlbum ?p ?artist .
    FILTER (sameTerm(?p, prop:artist))
    FILTER (str(?outputAlbum) < str(?maxedAlbum))
}
+2

All Articles