diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java index 352c70ea9d970c83a905fbcc5feaa90e769c1f09..46894fba4ed8797ea15584d9197db3356dcea447 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java @@ -45,6 +45,7 @@ import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.BasicOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Represents a basic ontology alignment, i.e., a fully functionnal alignment @@ -103,6 +104,7 @@ public class BasicAlignment implements Alignment { init( onto1, onto2 ); } + @SuppressWarnings( "unchecked" ) public void init( Object onto1, Object onto2 ) throws AlignmentException { if ( onto1 instanceof Ontology ) { this.onto1 = (Ontology<Object>)onto1; // [W:unchecked] diff --git a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java index 5689aba65bbb28a1f546f217e6ab2b54bfa1e845..5f5b12bf27c294171718ab654dce103f6ff1d565 100644 --- a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java @@ -34,6 +34,7 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.ontosim.util.HungarianAlgorithm; @@ -209,6 +210,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce } } } + } catch (OntowrapException owex) { owex.printStackTrace(); //} } catch (AlignmentException alex) { alex.printStackTrace(); } return((Alignment)this); } @@ -294,45 +296,46 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce } catch (AlignmentException alex) { alex.printStackTrace(); } // For individuals if ( params.getProperty("noinst") == null ){ - try{ - // Create individual lists - Object[] ind1 = new Object[ontology1().nbIndividuals()]; - Object[] ind2 = new Object[ontology2().nbIndividuals()]; - int nbind1 = 0; - int nbind2 = 0; - for( Object ob : ontology2().getIndividuals() ){ - // We suppress anonymous individuals... this is not legitimate - if ( ontology2().getEntityURI( ob ) != null ) { - ind2[nbind2++] = ob; + try{ + // Create individual lists + Object[] ind1 = new Object[ontology1().nbIndividuals()]; + Object[] ind2 = new Object[ontology2().nbIndividuals()]; + int nbind1 = 0; + int nbind2 = 0; + for( Object ob : ontology2().getIndividuals() ){ + // We suppress anonymous individuals... this is not legitimate + if ( ontology2().getEntityURI( ob ) != null ) { + ind2[nbind2++] = ob; + } } - } - for( Object ob : ontology1().getIndividuals() ){ - // We suppress anonymous individuals... this is not legitimate - if ( ontology1().getEntityURI( ob ) != null ) { - ind1[nbind1++] = ob; + for( Object ob : ontology1().getIndividuals() ){ + // We suppress anonymous individuals... this is not legitimate + if ( ontology1().getEntityURI( ob ) != null ) { + ind1[nbind1++] = ob; + } } - } - double[][] matrix = new double[nbind1][nbind2]; - int i, j; - for( i=0; i < nbind1; i++ ){ - for( j=0; j < nbind2; j++ ){ - matrix[i][j] = 1 - sim.getIndividualSimilarity(ind1[i],ind2[j]); + double[][] matrix = new double[nbind1][nbind2]; + int i, j; + for( i=0; i < nbind1; i++ ){ + for( j=0; j < nbind2; j++ ){ + matrix[i][j] = 1 - sim.getIndividualSimilarity(ind1[i],ind2[j]); + } } - } - // Pass it to the algorithm - int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" ); - // Extract the result - for( i=0; i < result.length ; i++ ){ - // The matrix has been destroyed - double val = 1 - sim.getIndividualSimilarity(ind1[result[i][0]],ind2[result[i][1]]); - // JE: here using strict-> is a very good idea. - // it means that alignments with 0. similarity - // will be excluded from the best match. - if( val > threshold ){ - addCell( new ObjectCell( (String)null, ind1[result[i][0]], ind2[result[i][1]], BasicRelation.createRelation("="), val ) ); + // Pass it to the algorithm + int[][] result = HungarianAlgorithm.hgAlgorithm( matrix, "max" ); + // Extract the result + for( i=0; i < result.length ; i++ ){ + // The matrix has been destroyed + double val = 1 - sim.getIndividualSimilarity(ind1[result[i][0]],ind2[result[i][1]]); + // JE: here using strict-> is a very good idea. + // it means that alignments with 0. similarity + // will be excluded from the best match. + if( val > threshold ){ + addCell( new ObjectCell( (String)null, ind1[result[i][0]], ind2[result[i][1]], BasicRelation.createRelation("="), val ) ); + } } - } - } catch (AlignmentException alex) { alex.printStackTrace(); } + } catch (AlignmentException alex) { alex.printStackTrace(); //} + } catch (OntowrapException owex) { owex.printStackTrace(); } } return((Alignment)this); } @@ -379,7 +382,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce return -1; // Assume they have different names } else { return 1; } - } catch ( AlignmentException e) { + } catch ( OntowrapException e) { e.printStackTrace(); return 0;} } } @@ -441,6 +444,8 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce } catch (AlignmentException alex) { alex.printStackTrace(); + } catch (OntowrapException owex) { + owex.printStackTrace(); }; return((Alignment)this); } diff --git a/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java b/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java index 38724dfbc6f7be5b2a8f39b592707d3b4bea6795..f032846a3ea488442c17d38b65be1353a70a3e09 100644 --- a/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java +++ b/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java @@ -32,6 +32,7 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.align.impl.Similarity; import fr.inrialpes.exmo.align.impl.ObjectAlignment; @@ -159,7 +160,7 @@ public abstract class MatrixMeasure implements Similarity { } indmatrix = new double[nbind1+1][nbind2+1]; //System.err.println(nbclass1+"/"+nbclass2+" - "+nbprop1+"/"+nbprop2+" - "+nbind1+"/"+nbind2); - } catch (AlignmentException e) { e.printStackTrace(); }; + } catch (OntowrapException e) { e.printStackTrace(); }; } public void compute( Properties params ){ @@ -229,7 +230,7 @@ public abstract class MatrixMeasure implements Similarity { } System.out.println("\\\\"); } - } catch (AlignmentException e) { e.printStackTrace(); }; + } catch (OntowrapException e) { e.printStackTrace(); }; System.out.println("\n\\end{tabular}"); } diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java index c69b106c65e09af30d4d41f65bff08ff3d7cc7b7..0e9844e27c5e1cf7dfac2ebcb748d43545e9de8f 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java @@ -43,6 +43,7 @@ import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Represents an OWL ontology alignment. An ontology comprises a number of @@ -140,25 +141,33 @@ public class ObjectAlignment extends BasicAlignment { } LoadedOntology<Object> o1 = (LoadedOntology<Object>)alignment.getOntologyObject1(); // [W:unchecked] LoadedOntology<Object> o2 = (LoadedOntology<Object>)alignment.getOntologyObject2(); // [W:unchecked] - for ( Cell c : al ) { - Cell newc = alignment.addAlignCell( c.getId(), - o1.getEntity( c.getObject1AsURI(alignment) ), - o2.getEntity( c.getObject2AsURI(alignment) ), - c.getRelation(), - c.getStrength() ); - Collection<String[]> exts = c.getExtensions(); - if ( exts != null ) { - for ( String[] ext : exts ){ - newc.setExtension( ext[0], ext[1], ext[2] ); + try { + for ( Cell c : al ) { + Cell newc = alignment.addAlignCell( c.getId(), + o1.getEntity( c.getObject1AsURI(alignment) ), + o2.getEntity( c.getObject2AsURI(alignment) ), + c.getRelation(), + c.getStrength() ); + Collection<String[]> exts = c.getExtensions(); + if ( exts != null ) { + for ( String[] ext : exts ){ + newc.setExtension( ext[0], ext[1], ext[2] ); + } } } - }; + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot dereference entity", owex ); + } return alignment; } static LoadedOntology loadOntology( URI ref ) throws AlignmentException { OntologyFactory factory = OntologyFactory.getFactory(); - return factory.loadOntology( ref ); + try { + return factory.loadOntology( ref ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot load ontology "+ref, owex ); + } } } diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java index e0536aa9baca0e8a7bf7aee78eabb4d2478a7b10..3e811a964da97aaee963c812b40bc2eddf9fd365 100644 --- a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java +++ b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java @@ -34,6 +34,7 @@ import org.semanticweb.owl.align.Relation; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.align.impl.BasicAlignment; @@ -81,7 +82,11 @@ public class ObjectCell extends BasicCell { if ( al instanceof BasicAlignment ) { Object ontology = ((BasicAlignment)al).getOntologyObject1(); if ( ontology instanceof LoadedOntology ) { - return ((LoadedOntology)ontology).getEntityURI( object1 ); + try { + return ((LoadedOntology)ontology).getEntityURI( object1 ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI(1)", owex ); + } } }; if ( object1 instanceof URI ) { @@ -94,7 +99,11 @@ public class ObjectCell extends BasicCell { if ( al instanceof BasicAlignment ) { Object ontology = ((BasicAlignment)al).getOntologyObject2(); if ( ontology instanceof LoadedOntology ) { - return ((LoadedOntology)ontology).getEntityURI( object2 ); + try { + return ((LoadedOntology)ontology).getEntityURI( object2 ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI(2)", owex ); + } } }; if ( object2 instanceof URI ) { diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java index 566c5db626efd8622bfe7d9fe84bcef2f21c5969..3c3c5ed5adb8f882379332a8f51ef2f1d7f47090 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java @@ -29,6 +29,7 @@ import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.util.Enumeration; import java.util.Properties; @@ -118,14 +119,19 @@ public class ExtPREvaluator extends BasicEvaluator { if( s2 != null ){ for( Iterator it2 = s2.iterator(); it2.hasNext() && c1 != null; ){ Cell c2 = (Cell)it2.next(); - URI uri1 = onto2.getEntityURI( c1.getObject2() ); - URI uri2 = onto2.getEntityURI( c2.getObject2() ); - // if (c1.getobject2 == c2.getobject2) - if ( uri1.toString().equals(uri2.toString()) ) { - symsimilarity += 1.; - effsimilarity += 1.; - orientsimilarity += 1.; - c1 = null; // out of the loop. + try { + URI uri1 = onto2.getEntityURI( c1.getObject2() ); + URI uri2 = onto2.getEntityURI( c2.getObject2() ); + // if ( uri1.equals( uri2 ) ) + if ( uri1.toString().equals(uri2.toString()) ) { + symsimilarity += 1.; + effsimilarity += 1.; + orientsimilarity += 1.; + c1 = null; // out of the loop. + } + } catch ( OntowrapException owex ) { + // This may be ignored as well + throw new AlignmentException( "Cannot find entity URI", owex ); } } // if nothing has been found @@ -178,6 +184,7 @@ public class ExtPREvaluator extends BasicEvaluator { if ( val != 0 && val < minval ) minval = val; } } + } catch( OntowrapException aex ) { return 0; } catch( AlignmentException aex ) { return 0; } //return symALPHA; //^minval; return Math.pow( symALPHA, minval ); @@ -239,26 +246,30 @@ public class ExtPREvaluator extends BasicEvaluator { * It would require to have a isDirectSubClassOf(). */ public int isSuperClass( Object class1, Object class2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { - URI uri1 = ontology.getEntityURI( class1 ); - Set<Object> bufferedSuperClasses = null; - Set<Object> superclasses = ontology.getSuperClasses( class1, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ); - int level = 0; - - while ( !superclasses.isEmpty() ){ - bufferedSuperClasses = superclasses; - superclasses = new HashSet<Object>(); - level++; - for( Object entity : bufferedSuperClasses ) { - if ( ontology.isClass( entity ) ){ - URI uri2 = ontology.getEntityURI( entity ); - //if ( entity == class2 ) return true; - if ( uri1.toString().equals(uri2.toString()) ) { - return level; - } else { - superclasses.addAll( ontology.getSuperClasses( entity, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ) ); + try { + URI uri1 = ontology.getEntityURI( class1 ); + Set<Object> bufferedSuperClasses = null; + Set<Object> superclasses = ontology.getSuperClasses( class1, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ); + int level = 0; + + while ( !superclasses.isEmpty() ){ + bufferedSuperClasses = superclasses; + superclasses = new HashSet<Object>(); + level++; + for( Object entity : bufferedSuperClasses ) { + if ( ontology.isClass( entity ) ){ + URI uri2 = ontology.getEntityURI( entity ); + //if ( entity == class2 ) return true; + if ( uri1.toString().equals(uri2.toString()) ) { + return level; + } else { + superclasses.addAll( ontology.getSuperClasses( entity, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ) ); + } } } } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } // get the return 0; diff --git a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java index b37617eb12bd0cafdb88f6e86e26b4aef635682c..5042287423bf616022a65bdefb5f1c2fe85380f9 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java @@ -32,6 +32,7 @@ import org.semanticweb.owl.align.AlignmentException; import fr.inrialpes.exmo.align.impl.DistanceAlignment; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.ontosim.string.StringDistances; @@ -108,12 +109,16 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment // Initialize class distances // JE: Here AlignmentException is raised if cl or classlist2.get(j) // cannot be identified as an Entity, maybe this should be traped here - for ( i=0; i<nbclass1; i++ ){ - Object cl = classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1 * StringDistances.subStringDistance(honto1.getEntityName( cl ).toLowerCase(), - honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + try { + for ( i=0; i<nbclass1; i++ ){ + Object cl = classlist1.get(i); + for ( j=0; j<nbclass2; j++ ){ + classmatrix[i][j] = pic1 * StringDistances.subStringDistance(honto1.getEntityName( cl ).toLowerCase(), + honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + } } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } if (debug > 0) System.err.print("Computing class distances\n"); diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java index ce5653de476f058eef6ed702e350420c19c9b4e8..261acb76c0992ee2d2d618a2348c7142e36c62e1 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java @@ -33,6 +33,7 @@ import org.semanticweb.owl.align.AlignmentException; import fr.inrialpes.exmo.align.impl.DistanceAlignment; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.ontosim.string.StringDistances; @@ -128,32 +129,34 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align } classmatrix = new double[nbclass1+1][nbclass2+1]; - if (debug > 0) System.err.println("Initializing property distances"); - - for ( i=0; i<nbprop1; i++ ){ - Object cl1 = proplist1.get(i); - String st1 = honto1.getEntityName( cl1 ); - if ( st1 != null) st1 = st1.toLowerCase(); - for ( j=0; j<nbprop2; j++ ){ - Object cl2 = proplist2.get(j); - String st2 = honto2.getEntityName( cl2 ); - if( st2 != null ) st2 = st2.toLowerCase(); - if ( st1 != null || st2 != null ) { - propmatrix[i][j] = pia1 * StringDistances.subStringDistance( st1, st2 ); - } else { - propmatrix[i][j] = 1.; + try { + if (debug > 0) System.err.println("Initializing property distances"); + for ( i=0; i<nbprop1; i++ ){ + Object cl1 = proplist1.get(i); + String st1 = honto1.getEntityName( cl1 ); + if ( st1 != null) st1 = st1.toLowerCase(); + for ( j=0; j<nbprop2; j++ ){ + Object cl2 = proplist2.get(j); + String st2 = honto2.getEntityName( cl2 ); + if( st2 != null ) st2 = st2.toLowerCase(); + if ( st1 != null || st2 != null ) { + propmatrix[i][j] = pia1 * StringDistances.subStringDistance( st1, st2 ); + } else { + propmatrix[i][j] = 1.; + } } } - } - - if (debug > 0) System.err.println("Initializing class distances"); - // Initialize class distances - for ( i=0; i<nbclass1; i++ ){ - Object cl1 = classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1*StringDistances.subStringDistance( honto1.getEntityName( cl1 ).toLowerCase(), honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + // Initialize class distances + if (debug > 0) System.err.println("Initializing class distances"); + for ( i=0; i<nbclass1; i++ ){ + Object cl1 = classlist1.get(i); + for ( j=0; j<nbclass2; j++ ){ + classmatrix[i][j] = pic1*StringDistances.subStringDistance( honto1.getEntityName( cl1 ).toLowerCase(), honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + } } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } // Iterate until completion @@ -259,13 +262,13 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align i++; try { s1 = honto1.getEntityName( property1 ).toLowerCase(); - } catch (AlignmentException aex) { s1 = null; }; + } catch ( OntowrapException aex ) { s1 = null; }; for ( Object property2 : prop2 ) { j++; try { s2 = honto2.getEntityName( property2 ).toLowerCase(); propmatrix[i][j] = 1.0-StringDistances.subStringDistance( s1, s2 ); - } catch (AlignmentException aex) { + } catch ( OntowrapException aex ) { propmatrix[i][j] = 0.0; } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java index 120fce2683d6993f1881c72ad76e2c1867161099..4544cb1cdd296d7f9b0e4869f8d842a68a92c751 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java @@ -34,6 +34,7 @@ import org.semanticweb.owl.align.AlignmentException; import fr.inrialpes.exmo.align.impl.DistanceAlignment; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import fr.inrialpes.exmo.ontosim.string.StringDistances; @@ -130,32 +131,35 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme } classmatrix = new double[nbclass1+1][nbclass2+1]; - if (debug > 0) System.err.println("Initializing property distances"); - - for ( i=0; i<nbprop1; i++ ){ - Object cl1 = proplist1.get(i); - String st1 = honto1.getEntityName( cl1 ); - if ( st1 != null) st1 = st1.toLowerCase(); - for ( j=0; j<nbprop2; j++ ){ - Object cl2 = proplist2.get(j); - String st2 = honto2.getEntityName( cl2 ); - if( st2 != null ) st2 = st2.toLowerCase(); - if ( st1 != null || st2 != null ) { - propmatrix[i][j] = pia1 * StringDistances.subStringDistance( st1, st2 ); - } else { - propmatrix[i][j] = pia1; + try{ + if (debug > 0) System.err.println("Initializing property distances"); + + for ( i=0; i<nbprop1; i++ ){ + Object cl1 = proplist1.get(i); + String st1 = honto1.getEntityName( cl1 ); + if ( st1 != null) st1 = st1.toLowerCase(); + for ( j=0; j<nbprop2; j++ ){ + Object cl2 = proplist2.get(j); + String st2 = honto2.getEntityName( cl2 ); + if( st2 != null ) st2 = st2.toLowerCase(); + if ( st1 != null || st2 != null ) { + propmatrix[i][j] = pia1 * StringDistances.subStringDistance( st1, st2 ); + } else { + propmatrix[i][j] = pia1; + } } } - } - if (debug > 0) System.err.println("Initializing class distances"); - - // Initialize class distances - for ( i=0; i<nbclass1; i++ ){ - Object cl1 = classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1*StringDistances.subStringDistance( honto1.getEntityName( cl1 ).toLowerCase(), honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + // Initialize class distances + if (debug > 0) System.err.println("Initializing class distances"); + for ( i=0; i<nbclass1; i++ ){ + Object cl1 = classlist1.get(i); + for ( j=0; j<nbclass2; j++ ){ + classmatrix[i][j] = pic1*StringDistances.subStringDistance( honto1.getEntityName( cl1 ).toLowerCase(), honto2.getEntityName( classlist2.get(j) ).toLowerCase()); + } } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } // Iterate until completion diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java index fe3984d0f946ade70e69b609595e6ce893781a87..3c52364eca611baa0d50ce479a1b8d6352273254 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java @@ -37,6 +37,7 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Renders an alignment as a new ontology merging these. @@ -176,14 +177,18 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor } public void printObject( Object ob, LoadedOntology onto ) throws AlignmentException { - if ( onto.isClass( ob ) ) { - writer.print(" <owl:Class rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); - } else if ( onto.isDataProperty( ob ) ) { - writer.print(" <owl:DataProperty rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); - } else if ( onto.isObjectProperty( ob ) ) { - writer.print(" <owl:ObjectProperty rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); - } else if ( onto.isIndividual( ob ) ) { - writer.print(" <owl:Individual rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); + try { + if ( onto.isClass( ob ) ) { + writer.print(" <owl:Class rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); + } else if ( onto.isDataProperty( ob ) ) { + writer.print(" <owl:DataProperty rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); + } else if ( onto.isObjectProperty( ob ) ) { + writer.print(" <owl:ObjectProperty rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); + } else if ( onto.isIndividual( ob ) ) { + writer.print(" <owl:Individual rdf:about=\""+onto.getEntityURI(ob)+"\"/>\n"); + } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java index 1fab9c3ac7b868e92ad3507f3c0cd256b825a95a..f36601ea246fe3654f70609017c9d9fe4c97a333 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java @@ -37,7 +37,9 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; + import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Renders an alignment as a new ontology merging these. @@ -88,32 +90,36 @@ public class SEKTMappingRendererVisitor implements AlignmentVisitor { String id = String.format( "s%06d", generator.nextInt(100000) ); Object ob1 = cell.getObject1(); Object ob2 = cell.getObject2(); - if ( onto1.isClass( ob1 ) ) { - writer.print(" classMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); - writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); - writer.print(" )\n"); - } else if ( onto1.isDataProperty( ob1 ) ) { - writer.print(" relationMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); - writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); - writer.print(" )\n"); - } else if ( onto1.isObjectProperty( ob1 ) ) { - writer.print(" attributeMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); - writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); - writer.print(" )\n"); - } else if ( onto1.isIndividual( ob1 ) ) { - writer.print(" instanceMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); - writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); - writer.print(" )\n"); + try { + if ( onto1.isClass( ob1 ) ) { + writer.print(" classMapping( <\"#"+id+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); + writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); + writer.print(" )\n"); + } else if ( onto1.isDataProperty( ob1 ) ) { + writer.print(" relationMapping( <\"#"+id+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); + writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); + writer.print(" )\n"); + } else if ( onto1.isObjectProperty( ob1 ) ) { + writer.print(" attributeMapping( <\"#"+id+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); + writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); + writer.print(" )\n"); + } else if ( onto1.isIndividual( ob1 ) ) { + writer.print(" instanceMapping( <\"#"+id+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" <\""+onto1.getEntityURI( ob1 )+"\">\n"); + writer.print(" <\""+onto2.getEntityURI( ob2 )+"\">\n"); + writer.print(" )\n"); + } + writer.print("\n"); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); } - writer.print("\n"); } public void visit( EquivRelation rel ) throws AlignmentException { diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java index 0e6f82a2aa5a263193ad5e1790cc87d0f45f376e..85b11cc1da71ed4138ec62158e8cf320a2fa945e 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java @@ -37,7 +37,9 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.rel.*; import fr.inrialpes.exmo.align.impl.ObjectAlignment; + import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Renders an alignment as a new ontology merging these. @@ -104,7 +106,11 @@ public class SKOSRendererVisitor implements AlignmentVisitor { public URI getURI2() throws AlignmentException { if ( onto2 != null ) { - return onto2.getEntityURI( cell.getObject2() ); + try { + return onto2.getEntityURI( cell.getObject2() ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } } else { return cell.getObject2AsURI( alignment ); } @@ -113,7 +119,11 @@ public class SKOSRendererVisitor implements AlignmentVisitor { public void visit( Cell cell ) throws AlignmentException { this.cell = cell; if ( onto1 != null ) { - writer.print(" <skos:Concept rdf:about=\""+onto1.getEntityURI( cell.getObject1() )+"\">\n"); + try { + writer.print(" <skos:Concept rdf:about=\""+onto1.getEntityURI( cell.getObject1() )+"\">\n"); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } } else { writer.print(" <skos:Concept rdf:about=\""+cell.getObject1AsURI( alignment )+"\">\n"); } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java index 51b5e4d4d73ebb0f9c1bfe36b34455fe2ba56d19..7edc629eb6d32428ab4ac491323843b978b6ed7a 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java @@ -37,7 +37,9 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; + import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Renders an alignment as a SWRL rule set interpreting @@ -103,7 +105,12 @@ public class SWRLRendererVisitor implements AlignmentVisitor { public void visit( EquivRelation rel ) throws AlignmentException { // JE: We should send warnings when dataproperties are mapped to individual properties and vice versa... Object ob1 = cell.getObject1(); - URI uri1 = onto1.getEntityURI( ob1 ); + URI uri1; + try { + uri1 = onto1.getEntityURI( ob1 ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI(1)", owex ); + } writer.println(" <ruleml:imp>"); writer.println(" <ruleml:_body>"); if ( onto1.isClass( ob1 ) ){ @@ -125,7 +132,12 @@ public class SWRLRendererVisitor implements AlignmentVisitor { writer.println(" </ruleml:_body>"); writer.println(" <ruleml:_head>"); Object ob2 = cell.getObject2(); - URI uri2 = onto2.getEntityURI( ob2 ); + URI uri2; + try { + uri2 = onto2.getEntityURI( ob2 ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI(2)", owex ); + } if ( onto2.isClass( ob2 ) ){ writer.println(" <swrlx:classAtom>"); writer.println(" <owllx:Class owllx:name=\""+uri2+"\"/>"); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java index 39f843c276a7f391b4858780a4343fe3fb576ca8..f4aa0ea0e943b995393d085a767f9c31650b2af8 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java @@ -37,7 +37,9 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.rel.*; import fr.inrialpes.exmo.align.impl.ObjectAlignment; + import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; /** * Renders an alignment as a XSLT stylesheet transforming @@ -132,8 +134,12 @@ public class XSLTRendererVisitor implements AlignmentVisitor { URI entity1URI, entity2URI; // JE: I think that now these two clauses should be unified (3.4) if ( onto1 != null ){ - entity1URI = onto1.getEntityURI( cell.getObject1() ); - entity2URI = onto2.getEntityURI( cell.getObject2() ); + try { + entity1URI = onto1.getEntityURI( cell.getObject1() ); + entity2URI = onto2.getEntityURI( cell.getObject2() ); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } } else { entity1URI = cell.getObject1AsURI(alignment); entity2URI = cell.getObject2AsURI(alignment); @@ -155,8 +161,12 @@ public class XSLTRendererVisitor implements AlignmentVisitor { public void visit( EquivRelation rel ) throws AlignmentException { // The code is exactly the same for properties and classes if ( onto1 != null ){ - writer.println(" <xsl:template match=\""+namespacify(onto1.getEntityURI( cell.getObject1() ))+"\">"); - writer.println(" <xsl:element name=\""+namespacify(onto2.getEntityURI( cell.getObject2() ))+"\">"); + try { + writer.println(" <xsl:template match=\""+namespacify(onto1.getEntityURI( cell.getObject1() ))+"\">"); + writer.println(" <xsl:element name=\""+namespacify(onto2.getEntityURI( cell.getObject2() ))+"\">"); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } } else { writer.println(" <xsl:template match=\""+namespacify(cell.getObject1AsURI(alignment))+"\">"); writer.println(" <xsl:element name=\""+namespacify(cell.getObject2AsURI(alignment))+"\">"); diff --git a/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java b/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java index b7563aac22ab374047e8420800994aca8bbc5923..027f30d8993aaf36478e46942058d9792f8f22cc 100644 --- a/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/BasicOntology.java @@ -22,9 +22,6 @@ package fr.inrialpes.exmo.ontowrap; import java.net.URI; -import org.semanticweb.owl.align.AlignmentVisitor; -import org.semanticweb.owl.align.AlignmentException; - /** * Store the information regarding ontologies in a specific structure */ @@ -39,10 +36,6 @@ public class BasicOntology<O> implements Ontology<O> { public BasicOntology() {}; - public void accept( AlignmentVisitor visitor) throws AlignmentException { - visitor.visit( this ); - } - public URI getURI() { return uri; } public URI getFile() { return file; } public URI getFormURI() { return formalismURI; } diff --git a/src/fr/inrialpes/exmo/ontowrap/HeavyLoadedOntology.java b/src/fr/inrialpes/exmo/ontowrap/HeavyLoadedOntology.java index f9101c65df38288a8f2cdc4b4ffc39ae5f8f8bc2..40d27ec5ee1a020185f4ece7268f12f48c7ac5da 100644 --- a/src/fr/inrialpes/exmo/ontowrap/HeavyLoadedOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/HeavyLoadedOntology.java @@ -22,8 +22,6 @@ package fr.inrialpes.exmo.ontowrap; import java.util.Set; -import org.semanticweb.owl.align.AlignmentException; - /** * Encapsulate deep access to an ontology through some Ontology API * diff --git a/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java b/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java index d470f1af5676fa0a77e272b823b1cb9af792ec33..107329b0f44769b4230064de7e0e964f943aed44 100644 --- a/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java @@ -23,13 +23,11 @@ package fr.inrialpes.exmo.ontowrap; import java.net.URI; import java.util.Set; -import org.semanticweb.owl.align.AlignmentException; - public interface LoadedOntology<O> extends Ontology<O> { - public Object getEntity( URI u ) throws AlignmentException; + public Object getEntity( URI u ) throws OntowrapException; - public URI getEntityURI( Object o ) throws AlignmentException; + public URI getEntityURI( Object o ) throws OntowrapException; /** * returns the default name of an entity if specified. @@ -39,9 +37,9 @@ public interface LoadedOntology<O> extends Ontology<O> { * last fragment (after the last "/" or just before) in this order. * @param o the entity * @return a label - * @throws AlignmentException + * @throws OntowrapException */ - public String getEntityName( Object o ) throws AlignmentException; + public String getEntityName( Object o ) throws OntowrapException; /** * returns the default name of an entity in a language (attribute xml:lang) @@ -50,9 +48,9 @@ public interface LoadedOntology<O> extends Ontology<O> { * otherwise returns the default name (getEntityName) * @param o the entity * @return a label - * @throws AlignmentException + * @throws OntowrapException */ - public String getEntityName( Object o, String lang ) throws AlignmentException; + public String getEntityName( Object o, String lang ) throws OntowrapException; /** * returns all the names of an entity in a language if specified. @@ -60,33 +58,33 @@ public interface LoadedOntology<O> extends Ontology<O> { * @param o the entity * @param lang the code of the language ("en", "fr", "es", etc.) * @return the default name - * @throws AlignmentException + * @throws OntowrapException */ - public Set<String> getEntityNames( Object o, String lang ) throws AlignmentException; + public Set<String> getEntityNames( Object o, String lang ) throws OntowrapException; /** * Returns all the names a given entity (e.g., rdfs:labels in OWL/RDFS). * @param o the entity * @return the set of labels - * @throws AlignmentException + * @throws OntowrapException */ - public Set<String> getEntityNames( Object o ) throws AlignmentException; + public Set<String> getEntityNames( Object o ) throws OntowrapException; /** * Returns the values ofof textual properties (e.g., "rdfs:comment", rdfs:label in RDFS/OWL) for a given entity and for a given natural language (attribute xml:lang). * @param o the entity * @param lang the code of the language ("en", "fr", "es", etc.) * @return the set of comments - * @throws AlignmentException + * @throws OntowrapException */ - public Set<String> getEntityComments( Object o , String lang ) throws AlignmentException; + public Set<String> getEntityComments( Object o , String lang ) throws OntowrapException; /** * Returns all the values of textual properties (e.g., "rdfs:comment", rdfs:label in RDFS/OWL) for a given entity * @param o the entity * @return the set of comments - * @throws AlignmentException + * @throws OntowrapException */ - public Set<String> getEntityComments( Object o ) throws AlignmentException; + public Set<String> getEntityComments( Object o ) throws OntowrapException; /** * Returns all the values of the "owl:AnnotationProperty" property for a given entity. @@ -94,9 +92,9 @@ public interface LoadedOntology<O> extends Ontology<O> { * but also all other defined annotation properties which are subClass of "owl:AnnotationProperty" * @param o the entity * @return the set of annotation values - * @throws AlignmentException + * @throws OntowrapException */ - public Set<String> getEntityAnnotations( Object o ) throws AlignmentException; + public Set<String> getEntityAnnotations( Object o ) throws OntowrapException; public boolean isEntity( Object o ); public boolean isClass( Object o ); @@ -105,12 +103,12 @@ public interface LoadedOntology<O> extends Ontology<O> { public boolean isObjectProperty( Object o ); public boolean isIndividual( Object o ); - public Set<?> getEntities(); - public Set<?> getClasses(); - public Set<?> getProperties(); - public Set<?> getObjectProperties(); - public Set<?> getDataProperties(); - public Set<?> getIndividuals(); + public Set<? extends Object> getEntities(); + public Set<? extends Object> getClasses(); + public Set<? extends Object> getProperties(); + public Set<? extends Object> getObjectProperties(); + public Set<? extends Object> getDataProperties(); + public Set<? extends Object> getIndividuals(); public int nbEntities(); public int nbClasses(); diff --git a/src/fr/inrialpes/exmo/ontowrap/Ontology.java b/src/fr/inrialpes/exmo/ontowrap/Ontology.java index 2816da5fda7b9c9c0dc82b2cceb168374b2e5ac2..2d8ce87eddfc713b182335321275f638cfbe2baa 100644 --- a/src/fr/inrialpes/exmo/ontowrap/Ontology.java +++ b/src/fr/inrialpes/exmo/ontowrap/Ontology.java @@ -22,9 +22,9 @@ package fr.inrialpes.exmo.ontowrap; import java.net.URI; -import org.semanticweb.owl.align.Visitable; +//import org.semanticweb.owl.align.Visitable; -public interface Ontology<O> extends Visitable { +public interface Ontology<O> {//extends Visitable { public URI getURI(); public URI getFile(); diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java index 5726c755f49d373f0f4585609414677908ccb017..c6e6f63b2837b3a0fa73833837bb984f869c1bc5 100644 --- a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java @@ -25,8 +25,6 @@ import java.util.Hashtable; import java.lang.reflect.InvocationTargetException; -import org.semanticweb.owl.align.AlignmentException; - public abstract class OntologyFactory { public static int ANY = 0; @@ -65,7 +63,7 @@ public abstract class OntologyFactory { if ( of != null ) return of; try { // This should also be a static getInstance! - Class ofClass = Class.forName(apiName); + Class<?> ofClass = Class.forName(apiName); Class[] cparams = {}; java.lang.reflect.Constructor ofConstructor = ofClass.getConstructor(cparams); Object[] mparams = {}; @@ -103,18 +101,18 @@ public abstract class OntologyFactory { * Encapsulate an ontology already in the environment * These methods should rather be in a LoadableOntologyFactory */ - public abstract LoadedOntology newOntology( Object onto ) throws AlignmentException; + public abstract LoadedOntology newOntology( Object onto ) throws OntowrapException; /** * Load an ontology, cache enabled * These methods should rather be in a LoadableOntologyFactory */ - public abstract LoadedOntology loadOntology( URI uri ) throws AlignmentException; + public abstract LoadedOntology loadOntology( URI uri ) throws OntowrapException; /** * Load an ontology, cache enabled if true, disabled otherwise * This will disappear: cache will be dispatched in implementations - public LoadedOntology loadOntology( URI uri, OntologyCache<LoadedOntology> ontologies ) throws AlignmentException { + public LoadedOntology loadOntology( URI uri, OntologyCache<LoadedOntology> ontologies ) throws OntowrapException { LoadedOntology onto = null; if ( ontologies != null ) { onto = ontologies.getOntologyFromURI( uri ); diff --git a/src/fr/inrialpes/exmo/ontowrap/OntowrapException.java b/src/fr/inrialpes/exmo/ontowrap/OntowrapException.java new file mode 100644 index 0000000000000000000000000000000000000000..30d69b152e0d50e8048269c22bb4fba2c153379e --- /dev/null +++ b/src/fr/inrialpes/exmo/ontowrap/OntowrapException.java @@ -0,0 +1,48 @@ +/* + * $Id$ + * + * Copyright (C) INRIA Rhône-Alpes, 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.ontowrap; + +import java.lang.Exception; + +/** + * Base class for all Ontowrap Exceptions. + * + * + * @author Jérôme Euzenat + * @version $Id: OntowrapException.java 670 2008-03-02 00:06:16Z euzenat $ + */ + +public class OntowrapException extends Exception { + + private static final long serialVersionUID = 400; + + public OntowrapException( String message ) + { + super( message ); + } + + public OntowrapException( String message, Exception e ) + { + super( message, e ); + } + +} + diff --git a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java index 27db3b0f8bfbb81d435781c62455707f794a2442..3259c38b72428b17c0f2a3af53a6688e082c5166 100644 --- a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntology.java @@ -26,8 +26,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.semanticweb.owl.align.AlignmentException; - import com.hp.hpl.jena.ontology.DatatypeProperty; import com.hp.hpl.jena.ontology.Individual; import com.hp.hpl.jena.ontology.ObjectProperty; @@ -44,17 +42,18 @@ import com.hp.hpl.jena.rdf.model.impl.LiteralImpl; import fr.inrialpes.exmo.ontowrap.BasicOntology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntology<OntModel>{ // JE: this is not very Java 1.5... // This is because of the version of Jena we use apparently - public Object getEntity(URI u) throws AlignmentException { + public Object getEntity(URI u) throws OntowrapException { return onto.getOntResource(u.toString()); } - public void getEntityAnnotations(Object o, Set<String> annots) throws AlignmentException { + public void getEntityAnnotations(Object o, Set<String> annots) throws OntowrapException { OntResource or = (OntResource) o; Iterator<?> z = onto.listAnnotationProperties(); while (z.hasNext()) { @@ -70,13 +69,13 @@ public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntol } } - public Set<String> getEntityAnnotations(Object o) throws AlignmentException { + public Set<String> getEntityAnnotations(Object o) throws OntowrapException { Set<String> annots = new HashSet<String>(); getEntityAnnotations(o,annots); return annots; } - public Set<String> getEntityComments(Object o, String lang) throws AlignmentException { + public Set<String> getEntityComments(Object o, String lang) throws OntowrapException { Set<String> comments = new HashSet<String>(); OntResource or = (OntResource) o; Iterator<?> i = or.listComments(lang); @@ -87,12 +86,12 @@ public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntol return comments; } - public Set<String> getEntityComments(Object o) throws AlignmentException { + public Set<String> getEntityComments(Object o) throws OntowrapException { return getEntityComments(o,null); } - public String getEntityName( Object o ) throws AlignmentException { + public String getEntityName( Object o ) throws OntowrapException { try { // Should try to get labels first... (done in the OWLAPI way) return getFragmentAsLabel( new URI( ((OntResource) o).getURI() ) ); @@ -101,12 +100,12 @@ public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntol } } - public String getEntityName( Object o, String lang ) throws AlignmentException { + public String getEntityName( Object o, String lang ) throws OntowrapException { // Should first get the label in the language return getEntityName( o ); } - public Set<String> getEntityNames(Object o, String lang) throws AlignmentException { + public Set<String> getEntityNames(Object o, String lang) throws OntowrapException { Set<String> labels = new HashSet<String>(); OntResource or = (OntResource) o; Iterator<?> i = or.listLabels(lang); @@ -117,16 +116,16 @@ public class JENAOntology extends BasicOntology<OntModel> implements LoadedOntol return labels; } - public Set<String> getEntityNames(Object o) throws AlignmentException { + public Set<String> getEntityNames(Object o) throws OntowrapException { return getEntityNames(o,null); } - public URI getEntityURI(Object o) throws AlignmentException { + public URI getEntityURI(Object o) throws OntowrapException { try { OntResource or = (OntResource) o; return new URI(or.getURI()); } catch (Exception e) { - throw new AlignmentException(o.toString()+" do not have uri", e ); + throw new OntowrapException(o.toString()+" do not have uri", e ); } } diff --git a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java index 28eecc924855dbbca931f9b656ec389e1d97e001..b5411f4c894df17ce2cc579bd9c6a19252dc8fec 100644 --- a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java @@ -24,8 +24,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.NoSuchElementException; -import org.semanticweb.owl.align.AlignmentException; - import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.Ontology; @@ -34,6 +32,7 @@ import com.hp.hpl.jena.rdf.model.ModelFactory; import fr.inrialpes.exmo.ontowrap.LoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.OntologyCache; +import fr.inrialpes.exmo.ontowrap.OntowrapException; public class JENAOntologyFactory extends OntologyFactory { @@ -49,7 +48,7 @@ public class JENAOntologyFactory extends OntologyFactory { } catch (URISyntaxException ex) { ex.printStackTrace(); } // should not happen } - public JENAOntology newOntology( Object ontology ) throws AlignmentException { + public JENAOntology newOntology( Object ontology ) throws OntowrapException { if ( ontology instanceof OntModel ) { JENAOntology onto = new JENAOntology(); onto.setFormalism( formalismId ); @@ -66,17 +65,17 @@ public class JENAOntologyFactory extends OntologyFactory { onto.setURI(new URI(((OntModel)ontology).getNsPrefixURI(""))); } } catch ( URISyntaxException usex ){ - // Better put in the AlignmentException of loaded - throw new AlignmentException( "URI Error ", usex ); + // Better put in the OntowrapException of loaded + throw new OntowrapException( "URI Error ", usex ); } cache.recordOntology( onto.getURI(), onto ); return onto; } else { - throw new AlignmentException( "Argument is not an OntModel: "+ontology ); + throw new OntowrapException( "Argument is not an OntModel: "+ontology ); } } - public JENAOntology loadOntology( URI uri ) throws AlignmentException { + public JENAOntology loadOntology( URI uri ) throws OntowrapException { JENAOntology onto = null; onto = cache.getOntologyFromURI( uri ); if ( onto != null ) return onto; @@ -100,7 +99,7 @@ public class JENAOntologyFactory extends OntologyFactory { cache.recordOntology( uri, onto ); return onto; } catch (Exception e) { - throw new AlignmentException("Cannot load "+uri, e ); + throw new OntowrapException("Cannot load "+uri, e ); } } diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntology.java b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntology.java index 240575124e2bf28c97791e50fd9f805f4152078e..19fa7b3c4bd0b7e750ba66949ed0eb28c70d9844 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntology.java @@ -39,11 +39,10 @@ import java.util.Iterator; import java.util.Set; import java.util.HashSet; -import org.semanticweb.owl.align.AlignmentException; - import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.HeavyLoadedOntology; import fr.inrialpes.exmo.ontowrap.BasicOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import org.semanticweb.owl.io.vocabulary.RDFSVocabularyAdapter; import org.semanticweb.owl.model.OWLAnnotationInstance; @@ -97,7 +96,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL // ----------------------------------------------------------------- // LoadedOntology interface [//DONE] - public Object getEntity( URI uri ) throws AlignmentException { + public Object getEntity( URI uri ) throws OntowrapException { try { OWLEntity result = onto.getClass( uri ); if ( result == null ) result = onto.getDataProperty( uri ); @@ -105,19 +104,19 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL if ( result == null ) result = onto.getIndividual( uri ); return result; } catch (OWLException ex) { - throw new AlignmentException( "Cannot dereference URI : "+uri ); + throw new OntowrapException( "Cannot dereference URI : "+uri ); } } - public URI getEntityURI( Object o ) throws AlignmentException { + public URI getEntityURI( Object o ) throws OntowrapException { try { return ((OWLEntity)o).getURI(); } catch (OWLException oex) { - throw new AlignmentException( "Cannot get URI ", oex ); + throw new OntowrapException( "Cannot get URI ", oex ); } } - public String getEntityName( Object o ) throws AlignmentException { + public String getEntityName( Object o ) throws OntowrapException { try { // Try to get labels first... URI u = ((OWLEntity)o).getURI(); @@ -128,12 +127,12 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL } }; - public String getEntityName( Object o, String lang ) throws AlignmentException { + public String getEntityName( Object o, String lang ) throws OntowrapException { // Should first get the label in the language return getEntityName( o ); } - public Set<String> getEntityNames( Object o , String lang ) throws AlignmentException { + public Set<String> getEntityNames( Object o , String lang ) throws OntowrapException { try { OWLEntity e = ((OWLEntity) o); return getAnnotations(e,lang,RDFSVocabularyAdapter.INSTANCE.getLabel()); @@ -141,7 +140,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL return null; } } - public Set<String> getEntityNames( Object o ) throws AlignmentException { + public Set<String> getEntityNames( Object o ) throws OntowrapException { try { OWLEntity e = ((OWLEntity) o); return getAnnotations(e,null,RDFSVocabularyAdapter.INSTANCE.getLabel()); @@ -151,7 +150,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL }; - public Set<String> getEntityComments( Object o , String lang ) throws AlignmentException { + public Set<String> getEntityComments( Object o , String lang ) throws OntowrapException { try { OWLEntity e = ((OWLEntity) o); return getAnnotations(e,lang,RDFSVocabularyAdapter.INSTANCE.getComment()); @@ -160,7 +159,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL } }; - public Set<String> getEntityComments( Object o ) throws AlignmentException { + public Set<String> getEntityComments( Object o ) throws OntowrapException { try { OWLEntity e = ((OWLEntity) o); return getAnnotations(e,null,RDFSVocabularyAdapter.INSTANCE.getComment()); @@ -207,7 +206,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL return annots;*/ } - public Set<String> getEntityAnnotations( Object o ) throws AlignmentException { + public Set<String> getEntityAnnotations( Object o ) throws OntowrapException { try { return getAnnotations(((OWLEntity) o),null,null); } catch (OWLException oex) { @@ -487,7 +486,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL return supers; } public Set<Object> getRange( Object p, int asserted ){ - Set resultSet = new HashSet(); + Set<Object> resultSet = new HashSet<Object>(); try { for ( Object ent : ((OWLProperty)p).getRanges( getOntology() ) ){ // Not correct @@ -499,8 +498,9 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL } catch (OWLException ex) {}; return resultSet; } + public Set<Object> getDomain( Object p, int asserted ){ - Set resultSet = new HashSet(); + Set<Object> resultSet = new HashSet<Object>(); try { for ( Object ent : ((OWLProperty)p).getDomains( getOntology() ) ){ // Not correct @@ -512,6 +512,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL } catch (OWLException ex) {}; return resultSet; } + public Set<Object> getClasses( Object i, int local, int asserted, int named ){ Set<Object> supers = null; try { @@ -529,8 +530,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL public Set<Object> getCardinalityRestrictions( Object p ){//JFDK Set<Object> spcl = new HashSet<Object>(); try { - Set<Object> sup = ((OWLClass)p).getSuperClasses( getOntology() ); - for( Object rest : sup ){ + for( Object rest : ((OWLClass)p).getSuperClasses( getOntology() ) ){ // This should be filtered if (rest instanceof OWLCardinalityRestriction) spcl.add( rest ); } @@ -543,7 +543,7 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements HeavyL * Inherits all properties of a class */ private Set<Object> getInheritedProperties( OWLClass cl ) { - Set resultSet = new HashSet(); + Set<Object> resultSet = new HashSet<Object>(); try { getProperties( cl, resultSet ); } catch (OWLException ex) {}; return resultSet; diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java index 129a68bf4428fd8d1f6abd8d596e5948ce98f9ad..754c29a38d7a09fd9cdaf7d7a024133d711b998a 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi10/OWLAPIOntologyFactory.java @@ -31,17 +31,16 @@ import java.util.Set; import org.apache.log4j.Logger; import org.apache.log4j.Level; -import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.model.OWLException; +import org.semanticweb.owl.model.OWLOntology; +import org.semanticweb.owl.util.OWLConnection; +import org.semanticweb.owl.util.OWLManager; import fr.inrialpes.exmo.ontowrap.OntologyCache; import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; - -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.util.OWLConnection; -import org.semanticweb.owl.util.OWLManager; +import fr.inrialpes.exmo.ontowrap.OntowrapException; public class OWLAPIOntologyFactory extends OntologyFactory { @@ -60,7 +59,7 @@ public class OWLAPIOntologyFactory extends OntologyFactory { cache.clear(); } - public OWLAPIOntology newOntology( Object ontology ) throws AlignmentException { + public OWLAPIOntology newOntology( Object ontology ) throws OntowrapException { if ( ontology instanceof OWLOntology ) { OWLAPIOntology onto = new OWLAPIOntology(); onto.setFormalism( formalismId ); @@ -70,17 +69,17 @@ public class OWLAPIOntologyFactory extends OntologyFactory { try { onto.setURI( ((OWLOntology)ontology).getLogicalURI() ); } catch (OWLException e) { - // Better put in the AlignmentException of loaded + // Better put in the OntowrapException of loaded e.printStackTrace(); } //cache.recordOntology( uri, onto ); return onto; } else { - throw new AlignmentException( "Argument is not an OWLOntology: "+ontology ); + throw new OntowrapException( "Argument is not an OWLOntology: "+ontology ); } } - public OWLAPIOntology loadOntology( URI uri ) throws AlignmentException { + public OWLAPIOntology loadOntology( URI uri ) throws OntowrapException { OWLAPIOntology onto = null; onto = cache.getOntologyFromURI( uri ); if ( onto != null ) return onto; @@ -105,13 +104,13 @@ public class OWLAPIOntologyFactory extends OntologyFactory { try { onto.setURI( ontology.getLogicalURI() ); } catch (OWLException e) { - // Better put in the AlignmentException of loaded + // Better put in the OntowrapException of loaded e.printStackTrace(); } cache.recordOntology( uri, onto ); return onto; } catch (OWLException e) { - throw new AlignmentException("Cannot load "+uri, e ); + throw new OntowrapException("Cannot load "+uri, e ); } } }