org.eclipse.rdf4j.query.algebra.StatementPattern Java Examples

The following examples show how to use org.eclipse.rdf4j.query.algebra.StatementPattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccumuloQueryRuleset.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the ruleset and the associated Ranges, given a Configuration that contains a SPARQL query.
 * @param conf Configuration including the query and connection information.
 * @throws IOException if the range can't be resolved
 * @throws QueryRulesetException if the query can't be translated to valid rules
 */
public AccumuloQueryRuleset(final RdfCloudTripleStoreConfiguration conf) throws IOException, QueryRulesetException {
    // Extract StatementPatterns and conditions from the query
    super(conf);
    // Turn StatementPatterns into Ranges
    ryaContext = RyaTripleContext.getInstance(conf);
    for (final CopyRule rule : rules) {
        final StatementPattern sp = rule.getStatement();
        final Map.Entry<TABLE_LAYOUT, ByteRange> entry = getRange(sp);
        final TABLE_LAYOUT layout = entry.getKey();
        final ByteRange byteRange = entry.getValue();
        final Range range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
        if (!tableRanges.containsKey(layout)) {
            tableRanges.put(layout, new LinkedList<Range>());
        }
        tableRanges.get(layout).add(range);
    }
}
 
Example #2
Source File: EventQueryNode.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance of {@link EventQueryNode}.
 * @param usedFilters
 *
 * @param type - The type of {@link Event} this node matches. (not null)
 * @param patterns - The query StatementPatterns that are solved using an
 *   Event of the Type. (not null)
 * @param entities - The {@link EventStorage} that will be searched to match
 *   {@link BindingSet}s when evaluating a query. (not null)
 */
private EventQueryNode(final EventStorage eventStore, final StatementPattern geoPattern, final StatementPattern temporalPattern, final Collection<IndexingExpr> geoFilters, final Collection<IndexingExpr> temporalFilters, final Collection<FunctionCall> usedFilters) throws IllegalStateException {
    this.geoPattern = requireNonNull(geoPattern);
    this.temporalPattern = requireNonNull(temporalPattern);
    this.geoFilters = requireNonNull(geoFilters);
    this.temporalFilters = requireNonNull(temporalFilters);
    this.eventStore = requireNonNull(eventStore);
    this.usedFilters = requireNonNull(usedFilters);
    bindingNames = new HashSet<>();

    // Subject based preconditions.
    verifySameSubjects(getPatterns());
    // Predicate based preconditions.
    verifyAllPredicatesAreConstants(getPatterns());

    // The Subject may either be constant or a variable.
    final Var subject = patterns.iterator().next().getSubjectVar();
    subjectIsConstant = subject.isConstant();
    if(subjectIsConstant) {
        subjectConstant = Optional.of( subject.getValue().toString() );
        subjectVar = Optional.empty();
    } else {
        subjectConstant = Optional.empty();
        subjectVar = Optional.of( subject.getName() );
    }
}
 
Example #3
Source File: QueryAlgebraUtil.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Construct the statement string, i.e. "s p ?o_varID FILTER ?o_N=o ". This kind of statement
 * pattern is necessary to later on identify available results.
 * 
 * @param stmt
 * @param varID
 * @param varNames
 * @param bindings
 * @return
 */
protected static TupleExpr constructStatementCheckId(StatementPattern stmt, int varID, Set<String> varNames, BindingSet bindings) {
	
	String _varID = Integer.toString(varID);
	Var subj = appendVarId(stmt.getSubjectVar(), _varID, varNames, bindings);
	Var pred = appendVarId(stmt.getPredicateVar(), _varID, varNames, bindings);
	
	Var obj = new Var("o_" + _varID);
	varNames.add("o_" + _varID);
			
	Value objValue;
	if (stmt.getObjectVar().hasValue()) {
		objValue = stmt.getObjectVar().getValue();
	} else if (bindings.hasBinding(stmt.getObjectVar().getName())){
		objValue = bindings.getBinding(stmt.getObjectVar().getName()).getValue();
	} else {
		// just to make sure that we see an error, will be deleted soon
		throw new RuntimeException("Unexpected.");
	}
	
	Compare cmp = new Compare(obj, new ValueConstant(objValue));
	cmp.setOperator(CompareOp.EQ);
	Filter filter = new Filter( new StatementPattern(subj, pred, obj), cmp);
			
	return filter;
}
 
