From 503f33d246c706eb2132d8884f9fdb27b519c8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Mon, 31 Mar 2008 10:26:08 +0000 Subject: [PATCH] - fully implemented abstract ontology management --- html/relnotes.html | 24 +- html/up2to3.html | 85 +++-- lib/mappingapilite.jar | Bin 89807 -> 89807 bytes .../exmo/align/impl/BasicAlignment.java | 65 +++- .../inrialpes/exmo/align/impl/BasicCell.java | 14 + .../exmo/align/impl/ConcatenatedIterator.java | 3 +- .../exmo/align/impl/DistanceAlignment.java | 184 +++++----- .../exmo/align/impl/MatrixMeasure.java | 98 +++-- .../exmo/align/impl/OWLAPIAlignment.java | 68 +--- .../inrialpes/exmo/align/impl/OWLAPICell.java | 32 +- .../exmo/align/impl/ObjectAlignment.java | 188 ++++++++++ .../inrialpes/exmo/align/impl/ObjectCell.java | 115 ++++++ .../inrialpes/exmo/align/impl/Similarity.java | 28 +- .../exmo/align/impl/eval/ExtPREvaluator.java | 159 ++++---- .../align/impl/eval/SymMeanEvaluator.java | 58 ++- .../impl/method/ClassStructAlignment.java | 201 ++++------ .../impl/method/EditDistNameAlignment.java | 40 +- .../impl/method/NameAndPropertyAlignment.java | 217 +++++------ .../align/impl/method/NameEqAlignment.java | 48 +-- .../align/impl/method/SMOANameAlignment.java | 45 +-- .../impl/method/StringDistAlignment.java | 51 +-- .../impl/method/StrucSubsDistAlignment.java | 347 +++++++----------- .../impl/method/SubsDistNameAlignment.java | 56 +-- .../renderer/COWLMappingRendererVisitor.java | 61 ++- .../renderer/OWLAxiomsRendererVisitor.java | 154 ++++---- .../impl/renderer/RDFRendererVisitor.java | 44 ++- .../renderer/SEKTMappingRendererVisitor.java | 86 ++--- .../impl/renderer/SKOSRendererVisitor.java | 37 +- .../impl/renderer/SWRLRendererVisitor.java | 112 +++--- .../impl/renderer/XSLTRendererVisitor.java | 30 +- .../exmo/align/ling/JWNLAlignment.java | 39 +- .../exmo/align/onto/HeavyLoadedOntology.java | 64 ++++ .../align/onto/owlapi10/OWLAPIOntology.java | 36 ++ .../onto/owlapi10/OWLAPIOntologyFactory.java | 2 +- .../exmo/align/parser/AlignmentParser.java | 10 +- .../align/service/AServProtocolManager.java | 18 +- .../exmo/align/service/CacheImpl.java | 2 +- .../align/service/CannotRenderAlignment.java | 4 +- .../exmo/align/util/ExtGroupEval.java | 6 +- .../exmo/align/util/ParserPrinter.java | 7 +- .../inrialpes/exmo/align/util/Procalign.java | 2 +- src/org/semanticweb/owl/align/Alignment.java | 12 +- 42 files changed, 1474 insertions(+), 1378 deletions(-) create mode 100644 src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java create mode 100644 src/fr/inrialpes/exmo/align/impl/ObjectCell.java create mode 100644 src/fr/inrialpes/exmo/align/onto/HeavyLoadedOntology.java diff --git a/html/relnotes.html b/html/relnotes.html index 59134f5c..d26a8174 100644 --- a/html/relnotes.html +++ b/html/relnotes.html @@ -17,23 +17,33 @@ <h2>Under development</h2> <p><ul compact="1"> +<li>Output HTML in XHTML+RDFa (impl)</li> <li>Online evaluation (server)</li> <li>Upgrade to OWL 1.1 (impl)</li> -<li>Restructuring language dependent alignments (impl)</li> <li>Implementing database store for OMWG Language (server)</li> -<li>Replacing <tt>Parameters</tt> with Java <tt>Property</tt> (api/impl)</li> +<li>Implement ontology support database store (server)</li> <li>Implement debug options with log4j</li> <li>Use more for-each Java 1.5 construct</li> +<li>Rendering alignments as module descriptions (impl)</li> +<li>Replacing <tt>Parameters</tt> with Java <tt>Property</tt> (api/impl)[Version 4]</li> </ul></p> <h2>Current SVN trunk version</h2> -<!--h2>Version 3.3 (): xx/yy/2008 - O sole mio</h2--> +<!--h2>Version 3.3 (688): xx/yy/2008 - O sole mio</h2--> <p><ul compact="1"> -<li>Added an abstract ontology interface (impl)</li> +<li>Suppressed language dependent (OWLAPI) alignments (impl)</li> +<li><a href="up2to3.html" style="color:red;">Deprecated</a> + <tt>OWLAPIAlignment</tt> to be replaced by <tt>ObjectAlignment</tt></li> +<li>Reimplemented the whole API in function of the onto package (impl)</li> +<li>Added an abstract ontology package allowing to change API (onto)</li> +<li>Made <tt>Alignment</tt> iterable<Cell> (api/impl)</li> +<li>Corrected a bug in AlignmentParser that overlooked formalism URI (parser)</li> <li>Passed to Java 1.5 generics [incl. API modif] (dev/api)</li> +<li>Added first unit tests (TestNG) (dev)</li> <li>Passed all code through lint (dev)</li> +<li>Corrected link to documentation (doc)</li> </ul></p> <h2>Version 3.2 (666): 29/02/2008 - Blejsko jezero</h2> @@ -57,7 +67,7 @@ <li>MANIFEST generation in buildfile (distrib)</li> <li>Improved version number management</li> <li>Javadoc generation flawless in buildfile (distrib)</li> -<li>Revised reference manual</li> +<li>Revised reference manual (doc)</li> </ul> </p> @@ -122,7 +132,9 @@ Other improvements include: The main modification in this version is more independence from the OWL API which is not anymore compulsory. Consequently, the existing implementation of matching methods with Alignment API should undergo - some modifications: <a href="up2to3.html">Here is how to do</a>.</p> + some modifications: <a href="up2to3.html">Here is how to do</a> + (this document has been updated to help migrating directly to + version 3.3 if necessary).</p> <p>The Alignment API is now compiled in Java 1.5 (older versions should still be able to run it).</p> diff --git a/html/up2to3.html b/html/up2to3.html index d3dfeba5..db5ef0a9 100644 --- a/html/up2to3.html +++ b/html/up2to3.html @@ -1,19 +1,56 @@ <html> <head> -<title>Alignment API: Upgrading from version 2.x to 3.0</title> +<title>Alignment API: Upgrading from version 2.x to 3.3</title> <!--style type="text/css">@import url(style.css);</style--> <link rel="stylesheet" type="text/css" href="base.css" /> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body bgcolor="#ffffff"> -<center><h1>Upgrading an Alignment implementation from version 2.x to - 3.0 of the Alignment API</h1></center> - -<p>The version 3.0 of the Alignment API has been designed to provide - matching algorithm designers more flexibility. In particular, the - version 3.0 does not necessarily rely on the OWL API, so designers - who want to use another OWL API can do so at no cost.</p> +<center><h1>Upgrading an Alignment implementation from version 2.x to 3.3 of the Alignment API</h1></center> + +<p> +Version 3.0 of the Alignment API has been designed to provide +matching algorithm designers more flexibility. In particular, the +version 3.0 does not necessarily rely on the OWL API, so designers +who want to use another OWL API, e.g., Jena, can do so at no cost. +</p> + +<p> +Version 3.3 goes one step further towards providing an API +independent access to ontologies. Hence it is possible to switch from +one API to another without changing code (see documentation). +</p> + +<p> +This has led to some changes over time in the API. +</p> + +<h2>Since version 3.3, OWLAPIAlignment, OWLAPICell, getObjectXAsURI() are + deprecated</h2> + +<p> +The <tt>OWLAPIAlignment</tt> and <tt>OWLAPICell</tt> introduced in +version 3.0 and which were previously discussed below are now deprecated and +replaced by <tt>ObjectAlignment</tt> and <tt>ObjectCell</tt>. However, +for compatibility purposes, these classes are still available and have +been reimplemented in function of the new ones. They still have the +same structure, content and behavior as the old ones, but the +remainder of the API does not use them anymore. +</p> + +<p> +Moreover, in most of the cases, these classes can be safely replaced +by the new ones (bringing the benefit of changing Ontology API).</p> + +<p>The main exception is that the <tt>getObjectXAsURI()</tt> is not available +in <tt>ObjectCell</tt>. So, call to this method on <tt>ObjectCell</tt> +will return <tt>null</tt>. The <tt>Ontology</tt> of the object is +necessary to obtain its URI, through the call to: +<pre> +ontology.getEntityURI( cell.getObjectX() ); +</pre> +</p> <h2>Don't panic</h2> @@ -22,20 +59,20 @@ 3. But first do not panic. This document aims at helping you in this simple task.</p> -<h2>From Basic to OWLAPI</h2> +<h2>From BasicAlignments to ObjectAlignments</h2> <p>Previously you certainly had your class extending <tt>BasicAlignment</tt>. You must now have it - extending <tt>OWLAPIAlignment</tt>. This guarantee that you will + extending <tt>ObjectAlignment</tt>. This guarantee that you will still find all the features found in the previous <tt>BasicAlignment</tt>.</p> <p>If you create on the fly new <tt>Alignment</tt> or - new <tt>Cell</tt>, if they must contain <tt>OWLEntity</tt>, then - be sure that they are created as <tt>OWLAPIAlignment</tt> - and <tt>OWLAPICell</tt> respectively.</p> + new <tt>Cell</tt>, if they must contain <tt>Object</tt> + (e.g., <tt>OWLEntity</tt>), then + be sure that they are created as <tt>ObjectAlignment</tt> + and <tt>ObjectCell</tt> respectively.</p> <p>The new implementation of <tt>BasicAlignment</tt> - and <tt>BasicCell</tt> provides additional new primitives such - as <tt>getOntology1URI()</tt> and <tt>getObject1AsURI()</tt>.</p> + provides additional new primitives such as <tt>getOntology1URI()</tt>.</p> <h2>Parsing alignments</h2> @@ -43,9 +80,9 @@ used <tt>AlignmentParser</tt> which returned a <tt>BasicAlignment</tt>. Now the <tt>AlignmentParser</tt> returns a <tt>URIAlignment</tt>. To turn this <tt>URIAlignment</tt> into - a <tt>OWLAPIAlignment</tt>, just - invoke <tt>OWLAPIAlignment.toOWLAPIAlignment( URIAlignment )</tt>. It - will return the corresponding <tt>OWLAPIAlignment</tt>.</p> + an <tt>ObjectAlignment</tt>, just + invoke <tt>ObjectAlignment.toObjectAlignment( URIAlignment )</tt>. It + will return the corresponding <tt>ObjectAlignment</tt>.</p> <p>Moreover, <tt>AlignmentParser.parse( URI )</tt> used to take a Hashtable as a second argument. This is not true anymore: you must @@ -57,19 +94,19 @@ following: <pre> AlignmentProcess al = new MyAlignment(); -al.init( OWLOntology, OWLOntology ); +al.init( Ontology, Ontology ); al.align( Alignment, Parameters ); </pre> -(You may have used a <tt>MyAlignment( OWLOntology, OWLOntology )</tt> +(You may have used a <tt>MyAlignment( Ontology, Ontology )</tt> constructor and no <tt>init</tt>. Now the sequence above is compulsory). -From version 3, the sequence is the same except that the arguments for init() are +Since version 3.0, the sequence is the same except that the arguments for init() are the <tt>URL</tt> where to find the ontologies instead of the ontology themselves. It is thus necessary for you to change your implementation of <tt>init()</tt> so that it loads the ontologies. Moreover, the init Alignment in <tt>align()</tt> is a <tt>URIAlignment</tt> and not -a <tt>OWLAPIAlignment</tt> so it may be necessary to change it as well.</p> +a <tt>ObjectAlignment</tt> so it may be necessary to change it as well.</p> -<p>Fortunately, the <tt>OWLAPIAlignment</tt> class already provides +<p>Fortunately, the <tt>OntologyFactory</tt> class already provides the <tt>loadOntology( URI, OntologyCache )</tt> method that loads the required ontology and a <tt>loadInit( URI )</tt> method that will load the initial alignment.</p> @@ -78,7 +115,7 @@ a <tt>OWLAPIAlignment</tt> so it may be necessary to change it as well.</p> <p>If you manipulated the alignment through the attributes (<tt>onto1</tt> and <tt>onto2</tt>), you must now explicitely cast - them as <tt>(OWLOntology)onto1</tt> because they are now declared + them as <tt>(Ontology)onto1</tt> because they are now declared as <tt>Object</tt>.</p> <h2>Misc.</h2> diff --git a/lib/mappingapilite.jar b/lib/mappingapilite.jar index 4ad55c763d9058068646f6db89ab6fb74ff00590..739d91e2bb26edeb2342522d35490c9757235016 100644 GIT binary patch delta 1787 zcmXw(ZA?>V6vyxBZFw(HKnV-XILfq9Tm=bLUP>uiD3*c+3bcR_6=Vc?o4hEBL*_Oy zz^>t%IVXk~-C#_-hRy|@+Zg*KjF4@~HaFb(pk_gXCPXD;_c_mF6WU+?=bZmJ&w1`; z=9X&amP(zQ%`5#l^668w_NzDYy^7W`!xHcvidG?3VIjX#i{hRF!KqrSLa6t9tkB3I zLr#;{VdFW@s^&POpb39Vx~Q(<F(*KCpH@8y4W<eozCx?6K)2_SlH<Ph=Qy)ml_urB z_CkqOwslor1O!jaG74jFj?$tS%gO^iaNL6Yw~e;arGuJG5w{rq?39Azx`aEPc(L3B zQBvxrenlXOP3!NyohZjvm14OT-VpTR!BWr`2OVv{{#`oSqxdiJ%+e<b6TaBjW&Ddy zl#&tRjb}~V@Lx}*eAZ?!j!VJ;db5wva<#qQ2dg@r*HqZ{pAf4#Tg7qr1F)^Mx3q<> z?zhT8>f2G(q{QhXB4SofzM5Xr*ACO!{;Uh7=Fb}TQN`6fsYG+UF#Hng^>M;{hrdwM z=7$5cwCSk*P{$=&W$8Re7x+{&etxsu$H$xF@`bSuvnX02Ob9p@A{BROX>w<GKP?aY zFpnzLJtcHAKb$F~%IkeL3UwdpXy{`hh*ph=@pM-W)$M~p@(tSpI4)D}wL@IZ0gaS& zF@h#Khf1i&jmvHXA@r&Z&-PRF>Xrogiq9*BZ!X74gICLF5BU57g-gQ>OkbR#%IxSl z3boe;D5$P8Wl(CTeWJ!$XxuXce5d??y?=8%`IRPbt|$<`pYWz|_qNFg70r)pyb*NM zXL*D>v&l4PbuIyIq{N?JP}uhC5nqjLX!tHRX}(c@A9}SM7c0z8tQS6A^c4>kgO~JV z{-_##4lOp)s)fggsbT37&|VeKAJUNRWipN-_V8dNRi0@cj;fGszK}@iR3NMm<WDGC z#o<UuCE)ot5)57_ZHR^igg`BrF_y1|<7;^NWfy<h4hHhNdo(-X16-SUAqkx1DH4~H zpbDWP87dK`lHo9dF$HQ6MpB>-Au1IPAiS3fEd&OPEYe_PHoqI80aNU0uovNa8k8f1 znV=crv<VI(ESp$QcRKUAn+~-YN;X3y!k8JV5h62K^X?2b*HQ-T$56>mW;nHzjiKKK z6&O0Zi#7GPu$&ePGyL1aeC(NQj2oHIj#XQ;pbNp11;-E!RydCEwUw<WJ{wNZoNRXF zO}n8JmC@ZSS#N_jR7PIG#vEq&Sq?N|Xq_G2K@jcCIXD+eQK`>m%EMf?jj}ujb9qqb zL;mai(eQFg-0Fa}V)-5@#ImpUuz@x^7z{et7Q*wHaylO-$nzyy3m^+&pg_JbqC78< z_d?)6p}Z*qvxTq^!QhmyhbUK^@_q^U7l8}mV3E9fqRbV613^~|MF=O0S@MHo`3^`< zehEvyUBYrAT=MWF)aU{`!lX;S6{6_etb3nZo{&8MPu-A%kWmV5grQOv@+y<NlN@&$ GH2n{zWH?a( delta 1787 zcmXw(ZA?>F7{|}k+wxwZfD#s%aTK*tTm=bLUP>uiD7FO)6leh<D#!@(HVG)ohRkhZ zlwHF$QzwS_vcZ^m4V?=*HyQgRjF4@~HaFb(pk_gXCPXD;_de&?g!Y&J|9LylxtFP1 zs;OHlbzUx~3?TAn{BldLdL4K7a?6Ne0XVz2nU7ak<X^E>abJPpQms@WGz2_RXe7&E zZ`L|(93fUUAx2&k`L=jLUCUuikmdo+dKw-|6)tj#W?g}9?_(t)-vtt4ma;O$yf<Dd zG0V29+D8W78@GtU$eLlA6lYm_s0Tvkq`%Fyl`a$1@)Qa4vCoew2<hVQcoT&R6U2z= z>w6W!vNx%}|4y>xEh~izExg6+BSXcIjZQk+9{u}tw8x2G;hDvANn`%l*KPcZPL!4v z=8I=dUi)89m2}n?A3{=afRnigX}a3c;D=eAu4^i6`%jqFoU0<_K@heTca^o$)%{l0 zPwRG6H!E@asHnK5qpznI^>u@Ewm<8`Y4PWcyQ$)C8CPO)yfFOY8}teMY)2qp+ZKQW zw6^JJ`GJm$G|SR?hA!}#X7ua^sgIv8AqD(MhglG;5Wxo>4iihdv^2Q0yO*X%e4I~} znx0a+nIBFRQRU53HVXBh=&1E6A40Q+ghaZl#+vs25b1_(L4;&Wy|xO=cF>3^7oupO zYoL_YxN*sYz=vP8;n{wQUEY`^UGZ5Z|Lvs&vHxm0?Ezn$r*LtQf$7T=RGA(=L!s_k z9|hHQru2*Lv`@?^vqrsBz&WG`?8BQ|<X>_8=8^*8?wBuyd$&z~sAzs%;ftV~Jk258 znNFoK%QHz>Moj+sC56qu9`x5p1r6WFr_44<@54zgA@Th5*lPZ>d4FMl3HXRlXAh~d z&i?r(nl<<204-Ry0JK--i$~P5y-LL~gdPrza+Y_JgF`ALn?EE|Iu;D8gJn$^jD~bH z|BVKN4@zreVGbc!3ug2Rv~XkvC%x>#FI&JMzwTbmR`>|lCY(<Jm;4k7iz!fzP?-u< z2otGr0Ku3BwFpCLP>&Fk4to(kNQYJ#`i#tJG_o?k8=(<H92u|+;d%yCAVip;1>v{} z_8}~qSWizTt8*_C>d;CxLleS?8EO!svsm-)EH>9d7VJT*bQ>!;v5k$P-wu^%o!-ux z23lB5tA!Q(+rsKNve_6nvY{QbHswGUf;R^aBN(i31mPPiTTfyxyhmel*^$@pfKF6~ zcd%f+4cbr{dJXIBtl;N%Xhv(51Kvdt9ISF^9+aWdkjIoqd2Acy`3z?Aq25paulGme zs|jI~6IKcpJD~{EzTU|O+Tdi+?_^tuEMUs<0vN;R#aakC2z`apg~?CXi$ZBHGVCpq zHYLM!5$r}VxTNcml`Af3zcK_CgBxLAv9x+wnJES*g02LL5ssFy;D;sB9mp{Sr7ZY% xDT|46OT)`nlN%fe<8J9zWJTv;-A{SggwH%+M=PrgJO~42%<?H`-96>d{6B*{jn@DG diff --git a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java index a51155bb..b0af8666 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicAlignment.java @@ -21,6 +21,7 @@ package fr.inrialpes.exmo.align.impl; +import java.lang.Iterable; import java.util.Hashtable; import java.util.HashSet; import java.util.Enumeration; @@ -93,11 +94,17 @@ public class BasicAlignment implements Alignment { onto2 = new BasicOntology<Object>(); } + /** + * Initialises the Alignment object with two ontologies. + * These two ontologies can be either an instance of fr.inrialpes.exmo.align.onto.Ontology + * which will then replaced the one that was there at creation time + * or a "concrete" ontology which will be inserted in the fr.inrialpes.exmo.align.onto.Ontology + * object. + */ public void init( Object onto1, Object onto2, Object cache ) throws AlignmentException { - // JE: Onto I am not sure this works if ( onto1 instanceof Ontology ) { - this.onto1 = (Ontology<Object>)onto1; - this.onto2 = (Ontology<Object>)onto2; + this.onto1 = (Ontology<Object>)onto1; // [W:unchecked] + this.onto2 = (Ontology<Object>)onto2; // [W:unchecked] } else { this.onto1.setOntology( onto1 ); this.onto2.setOntology( onto2 ); @@ -129,11 +136,11 @@ public class BasicAlignment implements Alignment { return onto2.getOntology(); }; - public Ontology getOntologyObject1() { + public Ontology<Object> getOntologyObject1() { return onto1; }; - public Ontology getOntologyObject2() { + public Ontology<Object> getOntologyObject2() { return onto2; }; @@ -195,6 +202,10 @@ public class BasicAlignment implements Alignment { return new MEnumeration<Cell>( hash1 ); } + public Iterator<Cell> iterator() { + return new MIterator<Cell>( hash1 ); + } + public ArrayList<Cell> getArrayElements() { ArrayList<Cell> array = new ArrayList<Cell>(); for (Enumeration e = getElements(); e.hasMoreElements(); ) { @@ -267,8 +278,7 @@ public class BasicAlignment implements Alignment { } /* - * Deprecated: implement as the one retrieving the highest strength correspondence - * @deprecated + * @deprecated implemented as the one retrieving the highest strength correspondence */ public Cell getAlignCell1(Object ob) throws AlignmentException { if ( Annotations.STRICT_IMPLEMENTATION == true ){ @@ -635,3 +645,44 @@ class MEnumeration<T> implements Enumeration<T> { return val; } } + +class MIterator<T> implements Iterator<T> { + // Because of the remove, the implentation should be different + // Keeping the last element at hand + private Enumeration<Set<T>> set = null; // The enumeration of sets + private Iterator<T> current = null; // The current set's enumeration + private Iterator<T> next = null; // The next set enumeration + + MIterator( Hashtable<Object,Set<T>> s ){ + set = s.elements(); + if ( set.hasMoreElements() ) { + current = set.nextElement().iterator(); + if ( current.hasNext() ) { + next = current; + } else { + while( set.hasMoreElements() && next == null ){ + next = set.nextElement().iterator(); + if( !next.hasNext() ) next = null; + } + } + } + } + public boolean hasNext(){ + return ( next != null && next.hasNext() ); + } + public T next(){ + current = next; + T val = current.next(); + if( !current.hasNext() ){ + next = null; + while( set.hasMoreElements() && next == null ){ + next = set.nextElement().iterator(); + if( !next.hasNext() ) next = null; + } + } + return val; + } + public void remove(){ + if ( current != null ) current.remove(); + } +} diff --git a/src/fr/inrialpes/exmo/align/impl/BasicCell.java b/src/fr/inrialpes/exmo/align/impl/BasicCell.java index 0e97b6db..c8b2952d 100644 --- a/src/fr/inrialpes/exmo/align/impl/BasicCell.java +++ b/src/fr/inrialpes/exmo/align/impl/BasicCell.java @@ -92,6 +92,13 @@ public class BasicCell implements Cell, Comparable<Cell> { public void setSemantics( String sem ){ semantics = sem; }; public Object getObject1(){ return object1; }; public Object getObject2(){ return object2; }; + /** + * Since version 3.3, the interpretation of objects (and thus finding their + * URI) depends on the Ontology API which is used. This information is not + * stored in the Cells (this would cost two pointers per cell) and thus, + * most of the time, this will raise an exception. + * Use <tt>Ontology.getEntityURI( this )</tt> instead. + */ public URI getObject1AsURI() throws AlignmentException { if ( object1 instanceof URI ) { return (URI)object1; @@ -99,6 +106,13 @@ public class BasicCell implements Cell, Comparable<Cell> { throw new AlignmentException( "Cannot find URI for "+object1 ); } } + /** + * Since version 3.3, the interpretation of objects (and thus finding their + * URI) depends on the Ontology API which is used. This information is not + * stored in the Cells (this would cost two pointers per cell) and thus, + * most of the time, this will raise an exception. + * Use <tt>Ontology.getEntityURI( this )</tt> instead. + */ public URI getObject2AsURI() throws AlignmentException { if ( object2 instanceof URI ) { return (URI)object2; diff --git a/src/fr/inrialpes/exmo/align/impl/ConcatenatedIterator.java b/src/fr/inrialpes/exmo/align/impl/ConcatenatedIterator.java index 76f9a056..89ac07a1 100644 --- a/src/fr/inrialpes/exmo/align/impl/ConcatenatedIterator.java +++ b/src/fr/inrialpes/exmo/align/impl/ConcatenatedIterator.java @@ -26,8 +26,7 @@ import java.lang.UnsupportedOperationException; /** * This class builds a composite iterator from two iterators - * This helps writing more concise code especially since - * the OWL API does not impements Iterator getProperties() in OWL Ontologies + * This helps writing more concise code. * * This is the naive implementation (can be optimized) * diff --git a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java index ee6f1c78..209b8a8c 100644 --- a/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/DistanceAlignment.java @@ -27,12 +27,7 @@ import java.util.TreeSet; import java.util.SortedSet; import java.util.Comparator; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; +import fr.inrialpes.exmo.align.onto.LoadedOntology; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; @@ -46,17 +41,18 @@ import org.semanticweb.owl.align.Parameters; * @version $Id$ */ -public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProcess +public class DistanceAlignment extends ObjectAlignment implements AlignmentProcess { Similarity sim; /** Creation **/ public DistanceAlignment() {} - public DistanceAlignment( OWLOntology onto1, OWLOntology onto2 ){ + // JE: OntoRewr (LoadedOntology -> one step above) + //public DistanceAlignment( LoadedOntology onto1, LoadedOntology onto2 ){ // Init must now be triggered explicitely // init( onto1, onto2 ); - }; + //}; public void setSimilarity( Similarity s ) { sim = s; } public Similarity getSimilarity() { return sim; } @@ -67,7 +63,7 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce public double getAlignedDistance1( Object ob ) throws AlignmentException { return (1 - getAlignedStrength1(ob)); }; - public double getAlignedDistance2( Object ob ) throws AlignmentException{ + public double getAlignedDistance2( Object ob ) throws AlignmentException { return (1 - getAlignedStrength2(ob)); }; @@ -86,7 +82,8 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce if ( sim == null ) throw new AlignmentException("DistanceAlignment: requires a similarity measure"); - sim.initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), init ); + sim.initialize( ontology1(), ontology2(), init ); + //sim.initialize( getOntologyObject1(), getOntologyObject2(), init ); sim.compute( params ); if ( params.getParameter("printMatrix") != null ) printDistanceMatrix(params); extract( getType(), params ); @@ -161,17 +158,17 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce try { // Extract for properties ConcatenatedIterator pit1 = new - ConcatenatedIterator(((OWLOntology)(onto1.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto1.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology1().getObjectProperties().iterator(), + ontology1().getDataProperties().iterator()); for ( ; pit1.hasNext(); ) { - OWLProperty prop1 = (OWLProperty)pit1.next(); + Object prop1 = pit1.next(); found = false; max = threshold; val = 0; - OWLProperty prop2 = null; + Object prop2 = null; ConcatenatedIterator pit2 = new - ConcatenatedIterator(((OWLOntology)(onto2.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto2.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology2().getObjectProperties().iterator(), + ontology2().getDataProperties().iterator()); for ( ; pit2.hasNext(); ) { - OWLProperty current = (OWLProperty)pit2.next(); + Object current = pit2.next(); val = 1 - sim.getPropertySimilarity(prop1,current); if ( val > max) { found = true; max = val; prop2 = current; @@ -180,30 +177,30 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce if ( found ) addAlignCell(prop1,prop2, "=", max); } // Extract for classes - for (Iterator it1 = ((OWLOntology)(onto1.getOntology())).getClasses().iterator(); it1.hasNext(); ) { - OWLClass class1 = (OWLClass)it1.next(); + for (Iterator it1 = ontology1().getClasses().iterator(); it1.hasNext(); ) { + Object class1 = it1.next(); found = false; max = threshold; val = 0; - OWLClass class2 = null; - for (Iterator it2 = ((OWLOntology)(onto2.getOntology())).getClasses().iterator(); it2.hasNext(); ) { - OWLClass current = (OWLClass)it2.next(); + Object class2 = null; + for (Iterator it2 = ontology2().getClasses().iterator(); it2.hasNext(); ) { + Object current = it2.next(); val = 1 - sim.getClassSimilarity(class1,current); if (val > max) { found = true; max = val; class2 = current; } } - if ( found ) addAlignCell(class1,class2, "=", max); + if ( found ) addAlignCell(class1, class2, "=", max); } // Extract for individuals // This does not work, at least for the OAEI 2005 tests if ( params.getParameter("noinst") == null ){ - for (Iterator it1 = ((OWLOntology)(onto1.getOntology())).getIndividuals().iterator(); it1.hasNext();) { - OWLIndividual ind1 = (OWLIndividual)it1.next(); - if ( ind1.getURI() != null ) { + for (Iterator it1 = ontology1().getIndividuals().iterator(); it1.hasNext();) { + Object ind1 = it1.next(); + if ( ontology1().getEntityURI( ind1 ) != null ) { found = false; max = threshold; val = 0; - OWLIndividual ind2 = null; - for (Iterator it2 = ((OWLOntology)(onto2.getOntology())).getIndividuals().iterator(); it2.hasNext(); ) { - OWLIndividual current = (OWLIndividual)it2.next(); - if ( current.getURI() != null ) { + Object ind2 = null; + for (Iterator it2 = ontology2().getIndividuals().iterator(); it2.hasNext(); ) { + Object current = it2.next(); + if ( ontology2().getEntityURI( current ) != null ) { val = 1 - sim.getIndividualSimilarity(ind1,current); if (val > max) { found = true; max = val; ind2 = current; @@ -214,8 +211,7 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce } } } - } catch (OWLException owlex) { owlex.printStackTrace(); } - catch (AlignmentException alex) { alex.printStackTrace(); } + } catch (AlignmentException alex) { alex.printStackTrace(); } return((Alignment)this); } @@ -230,18 +226,18 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce // (redoing the matrix instead of getting it) // For each kind of stuff (cl, pr, ind) // Create a matrix - int nbclasses1 = ((OWLOntology)(onto1.getOntology())).getClasses().size(); - int nbclasses2 = ((OWLOntology)(onto2.getOntology())).getClasses().size(); + int nbclasses1 = ontology1().nbClasses(); + int nbclasses2 = ontology2().nbClasses(); double[][] matrix = new double[nbclasses1][nbclasses2]; - OWLClass[] class1 = new OWLClass[nbclasses1]; - OWLClass[] class2 = new OWLClass[nbclasses2]; + Object[] class1 = new Object[nbclasses1]; + Object[] class2 = new Object[nbclasses2]; int i = 0; - for (Iterator it1 = ((OWLOntology)(onto1.getOntology())).getClasses().iterator(); it1.hasNext(); i++) { - class1[i] = (OWLClass)it1.next(); + for (Iterator it1 = ontology1().getClasses().iterator(); it1.hasNext(); i++) { + class1[i] = it1.next(); } int j = 0; - for (Iterator it2 = ((OWLOntology)(onto2.getOntology())).getClasses().iterator(); it2.hasNext(); j++) { - class2[j] = (OWLClass)it2.next(); + for (Iterator it2 = ontology2().getClasses().iterator(); it2.hasNext(); j++) { + class2[j] = it2.next(); } for( i = 0; i < nbclasses1; i++ ){ for( j = 0; j < nbclasses2; j++ ){ @@ -258,31 +254,30 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce // it means that alignments with 0. similarity // will be excluded from the best match. if( val > threshold ){ - addCell( new OWLAPICell( (String)null, class1[result[i][0]], class2[result[i][1]], BasicRelation.createRelation("="), val ) ); + addCell( new ObjectCell( (String)null, class1[result[i][0]], class2[result[i][1]], BasicRelation.createRelation("="), val ) ); } } - } catch (OWLException owlex) { owlex.printStackTrace(); } - catch (AlignmentException alex) { alex.printStackTrace(); } + } catch (AlignmentException alex) { alex.printStackTrace(); } // For properties try{ - int nbprop1 = ((OWLOntology)(onto1.getOntology())).getDataProperties().size() + ((OWLOntology)(onto1.getOntology())).getObjectProperties().size(); - int nbprop2 = ((OWLOntology)(onto2.getOntology())).getDataProperties().size() + ((OWLOntology)(onto2.getOntology())).getObjectProperties().size(); + int nbprop1 = ontology1().nbProperties(); + int nbprop2 = ontology2().nbProperties(); double[][] matrix = new double[nbprop1][nbprop2]; - OWLProperty[] prop1 = new OWLProperty[nbprop1]; - OWLProperty[] prop2 = new OWLProperty[nbprop2]; + Object[] prop1 = new Object[nbprop1]; + Object[] prop2 = new Object[nbprop2]; int i = 0; ConcatenatedIterator pit1 = new - ConcatenatedIterator(((OWLOntology)(onto1.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto1.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology1().getObjectProperties().iterator(), + ontology1().getDataProperties().iterator()); for (; pit1.hasNext(); i++) { - prop1[i] = (OWLProperty)pit1.next(); + prop1[i] = pit1.next(); } int j = 0; ConcatenatedIterator pit2 = new - ConcatenatedIterator(((OWLOntology)(onto2.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto2.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology2().getObjectProperties().iterator(), + ontology2().getDataProperties().iterator()); for (; pit2.hasNext(); j++) { - prop2[j] = (OWLProperty)pit2.next(); + prop2[j] = pit2.next(); } for( i = 0; i < nbprop1; i++ ){ for( j = 0; j < nbprop2; j++ ){ @@ -299,11 +294,10 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce // it means that alignments with 0. similarity // will be excluded from the best match. if( val > threshold ){ - addCell( new OWLAPICell( (String)null, prop1[result[i][0]], prop2[result[i][1]], BasicRelation.createRelation("="), val ) ); + addCell( new ObjectCell( (String)null, prop1[result[i][0]], prop2[result[i][1]], BasicRelation.createRelation("="), val ) ); } } - }catch (OWLException owlex) { owlex.printStackTrace(); } - catch (AlignmentException alex) { alex.printStackTrace(); } + } catch (AlignmentException alex) { alex.printStackTrace(); } return((Alignment)this); } @@ -322,7 +316,7 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce * with overall of 1.8. */ public Alignment extractqqNaive( double threshold, Parameters params) { - OWLEntity ent1=null, ent2=null; + Object ent1=null, ent2=null; double val = 0; //TreeSet could be replaced by something else //The comparator must always tell that things are different! @@ -348,21 +342,21 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce return -1; } else if ( o1.getStrength() < o2.getStrength() ){ return 1; - } else if ( (((OWLEntity)o1.getObject1()).getURI().getFragment() == null) - || (((OWLEntity)o2.getObject1()).getURI().getFragment() == null) ) { + } else if ( ontology1().getEntityName( o1.getObject1() ) == null + || ontology2().getEntityName( o2.getObject1() ) == null ) { return -1; - } else if ( ((OWLEntity)o1.getObject1()).getURI().getFragment().compareTo(((OWLEntity)o2.getObject1()).getURI().getFragment()) > 0) { + } else if ( ontology1().getEntityName( o1.getObject1()).compareTo( ontology2().getEntityName( o2.getObject1() ) ) > 0 ) { return -1; - } else if ( ((OWLEntity)o1.getObject1()).getURI().getFragment().compareTo(((OWLEntity)o2.getObject1()).getURI().getFragment()) < 0 ) { + } else if ( ontology1().getEntityName( o1.getObject1()).compareTo( ontology2().getEntityName( o2.getObject1() ) ) < 0 ) { return 1; - } else if ( (((OWLEntity)o1.getObject2()).getURI().getFragment() == null) - || (((OWLEntity)o2.getObject2()).getURI().getFragment() == null) ) { + } else if ( ontology1().getEntityName( o1.getObject2() ) == null + || ontology2().getEntityName( o2.getObject2() ) == null ) { return -1; - } else if ( ((OWLEntity)o1.getObject2()).getURI().getFragment().compareTo(((OWLEntity)o2.getObject2()).getURI().getFragment()) > 0) { + } else if ( ontology1().getEntityName( o1.getObject2()).compareTo( ontology2().getEntityName( o2.getObject2() ) ) > 0 ) { return -1; - // On va supposer qu'ils n'ont pas le meme nom + // Assume they have different names } else { return 1; } - } catch ( OWLException e) { + } catch ( AlignmentException e) { e.printStackTrace(); return 0;} } } @@ -373,46 +367,43 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce // Plus a map from the objects to the cells // O(n^2.log n) ConcatenatedIterator pit1 = new - ConcatenatedIterator(((OWLOntology)(onto1.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto1.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology1().getObjectProperties().iterator(), + ontology1().getDataProperties().iterator()); for (; pit1.hasNext(); ) { - ent1 = (OWLProperty)pit1.next(); + ent1 = pit1.next(); ConcatenatedIterator pit2 = new - ConcatenatedIterator(((OWLOntology)(onto2.getOntology())).getObjectProperties().iterator(), - ((OWLOntology)(onto2.getOntology())).getDataProperties().iterator()); + ConcatenatedIterator(ontology2().getObjectProperties().iterator(), + ontology2().getDataProperties().iterator()); for (; pit2.hasNext(); ) { - ent2 = (OWLProperty)pit2.next(); - val = 1 - sim.getPropertySimilarity((OWLProperty)ent1,(OWLProperty)ent2); - //val = ((SimilarityMeasure)getSimilarity()).getSimilarity(ent1.getURI(),ent2.getURI()); + ent2 = pit2.next(); + val = 1 - sim.getPropertySimilarity( ent1, ent2 ); if ( val > threshold ){ - cellSet.add( new OWLAPICell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); + cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); } } } - for (Iterator it1 = ((OWLOntology)(onto1.getOntology())).getClasses().iterator(); it1.hasNext(); ) { - ent1 = (OWLClass)it1.next(); - for (Iterator it2 = ((OWLOntology)(onto2.getOntology())).getClasses().iterator(); it2.hasNext(); ) { - ent2 = (OWLClass)it2.next(); - val = 1 - sim.getClassSimilarity((OWLClass)ent1,(OWLClass)ent2); - //val = ((SimilarityMeasure)getSimilarity()).getSimilarity(ent1.getURI(),ent2.getURI()); + for (Iterator it1 = ontology1().getClasses().iterator(); it1.hasNext(); ) { + ent1 = it1.next(); + for (Iterator it2 = ontology2().getClasses().iterator(); it2.hasNext(); ) { + ent2 = it2.next(); + val = 1 - sim.getClassSimilarity( ent1, ent2 ); if ( val > threshold ){ - cellSet.add( new OWLAPICell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); + cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); } } } // OLA with or without instances if ( params.getParameter("noinst") == null ){ - for (Iterator it1 = ((OWLOntology)(onto1.getOntology())).getIndividuals().iterator(); it1.hasNext();) { - ent1 = (OWLIndividual)it1.next(); - if ( ent1.getURI() != null ) { + for (Iterator it1 = ontology1().getIndividuals().iterator(); it1.hasNext();) { + ent1 = it1.next(); + if ( ontology1().getEntityURI( ent1 ) != null ) { - for (Iterator it2 = ((OWLOntology)(onto2.getOntology())).getIndividuals().iterator(); it2.hasNext(); ) { - ent2 = (OWLIndividual)it2.next(); - if ( ent2.getURI() != null ) { - val = 1 - sim.getIndividualSimilarity((OWLIndividual)ent1,(OWLIndividual)ent2); - //val = ((SimilarityMeasure)getSimilarity()).getSimilarity(ent1.getURI(),ent2.getURI()); + for (Iterator it2 = ontology2().getIndividuals().iterator(); it2.hasNext(); ) { + ent2 = it2.next(); + if ( ontology2().getEntityURI( ent2 ) != null ) { + val = 1 - sim.getIndividualSimilarity( ent1, ent2 ); if ( val > threshold ){ - cellSet.add( new OWLAPICell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); + cellSet.add( new ObjectCell( (String)null, ent1, ent2, BasicRelation.createRelation("="), val ) ); } } } @@ -423,16 +414,17 @@ public class DistanceAlignment extends OWLAPIAlignment implements AlignmentProce // O(n^2) for( Iterator it = cellSet.iterator(); it.hasNext(); ){ Cell cell = (Cell)it.next(); - ent1 = (OWLEntity)cell.getObject1(); - ent2 = (OWLEntity)cell.getObject2(); + ent1 = cell.getObject1(); + ent2 = cell.getObject2(); if ( (getAlignCells1( ent1 ) == null) && (getAlignCells2( ent2 ) == null) ){ // The cell is directly added! addCell( cell ); } }; - } catch (AlignmentException alex) { alex.printStackTrace(); } - catch (OWLException owlex) { owlex.printStackTrace(); } + } catch (AlignmentException alex) { + alex.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 4d231e86..0f0f6caa 100644 --- a/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java +++ b/src/fr/inrialpes/exmo/align/impl/MatrixMeasure.java @@ -24,17 +24,13 @@ import java.util.Iterator; import java.util.HashMap; import java.text.NumberFormat; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; +import fr.inrialpes.exmo.align.onto.LoadedOntology; + import fr.inrialpes.exmo.align.impl.Similarity; /** @@ -49,8 +45,8 @@ import fr.inrialpes.exmo.align.impl.Similarity; public abstract class MatrixMeasure implements Similarity { //Momentaneously public - public OWLOntology onto1 = null; - public OWLOntology onto2 = null; + public LoadedOntology onto1 = null; + public LoadedOntology onto2 = null; public int nbclass1 = 0; // number of classes in onto1 public int nbclass2 = 0; // number of classes in onto2 public int nbprop1 = 0; // number of classes in onto1 @@ -59,12 +55,12 @@ public abstract class MatrixMeasure implements Similarity { public int nbind2 = 0; // number of individuals in onto2 public int i, j = 0; // index for onto1 and onto2 classes public int l1, l2 = 0; // length of strings (for normalizing) - public HashMap<OWLClass,Integer> classlist2 = null; // onto2 classes - public HashMap<OWLClass,Integer> classlist1 = null; // onto1 classes - public HashMap<OWLProperty,Integer> proplist2 = null; // onto2 properties - public HashMap<OWLProperty,Integer> proplist1 = null; // onto1 properties - public HashMap<OWLIndividual,Integer> indlist2 = null; // onto2 individuals - public HashMap<OWLIndividual,Integer> indlist1 = null; // onto1 individuals + public HashMap<Object,Integer> classlist2 = null; // onto2 classes + public HashMap<Object,Integer> classlist1 = null; // onto1 classes + public HashMap<Object,Integer> proplist2 = null; // onto2 properties + public HashMap<Object,Integer> proplist1 = null; // onto1 properties + public HashMap<Object,Integer> indlist2 = null; // onto2 individuals + public HashMap<Object,Integer> indlist1 = null; // onto1 individuals private NumberFormat numFormat = null; // printing @@ -72,88 +68,88 @@ public abstract class MatrixMeasure implements Similarity { public double prmatrix[][]; // distance matrix public double indmatrix[][]; // distance matrix - public void initialize( OWLOntology onto1, OWLOntology onto2, Alignment align ){ + public void initialize( LoadedOntology onto1, LoadedOntology onto2, Alignment align ){ initialize( onto1, onto2 ); // Set the values of the initial alignment in the cells } - public void initialize( OWLOntology o1, OWLOntology o2 ){ + public void initialize( LoadedOntology o1, LoadedOntology o2 ){ onto1 = o1; onto2 = o2; - classlist2 = new HashMap<OWLClass,Integer>(); // onto2 classes - classlist1 = new HashMap<OWLClass,Integer>(); // onto1 classes - proplist2 = new HashMap<OWLProperty,Integer>(); // onto2 properties - proplist1 = new HashMap<OWLProperty,Integer>(); // onto1 properties - indlist2 = new HashMap<OWLIndividual,Integer>(); // onto2 instances - indlist1 = new HashMap<OWLIndividual,Integer>(); // onto1 instances + classlist2 = new HashMap<Object,Integer>(); // onto2 classes + classlist1 = new HashMap<Object,Integer>(); // onto1 classes + proplist2 = new HashMap<Object,Integer>(); // onto2 properties + proplist1 = new HashMap<Object,Integer>(); // onto1 properties + indlist2 = new HashMap<Object,Integer>(); // onto2 instances + indlist1 = new HashMap<Object,Integer>(); // onto1 instances try { // Create class lists for ( Iterator it = onto2.getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.put( (OWLClass)it.next(), new Integer(nbclass2) ); + classlist2.put( (Object)it.next(), new Integer(nbclass2) ); } for ( Iterator it = onto1.getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.put( (OWLClass)it.next(), new Integer(nbclass1) ); + classlist1.put( (Object)it.next(), new Integer(nbclass1) ); } clmatrix = new double[nbclass1+1][nbclass2+1]; // Create property lists for ( Iterator it = onto2.getObjectProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.put( (OWLProperty)it.next(), new Integer(nbprop2) ); + proplist2.put( (Object)it.next(), new Integer(nbprop2) ); } for ( Iterator it = onto2.getDataProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.put( (OWLProperty)it.next(), new Integer(nbprop2) ); + proplist2.put( (Object)it.next(), new Integer(nbprop2) ); } for ( Iterator it = onto1.getObjectProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.put( (OWLProperty)it.next(), new Integer(nbprop1) ); + proplist1.put( (Object)it.next(), new Integer(nbprop1) ); } for ( Iterator it = onto1.getDataProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.put( (OWLProperty)it.next(), new Integer(nbprop1) ); + proplist1.put( (Object)it.next(), new Integer(nbprop1) ); } prmatrix = new double[nbprop1+1][nbprop2+1]; // Create individual lists for ( Iterator it = onto2.getIndividuals().iterator(); it.hasNext(); ){ - OWLIndividual o = (OWLIndividual)it.next(); + Object o = (Object)it.next(); //System.err.println( o ); // We suppress anonymous individuals... this is not legitimate - if ( o.getURI() != null ) { + if ( onto2.getEntityURI(o) != null ) { indlist2.put( o, new Integer(nbind2) ); nbind2++; } } for ( Iterator it = onto1.getIndividuals().iterator(); it.hasNext(); ){ - OWLIndividual o = (OWLIndividual)it.next(); + Object o = (Object)it.next(); //System.err.println( o ); // We suppress anonymous individuals... this is not legitimate - if ( o.getURI() != null ) { + if ( onto2.getEntityURI(o) != null ) { indlist1.put( o, new Integer(nbind1) ); nbind1++; } } indmatrix = new double[nbind1+1][nbind2+1]; - } catch (OWLException e) { e.printStackTrace(); }; + } catch (AlignmentException e) { e.printStackTrace(); }; } public void compute( Parameters params ){ try { // Compute distances on classes for ( Iterator it2 = onto2.getClasses().iterator(); it2.hasNext(); ){ - OWLClass cl2 = (OWLClass)it2.next(); + Object cl2 = (Object)it2.next(); for ( Iterator it1 = onto1.getClasses().iterator(); it1.hasNext(); ){ - OWLClass cl1 = (OWLClass)it1.next(); - clmatrix[((Integer)classlist1.get(cl1)).intValue()][((Integer)classlist2.get(cl2)).intValue()] = measure( cl1, cl2 ); + Object cl1 = (Object)it1.next(); + clmatrix[((Integer)classlist1.get(cl1)).intValue()][((Integer)classlist2.get(cl2)).intValue()] = classMeasure( cl1, cl2 ); } } // Compute distances on individuals // (this comes first because otherwise, it2 is defined) for ( Iterator it2 = onto2.getIndividuals().iterator(); it2.hasNext(); ){ - OWLIndividual ind2 = (OWLIndividual)it2.next(); + Object ind2 = (Object)it2.next(); if ( indlist2.get(ind2) != null ) { for ( Iterator it1 = onto1.getIndividuals().iterator(); it1.hasNext(); ){ - OWLIndividual ind1 = (OWLIndividual)it1.next(); + Object ind1 = (Object)it1.next(); if ( indlist1.get(ind1) != null ) { - indmatrix[((Integer)indlist1.get(ind1)).intValue()][((Integer)indlist2.get(ind2)).intValue()] = measure( ind1, ind2 ); + indmatrix[((Integer)indlist1.get(ind1)).intValue()][((Integer)indlist2.get(ind2)).intValue()] = individualMeasure( ind1, ind2 ); } } } @@ -163,26 +159,26 @@ public abstract class MatrixMeasure implements Similarity { ConcatenatedIterator(onto2.getObjectProperties().iterator(), onto2.getDataProperties().iterator()); for ( ; it2.hasNext(); ){ - OWLProperty pr2 = (OWLProperty)it2.next(); + Object pr2 = (Object)it2.next(); ConcatenatedIterator it1 = new ConcatenatedIterator(onto1.getObjectProperties().iterator(), onto1.getDataProperties().iterator()); for ( ; it1.hasNext(); ){ - OWLProperty pr1 = (OWLProperty)it1.next(); - prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = measure( pr1, pr2 ); + Object pr1 = (Object)it1.next(); + prmatrix[((Integer)proplist1.get(pr1)).intValue()][((Integer)proplist2.get(pr2)).intValue()] = propertyMeasure( pr1, pr2 ); } } // What is caught is really Exceptions } catch (Exception e) { e.printStackTrace(); } } - public double getIndividualSimilarity( OWLIndividual i1, OWLIndividual i2 ){ + public double getIndividualSimilarity( Object i1, Object i2 ){ return indmatrix[((Integer)indlist1.get(i1)).intValue()][((Integer)indlist2.get(i2)).intValue()]; } - public double getClassSimilarity( OWLClass c1, OWLClass c2 ){ + public double getClassSimilarity( Object c1, Object c2 ){ return clmatrix[((Integer)classlist1.get(c1)).intValue()][((Integer)classlist2.get(c2)).intValue()]; } - public double getPropertySimilarity( OWLProperty p1, OWLProperty p2 ){ + public double getPropertySimilarity( Object p1, Object p2 ){ return prmatrix[((Integer)proplist1.get(p1)).intValue()][((Integer)proplist2.get(p2)).intValue()]; } @@ -197,20 +193,20 @@ public abstract class MatrixMeasure implements Similarity { System.out.println("}"); try { for ( Iterator it1 = onto1.getClasses().iterator(); it1.hasNext(); ){ - OWLClass cl1 = (OWLClass)it1.next(); - System.out.print(" & \\rotatebox{90}{"+cl1.getURI().getFragment()+"}"); + Object cl1 = (Object)it1.next(); + System.out.print(" & \\rotatebox{90}{"+onto1.getEntityName( cl1 )+"}"); } System.out.println(" \\\\ \\hline"); for ( Iterator it2 = onto2.getClasses().iterator(); it2.hasNext(); ){ - OWLClass cl2 = (OWLClass)it2.next(); - System.out.print(cl2.getURI().getFragment()); + Object cl2 = (Object)it2.next(); + System.out.print( onto2.getEntityName( cl2 ) ); for ( Iterator it1 = onto1.getClasses().iterator(); it1.hasNext(); ){ - OWLClass cl1 = (OWLClass)it1.next(); + Object cl1 = (Object)it1.next(); System.out.print(" & "+numFormat.format(clmatrix[((Integer)classlist1.get(cl1)).intValue()][((Integer)classlist2.get(cl2)).intValue()])); } System.out.println("\\\\"); } - } catch (OWLException e) { e.printStackTrace(); }; + } catch (AlignmentException e) { e.printStackTrace(); }; System.out.println("\n\\end{tabular}"); } diff --git a/src/fr/inrialpes/exmo/align/impl/OWLAPIAlignment.java b/src/fr/inrialpes/exmo/align/impl/OWLAPIAlignment.java index e2e2a6cb..928df006 100644 --- a/src/fr/inrialpes/exmo/align/impl/OWLAPIAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/OWLAPIAlignment.java @@ -56,9 +56,13 @@ import fr.inrialpes.exmo.align.onto.LoadedOntology; * * @author Jérôme Euzenat * @version $Id$ + * @deprecated OWLAPIAlignment has been deprecated to the profit of ObjectAlignment + * It remains here for compatibility purposes and is reimplemented in terms + * of ObjectAlignment. */ -public class OWLAPIAlignment extends BasicAlignment { +@Deprecated +public class OWLAPIAlignment extends ObjectAlignment { protected OWLAPIAlignment init = null; @@ -126,7 +130,7 @@ public class OWLAPIAlignment extends BasicAlignment { return super.addAlignCell( ob1, ob2 ); }; public Cell createCell(String id, Object ob1, Object ob2, Relation relation, double measure) throws AlignmentException { - return (Cell)new OWLAPICell( id, (OWLEntity)ob1, (OWLEntity)ob2, relation, measure); + return (Cell)new OWLAPICell( id, (OWLEntity)ob1, (OWLEntity)ob2, relation, measure); //[W:Deprecated] } public Set<Cell> getAlignCells1(Object ob) throws AlignmentException { @@ -144,7 +148,10 @@ public class OWLAPIAlignment extends BasicAlignment { } } - // Deprecated: implement as the one retrieving the highest strength correspondence ( + /** + * @deprecated implemented as the one retrieving the highest strength correspondence + */ + @Deprecated public Cell getAlignCell1(Object ob) throws AlignmentException { if ( Annotations.STRICT_IMPLEMENTATION == true ){ throw new AlignmentException("deprecated (use getAlignCells1 instead)"); @@ -157,6 +164,10 @@ public class OWLAPIAlignment extends BasicAlignment { } } + /** + * @deprecated implemented as the one retrieving the highest strength correspondence + */ + @Deprecated public Cell getAlignCell2(Object ob) throws AlignmentException { if ( Annotations.STRICT_IMPLEMENTATION == true ){ throw new AlignmentException("deprecated (use getAlignCells2 instead)"); @@ -210,17 +221,17 @@ public class OWLAPIAlignment extends BasicAlignment { align.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); } for (Enumeration e = getElements(); e.hasMoreElements();) { - Cell c = (Cell)e.nextElement(); + OWLAPICell c = (OWLAPICell)e.nextElement(); //[W:Deprecated] try { align.addAlignCell( c.getId(), c.getObject1AsURI(), c.getObject2AsURI(), c.getRelation(), c.getStrength() ); } catch (AlignmentException aex) { - // Sometimes URIs are null, this is ignore + // Sometimes URIs are null, this is ignored } }; return align; } - // Here it becomes necessary to load OWL + // Here it becomes necessary to load OWL: This is done by init(). static public OWLAPIAlignment toOWLAPIAlignment( URIAlignment al, OntologyCache ontologies ) throws AlignmentException, SAXException, OWLException { OWLAPIAlignment alignment = new OWLAPIAlignment(); alignment.init( al.getFile1(), al.getFile2(), ontologies ); @@ -246,13 +257,6 @@ public class OWLAPIAlignment extends BasicAlignment { return alignment; } - private static LoadedOntology loadOntology( URI ref, OntologyCache ontologies ) { - OntologyFactory factory = OntologyFactory.newInstance(); - LoadedOntology onto = factory.loadOntology( ref ); - if ( ontologies != null ) ontologies.recordOntology( ref, onto ); - return onto; - } - // JE: newOnto --- Onto: should be discarded private static OWLEntity getEntity( OWLOntology ontology, URI uri ) throws OWLException, SAXException { OWLEntity result = (OWLEntity)ontology.getClass( uri ); @@ -261,43 +265,5 @@ public class OWLAPIAlignment extends BasicAlignment { if ( result == null ) result = (OWLEntity)ontology.getIndividual( uri ); return result; } - - // JE: newOnto --- Onto: should be discarded - /** Can be used for loading the ontology if it is not available **/ - /* - //private static OWLOntology loadOntology( URI ref, Hashtable ontologies ) throws SAXException, OWLException { - private static OWLOntology loadOntology( URI ref, OntologyCache ontologies ) throws SAXException, OWLException { - if ( (ontologies != null) && ( ontologies.getOntology( ref ) != null ) ) { - return ontologies.getOntology( ref ); - } else { - OWLOntology parsedOnt = null; - OWLRDFParser parser = new OWLRDFParser(); - OWLRDFErrorHandler handler = new OWLRDFErrorHandler(){ - public void owlFullConstruct( int code, String message ) - throws SAXException { - } - public void owlFullConstruct(int code, String message, Object o) - throws SAXException { - } - public void error( String message ) throws SAXException { - throw new SAXException( message.toString() ); - } - public void warning( String message ) throws SAXException { - System.err.println("WARNING: " + message); - } - }; - Level lev = Logger.getLogger("org.semanticweb.owl").getLevel(); - Logger.getLogger("org.semanticweb.owl").setLevel(Level.ERROR); - parser.setOWLRDFErrorHandler( handler ); - parser.setConnection( OWLManager.getOWLConnection() ); - parsedOnt = parser.parseOntology( ref ); - if ( ontologies != null ) - ontologies.recordOntology( ref, parsedOnt ); - // ontologies.put( ref.toString(), parsedOnt ); - Logger.getLogger("org.semanticweb.owl").setLevel(lev); - return parsedOnt; - } - } - */ } diff --git a/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java b/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java index 55327d07..15997729 100644 --- a/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java +++ b/src/fr/inrialpes/exmo/align/impl/OWLAPICell.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2007-2008 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -30,7 +30,6 @@ import java.net.URI; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; -//import org.semanticweb.owl.model.OWLOntology; import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.model.OWLException; @@ -46,27 +45,23 @@ import fr.inrialpes.exmo.align.impl.rel.*; * * @author Jérôme Euzenat * @version $Id$ + * @deprecated OWLAPICell as been deprecated to the profit of ObjectCell + * It remains here for compatibility purposes and is reimplemented in terms + * of ObjectCell. */ -public class OWLAPICell extends BasicCell { +@Deprecated +public class OWLAPICell extends ObjectCell { public void accept( AlignmentVisitor visitor) throws AlignmentException { visitor.visit( this ); } - /** Creation **/ - //public OWLAPICell( Object ob1, Object ob2 ) throws AlignmentException { - // super( ob1, ob2 ); - // }; - - // public OWLAPICell( Object ob1, Object ob2, String rel, double m ) throws AlignmentException { - // super( ob1, ob2, rel, m ); - // } - public OWLAPICell( String id, OWLEntity ob1, OWLEntity ob2, Relation rel, double m ) throws AlignmentException { super( id, ob1, ob2, rel, m ); }; // the strength must be compared with regard to abstract types + // NOOWL public boolean equals( Cell c ) { if ( c instanceof OWLAPICell ){ return ( object1.equals(c.getObject1()) && object2.equals(c.getObject2()) && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); @@ -75,6 +70,7 @@ public class OWLAPICell extends BasicCell { } } + // Only OWL public URI getObject1AsURI() throws AlignmentException { try { return ((OWLEntity)object1).getURI(); @@ -82,6 +78,8 @@ public class OWLAPICell extends BasicCell { throw new AlignmentException( "Cannot convert to URI "+object1, e ); } } + + // Only OWL public URI getObject2AsURI() throws AlignmentException { try { return ((OWLEntity)object2).getURI(); @@ -89,16 +87,8 @@ public class OWLAPICell extends BasicCell { throw new AlignmentException( "Cannot convert to URI "+object2, e ); } } - //public Object getObject1(){ return object1; }; - //public Object getObject2(){ return object2; }; - // We could check that the given values are URIs - //public void setObject1( Object ob ) throws AlignmentException { - // object1 = ob; - //} - //public void setObject2( Object ob ) throws AlignmentException { - // object2 = ob; - //} + // Only OWL public Cell inverse() throws AlignmentException { return (Cell)new OWLAPICell( (String)null, (OWLEntity)object2, (OWLEntity)object1, relation.inverse(), strength ); // The same should be done for the measure diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java new file mode 100644 index 00000000..34e14585 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/ObjectAlignment.java @@ -0,0 +1,188 @@ +/* + * $Id: ObjectAlignment.java 677 2008-03-23 22:58:22Z euzenat $ + * + * Copyright (C) INRIA Rhône-Alpes, 2003-2008 + * + * 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.align.impl; + +import java.util.Hashtable; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Enumeration; +import java.util.Set; +import java.net.URI; + +import org.apache.log4j.Logger; +import org.apache.log4j.Level; + +import org.xml.sax.SAXException; + +import org.semanticweb.owl.align.Alignment; +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.Relation; +import org.semanticweb.owl.align.Parameters; + +import fr.inrialpes.exmo.align.onto.OntologyFactory; +import fr.inrialpes.exmo.align.onto.OntologyCache; +import fr.inrialpes.exmo.align.onto.Ontology; +import fr.inrialpes.exmo.align.onto.LoadedOntology; + +/** + * Represents an OWL ontology alignment. An ontology comprises a number of + * collections. Each ontology has a number of classes, properties and + * individuals, along with a number of axioms asserting information about those + * objects. + * + * @author Jérôme Euzenat + * @version $Id: ObjectAlignment.java 677 2008-03-23 22:58:22Z euzenat $ + */ + +public class ObjectAlignment extends BasicAlignment { + + protected ObjectAlignment init = null; + + public ObjectAlignment() {} + + public void init(Object onto1, Object onto2) throws AlignmentException { + init( onto1, onto2, (OntologyCache)null ); + } + + public void init(Object o1, Object o2, Object ontologies) throws AlignmentException { + OntologyCache cache = null; + if ( ontologies instanceof OntologyCache ) cache = (OntologyCache)ontologies; + else cache = (OntologyCache)null; + if ( (o1 instanceof LoadedOntology && o2 instanceof LoadedOntology) ){ + super.init( o1, o2, ontologies ); + } else if ( o1 instanceof URI && o2 instanceof URI ) { + super.init( loadOntology( (URI)o1, cache ), + loadOntology( (URI)o2, cache ) ); + } else { + throw new AlignmentException("Arguments must be LoadedOntology or URI"); + }; + } + + public LoadedOntology<Object> ontology1(){ + return (LoadedOntology<Object>)onto1; + } + + public LoadedOntology<Object> ontology2(){ + return (LoadedOntology<Object>)onto2; + } + + public void loadInit( Alignment al ) throws AlignmentException { + loadInit( al, (OntologyCache)null ); + } + + public void loadInit( Alignment al, OntologyCache ontologies ) throws AlignmentException { + if ( al instanceof URIAlignment ) { + try { init = toObjectAlignment( (URIAlignment)al, ontologies ); + } catch (SAXException e) { e.printStackTrace(); } + } else if ( al instanceof ObjectAlignment ) { + init = (ObjectAlignment)al; + } + } + + public URI getOntology1URI() { return onto1.getURI(); }; + + public URI getOntology2URI() { return onto2.getURI(); }; + + public Cell createCell(String id, Object ob1, Object ob2, Relation relation, double measure) throws AlignmentException { + return new ObjectCell( id, ob1, ob2, relation, measure); + } + + /** + * Generate a copy of this alignment object + */ + // JE: this is a mere copy of the method in BasicAlignement + // It has two difficulties + // - it should call the current init() and not that of BasicAlignement + // - it should catch the AlignmentException that it is supposed to raise + public Object clone() { + ObjectAlignment align = new ObjectAlignment(); + try { + align.init( onto1, onto2 ); + } catch ( AlignmentException e ) {}; + align.setType( getType() ); + align.setLevel( getLevel() ); + align.setFile1( getFile1() ); + align.setFile2( getFile2() ); + for ( Object ext : ((BasicParameters)extensions).getValues() ){ + align.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); + } + align.getExtensions().unsetParameter( Annotations.ALIGNNS+"id" ); + try { + align.ingest( this ); + } catch (AlignmentException ex) { ex.printStackTrace(); } + return align; + } + + /** + * This is a clone with the URI instead of Object objects + * + */ + public URIAlignment toURIAlignment() throws AlignmentException { + URIAlignment align = new URIAlignment(); + align.init( getOntology1URI(), getOntology2URI() ); + align.setType( getType() ); + align.setLevel( getLevel() ); + align.setFile1( getFile1() ); + align.setFile2( getFile2() ); + for ( Object ext : ((BasicParameters)extensions).getValues() ){ + align.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); + } + for (Enumeration e = getElements(); e.hasMoreElements();) { + Cell c = (Cell)e.nextElement(); + try { + align.addAlignCell( c.getId(), c.getObject1AsURI(), c.getObject2AsURI(), c.getRelation(), c.getStrength() ); + } catch (AlignmentException aex) { + // Sometimes URIs are null, this is ignore + } + }; + return align; + } + + static public ObjectAlignment toObjectAlignment( URIAlignment al, OntologyCache ontologies ) throws AlignmentException, SAXException { + ObjectAlignment alignment = new ObjectAlignment(); + alignment.init( al.getFile1(), al.getFile2(), ontologies ); + alignment.setType( al.getType() ); + alignment.setLevel( al.getLevel() ); + for ( Object ext : ((BasicParameters)al.getExtensions()).getValues() ){ + alignment.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); + } + LoadedOntology<Object> o1 = (LoadedOntology<Object>)alignment.getOntologyObject1(); // [W:unchecked] + LoadedOntology<Object> o2 = (LoadedOntology<Object>)alignment.getOntologyObject2(); // [W:unchecked] + for (Enumeration e = al.getElements(); e.hasMoreElements();) { + Cell c = (Cell)e.nextElement(); + alignment.addAlignCell( c.getId(), + o1.getEntity( c.getObject1AsURI() ), + o2.getEntity( c.getObject2AsURI() ), + c.getRelation(), + c.getStrength(), + c.getExtensions() ); + }; + return alignment; + } + + static LoadedOntology loadOntology( URI ref, OntologyCache ontologies ) throws AlignmentException { + OntologyFactory factory = OntologyFactory.newInstance(); + return factory.loadOntology( ref, ontologies ); + } +} + diff --git a/src/fr/inrialpes/exmo/align/impl/ObjectCell.java b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java new file mode 100644 index 00000000..400286a3 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/ObjectCell.java @@ -0,0 +1,115 @@ +/* + * $Id: BasicCell.java 670 2008-03-02 00:06:16Z euzenat $ + * + * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007-2008 + * + * 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.align.impl; + +import java.net.URI; +import java.util.Enumeration; + +import org.xml.sax.ContentHandler; + +import org.semanticweb.owl.align.AlignmentException; +import org.semanticweb.owl.align.AlignmentVisitor; +import org.semanticweb.owl.align.Cell; +import org.semanticweb.owl.align.Relation; +import org.semanticweb.owl.align.Parameters; + +/** + * Represents an ontology alignment correspondence. + * + * @author Jérôme Euzenat + * @version $Id: BasicCell.java 670 2008-03-02 00:06:16Z euzenat $ + */ + +public class ObjectCell extends BasicCell { + // JE ??: implements Comparable<ObjectCell> { + + // public void accept( AlignmentVisitor visitor) throws AlignmentException { + // visitor.visit( this ); + //} + + /** Creation **/ + public ObjectCell( String id, Object ob1, Object ob2, Relation rel, double m ) throws AlignmentException { + super( id, ob1, ob2, rel, m ); + }; + + + // the strength must be compared with regard to abstract types + public boolean equals( Cell c ) { + if ( c instanceof ObjectCell ){ + return ( object1 == c.getObject1() && object2 == c.getObject2() && strength == c.getStrength() && (relation.equals( c.getRelation() )) ); + } else { + return false; + } + } + + /** + * Used to order the cells in an alignment: + * -- this > c iff this.getStrength() < c.getStrength() -- + public int compareTo( Cell c ){ + //if ( ! (c instanceof Cell) ) return 1; + if ( c.getStrength() > getStrength() ) return 1; + if ( getStrength() > c.getStrength() ) return -1; + return 0; + } + */ + + public URI getObject1AsURI() throws AlignmentException { + if ( object1 instanceof URI ) { + return (URI)object1; + } else { + // TO BE DONE + return null; + } + } + public URI getObject2AsURI() throws AlignmentException { + if ( object2 instanceof URI ) { + return (URI)object2; + } else { + // TO BE DONE + return null; + } + } + public Cell inverse() throws AlignmentException { + Cell result = (Cell)new ObjectCell( (String)null, object2, object1, relation.inverse(), strength ); + if ( extensions != null ) { + for ( Object ext : ((BasicParameters)extensions).getValues() ){ + result.setExtension( ((String[])ext)[0], ((String[])ext)[1], ((String[])ext)[2] ); + } + } + result.getExtensions().unsetParameter( Annotations.ALIGNNS+Annotations.ID ); + // The sae should be done for the measure + return result; + } + + public Cell compose(Cell c) throws AlignmentException { + if (!object2.equals(c.getObject1()) && relation.compose(c.getRelation())==null ) + return null; + Cell result = (ObjectCell)new ObjectCell( (String)null, object1, c.getObject2(), relation.compose(c.getRelation()), strength*c.getStrength() ); + // TODO : extension... + return result; + } + + /** Housekeeping **/ + public void dump( ContentHandler h ){}; + +} + diff --git a/src/fr/inrialpes/exmo/align/impl/Similarity.java b/src/fr/inrialpes/exmo/align/impl/Similarity.java index 327cfed1..5a7316f9 100644 --- a/src/fr/inrialpes/exmo/align/impl/Similarity.java +++ b/src/fr/inrialpes/exmo/align/impl/Similarity.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2004, 2006-2007 + * Copyright (C) INRIA Rhône-Alpes, 2004, 2006-2008 * * 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 @@ -20,14 +20,11 @@ package fr.inrialpes.exmo.align.impl; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; - import org.semanticweb.owl.align.Parameters; import org.semanticweb.owl.align.Alignment; +import fr.inrialpes.exmo.align.onto.LoadedOntology; + /** * Represents the implementation of a similarity measure * @@ -42,12 +39,13 @@ public interface Similarity // It would be better if they where explicit... // Apparently the initialize also compute the similarity - public void initialize( OWLOntology onto1, OWLOntology onto2 ); - public void initialize( OWLOntology onto1, OWLOntology onto2, Alignment align ); + // JE: OntoRewr: This should not be in init + public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2 ); + public void initialize( LoadedOntology<Object> onto1, LoadedOntology<Object> onto2, Alignment align ); public void compute( Parameters p ); - public double getClassSimilarity( OWLClass c1, OWLClass c2 ); - public double getPropertySimilarity( OWLProperty p1, OWLProperty p2); - public double getIndividualSimilarity( OWLIndividual i1, OWLIndividual i2 ); + public double getClassSimilarity( Object c1, Object c2 ); + public double getPropertySimilarity( Object p1, Object p2); + public double getIndividualSimilarity( Object i1, Object i2 ); public void printClassSimilarityMatrix( String type ); public void printPropertySimilarityMatrix( String type ); @@ -59,8 +57,10 @@ public interface Similarity // the abstract matrix class provides the get- accessors and the // concrete classes implement measure as their computation function. // This is not clean. What should be done is: - public double measure( OWLClass c1, OWLClass c2 ) throws Exception; - public double measure( OWLProperty p1, OWLProperty p2) throws Exception; - public double measure( OWLIndividual i1, OWLIndividual i2 ) throws Exception; + // JE: OntoRewr: to be suppressed + public double measure( Object c1, Object c2 ) throws Exception; + public double classMeasure( Object c1, Object c2 ) throws Exception; + public double propertyMeasure( Object p1, Object p2) throws Exception; + public double individualMeasure( Object i1, Object i2 ) throws Exception; } diff --git a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java index 1e0f3595..75e5baad 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/ExtPREvaluator.java @@ -25,15 +25,10 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Parameters; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; import fr.inrialpes.exmo.align.impl.BasicEvaluator; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.onto.HeavyLoadedOntology; +import fr.inrialpes.exmo.align.onto.LoadedOntology; import java.util.Enumeration; import java.util.Iterator; @@ -54,8 +49,8 @@ import java.net.URI; public class ExtPREvaluator extends BasicEvaluator { - private OWLOntology onto1; - private OWLOntology onto2; + private HeavyLoadedOntology<Object> onto1; + private HeavyLoadedOntology<Object> onto2; private double symALPHA = .5; //private double editALPHA = .4; @@ -106,28 +101,30 @@ public class ExtPREvaluator extends BasicEvaluator { } public double eval(Parameters params, Object cache) throws AlignmentException { // Better to transform them instead... - if ( !( align1 instanceof OWLAPIAlignment ) || !( align2 instanceof OWLAPIAlignment ) ) - throw new AlignmentException( "ExtPREvaluation: requires OWLAPIAlignments" ); - onto1 = (OWLOntology)align1.getOntology1(); - onto2 = (OWLOntology)align1.getOntology2(); + if ( !( align1 instanceof ObjectAlignment ) || !( align2 instanceof ObjectAlignment ) ) + throw new AlignmentException( "ExtPREvaluation: requires ObjectAlignments" ); + LoadedOntology<Object> o1 = (LoadedOntology<Object>)((ObjectAlignment)align1).getOntologyObject1(); + LoadedOntology<Object> o2 = (LoadedOntology<Object>)((ObjectAlignment)align1).getOntologyObject2(); + if ( !( o1 instanceof HeavyLoadedOntology ) || !( o2 instanceof HeavyLoadedOntology ) ) + throw new AlignmentException( "ExtPREvaluation: requires HeavyLoadedOntology" ); + onto1 = (HeavyLoadedOntology<Object>)o1; + onto2 = (HeavyLoadedOntology<Object>)o2; nbexpected = align1.nbCells(); nbfound = align2.nbCells(); for ( Enumeration e = align1.getElements(); e.hasMoreElements();) { Cell c1 = (Cell)e.nextElement(); - Set s2 = (Set)align2.getAlignCells1((OWLEntity)c1.getObject1()); + Set s2 = (Set)align2.getAlignCells1( c1.getObject1() ); if( s2 != null ){ for( Iterator it2 = s2.iterator(); it2.hasNext() && c1 != null; ){ Cell c2 = (Cell)it2.next(); - try { - URI uri1 = ((OWLEntity)c1.getObject2()).getURI(); - URI uri2 = ((OWLEntity)c2.getObject2()).getURI(); - // if (c1.getobject2 == c2.getobject2) - if ( uri1.toString().equals(uri2.toString()) ) { - symsimilarity = symsimilarity + 1.; - c1 = null; // out of the loop. - } - } catch (OWLException exc) { exc.printStackTrace(); } + URI uri1 = onto2.getEntityURI( c1.getObject2() ); + URI uri2 = onto2.getEntityURI( c2.getObject2() ); + // if (c1.getobject2 == c2.getobject2) + if ( uri1.toString().equals(uri2.toString()) ) { + symsimilarity = symsimilarity + 1.; + c1 = null; // out of the loop. + } } // if nothing has been found // JE: Full implementation would require computing a matrix @@ -157,73 +154,87 @@ public class ExtPREvaluator extends BasicEvaluator { return (result); } + /** + * This computes similarity depending on structural measures: + * the similarity is symALPHA^minval, symALPHA being lower than 1. + * minval is the length of the subclass chain. + */ protected double computeSymSimilarity( Cell c1, Enumeration s2 ){ int minval = 0; int val = 0; - try{ + try { for( ; s2.hasMoreElements(); ){ Cell c2 = (Cell)s2.nextElement(); - if ( ((OWLEntity)c1.getObject1()).getURI().toString().equals(((OWLEntity)c2.getObject1()).getURI().toString()) ){ - val = relativePosition( (OWLEntity)c1.getObject2(), (OWLEntity)c2.getObject2(), onto2 ); + if ( onto1.getEntityURI( c1.getObject1() ).toString().equals(onto1.getEntityURI(c2.getObject1()).toString()) ){ + val = relativePosition( c1.getObject2(), c2.getObject2(), onto2 ); if ( val != 0 && val < minval ) minval = val; - } else if ( ((OWLEntity)c1.getObject2()).getURI().toString().equals(((OWLEntity)c2.getObject2()).getURI().toString()) ){ - val = relativePosition( (OWLEntity)c1.getObject1(), (OWLEntity)c2.getObject1(), onto1 ); + } else if ( onto2.getEntityURI(c1.getObject2()).toString().equals(onto2.getEntityURI(c2.getObject2()).toString()) ){ + val = relativePosition( c1.getObject1(), c2.getObject1(), onto1 ); if ( val != 0 && val < minval ) minval = val; } } - return symALPHA; //^minval; - } catch (OWLException e) { return 0; } + } catch( AlignmentException aex ) { return 0; } + //return symALPHA; //^minval; + return Math.pow( symALPHA, minval ); } - protected int relativePosition( OWLEntity o1, OWLEntity o2, OWLOntology onto ){ - try { - if ( o1 instanceof OWLClass && o2 instanceof OWLClass ){ - isSuperClass( (OWLClass)o2, (OWLClass)o1, onto ); - } else if ( o1 instanceof OWLProperty && o2 instanceof OWLProperty ){ - if ( isSuperProperty( (OWLProperty)o2, (OWLProperty)o1, onto ) ) { return -1; } - else if ( isSuperProperty( (OWLProperty)o1, (OWLProperty)o2, onto ) ) { return 1; } - else { return 0; } - } else if ( o1 instanceof OWLIndividual && o2 instanceof OWLIndividual ){ - return 0; - //if () { return -1; } - //else if () { return 1; } - //else return 0; - } - } catch (OWLException e) { e.printStackTrace(); } + 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 ) ){ + return 0; + //if () { return -1; } + //else if () { return 1; } + //else return 0; + } return 0; } - public int superClassPosition( OWLClass class1, OWLClass class2, OWLOntology onto ) throws OWLException { - int result = - isSuperClass( (OWLClass)class2, (OWLClass)class1, onto ); + public boolean isSuperProperty( Object prop1, Object prop2, HeavyLoadedOntology<Object> ontology ) throws AlignmentException { + return ontology.getSuperProperties( prop2 ).contains( prop1 ); + } + + + public int superClassPosition( Object class1, Object class2, HeavyLoadedOntology<Object> onto ) throws AlignmentException { + int result = - isSuperClass( class2, class1, onto ); if ( result == 0 ) - result = isSuperClass( (OWLClass)class1, (OWLClass)class2, onto ); + result = isSuperClass( class1, class2, onto ); return result; } - public int isSuperClass( OWLClass class1, OWLClass class2, OWLOntology ontology ) throws OWLException { - URI uri1 = class1.getURI(); - Set<OWLEntity> superclasses = new HashSet<OWLEntity>(); - // required for avoiding java.util.ConcurrentModificationException - Set<OWLEntity> bufferedSuperClasses = null; + /** + * This is a strange method which returns an integer representing how + * directly a class is superclass of another or not. + * + * This would require coputing the transitive reduction of the superClass + * relation which is currently returned bu HeavyLoadedOntology. + * + * 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.getAssertedSuperClasses( class1 ); int level = 0; - // [Warning:unchecked] due to OWL API not serving generic types - superclasses.addAll( class2.getSuperClasses( ontology )); // [W:unchecked] while ( !superclasses.isEmpty() ){ bufferedSuperClasses = superclasses; - superclasses = new HashSet<OWLEntity>(); - Iterator it = bufferedSuperClasses.iterator(); + superclasses = new HashSet<Object>(); level++; - for( ; it.hasNext() ; ){ - Object entity = it.next(); - if ( entity instanceof OWLClass ){ - URI uri2 = ((OWLClass)entity).getURI(); + 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 { - // [Warning:unchecked] due to OWL API not serving generic types - superclasses.addAll(((OWLClass)entity).getSuperClasses( ontology )); // [W:unchecked] + // [W:unchecked] due to OWL API not serving generic types + //superclasses.addAll(((OWLClass)entity).getSuperClasses( ontology )); // [W:unchecked] + superclasses.addAll( ontology.getAssertedSuperClasses( entity ) ); } } } @@ -232,20 +243,6 @@ public class ExtPREvaluator extends BasicEvaluator { return 0; } - public boolean isSuperProperty( OWLProperty prop1, OWLProperty prop2, OWLOntology ontology ) throws OWLException { - URI uri1 = prop1.getURI(); - for( Iterator it = prop2.getSuperProperties( ontology ).iterator(); it.hasNext() ; ){ - OWLEntity entity = (OWLEntity)it.next(); - //x.contains( prop2 ); - URI uri2 = entity.getURI(); - //if ( entity == prop2 ) return true; - if ( uri1.toString().equals(uri2.toString()) ) { - return true; - } - } - return false; - } - /** * This now output the results in Lockheed format. @@ -257,10 +254,8 @@ public class ExtPREvaluator extends BasicEvaluator { //if ( ) { // writer.println(" <map:algorithm rdf:resource=\"http://co4.inrialpes.fr/align/algo/"+align1.get+"\">"); //} - try { - writer.println(" <map:input1 rdf:resource=\""+((OWLOntology)(align1.getOntology1())).getURI()+"\">"); - writer.println(" <map:input2 rdf:resource=\""+((OWLOntology)(align1.getOntology2())).getURI()+"\">"); - } catch (OWLException e) { e.printStackTrace(); }; + writer.println(" <map:input1 rdf:resource=\""+((ObjectAlignment)align1).getOntologyObject1().getURI()+"\">"); + writer.println(" <map:input2 rdf:resource=\""+((ObjectAlignment)align1).getOntologyObject2().getURI()+"\">"); writer.print(" <map:symmetricprecision>"); writer.print(symprec); writer.print("</map:symmetricprecision>\n <map:symmetricrecall>"); diff --git a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java index 9dd6358a..112655f8 100644 --- a/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java +++ b/src/fr/inrialpes/exmo/align/impl/eval/SymMeanEvaluator.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2004-2005, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2004-2005, 2007-2008 * * 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 @@ -26,10 +26,8 @@ import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.BasicEvaluator; - -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.onto.LoadedOntology; import java.lang.Math; import java.util.Enumeration; @@ -52,15 +50,17 @@ import java.io.PrintWriter; * @version $Id$ */ -public class SymMeanEvaluator extends BasicEvaluator -{ +public class SymMeanEvaluator extends BasicEvaluator { private double classScore = 0.; private double propScore = 0.; private double indScore = 0.; /** Creation **/ - public SymMeanEvaluator( Alignment align1, Alignment align2 ){ + public SymMeanEvaluator( Alignment align1, Alignment align2 ) throws AlignmentException { super(align1,align2); + if ( !( align1 instanceof ObjectAlignment ) || + !( align2 instanceof ObjectAlignment ) ) + throw new AlignmentException( "Alignments should be ObjectAlignments, try to " ); } public double eval(Parameters params) throws AlignmentException { @@ -74,40 +74,32 @@ public class SymMeanEvaluator extends BasicEvaluator classScore = 0.; propScore = 0.; indScore = 0.; + LoadedOntology onto1 = (LoadedOntology)((ObjectAlignment)align1).getOntologyObject1(); + LoadedOntology onto2 = (LoadedOntology)((ObjectAlignment)align2).getOntologyObject1(); + //for ( Cell c1 : align1.getElements() ){ for (Enumeration e = align1.getElements() ; e.hasMoreElements() ;) { Cell c1 = (Cell)e.nextElement(); - if ( c1.getObject1() instanceof OWLClass ) nbClassCell++; - else if ( c1.getObject1() instanceof OWLProperty ) nbPropCell++; + if ( onto1.isClass( c1.getObject1() ) ) nbClassCell++; + else if ( onto1.isProperty( c1.getObject1() ) ) nbPropCell++; else nbIndCell++; - Set s2 = (Set)align2.getAlignCells1((OWLEntity)c1.getObject1()); + Set<Cell> s2 = (Set<Cell>)align2.getAlignCells1( c1.getObject1() ); if( s2 != null ){ - for( Iterator it2 = s2.iterator(); it2.hasNext() && c1 != null; ){ - Cell c2 = (Cell)it2.next(); - if ( c1.getObject2() == c2.getObject2() ) { - if ( c1.getObject2() instanceof OWLClass ) { - classScore = classScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); - } else if ( c1.getObject2() instanceof OWLProperty ) { - propScore = propScore + 1 - Math.abs(c2.getStrength() - c1.getStrength()); - } else { - indScore = indScore + 1 - Math.abs(c2.getStrength() - c1.getStrength());}}}}} + 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.getElements() ) { for (Enumeration e = align2.getElements() ; e.hasMoreElements() ;) { Cell c2 = (Cell)e.nextElement(); - if ( c2.getObject1() instanceof OWLClass ) nbClassCell++ ; - else if ( c2.getObject1() instanceof OWLProperty ) nbPropCell++; + if ( onto1.isClass( c2.getObject1() ) ) nbClassCell++ ; + else if ( onto1.isProperty( c2.getObject1() ) ) nbPropCell++; else nbIndCell++; - //Set s1 = (Set)align1.getAlignCells2((OWLEntity)c2.getObject1()); - //if( s1 != null ){ - // for( Iterator it1 = s1.iterator(); it1.hasNext() && c2 != null; ){ - // Cell c1 = (Cell)it1.next(); - // if ( c2.getObject1() == c1.getObject1() ) { - // if ( c2.getObject1() instanceof OWLClass ) { - // classScore = classScore + 1 - Math.abs(c1.getStrength() - c2.getStrength()); - // } else if ( c2.getObject1() instanceof OWLProperty ) { - // propScore = propScore + 1 - Math.abs(c1.getStrength() - c2.getStrength()); - // } else { - // indScore = indScore + 1 - Math.abs(c1.getStrength() - c2.getStrength());}}}} } // Beware, this must come first diff --git a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java index 065fbaf7..2081093e 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/ClassStructAlignment.java @@ -18,24 +18,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - package fr.inrialpes.exmo.align.impl.method; -import java.util.Iterator; import java.util.Vector; import java.util.Set; -import java.util.HashSet; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLNaryBooleanDescription; -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; @@ -44,6 +30,7 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.DistanceAlignment; +import fr.inrialpes.exmo.align.onto.HeavyLoadedOntology; /** This class has been built for ISWC experiments with bibliography. * It implements a non iterative (one step) OLA algorithms based on @@ -62,153 +49,93 @@ import fr.inrialpes.exmo.align.impl.DistanceAlignment; * @version $Id$ */ +public class ClassStructAlignment extends DistanceAlignment implements AlignmentProcess { + + private HeavyLoadedOntology<Object> honto1 = null; + private HeavyLoadedOntology<Object> honto2 = null; -public class ClassStructAlignment extends DistanceAlignment implements AlignmentProcess -{ /** Creation **/ public ClassStructAlignment(){}; /** Processing **/ public void align( Alignment alignment, Parameters params ) throws AlignmentException { loadInit( alignment ); - //ignore alignment; - //double threshold = 0.6; // threshold above which distances are to high + honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); + honto2 = (HeavyLoadedOntology<Object>)getOntologyObject2(); int i, j = 0; // index for onto1 and onto2 classes - //int l1, l2 = 0; // length of strings (for normalizing) int nbclass1 = 0; // number of classes in onto1 int nbclass2 = 0; // number of classes in onto2 - Vector<OWLClass> classlist2 = new Vector<OWLClass>(10); // onto2 classes - Vector<OWLClass> classlist1 = new Vector<OWLClass>(10); // onto1 classes + Vector<Object> classlist2 = new Vector<Object>(10); // onto2 classes + Vector<Object> classlist1 = new Vector<Object>(10); // onto1 classes double classmatrix[][]; // class distance matrix double pic1 = 0.5; // class weigth for name double pic2 = 0.5; // class weight for properties ingest( alignment ); - try { - // Create class lists - for ( Iterator it = ((OWLOntology)onto2).getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.add( (OWLClass)it.next() ); - } - for ( Iterator it = ((OWLOntology)onto1).getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.add( (OWLClass)it.next() ); - } - classmatrix = new double[nbclass1+1][nbclass2+1]; + + // Create class lists + for ( Object cl : honto2.getClasses() ){ + nbclass2++; + classlist2.add( cl ); + } + for ( Object cl : honto1.getClasses() ){ + nbclass1++; + classlist1.add( cl ); + } + classmatrix = new double[nbclass1+1][nbclass2+1]; - if (debug > 0) System.err.println("Initializing class distances"); - // Initialize class distances - for ( i=0; i<nbclass1; i++ ){ - OWLClass cl = (OWLClass)classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1 * StringDistances.subStringDistance( - cl.getURI().getFragment().toLowerCase(), - ((OWLClass)classlist2.get(j)).getURI().getFragment().toLowerCase()); - } + if (debug > 0) System.err.println("Initializing class distances"); + + // 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()); } + } - 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<OWLProperty> properties1 = getProperties( classlist1.get(i), ((OWLOntology)onto1) ); - int nba1 = properties1.size(); - if ( nba1 > 0 ) { // if not, keep old values... - //Set correspondences = new HashSet(); - for ( j=0; j<nbclass2; j++ ){ - Set<OWLProperty> properties2 = getProperties( classlist2.get(j), ((OWLOntology)onto2) ); - int nba2 = properties1.size(); - double attsum = 0.; - // check that there is a correspondance - // in list of class2 atts and add their weights - for ( OWLProperty prp : properties1 ){ - Set<Cell> s2 = (Set<Cell>)getAlignCells1( prp ); - // Find the property with the higest similarity - // that is matched here - double currentValue = 0.; - for( Iterator<Cell> it2 = s2.iterator(); it2.hasNext(); ){ - Cell c2 = it2.next(); - if ( properties2.contains((Object)c2.getObject2() ) ) { - double val = c2.getStrength(); - if ( val > currentValue ) - currentValue = val; - } + 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) ); + 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) ); + int nba2 = properties1.size(); + double attsum = 0.; + // check that there is a correspondance + // in list of class2 atts and add their weights + for ( Object prp : properties1 ){ + Set<Cell> s2 = (Set<Cell>)getAlignCells1( prp ); + // Find the property with the higest similarity + // that is matched here + double currentValue = 0.; + for( Cell c2 : s2 ){ + if ( properties2.contains( c2.getObject2() ) ) { + double val = c2.getStrength(); + if ( val > currentValue ) + currentValue = val; } - attsum = attsum + 1 - currentValue; } - classmatrix[i][j] = classmatrix[i][j] - + pic2 * (2 * attsum / (nba1 + nba2)); + attsum = attsum + 1 - currentValue; } + classmatrix[i][j] = classmatrix[i][j] + + pic2 * (2 * attsum / (nba1 + nba2)); } - // Assess factor - // -- FirstExp: nothing to be done: one pass } - //selectBestMatch( nbclass1, classlist1, nbclass2, classlist2, classmatrix, threshold, null); - } catch (OWLException e) { - throw new AlignmentException( "OWLException during alignment", e ); } } - public void getProperties( OWLDescription desc, OWLOntology o, Set<OWLProperty> list){ - // I am Jerome Euzenat and I am sure that there is some problem here... - // DISPATCHING MANUALLY ! - try { - Method mm = null; - if ( Class.forName("org.semanticweb.owl.model.OWLRestriction").isInstance(desc) ){ - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLRestriction"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLClass").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLClass"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } - if ( mm != null ) mm.invoke(this,new Object[] {desc,o,list}); - //Method mmm[] = this.getClass().getMethods(); - //for ( int i = 0; i < mmm.length ; i++ ){ - // if ( mmm[i].getName().equals("getProperties") ){ - // mmm[i].invoke(this,new Object[] {desc,o,list}); - // i = mmm.length; - // } - // } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - public void getProperties( OWLRestriction rest, OWLOntology o, Set<OWLProperty> list) throws OWLException { - list.add( rest.getProperty() ); - } - public void getProperties( OWLNaryBooleanDescription d, OWLOntology o, Set<OWLProperty> list) throws OWLException { - for ( Iterator it = d.getOperands().iterator(); it.hasNext() ;){ - getProperties( (OWLDescription)it.next(), o, list ); - } - } - public void getProperties( OWLClass cl, OWLOntology o, Set<OWLProperty> list) throws OWLException { - for ( Iterator it = cl.getSuperClasses(o).iterator(); it.hasNext(); ){ - OWLDescription dsc = (OWLDescription)it.next(); - getProperties( dsc, o, list ); - } - // JE: I suspect that this can be a cause for looping!! - for ( Iterator it = cl.getEquivalentClasses(o).iterator(); it.hasNext(); ){ - getProperties( (OWLDescription)it.next(), o, list ); - } - } - - private Set<OWLProperty> getProperties( OWLClass cl, OWLOntology o ) throws OWLException { - Set<OWLProperty> resultSet = new HashSet<OWLProperty>(); - getProperties( cl, o, resultSet ); - return resultSet; - } - } diff --git a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java index 5ec11055..a4229b0a 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/EditDistNameAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007-2008 * * 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 @@ -20,14 +20,6 @@ package fr.inrialpes.exmo.align.impl.method; -import java.util.Iterator; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.AlignmentProcess; import fr.inrialpes.exmo.align.impl.DistanceAlignment; @@ -42,34 +34,26 @@ import fr.inrialpes.exmo.align.impl.MatrixMeasure; * @version $Id$ */ -public class EditDistNameAlignment extends DistanceAlignment implements AlignmentProcess -{ +public class EditDistNameAlignment extends DistanceAlignment implements AlignmentProcess { /** Creation **/ public EditDistNameAlignment(){ setSimilarity( new MatrixMeasure() { - public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ - String s1 = cl1.getURI().getFragment(); - String s2 = cl2.getURI().getFragment(); + public double measure( Object o1, Object o2 ) throws Exception { + String s1 = ontology1().getEntityName( o1 ); + String s2 = ontology2().getEntityName( o2 ); if ( s1 == null || s2 == null ) return 1.; else return StringDistances.levenshteinDistance( s1.toLowerCase(), s2.toLowerCase()) / max(s1.length(),s2.length()); } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ - String s1 = pr1.getURI().getFragment(); - String s2 = pr2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - else return StringDistances.levenshteinDistance( - s1.toLowerCase(), - s2.toLowerCase()) / max(s1.length(),s2.length()); + public double classMeasure( Object cl1, Object cl2 ) throws Exception { + return measure( cl1, cl2 ); } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ - String s1 = id1.getURI().getFragment(); - String s2 = id2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - else return StringDistances.levenshteinDistance( - s1.toLowerCase(), - s2.toLowerCase()) / max(s1.length(),s2.length()); + public double propertyMeasure( Object pr1, Object pr2 ) throws Exception { + return measure( pr1, pr2 ); + } + public double individualMeasure( Object id1, Object id2 ) throws Exception { + return measure( id1, id2 ); } } ); }; diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java index e05fdff3..a53f0d18 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameAndPropertyAlignment.java @@ -22,20 +22,8 @@ package fr.inrialpes.exmo.align.impl.method; import java.lang.Integer; -import java.util.Iterator; import java.util.Vector; import java.util.Set; -import java.util.HashSet; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLNaryBooleanDescription; -import org.semanticweb.owl.model.OWLException; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; @@ -43,7 +31,7 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.DistanceAlignment; - +import fr.inrialpes.exmo.align.onto.HeavyLoadedOntology; /** This class has been built for ISWC experiments with bibliography. * It implements a non iterative (one step) OLA algorithms based on @@ -62,89 +50,95 @@ import fr.inrialpes.exmo.align.impl.DistanceAlignment; * @version $Id$ */ +public class NameAndPropertyAlignment extends DistanceAlignment implements AlignmentProcess { + + private HeavyLoadedOntology<Object> honto1 = null; + private HeavyLoadedOntology<Object> honto2 = null; -public class NameAndPropertyAlignment extends DistanceAlignment implements AlignmentProcess -{ /** Creation **/ public NameAndPropertyAlignment(){ setType("**"); }; - /** Processing **/ public void align( Alignment alignment, Parameters params ) throws AlignmentException { loadInit( alignment ); - //ignore alignment; + honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); + honto2 = (HeavyLoadedOntology<Object>)getOntologyObject2(); double threshold = 1.; // threshold above which distances are too high int i, j = 0; // index for onto1 and onto2 classes - //int l1, l2 = 0; // length of strings (for normalizing) int nbclass1 = 0; // number of classes in onto1 int nbclass2 = 0; // number of classes in onto2 - Vector<OWLClass> classlist2 = new Vector<OWLClass>(10); // onto2 classes - Vector<OWLClass> classlist1 = new Vector<OWLClass>(10); // onto1 classes + Vector<Object> classlist2 = new Vector<Object>(10); // onto2 classes + Vector<Object> classlist1 = new Vector<Object>(10); // onto1 classes double classmatrix[][]; // class distance matrix int nbprop1 = 0; // number of properties in onto1 int nbprop2 = 0; // number of properties in onto2 - Vector<OWLProperty> proplist2 = new Vector<OWLProperty>(10); // onto2 properties - Vector<OWLProperty> proplist1 = new Vector<OWLProperty>(10); // onto1 properties + Vector<Object> proplist2 = new Vector<Object>(10); // onto2 properties + Vector<Object> proplist1 = new Vector<Object>(10); // onto1 properties double propmatrix[][]; // properties distance matrix double pic1 = 0.5; // class weigth for name - //double pic2 = 0.5; // class weight for properties double pia1 = 1.; // relation weight for name - //double pia2 = 0.; // relation weight for domain - //double pia3 = 0.; // relation weight for range double epsillon = 0.05; // stoping condition if ( params.getParameter("debug") != null ) debug = ((Integer)params.getParameter("debug")).intValue(); - try { // Create property lists and matrix - for ( Iterator it = ((OWLOntology)getOntology1()).getObjectProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( (OWLProperty)it.next() ); + for ( Object prop : honto1.getObjectProperties() ){ + nbprop1++; + proplist1.add( prop ); } - for ( Iterator it = ((OWLOntology)getOntology1()).getDataProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( (OWLProperty)it.next() ); + for ( Object prop : honto1.getDataProperties() ){ + nbprop1++; + proplist1.add( prop ); } - for ( Iterator it = ((OWLOntology)getOntology2()).getObjectProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( (OWLProperty)it.next() ); + for ( Object prop : honto2.getObjectProperties() ){ + nbprop2++; + proplist2.add( prop ); } - for ( Iterator it = ((OWLOntology)getOntology2()).getDataProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( (OWLProperty)it.next() ); + for ( Object prop : honto2.getDataProperties() ){ + nbprop2++; + proplist2.add( prop ); } propmatrix = new double[nbprop1+1][nbprop2+1]; // Create class lists - for ( Iterator it = ((OWLOntology)getOntology2()).getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.add( (OWLClass)it.next() ); + for ( Object cl : honto1.getClasses() ){ + nbclass1++; + classlist1.add( cl ); } - for ( Iterator it = ((OWLOntology)getOntology1()).getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.add( (OWLClass)it.next() ); + 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++ ){ - OWLProperty cl = (OWLProperty)proplist1.get(i); - String st1=new String(); - String st2=new String(); - if (cl.getURI().getFragment()!=null){ st1 = cl.getURI().getFragment().toLowerCase();} + Object cl1 = proplist1.get(i); + String st1 = honto1.getEntityName( cl1 ); + if ( st1 != null) st1 = st1.toLowerCase(); for ( j=0; j<nbprop2; j++ ){ - cl = (OWLProperty)proplist2.get(j); - if(cl.getURI().getFragment()!=null){st2 = cl.getURI().getFragment().toLowerCase() ;} - propmatrix[i][j] = pia1 * StringDistances.subStringDistance( st1, st2 ); - + 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++ ){ - OWLClass cl = (OWLClass)classlist1.get(i); + Object cl1 = classlist1.get(i); for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1*StringDistances.subStringDistance( - cl.getURI().getFragment().toLowerCase(), - ((OWLClass)classlist2.get(j)).getURI().getFragment().toLowerCase()); + classmatrix[i][j] = pic1*StringDistances.subStringDistance( honto1.getEntityName( cl1 ).toLowerCase(), honto2.getEntityName( classlist2.get(j) ).toLowerCase()); } } @@ -168,7 +162,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align max = propmatrix[i][j]; } } - if ( found && max < 0.5) { addAlignDistanceCell( (OWLProperty)proplist1.get(i), (OWLProperty)proplist2.get(best), "=", max ); } + 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 @@ -181,13 +175,13 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align // / nbatts of c[i] + nbatts of c[j] for ( i=0; i<nbclass1; i++ ){ - Set properties1 = getProperties( (OWLClass)classlist1.get(i), ((OWLOntology)getOntology1()) ); + Set<Object> properties1 = honto1.getProperties( classlist1.get(i) ); int nba1 = properties1.size(); if ( nba1 > 0 ) { // if not, keep old values... //Set correspondences = new HashSet(); for ( j=0; j<nbclass2; j++ ){ - Set properties2 = getProperties( (OWLClass)classlist2.get(j), ((OWLOntology)getOntology2()) ); + Set<Object> properties2 = honto2.getProperties( classlist2.get(j) ); //int nba2 = properties1.size(); //double attsum = 0.; // check that there is a correspondance @@ -196,7 +190,7 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align // Make a local alignment with the properties. double moy_align_loc = alignLocal(properties1,properties2); - if (moy_align_loc>0.7){ + if (moy_align_loc > 0.7){ classmatrix[i][j] = (classmatrix[i][j] + 2* moy_align_loc)/3; } } @@ -207,9 +201,6 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align // -- FirstExp: nothing to be done: one pass factor = 0.; } - } catch (OWLException e) { - throw new AlignmentException( "OWLException during alignment", e ); - } // This mechanism should be parametric! // Select the best match // There can be many algorithm for these: @@ -230,95 +221,51 @@ public class NameAndPropertyAlignment extends DistanceAlignment implements Align max = classmatrix[i][j]; } } - if ( found && max < 0.5) { addAlignDistanceCell( (OWLClass)classlist1.get(i), (OWLClass)classlist2.get(best), "=", max ); } + if ( found && max < 0.5) { addAlignDistanceCell( classlist1.get(i), classlist2.get(best), "=", max ); } } } - public void getProperties( OWLDescription desc, OWLOntology o, Set<OWLProperty> list){ - // I am Jerome Euzenat and I am sure that there is some problem here... - // DISPATCHING MANUALLY ! - try { - Method mm = null; - if ( Class.forName("org.semanticweb.owl.model.OWLRestriction").isInstance(desc) ){ - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLRestriction"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLClass").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLClass"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set")}); - } - if ( mm != null ) mm.invoke(this,new Object[] {desc,o,list}); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - public void getProperties( OWLRestriction rest, OWLOntology o, Set<OWLProperty> list) throws OWLException { - list.add( rest.getProperty() ); - } - public void getProperties( OWLNaryBooleanDescription d, OWLOntology o, Set<OWLProperty> list) throws OWLException { - for ( Iterator it = d.getOperands().iterator(); it.hasNext() ;){ - getProperties( (OWLDescription)it.next(), o, list ); - } - } - public void getProperties( OWLClass cl, OWLOntology o, Set<OWLProperty> list) throws OWLException { - for ( Iterator it = cl.getSuperClasses(o).iterator(); it.hasNext(); ){ - OWLDescription dsc = (OWLDescription)it.next(); - getProperties( dsc, o, list ); - } - // JE: I suspect that this can be a cause for looping!! - for ( Iterator it = cl.getEquivalentClasses(o).iterator(); it.hasNext(); ){ - getProperties( (OWLDescription)it.next(), o, list ); - } - } - - private Set<OWLProperty> getProperties( OWLClass cl, OWLOntology o ) throws OWLException { - Set<OWLProperty> resultSet = new HashSet<OWLProperty>(); - getProperties( cl, o, resultSet ); - return resultSet; - } - - private double alignLocal( Set prop1, Set prop2) throws OWLException { - // make a local alignement - // return an average of all the property alignement - - double propmatrix[] []; - int nbprop1=prop1.size(); - int nbprop2=prop2.size(); - //int best=0; - double max =0.0; - double moy=0.0; - int i=0; - int j=0; - propmatrix = new double[nbprop1+1][nbprop2+1]; + /** + * Make a local alignement + * @return an average of all the property alignement + */ + private double alignLocal( Set<Object> prop1, Set<Object> prop2) { + int nbprop1 = prop1.size(); + int nbprop2 = prop2.size(); + double max = 0.0; + double moy= 0.0; + int i = 0; + int j = 0; + String s1 = null; + String s2 = null; + double[][] propmatrix = new double[nbprop1+1][nbprop2+1]; - for ( Iterator prp1 = prop1.iterator(); prp1.hasNext();i++ ){ - OWLProperty property1 = (OWLProperty)prp1.next(); - String s1 = property1.getURI().getFragment().toLowerCase(); - for ( Iterator prp2 = prop2.iterator(); prp2.hasNext();j++ ){ - OWLProperty property2 = (OWLProperty)prp2.next(); - String s2 = property2.getURI().getFragment().toLowerCase(); - propmatrix[i][j] = StringDistances.subStringDistance( s1, s2 ); + for ( Object property1 : prop1 ){ + i++; + try { + s1 = honto1.getEntityName( property1 ).toLowerCase(); + } catch (AlignmentException 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) { + propmatrix[i][j] = 0.0; + } } j=0; } - for (i=0; i< nbprop1; i++){ - for(j=0;j<nbprop2;j++){ - if (1.0-propmatrix[i][j]>max){ - max=1.0-propmatrix[i][j]; + for ( i=0; i< nbprop1; i++ ) { + for ( j=0; j<nbprop2; j++ ) { + if ( propmatrix[i][j] > max ) { + max = propmatrix[i][j]; } } - moy=moy+max; - max=0.0; + moy = moy+max; + max = 0.0; } return moy; } diff --git a/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java index 49dbea91..3c24c7f7 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/NameEqAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,59 +20,19 @@ package fr.inrialpes.exmo.align.impl.method; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - -import org.semanticweb.owl.align.Alignment; -import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.AlignmentException; -import org.semanticweb.owl.align.Parameters; - -import fr.inrialpes.exmo.align.impl.DistanceAlignment; -import fr.inrialpes.exmo.align.impl.MatrixMeasure; - /** * Matches two oontologies based on the equality of the name of their entities. + * THIS CLASS IS ONLY HERE FOR COMPATIBILITY PURPOSES * * @author Jérôme Euzenat * @version $Id$ */ -public class NameEqAlignment extends DistanceAlignment implements AlignmentProcess { +public class NameEqAlignment extends StringDistAlignment { /** Creation **/ public NameEqAlignment(){ - setSimilarity( new MatrixMeasure() { - public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ - String s1 = cl1.getURI().getFragment(); - String s2 = cl2.getURI().getFragment(); - if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; - else return 1.; - } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ - String s1 = pr1.getURI().getFragment(); - String s2 = pr2.getURI().getFragment(); - if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; - else return 1.; - } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ - String s1 = id1.getURI().getFragment(); - String s2 = id2.getURI().getFragment(); - if ( s1 != null && s2 != null && s1.toLowerCase().equals(s2.toLowerCase()) ) return 0.; - else return 1.; - } - } ); - setType("**"); + methodName = "equalDistance"; }; - /** Processing **/ - public void align( Alignment alignment, Parameters params ) throws AlignmentException { - loadInit( alignment ); - getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); - getSimilarity().compute( params ); - extract( type, params ); - } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/SMOANameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/SMOANameAlignment.java index da41a525..0ce23cb6 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/SMOANameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/SMOANameAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2008 * * 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 @@ -20,55 +20,20 @@ package fr.inrialpes.exmo.align.impl.method; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - -import fr.inrialpes.exmo.align.impl.DistanceAlignment; -import fr.inrialpes.exmo.align.impl.MatrixMeasure; - -import org.semanticweb.owl.align.AlignmentProcess; - /** * This class aligns ontology with regard to the editing distance between * class names. + * THIS CLASS IS ONLY HERE FOR COMPATIBILITY PURPOSES * * @author Jérôme Euzenat * @version $Id$ */ -public class SMOANameAlignment extends DistanceAlignment implements AlignmentProcess -{ +public class SMOANameAlignment extends StringDistAlignment { + /** Creation **/ public SMOANameAlignment(){ - setSimilarity( new MatrixMeasure() { - public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ - String s1 = cl1.getURI().getFragment(); - String s2 = cl2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - else return StringDistances.smoaDistance( - s1.toLowerCase(), - s2.toLowerCase()); - } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ - String s1 = pr1.getURI().getFragment(); - String s2 = pr2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - else return StringDistances.smoaDistance( - s1.toLowerCase(), - s2.toLowerCase()); - } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ - String s1 = id1.getURI().getFragment(); - String s2 = id2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - else return StringDistances.smoaDistance( - s1.toLowerCase(), - s2.toLowerCase()); - } - } ); + methodName = "smoaDistance"; }; } diff --git a/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java index 0c293071..89c536f0 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StringDistAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,12 +23,6 @@ package fr.inrialpes.exmo.align.impl.method; import java.net.URI; import java.lang.reflect.Method; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; import org.semanticweb.owl.align.AlignmentException; @@ -54,35 +48,29 @@ import fr.inrialpes.exmo.align.impl.BasicParameters; public class StringDistAlignment extends DistanceAlignment implements AlignmentProcess { Method dissimilarity = null; + String methodName = "equalDistance"; /** Creation **/ public StringDistAlignment() { setSimilarity( new MatrixMeasure() { - public double measure( OWLClass cl1, OWLClass cl2 ) throws Exception{ - Object[] params = { cl1.getURI().getFragment(), cl2.getURI().getFragment() }; - if ( debug > 4 ) - System.err.println( "CL:"+cl1.getURI().getFragment()+" ++ "+cl2.getURI().getFragment()); - return ((Double)dissimilarity.invoke( null, params )).doubleValue(); + public double classMeasure( Object cl1, Object cl2 ) throws Exception { + return measure( cl1, cl2 ); } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws Exception{ - Object[] params = { pr1.getURI().getFragment(), pr2.getURI().getFragment() }; + public double measure( Object o1, Object o2 ) throws Exception { + String s1 = ontology1().getEntityName( o1 ); + String s2 = ontology2().getEntityName( o2 ); + // Unnamed entity = max distance + if ( s1 == null || s2 == null ) return 1.; + Object[] params = { s1.toLowerCase(), s2.toLowerCase() }; if ( debug > 4 ) - System.err.println( "PR:"+pr1.getURI().getFragment()+" ++ "+pr2.getURI().getFragment()); + System.err.println( "OB:"+ontology1().getEntityName( o1 )+" ++ "+ontology2().getEntityName( o2 )+" ==> "+dissimilarity.invoke( null, params )); return ((Double)dissimilarity.invoke( null, params )).doubleValue(); } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws Exception{ - if ( debug > 4 ) - System.err.println( "ID:"+id1+" -- "+id2); - URI URI1 = id1.getURI(); - String name1; - if ( URI1 != null ) name1 = URI1.getFragment(); - else name1 = ""; - URI URI2 = id2.getURI(); - String name2; - if ( URI2 != null ) name2 = URI2.getFragment(); - else name2 = ""; - Object[] params = { name1, name2 }; - return ((Double)dissimilarity.invoke( null, params )).doubleValue(); + public double propertyMeasure( Object pr1, Object pr2 ) throws Exception{ + return measure( pr1, pr2 ); + } + public double individualMeasure( Object id1, Object id2 ) throws Exception{ + return measure( id1, id2 ); } } ); setType("**"); @@ -95,11 +83,10 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP // Get function from params String f = (String)params.getParameter("stringFunction"); try { - String fname = "equalDistance"; - if ( f != null ) fname = f.trim(); + if ( f != null ) methodName = f.trim(); Class sClass = Class.forName("java.lang.String"); Class[] mParams = { sClass, sClass }; - dissimilarity = Class.forName("fr.inrialpes.exmo.align.impl.method.StringDistances").getMethod( fname, mParams ); + dissimilarity = Class.forName("fr.inrialpes.exmo.align.impl.method.StringDistances").getMethod( methodName, mParams ); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { @@ -107,7 +94,7 @@ public class StringDistAlignment extends DistanceAlignment implements AlignmentP } // Initialize matrix - getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); + getSimilarity().initialize( ontology1(), ontology2(), alignment ); // Compute similarity/dissimilarity getSimilarity().compute( params ); diff --git a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java index 04a1d5c0..a9083218 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/StrucSubsDistAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007-2008 * * 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 @@ -21,22 +21,9 @@ package fr.inrialpes.exmo.align.impl.method; -import java.util.Iterator; import java.util.Vector; import java.util.Set; -import java.util.HashSet; import java.lang.Integer; -import java.lang.reflect.Method; -import java.lang.reflect.InvocationTargetException; - -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLRestriction; -import org.semanticweb.owl.model.OWLDescription; -import org.semanticweb.owl.model.OWLNaryBooleanDescription; -import org.semanticweb.owl.model.OWLException; -import org.semanticweb.owl.model.OWLEntity; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentProcess; @@ -45,6 +32,7 @@ import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Parameters; import fr.inrialpes.exmo.align.impl.DistanceAlignment; +import fr.inrialpes.exmo.align.onto.HeavyLoadedOntology; /** This class has been built for ISWC experiments with bibliography. * It implements a non iterative (one step) OLA algorithms based on @@ -63,9 +51,11 @@ import fr.inrialpes.exmo.align.impl.DistanceAlignment; * @version $Id$ */ +public class StrucSubsDistAlignment extends DistanceAlignment implements AlignmentProcess { + + private HeavyLoadedOntology<Object> honto1 = null; + private HeavyLoadedOntology<Object> honto2 = null; -public class StrucSubsDistAlignment extends DistanceAlignment implements AlignmentProcess -{ /** Creation **/ public StrucSubsDistAlignment() { setType("**"); @@ -74,235 +64,174 @@ public class StrucSubsDistAlignment extends DistanceAlignment implements Alignme /** Processing **/ public void align( Alignment alignment, Parameters params ) throws AlignmentException { loadInit( alignment ); - //ignore alignment; + honto1 = (HeavyLoadedOntology<Object>)getOntologyObject1(); + honto2 = (HeavyLoadedOntology<Object>)getOntologyObject2(); double threshold = 1.; // threshold above which distances are too high int i, j = 0; // index for onto1 and onto2 classes - //int l1, l2 = 0; // length of strings (for normalizing) int nbclass1 = 0; // number of classes in onto1 int nbclass2 = 0; // number of classes in onto2 - Vector<OWLClass> classlist2 = new Vector<OWLClass>(10); // onto2 classes - Vector<OWLClass> classlist1 = new Vector<OWLClass>(10); // onto1 classes + Vector<Object> classlist2 = new Vector<Object>(10); // onto2 classes + Vector<Object> classlist1 = new Vector<Object>(10); // onto1 classes double classmatrix[][]; // class distance matrix int nbprop1 = 0; // number of properties in onto1 int nbprop2 = 0; // number of properties in onto2 - Vector<OWLProperty> proplist2 = new Vector<OWLProperty>(10); // onto2 properties - Vector<OWLProperty> proplist1 = new Vector<OWLProperty>(10); // onto1 properties + Vector<Object> proplist2 = new Vector<Object>(10); // onto2 properties + Vector<Object> proplist1 = new Vector<Object>(10); // onto1 properties double propmatrix[][]; // properties distance matrix double pic1 = 0.5; // class weigth for name double pic2 = 0.5; // class weight for properties double pia1 = 1.; // relation weight for name - //double pia2 = 0.; // relation weight for domain - //double pia3 = 0.; // relation weight for range double epsillon = 0.05; // stoping condition if ( params.getParameter("debug") != null ) debug = ((Integer)params.getParameter("debug")).intValue(); - try { - // Create property lists and matrix - for ( Iterator it = ((OWLOntology)onto1).getObjectProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( (OWLProperty)it.next() ); - } - for ( Iterator it = ((OWLOntology)onto1).getDataProperties().iterator(); it.hasNext(); nbprop1++ ){ - proplist1.add( (OWLProperty)it.next() ); - } - for ( Iterator it = ((OWLOntology)onto2).getObjectProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( (OWLProperty)it.next() ); - } - for ( Iterator it = ((OWLOntology)onto2).getDataProperties().iterator(); it.hasNext(); nbprop2++ ){ - proplist2.add( (OWLProperty)it.next() ); - } - propmatrix = new double[nbprop1+1][nbprop2+1]; + // 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]; - // Create class lists - for ( Iterator it = ((OWLOntology)onto1).getClasses().iterator(); it.hasNext(); nbclass1++ ){ - classlist1.add( (OWLClass)it.next() ); + 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; + } } - for ( Iterator it = ((OWLOntology)onto2).getClasses().iterator(); it.hasNext(); nbclass2++ ){ - classlist2.add( (OWLClass)it.next() ); + } + + 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()); } - classmatrix = new double[nbclass1+1][nbclass2+1]; + } - if (debug > 0) System.err.println("Initializing property distances"); + // 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++ ){ - OWLProperty cl = proplist1.get(i); - String s1 = cl.getURI().getFragment(); - if ( s1 != null ) s1 = s1.toLowerCase(); + boolean found = false; + int best = 0; + double max = threshold; for ( j=0; j<nbprop2; j++ ){ - cl = proplist2.get(j); - String s2 = cl.getURI().getFragment(); - if ( s2 != null ) s2 = s2.toLowerCase(); - if ( s1 == null || s2 == null ) { propmatrix[i][j] = pia1; } - else { - propmatrix[i][j] = pia1 * StringDistances.subStringDistance( s1, s2 ); + if ( propmatrix[i][j] < max) { + found = true; + best = j; + max = propmatrix[i][j]; } } + if ( found ) { addAlignDistanceCell( proplist1.get(i), proplist2.get(best), "=", max ); } } - - if (debug > 0) System.err.println("Initializing class distances"); - // Initialize class distances + + 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++ ){ - OWLClass cl = classlist1.get(i); - for ( j=0; j<nbclass2; j++ ){ - classmatrix[i][j] = pic1 * StringDistances.subStringDistance( - cl.getURI().getFragment().toLowerCase(), - classlist2.get(j).getURI().getFragment().toLowerCase()); - } - } - - // 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 ) { 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 properties1 = getProperties( classlist1.get(i), ((OWLOntology)onto1) ); - int nba1 = properties1.size(); - if ( nba1 > 0 ) { // if not, keep old values... - //Set correspondences = new HashSet(); - for ( j=0; j<nbclass2; j++ ){ - Set properties2 = getProperties( classlist2.get(j), ((OWLOntology)onto2) ); - int nba2 = properties2.size(); - double attsum = 0.; - // check that there is a correspondance - // in list of class2 atts and add their weights - for ( Iterator prp = properties1.iterator(); prp.hasNext(); ){ - Set s2 = getAlignCells1( (OWLEntity)prp.next() ); - // Find the property with the higest similarity - // that is matched here - double currentValue = 0.; - for( Iterator it2 = s2.iterator(); it2.hasNext(); ){ - Cell c2 = (Cell)it2.next(); - if ( properties2.contains((Object)c2.getObject2() ) ) { - double val = c2.getStrength(); - if ( val > currentValue ) - currentValue = val; - } + Set<Object> properties1 = honto1.getProperties( classlist1.get(i) ); + 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) ); + int nba2 = properties2.size(); + double attsum = 0.; + // check that there is a correspondance + // in list of class2 atts and add their weights + for ( Object prp : properties1 ){ + Set<Cell> s2 = getAlignCells1( prp ); + // Find the property with the higest similarity + // that is matched here + double currentValue = 0.; + for( Cell c2 : s2 ){ + if ( properties2.contains( c2.getObject2() ) ) { + double val = c2.getStrength(); + if ( val > currentValue ) + currentValue = val; } - attsum = attsum + 1 - currentValue; } - classmatrix[i][j] = classmatrix[i][j] - + pic2 * (2 * attsum / (nba1 + nba2)); + attsum = attsum + 1 - currentValue; } + classmatrix[i][j] = classmatrix[i][j] + + pic2 * (2 * attsum / (nba1 + nba2)); } } - // 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: - // n:m: get all of those above a threshold - // 1:1: get the best discard lines and columns and iterate - // Here we basically implement ?:* because the algorithm - // picks up the best matching object above threshold for i. - if (debug > 0) System.err.print("Storing class alignment\n"); + // This mechanism should be parametric! + // Select the best match + // There can be many algorithm for these: + // n:m: get all of those above a threshold + // 1:1: get the best discard lines and columns and iterate + // Here we basically implement ?:* because the algorithm + // picks up the best matching object above threshold for i. + if (debug > 0) System.err.print("Storing class alignment\n"); - for ( i=0; i<nbclass1; i++ ){ - boolean found = false; - int best = 0; - double max = threshold; - for ( j=0; j<nbclass2; j++ ){ - if ( classmatrix[i][j] < max) { - found = true; - best = j; - max = classmatrix[i][j]; - } + for ( i=0; i<nbclass1; i++ ){ + boolean found = false; + int best = 0; + double max = threshold; + for ( j=0; j<nbclass2; j++ ){ + if ( classmatrix[i][j] < max) { + found = true; + best = j; + max = classmatrix[i][j]; } - if ( found ) { addAlignDistanceCell( classlist1.get(i), classlist2.get(best), "=", max ); } } - } catch (OWLException e) { - throw new AlignmentException( "OWLException during alignment", e ); + if ( found ) { addAlignDistanceCell( classlist1.get(i), classlist2.get(best), "=", max ); } } } - - public void getProperties( OWLDescription desc, OWLOntology o, Set<OWLProperty> list, Set<Object> accu){ - // I am Jerome Euzenat and I am sure that there is some problem here... - // DISPATCHING MANUALLY ! - try { - Method mm = null; - if ( Class.forName("org.semanticweb.owl.model.OWLRestriction").isInstance(desc) ){ - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLRestriction"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLClass").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLClass"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set"),Class.forName("java.util.Set")}); - } else if (Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription").isInstance(desc) ) { - mm = this.getClass().getMethod("getProperties", - new Class [] {Class.forName("org.semanticweb.owl.model.OWLNaryBooleanDescription"),Class.forName("org.semanticweb.owl.model.OWLOntology"),Class.forName("java.util.Set"),Class.forName("java.util.Set")}); - } - if ( mm != null ) mm.invoke(this,new Object[] {desc,o,list,accu}); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - public void getProperties( OWLRestriction rest, OWLOntology o, Set<OWLProperty> list, Set<Object> accu) throws OWLException { - if ( !accu.contains( (Object)rest ) ) { - accu.add((Object)rest); - list.add( rest.getProperty() ); - } - } - public void getProperties( OWLNaryBooleanDescription d, OWLOntology o, Set<OWLProperty> list, Set<Object> accu) throws OWLException { - if ( !accu.contains( (Object)d ) ) { - accu.add((Object)d); - for ( Iterator it = d.getOperands().iterator(); it.hasNext() ;){ - getProperties( (OWLDescription)it.next(), o, list, accu ); - } - } - } - public void getProperties( OWLClass cl, OWLOntology o, Set<OWLProperty> list, Set<Object> accu) throws OWLException { - if ( !accu.contains( (Object)cl ) ) { - accu.add((Object)cl); - for ( Iterator it = cl.getSuperClasses(o).iterator(); it.hasNext(); ){ - OWLDescription dsc = (OWLDescription)it.next(); - getProperties( dsc, o, list, accu ); - } - // avoid loops - //for ( Iterator it = cl.getEquivalentClasses(o).iterator(); it.hasNext(); ){ - // getProperties( (OWLDescription)it.next(), o, list, accu ); - //} - } - } - - private Set<OWLProperty> getProperties( OWLClass cl, OWLOntology o ) throws OWLException { - Set<OWLProperty> resultSet = new HashSet<OWLProperty>(); - Set<Object> accu = new HashSet<Object>(); - getProperties( cl, o, resultSet, accu ); - return resultSet; - } } diff --git a/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java b/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java index eb96bf67..08155174 100644 --- a/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/method/SubsDistNameAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007-2008 * * 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 @@ -20,66 +20,20 @@ package fr.inrialpes.exmo.align.impl.method; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - -import fr.inrialpes.exmo.align.impl.MatrixMeasure; -import fr.inrialpes.exmo.align.impl.Similarity; - -import org.semanticweb.owl.align.Alignment; -import org.semanticweb.owl.align.AlignmentProcess; -import org.semanticweb.owl.align.AlignmentException; -import org.semanticweb.owl.align.Parameters; - -import fr.inrialpes.exmo.align.impl.DistanceAlignment; - /** * This class implements alignment based on substring distance * of class and property labels + * THIS CLASS IS ONLY HERE FOR COMPATIBILITY PURPOSES * * @author Jérôme Euzenat * @version $Id$ */ -public class SubsDistNameAlignment extends DistanceAlignment implements AlignmentProcess -{ +public class SubsDistNameAlignment extends StringDistAlignment { + /** Creation **/ public SubsDistNameAlignment(){ - setSimilarity( new MatrixMeasure() { - public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ - String s1 = cl1.getURI().getFragment(); - String s2 = cl2.getURI().getFragment(); - if ( s1 != null && s2 != null ) - return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); - else return 1.; - } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ - String s1 = pr1.getURI().getFragment(); - String s2 = pr2.getURI().getFragment(); - if ( s1 != null && s2 != null ) - return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); - else return 1.; - } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ - String s1 = id1.getURI().getFragment(); - String s2 = id2.getURI().getFragment(); - if ( s1 != null && s2 != null ) - return StringDistances.subStringDistance(s1.toLowerCase(),s2.toLowerCase()); - else return 1.; - } - } ); - setType("**"); + methodName = "subStringDistance"; }; - /** Processing **/ - public void align( Alignment alignment, Parameters params ) throws AlignmentException { - loadInit( alignment ); - getSimilarity().initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); - getSimilarity().compute( params ); - extract( type, params ); - } - } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java index a2008b23..0c137e00 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/COWLMappingRendererVisitor.java @@ -26,18 +26,15 @@ import java.io.PrintWriter; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.onto.LoadedOntology; /** * Renders an alignment as a new ontology merging these. @@ -51,6 +48,8 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Cell cell = null; public COWLMappingRendererVisitor( PrintWriter writer ){ @@ -58,9 +57,11 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor } public void visit( Alignment align ) throws AlignmentException { - if ( !(align instanceof OWLAPIAlignment) ) - throw new AlignmentException("COWLMappingRenderer: cannot render simple alignment. Turn them into OWLAlignment, by toOWLAPIAlignement()"); + if ( !(align instanceof ObjectAlignment) ) + throw new AlignmentException("COWLMappingRenderer: cannot render simple alignment. Turn them into ObjectAlignment, by toObjectAlignement()"); alignment = align; + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); writer.print("<rdf:RDF\n"); writer.print(" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"); writer.print(" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"); @@ -70,10 +71,10 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor writer.print(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\">\n\n"); writer.print(" <cowl:Mapping rdf:ID=\"\">\n"); writer.print(" <cowl:sourceOntology>\n"); - writer.print(" <owl:Ontology rdf:about=\""+align.getOntology1URI()+"\"/>\n"); + writer.print(" <owl:Ontology rdf:about=\""+onto1.getURI()+"\"/>\n"); writer.print(" </cowl:sourceOntology>\n"); writer.print(" <cowl:targetOntology>\n"); - writer.print(" <owl:Ontology rdf:about=\""+align.getOntology2URI()+"\"/>\n"); + writer.print(" <owl:Ontology rdf:about=\""+onto2.getURI()+"\"/>\n"); writer.print(" </cowl:targetOntology>\n"); for( Enumeration e = align.getElements() ; e.hasMoreElements(); ){ Cell c = (Cell)e.nextElement(); @@ -89,53 +90,45 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor writer.print(" </cowl:bridgeRule>\n"); } public void visit( EquivRelation rel ) throws AlignmentException { - try { writer.print(" <cowl:Equivalent>\n"); writer.print(" <cowl:source>\n"); - printObject(cell.getObject1AsURI(),(OWLOntology)alignment.getOntology1()); + printObject(cell.getObject1(),onto1); writer.print(" </cowl:source>\n"); writer.print(" <cowl:target>\n"); - printObject(cell.getObject2AsURI(),(OWLOntology)alignment.getOntology2()); + printObject(cell.getObject2(),onto2); writer.print(" </cowl:target>\n"); writer.print(" </cowl:Equivalent>\n"); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; } public void visit( SubsumeRelation rel ) throws AlignmentException { - try { writer.print(" <cowl:Into>\n"); writer.print(" <cowl:source>\n"); - printObject(cell.getObject1AsURI(),(OWLOntology)alignment.getOntology1()); + printObject(cell.getObject1(),onto1); writer.print(" </cowl:source>\n"); writer.print(" <cowl:target>\n"); - printObject(cell.getObject2AsURI(),(OWLOntology)alignment.getOntology2()); + printObject(cell.getObject2(),onto2); writer.print(" </cowl:target>\n"); writer.print(" </cowl:Into>\n"); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; } public void visit( SubsumedRelation rel ) throws AlignmentException { - try { writer.print(" <cowl:Onto>\n"); writer.print(" <cowl:source>\n"); - printObject(cell.getObject1AsURI(),(OWLOntology)alignment.getOntology1()); + printObject(cell.getObject1(),onto1); writer.print(" </cowl:source>\n"); writer.print(" <cowl:target>\n"); - printObject(cell.getObject2AsURI(),(OWLOntology)alignment.getOntology2()); + printObject(cell.getObject2(),onto2); writer.print(" </cowl:target>\n"); writer.print(" </cowl:Onto>\n"); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; } public void visit( IncompatRelation rel ) throws AlignmentException { - try { writer.print(" <cowl:INCOMPATIBLE>\n"); writer.print(" <cowl:source>\n"); - printObject(cell.getObject1AsURI(),(OWLOntology)alignment.getOntology1()); + printObject(cell.getObject1(),onto1); writer.print(" </cowl:source>\n"); writer.print(" <cowl:target>\n"); - printObject(cell.getObject2AsURI(),(OWLOntology)alignment.getOntology2()); + printObject(cell.getObject2(),onto2); writer.print(" </cowl:target>\n"); writer.print(" </cowl:INCOMPATIBLE>\n"); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; } public void visit( Relation rel ) throws AlignmentException { // JE: I do not understand why I need this, @@ -167,15 +160,15 @@ public class COWLMappingRendererVisitor implements AlignmentVisitor } } - public void printObject( URI uri, OWLOntology onto ) throws OWLException { - if ( (OWLEntity)onto.getClass( uri ) != null ) { // A class - writer.print(" <owl:Class rdf:about=\""+uri.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto.getDataProperty( uri ) != null ) { // A Dataproperty - writer.print(" <owl:DataProperty rdf:about=\""+uri.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto.getObjectProperty( uri ) != null ) { // An ObjectProperty - writer.print(" <owl:ObjectProperty rdf:about=\""+uri.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto.getIndividual( uri ) != null ) { // An individual (but check this) - writer.print(" <owl:Individual rdf:about=\""+uri.toString()+"\"/>\n"); + 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"); } } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java index 5f3ffb98..0a0308ee 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007-2008 * * 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 @@ -26,17 +26,14 @@ import java.net.URI; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.onto.LoadedOntology; import fr.inrialpes.exmo.align.impl.rel.*; /** @@ -46,11 +43,11 @@ import fr.inrialpes.exmo.align.impl.rel.*; * @version $Id$ */ - -public class OWLAxiomsRendererVisitor implements AlignmentVisitor -{ +public class OWLAxiomsRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Cell cell = null; public OWLAxiomsRendererVisitor( PrintWriter writer ){ @@ -58,9 +55,14 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor } public void visit( Alignment align ) throws AlignmentException { - if ( !( align instanceof OWLAPIAlignment ) ) - throw new AlignmentException("OWLAxiomsRenderer: cannot render simple alignment. Turn them into OWLAlignment, by toOWLAPIAlignement()"); + if ( !( align instanceof ObjectAlignment )) { + throw new AlignmentException("OWLAxiomsRenderer: cannot render simple alignment. Turn them into ObjectAlignment, by toObjectAlignement()"); + } alignment = align; + if ( align instanceof ObjectAlignment ){ + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); + } writer.print("<rdf:RDF\n"); writer.print(" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"); writer.print(" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"); @@ -81,86 +83,77 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor public void visit( Cell cell ) throws AlignmentException { this.cell = cell; - OWLOntology onto1 = null; - URI entity1URI = null; - try { - // Not very good but we failed to think subsumed from the first shot. - if ( cell.getRelation() instanceof SubsumedRelation ){ - onto1 = (OWLOntology)alignment.getOntology2(); - entity1URI = cell.getObject2AsURI(); - } else { - onto1 = (OWLOntology)alignment.getOntology1(); - entity1URI = cell.getObject1AsURI(); - } - if ( (OWLEntity)onto1.getClass( entity1URI ) != null ) { // A class - writer.print(" <owl:Class rdf:about=\""+entity1URI.toString()+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:Class>\n"); - } else if ( (OWLEntity)onto1.getDataProperty( entity1URI ) != null ) { // A Dataproperty - writer.print(" <owl:DatatypeProperty rdf:about=\""+entity1URI.toString()+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:DatatypeProperty>\n"); - } else if ( (OWLEntity)onto1.getObjectProperty( entity1URI ) != null ) { // An ObjectProperty - writer.print(" <owl:ObjectProperty rdf:about=\""+entity1URI.toString()+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:ObjectProperty>\n"); - } else if ( (OWLEntity)onto1.getIndividual( entity1URI ) != null ) { // An individual (but check this) - writer.print(" <owl:Thing rdf:about=\""+entity1URI.toString()+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" </owl:Thing>\n"); - } - writer.print("\n"); + Object ob1 = cell.getObject1(); + URI u1; + if ( cell.getRelation() instanceof SubsumedRelation ){ + u1 = onto2.getEntityURI( cell.getObject2() ); + } 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 (OWLException e) { throw new AlignmentException("getURI problem", e); } } + public void visit( EquivRelation rel ) throws AlignmentException { - OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); - try { - URI entity2URI = cell.getObject2AsURI(); - if ( (OWLEntity)onto2.getClass( entity2URI ) != null ) { // A class - writer.print(" <owl:equivalentClass rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto2.getDataProperty( entity2URI ) != null ) { // A Dataproperty - writer.print(" <owl:equivalentProperty rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto2.getObjectProperty( entity2URI ) != null ) { // An ObjectProperty - writer.print(" <owl:equivalentProperty rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto2.getIndividual( entity2URI ) != null ) { // An individual (but check this) - writer.print(" <owl:sameAs rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; + Object ob2 = cell.getObject2(); + URI u2 = onto2.getEntityURI( ob2 ); + if ( onto1.isClass( ob2 ) ) { + writer.print(" <owl:equivalentClass rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto1.isDataProperty( ob2 ) ) { + writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto1.isObjectProperty( ob2 ) ) { + writer.print(" <owl:equivalentProperty rdf:resource=\""+u2+"\"/>\n"); + } else if ( onto1.isIndividual( ob2 ) ) { + writer.print(" <owl:sameAs rdf:resource=\""+u2+"\"/>\n"); + } } - public void visit( SubsumeRelation rel ) throws AlignmentException { - OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); - try { - URI entity2URI = cell.getObject2AsURI(); - if ( (OWLEntity)onto2.getClass( entity2URI ) != null ) { // A class - writer.print(" <rdfs:subClassOf rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto2.getDataProperty( entity2URI ) != null ) { // A Dataproperty - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto2.getObjectProperty( entity2URI ) != null ) { // An ObjectProperty - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+entity2URI.toString()+"\"/>\n"); - } - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; + Object ob2 = cell.getObject2(); + URI 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"); + } } + public void visit( SubsumedRelation rel ) throws AlignmentException { - OWLOntology onto1 = (OWLOntology)alignment.getOntology1(); - try { - URI entity1URI = cell.getObject1AsURI(); - if ( (OWLEntity)onto1.getClass( entity1URI ) != null ) { // A class - writer.print(" <rdfs:subClassOf rdf:resource=\""+entity1URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto1.getDataProperty( entity1URI ) != null ) { // A Dataproperty - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+entity1URI.toString()+"\"/>\n"); - } else if ( (OWLEntity)onto1.getObjectProperty( entity1URI ) != null ) { // An ObjectProperty - writer.print(" <rdfs:subPropertyOf rdf:resource=\""+entity1URI.toString()+"\"/>\n"); - } - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; + Object ob1 = cell.getObject1(); + URI 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"); + } } + + // JE: I assume this is incorrect public void visit( IncompatRelation rel ) throws AlignmentException { - //OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); - URI entity2URI = cell.getObject2AsURI(); - writer.print(" <owl:inverseOf rdf:resource=\""+entity2URI.toString()+"\"/>\n"); + Object ob2 = cell.getObject2(); + URI u2 = onto2.getEntityURI( ob2 ); + writer.print(" <owl:inverseOf rdf:resource=\""+u2+"\"/>\n"); } + public void visit( Relation rel ) throws AlignmentException { // JE: I do not understand why I need this, // but this seems to be the case... @@ -189,6 +182,5 @@ public class OWLAxiomsRendererVisitor implements AlignmentVisitor } catch (InvocationTargetException e) { e.printStackTrace(); } - // } catch (Exception e) { throw new AlignmentException("Dispatching problem ", e); }; }; } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java index 6743eb74..1f2bc160 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2006, 2007-2008 + * Copyright (C) INRIA Rhône-Alpes, 2003-2008 * * 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 @@ -21,8 +21,9 @@ package fr.inrialpes.exmo.align.impl.renderer; import java.util.Enumeration; -import java.io.PrintWriter; import java.util.Hashtable; +import java.io.PrintWriter; +import java.net.URI; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; @@ -32,7 +33,9 @@ import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.Annotations; import fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.ObjectCell; import fr.inrialpes.exmo.align.impl.BasicParameters; +import fr.inrialpes.exmo.align.onto.LoadedOntology; import org.omwg.mediation.language.export.omwg.OmwgSyntaxFormat; import org.omwg.mediation.parser.alignment.NamespaceDefs; @@ -132,21 +135,25 @@ public class RDFRendererVisitor implements AlignmentVisitor writer.print("\n <location>"+align.getFile2()+"</location>"); if ( align instanceof BasicAlignment && ((BasicAlignment)align).getOntologyObject2().getFormalism() != null ) { writer.print("\n <formalism>\n <Formalism align:name=\""+((BasicAlignment)align).getOntologyObject2().getFormalism()+"\" align:uri=\""+((BasicAlignment)align).getOntologyObject2().getFormURI()+"\"/>\n </formalism>"); - } writer.print("\n </Ontology>\n </onto2>\n"); - for( Enumeration e = align.getElements() ; e.hasMoreElements(); ){ - Cell c = (Cell)e.nextElement(); - c.accept( this ); - } //end for + for( Cell c : align ){ c.accept( this ); }; writer.print("</Alignment>\n"); writer.print("</rdf:RDF>\n"); } public void visit( Cell cell ) throws AlignmentException { this.cell = cell; - if ( ( cell.getObject1AsURI() != null && - cell.getObject2AsURI() != null) || - alignment.getLevel().equals("2OMWG") ){ + URI u1, u2; + if ( cell instanceof ObjectCell ) { + u1 = ((LoadedOntology)((BasicAlignment)alignment).getOntologyObject1()).getEntityURI( cell.getObject1() ); + u2 = ((LoadedOntology)((BasicAlignment)alignment).getOntologyObject2()).getEntityURI( cell.getObject2() ); + } else { + System.err.println( cell ); + u1 = cell.getObject1AsURI(); + u2 = cell.getObject2AsURI(); + } + if ( ( u1 != null && u2 != null) + || alignment.getLevel().equals("2OMWG") ){ writer.print(" <map>\n"); writer.print(" <Cell"); if ( cell.getId() != null ){ @@ -158,22 +165,19 @@ public class RDFRendererVisitor implements AlignmentVisitor if ( alignment.getLevel().equals("2OMWG") ) { writer.print(" <entity1>"); writer.print( oMWGformatter.export( (Expression)cell.getObject1() ) ); - //writer.print( oMWGformatter.getExprNode( (Expression)cell.getObject1(), model ) ); writer.print("\n </entity1>\n <entity2>"); writer.print( oMWGformatter.export( (Expression)cell.getObject2() ) ); - //writer.print( oMWGformatter.getExprNode( (Expression)cell.getObject2(), model ) ); - writer.print("\n </entity2>\n <relation>"); - cell.getRelation().accept( this ); - writer.print("</relation>\n"); + writer.print("\n </entity2>\n"); } else { writer.print(" <entity1 rdf:resource='"); - writer.print( cell.getObject1AsURI().toString() ); + writer.print( u1.toString() ); writer.print("'/>\n <entity2 rdf:resource='"); - writer.print( cell.getObject2AsURI().toString() ); - writer.print("'/>\n <relation>"); - cell.getRelation().accept( this ); - writer.print("</relation>\n"); + writer.print( u2.toString() ); + writer.print("'/>\n"); } + writer.print(" <relation>"); + cell.getRelation().accept( this ); + writer.print("</relation>\n"); writer.print(" <measure rdf:datatype='http://www.w3.org/2001/XMLSchema#float'>"); writer.print( cell.getStrength() ); writer.print("</measure>\n"); diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java index c8ed350f..4badb16d 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SEKTMappingRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2005, 2007-2008 * * 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 @@ -27,18 +27,15 @@ import java.net.URI; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLEntity; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.onto.LoadedOntology; /** * Renders an alignment as a new ontology merging these. @@ -47,11 +44,11 @@ import fr.inrialpes.exmo.align.impl.rel.*; * @version $Id$ */ - -public class SEKTMappingRendererVisitor implements AlignmentVisitor -{ +public class SEKTMappingRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Cell cell = null; // I hate using random generator for generating symbols (address would be better) Random generator = null; @@ -62,12 +59,14 @@ public class SEKTMappingRendererVisitor implements AlignmentVisitor } public void visit( Alignment align ) throws AlignmentException { + if ( !(align instanceof ObjectAlignment) ) + throw new AlignmentException("SEKTMappingRenderer: cannot render simple alignment. Turn them into ObjectAlignment, by toObjectAlignement()"); alignment = align; - if ( !(align instanceof OWLAPIAlignment) ) - throw new AlignmentException("SEKTMappingRenderer: cannot render simple alignment. Turn them into OWLAlignment, by toOWLAPIAlignement()"); + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); writer.print("MappingDocument(<\""+"\">\n"); - writer.print(" source(<\""+align.getOntology1URI().toString()+"\">)\n"); - writer.print(" target(<\""+align.getOntology2URI().toString()+"\">)\n"); + writer.print(" source(<\""+onto1.getURI()+"\">)\n"); + writer.print(" target(<\""+onto2.getURI()+"\">)\n"); for( Enumeration e = align.getElements() ; e.hasMoreElements(); ){ Cell c = (Cell)e.nextElement(); @@ -78,39 +77,34 @@ public class SEKTMappingRendererVisitor implements AlignmentVisitor public void visit( Cell cell ) throws AlignmentException { this.cell = cell; String id = "s"+generator.nextInt(100000); - OWLOntology onto1 = (OWLOntology)alignment.getOntology1(); - //OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); - try { - URI entity1URI = cell.getObject1AsURI(); - URI entity2URI = cell.getObject2AsURI(); - if ( (OWLEntity)onto1.getClass( entity1URI ) != null ) { // A class - writer.print(" classMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+entity1URI.toString()+"\">\n"); - writer.print(" <\""+entity2URI.toString()+"\">\n"); - - writer.print(" )\n"); - } else if ( (OWLEntity)onto1.getDataProperty( entity1URI ) != null ) { // A Dataproperty - writer.print(" relationMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+entity1URI.toString()+"\">\n"); - writer.print(" <\""+entity2URI.toString()+"\">\n"); - writer.print(" )\n"); - } else if ( (OWLEntity)onto1.getObjectProperty( entity1URI ) != null ) { // An ObjectProperty - writer.print(" attributeMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+entity1URI.toString()+"\">\n"); - writer.print(" <\""+entity2URI.toString()+"\">\n"); - writer.print(" )\n"); - } else if ( (OWLEntity)onto1.getIndividual( entity1URI ) != null ) { // An individual (but check this) - writer.print(" instanceMapping( <\"#"+id+"\">\n"); - cell.getRelation().accept( this ); - writer.print(" <\""+entity1URI.toString()+"\">\n"); - writer.print(" <\""+entity2URI.toString()+"\">\n"); - writer.print(" )\n"); - } - writer.print("\n"); - } catch (OWLException e) { throw new AlignmentException("getURI problem", e); }; + 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"); + } + 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 2a11c5b9..691ba69c 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SKOSRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2006-2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2006-2008 * * 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 @@ -33,19 +33,21 @@ import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.onto.LoadedOntology; /** * Renders an alignment as a new ontology merging these. * * @author Jérôme Euzenat - * @version $$ + * @version $Id$ */ - -public class SKOSRendererVisitor implements AlignmentVisitor -{ +public class SKOSRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Cell cell = null; public SKOSRendererVisitor( PrintWriter writer ){ @@ -54,6 +56,10 @@ public class SKOSRendererVisitor implements AlignmentVisitor // This must be considered public void visit( Alignment align ) throws AlignmentException { + if ( align instanceof ObjectAlignment ) { + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); + } alignment = align; writer.print("<rdf:RDF\n"); writer.print(" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"); @@ -66,20 +72,32 @@ public class SKOSRendererVisitor implements AlignmentVisitor writer.print("</rdf:RDF>\n"); } + public URI getURI2() throws AlignmentException { + if ( onto2 != null ) { + return onto2.getEntityURI( cell.getObject2() ); + } else { + return cell.getObject2AsURI(); + } + } + public void visit( Cell cell ) throws AlignmentException { this.cell = cell; - writer.print(" <skos:Concept rdf:about=\""+cell.getObject1AsURI().toString()+"\">\n"); + if ( onto1 != null ) { + writer.print(" <skos:Concept rdf:about=\""+onto1.getEntityURI( cell.getObject1() )+"\">\n"); + } else { + writer.print(" <skos:Concept rdf:about=\""+cell.getObject1AsURI()+"\">\n"); + } cell.getRelation().accept( this ); writer.print(" </skos:Concept>\n\n"); } public void visit( EquivRelation rel ) throws AlignmentException { - writer.print(" <skos:related rdf:resource=\""+cell.getObject2AsURI().toString()+"\"/>\n"); + writer.print(" <skos:related rdf:resource=\""+getURI2()+"\"/>\n"); } public void visit( SubsumeRelation rel ) throws AlignmentException { - writer.print(" <skos:narrower rdf:resource=\""+cell.getObject2AsURI().toString()+"\"/>\n"); + writer.print(" <skos:narrower rdf:resource=\""+getURI2()+"\"/>\n"); } public void visit( SubsumedRelation rel ) throws AlignmentException { - writer.print(" <skos:broader rdf:resource=\""+cell.getObject2AsURI().toString()+"\"/>\n"); + writer.print(" <skos:broader rdf:resource=\""+getURI2()+"\"/>\n"); } public void visit( IncompatRelation rel ) throws AlignmentException { throw new AlignmentException("Cannot translate in SKOS"+rel); @@ -112,6 +130,5 @@ public class SKOSRendererVisitor implements AlignmentVisitor } catch (InvocationTargetException e) { e.printStackTrace(); } - // } catch (Exception e) { throw new AlignmentException("Dispatching problem ", e); }; }; } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java index e7cf95d1..fe848b6b 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SWRLRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007 + * Copyright (C) INRIA Rhône-Alpes, 2003-2004, 2007-2008 * * 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 @@ -27,17 +27,15 @@ import java.net.URI; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLException; - import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.onto.LoadedOntology; /** * Renders an alignment as a SWRL rule set interpreting @@ -47,11 +45,11 @@ import fr.inrialpes.exmo.align.impl.rel.*; * @version $Id$ */ - -public class SWRLRendererVisitor implements AlignmentVisitor -{ +public class SWRLRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Cell cell = null; public SWRLRendererVisitor( PrintWriter writer ){ @@ -59,15 +57,17 @@ public class SWRLRendererVisitor implements AlignmentVisitor } public void visit( Alignment align ) throws AlignmentException { - if ( !( align instanceof OWLAPIAlignment) ) - throw new AlignmentException("SWRLRenderer: cannot render simple alignment. Turn them into OWLAlignment, by toOWLAPIAlignement()"); + if ( !( align instanceof ObjectAlignment) ) + throw new AlignmentException("SWRLRenderer: cannot render simple alignment. Turn them into ObjectAlignment, by toObjectAlignement()"); alignment = align; + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.println("<swrlx:Ontology swrlx:name=\"generatedAl\""); writer.println(" xmlns:swrlx=\"http://www.w3.org/2003/11/swrlx#\""); writer.println(" xmlns:owlx=\"http://www.w3.org/2003/05/owl-xml\""); writer.println(" xmlns:ruleml=\"http://www.w3.org/2003/11/ruleml#\">"); - writer.println(" <owlx:Imports rdf:resource=\""+align.getOntology1URI().toString()+"\"/>\n"); + writer.println(" <owlx:Imports rdf:resource=\""+onto1.getURI()+"\"/>\n"); for( Enumeration e = align.getElements() ; e.hasMoreElements(); ){ Cell c = (Cell)e.nextElement(); c.accept( this ); @@ -77,58 +77,53 @@ public class SWRLRendererVisitor implements AlignmentVisitor public void visit( Cell cell ) throws AlignmentException { this.cell = cell; - URI entity1URI = cell.getObject1AsURI(); cell.getRelation().accept( this ); } public void visit( EquivRelation rel ) throws AlignmentException { - // JE: It sounds that the alignment and cell variables are taken as global... - // But it seems that this is not the case... // JE: We should send warnings when dataproperties are mapped to individual properties and vice versa... - try { - writer.println(" <ruleml:imp>"); - writer.println(" <ruleml:_body>"); - OWLOntology onto1 = (OWLOntology)alignment.getOntology1(); - URI uri1 = cell.getObject1AsURI(); - if ( onto1.getClass( uri1 ) != null ){ - writer.println(" <swrl:classAtom>"); - writer.println(" <owllx:Class owllx:name=\""+uri1.toString()+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" </swrl:classAtom>"); - } else if ( onto1.getDataProperty( uri1 ) != null ){ - writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri1.toString()+"\"/>"); - 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.toString()+"\"/>"); - 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>"); - OWLOntology onto2 = (OWLOntology)alignment.getOntology2(); - URI uri2 = cell.getObject2AsURI(); - if ( onto2.getClass( uri2 ) != null ){ - writer.println(" <swrlx:classAtom>"); - writer.println(" <owllx:Class owllx:name=\""+uri2.toString()+"\"/>"); - writer.println(" <ruleml:var>x</ruleml:var>"); - writer.println(" </swrl:classAtom>"); - } else if ( onto2.getDataProperty( uri2 ) != null ){ - writer.println(" <swrl:datavaluedPropertyAtom swrlx:property=\""+uri2.toString()+"\"/>"); - 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.toString()+"\"/>"); - 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 (OWLException e) { throw new AlignmentException("getURI problem", e); }; + Object ob1 = cell.getObject1(); + URI 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>"); + Object ob2 = cell.getObject2(); + URI 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"); } public void visit( SubsumeRelation rel ){}; @@ -163,6 +158,5 @@ public class SWRLRendererVisitor implements AlignmentVisitor } catch (InvocationTargetException e) { e.printStackTrace(); } - // } catch (Exception e) { throw new AlignmentException("Dispatching problem ", e); }; }; } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java index effb03bc..56b500bc 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/XSLTRendererVisitor.java @@ -34,6 +34,8 @@ import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; import fr.inrialpes.exmo.align.impl.rel.*; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; +import fr.inrialpes.exmo.align.onto.LoadedOntology; /** * Renders an alignment as a XSLT stylesheet transforming @@ -43,11 +45,12 @@ import fr.inrialpes.exmo.align.impl.rel.*; * @version $Id$ */ -public class XSLTRendererVisitor implements AlignmentVisitor -{ +public class XSLTRendererVisitor implements AlignmentVisitor { PrintWriter writer = null; Alignment alignment = null; Cell cell = null; + LoadedOntology onto1 = null; + LoadedOntology onto2 = null; Hashtable<String,String> namespaces = null; int nsrank = 0; @@ -61,6 +64,10 @@ public class XSLTRendererVisitor implements AlignmentVisitor } public void visit( Alignment align ) throws AlignmentException { + if ( align instanceof ObjectAlignment ) { + onto1 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject1(); + onto2 = (LoadedOntology)((ObjectAlignment)alignment).getOntologyObject2(); + } for( Enumeration e = align.getElements(); e.hasMoreElements(); ){ collectURIs( (Cell)e.nextElement() ); } @@ -99,8 +106,14 @@ public class XSLTRendererVisitor implements AlignmentVisitor } private void collectURIs ( Cell cell ) throws AlignmentException { - URI entity1URI = cell.getObject1AsURI(); - URI entity2URI = cell.getObject2AsURI(); + URI entity1URI, entity2URI; + if ( onto1 != null ){ + entity1URI = onto1.getEntityURI( cell.getObject1() ); + entity2URI = onto2.getEntityURI( cell.getObject2() ); + } else { + entity1URI = cell.getObject1AsURI(); + entity2URI = cell.getObject2AsURI(); + } if ( entity1URI != null ) { String ns1 = entity1URI.getScheme()+":"+entity1URI.getSchemeSpecificPart()+"#"; if ( namespaces.get( ns1 ) == null ){ @@ -117,8 +130,13 @@ public class XSLTRendererVisitor implements AlignmentVisitor public void visit( EquivRelation rel ) throws AlignmentException { // The code is exactly the same for properties and classes - writer.println(" <xsl:template match=\""+namespacify(cell.getObject1AsURI())+"\">"); - writer.println(" <xsl:element name=\""+namespacify(cell.getObject2AsURI())+"\">"); + if ( onto1 != null ){ + writer.println(" <xsl:template match=\""+namespacify(onto1.getEntityURI( cell.getObject1() ))+"\">"); + writer.println(" <xsl:element name=\""+namespacify(onto2.getEntityURI( cell.getObject2() ))+"\">"); + } else { + writer.println(" <xsl:template match=\""+namespacify(cell.getObject1AsURI())+"\">"); + writer.println(" <xsl:element name=\""+namespacify(cell.getObject2AsURI())+"\">"); + } writer.println(" <xsl:apply-templates select=\"*|@*|text()\"/>"); writer.println(" </xsl:element>"); writer.println(" </xsl:template>\n"); diff --git a/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java b/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java index 4703f83a..398b27cf 100644 --- a/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java +++ b/src/fr/inrialpes/exmo/align/ling/JWNLAlignment.java @@ -20,12 +20,6 @@ package fr.inrialpes.exmo.align.ling; -import org.semanticweb.owl.model.OWLOntology; -import org.semanticweb.owl.model.OWLClass; -import org.semanticweb.owl.model.OWLProperty; -import org.semanticweb.owl.model.OWLIndividual; -import org.semanticweb.owl.model.OWLException; - import fr.inrialpes.exmo.align.impl.DistanceAlignment; import fr.inrialpes.exmo.align.impl.MatrixMeasure; @@ -61,33 +55,22 @@ public class JWNLAlignment extends DistanceAlignment implements AlignmentProcess public void init( String wndict ) throws AlignmentException { Dist.Initialize( wndict, WNVERS ); } - public double measure( OWLClass cl1, OWLClass cl2 ) throws OWLException{ - String s1 = cl1.getURI().getFragment(); - String s2 = cl2.getURI().getFragment(); + public double measure( Object o1, Object o2 ) throws Exception { + String s1 = ontology1().getEntityName( o1 ); + String s2 = ontology2().getEntityName( o2 ); if ( s1 == null || s2 == null ) return 1.; return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); } - public double measure( OWLProperty pr1, OWLProperty pr2 ) throws OWLException{ - String s1 = pr1.getURI().getFragment(); - String s2 = pr2.getURI().getFragment(); - if ( s1 == null || s2 == null ) return 1.; - return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); + public double classMeasure( Object cl1, Object cl2 ) throws Exception { + return measure( cl1, cl2 ); } - public double measure( OWLIndividual id1, OWLIndividual id2 ) throws OWLException{ + public double propertyMeasure( Object pr1, Object pr2 ) throws Exception { + return measure( pr1, pr2 ); + } + public double individualMeasure( Object id1, Object id2 ) throws Exception { if ( debug > 4 ) System.err.println( "ID:"+id1+" -- "+id2); - URI URI1 = id1.getURI(); - String s1; - if ( URI1 != null ) s1 = URI1.getFragment(); - else s1 = ""; - URI URI2 = id2.getURI(); - String s2; - if ( URI2 != null ) s2 = URI2.getFragment(); - else s2 = ""; - if ( s1 == null || s2 == null ) return 1.; - // String s1 = id1.getURI().getFragment(); - // String s2 = id2.getURI().getFragment(); - return Dist.BasicSynonymDistance(s1.toLowerCase(),s2.toLowerCase()); + return measure( id1, id2 ); } } @@ -104,7 +87,7 @@ public class JWNLAlignment extends DistanceAlignment implements AlignmentProcess String wnvers = (String)params.getParameter("wnvers"); if ( wnvers == null ) wnvers = WNVERS; sim.init( (String)params.getParameter("wndict"), wnvers ); - sim.initialize( (OWLOntology)getOntology1(), (OWLOntology)getOntology2(), alignment ); + sim.initialize( ontology1(), ontology2(), alignment ); getSimilarity().compute( params ); if ( params.getParameter("printMatrix") != null ) printDistanceMatrix(params); extract( type, params ); diff --git a/src/fr/inrialpes/exmo/align/onto/HeavyLoadedOntology.java b/src/fr/inrialpes/exmo/align/onto/HeavyLoadedOntology.java new file mode 100644 index 00000000..bd31761d --- /dev/null +++ b/src/fr/inrialpes/exmo/align/onto/HeavyLoadedOntology.java @@ -0,0 +1,64 @@ +/* + * $Id$ + * + * Copyright (C) INRIA Rhône-Alpes, 2008 + * + * 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.align.onto; + +import java.util.Set; + +import org.semanticweb.owl.align.AlignmentException; + +/** + * Encapsulate deep access to an ontology through some Ontology API + * + * Asserted methods corresponds to the information explicitely given or stored about the entity. + * Non-asserted corresponds to the information that can be deduced from it. + * So asserted methods are related to a syntactic view while the others are related to the semantics + */ +public interface HeavyLoadedOntology<O> extends LoadedOntology<O> { + + /* Class methods */ + public Set<Object> getSubClasses( Object c ); + public Set<Object> getAssertedSubClasses( Object c ); + public Set<Object> getSuperClasses( Object c ); + public Set<Object> getAssertedSuperClasses( Object c ); + public Set<Object> getProperties( Object c ); + public Set<Object> getAssertedProperties( Object c ); + public Set<Object> getDataProperties( Object c ); + public Set<Object> getAssertedDataProperties( Object c ); + public Set<Object> getObjectProperties( Object c ); + public Set<Object> getAssertedObjectProperties( Object c ); + public Set<Object> getInstances( Object c ); + public Set<Object> getAssertedInstances( Object c ); + + /* Property methods */ + public Set<Object> getSubProperties( Object p ); + public Set<Object> getAssertedSubProperties( Object p ); + public Set<Object> getSuperProperties( Object p ); + public Set<Object> getAssertedSuperProperties( Object p ); + public Set<Object> getRange( Object p ); + public Set<Object> getAssertedRange( Object p ); + public Set<Object> getDomain( Object p ); + public Set<Object> getAssertedDomain( Object p ); + + /* Individual methods */ + public Set<Object> getClasses( Object i ); + public Set<Object> getAssertedClasses( Object i ); + +} diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java index d4093a9a..ade34980 100644 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java +++ b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntology.java @@ -18,10 +18,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + * This should be turned into an HeavyLoadedOntology. + * Some primitives are already avalible below + * + * + */ + package fr.inrialpes.exmo.align.onto.owlapi10; import java.net.URI; import java.util.Set; +import java.util.HashSet; import java.util.Iterator; import java.util.NoSuchElementException; import java.lang.UnsupportedOperationException; @@ -38,6 +46,9 @@ import org.semanticweb.owl.model.OWLObjectProperty; import org.semanticweb.owl.model.OWLDataProperty; import org.semanticweb.owl.model.OWLIndividual; import org.semanticweb.owl.model.OWLEntity; +import org.semanticweb.owl.model.OWLRestriction; +import org.semanticweb.owl.model.OWLDescription; +import org.semanticweb.owl.model.OWLNaryBooleanDescription; import org.semanticweb.owl.model.OWLException; /* @@ -279,6 +290,31 @@ public class OWLAPIOntology extends BasicOntology<OWLOntology> implements Loaded } } + /* HeavyLoadedOntology specifics */ + + public Set<Object> getProperties( OWLDescription desc ) { + Set<Object> list = new HashSet<Object>(); + try { + if ( desc instanceof OWLRestriction ){ + list.add( ((OWLRestriction)desc).getProperty() ); + } else if ( desc instanceof OWLClass ) { + // JE: I suspect that this can be a cause for looping!! + for ( Object cl : ((OWLClass)desc).getEquivalentClasses((OWLOntology)onto) ){ + // JE: strange casting + Set<Object> res = getProperties( (OWLDescription)cl ); + if ( res != null ) list.add( res ); + } + } else if ( desc instanceof OWLNaryBooleanDescription ) { + for ( Object d : ((OWLNaryBooleanDescription)desc).getOperands() ){ + // JE: strange casting + Set<Object> res = getProperties( (OWLDescription)d ); + if ( res != null ) list.add( res ); + } + } + } catch (OWLException e) { e.printStackTrace(); } + return list; + } + public void unload() { try { ((OWLOntology)onto).getOWLConnection().notifyOntologyDeleted( ((OWLOntology)onto) ); diff --git a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java index deeb5cfd..8004be83 100644 --- a/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java +++ b/src/fr/inrialpes/exmo/align/onto/owlapi10/OWLAPIOntologyFactory.java @@ -67,7 +67,7 @@ public class OWLAPIOntologyFactory extends OntologyFactory { public LoadedOntology loadOntology( URI uri ) throws AlignmentException { OWLConnection connection = null; Map parameters = new HashMap(); - parameters.put(OWLManager.OWL_CONNECTION, + parameters.put(OWLManager.OWL_CONNECTION, // [W:unchecked] "org.semanticweb.owl.impl.model.OWLConnectionImpl"); try { connection = OWLManager.getOWLConnection(parameters); diff --git a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java index b474d046..b8bf6e6f 100644 --- a/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java +++ b/src/fr/inrialpes/exmo/align/parser/AlignmentParser.java @@ -272,9 +272,13 @@ public class AlignmentParser extends DefaultHandler { throw new SAXException("Catched alignment exception", e ); } } else if (pName.equals("Formalism")) { - // JE: OMWG1 leave it alone for the moment - //if ( atts.getValue("uri") != null ) - // curronto.setFormalismURI( new URI(atts.getValue("uri")) ); + // JE: Check that this is OK with OMWG + if ( atts.getValue("uri") != null ) + try { + curronto.setFormURI( new URI(atts.getValue("uri")) ); + } catch (Exception e) { + throw new SAXException("Malformed URI"+atts.getValue("uri"), e ); + }; if ( atts.getValue("name") != null ) curronto.setFormalism( atts.getValue("name") ); } else if (pName.equals("formalism")) { diff --git a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java index c2dcc6f8..982a2564 100644 --- a/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java +++ b/src/fr/inrialpes/exmo/align/service/AServProtocolManager.java @@ -549,20 +549,10 @@ public class AServProtocolManager { *********************************************************************/ public LoadedOntology reachable( URI uri ){ - try { return loadOntology( uri ); } - catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public LoadedOntology loadOntology( URI uri ) { - // Test if not loaded... - OntologyFactory factory = OntologyFactory.newInstance(); - LoadedOntology onto = factory.loadOntology( uri ); - if ( loadedOntologies != null ) - loadedOntologies.recordOntology( uri, onto ); - return onto; + try { + OntologyFactory factory = OntologyFactory.newInstance(); + return factory.loadOntology( uri, loadedOntologies ); + } catch (Exception e) { return null; } } /********************************************************************* diff --git a/src/fr/inrialpes/exmo/align/service/CacheImpl.java b/src/fr/inrialpes/exmo/align/service/CacheImpl.java index ed58e2bc..888c9eb2 100644 --- a/src/fr/inrialpes/exmo/align/service/CacheImpl.java +++ b/src/fr/inrialpes/exmo/align/service/CacheImpl.java @@ -161,7 +161,7 @@ public class CacheImpl { * in an alignment object * * Beware, the Alignment API has two attributes: - * onto1 is the OWLOntology object + * onto1 is the Ontology object * uri1 is the URI object from which loading the ontologies * In the database we store: * owlontology1 the URI string of the ontology diff --git a/src/fr/inrialpes/exmo/align/service/CannotRenderAlignment.java b/src/fr/inrialpes/exmo/align/service/CannotRenderAlignment.java index 21d7ca68..fdcc00ab 100644 --- a/src/fr/inrialpes/exmo/align/service/CannotRenderAlignment.java +++ b/src/fr/inrialpes/exmo/align/service/CannotRenderAlignment.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA Rhône-Alpes, 2006-2007 + * Copyright (C) INRIA Rhône-Alpes, 2006-2008 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -31,6 +31,6 @@ public class CannotRenderAlignment extends ErrorMsg { super( surr, rep, from, to, cont, param ); } public String HTMLString(){ - return "Cannot render alignment "+content+": turn it to a OWLAPIAlignment with OWLAPIAlignement.toOWLAPIAlignement( al )"; + return "Cannot render alignment "+content+": turn it to an ObjectAlignment with ObjectAlignement.toOkbjectAlignement( al )"; } } diff --git a/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java b/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java index 3a5b7274..7850c188 100644 --- a/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java +++ b/src/fr/inrialpes/exmo/align/util/ExtGroupEval.java @@ -33,7 +33,7 @@ import org.semanticweb.owl.align.Parameters; import org.semanticweb.owl.align.Evaluator; import fr.inrialpes.exmo.align.impl.BasicParameters; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.impl.eval.ExtPREvaluator; import fr.inrialpes.exmo.align.parser.AlignmentParser; @@ -240,8 +240,8 @@ public class ExtGroupEval { Alignment align2 = aparser2.parse( alignName2 ); if ( debug > 1 ) System.err.println(" Alignment structure2 parsed"); // Create evaluator object - eval = new ExtPREvaluator(OWLAPIAlignment.toOWLAPIAlignment( (URIAlignment)align1, loaded ), - OWLAPIAlignment.toOWLAPIAlignment( (URIAlignment)align2, loaded ) ); + eval = new ExtPREvaluator(ObjectAlignment.toObjectAlignment( (URIAlignment)align1, loaded ), + ObjectAlignment.toObjectAlignment( (URIAlignment)align2, loaded ) ); // Compare params.setParameter( "debug", new Integer( nextdebug ) ); eval.eval( params, loaded ) ; diff --git a/src/fr/inrialpes/exmo/align/util/ParserPrinter.java b/src/fr/inrialpes/exmo/align/util/ParserPrinter.java index 09fe449c..24bc304a 100644 --- a/src/fr/inrialpes/exmo/align/util/ParserPrinter.java +++ b/src/fr/inrialpes/exmo/align/util/ParserPrinter.java @@ -32,7 +32,7 @@ import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.AlignmentException; import fr.inrialpes.exmo.align.impl.renderer.RDFRendererVisitor; -import fr.inrialpes.exmo.align.impl.OWLAPIAlignment; +import fr.inrialpes.exmo.align.impl.ObjectAlignment; import fr.inrialpes.exmo.align.impl.URIAlignment; import fr.inrialpes.exmo.align.onto.OntologyCache; @@ -167,7 +167,6 @@ public class ParserPrinter { // Create parser AlignmentParser aparser = null; if ( parserClass == null ) aparser = new AlignmentParser( debug ); - // JE: I would be surprised that it works for the moment else { try { Object[] mparams = { (Object)debug }; @@ -223,9 +222,9 @@ public class ParserPrinter { try { result.render( renderer ); } catch ( AlignmentException aex ) { - // if the renderer needs an OWLAPIALignment: give it + // if the renderer needs an ObjectALignment: give it //aex.printStackTrace(); - result = OWLAPIAlignment.toOWLAPIAlignment( (URIAlignment)result, (OntologyCache)null ); + result = ObjectAlignment.toObjectAlignment( (URIAlignment)result, (OntologyCache)null ); result.render( renderer ); } writer.flush(); diff --git a/src/fr/inrialpes/exmo/align/util/Procalign.java b/src/fr/inrialpes/exmo/align/util/Procalign.java index 0613657a..9df7b236 100644 --- a/src/fr/inrialpes/exmo/align/util/Procalign.java +++ b/src/fr/inrialpes/exmo/align/util/Procalign.java @@ -252,7 +252,7 @@ public class Procalign { // Thresholding if (threshold != 0) result.cut( cutMethod, threshold ); - if (debug > 0) System.err.println(" Alignment performed"); + if (debug > 0) System.err.println(" Matching performed"); // Set output file OutputStream stream; diff --git a/src/org/semanticweb/owl/align/Alignment.java b/src/org/semanticweb/owl/align/Alignment.java index eef89eb7..c4ed3fc1 100644 --- a/src/org/semanticweb/owl/align/Alignment.java +++ b/src/org/semanticweb/owl/align/Alignment.java @@ -21,7 +21,9 @@ package org.semanticweb.owl.align; import java.lang.Cloneable; +import java.lang.Iterable; import java.util.Enumeration; +import java.util.Iterator; import java.util.Set; import java.net.URI; @@ -35,8 +37,7 @@ import org.xml.sax.ContentHandler; */ -public interface Alignment extends Cloneable -{ +public interface Alignment extends Cloneable, Iterable<Cell> { /** Initialize the alignement before using it **/ @@ -112,8 +113,14 @@ public interface Alignment extends Cloneable * Reason: this applies only for 1:1 alignments * Some implementations might act cleverly (retrieving the best value). * Basic implementations may raise the exception + * //@deprecated There is more than one cell about one object */ + //@Deprecated public Cell getAlignCell1( Object ob ) throws AlignmentException; + /** + * //@deprecated There is more than one cell about one object + */ + //@Deprecated public Cell getAlignCell2( Object ob ) throws AlignmentException; /** * Each part of the cell can be queried independently. @@ -150,6 +157,7 @@ public interface Alignment extends Cloneable public void setExtension( String uri, String label, String value ); public Enumeration<Cell> getElements(); + public Iterator<Cell> iterator(); public int nbCells(); public void cut( String method, double threshold ) throws AlignmentException; -- GitLab