P2: Writing MetaModel Constraints in Prolog

In this assignment, you will write metamodel constraints in Prolog.  You will need to install some software and read a bit about Prolog to become familar with it.  We will be using SWI_Prolog.


1 Read and Learn about Prolog

So you should brush-up on your knowledge of Prolog. Listed below are some tutorials that you can consult, in order of my preference (ie read top first). Hint: your constraints and transformation rules are too complicated if you need to use Prolog lists.  You might need recursion, but I doubt it.

  1. http://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpages/
  2. http://www.learnprolognow.org/lpnpage.php?pageid=online
  3. http://kti.mff.cuni.cz/~bartak/prolog/contents.html

2 Install SWI_Prolog Software

SWI_Prolog is windows-based tool that provides a veryt good Prolog environment.  It should be already installed in on the CS MicroLab machines.  You'll need to put it on your own Windoze box for this and the next assignment.  Here's the link.

3 Install CatLite Software

CatLite is a set of experimental tools for writing MDE applications using Prolog.  You will need to install CatLite, which includes a set of Jar files, batch files, and the Violet UML editor.  Follow the installation instructions of CatLite.  Here's the link.

Metamodel Constraints

Violet is a Java-based tool that allows you to draw a number of different UML diagrams, including class diagrams, state diagrams, and so on.  Violet, like many other tools, is not very smart.  Look at the figure below.  Violet allows you to customize relationships between pairs of classes by drawing lines between boxes.  At which point, you can say 'put a diamond at this end of the line', 'put an inheritance arrow at this other end', and so on, yielding a diagram that is UML-like, but nonsensical.  The figure below has several errors:  (1) inheritance links never have diamonds at the subclass end, (2) inheritance links don't have labels, and (3) inheritance links between classes are not dashed and are always solid.

Violet allows you to draw any nonsensical set of beautiful boxes and links, and to output them as an XML documents with a .violet extension.  If you click on the figure above, you will see the XML file that is produced.  You will also see that Violet is not very good at defining methods and variables -- it only provides a big fat text string in which you can scribble anything.  If you click on the figure below, you will see the Prolog tables that describe the above figure.  Note that the prolog statement ":-dynamic T/C." means table T with C columns is empty (i.e. has no rows).

In the first part of this assignment, you will write Prolog rules to check a Prolog database (multiple Prolog tables) that are derived from .violet files. Fortunately, a violet-to-Prolog-database translator has been written for you.  It is available in the CatLite tool, and can be invoked by:

> java CatLite.classVioletParser.Main X.class.violet X.vpl.pl

where X is the name that you gave to the violet file (its full name is X.class.violet).  The naming scheme is important to CatLite: "X.vpl.pl" -- X is as before, vpl is the name of the file (libpl/vpl.schema.pl) that defines the schema of the database produced and "pl" simply designates a Prolog file.  To test conformance, you invoke (see CatLite documentation):

> cd P2                              /* Catalina MDE application directory given below */
> java CatCore.Main X.vpl.pl conform

which will evaluate the database constraints in libpl/vpl.conform.pl against the X.vpl.pl database.  Now, of course, your task in this assignment is to write the constraint file libpl/vpl.conform.pl -- what I have provided is just a dummy file that you have to fill out.

So again, your task is to (a) translate a .class.violet file to a Prolog database using the provided tool and (b) you will write a set of Prolog rules to check whether the .violet diagram conforms to sensible UML metamodel constraints.

Before continuing, you should understand the set of prolog tables that are generated.  The vpl schema consists of 4 tables, namely violetClass, violetInterface, violetAssociation, violetMiddleLabels.

Let's look at a table definition.  An example -- not from the violet database -- is show below:


This defines the prolog table "myTable" with the following column names -- id, A, B, C.  Columns id and C contain prolog atoms (unquoted names or numbers), and columns A and B will contain single-quoted strings.  A few tuples (rows) of this table can be:

myTable(c1,'don','imus', 44).

Now, here are the schema declarations for the tables in the Violet database:

violetClass is the name of a table with 6 columns.
id is the internal identifier of a class.
x,y are the coordinate positions at which this class is displayed.
name, fields, methods are single-quoted strings which contain the name of the class,
the string of fields and methods for that class. 
violetInterface is the name of a table with 5 columns.
id is the internal identifier of a class.
x,y are the coordinate positions at which this class is displayed.
name, fields, methods are single-quoted strings which contain the name of the class,
the string of fields and methods for that class. 
violetAssociation is a table with 10 columns.
id is the internal identifier of an association.
cid1, cid2 are identifiers of classes or interfaces to be connected.
type1, type2 are enums with values classnode or interfacenode to type cid1 and cid2
role1, role2 -- is any text e.g., name and/or cardinality to be displayed
arrow1, arrow2 -- only legal values {NONE,TRIANGLE,V,DIAMOND,BLACK_DIAMOND}, where NONE is ''
linestyle -- only legal values {SOLID,DOTTED}
this is a strange duck. The translation of violet to prolog assumes that all middle labels
of associations are empty. For each non-empty middle label, a tuple appears in this table,
along with the cids of the classes/interfaces that are connected. Basically this table should
never have rows.

You are to write metamodel constraints in Prolog that will evaluate the correctness of .violet models of class diagrams.  There are all sorts of constraints that you could write on checking the validity of fields and methods. But because Violet simply mashes field and method declarations into a big fat text string, this makes it much harder to perform such checks.  So to keep things simple -- and you should thank me for this --  do not make these checks!  Limit yourself to checking only the validity of links (associations, extends links, and implements links), and the names on links and boxes.

Here is the 7z P2 Catalina MDE application you will use (which I referenced above). Unzip it and you'll
find a libpl (Prolog Library), and within libpl, the file vpl.conform.pl, which is the prolog file in which you are to place your rules for validating constraints and posting error messages.  I supply a dummy file so that you can get started -- of course, you should throw this rule out and replace it with your own rules.  Bottom line: your job is to add real prolog rules.

To invoke your the rules in your file, let XXX.violet be the Violet file that you want to examine.  Make the following call:

> cd P2
> java CatLite.classVioletParser.Main XXX.class.violet XXX.vpl.pl

> java CatCore.Main XXX.vpl.pl conform
The following 7z file contains a set of six Violet designs that you are to validate.  For each file, present the list of error messages (if any) that your tool produces.  I presume that you will test your work on other Violet designs.  You may include them (and their documentation) too.

What to Submit

All of the below in a zip file. The zip file must unzip into <yourName>/<YourFilesAndDirectories>.
  1. Your vpl.conform.pl file

  2. An easy to read english description of this file -- see point 4 below.  (You might combine 1&2 by adding comments in the vpl.conform.pl file or by placing your description in the PDF file -- see 4 below).

  3. For each example, the output of your conformance test.

  4. A PDF file (in the required format) that the Grader should read to provide any information that is not obvious.  The contents of the PDF file can be minimal.

You should expect other violet files, of the Grader's choosing, will be used to evaluate your rules/constraints.