Example #4
Source File: GeneralizedExternalProcessor.java    From rya with Apache License 2.0 6 votes vote down vote up
private static Set<QueryModelNode> getQNodes(String node, QueryModelNode queryNode) {

        if (node.equals("sp")) {
            Set<QueryModelNode> eSet = new HashSet<QueryModelNode>();
            StatementPatternCollector spc = new StatementPatternCollector();
            queryNode.visit(spc);
            List<StatementPattern> spList = spc.getStatementPatterns();
            eSet.addAll(spList);
            // returns empty set if list contains duplicate StatementPatterns
            if (spList.size() > eSet.size()) {
                return Sets.newHashSet();
            } else {
                return eSet;
            }
        } else if (node.equals("filter")) {

            FilterCollector fvis = new FilterCollector();
            queryNode.visit(fvis);

            return Sets.newHashSet(fvis.getFilters());
        } else {

            throw new IllegalArgumentException("Invalid node type.");
        }
    }
 
Example #5
Source File: HasSelfVisitorTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testTypePattern() throws Exception {
    final InferenceEngine inferenceEngine = mock(InferenceEngine.class);
    final Set<IRI> narcissistProps = new HashSet<>();
    narcissistProps.add(love);
    when(inferenceEngine.getHasSelfImplyingType(narcissist)).thenReturn(narcissistProps);
    final Var subj = new Var("s");
    final Var obj = new Var("o", narcissist);
    obj.setConstant(true);
    final Var pred = new Var("p", RDF.TYPE);
    pred.setConstant(true);

    final Projection query = new Projection(new StatementPattern(subj, pred, obj),
            new ProjectionElemList(new ProjectionElem("s", "subject")));
    query.visit(new HasSelfVisitor(conf, inferenceEngine));

    Assert.assertTrue(query.getArg() instanceof Union);
    final Union union = (Union) query.getArg();
    Assert.assertTrue(union.getRightArg() instanceof StatementPattern);
    Assert.assertTrue(union.getLeftArg() instanceof StatementPattern);
    final StatementPattern expectedLeft = new StatementPattern(subj, pred, obj);
    final StatementPattern expectedRight = new StatementPattern(subj, new Var("urn:love", love), subj);
    Assert.assertEquals(expectedLeft, union.getLeftArg());
    Assert.assertEquals(expectedRight, union.getRightArg());
}
 
Example #6
Source File: HibiscusSourceSelection.java    From CostFed with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * HiBISCuS Index lookup for rdf:type and its its corresponding values
 * @param p Predicate i.e. rdf:type
 * @param o Predicate value
 * @param stmt Statement Pattern
 * @throws RepositoryException Repository Error
 * @throws MalformedQueryException Query Error
 * @throws QueryEvaluationException Query Execution Error
 */
public void FedSumClassLookup(StatementPattern stmt, String p, String o) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
	
	  String  queryString = "Prefix ds:<http://aksw.org/fedsum/> "
		   		+ "SELECT  Distinct ?url "
			   	+ " WHERE {?s ds:url ?url. "
				+ " 		?s ds:capability ?cap. "
				+ "		   ?cap ds:predicate <" + p + ">."
						+ "?cap ds:objAuthority  <" + o + "> }" ;
	    TupleQuery tupleQuery = getSummaryConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
		 TupleQueryResult result = tupleQuery.evaluate();
		   while(result.hasNext())
		   {
			  String endpoint = result.next().getValue("url").stringValue();
				String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
				addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
		   }
}
 
