From 119c2e8d27e3e5532b8d6333b3c86064ac7dbec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Euzenat?= <Jerome.Euzenat@inria.fr> Date: Mon, 1 Jun 2015 13:25:12 +0000 Subject: [PATCH] - improved SPARQL renderers (init, datatypes) - corrected documentation edoal - added LinkkerRenderer --- html/edoal.html | 8 +- .../renderer/GraphPatternRendererVisitor.java | 52 +-- .../SPARQLConstructRendererVisitor.java | 11 +- .../SPARQLLinkkerRendererVisitor.java | 302 ++++++++++++++++++ .../renderer/SPARQLSelectRendererVisitor.java | 19 +- test/src/SPARQLConstructVisitorTest.java | 18 +- test/src/SPARQLSelectRendererVisitorTest.java | 68 ++-- 7 files changed, 411 insertions(+), 67 deletions(-) create mode 100644 src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java diff --git a/html/edoal.html b/html/edoal.html index 301763f0..38ca80d5 100644 --- a/html/edoal.html +++ b/html/edoal.html @@ -387,7 +387,7 @@ Restrictions are defined by giving an <i>path expression</i> (relation or proper | <AttributeOccurenceRestriction> <u>onatt</u> <u>comp</u> <value><Literal edoal:type="&xsd;integer" edoal:string="INTEGER" /></value> </AttributeOccurenceRestriction> | <AttributeDomainRestriction> <u>onatt</u> <u>classrest</u> </AttributeDomainRestriction> | <AttributeTypeRestriction> <u>onatt</u> <u>typerest</u> </AttributeTypeRestriction> - | <AttributeValueRestriction> <u>onatt</u> <u>comp</u> (<value><u>instexpr</u></value>|<u>val</u>) </AttributeValueRestriction> + | <AttributeValueRestriction> <u>onatt</u> <u>comp</u> <u>val</u> </AttributeValueRestriction> <u>classconst</u> ::= <and rdf:parseType="Collection"> <u>classexpr</u>* </and> | <or rdf:parseType="Collection"> <u>classexpr</u>* </or> @@ -453,7 +453,7 @@ Thanks to paths and restrictions, it is possible to restrict a correspondence to </Property> </onAttribute> <comparator rdf:resource="&edoal;equals" /> - <value edoal:type="&xsd;string">Acquitaine</value> + <value><Literal edoal:type="&xsd;string" edoal:string="Acquitaine"/></value> </AttributeValueRestriction> </and> </Class> @@ -482,7 +482,7 @@ We can with this restriction build the correspondence between </Relation> </onAttribute> <comparator rdf:resource="&edoal;equals" /> - <value edoal:type="&xsd;string">Acquitaine</value> + <value><Literal edoal:type="&xsd;string" edoal:string="Acquitaine"/></value> </Restriction> </attributeValueCondition> </Class> @@ -660,7 +660,7 @@ An example of occurrence restriction would be the wines produced in a region wit </Relation> </onAttribute> <comparator rdf:resource="&edoal;greater-than" /> - <value edoal:type="&xsd;integer">0</value> + <value><Literal edoal:type="&xsd;integer" edoal:string="0"/></value> </Restriction> </attributeOccurrenceCondition> </and> diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java index 5be60b12..2baf6c19 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/GraphPatternRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2012-2014 + * Copyright (C) INRIA, 2012-2015 * * 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 @@ -123,6 +123,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito objectsRestriction = new HashSet<String>(); prefixList = new Hashtable<String, String>(); prefixList.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf"); + prefixList.put("http://www.w3.org/2001/XMLSchema#", "xsd"); // used in types queries = new LinkedHashMap<Object, List<String>>(); } @@ -166,8 +167,12 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito obj = o; } - // JE2014: Why do we only create variables for obj? - private String createVarName() { + /** + * Generates anew variable. This is always an object because we know + * the subjects (named by outside). + * It may be necessary to generate blanks. + */ + protected String createVarName() { if (blanks) { obj = "_:o" + ++varsIndexcount; } else { @@ -184,6 +189,10 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito return strBGP; } + protected void emptyGP() { + strBGP = ""; + } + protected List<String> getBGP() { return listBGP; } @@ -557,7 +566,7 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito obj = "?o" + ++varsIndexcount; } - public void visit(final PropertyValueRestriction c) throws AlignmentException { + public void visit( final PropertyValueRestriction c ) throws AlignmentException { String str = ""; value = ""; uriType = ""; @@ -759,22 +768,11 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito } } - public void visit(final Value e) throws AlignmentException { - if (e.getType() != null) { - String str = e.getType().toString(); - int index; - if (str.contains("#")) { - index = str.lastIndexOf("#"); - } else { - index = str.lastIndexOf("/"); - } - uriType = str.substring(index + 1); - } + public void visit( final Value e ) throws AlignmentException { value = e.getValue(); - if (uriType != null && uriType.equals("")) { - uriType = "string"; - } - + if ( e.getType() != null ) uriType = decodeDatatype( e.getType().toString() ); + // JE2015: Not sure that this is really useful + //if ( uriType != null && uriType.equals("") ) uriType = "xsd:string"; } public void visit(final Apply e) throws AlignmentException { @@ -783,14 +781,20 @@ public abstract class GraphPatternRendererVisitor extends IndentedRendererVisito public void visit(final Transformation transf) throws AlignmentException { } - public void visit(final Datatype e) throws AlignmentException { + public void visit( final Datatype e ) throws AlignmentException { + datatype = decodeDatatype( e.getType() ); + } + + // if known prefix: prefix : suffix + // Otherwise full uri + private String decodeDatatype( String datatype ) { int index; - if (e.getType().contains("#")) { - index = e.getType().lastIndexOf("#"); + if ( datatype.contains("#")) { + index = datatype.lastIndexOf("#"); } else { - index = e.getType().lastIndexOf("/"); + index = datatype.lastIndexOf("/"); } - datatype = e.getType().substring(index + 1); + return datatype.substring(index + 1); } } diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java index 10ab1695..934136c2 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLConstructRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2012-2014 + * Copyright (C) INRIA, 2012-2015 * * 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 @@ -61,15 +61,18 @@ public class SPARQLConstructRendererVisitor extends GraphPatternRendererVisitor super(writer); } - public SPARQLConstructRendererVisitor(PrintWriter writer, String namedGraph) { - this(writer); - this.namedGraph = namedGraph; + public void setGraphName( String name ) { + namedGraph = name; } /** * Initialises the parameters of the renderer */ public void init(Properties p) { + if ( p.getProperty("graphName") != null ) { + setGraphName( p.getProperty("graphName") ); + } + if (p.getProperty("embedded") != null && !p.getProperty("embedded").equals("")) { embedded = true; diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java new file mode 100644 index 00000000..5ad1512f --- /dev/null +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java @@ -0,0 +1,302 @@ +/* + * $Id$ + * + * Copyright (C) INRIA, 2015 + * + * 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.renderer; + +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 fr.inrialpes.exmo.align.impl.BasicAlignment; +import fr.inrialpes.exmo.align.impl.edoal.EDOALAlignment; +import fr.inrialpes.exmo.align.impl.edoal.EDOALCell; +import fr.inrialpes.exmo.align.impl.edoal.Expression; +import fr.inrialpes.exmo.align.impl.edoal.ClassExpression; +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.ArrayList; +import java.util.Set; +import java.util.Hashtable; +import java.util.List; +import java.util.Properties; + +/** + * The architecture of these SPARQL renderer does not comply with the classical renderer architecture + * whose goal is to immediatelt display the query on given writer. + * + * It would be better to come back to it. + * But beware, this will conflict with split (several output files) + */ + +public class SPARQLLinkkerRendererVisitor extends GraphPatternRendererVisitor implements AlignmentVisitor { + + Alignment alignment = null; + Cell cell = null; + Hashtable<String, String> nslist = null; + + /* Named graph for the data sources (if none, null) */ + private String onto1NamedGraph, onto2NamedGraph = null; + + /* Name of variables to be used for the individual to match */ + private String lkvar1, lkvar2 = null; + + /* Name of the linking graph pattern */ + private String lkpattern = null; + + boolean embedded = false; + boolean oneway = false; + + boolean edoal = false; + + boolean requestedblanks = false; + + private String content_Corese = ""; // resulting string for Corese + + public SPARQLLinkkerRendererVisitor( PrintWriter writer ) { + super(writer); + prefixList.put("http://www.w3.org/2002/07/owl#", "owl"); + } + + public void setGraph1Name( String name ) { + onto1NamedGraph = name; + } + + public void setGraph2Name( String name ) { + onto2NamedGraph = name; + } + + /** + * Initialises the parameters of the renderer + */ + public void init( Properties p ) { + if ( p.getProperty("graphName1") != null ) { + setGraph1Name( p.getProperty("graphName1") ); + } + if ( p.getProperty("graphName2") != null ) { + setGraph2Name( p.getProperty("graphName2") ); + } + + if (p.getProperty("embedded") != null + && !p.getProperty("embedded").equals("")) { + embedded = true; + } + if (p.getProperty("oneway") != null && !p.getProperty("oneway").equals("")) { + oneway = true; + } + if (p.getProperty("blanks") != null && !p.getProperty("blanks").equals("")) { + requestedblanks = true; + } + if (p.getProperty("weakens") != null && !p.getProperty("weakens").equals("")) { + weakens = true; + } + if (p.getProperty("ignoreerrors") != null && !p.getProperty("ignoreerrors").equals("")) { + ignoreerrors = true; + } + if (p.getProperty("corese") != null && !p.getProperty("corese").equals("")) { + corese = true; + } + + split((p.getProperty("split") != null && !p.getProperty("split").equals("")), p.getProperty("dir") + "/"); + + if (p.getProperty("indent") != null) { + INDENT = p.getProperty("indent"); + } + if (p.getProperty("newline") != null) { + NL = p.getProperty("newline"); + } + } + + public void visit( Alignment align ) throws AlignmentException { + if (subsumedInvocableMethod(this, align, Alignment.class)) { + return; + } + if (align instanceof EDOALAlignment) { + alignment = align; + } else { + try { + alignment = EDOALAlignment.toEDOALAlignment((BasicAlignment) align); + } catch (AlignmentException alex) { + throw new AlignmentException("SPARQLLinkerRenderer: cannot render simple alignment. Need an EDOALAlignment", alex); + } + } + edoal = alignment.getLevel().startsWith("2EDOAL"); + if ( !edoal ) throw new AlignmentException("SPARQLLinkerRenderer: cannot render simple alignment. Need an EDOALAlignment" ); + content_Corese = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + NL; + content_Corese += "<!DOCTYPE rdf:RDF [" + NL; + content_Corese += "<!ENTITY rdf \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" + NL; + content_Corese += "<!ENTITY rdfs \"http://www.w3.org/2000/01/rdf-schema#\">" + NL; + content_Corese += "<!ENTITY rul \"http://ns.inria.fr/edelweiss/2011/rule#\">" + NL; + content_Corese += "]>" + NL; + content_Corese += "<rdf:RDF xmlns:rdfs=\"&rdfs;\" xmlns:rdf=\"&rdf;\" xmlns = \'&rul;\' >" + NL + NL + NL; + for ( Cell c : alignment ) { + c.accept( this ); + }; + content_Corese += "</rdf:RDF>" + NL; + if ( corese ) { + saveQuery( align, content_Corese ); + } + } + + public void visit( Cell cell ) throws AlignmentException { + if ( subsumedInvocableMethod(this, cell, Cell.class) ) { + return; + } + // default behaviour + this.cell = cell; + // This should necessarily be cells with linkkeys + generateLinkConstruct( cell, (Expression)(cell.getObject1()), (Expression)(cell.getObject2()) ); + } + + public void visit(Relation rel) throws AlignmentException { + if (subsumedInvocableMethod(this, rel, Relation.class)) { + return; + } + // default behaviour + // rel.write( writer ); + } + + protected void generateLinkConstruct( Cell cell, Expression expr1, Expression expr2 ) throws AlignmentException { + if ( expr1 instanceof ClassExpression && expr2 instanceof ClassExpression ) { + generateLinkConstruct( cell, (ClassExpression)expr1, (ClassExpression)expr2 ); + } //else {} Do nothing (maybe for instances) + } + + protected void generateLinkConstruct( Cell cell, ClassExpression expr1, ClassExpression expr2 ) throws AlignmentException { + Set<Linkkey> linkkeys = ((EDOALCell)cell).linkkeys(); + if ( linkkeys == null || linkkeys.isEmpty() ) return; + + // Here the generation is dependent on global variables + blanks = true; + resetVariables( expr1, "s1", "o1" ); + expr1.accept( this ); + String GP1 = wrapInNamedGraph( onto1NamedGraph, getGP() ); + List<String> listGP1 = new ArrayList<String>(getBGP()); + blanks = requestedblanks; + resetVariables( expr2, "s2", "o2" ); + expr2.accept( this ); + String GP2 = wrapInNamedGraph( onto2NamedGraph, getGP() ); + + // Generate linkkey part! + // JE2015: only works if only one linkkey + for ( Linkkey linkkey : linkkeys ) { + lkvar1 = "?s1"; + lkvar2 = "?s2"; + linkkey.accept( this ); + } + + // End of global variables + String query = ""; + if ( !GP1.contains("UNION") && !GP1.contains("FILTER") ) { + query = createLinkConstruct( "?s1", GP1, "?s2", GP2, lkpattern ); + if (corese) { + content_Corese += createCoreseQuery( query ); + } + } else if (weakens) { + String tmp = ""; + for (String str : listGP1) { + if (!str.contains("UNION") && !str.contains("FILTER")) { + tmp += str; + } + } + if (!tmp.equals("")) { + query = createLinkConstruct( "?s1", tmp, "?s2", GP2, lkpattern ); + } + } else if (ignoreerrors) { + query = createLinkConstruct( "?s1", GP1, "?s2", GP2, lkpattern ); + } + if (corese) { + return; + } + saveQuery(cell, query); + } + + protected String createLinkConstruct( String v1, String GP1, String v2, String GP2, String LKPat ) { + return createPrefixList() + NL + "CONSTRUCT { " + v1 + " owl:sameAs " + v2 + " }" + NL + "WHERE {" + NL + GP1 + GP2 + LKPat + "}" + NL; + } + + protected String createCoreseQuery( String query ) { + return "<rule>" + NL + "<body>" + NL + "<![CDATA[" + NL + query + "]]>" + NL + "</body>" + NL + "</rule>" + NL + NL; + } + + public void visit( final Linkkey linkkey ) throws AlignmentException { + lkpattern = ""; + for( LinkkeyBinding linkkeyBinding : linkkey.bindings() ) { + linkkeyBinding.accept(this); + } + } + + public void visit( final LinkkeyEquals linkkeyEquals ) throws AlignmentException { + String extravar1 = "x"; + String extravar2 = "y"; + initStructure(); //strBGP = ""; // congrats! + resetVariables( "?x", "?o" ); + linkkeyEquals.getExpression1().accept( this ); + String temp = obj; + String GP1 = wrapInNamedGraph( onto1NamedGraph, getGP() ); + // == resetS2( lkvar2 ); + initStructure(); //strBGP = ""; // congrats! + resetVariables( "?y", "?o" ); + obj = temp; + linkkeyEquals.getExpression2().accept( this ); + String GP2 = wrapInNamedGraph( onto2NamedGraph, getGP() ); + lkpattern += "MINUS SELECT ?x ?y WHERE { " + GP1 + " FILTER NOT EXISTS { " + GP2 + " } }"; + lkpattern += "MINUS SELECT ?x ?y WHERE { " + GP2 + " FILTER NOT EXISTS { " + GP1 + " } }"; + //MINUS SELECT ?x ?y WHERE { ?x pj ?wj . FILTER NOT EXISTS { ?y qj ?wj . } } + //MINUS SELECT ?x ?y WHERE { ?y qj ?wj . FILTER NOT EXISTS { ?x pj ?wj . } } + } + + // JE: I do not understand where the common variables are created... (by default obj is preserved) + // JE: Is the GP reset??? The answer is no. Hence init... + public void visit( final LinkkeyIntersects linkkeyIntersects ) throws AlignmentException { + //?x p'i ?zi . ?y q'i ?zi . + //= lkpattern += NL + lkvar1 + "p" + "newvar" + " . " + NL + lkvar2 + "q" + "samenewvar" + " . "; + // == resetS1( lkvar1 ); + //initStructure(); //strBGP = ""; // congrats! + emptyGP(); + String o1 = createVarName(); + resetVariables( lkvar1, o1 ); + linkkeyIntersects.getExpression1().accept( this ); + lkpattern += wrapInNamedGraph( onto1NamedGraph, getGP() ); + // == resetS2( lkvar2 ); + //initStructure(); //strBGP = ""; // congrats! + emptyGP(); + String o2 = createVarName(); + resetVariables( lkvar2, o2 ); + linkkeyIntersects.getExpression2().accept( this ); + lkpattern += wrapInNamedGraph( onto2NamedGraph, getGP() ); + lkpattern += "FILTER( lcase(str("+o1+")) = lcase(str("+o2+")) ) "; + } + + protected String wrapInNamedGraph( String namedGraph, String stuff ) { + if ( namedGraph != null ) { + return "GRAPH <" + namedGraph + "> {" + NL + stuff + "}" + NL ; + } else { + return stuff; + } + } + +} diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java index cdbd3ce1..845d7c14 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java @@ -1,7 +1,7 @@ /* * $Id$ * - * Copyright (C) INRIA, 2012-2014 + * Copyright (C) INRIA, 2012-2015 * * 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 @@ -63,13 +63,22 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp super(writer); } - public SPARQLSelectRendererVisitor(PrintWriter writer, String onto1NamedGraph, String onto2NamedGraph) { - super(writer); - this.onto1NamedGraph = onto1NamedGraph; - this.onto2NamedGraph = onto2NamedGraph; + public void setGraph1Name( String name ) { + onto1NamedGraph = name; + } + + public void setGraph2Name( String name ) { + onto2NamedGraph = name; } public void init(Properties p) { + if ( p.getProperty("graphName1") != null ) { + setGraph1Name( p.getProperty("graphName1") ); + } + if ( p.getProperty("graphName2") != null ) { + setGraph2Name( p.getProperty("graphName2") ); + } + if (p.getProperty("embedded") != null && !p.getProperty("embedded").equals("")) { embedded = true; } diff --git a/test/src/SPARQLConstructVisitorTest.java b/test/src/SPARQLConstructVisitorTest.java index 4c8b9c02..284a4c10 100644 --- a/test/src/SPARQLConstructVisitorTest.java +++ b/test/src/SPARQLConstructVisitorTest.java @@ -1,5 +1,5 @@ /* - * $Id: READMETest.java 1985 2014-11-09 16:50:18Z euzenat $ + * $Id$ * * Copyright (C) INRIA, 2014-2015 * @@ -35,11 +35,6 @@ import static org.testng.Assert.assertEquals; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -/* - * 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. - */ /** * * @author Nicolas Guillouet <nicolas.guillouet@inria.fr> @@ -75,6 +70,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s ns1:opus ?o .\n" @@ -85,6 +81,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s ns0:opus ?o .\n" @@ -98,13 +95,15 @@ public class SPARQLConstructVisitorTest { //With Named Graph String namedGraph = "http://exmo.inrialpes.fr/connectors/one-graph"; - renderer = new SPARQLConstructRendererVisitor(writer, namedGraph); + renderer = new SPARQLConstructRendererVisitor(writer); properties = new Properties(); + properties.setProperty( "graphName", namedGraph ); renderer.init(properties); alignment.render(renderer); expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s ns1:opus ?o .\n" @@ -117,6 +116,7 @@ public class SPARQLConstructVisitorTest { expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s ns0:opus ?o .\n" @@ -186,6 +186,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s rdf:type ns1:MusicalWork .\n" @@ -196,6 +197,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" + "?s rdf:type ns0:RootElement .\n" @@ -225,6 +227,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery1 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns1:<http://purl.org/NET/c4dm/keys.owl#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns3:<http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX ns2:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" @@ -239,6 +242,7 @@ public class SPARQLConstructVisitorTest { String expectedQuery2 = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns1:<http://purl.org/NET/c4dm/keys.owl#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns3:<http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX ns2:<http://purl.org/ontology/mo/>\n" + "CONSTRUCT {\n" diff --git a/test/src/SPARQLSelectRendererVisitorTest.java b/test/src/SPARQLSelectRendererVisitorTest.java index 987cebd3..81fb0970 100644 --- a/test/src/SPARQLSelectRendererVisitorTest.java +++ b/test/src/SPARQLSelectRendererVisitorTest.java @@ -1,7 +1,7 @@ /* - * $Id: READMETest.java 1985 2014-11-09 16:50:18Z euzenat $ + * $Id$ * - * Copyright (C) INRIA, 2014 + * Copyright (C) INRIA, 2014-2015 * * 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 @@ -43,6 +43,7 @@ import org.testng.annotations.Test; * * @author Nicolas Guillouet <nicolas.guillouet@inria.fr> */ + public class SPARQLSelectRendererVisitorTest { @Test(groups = {"full", "impl", "raw"}) @@ -60,25 +61,27 @@ public class SPARQLSelectRendererVisitorTest { Cell cell = cells.nextElement(); String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" - + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" - + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" - + "SELECT DISTINCT ?s1 ?s2 \n" - + "WHERE {\n" - + "?s1 rdf:type ns0:RootElement .\n" - + "?s2 rdf:type ns1:MusicalWork .\n" - + "FILTER(?s1 != ?s2)\n" - + "}\n"; + + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + + "SELECT DISTINCT ?s1 ?s2 \n" + + "WHERE {\n" + + "?s1 rdf:type ns0:RootElement .\n" + + "?s2 rdf:type ns1:MusicalWork .\n" + + "FILTER(?s1 != ?s2)\n" + + "}\n"; assertEquals(renderer.getQueryFromOnto1ToOnto2(cell), expectedQuery); expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" - + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" - + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" - + "SELECT DISTINCT ?s1 ?s2 \n" - + "WHERE {\n" - + "?s2 rdf:type ns0:RootElement .\n" - + "?s1 rdf:type ns1:MusicalWork .\n" - + "FILTER(?s1 != ?s2)\n" - + "}\n"; + + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors#>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + + "PREFIX ns1:<http://purl.org/ontology/mo/>\n" + + "SELECT DISTINCT ?s1 ?s2 \n" + + "WHERE {\n" + + "?s2 rdf:type ns0:RootElement .\n" + + "?s1 rdf:type ns1:MusicalWork .\n" + + "FILTER(?s1 != ?s2)\n" + + "}\n"; assertEquals(renderer.getQueryFromOnto2ToOnto1(cell), expectedQuery); } @@ -184,6 +187,7 @@ public class SPARQLSelectRendererVisitorTest { String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" @@ -258,6 +262,7 @@ public class SPARQLSelectRendererVisitorTest { String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" @@ -347,6 +352,7 @@ public class SPARQLSelectRendererVisitorTest { String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" @@ -411,8 +417,10 @@ public class SPARQLSelectRendererVisitorTest { String onto2NamedGraph = "http://exmo.inrialpes.fr/connectors/onto2-graph"; //With named Graph on onto1 and onto2 - SPARQLSelectRendererVisitor renderer = new SPARQLSelectRendererVisitor(writer, onto1NamedGraph, onto2NamedGraph); + SPARQLSelectRendererVisitor renderer = new SPARQLSelectRendererVisitor(writer); Properties properties = new Properties(); + properties.setProperty( "graphName1", onto1NamedGraph ); + properties.setProperty( "graphName2", onto2NamedGraph ); renderer.init(properties); alignment.render(renderer); assertEquals(alignment.nbCells(), 1); @@ -422,6 +430,7 @@ public class SPARQLSelectRendererVisitorTest { String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -443,6 +452,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -462,8 +472,9 @@ public class SPARQLSelectRendererVisitorTest { assertEquals(renderer.getQueryFromOnto2ToOnto1(cell), expectedQuery); //With named Graph only on onto1 - renderer = new SPARQLSelectRendererVisitor(writer, onto1NamedGraph, null); + renderer = new SPARQLSelectRendererVisitor(writer); properties = new Properties(); + properties.setProperty( "graphName1", onto1NamedGraph ); renderer.init(properties); alignment.render(renderer); assertEquals(alignment.nbCells(), 1); @@ -473,6 +484,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -490,6 +502,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -505,8 +518,9 @@ public class SPARQLSelectRendererVisitorTest { assertEquals(renderer.getQueryFromOnto2ToOnto1(cell), expectedQuery); //With named Graph only on onto2 - renderer = new SPARQLSelectRendererVisitor(writer, null, onto2NamedGraph); + renderer = new SPARQLSelectRendererVisitor(writer); properties = new Properties(); + properties.setProperty( "graphName2", onto2NamedGraph ); renderer.init(properties); alignment.render(renderer); assertEquals(alignment.nbCells(), 1); @@ -516,6 +530,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" @@ -534,6 +549,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "?s2 rdf:type ns0:Personne .\n" @@ -553,8 +569,10 @@ public class SPARQLSelectRendererVisitorTest { alignment = Utils.loadAlignement(alignmentFileName); stringWriter = new StringWriter(); writer = new PrintWriter(stringWriter); - renderer = new SPARQLSelectRendererVisitor(writer, onto1NamedGraph, onto2NamedGraph); + renderer = new SPARQLSelectRendererVisitor(writer); properties = new Properties(); + properties.setProperty( "graphName1", onto1NamedGraph ); + properties.setProperty( "graphName2", onto2NamedGraph ); renderer.init(properties); alignment.render(renderer); @@ -566,6 +584,7 @@ public class SPARQLSelectRendererVisitorTest { expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -599,8 +618,10 @@ public class SPARQLSelectRendererVisitorTest { String onto2NamedGraph = "http://exmo.inrialpes.fr/connectors/onto2-graph"; //With named Graph on onto1 and onto2 - SPARQLSelectRendererVisitor renderer = new SPARQLSelectRendererVisitor(writer, onto1NamedGraph, onto2NamedGraph); + SPARQLSelectRendererVisitor renderer = new SPARQLSelectRendererVisitor(writer); Properties properties = new Properties(); + properties.setProperty( "graphName1", onto1NamedGraph ); + properties.setProperty( "graphName2", onto2NamedGraph ); renderer.init(properties); alignment.render(renderer); assertEquals(alignment.nbCells(), 1); @@ -609,6 +630,7 @@ public class SPARQLSelectRendererVisitorTest { String expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + "SELECT DISTINCT ?s1 ?s2 \n" + "WHERE {\n" -- GitLab