From edafb92f91c424ffb465786aadf8315663a596e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Thu, 18 Mar 2010 21:33:00 +0000 Subject: [PATCH] - introduced type checking for EDOAL --- .../exmo/align/impl/edoal/EDOALAlignment.java | 8 +- .../exmo/align/impl/edoal/EDOALCell.java | 6 + .../exmo/align/impl/edoal/EDOALRelation.java | 7 + .../exmo/align/impl/edoal/Expression.java | 6 + .../align/parser/TypeCheckingVisitor.java | 285 ++++++++++++++++++ 5 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java index 00e0da2c..8fd00f85 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java @@ -39,6 +39,8 @@ import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.impl.BasicAlignment; import fr.inrialpes.exmo.align.impl.Extensions; +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + /** * <p>This class is an encapsulation of BasicAlignement so that * it creates the structures required by the MappingDocument within @@ -55,7 +57,7 @@ public class EDOALAlignment extends BasicAlignment { protected EDOALAlignment init = null; /* - * The list of variables in declared in this alignment + * The list of variables declared in this alignment * //EDOALPattern */ protected Hashtable<String,Variable> variables; @@ -66,6 +68,10 @@ public class EDOALAlignment extends BasicAlignment { variables = new Hashtable<String,Variable>(); } + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + public void init( Object onto1, Object onto2 ) throws AlignmentException { if ( (onto1 == null) || (onto2 == null) ) throw new AlignmentException("The source and target ontologies must not be null"); diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java index 8bb0802e..29a61cdf 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALCell.java @@ -41,6 +41,8 @@ import fr.inrialpes.exmo.align.impl.BasicCell; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + /** * This implements a particular of ontology correspondence when it * is a correspondence from the EDOAL Mapping Language. @@ -78,6 +80,10 @@ public class EDOALCell extends BasicCell { super( id, (Object)ob1, (Object)ob2, rel, m ); }; + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + public URI getObject1AsURI( Alignment al ) throws AlignmentException { if ( object1 instanceof Id ) return ((Id)object1).getURI(); else return null; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java index 808e5fc3..f60b266f 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALRelation.java @@ -36,6 +36,8 @@ import java.util.Map; import org.xml.sax.ContentHandler; +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + /** * Represents an ontology alignment relation. * In fact, for the EDOAL Mapping language, this encodes directions @@ -119,6 +121,11 @@ public class EDOALRelation implements Relation { public void accept( AlignmentVisitor visitor) throws AlignmentException { visitor.visit( this ); } + + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + /** * It is intended that the value of the relation is =, < or >. * But this can be any string in other applications. diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Expression.java b/src/fr/inrialpes/exmo/align/impl/edoal/Expression.java index fb3aae6a..0cde36ec 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/Expression.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Expression.java @@ -31,6 +31,8 @@ import org.semanticweb.owl.align.Visitable; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.AlignmentVisitor; +import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; + /** * <p> * This class serves as the base for the four different expression types. These @@ -70,6 +72,10 @@ public abstract class Expression implements Cloneable, Visitable { visitor.visit(this); } + public void accept(TypeCheckingVisitor visitor) throws AlignmentException { + visitor.visit(this); + } + public Variable getVariable() { return variable; } public void setVariable( Variable v ) { variable = v; } diff --git a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java new file mode 100644 index 00000000..af1ebaa7 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java @@ -0,0 +1,285 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.inrialpes.exmo.align.parser; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Set; +import java.util.HashSet; +import java.util.Properties; +import java.net.URI; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.Relation; +import org.semanticweb.owl.align.AlignmentException; + +import fr.inrialpes.exmo.align.impl.Annotations; +import fr.inrialpes.exmo.align.impl.Namespace; +import fr.inrialpes.exmo.align.impl.Extensions; +import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.ObjectCell; + +import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.Ontology; //? + +import fr.inrialpes.exmo.align.parser.SyntaxElement; +import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor; + +import fr.inrialpes.exmo.align.impl.edoal.Id; +import fr.inrialpes.exmo.align.impl.edoal.PathExpression; +import fr.inrialpes.exmo.align.impl.edoal.Expression; +import fr.inrialpes.exmo.align.impl.edoal.ClassExpression; +import fr.inrialpes.exmo.align.impl.edoal.ClassId; +import fr.inrialpes.exmo.align.impl.edoal.ClassConstruction; +import fr.inrialpes.exmo.align.impl.edoal.ClassRestriction; +import fr.inrialpes.exmo.align.impl.edoal.ClassTypeRestriction; +import fr.inrialpes.exmo.align.impl.edoal.ClassDomainRestriction; +import fr.inrialpes.exmo.align.impl.edoal.ClassValueRestriction; +import fr.inrialpes.exmo.align.impl.edoal.ClassOccurenceRestriction; +import fr.inrialpes.exmo.align.impl.edoal.PropertyExpression; +import fr.inrialpes.exmo.align.impl.edoal.PropertyId; +import fr.inrialpes.exmo.align.impl.edoal.PropertyConstruction; +import fr.inrialpes.exmo.align.impl.edoal.PropertyRestriction; +import fr.inrialpes.exmo.align.impl.edoal.PropertyDomainRestriction; +import fr.inrialpes.exmo.align.impl.edoal.PropertyTypeRestriction; +import fr.inrialpes.exmo.align.impl.edoal.PropertyValueRestriction; +import fr.inrialpes.exmo.align.impl.edoal.RelationExpression; +import fr.inrialpes.exmo.align.impl.edoal.RelationId; +import fr.inrialpes.exmo.align.impl.edoal.RelationConstruction; +import fr.inrialpes.exmo.align.impl.edoal.RelationRestriction; +import fr.inrialpes.exmo.align.impl.edoal.RelationDomainRestriction; +import fr.inrialpes.exmo.align.impl.edoal.RelationCoDomainRestriction; +import fr.inrialpes.exmo.align.impl.edoal.InstanceExpression; +import fr.inrialpes.exmo.align.impl.edoal.InstanceId; + +import fr.inrialpes.exmo.align.impl.edoal.TransfService; +import fr.inrialpes.exmo.align.impl.edoal.Value; +import fr.inrialpes.exmo.align.impl.edoal.Datatype; +import fr.inrialpes.exmo.align.impl.edoal.Comparator; + +import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; +import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; +import fr.inrialpes.exmo.align.impl.edoal.EDOALRelation; + +/** + * Renders an alignment in its RDF format + * + * @author Jérôme Euzenat + * @version $Id: RDFRendererVisitor.java 1335 2010-03-18 20:52:30Z euzenat $ + */ + +public class TypeCheckingVisitor { + + EDOALAlignment alignment = null; + EDOALCell cell = null; + Hashtable<String,String> nslist = null; + boolean embedded = false; // if the output is XML embeded in a structure + + private static Namespace DEF = Namespace.ALIGNMENT; + + private boolean isPattern = false; + + /* + * JE: These major dispatches are a pain. + * I should learn a bit more Java about that + * (and at least inverse the order + */ + // JE: Beware: THERE MAY BE EFFECTIVE STUFF MISSING THERE (CAN WE DO THE DISPATCH LOWER -- YES) + // It is a real mess already... + public void visit( Expression o ) throws AlignmentException { + if ( o instanceof ClassExpression ) visit( (ClassExpression)o ); + //else if ( o instanceof TransfService ) visit( (TransfService)o ); + else if ( o instanceof RelationRestriction ) visit( (RelationRestriction)o ); + else if ( o instanceof PropertyRestriction ) visit( (PropertyRestriction)o ); + else if ( o instanceof ClassRestriction ) visit( (ClassRestriction)o ); + else if ( o instanceof PathExpression ) visit( (PathExpression)o ); + else if ( o instanceof PropertyExpression ) visit( (PropertyExpression)o ); + else if ( o instanceof InstanceExpression ) visit( (InstanceExpression)o ); + else if ( o instanceof RelationExpression ) visit( (RelationExpression)o ); + throw new AlignmentException("Cannot export abstract Expression: "+o ); + } + + public void visit( EDOALAlignment align ) throws AlignmentException { + alignment = align; + if ( alignment.getLevel().startsWith("2EDOALPattern") ) isPattern = true; + align.getOntology1URI(); + for( Cell c : align ){ ((EDOALCell)c).accept( this ); }; + } + + public void visit( EDOALCell cell ) throws AlignmentException { + this.cell = cell; + if ( alignment.getLevel().startsWith("2EDOAL") ) { + ((Expression)(cell.getObject1())).accept( this ); + ((Expression)(cell.getObject2())).accept( this ); + } + } + + public void visit( EDOALRelation rel ) { + }; + + public void visit( final PathExpression p ) throws AlignmentException { + if ( p instanceof RelationExpression ) visit( (RelationExpression)p ); + else if ( p instanceof PropertyExpression ) visit( (PropertyExpression)p ); + else throw new AlignmentException( "Cannot dispatch PathExpression "+p ); + } + + public void visit( final ClassExpression e ) throws AlignmentException { + if ( e instanceof ClassId ) visit( (ClassId)e ); + else if ( e instanceof ClassConstruction ) visit( (ClassConstruction)e ); + else if ( e instanceof ClassRestriction ) visit( (ClassRestriction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit( final ClassId e ) throws AlignmentException { + } + + public void visit( final ClassConstruction e ) throws AlignmentException { + final Constructor op = e.getOperator(); + for (final ClassExpression ce : e.getComponents()) { + visit( ce ); + } + } + + public void visit(final ClassRestriction e) throws AlignmentException { + if ( e instanceof ClassValueRestriction ) visit( (ClassValueRestriction)e ); + else if ( e instanceof ClassTypeRestriction ) visit( (ClassTypeRestriction)e ); + else if ( e instanceof ClassDomainRestriction ) visit( (ClassDomainRestriction)e ); + else if ( e instanceof ClassOccurenceRestriction ) visit( (ClassOccurenceRestriction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit( final ClassValueRestriction c ) throws AlignmentException { + visit( c.getRestrictionPath() ); + if ( c.getValue() != null ) { + visit( c.getValue() ); + } else if ( c.getInstanceValue() != null ) { + visit( c.getInstanceValue() ); + } else { + visit( c.getPathValue() ); + } + } + + public void visit( final ClassTypeRestriction c ) throws AlignmentException { + visit( c.getRestrictionPath() ); + visit( c.getType() ); + } + + public void visit( final ClassDomainRestriction c ) throws AlignmentException { + visit( c.getRestrictionPath() ); + visit( c.getDomain() ); + } + + public void visit( final ClassOccurenceRestriction c ) throws AlignmentException { + visit( c.getRestrictionPath() ); + c.getComparator().getURI(); + c.getOccurence(); + } + + public void visit(final PropertyExpression e) throws AlignmentException { + if ( e instanceof PropertyId ) visit( (PropertyId)e ); + else if ( e instanceof PropertyConstruction ) visit( (PropertyConstruction)e ); + else if ( e instanceof PropertyRestriction ) visit( (PropertyRestriction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit(final PropertyId e) throws AlignmentException { + } + + public void visit(final PropertyConstruction e) throws AlignmentException { + final Constructor op = e.getOperator(); + for ( final PathExpression pe : e.getComponents() ) { + visit( pe ); + } + } + + public void visit(final PropertyRestriction e) throws AlignmentException { + if ( e instanceof PropertyValueRestriction ) visit( (PropertyValueRestriction)e ); + else if ( e instanceof PropertyDomainRestriction ) visit( (PropertyDomainRestriction)e ); + else if ( e instanceof PropertyTypeRestriction ) visit( (PropertyTypeRestriction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit(final PropertyValueRestriction c) throws AlignmentException { + c.getComparator().getURI(); + if ( c.getValue() != null ) { + visit( c.getValue() ); + } else if ( c.getInstanceValue() != null ) { + visit( c.getInstanceValue() ); + } else { + visit( c.getPath() ); + } + } + + public void visit(final PropertyDomainRestriction c) throws AlignmentException { + visit( c.getDomain() ); + } + + public void visit(final PropertyTypeRestriction c) throws AlignmentException { + visit( c.getType() ); + } + + public void visit( final RelationExpression e ) throws AlignmentException { + if ( e instanceof RelationId ) visit( (RelationId)e ); + else if ( e instanceof RelationRestriction ) visit( (RelationRestriction)e ); + else if ( e instanceof RelationConstruction ) visit( (RelationConstruction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit( final RelationId e ) throws AlignmentException { + } + + public void visit( final RelationConstruction e ) throws AlignmentException { + final Constructor op = e.getOperator(); + for (final PathExpression re : e.getComponents()) { + visit( re ); + } + } + + public void visit( final RelationRestriction e ) throws AlignmentException { + if ( e instanceof RelationCoDomainRestriction ) visit( (RelationCoDomainRestriction)e ); + else if ( e instanceof RelationDomainRestriction ) visit( (RelationDomainRestriction)e ); + else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); + } + + public void visit(final RelationCoDomainRestriction c) throws AlignmentException { + visit( c.getCoDomain() ); + } + + public void visit(final RelationDomainRestriction c) throws AlignmentException { + visit( c.getDomain() ); + } + + public void visit( final InstanceExpression e ) throws AlignmentException { + if ( e instanceof InstanceId ) visit( (InstanceId)e ); + else throw new AlignmentException( "Cannot handle InstanceExpression "+e ); + } + + public void visit( final InstanceId e ) throws AlignmentException { + } + + public void visit( final Value e ) throws AlignmentException { + } + + public void visit( final Datatype e ) throws AlignmentException { + } + +} -- GitLab