Questions tagged [sparql]

SPARQL (pronounced "sparkle", a recursive acronym for SPARQL Protocol and RDF Query Language) is a set of specifications by W3C that provide languages and protocols to query and manipulate RDF graph content on the Web or in an RDF store.

SPARQL

SPARQL (pronounced "sparkle", a recursive acronym for SPARQL Protocol and RDF Query Language) is a set of specifications by W3C that provide languages and protocols to query and manipulate RDF graph content on the Web or in an RDF store.

SPARQL 1.0

SPARQL 1.0 is the original version of SPARQL, and simply provides a query language for RDF. The language is based on Graph Pattern matching and provides 4 forms of query:

  1. ASK WHERE { } - An ASK query simply asks whether there exists a match for the Graph Pattern stated in the WHERE clause in the data being queried.
    This returns a Boolean SPARQL Results Set containing a True/False response.
  2. SELECT * WHERE { } - A SELECT query finds all the solutions that match the Graph Pattern and returns the desired parts of them. Results can be ORDERed as desired and use LIMIT and/or OFFSET for paging purposes. This is the most commonly used query form and corresponds in function (if very differently in syntax and semantics) to the SQL that many developers coming to the Semantic Web are familiar with.
    This returns a SPARQL Result Set containing the solutions.
  3. DESCRIBE <http://example.org> - A DESCRIBE query gets the description of one/more resources from the data. The query engine is free to decide what constitutes a description. A WHERE clause may be used to select what resources are to be described.
    This returns an RDF Graph.
  4. CONSTRUCT { } WHERE { } - A CONSTRUCT query takes solutions that match the WHERE clause and uses them to construct a new RDF Graph.
    This returns an RDF Graph.

SPARQL 1.0 Example

A SPARQL 1.0 query might look like the following:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
FROM <http://default>
WHERE
{
  ?s a ?type .
  OPTIONAL
  {
    ?s rdfs:label ?label .
    FILTER (LANGMATCHES(?label, "en"))
  }
}
ORDER BY ?label
LIMIT 10

This query looks for things with a type in the graph <http://default> and optionally includes their labels provided those labels are in English. It orders the results by the label limiting the results returned to 10.

SPARQL 1.1

SPARQL 1.1 is a major extension to the SPARQL ecosystem approved as a W3C Recommendation in March 2013. It provides many extensions to the existing query language including:

  • Project expressions in SELECT, e.g. (?x + ?y AS ?z)
  • Aggregates, e.g. COUNT(), GROUP BY, and HAVING
  • Property Paths, e.g. {?x ex:predicate+ ?y}
  • EXISTS and NOT EXISTS filters
  • MINUS clause for subtractive negation
  • SERVICE clause for federated querying
  • Subqueries
  • Many new built in functions particularly around string and date manipulation

It also adds a number of entirely new features into the ecosystem including:

See the SPARQL 1.1 Implementation Report for implementations that have reported compliance test results. See the SPARQL Wikipedia article for examples, extensions, and another list of implementations.

5278 questions
69
votes
2 answers

Graph Databases vs Triple Stores - when to use which?

I know that there are similar questions around on Stackoverflow but I don't feel they answer the following. Graph Databases to my understanding store data following mostly this schema: Table/Collection 1: store nodes with UID Table/Collection 2:…
B M
  • 3,395
  • 2
  • 24
  • 40
52
votes
4 answers

Exploratory SPARQL queries?

whenever i start using sql i tend to throw a couple of exploratory statements at the database in order to understand what is avaliable, and what form the data takes. eg. show tables describe table select * from table could anyone help me…
significance
  • 3,923
  • 8
  • 35
  • 55
49
votes
10 answers

What is the semantic web?

I've heard a lot about the semantic web but I'm still not exactly sure what it is. How will it be different to the web we know now?
Matthew James Taylor
  • 4,459
  • 5
  • 26
  • 32
42
votes
4 answers

Triple Stores vs Relational Databases

I was wondering what are the advantages of using Triple Stores over a relational database?
Sam
  • 1,231
  • 2
  • 12
  • 16
30
votes
7 answers

Is there any killer application for Ontology/semantics/OWL/RDF yet?

I got interested in semantic technologies after reading a lot of books, blogs and articles on the net saying that it would make data machine-understandable, allow intelligent agents make great reasoning, automated & dynamic service composition…
user304867
  • 317
  • 3
  • 3
30
votes
2 answers

SPARQL query and distinct count

I have the following query: SELECT ?tag WHERE { ?r ns9:taggedWithTag ?tagresource. ?tagresource ns9:name ?tag } LIMIT 5000 and the results are: abc abc abc abc abc abc abc abd ads anb I want to get somthing like: tag |…
cupakob
  • 7,691
  • 24
  • 60
  • 75
29
votes
2 answers

"or" in a SPARQL query

I don't quite understand why in SPARQL they haven't implemented the basic logic operators. However in most of the cases is possible to obtain the same result in a number of way. The purpose of this question is to have a quick reference for the…
ffa
  • 557
  • 1
  • 4
  • 12
28
votes
4 answers

What is the difference between GraphQL and SPARQL?

I'm doing a lot of research right now on Semantic Web and complex data models that represent relationships between individuals and organizations. I knew a little semantic ontologies although I never understood what it was used if not make graphs. I…
Erwan Pesle
  • 631
  • 1
  • 7
  • 12
24
votes
1 answer

What is the difference between DatatypeProperty, ObjectProperty, & FunctionalProperty, and when should I use them?

When writing an ontology, there are several very commonly used types, including: DatatypeProperty ObjectProperty FunctionalProperty InverseFunctionalProperty The first three kinda look like they'd be used in a particular set of ways, but I find my…
Kristian
  • 19,340
  • 14
  • 84
  • 156
23
votes
2 answers

SPARQL DISTINCT vs. REDUCED

What is the difference between DISTINCT and REDUCED in SPARQL?
Infinite
  • 2,692
  • 2
  • 25
  • 32
23
votes
3 answers

Is it possible to get the position of an element in an RDF Collection in SPARQL?

Suppose that I have the following Turtle declaration: @prefix : . :ls :list (:a :b :c) Is there a way to get the positions of the elements in the collection? For example, with this query: PREFIX : …
Labra
  • 1,252
  • 1
  • 10
  • 30
20
votes
3 answers

SPARQL select optional with language

I have some triples that look like this: test:thing rdfs:label "Non-Language Label" test:thing rdfs:label "English Label"@en test:thing rdfs:label "French Label"@fr I'd like to form a sparql query that gives me the "Non-Language Label" AND the…
Devin McQueeney
  • 1,231
  • 2
  • 12
  • 29
20
votes
2 answers

Get all properties for a DBpedia class

How to get a list of properties for a specific class? Consider the class dbpedia-owl:Person. All instances of the Person class have some properties prefixed with dbpprop:. How can I get all the dbpprop: properties that we may find for all the…
user878812
  • 239
  • 1
  • 2
  • 6
20
votes
1 answer

Meaning of SPARQL operator ';'

What does ';' operator in WHERE clause means in SPARQL? For example: SELECT ?x ?y WHERE { ?z foaf:name ?x ; :surname ?y } What the ; operator means here? Is like a logical and that means this part ?z foaf: goes before :surname again?
Blenikos
  • 693
  • 11
  • 18
1
2 3
99 100