a tester specification code translator using ontology and xml/xslt technologies

36
A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies The 1 st Malaysian Software Engineering Conference 13 Dec 2005 Lim Lian Tze, Tang Enya Kong and Zaharin Yusoff Computer Aided Translation Unit School of Computer Sciences Universiti Sains Malaysia Penang, Malaysia

Upload: darrin

Post on 05-Jan-2016

39 views

Category:

Documents


1 download

DESCRIPTION

A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies. The 1 st Malaysian Software Engineering Conference 13 Dec 2005 Lim Lian Tze, Tang Enya Kong and Zaharin Yusoff Computer Aided Translation Unit School of Computer Sciences - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

The 1st Malaysian Software Engineering Conference

13 Dec 2005

Lim Lian Tze, Tang Enya Kong and Zaharin Yusoff

Computer Aided Translation UnitSchool of Computer Sciences

Universiti Sains MalaysiaPenang, Malaysia

Page 2: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Outline of Presentation

• Problem Background• Program Translators & Code Generation• Design of Translation Engine

– Overall Strategy– Test Domain Ontology– Generic Representation– Parser Module– Generator Module

• Conclusion

With Simple

(Dummy) Examples

in 2 Languages

Page 3: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Problem Background

Page 4: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Project Background

• Test equipment from different vendors different tester language syntax

– Structures and constructs– Names of special entities (test keywords)

• Developing same tests for equipment from different vendors by hand is time-consuming, tiresome and error-prone

Page 5: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Dummy Code Example

• Different Syntax– Language A: C-like– Language B: Lisp-like– reserved keywords

• Different Test Keywords– Test schema types– Parameter names– Enumeration values

(>2 languages in actuality)

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

Language A

Language B

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

Page 6: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Two Requirements

• “Syntactic”– Grammars– For parsing: use CFG– For generation: use XSLT template

• “Semantic”– Test Keywords (names of test schemas, bindings,

enumeration values)– Use ontology

Page 7: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Objectives

To develop a translation engine prototype that can

• Generate tester-specifications for different vendors, based on a generic language syntax

• Reverse engineer vendor-specific tester syntax to generic language syntax

Page 8: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Program Translators and Code Generation

Page 9: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Program Generators

• Automates creation of repetitive code

