diff --git a/lib/iddl/iddl.jar b/lib/iddl/iddl.jar index 286099a1b682313c2a524d20b7fbf8afaa15f42d..74b8fb8970b9164cf3a3a813df5ee16e48c4ebf3 100644 Binary files a/lib/iddl/iddl.jar and b/lib/iddl/iddl.jar differ diff --git a/lib/iddl/iddl.pom b/lib/iddl/iddl.pom index 7640aa959fc23b963984720de2e6118a4063d783..201fefb0f8042d65668b6d35c929a79afaa1c640 100644 --- a/lib/iddl/iddl.pom +++ b/lib/iddl/iddl.pom @@ -1,11 +1,12 @@ <project> <modelVersion>4.0.0</modelVersion> - <groupId>fr.inrialpes.exmo</groupId> + <groupId>fr.paris8.iut.info.iddl</groupId> <artifactId>iddl</artifactId> - <version>1.3-20100331</version> + <version>1.4d</version> + <!-- Unreleased version of 2013-03-01 --> <name>Integrated Distributed Description Logic</name> - <description>A Resonner for Integrated Distributed Description Logic - special revision of 31/03/2010 (revision 49+)</description> + <description>A Resonner for Integrated Distributed Description Logic</description> <licenses> <license> <name>GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999</name> @@ -14,17 +15,14 @@ </licenses> <url>http://iddl.gforge.inria.fr/</url> - <!--distributionManagement> - <downloadUrl></downloadUrl> - </distributionManagement--> - <!-- align api? Pellet? OWLAPI? --> - <dependencies> + <!-- alignapi owlapi, clairement --> + <!--dependencies> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> - </dependencies> + </dependencies--> </project> diff --git a/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java b/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java index 7dd909b2b94b2c3eb7e2c31f8f9072659ddd5f4e..13a84723a10ab1be8f320f3baa429564cb7bc722 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicEvaluator.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2004, 2007-2008, 2010 + * Copyright (C) INRIA, 2004, 2007-2008, 2010, 2013 * * 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 @@ -24,6 +24,9 @@ import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Evaluator; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.impl.URIAlignment; + import java.io.PrintWriter; /** @@ -40,23 +43,25 @@ public abstract class BasicEvaluator implements Evaluator { /** Creation **/ public BasicEvaluator( Alignment align1, Alignment align2 ) throws AlignmentException { - /* - * JE: This is obviously a killer test. - * Most of the matcher do not fill this correctly - * This should be made smoother - if ( !align1.getOntology1URI().equals( align2.getOntology1URI() ) - || !align1.getOntology2URI().equals( align2.getOntology2URI() ) ) { - System.err.println( " r1: "+align1.getOntology1URI() +" -- "+align1.getFile1() ); - System.err.println( " r2: "+align1.getOntology2URI() +" -- "+align1.getFile2() ); - System.err.println( " u1: "+align2.getOntology1URI() +" -- "+align2.getFile1() ); - System.err.println( " u2: "+align2.getOntology2URI() +" -- "+align2.getFile2() ); - throw new AlignmentException( "The alignments must align the same ontologies\n" ); - } - */ this.align1 = align1; this.align2 = align2; } + public void convertToObjectAlignments( Alignment al1, Alignment al2 ) throws AlignmentException { + align1 = convertToObjectAlignment( al1 ); + align2 = convertToObjectAlignment( al2 ); + } + + public ObjectAlignment convertToObjectAlignment( Alignment al ) throws AlignmentException { + if ( al instanceof ObjectAlignment ) { + return (ObjectAlignment)al; + } else if ( al instanceof URIAlignment ) { + return ObjectAlignment.toObjectAlignment( (URIAlignment)al ); + } else { + throw new AlignmentException( "Cannot convert to ObjectAlignment : "+al ); + } + } + public void write( PrintWriter writer ) throws java.io.IOException { writer.print("<rdf:RDF>\n <Evaluation class=\"BasicEvaluator\">\n <result>"); writer.print(result); diff --git a/src/fr/inrialpes/exmo/align/impl/IDDLOntologyNetwork.java b/src/fr/inrialpes/exmo/align/impl/IDDLOntologyNetwork.java index 6f9ab44d4a99cee63965967c0f7546b573b4cd66..efe7a817a1c6d66d7a24bcddaa42d2410c68c3a1 100644 --- a/src/fr/inrialpes/exmo/align/impl/IDDLOntologyNetwork.java +++ b/src/fr/inrialpes/exmo/align/impl/IDDLOntologyNetwork.java @@ -1,7 +1,7 @@ /* * $Id: IDDLOntologyNetwork.java 987 2009-05-27 13:48:33Z euzenat $ * - * Copyright (C) INRIA, 2009-2010 + * Copyright (C) INRIA, 2009-2010, 2013 * * 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 @@ -35,8 +35,9 @@ import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.LogicOntologyNetwork; -import fr.inrialpes.exmo.iddl.IDDLReasoner; -import fr.inrialpes.exmo.iddl.conf.Semantics; +import fr.paris8.iut.info.iddl.IDDLReasoner; +import fr.paris8.iut.info.iddl.IDDLException; +import fr.paris8.iut.info.iddl.conf.Semantics; /** * Represents a distributed system of aligned ontologies or network of ontologies. @@ -69,11 +70,7 @@ public class IDDLOntologyNetwork extends BasicOntologyNetwork implements LogicOn public void setSemantics( String s ){ semantics = s; if ( reasoner != null ) { - if ( semantics.equals( "DL" ) ) { - reasoner.setSemantics( Semantics.DL ); - } else { - reasoner.setSemantics( Semantics.IDDL ); - } + reasoner.setSemantics( Semantics.valueOf( s ) ); } }; public String getSemantics(){ @@ -83,9 +80,14 @@ public class IDDLOntologyNetwork extends BasicOntologyNetwork implements LogicOn init(); return reasoner.isConsistent(); }; - public boolean isEntailed( Alignment al ){ + public boolean isEntailed( Alignment al ) { init(); - return reasoner.isEntailed( al ); + try { + return reasoner.isEntailed( al ); + } catch ( IDDLException idex ) { + idex.printStackTrace(); + return false; + } }; } diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java index fa0676f027ed3850b6fd8da379b0de67cef9ccc0..f2a414820fa862fa027fe39d68f6343efacb24f6 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java @@ -107,6 +107,7 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { /** Creation **/ public ExtPREvaluator(Alignment align1, Alignment align2) throws AlignmentException { super(align1, align2); + convertToObjectAlignments( align1, align2 ); } public void setConfidence( boolean b ) { withConfidence = b; } @@ -141,9 +142,6 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { public double eval( Properties params, Object cache ) throws AlignmentException { if ( params.getProperty( "noconfidence" ) != null ) withConfidence = false; if ( params.getProperty( "relations" ) != null ) relsensitive = true; - // Better to transform them instead... - if ( !( align1 instanceof ObjectAlignment ) || !( align2 instanceof ObjectAlignment ) ) - throw new AlignmentException( "ExtPREvaluation: requires ObjectAlignments" ); LoadedOntology<Object> o1 = (LoadedOntology<Object>)((ObjectAlignment)align1).getOntologyObject1(); LoadedOntology<Object> o2 = (LoadedOntology<Object>)((ObjectAlignment)align1).getOntologyObject2(); if ( !( o1 instanceof HeavyLoadedOntology ) || !( o2 instanceof HeavyLoadedOntology ) ) diff --git a/src/fr/inrialpes/exmo/align/impl/eval/SemPRecEvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/SemPRecEvaluator.java index b854f89a2d3ad706ce758b6723806cb7212a3c0b..b0103186adfb71d39d1047fa0f46ed690643d0c6 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/SemPRecEvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/SemPRecEvaluator.java @@ -40,10 +40,12 @@ import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; import fr.inrialpes.exmo.ontowrap.OntowrapException; -//import fr.paris8.iut.info.iddl.IDDLReasoner; -//import fr.paris8.iut.info.iddl.conf.Semantics; +// ---- IDDL +import fr.paris8.iut.info.iddl.IDDLReasoner; +import fr.paris8.iut.info.iddl.IDDLException; +import fr.paris8.iut.info.iddl.conf.Semantics; -// HermiT implementation +// ---- HermiT Implementation import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLOntology; @@ -64,6 +66,9 @@ import org.semanticweb.owlapi.reasoner.BufferingMode; import org.semanticweb.HermiT.Reasoner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.IOException; import java.io.FileWriter; @@ -75,6 +80,7 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.lang.Thread; import java.lang.Runnable; +import java.lang.IllegalArgumentException; import java.util.Properties; import java.util.Enumeration; @@ -94,10 +100,12 @@ import java.net.URI; public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { + final Logger logger = LoggerFactory.getLogger( SemPRecEvaluator.class ); private int nbfoundentailed = 0; // nb of returned cells entailed by the reference alignment private int nbexpectedentailed = 0; // nb of reference cells entailed by returned alignment - //private Semantics semantics = Semantics.DL; // the semantics used for interpreting alignments + private Semantics semantics = null; // the semantics used for interpreting alignments + // null means that we use the reduced semantics with HermiT, otherwise, this is an IDDL semantics /** Creation * Initiate Evaluator for precision and recall @@ -105,31 +113,20 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { * @param align2 : the alignment to evaluate **/ public SemPRecEvaluator( Alignment al1, Alignment al2) throws AlignmentException { - super(((BasicAlignment)al1).toURIAlignment(), ((BasicAlignment)al2).toURIAlignment()); - try { - if ( al1 instanceof ObjectAlignment ) { - align1 = al1; - } else { - align1 = ObjectAlignment.toObjectAlignment((URIAlignment)align1); - } - if ( al2 instanceof ObjectAlignment ) { - align2 = al2; - } else { - align2 = ObjectAlignment.toObjectAlignment((URIAlignment)align2); - } - } catch ( AlignmentException aex ) { - throw new AlignmentException( "SemPRecEvaluator can only work on ObjectAlignments", aex ); - } + super( al1, al2 ); + logger.info( "Created one SemPREvaluator" ); + convertToObjectAlignments( al1, al2 ); } - public void init( Object sem ){ + public void init( Properties params ){ super.init(); // ?? nbexpectedentailed = 0; nbfoundentailed = 0; - // Better use Properties - //if ( sem instanceof Semantics ) { - // semantics = (Semantics)sem; - //} + // Set the semantics to be used + String sem = params.getProperty( "semantics" ); + if ( sem != null ) { + semantics = Semantics.valueOf( sem ); + } } /** @@ -146,10 +143,10 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { * * In the implementation |B|=nbfound, |A|=nbexpected and |A inter B|=nbcorrect. * - * This takes semantivs as a parameter which should be a litteral of fr.paris8.iut.info.iddl.conf.Semantics + * This takes semantics as a parameter which should be a litteral of fr.paris8.iut.info.iddl.conf.Semantics */ public double eval( Properties params ) throws AlignmentException { - init( params.getProperty( "semantics" ) ); + init( params ); nbfound = align2.nbCells(); nbexpected = align1.nbCells(); @@ -172,37 +169,47 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { } public int nbEntailedCorrespondences( ObjectAlignment al1, ObjectAlignment al2 ) throws AlignmentException { - //System.err.println( "Computing correctness" ); - //IDDLReasoner reasoner = new IDDLReasoner( semantics ); - //loadOntology( reasoner, ((BasicAlignment)al1).getOntologyObject1() ); - //loadOntology( reasoner, ((BasicAlignment)al1).getOntologyObject2() ); - //reasoner.addAlignment( al1 ); - loadPipedAlignedOntologies( al1 ); + logger.debug( "Computing entailment (semantics: {})", semantics ); + if ( semantics != null ) { // IDDL + IDDLReasoner iddlreasoner = new IDDLReasoner( semantics ); + loadOntology( iddlreasoner, ((BasicAlignment)al1).getOntologyObject1() ); + loadOntology( iddlreasoner, ((BasicAlignment)al1).getOntologyObject2() ); + iddlreasoner.addAlignment( al1 ); + reasoner = iddlreasoner; + } else { // Hermit + loadPipedAlignedOntologies( al1 ); + } if ( !reasoner.isConsistent() ) return al2.nbCells(); // everything is entailed - //System.err.println( al1+" is consistent" ); + logger.debug( "{} is consistent", al1 ); int entailed = 0; for ( Cell c2 : al2 ) { - // create alignment - //Alignment al = new ObjectAlignment(); - //al.init( align2.getOntology1URI(), align2.getOntology2URI() ); - // add the cell - //al.addAlignCell( c2.getObject1(), c2.getObject2(), c2.getRelation().getRelation(), 1. ); - //System.err.println( c2.getObject1()+" "+c2.getRelation().getRelation()+" "+c2.getObject2() ); - //if ( reasoner.isEntailed( al ) ) { - try { - if ( reasoner.isEntailed( correspToAxiom( al2, (ObjectCell)c2 ) ) ) { - //System.err.println( " --> entailed" ); - entailed++; + logger.trace( c2.getObject1()+" {} {}", c2.getRelation().getRelation(), c2.getObject2() ); + if ( semantics != null ) { // IDDL + try { + if ( ((IDDLReasoner)reasoner).isEntailed( al2, c2 ) ) { + logger.trace( " --> entailed" ); + entailed++; + } + } catch (IDDLException idex) { // counted as non entailed + logger.warn( "Cannot be translated." ); + } + } else { // Hermit + try { + if ( reasoner.isEntailed( correspToAxiom( al2, (ObjectCell)c2 ) ) ) { + logger.trace( " --> entailed" ); + entailed++; + } + } catch ( AlignmentException aex ) { // type mismatch -> 0 + logger.warn( "Cannot be translated." ); } - } catch ( AlignmentException aex ) { // type mismatch -> 0 - //System.err.println( "Cannot be translated." ); } } return entailed; } /** - * It would be useful to do better since we have the two ontologies here + * It would be useful to directly use the Ontologies since they are already loaded + * Two implementation of Alignment loading: one with intermediate file and one without. */ protected OWLOntologyManager manager = null; protected OWLReasoner reasoner = null; @@ -213,37 +220,42 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { public void loadPipedAlignedOntologies( final ObjectAlignment align ) throws AlignmentException { PipedInputStream in = new PipedInputStream(); try { - final PipedOutputStream out = new PipedOutputStream(in); - new Thread( - new Runnable(){ - public void run() { - PrintWriter writer; - try { - writer = new PrintWriter ( - new BufferedWriter( - new OutputStreamWriter( out, "UTF-8" )), true); - } catch ( Exception ex ) { - return; //throw new AlignmentException( "Cannot load alignments because of I/O errors" ); - } - OWLAxiomsRendererVisitor renderer = new OWLAxiomsRendererVisitor( writer ); - renderer.init( new Properties() ); - // Generate the ontology as OWL Axioms - try { - align.render( renderer ); - } catch ( AlignmentException aex ) { - return; - } finally { - writer.flush(); - writer.close(); - } + final PipedOutputStream out = new PipedOutputStream(in); + Thread myThread = new Thread( + new Runnable(){ + public void run() { + PrintWriter writer = null; + try { + writer = new PrintWriter ( + new BufferedWriter( + new OutputStreamWriter( out, "UTF-8" )), true); + OWLAxiomsRendererVisitor renderer = new OWLAxiomsRendererVisitor( writer ); + renderer.init( new Properties() ); + // Generate the ontology as OWL Axioms + align.render( renderer ); + } catch ( Exception ex ) { + // No way to handle this exception??? + // At worse, the other end will raise an exception + logger.error( "Cannot render alignment to OWL", ex ); + } finally { + if ( writer != null ) { + writer.flush(); + writer.close(); } - } - ).start(); - } catch ( Exception ex ) {};//java.io.UnsupportedEncodingException + } + } + } + ); + myThread.start(); + } catch ( UnsupportedEncodingException ueex ) { + throw new AlignmentException( "Cannot render alignment to OWL", ueex ); + } catch ( IOException ioex ) { + throw new AlignmentException( "Cannot render alignment to OWL", ioex ); + } manager = OWLManager.createOWLOntologyManager(); - //System.err.println( al.getOntology1URI()+" ----> "+al.getFile1() ); - //System.err.println( al.getOntology2URI()+" ----> "+al.getFile2() ); + logger.debug( "{} ----> {}", align.getOntology1URI(), align.getFile1() ); + logger.debug( "{} ----> {}", align.getOntology2URI(), align.getFile2() ); manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology1URI() ), IRI.create( align.getFile1() ) ) ); manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology2URI() ), @@ -255,7 +267,9 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { OWLOntology ontology = manager.loadOntologyFromOntologyDocument( in ); reasoner = new Reasoner( ontology ); } catch ( OWLOntologyCreationException ooce ) { - ooce.printStackTrace(); + throw new AlignmentException( "Hermit : Cannot load alignment", ooce ); + } catch ( IllegalArgumentException ilex ) { + throw new AlignmentException( "Hermit : Cannot load alignment", ilex ); } } @@ -271,14 +285,12 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { merged.deleteOnExit(); writer = new PrintWriter ( new FileWriter( merged, false ), true ); OWLAxiomsRendererVisitor renderer = new OWLAxiomsRendererVisitor(writer); - //renderer.init( new Properties() ); - align.render(renderer); - } catch (UnsupportedEncodingException uee) { - uee.printStackTrace(); - } catch (AlignmentException ae) { - ae.printStackTrace(); - } catch (IOException ioe) { - ioe.printStackTrace(); + renderer.init( new Properties() ); + align.render( renderer ); + } catch (UnsupportedEncodingException ueex) { + throw new AlignmentException( "Cannot render alignment to OWL", ueex ); + } catch (IOException ioex) { + throw new AlignmentException( "Cannot render alignment to OWL", ioex ); } finally { if ( writer != null ) { writer.flush(); @@ -288,17 +300,21 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { // Load the ontology manager = OWLManager.createOWLOntologyManager(); + logger.debug( "{} ----> {}", align.getOntology1URI(), align.getFile1() ); + logger.debug( "{} ----> {}", align.getOntology2URI(), align.getFile2() ); + manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology1URI() ), + IRI.create( align.getFile1() ) ) ); + manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology2URI() ), + IRI.create( align.getFile2() ) ) ); try { - manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology1URI() ), - IRI.create( align.getFile1() ) ) ); - manager.addIRIMapper(new SimpleIRIMapper( IRI.create( align.getOntology2URI() ), - IRI.create( align.getFile2() ) ) ); manager.loadOntologyFromOntologyDocument( IRI.create( align.getFile1() ) ); manager.loadOntologyFromOntologyDocument( IRI.create( align.getFile2() ) ); OWLOntology ontology = manager.loadOntologyFromOntologyDocument( merged ); reasoner = new Reasoner( ontology ); - } catch (OWLOntologyCreationException ooce) { - ooce.printStackTrace(); + } catch ( OWLOntologyCreationException ooce ) { + throw new AlignmentException( "Hermit : Cannot load alignment", ooce ); + } catch ( IllegalArgumentException ilex ) { + throw new AlignmentException( "Hermit : Cannot load alignment", ilex ); } } @@ -375,23 +391,13 @@ public class SemPRecEvaluator extends PRecEvaluator implements Evaluator { throw new AlignmentException( "Cannot convert correspondence "+corresp ); } - // This method can be suppressed - public boolean isConsistent( OWLReasoner reasoner ) { - return reasoner.isConsistent(); - } - - // This method can be suppressed - public boolean isEntailed( OWLAxiom axiom ) { - return reasoner.isEntailed( axiom ); + // load ontology for the IDDLReasoner + public void loadOntology( IDDLReasoner reasoner, Object onto ) { + Ontology oo = (Ontology)onto; + URI f = oo.getFile(); + if ( f == null ) f = oo.getURI(); + reasoner.addOntology( f ); } - //public void loadOntology( IDDLReasoner reasoner, Object onto ) { - // System.err.println( reasoner +" -- "+onto ); - // Ontology oo = (Ontology)onto; - // URI f = oo.getFile(); - // if ( f == null ) f = oo.getURI(); - // reasoner.addOntology( f ); - //} - } diff --git a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java index f1e8c77517bbfd15c7f218185d90f883b5f4416a..a7b5d827beb181ece9103c0082cd3c49f477dfa2 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java @@ -62,9 +62,7 @@ public class SymMeanEvaluator extends BasicEvaluator implements Evaluator { /** Creation **/ public SymMeanEvaluator( Alignment align1, Alignment align2 ) throws AlignmentException { super(align1,align2); - if ( !( align1 instanceof ObjectAlignment ) || - !( align2 instanceof ObjectAlignment ) ) - throw new AlignmentException( "Alignments should be ObjectAlignments, try to " ); + convertToObjectAlignments( align1, align2 ); } public double eval( Properties params ) throws AlignmentException { @@ -78,6 +76,7 @@ public class SymMeanEvaluator extends BasicEvaluator implements Evaluator { classScore = 0.; propScore = 0.; indScore = 0.; + // This seems to be correct LoadedOntology onto1 = (LoadedOntology)((ObjectAlignment)align1).getOntologyObject1(); LoadedOntology onto2 = (LoadedOntology)((ObjectAlignment)align2).getOntologyObject1();