IO Dlgp module

Download this module

This module provides a Parser and a Writer for the Dlgp format. This format is the main format supported by Graal, however you can use Graal without the slightest bit of Dlgp.

DlgpParser

The DlgpParser provides two different ways of producing Graal objects. The first one is to create a new instance from a File or a String, then iterate over generated objects as follows:


    DlgpParser parser = new DlgpParser("human(socrate). mortal(X) :- human(X). ?(X) :- mortal(X).");
    while (parser.hasNext()) {
        Object o = dlgpParser.next();
        if (o instanceof Atom) {
            System.out.println("Atom: " + ((Atom)o));
        } else if (o instanceof Rule) {
            System.out.println("Rule: " + ((Rule)o));
        } else if (o instanceof ConjunctiveQuery) {
            System.out.println("ConjunctiveQuery: " + ((Query)o));
        }
    }
    parser.close();
  

Note that a DlgpParser can also produce a Directive or a Prefix, see JavaDoc or Dlgp documentation for more details.

The second way of producing Graal objects is to use one of the following static methods:

DlgpWriter

The DlgpWriter is easy to use, just construct an instance with the File, Writer, OutputStream or file path to write. Then call the write method on the objects to write. Note that if there is no specific handling for the class of the specified object, the DlgpWriter will write the result of the toString method.