diff --git a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java index ffc0a69bb9416e69a545bda79df5eeabe2f6c689..870a4d8d89ca3ca39645c5fb821ce62398337e6d 100644 --- a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java @@ -260,6 +260,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce } } } catch (AlignmentException alex) { alex.printStackTrace(); } + catch (OntowrapException owex) { owex.printStackTrace(); } // For properties try{ int nbprop1 = ontology1().nbProperties(); @@ -296,6 +297,7 @@ public class DistanceAlignment extends ObjectAlignment implements AlignmentProce } } } catch (AlignmentException alex) { alex.printStackTrace(); } + catch (OntowrapException owex) { owex.printStackTrace(); } // For individuals if ( params.getProperty("noinst") == null ){ try{ diff --git a/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java b/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java index 114a78d94354a192306cb5f5a75f2fa8921d79c5..5d65c9db4cd3d0952a496e4b97ce6325d08851f4 100644 --- a/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java +++ b/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java @@ -119,6 +119,7 @@ public abstract class MatrixMeasure implements Similarity { proplist1 = new HashMap<Object,Integer>(); // onto1 properties indlist2 = new HashMap<Object,Integer>(); // onto2 instances indlist1 = new HashMap<Object,Integer>(); // onto1 instances + //System.err.println(" >> "+onto1+"/"+onto2 ); try { // Create class lists @@ -128,6 +129,7 @@ public abstract class MatrixMeasure implements Similarity { for( Object cl : onto1.getClasses() ){ classlist1.put( cl, new Integer(nbclass1++) ); } + //System.err.println(" >> NbClasses: "+nbclass1+"/"+nbclass2 ); clmatrix = new double[nbclass1+1][nbclass2+1]; // Create property lists @@ -143,6 +145,7 @@ public abstract class MatrixMeasure implements Similarity { for( Object pr : onto1.getDataProperties() ){ proplist1.put( pr, new Integer(nbprop1++) ); } + //System.err.println(" >> NbProp: "+nbprop1+"/"+nbprop2 ); prmatrix = new double[nbprop1+1][nbprop2+1]; // Create individual lists @@ -158,8 +161,8 @@ public abstract class MatrixMeasure implements Similarity { indlist1.put( ind, new Integer(nbind1++) ); } } + //System.err.println(" >> NbInd: "+nbind1+"/"+nbind2 ); indmatrix = new double[nbind1+1][nbind2+1]; - //System.err.println(nbclass1+"/"+nbclass2+" - "+nbprop1+"/"+nbprop2+" - "+nbind1+"/"+nbind2); } catch (OntowrapException e) { e.printStackTrace(); }; } diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java index 76be9de6c0531d10b41d4eaa314b3dbd4abaafd7..2dc35437fd83900b5a0a4c1265de7367b9e173b1 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java @@ -212,19 +212,23 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { } protected int relativePosition( Object o1, Object o2, HeavyLoadedOntology<Object> onto ) throws AlignmentException { - if ( onto.isClass( o1 ) && onto.isClass( o2 ) ){ - isSuperClass( o2, o1, onto ); // This is the level - } else if ( onto.isProperty( o1 ) && onto.isProperty( o2 ) ){ - if ( isSuperProperty( o2, o1, onto ) ) { return -1; } - else if ( isSuperProperty( o1, o2, onto ) ) { return 1; } - else { return 0; } - } else if ( onto.isIndividual( o1 ) && onto.isIndividual( o2 ) ){ + try { + if ( onto.isClass( o1 ) && onto.isClass( o2 ) ){ + isSuperClass( o2, o1, onto ); // This is the level + } else if ( onto.isProperty( o1 ) && onto.isProperty( o2 ) ){ + if ( isSuperProperty( o2, o1, onto ) ) { return -1; } + else if ( isSuperProperty( o1, o2, onto ) ) { return 1; } + else { return 0; } + } else if ( onto.isIndividual( o1 ) && onto.isIndividual( o2 ) ){ + return 0; + //if () { return -1; } + //else if () { return 1; } + //else return 0; + } return 0; - //if () { return -1; } - //else if () { return 1; } - //else return 0; + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot access class hierarchy", owex ); } - return 0; } public boolean isSuperProperty( Object prop1, Object prop2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { diff --git a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java index f6cf570fbb95340aae397f6f237ae984e35c3fd2..f1e8c77517bbfd15c7f218185d90f883b5f4416a 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java @@ -30,6 +30,7 @@ import fr.inrialpes.exmo.align.impl.Namespace; import fr.inrialpes.exmo.align.impl.BasicEvaluator; import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.ontowrap.LoadedOntology; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.lang.Math; import java.util.Enumeration; @@ -80,33 +81,37 @@ public class SymMeanEvaluator extends BasicEvaluator implements Evaluator { LoadedOntology onto1 = (LoadedOntology)((ObjectAlignment)align1).getOntologyObject1(); LoadedOntology onto2 = (LoadedOntology)((ObjectAlignment)align2).getOntologyObject1(); - for ( Cell c1 : align1 ){ - if ( onto1.isClass( c1.getObject1() ) ) nbClassCell++; - else if ( onto1.isProperty( c1.getObject1() ) ) nbPropCell++; - else nbIndCell++; - Set<Cell> s2 = align2.getAlignCells1( c1.getObject1() ); - if( s2 != null ){ - for ( Cell c2: s2 ){ - if ( c1.getObject2() == c2.getObject2() ) { - if ( onto2.isClass( c1.getObject2() ) ) { - classScore = classScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); - } else if ( onto2.isProperty( c1.getObject2() ) ) { - propScore = propScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); - } else { - indScore = indScore + 1 - Math.abs(c2.getStrength() - c1.getStrength());}}}}} + try { + for ( Cell c1 : align1 ){ + if ( onto1.isClass( c1.getObject1() ) ) nbClassCell++; + else if ( onto1.isProperty( c1.getObject1() ) ) nbPropCell++; + else nbIndCell++; + Set<Cell> s2 = align2.getAlignCells1( c1.getObject1() ); + if( s2 != null ){ + for ( Cell c2: s2 ){ + if ( c1.getObject2() == c2.getObject2() ) { + if ( onto2.isClass( c1.getObject2() ) ) { + classScore = classScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); + } else if ( onto2.isProperty( c1.getObject2() ) ) { + propScore = propScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); + } else { + indScore = indScore + 1 - Math.abs(c2.getStrength() - c1.getStrength());}}}}} + + for( Cell c2: align2 ) { + if ( onto1.isClass( c2.getObject1() ) ) nbClassCell++ ; + else if ( onto1.isProperty( c2.getObject1() ) ) nbPropCell++; + else nbIndCell++; + } - for( Cell c2: align2 ) { - if ( onto1.isClass( c2.getObject1() ) ) nbClassCell++ ; - else if ( onto1.isProperty( c2.getObject1() ) ) nbPropCell++; - else nbIndCell++; + // Beware, this must come first + result = 2*(classScore+propScore+indScore) / (nbClassCell+nbPropCell+nbIndCell); + classScore = 2*classScore / nbClassCell; + propScore = 2*propScore / nbPropCell; + indScore = 2*indScore / nbIndCell; + return(result); + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot access class hierarchy", owex ); } - - // Beware, this must come first - result = 2*(classScore+propScore+indScore) / (nbClassCell+nbPropCell+nbIndCell); - classScore = 2*classScore / nbClassCell; - propScore = 2*propScore / nbPropCell; - indScore = 2*indScore / nbIndCell; - return(result); } public void write( PrintWriter writer ) throws java.io.IOException { diff --git a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java index 5042287423bf616022a65bdefb5f1c2fe85380f9..26471f08c3371fa0d1b4ac4df9c13b3caf9b5973 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java @@ -94,13 +94,17 @@ public class ClassStructAlignment extends DistanceAlignment implements Alignment if ( init != null ) ingest( init ); // Create class lists - for ( Object cl : honto2.getClasses() ){ - nbclass2++; - classlist2.add( cl ); - } - for ( Object cl : honto1.getClasses() ){ - nbclass1++; - classlist1.add( cl ); + try { + for ( Object cl : honto2.getClasses() ){ + nbclass2++; + classlist2.add( cl ); + } + for ( Object cl : honto1.getClasses() ){ + nbclass1++; + classlist1.add( cl ); + } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot access class hierarchy", owex ); } classmatrix = new double[nbclass1+1][nbclass2+1]; diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java index 261acb76c0992ee2d2d618a2348c7142e36c62e1..01a7c58eead52afbc428759fbf6b1df8fcf7e9ac 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java @@ -99,6 +99,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align if ( params.getProperty("debug") != null ) debug = Integer.parseInt( params.getProperty("debug") ); + try { // Create property lists and matrix for ( Object prop : honto1.getObjectProperties() ){ nbprop1++; @@ -128,96 +129,95 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align classlist2.add( cl ); } classmatrix = new double[nbclass1+1][nbclass2+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 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.; } } - - // 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()); - } + } + + // 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 ); } + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } - // Iterate until completion - double factor = 1.0; - while ( factor > epsillon ){ - // Compute property distances - // -- FirstExp: nothing to be done: one pass - // Here create the best matches for property distance already - // -- FirstExp: goes directly in the alignment structure - // since it will never be refined anymore... - if (debug > 0) System.err.print("Storing property alignment\n"); - for ( i=0; i<nbprop1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbprop2; j++ ){ - if ( propmatrix[i][j] < max) { - found = true; - best = j; - max = propmatrix[i][j]; - } + // Iterate until completion + double factor = 1.0; + while ( factor > epsillon ){ + // Compute property distances + // -- FirstExp: nothing to be done: one pass + // Here create the best matches for property distance already + // -- FirstExp: goes directly in the alignment structure + // since it will never be refined anymore... + if (debug > 0) System.err.print("Storing property alignment\n"); + for ( i=0; i<nbprop1; i++ ){ + boolean found = false; + int best = 0; + double max = threshold; + for ( j=0; j<nbprop2; j++ ){ + if ( propmatrix[i][j] < max) { + found = true; + best = j; + max = propmatrix[i][j]; } - if ( found && max < 0.5) { addAlignDistanceCell( proplist1.get(i), proplist2.get(best), "=", max ); } } - if (debug > 0) System.err.print("Computing class distances\n"); - // Compute classes distances - // -- for all of its attribute, find the best match if possible... easy - // -- simply replace in the matrix the value by the value plus the - // classmatrix[i][j] = - // pic1 * classmatrix[i][j] - // + pic2 * 2 * - // (sigma (att in c[i]) getAllignCell... ) - // / nbatts of c[i] + nbatts of c[j] - - for ( i=0; i<nbclass1; i++ ){ - Set<Object> properties1 = honto1.getProperties( classlist1.get(i), OntologyFactory.ANY, OntologyFactory.ANY, OntologyFactory.ANY ); - - int nba1 = properties1.size(); - if ( nba1 > 0 ) { // if not, keep old values... - //Set correspondences = new HashSet(); - for ( j=0; j<nbclass2; j++ ){ - Set<Object> properties2 = honto2.getProperties( classlist2.get(j), OntologyFactory.ANY, OntologyFactory.ANY, OntologyFactory.ANY ); - //int nba2 = properties1.size(); - //double attsum = 0.; - // check that there is a correspondance - // in list of class2 atts and add their weights + if ( found && max < 0.5) { addAlignDistanceCell( proplist1.get(i), proplist2.get(best), "=", max ); } + } + if (debug > 0) System.err.print("Computing class distances\n"); + // Compute classes distances + // -- for all of its attribute, find the best match if possible... easy + // -- simply replace in the matrix the value by the value plus the + // classmatrix[i][j] = + // pic1 * classmatrix[i][j] + // + pic2 * 2 * + // (sigma (att in c[i]) getAllignCell... ) + // / nbatts of c[i] + nbatts of c[j] + + for ( i=0; i<nbclass1; i++ ){ + Set<Object> properties1 = honto1.getProperties( classlist1.get(i), OntologyFactory.ANY, OntologyFactory.ANY, OntologyFactory.ANY ); + + int nba1 = properties1.size(); + if ( nba1 > 0 ) { // if not, keep old values... + //Set correspondences = new HashSet(); + for ( j=0; j<nbclass2; j++ ){ + Set<Object> properties2 = honto2.getProperties( classlist2.get(j), OntologyFactory.ANY, OntologyFactory.ANY, OntologyFactory.ANY ); + //int nba2 = properties1.size(); + //double attsum = 0.; + // check that there is a correspondance + // in list of class2 atts and add their weights - // Make a local alignment with the properties. - double moy_align_loc = alignLocal(properties1,properties2); - - if (moy_align_loc > 0.7){ - classmatrix[i][j] = (classmatrix[i][j] + 2* moy_align_loc)/3; - } + // Make a local alignment with the properties. + double moy_align_loc = alignLocal(properties1,properties2); + + if (moy_align_loc > 0.7){ + classmatrix[i][j] = (classmatrix[i][j] + 2* moy_align_loc)/3; } } } - - // Assess factor - // -- FirstExp: nothing to be done: one pass - factor = 0.; } + + // Assess factor + // -- FirstExp: nothing to be done: one pass + factor = 0.; + } // This mechanism should be parametric! // Select the best match // There can be many algorithm for these: diff --git a/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java index 013f3cb0bce16950a3d93e4685eadc507435bb86..b69294e7f6eded3c7d1a2155155487870a8617ce 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java @@ -58,7 +58,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP // Unnamed entity = max distance if ( s1 == null || s2 == null ) return 1.; Object[] params = { s1.toLowerCase(), s2.toLowerCase() }; - if ( debug > 4 ) + //if ( debug > 4 ) System.err.println( "OB:"+s1+" ++ "+s2+" ==> "+dissimilarity.invoke( null, params )); return ((Double)dissimilarity.invoke( null, params )).doubleValue(); } diff --git a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java index 4544cb1cdd296d7f9b0e4869f8d842a68a92c751..d4d9fdbea815088e92fb2c63710f3816464c066a 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java @@ -101,39 +101,39 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme if ( params.getProperty("debug") != null ) debug = Integer.parseInt( params.getProperty("debug") ); - // Create property lists and matrix - for ( Object prop : honto1.getObjectProperties() ){ - nbprop1++; - proplist1.add( prop ); - } - for ( Object prop : honto1.getDataProperties() ){ - nbprop1++; - proplist1.add( prop ); - } - for ( Object prop : honto2.getObjectProperties() ){ - nbprop2++; - proplist2.add( prop ); - } - for ( Object prop : honto2.getDataProperties() ){ - nbprop2++; - proplist2.add( prop ); - } - propmatrix = new double[nbprop1+1][nbprop2+1]; - - // Create class lists - for ( Object cl : honto1.getClasses() ){ - nbclass1++; - classlist1.add( cl ); - } - for ( Object cl : honto2.getClasses() ){ - nbclass2++; - classlist2.add( cl ); - } - classmatrix = new double[nbclass1+1][nbclass2+1]; - - try{ + try { + // Create property lists and matrix + for ( Object prop : honto1.getObjectProperties() ){ + nbprop1++; + proplist1.add( prop ); + } + for ( Object prop : honto1.getDataProperties() ){ + nbprop1++; + proplist1.add( prop ); + } + for ( Object prop : honto2.getObjectProperties() ){ + nbprop2++; + proplist2.add( prop ); + } + for ( Object prop : honto2.getDataProperties() ){ + nbprop2++; + proplist2.add( prop ); + } + propmatrix = new double[nbprop1+1][nbprop2+1]; + + // Create class lists + for ( Object cl : honto1.getClasses() ){ + nbclass1++; + classlist1.add( cl ); + } + for ( Object cl : honto2.getClasses() ){ + nbclass2++; + classlist2.add( cl ); + } + 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 ); @@ -149,7 +149,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme } } } - + // Initialize class distances if (debug > 0) System.err.println("Initializing class distances"); for ( i=0; i<nbclass1; i++ ){ @@ -159,7 +159,7 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme } } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); + throw new AlignmentException( "Error accessing ontology", owex ); } // Iterate until completion diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java index 2b3a499232a1f3ef5cb172a2c6a4779e401f4be7..1bfe4006949fb17e1ae76218cd55b2ac104eb570 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java @@ -94,18 +94,23 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { writer.print(" <owl:imports rdf:resource=\""+align.getOntology2URI().toString()+"\"/>\n"); writer.print(" </owl:Ontology>\n\n"); - for( Cell c : align ){ - Object ob1 = c.getObject1(); - Object ob2 = c.getObject2(); + try { + for( Cell c : align ){ + Object ob1 = c.getObject1(); + Object ob2 = c.getObject2(); + + if ( heterogeneous || + ( onto1.isClass( ob1 ) && onto2.isClass( ob2 ) ) || + ( onto1.isDataProperty( ob1 ) && onto2.isDataProperty( ob2 ) ) || + ( onto1.isObjectProperty( ob1 ) && onto2.isObjectProperty( ob2 ) ) || + ( onto1.isIndividual( ob1 ) && onto2.isIndividual( ob2 ) ) ) + c.accept( this ); + + } //end for + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Error accessing ontology", owex ); + } - if ( heterogeneous || - ( onto1.isClass( ob1 ) && onto2.isClass( ob2 ) ) || - ( onto1.isDataProperty( ob1 ) && onto2.isDataProperty( ob2 ) ) || - ( onto1.isObjectProperty( ob1 ) && onto2.isObjectProperty( ob2 ) ) || - ( onto1.isIndividual( ob1 ) && onto2.isIndividual( ob2 ) ) ) - c.accept( this ); - - } //end for writer.print("</rdf:RDF>\n"); } @@ -120,25 +125,25 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { } else { u1 = onto1.getEntityURI( ob1 ); } + if ( onto1.isClass( ob1 ) ) { + writer.print(" <owl:Class rdf:about=\""+u1+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" </owl:Class>\n"); + } else if ( onto1.isDataProperty( ob1 ) ) { + writer.print(" <owl:DatatypeProperty rdf:about=\""+u1+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" </owl:DatatypeProperty>\n"); + } else if ( onto1.isObjectProperty( ob1 ) ) { + writer.print(" <owl:ObjectProperty rdf:about=\""+u1+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" </owl:ObjectProperty>\n"); + } else if ( onto1.isIndividual( ob1 ) ) { + writer.print(" <owl:Thing rdf:about=\""+u1+"\">\n"); + cell.getRelation().accept( this ); + writer.print(" </owl:Thing>\n"); + } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); - } - if ( onto1.isClass( ob1 ) ) { - writer.print(" <owl:Class rdf:about=\""+u1+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:Class>\n"); - } else if ( onto1.isDataProperty( ob1 ) ) { - writer.print(" <owl:DatatypeProperty rdf:about=\""+u1+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:DatatypeProperty>\n"); - } else if ( onto1.isObjectProperty( ob1 ) ) { - writer.print(" <owl:ObjectProperty rdf:about=\""+u1+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:ObjectProperty>\n"); - } else if ( onto1.isIndividual( ob1 ) ) { - writer.print(" <owl:Thing rdf:about=\""+u1+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:Thing>\n"); + throw new AlignmentException( "Error accessing ontology", owex ); } } @@ -147,17 +152,17 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { URI u2; try { u2 = onto2.getEntityURI( ob2 ); + if ( onto2.isClass( ob2 ) ) { + writer.print(" <owl:equivalentClass rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto2.isDataProperty( ob2 ) ) { + writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto2.isObjectProperty( ob2 ) ) { + writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto2.isIndividual( ob2 ) ) { + writer.print(" <owl:sameAs rdf:resource=\""+u2+"\"/>\n"); + } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); - } - if ( onto2.isClass( ob2 ) ) { - writer.print(" <owl:equivalentClass rdf:resource=\""+u2+"\"/>\n"); - } else if ( onto2.isDataProperty( ob2 ) ) { - writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); - } else if ( onto2.isObjectProperty( ob2 ) ) { - writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); - } else if ( onto2.isIndividual( ob2 ) ) { - writer.print(" <owl:sameAs rdf:resource=\""+u2+"\"/>\n"); + throw new AlignmentException( "Error accessing ontology", owex ); } } @@ -166,15 +171,15 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { URI u2; try { u2 = onto2.getEntityURI( ob2 ); + if ( onto1.isClass( ob2 ) ) { + writer.print(" <rdfs:subClassOf rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto1.isDataProperty( ob2 ) ) { + writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto1.isObjectProperty( ob2 ) ) { + writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u2+"\"/>\n"); + } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); - } - if ( onto1.isClass( ob2 ) ) { - writer.print(" <rdfs:subClassOf rdf:resource=\""+u2+"\"/>\n"); - } else if ( onto1.isDataProperty( ob2 ) ) { - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u2+"\"/>\n"); - } else if ( onto1.isObjectProperty( ob2 ) ) { - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u2+"\"/>\n"); + throw new AlignmentException( "Error accessing ontology", owex ); } } @@ -183,15 +188,15 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { URI u1; try { u1 = onto1.getEntityURI( ob1 ); + if ( onto1.isClass( ob1 ) ) { + writer.print(" <rdfs:subClassOf rdf:resource=\""+u1+"\"/>\n"); + } else if ( onto1.isDataProperty( ob1 ) ) { + writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u1+"\"/>\n"); + } else if ( onto1.isObjectProperty( ob1 ) ) { + writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u1+"\"/>\n"); + } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); - } - if ( onto1.isClass( ob1 ) ) { - writer.print(" <rdfs:subClassOf rdf:resource=\""+u1+"\"/>\n"); - } else if ( onto1.isDataProperty( ob1 ) ) { - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u1+"\"/>\n"); - } else if ( onto1.isObjectProperty( ob1 ) ) { - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+u1+"\"/>\n"); + throw new AlignmentException( "Error accessing ontology", owex ); } } @@ -231,15 +236,15 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor { URI u2; try { u2 = onto2.getEntityURI( ob2 ); + if ( onto2.isIndividual( ob2 ) ) { // ob1 has been checked before + // It would be better to check that r is a relation of one of the ontologies by + // onto1.isObjectProperty( onto1.getEntity( new URI ( r ) ) ) + String r = ((BasicRelation)rel).getRelation(); + if ( r!=null && !r.equals("") ) + writer.print(" <"+r+" rdf:resource=\""+u2+"\"/>\n"); + } } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot find entity URI", owex ); - } - if ( onto2.isIndividual( ob2 ) ) { // ob1 has been checked before - // It would be better to check that r is a relation of one of the ontologies by - // onto1.isObjectProperty( onto1.getEntity( new URI ( r ) ) ) - String r = ((BasicRelation)rel).getRelation(); - if ( r!=null && !r.equals("") ) - writer.print(" <"+r+" rdf:resource=\""+u2+"\"/>\n"); + throw new AlignmentException( "Error accessing ontology", owex ); } } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java index 7edc629eb6d32428ab4ac491323843b978b6ed7a..72198d88ed7f1274245b412e311dbfa8404d53d8 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java @@ -105,57 +105,53 @@ 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; - 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 ) ){ - writer.println(" <swrl:classAtom>"); - writer.println(" <owllx:Class owllx:name=\""+uri1+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" </swrl:classAtom>"); - } else if ( onto1.isDataProperty( ob1 ) ){ - writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri1+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" <ruleml:var>y</ruleml:var>"); - writer.println(" <swrl:datavaluedPropertyAtom>"); - } else { - writer.println(" <swrl:individualPropertyAtom swrlx:property=\""+uri1+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" <ruleml:var>y</ruleml:var>"); - writer.println(" </swrl:individualPropertyAtom>"); - } - writer.println(" </ruleml:_body>"); - writer.println(" <ruleml:_head>"); Object ob2 = cell.getObject2(); + URI uri1; URI uri2; try { + uri1 = onto1.getEntityURI( ob1 ); + writer.println(" <ruleml:imp>"); + writer.println(" <ruleml:_body>"); + if ( onto1.isClass( ob1 ) ){ + writer.println(" <swrl:classAtom>"); + writer.println(" <owllx:Class owllx:name=\""+uri1+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" </swrl:classAtom>"); + } else if ( onto1.isDataProperty( ob1 ) ){ + writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri1+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" <ruleml:var>y</ruleml:var>"); + writer.println(" <swrl:datavaluedPropertyAtom>"); + } else { + writer.println(" <swrl:individualPropertyAtom swrlx:property=\""+uri1+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" <ruleml:var>y</ruleml:var>"); + writer.println(" </swrl:individualPropertyAtom>"); + } + writer.println(" </ruleml:_body>"); + writer.println(" <ruleml:_head>"); uri2 = onto2.getEntityURI( ob2 ); + if ( onto2.isClass( ob2 ) ){ + writer.println(" <swrlx:classAtom>"); + writer.println(" <owllx:Class owllx:name=\""+uri2+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" </swrl:classAtom>"); + } else if ( onto2.isDataProperty( ob2 ) ){ + writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri2+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" <ruleml:var>y</ruleml:var>"); + writer.println(" </swrl:datavaluedPropertyAtom>"); + } else { + writer.println(" <swrl:individualPropertyAtom swrlx:property=\""+uri2+"\"/>"); + writer.println(" <ruleml:var>x</ruleml:var>"); + writer.println(" <ruleml:var>y</ruleml:var>"); + writer.println(" </swrl:individualPropertyAtom>"); + } + writer.println(" </ruleml:_head>"); + writer.println(" </ruleml:imp>\n"); } 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+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" </swrl:classAtom>"); - } else if ( onto2.isDataProperty( ob2 ) ){ - writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri2+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" <ruleml:var>y</ruleml:var>"); - writer.println(" </swrl:datavaluedPropertyAtom>"); - } else { - writer.println(" <swrl:individualPropertyAtom swrlx:property=\""+uri2+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" <ruleml:var>y</ruleml:var>"); - writer.println(" </swrl:individualPropertyAtom>"); + throw new AlignmentException( "Error accessing ontology", owex ); } - writer.println(" </ruleml:_head>"); - writer.println(" </ruleml:imp>\n"); } public void visit( SubsumeRelation rel ){}; diff --git a/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java b/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java index b5dff2f56b5394828ad4d46fc778779aaa6a3bb3..bfa6ce6b6fb37f963e6eb1855cde84126c09e271 100644 --- a/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java +++ b/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java @@ -38,6 +38,7 @@ import fr.inrialpes.exmo.align.impl.eval.ExtPREvaluator; import fr.inrialpes.exmo.align.parser.AlignmentParser; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.io.File; import java.io.PrintStream; @@ -239,7 +240,11 @@ public class ExtGroupEval { result.add( i, evaluator ); } // Unload the ontologies. - OntologyFactory.clear(); + try { + OntologyFactory.clear(); + } catch ( OntowrapException owex ) { // only report + owex.printStackTrace(); + } if ( ok == true ) return result; else return null; diff --git a/src/fr/inrialpes/exmo/align/util/GenPlot.java b/src/fr/inrialpes/exmo/align/util/GenPlot.java index e1a5e01947201f48d0b9edac1656dbc8f4eb8359..580f8bcc9714885e1bff16889026b316034f9821 100644 --- a/src/fr/inrialpes/exmo/align/util/GenPlot.java +++ b/src/fr/inrialpes/exmo/align/util/GenPlot.java @@ -30,6 +30,7 @@ import fr.inrialpes.exmo.align.impl.eval.GraphEvaluator; import fr.inrialpes.exmo.align.impl.eval.Pair; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.io.File; import java.io.PrintStream; @@ -327,7 +328,11 @@ public class GenPlot { evaluators.get(i).ingest( al, refalign ); } // Unload the ontologies. - OntologyFactory.clear(); + try { + OntologyFactory.clear(); + } catch ( OntowrapException owex ) { // only report + owex.printStackTrace(); + } } // should be OK for changing granularity diff --git a/src/fr/inrialpes/exmo/align/util/GroupEval.java b/src/fr/inrialpes/exmo/align/util/GroupEval.java index 5ab6b1cedf66956adcd3fa2cc59d00fcfcc0797b..1f4743813a64e5fb395e8d8766329dbc8739ae47 100644 --- a/src/fr/inrialpes/exmo/align/util/GroupEval.java +++ b/src/fr/inrialpes/exmo/align/util/GroupEval.java @@ -33,6 +33,7 @@ import fr.inrialpes.exmo.align.impl.BasicParameters; import fr.inrialpes.exmo.align.impl.eval.PRecEvaluator; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.io.File; import java.io.PrintStream; @@ -236,7 +237,11 @@ public class GroupEval { result.add( i, evaluator ); } // Unload the ontologies. - OntologyFactory.clear(); + try { + OntologyFactory.clear(); + } catch ( OntowrapException owex ) { // only report + owex.printStackTrace(); + } if ( ok == true ) return result; else return null; diff --git a/src/fr/inrialpes/exmo/align/util/GroupOutput.java b/src/fr/inrialpes/exmo/align/util/GroupOutput.java index be92f1a0385577fcb88b6a5d12cb156dc47c2f73..4e1c5013d017928793cd4c5741fac9ab58a64ae4 100644 --- a/src/fr/inrialpes/exmo/align/util/GroupOutput.java +++ b/src/fr/inrialpes/exmo/align/util/GroupOutput.java @@ -35,6 +35,7 @@ import fr.inrialpes.exmo.align.impl.BasicParameters; import fr.inrialpes.exmo.align.impl.eval.PRecEvaluator; import fr.inrialpes.exmo.ontowrap.OntologyFactory; +import fr.inrialpes.exmo.ontowrap.OntowrapException; import java.io.File; import java.io.FileOutputStream; @@ -243,7 +244,11 @@ public class GroupOutput { } catch (AlignmentException aex ) { aex.printStackTrace(); } } // Unload the ontologies. - OntologyFactory.clear(); + try { + OntologyFactory.clear(); + } catch ( OntowrapException owex ) { // only report + owex.printStackTrace(); + } return result/(double)tests.length; } diff --git a/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java b/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java index 103f391a25b04ae010764cd61702880b613d4a27..785b5a7fdf22ae16bf63ee8219833c5c54c0ec9b 100644 --- a/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java +++ b/src/fr/inrialpes/exmo/ontowrap/LoadedOntology.java @@ -118,30 +118,30 @@ public interface LoadedOntology<O> extends Ontology<O> { */ public Set<String> getEntityAnnotations( Object o, String lang ) throws OntowrapException; - public boolean isEntity( Object o ); - public boolean isClass( Object o ); - public boolean isProperty( Object o ); - public boolean isDataProperty( Object o ); - public boolean isObjectProperty( Object o ); - public boolean isIndividual( Object o ); + public boolean isEntity( Object o ) throws OntowrapException; + public boolean isClass( Object o ) throws OntowrapException; + public boolean isProperty( Object o ) throws OntowrapException; + public boolean isDataProperty( Object o ) throws OntowrapException; + public boolean isObjectProperty( Object o ) throws OntowrapException; + public boolean isIndividual( Object o ) throws OntowrapException; /** * Returns all named entities having URI beginning with the ontology URI * @return the set of entities */ - 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 Set<? extends Object> getEntities() throws OntowrapException; + public Set<? extends Object> getClasses() throws OntowrapException; + public Set<? extends Object> getProperties() throws OntowrapException; + public Set<? extends Object> getObjectProperties() throws OntowrapException; + public Set<? extends Object> getDataProperties() throws OntowrapException; + public Set<? extends Object> getIndividuals() throws OntowrapException; - public int nbEntities(); - public int nbClasses(); - public int nbProperties(); - public int nbDataProperties(); - public int nbObjectProperties(); - public int nbIndividuals(); + public int nbEntities() throws OntowrapException; + public int nbClasses() throws OntowrapException; + public int nbProperties() throws OntowrapException; + public int nbDataProperties() throws OntowrapException; + public int nbObjectProperties() throws OntowrapException; + public int nbIndividuals() throws OntowrapException; - public void unload(); + public void unload() throws OntowrapException; } diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyCache.java b/src/fr/inrialpes/exmo/ontowrap/OntologyCache.java index 3ab37bbbf053f446c3e15c026558e19bd1fdc201..0c4c9b4dd52d3e48603881fcf300654dab135a63 100644 --- a/src/fr/inrialpes/exmo/ontowrap/OntologyCache.java +++ b/src/fr/inrialpes/exmo/ontowrap/OntologyCache.java @@ -64,7 +64,7 @@ public class OntologyCache <O extends LoadedOntology> { return ontologyUris.get( uri ); } - public void unloadOntology( URI uri, O ontology ){ + public void unloadOntology( URI uri, O ontology ) throws OntowrapException { O o = ontologyUris.get(uri); o.unload(); ontologyUris.remove( uri ); @@ -85,7 +85,7 @@ public class OntologyCache <O extends LoadedOntology> { } }; - public void clear(){ + public void clear() throws OntowrapException { for ( LoadedOntology o : ontologies.values() ){ o.unload(); } diff --git a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java index c6e6f63b2837b3a0fa73833837bb984f869c1bc5..de907d7b789d7e24ac43426788cd69eb4ed3823e 100644 --- a/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/OntologyFactory.java @@ -43,7 +43,8 @@ public abstract class OntologyFactory { protected static Hashtable<String,OntologyFactory> instances = null; - private static String API_NAME="fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3OntologyFactory"; + private static String API_NAME="fr.inrialpes.exmo.ontowrap.skosapi.SKOSOntologyFactory"; + //private static String API_NAME="fr.inrialpes.exmo.ontowrap.owlapi30.OWLAPI3OntologyFactory"; public static String getDefaultFactory(){ return API_NAME; @@ -83,7 +84,7 @@ public abstract class OntologyFactory { return of; } - public static void clear() { + public static void clear() throws OntowrapException { if ( instances != null ) { for ( OntologyFactory of : instances.values() ){ of.clearCache(); @@ -95,7 +96,7 @@ public abstract class OntologyFactory { * All Ontologies must implement clearCache() * which unload their ontologies if any cache is enabled. */ - public abstract void clearCache(); + public abstract void clearCache() throws OntowrapException; /** * Encapsulate an ontology already in the environment diff --git a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java index 5e396c23e7c8f9d909be36ac86a28d75e44d83de..8226b3eea417f75f006b5f3154c5dd36b55cae11 100644 --- a/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/jena25/JENAOntologyFactory.java @@ -104,7 +104,7 @@ public class JENAOntologyFactory extends OntologyFactory { } @Override - public void clearCache() { + public void clearCache() throws OntowrapException { cache.clear(); }; diff --git a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java index bbc9fdd2f99396a221378ae8bf9cedde8fdc0b4d..031539dce7d3a7475840d07ed9835473defe9a54 100644 --- a/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java +++ b/src/fr/inrialpes/exmo/ontowrap/owlapi30/OWLAPI3OntologyFactory.java @@ -108,8 +108,7 @@ public class OWLAPI3OntologyFactory extends OntologyFactory { } @Override - public void clearCache() { - + public void clearCache() throws OntowrapException { cache.clear(); }