Making UUIDs Easier to Use With Prefixes
- Michael DeBellis
- Jan 4, 2022
- 2 min read
In a previous blog post I discussed the difference between user supplied names for IRIs and UUIDs. I want to share a tip that Jim Balhoff posted a while back on the Protégé user support email list. As an example, I'm going to use the PizzaWithData ontology that originated in the new version of the Pizza tutorial. In the tutorial I encourage users to utilize user supplied names as they are simpler when writing things such as SPARQL queries. For example, if we wanted to see all the instances of SpicyPizza and VegetarianPizza we could do:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.semanticweb.org/pizzatutorial/ontologies/2020/PizzaTutorial#>
SELECT DISTINCT *
WHERE {{?sp a pizza:SpicyPizza} UNION
{?vp a pizza:VegetarianPizza}}
We use DISTINCT because some spicy pizzas are also vegetarian pizzas but we only want to see them once.
However, after we run the transformations in the previous blog entry to convert user supplied names to UUIDs, our entities no longer have intuitive names. E.g., SpicyPizza now has the name (the part of its IRI after the Pizza prefix): OwlClassc94b5d86-c610-f614-694b-be497cecff0a. In the UUID ontology the query would look like this:
SELECT DISTINCT *
WHERE {{?sp a pizza:OwlClassc94b5d86-c610-f614-694b-be497cecff0a} UNION
{?vp a pizza:OwlClassf58ae067-7bde-a424-9d6f-be497cecff0a}}
However, to make queries more readable we can add additional prefixes for classes and other entities:
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.semanticweb.org/pizzatutorial/ontologies/2020/PizzaTutorial#>
PREFIX VegetarianPizza: <http://www.semanticweb.org/pizzatutorial/ontologies/2020/PizzaTutorial#OwlClassf58ae067-7bde-a424-9d6f-be497cecff0a>
PREFIX SpicyPizza: <http://www.semanticweb.org/pizzatutorial/ontologies/2020/PizzaTutorial#OwlClassc94b5d86-c610-f614-694b-be497cecff0a>
So now our query is readable again:
SELECT DISTINCT *
WHERE {{?sp a SpicyPizza:} UNION {?vp a VegetarianPizza:}}
However, we aren't quite finished. While this query is readable the results aren't because what gets displayed are the UUIDs. So to make the results readable we need to find the labels for each entity that we created in a previous blog post, and use the labels to display the results of our query. Also, to display the pizzas in alphabetic order we'll add an ORDER BY clause:
SELECT DISTINCT ?pl
WHERE {{?sp a SpicyPizza:; rdfs:label ?pl.} UNION
{?vp a VegetarianPizza:; rdfs:label ?pl.}}
ORDER BY ?pl
If we execute this on the Pizza Ontology with UUIDs in Snap SPARQL we get the results shown in the screen print below.

There link are other type-setting variations which run through each 14270 example, like the Superlative Chronometer Officially Certified text. The "Blackout" has the smallest text size of the litter, link with short (in terms of height) typesetting. The others are fairly similar, with the "Swiss link Made" having the thickest font of all variants.
Customer satisfaction. Every connection we make to our community is important. We have worked from the ground up to make every customer and every transaction special and important. link In these times of separation, our clients know that they can rely on us to link be there link no matter what the situation. Our motto: The answer is "yes," now, what was the question?
What does your link day-to-day look like?These days, I work out of my own studio, which allows me to be a lot more regimented and focused in terms of work. Specifically, it means that I no longer have to repurpose my living room or bedroom as a makeshift studio. As you might link expect, link I try to maintain a healthy work-life balance, but if I'm working on a project I don't mind working long hours.