diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/GenericReflectiveVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/GenericReflectiveVisitor.java index 5ad52ad9447be4d6e260e981de100692bb8c14a7..ea9bd4fd23514ead9ad886413ccf160f55b3fc2d 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/GenericReflectiveVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/GenericReflectiveVisitor.java @@ -23,6 +23,8 @@ package fr.inrialpes.exmo.align.impl.renderer; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; +import org.semanticweb.owl.align.AlignmentException; + /** * This class offers the tools for implementing Reflective visitors, * i.e., visitors in which the visit method will depend on the actual @@ -74,7 +76,7 @@ public class GenericReflectiveVisitor { return m; } - public boolean subsumedInvocableMethod( Object visitor, Object o, Class cl ) { + public boolean subsumedInvocableMethod( Object visitor, Object o, Class cl ) throws AlignmentException { Method method = getMethod( o.getClass(), cl ); if ( method != null ) { try { @@ -83,7 +85,11 @@ public class GenericReflectiveVisitor { } catch ( IllegalAccessException iaex ) { iaex.printStackTrace(); } catch ( InvocationTargetException itex ) { - itex.printStackTrace(); + if ( itex.getCause() instanceof AlignmentException ) { + throw (AlignmentException)itex.getCause(); + } else { + itex.printStackTrace(); + } } } return false; diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/HTMLMetadataRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/HTMLMetadataRendererVisitor.java index b450c9d8e6197fdd62b451a54f59891e75d9298e..d237631e0a4a3df32e7cd1b42b769c47ebd55957 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/HTMLMetadataRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/HTMLMetadataRendererVisitor.java @@ -128,12 +128,12 @@ public class HTMLMetadataRendererVisitor extends GenericReflectiveVisitor implem writer.print("</body>\n</html>\n"); } - public void visit( Cell c ) { + public void visit( Cell c ) throws AlignmentException { if ( subsumedInvocableMethod( this, c, Cell.class ) ) return; // default behaviour }; - public void visit( Relation r ) { + public void visit( Relation r ) throws AlignmentException { if ( subsumedInvocableMethod( this, r, Relation.class ) ) return; // default behaviour }; diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/HTMLRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/HTMLRendererVisitor.java index 67c19f5c63b61ee2044fec9ae267aa7f7564032e..ad3a8dc1bdc4a0230c045978688b583c2f1c5576 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/HTMLRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/HTMLRendererVisitor.java @@ -175,7 +175,7 @@ public class HTMLRendererVisitor extends GenericReflectiveVisitor implements Ali // writer.print(" <semantics>"+cell.getSemantics()+"</semantics>\n"); writer.println("</tr>"); } - public void visit( Relation rel ) { + public void visit( Relation rel ) throws AlignmentException { if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; // default behaviour rel.write( writer ); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java index e197bea7d72a09845dcbee7d62a4f32d5983fe4d..fb5ef254ce4d27130c56573f34df5c46986b7fef 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java @@ -166,26 +166,27 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements Object ob2 = cell.getObject2(); URI u1; try { - if ( cell.getRelation() instanceof SubsumedRelation ){ - u1 = onto2.getEntityURI( cell.getObject2() ); + Relation rel = cell.getRelation(); + if ( rel instanceof SubsumedRelation || rel instanceof HasInstanceRelation ){ + u1 = onto2.getEntityURI( ob2 ); } else { u1 = onto1.getEntityURI( ob1 ); } if ( ob1 instanceof ClassExpression || onto1.isClass( ob1 ) ) { writer.print(" <owl:Class rdf:about=\""+u1+"\">"+NL); - cell.getRelation().accept( this ); + rel.accept( this ); writer.print(" </owl:Class>"+NL); } else if ( ob1 instanceof PropertyExpression || onto1.isDataProperty( ob1 ) ) { writer.print(" <owl:DatatypeProperty rdf:about=\""+u1+"\">"+NL); - cell.getRelation().accept( this ); + rel.accept( this ); writer.print(" </owl:DatatypeProperty>"+NL); } else if ( ob1 instanceof RelationExpression || onto1.isObjectProperty( ob1 ) ) { writer.print(" <owl:ObjectProperty rdf:about=\""+u1+"\">"+NL); - cell.getRelation().accept( this ); + rel.accept( this ); writer.print(" </owl:ObjectProperty>"+NL); } else if ( ob1 instanceof InstanceExpression || onto1.isIndividual( ob1 ) ) { writer.print(" <owl:Thing rdf:about=\""+u1+"\">"+NL); - cell.getRelation().accept( this ); + rel.accept( this ); writer.print(" </owl:Thing>"+NL); } } catch ( OntowrapException owex ) { @@ -197,11 +198,13 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements public void visit( EDOALCell cell ) throws AlignmentException { this.cell = cell; toProcess = cell.getRelation(); + increaseIndent(); if ( toProcess instanceof SubsumeRelation || toProcess instanceof HasInstanceRelation ) { ((Expression)cell.getObject2()).accept( this ); } else { ((Expression)cell.getObject1()).accept( this ); } + decreaseIndent(); writer.print(NL); } @@ -233,14 +236,6 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements throw new AlignmentException( "Error accessing ontology", owex ); } } - /* This dispatch may be used for more customization - if ( rel instanceof EquivRelation ) visit( (EquivRelation)rel ); - else if ( rel instanceof SubsumeRelation ) visit( (SubsumeRelation)rel ); - else if ( rel instanceof SubsumedRelation ) visit( (SubsumedRelation)rel ); - else if ( rel instanceof IncompatRelation ) visit( (IncompatRelation)rel ); - else if ( rel instanceof InstanceOfRelation ) visit( (InstanceOfRelation)rel ); - else if ( rel instanceof HasInstanceRelation ) visit( (HasInstanceRelation)rel ); - */ } @@ -341,107 +336,143 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements public void visit( EquivRelation rel ) throws AlignmentException { Object ob2 = cell.getObject2(); - String owlrel = getRelationName( onto2, rel, ob2 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); if ( !edoal ) { + String owlrel = getRelationName( onto2, rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { writer.print(" <"+owlrel+" rdf:resource=\""+onto2.getEntityURI( ob2 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Error accessing ontology", owex ); } } else { + String owlrel = getRelationName( rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); if ( ob2 instanceof InstanceId ) { - writer.print(" <"+owlrel+" rdf:resource=\""+((InstanceId)ob2).getURI()+"\"/>"+NL); + indentedOutput("<"+owlrel+" rdf:resource=\""+((InstanceId)ob2).getURI()+"\"/>"); } else { - writer.println(" <"+owlrel+">"); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); ((Expression)ob2).accept( this ); - writer.println(" </"+owlrel+">"); + decreaseIndent(); + writer.print(NL); + indentedOutput("</"+owlrel+">"); } } } public void visit( SubsumeRelation rel ) throws AlignmentException { - Object ob2 = cell.getObject2(); - String owlrel = getRelationName( onto2, rel, ob2 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + Object ob1 = cell.getObject1(); if ( !edoal ) { + String owlrel = getRelationName( onto1, rel, ob1 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { - writer.print(" <"+owlrel+" rdf:resource=\""+onto2.getEntityURI( ob2 )+"\"/>"+NL); + writer.print(" <"+owlrel+" rdf:resource=\""+onto1.getEntityURI( ob1 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Error accessing ontology", owex ); } } else { - writer.println(" <"+owlrel+">"); - ((Expression)ob2).accept( this ); - writer.println(" </"+owlrel+">"); + String owlrel = getRelationName( rel, ob1 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); + ((Expression)ob1).accept( this ); + decreaseIndent(); + writer.print(NL); + indentedOutput("</"+owlrel+">"); } } public void visit( SubsumedRelation rel ) throws AlignmentException { - Object ob1 = cell.getObject1(); - String owlrel = getRelationName( onto1, rel, ob1 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + Object ob2 = cell.getObject2(); if ( !edoal ) { + String owlrel = getRelationName( onto2, rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { - writer.print(" <"+owlrel+" rdf:resource=\""+onto1.getEntityURI( ob1 )+"\"/>"+NL); + writer.print(" <"+owlrel+" rdf:resource=\""+onto2.getEntityURI( ob2 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Error accessing ontology", owex ); } } else { - writer.println(" <"+owlrel+">"); - ((Expression)ob1).accept( this ); - writer.println(" </"+owlrel+">"); + String owlrel = getRelationName( rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); + ((Expression)ob2).accept( this ); + decreaseIndent(); + writer.print(NL); + indentedOutput("</"+owlrel+">"); } } public void visit( IncompatRelation rel ) throws AlignmentException { Object ob2 = cell.getObject2(); - String owlrel = getRelationName( onto2, rel, ob2 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); if ( !edoal ) { + String owlrel = getRelationName( onto2, rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { writer.print(" <"+owlrel+" rdf:resource=\""+onto2.getEntityURI( ob2 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Cannot find entity URI", owex ); } } else { - writer.println(" <"+owlrel+">"); + String owlrel = getRelationName( rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); ((Expression)ob2).accept( this ); - writer.println(" </"+owlrel+">"); + writer.print(NL); + decreaseIndent(); + indentedOutput("</"+owlrel+">"); } } public void visit( InstanceOfRelation rel ) throws AlignmentException { Object ob2 = cell.getObject2(); - String owlrel = getRelationName( onto2, rel, ob2 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); if ( !edoal ) { + String owlrel = getRelationName( onto2, rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { writer.print(" <"+owlrel+" rdf:resource=\""+onto2.getEntityURI( ob2 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Cannot find entity URI", owex ); } } else { - writer.println(" <"+owlrel+">"); + String owlrel = getRelationName( rel, ob2 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); ((Expression)ob2).accept( this ); - writer.println(" </"+owlrel+">"); + writer.print(NL); + decreaseIndent(); + indentedOutput("</"+owlrel+">"); } } public void visit( HasInstanceRelation rel ) throws AlignmentException { Object ob1 = cell.getObject1(); - String owlrel = getRelationName( onto1, rel, ob1 ); - if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); if ( !edoal ) { + String owlrel = getRelationName( onto1, rel, ob1 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); try { writer.print(" <"+owlrel+" rdf:resource=\""+onto1.getEntityURI( ob1 )+"\"/>"+NL); } catch ( OntowrapException owex ) { throw new AlignmentException( "Error accessing ontology", owex ); } } else { - writer.println(" <"+owlrel+">"); + String owlrel = getRelationName( rel, ob1 ); + if ( owlrel == null ) throw new AlignmentException( "Cannot express relation "+rel ); + indentedOutput("<"+owlrel+">"); + writer.print(NL); + increaseIndent(); ((Expression)ob1).accept( this ); - writer.println(" </"+owlrel+">"); + writer.print(NL); + decreaseIndent(); + indentedOutput("</"+owlrel+">"); } } @@ -673,7 +704,7 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements * and Property (DataProperty) constructor than owl:inverseOf * It is thus imposible to transcribe our and, or and not constructors. */ - public void visit(final PropertyConstruction e) throws AlignmentException { + public void visit( final PropertyConstruction e ) throws AlignmentException { Relation toProcessNext = toProcess; toProcess = null; indentedOutput("<owl:DatatypePropety>"+NL); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java index 6bc42f65a6ea2e188f2c3c4b9a195d5a49163b86..0a3b9198f9e46ac22fd718a4659de60804b8b403 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java @@ -306,7 +306,7 @@ public class RDFRendererVisitor extends IndentedRendererVisitor implements Align } } - public void visit( Relation rel ) { + public void visit( Relation rel ) throws AlignmentException { if ( subsumedInvocableMethod( this, rel, Relation.class ) ) return; // default behaviour rel.write( writer ); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/XMLMetadataRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/XMLMetadataRendererVisitor.java index f69c70c1c09397a3972d6b08548ba46d7d5d7586..0b529812ee619b2df45d8bcabf3c5e96bb150f8b 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/XMLMetadataRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/XMLMetadataRendererVisitor.java @@ -149,12 +149,12 @@ public class XMLMetadataRendererVisitor extends GenericReflectiveVisitor impleme writer.print("</rdf:RDF>\n"); } - public void visit( Cell c ) { + public void visit( Cell c ) throws AlignmentException { if ( subsumedInvocableMethod( this, c, Cell.class ) ) return; // default behaviour }; - public void visit( Relation r ) { + public void visit( Relation r ) throws AlignmentException { if ( subsumedInvocableMethod( this, r, Relation.class ) ) return; // default behaviour };