當前位置: 首頁>>代碼示例>>Java>>正文


Java BindingSet.hasBinding方法代碼示例

本文整理匯總了Java中org.openrdf.query.BindingSet.hasBinding方法的典型用法代碼示例。如果您正苦於以下問題:Java BindingSet.hasBinding方法的具體用法?Java BindingSet.hasBinding怎麽用?Java BindingSet.hasBinding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openrdf.query.BindingSet的用法示例。


在下文中一共展示了BindingSet.hasBinding方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private void init(RepositoryConnection conn, String queryName) throws IOException, OpenRDFException {
	trails = new ArrayList<>();
	File queryFile = NanolyticsUtils.getProvViewFile(queryName);
	varNames = new ArrayList<>();
	String queryString = NanolyticsUtils.getQuery(queryFile, varNames);
	varNames = ImmutableList.copyOf(varNames);
	TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	TupleQueryResult result = query.evaluate();
	while (result.hasNext()) {
		BindingSet bs = result.next();
		List<URI> uris = new ArrayList<>();
		for (String n : varNames) {
			if (bs.hasBinding(n)) {
				Value v = bs.getBinding(n).getValue();
				if (!(v instanceof URI)) {
					throw new RuntimeException("Not a URI: " + v);
				}
				uris.add((URI) v);
			} else {
				uris.add(null);
			}
		}
		trails.add(new ProvTrail(uris));
	}
	trails = ImmutableList.copyOf(trails);
}
 
開發者ID:tkuhn,項目名稱:nanolytics,代碼行數:27,代碼來源:ProvNetwork.java

示例2: init

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private void init(RepositoryConnection conn, String queryName) throws IOException, OpenRDFException {
	metrics = new HashMap<String,Object>();
	File queryFile = NanolyticsUtils.getProvMetricFile(queryName);
	varNames = new ArrayList<>();
	String queryString = NanolyticsUtils.getQuery(queryFile, varNames);
	varNames = ImmutableList.copyOf(varNames);
	TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	TupleQueryResult result = query.evaluate();
	if (!result.hasNext()) {
		throw new RuntimeException("Metric calculation failed");
	}
	BindingSet bs = result.next();
	if (result.hasNext()) {
		throw new RuntimeException("Metric calculation led to multiple results");
	}
	for (String n : varNames) {
		if (bs.hasBinding(n)) {
			metrics.put(n, bs.getBinding(n).getValue());
		}
	}
}
 
開發者ID:tkuhn,項目名稱:nanolytics,代碼行數:22,代碼來源:ProvMetric.java

