diff --git a/examples/omwg/total.xml b/examples/omwg/total.xml index a075c5ebc8d7ce20cd3005deaba3614b751afba5..6d5e7992d97961c4cd77781cf98733e9f431363e 100644 --- a/examples/omwg/total.xml +++ b/examples/omwg/total.xml @@ -818,16 +818,16 @@ without it, this is not! --> <measure rdf:datatype='&xsd;float'>1.</measure> <relation>SubsumedBy</relation> <edoal:linkkey> - <edoal:Linkkey edoal:type="weak"> + <edoal:Linkkey> <edoal:binding> - <edoal:Corresp edoal:type="eq"> + <edoal:Equals> <edoal:property1> <edoal:Property rdf:about="&wine;yearValue" /> </edoal:property1> <edoal:property2> <edoal:Property rdf:about="&vin;annee_millesime" /> </edoal:property2> - </edoal:Corresp> + </edoal:Equals> </edoal:binding> </edoal:Linkkey> </edoal:linkkey> diff --git a/lib/align.jar b/lib/align.jar index b65e59faae6da58af6684fc460ebcf792e1b45b5..8c4c4da4aeca5e67dc3b8865e34277d049e912f9 100644 Binary files a/lib/align.jar and b/lib/align.jar differ diff --git a/lib/align.pom b/lib/align.pom index fee6777b762d4240a5c22efd03aacfa93f64ebcf..cf2808c1caac3c0cb72257db675361441654adc7 100644 --- a/lib/align.pom +++ b/lib/align.pom @@ -17,7 +17,7 @@ <groupId>org.semanticweb.owl</groupId> <artifactId>align</artifactId> <version>4.6</version> - <!-- Rev 1954:1956M 11/07/2014 --> + <!-- Rev 1954:1957M 03/09/2014 --> <name>The Alignment API</name> <description>The Alignment API is an API for manipulating ontology alignments.</description> <url>http://alignapi.gforge.inria.fr</url> diff --git a/lib/alignsvc.jar b/lib/alignsvc.jar index efa67d9381e77212a28792233a0d7c6efb29e3c3..743fabd92428e8d8baa2b8f339cf9389d3190c3a 100644 Binary files a/lib/alignsvc.jar and b/lib/alignsvc.jar differ diff --git a/lib/alignsvc.pom b/lib/alignsvc.pom index 23dbe5913041637ef87a9982fded54fa0e2f5b3d..1e17bea3159ed15d034de164d0df0a5153921929 100644 --- a/lib/alignsvc.pom +++ b/lib/alignsvc.pom @@ -17,7 +17,7 @@ <groupId>fr.inrialpes.exmo.align</groupId> <artifactId>alignsvc</artifactId> <version>4.6</version> - <!-- Rev 1954:1956M 11/07/2014 --> + <!-- Rev 1954:1957M 03/09/2014 --> <name>Alignment server</name> <description>A server for storing and sharing ontology alignments.</description> <url>http://alignapi.gforge.inria.fr</url> diff --git a/lib/ontowrap.jar b/lib/ontowrap.jar index 80d5a0cbc70ac9640c2e40eec34525592e6c3f99..fd98b4964f1058f37e31a782eb68711b8085aa57 100644 Binary files a/lib/ontowrap.jar and b/lib/ontowrap.jar differ diff --git a/lib/ontowrap.pom b/lib/ontowrap.pom index fbc1acc2a8a82e4ade90e00df82bacc05aaa36b0..d47550890fcaedddfcbb1f30bd11829f5dc4c9ea 100644 --- a/lib/ontowrap.pom +++ b/lib/ontowrap.pom @@ -17,7 +17,7 @@ <groupId>fr.inrialpes.exmo</groupId> <artifactId>ontowrap</artifactId> <version>4.6</version> - <!-- Rev 1954:1956M 11/07/2014 --> + <!-- Rev 1954:1957M 03/09/2014 --> <name>Ontology wrapping API</name> <description>An ontology wrapping API and library.</description> <url>http://alignapi.gforge.inria.fr</url> diff --git a/lib/procalign.jar b/lib/procalign.jar index de094405c9d309151efbad40beb2fa713f4b7bff..64c834bed3a57a0f74fd65e503f09612217ad8d3 100644 Binary files a/lib/procalign.jar and b/lib/procalign.jar differ diff --git a/lib/procalign.pom b/lib/procalign.pom index 8ce48a0d46662ce311873d39e800372941c7839a..f2221d602339c8b35bf606b681677a84b53cb924 100644 --- a/lib/procalign.pom +++ b/lib/procalign.pom @@ -17,7 +17,7 @@ <groupId>fr.inrialpes.exmo.align</groupId> <artifactId>procalign</artifactId> <version>4.6</version> - <!-- Rev 1954:1956M 11/07/2014 --> + <!-- Rev 1954:1957M 03/09/2014 --> <name>Reference implementation of the Alignment API</name> <description>Implementation of the Alignment API for manipulating ontology alignments.</description> <url>http://alignapi.gforge.inria.fr</url> diff --git a/src/fr/inrialpes/exmo/align/impl/Extensions.java b/src/fr/inrialpes/exmo/align/impl/Extensions.java index 1331b30923af594f0cd48d0e74a7d1f19b5bcb27..e828a18cde2df680d04d64a5a247a541bad10bd0 100644 --- a/src/fr/inrialpes/exmo/align/impl/Extensions.java +++ b/src/fr/inrialpes/exmo/align/impl/Extensions.java @@ -32,7 +32,7 @@ import java.util.Set; * So it is implemented the old way with concatenation... unfortunately */ -public class Extensions { + public class Extensions { private Hashtable<String,String[]> table; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java index 6db026def63600bf4aef0854bff59503cbfee867..82ee24b67b98a3da9eaa4f7a2a1306cda07e88f3 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALAlignment.java @@ -21,9 +21,7 @@ package fr.inrialpes.exmo.align.impl.edoal; -import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; import java.util.Hashtable; import java.util.Collection; import java.util.Set; @@ -33,12 +31,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.semanticweb.owl.align.AlignmentException; -import org.semanticweb.owl.align.AlignmentVisitor; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.Cell; import org.semanticweb.owl.align.Relation; -import fr.inrialpes.exmo.ontowrap.OntologyFactory; import fr.inrialpes.exmo.ontowrap.Ontology; import fr.inrialpes.exmo.ontowrap.LoadedOntology; import fr.inrialpes.exmo.ontowrap.OntologyFactory; diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALVisitor.java b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALVisitor.java index 7ecade0db8101b9c92c75815c145f5bc832e8728..1fbf1cf91681899c0756d5b919a5a8dc6f3dda4c 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/EDOALVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/EDOALVisitor.java @@ -46,6 +46,9 @@ public interface EDOALVisitor { public void visit( Apply o ) throws AlignmentException; public void visit( Datatype o ) throws AlignmentException; public void visit( Linkkey o ) throws AlignmentException; + public void visit( LinkkeyEquals o ) throws AlignmentException; + public void visit( LinkkeyIntersects o ) throws AlignmentException; + //public void visit( Comparator o ) throws AlignmentException; //public void visit( EDOALCell o ) throws AlignmentException; } diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Extensable.java b/src/fr/inrialpes/exmo/align/impl/edoal/Extensable.java new file mode 100644 index 0000000000000000000000000000000000000000..0f14f588aaab1019f218f1c21cf8cc3feeb66e45 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Extensable.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package fr.inrialpes.exmo.align.impl.edoal; + +import fr.inrialpes.exmo.align.impl.Extensions; +import java.util.Collection; + +/** + * + * @author Nicolas Guillouet <nicolas@meaningengines.com> + */ +public interface Extensable { + + + /** + * Extensions are a way to read and add other information (metadata) + * to the alignment structure itself. + * getExtensions returns a set of tripes: uri*label*value + * all three being String + */ + public Collection<String[]> getExtensions(); + public String getExtension( String uri, String label ); + public void setExtension( String uri, String label, String value ); + public void setExtensions(Extensions p); +} diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/Linkkey.java b/src/fr/inrialpes/exmo/align/impl/edoal/Linkkey.java index df2cee152ad61027bf520cf681616cb9f4d2b810..f7fb4f56781da8d7e89ea66510b329cfa9feeadf 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/Linkkey.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/Linkkey.java @@ -5,10 +5,10 @@ */ package fr.inrialpes.exmo.align.impl.edoal; +import fr.inrialpes.exmo.align.impl.Extensions; import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; -import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.semanticweb.owl.align.AlignmentException; @@ -16,14 +16,10 @@ import org.semanticweb.owl.align.AlignmentException; * * @author Nicolas Guillouet <nicolas@meaningengines.com> */ -public class Linkkey { - public static final String PLAIN = "plain"; - public static final String WEAK = "weak"; - public static final String STRONG = "strong"; - private static List<String> ALLOWED_TYPES = Arrays.asList(PLAIN, WEAK, STRONG); +public class Linkkey implements Extensable{ - private String type; private Set<LinkkeyBinding> bindings; + protected Extensions extensions = null; public void accept(EDOALVisitor visitor) throws AlignmentException { visitor.visit(this); @@ -33,18 +29,11 @@ public class Linkkey { return visitor.visit(this); } - public Linkkey() throws AlignmentException { - this(PLAIN); - } - - public Linkkey(String type) throws AlignmentException { - if(!ALLOWED_TYPES.contains(type)){ - throw new AlignmentException("The type " + type + " is not allowed !"); - } - this.type = type; + public Linkkey() { bindings = new HashSet<>(); } + public void addBinding(LinkkeyBinding binding){ bindings.add(binding); } @@ -53,7 +42,25 @@ public class Linkkey { return bindings; } - public String getType() { - return type; + + public Collection<String[]> getExtensions(){ + if ( extensions != null ) return extensions.getValues(); + else return null; } + public void setExtensions( Extensions p ){ + extensions = p; + } + + public void setExtension( String uri, String label, String value ) { + if ( extensions == null ) extensions = new Extensions(); + extensions.setExtension( uri, label, value ); + }; + + public String getExtension( String uri, String label ) { + if ( extensions != null ) { + return extensions.getExtension( uri, label ); + } else { + return (String)null; + } + }; } diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyBinding.java b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyBinding.java index 94d75d2337714d1436d66c63aaae07c4f92c7100..8ecb9d093afbf07123da95181a910f236df5c753 100644 --- a/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyBinding.java +++ b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyBinding.java @@ -6,39 +6,22 @@ package fr.inrialpes.exmo.align.impl.edoal; -import fr.inrialpes.exmo.align.parser.TypeCheckingVisitor; -import java.util.Arrays; -import java.util.List; import org.semanticweb.owl.align.AlignmentException; -import org.semanticweb.owl.align.AlignmentVisitor; -import org.semanticweb.owl.align.Visitable; /** * * @author Nicolas Guillouet <nicolas@meaningengines.com> */ -public class LinkkeyBinding { - public static final String IN = "in"; - public static final String EQ = "eq"; - private static List<String> ALLOWED_TYPES = Arrays.asList(IN, EQ); +public abstract class LinkkeyBinding { private PathExpression expression1; private PathExpression expression2; - private String type; - public LinkkeyBinding(PathExpression expression1, PathExpression expression2, String type) throws AlignmentException { - if(!ALLOWED_TYPES.contains(type)){ - throw new AlignmentException("The type " + type + " is not allowed !"); - } - this.type = type; + public LinkkeyBinding(PathExpression expression1, PathExpression expression2) throws AlignmentException { this.expression1 = expression1; this.expression2 = expression2; } - - - public String getType(){ - return type; - } + public PathExpression getExpression1(){ return expression1; @@ -46,4 +29,7 @@ public class LinkkeyBinding { public PathExpression getExpression2(){ return expression2; } + + public abstract void accept( EDOALVisitor visitor ) throws AlignmentException; + } diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyEquals.java b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyEquals.java new file mode 100644 index 0000000000000000000000000000000000000000..c52ed8bae85f5df3e62d7b20f973730e0f42ea11 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyEquals.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package fr.inrialpes.exmo.align.impl.edoal; + +import org.semanticweb.owl.align.AlignmentException; + +/** + * + * @author Nicolas Guillouet <nicolas@meaningengines.com> + */ +public class LinkkeyEquals extends LinkkeyBinding{ + + public LinkkeyEquals(PathExpression expression1, PathExpression expression2) throws AlignmentException { + super(expression1, expression2); + } + + public void accept( EDOALVisitor visitor ) throws AlignmentException { + visitor.visit( this ); + } +} diff --git a/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyIntersects.java b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyIntersects.java new file mode 100644 index 0000000000000000000000000000000000000000..13fc58fbdda065b6e56ddd3d99099dba0d211290 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/edoal/LinkkeyIntersects.java @@ -0,0 +1,24 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package fr.inrialpes.exmo.align.impl.edoal; + +import org.semanticweb.owl.align.AlignmentException; + +/** + * + * @author Nicolas Guillouet <nicolas@meaningengines.com> + */ +public class LinkkeyIntersects extends LinkkeyBinding{ + + public LinkkeyIntersects(PathExpression expression1, PathExpression expression2) throws AlignmentException { + super(expression1, expression2); + } + + public void accept( EDOALVisitor visitor ) throws AlignmentException { + visitor.visit( this ); + } +} diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/JSONRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/JSONRendererVisitor.java index cd190250ff6599fd4e6846ca0556c51dbc5613fe..9c72611c268e852f8870e88da12771a6b4c34f8f 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/JSONRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/JSONRendererVisitor.java @@ -69,6 +69,9 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; import fr.inrialpes.exmo.align.impl.edoal.EDOALVisitor; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; +import java.util.Collection; /** * Renders an alignment in JSON (and in fact in JSON-LD) IETF RFC 7159 + @@ -311,12 +314,7 @@ public class JSONRendererVisitor extends IndentedRendererVisitor implements Alig writer.print("," + NL); indentedOutput("\"" + SyntaxElement.SEMANTICS.print(DEF) + "\" : \"" + cell.getSemantics() + "\""); } - if (cell.getExtensions() != null) { - for (String[] ext : cell.getExtensions()) { - writer.print("," + NL); - indentedOutputln(ext[1] + " : \"" + ext[2] + "\""); - } - } + printAnnotations(cell.getExtensions()); decreaseIndent(); writer.print(NL); indentedOutput("}"); @@ -724,7 +722,6 @@ public class JSONRendererVisitor extends IndentedRendererVisitor implements Alig public void visit(final Linkkey linkkey) throws AlignmentException { indentedOutputln("{ \"@type\" : \"" + SyntaxElement.LINKKEY.print(DEF) + "\","); increaseIndent(); - indentedOutputln("\"" + SyntaxElement.EDOAL_TYPE.print(DEF) + "\" : \"" + linkkey.getType() + "\","); indentedOutputln("\"" + SyntaxElement.LINKKEY_BINDING.print(DEF) + "\" : ["); increaseIndent(); boolean first = true; @@ -734,21 +731,9 @@ public class JSONRendererVisitor extends IndentedRendererVisitor implements Alig } else { writer.print("," + NL); } - indentedOutputln("{ \"@type\" : \"" + SyntaxElement.CORRESP.print(DEF) + "\","); - increaseIndent(); - indentedOutputln("\"" + SyntaxElement.EDOAL_TYPE.print(DEF) + "\" : \"" + linkkeyBinding.getType() + "\","); - indentedOutputln("\"" + SyntaxElement.CORRESP_PROPERTY1.print(DEF) + "\" :"); - increaseIndent(); - linkkeyBinding.getExpression1().accept(this); - writer.print("," + NL); - decreaseIndent(); - indentedOutputln("\"" + SyntaxElement.CORRESP_PROPERTY2.print(DEF) + "\" :"); increaseIndent(); - linkkeyBinding.getExpression2().accept(this); - decreaseIndent(); - writer.print(NL); + linkkeyBinding.accept(this); decreaseIndent(); - indentedOutput("}"); } writer.print(NL); decreaseIndent(); @@ -757,4 +742,38 @@ public class JSONRendererVisitor extends IndentedRendererVisitor implements Alig indentedOutput("}"); } + private void visitLinkKeyBinding(LinkkeyBinding linkkeyBinding, SyntaxElement syntaxElement) throws AlignmentException { + indentedOutputln("{ \"@type\" : \"" + syntaxElement.print(DEF) + "\","); + increaseIndent(); + indentedOutputln("\"" + SyntaxElement.LINKEY_PROPERTY1.print(DEF) + "\" :"); + increaseIndent(); + linkkeyBinding.getExpression1().accept(this); + writer.print("," + NL); + decreaseIndent(); + indentedOutputln("\"" + SyntaxElement.LINKEY_PROPERTY2.print(DEF) + "\" :"); + increaseIndent(); + linkkeyBinding.getExpression2().accept(this); + decreaseIndent(); + writer.print(NL); + decreaseIndent(); + indentedOutput("}"); + } + + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { + visitLinkKeyBinding(linkkeyEquals, SyntaxElement.LINKEY_EQUALS); + } + + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { + visitLinkKeyBinding(linkkeyIntersects, SyntaxElement.LINKEY_INTERSECTS); + } + + private void printAnnotations(Collection<String[]> extensions) { + if (extensions != null) { + for (String[] ext : extensions) { + writer.print("," + NL); + indentedOutputln(ext[1] + " : \"" + ext[2] + "\""); + } + } + } + } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java index 3f2ee321b0423d6b6b11372f9dd531138476bbcd..bf5d6cb14021b1221d3c3c1e4bf2bb846a3e8440 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/OWLAxiomsRendererVisitor.java @@ -83,6 +83,8 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; import fr.inrialpes.exmo.align.impl.edoal.EDOALVisitor; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; /** * Renders an alignment as a new ontology merging these. @@ -855,4 +857,10 @@ public class OWLAxiomsRendererVisitor extends IndentedRendererVisitor implements public void visit(final LinkkeyBinding linkkeyBinding) throws AlignmentException { throw new AlignmentException("NOT IMPLEMENTED !"); } + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java index 3350d5c6ed89803a79fe62ed58dc04315e513c09..713aaa640e8aa9486e78c4e013a361bf0abe70b0 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/RDFRendererVisitor.java @@ -72,6 +72,9 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; import fr.inrialpes.exmo.align.impl.edoal.EDOALVisitor; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; +import java.util.Collection; /** * Renders an alignment in its RDF format @@ -717,28 +720,62 @@ public class RDFRendererVisitor extends IndentedRendererVisitor implements Align public void visit(final Linkkey linkkey) throws AlignmentException { indentedOutputln("<" + SyntaxElement.LINKKEYS.print(DEF) + ">"); increaseIndent(); - indentedOutput("<" + SyntaxElement.LINKKEY.print(DEF) + " " + SyntaxElement.EDOAL_TYPE.print(DEF) + "=\"" + linkkey.getType() + "\">" + NL); + indentedOutput("<" + SyntaxElement.LINKKEY.print(DEF) + ">" + NL); + Collection<String[]> extensions = linkkey.getExtensions(); +// nslist.put(Namespace.EDOAL.prefix, Namespace.EDOAL.shortCut); +// if (extensions != null) { +// printAnnotations(extensions); +// } + increaseIndent(); for (LinkkeyBinding linkkeyBinding : linkkey.bindings()) { indentedOutputln("<" + SyntaxElement.LINKKEY_BINDING.print(DEF) + ">"); increaseIndent(); - indentedOutput("<" + SyntaxElement.CORRESP.print(DEF) + " " + SyntaxElement.EDOAL_TYPE.print(DEF) + "=\"" + linkkeyBinding.getType() + "\">" + NL); - increaseIndent(); - indentedOutputln("<" + SyntaxElement.CORRESP_PROPERTY1.print(DEF) + ">"); - linkkeyBinding.getExpression1().accept(this); - indentedOutputln("</" + SyntaxElement.CORRESP_PROPERTY1.print(DEF) + ">"); - indentedOutputln("<" + SyntaxElement.CORRESP_PROPERTY2.print(DEF) + ">"); - linkkeyBinding.getExpression2().accept(this); - indentedOutputln("</" + SyntaxElement.CORRESP_PROPERTY2.print(DEF) + ">"); - decreaseIndent(); - indentedOutput("</" + SyntaxElement.CORRESP.print(DEF) + ">" + NL); + linkkeyBinding.accept(this); decreaseIndent(); indentedOutputln("</" + SyntaxElement.LINKKEY_BINDING.print(DEF) + ">"); -// linkkeyBinding.accept(this); } decreaseIndent(); indentedOutput("</" + SyntaxElement.LINKKEY.print(DEF) + ">" + NL); decreaseIndent(); indentedOutputln("</" + SyntaxElement.LINKKEYS.print(DEF) + ">"); } + + private void visitLinkKeyBinding(LinkkeyBinding linkkeyBinding, SyntaxElement syntaxElement) throws AlignmentException { + indentedOutput("<" + syntaxElement.print(DEF) + ">" + NL); + increaseIndent(); + indentedOutputln("<" + SyntaxElement.LINKEY_PROPERTY1.print(DEF) + ">"); + linkkeyBinding.getExpression1().accept(this); + indentedOutputln("</" + SyntaxElement.LINKEY_PROPERTY1.print(DEF) + ">"); + indentedOutputln("<" + SyntaxElement.LINKEY_PROPERTY2.print(DEF) + ">"); + linkkeyBinding.getExpression2().accept(this); + indentedOutputln("</" + SyntaxElement.LINKEY_PROPERTY2.print(DEF) + ">"); + decreaseIndent(); + indentedOutput("</" + syntaxElement.print(DEF) + ">" + NL); + } + + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { + visitLinkKeyBinding(linkkeyEquals, SyntaxElement.LINKEY_EQUALS); + } + + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { + visitLinkKeyBinding(linkkeyIntersects, SyntaxElement.LINKEY_INTERSECTS); + } + + private void printAnnotations(Collection<String[]> extensions) { + for (String[] ext : extensions) { + String uri = ext[0]; + String tag = nslist.get(uri); + if (tag == null) { + tag = ext[1]; + // That's heavy. + // Maybe adding an extra: ns extension in the alignment at parsing time + // would help redisplaying it better... + indentedOutputln("<alignapilocalns:" + tag + " xmlns:alignapilocalns=\"" + uri + "\">" + ext[2] + "</alignapilocalns:" + tag + ">"); + } else { + tag += ":" + ext[1]; + indentedOutputln("<" + tag + ">" + ext[2] + "</" + tag + ">"); + } + } + } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java index c4c28ffbf21f1d545c4d861c698208ae3fe21b5f..15ecfedd63fa816fa6bbad7ec7bf8ad8c3c481e4 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SILKRendererVisitor.java @@ -35,6 +35,8 @@ import fr.inrialpes.exmo.align.impl.BasicAlignment; import fr.inrialpes.exmo.align.impl.edoal.Expression; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; import java.net.URI; import java.util.Enumeration; @@ -262,4 +264,10 @@ public class SILKRendererVisitor extends GraphPatternRendererVisitor implements throw new AlignmentException("NOT IMPLEMENTED !"); } + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java index e00ec0264a605b4eae01f214882052737e552820..bf84109f5a66206eae0e5257a999860d08583cf9 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java @@ -30,6 +30,8 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; import fr.inrialpes.exmo.align.impl.edoal.Expression; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; import java.io.PrintWriter; import java.net.URI; @@ -148,7 +150,10 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor throw new AlignmentException("NOT IMPLEMENTED !"); } - public void visit(final LinkkeyBinding linkkeyBinding) throws AlignmentException { + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { throw new AlignmentException("NOT IMPLEMENTED !"); } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java index cc2762c81cb3547b06e45bbf397f14428f67218c..18c84673a0ea5c911d23e2feea0c0178bb90d986 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java @@ -30,10 +30,11 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; import fr.inrialpes.exmo.align.impl.edoal.Expression; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; import java.io.PrintWriter; import java.net.URI; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; @@ -138,7 +139,14 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp throw new AlignmentException("NOT IMPLEMENTED !"); } - public void visit(final LinkkeyBinding linkkeyBinding) throws AlignmentException { + public void visit(final LinkkeyEquals linkkeyEquals) throws AlignmentException { throw new AlignmentException("NOT IMPLEMENTED !"); } + public void visit(final LinkkeyIntersects linkkeyIntersects) throws AlignmentException { + throw new AlignmentException("NOT IMPLEMENTED !"); + } + +// public void visit(final LinkkeyBinding linkkeyBinding) throws AlignmentException { +// throw new AlignmentException("NOT IMPLEMENTED !"); +// } } diff --git a/src/fr/inrialpes/exmo/align/parser/RDFParser.java b/src/fr/inrialpes/exmo/align/parser/RDFParser.java index f9eed4f2d98a8f253282678ee04ae40a49ad6450..4ec703f9a0502b624b34ba90370547e2aa1f0b19 100644 --- a/src/fr/inrialpes/exmo/align/parser/RDFParser.java +++ b/src/fr/inrialpes/exmo/align/parser/RDFParser.java @@ -89,9 +89,11 @@ import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.vocabulary.RDF; +import fr.inrialpes.exmo.align.impl.edoal.Extensable; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; -import java.io.StringWriter; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; /** * <p> @@ -457,14 +459,11 @@ public class RDFParser { throw new NullPointerException("The node must not be null"); } try { - // parsing type - Statement stmt = node.getProperty((Property) SyntaxElement.EDOAL_TYPE.resource); - if (stmt == null) { - throw new AlignmentException("Required " + SyntaxElement.EDOAL_TYPE.print() + " property in Linkkey"); - } - String type = stmt.getLiteral().toString(); - Linkkey linkkey = new Linkkey(type); + Linkkey linkkey = new Linkkey(); + // parsing annotations (type, ...) + parseAnnotation(node.getProperty((Property) SyntaxElement.EDOAL_TYPE.resource), linkkey); + //Parsing bindings StmtIterator stmtIt = node.listProperties((Property) SyntaxElement.LINKKEY_BINDING.resource); while (stmtIt.hasNext()) { Statement bindingStmt = stmtIt.nextStatement(); @@ -480,24 +479,33 @@ public class RDFParser { } } + /** + * + * @param node + * @return + * @throws AlignmentException + */ protected LinkkeyBinding parseLinkkeyBinding(final Resource node) throws AlignmentException { if (node == null) { throw new NullPointerException("The node must not be null"); } try { - Statement bindingTypeStmt = node.getProperty((Property) SyntaxElement.EDOAL_TYPE.resource); - if (bindingTypeStmt == null) { - throw new AlignmentException("Required " + SyntaxElement.EDOAL_TYPE.print() + " property in Corresp"); - } - String bindingType = bindingTypeStmt.getLiteral().toString(); - Statement property1Stmt = node.getProperty((Property) SyntaxElement.CORRESP_PROPERTY1.resource); - Statement property2Stmt = node.getProperty((Property) SyntaxElement.CORRESP_PROPERTY2.resource); + Statement property1Stmt = node.getProperty((Property) SyntaxElement.LINKEY_PROPERTY1.resource); + Statement property2Stmt = node.getProperty((Property) SyntaxElement.LINKEY_PROPERTY2.resource); if (property1Stmt == null || property2Stmt == null) { - throw new AlignmentException("Required " + SyntaxElement.CORRESP_PROPERTY1.print() + " and " + SyntaxElement.CORRESP_PROPERTY2.print() + " properties in Linkkey binding corresp."); + throw new AlignmentException("Required " + SyntaxElement.LINKEY_PROPERTY1.print() + " and " + SyntaxElement.LINKEY_PROPERTY2.print() + " properties in Linkkey binding corresp."); } PathExpression pathExpression1 = parsePathExpression(property1Stmt.getResource()); PathExpression pathExpression2 = parsePathExpression(property2Stmt.getResource()); - return new LinkkeyBinding(pathExpression1, pathExpression2, bindingType); + + Resource rdfType = node.getProperty(RDF.type).getResource(); + if (rdfType.equals(SyntaxElement.LINKEY_EQUALS.resource)) { + return new LinkkeyEquals(pathExpression1, pathExpression2); + } else if (rdfType.equals(SyntaxElement.LINKEY_INTERSECTS.resource)) { + return new LinkkeyIntersects(pathExpression1, pathExpression2); + } else { + throw new Exception("Unknown type linkey binding : " + rdfType); + } } catch (Exception e) { //wrap other type exception throw new AlignmentException("Cannot parse linkkey " + node, e); } @@ -999,10 +1007,10 @@ public class RDFParser { * Parses a given annotaion in the the given node. * * @param stmt the annotation statement - * @param al the alignment in which the annotation is + * @param extensable * @throws NullPointerException if the node or the element is null */ - protected void parseAnnotation(final Statement stmt, EDOALAlignment al) throws AlignmentException { + protected void parseAnnotation(final Statement stmt, Extensable extensable) throws AlignmentException { try { final String anno = stmt.getString(); if ((anno != null) && (anno.length() > 0)) { @@ -1017,7 +1025,7 @@ public class RDFParser { prefix += "#"; } // This will not work for stuff like dc:creator which has no fragment! - al.setExtension(prefix, name, anno); + extensable.setExtension(prefix, name, anno); } } catch (Exception e1) { // It would be better to silently ignore annotations diff --git a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java index 0aebc1f62475d34be58d28679f7d0c1561b7e9b2..38cc60af20b0156a9fdbf9d50fd6e08e3013842d 100644 --- a/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java +++ b/src/fr/inrialpes/exmo/align/parser/SyntaxElement.java @@ -20,7 +20,6 @@ * 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.parser; import java.util.HashMap; @@ -38,260 +37,287 @@ import org.semanticweb.owl.align.AlignmentException; * <p> * $Id$ * </p> - * + * * @author richi * @version $Revision: 1.6 $ */ - public enum SyntaxElement { // RDF NAMESPACE // RDF NAMESPACE - RDF( Namespace.RDF, "RDF", true), // This is not a resource, nor a property - RDF_ID( Namespace.RDF, "ID"), - RDF_ABOUT( Namespace.RDF, "about"), - RDF_DATATYPE( Namespace.RDF, "datatype"), - RDF_PARSETYPE( Namespace.RDF, "parseType"), - RDF_RESOURCE( Namespace.RDF, "resource"), - +// RDF NAMESPACE +// RDF NAMESPACE +// RDF NAMESPACE +// RDF NAMESPACE +// RDF NAMESPACE +// RDF NAMESPACE + RDF(Namespace.RDF, "RDF", true), // This is not a resource, nor a property + RDF_ID(Namespace.RDF, "ID"), + RDF_ABOUT(Namespace.RDF, "about"), + RDF_DATATYPE(Namespace.RDF, "datatype"), + RDF_PARSETYPE(Namespace.RDF, "parseType"), + RDF_RESOURCE(Namespace.RDF, "resource"), // DUBLINCORE NAMESPACE - CREATOR( Namespace.DUBLIN_CORE, "creator"), - DATE( Namespace.DUBLIN_CORE, "date"), - IDENTIFIER( Namespace.DUBLIN_CORE, "identifier"), - + CREATOR(Namespace.DUBLIN_CORE, "creator"), + DATE(Namespace.DUBLIN_CORE, "date"), + IDENTIFIER(Namespace.DUBLIN_CORE, "identifier"), // ALIGNMENT NAMESPACE - ONTOLOGYNETWORK(Namespace.ALIGNMENT, "OntologyNetwork", true), - ONID( Namespace.ALIGNMENT, "id"), - ONONTOLOGY( Namespace.ALIGNMENT, "ontology"), - ONALIGNMENT( Namespace.ALIGNMENT, "alignment"), - ALIGNMENT( Namespace.ALIGNMENT, "Alignment", true), - ALID( Namespace.ALIGNMENT, "id"), - CELL( Namespace.ALIGNMENT, "Cell", true), - CERTIFICATE( Namespace.ALIGNMENT, "certificate"), - FORMALISM( Namespace.ALIGNMENT, "Formalism", true), - FORMATT( Namespace.ALIGNMENT, "formalism"), - CELLID( Namespace.ALIGNMENT, "id"), - LEVEL( Namespace.ALIGNMENT, "level"), - LIMITATIONS( Namespace.ALIGNMENT, "limitations"), - MAP( Namespace.ALIGNMENT, "map"), - MAPPING_SOURCE( Namespace.ALIGNMENT, "onto1"), - MAPPING_TARGET( Namespace.ALIGNMENT, "onto2"), - MEASURE( Namespace.ALIGNMENT, "measure"), - METHOD( Namespace.ALIGNMENT, "method"), - NAME( Namespace.ALIGNMENT, "name"), - PURPOSE( Namespace.ALIGNMENT, "purpose"), - RULE_RELATION( Namespace.ALIGNMENT, "relation"), - SEMANTICS( Namespace.ALIGNMENT, "semantics"), - ENTITY1( Namespace.ALIGNMENT, "entity1"), - ENTITY2( Namespace.ALIGNMENT, "entity2"), - TIME( Namespace.ALIGNMENT, "time"), - TYPE( Namespace.ALIGNMENT, "type"), - URI( Namespace.ALIGNMENT, "uri"), - XML( Namespace.ALIGNMENT, "xml"), - ONTOLOGY( Namespace.ALIGNMENT, "Ontology", true ), - LOCATION( Namespace.ALIGNMENT, "location"), - + ONTOLOGYNETWORK(Namespace.ALIGNMENT, "OntologyNetwork", true), + ONID(Namespace.ALIGNMENT, "id"), + ONONTOLOGY(Namespace.ALIGNMENT, "ontology"), + ONALIGNMENT(Namespace.ALIGNMENT, "alignment"), + ALIGNMENT(Namespace.ALIGNMENT, "Alignment", true), + ALID(Namespace.ALIGNMENT, "id"), + CELL(Namespace.ALIGNMENT, "Cell", true), + CERTIFICATE(Namespace.ALIGNMENT, "certificate"), + FORMALISM(Namespace.ALIGNMENT, "Formalism", true), + FORMATT(Namespace.ALIGNMENT, "formalism"), + CELLID(Namespace.ALIGNMENT, "id"), + LEVEL(Namespace.ALIGNMENT, "level"), + LIMITATIONS(Namespace.ALIGNMENT, "limitations"), + MAP(Namespace.ALIGNMENT, "map"), + MAPPING_SOURCE(Namespace.ALIGNMENT, "onto1"), + MAPPING_TARGET(Namespace.ALIGNMENT, "onto2"), + MEASURE(Namespace.ALIGNMENT, "measure"), + METHOD(Namespace.ALIGNMENT, "method"), + NAME(Namespace.ALIGNMENT, "name"), + PURPOSE(Namespace.ALIGNMENT, "purpose"), + RULE_RELATION(Namespace.ALIGNMENT, "relation"), + SEMANTICS(Namespace.ALIGNMENT, "semantics"), + ENTITY1(Namespace.ALIGNMENT, "entity1"), + ENTITY2(Namespace.ALIGNMENT, "entity2"), + TIME(Namespace.ALIGNMENT, "time"), + TYPE(Namespace.ALIGNMENT, "type"), + URI(Namespace.ALIGNMENT, "uri"), + XML(Namespace.ALIGNMENT, "xml"), + ONTOLOGY(Namespace.ALIGNMENT, "Ontology", true), + LOCATION(Namespace.ALIGNMENT, "location"), // EDOAL NAMESPACE - AND( Namespace.EDOAL, "and", Constructor.AND), - APPLY( Namespace.EDOAL, "Apply", true), - ARGUMENTS( Namespace.EDOAL, "arguments"), - ATTR_TRANSF( Namespace.EDOAL, "transf"), - CLASS_EXPR( Namespace.EDOAL, "Class", true),//ALIGNMENT - COMPARATOR( Namespace.EDOAL, "comparator"), - COMPOSE( Namespace.EDOAL, "compose", Constructor.COMP), - EDATATYPE( Namespace.EDOAL, "datatype"), - DATATYPE( Namespace.EDOAL, "Datatype"), - DOMAIN_RESTRICTION(Namespace.EDOAL, "AttributeDomainRestriction", true), - //ID( Namespace.EDOAL, "Id", true), // Useless - INSTANCE_EXPR( Namespace.EDOAL, "Instance", true), - INVERSE( Namespace.EDOAL, "inverse", Constructor.INVERSE), - LITERAL( Namespace.EDOAL, "Literal", true), - NOT( Namespace.EDOAL, "not", Constructor.NOT), - ONPROPERTY( Namespace.EDOAL, "onAttribute"), - OPERATOR( Namespace.EDOAL, "operator"), - OR( Namespace.EDOAL, "or", Constructor.OR), - //PARAMETERS( Namespace.EDOAL, "parameters"), - //PROPERTY( Namespace.EDOAL, "Property", true), // ?? - PROPERTY_EXPR( Namespace.EDOAL, "Property"), - OCCURENCE_COND(Namespace.EDOAL, "AttributeOccurenceRestriction", true), - PROPERTY_TYPE_COND(Namespace.EDOAL, "PropertyTypeRestriction", true), - PROPERTY_DOMAIN_COND(Namespace.EDOAL, "PropertyDomainRestriction", true), - PROPERTY_VALUE_COND( Namespace.EDOAL, "PropertyValueRestriction", true), - RELATION_DOMAIN_COND(Namespace.EDOAL, "RelationDomainRestriction", true), - RELATION_CODOMAIN_COND(Namespace.EDOAL, "RelationCoDomainRestriction", true), - REFLEXIVE( Namespace.EDOAL, "reflexive", Constructor.REFLEXIVE), - RELATION_EXPR( Namespace.EDOAL, "Relation", true), - //SERVICE( Namespace.EDOAL, "service"), - STRING( Namespace.EDOAL, "string"), - ETYPE( Namespace.EDOAL, "type"), - SYMMETRIC( Namespace.EDOAL, "symmetric", Constructor.SYMMETRIC), - TOCLASS( Namespace.EDOAL, "class"), - ALL( Namespace.EDOAL, "all"), - EXISTS( Namespace.EDOAL, "exists"), - TRENT1( Namespace.EDOAL, "entity1"), - TRENT2( Namespace.EDOAL, "entity2"), - TRANSF( Namespace.EDOAL, "Transformation", true), - TRDIR( Namespace.EDOAL, "direction"), - TRANSFORMATION( Namespace.EDOAL, "transformation"), - LINKKEYS( Namespace.EDOAL, "linkkey", true), - LINKKEY( Namespace.EDOAL, "Linkkey"), - LINKKEY_BINDING( Namespace.EDOAL, "binding"), - CORRESP( Namespace.EDOAL, "Corresp"), - CORRESP_PROPERTY1( Namespace.EDOAL, "property1"), - CORRESP_PROPERTY2( Namespace.EDOAL, "property2"), - EDOAL_TYPE( Namespace.EDOAL, "type"), - TRANSITIVE( Namespace.EDOAL, "transitive", Constructor.TRANSITIVE), - TYPE_COND(Namespace.EDOAL, "AttributeTypeRestriction", true), // undocumented - VALUE( Namespace.EDOAL, "value"), - VAR( Namespace.EDOAL, "var"), - VALUE_COND(Namespace.EDOAL, "AttributeValueRestriction", true), - ; + AND(Namespace.EDOAL, "and", Constructor.AND), + APPLY(Namespace.EDOAL, "Apply", true), + ARGUMENTS(Namespace.EDOAL, "arguments"), + ATTR_TRANSF(Namespace.EDOAL, "transf"), + CLASS_EXPR(Namespace.EDOAL, "Class", true),//ALIGNMENT + COMPARATOR(Namespace.EDOAL, "comparator"), + COMPOSE(Namespace.EDOAL, "compose", Constructor.COMP), + EDATATYPE(Namespace.EDOAL, "datatype"), + DATATYPE(Namespace.EDOAL, "Datatype"), + DOMAIN_RESTRICTION(Namespace.EDOAL, "AttributeDomainRestriction", true), + //ID( Namespace.EDOAL, "Id", true), // Useless + INSTANCE_EXPR(Namespace.EDOAL, "Instance", true), + INVERSE(Namespace.EDOAL, "inverse", Constructor.INVERSE), + LITERAL(Namespace.EDOAL, "Literal", true), + NOT(Namespace.EDOAL, "not", Constructor.NOT), + ONPROPERTY(Namespace.EDOAL, "onAttribute"), + OPERATOR(Namespace.EDOAL, "operator"), + OR(Namespace.EDOAL, "or", Constructor.OR), + //PARAMETERS( Namespace.EDOAL, "parameters"), + //PROPERTY( Namespace.EDOAL, "Property", true), // ?? + PROPERTY_EXPR(Namespace.EDOAL, "Property"), + OCCURENCE_COND(Namespace.EDOAL, "AttributeOccurenceRestriction", true), + PROPERTY_TYPE_COND(Namespace.EDOAL, "PropertyTypeRestriction", true), + PROPERTY_DOMAIN_COND(Namespace.EDOAL, "PropertyDomainRestriction", true), + PROPERTY_VALUE_COND(Namespace.EDOAL, "PropertyValueRestriction", true), + RELATION_DOMAIN_COND(Namespace.EDOAL, "RelationDomainRestriction", true), + RELATION_CODOMAIN_COND(Namespace.EDOAL, "RelationCoDomainRestriction", true), + REFLEXIVE(Namespace.EDOAL, "reflexive", Constructor.REFLEXIVE), + RELATION_EXPR(Namespace.EDOAL, "Relation", true), + //SERVICE( Namespace.EDOAL, "service"), + STRING(Namespace.EDOAL, "string"), + ETYPE(Namespace.EDOAL, "type"), + SYMMETRIC(Namespace.EDOAL, "symmetric", Constructor.SYMMETRIC), + TOCLASS(Namespace.EDOAL, "class"), + ALL(Namespace.EDOAL, "all"), + EXISTS(Namespace.EDOAL, "exists"), + TRENT1(Namespace.EDOAL, "entity1"), + TRENT2(Namespace.EDOAL, "entity2"), + TRANSF(Namespace.EDOAL, "Transformation", true), + TRDIR(Namespace.EDOAL, "direction"), + TRANSFORMATION(Namespace.EDOAL, "transformation"), + LINKKEYS(Namespace.EDOAL, "linkkey", true), + LINKKEY(Namespace.EDOAL, "Linkkey"), + LINKKEY_BINDING(Namespace.EDOAL, "binding"), + // CORRESP( Namespace.EDOAL, "Corresp"), + LINKEY_EQUALS(Namespace.EDOAL, "Equals"), + LINKEY_INTERSECTS(Namespace.EDOAL, "Intersects"), + LINKEY_PROPERTY1(Namespace.EDOAL, "property1"), + LINKEY_PROPERTY2(Namespace.EDOAL, "property2"), + EDOAL_TYPE(Namespace.EDOAL, "type"), + TRANSITIVE(Namespace.EDOAL, "transitive", Constructor.TRANSITIVE), + TYPE_COND(Namespace.EDOAL, "AttributeTypeRestriction", true), // undocumented + VALUE(Namespace.EDOAL, "value"), + VAR(Namespace.EDOAL, "var"), + VALUE_COND(Namespace.EDOAL, "AttributeValueRestriction", true),; - /** Operator to determine how to combine the expressions */ + /** + * Operator to determine how to combine the expressions + */ public enum Constructor { - AND, OR, NOT, COMP, JOIN, SYMMETRIC, REFLEXIVE, TRANSITIVE, INVERSE - }; + + AND, OR, NOT, COMP, JOIN, SYMMETRIC, REFLEXIVE, TRANSITIVE, INVERSE + }; private static Map<String, SyntaxElement> register; - /** Holds the xml name for the element. */ + /** + * Holds the xml name for the element. + */ public final String name; - /** Holds the namespace for the element. */ + /** + * Holds the namespace for the element. + */ public final Namespace namespace; - - /** Holds the corresponding operator in the . */ + + /** + * Holds the corresponding operator in the . + */ public final Constructor operator; - - /** Holds the RDF Resource or property for the entity - * This is to be used by the RDF parser. + + /** + * Holds the RDF Resource or property for the entity This is to be used by + * the RDF parser. */ public Object resource; - /** If the resource is a property. + /** + * If the resource is a property. */ public final boolean isProperty; - private static void recordElement( final String name, final SyntaxElement el ) { - if ( register == null ) register = new HashMap<String, SyntaxElement>(); - register.put( name, el ); + private static void recordElement(final String name, final SyntaxElement el) { + if (register == null) { + register = new HashMap<String, SyntaxElement>(); + } + register.put(name, el); } /** * Constructor which takes the name and the namespace of the element. - * - * @param namespace - * for the element - * @param name - * for the element - * @throws NullPointerException - * if the name or the namespace is <code>null</code> + * + * @param namespace for the element + * @param name for the element + * @throws NullPointerException if the name or the namespace is + * <code>null</code> */ - private SyntaxElement( final Namespace ns, final String name, final Constructor op, final boolean prp ) { - if ((name == null) || (ns == null)) { - throw new NullPointerException("The name and the namespace must not be null"); - } - namespace = ns; - this.name = name; - isProperty = prp; - operator = op; - recordElement( name, this ); + private SyntaxElement(final Namespace ns, final String name, final Constructor op, final boolean prp) { + if ((name == null) || (ns == null)) { + throw new NullPointerException("The name and the namespace must not be null"); + } + namespace = ns; + this.name = name; + isProperty = prp; + operator = op; + recordElement(name, this); } private SyntaxElement(final Namespace namespace, final String name) { - this( namespace, name, (Constructor)null, true ); + this(namespace, name, (Constructor) null, true); } - + private SyntaxElement(final Namespace namespace, final String name, final boolean prp) { - this( namespace, name, (Constructor)null, prp ); + this(namespace, name, (Constructor) null, prp); } - - private SyntaxElement(final Namespace namespace, final String name, final Constructor op ) { - // constructors are properties... - this( namespace, name, op, true ); + + private SyntaxElement(final Namespace namespace, final String name, final Constructor op) { + // constructors are properties... + this(namespace, name, op, true); } /** * Determines an element given on a name string. The search will be - * case-sensitive. - * Good morning efficiency... - * - * @param s - * the string to search for + * case-sensitive. Good morning efficiency... + * + * @param s the string to search for * @return the element with the given string as name, or null, if any could - * be found - * @throws NullPointerException - * if the string is null + * be found + * @throws NullPointerException if the string is null */ - public static SyntaxElement getElementByName( final String s ) { - if ( s == null ) throw new NullPointerException("The string must not be null"); - for ( SyntaxElement e : SyntaxElement.values() ) { - if ( s.equals( e.getName() ) ) return e; - } - return null; + public static SyntaxElement getElementByName(final String s) { + if (s == null) { + throw new NullPointerException("The string must not be null"); + } + for (SyntaxElement e : SyntaxElement.values()) { + if (s.equals(e.getName())) { + return e; + } + } + return null; } - - public static SyntaxElement getSyntaxElement( final Namespace ns, final String s ) { - if ( s == null ) throw new NullPointerException("The string must not be null"); - for ( SyntaxElement e : SyntaxElement.values() ) { - if ( ns == e.getNamespace() && s.equals( e.getName() ) ) return e; - } - return null; + + public static SyntaxElement getSyntaxElement(final Namespace ns, final String s) { + if (s == null) { + throw new NullPointerException("The string must not be null"); + } + for (SyntaxElement e : SyntaxElement.values()) { + if (ns == e.getNamespace() && s.equals(e.getName())) { + return e; + } + } + return null; } - + /** * Returns the xml name of the element. - * + * * @return the name */ - public String getName() { return name; } + public String getName() { + return name; + } /** * Returns the namespace of the element. - * + * * @return the namespace */ - public Namespace getNamespace() { return namespace; } + public Namespace getNamespace() { + return namespace; + } /** * Returns the resource of the element. - * + * * @return the resource */ - public static Object getResource( String name ) throws AlignmentException { - if ( register == null ) throw new AlignmentException( "Non initialized Syntax resources" ); - return register.get( name ).resource; + public static Object getResource(String name) throws AlignmentException { + if (register == null) { + throw new AlignmentException("Non initialized Syntax resources"); + } + return register.get(name).resource; } /** * Returns the namespace of the element. - * + * * @return the namespace */ - public Constructor getOperator() { return operator; } + public Constructor getOperator() { + return operator; + } - public static SyntaxElement getElement( Constructor op ){ - for ( SyntaxElement e : SyntaxElement.values() ) { - if ( op.equals( e.getOperator() ) ) { - return e; - } - } - return null; + public static SyntaxElement getElement(Constructor op) { + for (SyntaxElement e : SyntaxElement.values()) { + if (op.equals(e.getOperator())) { + return e; + } + } + return null; } /** * Formats the element to a printable string. The resulting string will * consist of the sort form of the namespace and the name of the element * separated by a ':' e.g. <code>rdf:resource</code> - * + * * @return the formated string */ public String print() { - return namespace.getShortCut() + ":" + name; + return namespace.getShortCut() + ":" + name; } public String id() { - return namespace.getUriPrefix()+name; + return namespace.getUriPrefix() + name; } /** @@ -299,16 +325,16 @@ public enum SyntaxElement { * way with the difference, that if the given namespace matches the * namespace of the element, the formated string will not be prefixed bye * the namespace and ':'. - * - * @param namespace - * the namespace for which not to prefix the resulting string + * + * @param namespace the namespace for which not to prefix the resulting + * string * @return teh formated string * @see #print() */ - public String print( final Namespace namespace ) { - return (this.namespace == namespace) ? name : print(); + public String print(final Namespace namespace) { + return (this.namespace == namespace) ? name : print(); } - + /** * <p> * Prints a short description of the element. The format will be the @@ -317,10 +343,10 @@ public enum SyntaxElement { * <p> * A example string could be: <code>rdf:resource</code> * </p> + * * @return the description of the element */ public String toString() { - return print(); + return print(); } } - diff --git a/src/org/semanticweb/owl/align/Alignment.java b/src/org/semanticweb/owl/align/Alignment.java index a1e47adae11b24e468d865792eebc3f7fcdf0e96..67e0d097413de6ce3bbb3f20c8df118c09d76fcb 100644 --- a/src/org/semanticweb/owl/align/Alignment.java +++ b/src/org/semanticweb/owl/align/Alignment.java @@ -20,6 +20,7 @@ package org.semanticweb.owl.align; +import fr.inrialpes.exmo.align.impl.edoal.Extensable; import java.lang.Cloneable; import java.lang.Iterable; import java.util.Enumeration; @@ -38,7 +39,7 @@ import org.xml.sax.ContentHandler; */ -public interface Alignment extends Cloneable, Iterable<Cell>, Visitable { +public interface Alignment extends Cloneable, Iterable<Cell>, Visitable, Extensable { /** Initialize the alignement before using it **/ /** This should return an Alignment and not be void **/ @@ -152,15 +153,6 @@ public interface Alignment extends Cloneable, Iterable<Cell>, Visitable { public Set<Cell> getAlignCells1( Object ob ) throws AlignmentException; public Set<Cell> getAlignCells2( Object ob ) throws AlignmentException; - /** - * Extensions are a way to read and add other information (metadata) - * to the alignment structure itself. - * getExtensions returns a set of tripes: uri*label*value - * all three being String - */ - public Collection<String[]> getExtensions(); - public String getExtension( String uri, String label ); - public void setExtension( String uri, String label, String value ); public Enumeration<Cell> getElements(); public Iterator<Cell> iterator(); diff --git a/test/input/alignment2.rdf b/test/input/alignment2.rdf index fb633067e2e9459078b29b03f98310faafad9569..29222a4615fd6d112a091318057458e54667e1ad 100644 --- a/test/input/alignment2.rdf +++ b/test/input/alignment2.rdf @@ -44,26 +44,27 @@ <relation>=</relation> <measure rdf:datatype='http://www.w3.org/2001/XMLSchema#float'>1.0</measure> <edoal:linkkey> - <edoal:Linkkey edoal:type="weak"> + <edoal:Linkkey> + <edoal:type>weak</edoal:type> <edoal:binding> - <edoal:Corresp edoal:type="eq"> + <edoal:Equals> <edoal:property1> <edoal:Property rdf:about="http://purl.org/ontology/mo/opus" /> </edoal:property1> <edoal:property2> <edoal:Property rdf:about="http://exmo.inrialpes.fr/connectors#number" /> </edoal:property2> - </edoal:Corresp> + </edoal:Equals> </edoal:binding> <edoal:binding> - <edoal:Corresp edoal:type="in"> + <edoal:Intersects> <edoal:property1> <edoal:Property rdf:about="http://purl.org/ontology/mo/name" /> </edoal:property1> <edoal:property2> <edoal:Property rdf:about="http://exmo.inrialpes.fr/connectors#nom" /> </edoal:property2> - </edoal:Corresp> + </edoal:Intersects> </edoal:binding> </edoal:Linkkey> </edoal:linkkey> diff --git a/test/src/EDOALExportTest.java b/test/src/EDOALExportTest.java index 2c782699eb8446bde55464e49541cfbb08b91448..3921313c81bf1e1d527d7608150f0a8c370ef768 100644 --- a/test/src/EDOALExportTest.java +++ b/test/src/EDOALExportTest.java @@ -79,6 +79,8 @@ import fr.inrialpes.exmo.align.impl.edoal.Datatype; import fr.inrialpes.exmo.align.impl.edoal.Comparator; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; /** * These tests corresponds to the tests presented in the examples/omwg directory @@ -209,7 +211,7 @@ public class EDOALExportTest { writer.flush(); writer.close(); String str1 = stream.toString(); - assertEquals(str1.length(), 37076); + assertEquals(str1.length(), 36468); } @Test(groups = {"full", "omwg", "raw"}, dependsOnMethods = {"setUp"}) @@ -488,73 +490,48 @@ public class EDOALExportTest { // Assert.fail("HAVE TODO"); } -// @Test(groups = {"full", "omwg"}, dependsOnMethods = {"setUp"}) -// public void testExportLinkkeyBinding() throws Exception { -// LinkkeyBinding linkkeyBinding = new LinkkeyBinding(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2")), LinkkeyBinding.EQ); -// assertEquals(render(linkkeyBinding), -// "<edoal:binding>" -// + "<edoal:Corresp edoal:type=\"eq\">" -// + "<edoal:property1>" -// + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding1\"/>" -// + "</edoal:property1>" -// + "<edoal:property2>" -// + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding2\"/>" -// + "</edoal:property2>" -// + "</edoal:Corresp>" -// + "</edoal:binding>" -// ); -// linkkeyBinding = new LinkkeyBinding(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2")), LinkkeyBinding.IN); -// assertEquals(render(linkkeyBinding), -// "<edoal:binding>" -// + "<edoal:Corresp edoal:type=\"in\">" -// + "<edoal:property1>" -// + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding1\"/>" -// + "</edoal:property1>" -// + "<edoal:property2>" -// + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding2\"/>" -// + "</edoal:property2>" -// + "</edoal:Corresp>" -// + "</edoal:binding>" -// ); -// } @Test(groups = {"full", "omwg"}, dependsOnMethods = {"setUp"}) public void testExportLinkkey() throws Exception { //With EQ Linkkey linkkey = new Linkkey(); - LinkkeyBinding linkkeyBinding = new LinkkeyBinding(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2")), LinkkeyBinding.EQ); + LinkkeyBinding linkkeyBinding = new LinkkeyEquals(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2"))); linkkey.addBinding(linkkeyBinding); + linkkey.setExtension("http://ns.inria.org/edoal/1.0/#", "type", "plain"); assertEquals(render(linkkey), "<edoal:linkkey>" - + "<edoal:Linkkey edoal:type=\"plain\">" + + "<edoal:Linkkey>" +// + "<edoal:type>plain</edoal:type>" + "<edoal:binding>" - + "<edoal:Corresp edoal:type=\"eq\">" + + "<edoal:Equals>" + "<edoal:property1>" + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding1\"/>" + "</edoal:property1>" + "<edoal:property2>" + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding2\"/>" + "</edoal:property2>" - + "</edoal:Corresp>" + + "</edoal:Equals>" + "</edoal:binding>" + "</edoal:Linkkey>" + "</edoal:linkkey>" ); //With IN linkkey = new Linkkey(); - linkkeyBinding = new LinkkeyBinding(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2")), LinkkeyBinding.IN); + linkkeyBinding = new LinkkeyIntersects(new PropertyId(new URI("http://exmo.inrialpes.fr/binding1")), new PropertyId(new URI("http://exmo.inrialpes.fr/binding2"))); linkkey.addBinding(linkkeyBinding); + linkkey.setExtension("http://ns.inria.org/edoal/1.0/#", "type", "plain"); assertEquals(render(linkkey), "<edoal:linkkey>" - + "<edoal:Linkkey edoal:type=\"plain\">" + + "<edoal:Linkkey>" +// + "<edoal:type>plain</edoal:type>" + "<edoal:binding>" - + "<edoal:Corresp edoal:type=\"in\">" + + "<edoal:Intersects>" + "<edoal:property1>" + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding1\"/>" + "</edoal:property1>" + "<edoal:property2>" + "<edoal:Property rdf:about=\"http://exmo.inrialpes.fr/binding2\"/>" + "</edoal:property2>" - + "</edoal:Corresp>" + + "</edoal:Intersects>" + "</edoal:binding>" + "</edoal:Linkkey>" + "</edoal:linkkey>" @@ -586,12 +563,11 @@ public class EDOALExportTest { writer.flush(); writer.close(); stream.close(); - assertEquals(stream.toString(), - "<?xml version='1.0' encoding='utf-8' standalone='no'?><rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" + String stringToTest = "<?xml version='1.0' encoding='utf-8' standalone='no'?><rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema#'" + " xmlns:align='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" - + " xmlns:edoal='http://ns.inria.org/edoal/1.0/#'>" + + " xmlns:edoal='http://ns.inria.org/edoal/1.0/#'>" + "<Alignment rdf:about=\"http://asdf\"><xml>yes</xml><level>2EDOAL</level><type>**</type><id>http://asdf</id>" + "<onto1>" + "<Ontology rdf:about=\"http://source\"><location>http://source</location>" @@ -600,7 +576,8 @@ public class EDOALExportTest { + "<Ontology rdf:about=\"http://target\"><location>http://target</location>" + "<formalism><Formalism align:name=\"wsml\" align:uri=\"http://wsml\"/></formalism>" + "</Ontology>" + "</onto2>" - + "</Alignment>" + "</rdf:RDF>"); + + "</Alignment>" + "</rdf:RDF>"; + assertEquals(stream.toString(), stringToTest); doc.setType("1*"); stream = new ByteArrayOutputStream(); writer = new PrintWriter(new BufferedWriter( @@ -612,8 +589,7 @@ public class EDOALExportTest { writer.flush(); writer.close(); stream.close(); - assertEquals(stream.toString(), - "<?xml version='1.0' encoding='utf-8' standalone='no'?><rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" + stringToTest = "<?xml version='1.0' encoding='utf-8' standalone='no'?><rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" + " xmlns:xsd='http://www.w3.org/2001/XMLSchema#'" + " xmlns:align='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'" @@ -626,7 +602,8 @@ public class EDOALExportTest { + "<Ontology rdf:about=\"http://target\"><location>http://target</location>" + "<formalism><Formalism align:name=\"wsml\" align:uri=\"http://wsml\"/></formalism>" + "</Ontology>" + "</onto2>" - + "</Alignment>" + "</rdf:RDF>"); + + "</Alignment>" + "</rdf:RDF>"; + assertEquals(stream.toString(), stringToTest); } } diff --git a/test/src/EDOALParserTest.java b/test/src/EDOALParserTest.java index d2f96bc983cf7acdf40d66db45f8f613e5b4f366..35432ebfddb2e983a967a0e0b9c1165c82f9f247 100644 --- a/test/src/EDOALParserTest.java +++ b/test/src/EDOALParserTest.java @@ -18,10 +18,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +import fr.inrialpes.exmo.align.impl.Extensions; import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; import fr.inrialpes.exmo.align.impl.edoal.PropertyId; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -54,6 +56,7 @@ import static org.testng.Assert.assertFalse; public class EDOALParserTest { private AlignmentParser aparser1 = null; + protected Extensions extensions = null; @Test(groups = {"full", "omwg", "raw"}) @@ -89,7 +92,7 @@ public class EDOALParserTest { Set<Linkkey> linkkeys = cell.linkkeys(); assertEquals(linkkeys.size(), 1); Linkkey linkkey = linkkeys.iterator().next(); - assertEquals(linkkey.getType(), "weak"); + assertEquals(linkkey.getExtension("http://ns.inria.org/edoal/1.0/#", "type"), "weak"); Set<LinkkeyBinding> bindings = linkkey.bindings(); assertEquals(bindings.size(), 2); @@ -97,7 +100,7 @@ public class EDOALParserTest { LinkkeyBinding binding = bindingIter.next(); LinkkeyBinding firstBinding = null; LinkkeyBinding secondBinding = null; - if(binding.getType().equals("eq")){ + if(binding instanceof LinkkeyEquals){ firstBinding = binding; secondBinding = bindingIter.next(); } @@ -106,11 +109,9 @@ public class EDOALParserTest { secondBinding = binding; } - assertEquals(firstBinding.getType(), "eq"); assertEquals(((PropertyId)firstBinding.getExpression1()).getURI().toString(), "http://purl.org/ontology/mo/opus"); assertEquals(((PropertyId)firstBinding.getExpression2()).getURI().toString(), "http://exmo.inrialpes.fr/connectors#number"); - assertEquals(secondBinding.getType(), "in"); assertEquals(((PropertyId)secondBinding.getExpression1()).getURI().toString(), "http://purl.org/ontology/mo/name"); assertEquals(((PropertyId)secondBinding.getExpression2()).getURI().toString(), "http://exmo.inrialpes.fr/connectors#nom"); } @@ -150,7 +151,7 @@ public class EDOALParserTest { // They should be the same... (no because of invertion...) //assertEquals( str1, str2 ); // But have the same length - assertEquals(str1.length(), str2.length()); + assertEquals(str1.length(), str2.length(), "STR 1 : \n " + str1 + "STR2 : \n" + str2); } } diff --git a/test/src/EDOALTest.java b/test/src/EDOALTest.java index 76956a2d93cf720a9891d846a24a4f7dafa6d2f9..3d271555f0b3ef68af5eac1bee4851c768331413 100644 --- a/test/src/EDOALTest.java +++ b/test/src/EDOALTest.java @@ -32,6 +32,8 @@ import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; import fr.inrialpes.exmo.align.impl.edoal.Expression; import fr.inrialpes.exmo.align.impl.edoal.Linkkey; import fr.inrialpes.exmo.align.impl.edoal.LinkkeyBinding; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyEquals; +import fr.inrialpes.exmo.align.impl.edoal.LinkkeyIntersects; import fr.inrialpes.exmo.align.impl.edoal.PathExpression; import fr.inrialpes.exmo.align.impl.edoal.PropertyId; import fr.inrialpes.exmo.align.impl.rel.EquivRelation; @@ -147,24 +149,18 @@ public class EDOALTest { } */ @Test(groups = {"full", "omwg", "raw"}, dependsOnMethods = {"roundTripTest"}) public void linkkeyBindingTest() throws Exception { - String[] types = {"eq", "in"}; PathExpression expression1 = new PropertyId(new URI("http://exmo.inria.fr/RootElement1")); PathExpression expression2 = new PropertyId(new URI("http://exmo.inria.fr/RootElement2")); LinkkeyBinding linkkeyBinding = null; - for (String type : types) { - linkkeyBinding = new LinkkeyBinding(expression1, expression2, type); - assertEquals(linkkeyBinding.getExpression1(), expression1); - assertEquals(linkkeyBinding.getExpression2(), expression2); - assertEquals(type, linkkeyBinding.getType()); - } - - try { - new LinkkeyBinding(expression1, expression2, "toto"); - fail("AlignmentException should be raised !"); - } catch (AlignmentException aex) { - ;//OK - } + + linkkeyBinding = new LinkkeyEquals(expression1, expression2); + assertEquals(linkkeyBinding.getExpression1(), expression1); + assertEquals(linkkeyBinding.getExpression2(), expression2); + + linkkeyBinding = new LinkkeyIntersects(expression1, expression2); + assertEquals(linkkeyBinding.getExpression1(), expression1); + assertEquals(linkkeyBinding.getExpression2(), expression2); } @Test(groups = {"full", "omwg", "raw"}, dependsOnMethods = {"linkkeyBindingTest"}) @@ -174,36 +170,19 @@ public class EDOALTest { Expression expression2 = new ClassId("http://exmo.inria.fr/RootElement2"); EDOALCell cell = new EDOALCell("1", expression1, expression2, relation, 1.0); - //Testing type - assertEquals("weak", Linkkey.WEAK); - assertEquals("plain", Linkkey.PLAIN); - assertEquals("strong", Linkkey.STRONG); - String[] types = {"weak", "plain", "strong"}; - Linkkey linkkey = null; - for (String type : types) { - linkkey = new Linkkey(type); - assertEquals(type, linkkey.getType()); - cell.addLinkkey(linkkey); - } - assertEquals(3, cell.linkkeys().size()); - - linkkey = new Linkkey(); - assertEquals(Linkkey.PLAIN, linkkey.getType()); - try { - new Linkkey("toto"); - fail("AlignmentException should be raised !"); - } catch (AlignmentException aex) { - ;//OK - } - + Linkkey linkkey = new Linkkey(); //Tests on bindings - LinkkeyBinding linkkeyBinding1 = new LinkkeyBinding(new PropertyId(), new PropertyId(), LinkkeyBinding.IN); - LinkkeyBinding linkkeyBinding2 = new LinkkeyBinding(new PropertyId(), new PropertyId(), LinkkeyBinding.EQ); + LinkkeyBinding linkkeyBinding1 = new LinkkeyIntersects(new PropertyId(), new PropertyId()); + LinkkeyBinding linkkeyBinding2 = new LinkkeyEquals(new PropertyId(), new PropertyId()); linkkey.addBinding(linkkeyBinding1); linkkey.addBinding(linkkeyBinding2); Set<LinkkeyBinding> bindings = linkkey.bindings(); assertEquals(2, bindings.size()); assertTrue(bindings.contains(linkkeyBinding1)); assertTrue(bindings.contains(linkkeyBinding2)); + + //Tests on type + linkkey.setExtension("http://ns.inria.org/edoal/1.0/", "type", "weak"); + assertEquals("weak", linkkey.getExtension("http://ns.inria.org/edoal/1.0/", "type")); } } diff --git a/test/src/RendererTest.java b/test/src/RendererTest.java index 1de2b1ce1a0903ee22d0024596a5331cb9aea810..6a7368dde6a5c312921e26752296e44a01ef177d 100644 --- a/test/src/RendererTest.java +++ b/test/src/RendererTest.java @@ -46,7 +46,6 @@ import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.util.Properties; -import static org.testng.Assert.fail; public class RendererTest { @@ -80,7 +79,7 @@ public class RendererTest { alignment.render( renderer ); writer.flush(); writer.close(); - //System.err.println( stream.toString() ); +// System.err.println( stream.toString() ); assertTrue( valueSimilarTo( stream.toString().length(), 11563 ), "Rendered differently: expected "+11563+" but was "+stream.toString().length() ); Properties params = new Properties(); params.setProperty( "embedded", "1"); diff --git a/test/src/SPARQLSelectRendererVisitorTest.java b/test/src/SPARQLSelectRendererVisitorTest.java index d268d42b35d8ef1fb94e99dacd9c4c95d2816362..e110cd71cd0d91f8a55cc744b3588abc1cef2718 100644 --- a/test/src/SPARQLSelectRendererVisitorTest.java +++ b/test/src/SPARQLSelectRendererVisitorTest.java @@ -19,8 +19,81 @@ import org.testng.annotations.Test; public class SPARQLSelectRendererVisitorTest { // @Test(groups = {"full", "impl", "raw"}) +// public void QueryFromWithoutLinkkey() throws Exception { +// String alignmentFileName = "alignment3.rdf"; +// EDOALAlignment alignment = Utils.loadAlignement(alignmentFileName); +// StringWriter stringWriter = new StringWriter(); +// PrintWriter writer = new PrintWriter(stringWriter); +// SPARQLSelectRendererVisitor renderer = new SPARQLSelectRendererVisitor(writer); +// Properties properties = new Properties(); +// renderer.init(properties); +// alignment.render(renderer); +// assertEquals(alignment.nbCells(), 1); +// Enumeration<Cell> cells = alignment.getElements(); +// Cell cell = cells.nextElement(); +// URI remoteURI = new URI("http://example.org/data.rdf"); +// +// +// //Without service => UNSING FROM ? +// String expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +// + "PREFIX ns0:<http://exmo.inria.fr/connectors#>\n" +// + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" +// + "SELECT ?s1 ?s2" +// + "WHERE {\n" +// + "?s1 rdf:type ns0:RootElement .\n" +// + "SERVICE <http://example.org/data.rdf> {" +// + "?s2 rdf:type ns1:MusicalWork . \n" +// + "?s2 ns1:opus ?o1" +// + "}\n" +// + "}\n"; +// +// String expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +// + "PREFIX ns0:<http://exmo.inria.fr/connectors#>\n" +// + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" +// + "SELECT ?s1 ?s2" +// + "WHERE {\n" +// + "?s2 rdf:type ns1:MusicalWork . \n" +// + "?s2 ns1:opus ?o1" +// + "SERVICE <http://example.org/data.rdf> {" +// + "?s1 rdf:type ns0:RootElement .\n" +// + "?s1 ns0:number ?o1 ." +// + "}\n" +// + "}\n"; +// assertEquals(renderer.getQuery(cell, 0), expectedQuery1); +// assertEquals(renderer.getQuery(cell, 1), expectedQuery2); +// +// //With service +// expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +// + "PREFIX ns0:<http://exmo.inria.fr/connectors#>\n" +// + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" +// + "SELECT ?s1 ?s2" +// + "WHERE {\n" +// + "?s1 rdf:type ns0:RootElement .\n" +// + "SERVICE <http://example.org/data.rdf> {" +// + "?s2 rdf:type ns1:MusicalWork . \n" +// + "?s2 ns1:opus ?o1" +// + "}\n" +// + "}\n"; +// +// expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +// + "PREFIX ns0:<http://exmo.inria.fr/connectors#>\n" +// + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" +// + "SELECT ?s1 ?s2" +// + "WHERE {\n" +// + "?s2 rdf:type ns1:MusicalWork . \n" +// + "?s2 ns1:opus ?o1" +// + "SERVICE <http://example.org/data.rdf> {" +// + "?s1 rdf:type ns0:RootElement .\n" +// + "?s1 ns0:number ?o1 ." +// + "}\n" +// + "}\n"; +// assertEquals(renderer.getQuery(cell, 0, remoteURI), expectedQuery1); +// assertEquals(renderer.getQuery(cell, 1, remoteURI), expectedQuery2); +// } +// +// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromWithoutLinkkey"}) // public void QueryFromSimpleLinkkey() throws Exception { -// String alignmentFileName = "alignment2.rdf"; +// String alignmentFileName = "alignment4.rdf"; // EDOALAlignment alignment = Utils.loadAlignement(alignmentFileName); // StringWriter stringWriter = new StringWriter(); // PrintWriter writer = new PrintWriter(stringWriter); @@ -32,12 +105,12 @@ public class SPARQLSelectRendererVisitorTest { // Enumeration<Cell> cells = alignment.getElements(); // Cell cell = cells.nextElement(); // URI remoteURI = new URI("http://example.org/data.rdf"); -// // THIS DOES THE edoal:type="in" How to do equal? +// // THIS DOES THE edoal:type="in" How to do equal? // String expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" // + "PREFIX ns0:<http://exmo.inria.fr/connectors#>\n" // + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" -// //+ "CONSTRUCT { ?s1 owl:sameAs ?s2 }" -// + "SELECT ?s1 ?s2" +// //+ "CONSTRUCT { ?s1 owl:sameAs ?s2 }" +// + "SELECT ?s1 ?s2" // + "WHERE {\n" // + "?s1 rdf:type ns0:RootElement .\n" // + "?s1 ns0:number ?o1 ." @@ -59,9 +132,8 @@ public class SPARQLSelectRendererVisitorTest { // + "?s1 ns0:number ?o1 ." // + "}\n" // + "}\n"; -// assertEquals(renderer.getQuery(cell, 0, remoteURI), expectedQuery1, "FOR alignment file " + alignmentFileName); -// assertEquals(renderer.getQuery(cell, 1, remoteURI), expectedQuery2, "FOR alignment file " + alignmentFileName); -// fail("HAVE TODO"); +// assertEquals(renderer.getQuery(cell, 0, remoteURI), expectedQuery1); +// assertEquals(renderer.getQuery(cell, 1, remoteURI), expectedQuery2); // } // // @Test(groups = {"full", "impl", "raw"})