A Demo of OptimixJ

  • 格式:pdf
  • 大小:29.07 KB
  • 文档页数:5

A Demo of OptimixJUwe Aßmann Johan LövdahlResearch Center for Integrational Software Engineering (RISE)Programming Environments Lab (PELAB),Linköpings Universitet,Sweden{uweas|jolov}@ida.liu.seAbstract.OptimixJ is a graph rewrite tool that generates Java code from rewrite specifications.Java classes are treated as graph schemas,enabling OptimixJ to extend legacy Java applications through code weaving in a simple way.The demo shows how OptimixJ has been used to implement graph rewriting for RDF/XML documents in the context of the Semantic Web.1Introduction to OptimixJOptimixJ [1]lets the user specify graph transformations in a declarative,Datalog style language .From these transformation specifications (also called rewrite systems )Opti-mixJ generates Java code that navigates/modifies Java objects.OptimixJ specifications consists of a data model (i.e.the type graph)and one or several graph rewrite modules.Java classes Rewrite moduleData modelRewrite specification Fig.1.OptimixJ uses the data definition parts of Java (classes,fields and method signatures)as its language for data models.Rewrite specifications are typechecked against the data model before generating Java code.Work partially supported by European Community under the IST programme -Future and Emerging Technologies,contract IST-1999-14191-EASYCOMP.The authors are solely re-sponsible for the content of this paper.It does not represent the opinion of the European Com-munity,and the European Community is not responsible for any use that might be made of data appearing herein.Rather than having a specialized language for describing the data model OptimixJ uses ordinary Java classes.Each Java class defines a possible node type and the fields in the class define the possible outgoing edges.Hence OptimixJ data model specifications allow directed graphs where the nodes have one or several types and where the edges are binary and labelled.Furthermore the range and domain of edges are typed.One advantage with using Java as the data model language is that it becomes easy to integrate OptimixJ rewrite specifications with e.g.legacy Java implementations.public class Node {public Node[] transitiveEdge;}public Node[] basicEdge;MODULE Node transitiveEdge(node, n) :− basicEdge(node, n); transitiveEdge(node, n) :− basicEdge(node, s), transitiveEdge(s, n); RANGE node <= nodes; RULES }EARS transitiveClosure(nodes:Node[]) {public class Node {public Node[] basicEdge;public Node[] transitiveEdge;} public void transitiveClosure(Node[] nodes) {/* The generated transformation code */}a)b)c)Fig.2.A tiny example of an OptimixJ specification.a)shows the data model specification,it defines two relations (Java fields)basicEdge and transitiveEdge that can be used in transformation specifications.b)shows how the transitive closure can be computed given the relations in the data model.c)shows the result after code generation and weaving into the class.A graph rewrite module consists of one or several rewrite systems which specify the actual graph transformations to be carried out.The rewrite specification language has a higly declarative style,it is based on relational graph rewriting and supports both edge addition/deletion as well as node deletion/addition.OptimixJ generates one Java method for each rewrite system in the rewrite module,the method will have the same name and parameter list as given in the rewrite system.If the name of the module containing the rewrite system matches the name of a Java class the generated method will be weaved in to that Java class,if no matching class is found a new class with static methods will be generated.See figure 2for an example of a rewrite module.During code generation OptimixJ also type-checks the rewrite rules:predicates in the rules are looked up in the data model and the domain/range types is checked.Opti-mixJ also analyzes the inheritance structure of the data model so relations applicable to a class are also applicable to its sub-classes.To learn more about OptimixJ see[2,1].The next section describes how the OptimixJ tool can be used in the context of the Semantic Web.2OptimixJ and the Semantic WebThe focus of this demonstration is to show how graph rewriting and the OptimixJ tool can be used as an executable representation of Semantic Web ontologies.First we will give a brief description of the Semantic Web languages.2.1A Brief Description of the Semantic WebThe purpose of the Semantic Web[3]is to express knowledge about things,called resources,(a resource can be a webpage,person or just anything that has a Uniform Resource Locator,URI)in a way that enables automated agents to reason about these resources,i.e.infer knowledge from the given facts.The idea is that one creates ontologies that models a domain of interest.There are a few different ontology languages(RDFS,DAML+OIL,OWL)providing somewhat different language constructs,we will discuss the Web Ontology Language OWL[3] defined by the web consortium.The basic modelling primitives of OWL are classes and properties,classes can in-herit from other classes and have properties.But OWL also supports more expressive constructs that allows the modeller to express things like:–characteristics of properties(e.g.a property can be symmetric or transitive).–property inheritance(hasFather is a subproperty of hasParent).–relations between classes(e.g.disjointness).Seefigure3for an example ontology.<Class ID="Person"/><Class ID="Male"><subClassOf resource="Person"/><disjointWith resource="Female"/> </Class><ObjectProperty ID="spouse"><domain resource="Person"/><range resource="Person"/><type resource="functionalProperty"/> </ObjectProperty>a)<Male ID="John"><spouse resource="Mary"/> </Male><spouse resource="John"/> <Female ID="Mary">b)</Female>Fig.3.a)shows a sample OWL ontology defining some classes and a property.b)shows a fragment of an RDF document defining some instances of the ontology.The classes and properties defined in an ontology can then be used to create in-stances(seefigure3b),the instances are represented in a format called RDF(Resource Description Framework)[4].In terms of graphs RDF is an XML format for directed, edge-labelled graphs where the nodes can have one or several types.As we pointed out in the previous section this is exactly the kind of graphs OptimixJ is designed to work on,in the next section we show how this can be used in order to execute inference rules and constraints defined in OWL.2.2Compiling OWL Ontologies to Java and OptimixJIn order to do something interesting with the ontologies and instances we need some kind of inference engine.OWL is based on the Description Logic formalism for which reasoning engines exist,these systems are very fast but it is difficult to extend the system to handle more expressive rules.Another approach that is used is to translate the ontologies and instances to Frame Logic[5],this allows for the addition of more expressive rules.The problem with this approach is that the Frame Logic engine is quite slow(it is running on top of Prolog).Another potential problem with these approaches is integration with the application programs that wants the result of the inferences,it can be difficult to communicate between the two parts.To overcome the problems described above(additional expressivity and interfacing to inference engine)we are working on generating Java code and OptimixJ rules from ontologies defined in a subset of OWL.This will give both a more powerful language for expressing rules/constraints as well as seamless integration with Java applications.As we can see from the description of OWL in section2.1there are some simi-larities between the OWL modelling language and Java.The OWL class and property constructs maps to Java’s classes/interfaces andfields/methods,OWL inheritance can also be translated to Java inheritance/implementation.Hence part of the OWL language is used for describing the graph schema and it can be mapped to Java classes that are used to define the data model for the OptimixJ rewrite specifications(as discussed in section1).But there are other OWL modelling primitives that are less straightforward to map to Java.For example if the OWL property spouse has been declared as symmetric we need to generate some Java code to make sure that this rule is satisfied.Interestingly it turns out that the OptimixJ rewrite language to a large extent is sufficient for imple-menting the inference rules and constraints expressible by OWL.We can also add more expressive constraints to the Java code by writing OptimixJ specifications by hand and merging them with the rest of the code.The Semantic Web Ontology Development Environment(SWEDE)[6]toolset is able to translate a subset of OWL to Java class definitions and OptimixJ rewrite modules,figure4shows the process of translating OWL to Java.Each OWL class is mapped to one Java class and one interface,the interface is used for encoding the inheritance structure(OWL allows multiple inheritance).Each OWL property defined for a class is mapped to a Javafield in the corresponding Java class.Fig.4.Translating OWL ontologies to Java.Once the Java code generation isfinished we can read RDF instances with a program that creates new Java objects.Once the OptimixJ has generated code from the rewrite specifications and merged the code with the Java classes we can use them to create Java objects from RDF instance documents.The RDFReader parses the RDF document and instantiates a new Java object ac-cording to the types of the RDF instance,the reader also inserts property values into the Java object.For example,the RDF document infigure3b would create two new Java objects:one of the type Female with the spousefield pointing to the second object,the second object would have the type Male and the spousefield would point to thefirst object.The SWEDE tools can also translate XML DTD’s to OWL ontologies,which enables us to generate Java classes and OptimixJ rewritings for XML trees.References1.Aßmann,U.:OPTIMIX website.(2003)2.Aßmann,U.In:OPTIMIX,A Tool for Rewriting and Optimizing Programs.Chapman-Hall(1999)3.W3C:The Semantic Web Activity./2001/sw(2003)4.W3C:RDF specification./TR/REC-rdf-syntax/(2003)5.Flora:Flora2website.http://fl(2003)6.Lövdahl,J.:An editing environment for the semantic web.Master’s thesis,Linköpings Uni-versitet(2002)。