• Aucun résultat trouvé

Movie Database Case: An EMF-IncQuery Solution

N/A
N/A
Protected

Academic year: 2022

Partager "Movie Database Case: An EMF-IncQuery Solution"

Copied!
13
0
0

Texte intégral

(1)

Submitted to:

TTC 2014

© G. Szárnyas et al.

This work is licensed under the Creative Commons Attribution License.

Gábor Szárnyas Oszkár Semeráth Benedek Izsó Csaba Debreceni Ábel Hegedüs Zoltán Ujhelyi Gábor Bergmann

Budapest University of Technology and Economics, Department of Measurement and Information Systems,

H-1117 Magyar tudósok krt. 2., Budapest, Hungary

{szarnyas, semerath, izso, debreceni, abel.hegedus, ujhelyiz, bergmann}@mit.bme.hu

This paper presents a solution for the Movie Database Case of the Transformation Tool Contest 2014, using EMF-I

NC

Q

UERY

and Xtend for implementing the model transformation.

1 Introduction

Automated model transformations are frequently integrated to modeling environments, requiring both high performance and a concise programming interface to support software engineers. The objective of the EMF-I NC Q UERY [2] framework is to provide a declarative way to define queries over EMF models.

EMF-I NC Q UERY extended the pattern language of VIATRA with new features (including transitive closure, role navigation, match count) and tailored it to EMF models [1].

EMF-I NC Q UERY is developed with a focus on incremental query evaluation. The latest develop- ments extend this concept by providing a preliminary rule execution engine to perform transformations.

As the engine is under heavy development, the design of a dedicated rule language (instead of using the API of the engine) is currently subject to future work. Conceptually, the environment relies on graph transformation (GT) rules: conditions are specified as EMF-I NC Q UERY patterns, while model manipu- lation and environment configuration is managed using the Xtend language [3].

One case study of the 2014 Transformation Tool Contest describes a movie database transforma- tion [4]. The main characteristics of the transformation related to the application of EMF-I NC Q UERY

are that i) it only adds new elements to the input model (i.e. couple and group are does not modify the input model), and ii) it is non-incremental (i.e. creating a new group will not affect rule applicability).

The rest of the paper is structured as follows: Section 2 gives an overview of the implementation, Section 3 describes the solution including measurement results, and Section 4 concludes our paper.

2 Architecture Overview

The overview of the rule-based solution is illustrated in Figure 1a. The input of the transformation is a movie model. The result is a transformed movie model including various groups (couples and n-cliques) and their average rating [4]. The transformation runs in a Java application, that uses pattern matchers provided by EMF-I NC Q UERY and model manipulation specified in Xtend. The pattern matcher monitors

This work was partially supported by the MONDO (EU ICT-611125) and TÁMOP (4.2.2.B-10/1–2010-0009) projects.

This research was realized in the frames of TÁMOP 4.2.4. A/1-11-1-2012-0001 „National Excellence Program – Elaborating

and operating an inland student and researcher personal support system”. The project was subsidized by the European Union

and co-financed by the European Social Fund.

(2)

Java application

« notifies »

« modifies » Movie model

Pattern matcher

Rule execution engine

Transformed movie model EMF

resources

« monitors » Rule condition

Rule consequence

(a) The specification and runtime

Person nameG:GEString

Actor Actress

Couple Movie

titleG:GEString ratingG:GEDouble yearG:GEInt typeG:GMovieType

<<enumeration>>

MovieType MOVIE TV VIDEO VIDEOGAME

Group avgRatingG:GEDouble EAttribute0

Clique

Root ContainedElement

movies 0..*

p1 0..1 p2 0..1 persons 0..*

commonMovies 0..*

persons 0..*

children 0..*

(b) Our extended metamodel

Figure 1: Overview of our approach

the resources to incrementally update match sets. The application initially reads the input movie database, creates the output resources, then executes the transformation, and finally serializes the results into files.

In the Ecore model of the specification, no containment hierarchy is used and all objects are held in the contents list of the EMF resource. However, the performance of the transformation was affected by the resource implementation used (since it will determine the implementation of the list operations). To avoid this issue, we have extended the metamodel by a Root object (see Figure 1b). This object serves as a container for all Group, Movie and Person objects. According to our experiments, this increases the speed of the pattern matching by a factor of two. For compatibility with the specification, we ensured that our solution works with the models provided and persists outputs in a format without this root element.

3 Solution

3.1 Patterns and Transformations

Task 1: Generating Test Data The synthetic test data is generated in Xtend (see Listing A.2.1). The code tightly follows the specification defined in the case description [4].

Task 2: Finding Couples Couples are listed with the following pattern:

1 p a t t e r n p e r s o n s T o C o u p l e ( p1name , p 2 n a m e ) { 2 f i n d c a s t ( p1name , M1 ) ; f i n d c a s t ( p2name , M1 ) ; 3 f i n d c a s t ( p1name , M2 ) ; f i n d c a s t ( p2name , M2 ) ; 4 f i n d c a s t ( p1name , M3 ) ; f i n d c a s t ( p2name , M3 ) ;

5 M1 != M2 ; M2 != M3 ; M1 != M3 ;

6 c h e c k( p 1 n a m e < p 2 n a m e ) ; 7 }

8 p a t t e r n c a s t ( name , M ) { M o v i e . p e r s o n s . n a m e ( M , n a m e ) ; } 9 p a t t e r n p e r s o n N a m e ( p , p N a m e ) { P e r s o n . n a m e ( p , p N a m e ) ; }

Note that the cast pattern returns the names of persons that play in a given movie. This is important

