diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java index b2fd9bc9b19d923cede2109c28fb6009cb2cd979..e4384466882dc748b7f0db35fe6392b771b4fbdb 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLLinkkerRendererVisitor.java @@ -293,29 +293,29 @@ public class SPARQLLinkkerRendererVisitor extends GraphPatternRendererVisitor im public void processInLinkKey( final LinkkeyBinding binding ) throws AlignmentException { if ( (binding.getExpression1() instanceof PropertyExpression) || (binding.getExpression2() instanceof PropertyExpression) ) { - //?x p'i ?zi . ?y q'i ?zi . + //Literal values emptyGP(); String o1 = createVarName(); resetVariables( lkvar1, o1 ); binding.getExpression1().accept( this ); lkpattern += wrapInNamedGraph( onto1NamedGraph, getGP() ); emptyGP(); - resetVariables( lkvar2, o1 ); + String o2 = createVarName(); + resetVariables( lkvar2, o2 ); binding.getExpression2().accept( this ); lkpattern += wrapInNamedGraph( onto2NamedGraph, getGP() ); + lkpattern += "FILTER( lcase(str("+o1+")) = lcase(str("+o2+")) )"+NL; } else { - //Literal values + //?x p'i ?zi . ?y q'i ?zi . emptyGP(); String o1 = createVarName(); resetVariables( lkvar1, o1 ); binding.getExpression1().accept( this ); lkpattern += wrapInNamedGraph( onto1NamedGraph, getGP() ); emptyGP(); - String o2 = createVarName(); - resetVariables( lkvar2, o2 ); + resetVariables( lkvar2, o1 ); binding.getExpression2().accept( this ); lkpattern += wrapInNamedGraph( onto2NamedGraph, getGP() ); - lkpattern += "FILTER( lcase(str("+o1+")) = lcase(str("+o2+")) ) "+NL; } } diff --git a/test/src/SPARQLLinkkerRendererVisitorTest.java b/test/src/SPARQLLinkkerRendererVisitorTest.java index 45b507ea467132e4b65309b627517ff9f491e44f..3f64ca6e39aee74b90ce3198264705cea663ce11 100644 --- a/test/src/SPARQLLinkkerRendererVisitorTest.java +++ b/test/src/SPARQLLinkkerRendererVisitorTest.java @@ -52,7 +52,7 @@ import org.testng.annotations.Test; public class SPARQLLinkkerRendererVisitorTest { - // JE2015-Tosee + // JE2015: // This is a test which has no sense, because there is no linkkey // In this case, my new SPARQLLinkkey does not return a query // It would link all pairs of RootElement / MusicalWork @@ -213,13 +213,14 @@ System.err.println( renderer.getQuery( cell ) ); + "PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX owl:<http://www.w3.org/2002/07/owl#>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" - + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "CONSTRUCT { ?s1 owl:sameAs ?s2 }\n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" + "?s2 rdf:type ns1:Person .\n" + "?s1 ns0:nom ?o3 .\n" - + "?s2 ns1:givenName ?o3 .\n" + + "?s2 ns1:givenName ?o4 .\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; String query = renderer.getQuery( cell ); assertEquals( query, expectedQuery0 ); @@ -233,13 +234,14 @@ System.err.println( renderer.getQuery( cell ) ); 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\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "SELECT DISTINCT ?s1 ?s2\n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" + "?s2 rdf:type ns1:Person .\n" + "?s1 ns0:nom ?o3 .\n" - + "?s2 ns1:givenName ?o3 .\n" + + "?s2 ns1:givenName ?o4 .\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; query = renderer.getQuery(cell); assertEquals( query, expectedQuery ); @@ -319,7 +321,7 @@ System.err.println( renderer.getQuery( cell ) ); 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 xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" + "SELECT DISTINCT ?s1 ?s2\n\n" + "WHERE {\n" @@ -412,15 +414,17 @@ System.err.println( renderer.getQuery( cell ) ); 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\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "SELECT DISTINCT ?s1 ?s2\n" + "WHERE {\n" + "?s1 rdf:type ns0:Personne .\n" + "?s2 rdf:type ns1:Person .\n" + "?s1 ns0:connait ?o3 .\n" - + "?o4 rdf:type ns1:Person .\n" - + "?s2 ns1:knows ?o4 .\n" - + "?o4 ns1:givenName ?o3 .\n" + + "?o5 rdf:type ns1:Person .\n" + + "?s2 ns1:knows ?o5 .\n" + + "?o5 ns1:givenName ?o4 .\n" + // JE2015: Here we have a URI (o3) compared to a string (o4) + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n" + ""; assertEquals( query, expectedQuery ); @@ -494,7 +498,7 @@ System.err.println( renderer.getQuery( cell ) ); 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\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "SELECT DISTINCT ?s1 ?s2\n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" @@ -507,8 +511,9 @@ System.err.println( renderer.getQuery( cell ) ); + "?s1 ns0:nom ?o3 .\n" + "}\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" - + "?s2 ns1:givenName ?o3 .\n" + + "?s2 ns1:givenName ?o4 .\n" + "}\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; assertEquals( renderer.getQuery(cell), expectedQuery ); @@ -516,7 +521,7 @@ System.err.println( renderer.getQuery( cell ) ); expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns1:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns0:<http://xmlns.com/foaf/0.1/>\n" - + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "SELECT DISTINCT ?s1 ?s2\n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" @@ -529,8 +534,9 @@ System.err.println( renderer.getQuery( cell ) ); + "?s1 ns0:givenName ?o3 .\n" + "}\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" - + "?s2 ns1:nom ?o3 .\n" + + "?s2 ns1:nom ?o4 .\n" + "}\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; EDOALAlignment inval = alignment.inverse(); properties.setProperty( "graphName1", onto2NamedGraph ); @@ -565,7 +571,8 @@ System.err.println( renderer.getQuery( cell ) ); + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" + "?s1 ns0:nom ?o3 .\n" + "}\n" - + "?s2 ns1:givenName ?o3 .\n" + + "?s2 ns1:givenName ?o4 .\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; assertEquals(renderer.getQuery(cell), expectedQuery); @@ -582,8 +589,9 @@ System.err.println( renderer.getQuery( cell ) ); + "}\n" + "?s1 ns0:givenName ?o3 .\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto1-graph> {\n" - + "?s2 ns1:nom ?o3 .\n" + + "?s2 ns1:nom ?o4 .\n" + "}\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; renderer = new SPARQLLinkkerRendererVisitor(writer); properties = new Properties(); @@ -606,8 +614,9 @@ System.err.println( renderer.getQuery( cell ) ); + "}\n" + "?s1 ns0:nom ?o3 .\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" - + "?s2 ns1:givenName ?o3 .\n" + + "?s2 ns1:givenName ?o4 .\n" + "}\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; renderer = new SPARQLLinkkerRendererVisitor(writer); properties = new Properties(); @@ -624,7 +633,7 @@ System.err.println( renderer.getQuery( cell ) ); expectedQuery = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX ns1:<http://exmo.inrialpes.fr/connectors-core/>\n" + "PREFIX ns0:<http://xmlns.com/foaf/0.1/>\n" - + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n\n" + "SELECT DISTINCT ?s1 ?s2\n" + "WHERE {\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" @@ -634,7 +643,8 @@ System.err.println( renderer.getQuery( cell ) ); + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" + "?s1 ns0:givenName ?o3 .\n" + "}\n" - + "?s2 ns1:nom ?o3 .\n" + + "?s2 ns1:nom ?o4 .\n" + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; renderer = new SPARQLLinkkerRendererVisitor(writer); properties = new Properties(); @@ -678,10 +688,12 @@ System.err.println( renderer.getQuery( cell ) ); + "?s1 ns0:connait ?o3 .\n" + "}\n" + "GRAPH <http://exmo.inrialpes.fr/connectors/onto2-graph> {\n" - + "?o4 rdf:type ns1:Person .\n" - + "?s2 ns1:knows ?o4 .\n" - + "?o4 ns1:givenName ?o3 .\n" + + "?o5 rdf:type ns1:Person .\n" + + "?s2 ns1:knows ?o5 .\n" + + "?o5 ns1:givenName ?o4 .\n" + "}\n" + // JE2015: Here we have a URI (o3) compared to a string (o4) + + "FILTER( lcase(str(?o3)) = lcase(str(?o4)) )\n" + "}\n"; assertEquals( query, expectedQuery );