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

Different result in DBPedia using WebClient and browser

I want to extract some information which exists in DBPedia. So, I've written an application using .NET's System.Net.WebClient which gets urls and returns the content of url in N-Triples format (plain text). The result of extracted data for the url…
Amir Pournasserian
  • 1,498
  • 4
  • 21
  • 41
2
votes
1 answer

How to make a sparql query with unicode letters?

I am querying the french dbpedia (http://fr.dbpedia.org/) with SPARQL. I am using Python and SPARQLWrapper if it makes any difference. This 1st query is working Ok. PREFIX dbpp: PREFIX…
luc
  • 37,543
  • 21
  • 117
  • 168
2
votes
2 answers

UNION operator in SPARQL updates

I have two SPARQL updates.First one: INSERT { GRAPH <[http://example/bookStore2]> { ?book ?p ?v } } WHERE { GRAPH <[http://example/bookStore]> { ?book dc:date ?date . FILTER ( ?date > "1970-01-01T00:00:00-02:00"^^xsd:dateTime ) ?book…
Cheryl
  • 245
  • 1
  • 11
2
votes
1 answer

STRAFTER SPARQL 1.1 function in Virtuoso

Does STRAFTER from SPARQL 1.1 work in Virtuoso (version 6.04 June 2012 build)? Trying PREFIX qb: PREFIX iodp: PREFIX sdmx-dimension: …
Douglas Fils
  • 283
  • 4
  • 12
2
votes
1 answer

How to convert a SPARQL query into an RDF file in Jena?

I am trying to output an RDF/XML file directly from an SPARQL query from an Oracle database. The query is working fine as I've verified the results in the ResultSet object. However, I'm not sure how to proceed from there. I think I want to create a…
C.Neal
  • 189
  • 1
  • 11
2
votes
1 answer

Limit a SPARQL query to one dataset

I'm working with the following SPARQL query, which is an example on the web-based end of my institution's SPARQL endpoint; SELECT ?building_number ?name ?occupants WHERE { ?site a org:Site ; rdfs:label "Highfield Campus" . ?building…
Matthew Higgins
  • 557
  • 1
  • 9
  • 22
2
votes
1 answer

How to add triples to a jena Query

Suppose I have some jena query object : String query = "SELECT * WHERE{ ?s ?o ...etc. }"; Query q = QueryFactory.create(query, Syntax.syntaxARQ); How would one go about getting information about the jena query object and adding in…
Nick Bartlett
  • 4,315
  • 1
  • 20
  • 37
2
votes
1 answer

SparQL - list cities

I'm trying to list all the cities in Denmark from Wikipedia/dbpedia by using SPARQL. I've tried a lot of things and I can't get it to work. This is what I have come up with: SELECT * WHERE { …
Sane
  • 574
  • 1
  • 6
  • 15
2
votes
1 answer

How to get the complete list of pages titles from wikipedia ?

I want to get this list to later work on it for linquistic researches. The API:Allpages is limited to 500 queries. I need them all (4millions). Maybe attack it using dbpedia. Any trick to do it ?
Hugolpz
  • 14,637
  • 24
  • 85
  • 173
2
votes
1 answer

Restrict SPARQL query to a certain kind of Class

I have a SPARQL query to select all resources that has the location "California" within the dbpedia database: select distinct ?subj where { ?subj dbpprop:location dbpedia:California . } LIMIT 100 Now my problem is to filter this results, so that I…
Tobias
  • 6,885
  • 8
  • 46
  • 74
2
votes
2 answers

About DBPedia Access

I am very new to DBPedia and I don't know how to and from where to start. I did some research on this and from that what I understand is we can access the data using SPARQL query language (Apache Jena). So I started to download the .ttl files for…
Amar
  • 725
  • 2
  • 12
  • 35
2
votes
1 answer

Jena Sparql output as .txt or .xls file

I'm wondering how to create a .txt or .xls file output from the result of Jena SPARQL query. Can anyone help? here some part of the code InputStream in = new FileInputStream(new File("./src/myfile.owl")); Model model =…
blackSweet
  • 131
  • 1
  • 11
2
votes
1 answer

Finding k nearest neighbors with SPARQL query

I would like to write a single SPARQL query to find the k nearest neighbors for a set of vectors. To find the average label for the 100 nearest neighbors for a single vector I can use the following query: PREFIX : PREFIX vector:…
2
votes
1 answer

Dbpedia query takes too much time (Ruby)

i'm building an integration system that makes a query to the prefixSearch Api of dbPedia http://lookup.dbpedia.org/api/search.asmx/PrefixSearch?QueryClass=&MaxHits=1&QueryString=KEYWORD From this i obtain an URI of a resource and get the resource…
dbonadiman
  • 267
  • 2
  • 7
2
votes
1 answer

Query RDF file using PHP and SPARQL. Help and suggestions?

What is the endpoint for Virtuoso?
1 2 3
99
100