12) Validation of Graph-Based Models (Analysis and...

107
Fakultät Informatik, Institut für Software- und Multimediatechnik, Lehrstuhl für Softwaretechnologie 12) Validation of Graph-Based Models (Analysis and Consistency of Models) Prof. Dr. U. Aßmann Technische Universität Dresden Institut für Software- und Multimediatechnik Gruppe Softwaretechnologie http://st.inf.tu-dresden.de/teaching/swt2 Version 11-0.2, 05.11.11 1. Big Models 2. Examples of Graphs in Models 3. Types of Graphs 4. Analysis of Graphs in Models 1. Layering of Graphs 2. Searching in Graphs 3. Checking UML Models with Datalog 5. Transitive Closure and Reachability in Models 6. Validation Applications

Transcript of 12) Validation of Graph-Based Models (Analysis and...

Page 1: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Fakultät Informatik, Institut für Software- und Multimediatechnik, Lehrstuhl für Softwaretechnologie

12) Validation of Graph-Based Models

(Analysis and Consistency of Models)

Ø Prof. Dr. U. Aßmann Ø Technische Universität Dresden Ø Institut für Software- und Multimediatechnik Ø Gruppe Softwaretechnologie Ø http://st.inf.tu-dresden.de/teaching/swt2 Ø Version 11-0.2, 05.11.11

1.  Big Models 2.  Examples of Graphs in Models 3.  Types of Graphs 4.  Analysis of Graphs in Models

1.  Layering of Graphs 2.  Searching in Graphs 3.  Checking UML Models with Datalog

5.  Transitive Closure and Reachability in Models

6.  Validation Applications

Page 2: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Contents

Ø  Different kinds of relations: Lists, Trees, Dags, Graphs Ø  Treating graph-based models – The graph-logic isomorphism Ø  Analysis, querying, searching graph-based models

Ø  The Same Generation Problem Ø Datalog and EARS Ø  Transitive Closure

Ø  Consistency checking of graph-based specifications (aka model validation) Ø  Projections of graphs Ø  Transformation of graphs

TU Dresden, Prof. U. Aßmann Model Consistency 2

Page 3: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Obligatory Reading

Ø  Jazayeri Chap 3 Ø  If you have Balzert, Macasziek or Pfleeger, read the lecture slides carefully and do the exercise sheets Ø  J. Pan et. al. Ontology Driven Architectures and Potential Uses of the Semantic Web in Systems and

Software Engineering Ø  http://www.w3.org/2001/sw/BestPractices/SE/ODA/

Ø  Alexander Christoph. Graph rewrite systems for software design transformations. In M. Aksit, editor, Proceedings of Net Object Days 2002, Erfurt, Germany, October 2002. Springer LNCS 2591

Ø  D. Calvanese, M. Lenzerini, D. Nardi. Description Logics for Data Modeling. In J. Chomicki, G. Saale. Logics for Databases and Information Systems. Kluwer, 1998.

Ø  Michael Kifer. Rules and Ontologies in F-Logic. Reasoning Web Summer School 2005. Lecture Notes in Computer Science, LNCS 3564, Springer. http://dx.doi.org/10.1007/11526988_2

Ø  Mira Balaban, Michael Kifer. An Overview of F-OML: An F-Logic Based Object Modeling Language. Proceedings of the Workshop on OCL and Textual Modelling (OCL 2010). ECEASST 2010, 36, http://journal.ub.tu-berlin.de/eceasst/article/view/537/535

Ø  Holger Knublauch, Daniel Oberle, Phil Tetlow, Evan Wallace (ed.). A Semantic Web Primer for Object-Oriented Software Developers http://www.w3.org/2001/sw/BestPractices/SE/ODSD/

Ø  Yi, Kwangkeun, Whaley, John, Avots, Dzintars, Carbin, Michael, Lam, Monica. Using Datalog with Binary Decision Diagrams for Program Analysis. In: Programming Languages and Systems. Lecture Notes in Computer Science 3780, 2005, pp. 97-118 http://dx.doi.org/10.1007/11575467_8

Ø  Lam, M. S., Whaley, J., Livshits, V. B., Martin, M. C., Avots, D., Carbin, M., and Unkel, C. 2005. Context-sensitive program analysis as database queries. In Proceedings of the Twenty-Fourth ACM SIGMOD-SIGACT-SIGART Symposium on Principles of Database Systems (Baltimore, Maryland, June 13 - 15, 2005). PODS '05. ACM, New York, NY, 1-12. DOI= http://doi.acm.org/10.1145/1065167.1065169

Ø  Thomas, Dave, Hajiyev, Elnar, Verbaere, Mathieu, de Moor, Oege. codeQuest: Scalable Source Code Queries with Datalog, ECOOP 2006 – Object-Oriented Programming, Lecture Notes in Computer Science 4067, 2006, Springer, pp. 2 - 27 http://dx.doi.org/10.1007/11785477_2

TU Dresden, Prof. U. Aßmann Model Consistency 3

Page 4: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

References

Ø  S. Ceri, G. Gottlob, L. Tanca. What You Always Wanted to Know About Datalog (And Never Dared to Ask). IEEE Transactions on Knowledge And Data Engineering. March 1989, (1) 1, pp. 146-166.

Ø  S. Ceri, G. Gottlob, L. Tanca. Logic Programming and Databases. Springer, 1989. Ø  Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer Science

Press 1989. Ø  Benjamin Grosof, Ian Horrocks, Raphael Volz, and Stefan Decker. Description logic

programs: Combining logic programs with description logics. In Proc. of World Wide Web Conference (WWW) 2003, Budapest, Hungary, 05 2003. ACM Press.

Ø  Uwe Aßmann, Steffen Zschaler, and Gerd Wagner. Ontologies, Meta-Models, and the Model-Driven Paradigm. Handbook of Ontologies in Software Engineering. Springer, 2006.

Ø  http://www.uni-koblenz-landau.de/koblenz/fb4/institute/IST/AGEbert/personen/juergen-ebert/juergen-ebert/

Ø  Ebert, Jürgen; Riediger, Volker; Schwarz, Hannes; Bildhauer, Daniel (2008): Using the TGraph Approach for Model Fact Repositories. In: Proceedings of the International Workshop on Model Reuse Strategies (MoRSe 2008). S. 9--18.

Ø  Bildhauer, Daniel; Ebert, Jürgen (2008): Querying Software Abstraction Graphs. In: Working Session on Query Technologies and Applications for Program Comprehension (QTAPC 2008), collocated with ICPC 2008.

TU Dresden, Prof. U. Aßmann Model Consistency 4

Page 5: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Graph Rewriting

Ø  Graph rewriting for programs and models: Ø  U. Aßmann. On Edge Addition Rewrite Systems and Their Relevance to Program

Analysis. In J. Cuny, H. Ehrig, G. Engels, and G. Rozenberg, editors, 5th Int. Workshop on Graph Grammars and Their Application To Computer Science, volume 1073 of Lecture Notes in Computer Science, pages 321-335. Springer, Heidelberg, November 1994.

Ø  Uwe Aßmann. How to uniformly specify program analysis and transformation. In P. A. Fritzson, editor, Proceedings of the International Conference on Compiler Construction (CC), volume 1060 of Lecture Notes in Computer Science, pages 121-135. Springer, Heidelberg, 1996.

Ø  U. Aßmann. Graph Rewrite Systems for Program Optimization. ACM Transactions on Programming Languages and Systems, June 2000.

Ø  U. Aßmann. OPTIMIX, A Tool for Rewriting and Optimizing Programs. Graph Grammar Handbook, Vol. II, 1999. Chapman&Hall.

