• No results found

Implementation

4.6 Concluding Remarks

5.1.3 Implementation

The LQML grammar is implemented in JavaCC (Java Compiler Compiler)2. JavaCC is a parser generator and a lexical analyser, where the grammar is specified in EBNF notation. Blueprints defined in LQML are interpreted by the JavaCC compiler where each blueprint is then interpreted and transformed into a Java class during Luzzu’s runtime.

The following listings (Listings5.5to5.7) shows the EBNF grammar for the main parts of the LQML syntax. A blueprint starts with the header definition, which includes information about the creator of the blueprint metric and information about the final (Java) package of the generated metric (since the blueprint will be compiled into a Java class that will be used within Luzzu (Section4.4) as a metric). Following the header, the def marks the start of the blueprint, followed by a permutation of the metric, label, description, rule blocks.

5.1 Luzzu Quality Metric Language

The rule block is made up of one or more match and action pairs, whose result of each pair is stored in a variable that can be used later in the finally block. The match condition is made up of one or more atomic and simple conditions. A simple condition is one that assesses simple equality between two values, possibly returned by some function. Given a number of simple conditions, an atomic condition is one that returns true or false. An action is triggered if the condition is satisfied. The finally block uses the values of the variables assigned in the rule block.

< B l u e p r i n t > : = < Hea der > <Def > < D e f i n i t i o n P e r m > < F i n a l l y > < P e r i o d > < Hea der > : = < H e a d e r _ I n d i c a t o r > < A u t h o r > | < P a c k a g e >

<Def > : = "d e f" < LBrace > < S t r i c t _ S t r > <RBrace > < Colon > < D e f i n i t i o n P e r m > : = ( ( < M e t r i c > < L a b e l > < D e s c r i p t i o n > < Rule > ) | ( < L a b e l > < Rule > < D e s c r i p t i o n > < M e t r i c > ) | ( < Rule > < M e t r i c > < L a b e l > < D e s c r i p t i o n > ) | . . . # 21 o t h e r p e r m u t a t i o n p o s s i b i l i t i e s ) < F i n a l l y > : = "f i n a l l y" < LBrace > ( < F i n a l l y A c t i o n s > ) <RBrace > < F i n a l l y A c t i o n s > : = ( < Add> | < R a t i o > )

<Add> : = "add" < LParen > ( < T o t a l T r i p l e s > | < Vars > | < F i n a l l y A c t i o n s > ) <Comma> ( < Vars > | < F i n a l l y A c t i o n s > ) < RParen >

< R a t i o > : = "r a t i o" < LParen > ( < T o t a l T r i p l e s > | < Vars > | < F i n a l l y A c t i o n s > ) <Comma> ( < Vars > | < F i n a l l y A c t i o n s > ) < RParen >

Listing 5.5: LQML main Grammar.

< A u t h o r > : = "a u t h o r" < Colon > < Q u o t e d _ S t r > < P a c k a g e > : = "p a c k a g e" < Colon > < Q u o t e d _ S t r >

Listing 5.6: LQML header grammar.

External Functions: External functions, defined as Java classes, are preloaded into Luzzu. These can only be used within a match and action patterns. The structure (as described in the EBNF <Custom>) requires a function name (as a string) and one or more parameters. In AppendixCwe show

< M e t r i c > : = "m e t r i c" < LBrace > < I R I r e f > <RBrace > < SemiColon > < L a b e l > : = "l a b e l" < LBrace > < Q u o t e d _ S t r > <RBrace > < SemiColon >

< D e s c r i p t i o n > : = "d e s c r i p t i o n" < LBrace > < Q u o t e d _ S t r > <RBrace > < SemiColon >

< Rule > : = "r u l e" < LBrace > ( < Vars > " = " <Match > "= >" < A c t i o n > ) + <RBrace > < SemiColon >

< Vars > : = "v a r" < P e r i o d > < S t r i c t _ S t r >

<Match > : = "m a t c h" < LBrace > ( < C o n d i t i o n > ) + <RBrace >

< C o n d i t i o n > : = ( ( < L o g i c N e g a t i o n > < A t o m i c C o n d i t i o n > ) | < A t o m i c C o n d i t i o n > | < S i m p l e C o n d i t i o n > )

( < L o g i c B i n a r y O p > < C o n d i t i o n > ) *

< S i m p l e C o n d i t i o n > : = < LParen > " ? s " <BooleanOp > < I R I r e f > < RParen > | < LParen > " ? p " <BooleanOp > < I R I r e f > < RParen >

| < LParen > " ? o " <BooleanOp > ( < I R I r e f > | < Q u o t e d _ S t r > ) < RParen >

< A t o m i c C o n d i t i o n > : = <TypeOf > | < IsURI > | < I s B l a n k > | < I s L i t e r a l > | <Custom > <Custom > : = "c u s t o m" < P e r i o d > < S t r i c t _ S t r > < Params >

< Params > : = < LParen > ( " ? s " | " ? p " | " ? o " ) ( <Comma> ( " ? s " | " ? p " | " ? o " ) ) * < RParen >

< A c t i o n > : = "a c t i o n" < LBrace > < Count > | < C o u n t U n i q u e > | <Custom > <RBrace >

Listing 5.7: LQML definition constructs.