Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

rdf - Paginating SPARQL results

Suppose I have the following SPARQL query:

SELECT DISTINCT ?result ?label
WHERE {
  ?result a database:Column .
  ?result rdfs:label ?label .
}
ORDER BY (LCASE(?label))

What can I add to the query to limit the number of results to the first 10 given? Or preferably, the 10 results after the first n×10 results? I'm trying to implement pagination for visualizing the results.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm trying to implement a system of paging for a table that visualizes the returned data.

You want to use limit, order by, and offset. They're described pretty well in the standard:

15.4 OFFSET

OFFSET causes the solutions generated to start after the specified number of solutions. An OFFSET of zero has no effect.

Using LIMIT and OFFSET to select different subsets of the query solutions will not be useful unless the order is made predictable by using ORDER BY.

15.5 LIMIT

The LIMIT clause puts an upper bound on the number of solutions returned. If the number of actual solutions, after OFFSET is applied, is greater than the limit, then at most the limit number of solutions will be returned.

In your case, your query would be something like this to show the fourth page of results when you are showing ten results per page:

SELECT DISTINCT ?result ?label
WHERE {
  ?result a database:Column .
  ?result rdfs:label ?label .
}
ORDER BY (LCASE(?label))
LIMIT 10
OFFSET 30

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...