From: <mrp...@us...> - 2010-10-19 20:46:08
|
Revision: 3824 http://bigdata.svn.sourceforge.net/bigdata/?rev=3824&view=rev Author: mrpersonick Date: 2010-10-19 20:46:00 +0000 (Tue, 19 Oct 2010) Log Message: ----------- testing single tail rules Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpContext.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Bigdata2Sesame2BindingSetIterator.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSingleTailRule.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpContext.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpContext.java 2010-10-19 17:29:08 UTC (rev 3823) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/bop/BOpContext.java 2010-10-19 20:46:00 UTC (rev 3824) @@ -279,6 +279,23 @@ } + } else { + + final IVariable<?> var = (IVariable<?>) t + .getProperty(Constant.Annotations.VAR); + + if (var != null) { + + final Object val = e.get(i); + + if (val != null) { + + bindingSet.set(var, new Constant(val)); + + } + + } + } } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Bigdata2Sesame2BindingSetIterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Bigdata2Sesame2BindingSetIterator.java 2010-10-19 17:29:08 UTC (rev 3823) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/Bigdata2Sesame2BindingSetIterator.java 2010-10-19 20:46:00 UTC (rev 3824) @@ -42,6 +42,8 @@ */ private final ICloseableIterator<IBindingSet> src; + private final BindingSet constants; + /** * * @param src @@ -49,12 +51,19 @@ * closed). All bound values in the visited {@link IBindingSet}s * MUST be {@link BigdataValue}s. */ - public Bigdata2Sesame2BindingSetIterator(ICloseableIterator<IBindingSet> src) { + public Bigdata2Sesame2BindingSetIterator(final ICloseableIterator<IBindingSet> src) { + this(src, null); + } + + public Bigdata2Sesame2BindingSetIterator(final ICloseableIterator<IBindingSet> src, final BindingSet constants) { + if (src == null) throw new IllegalArgumentException(); this.src = src; + + this.constants = constants; } @@ -107,6 +116,17 @@ } + if (constants != null) { + + final Iterator<Binding> it = constants.iterator(); + while (it.hasNext()) { + final Binding b = it.next(); + bindingSet.addBinding(b.getName(), b.getValue()); +// bindingSet.addBinding(b); + } + + } + return bindingSet; } Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java 2010-10-19 17:29:08 UTC (rev 3823) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/java/com/bigdata/rdf/sail/BigdataEvaluationStrategyImpl.java 2010-10-19 20:46:00 UTC (rev 3824) @@ -464,7 +464,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query); + return execute(query, bindings); } catch (UnknownOperatorException ex) { @@ -575,7 +575,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query); + return execute(query, bindings); } catch (UnknownOperatorException ex) { @@ -681,7 +681,7 @@ return new EmptyIteration<BindingSet, QueryEvaluationException>(); } - return execute(query); + return execute(query, bindings); } catch (UnknownOperatorException ex) { @@ -1546,7 +1546,10 @@ } return null; } - result = new Constant<IV>(iv); + if (var.isAnonymous()) + result = new Constant<IV>(iv); + else + result = new Constant<IV>(com.bigdata.bop.Var.var(name), iv); } return result; } @@ -1663,8 +1666,16 @@ * * @throws QueryEvaluationException */ +// protected CloseableIteration<BindingSet, QueryEvaluationException> execute( +// final IStep step) +// throws Exception { +// +// return execute(step, null); +// +// } + protected CloseableIteration<BindingSet, QueryEvaluationException> execute( - final IStep step) + final IStep step, final BindingSet constants) throws Exception { final QueryEngine queryEngine = tripleSource.getSail().getQueryEngine(); @@ -1706,7 +1717,7 @@ CloseableIteration<BindingSet, QueryEvaluationException> result = new Bigdata2Sesame2BindingSetIterator<QueryEvaluationException>( new BigdataBindingSetResolverator(database, it2).start(database - .getExecutorService())); + .getExecutorService()), constants); try { // Wait for the Future (checks for errors). @@ -1882,7 +1893,7 @@ try { - return execute(query); + return execute(query, bindings); } catch (Exception ex) { Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSingleTailRule.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSingleTailRule.java 2010-10-19 17:29:08 UTC (rev 3823) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestSingleTailRule.java 2010-10-19 20:46:00 UTC (rev 3824) @@ -27,9 +27,13 @@ package com.bigdata.rdf.sail; import info.aduna.iteration.CloseableIteration; +import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Properties; +import java.util.Set; import org.apache.log4j.Logger; import org.openrdf.model.Literal; import org.openrdf.model.Resource; @@ -49,6 +53,7 @@ import org.openrdf.query.impl.EmptyBindingSet; import org.openrdf.query.parser.ParsedTupleQuery; import org.openrdf.query.parser.QueryParserUtil; +import org.openrdf.repository.Repository; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.sail.SailRepository; import org.openrdf.repository.sail.SailRepositoryConnection; @@ -77,7 +82,7 @@ props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName()); props.setProperty(BigdataSail.Options.JUSTIFY, "false"); - props.setProperty(BigdataSail.Options.TEXT_INDEX, "false"); + props.setProperty(BigdataSail.Options.TEXT_INDEX, "true"); return props; @@ -96,7 +101,7 @@ super(arg0); } - public void testMultiGraphs() throws Exception { + public void testSingleTail() throws Exception { final BigdataSail sail = getSail(); final BigdataSailRepository repo = new BigdataSailRepository(sail); @@ -118,6 +123,10 @@ testValueRoundTrip(cxn.getSailConnection(), mike, likes, rdf); + if (log.isInfoEnabled()) { + log.info("\n" + ((BigdataSail)sail).getDatabase().dumpStore()); + } + } finally { cxn.close(); if (sail instanceof BigdataSail) @@ -126,6 +135,104 @@ } + public void testSingleTailSearch() throws Exception { + + final BigdataSail sail = getSail(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + repo.initialize(); + final BigdataSailRepositoryConnection cxn = repo.getConnection(); + cxn.setAutoCommit(false); + + try { + + final ValueFactory vf = sail.getValueFactory(); + + final String ns = BD.NAMESPACE; + + URI mike = vf.createURI(ns+"Mike"); + URI likes = vf.createURI(ns+"likes"); + URI rdf = vf.createURI(ns+"RDF"); + Literal l1 = vf.createLiteral("Mike"); +/**/ + cxn.setNamespace("ns", ns); + + cxn.add(mike, RDFS.LABEL, l1); + cxn.commit(); + + if (log.isInfoEnabled()) { + log.info("\n" + ((BigdataSail)sail).getDatabase().dumpStore()); + } + + { + + String query = + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX ns: <"+ns+"> " + + + "select ?s ?p ?o " + + "WHERE { " + + " ?s ?p ?o . " + + " filter(?p = <"+RDFS.LABEL+">) " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + TupleQueryResult result = tupleQuery.evaluate(); + +// while (result.hasNext()) { +// System.err.println(result.next()); +// } + + Collection<BindingSet> solution = new LinkedList<BindingSet>(); + solution.add(createBindingSet(new Binding[] { + new BindingImpl("s", mike), + new BindingImpl("p", RDFS.LABEL), + new BindingImpl("o", l1), + })); + + compare(result, solution); + + } + + { + + String query = + "PREFIX rdf: <"+RDF.NAMESPACE+"> " + + "PREFIX rdfs: <"+RDFS.NAMESPACE+"> " + + "PREFIX ns: <"+ns+"> " + + + "select ?s " + + "WHERE { " + + " ?s ns:search \"Mike\" . " + + "}"; + + final TupleQuery tupleQuery = + cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + TupleQueryResult result = tupleQuery.evaluate(); + +// while (result.hasNext()) { +// System.err.println(result.next()); +// } + + Collection<BindingSet> solution = new LinkedList<BindingSet>(); + solution.add(createBindingSet(new Binding[] { + new BindingImpl("s", l1), + })); + + compare(result, solution); + + } + + + } finally { + cxn.close(); + if (sail instanceof BigdataSail) + ((BigdataSail)sail).__tearDownUnitTest(); + } + + } + private void testValueRoundTrip(final SailConnection con, final Resource subj, final URI pred, final Value obj) throws Exception @@ -175,6 +282,68 @@ } } + public void testOptionalFilter() + throws Exception + { + final BigdataSail sail = getSail(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); +// final Sail sail = new MemoryStore(); +// final Repository repo = new SailRepository(sail); + + repo.initialize(); + final RepositoryConnection cxn = repo.getConnection(); + cxn.setAutoCommit(false); + + try { + + final ValueFactory vf = sail.getValueFactory(); + URI s = vf.createURI("urn:test:s"); + URI p1 = vf.createURI("urn:test:p1"); + URI p2 = vf.createURI("urn:test:p2"); + Literal v1 = vf.createLiteral(1); + Literal v2 = vf.createLiteral(2); + Literal v3 = vf.createLiteral(3); + cxn.add(s, p1, v1); + cxn.add(s, p2, v2); + cxn.add(s, p1, v3); + cxn.commit(); + + String qry = + "PREFIX :<urn:test:> " + + "SELECT ?s ?v1 ?v2 " + + "WHERE { " + + " ?s :p1 ?v1 . " + + " OPTIONAL {?s :p2 ?v2 FILTER(?v1 < 3) } " + + "}"; + + TupleQuery query = cxn.prepareTupleQuery(QueryLanguage.SPARQL, qry); + TupleQueryResult result = query.evaluate(); + +// while (result.hasNext()) { +// System.err.println(result.next()); +// } + + Collection<BindingSet> solution = new LinkedList<BindingSet>(); + solution.add(createBindingSet(new Binding[] { + new BindingImpl("s", s), + new BindingImpl("v1", v1), + new BindingImpl("v2", v2), + })); + solution.add(createBindingSet(new Binding[] { + new BindingImpl("s", s), + new BindingImpl("v1", v3), + })); + + compare(result, solution); + + } finally { + cxn.close(); + if (sail instanceof BigdataSail) + ((BigdataSail)sail).__tearDownUnitTest(); + } + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |