Lab: SPARQL queries
Lab 6: SPARQL queries with Fuseki
The Fuseki tool. SPARQL queries and updates. Programming SPARQL queries and updates in Jena.
Read up on Fuseki1 here: https://jena.apache.org/documentation/serving_data/ . We are aware that Fuseki2 is out now, but we prefer to run Fuseki1 this semester because it seems to offer simpler support for SPARQL Update.
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)
- 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
- GraphStoreFactory (create)
- UpdateFactory (create)
- UpdateAction (exectute)
Tasks: Go to the folder to which you downloaded Jena. Go to the jena-fuseki1-1.3.1 or similar subfolder. Start the Fuseki server as follows:
./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). Check this resource if you have other trouble: https://jena.apache.org/documentation/serving_data/#getting-started-with-fuseki .
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. IMPORTANT TIP: You dataset is only stored in memory, and will disappear when Fuseki is stopped or crashes. So save all your INSERT DATA and other queries and updates in a file as you go along. (Also, you will include them in Java programs later :-))
Write a SPARQL SELECT or CONSTRUCT query to view all the triples in your graph.
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.
Honour task: What do the various parameters used to start fuseki-server mean? (Tip: https://jena.apache.org/documentation/serving_data/#running-a-fuseki-server)
Run Fuseki against your TDB database from lab 4. 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.