• Commonly encountered and widely used– Web page creation (ASP, PHP, JSP…)– SQL scripts– Documentation, code snippets (or whole classes) by CASE tools– Example program generator: Jostraca (http://www.jostraca.org)

• Requires systematic process of understanding application domains, and building software tools in that domain (Cleaveland 2001)

o Cleaveland, J. C. Program Generators with XML and Java. Prentice-Hall PTR, New Jersey, 2001.

Page 10: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Code Generation Model

• HOW to generate– Output text boilerplates or templates

• WHAT to generate– A declarative model– Needs to be “discovered” from a existing platform-

specific test program

Page 11: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Design of Translation Engine

Page 12: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

lang. Blang. ALanguage for vendor 1

Language for vendor n

Language for vendor 2

Analysis (parsing)

Overview

Test Specs inGeneric Representation

Generation Modules

Parser Modules

Synthesis (generation)

Test DomainOntology

n platforms 2n modules

Page 13: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

(This won’t work very well)

Test specs in lang. A

Test specs in lang. B

Test specs in lang. C

Test specs in lang. D

n platforms n(n-1) modules

Page 14: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Generic Representation Scheme

• The “pivot” in our architecture

• Needs platform-specific knowledge, configuration files and settings for analysing/generating

How to store/represent this knowledge?

How to store/represent this knowledge?

Page 15: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Test Domain Ontology

Page 16: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Ontology

• “Explicit formal specifications of the terms in the domain and relations among them” (Gruber 1993)

– To share common understanding of the structure of information– To enable reuse of domain knowledge– To separate domain knowledge from operational knowledge

• Taxonomy – categorisation of concepts– OOP: focus on methods– Ontology: focus on data structure (Noy & McGuiness 2001)

– Semantic information: properties, restrictions

o Gruber, T. “A Translation Approach to Portable Ontology Specification”, Knowl edge Acquisition, 5(2), 1993, pp. 199-220.o Noy, N. F. and McGuiness, D. L. “Ontology Development 101: A Guide to Creating Your First Ontology”, Technical

Report SMI-2001-0880, Stanford Medical Informatics, Stanford University, Stanford, 2001.

Page 17: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Test Domain Ontology

• To aid our understanding of the domain (in the early days)

• To provide a model for the generic language

• To specify platform-specific constraints, configurations etc

• Protégé — tool for:

– ontology editor

– knowledge acquisition

o Protégé. “The Protégé Ontology Editor and Knowledge Acquisition System”, http://protege.stanford.edu/, 2005.

Page 18: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Key Concepts

• Platform– Code templates required for

generation– Test specs file extensions– Other platform-specific formatting

• Test_Template– Instances =

test_template_instance or define-instance blocks

– has key-value Bindings for each test-instance

• Enum– Enumeration values for some

types of bindings

Page 19: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Key Concepts (cont’d)

• Test_Template, Binding, Enum have translations– “translations” of keywords on different platforms

• No translation schema or parameter unavailable on target platform

Keyword TypeExample Keyword

(Generic)

Platform-specific Translation

Platform Equiv. String

Test template / schema

sc1A schema1

B template1

Binding Bind1A binding1

B param1

Enum BIND1_NOA 0

B 0, “No”

Page 20: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Role of the Ontology

• Test_Template, Binding– Instances correspond to code blocks in test spec files– Represented generically by an XML file

• Platform, Enum, hasTranslation– “Configuration settings”– Stored as OWL ontology file– Can be accessed/queried via API (e.g. Jena/RDQL for

Java)

o JENA – A Semantic Web Framework for Java, HP Labs. http://jena.sourceforge.net/, 2005.

Page 21: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Generic Representation Schema

Page 22: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

XML as Generic Representation Schema

• Based on key concepts in Test Domain Ontology• Benefits of using XML:

– Portable– Large range of widely available manipulation tools– Can be converted to various formats and outputs

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

<test> <name>t1</name> <schema>sc1</schema> <binding name = "Bind1" enum="true" >BIND1_NO</binding> <binding name = "Bind2"> operation1</binding> <binding name = "Bind3"> <value>-0.05</value> <value>0</value> <value>0.05</value> </binding></test>

Language A

Language B Generic

Page 23: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

The Translator

Page 24: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Translator Modules

Translator

ParserModule

GeneratorModule

test specs ingeneric

representation

Test DomainOntology

output files(target

platform)

input files(source

platform)

Page 25: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Example: Translating from Language A to Language B

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

Page 26: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

The Parser

Page 27: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Parser Generation from Context Free Grammar (CFG)

• Parse and analyse platform-specific test specifications– well-formed – context free

CFG (with parser actions)• JavaCC: a parser generator

– generates Java classes from high-level grammar specifications

o JavaCC. “Java Compiler Compiler (JavaCC) - The Java Parser Generator”,https://javacc.dev.java.net/, 2005.

Page 28: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Example JavaCC Source File

A.jj (CFG specification for Language A)

void Start( Element testspecs ):{ TestInstance test; }{

( test = TestBlock() { ... process test object ... } )* <EOF>

}

TestInstance TestBlock():{ TestInstance test = new TestInstance(); String s; }{

<KW_TESTINST> s = Head() { test.setName( s ); }TBody( test ) Tail() { return test; }

}

String Head():{ Token t; }{ t = <ID> <OBRACE> { return t.image; } }

void Tail():{}{ <CBRACE> <SEMICLN> }

void TBody(): ...

Java Source filesfor Lang. A Parser

JavaCC

Page 29: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Parser Module

Syntax-directed parsing

Filtering* & keyword

translationXML writer

Example Parsing Process

inputplatformspecific

test specs

Platform-specifictest instances &

segments

Filtering + keyword translation(specific

generic)

GenericTest Specs

(XML)

Test SpecsOntology

*Filtering:• Discard test instances with non-generic schemas• Discard non-generic parameters

test_template_instance t1 schema1 { binding1 = 0, binding2 = "operation1", binding3 = "-0.05, 0, 0.05"}

name: t1schema: schema1bindings:

name Value(s)binding1 0binding2 operation1binding3 -0.05;0;0.05

name: t1schema: sc1bindings:

name isEnum multiple Value(s)

values

Bind1 Y N 0Bind2 N N operation1Bind3 N Y -0.05;0;0.05

Platform-A specific object Platform-independent object

<test> <name>t1</name> <schema>sc1</schema> <binding name = "Bind1" enum="true">BIND1_NO </binding> <binding name = "Bind2"> operation1</binding> <binding name = "Bind3"> <value>-0.05</value> <value>0</value> <value>0.05</value> </binding></test>

Input file (language A)test.A

Platform-independenttest.xml

Page 30: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

The Generator

Page 31: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Code Generation from XML with XSLT

• XML plain text output• XSL stylesheets as “boilerplates” – natural choice• Example XSL Stylesheet snippet (much simplified!):

<test> <name>t1</name> <schema>template1</schema> ... <binding name = "param2"> operation1 </binding> ...</test>

<xsl:template match = "test">(define-instance <xsl:value-of select = "name" /> <xsl:text>&#x20;</xsl:text> <xsl:value-of select = "schema" /> <xsl:apply-templates select="binding" />)</xsl:template>

<xsl:template match="binding"> <xsl:text> </xsl:text>(value <xsl:value-of select="@name" /> <xsl:text>&#x20;</xsl:text> <xsl:value-of select="." />) <xsl:text>&#xa;</xsl:text></xsl:template>

define-instance t1 template1 ( ... (define param2 operation1) ...)

B.xsl (XSL Stylesheet for Language B)

Page 32: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Generation Module

Example Generation Process

input DOMtree

Input generic XMLfile XML

parsertranslatekeywords

XSLTtransformation

intermediateDOM tree (with

platform-specificlabels)

Test SpecsOntology

outputboilerplates

outputplatform-specific

test specs

<test> <name>t1</name> <schema>sc1</schema> <binding name = "Bind1" enum="true">BIND1_NO </binding> <binding name = "Bind2"> operation1</binding> <binding name = "Bind3"> <value>-0.05</value> <value>0</value> <value>0.05</value> </binding></test>

<test> <name>t1</name> <schema>sc1</schema> <binding name = "Bind1" enum="true">BIND1_NO</binding> <binding name = "Bind2"> operation1</binding> <binding name = "Bind3" multiple="true"> <value>-0.05</value> <value>0</value> <value>0.05</value> </binding></test>

Platform-independent DOM tree

<test> <name>t1</name> <schema>template1</schema> <binding name = "param1" enum="true" str="No"> 0</binding> <binding name = "param2"> operation1</binding> <binding name = "param3" multiple = "true"> <value>-0.05</value> <value>0</value> <value>0.05</value> </binding></test>

DOM tree with platform B-specific keywords

define-instance t1 template1 ( (define param1 0 :choice "No") (define param2 operation1) (define param3 -0.05 0 0.05))

Platform-independenttest.xml

Output file (language B)test.B

Page 33: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Conclusion

Page 34: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Conclusion

• A reusable framework for code translation between platform-specific formats/languages

• Parse-Generate c.f. interlingual machine translation – a.k.a. abstract-reimplement (Waters 1988)

– O(n) modules instead of O(n2)• Ontology as knowledge repository

– Jena API, RDQL for querying ontology• Parser Generators

– Context-free grammar (CFG) specifications– JavaCC generates parser classes

• XML and XSL Transformations– XSLT templates as output templates– JDOM, SAXON to aid XML parsing and XSLT execution.

o Waters, R. C. “Program Translation via Abstraction and Reimplementation”, IEEE Transactions on Software Engineering, 14(8), 1988, pp. 1207-1228.

Page 35: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Thank you for listening!

Page 36: A Tester Specification Code Translator Using Ontology and XML/XSLT Technologies

Ideas for refinement

• Ontology:– Define more schema types– Model other types of code blocks in ontology

• Translation engine:– Handle platform-specific extensions– Extend to 3rd (or more) language

• Understanding of Domain is Crucial