Ø  U. Aßmann. Reuse in Semantic Applications. REWERSE Summer School. July 2005. Malta. Reasoning Web, First International Summer School 2005, number 3564 in Lecture Notes in Computer Science. Springer.

Ø  Alexander Christoph. GREAT - a graph rewriting transformation framework for designs. Electronic Notes in Theoretical Computer Science (ENTCS), 82(4), April 2003.

TU Dresden, Prof. U. Aßmann Model Consistency 5

Page 6: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Goals

Ø  Understand that software models can become very large Ø  the need for appropriate techniques to handle large models

Ø in hand development Ø automatic analysis of the models

Ø  Learn how to use graph-based techniques to analyze and check models for consistency, well-formedness, integrity •  Datalog, Graph Query Languages, Description Logic, EARS, graph

transformations

Ø  Understand some basic concepts of simplicity in software models

TU Dresden, Prof. U. Aßmann Model Consistency 6

Page 7: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Motivation

Ø  Software engineers must be able to Ø  handle big design specifications (design models) during development Ø  work with consistent models Ø  measure models and implementations Ø  validate models and implementations

Ø  Real models and systems become very complex Ø  Most specifications are graph-based

Ø  We have to deal with basic graph theory to be able to measure well Ø  Every analysis method is very welcome Ø  Every structuring method is very welcome

TU Dresden, Prof. U. Aßmann Model Consistency 7

Page 8: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.1 THE PROBLEM: HOW TO MASTER LARGE MODELS

Ø  Large models have large graphs Ø  They can be hard to understand

Ø  Figures taken from Goose Reengineering Tool, analysing a Java class system [Goose, FZI Karlsruhe]

TU Dresden, Prof. U. Aßmann Model Consistency 8

Page 9: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

TU Dresden, Prof. U. Aßmann Model Consistency 9

Page 10: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Partially Collapsed

TU Dresden, Prof. U. Aßmann Model Consistency 10

Page 11: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Totally Collapsed

TU Dresden, Prof. U. Aßmann Model Consistency 11

Page 12: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Requirements for Modeling in Requirements and Design

Ø  We need guidelines how to develop simple models Ø  We need analysis techniques to

Ø  Analyze models Ø  Find out about their complexity Ø  Find out about simplifications

Ø  Search in models Ø  Check the consistency of the models

TU Dresden, Prof. U. Aßmann Model Consistency 12

Page 13: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.2 GENERATING GRAPHS FROM MODELS AND SOFTWARE

How are models and programs represented in a Software Tool?

Some Relationships (Graphs) in Software Systems

TU Dresden, Prof. U. Aßmann Model Consistency 13

Page 14: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

All Specifications and All Programs Have an Internal Graph-Based Representation

Ø  Texts are parsed to abstract syntax trees (AST) Ø  Two step procedure

Ø  Concrete Syntax Tree (CST) Ø  Abstract Syntax Tree (AST)

Ø  Through name analysis, they become abstract syntax graphs (ASG) or Use-Def-Graphs (UDG)

Ø  Through def-use-analysis, they become Use-def-Use Graphs (UDUG)

TU Dresden, Prof. U. Aßmann Model Consistency 14

.......

AST

.......

ASG (UDG)

.......

UDUG

Page 15: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Concrete Syntax Tree (CST) – Example

TU Dresden, Prof. U. Aßmann Model Consistency 15

Expr ::= ‘(’ Expr ‘)’ | Expr ‘&&’ Expr | Expr ‘||’ expr | ‘!’ Expr | Lit .

Lit ::= Var | ‘true’ | ‘false’. Var ::= [a-z][a-z 0-9_]+ .

Parsing this string: (( looking || true) && !found )

Page 16: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

CST - Example

Expr

( Expr

Expr

( Expr

Expr

Var id = looking

|| Expr

true

)

&& Expr

! Expr

Var id = found

)

TU Dresden, Prof. U. Aßmann Model Consistency 16

Expr ::= ‘(’ Expr ‘)’ | Expr ‘&&’ Expr | Expr ‘||’ expr | ‘!’ Expr | Lit .

Lit ::= Var | ‘true’ | ‘false’. Var ::= [a-z][a-z 0-9_]+ .

Parsing this string: (( looking || true) && !found )

Page 17: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

From the CST to the AST

&&

||

Var id = looking

True

!

Var id = found

TU Dresden, Prof. U. Aßmann Model Consistency 17

Expr

( Expr

Expr

( Expr

Expr

Var id = looking

|| Expr

true

)

&& Expr

! Expr

Var id = found

)

Page 18: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

AST

Ø  Parse trees (CST) waste a fair amount of space for representation of terminal symbols and productions

Ø  Compilers post-process parse trees into ASTs

Ø  ASTs are the fundamental data structure of IDEs (ASTView in Eclipse JDT)

TU Dresden, Prof. U. Aßmann Model Consistency 18

Page 19: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

AST

Ø  Problem with ASTs: They do not support static semantic checks, re-factoring and browsing operations, e.g: •  Name semantics:

§  Have all used variables been declared? Are they declared once? §  Have all Classes used been imported?

•  Are the types used in expressions / assignments compatible? (type checking)

•  Referencing: §  Navigate to the declaration of method call / variable reference / type

•  How can I pretty-print the AST to a CST again, so that the CST looks like the original CST §  Necessary for hygenic refactoring

TU Dresden, Prof. U. Aßmann Model Consistency 19

Page 20: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Def-Use Graphs (DUG) and Use-Definition-Use Graphs (UDUG)

Ø  Every language and notation has Ø  Definitions of items (definition of the variable Foo), who add type or other

metadata Ø  Uses of items (references to Foo)

Ø  We talk in specifications or programs about names of objects and their use Ø  Definitions are done in a data definition language (DDL) Ø  Uses are part of a data query language (DQL) or data manipulation language

(DML) Ø  Starting from the abstract syntax tree, name analysis finds out

about the definitions of uses of names •  Building the Use-Def graph •  This revolves the meaning of used names to definitions •  Inverting the Use-Def graph to a Use-Def-Use graph (UDUG) •  This links all definitions to their uses

TU Dresden, Prof. U. Aßmann Model Consistency 20

Page 21: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Abstract Syntax Graphs (ASG) are UDGs

Ø  Abstract Syntax Graphs have use-def edges that reflect semantic relationships •  from uses of names to

definitions of names Ø  These edges are used for

static semantic checks •  Type checking •  Casts and coercions •  Type inference

TU Dresden, Prof. U. Aßmann Model Consistency 21

boolean looking, found; … if (looking && !found ) {…}

Block

VarDecl type=boolean

VarName id=looking

VarDecl Type=boolean

VarName id=found

IfStmt

&&

looking !

found

Block

Page 22: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Refactoring on Complete Name-Resolved Graphs (Use-Def-Use Graphs)

Ø  UDUGs are used in refactoring operations (e.g. renaming a class).

Ø  For renaming of a definition, all uses have to be changed, too Ø  We need to trace all uses of a definition in the Use-Def-graph, resulting in its

inverse, the Def-Use-graph Ø  Refactoring works always on Def-Use-graphs and Use-Def-graphs, the

complete name-resolved graph (the Use-Def-Use graphs)

TU Dresden, Prof. U. Aßmann Model Consistency 22

Page 23: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

class Person { .. }

class Course {

Person teacher = new Person(“Jim”);

Person student = new Person(“John”);

}

Example: Rename Refactorings in Programs

TU Dresden, Prof. U. Aßmann Model Consistency 23

Definition

Reference (Use)

