本文整理汇总了Java中org.openrdf.query.Binding类的典型用法代码示例。如果您正苦于以下问题:Java Binding类的具体用法?Java Binding怎么用?Java Binding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binding类属于org.openrdf.query包,在下文中一共展示了Binding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BooleanBindingSet
import org.openrdf.query.Binding; //导入依赖的package包/类
public BooleanBindingSet(final boolean result) {
map = new HashMap<String, Binding>();
Binding binding = new Binding() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public Value getValue() {
ValueFactory vf = new ValueFactoryImpl();
return vf.createLiteral(result);
}
@Override
public String getName() {
return "k0";
}
};
map.put(binding.getName(), binding);
}
示例2: writeDesc
import org.openrdf.query.Binding; //导入依赖的package包/类
/**
* Adds to the description table information for a binding.
*
* @param binding
*/
protected void writeDesc(Binding binding) {
descData.append(NEWLINE);
indent(descData, depth + 1);
descData.append(TABLE_ROW_BEGIN);
descData.append(TABLE_DATA_BEGIN);
descData.append(binding.getName());
descData.append(TABLE_DATA_END);
descData.append(TABLE_DATA_BEGIN);
if (binding.getValue() instanceof BNode) {
descData.append("_:");
}
descData.append(binding.getValue().stringValue());
descData.append(TABLE_DATA_END);
descData.append(TABLE_ROW_END);
}
示例3: handleSolution
import org.openrdf.query.Binding; //导入依赖的package包/类
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
xmlWriter.startTag(RESULT_TAG);
for (String bindingName : bindingNames) {
Binding binding = bindingSet.getBinding(bindingName);
if (binding != null) {
xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName());
xmlWriter.startTag(BINDING_TAG);
writeValue(binding.getValue());
xmlWriter.endTag(BINDING_TAG);
}
}
xmlWriter.endTag(RESULT_TAG);
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
}
}
示例4: testAverageReadLengthNumber
import org.openrdf.query.Binding; //导入依赖的package包/类
@Test
public void testAverageReadLengthNumber() throws IOException,
QueryEvaluationException, MalformedQueryException,
RepositoryException, SailException {
assertTrue(newFile.exists());
BEDFileStore rep = new BEDFileStore();
rep.setDataDir(dataDir);
rep.setBedFile(newFile);
rep.setValueFactory(new SimpleValueFactory());
SailRepository sr = new SailRepository(rep);
rep.initialize();
TupleQuery pTQ = sr.getConnection().prepareTupleQuery(
QueryLanguage.SPARQL, query3);
TupleQueryResult eval = pTQ.evaluate();
assertTrue(eval.hasNext());
BindingSet next = eval.next();
assertNotNull(next);
Binding lb = next.getBinding("avgLength");
assertEquals("1166", lb.getValue()
.stringValue());
}
示例5: assertBindingSet
import org.openrdf.query.Binding; //导入依赖的package包/类
private static void assertBindingSet(final Iterator<BindingSet> bindingSetIter, final Iterator<Resource> expectedValues) {
while (expectedValues.hasNext()) {
final Resource expectedValue = expectedValues.next();
assertTrue(bindingSetIter.hasNext());
final BindingSet bindingSet = bindingSetIter.next();
assertTrue(bindingSet instanceof QueryBindingSet);
assertEquals(1, bindingSet.getBindingNames().size());
final Binding binding = bindingSet.getBinding("s");
assertNotNull(binding);
final Value actualValue = binding.getValue();
assertEquals(expectedValue, actualValue);
}
}
示例6: docToBindingSet
import org.openrdf.query.Binding; //导入依赖的package包/类
private QueryBindingSet docToBindingSet(Document result) {
QueryBindingSet bindingSet = new QueryBindingSet(bindings);
Document valueSet = result.get(AggregationPipelineQueryNode.VALUES, Document.class);
Document typeSet = result.get(AggregationPipelineQueryNode.TYPES, Document.class);
if (valueSet != null) {
for (Map.Entry<String, Object> entry : valueSet.entrySet()) {
String fieldName = entry.getKey();
String valueString = entry.getValue().toString();
String typeString = typeSet == null ? null : typeSet.getString(fieldName);
String varName = varToOriginalName.getOrDefault(fieldName, fieldName);
Value varValue;
if (typeString == null || typeString.equals(XMLSchema.ANYURI.stringValue())) {
varValue = VF.createURI(valueString);
}
else {
varValue = VF.createLiteral(valueString, VF.createURI(typeString));
}
Binding existingBinding = bindingSet.getBinding(varName);
// If this variable is not already bound, add it.
if (existingBinding == null) {
bindingSet.addBinding(varName, varValue);
}
// If it's bound to something else, the solutions are incompatible.
else if (!existingBinding.getValue().equals(varValue)) {
return null;
}
}
}
return bindingSet;
}
示例7: keepBindings
import org.openrdf.query.Binding; //导入依赖的package包/类
/**
* Create a new {@link BindingSet} that only includes the bindings whose names appear within the {@code variableOrder}.
* If no binding is found for a variable, then that binding is just omitted from the resulting object.
*
* @param variableOrder - Defines which bindings will be kept. (not null)
* @param bindingSet - Contains the source {@link Binding}s. (not null)
* @return A new {@link BindingSet} containing only the specified bindings.
*/
public static BindingSet keepBindings(final VariableOrder variableOrder, final BindingSet bindingSet) {
requireNonNull(variableOrder);
requireNonNull(bindingSet);
final MapBindingSet result = new MapBindingSet();
for(final String bindingName : variableOrder) {
if(bindingSet.hasBinding(bindingName)) {
final Binding binding = bindingSet.getBinding(bindingName);
result.addBinding(binding);
}
}
return result;
}
示例8: write
import org.openrdf.query.Binding; //导入依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final VisibilityBindingSet visBindingSet) {
output.writeString(visBindingSet.getVisibility());
// write the number count for the reader.
output.writeInt(visBindingSet.size());
for (final Binding binding : visBindingSet) {
output.writeString(binding.getName());
final RyaType ryaValue = RdfToRyaConversions.convertValue(binding.getValue());
final String valueString = ryaValue.getData();
final URI type = ryaValue.getDataType();
output.writeString(valueString);
output.writeString(type.toString());
}
}
示例9: canJoinBindingSets
import org.openrdf.query.Binding; //导入依赖的package包/类
private boolean canJoinBindingSets(BindingSet bs1, BindingSet bs2) {
for (Binding b : bs1) {
String name = b.getName();
Value val = b.getValue();
if (bs2.hasBinding(name) && (!bs2.getValue(name).equals(val))) {
return false;
}
}
return true;
}
示例10: getSPARQLBindings
import org.openrdf.query.Binding; //导入依赖的package包/类
/**
* converts Sesame BindingSet to java api client SPARQLBindings
*
* @param bindings
* @return
*/
protected SPARQLBindings getSPARQLBindings(SPARQLQueryBindingSet bindings) {
SPARQLBindings sps = new SPARQLBindingsImpl();
for (Binding binding : bindings) {
sps.bind(binding.getName(), binding.getValue().stringValue());
}
return sps;
}
示例11: next
import org.openrdf.query.Binding; //导入依赖的package包/类
@Override
public Binding next() {
final Binding result = this.next;
if (result == null) {
throw new NoSuchElementException();
}
this.next = null;
advance();
return result;
}
示例12: testSesameQueryHandler
import org.openrdf.query.Binding; //导入依赖的package包/类
@Test
@FileParameters("src/test/resources/SesameQueryHandlerTest.csv")
public void testSesameQueryHandler(
String query,
@ConvertParam(value = ParamsConverterTest.StringToStatementsConverter.class) Set<Statement> statements,
@ConvertParam(value = ParamsConverterTest.StringToBindingMapSet.class) Set<Map<String, String>> e,
String assertType) throws MalformedQueryException {
SPARQLParser p = new SPARQLParser();
ParsedQuery q = p.parseQuery(query, null);
SesameQueryHandler h = new SesameQueryHandler(new ThisQueryHandler(statements), q);
ResultSet<BindingSet> r = h.evaluate();
Set<Map<String, String>> a = new HashSet<Map<String, String>>();
while (r.hasNext()) {
BindingSet bs = r.next();
Map<String, String> m = new HashMap<String, String>();
a.add(m);
Iterator<Binding> it = bs.iterator();
while (it.hasNext()) {
Binding b = it.next();
m.put(b.getName(), b.getValue().stringValue());
}
}
if (assertType.equals("assertEquals")) {
assertTrue(CollectionUtils.isEqualCollection(e, a));
return;
}
assertFalse(CollectionUtils.isEqualCollection(e, a));
}
示例13: next
import org.openrdf.query.Binding; //导入依赖的package包/类
/**
* Return the next tuple.
*/
@Override
public Map<String, Node> next() throws TrippiException {
Map<String, Node> to_return = new HashMap<String, Node>();
try {
for (Binding i : result.next()) {
to_return.put(i.getName(), objectNode(i.getValue()));
}
}
catch (Exception e) {
throw new TrippiException("Exception in next().", e);
}
return to_return;
}
示例14: buildHashMap
import org.openrdf.query.Binding; //导入依赖的package包/类
private void buildHashMap() {
try {
this.joinHashMap = new HashMap<List<Binding>, List<BindingSet>>();
// populate hash map with left side results
while (!closed && leftIter.hasNext()) {
BindingSet next = leftIter.next();
// compile join bindings of current binding set
// (cross product will result in empty bindings list)
List<Binding> joinBindings = new ArrayList<Binding>();
for (String bindingName : this.joinBindingNames) {
joinBindings.add(next.getBinding(bindingName));
}
// add join bindings to hash map
List<BindingSet> bindings = joinHashMap.get(joinBindings);
if (bindings == null) {
bindings = new ArrayList<BindingSet>();
joinHashMap.put(joinBindings, bindings);
}
bindings.add(next);
}
} catch (QueryEvaluationException e) {
e.printStackTrace();
}
}
示例15: getBindingValue
import org.openrdf.query.Binding; //导入依赖的package包/类
protected String getBindingValue(Binding binding) {
String val = binding.getValue().stringValue();
if (binding.getValue() instanceof BNode) {
val = "_:" + val;
}
return val;
}