diff --git a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java index 7f0b27e4a3f1eb461012ff6ea700a73590d33a7d..4105fd92b2518ecd8dfdc5eae2cc69ba90bcc51f 100644 --- a/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java +++ b/src/fr/inrialpes/exmo/align/impl/renderer/SPARQLSelectRendererVisitor.java @@ -223,7 +223,7 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp resetS1("?o1"); Expression expr1 = linkkeyIntersects.getExpression1(); expr1.accept(this); - resetS2("?o2"); + resetS2("?o1"); Expression expr2 = linkkeyIntersects.getExpression2(); expr2.accept(this); } @@ -249,19 +249,14 @@ public class SPARQLSelectRendererVisitor extends GraphPatternRendererVisitor imp expr2.accept(this); listGP.add(getGP()); initStructure(); - boolean hasLinkeys = false; String filter = "FILTER(?s1 != ?s2)"; Set<Linkkey> linkkeys = ((EDOALCell) cell).linkkeys(); if (linkkeys != null) { - hasLinkeys = true; for (Linkkey linkkey : linkkeys) { linkkey.accept(this); } - } - if (hasLinkeys) { - filter = "FILTER(?s1 != ?s2 && ?o2 = ?o1)"; listGP.add(getGP()); - } + } String query = createSelect(listGP, filter); if (corese) { throw new AlignmentException("corese case NOT IMPLEMENTED for SPARQLSelectRendererVisitor !!"); diff --git a/test/input/equals_people_1.rdf b/test/input/equals_people_1.rdf index 37bab6c3c035dc8a8bb6053c5108a031de97ddd8..40701361e447d4d4963be0f29d493262acc2c728 100644 --- a/test/input/equals_people_1.rdf +++ b/test/input/equals_people_1.rdf @@ -73,8 +73,8 @@ Tests are on two main elements tested on datas for one property : <exmo:nom>AliceC2</exmo:nom> <exmo:nom>AliceC2_1</exmo:nom> <exmo:nom>AliceC2_2</exmo:nom> - <exmo:connait>DaveC1_1</exmo:connait> - <exmo:connait>CarolC1_1</exmo:connait> + <!--<exmo:connait>DaveC1_1</exmo:connait> + <exmo:connait>CarolC1_1</exmo:connait>--> <exmo:connait>Ivan2</exmo:connait> <exmo:boitemel>alice1@gmail.com</exmo:boitemel> <exmo:boitemel>alice1@msn.com</exmo:boitemel> diff --git a/test/input/equals_people_2.rdf b/test/input/equals_people_2.rdf index a204be68270c35945104e39735c5afc13573d4f6..20887a3b30908475266b11c517af0916ac20cf8b 100644 --- a/test/input/equals_people_2.rdf +++ b/test/input/equals_people_2.rdf @@ -33,8 +33,8 @@ <foaf:givenName>AliceC2</foaf:givenName> <foaf:givenName>AliceC2_1</foaf:givenName> <foaf:givenName>AliceC2_2_diff</foaf:givenName> - <foaf:knows rdf:resource="http://exmo.inrialpes.fr/connectors-data/people#dave_c1_2" /> - <foaf:knows rdf:resource="http://exmo.inrialpes.fr/connectors-data/people#carol_c1_2" /> + <!--<foaf:knows rdf:resource="http://exmo.inrialpes.fr/connectors-data/people#dave_c1_2" /> + <foaf:knows rdf:resource="http://exmo.inrialpes.fr/connectors-data/people#carol_c1_2" />--> <foaf:knows rdf:resource="http://exmo.inrialpes.fr/connectors-data/people#ivan_2" /> <foaf:mbox>alice2@gmail.com</foaf:mbox> <foaf:mbox>alice2@msn.com</foaf:mbox> diff --git a/test/input/intersects_people_1.rdf b/test/input/intersects_people_1.rdf index 3f417be8c575ee2a16ac8183e253a59aef99b307..8ec5a32b023c4a8ce957f0a7e94c7f3a60245f83 100644 --- a/test/input/intersects_people_1.rdf +++ b/test/input/intersects_people_1.rdf @@ -19,7 +19,7 @@ <owl:imports rdf:resource="http://xmlns.com/foaf/0.1/"/> </owl:Ontology> - <!-- EQUALS for (nom, givenName) / Intersects for (connait, knows)--> + <!-- INTERSECTS + EQUALS for (nom, givenName) / Intersects for (connait, knows)--> <rdf:Description rdf:about="http://exmo.inrialpes.fr/connectors-data/people#alice_c1_1"> <rdf:type rdf:resource="&exmo;Personne"/> <exmo:nom>AliceC1</exmo:nom> @@ -31,7 +31,7 @@ <exmo:boitemel>alice1@msn.com</exmo:boitemel> </rdf:Description> - <!-- INTERSECTS on AliceC2 for (nom, givenName) / Equals for (connait, knows)--> + <!-- INTERSECTS on AliceC2 for (nom, givenName) / Equals + INTERSECTS for (connait, knows)--> <rdf:Description rdf:about="http://exmo.inrialpes.fr/connectors-data/people#alice_c2_1"> <rdf:type rdf:resource="&exmo;Personne"/> <exmo:nom>AliceC2</exmo:nom> diff --git a/test/input/intersects_people_2.rdf b/test/input/intersects_people_2.rdf index 5917be0089a2ccdf2b0628d8a242bcb98065221d..94690df7bcde38f9b836b0664b55616839da02e7 100644 --- a/test/input/intersects_people_2.rdf +++ b/test/input/intersects_people_2.rdf @@ -18,7 +18,7 @@ </owl:Ontology> - <!-- EQUALS for (nom, givenName) / Intersects for (connait, knows) --> + <!-- EQUALS + Intersects for (nom, givenName) / Intersects for (connait, knows) --> <rdf:Description rdf:about="http://exmo.inrialpes.fr/connectors-data/people#alice_c1_2"> <rdf:type rdf:resource="&foaf;Person"/> <foaf:givenName>AliceC1</foaf:givenName> @@ -30,7 +30,7 @@ <foaf:mbox>alice2@msn.com</foaf:mbox> </rdf:Description> - <!-- INTERSECTS on AliceC2 for (nom, givenName) / Equals for (connait, knows)--> + <!-- INTERSECTS on AliceC2 for (nom, givenName) / Equals + Intersects for (connait, knows)--> <rdf:Description rdf:about="http://exmo.inrialpes.fr/connectors-data/people#alice_c2_2"> <rdf:type rdf:resource="&foaf;Person"/> <foaf:givenName>AliceC2</foaf:givenName> diff --git a/test/src/SPARQLSelectRendererVisitorTest.java b/test/src/SPARQLSelectRendererVisitorTest.java index 1aad28cbee4f6a9e30aa21078254a90f1b5f2aed..85620769b36569f01f518308ef3144c138978f06 100644 --- a/test/src/SPARQLSelectRendererVisitorTest.java +++ b/test/src/SPARQLSelectRendererVisitorTest.java @@ -62,7 +62,7 @@ public class SPARQLSelectRendererVisitorTest { } @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromWithoutLinkkey"}) - public void QueryFromSimpleLinkkeyFromIntersects() throws Exception { + public void QueryFromSimpleLinkkeyAndIntersects() throws Exception { String alignmentFileName = "people_intersects_alignment.rdf"; EDOALAlignment alignment = Utils.loadAlignement(alignmentFileName); StringWriter stringWriter = new StringWriter(); @@ -74,20 +74,21 @@ public class SPARQLSelectRendererVisitorTest { assertEquals(alignment.nbCells(), 1); Enumeration<Cell> cells = alignment.getElements(); Cell cell = cells.nextElement(); - //Without any service -// PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> -// PREFIX ns0:<http://exmo.inrialpes.fr/connectors-core/> -// PREFIX ns1:<http://xmlns.com/foaf/0.1/> -// SELECT DISTINCT ?s1 ?s2 -// WHERE { -// ?s1 rdf:type ns0:Personne . -// ?s2 rdf:type ns1:Person . -// ?s1 ns0:nom ?o1 . -// ?s2 ns1:givenName ?o2 . -// FILTER(?s1 != ?s2 && ?o2 = ?o1) -// } + 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" + + "SELECT DISTINCT ?s1 ?s2 \n" + + "WHERE {\n" + + "?s1 rdf:type ns0:Personne .\n" + + "?s2 rdf:type ns1:Person .\n" + + "?s1 ns0:nom ?o1 .\n" + + "?s2 ns1:givenName ?o1 .\n" + + "FILTER(?s1 != ?s2)\n" + + "}\n"; String query = renderer.getQueryFromOnto1ToOnto2(cell); -// System.out.println("QUERY = " + query); +// System.out.println("QueryFromSimpleLinkkeyFromIntersects expectedQuery = " + expectedQuery); +// System.out.println("QueryFromSimpleLinkkeyFromIntersects QUERY = " + query); + assertEquals(expectedQuery, query); Model values = Utils.loadValues(new String[]{"intersects_people_1.rdf", "intersects_people_2.rdf"}); Query selectQuery = QueryFactory.create(query); @@ -123,7 +124,7 @@ public class SPARQLSelectRendererVisitorTest { assertEquals(resultValues.size(), expectedS2.length); for (String expected : expectedS2) { assertTrue(resultValues.contains(expected), "For expected : " + expected); - } + } resultValues = allResultValues.get("s2"); assertEquals(resultValues.size(), expectedS1.length); @@ -131,9 +132,9 @@ public class SPARQLSelectRendererVisitorTest { assertTrue(resultValues.contains(expected)); } } -// -// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromWithoutLinkkey", "QueryFromSimpleLinkkeyFromIntersects"}) -// public void QueryFromSimpleLinkkeyFromEquals() throws Exception { + +// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromWithoutLinkkey", "QueryFromSimpleLinkkeyAndIntersects"}) +// public void QueryFromSimpleLinkkeyAndEquals() throws Exception { // String alignmentFileName = "people_equals_alignment.rdf"; // EDOALAlignment alignment = Utils.loadAlignement(alignmentFileName); // StringWriter stringWriter = new StringWriter(); @@ -146,7 +147,7 @@ public class SPARQLSelectRendererVisitorTest { // assertEquals(alignment.nbCells(), 1); // Enumeration<Cell> cells = alignment.getElements(); // Cell cell = cells.nextElement(); -// //Without any service +// // 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" @@ -155,34 +156,26 @@ public class SPARQLSelectRendererVisitorTest { // + "?s1 rdf:type ns0:Personne .\n" // + "?s2 rdf:type ns1:Person .\n" // + "?s1 ns0:nom ?o1 .\n" -// + "?s2 ns1:givenName ?o2 .\n" +// + "?s2 ns1:givenName ?o1 .\n" // + "MINUS { \n" -// + "SELECT DISTINCT ?s1 ?s2 \n" -// + "WHERE \n" -// + "{ \n" // + "?s1 ns0:nom ?o1 .\n" // + "?s1 ns0:nom ?o2 .\n" -// + "?s2 ns1:givenName ?o3 .\n" -// + "FILTER(?s1 != ?s2 && ?o2 != ?o1 && ?o3 = ?o1 && NOT EXISTS {\n" +// + "?s2 ns1:givenName ?o1 .\n" +// + "FILTER(?s1 != ?s2 && ?o2 != ?o1 && NOT EXISTS {\n" // + "?s2 ns1:givenName ?o2 .\n" // + "}) \n" -// + "} \n" -// + "} \n" +// + "}\n" // + "MINUS {\n" -// + "SELECT DISTINCT ?s1 ?s2 \n" -// + "WHERE \n" -// + "{ \n" // + "?s1 ns0:nom ?o1 .\n" +// + "?s2 ns1:givenName ?o1 .\n" // + "?s2 ns1:givenName ?o2 .\n" -// + "?s2 ns1:givenName ?o3 .\n" -// + "FILTER(?s1 != ?s2 && ?o2 != ?o3 && ?o2 = ?o1 && NOT EXISTS {\n" -// + "?s1 ns0:nom ?o3 .\n" +// + "FILTER(?s1 != ?s2 && ?o2 != ?o1 && NOT EXISTS {\n" +// + "?s1 ns0:nom ?o2 .\n" // + "})\n" // + "}\n" -// + "}\n" -// + "FILTER(?s1 != ?s2 && ?o2 = ?o1)\n" +// + "FILTER(?s1 != ?s2)\n" // + "}\n"; -// String query = renderer.getQueryFromOnto1ToOnto2(cell);//Where ?p1 is in onto1 +// String query = renderer.getQueryFromOnto1ToOnto2(cell); // System.out.println("QueryFromSimpleLinkkeyFromEquals expected Query : " + expectedQuery); //// assertEquals(query, expectedQuery); // @@ -224,7 +217,7 @@ public class SPARQLSelectRendererVisitorTest { // } // } // -// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {})//"QueryFromSimpleLinkkeyFromIntersects" +// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromSimpleLinkkeyAndIntersects"}) // public void QueryFromRelationLinkkeyAndIntersects() throws Exception { // String alignmentFileName = "people_relation_intersects_alignment.rdf"; // EDOALAlignment alignment = Utils.loadAlignement(alignmentFileName); @@ -252,12 +245,12 @@ public class SPARQLSelectRendererVisitorTest { // + "?s1 ns0:connait ?o1 .\n" // + "?s2 ns1:knows ?o2 .\n" // + "?o2 rdf:type ns1:Person .\n" -// + "?o2 ns1:givenName ?o3 .\n" -// + "FILTER(?s1 != ?s2 && ?o3 = ?o1)\n" +// + "?o2 ns1:givenName ?o1 .\n" +// + "FILTER(?s1 != ?s2)\n" // + "}"; // System.out.println("QueryFromRelationLinkkeyAndIntersects expectedQuery : " + expectedQuery); // System.out.println("query : " + query); -//// assertEquals(expectedQuery, query); +// assertEquals(expectedQuery, query); // Query selectQuery = QueryFactory.create(query); // QueryExecution selectQueryExec = QueryExecutionFactory.create(selectQuery, values); // ResultSet results = selectQueryExec.execSelect(); @@ -300,7 +293,7 @@ public class SPARQLSelectRendererVisitorTest { // } // } // -// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromSimpleLinkkeyFromEquals"}) +// @Test(groups = {"full", "impl", "raw"}, dependsOnMethods = {"QueryFromSimpleLinkkeyAndEquals"}) // public void QueryFromRelationLinkkeyAndEquals() throws Exception { // //With Equals Linkkey => throw Exception, I already don't know to do it, could be performances innefficiente ... // String alignmentFileName = "people_relation_equals_alignment.rdf"; @@ -315,8 +308,44 @@ public class SPARQLSelectRendererVisitorTest { // assertEquals(alignment.nbCells(), 1); // Enumeration<Cell> cells = alignment.getElements(); // 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-core/>\n" +// + "PREFIX ns1:<http://xmlns.com/foaf/0.1/>\n" +// + "SELECT DISTINCT ?s1 ?s2\n" +// + "WHERE {\n" +// + "?s1 rdf:type ns0:Personne .\n" +// + "?s2 rdf:type ns1:Person .\n" +// + "?s1 ns0:connait ?o1 .\n" +// + "?s2 ns1:knows ?o2 .\n" +// + "?o2 rdf:type ns1:Person .\n" +// + "?o2 ns1:givenName ?o1 .\n" +// + "MINUS { \n" +// + "?s1 ns0:connait ?o1 .\n" +// + "?s1 ns0:connait ?o2 .\n" +// + "?s2 ns1:knows ?o3 .\n" +// + "?o3 ns1:givenName ?o1 .\n" +// + "FILTER(?s1 != ?s2 && ?o2 != ?o1 && NOT EXISTS {\n" +// + "?s2 ns1:knows ?o4 .\n" +// + "?o4 ns1:givenName ?o2 .\n" +// + "}) \n" +// + "}\n" +// + "MINUS {\n" +// + "?s1 ns0:connait ?o1 .\n" +// + "?s2 ns1:knows ?o2 .\n" +// + "?o2 ns1:givenName ?o1 .\n" +// + "?s2 ns1:knows ?o3 .\n" +// + "?o3 ns1:givenName ?o4 .\n" +// + "FILTER(?s1 != ?s2 && ?o1 != ?o4 && NOT EXISTS {\n" +// + "?s1 ns0:connait ?o4 .\n" +// + "})\n" +// + "}\n" +// + "FILTER(?s1 != ?s2)\n" +// + "}"; +// // String query = renderer.getQueryFromOnto1ToOnto2(cell); -//// System.out.println("QueryFromSimpleLinkkeyFromIntersects : " + query); +// System.out.println("QueryFromRelationLinkkeyAndEquals expectedQuery : " + expectedQuery); +//// System.out.println("QueryFromRelationLinkkeyAndEquals : " + query); +// assertEquals(query, expectedQuery); // Model values = Utils.loadValues(new String[]{"equals_people_1.rdf", "equals_people_2.rdf"}); // // Query selectQuery = QueryFactory.create(query);