since the names of the persons can be used to avoid symmetric matches in the personsToCouple pattern

by sorting. The Couple objects are created and configured in Xtend (see createCouples in line 45 of

Listing A.2.2). This includes setting the p1 and p2 references using a personName pattern and computing

the commonMovies by simple set intersection operators (retainAll).

(3)

Task 3: Computing Average Rankings The average rankings are computed in Xtend by calculating the mean of the rating attributes of a couple’s common movies (see calculateAvgRatings in line 122 of Listing A.2.2). The movies are enumerated with the following pattern:

1 p a t t e r n c o m m o n M o v i e s O f C o u p l e ( c , m ) { C o u p l e . c o m m o n M o v i e s ( c , m ) ; }

Extension Task 1: Compute Top-15 Couples This task is mostly implemented in Xtend (see top- GroupByRating in line 70 and topGroupByCommonMovies in line 84 of Listing A.2.2), however, it uses the groupSize pattern in order to filter the groups with the particular number of members.

1 p a t t e r n g r o u p S i z e ( group , S ) { 2 G r o u p ( g r o u p ) ;

3 S == c o u n t f i n d m e m b e r O f G r o u p ( _ , g r o u p ) ; 4 }

This pattern uses the count find construct which computes the number of matches for a given pattern.

Additionally, specific comparators are used to sort and determine the top-15 lists by rating or number of common movies (see Listing A.2.4).

Extension Task 2: Finding Cliques The pattern for finding cliques is implemented similarly to the personsToCouple pattern 3.1. The pattern for 3-cliques is defined as follows:

1 p a t t e r n p e r s o n s T o 3 C l i q u e ( P1 , P2 , P3 ) {

2 f i n d c a s t ( P1 , M1 ) ; f i n d c a s t ( P2 , M1 ) ; f i n d c a s t ( P3 , M1 ) ; 3 f i n d c a s t ( P1 , M2 ) ; f i n d c a s t ( P2 , M2 ) ; f i n d c a s t ( P3 , M2 ) ; 4 f i n d c a s t ( P1 , M3 ) ; f i n d c a s t ( P2 , M3 ) ; f i n d c a s t ( P3 , M3 ) ;

5 M1 != M2 ; M2 != M3 ; M1 != M3 ;

6 c h e c k( P1 < P2 ) ; c h e c k( P2 < P3 ) ; 7 c h e c k( P1 < P3 ) ;

8 }

The creation of cliques is done similarly to couples (see createCliques in line 138 of Listing A.2.2).

However, this pattern has a redundant check constraint, as P

1

< P

2

and P

2

< P

3

already imply P

1

< P

3

. This works as a hint for the query engine and allows it to filter the permutation of the results (e.g.

(a

2

,a

1

, a

3

),(a

1

,a

3

,a

2

), . . .)) earlier.

For performance considerations, additional patterns were defined manually for 4- and 5-cliques. For larger cliques (n > 5), patterns could be automatically generated using code generation techniques.

General solution for n-cliques. We also provide the outline for a more general solution (for arbitrary n values). For the sake of clarity, we will refer to couples as 2-cliques. In this approach, the cliques are built iteratively. Suppose we already have all k-cliques in the graph (e.g. we already added the 2-, 3-, 4- and 5-cliques with the previous patterns). To get the (k + 1)-cliques, we look for a group g

0

and a person p

0

that (i) have at least 3 movies in common, (ii) g = g

0

∪ {p

0

} is a group that is not a subset of any other groups (see Figure 2).

Formally, (ii) can be expressed as (6 ∃g

0

) : g ⊆ g

0

. Using g = g

0

∪ {p

0

}, we derive the following expression (6 ∃g

0

) : (g

0

⊆ g

0

) ∧ (p

0

∈ g

0

). The g

0

⊆ g

0

expression can be formulated as follows: (∀p ∈ g

0

) : p ∈ g

0

. As the EMF-I NC Q UERY Pattern Language does not have a universal quantifier, we rewrite this using the existential quantifier: (6 ∃p ∈ g

0

) : p 6∈ g

0

.

The resulting expression for condition (ii) is the following: (6 ∃g

0

) : ((6 ∃p ∈ g

0

) : p 6∈ g

0

) ∧ (p

0

∈ g

0

).

We have implemented this general solution (see Listing A.2.3). Pattern subsetOfGroup implements

condition (ii), while nextClique pattern is capable of determining the (k + 1)-cliques given a model

(4)

m m m m m

p0

g0

g

Figure 2: Matching 3-clique groups in the positive test pattern. g

0

is a couple.

containing all k-cliques. This approach is functionally correct, however, it only works for very small input models and hence is omitted from our measurements.

Extension Task 3: The average rankings are computed the same way as in task 3.

Extension Task 4: The top 15 average rankings are computed the same way as in extension task 2.

3.2 Optimizations

To increase the performance of the transformations, we carried out some optimizations. (1) The com- mon movies of the two Person objects are computed from Xtend instead of EMF-I NC Q UERY . (2) The patterns for 3-, 4- and 5-cliques are implemented manually. (3) Common subpatterns were identified and extracted them into separate patterns, as the engine can reuse the pattern for each occurrence, and makes the query definition file easier to maintain. For an example, see the cast pattern in A.1.

3.3 Benchmark Results

The implementation was benchmarked in the SHARE cloud, on an Ubuntu 12.04 64-bit operating system running in a VirtualBox environment. The virtual machine used one core of an Intel Xeon E5-2650 CPU and had 6 GB of RAM. The transformations were ran in a timeout window of 10 minutes.

3.4 Synthetic model

