Java Code Examples for org.apache.jena.sparql.syntax.ElementGroup#get()

The following examples show how to use org.apache.jena.sparql.syntax.ElementGroup#get() . 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: ElementTransformSPARQLStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
protected void checkForEquivalence( ElementGroup expectedEG, ElementGroup testEG )
{
	assertEquals( expectedEG.size(), testEG.size() );
	assertEquals( expectedEG.get(0).getClass(), testEG.get(0).getClass() );

	if ( expectedEG.get(0) instanceof ElementPathBlock ) {
		final ElementPathBlock expectedEPB = (ElementPathBlock) expectedEG.get(0);
		final ElementPathBlock convertedEPB = (ElementPathBlock) testEG.get(0);
		checkForEquivalence( expectedEPB, convertedEPB );
	}
	else if ( expectedEG.get(0) instanceof ElementBind ) {
		final ElementBind expectedEB = (ElementBind) expectedEG.get(0);
		final ElementBind convertedEB = (ElementBind) testEG.get(0);
		checkForEquivalence( expectedEB, convertedEB );
	}
	else
		fail();
}
 
Example 2
Source File: ParserSPARQLStarTest.java    From RDFstarTools with Apache License 2.0 6 votes vote down vote up
protected Triple getBindTriplePattern( String queryString ) {
	final ElementGroup eg = getElementGroup(queryString);
	assertEquals( 1, eg.size() );
	assertTrue( "unexpected type (" + eg.get(0).getClass() + ")", 
			    eg.get(0) instanceof ElementBind );

	final ElementBind eb = (ElementBind) eg.get(0);
	assertTrue( "unexpected type (" + eb.getExpr().getClass() + ")", 
		        eb.getExpr() instanceof NodeValue );

	final Node n = ( (NodeValue) eb.getExpr() ).getNode();
	assertTrue( "unexpected type (" + n.getClass() + ")", 
		        n instanceof Node_Triple );

	return ( (Node_Triple) n ).get();
}
 
Example 3
Source File: ParserSPARQLStarTest.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
protected ElementPathBlock getElementPathBlock( String queryString ) {
	final ElementGroup eg = getElementGroup(queryString);
	assertEquals( 1, eg.size() );
	assertTrue( "unexpected type (" + eg.get(0).getClass() + ")", 
			    eg.get(0) instanceof ElementPathBlock );

	return (ElementPathBlock) eg.get(0);
}
 
Example 4
Source File: SelectPlan.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private void augmentQuery(final Query q, final List<Var> variables, final List<Binding> values) {
	if (variables.isEmpty()) {
		return;
	}
	ElementGroup old = (ElementGroup) q.getQueryPattern();
	ElementGroup newQueryPattern = new ElementGroup();
	q.setQueryPattern(newQueryPattern);
	if (old.size() >= 1 && old.get(0) instanceof ElementData) {
		ElementData qData = (ElementData) old.get(0);
		int oldSize = qData.getRows().size();
		qData = mergeValues(qData, variables, values);
		newQueryPattern.addElement(qData);
		for (int i = 1; i < old.size(); i++) {
			newQueryPattern.addElement(old.get(i));
		}
		LOG.debug("New query has " + qData.getRows().size() + " initial values. It had " + oldSize
				+ " values before");
	} else {
		ElementData data = new ElementData();
		variables.forEach(data::add);
		values.forEach(data::add);
		newQueryPattern.addElement(data);
		old.getElements().forEach(newQueryPattern::addElement);
		// unexplainable, but did happen
		check(data, values);
	}
}