Is there a way to sort the results by creation date?
Example query which must be sortet:
SELECT * WHERE {?s ?p ?o} limit 200
You can use an order by clause just like you can in SQL. Note that per the SPARQL specification, the ORDER BY only applies to SELECT queries. You will need to create a binding for the property you want to use for ordering.
Dataset: Friend of a Friend (FOAF) @prefix card: <http://www.w3.org/People/Berners-Lee/card#> .
SPARQL from Within Correspondingly, a SPARQL query consists of a set of triple patterns in which each element (the subject, predicate and object) can be a variable (wildcard). Solutions to the variables are then found by matching the patterns in the query to triples in the dataset.
SPARQL is a recursive acronym, which stands for SPARQL Protocol and RDF Query Language. SPARQL consists of two parts: query language and protocol. The query part of that is pretty straightforward. SQL is used to query relational data. XQuery is used to query XML data.
You can use an order by clause just like you can in SQL. Note that per the SPARQL specification, the ORDER BY
only applies to SELECT
queries. You will need to create a binding for the property you want to use for ordering.
SELECT ?s ?p ?o
WHERE {?s ?p ?o .
?s <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200
Update: If you're not already storing the creation date, you will need to store the metadata yourself. As to how do to do that, you have a few options:
Store a triple in your default graph which has the creation date for each subject. If you're storing more than one graph, this will become unwieldy very quickly and probably is not what you want.
Store each graph as a named graph in your RDF triple store. You can then store metadata about each graph in the default graph or in one "shared" named graph for creation times.
Store your data in the named graph and use a named graph to store the creation time metadata.
An example of option #2's SPARQL query would be:
SELECT ?s ?p ?o
WHERE {
GRAPH ?g { ?s ?p ?o . }
?g <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200
Since you've said you don't actually store the creation date in your RDF then any possible mechanism for doing this would be specific to the SPARQL implementation you were using and the backing RDF store or whatever. It's quite likely that it's just not possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With