Results are displayed in Figure 3. The diagram shows the transformation times for creating couples and cliques for synthetic models. The results show that the transformations run in near linear time.

The dominating factor of the running time is the initialization of the query engine. However, after initialization, creating groups can be carried out efficiently. Furthermore, our experiments showed that the limiting factor for our solution is the memory consumption of the incremental query engine. Given more memory, the solution is capable of transforming larger models as well.

3.5 IMDb model

In the given time range and memory constraints, the transformation of the IMDb model could only

generate the couples and 3-cliques for the smallest instance model. Finding the couples took 3 minutes,

(5)

0 10 20 30 40 50 60 70 80 90 100

0 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000

Time (s)

Size (N) Runtime of Transformation Tasks

Couples 3-Clique 4-Clique 5-Clique

Figure 3: Benchmark results

while finding 3-cliques took 6. However, in case of a live and evolving model, our solution is capable of incrementally running the transformation which in practice results in near instantaneous response time.

3.6 Transformation Correctness and Reproducibility

Our solution was developed as Eclipse plug-ins, however, it is also available as a command line applica- tion compiled using the Apache Maven.The transformation runs correctly for the provided test cases on SHARE

1

, and the source code is also available in a Git repository

2

. The results of the transformations were spot-checked for both synthetic and IMDb models.

4 Conclusion

In this paper we have presented our implementation of the Movie Database Case. The solution uses EMF-I NC Q UERY as a model query engine: the transformation is specified using declarative graph pat- tern queries over EMF models for rule preconditions, and Xtend code for model manipulations. The main conclusion of the performance evaluation is that EMF-IncQuery’s incremental approach is not a good fit for this case study as the transformation is very model manipulation dominant.

References

[1] Gábor Bergmann, Zoltán Ujhelyi, István Ráth & Dániel Varró (2011): A Graph Query Language for EMF models. In: Theory and Practice of Model Transformations, Fourth Int. Conf., LNCS 6707, Springer.

[2] Eclipse.org (2014): EMF-IncQuery. http://eclipse.org/incquery/.

[3] Eclipse.org (2014): Xtend – Modernized Java. https://www.eclipse.org/xtend/.

[4] Matthias Tichy Tassilo Horn, Christian Krause (2014): The TTC 2014 Movie Database Case. In: 7th Trans- formation Tool Contest (TTC 2014), EPTCS.

1http://is.ieis.tue.nl/staff/pvgorp/share/?page=ConfigureNewSession&vdi=Ubuntu12LTS_TTC14_

64bit_TTC14-EIQ-imdb.vdi

2https://git.inf.mit.bme.hu/w?p=projects/viatra/ttc14-eiq.git

(username:

anonymous, no password).

(6)

A Appendix – Movie Database Case Transformation Code

A.1 EMF-I NC Q UERY Graph Patterns

1 p a c k a g e hu . bme . mit . ttc . i m d b . q u e r i e s 2

3 i m p o r t " h t t p :// m o v i e s / 1 . 0 "

4 5

6 // S h o r t h a n d p a t t e r n s

7 p a t t e r n p e r s o n N a m e ( p , p N a m e ) { 8 P e r s o n . n a m e ( p , p N a m e ) ; 9 }

10

11 // A c t o r w i t h n a m e is p a r t of the c a s e of m o v i e M 12 p a t t e r n c a s t ( name , M ) {

13 M o v i e . p e r s o n s . n a m e ( M , n a m e ) ; 14 }

15

16 // M o v i e m is a c o m m o n m o v i e of C o u p l e c 17 p a t t e r n c o m m o n M o v i e s O f C o u p l e ( c , m ) { 18 C o u p l e . c o m m o n M o v i e s ( c , m ) ;

19 } 20 21 /* *

22 * T h i s p a t t e r n d e t e r m i n e s if a p e r s o n is a m e m b e r of a g r o u p .

23 */

24 p a t t e r n m e m b e r O f G r o u p ( person , g r o u p ) { 25 C o u p l e . p1 ( group , p e r s o n ) ;

26 } or {

27 C o u p l e . p2 ( group , p e r s o n ) ;

28 } or {

29 C l i q u e . p e r s o n s ( group , p e r s o n ) ; 30 }

31 32 /* *

33 * T h i s p a t t e r n d e t e r m i n e s the s i z e of a g r o u p .

34 */

35 p a t t e r n g r o u p S i z e ( group , S ) { 36 G r o u p ( g r o u p ) ;

37 S == c o u n t f i n d m e m b e r O f G r o u p ( _ , g r o u p ) ; 38 }

39

40 // C o u p l e p a t t e r n s 41 /* *

42 * T h i s p a t t e r n l o o k s for two p e r s o n n a m e s ( p1name , p 2 n a m e ) , who w e r e in the c a s t of 43 * t h r e e d i f f e r e n t m o v i e s ( M1 , M2 , M3 ) .

