1-- @path Library=/Library/Library.ecore
2-- @path Catalog=/Catalog/Catalog.ecore
3
4module LibraryTransform;
5create OUT: Catalog from IN: Library;
6
7-- Attribute helper: determines if a book is a classic
8helper context Library!Book def: isClassic(): Boolean =
9 self.yearPublished < 1950;
10
11-- Attribute helper: gets formatted publication information
12helper context Library!Book def: publicationInfo(): String =
13 thisModule.formatYear(self.yearPublished) + ' by ' + self.author.name;
14
15-- Query helper: formats a year with century suffix
16helper def: formatYear(year : Integer) : String =
17 if year < 1900 then
18 year.toString() + ' (19th century)'
19 else
20 if year < 2000 then
21 year.toString() + ' (20th century)'
22 else
23 year.toString() + ' (21st century)'
24 endif
25 endif;
26
27-- Rule 1: Classic books with detailed information
28rule ClassicBook {
29 from
30 s: Library!Book (s.isClassic())
31 to
32 t: Catalog!Item (
33 title <- s.title,
34 category <- 'Classic',
35 description <- 'Published ' + s.publicationInfo()
36 )
37}
38
39-- Rule 2: Modern books with standard information
40rule ModernBook {
41 from
42 s: Library!Book (not s.isClassic())
43 to
44 t: Catalog!Item (
45 title <- s.title,
46 category <- 'Modern',
47 description <- 'Published ' + s.publicationInfo()
48 )
49}