Approach for Non-Invasive Graph Transformation in Java

chart an approach for non invasive model n.w
1 / 27
Embed
Share

Explore an innovative approach for non-invasive graph transformation in Java, involving custom annotation and transformation languages, along with a custom compiler. User experiences and demo insights included.

  • Java
  • Graph Transformation
  • Non-Invasive
  • Custom Compiler

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CHART: An Approach for Non Invasive Model Transformation IPA Spring Days, April 18th, 2012 CHART: An Approach for Non Invasive Graph Transformation Maarten de Mol1, Arend Rensink1, James J. Hunt2 1University of Twente, Netherlands 2Aicas GmbH, Karlsruhe, Germany

  2. Graphs Structured graphical diagram: nodes attributes directed edges multiplicity, ordered, . Node Node edge 1..* attribute attribute 2 CHART Apr 18, 2012

  3. Graph rules Pair of graphs: left-hand-side: matching right-hand-side: updating X X X X p o o 3 CHART Apr 18, 2012

  4. Graph rule application (1) X X X X p o o X X p o o X o 4 CHART Apr 18, 2012

  5. Graph rule application (2) p p X X X X X X p o o X X X o X X X X X X p o o X X X p p o 5 CHART Apr 18, 2012

  6. Overview Idea: embed graph transformation in Java. Our approach: custom annotation language custom transformation language (CHART) custom compiler (RDT) Demo: hashi puzzle. User experiences. Conclusions. 6 CHART Apr 18, 2012

  7. Observation Run-time data of an object oriented program: objects fields: references basic data Object Object reference data data 7 CHART Apr 18, 2012

  8. Observation Run-time data of an object oriented program forms a graph: objects nodes fields: references edges basic data attributes Node Node edge attribute attribute 8 CHART Apr 18, 2012

  9. Idea Use graph transformation to express manipulation of Java data. Compile graph transformation to Java code. Benefits: Java: General purpose programming language. GT: Special purpose transformation language. Requirements: Embed:arbitrarily mix Java code and GT code. Non invasive: user code does not have to be modified. Geared towards Javaprogrammers: intended users. Efficient: little or no performance loss compared to Java. 9 CHART Apr 18, 2012

  10. Approach Start point: Java program with OO data. Step 1: build graph view. Step 2: write graph rules. Step 3: compile rules into Java. End point: extended Java program. Java Program Graph View annotate refer to Extended Java Program Java Rules Graph Rules compile RDT Rule Driven Transforme CHARTER Training 10

  11. Step 1: build graph view Purpose of graph view: Select relevant data structures. Provide additional meta information. Custom annotation language. How should the graph rules manipulate data? Rely on user provided manipulation methods. Nodes: create, delete, match, visit all. Fields: add, remove, get one, set one, visit all, clear, replace, get size, membership, get index. Manipulate single elements only. Implementation can choose collection type freely. 11 CHART Apr 18, 2012

  12. Example (annotated node) @Node public classAuthor { private final String name; publicAuthor(String name) { this.name = name; } @NodeCreate(inits = { name }) public static Author create(String name) { return new Author(name); } @AttributeGet public String getName() { return this.name; } } 12 CHART Apr 18, 2012

  13. Example (annotated edge, 1) @Node public classBook extends Readable { private final List<Author> writtenBy; public List<Author> getWrittenBy() { return this.writtenBy; } } 13 CHART Apr 18, 2012

  14. Example (annotated edge, 2) @Edge(target = Author.class, isOrdered = true) public interfaceWrittenBy { @EdgeAdd public void addAuthor(int index, Author author); @EdgeGet public Author getAuthor(int index); @EdgeVisit public GraphVisitor.CONTINUE visitAuthors( GraphVisitor<Author> visitor) throws GraphException; @EdgeSize public int getNrAuthors(); } 14 CHART Apr 18, 2012

  15. Example (annotated edge, 3) public class Book implements WrittenBy { ... @Override public Author getAuthor(int index) { return getWrittenBy().get(index); } @Override public GraphVisitor.CONTINUE visitAuthors( GraphVisitor<Author> visitor) throws GraphException { return visitor.apply(getWrittenBy()); } ... } 15 CHART Apr 18, 2012

  16. Step 2: write graph rules. Custom transformation language: CHART. Mix of graph transformation and Java. Graph transformation influence: Rule based. Rule format: match -> update -> sequence. Declarative matching (LHS of rule). Simultaneous updating (RHS of rule).> sequence. Java influence: Textual Java-like syntax. Imperative control structure (sequence block). 16 CHART Apr 18, 2012

  17. Example (rule, 1) rule Author{} findRich(int price) { Author{} authors; match (authors) { foreach (Author author : authors) { Comic comic; author elementof comic.writtenBy; comic.price > price; } } return authors; } 17 CHART Apr 18, 2012

  18. Example (rule, 2) rule voidaddPicture(Comic comic, Picture picture) { int old_price; match () { comic.price > 1; } update let { Comic new_comic = new Comic(); } in { new_comic.contains = comic.contains + [picture]; new_comic.price = comic.price; new_comic.writtenBy = comic.writtenBy; comic.price = comic.price 1; old_price = comic.price; } return old_price; } 18 CHART Apr 18, 2012

  19. Example (rule, 3) rule voidaddPictures(Comic comic, Picture[] pictures) { sequence { if (pictures.size > 0) { try { addPicture(comic, pictures[0]); addPictures(comic, pictures[1:]); } } } } 19 CHART Apr 18, 2012

  20. Step 3: compile graph rules. RDT: Rule Driven Transformer. Written in Java. Steps: Analyze annotations (reflection). Parse rules into internal representation (Antlr). Optimize. Produce code. 20 CHART Apr 18, 2012

  21. Demo: hashi puzzle 21 CHART Apr 18, 2012

  22. Demo: hashi puzzle 22 CHART Apr 18, 2012

  23. Demo: hashi puzzle 23 CHART Apr 18, 2012

  24. Experiences Technology has been applied successfully in CHARTER project: Aicas (JamaicaVM). Atego (ArtisanStudio). Chalmers (KeY). Observations of Aicas: More concise: reported 5-10 times less lines of code. Easier to maintain and adapt. Easy to experiment with different algorithms. No efficiency loss. With respect to old Java algorithm. 24 CHART Apr 18, 2012

  25. Conclusions RDT allows graph transformation to be embedded in Java: Embed Non invasive Geared towards Java programmers Efficient 25 CHART Apr 18, 2012

  26. Conclusions RDT allows graph transformation to be embedded in Java: Embed Non invasive (requires gluing code ) Geared towards Java programmers Efficient (more experiments needed) 26 CHART Apr 18, 2012

  27. Questions 27 CHART Apr 18, 2012

More Related Content