44 * The n a m e s are o r d e r e d l e x i c o g r a p h i c a l l y in o r d e r to l i s t the s a m e p a i r o n l y one 45 * ( the m a t c h set c o n t a i n s o n l y {( a1 , a2 ) } i n s t e a d of {( a1 , a2 ) , ( a2 , a1 ) }.

46 */

47 p a t t e r n p e r s o n s T o C o u p l e ( p1name , p 2 n a m e ) { 48 f i n d c a s t ( p1name , M1 ) ; f i n d c a s t ( p2name , M1 ) ; 49 f i n d c a s t ( p1name , M2 ) ; f i n d c a s t ( p2name , M2 ) ; 50 f i n d c a s t ( p1name , M3 ) ; f i n d c a s t ( p2name , M3 ) ; 51

52 M1 != M2 ; M2 != M3 ; M1 != M3 ;

53

54 c h e c k( p 1 n a m e < p 2 n a m e ) ; 55 }

56 57 /* *

58 * T h i s p a t t e r n l o o k s for the c o m m o n m o v i e s of a c o u p l e . 59 * The c o u p l e is d e t e r m i n e d w i t h the p e r s o n s T o C o u p l e p a t t e r n .

60 */

(7)

61 p a t t e r n c o m m o n M o v i e s T o C o u p l e ( p1name , p2name , m ) { 62 f i n d p e r s o n s T o C o u p l e ( p1name , p 2 n a m e ) ;

63

64 P e r s o n . m o v i e s ( p1 , m ) ; 65 P e r s o n . m o v i e s ( p2 , m ) ; 66 P e r s o n . n a m e ( p1 , p 1 n a m e ) ; 67 P e r s o n . n a m e ( p2 , p 2 n a m e ) ; 68

69 c h e c k( p 1 n a m e < p 2 n a m e ) ; 70 }

71 72 /* *

73 * R e t u r n s w i t h the n u m b e r of c o m m o n m o v i e s of a c o u p l e .

74 */

75 p a t t e r n c o u n t O f C o m m o n M o v i e s O f C o u p l e ( p1 , p2 , n ) { 76 C o u p l e . p1 ( c , p1 ) ;

77 C o u p l e . p2 ( c , p2 ) ;

78 n == c o u n t f i n d c o m m o n M o v i e s O f C o u p l e ( c , _m ) ; 79 }

80

81 // C l i q u e p a t t e r n s 82 /* *

83 * S i m i l a r l y to the c o u p l e pattern , t h i s p a t t e r n l o o k s for 3 - c l i q u e s .

84 */

85 p a t t e r n p e r s o n s T o 3 C l i q u e ( P1 , P2 , P3 ) {

86 f i n d c a s t ( P1 , M1 ) ; f i n d c a s t ( P2 , M1 ) ; f i n d c a s t ( P3 , M1 ) ; 87 f i n d c a s t ( P1 , M2 ) ; f i n d c a s t ( P2 , M2 ) ; f i n d c a s t ( P3 , M2 ) ; 88 f i n d c a s t ( P1 , M3 ) ; f i n d c a s t ( P2 , M3 ) ; f i n d c a s t ( P3 , M3 ) ; 89

90 M1 != M2 ; M2 != M3 ; M1 != M3 ;

91

92 c h e c k( P1 < P2 ) ; c h e c k( P2 < P3 ) ; 93 }

94 95 /* *

96 * S i m i l a r l y to the c o u p l e pattern , t h i s p a t t e r n l o o k s for 4 - c l i q u e s .

97 */

98 p a t t e r n p e r s o n s T o 4 C l i q u e ( P1 , P2 , P3 , P4 ) {

99 f i n d c a s t ( P1 , M1 ) ; f i n d c a s t ( P2 , M1 ) ; f i n d c a s t ( P3 , M1 ) ; f i n d c a s t ( P4 , M1 ) ; 100 f i n d c a s t ( P1 , M2 ) ; f i n d c a s t ( P2 , M2 ) ; f i n d c a s t ( P3 , M2 ) ; f i n d c a s t ( P4 , M2 ) ; 101 f i n d c a s t ( P1 , M3 ) ; f i n d c a s t ( P2 , M3 ) ; f i n d c a s t ( P3 , M3 ) ; f i n d c a s t ( P4 , M3 ) ; 102

103 M1 != M2 ; M2 != M3 ; M1 != M3 ;

104

105 c h e c k( P1 < P2 ) ; c h e c k( P2 < P3 ) ; c h e c k( P3 < P4 ) ; 106 }

107 108 /* *

109 * S i m i l a r l y to the c o u p l e pattern , t h i s p a t t e r n l o o k s for 5 - c l i q u e s .

110 */

111 p a t t e r n p e r s o n s T o 5 C l i q u e ( P1 , P2 , P3 , P4 , P5 ) {

112 f i n d c a s t ( P1 , M1 ) ; f i n d c a s t ( P2 , M1 ) ; f i n d c a s t ( P3 , M1 ) ; f i n d c a s t ( P4 , M1 ) ; f i n d c a s t ( P5 , M1 ) ;

113 f i n d c a s t ( P1 , M2 ) ; f i n d c a s t ( P2 , M2 ) ; f i n d c a s t ( P3 , M2 ) ; f i n d c a s t ( P4 , M2 ) ; f i n d c a s t ( P5 , M2 ) ;

114 f i n d c a s t ( P1 , M3 ) ; f i n d c a s t ( P2 , M3 ) ; f i n d c a s t ( P3 , M3 ) ; f i n d c a s t ( P4 , M3 ) ; f i n d c a s t ( P5 , M3 ) ;

115

116 M1 != M2 ; M2 != M3 ; M1 != M3 ;

117

118 c h e c k( P1 < P2 ) ; c h e c k( P2 < P3 ) ; c h e c k( P3 < P4 ) ; c h e c k( P4 < P5 ) ; 119 }

(8)

A.2 Xtend Code A.2.1 Generator Code

1 /* *

2 * T h i s c l a s s i m p l e m e n t s the t e s t m o d e l g e n e r a t o r l o g i c .

3 */

4 c l a s s G e n e r a t o r {

5

6 // The EMF r e s o u r c e on w h i c h the t r a n s f o r m a t i o n o p e r a t e s

7 p u b l i c R e s o u r c e r

8

9 // We d e f i n e t h i s e x t e n s i o n to h e l p w i t h m o d e l e l e m e n t c r e a t i o n

10 e x t e n s i o n M o v i e s F a c t o r y = M o v i e s F a c t o r y . e I N S T A N C E

11

12 // m e t h o d to g e n e r a t e an e x a m p l e of s i z e N

13 def g e n e r a t e ( int N ) {

14 c r e a t e E x a m p l e ( N ) ;

15 }

16

17 // c r e a t e N t e s t c a s e s in the m o d e l

18 def c r e a t e E x a m p l e ( int N ) {

19 (0 .. N - 1) . f o r E a c h [ c r e a t e T e s t ( it ) ]

20 }

21

22 // c r e a t e a t e s t c a s e s in the m o d e l w i t h p a r a m e t e r n

23 def c r e a t e T e s t ( int n ) {

24 c r e a t e P o s i t i v e ( n )

25 c r e a t e N e g a t i v e ( n )

26 }

27

28 // c r e a t e a p o s i t i v e m a t c h for the t e s t c a s e

29 // i n i t i a l i z e s o m e m o v i e s and a c t o r s / a c t r e s s e s

30 // c r e a t e i n t e r c o n n e c t i o n s a c c o r d i n g to a l o g i c t h a t w i l l y i e l d a p o s i t i v e m a t c h

31 def c r e a t e P o s i t i v e ( int n ) {

32 val m o v i e s = n e w A r r a y L i s t ()

33 (0 .. 4) . f o r E a c h [ m o v i e s += c r e a t e M o v i e (10 * n + it ) ]

34

35 val a = c r e a t e A c t o r (" a " + (10 * n ) )

36 val b = c r e a t e A c t o r (" a " + (10 * n + 1) )

37 val c = c r e a t e A c t o r (" a " + (10 * n + 2) )

38 val d = c r e a t e A c t r e s s (" a " + (10 * n + 3) )

39 val e = c r e a t e A c t r e s s (" a " + (10 * n + 4) )

40

41 val a c t o r s = #[ a , b , c , d , e ]

42 val f i r s t T w o = #[ a , b ]

43 val l a s t T w o = #[ d , e ]

44

45 m o v i e s . get (0) . p e r s o n s += f i r s t T w o ;

46 (1 .. 3) . f o r E a c h [ m o v i e s . get ( it ) . p e r s o n s += a c t o r s ]

47 m o v i e s . get (4) . p e r s o n s += l a s t T w o

48

49 r . c o n t e n t s += a c t o r s

50 r . c o n t e n t s += m o v i e s

51 }

52

53 // c r e a t e a p o s i t i v e m a t c h for the t e s t c a s e

54 // i n i t i a l i z e s o m e m o v i e s and a c t o r s / a c t r e s s e s

55 // c r e a t e i n t e r c o n n e c t i o n s a c c o r d i n g to a l o g i c t h a t w i l l y i e l d a n e g a t i v e m a t c h

56 def c r e a t e N e g a t i v e ( int n ) {

57 val m o v i e s = n e w A r r a y L i s t ()

58 (5 .. 9) . f o r E a c h [ m o v i e s += c r e a t e M o v i e (10 * n + it ) ]

59

60 val a = c r e a t e A c t o r (" a " + (10 * n + 5) )

61 val b = c r e a t e A c t o r (" a " + (10 * n + 6) )

(9)

62 val c = c r e a t e A c t r e s s (" a " + (10 * n + 7) )

63 val d = c r e a t e A c t r e s s (" a " + (10 * n + 8) )

64 val e = c r e a t e A c t r e s s (" a " + (10 * n + 9) )

65

66 val a c t o r s = #[ a , b , c , d , e ]

67 m o v i e s . get (0) . p e r s o n s += #[ a , b ]

68 m o v i e s . get (1) . p e r s o n s += #[ a , b , c ]

69 m o v i e s . get (2) . p e r s o n s += #[ b , c , d ]

70 m o v i e s . get (3) . p e r s o n s += #[ c , d , e ]

71 m o v i e s . get (4) . p e r s o n s += #[ d , e ]

72

73 r . c o n t e n t s += a c t o r s

74 r . c o n t e n t s += m o v i e s

75 }

76

77 // c r e a t e a m o v i e w i t h the g i v e n r a t i n g

78 def c r e a t e M o v i e ( int r a t i n g ) {

79 val m o v i e = c r e a t e M o v i e

80 m o v i e . r a t i n g = r a t i n g

81 m o v i e

82 }

83

84 // c r e a t e an a c t o r w i t h the g i v e n n a m e

85 def c r e a t e A c t o r ( S t r i n g n a m e ) {

86 val a c t o r = c r e a t e A c t o r

87 a c t o r . n a m e = n a m e

88 a c t o r

89 }

90

91 // c r e a t e an a c t r e s s w i t h the g i v e n n a m e

92 def c r e a t e A c t r e s s ( S t r i n g n a m e ) {

93 val a c t r e s s = c r e a t e A c t r e s s

94 a c t r e s s . n a m e = n a m e

95 a c t r e s s

96 }

97 98 }

A.2.2 Transformation Code

1 /* *

2 * T h i s c l a s s i m p l e m e n t s the t r a n s f o r m a t i o n l o g i c .

3 */

4 c l a s s T r a n s f o r m a t i o n {

5

6 /* *

7 * I n i t i a l i z e the t r a n s f o r m a t i o n p r o c e s s o r on a r e s o u r c e .

8 * The r u n t i m e of the t r a n s f o r m a t i o n s t e p s are l o g g e d .

9 * @ p a r a m r The t a r g e t r e s o u r c e of the t r a n s f o r m a t i o n .

10 * @ p a r a m bmr The b e n c h m a r k l o g g e r .

11 */

12 new ( R e s o u r c e r , B e n c h m a r k R e s u l t s bmr ) {

13 t h i s. r = r ;

14 t h i s. bmr = bmr ;

15 t h i s. r o o t = r . c o n t e n t s . get (0) as R o o t

16 }

17

18 // to s t o r e the b e n c h m a r k r e s u l t s

19 p r o t e c t e d val B e n c h m a r k R e s u l t s bmr ;

20 // to s t o r e the m o d e l

21 p r o t e c t e d R e s o u r c e r

22

23 // / / / / R e s o u r c e s M a n a g e m e n t

24 p r o t e c t e d val R o o t r o o t ;

25 /* *

(10)

26 * H e l p e r f u n c t i o n to add e l e m e n t s to the t a r g e t r e s o u r c e .

27 * @ p a r a m

28 */

29 def a d d E l e m e n t T o R e s o u r c e ( C o n t a i n e d E l e m e n t c o n t a i n e d E l e m e n t ) {

30 r o o t . c h i l d r e n . add ( c o n t a i n e d E l e m e n t )

31 }

32 def a d d E l e m e n t s T o R e s o u r c e ( C o l l e c t i o n <? e x t e n d s C o n t a i n e d E l e m e n t > c o n t a i n e d E l e m e n t s ) {

33 r o o t . c h i l d r e n . a d d A l l ( c o n t a i n e d E l e m e n t s )

34 }

35 def g e t E l e m e n t s F r o m R e s o u r c e () {

36 r o o t . c h i l d r e n

37 }

38 // / / / / / / / / / / / / / / / / / / / / / / / / / /

39

40 // to h e l p w i t h m o d e l m a n i p u l a t i o n

41 e x t e n s i o n M o v i e s F a c t o r y = M o v i e s F a c t o r y . e I N S T A N C E

42 e x t e n s i o n I m d b = I m d b . i n s t a n c e

43

44 // c r e a t e c o u p l e s

45 p u b l i c def c r e a t e C o u p l e s () {

46 val e n g i n e = A d v a n c e d I n c Q u e r y E n g i n e . c r e a t e U n m a n a g e d E n g i n e ( r )

47 val c o u p l e M a t c h e r = e n g i n e . p e r s o n s T o C o u p l e

48 val c o m m o n M o v i e s M a t c h e r = e n g i n e . c o m m o n M o v i e s T o C o u p l e

49 val p e r s o n N a m e M a t c h e r = e n g i n e . p e r s o n N a m e

50

51 val n e w C o u p l e s = new L i n k e d L i s t < Couple >

52 c o u p l e M a t c h e r . f o r E a c h M a t c h [

53 val c o u p l e = c r e a t e C o u p l e ()

54 val p1 = p e r s o n N a m e M a t c h e r . g e t A l l V a l u e s O f p ( p 1 n a m e ) . h e a d

55 val p2 = p e r s o n N a m e M a t c h e r . g e t A l l V a l u e s O f p ( p 2 n a m e ) . h e a d

56 c o u p l e . s e t P 1 ( p1 )

57 c o u p l e . s e t P 2 ( p2 )

58 val c o m m o n M o v i e s = c o m m o n M o v i e s M a t c h e r . g e t A l l V a l u e s O f m ( p1name , p 2 n a m e )

59 c o u p l e . c o m m o n M o v i e s . a d d A l l ( c o m m o n M o v i e s )

60

61 n e w C o u p l e s += c o u p l e

62 ]

63

64 p r i n t l n (" # of c o u p l e s = " + n e w C o u p l e s . s i z e )

65 e n g i n e . d i s p o s e

66 a d d E l e m e n t s T o R e s o u r c e ( n e w C o u p l e s ) ;

67 }

68

69 // c a l c u l a t e the top g r o u p by r a t i n g

70 def t o p G r o u p B y R a t i n g ( int s i z e ) {

71 p r i n t l n (" Top -15 by A v e r a g e R a t i n g ")

72 p r i n t l n (" = = = = = = = = = = = = = = = = = = = = = = = = ")

73 val n = 15;

74

75 val e n g i n e = I n c Q u e r y E n g i n e . on ( r )

76 val c o u p l e W i t h R a t i n g M a t c h e r = e n g i n e . g r o u p S i z e

77 val r a n k e d C o u p l e s = c o u p l e W i t h R a t i n g M a t c h e r . g e t A l l V a l u e s O f g r o u p ( s i z e ) . s o r t (

78 new G r o u p A V G C o m p a r a t o r )

79

80 p r i n t C o u p l e s ( n , r a n k e d C o u p l e s )

81 }

82

83 // c a l c u l a t e the top g r o u p by c o m m o n m o v i e s

84 def t o p G r o u p B y C o m m o n M o v i e s ( int s i z e ) {

85 p r i n t l n (" Top -15 by N u m b e r of C o m m o n M o v i e s ")

86 p r i n t l n (" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ")

87

88 val n = 15;

89 val e n g i n e = I n c Q u e r y E n g i n e . on ( r )

90 val c o u p l e W i t h R a t i n g M a t c h e r = e n g i n e . g r o u p S i z e

(11)

91

92 val r a n k e d C o u p l e s = c o u p l e W i t h R a t i n g M a t c h e r . g e t A l l V a l u e s O f g r o u p ( s i z e ) . s o r t (

93 new G r o u p S i z e C o m p a r a t o r

94 )

95 p r i n t C o u p l e s ( n , r a n k e d C o u p l e s )

96 }

97

98 // pretty - p r i n t c o u p l e s

99 def p r i n t C o u p l e s ( int n , List < Group > r a n k e d C o u p l e s ) {

100 (0 .. n - 1) . f o r E a c h [

101 if( it < r a n k e d C o u p l e s . s i z e ) {

102 val c = r a n k e d C o u p l e s . get ( it ) ;

103 p r i n t l n ( c . p r i n t G r o u p ( it ) )

104 }

105 ]

106 }

107

108 // pretty - p r i n t g r o u p s

109 def p r i n t G r o u p ( G r o u p group , int l i n e N u m b e r ) {

110 if( g r o u p i n s t a n c e o f C o u p l e ) {

111 val c o u p l e = g r o u p as C o u p l e

112 r e t u r n ’ ’ ’ « l i n e N u m b e r » . C o u p l e a v g R a t i n g « g r o u p . a v g R a t i n g » , « g r o u p . c o m m o n M o v i e s . s i z e » m o v i e s ( « c o u p l e . p1 . n a m e » ; « c o u p l e . p2 . n a m e » ) ’ ’ ’

113 }

114 e l s e {

115 val c l i q u e = g r o u p as C l i q u e

116 r e t u r n ’ ’ ’ « l i n e N u m b e r » . « c l i q u e . p e r s o n s . s i z e » - C l i q u e a v g R a t i n g « g r o u p . a v g R a t i n g » , « g r o u p . c o m m o n M o v i e s . s i z e » m o v i e s ( «

117 FOR p e r s o n : c l i q u e . p e r s o n s S E P A R A T O R " , "» « p e r s o n . n a m e » « E N D F O R » ) ’ ’ ’

118 }

119 }

120

121 // c a l c u l a t e a v e r a g e r a t i n g s

122 def c a l c u l a t e A v g R a t i n g s () {

123 g e t E l e m e n t s F r o m R e s o u r c e . f i l t e r ( t y p e o f ( G r o u p ) ) . f o r E a c h [ x | c a l c u l a t e A v g R a t i n g ( x . c o m m o n M o v i e s , x ) ]

124 }

125

126 // c a l c u l a t e a v e r a g e r a t i n g

127 p r o t e c t e d def c a l c u l a t e A v g R a t i n g ( C o l l e c t i o n < Movie > c o m m o n M o v i e s , G r o u p g r o u p ) {

128 var s u m R a t i n g = 0.0

129

130 for ( m : c o m m o n M o v i e s ) {

131 s u m R a t i n g = s u m R a t i n g + m . r a t i n g

132 }

133 val n = c o m m o n M o v i e s . s i z e

134 g r o u p . a v g R a t i n g = s u m R a t i n g / n

135 }

136

137 // c r e a t e c l i q u e s

138 p u b l i c def c r e a t e C l i q u e s ( int c l i q u e s ) {

139 val e n g i n e = A d v a n c e d I n c Q u e r y E n g i n e . c r e a t e U n m a n a g e d E n g i n e ( r )

140 val p e r s o n M a t c h e r = g e t P e r s o n N a m e ( e n g i n e )

141 var C o l l e c t i o n < Clique > n e w C l i q u e s

142

143 if( c l i q u e s == 3) {

144 val c l i q u e 3 = g e t P e r s o n s T o 3 C l i q u e ( e n g i n e )

145

146 n e w C l i q u e s = c l i q u e 3 . a l l M a t c h e s . map [ x | g e n e r a t e C l i q u e (

147 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p1 ) . p ,

148 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p2 ) . p ,

149 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p3 ) . p ) ]. t o L i s t ;

150 }