Refactor the name Person to Human:

class Human { .. } class Course { Human teacher = new Human(“Jim”); Human student = new Human(“John”); }

Page 24: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Refactoring

Ø  Refactoring works always in the same way: Ø  Change a definition Ø  Find all dependent references Ø  Change them Ø  Recurse handling other dependent definitions

Ø  Refactoring can be supported by tools Ø  The Use-Def-Use-graph forms the basis of refactoring tools

Ø  However, building the Use-Def-Use-Graph for a complete program costs a lot of space and is a difficult program analysis task Ø  Every method that structures this graph benefits immediately the

refactoring Ø  either simplifying or accelerating it

Ø UDUGs are large •  Efficient representation important

TU Dresden, Prof. U. Aßmann Model Consistency 24

Page 25: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Further Representations

From the ASG or an UDUG, more graph-based program representations can be derived

Ø  Control-flow Analysis -> Control-Flow Graph (CFG), Call graph (CLG) •  Records control-flow relationships

Ø  Data-Flow Analysis -> Data-Flow Graph (DFG) or Value-Flow Graph (VFG) •  Records flow relationships for data values

The same remarks holds for graphic specifications Ø  Hence, all specifications are graph-based!

TU Dresden, Prof. U. Aßmann Model Consistency 25

.......

CFG, CLG

.......

VFG (DFG)

.......

ASG (UDG)

Page 26: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Control-Flow Graphs

Ø  Describe the control flow in a program Ø  Typically, if statements and switch statements split control flow

Ø  Their ends join control flow Ø  Control-Flow Graphs resolve symbolic labels

Ø  Perform name analysis on labels

Ø  Nested loops are described by nested control flow graphs

TU Dresden, Prof. U. Aßmann Model Consistency 26

while

if

print a

a+=5;

print a++

return

Page 27: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Simple (Flow-Insensitive) Call Graph (CLG)

Ø  Describe the call relationship between the procedures Ø  Interprocedural control-flow analysis performs name analysis on called

procedure names

TU Dresden, Prof. U. Aßmann Model Consistency 27

main = procedure () { array int[] a = read(); print(a); quicksort(a); print(a); } quicksort = procedure(a: array[0..n]) { int pivot = searchPivot(a); quicksort(a[0], a[pivot-1]); quicksort(a[pivot+1,n]); }

quicksort

main

print

read

searchPivot

Page 28: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

(Flow-Insensitive) Call Graph (CLG)

Ø  Describe the call relationship between the procedures including call sites Ø  Flow-insensitive Ø  Flow-sensitive versions consider the control flow graph

TU Dresden, Prof. U. Aßmann Model Consistency 28

quicksort

main

print

read 2

1

1 2

searchPivot

Page 29: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Data-Flow Graphs (DFG)

Ø  A data-flow graph (DFG) aka value-flow graph (VFG) describes the flow of data through the variables Ø  DFG are based on control-flow graphs

Ø  Building the data-flow graph is called data-flow analysis Ø  Data-flow analysis is often done by abstract interpretation, the symbolic

execution of a program at compile time

TU Dresden, Prof. U. Aßmann Model Consistency 29

while

if

print a

a=a+5;

print a++

b=a

a=0

Page 30: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Inheritance Analysis: Building an Inheritance Tree or Inheritance Lattice

Ø  A lattice is a partial order with largest and smallest element Ø  Inheritance hierarchies can be generalized to inheritance lattices Ø  An inheritance analysis builds the transitive closure of the

inheritance lattice

TU Dresden, Prof. U. Aßmann Model Consistency 30

Don’t Know

Man Woman

Undefined

Object

Person

Inheritance

Page 31: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

UML Graphs

Ø  All diagram sublanguages of UML generate internal graph representations Ø  They can be analyzed and checked with graph techniques Ø  Graphic languages, such as UML, need a graph parser to be recognized, or a

specific GUI who knows about graphic elements

Ø  Hence, graph techniques are an essential tool of the software engineer

TU Dresden, Prof. U. Aßmann Model Consistency 31

Page 32: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Remark: All Specifications Have a Graph-Based Representation

Ø  Texts are parsed to abstract syntax trees (AST) Ø  Graphics are parsed by GUI or graph parser to AST also Ø  Through name analysis, they become abstract syntax graphs (ASG) Ø  Through def-use-analysis, they become Use-def-Use Graphs (UDUG) Ø  Control-flow Analysis -> CFG, CLG Ø  Data-Flow Analysis -> DFG

TU Dresden, Prof. U. Aßmann Model Consistency 32

.......

AST

.......

ASG

.......

UDUG

.......

CFG, CLG

.......

DFG

Page 33: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.3 TYPES OF GRAPHS IN SPECIFICATIONS

Lists, Trees, Dags, Graphs

Structural constrains on graphs

(background information)

TU Dresden, Prof. U. Aßmann Model Consistency 33

Page 34: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Modeling Graphs on Two Abstraction Levels

Ø  In modeling, we deal mostly with directed graphs (digraphs) representing unidirectional relations Ø  lists, trees, dags, overlay graphs, reducible (di-)graphs, graphs

Ø  There are two different abstraction levels; we are interested in the logical level: Ø  Logical level (conceptual, abstract, often declarative, problem oriented)

Ø  Methods to specify graph and algorithms on graphs: Ø Relational algebra Ø Datalog, description logic Ø Graph rewrite systems, graph grammars Ø Recursion schemas

Ø  Physical level (implementation level concrete, often imperative, machine oriented) Ø  Representations: Data type adjacency list, boolean (bit)matrix,

BDD Ø  Imperative algorithms Ø  Pointer based representations and algorithms

TU Dresden, Prof. U. Aßmann Model Consistency 34

Page 35: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Essential Graph Definitions

Ø  Fan-in Ø  In-degree of node under a certain relation Ø  Fan-in(n = 0): n is root node (source) Ø  Fan-in(n) > 0: n is reachable from other nodes

Ø  Fan-out Ø  Out-degree of node under a certain relation Ø  Fan-out(n) = 0: n is leaf node (sink) Ø  An inner node is neither a root nor a leaf

Ø  Path Ø  A path p = (n1, n2,…,nk) is a sequence of nodes of length k

TU Dresden, Prof. U. Aßmann Model Consistency 35

Page 36: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Lists

Ø  One source (root) Ø  One sink Ø  Every other node has fan-in 1, fan-out 1

Ø  Represents a total order (sequentialization)

Ø  Gives Ø  Prioritization Ø  Execution order

TU Dresden, Prof. U. Aßmann Model Consistency 36

root

sink

Page 37: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Trees

Ø  One source (root) Ø  Many sinks (leaves) Ø  Every node has fan-in <= 1

Ø  Hierarchical abstraction: Ø  A node represents or abstracts

all nodes of a sub tree

Ø  Example Ø  SA function trees Ø  Organization trees (line organization)

TU Dresden, Prof. U. Aßmann Model Consistency 37

.......

.......

.......

root

sinks

Page 38: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Directed Acyclic Graphs

Ø  Many sources Ø  A jungle (term graph) is a dag with

one root Ø  Many sinks Ø  Fan-in, fan-out arbitrary Ø  Represents a partial order

Ø  Less constraints that in a total order

Ø  Weaker hierarchical abstraction feature Ø  Can be layered

Ø  Example Ø  UML inheritance dags Ø  Inheritance lattices

TU Dresden, Prof. U. Aßmann Model Consistency 38

.......

.......

.......

roots

sinks

Page 39: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Skeleton Trees with Overlay Graphs (Trees with Secondary Graphs)

