
| This site refers to version 0.5.x of the Reuseware Composition Framework. |
Contents |
This page contains information about the Reuseware application "Xcerptware". Xcerptware provides the language Xcerpt with additional reuse possibilities. More precisely, it provides Xcerpt programmers with the opportunity to develop, and design, programs using the 'module' concept.
Xcerpt is an XML query and transformation language. For an introduction into Xcerpt, please refer to Querying the Web Reconsidered: A Practical Introduction to Xcerpt. Xcerpt is a rule-based language and is closely related to other logic programming languages, such as Prolog, in that it is a declarative rule-based language. Xcerpt differs from other XML query languages, such as, e.g., XQuery, in clearly separating between query and construct parts of its rules.
Xcerpt rules come in two forms: goal rules, which make up the output of programs, and construct rules, which are used to construct intermediate results in a program. Goal rules look like this:
GOAL <construct term> FROM <query> END
And construct rules look like this:
CONSTRUCT <construct term> FROM <query> END
Rules without a FROM-part (query part) are called facts. An example of a one-rule Xcerpt program is shown below:
GOAL
result [ title [ var X ] ]
FROM
in { resource { "file:biblio.xml", "xml" },
books [
book [
author [ var Y ],
title [ var X ]
]
]
}
END
The above program queries the XML file biblio.xml. The data structure of the file is assumed to consists of a root node labeled 'books', containing, possibly, several 'book' labeled nodes. Each book node in turn contains an author and a title entry. The result of the program is a list of all the book titles in the XML file, structured as indicated in the construct term of the rule.
Modules enable the separation and encapsulation of reusable functionality, such that several different applications can integrate and take advantage of such entities in an easy way. Xcerpt modules are very similar to modules as used in other logic programming systems, such as XSB etc.
Module programmers already familiar with Xcerpt have very little to learn before being able to define reusable modules. An Xcerpt module is simply a set of Xcerpt rules that provides the intended functionality. The rules of a module are grouped together using the following construct:
MODULE [name] <module imports*> <rules+>
As can be noticed, a module can in its turn import other modules. An example of a simple module is given below:
MODULE moduleB CONSTRUCT public bookTitleFromB [ "White Mughals" ] END CONSTRUCT bookTitleFromB [ "Stanley" ] END
The module is given the name moduleB and defines two rules. The two rules here are facts, and define two titles. As can be seen, in the first rule, the constructed data is proceeded by the public keyword. This keyword is used to specify that the data constructed by this rule may be accessed by programs or modules importing this module. The second rule is not specified with the public keyword, and hence, the data it constructs should not be accessible from the outside.
In order to import and reuse modules, the import-construct is used:
IMPORT [module] AS [prefix]
There is a prefix associated with the module so as to make it easier to refer to the module later. The following shows a program importing the above-defined module, assumed to be located at /moduleB.mxcerpt.
IMPORT /moduleB.mxcerpt AS mB GOAL finalResult [ all var Data ] FROM in mB ( bookTitleFromB [ var Data ] ) END
In addition to importing a module, the program makes use of the in-module construct to access data provided by the importing module.
in [module prefix] ( <query> )
The execution of the above program results in the output:
finalResult [ "White Mughals" ]
Changing the used module to the following:
MODULE moduleB CONSTRUCT public bookTitleFromB [ "White Mughals" ] END CONSTRUCT public bookTitleFromB [ "Stanley" ] END
causes the output of the program to instead be:
finalResult [ "White Mughals", "Stanley" ]
Obviously, removing both the public keywords in the module makes the output empty.
This has been a short introduction to the basic concepts of the Xcerpt module system.
The following shows a screenshot of the Modular Xcerpt environment running in Eclipse. To the left the available Xcerpt modules are shown (under folder components), together with Modular Xcerpt programs that import and make use of the modules (under folder compositionPrograms). As can be seen, syntax highlighting is for example supported.