151 e l s e if( c l i q u e s == 4) {

152 val c l i q u e 4 = g e t P e r s o n s T o 4 C l i q u e ( e n g i n e )

(12)

153

154 n e w C l i q u e s = c l i q u e 4 . a l l M a t c h e s . map [ x | g e n e r a t e C l i q u e (

155 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p1 ) . p ,

156 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p2 ) . p ,

157 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p3 ) . p ,

158 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p4 ) . p ) ]. t o L i s t ;

159 }

160 e l s e if( c l i q u e s == 5) {

161 val c l i q u e 5 = g e t P e r s o n s T o 5 C l i q u e ( e n g i n e )

162 n e w C l i q u e s = c l i q u e 5 . a l l M a t c h e s . map [ x | g e n e r a t e C l i q u e (

163 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p1 ) . p ,

164 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p2 ) . p ,

165 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p3 ) . p ,

166 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p4 ) . p ,

167 p e r s o n M a t c h e r . g e t O n e A r b i t r a r y M a t c h (null, x . p5 ) . p ) ]. t o L i s t ;

168 }

169

170 p r i n t l n (" # of "+ c l i q u e s +" - c l i q u e s = " + n e w C l i q u e s . s i z e )

171

172 e n g i n e . d i s p o s e

173 n e w C l i q u e s . f o r E a c h [ x | x . c o m m o n M o v i e s . a d d A l l ( x . c o l l e c t C o m m o n M o v i e s ) ]

