top of page
Writer's pictureMichael DeBellis

Making UUIDs Easier to Use With Prefixes

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.




Comments


bottom of page