Ø  Skeleton tree with overlay graph (secondary links) Ø  Skeleton tree is primary Ø  Overlay graph is secondary: “less important”

Ø  Advantage of an Overlay Graph Ø  Tree can be used as a conceptual hierarchy Ø  References to other parts are possible

Ø  Example Ø  XML, e.g., XHTML. Structure is described

by Xschema/DTD, links form the secondary relations

Ø  AST with name relationships after name analysis (name-resolved trees, abstract syntax graphs)

TU Dresden, Prof. U. Aßmann Model Consistency 39

.......

.......

.......

roots

sinks

Page 40: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Reducible Graphs (Graphs with Skeleton Trees)

Ø  A reducible graph is a graph with cycles, however, only between siblings Ø  No cycles between hierarchy levels

Ø  Graph can be “reduced” to one node Ø  Advantage

Ø  Tree can be used as a conceptual hierarchy

Ø  Example Ø  UML statecharts Ø  UML and SysML component diagrams Ø  Control-flow graphs of Modula, Ada, Java

(not C, C++) Ø  SA data flow diagrams Ø  Refined Petri Nets

TU Dresden, Prof. U. Aßmann Model Consistency 40

.......

.......

.......

roots

sinks

Page 41: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Reduction of a Reducible Graph

TU Dresden, Prof. U. Aßmann Model Consistency 41

B1

B2

B3

B4

B1a

B3a

B1a

B3a B1b

Page 42: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Layerable Graphs with Skeleton Dags

Ø  Like reducible graphs, however, sharing between different parts of the skeleton trees Ø  Graph cannot be “reduced” to one node

Ø  Advantage Ø  Skeleton can be used to layer the graph Ø  Cycles only within one layer

Ø  Example Ø  Layered system architectures

TU Dresden, Prof. U. Aßmann Model Consistency 42

.......

.......

.......

Page 43: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Wild Unstructured (Directed) Graphs

Ø  Wild, unstructured graphs are the worst structure we can get Ø  Wild, unstructured, irreducible cycles Ø  Unlayerable, no abstraction possible Ø  No overview possible

Ø  Many roots Ø  A digraph with one source is called flow graph

Ø  Many sinks Ø  Example

Ø  Many diagrammatic methods in Software Engineering

Ø  UML class diagrams

TU Dresden, Prof. U. Aßmann Model Consistency 43

.......

.......

.......

Page 44: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Strength of Assertions in Models

TU Dresden, Prof. U. Aßmann Model Consistency 44

List: strong assertion: total order

Graph: the worst case

Dag: still layering possible

Tree: still abstraction possible

Sequential

Partial order

Layered

Hierarchies

Unstructured

Ease of Understanding

Page 45: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Strength of Assertions in Models

Ø  Saying that a relation is Ø  A list: very strong assertion, total order! Ø  A tree: still a strong assertion: hierarchies possible, easy to think Ø  A dag: still layering possible, still a partial order Ø  A layerable graph: still layering possible, but no partial order Ø  A reducible graph: graph with a skeleton tree Ø  A graph: hopefully, some structuring or analysis is possible. Otherwise, it’s

the worst case

Ø  And those propositions hold for every kind of diagram in Software Engineering!

Ø  Try to model reducible graphs, dags, trees, or lists in your specifications, models, and designs Ø  Systems will be easier, more efficient

TU Dresden, Prof. U. Aßmann Model Consistency 45

Page 46: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Structuring Improves Worst Case

TU Dresden, Prof. U. Aßmann Model Consistency 46

List: strong assertion: total order

Graph: the worst case

Dag: still layering possible

Tree: still abstraction possible

Sequential

Partial order

Layered

Hierarchies

Unstructured

Structured Structured graph (reducible, skeleton dag)

Ease of Understanding

Unstructured Graph with analyzed features

Page 47: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.4 METHODS AND TOOLS FOR ANALYSIS OF GRAPH-BASED MODELS

TU Dresden, Prof. U. Aßmann Model Consistency 47

Page 48: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

The Graph-Logic Isomorphism

Ø  In the following, we will make use of the graph-logic isomorphism: Ø  Graphs can be used to represent logic

Ø  Nodes correspond to constants Ø  (Directed) edges correspond to binary predicates oder nodes (triple statements) Ø  Hyperedges (n-edges) correspond to n-ary predicates

Ø  Consequence: Ø  Graph algorithms can be used to test logic queries on graph-based specifications Ø  Graph rewrite systems can be used for deduction

TU Dresden, Prof. U. Aßmann Model Consistency 48

Victoria

Silvia

Carl Gustav

married

father

mother

married(CarlGustav,Silvia). married(Silvia, CarlGustav). father(CarlGustav,Victoria). mother(Silvia,Victoria).

CarlGustav is married to Silvia. Silvia is married to CarlGustav. CarlGustav is father to Victoria. Silvia is mother to Victoria.

Page 49: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Graphs and Fact Data Bases

Ø  Graphs can also be noted textually Ø  Graphs consist of nodes, relations Ø  Relations link nodes

TU Dresden, Prof. U. Aßmann Model Consistency 49

Ø  Fact data bases consist of constants (data) and predicates

Ø  Nodes of graphs can be regarded as constants, edges as predicates between constants (facts):

GustavAdolf

Adam

Sibylla

isParentOf

isParentOf

// Facts isParentOf(Adam,GustavAdolf). isParentOf(Adam,Sibylla).

// Triples Adam isParentOf GustavAdolf. Adam isParentOf Sibylla.

Page 50: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Queries on Graph-Based Models Make Implicit Knowledge Explicit

Ø  Since graph-based models are a mess, we try to analyze them Ø  Knowledge is either

Ø  Explicit, I.e., represented in the model as edges and nodes Ø  Implicit, I.e., hidden, not directly represented, and must be analyzed

Ø  Query and analysis problems try to make implicit knowledge explicit Ø  E.g. Does the graph have one root? How many leaves do we have? Is this

subgraph a tree? Can I reach that node from this node?

Ø  Determining features of nodes and edges Ø  Finding certain nodes, or patterns

Ø  Determining global features of the model Ø  Finding paths between two nodes (e.g., connected, reachable) Ø  Finding paths that satisfy additional constraints Ø  Finding subgraphs that satisfy additional constraints

TU Dresden, Prof. U. Aßmann Model Consistency 50

Page 51: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Queries for Checking Consistency (Model Validation)

Ø  Queries can be used to find out whether a graph is consistent (i.e., valid, well-formed) Ø  Due to the graph-logic isomorphism, constraint specifications can be phrased

in logic and applied to graphs Ø  Business people call these constraint specifications business rules

Ø  Example: Ø  if a person hasn't died yet, its town should not list her in the list of dead

people Ø  if a car is exported to England, steering wheel and pedals should be on the

right side; otherwise on the left

TU Dresden, Prof. U. Aßmann Model Consistency 51

Page 52: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.4.1 Layering Graphs: How to Analyze a System for Layers

Ø  With the Same Generation Problem Ø  How to query a dag and search in a dag Ø  How to layer a dag – a simple structuring problem

TU Dresden, Prof. U. Aßmann Model Consistency 52

Page 53: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Layering of Systems

Ø  To be comprehensible, a system should be structured in layers Ø  Several relations in a system can be used to structure it, e.g., the

Ø  Call graph: layered call graph Ø  Layered definition-use graph

TU Dresden, Prof. U. Aßmann Model Consistency 53

Ø  A layered architecture is the dominating style for large systems

Ø  Outer, upper layers use inner, lower layers (layered USES relationship)

