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
2
votes
1 answer

Sparql - alphabetical sorting issue

I use AllegroGraph and Sparql to query the results. I am trying to sort based on alphabetical order, but Sparql gives the upper case more preference. Below is an analogous data and query that resembles my issue. Data:
John Jai
  • 2,363
  • 4
  • 20
  • 29
2
votes
1 answer

SPARQL Tracker Could not run update, Property not found in the ontology

tracker-sparql -qu "INSERT SILENT INTO { a nfo:FileDataObject , nie:InformationElement ;nie:isStoredAs ; nie:url 'file.mp3' ; nie:dataSource ;nie:deviceId…
Cumatru
  • 635
  • 2
  • 11
  • 31
2
votes
1 answer

How to assign parameter values in a SparqlParameterizedString

I'm playing around some with Dotnetrdf's sparql engine and I'm trying to create parametered queries with no success yet. Say I'm working on a graph g with a blank node identified as _:1690 with the code Dim queryString As SparqlParameterizedString =…
Max
  • 675
  • 4
  • 14
2
votes
2 answers

Inquiry on example of explicit join in the SPARQL

I have following sparql query(from the book, semantic web primer): select ?n where { ?x rdf:type uni:Course; uni:isTaughtBy :949352 ?c uni:name ?n . FILTER(?c=?x) . } In this case, I guess this code is same as the the…
Cho Sinhee
  • 59
  • 1
  • 10
2
votes
2 answers

Sparql queries with two variables

How can I make a sparql query with 2 variables? And let me explain: I have an ontology for historical maps. My entities are:HistoricalMap , Language , Color and the object properties that connect them are:hasLanguage , hasColor (the hist.map has…
2
votes
1 answer

Sparql bound() not working

I am new to Sparql., I have a query to fetch a property from different subjects (say parent and parentG). I have tried using PREFIX ac: PREFIX dcterms: PREFIX rdf:…
gpsbabu
  • 23
  • 1
  • 3
2
votes
2 answers

SPARQL QuadPattern

In SPARQL a QuadPattern is defined as QuadPattern ::= '{' Quads '}' Quads ::= TriplesTemplate? ( QuadsNotTriples '.'? TriplesTemplate? )* From this I understand that a QuadPattern can be empty. But I can not understand the reason. Whats the…
Cheryl
  • 245
  • 1
  • 11
2
votes
2 answers

How to get Dbpedia resource details using Jena?

After I query dbpedia over its Sparql endpoint, I get results as Jena ResourceImpl objects. Then how I can get details of this resource? For example if this resource is a person; how can I get his/her birthDate? I tried this one; but it always…
talha06
  • 5,286
  • 16
  • 75
  • 127
2
votes
1 answer

virtuoso sparql engine

I'd like to ask if anyone knows how a sparql query is actually executed in virtuoso opensource edition. Is the sparql query mapped to an sql query? How the RDF data are accessed? Should I read the source code for this? Thanks for any hint!
Tester
  • 31
  • 4
2
votes
2 answers

How to get the relationship between United Kingdom and England from DBpedia?

I'm trying to write a SPARQL query to obtain the relationship between the United Kingdom and England with no success: no result is returned, as you can see here: SELECT ?property WHERE { ?property…
Noor
  • 18,061
  • 35
  • 123
  • 236
2
votes
1 answer

How to get this sparqle query to work?

I want to have the following query in Sparql: "social triads involving Barack Obama and two other people who have some connection to the state of Illinois." Where a social triad is a group of three people where there is a link between every pair. #…
Sina
  • 1,463
  • 3
  • 14
  • 21
2
votes
1 answer

DBpedia Query: SnorQL VS SparQL VS QueryBuilder?

What are http://dbpedia.org/snorql/ and http://dbpedia.org/sparql/ and http://querybuilder.dbpedia.org/ ? Both SnorQL VS SparQL seems to run the following code similarly : SELECT ?resource ?value WHERE { ?resource a…
Hugolpz
  • 14,637
  • 24
  • 85
  • 173
2
votes
2 answers

Query cities and their country from dbpedia

I'm trying to construct an ontology in OWL for countries and cities(If such an implementation already exist, please point it to me) To get the data, I'm trying to use sparql with the following code: SELECT ?c WHERE { ?c rdfs:label ?name . ?c…
Noor
  • 18,061
  • 35
  • 123
  • 236
2
votes
1 answer

SPARQL date range

I'm trying to obtain all records between certain dates. The date field has appears in this format: 2012-01-31. I think it is of type: How would I modify the query below to extract records with date greater…
spiderplant0
  • 3,580
  • 11
  • 46
  • 84
2
votes
1 answer

SPARQL - Subjects needed to complete the set

I am working on a new project using RDF, just learning it and SPARQL. I thought this query would be easier than it is turning out to be. Given this store (simplified out of the ontology) Person1 -Owns-> Part1 Person2 -Owns-> Part1 Person2 -Owns->…
Craig
  • 249
  • 2
  • 5