174 a d d E l e m e n t s T o R e s o u r c e ( n e w C l i q u e s ) ;

175 }

176

177 // g e n e r a t e c l i q u e s

178 p r o t e c t e d def g e n e r a t e C l i q u e ( P e r s o n ... p e r s o n s ) {

179 val c = c r e a t e C l i q u e

180 c . p e r s o n s += p e r s o n s

181 r e t u r n c

182 }

183

184 // c o l l e c t c o m m o n m o v i e s

185 p r o t e c t e d def c o l l e c t C o m m o n M o v i e s ( C l i q u e c l i q u e ) {

186 var Set < Movie > c o m m o n M o v i e s = n u l l;

187 for ( p e r s o n M o v i e s : c l i q u e . p e r s o n s . map [ m o v i e s ]) {

188 if( c o m m o n M o v i e s == n u l l) {

189 c o m m o n M o v i e s = p e r s o n M o v i e s . t o S e t ;

190 }

191 e l s e {

192 c o m m o n M o v i e s . r e t a i n A l l ( p e r s o n M o v i e s )

193 }

194 }

195 r e t u r n c o m m o n M o v i e s

196 }

197 }

A.2.3 General Clique Patterns

The resulting expression for condition (ii) is the following: (6 ∃g

0

) : ((6 ∃p

0

∈ g

0

) : p

0

6∈ g

0

) ∧ (p ∈ g

0

).