Ø  Legacy systems can be analyzed for layering, and if they do not have a layered architecture, their structure can be improved towards this principle

Page 54: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Layering of Acyclic Graphs

Ø  Given any acyclic relation, it can be made layered Ø  SameGeneration analysis layers in trees or dags

Ø  Example: layering a family tree: Ø  Who is whose contemporary? Ø  Who is ancestor of whom?

TU Dresden, Prof. U. Aßmann Model Consistency 54

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

Carl Gustav

Page 55: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Pattern and Rules

Ø  Parenthood can be described by a graph pattern Ø  We can write the graph pattern also in logic:

isParentOf(Parent,Child1) && isParentOf(Parent,Child2)

Ø  And define the rule if isParentOf(Parent,Child1) && isParentOf(Parent,Child2) then sameGeneration(Child1,Child2)

TU Dresden, Prof. U. Aßmann Model Consistency 55

Parent

Child 1

Child 2

Parent

Child 1

Child 2

Page 56: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Impact of Rule on Family Graph

TU Dresden, Prof. U. Aßmann Model Consistency 56

CarlGustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

CarlGustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

Page 57: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Rule set “Same Generation“

Ø  Base rule: Beyond sisters and brothers we can link all people of same generation

Ø  Additional rule (transitive): Enters new levels into the graph

TU Dresden, Prof. U. Aßmann Model Consistency 57

Parent

Child 1

Child 2

Parent

Child 1

Child 2

Parent 1 Child 1

Parent 2 Child 2

Parent 1 Child 1

Parent 2 Child 2

Page 58: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Impact of Transitive Rule

TU Dresden, Prof. U. Aßmann Model Consistency 58

Carl Gustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

Page 59: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

”Same Generation” Introduces Layers

Ø  Computes all nodes that belong to one layer of a dag Ø  If backedges are neglected, also for an arbitrary graph

Ø  Algorithm: Ø  Compute Same Generation Ø  Go through all layers and number them

Ø  Applications: Ø  Compute layers in a call graph

Ø  Find out the call depth of a procedure from the main procedure Ø  Restructuring of legacy software (refactoring)

Ø  Compute layers of systems by analyzing the USES relationships (ST-I) Ø  Insert facade classes for each layer (Facade design pattern)

Ø  Every call into the layer must go through the facade Ø  As a result, the application is much more structured

TU Dresden, Prof. U. Aßmann Model Consistency 59

Page 60: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.4.2 SEARCHING GRAPHS – SEARCHING IN SPECIFICATIONS WITH DATALOG AND EARS

TU Dresden, Prof. U. Aßmann Model Consistency 60

Page 61: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

SameGeneration as a Graph Rewrite System

Ø  The rule system SameGeneration only adds edges. Ø  An edge addition rewrite system (EARS) adds edges to graphs

Ø  It enlarges the graph, but the new edges can be marked such that they are not put permanently into the graph

Ø  EARS are declarative Ø  No specification of control flow and an abstract representation Ø  Confluence: The result is independent of the order in which rules

are applied Ø Recursion: The system is recursive, since relation sameGeneration

is used and defined Ø Termination: terminates, if all possible edges are added, latest,

when graph is complete Ø  EARS compute with graph query and graph analysis

Ø  reachabilities of nodes Ø  Paths in graphs Ø  SameGeneration can be used for graph analysis

TU Dresden, Prof. U. Aßmann Model Consistency 61

Page 62: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Rule Systems in EARS and Datalog

Ø  Rule systems can be noted textually or graphically (DATALOG or EARS)

Ø  Datalog contains •  textual if-then rules, which test

predicates about the constants •  rules contain variables

TU Dresden, Prof. U. Aßmann Model Consistency 62

Child1

Parent

Child2

Child1

Parent

Child2

// conclusion sameGeneration(Child1, Child2) :- // say: "if" // premise isParentOf(Parent,Child1), isParentOf(Parent,Child2).

// premise if isParentOf(Parent,Child1) && isParentOf(Parent,Child2) then // conclusion sameGeneration(Child1,Child2)

Page 63: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Same Generation Datalog Program

TU Dresden, Prof. U. Aßmann Model Consistency 63

isParentOf(Adam,GustavAdolf). isParentOf(Adam,Sibylla). ..... if isParentOf(Parent,Child1), isParentOf(Parent,Child2) then sameGeneration(Child1, Child2). if sameGeneration(Parent1,Parent2), isParentOf(Parent1,Child1), isParentOf(Parent2,Child2) then sameGeneration(Child1, Child2).

Page 64: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Searching and Solving Path Problems is Easy With Datalog

TU Dresden, Prof. U. Aßmann Model Consistency 64

# A SMPP problem (searching for Single source a set of Multiple targets) descendant(Adam,X)? X={ Silvia, Carl-Gustav, Victoria, ....} # An MSPP problem (multiple source, single target) descendant(X,Silvia)? X={Walter, Adam, Alice} # An MMPP problem (multiple source, multiple target) ancestor(X,Y)? {X=Walter, Y={Adam} X=Victoria, Y={CarlGustav, Silvia, Sibylla, ...} Y = Adam, Walter, ... # Victoria, Madeleine, CarlPhilipp not in the set

Page 65: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

F-Datalog and OWL (Description Logic, DL)

Ø  F-Datalog and DL are special forms of typed binary Datalog (typed EARS) Ø  Only with unary (classes) and binary relations (relationships) Ø  Classes and objects as types, relationship types and relations Ø  Inheritance of classes and relationships Ø  Frame-based (like UML-CD) Ø  F-Datalog has Closed-World Assumption (CWA), i.e., treats incomplete information as FALSE

Ø  OWL (Web Ontology Language): Ø  Triple-, not frame-based - all knowledge is specified with triples Ø  OWL has a cleanly defined sublanguage hierarchy Ø  OWL has Open-World Assumption (OWA), i.e., treats incomplete information as TRUE

TU Dresden, Prof. U. Aßmann Model Consistency 65

Adam: Person

Victoria: Princess Madeleine:

Princess

Ralf: Person

Silvia: Person

Sibylla: Person

GustavAdolf: Person

Walter: Person

Alice: Person

Desiree: Person

Carl Gustav: King

Adam instanceOf Person. Sibylla instanceOf Person. GustavAdolf instanceOf Person. King isA Person. Princess isA Person. ... Adam parentOf GustavAdolf. Adam parentOf Sibylla. ...

Page 66: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Relational Algebra (SQL)

Desciption Logic (OWL)

F-Datalog (with recursion; SQL3) SPARQL F-Datalog with negation and recursion

F-Datalog, DL, OCL, and EARS: Extended Relational Algebra

Ø  F-Datalog, DL and EARS correspond to relational Algebra with recursion (see lecture on data bases). Ø  SQL has no recursion, SQL-3 has Ø  Negation can be added Ø  F-Datalog is a simple variant of Prolog

Ø  DL languages: Ø  OWL (ontology web language) Ø  SPARQL (SQL like QL for RDFS)

Ø  OCL does not have transitive closure, but iteration

TU Dresden, Prof. U. Aßmann Model Consistency 66

OCL

Page 67: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Datalog, DL, OCL, and EARS: Extended Relational Algebra

TU Dresden, Prof. U. Aßmann Model Consistency 67

Relational Algebra (SQL)

F-Datalog (with recursion) (SQL3, SPARQL)

F-Datalog with negation and recursion

"Business rules”

Description Logic (OWL)

decidable

OCL OCL

Prolog with negation and recursion

classes = unary

predicates

Binary F-Datalog (EARS) binary

predicates

Page 68: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Application Areas of Datalog, DL, OCL, and EARS

