Tips For Using Gruff With AllegroGraph - mdebellis/SemanticKG-Design GitHub Wiki
🧠 Some Tips for Using Gruff and SPARQL to Visualize Semantic Knowledge Graphs
Gruff is an incredibly powerful tool. I've been using it for years and I can still be surprised by some of the features that I wasn't aware of. The power can be somewhat intimidating. There are so many options it can be difficult to know where to start. This exercise will use the People Ontology to demonstrate some of the basic Gruff features that I use all the time.
➤ Step 1: Start AllegroGraph, Load the People Ontology, and run the reasoner
For help on how to get access to the various free versions of AllegroGraph see:
Getting Access to the Community Version of AllegroGraph
For help loading the People Ontology into AllegroGraph see:
Loading the People Ontology into AllegroGraph
Next, you want to run the reasoner. Surprisingly, you may not always want to run the reasoner before using Gruff. There can be certain use cases where it is easy to view certain paths without the additional triples created by the reasoner. But usually you do want to run it.
- Make sure you are focused on the People Ontology. You should be since you just loaded it but to be sure
expand the Root folder at the top of the options on the left. You should see 3 options when you do that: root, fedshard, and system. Click on root. Note: this is the root in the Root folder, not the Root folder. You should see something similar to the figure below, a list of all your repositories.Click on the people repository to select it
- Next
click on Repository control in the left control panel - Your user name will probably appear in the Search field.
Remove that and type "Manage Rea"you will see as you type that the possible menu options pop up and decrease with every letter you type. The only one visible after you type "Manage Rea" will be Manage Repository. Your UI should look similar to this:
Click on Manage Reasoning- That should take you to a page titled Manage Reasoning.
- There should be two large buttons around the middle of the page. A blue button that says Applyand a red one to its right labelled Delete
Click the Apply button.- You should see a green box pop up that says something like: Success Generated 3004 triples!.
- Now you want to move to Gruff. Look at the options in the left control panel. Near the bottom there should be an option for Gruff and the Gruff icon.
Click on the Gruff menu item
➤ Step 2: Do a SPARQL Query and View the Results
That should take you to Gruff. There are several different Gruff views you can control from the View menu. If you click on the View menu, the options at the top are all the possible Views. The one with a check next to it is where you currently are. You should see something like this which shows you that you are currently in the Graph view. You want to be in the Query View. That's the View where you can execute a SPARQL query.
- Use the View menu to change to the Query View.
- You should be in the Query View. The Query View concists of two main pains. The white area at the top that is where you edit or paste your query. The blue area below it is where any matching data is displayed.
- Gruff starts with a very basic query that will display 100 random triples. Remove that
- Copy the following prefixes and query into the pane that had the starting query.
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX : <https://michaeldebellis.com/people/>
SELECT DISTINCT *
WHERE {:Albert_Einstein :has_social_relationship ?o}
✅ Click Run Query (the large button above the query box).
📄 This lists all of Einstein's social relations and should look similar to this:
- Since all the graphed triples point from Einstein we could make the graph a bit more structured by doing a Tree layout from Einstein.
Left click on Einstein's node in the graph to select it.Select: Layout>Do tree layout from selected node.- Now the graph has Einstein as the root of a tree graph. Here's what it looks like on my PC:
➤ Step 3: Use Menu Options to change the way Gruff Displays Graphs
- It's possible that your graph has Einstein at the top rather than at the left as mine does. It depends on the Orient tree layout setting of graph layout options. Mine is currently set to display trees horizontally, from left to right. There are many ways to control how Gruff displays graphs. Sometimes (e.g., if you have many different edges in the graph) you want to see the label for each edge in the graph. Other times (you have just a few edges and your graph makes a nice tree, e.g. rdfs:subClassOf and rdf:type) the node labels get in the way and the information can best be visualized by color coding the edges. Also, for some types of documents the publisher may want graphics that aren't dependent on color. This exercise shows you some of the ways you can control these options in Gruff.
- To start, if you want Tree Layout to go the other way, select:
Visual Graph Options> Tree layout options> Orient tree layouts vertically
- After changing that value, if you select Einstein again and use him as the root for a tree graph it now looks like this:
- Let's expand the graph a bit. Von Neuman knew a lot of people and was associated with many major scientific, mathematic, and engineering achievements in the early 20th century, from inventing Game Theory, to the computer, to the atomic bomb and many more. Of course, this is just a demo graph so most of his achievements aren't in the graph yet. We can see all the objects that currently point to him (i.e., triples where he's the object) as follows:
Right click on Von Neumann and select Display Linked Nodes from menu.- The next menu that comes up gives us two options: 1) As subject 2) As object. It's asking if we want triples where Von Neuman is the subject or the object. Let's
select as object. - This menu shows us all the properties that have Von Neumann as an Object.
Select is_employee_of.
- That displays the two emplooyers for Von Neumann: IBM and the Institute for Advanced Study.
- In the current graph we are distinguishing between instances of Employee and instances of Person. Employee is a defined class. Any Person who has a value for has_employer is an Employee. In fact most of the people in the graph have employers, however since this is only an ontology meant for learning it is very incomplete. Suppose that we don't want to show the difference between instances of Employee and instances of Person. We can do that by:
- Selecting one of the instances (Einstein or Von Neumann) who are instances of Employee with a right click.
Right click on Von Neumann. You should see the options below,click on Select Preferred Type for Node Colors.
- That will give you a list of all the classes that Von Neumann is an instance of
Select Person:
💡 Tip: Those anon nodes are Anonymous Classes created by OWL axioms.
- Now your graph should like like this:
- Suppose you want to increase the font size for the node labels.
Select Visual Graph Options>Node Labels>Node Label Font. That allows you to increase or decrease the font side for your labels. - Other useful visualization options include:
Visual Graph Options > Link Labels > Draw Link Labels. That will add link labels to all the edges in the graph. - If you are constrained to just use black and white, you can use link labels and change the color of the edges to be black.
- In the pallete on the left,
Right click on has_social_relationship.
-
Select Set Line Color. -
That will bring up a menu with the current color. Since it is Blue in my environment (it may be different in yours) the Red-Green-Blue values are 0-0-255. To make the edge black change it to 0-0-0.
- Make the same change to
is_employer_of. Right now this isn't very helpful since we can't distinguish the two types of edges. However, (this is for use cases where we are constrained to black and white) we can still differentiate the edges by using dots and dashes. Right click on is_employer_of. Thenselect Set line dashing. Choosedot. Your graph should now look like this:
- These are just some of the possible options with Gruff. There are many more you can find to change the appearance and the contents of your graph.