Example #7
Source File: SparqlToPipelineTransformVisitorTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsupportedExtension() throws Exception {
    StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
    List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"),
            new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"),
            new ExtensionElem(new ValueConstant(TAKES), "constant"));
    Extension extensionNode = new Extension(sp, elements);
    QueryRoot queryTree = new QueryRoot(extensionNode);
    SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
    queryTree.visit(visitor);
    Assert.assertTrue(queryTree.getArg() instanceof Extension);
    Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
    TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
    Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
    AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
    Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
 
Example #8
Source File: EntityOptimizer.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void meet(Join node) {
    try {
        if (node.getLeftArg() instanceof FixedStatementPattern && node.getRightArg() instanceof DoNotExpandSP) {
            return;
        }
        List<TupleExpr> joinArgs = getJoinArgs(node, new ArrayList<TupleExpr>());
        HashMultimap<String, StatementPattern> varMap = getVarBins(joinArgs);
        while (!varMap.keySet().isEmpty()) {
            String s = getHighestPriorityKey(varMap);
            constructTuple(varMap, joinArgs, s);
        }
        List<TupleExpr> filterChain = getFilterChain(joinArgs);

        for (TupleExpr te : joinArgs) {
            if (!(te instanceof StatementPattern) || !(te instanceof EntityTupleSet)) {
                te.visit(this);
            }
        }
        // Replace old join hierarchy
        node.replaceWith(getNewJoin(joinArgs, filterChain));

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: ConstructGraphTest.java    From rya with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructGraph() throws MalformedQueryException, UnsupportedEncodingException {
    String query = "select ?x where { ?x <uri:talksTo> <uri:Bob>. ?y <uri:worksAt> ?z }";

    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> patterns = StatementPatternCollector.process(pq.getTupleExpr());
    ConstructGraph graph = new ConstructGraph(patterns);

    QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("x", VF.createIRI("uri:Joe"));
    bs.addBinding("y", VF.createIRI("uri:Bob"));
    bs.addBinding("z", VF.createIRI("uri:BurgerShack"));
    VisibilityBindingSet vBs = new VisibilityBindingSet(bs,"FOUO");
    Set<RyaStatement> statements = graph.createGraphFromBindingSet(vBs);
    
    RyaStatement statement1 = new RyaStatement(new RyaIRI("uri:Joe"), new RyaIRI("uri:talksTo"), new RyaIRI("uri:Bob"));
    RyaStatement statement2 = new RyaStatement(new RyaIRI("uri:Bob"), new RyaIRI("uri:worksAt"), new RyaIRI("uri:BurgerShack"));
    Set<RyaStatement> expected = Sets.newHashSet(Arrays.asList(statement1, statement2));
    expected.forEach(x-> x.setColumnVisibility("FOUO".getBytes()));
    ConstructGraphTestUtils.ryaStatementSetsEqualIgnoresTimestamp(expected, statements);
}
 
Example #10
Source File: VOIDSourceSelector.java    From semagrow with Apache License 2.0 5 votes vote down vote up
private Collection<SourceMetadata> getSources(Iterable<StatementPattern> patterns, Dataset dataset, BindingSet bindings) {
    Collection<SourceMetadata> metadata = new LinkedList<SourceMetadata>();
    for (StatementPattern pattern : patterns) {
        metadata.addAll(getSources(pattern, dataset, bindings));
    }
    return metadata;
}
 
Example #11
Source File: GeoEnabledFilterFunctionOptimizer.java    From rya with Apache License 2.0 5 votes vote down vote up
private void processPropertySearches(final TupleExpr tupleExpr, final Collection<Var> searchProperties) {
    final MatchStatementVisitor matchStatements = new MatchStatementVisitor(searchProperties);
    tupleExpr.visit(matchStatements);
    for (final StatementPattern matchStatement: matchStatements.matchStatements) {
        final Var subject = matchStatement.getSubjectVar();
        if (subject.hasValue() && !(subject.getValue() instanceof Resource)) {
            throw new IllegalArgumentException("Query error: Found " + subject.getValue() + ", expected an IRI or BNode");
        }
        Validate.isTrue(subject.hasValue() || subject.getName() != null);
        Validate.isTrue(!matchStatement.getObjectVar().hasValue() && matchStatement.getObjectVar().getName() != null);
        buildQuery(tupleExpr, matchStatement);
    }
}
 
Example #12
Source File: CardinalityVisitor.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void meet(StatementPattern stmt) {
	List<StatementSource> stmtSrces = queryInfo.getSourceSelection().getStmtToSources().get(stmt);
	current.card = Cardinality.getTriplePatternCardinality(queryInfo, stmt, stmtSrces);
	assert(current.card != 0);
	current.sel = current.card/(double)Cardinality.getTotalTripleCount(getSummaryConnection(), stmtSrces);
	current.mvsbjkoef = Cardinality.getTriplePatternSubjectMVKoef(queryInfo, stmt, stmtSrces);
	current.mvobjkoef = Cardinality.getTriplePatternObjectMVKoef(queryInfo, stmt, stmtSrces);
}
 
Example #13
Source File: QueryStringUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Construct a boolean ASK query for the provided statement.
 *
 * @param stmt
 * @param bindings
 * @return the ASK query string
 */
public static String askQueryString(StatementPattern stmt, BindingSet bindings, Dataset dataset) {

	Set<String> varNames = new HashSet<>();
	String s = constructStatement(stmt, varNames, bindings);

	StringBuilder res = new StringBuilder();

	res.append("ASK ");
	appendDatasetClause(res, dataset);
	res.append(" { ");
	res.append(s).append(" }");

	return res.toString();
}
 
Example #14
Source File: QueryJoinOptimizer.java    From rya with Apache License 2.0 5 votes vote down vote up
protected List<Var> getStatementPatternVars(TupleExpr tupleExpr) {
    List<StatementPattern> stPatterns = StatementPatternCollector.process(tupleExpr);
    List<Var> varList = new ArrayList<Var>(stPatterns.size() * 4);
    for (StatementPattern sp : stPatterns) {
        sp.getVars(varList);
    }
    return varList;
}
 
Example #15
Source File: EntityQueryNodeIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void constructor_predicateNotPartOfType() throws Exception {
    // A pattern that does uses a predicate that is not part of the type.
    final List<StatementPattern> patterns = getSPs(
            "SELECT * WHERE { " +
                "?subject <" + RDF.TYPE + "> <urn:person> ."+
                "?subject <urn:age> ?age . " +
                "?subject <urn:eye> ?eye . " +
                "?subject <urn:name> ?name . " +
                "?subject <urn:notPartOfType> ?value . " +
            "}");

    // This will fail.
    new EntityQueryNode(PERSON_TYPE, patterns, mock(EntityStorage.class));
}
 
Example #16
Source File: TopologyFactoryTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionStatementPattern() throws Exception {
    final String query = "SELECT * WHERE { "
            + "?person <urn:talksTo> ?otherPerson . "
            + "}";

    FACTORY.build(query, "source", "sink", new RandomUUIDFactory());
    final List<ProcessorEntry> entries = FACTORY.getProcessorEntry();

    assertTrue(entries.get(0).getNode() instanceof Projection);
    assertTrue(entries.get(1).getNode() instanceof StatementPattern);

    final StatementPattern expected = new StatementPattern(new Var("person"), TALKS_TO, new Var("otherPerson"));
    assertEquals(expected, entries.get(1).getNode());
}
 
Example #17
Source File: StatementMetadataNode.java    From rya with Apache License 2.0 5 votes vote down vote up
private Set<String> getVariableNames() {
    final Set<String> vars = new HashSet<>();
    for (final StatementPattern pattern : patterns) {
        for (final Var var : pattern.getVarList()) {
            if (var.getValue() == null) {
                vars.add(var.getName());
            }
        }
    }
    return vars;
}
 
Example #18
Source File: AccumuloSelectivityEvalDAO.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public void meetNode(QueryModelNode node) throws RuntimeException {
    if (node instanceof ExternalSet || node instanceof StatementPattern) {
        eSet.add(node);
    }
    super.meetNode(node);
}
 
Example #19
Source File: SparqlTripleSource.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> getStatements(
		StatementPattern stmt, RepositoryConnection conn,
		BindingSet bindings, FilterValueExpr filterExpr)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException  {
	
	throw new RuntimeException("NOT YET IMPLEMENTED.");
}
 
Example #20
Source File: ParallelUnionTask.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ParallelUnionTask(ParallelExecutor<BindingSet> unionControl, StatementPattern stmt, Endpoint endpoint,
		BindingSet bindings, FilterValueExpr filterExpr, QueryInfo queryInfo) {
	this.endpoint = endpoint;
	this.stmt = stmt;
	this.bindings = bindings;
	this.unionControl = unionControl;
	this.filterExpr = filterExpr;
	this.queryInfo = queryInfo;
}
 
Example #21
Source File: VOIDStatistics.java    From semagrow with Apache License 2.0 5 votes vote down vote up
private boolean isTypeClass(StatementPattern pattern) {
    Value predVal = pattern.getPredicateVar().getValue();
    Value objVal = pattern.getObjectVar().getValue();

    if (predVal != null && objVal != null && predVal.equals(RDF.TYPE))
        return true;
    else
        return false;
}
 
Example #22
Source File: QueryAlgebraUtil.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
public static StatementPattern toStatementPattern(Resource subj, IRI pred, Value obj) {
	Var s = subj==null ? new Var("s") : new Var("const_s", subj);
	Var p = pred==null ? new Var("p") : new Var("const_p", pred);
	Var o = obj==null ? new Var("o") : new Var("const_o", obj);
	// TODO context
	
	return new StatementPattern(s, p, o);
}
 
Example #23
Source File: AccumuloSelectivityEvalDAOTest.java    From rya with Apache License 2.0 5 votes vote down vote up
private List<StatementPattern> getSpList(String query) throws MalformedQueryException {

        SPARQLParser sp = new SPARQLParser();
        ParsedQuery pq = sp.parseQuery(query, null);
        TupleExpr te = pq.getTupleExpr();

        return StatementPatternCollector.process(te);
    }
 
Example #24
Source File: VOIDSourceSelector.java    From semagrow with Apache License 2.0 5 votes vote down vote up
private Collection<SourceMetadata> uritoSourceMetadata(StatementPattern pattern, Collection<IRI> endpoints) {
    Collection<SourceMetadata> metadata = new LinkedList<SourceMetadata>();
    for (IRI e : endpoints) {
        metadata.add(createSourceMetadata(pattern, e));
    }
    return metadata;
}
 
Example #25
Source File: StatisticsUtil.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Statement toStatement(StatementPattern stmt, BindingSet bindings) {
	
	Value subj = toValue(stmt.getSubjectVar(), bindings);
	Value pred = toValue(stmt.getPredicateVar(), bindings);
	Value obj = toValue(stmt.getObjectVar(), bindings);
	
	return new UnboundStatement((Resource)subj, (IRI)pred, obj);
}
 
Example #26
Source File: IntersectionOfVisitor.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
protected void meetSP(final StatementPattern node) throws Exception {
    final StatementPattern currentNode = node.clone();
    final Var subVar = node.getSubjectVar();
    final Var predVar = node.getPredicateVar();
    final Var objVar = node.getObjectVar();
    final Var conVar = node.getContextVar();
    if (predVar != null && objVar != null && objVar.getValue() != null && RDF.TYPE.equals(predVar.getValue()) && !EXPANDED.equals(conVar)) {
        final List<Set<Resource>> intersections = inferenceEngine.getIntersectionsImplying((IRI) objVar.getValue());
        if (intersections != null && !intersections.isEmpty()) {
            final List<TupleExpr> joins = new ArrayList<>();
            for (final Set<Resource> intersection : intersections) {
                final Set<Resource> sortedIntersection = new TreeSet<>(new ResourceComparator());
                sortedIntersection.addAll(intersection);

                // Create a join tree of all statement patterns in the
                // current intersection.
                final TupleExpr joinTree = createJoinTree(new ArrayList<>(sortedIntersection), subVar, conVar);
                if (joinTree != null) {
                    joins.add(joinTree);
                }
            }

            if (!joins.isEmpty()) {
                // Combine all the intersection join trees for the type
                // together into a union tree.  This will be a join tree if
                // only one intersection exists.
                final TupleExpr unionTree = createUnionTree(joins);
                // Union the above union tree of intersections with the
                // original node.
                final Union union = new InferUnion(unionTree, currentNode);
                node.replaceWith(union);
                log.trace("Replacing node with inferred intersection union: " + union);
            }
        }
    }
}
 
Example #27
Source File: TBSSSourceSelectionOriginal.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Search Quetzal index for the given triple pattern p with sbj authority and obj authority.
 * Note: sa, oa can be null i.e. for unbound tuple 
 * @param stmt Statement pattern	
 * @param sa Subject authority
 * @param p Predicate
 * @param oa Object authority
 */
public void lookupFedSum(StatementPattern stmt, String sa, String p, String oa) {
	String  queryString = getFedSumLookupQuery(sa, p, oa) ;
	TupleQuery tupleQuery = getSummaryConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	//System.out.println(queryString);
	TupleQueryResult result = tupleQuery.evaluate();
	while(result.hasNext())
	{
		String endpoint = result.next().getValue("url").stringValue();
		String id = "sparql_" + endpoint.replace("http://", "").replace("/", "_");
		//System.out.println(stmt.getPredicateVar().getValue() + " source: " + id);
		addSource(stmt, new StatementSource(id, StatementSourceType.REMOTE));
	}
}
 
Example #28
Source File: BGPCollector.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(StatementPattern sp) throws X {
	if (statementPatterns == null) {
		statementPatterns = new ArrayList<>();
	}
	statementPatterns.add(sp);
}
 
Example #29
Source File: SparqlTripleSource.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> getStatements(
		StatementPattern stmt, BindingSet bindings, FilterValueExpr filterExpr, QueryInfo queryInfo)
		throws RepositoryException, MalformedQueryException,
		QueryEvaluationException {

	throw new RuntimeException("NOT YET IMPLEMENTED.");
}
 
Example #30
Source File: MongoDbSmartUriIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testStorage() throws SmartUriException, RuntimeException {
    smartUriConverter.storeEntity(BOB_ENTITY);

    final String sparql = "SELECT * WHERE { " +
        "<" + BOB.getData() + "> <" + RDF.TYPE + "> <" + PERSON_TYPE.getId().getData() + "> . " +
        "<" + BOB.getData() + "> <" + HAS_SSN.getData() + "> ?ssn . " +
        "<" + BOB.getData() + "> <" + HAS_AGE.getData() + "> ?age . " +
        "<" + BOB.getData() + "> <" + HAS_WEIGHT.getData() + "> ?weight . " +
        "<" + BOB.getData() + "> <" + HAS_ADDRESS.getData() + "> ?address . " +
    "}";

    final StatementPatternCollector spCollector = new StatementPatternCollector();
    new SPARQLParser().parseQuery(sparql, null).getTupleExpr().visit(spCollector);
    final List<StatementPattern> patterns = spCollector.getStatementPatterns();
    final EntityQueryNode entityQueryNode = new EntityQueryNode(PERSON_TYPE, patterns, smartUriConverter.getEntityStorage());
    final QueryBindingSet queryBindingSet = new QueryBindingSet();
    final Property ssnProperty = BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get();
    queryBindingSet.addBinding(HAS_SSN.getData(), RyaToRdfConversions.convertValue(ssnProperty.getValue()));

    final CloseableIteration<BindingSet, QueryEvaluationException> iter = entityQueryNode.evaluate(queryBindingSet);
    int count = 0;
    // These should match what was used in the SPARQL query.
    final List<String> queryParamNames = Lists.newArrayList("ssn", "age", "weight", "address");
    while (iter.hasNext()) {
        final BindingSet bs = iter.next();
        assertTrue(bs.getBindingNames().containsAll(queryParamNames));
        count++;
    }
    assertEquals(count, 1);
}