Ø  See the new language F-OML [Baladan/Kifer], in which UML-CD are interpreted as graphs and queried with F-Datalog

Ø  Graph query problems (searching graphs) Ø  Reachability of nodes (transitive closure, SSPP, etc.)

Ø  Consistency checking of graph-based specifications Ø  Name analysis (building def-use graphs) Ø  Data analysis Ø  Program analysis

Ø  Building control-flow graphs Ø  Value-flow analysis

Ø  Model analysis (UML, OWL)

Ø  Structurings and algorithms on structured graphs Ø  Layering of system relations Ø  Reducibility Ø  Strongly connected components

Ø  Specification of contracts for procedures and services Ø  Prover can statically prove the validity of the contract

TU Dresden, Prof. U. Aßmann Model Consistency 68

Page 69: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.4.3 EXAMPLE FOR MODEL VALIDATION: CHECKING UML DIAGRAMS WITH F-DATALOG

Ø Step 1: encode the diagram into a Datalog or DL fact base Ø Step 2: define integrity constraint rules Ø Step 3: let the rules run

TU Dresden, Prof. U. Aßmann Model Consistency 69

Page 70: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example: The Domain Model of the Web-Based Course System

TU Dresden, Prof. U. Aßmann Model Consistency 70

Pupil Education Teacher

name description lastChanged

CourseSatus

beginDate endDate ready resultProcent

ModuleStatus

endDate ready

QuestionStatus

status

Question

category text

Course

name description lastChanged changedBy active

name description lastChanged changedBy active

Module

Course Owner

Course Modifier

Link

name description URL

Answer Alternative

category text

{OR}

{OR}

teacher

hasCourse

hasPupil

hasModule

linksTo

linksTo

linksTo

reads

Page 71: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Searching with F-Datalog or DLQueries on UML Class Diagrams

TU Dresden, Prof. U. Aßmann Model Consistency 71

// Step 1: construct fact base: the UML class diagram // in Datalog fact syntax. // Object declarations: programming:Education. john:Person. mary:Person. lisp:Module // Edge fact declarations: teacher(programming,john). hasCourse(programming, lisp). hasPupil(programming,mary). hasModule(lisp,closures). // Step 2: construct integrity constraint rules reads(Person,Module) :- hasPupil(Person,E), hasCourse(E,C), hasModule(C,Module). // Step 3: let rules run: form and execute a query :- reads(mary, Module) // the answer >> Module = closures

Page 72: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example: Web Queries with Logic

Ø  The Web is a gigantic graph Ø  Pages are trees, but links create real graphs Ø  Links are a secondary structure which overlays the primary tree structure Ø  Graph algorithms and queries can be applied to the web

Ø  RDFS (resource description framework schema) is used as DDL Ø  a simple graph language for triple specifications Ø  classes, inheritance, inheritance on binary relations, expressions and

queries on binary relations Ø  SPARQL as query language (triple querying with SQL-like

language Ø  OWL adds inheritance analysis (subsumption analysis) Ø  Other experimental languages:

Ø  F-Datalog/Flora/XSB (M. Kifer, NY Stony Brook), Florijd (Freiburg) Ø  OntoBroker von Ontoprise.com:

http://www.ontoprise.de/deutsch/start/produkte/ontobroker/, based on F-Datalog

Ø  New languages are being developed Ø  In the European network REWERSE (www.rewerse.net)

Ø www.w3c.org

TU Dresden, Prof. U. Aßmann Model Consistency 72

Page 73: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.5 REACHABILITY QUERIES WITH TRANSITIVE CLOSURE IN F-DATALOG AND EARS

Ø  The Swiss-Knife of Graph Analysis

TU Dresden, Prof. U. Aßmann Model Consistency 73

Page 74: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Who is Descendant of Whom?

Ø  Sometimes we need to know transitive edges, i.e., edges after edges of the same color Ø  Question: what is reachable from a node? Ø  Which descendants has Adam?

Ø  Answer: Transitive closure calculates reachability over nodes Ø  It contracts a graph, inserting masses of edges to all reachable nodes Ø  It contracts all paths to single edges Ø  It makes reachability information explicit

Ø  After transitive closure, it can easily be decided whether a node is reachable or not Ø  Basic premise: base relation is not changed (offline problem)

TU Dresden, Prof. U. Aßmann Model Consistency 74

Page 75: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Transitive Closure as Datalog Rule System or EARS

Ø  Basic rule descendant(V,N) :- isChildOf(V,N).

Ø  Transitive rule (recursion rule) Ø  left recursive: descendant(V,N) :- descendant(V,X),isChildOf(X,N). Ø  right recursive: descendant(V,N) :- isChildOf(V,X), descendant

(X,N).

TU Dresden, Prof. U. Aßmann Model Consistency 75

Parent

Child

Parent

Child

Parent

Child

GrandCh Parent

Child

GrandCh

Page 76: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Impact of Basic Rule

TU Dresden, Prof. U. Aßmann Model Consistency 76

CarlGustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

CarlGustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

Page 77: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Impact of Recursion Rule

TU Dresden, Prof. U. Aßmann Model Consistency 77

CarlGustav

Victoria Madeleine

Ralf

Silvia

Sibylla

GustavAdolf

Walter

Alice

Desiree

Adam

Impact only shown for Adam, but is applied to other nodes too

Page 78: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

[S|M][S|M]PP Path Problems are Special Cases of Transitive Closure

Ø  Single Source Single Target Path Problem, SSPP: Ø  Test, whether there is a path from a source to a target

Ø  Single Source Multiple Target SMPP: Ø  Test, whether there is a path from a source to several targets Ø  Or: find n targets, reachable from one source

Ø  Multiple Source Single Target MSPP: Ø  Test, whether a path from n sources to one target

Ø  Multiple Source Multiple Target MMPP: Ø  Test, whether a path of n sources to n targets exists

Ø  All can be computed with transitive closure: Ø  Compute transitive closure Ø  Test sources and targets on direct neighborship

TU Dresden, Prof. U. Aßmann Model Consistency 78

Page 79: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Exercise: Railway Routes as Reachability Queries

Ø  Base (Facts): Ø  directlyLinked(Berlin, Potsdam). Ø  directlyLinked(Potsdam,Braunschweig). Ø  directlyLinked(Braunschweig, Hannover).

Ø  Define the predicates Ø  linked(A,B) Ø  alsoLinked(A,B) Ø  unreachable(A,B)

Ø  Answer the queries Ø  linked(Berlin,X) Ø  unreachable(Berlin, Hannover)

TU Dresden, Prof. U. Aßmann Model Consistency 79

Page 80: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Application: Inheritance Analysis as Reachability Queries

Ø  Base (Facts): Ø  class(Person). class(Human). class(Man). class(Woman). Ø  extends(Person, Human). Ø  extends(Man,Person). Ø  extends(Woman,Person).

Ø  Define the predicates Ø  superScope(A,B) :- class(A), class(B), isA(A,B). Ø  transitiveSuperScope(A,B) :- superScope(A,C),

transitiveSuperScope(C,B).

Ø  Answer the queries Ø  ? transitiveSuperScope(Man,X) Ø  >> {X=Person,X=Human} Ø  ? transitiveSuperScope(Woman,Y) Ø  >> {Y=Person,Y=Human}

TU Dresden, Prof. U. Aßmann Model Consistency 80

Page 81: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Operator Transitive Closure

Ø  Transitive closure can be defined as higher-order Operator (Skeleton): Operator *<rel,baseRel>(A,B) = { rel(A,B) :- baseRel(A,B). rel(A,B) :- rel(A,C),baseRel(C,B).

Ø  With that holds:

Ø  transitiveSuperScope(A,B) :- isA*(A,B).

Ø  Operator positive transitive closure: Operator +<rel,baseRel>(A,B) = { rel(A,B) :- baseRel(A,C), baseRel(C,B). rel(A,B) :- rel(A,C),baseRel(C,B).

Ø  With that holds: Ø  realSuperClass(A,B) :- isA+(A,B).

TU Dresden, Prof. U. Aßmann Model Consistency 81

Page 82: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Cost of Transitive Closure

Ø  Transitive closure (TC) has many implementations Ø  Naive: multiplication of boolean matrices O(n3) Ø  Multiplication of boolean matrices with Russian Method is

O(n2.4) Ø  Nested-loop joins from relational algebra: O(n3)

Ø Gets better with semi-naive evaluation, hashed joins, semi-joins, and indices Ø  Munro/Purdue algorithm is almost linear, but costs space

TU Dresden, Prof. U. Aßmann Model Consistency 82

Page 83: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Transitive Closure and Several Relations

Ø  Transitive closure can work on several relations Ø  If we want to know, whether a certain node is reachable under

several relations Ø  Compute transitive closure on all of them Ø  Test neighbor ship directly

Ø  This delivers an implementation of the existential quantifier for logic

TU Dresden, Prof. U. Aßmann Model Consistency 83

Page 84: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Central Theorem of Datalog/DL/EARS

Ø  Any Datalog program or EARS graph rewrite system can be transformed into an equivalent one without recursion Ø  And only applies the operator Transitive Closure Ø  (The transitive closure uses direct recursion, but encapsulates it)

Ø  What does this mean in practice? (Remember, Datalog/EARS can be used to specify consistency constraint on graph-based specifications)

TU Dresden, Prof. U. Aßmann Model Consistency 84

Page 85: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Ex.: SameGeneration as Non-Recursive System

Ø  Basic rule as before

Ø  Additional non-recursive rule (descendant is transitive closure of isChildOf)

TU Dresden, Prof. U. Aßmann Model Consistency 85

Parent

Child 1

Child 2

Parent

Child 1

Child 2

Parent 1

Child 2

Desc

isChildOf

isChildOf

isChildOf

isChildOf

descendant (isChildOf[n])

isChildOf

Child 1

isChildOf

Parent 1

Child 2

Desc

descendant (isChildOf[n])

isChildOf

Child 1

isChildOf

Page 86: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Applications of Graph Reachability in Consistency Checking

Ø  Corollary: To solve an arbitrary reachability problem, use a non-recursive query and the operator TransitiveClosure.

Ø  Consequence: should a graph-based specification be checked on consistency (by evaluation of consistency constraints), Ø  it can be done with non-recursive Datalog query and the operator

TransitiveClosure Ø  And solved with the complexity of a good TransitiveClosure algorithm

Ø  Precondition: the input graphs are fix, i.e., do not change (static problem)

Ø  Since the relation is one of the qualities of the world this is a central problem of computer science and IT Ø  Similar to searching and sorting

TU Dresden, Prof. U. Aßmann Model Consistency 86

Page 87: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Dynamic Graph Reachability and its Applications

Ø  The Reps/Ramalinguan Checking Theorem: (1997): Ø  An online analysis and constraint-checking problem is a problem that is

specified by Datalog, EARS, or definite set constraints, in which the basic relations are changed online (dynamic graph reachability problem)

Ø  An online analysis problem can be reduced to context-sensitive graph reachability resp. dynamic transitive closure

Ø  and be computed in O(n3) (cubic barrier problem) Ø  Applies to many problems in modeling, requirement analysis,

design consistency: Ø  If you can reduce a consistency or structuring problem to static or dynamic

graph reachability, you have almost won since Datalog and transitive closure are powerful tools

TU Dresden, Prof. U. Aßmann Model Consistency 87

Page 88: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Generic Datalog Queries

Ø  Transitive closure is a general graph operator Ø  Computing reachability Ø  Can be applied generically to all relations!

Ø  Many other Datalog rule systems are also generic operators Ø  sameGeneration Ø  stronglyConnectedComponents Ø  dominators

Ø  And that’s why we consider them here: Ø  They can be applied to design graphs Ø  Is class X reachable from class Y? Ø  Show me the ancestors in the inheritance graph of class Y Ø  Is there a cycle in this cross-referencing graph?

TU Dresden, Prof. U. Aßmann Model Consistency 88

Page 89: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Ex. The Query Language TGreQL

Ø  Prof. J. Ebert U Koblenz

TU Dresden, Prof. U. Aßmann Model Consistency 89

From caller, callee: V{Method} With caller ( ß {isStatementIn} [ ß {isReturnValueOf} ] ß {isActualParameterOf} * ß {isCalleeOf} ) + Report caller.name as „Caller“ callee.name as „Callee“

Caller Callee

main System.out.println

main compute

main twice

main add

compute twice

compute add

•  * Transitive closure operator •  + positive transitive closure •  ß navigation direction •  [] optional path •  ( ) sequence of paths or edges •  | alternative path

Page 90: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

12.6 APPLICATION: CONSISTENCY CHECKING OF GRAPH-BASED MODELS

When a specification becomes big...

TU Dresden, Prof. U. Aßmann Model Consistency 90

Page 91: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example 1: Consistency Checking for Car Specifications

Ø  Car data specifications in the MOST standard Ø  Thousands of parts, described for an entire supplier industry Ø  Many inconsistencies possible Ø  Due to human errors

Ø  Global variants of the cars must be described Ø  Examples of context conditions for global variants of cars:

Ø  The problem of English cars: A steering wheel on the right implies accelerator, brake, clutch on the right

Ø  Automatic gears: an automatic gear box requires an automatic gear-shift lever

TU Dresden, Prof. U. Aßmann Model Consistency 91

Page 92: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

First Idea

Ø  Define a context free grammar for the car data Ø  From that, derive a XML schema for the car data

Ø  Enrich the grammar nonterminals with attributes Ø  Parse the data and validate it according to its context free structure

TU Dresden, Prof. U. Aßmann Model Consistency 92

Page 93: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Second Idea

Ø  Analyze consistency of the specifications by regarding them as graphs

Ø  Check definition criterion (name analysis) Ø  “is every name I refer to defined elsewhere”?

Ø  Analyze layers with SameGeneration Ø  How many layers does my car specification have? Ø  Is it acyclic?

Ø  Write a query that checks the consistency global variants Ø  If the car is to be exported to England, the steering wheel, the pedals should

be on the right side Ø  If the car has an automatic gear box, it must have an automatic gear-shift

lever

TU Dresden, Prof. U. Aßmann Model Consistency 93

Page 94: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Third Idea: Use Logic Language

Ø  OWL (description logic) can be used for consistency constraints, also of car specifications Ø  Result: an ontology, a vocabulary of classes with consistency constraints Ø  OWL engines (RACER, Triple) can evaluate the consistency of car

specifications Ø  Ontologies can formulate consistency criteria for an entire supplier chain

[Aßmann2005] Ø Typed (F-Datalog) can be used for recursive consistency constraints

•  Ontoprise reasoner •  XSB F-Datalog plugin

TU Dresden, Prof. U. Aßmann Model Consistency 94

Page 95: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example 2: Consistency Checking of Tax Declarations

Ø  Task: you have been hired by the tax authorities. Write a program that checks the income task declarations on consistency

Ø  Represent the tax declarations with graphs. Ø  How many graphs will you get? Ø  How big are they? Ø  How much memory do you need at least?

TU Dresden, Prof. U. Aßmann Model Consistency 95

Page 96: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

First Idea

Ø  Write a context free grammar for the tax declarations Ø  From that, derive a XML schema

Ø  Enrich the grammar nonterminals with attributes Ø  Check context free structure of the tax declarations with the XML

parser (contextfree consistency) Ø  This is usually assured by the tax form

Ø  It is, however, nevertheless necessary, if the forms have been fed into a computer, to avoid feeding problems.

TU Dresden, Prof. U. Aßmann Model Consistency 96

Page 97: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Second Idea

Ø  Write queries that checks document-local, but global constraints Ø  Are there bills for all claimed tax reductions? Ø  Are the appendices consistent with the main tax document?

Ø  Global Constraints over all tax Declarations: Ø  Have all bills for all claimed tax reductions really been payed by the tax

payer? Ø  Is a reduction for a debt reduced only once per couple? Ø  ....

Ø  Write an OCL invariant specification for the tax UML class diagram that checks the constraints Ø  Use the Dresden OCL toolkit to solve the problem http://dresden-ocl.sf.net

TU Dresden, Prof. U. Aßmann Model Consistency 97

Page 98: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Third Idea: Use Ontology Language

Ø  OWL (description logic) can be used for consistency constraints, also of tax declarations Ø  Result: a tax ontology, a vocabulary of classes with consistency constraints Ø  OWL engines (RACER, Triple) can evaluate the consistency of tax

specifications Ø  Ontologies can formulate consistency criteria for an entire administrative

workflow [Aßmann2005] Ø Ontologies union a class specification (T-box) and an object base

(A-box) •  Classes are sets of objects •  Classes need not have a unique name (no unique name assumption) •  Objects can be members of several classes (no unique membership)

Ø Ontology services: •  Subsumption checking (is a class subclass to another class) •  Consistency checking (is an object member of several disjoint classes) •  Satisfiability checking (is a class not a subclass of the empty class (empty

set))

TU Dresden, Prof. U. Aßmann Model Consistency 98

Page 99: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example 3: UML Specifications in Software Engineering

Ø  Imagine a UML model of the Java Development Kit JDK. Ø  7000 classes Ø  Inheritance tree on classes Ø  Inheritance lattice (dag) on interfaces Ø  Definition-use graph: how big?

Ø  Task: You are the release manager of the new JDK 1.8. It has 1000 classes more. Ø  Ensure consistency please. - How?

TU Dresden, Prof. U. Aßmann Model Consistency 99

Page 100: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Ideas

Ø  Build up inheritance graphs and definition-use graphs Ø  in a database

Ø Use F-Datalog for inheritance analysis Ø Use OWL for inheritance analysis Ø  Analyse conditions such as

Ø  Depth of inheritance tree: how easy is it to use the library? Ø  Hot-spot methods and classes: Most-used methods and classes (e.g., String)

Ø Optimize them Ø  Does every class/package have a tutorial? Ø  Is every class containt in a roadmap for a certain user group? (i.e., does the

documentation explain how to use a class?)

TU Dresden, Prof. U. Aßmann Model Consistency 100

Page 101: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Example 3: Exam Enrollment

Ø  Check if a student can enroll to a lecture Ø  Check if a student has passed his master degree

TU Dresden, Prof. U. Aßmann Model Consistency 101

Page 102: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

First Idea

Ø  Store all basic claims data in the database Ø  Write all contrains and rules into code fragments and check (stored

procedures)

TU Dresden, Prof. U. Aßmann Model Consistency 102

Page 103: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Second Idea

Ø  Check all rules with Prolog or Datalog:

Ø  attendMEMax(STUDENTID,MEID,N):-setof(A,nr(A,STUDENTID,MEID), L), length(L, N).

Ø  attendAdditionalMax(STUDENTID,MEID,N):-setof(A,r(A,STUDENTID,MEID), L), length(L, N).

Ø  attendModulesMax(STUDENTID,L,IMAX):-setof(MEID,(attendMEMax(STUDENTID,MEID,N),N>=IMAX,member(MEID,L)),LIST).

Ø  attendModuleElementsMax(STUDENTID,L,IMAX,MAX):-setof(MEID,(attendMEMax(STUDENTID,MEID,N),N>=IMAX,member(MEID,L)),LIST),length(LIST, N),N>MAX.

Ø  recommendGradingValues(STUDENTID,[K1|[]],N):-if_then_elseME(me(K1,B),K1,B),if_then_elseMEPASS(p(STUDENTID,K1),Y,B,0),N is Y.

Ø  recommendGradingValues(STUDENTID,[K1|Rest],MIN):-recommendGradingValues(STUDENTID,Rest,X),if_then_elseME(me(K1,B),K1,B),if_then_elseMEPASS(p(STUDENTID,K1),Y,B,0),N is Y + X,N>=MIN,!.

TU Dresden, Prof. U. Aßmann Model Consistency 103

Page 104: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Third Idea: use OWL on domain model Example: The Domain Model of the Web-Based Course System

TU Dresden, Prof. U. Aßmann Model Consistency 104

Pupil Education Teacher

name description lastChanged

CourseSatus

beginDate endDate ready resultProcent

ModuleStatus

endDate ready

QuestionStatus

status

Question

category text

Course

name description lastChanged changedBy active

name description lastChanged changedBy active

Module

Course Owner

Course Modifier

Link

name description URL

Answer Alternative

category text

{OR}

{OR}

teacher

hasCourse

hasPupil

hasModule

linksTo

linksTo

linksTo

Page 105: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Consistency Checking on UML Class Diagrams with Description Logic

Ø  Step 1: encode the diagram into a Datalog/DL fact base Ø  Step 2: specify integrity constraint rules Ø  Step 3: let the rules run

TU Dresden, Prof. U. Aßmann Model Consistency 105

// Step 1: factbase teacher(programming,john). hasCourse(programming, lisp). hasPupil(programming, mary). hasModule(lisp,closures). linksTo(linkA, closures). linksTo(linkA, lisp). linksTo(linkA, q). // Step 2: integrity constraints specification consistent(Link,Course,Module,Question) :- linksTo(Link,Course) || linksTo(Link, Module) || linksTo(Link,Question).

// Step 3: consistency checking query :- consistent(linkA,lisp,closures,q) // answer: false

Page 106: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

Third Idea: Use Ontology Language

Ø  OWL (description logic) can be used for consistency constraints, also of UML domain models Ø  Result: a domain ontology, a vocabulary of classes with consistency

constraints about the domain Ø  OWL engines (RACER, Triple) can evaluate the consistency of such domain

specifications Ø  Ontologies can formulate consistency criteria for domain models of

applications and product lines [Aßmann2005]

TU Dresden, Prof. U. Aßmann Model Consistency 106

Page 107: 12) Validation of Graph-Based Models (Analysis and ...st.inf.tu-dresden.de/.../12-model-consistency.pdf · Ullman, J. D. Principles of Database and Knowledge Base Systems. Computer

The End: What Have We Learned

Ø  Graphs and Logic are isomorphic to each other Ø  Using logic or graph rewrite systems, models can be validated

Ø  Analyzed Ø  Queried Ø  Checked for consistency Ø  Structured

Ø  Applications are many-fold, using all kinds of system relationships Ø  Consistency of UML class models (domain, requirement, design models) Ø  Structuring (layering) of USES relationships

Ø  Logic and graph rewriting technology involves reachability questions

TU Dresden, Prof. U. Aßmann Model Consistency 107

Logic and edge addition rewrite systems are the Swiss army knifes of the validating modeler