示例3: convert

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public String convert(final BindingSet bindingSet, final VariableOrder varOrder) {
    requireNonNull(bindingSet);
    requireNonNull(varOrder);

    // Convert each Binding to a String.
    final List<String> bindingStrings = new ArrayList<>();
    for(final String varName : varOrder) {
        if(bindingSet.hasBinding(varName)) {
            // Add a value to the binding set.
            final Value value = bindingSet.getBinding(varName).getValue();
            final RyaType ryaValue = RdfToRyaConversions.convertValue(value);
            final String bindingString = ryaValue.getData() + TYPE_DELIM + ryaValue.getDataType();
            bindingStrings.add(bindingString);
        } else {
            // Add a null value to the binding set.
            bindingStrings.add(NULL_VALUE_STRING);
        }
    }

    // Join the bindings using the binding delim.
    return Joiner.on(BINDING_DELIM).join(bindingStrings);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:24,代碼來源:BindingSetStringConverter.java

示例4: handleTuple

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
	// we can *sometimes* use a binding set instead of getResult().add(...)
	// *) if it has only three elements of the type Resource URI Value,

	boolean ok = false;
	if ( 3 == set.size() ) {
		String[] names = new String[3];
		getBindingNames().toArray( names );

		Resource subject = null;
		URI predicate = null;
		Value object = set.getValue( names[2] );

		if ( set.hasBinding( names[0] )
				&& set.getValue( names[0] ) instanceof Resource ) {
			subject = Resource.class.cast( set.getValue( names[0] ) );
		}
		if ( set.hasBinding( names[1] )
				&& set.getValue( names[1] ) instanceof URI ) {
			predicate = URI.class.cast( set.getValue( names[1] ) );
		}

		if ( !( null == subject || null == predicate || null == object ) ) {
			ok = true;
			result.add( subject, predicate, object );
		}
	}

	if ( !ok ) {
		Logger.getLogger( getClass() ).error( "use getResults().add() instead" );
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:34,代碼來源:ModelQueryAdapter.java

示例5: keepBindings

import org.openrdf.query.BindingSet; //導入方法依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:22,代碼來源:BindingSetUtil.java

示例6: canJoinBindingSets

import org.openrdf.query.BindingSet; //導入方法依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:11,代碼來源:StatementMetadataNode.java

示例7: convert

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public byte[] convert(BindingSet bindingSet, VariableOrder varOrder) throws BindingSetConversionException {
    checkNotNull(bindingSet);
    checkNotNull(varOrder);

    // A list that holds all of the byte segments that will be concatenated at the end.
    // This minimizes byte[] construction.
    final List<byte[]> byteSegments = new LinkedList<>();

    try {
        for(final String varName: varOrder) {
            // Only write information for a variable name if the binding set contains it.
            if(bindingSet.hasBinding(varName)) {
                final RyaType rt = RdfToRyaConversions.convertValue(bindingSet.getBinding(varName).getValue());
                final byte[][] serializedVal = RyaContext.getInstance().serializeType(rt);
                byteSegments.add(serializedVal[0]);
                byteSegments.add(serializedVal[1]);
            }

            // But always write the value delimiter. If a value is missing, you'll see two delimiters next to each-other.
            byteSegments.add(DELIM_BYTES);
        }

        return concat(byteSegments);
    } catch (RyaTypeResolverException e) {
        throw new BindingSetConversionException("Could not convert the BindingSet into a byte[].", e);
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:29,代碼來源:AccumuloPcjSerializer.java

示例8: readValue

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private String readValue(BindingSet set, String name, Matcher regex) {
	if (set.hasBinding(name)) {
		return apply(regex, set.getValue(name).stringValue());
	}
	return null;
}
 
開發者ID:mowjoothfm,項目名稱:persistenturls,代碼行數:7,代碼來源:PURLSupport.java

示例9: evaluate

import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final BindingSet bindings) throws QueryEvaluationException {
    final List<BindingSet> list = new ArrayList<>();
    try {
        final Collection<Event> searchEvents;
        final String subj;
        //if the provided binding set has the subject already, set it to the constant subject.
        if(!subjectConstant.isPresent() && bindings.hasBinding(subjectVar.get())) {
            subjectConstant = Optional.of(bindings.getValue(subjectVar.get()).stringValue());
        } else if(bindings.size() != 0) {
            list.add(bindings);
        }

        // If the subject needs to be filled in, check if the subject variable is in the binding set.
        if(subjectConstant.isPresent()) {
            // if it is, fetch that value and then fetch the entity for the subject.
            subj = subjectConstant.get();
            searchEvents = eventStore.search(Optional.of(new RyaURI(subj)), Optional.of(geoFilters), Optional.of(temporalFilters));
        } else {
            searchEvents = eventStore.search(Optional.empty(), Optional.of(geoFilters), Optional.of(temporalFilters));
        }

        for(final Event event : searchEvents) {
            final MapBindingSet resultSet = new MapBindingSet();
            if(event.getGeometry().isPresent()) {
                final Geometry geo = event.getGeometry().get();
                final Value geoValue = ValueFactoryImpl.getInstance().createLiteral(geo.toText());
                final Var geoObj = geoPattern.getObjectVar();
                resultSet.addBinding(geoObj.getName(), geoValue);
            }

            final Value temporalValue;
            if(event.isInstant() && event.getInstant().isPresent()) {
                final Optional<TemporalInstant> opt = event.getInstant();
                DateTime dt = opt.get().getAsDateTime();
                dt = dt.toDateTime(DateTimeZone.UTC);
                final String str = dt.toString(TemporalInstantRfc3339.FORMATTER);
                temporalValue = ValueFactoryImpl.getInstance().createLiteral(str);
            } else if(event.getInterval().isPresent()) {
                temporalValue = ValueFactoryImpl.getInstance().createLiteral(event.getInterval().get().getAsPair());
            } else {
                temporalValue = null;
            }

            if(temporalValue != null) {
                final Var temporalObj = temporalPattern.getObjectVar();
                resultSet.addBinding(temporalObj.getName(), temporalValue);
            }
            list.add(resultSet);
        }
    } catch (final ObjectStorageException e) {
        throw new QueryEvaluationException("Failed to evaluate the binding set", e);
    }
    return new CollectionIteration<>(list);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:56,代碼來源:EventQueryNode.java


注:本文中的org.openrdf.query.BindingSet.hasBinding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。