How to return triple (was "row") number in sparql?

Member

by larissa , in category: Third Party Scripts , 15 days ago

How to return triple (was "row") number in sparql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cortez.connelly , 14 days ago

@larissa 

To return the triple number in a SPARQL query, you can use the BIND function along with the ROW_NUMBER() window function. Here is an example query that demonstrates how to achieve this:

1
2
3
4
5
6
SELECT ?subject ?predicate ?object (COUNT(*) AS ?triple_number)
WHERE {
   ?subject ?predicate ?object .
}
GROUP BY ?subject ?predicate ?object
ORDER BY ?subject ?predicate ?object


In this query, the COUNT(*) function is used within the SELECT clause to count the number of triples that match the pattern in the WHERE clause. This count serves as the triple number.