Java Code Examples for org.eclipse.rdf4j.query.Binding#getName()

The following examples show how to use org.eclipse.rdf4j.query.Binding#getName() . 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: ValueMappingBindingSet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Binding mapBinding(Binding binding) {
	return new Binding() {
		@Override
		public String getName() {
			return binding.getName();
		}

		@Override
		public Value getValue() {
			return mapper.apply(binding.getValue());
		}

		@Override
		public String toString() {
			return getName() + "=" + getValue().toString();
		}
	};
}
 
Example 2
Source File: GroupedCheckConversionIteration.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) {
	int bIndex = -1;
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		String name = b.getName();
		bIndex = Integer.parseInt(name.substring(name.lastIndexOf("_")+1));
	}
	return bindings.get(bIndex);
}
 
Example 3
Source File: BoundJoinConversionIteration.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) {
	QueryBindingSet res = new QueryBindingSet();
	int bIndex = -1;
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		String name = b.getName();
		bIndex = Integer.parseInt(name.substring(name.lastIndexOf("_")+1));
		res.addBinding(name.substring(0, name.lastIndexOf("_")), b.getValue());
	}
	res.addAll( bindings.get(bIndex));
	return res;
}
 
Example 4
Source File: GroupedCheckConversionIteration.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {
	int bIndex = -1;
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		String name = b.getName();
		bIndex = Integer.parseInt(name.substring(name.lastIndexOf('_') + 1));
	}
	return bindings.get(bIndex);
}
 
Example 5
Source File: BoundJoinConversionIteration.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {
	QueryBindingSet res = new QueryBindingSet();
	int bIndex = -1;
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		String name = b.getName();
		bIndex = Integer.parseInt(name.substring(name.lastIndexOf('_') + 1));
		res.addBinding(name.substring(0, name.lastIndexOf('_')), b.getValue());
	}
	res.addAll(bindings.get(bIndex));
	return res;
}
 
Example 6
Source File: ServiceJoinConversionIteration.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected BindingSet convert(BindingSet bIn) throws QueryEvaluationException {

	// overestimate the capacity
	SPARQLQueryBindingSet res = new SPARQLQueryBindingSet(bIn.size() + bindings.size());

	int bIndex = -1;
	Iterator<Binding> bIter = bIn.iterator();
	while (bIter.hasNext()) {
		Binding b = bIter.next();
		String name = b.getName();
		if (name.equals("__rowIdx")) {
			bIndex = Integer.parseInt(b.getValue().stringValue());
			continue;
		}
		res.addBinding(b.getName(), b.getValue());
	}

	// should never occur: in such case we would have to create the cross product (which
	// is dealt with in another place)
	if (bIndex == -1) {
		throw new QueryEvaluationException(
				"Invalid join. Probably this is due to non-standard behavior of the SPARQL endpoint. "
						+ "Please report to the developers.");
	}

	res.addAll(bindings.get(bIndex));
	return res;
}
 
Example 7
Source File: StatementMetadataNode.java    From rya with Apache License 2.0 5 votes vote down vote up
private boolean canJoinBindingSets(final BindingSet bs1, final BindingSet bs2) {
    for (final Binding b : bs1) {
        final String name = b.getName();
        final Value val = b.getValue();
        if (bs2.hasBinding(name) && (!bs2.getValue(name).equals(val))) {
            return false;
        }
    }
    return true;
}
 
Example 8
Source File: TransactionWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void serialize(SPARQLUpdateOperation op, XMLWriter xmlWriter) throws IOException {
	String baseURI = op.getBaseURI();
	if (baseURI != null) {
		xmlWriter.setAttribute(TransactionXMLConstants.BASE_URI_ATT, baseURI);
	}
	xmlWriter.setAttribute(TransactionXMLConstants.INCLUDE_INFERRED_ATT, op.isIncludeInferred());
	xmlWriter.startTag(TransactionXMLConstants.SPARQL_UPDATE_TAG);

	// serialize update string
	String updateString = op.getUpdateString();
	xmlWriter.textElement(TransactionXMLConstants.UPDATE_STRING_TAG, updateString);

	// serialize dataset definition (if any)
	Dataset dataset = op.getDataset();
	if (dataset != null) {
		xmlWriter.startTag(TransactionXMLConstants.DATASET_TAG);

		xmlWriter.startTag(TransactionXMLConstants.DEFAULT_GRAPHS_TAG);
		for (IRI defaultGraph : dataset.getDefaultGraphs()) {
			xmlWriter.textElement(TransactionXMLConstants.GRAPH_TAG, defaultGraph.stringValue());
		}
		xmlWriter.endTag(TransactionXMLConstants.DEFAULT_GRAPHS_TAG);

		xmlWriter.startTag(TransactionXMLConstants.NAMED_GRAPHS_TAG);
		for (IRI namedGraph : dataset.getNamedGraphs()) {
			xmlWriter.textElement(TransactionXMLConstants.GRAPH_TAG, namedGraph.stringValue());
		}
		xmlWriter.endTag(TransactionXMLConstants.NAMED_GRAPHS_TAG);

		xmlWriter.startTag(TransactionXMLConstants.DEFAULT_REMOVE_GRAPHS_TAG);
		for (IRI defaultRemoveGraph : dataset.getDefaultRemoveGraphs()) {
			xmlWriter.textElement(TransactionXMLConstants.GRAPH_TAG, defaultRemoveGraph.stringValue());
		}
		xmlWriter.endTag(TransactionXMLConstants.DEFAULT_REMOVE_GRAPHS_TAG);

		if (dataset.getDefaultInsertGraph() != null) {
			xmlWriter.textElement(TransactionXMLConstants.DEFAULT_INSERT_GRAPH,
					dataset.getDefaultInsertGraph().stringValue());
		}
		xmlWriter.endTag(TransactionXMLConstants.DATASET_TAG);
	}

	if (op.getBindings() != null && op.getBindings().length > 0) {
		xmlWriter.startTag(TransactionXMLConstants.BINDINGS);

		for (Binding binding : op.getBindings()) {
			if (binding.getName() != null && binding.getValue() != null
					&& binding.getValue().stringValue() != null) {
				if (binding.getValue() instanceof IRI) {
					xmlWriter.setAttribute(TransactionXMLConstants.NAME_ATT, binding.getName());
					xmlWriter.textElement(TransactionXMLConstants.BINDING_URI, binding.getValue().stringValue());
				}

				if (binding.getValue() instanceof BNode) {
					xmlWriter.setAttribute(TransactionXMLConstants.NAME_ATT, binding.getName());
					xmlWriter.textElement(TransactionXMLConstants.BINDING_BNODE, binding.getValue().stringValue());
				}

				if (binding.getValue() instanceof Literal) {
					xmlWriter.setAttribute(TransactionXMLConstants.NAME_ATT, binding.getName());

					Literal literal = (Literal) binding.getValue();
					if (Literals.isLanguageLiteral(literal)) {
						xmlWriter.setAttribute(TransactionXMLConstants.LANGUAGE_ATT, literal.getLanguage().get());
					} else {
						xmlWriter.setAttribute(TransactionXMLConstants.DATA_TYPE_ATT,
								literal.getDatatype().stringValue());
					}

					xmlWriter.textElement(TransactionXMLConstants.BINDING_LITERAL,
							binding.getValue().stringValue());
				}
			}
		}

		xmlWriter.endTag(TransactionXMLConstants.BINDINGS);
	}

	xmlWriter.endTag(TransactionXMLConstants.SPARQL_UPDATE_TAG);

}