This is equivalent to the following EMF-I NC Q UERY pattern:

1 /* * G r o u p g0 is a s u b s e t of G r o u p gx . */

2 p a t t e r n s u b s e t O f G r o u p ( g0 : Group , gx : G r o u p ) { 3 neg f i n d n o t S u b s e t O f G r o u p ( p0 , g0 , gx ) ;

4 } 5

6 /* * T h i s p a t t e r n r e t u r n s is a h e l p e r for the s u b s e t O f G r o u p p a t t e r n . */

7 p a t t e r n n o t S u b s e t O f G r o u p ( p0 : Person , g0 : Group , gx : G r o u p ) { 8 f i n d m e m b e r O f G r o u p ( p0 , g0 ) ;

9 neg f i n d m e m b e r O f G r o u p ( p0 , gx ) ; 10 }

11

12 /* * P e r s o n p is a m e m b e r of G r o u p g . A G r o u p is e i t h e r a C o u p l e or a C l i q u e . */

13 p a t t e r n m e m b e r O f G r o u p ( p , g ) { 14 C o u p l e . p1 ( g , p ) ;

(13)

15 } or {

16 C o u p l e . p2 ( g , p ) ;

17 } or {

18 C l i q u e . p e r s o n s ( g , p ) ; 19 }

Based on the subsetOfGroup pattern, we may implement the nextClique pattern like follows:

