44 Possible Representations of Cliché (1) Text

Pattern
Re-Engineering
$f_1 = ’*max*’
%%
$t_1 $f_1($*v)
$*d
{*
@[while|dowhile|for]
{*
if ($v_2[#] > $v_3)
$v_3 = $v_2[#]
*}
*}
Text
Sample: Maximum Search in an Array
int find_max (int_arr, N)
int int_arr[];
int N;
{ int i;
int maxstore;
maxstore = int_arr[0];
for (i=1; i<N; i++)
{
if (int_arr[i] > maxstore)
maxstore = int_arr[i];
}
return (maxstore);
}
Match
Possible Representations of Cliché (1)
44
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
# (#*)
@ (@*)
Statement (sequence)
$f
Function
Expression (s)
$v ($*v)
$t
$d ($*d)
Pattern Symbol
Variable
Type
Declaration (s)
Syntactic Unit
Possible Representations of Cliché (2)
45
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
1.
Re-Engineering
Graph (s)
SelDistinctCliché
::=
projects
Range
lc
Relation
Projection
lc
Select
From
Clause
lf
ll
lc
Selection
Clause
lc
Distinct
qualifies
ConstEqual
Conjunction
Where
Clause
lc
lc
Possible Representations of Cliché (3)
46
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
node labeling functions (if L(v) = A we call v an A - node)
L : V → ΣV
47
edges ((v, x, w) is called x-edge from v to w)
E ⊆ V x ΣE x V
Re-Engineering
Node (identifiers)
ΣV, ΣE finite sets of node (ΣV) and edge-labels (ΣE)
V ⊆ ΙΝ∗
and
G = (V, E, L, ΣV, ΣE)
A directed, node and edge-labeled graph (DAG) is defined as
Definition of a Graph
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
48
If d1 is identified (isomorphic image) in a host graph g, then replacing d1 (the isomorphic
image) by d2 results in host graph g‘ by connecting (dangling) edges as defined in the
embedding rule.
Application:
A graph rule is defined by a left side d1 and a right side d2 (both sides are DAGs) and an
embedding rule.
Definition of a Graph Production (informal)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
{geordnet}
GroupByClause
belongs_to
Column
{geordnet} 1+
SelectionClause
SelectStatement
Relation
1+
Cursor
{geordnet}
Range
FromClause
UpdateStatement
HavingClause
{geordnet}
TreeNode
{geordnet}
WhereClause
DeleteStatement
SQL-Statement
Meta-Schema for an SQL-Abstract
Syntax Graph (ASG) Representation (1)
49
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
Literal
Parameter
Constant
Not
Column
And
Connect
TreeNode
Or
In
Equal
SelectStatement
...
Greater
NotEqual
Comparison
Meta-Schema for an SQL-Abstract
Syntax Graph (ASG) Representation (2)
50
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
lf
lc
: Range
: Relation
lc
‘5
‘7
belongs_to
: Column
‘13
ll
lf
: SelectionClause
lc
‘12
lc
‘2
ln
: FromClause
lc
‘4
‘6
lc
ll
lc
‘11
lc
belongs_to
: Range
: Relation
‘1 : SelectStatement
SELECT V.Name
FROM Vorlesung V, Professor P
WHERE P.Name = ’Schäfer’
: Column
lf
‘8
‘10
lc
: Equal
ln
lc
‘9
lc
: Literal
: WhereClause
ll
51
lc - list contained
ll - list last
lf - list first
ln - list next
A Sample ASG for a Select Statement
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
ASG of an SQL-Statement
Re-Engineering
cliche_name (relation (attr 1,..., attr n) or
cliche_name (relation 1 (attr 1,..., attr n)
relation 2 (attr 1,..., attr n))
Output: a recognized cliché (or none) and the involved tables
52
applies specified graph grammer rules to the ASG of an SQL-statement until it terminates.
Input:
The Cliché Recognizer
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
G < G‘: ↔ ∃ i : |G |i < |G‘ |i Λ ∀ (j<i) : |G |j = |G‘ |j
|G |k = | { x ε G| layer (x) = k}|
|G |k is the number of all nodes and edges which belong to layer k
a) right side of a rule is a connected graph
b) left side is non-empty
c) Vright side\Vleft side = non-empty
d) L < R whereby
A graph grammar is Layered iff
Assume L0 ⊗ ..⊗ Ln as a disjunctive decomposition of ΣV ⊗ ΣE.
A Layered Graph Grammar
53
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
concise definition of a set of nodes and edges
path expression ⇒
meaning:
First rule with optional nodes is applied, if it fails the other one is extented
54
A rule containing optional nodes can be replaced by two rules, one containing only nonoptional nodes, the other containing all optional nodes
meaning:
optional nodes
Some technical Abbreviations (1)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
(e.g. ∗ Cursor
Conjunction
Connect
List
*
logical and
any logical operator
any other composition of nodes
Wildcard for a predefined
set of possibilities
Cursor ε {Range, Relation})
means
means
means
means
Affices of node labels indicate type, i. e.
Some technical Abbreviations (2)
55
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
∈
∈
∈
∈
{WhereClause, And};
{Literal, Parameter};
{ConstEqualConjunction, ConstEqual};
{Range, Relation};
select distinct Fachbereich
from Professor
where Name = :N
Re-Engineering
layer(x) = 0:
Projection}})
∀( x ∈ { { V } }\{ConstEqualConjunction,
)
})
layer(x) = 1: ∀( x ∈ {{ E }, ,ConstEqualConjunction,
Projection})
WhereAnd
DefiniteConstant
ConstEquals
Cursor
wildcards
ex.
56
Formal Definiton of Select-Distinct Cliché (1)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
57
Formal Definition of Select-Distinct Cliché (2)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
58
Formal Definition of Select-Distinct Cliché (3)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
59
Formal Definition of Select-Distinct Cliché (4)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
SELECT distinct V. Name
FROM Vorlesung V, Professor P
WHERE P.Name = ’Schäfer’
Sample Application
60
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
∈
∈
∈
∈
select *
from Professor x, Professor y
where (x.Name = y.Name)
and (x.Fachbereich = y.Fachbereich)
...
and not (x.Pers-Nr = y.Pers-Nr)
{Where, And};
{Range, Relation};
{NotColEqualConjunction, NotColEqual};
{Or, And, Not, Where};
Re-Engineering
WhereAnd
Cursor
NotColEquals
Connect
wildcards
ex.
61
Formal Definition of Cyclic-Exclusion Cliché (1)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
62
Formal Definition of Cyclic-Exclusion Cliché (2)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
63
Formal Definition of Cyclic-Exclusion Cliché (3)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer
Re-Engineering
64
Formal Definition of Cyclic-Exclusion Cliché (4)
Universität Paderborn
AG Softwaretechnik
Prof. Dr. W. Schäfer