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.

6076 questions
2
votes
2 answers

SPARQL Results in multiple Languages

I have a quite simple query to find all the museums (museum, abstract) that have at least 1 artwork. It works fine. I would like to have the Abstract in various languages... how can i solve it? Here the very simple query: SELECT ?museum ?abstract …
2
votes
1 answer

Marklogic - Adding a default rule set through admin console

I have defined a default ruleset through admin console. I have given the location of the ruleset as "C:/isParentOf.rules". However, it is not able to find this file. While running a query, it is complaining that " The ruleset file cannot be found:…
Deepak Saini
  • 103
  • 8
2
votes
1 answer

Calculate length of path betwen nodes (with unknown edges)?

The problem is how to calculate the distance between two nodes (concepts) in a Triple Store (RDF) using sparql queries without know the type of edges. Essencially, is to use Dijkstras_algorithm to find the shorter path between two concepts in a…
Malex
  • 41
  • 4
2
votes
1 answer

How to use the ASK WHERE statement with multiple conditions (sparql)

I want to check if an entity has one of the types listed below. If it does then the query must return true. PREFIX…
Hani Goc
  • 2,371
  • 5
  • 45
  • 89
2
votes
2 answers

SPARQL: How do I List and count each data type in an RDF dataset?

I am trying to count the instances of each datatype in a dataset. It is a simple dataset with only three data types: integer, string and dateTime. I can get the number of datatypes (3) by querying: SELECT (COUNT(DISTINCT datatype(?o)) AS…
Hilary
  • 321
  • 5
  • 15
2
votes
3 answers

SPARQL: selecting people by country

I am trying to select all people born in a specific country (e.g. Portugal) from DBPedia. I could use this query: SELECT DISTINCT ?person WHERE { ?person dbpedia-owl:birthPlace dbpedia:Portugal. } But the…
GML-VS
  • 1,101
  • 1
  • 9
  • 34
2
votes
1 answer

range function in sparql

I need all years in a given range as values in sparql (especially for the sesame implementation). Is there any way to "generate" new numbers in sparql like: SELECT (RANGE(2,10) AS ?numbers) WHERE{}
Raphael Schumann
  • 162
  • 1
  • 10
2
votes
3 answers

URLError with SPARQLWrapper at sparql.query().convert()

I try a small python script to test my SPARQL request. However, just the next simple code doesn't work. from SPARQLWrapper import SPARQLWrapper, JSON import rdflib #connect to the sparql point sparql =…
Cyril
  • 485
  • 4
  • 15
2
votes
2 answers

How to bind individual json data "values" in angular to named $scope variables (data returned using SPARQL query)?

Newby to Angular so apologies if a stupid question. Have checked other questions on dataversity, stack overflow, google ... checked w3c and attempted several "try it and see solutions" but just can't get this to play ball. Basically, i am using…
Hilary
  • 321
  • 5
  • 15
2
votes
1 answer

MarkLogic 8 - Node.js Client API - Can I do a SPARQL Query?

As the title says, I want to know if I can do a SPARQL query in the node.js client API or if I need to use the Server Side Javascript API.
Tutan Ramen
  • 1,234
  • 1
  • 8
  • 27
2
votes
2 answers

What is the difference between a temporal and a non-temporal query

I have read some resources that talk about temporal and non-temporal queries, specifically with SPARQL. What is the difference between these two kinds of queries?
Ogen
  • 6,499
  • 7
  • 58
  • 124
2
votes
2 answers

Consequence of restrictions in ontology on SPARQL end results

I am concerned about two classes (SensingDevice and Property) of my ontology (dgo.owl) as shown in the below figure. These two classes are connected by observes property: and the related ontology portion is as:
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65
2
votes
1 answer

Sparql query not showing results

I have an ontology (dgo.owl) and a simple program (SparqlQuery.java) to query the same ontology. On running the query I do not get any results. After debugging for a long time I thought it would be good to put it in the community. The query script…
Haroon Lone
  • 2,837
  • 5
  • 29
  • 65
2
votes
1 answer

How to retrieve person names with punctuation marks from DBPedia?

I am currently querying DBPedia for a list of person names by using the SPARQL package in R. When I retrieve a list of names by SPARQL, there appears a problem that some names in the form of URI, which contains punctuation marks (such as "," or "(")…
Frown
  • 259
  • 1
  • 12
2
votes
3 answers

How to add dot '.' in the name of individuals in Sparql?

Is it possible to have a . (dot) in the qname of individuals or RDF resources in general? Something like this? SELECT ?tableName ?fieldName WHERE { ?fieldName hrdata:relatedField hrdata:ps_ti0002.EMPLID. } The dot in ps_ti0002.EMPLID is…
MJBZA
  • 4,796
  • 8
  • 48
  • 97
1 2 3
99
100