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:
- Read facts and sets
- Create new facts and sets
- Write fact bases and sets
Reading Facts and Sets
The following commands help you give input to grok:
-
getdb F : This command clears grok's in-memory database and reads facts from file
F. For example, getdb facts.rsf will erase any facts in the
database and read new facts from a file called facts.rsf .
-
adddb F : Same as getdb but the facts are now added to the existing
database.
-
getset s [F [D]] : This command reads the elements of set s from
file F in directory D. If D is missing, then the current directory is
assumed, and if F is missing it is assumed to have the same name as s. The
format of file F must be: Each element in a separate line. For example,
getset procs procs.set
reads a set from file procs.set
and creates an in-memory set called procs.
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:
-
putdb F : This command will output the whole database to file F.
-
putset s [F [D]] : This command will output set s to file F in directory
D. If D is omitted, then the current directory is assumed, and if F is
omitted the file is assumed to have the same name as s.
-
putrel R [F [D]] : This command will output relation R to file F in directory
D. If D is omitted, then the current directory is assumed, and if F is
omitted it is assumed to have the same name as s.
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.