From 749d84efb3b65e1065cfa92d0cd1b7f53c3cf831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Tue, 12 Oct 2010 09:56:50 +0000 Subject: [PATCH] - corrected a bug in relativePosition (always returned 0 for classes) - implemented isPropertyPosition --- .../exmo/align/impl/eval/ExtPREvaluator.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java index 2ecdce27..c51b5b96 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java @@ -378,11 +378,9 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { protected int relativePosition( Object o1, Object o2, HeavyLoadedOntology<Object> onto ) throws AlignmentException { try { if ( onto.isClass( o1 ) && onto.isClass( o2 ) ){ - isSuperClass( o2, o1, onto ); // This is the level + return superClassPosition( o1, o2, onto ); } 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; } + return superPropertyPosition( o1, o2, onto ); } else if ( onto.isIndividual( o1 ) && onto.isIndividual( o2 ) ){ return 0; } @@ -392,18 +390,6 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { } } - /** - * JE2010: THIS SHOULD BE REWRITTEN AS THE SUBCLASS STUFF - */ - public boolean isSuperProperty( Object prop1, Object prop2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { - try { - return ontology.getSuperProperties( prop2, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ).contains( prop1 ); - } catch ( OntowrapException owex ) { - throw new AlignmentException( "Cannot interpret isSuperProperty", owex ); - } - } - - public int superClassPosition( Object class1, Object class2, HeavyLoadedOntology<Object> onto ) throws AlignmentException { int result = - isSuperClass( class2, class1, onto ); if ( result == 0 ) @@ -416,7 +402,7 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { * directly a class is superclass of another or not. * * This would require computing the transitive reduction of the superClass - * relation which is currently returned bu HeavyLoadedOntology. + * relation which is currently returned by HeavyLoadedOntology. */ @SuppressWarnings("unchecked") public int isSuperClass( Object class1, Object class2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { @@ -448,6 +434,41 @@ public class ExtPREvaluator extends BasicEvaluator implements Evaluator { } } + public int superPropertyPosition( Object prop1, Object prop2, HeavyLoadedOntology<Object> onto ) throws AlignmentException { + int result = - isSuperProperty( prop2, prop1, onto ); + if ( result == 0 ) + return isSuperProperty( prop1, prop2, onto ); + return result; + } + + public int isSuperProperty( Object prop1, Object prop2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { + try { + URI uri1 = ontology.getEntityURI( prop1 ); + Set<?> bufferedSuperProperties = null; + Set<Object> superproperties = (Set<Object>)ontology.getSuperProperties( prop1, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ); + int level = 0; + int foundlevel = 0; + + while ( !superproperties.isEmpty() ){ + bufferedSuperProperties = superproperties; + superproperties = new HashSet<Object>(); + level++; + for( Object entity : bufferedSuperProperties ) { + if ( ontology.isProperty( entity ) ){ + URI uri2 = ontology.getEntityURI( entity ); + if ( uri1.equals( uri2 ) ) { + if ( level < foundlevel ) foundlevel = level; + } else { + superproperties.addAll(ontology.getSuperProperties( entity, OntologyFactory.DIRECT, OntologyFactory.ANY, OntologyFactory.ANY ) ); + } + } + } + } + return foundlevel; + } catch ( OntowrapException owex ) { + throw new AlignmentException( "Cannot find entity URI", owex ); + } + } /** * This now output the results in Lockheed format. -- GitLab