A Brief Introduction to Grok

By Vassilios Tzerpos - Last updated November 2, 1997

Grok is a tool that can help you manipulate facts, such as those generated using cfx and fbgen, i.e., tuples of the form:

        relation source target
For example, this tuple means that procedure P calls procedure Q:
        call P Q
This form of tuple is called RSF (for Rigi Standard Form).

Grok can be used to do these three things for you:

  1. Read facts and sets
  2. Create new facts and sets
  3. Write fact bases and sets

Reading Facts and Sets

The following commands help you give input to grok:

Creating New Facts and Sets of Entities

Once you have read all your data into the grok in-memory database you can apply various operations to your relations and sets. These include addition and subtraction of relations, union and intersection of sets, etc.

The following example shows a common use of the relational composition command. We assume that the file contain.rsf lists information about which file contain which procedure and call.rsf contains info on which procedure calls which procedure. Here is a grok script that induces the call relation at the file level.

getdb contain.rsf            % Read the containment information
adddb call.rsf               % Read the call information
invcontain = inv contain     % Create a new relation called invcontain
                             % which is the inverse of the contain relation
tmp = contain * call         % Create a temporary relation called tmp
                             % which will be the composition of the
                             % relations contain and call
                             % Only composition of two relations is 
                             % supported at this point, that's why we 
                             % need the temporary relation
filecall = tmp * invcontain  % The relation filecall is now the composition
                             % of tmp and invcontain, so effectively it is
                             % the composiiton of contain, call and invcontain.
putrel filecall filecall.rsf % The file filecall.rsf will now contain the
                             % facts for relation filecall.

Writing Fact Bases and Sets

The following commands can be used to create output from grok:

Other Facilities Provided by Grok

Grok provides a fairly rich set of operations. If you have a working version of grok, you can get fa full list of these, by reading grok's help file, which you can get by typing ? at the grok prompt. For more background on these operations with their use in software architecture and the theory behind them, you may want to read the paper Binary Relational Algebra Applied to Software Architecture.