From: <tho...@us...> - 2014-02-21 19:46:44
|
Revision: 7865 http://sourceforge.net/p/bigdata/code/7865 Author: thompsonbry Date: 2014-02-21 19:46:40 +0000 (Fri, 21 Feb 2014) Log Message: ----------- more RDR parser tests Modified Paths: -------------- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestReificationDoneRightParser.java Modified: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestReificationDoneRightParser.java =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestReificationDoneRightParser.java 2014-02-21 19:39:06 UTC (rev 7864) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/sparql/TestReificationDoneRightParser.java 2014-02-21 19:46:40 UTC (rev 7865) @@ -591,7 +591,171 @@ * <pre> * prefix : <http://example.com/> * SELECT ?a { - * BIND( <<?a ?b ?c>> >> as ?sid ) . + * ?d ?e <<?a ?b ?c>> . + * } + * </pre> + * + * Should be translated as : + * + * <pre> + * SP(?a, ?b, ?c) as ?sid-1 . + * SP(?d, ?e, ?-sid-1). + * </pre> + * + * Note that the SP for the first bound triple pattern will enforce the + * semantics that the triple must exist in the data in order for the query + * to succeed. + */ + public void test_triple_ref_pattern_all_vars() + throws MalformedQueryException, TokenMgrError, ParseException { + + final String sparql // + = "prefix : <http://example.com/>\n" // + + "select ?a {\n"// + + " ?d ?e <<?a ?b ?c>> .\n" + + "}"; + + final QueryRoot expected = new QueryRoot(QueryType.SELECT); + { + + final VarNode a = new VarNode("a"); + final VarNode b = new VarNode("b"); + final VarNode c = new VarNode("c"); + final VarNode d = new VarNode("d"); + final VarNode e = new VarNode("e"); + final VarNode sid = new VarNode("-sid-1"); + + { + final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(); + expected.setPrefixDecls(prefixDecls); + prefixDecls.put("", "http://example.com/"); + } + + final ProjectionNode projection = new ProjectionNode(); + projection.addProjectionVar(new VarNode("a")); + expected.setProjection(projection); + + final JoinGroupNode whereClause = new JoinGroupNode(); + expected.setWhereClause(whereClause); + + // SP(?a, ?b, ?c) as ?sid . + final StatementPatternNode sp1 = new StatementPatternNode(// + a,// + b,// + c,// + null/* c */,// + Scope.DEFAULT_CONTEXTS); + sp1.setSid(sid); + + // SP(?d, ?e, ?sid). + final StatementPatternNode sp2 = new StatementPatternNode(// + d,// + e,// + sid,// + null/* c */,// + Scope.DEFAULT_CONTEXTS); + + whereClause.addChild(sp1); + + whereClause.addChild(sp2); + + } + + final QueryRoot actual = parse(sparql, baseURI); + + assertSameAST(sparql, expected, actual); + + } + + /** + * A unit test when the triple reference pattern is a constant. + * + * <pre> + * prefix : <http://example.com/> + * SELECT ?a { + * <<?a ?b ?c>> ?d ?e . + * } + * </pre> + * + * Should be translated as : + * + * <pre> + * SP(?a, ?b, ?c) as ?sid-1 . + * SP(?-sid-1, ?d, ?e). + * </pre> + * + * Note that the SP for the first bound triple pattern will enforce the + * semantics that the triple must exist in the data in order for the query + * to succeed. + */ + public void test_triple_ref_pattern_all_vars2() + throws MalformedQueryException, TokenMgrError, ParseException { + + final String sparql // + = "prefix : <http://example.com/>\n" // + + "select ?a {\n"// + + " <<?a ?b ?c>> ?d ?e .\n" + + "}"; + + final QueryRoot expected = new QueryRoot(QueryType.SELECT); + { + + final VarNode a = new VarNode("a"); + final VarNode b = new VarNode("b"); + final VarNode c = new VarNode("c"); + final VarNode d = new VarNode("d"); + final VarNode e = new VarNode("e"); + final VarNode sid = new VarNode("-sid-1"); + + { + final Map<String, String> prefixDecls = new LinkedHashMap<String, String>(); + expected.setPrefixDecls(prefixDecls); + prefixDecls.put("", "http://example.com/"); + } + + final ProjectionNode projection = new ProjectionNode(); + projection.addProjectionVar(new VarNode("a")); + expected.setProjection(projection); + + final JoinGroupNode whereClause = new JoinGroupNode(); + expected.setWhereClause(whereClause); + + // SP(?a, ?b, ?c) as ?sid . + final StatementPatternNode sp1 = new StatementPatternNode(// + a,// + b,// + c,// + null/* c */,// + Scope.DEFAULT_CONTEXTS); + sp1.setSid(sid); + + // SP(?sid, ?d, ?e). + final StatementPatternNode sp2 = new StatementPatternNode(// + sid,// + d,// + e,// + null/* c */,// + Scope.DEFAULT_CONTEXTS); + + whereClause.addChild(sp1); + + whereClause.addChild(sp2); + + } + + final QueryRoot actual = parse(sparql, baseURI); + + assertSameAST(sparql, expected, actual); + + } + + /** + * A unit test when the triple reference pattern is a constant. + * + * <pre> + * prefix : <http://example.com/> + * SELECT ?a { + * BIND( <<?a ?b ?c>> as ?sid ) . * ?d ?e ?sid . * } * </pre> @@ -607,7 +771,7 @@ * semantics that the triple must exist in the data in order for the query * to succeed. */ - public void test_triple_ref_pattern_all_vars() + public void test_triple_ref_pattern_all_vars_with_explicit_bind() throws MalformedQueryException, TokenMgrError, ParseException { final String sparql // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |