Visualizing the Consulting Taxonomy To Ontology - mdebellis/SemanticKG-Design GitHub Wiki

🧠 Visualizing the Consulting Ontology Taxonomy with the Proper Semantic Relations

This exercise is for the end of chapter 12, after we've converted the initial consulting taxonomy into an ontology.

➤ Step 1: Load the consulting ontology

If you've been following along you should be able to load the ontology that you created by the end of the chapter. If you want to load the "school solution" start by loading this ontology into AllegroGraph (or some other tool that can draw tree graphs): Consulting Ontology. After you load the ontology into AllegroGraph then start Gruff on that ontology.

➤ Step 2: Run the Materializer

You'll need to run the reasoner to get the appropriate semantic relations. After you log the ontology, go to Repository Control> Manage Reasoner Select Manage Reasoner. Accept the defaults and then hit the Apply button. You should see a message similar to the one below that says 971 Triples Generated.

➤ Step 3: Run the SPARQL Query to view the Tree with Semantic Relations in Gruff

While still focused on the Consulting_Ontology, select the Gruff icon from the pallete on the left. This opens the area where SPARQL queries can be written and executed. Paste the following query into the Gruff Query view. This query is also at the bottom of the file: Chapter 12 Taxonomy Transformations.

PREFIX :     <https://michaeldebellis.com/consulting_taxonomy/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>
PREFIX sulo: <https://w3id.org/sulo/>
SELECT DISTINCT ?subject ?predicate ?object
WHERE {
  {
    # Consulting Firm -> top-level concepts
    {
      BIND(:Consulting_Firm AS ?subject)
      BIND(skos:narrower AS ?predicate)
    }
    UNION
    # Deliverable subclasses -> Deliverable
    {
      BIND(:Deliverable AS ?object)
      BIND(rdfs:subClassOf AS ?predicate)
    }
    UNION
    # Client instances -> Client
    {
      BIND(:Client AS ?object)
      BIND(rdf:type AS ?predicate)
    }
    UNION
    # Engagement instances -> Engagement
    {
      BIND(:Engagement AS ?object)
      BIND(rdf:type AS ?predicate)
    }
    UNION
    # Offering subclasses -> Offering
    {
      BIND(:Offering AS ?object)
      BIND(rdfs:subClassOf AS ?predicate)
    }
    UNION
    # Industry instances -> Industry
    {
      BIND(:Industry AS ?object)
      BIND(rdf:type AS ?predicate)
    }
    UNION
    # Service Line subclasses -> Service Line
    {
      BIND(:Service_Line AS ?object)
      BIND(rdfs:subClassOf AS ?predicate)
    }
    UNION
    # Team subclasses -> Team
    {
      BIND(:Team AS ?object)
      BIND(rdfs:subClassOf AS ?predicate)
    }
    UNION
    # Individual engagements -> their direct parts
    {
      ?subject rdf:type :Engagement .
      BIND(sulo:hasDirectPart AS ?predicate)
    }
  }

  # Retrieve the triples selected by the bindings above
  ?subject ?predicate ?object .
  # Keep both endpoints in the consulting taxonomy namespace
  FILTER(
  IF(
    isIRI(?subject) && isIRI(?object),
    ?subject != owl:Nothing &&
    ?object != owl:Nothing &&
    STRSTARTS(STR(?subject), STR(:)) &&
    STRSTARTS(STR(?object), STR(:)),
    false
  )
)
}
ORDER BY ?predicate ?subject ?object

➤ Step 4: Use Tree Layout

After you paste this query do Run Query in Gruff and then Create Visual Graph. The initial graph will be a bit of a mess. You should see the Consulting_Firm Concept in the center of the graph. Select that node as shown in the following figure:

With the Consulting_Firm node selected do Layout>Draw Tree Layout From Selected Node. After you do this, your graph should look much more readable:

If your graph is still a bit hard to visualize, you might want to change some of the default values such as making the font for node labels smaller. You can find options to do that in this exercise: Tips for Changing Visualization in Gruff

🧩 Why this matters:
We can now visualize how the initial taxonomy that was defined only with skos:narrower edges now has the same hierarchical structure, but the edges have more semantics than simply skos:narrower such as subclasses, types, and subparts.