Lab: SPARQL queries

From Info216
Jump to: navigation, search

Lab 3: SPARQL queries

Topics

The Fuseki tool. SPARQL queries and updates. Programming SPARQL queries and updates in Jena.

Preparations

Read up on Fuseki 2 here: https://jena.apache.org/documentation/fuseki2/ .

Classes/interfaces

SPARQL queries and updates are part of ARQ, whose JavaDoc is separate from the rest of Jena: https://jena.apache.org/documentation/javadoc/arq/ .

  • QueryFactory (create)
  • Query
  • QueryExecutionFactory (create)
  • QueryExecution (execSelect, execConstruct, execAsk, execDescribe)
  • ResultSet (hasNext, nextSolution) - this contains the table that results from SPARQL SELECT
  • QuerySolution (get, getResource, getLiteral) - this contains a row in that table
  • GraphStore
  • GraphStoreFactory (create)
  • UpdateFactory (create)
  • UpdateRequest
  • UpdateAction (exectute)

Tasks

Go to the folder to which you downloaded Jena. Go to the apache-jena-fuseki1-2.4.1 or similar subfolder. Start the Fuseki server as follows:

 ./fuseki-server --mem --update --localhost /mydataset

On Linux you need:

sh ./fuseki-server --mem --update --localhost /mydataset

NOTES:

  • The most recent versions of Fuseki needs Java 8, so make sure you have that installed (or you get an "Unsupported major.minor version" error).
  • Save all your INSERT DATA and other queries and updates in a file as you go along. (You will include them in Java programs later...)
  • If you use the --mem option, your dataset will only be stored in memory, and will disappear when Fuseki is stopped or crashes. Alternatively, you can create a TDB triple store using Jena and load it with the --loc option we used earlier.

Open a web browser and goto http://localhost:3030 . You are now in contact with the Fuseki server you just started. Go to the control panel and choose the dataset /mydataset . You can now run SPARQL queries and updates and load RDF graphs from file into your SPARQL engine.

Use SPARQL Update's INSERT DATA operation to add triples to the default graph of /mydataset. You can use triples from the graphs you made in labs 2 and 3.

Write a SPARQL SELECT query to view all the triples in your graph. Write a CONSTRUCT query to do the same.

Use SPARQL Update's DELETE DATA to delete a triple. Run your SPARQL query again to check that the graph has changed.

Use INSERT DATA to add information about Sergio Pastor, who lives in 4 Carrer del Serpis, 46021 Valencia, Spain. he has a M.Sc. in computer from the University of Valencia from 2008. His areas of expertise include big data, semantic technologies and machine learning.

Write a SPARQL DELETE/INSERT update to change the name of "University of Valencia" to "Universidad de Valencia" whereever it occurs.

Write a SPARQL DESCRIBE query to get basic information about the University of Valencia.

Redo all the above steps, this time writing a Java/Jena program.

If you have more time

What do the various parameters used to start fuseki-server mean?

Run Fuseki against your TDB database from earlier labs. Update the database. Terminate the server. Start it again, reload http://localhost:3030, and check that the changes were persistent. Alternatively, check by running your program to read the TDB database.

If you want more RDF data to play with, you can have a look at these files:

http://people.uib.no/sinoa/european-populations.ttl
http://people.uib.no/sinoa/polvarer.ttl
http://people.uib.no/sinoa/mini-polvarer.ttl