diff --git a/html/relnotes.html b/html/relnotes.html index 1bc67f810b9214de1daa8296be5984691aafa6f5..5aaad6c76440b779e452a90dd17ecc152fd96972 100644 --- a/html/relnotes.html +++ b/html/relnotes.html @@ -37,7 +37,6 @@ The development of 4 versions continues. <h2>Under development (you can contribute)</h2> <p><ul compact="1"> -<li>Adding type checking to EDOAL parser (parser)</li> <li>Implement database store for EDOAL (server)</li> <li>Integrate some basic reasoning.</li> <li>Complete tutorial4 with distributed reasoning.</li> @@ -62,6 +61,7 @@ The development of 4 versions continues. <!--h2>Version 4.2 (): xx/xx/2011 - Tring</h2--> <p><ul compact="1"> +<li>Added type checking to EDOAL parser (parser)</li> <li>Added <tt>WeightedPRecEvaluator</tt> weighting confidences (eval)</li> <li>Added <tt>toURIAlignment</tt> and <tt>toEDOALAlignment</tt> for <tt>EDOALAlignment</tt> (edoal)</li> <li>Changed order of display to precision/F-measure/recall (util)</li> diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java index 6afe5f60a048c6dddd0a6bde631714c3cc2a975f..93cc915578bbd99672175aefdd15552a23ac2ee7 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java @@ -30,6 +30,7 @@ import java.util.Set; import java.net.URI; import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; diff --git a/src/fr/inrialpes/exmo/align/parser/RDFParser.java b/src/fr/inrialpes/exmo/align/parser/RDFParser.java index 5a0c2ec46c044ad57043f2dee2bb9b72586ad73c..62415fcc441d5b9acf76b8dec64646847c220b3b 100644 --- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java +++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java @@ -122,7 +122,8 @@ public class RDFParser { private int debug = 0; - private boolean isPattern = false; + private boolean isPattern = false; // I contain variables + private boolean speedparse = false; // skip all checks private EDOALAlignment alignment; @@ -178,6 +179,8 @@ public class RDFParser { Statement alignDoc = stmtIt.nextStatement(); // Step from this statement alignment = parseAlignment( alignDoc.getSubject() ); + // If necessary type-check the alignment + if ( !speedparse ) alignment.accept( new TypeCheckingVisitor() ); // Clean up memory rdfmodel.close(); // JE: I am not sure that I will not have trouble with initSyntax return alignment; @@ -253,6 +256,9 @@ public class RDFParser { if ( stmtIt.hasNext() ) { final String level = stmtIt.nextStatement().getString(); if ((level != null) && (!level.equals(""))) { + //if ( level.equals("0") ) { + // alignment.setLevel( level ); + //} else if ( level.startsWith("2EDOAL") ) { alignment.setLevel( level ); if ( level.equals("2EDOALPattern") ) isPattern = true; @@ -372,6 +378,7 @@ public class RDFParser { // If both have none, then we get a old-style correspondence for free // If it has one, let's go parsing // I also assume that the factory only do dispatch + // JE2010 ~later: that would also allow for parsing old alignments Expression s = parseExpression( entity1 ); Expression t = parseExpression( entity2 ); diff --git a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java index 895843fe6c5e6146963439c436d23e6ec3f41bc6..8f5c10493c2e5c96a2f8884de56f3f68fb72faef 100644 --- a/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java +++ b/src/fr/inrialpes/exmo/align/parser/TypeCheckingVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2010 + * Copyright (C) INRIA, 2010-2011 * * 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 @@ -20,31 +20,21 @@ 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.AlignmentVisitor; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; +import org.semanticweb.owl.align.Visitable; 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; @@ -83,202 +73,325 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; import fr.inrialpes.exmo.align.impl.edoal.EDOALRelation; /** - * Renders an alignment in its RDF format + * Checks if an EDOALAlignment is well-typed + * This is called by AlignmentParser (with debug>0) * * @author Jérôme Euzenat - * @version $Id: RDFRendererVisitor.java 1335 2010-03-18 20:52:30Z euzenat $ + * @version $Id$ */ public class TypeCheckingVisitor { + private enum TYPE { CLASS, PROPERTY, RELATION, INSTANCE, VALUE, DATATYPE, ANY, ERROR }; + EDOALAlignment alignment = null; EDOALCell cell = null; - Hashtable<String,String> nslist = null; + Hashtable<URI,TYPE> nslist = null; boolean embedded = false; // if the output is XML embeded in a structure + boolean error = false; // has an error been encountered + boolean print = false; // do we print error messages + private boolean isPattern = false; private static Namespace DEF = Namespace.ALIGNMENT; - private boolean isPattern = false; + public TypeCheckingVisitor() { + nslist = new Hashtable<URI,TYPE>(); + } /* * 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 ); + + public TYPE visit( Visitable o ) throws AlignmentException { + if ( o instanceof Expression ) return visit( (Expression)o ); + else throw new AlignmentException( "Cannot type check all" ); + } + + public TYPE visit( Expression o ) throws AlignmentException { + if ( o instanceof ClassExpression ) return visit( (ClassExpression)o ); + //else if ( o instanceof TransfService ) return visit( (TransfService)o ); + else if ( o instanceof RelationRestriction ) return visit( (RelationRestriction)o ); + else if ( o instanceof PropertyRestriction ) return visit( (PropertyRestriction)o ); + else if ( o instanceof ClassRestriction ) return visit( (ClassRestriction)o ); + else if ( o instanceof PathExpression ) return visit( (PathExpression)o ); + else if ( o instanceof PropertyExpression ) return visit( (PropertyExpression)o ); + else if ( o instanceof InstanceExpression ) return visit( (InstanceExpression)o ); + else if ( o instanceof RelationExpression ) return visit( (RelationExpression)o ); throw new AlignmentException("Cannot export abstract Expression: "+o ); } - public void visit( EDOALAlignment align ) throws AlignmentException { + public TYPE visit( EDOALAlignment align ) throws AlignmentException { alignment = align; if ( alignment.getLevel().startsWith("2EDOALPattern") ) isPattern = true; - align.getOntology1URI(); - for( Cell c : align ){ ((EDOALCell)c).accept( this ); }; + align.getOntology1URI(); + for( Cell c : align ){ ((EDOALCell)c).accept( this ); }; + return TYPE.ANY; } - public void visit( EDOALCell cell ) throws AlignmentException { + public TYPE visit( EDOALCell cell ) throws AlignmentException { this.cell = cell; + // JE2011???? Could be useful when not parsing EDOAL if ( alignment.getLevel().startsWith("2EDOAL") ) { - ((Expression)(cell.getObject1())).accept( this ); - ((Expression)(cell.getObject2())).accept( this ); + TYPE t1 = visit( ((Expression)(cell.getObject1())) ); + TYPE t2 = visit( ((Expression)(cell.getObject2())) ); + // JE2011: This should be dependent on the Relation type (e.g., instanceOf) + if ( !compatible( t1, t2 ) ) return TYPE.ERROR; } + return TYPE.ANY; + } + + public boolean compatible( TYPE t1, TYPE t2 ) { + if ( t1 == TYPE.ERROR || t2 == TYPE.ERROR ) return true; //nomore + if ( t1 == TYPE.ANY || t2 == TYPE.ANY || t1 == t2 ) return true; + return false; + } + + public boolean pcompatible( TYPE ptype, TYPE tp ) { + if ( ptype == TYPE.ERROR || tp == TYPE.ERROR ) return true; //nomore + if ( ( ptype == TYPE.RELATION && tp == TYPE.INSTANCE ) || + ( ptype == TYPE.PROPERTY && tp == TYPE.VALUE ) || + tp == TYPE.ANY ) return true; + return false; } - public void visit( EDOALRelation rel ) { + public TYPE visit( EDOALRelation rel ) { + return TYPE.ANY; }; - public void visit( final Transformation trsf ) throws AlignmentException { + public TYPE visit( final Transformation trsf ) throws AlignmentException { + // getType() could allow to do better typing + TYPE tp1 = visit( trsf.getObject1() ); + TYPE tp2 = visit( trsf.getObject2() ); + if ( !compatible( tp1, TYPE.VALUE ) ) return raiseError( null, tp1, TYPE.VALUE ); + if ( !compatible( tp2, TYPE.VALUE ) ) return raiseError( null, tp2, TYPE.VALUE ); + return TYPE.ANY; } - public void visit( final PathExpression p ) throws AlignmentException { - if ( p instanceof RelationExpression ) visit( (RelationExpression)p ); - else if ( p instanceof PropertyExpression ) visit( (PropertyExpression)p ); + public TYPE visit( final PathExpression p ) throws AlignmentException { + if ( p instanceof RelationExpression ) return visit( (RelationExpression)p ); + else if ( p instanceof PropertyExpression ) return 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 ); + public TYPE visit( final ClassExpression e ) throws AlignmentException { + if ( e instanceof ClassId ) return visit( (ClassId)e ); + else if ( e instanceof ClassConstruction ) return visit( (ClassConstruction)e ); + else if ( e instanceof ClassRestriction ) return visit( (ClassRestriction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit( final ClassId e ) throws AlignmentException { + public TYPE visit( final ClassId e ) throws AlignmentException { + TYPE type = nslist.get( e.getURI() ); + if ( type == null ) nslist.put( e.getURI(), TYPE.CLASS ); + else if ( !compatible( type, TYPE.CLASS ) ) return raiseError( e.getURI(), type, TYPE.CLASS ); + return TYPE.CLASS; } - public void visit( final ClassConstruction e ) throws AlignmentException { - final Constructor op = e.getOperator(); + public TYPE visit( final ClassConstruction e ) throws AlignmentException { + final Constructor op = e.getOperator(); // do we test the operator? + boolean allright = true; for (final ClassExpression ce : e.getComponents()) { - visit( ce ); + TYPE tp = visit( ce ); + if ( !compatible( tp, TYPE.CLASS ) ) { + raiseError( null, tp, TYPE.CLASS ); + allright = false; + } } + if ( allright ) return TYPE.CLASS; + else return TYPE.ERROR; } - 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 ); + public TYPE visit(final ClassRestriction e) throws AlignmentException { + if ( e instanceof ClassValueRestriction ) return visit( (ClassValueRestriction)e ); + else if ( e instanceof ClassTypeRestriction ) return visit( (ClassTypeRestriction)e ); + else if ( e instanceof ClassDomainRestriction ) return visit( (ClassDomainRestriction)e ); + else if ( e instanceof ClassOccurenceRestriction ) return visit( (ClassOccurenceRestriction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit( final ClassValueRestriction c ) throws AlignmentException { - visit( c.getRestrictionPath() ); - visit( c.getValue() ); + public TYPE visit( final ClassValueRestriction c ) throws AlignmentException { + TYPE ptype = visit( c.getRestrictionPath() ); + TYPE tp = visit( c.getValue() ); + if ( !pcompatible( ptype, tp ) ) return raiseError( null, ptype, tp ); + return TYPE.CLASS; } - public void visit( final ClassTypeRestriction c ) throws AlignmentException { - visit( c.getRestrictionPath() ); - visit( c.getType() ); + public TYPE visit( final ClassTypeRestriction c ) throws AlignmentException { + TYPE ptype = visit( c.getRestrictionPath() ); + TYPE tp = visit( c.getType() ); + if ( !compatible( ptype, TYPE.PROPERTY ) ) return raiseError( null, ptype, TYPE.PROPERTY ); + if ( !compatible( tp, TYPE.DATATYPE ) ) return raiseError( null, tp, TYPE.DATATYPE ); + return TYPE.CLASS; } - public void visit( final ClassDomainRestriction c ) throws AlignmentException { - visit( c.getRestrictionPath() ); - visit( c.getDomain() ); + public TYPE visit( final ClassDomainRestriction c ) throws AlignmentException { + TYPE ptype = visit( c.getRestrictionPath() ); + TYPE tp = visit( c.getDomain() ); + if ( !compatible( ptype, TYPE.RELATION ) ) return raiseError( null, ptype, TYPE.RELATION ); + if ( !compatible( tp, TYPE.CLASS ) ) return raiseError( null, tp, TYPE.CLASS ); + return TYPE.CLASS; } - public void visit( final ClassOccurenceRestriction c ) throws AlignmentException { - visit( c.getRestrictionPath() ); - c.getComparator().getURI(); - c.getOccurence(); + public TYPE visit( final ClassOccurenceRestriction c ) throws AlignmentException { + //c.getComparator().getURI(); + TYPE ptype = visit( c.getRestrictionPath() ); + // c.getOccurence() is an integer + if ( !compatible( ptype, TYPE.RELATION ) && + !compatible( ptype, TYPE.PROPERTY ) ) return raiseError( null, ptype, TYPE.RELATION ); + return TYPE.CLASS; } - 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 ); + public TYPE visit(final PropertyExpression e) throws AlignmentException { + if ( e instanceof PropertyId ) return visit( (PropertyId)e ); + else if ( e instanceof PropertyConstruction ) return visit( (PropertyConstruction)e ); + else if ( e instanceof PropertyRestriction ) return visit( (PropertyRestriction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit(final PropertyId e) throws AlignmentException { + public TYPE visit(final PropertyId e) throws AlignmentException { + TYPE type = nslist.get( e.getURI() ); + if ( type == null ) nslist.put( e.getURI(), TYPE.PROPERTY ); + else if ( !compatible( type, TYPE.PROPERTY ) ) return raiseError( e.getURI(), type, TYPE.PROPERTY ); + return TYPE.PROPERTY; } - public void visit(final PropertyConstruction e) throws AlignmentException { - final Constructor op = e.getOperator(); + public TYPE visit(final PropertyConstruction e) throws AlignmentException { + //final Constructor op = e.getOperator(); // do we test the operator? + boolean allright = true; for ( final PathExpression pe : e.getComponents() ) { - visit( pe ); + TYPE tp = visit( pe ); + if ( !compatible( tp, TYPE.PROPERTY ) ) { + raiseError( null, tp, TYPE.PROPERTY ); + allright = false; + } } + if ( allright ) return TYPE.PROPERTY; + else return TYPE.ERROR; } - 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 ); + public TYPE visit(final PropertyRestriction e) throws AlignmentException { + if ( e instanceof PropertyValueRestriction ) return visit( (PropertyValueRestriction)e ); + else if ( e instanceof PropertyDomainRestriction ) return visit( (PropertyDomainRestriction)e ); + else if ( e instanceof PropertyTypeRestriction ) return visit( (PropertyTypeRestriction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit(final PropertyValueRestriction c) throws AlignmentException { - c.getComparator().getURI(); - visit( c.getValue() ); + public TYPE visit(final PropertyValueRestriction c) throws AlignmentException { + //c.getComparator().getURI(); // do we test the operator? + TYPE type = visit( c.getValue() ); + if ( !compatible( type, TYPE.VALUE ) ) return raiseError( null, type, TYPE.VALUE ); + return TYPE.PROPERTY; } - public void visit(final PropertyDomainRestriction c) throws AlignmentException { - visit( c.getDomain() ); + public TYPE visit(final PropertyDomainRestriction c) throws AlignmentException { + TYPE type = visit( c.getDomain() ); + if ( !compatible( type, TYPE.DATATYPE ) ) return raiseError( null, type, TYPE.DATATYPE ); + return TYPE.PROPERTY; } - public void visit(final PropertyTypeRestriction c) throws AlignmentException { - visit( c.getType() ); + public TYPE visit(final PropertyTypeRestriction c) throws AlignmentException { + TYPE type = visit( c.getType() ); + if ( !compatible( type, TYPE.DATATYPE ) ) return raiseError( null, type, TYPE.DATATYPE ); + return TYPE.PROPERTY; } - 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 ); + public TYPE visit( final RelationExpression e ) throws AlignmentException { + if ( e instanceof RelationId ) return visit( (RelationId)e ); + else if ( e instanceof RelationRestriction ) return visit( (RelationRestriction)e ); + else if ( e instanceof RelationConstruction ) return visit( (RelationConstruction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit( final RelationId e ) throws AlignmentException { + public TYPE visit( final RelationId e ) throws AlignmentException { + TYPE type = nslist.get( e.getURI() ); + if ( type == null ) nslist.put( e.getURI(), TYPE.RELATION ); + else if ( !compatible( type, TYPE.RELATION ) ) return raiseError( e.getURI(), type, TYPE.RELATION ); + return TYPE.RELATION; } - public void visit( final RelationConstruction e ) throws AlignmentException { - final Constructor op = e.getOperator(); + public TYPE visit( final RelationConstruction e ) throws AlignmentException { + final Constructor op = e.getOperator(); // do we test the operator? + boolean allright = true; for (final PathExpression re : e.getComponents()) { - visit( re ); + TYPE tp = visit( re ); + if ( !compatible( tp, TYPE.RELATION ) ) { + raiseError( null, tp, TYPE.RELATION ); + allright = false; + } } + if ( allright ) return TYPE.RELATION; + else return TYPE.ERROR; } - public void visit( final RelationRestriction e ) throws AlignmentException { - if ( e instanceof RelationCoDomainRestriction ) visit( (RelationCoDomainRestriction)e ); - else if ( e instanceof RelationDomainRestriction ) visit( (RelationDomainRestriction)e ); + public TYPE visit( final RelationRestriction e ) throws AlignmentException { + if ( e instanceof RelationCoDomainRestriction ) return visit( (RelationCoDomainRestriction)e ); + else if ( e instanceof RelationDomainRestriction ) return visit( (RelationDomainRestriction)e ); else throw new AlignmentException( "Cannot dispatch ClassExpression "+e ); } - public void visit(final RelationCoDomainRestriction c) throws AlignmentException { - visit( c.getCoDomain() ); + public TYPE visit(final RelationCoDomainRestriction c) throws AlignmentException { + TYPE type = visit( c.getCoDomain() ); + if ( !compatible( type, TYPE.CLASS ) ) return raiseError( null, type, TYPE.CLASS ); + return TYPE.RELATION; } - public void visit(final RelationDomainRestriction c) throws AlignmentException { - visit( c.getDomain() ); + public TYPE visit(final RelationDomainRestriction c) throws AlignmentException { + TYPE type = visit( c.getDomain() ); + if ( !compatible( type, TYPE.CLASS ) ) return raiseError( null, type, TYPE.CLASS ); + return TYPE.RELATION; } - public void visit( final InstanceExpression e ) throws AlignmentException { - if ( e instanceof InstanceId ) visit( (InstanceId)e ); + public TYPE visit( final InstanceExpression e ) throws AlignmentException { + if ( e instanceof InstanceId ) return visit( (InstanceId)e ); else throw new AlignmentException( "Cannot handle InstanceExpression "+e ); } - public void visit( final InstanceId e ) throws AlignmentException { + public TYPE visit( final InstanceId e ) throws AlignmentException { + TYPE type = nslist.get( e.getURI() ); + if ( type == null ) nslist.put( e.getURI(), TYPE.INSTANCE ); + else if ( type != TYPE.INSTANCE ) return raiseError( e.getURI(), type, TYPE.INSTANCE ); + return TYPE.INSTANCE; } - public void visit( final Value e ) throws AlignmentException { + public TYPE visit( final ValueExpression e ) throws AlignmentException { + if ( e instanceof Value ) return visit( (Value)e ); + else if ( e instanceof Apply ) return visit( (Apply)e ); + else if ( e instanceof InstanceExpression ) return visit( (InstanceExpression)e ); + else if ( e instanceof PathExpression ) { + TYPE type = visit( (PathExpression)e ); + if ( !compatible( type, TYPE.PROPERTY ) ) return raiseError( null, type, TYPE.PROPERTY ); + return TYPE.VALUE; + } else throw new AlignmentException( "Cannot handle ValueExpression "+e ); } - public void visit( final ValueExpression e ) throws AlignmentException { + public TYPE visit( final Value e ) throws AlignmentException { + return TYPE.VALUE; } - public void visit( final Apply e ) throws AlignmentException { + public TYPE visit( final Apply e ) throws AlignmentException { + // e.getOperation() + boolean allright = true; + for ( ValueExpression ve : e.getArguments() ) { + TYPE tp = visit( ve ); + if ( !compatible( tp, TYPE.VALUE ) ) { + raiseError( null, tp, TYPE.VALUE ); + allright = false; + } + } + if ( !allright ) return TYPE.ERROR; + else return TYPE.VALUE; // but is it necessarily VALUE? not INSTANCE? } - public void visit( final Datatype e ) throws AlignmentException { + public TYPE visit( final Datatype e ) throws AlignmentException { + return TYPE.DATATYPE; } + public TYPE raiseError( final URI u, TYPE expT, TYPE foundT ) { + error = true; + if ( print ) System.err.println( "Incorrectly typed expression "+u+": Type "+foundT+" ("+expT+" expected)"); + return TYPE.ERROR; + } + } diff --git a/test/src/EDOALExportTest.java b/test/src/EDOALExportTest.java index 2640a478dc837c5756ca704006a014ca8baa62fd..d1e6c687594421e0b9156aee5b3d201a24b858b1 100644 --- a/test/src/EDOALExportTest.java +++ b/test/src/EDOALExportTest.java @@ -27,7 +27,6 @@ import static org.testng.Assert.assertTrue; import org.testng.annotations.BeforeClass; import org.testng.annotations.Configuration; import org.testng.annotations.Test; -//import org.testng.annotations.*; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; @@ -47,21 +46,12 @@ import java.io.ByteArrayOutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; -import java.io.FileOutputStream; -import java.io.OutputStream; -// JE: the old imports - -import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.net.URI; -import java.net.URISyntaxException; -//import org.omwg.mediation.language.export.omwg.OmwgSyntaxFormat; -import fr.inrialpes.exmo.align.parser.SyntaxElement; import fr.inrialpes.exmo.align.parser.SyntaxElement.Constructor; import fr.inrialpes.exmo.align.impl.edoal.Id; @@ -89,7 +79,6 @@ 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; @@ -101,7 +90,6 @@ import fr.inrialpes.exmo.align.impl.edoal.Comparator; public class EDOALExportTest { - // private OmwgSyntaxFormat sf; private RDFRendererVisitor renderer; private PrintWriter writer; private ByteArrayOutputStream stream; @@ -109,8 +97,6 @@ public class EDOALExportTest { @Test(groups = { "full", "omwg", "raw" }) //@BeforeClass(groups = { "full", "omwg", "raw" }) public void setUp() throws Exception { - // JE2009: Suppress this once all tests pass with render instead of export - // sf = new OmwgSyntaxFormat(); } private String render( Visitable v ) throws Exception { @@ -200,24 +186,6 @@ public class EDOALExportTest { "</edoal:compose></edoal:Property>" ); } - /* -This is a test for ontowrap... not EDOAL. -Does bot work anymore because not visitable - @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods = {"setUp"}) - public void testExportOntology() throws Exception { //URISyntax - Ontology onto = new BasicOntology(); - onto.setURI( new URI("http://path.to.the/source") ); - onto.setFormalism( "wsml" ); - onto.setFormURI( new URI("http://path.to.the/spec") ); - assertEquals( render( onto ), "<Ontology rdf:about=\"http://path.to.the/source\"><location>http://path.to.the/source</location><formalism><Formalism align:name=\"wsml\" align:uri=\"http://path.to.the/spec\"/></formalism></Ontology>"); - - onto.setURI( new URI("http://path.to.the/target") ); - onto.setFormalism( "owl" ); - onto.setFormURI( new URI("http://path.to.the/owl") ); - assertEquals( render( onto ), "<Ontology rdf:about=\"http://path.to.the/target\"><location>http://path.to.the/target</location><formalism><Formalism align:name=\"owl\" align:uri=\"http://path.to.the/owl\"/></formalism></Ontology>"); - } - */ - @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods = {"setUp"}) public void testExportInstanceExpression() throws Exception { final InstanceExpression toExport = new InstanceId(new URI("http://meine.tolle/instance#blah")); @@ -354,19 +322,6 @@ Does bot work anymore because not visitable + "<edoal:Property rdf:about=\"http://mein/super/property0\"/>" + "<edoal:Property rdf:about=\"http://mein/super/property1\"/>" + "</edoal:and></edoal:Property>"); - // JE2009: Illegal - /* - toExport = new PropertyExpression( - single, - Collections - .singleton((PropertyExpression) new PropertyDomainRestriction( - new ClassId("http://my/super/class"), - Comparator.EQUAL))); - assertEquals( render( toExport), "<edoal:Property rdf:about=\"http://mein/super/property\">" - + "<edoal:domainRestriction>" - + "<edoal:Class rdf:about=\"http://my/super/class\"/>" - + "</edoal:domainRestriction>" + "</edoal:Property>"); - */ final Set<PathExpression> expressions2 = new LinkedHashSet<PathExpression>(2); expressions2.add( new PropertyConstruction( Constructor.OR, expressions )); @@ -381,15 +336,6 @@ Does bot work anymore because not visitable + "<edoal:value><edoal:Literal edoal:string=\"5\"/></edoal:value></edoal:PropertyValueRestriction>" + "</edoal:and></edoal:Property>"); toExport = new PropertyConstruction( Constructor.NOT, Collections.singleton((PathExpression)new PropertyId(new URI("http://mein/super/property")))); - // JE2009-ERROR-HERE - /* - assertEquals( sf.export( toExport), "<edoal:Property><edoal:not>" - + "<edoal:Property rdf:about=\"http://mein/super/property\"/>" - + "</edoal:not><edoal:transf rdf:resource=\"http://mein/transformator\"></edoal:transf></edoal:Property>" ); - */ - // TODO: do the transf!!! - // JE2010: do not know what to do - //, new TransfService(new URI( "http://mein/transformator"), null)); } // ------ @@ -412,19 +358,6 @@ Does bot work anymore because not visitable RelationExpression toExport = new RelationId("http://my/super/relation"); assertEquals( render(toExport), "<edoal:Relation rdf:about=\"http://my/super/relation\"/>"); - // JE2009: Illegal - /* - toExport = new RelationExpression( - new RelationId("http://my/super/relation"), - Collections - .singleton((RelationExpression) new RelationDomainRestriction(new ClassId("http://my/super/class")))); - assertEquals( sf.export(toExport), - "<edoal:Relation rdf:about=\"http://my/super/relation\">" - + "<edoal:domainRestriction>" - + "<edoal:Class rdf:about=\"http://my/super/class\"/>" - + "</edoal:domainRestriction>" + "</edoal:Relation>"); - */ - // JE 2010: I could export it as well RelationExpression relexp = new RelationDomainRestriction( new ClassId("http://my/super/class")); @@ -499,31 +432,6 @@ Does bot work anymore because not visitable @Test(groups = { "full", "omwg" }, dependsOnMethods = {"setUp"}) public void testExportCell() throws Exception { - // JE2009: these types of MappingRule do not exist anymore: find the new way to do it. - /* - final MappingRule[] toExport = new MappingRule[] { - new Class2Class(null, Direction.EQUIVALENCE, new ClassId("http://my/super/class0"), - new ClassId("http://my/super/class1"), .5f), - new Relation2Class(null, Direction.MAPPING, new RelationId("http://my/super/attribute"), - new ClassId("http://my/super/instance"), .3f) }; - - final String[] outcome = new String[] { - "<Cell>" - + "<entity1><Class rdf:about=\"http://my/super/class0\"></Class></entity1>" - + "<entity2><Class rdf:about=\"http://my/super/class1\"></Class></entity2>" - + "<measure>0.5</measure>" - + "<relation>ClassEquivalence</relation>" + "</Cell>", - "<Cell>" - + "<entity1><Relation rdf:about=\"http://my/super/attribute\"></Relation></entity1>" - + "<entity2><Class rdf:about=\"http://my/super/instance\"></Class></entity2>" - + "<measure>0.3</measure>" - + "<relation>RelationClassMapping</relation>" - + "</Cell>" }; - - for (int i = 0; i < toExport.length; i++) { - assertEquals(outcome[i], sf.export(toExport[i])); - } - */ } @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods = {"setUp"}) @@ -574,105 +482,4 @@ Does bot work anymore because not visitable + "</Alignment>" +"</rdf:RDF>" ); } - // JE2009: Incorrect one - /* - @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods = {"setUp"}) - public void testExportRelationExprExotic() throws Exception { - final String reference = "<edoal:Relation>" - + "<edoal:and rdf:parseType=\"Collection\">" - + "<edoal:DomainRestriction><edoal:class>" - + "<edoal:Class rdf:about=\"r2\"/>" + "</edoal:class></edoal:DomainRestriction>" - + "<edoal:Relation rdf:about=\"c1\"/>" - + "<edoal:DomainRestriction><edoal:class>" + "<edoal:Class rdf:about=\"r1\"/>" - + "</edoal:class></edoal:DomainRestriction>" - + "<edoal:DomainRestriction><edoal:class>" + "<edoal:Class rdf:about=\"r0\"/>" - + "</edoal:class></edoal:DomainRestriction>" + "</edoal:and>" + "</edoal:Relation>"; - - RelationId c1 = new RelationId("c1"); - RelationId c2 = new RelationId("c2"); - ComplexExpression combined = new ComplexExpression(Arrays - .asList(new RelationId[] { c1, c2 }), Constructor.AND); - RelationRestriction con0 = new RelationDomainRestriction(new ClassId("r0")), combined); - RelationRestriction con1 = new RelationDomainRestriction(ClassId("r1")), c1); - RelationRestriction con2 = new RelationDomainRestriction(ClassId("r2")), c2); - RelationExpression ce = new RelationConstruction(combined, Arrays - .asList(new RelationRestriction[] { con0, con1, con2 })); - - assertEquals( sf.export(ce), reference ); - } - */ - - // JE2009: Incorrect one - /* - @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods = {"setUp"}) - public void testExportPropertyExprExotic() throws Exception { - final String reference = "<edoal:Property>" - + "<edoal:and rdf:parseType=\"Collection\">" - + "<edoal:Property rdf:about=\"c2\">" + "<edoal:valueRestriction>" - + "<edoal:value>val2</edoal:value>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" + "</edoal:valueRestriction>" - + "</edoal:Property>" + "<edoal:Property rdf:about=\"c1\">" - + "<edoal:valueRestriction>" + "<edoal:value>val1</edoal:value>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" + "</edoal:valueRestriction>" - + "</edoal:Property>" + "</edoal:and>" + "<edoal:valueRestriction>" - + "<edoal:value>val0</edoal:value>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" + "</edoal:valueRestriction>" - + "</edoal:Property>"; - - PropertyId c1 = new PropertyId("c1"); - PropertyId c2 = new PropertyId("c2"); - ComplexExpression combined = new ComplexExpression(Arrays - .asList(new PropertyId[] { c1, c2 }), Constructor.AND); - PropertyRestriction con0 = new PropertyValueRestriction(new Restriction( - new Value("val0"), Comparator.EQUAL), combined); - PropertyRestriction con1 = new PropertyValueRestriction(new Restriction( - new Value("val1"), Comparator.EQUAL), c1); - PropertyRestriction con2 = new PropertyValueRestriction(new Restriction( - new Value("val2"), Comparator.EQUAL), c2); - PropertyExpression ce = new PropertyConstruction(combined, Arrays - .asList(new PropertyRestriction[] { con0, con1, con2 })); - - assertEquals( sf.export(ce), reference ); - } - */ - - // JE2009: Incorrect one - /* - @Test(groups = { "full", "omwg" }, dependsOnMethods = {"setUp"}) - public void testExportClassExprExotic() throws Exception { - final String reference = "<edoal:Class>" - + "<edoal:and rdf:parseType=\"Collection\">" - + "<edoal:Class rdf:about=\"c2\">" + "<edoal:attributeValueCondition>" - + "<edoal:Restriction>" - + "<edoal:onProperty><edoal:Property rdf:about=\"a2\"/></edoal:onProperty>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" - + "<edoal:value>val2</edoal:value>" + "</edoal:Restriction>" - + "</edoal:attributeValueCondition>" + "</edoal:Class>" - + "<edoal:Class rdf:about=\"c1\">" + "<edoal:attributeValueCondition>" - + "<edoal:Restriction>" - + "<edoal:onProperty><edoal:Property rdf:about=\"a1\"/></edoal:onProperty>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" - + "<edoal:value>val1</edoal:value>" + "</edoal:Restriction>" - + "</edoal:attributeValueCondition>" + "</edoal:Class>" + "</edoal:and>" - + "<edoal:attributeValueCondition>" + "<edoal:Restriction>" - + "<edoal:onProperty><edoal:Property rdf:about=\"a0\"/></edoal:onProperty>" - + "<edoal:comparator rdf:resource=\"http://www.w3.org/2001/XMLSchema#equals\"/>" - + "<edoal:value><edoal:Literal edoal:string=\"val0\"/></edoal:value>" + "</edoal:Restriction>" - + "</edoal:attributeValueCondition>" + "</edoal:Class>"; - - ClassId c1 = new ClassId("c1"); - ClassId c2 = new ClassId("c2"); - ComplexExpression combined = new ComplexExpression(Arrays - .asList(new ClassId[] { c1, c2 }), Constructor.AND); - ClassRestriction con0 = new ClassValueRestriction(new PropertyId("a0"), Comparator.EQUAL,new Value("val0")), - combined); - ClassRestriction con1 = new ClassValueRestriction(new PropertyId("a1"), Comparator.EQUAL, new Value("val1")), c1); - ClassRestriction con2 = new ClassValueRestriction(new PropertyId("a2"), Comparator.EQUAL,new Value("val2")), c2); - ClassExpression ce = new ClassExpression(combined, Arrays - .asList(new ClassRestriction[] { con0, con1, con2 })); - - assertEquals(reference, sf.export(ce)); - } - */ - } diff --git a/test/src/EDOALParserTest.java b/test/src/EDOALParserTest.java index 6b6e2138c6f12f6a2d3b34d222f57b4234e82718..19789b20cd3a6e5bb6e758158df5c8e7db08fe67 100644 --- a/test/src/EDOALParserTest.java +++ b/test/src/EDOALParserTest.java @@ -32,6 +32,8 @@ import org.semanticweb.owl.align.Alignment; import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; import fr.inrialpes.exmo.align.parser.AlignmentParser; +import fr.inrialpes.exmo.align.parser.RDFParser; +import fr.inrialpes.exmo.align.util.NullStream; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -43,6 +45,8 @@ import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; import java.util.Collections; import java.util.HashSet; @@ -65,6 +69,18 @@ public class EDOALParserTest { } @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods={ "setUp" }) + public void typedParsingTest() throws Exception { + AlignmentParser aparser2 = new AlignmentParser( 2 ); + aparser2.initAlignment( null ); + // Would be good to close System.err at that point... + OutputStream serr = System.err; + System.setErr( new PrintStream( new NullStream() ) ); + Alignment al = aparser2.parse( "file:examples/omwg/total.xml" ); + System.setErr( new PrintStream( serr ) ); + assertNotNull( al ); + } + + @Test(groups = { "full", "omwg", "raw" }, dependsOnMethods={ "typedParsingTest" }) public void roundTripTest() throws Exception { // Load the full test aparser1.initAlignment( null );