Installing and Configuring Protégé Desktop to Run SPARQL Queries
As of the time I’m writing this, I am halfway through my second year of studies. One of the modules I did for the first semester was Internet Systems (INS). One of the later weeks of the module covered ontologies (RDF, turtle files, et cetera) and the querying of them using the SPARQL Protocol and RDF Query Language. The hands-on on video the lecturer made for querying ontologies did not go over how he set up the software to run queries, which left me perplexed when I tried opening Protégé Desktop and saw barely anything that resembled his setup.
So I did all of this to set up Protégé on my computer to analyse and query some ontologies. As for the typing (well, copy-pasting) of these ontologies into .ttl files: I do that on VSCode.
I made this tutorial for a fellow student (and a friend of mine) who had some trouble with a few quiz questions in the INS module regarding ontologies. I also sent it to a few other students and pretty much all of them found it helpful. In this tutorial, which is pretty much the first tutorial I’ve ever posted online, I will go over installing Protégé Desktop on your machine, opening an ontology file on Protégé and setting up Protégé to effectively run SPARQL queries on a currently open ontology.
I have no idea whether I’m going to work with ontologies in the future, and I’m entirely not sure what use this article will serve to anyone reading it, but I do hope it helps at least someone out here!
Installing the software
- Go to the Protégé website and download Protégé Desktop for your OS. When it asks you to register, click “No thanks, I’m already registered” at the bottom. Save the resulting compressed file and extract its contents to a location of your choice.
- Run the executable and/or shell script (depending on your OS).
- If you’re on Windows or Linux, it should be in the root of the extracted folder (NOT in bin/ as that’s where the program’s JAR files are).
- If you’re on Mac OS, the contents of the program should be in a Protégé.app folder that you can just run once you’ve extracted it (but I’ve barely ever used MacOS so I might have it wrong, and if I do please tell me somehow so I can correct this).
- If a plugin dialog pops up once you open Protégé, you’ll have to scroll down the list of plugins and look for
Snap SPARQL Query Plugin
(or words to that effect, I can’t entirely remember from the top of my head). Click the checkbox for it, then click install.- If you closed this dialog, don’t worry. You can do this later by clicking
File -> Check for Plugins
, but make sure you do this before trying to set up the SPARQL Query tab and view.
- If you closed this dialog, don’t worry. You can do this later by clicking
Opening Ontology Files
You can open an ontology in one of the following ways:
- Open an ontology file in your system (e.g.
.ttl
,.owl
etc) by clickingFile -> Open
and selecting a file to open. - Open an ontology file on the web by copying its URL, then going to Protégé and clicking
File -> Open by URL
and pasting the copied URL into theURI
text box. ClickOK
to open it.- If it asks you if you want to open the ontology in the current window, click
Yes
(unless you have a very good reason not to).
- If it asks you if you want to open the ontology in the current window, click
- If you have opened an ontology through Protégé recently, click
File -> Open Recent
and look for your file on the menu. You should be able to open it through there.
Configuring Protégé to Run SPARQL Queries
This next step assumes you’ve already installed the SNAP SPARQL Query Plugin. If you haven’t already, I’ve told you how to do so here.
Assuming you also have Protégé open with an ontology at this time:
- Go to
Window -> Tabs -> SPARQL Query
and, if it isn’t enabled already, enable that. Another tab in the editor should appear, aptly namedSPARQL Query
. A black checkmark should appear next to it. - Click the tab to open it. It should look plain and there should be no syntax highlighting, and the purple header for the query view should read
SPARQL Query
. - Remove that view by clicking the tiny rightmost box, marked with an X. If you hover over it, it should read
Close
. - Now, stay in the
SPARQL Query
tab (there should be nothing useful on there) and go toWindow -> Views -> Query views -> Snap SPARQL Query
(NOTSPARQL Query
) and enable that. A black check should show up just like before. - There should be a black dot at the tip of your mouse cursor. Make sure it hovers over the empty view (if it does, a blue border will show up). Click the empty view. The
Snap SPARQL Query
view should now cover what was previously empty, and the text box for the query should now have syntax highlighting. The tab, however, should still be calledSPARQL Query
. - ⚠️⚠️ IMPORTANT ⚠️⚠️ Before you start querying, you must start your reasoner.
- Go to
Reasoner
and look at the bottom of the dropdown. If the currently selected option for the reasoner isNone
, make sure it’s atHermiT
instead (it should be built-in to newer versions of Protégé). - Once you’ve got
HermiT
as your selected reasoner, clickStart reasoner
(it’s in theReasoner
menu, or you can just doCtrl + R
to start, but not stop, the reasoner).- The reasoner should now be running in the background, and you should now be able to query the currently open ontology by typing in your query and then clicking
Execute
. The results of your query should show up at the bottom half of the view as a table, which you can resize to your liking. - If ever you need to stop the reasoner running in the background, there’s a
Stop reasoner
option in theReasoner
menu.
- The reasoner should now be running in the background, and you should now be able to query the currently open ontology by typing in your query and then clicking
- Go to
When you reopen Protégé, the views and tabs will be configured as it was through this tutorial. The only thing you need to do every time you open Protégé is make sure the reasoner is turned on before you start querying, which you should know how to do by this point. HermiT
should already be selected as the reasoner, you just need to start it.
And that’s it!
Well, would you believe it? My first tutorial on the web and it isn’t an hour-long YouTube video! Maybe I might do that some time. For now, though, I’m just glad to have updated this blog for the first time since the end of August last year!
Speaking of years, it’s also my first blog post for 2022 too! Happy new year, I guess! Even if I am nearly 2 weeks late as I’m typing this post…