1 /* * the n e x t C l i q u e s p a t t e r n */

2 p a t t e r n n e x t C l i q u e s ( g : Group , p : P e r s o n ) { 3 neg f i n d a l p h a b e t i c a l l y L a t e r M e m b e r O f G r o u p ( g , p ) ; 4 n == c o u n t f i n d c o m m o n M o v i e O f G r o u p A n d P e r s o n ( g , p , m ) ; 5 c h e c k( n >= 3) ;

6 neg f i n d u n i o n ( g , p ) ; 7 }

8

9 /* * p is a m e m b e r of g for w h i c h a n o t h e r a l p h a b e t i c a l l y p r e v i o u s m e m b e r e x i s t s */

10 p a t t e r n a l p h a b e t i c a l l y L a t e r M e m b e r O f G r o u p ( g : Group , p : P e r s o n ) { 11 f i n d m e m b e r O f G r o u p ( m , g ) ;

12 P e r s o n . n a m e ( p , p N a m e ) ; 13 P e r s o n . n a m e ( m , m N a m e ) ; 14 c h e c k( m N a m e >= p N a m e ) ; 15 }

16

17 /* * m is a c o m m o n m o v i e of g and p */

18 p a t t e r n c o m m o n M o v i e O f G r o u p A n d P e r s o n ( g , p , m ) { 19 f i n d c o m m o n M o v i e s O f G r o u p ( g , m ) ;

20 P e r s o n . m o v i e s ( p , m ) ; 21 }

22

23 /* * m is a c o m m o n m o v i e of g */

24 p a t t e r n c o m m o n M o v i e s O f G r o u p ( g , m ) { 25 G r o u p . c o m m o n M o v i e s ( g , m ) ;

26 } 27

28 /* * p is in g0 */

29 p a t t e r n u n i o n ( g0 , p ) { 30 f i n d m e m b e r O f G r o u p ( p , gx ) ; 31 f i n d s u b s e t O f G r o u p ( g0 , gx ) ; 32 }

A.2.4 Comparator Code for Top-15

1 c l a s s G r o u p S i z e C o m p a r a t o r i m p l e m e n t s C o m p a r a t o r < Group >{

2

3 o v e r r i d e c o m p a r e ( G r o u p arg0 , G r o u p a r g 1 ) {

4 if ( a r g 0 . c o m m o n M o v i e s . s i z e < a r g 1 . c o m m o n M o v i e s . s i z e ) { r e t u r n 1}

5 e l s e if ( a r g 0 . c o m m o n M o v i e s . s i z e == a r g 1 . c o m m o n M o v i e s . s i z e ) { r e t u r n 0}

6 e l s e r e t u r n -1;

7 }

8 }

9

10 c l a s s G r o u p A V G C o m p a r a t o r i m p l e m e n t s C o m p a r a t o r < Group >{

11

12 o v e r r i d e c o m p a r e ( G r o u p arg0 , G r o u p a r g 1 ) {

13 if( a r g 0 . a v g R a t i n g < a r g 1 . a v g R a t i n g ) { r e t u r n 1;}

14 e l s e if ( a r g 0 . a v g R a t i n g == a r g 1 . a v g R a t i n g ) { r e t u r n 0;}

15 e l s e r e t u r n -1;

16 }

17 }

Références

Documents relatifs