本文整理匯總了Java中org.openrdf.query.BindingSet.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java BindingSet.getValue方法的具體用法?Java BindingSet.getValue怎麽用?Java BindingSet.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.query.BindingSet
的用法示例。
在下文中一共展示了BindingSet.getValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleTuple
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
URI pred = fac.createURI( set.getValue( "p" ).stringValue() );
Value val = set.getValue( "o" );
// for baseuri, we need the subject, not the object
// and also, we use the VOID_DS as the key elsewhere in the code
if ( RDF.TYPE.equals( pred ) ) {
pred = SEMTOOL.Database;
val = set.getValue( "db" );
}
else if ( pred.getNamespace().equals( DC.NAMESPACE ) ) {
// silently handle the old DC namespace (ignore our DC-specific URIs)
if ( !( MetadataConstants.DCT_CREATED.equals( pred )
|| MetadataConstants.DCT_MODIFIED.equals( pred ) ) ) {
pred = fac.createURI( DCTERMS.NAMESPACE, pred.getLocalName() );
}
}
result.put( pred, val );
}
示例2: doTupleQuery
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public static List<HashMap<String, Value>> doTupleQuery(RepositoryConnection con, String query) {
List<HashMap<String, Value>> results = new ArrayList<HashMap<String, Value>>();
try {
TupleQuery resultsTable = con.prepareTupleQuery(QueryLanguage.SPARQL, query);
TupleQueryResult bindings = resultsTable.evaluate();
for (@SuppressWarnings("unused")
int row = 0; bindings.hasNext(); row++) {
HashMap<String, Value> riga = new HashMap<String, Value>();
BindingSet pairs = bindings.next();
List<String> names = bindings.getBindingNames();
for (int i = 0; i < names.size(); i++) {
String name = names.get(i);
Value value = pairs.getValue(name);
riga.put(name, value != null && value.stringValue().equals("") ? null : value);
}
results.add(riga);
}
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
示例3: testSPARQLQueryWithMultipleRulesets
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Test
public void testSPARQLQueryWithMultipleRulesets()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 100 ";
MarkLogicTupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setRulesets(SPARQLRuleset.RDFS_FULL,SPARQLRuleset.DOMAIN);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
results.close();
}
示例4: handleTuple
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
Value[] vals = new Value[getNumBindings()];
int idx = 0;
for ( String name : getBindingNames() ) {
vals[idx] = set.getValue( name );
idx++;
}
add( vals );
}
示例5: 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" );
}
}
示例6: handleTuple
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
Object[] vals = new Object[getNumBindings()];
int idx = 0;
for ( String name : getBindingNames() ) {
Value v = set.getValue( name );
vals[idx] = convertToBaseObject( v );
idx++;
}
add( vals );
}
示例7: getBindingSetEntryAndMatchConstants
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
/**
*
* @param key
* - Accumulo key obtained from scan
* @return - Entry<String,BindingSet> satisfying the constant constraints
* @throws BindingSetConversionException
*/
private Map.Entry<String, BindingSet> getBindingSetEntryAndMatchConstants(
Key key) throws BindingSetConversionException {
byte[] row = key.getRow().getBytes();
String[] varOrder = key.getColumnFamily().toString()
.split(ExternalTupleSet.VAR_ORDER_DELIM);
BindingSet bindingSet = converter.convert(row, new VariableOrder(
varOrder));
QueryBindingSet bs = new QueryBindingSet();
for (String var : bindingSet.getBindingNames()) {
String mappedVar = pcjVarMap.get(var);
if (mappedVar.startsWith(ExternalTupleSet.CONST_PREFIX)
&& constantConstraints.containsKey(mappedVar)
&& !constantConstraints.get(mappedVar).equals(
bindingSet.getValue(var))) {
return EMPTY_ENTRY;
} else {
bs.addBinding(mappedVar, bindingSet.getValue(var));
}
}
String orderedValueString = bindingSet.getValue(varOrder[0]).toString();
for (int i = 1; i < maxPrefixLen; i++) {
Value value = bindingSet.getValue(varOrder[i]);
if (value != null) {
orderedValueString = orderedValueString
+ ExternalTupleSet.VALUE_DELIM + value.toString();
}
}
return new RdfCloudTripleStoreUtils.CustomEntry<String, BindingSet>(
orderedValueString, bs);
}
示例8: Key
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public Key(BindingSet bindingSet) {
this.bindingSet = bindingSet;
for (String name : group.getGroupBindingNames()) {
Value value = bindingSet.getValue(name);
if (value != null) {
this.hash ^= value.hashCode();
}
}
}
示例9: getConstrainedStarQuery
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public static StarQuery getConstrainedStarQuery(final StarQuery query, final BindingSet bs) {
if(bs.size() == 0) {
return query;
}
final Set<String> bindingNames = bs.getBindingNames();
final Set<String> unCommonVarNames = query.getUnCommonVars();
final Set<String> intersectVar = Sets.intersection(bindingNames, unCommonVarNames);
if (!query.commonVarConstant()) {
final Value v = bs.getValue(query.getCommonVarName());
if (v != null) {
query.commonVar.setValue(v);
}
}
for(final String s: intersectVar) {
try {
query.nodeColumnCond[query.varPos.get(s)] = query.setValue(query.nodeColumnCond[query.varPos.get(s)], bs.getValue(s));
} catch (final RyaTypeResolverException e) {
e.printStackTrace();
}
}
return query;
}
示例10: loadBlock
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private Object[] loadBlock(int b) throws RepositoryException, QueryEvaluationException {
TupleQuery query = createBlockQuery(b);
TupleQueryResult result = query.evaluate();
BindingSet bindings = result.next();
ObjectConnection con = getObjectConnection();
Object[] list = new Object[BSIZE];
while (bindings != null) {
URI pred = (URI) bindings.getValue("pred");
int idx = getIndex(pred);
Value value = bindings.getValue("value");
Set<URI> types = new HashSet<URI>(4);
do {
Value c = bindings.getValue("value_class");
if (c instanceof URI) {
types.add((URI) c);
}
bindings = result.hasNext() ? result.next() : null;
} while (bindings != null && pred.equals(bindings.getValue("pred")));
int i = idx % BSIZE;
if (value instanceof Literal) {
list[i] = con.getObject((Literal) value);
} else {
list[i] = con.getObject(types, (Resource) value);
}
}
return list;
}
示例11: testSPARQLQueryWithDefaultInferred
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
@Test
public void testSPARQLQueryWithDefaultInferred()
throws Exception {
String queryString = "select ?s ?p ?o { ?s ?p ?o } limit 2 ";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleQuery.setIncludeInferred(true);
TupleQueryResult results = tupleQuery.evaluate();
Assert.assertEquals(results.getBindingNames().get(0), "s");
Assert.assertEquals(results.getBindingNames().get(1), "p");
Assert.assertEquals(results.getBindingNames().get(2), "o");
BindingSet bindingSet = results.next();
Value sV = bindingSet.getValue("s");
Value pV = bindingSet.getValue("p");
Value oV = bindingSet.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#AttaliaGeodata", sV.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV.stringValue());
Assert.assertEquals("0", oV.stringValue());
BindingSet bindingSet1 = results.next();
Value sV1 = bindingSet1.getValue("s");
Value pV1 = bindingSet1.getValue("p");
Value oV1 = bindingSet1.getValue("o");
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#BabylonGeodata", sV1.stringValue());
Assert.assertEquals("http://semanticbible.org/ns/2006/NTNames#altitude", pV1.stringValue());
Assert.assertEquals("0", oV1.stringValue());
results.close();
}
示例12: encode
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public static String encode(final List<String> variables, final BindingSet bindings) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < variables.size(); ++i) {
if (i > 0) {
builder.append('\t');
}
final Value value = bindings.getValue(variables.get(i));
builder.append(format(value));
}
return builder.toString();
}
示例13: selectIncoming
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public List<IncomingNodeStruct> selectIncoming(String resourceURI, String directoryGraph, String metadataRepositoryGraph) throws QueryExecutionException {
String queryString = "SELECT DISTINCT ?predicate ?subject ?subjectType ?subjectName"
+ " FROM <"+directoryGraph+"> "
+ " FROM <"+metadataRepositoryGraph+"> "
+ " WHERE { "
+ " ?subject ?predicate <" + resourceURI + "> ."
+ " OPTIONAL { ?subject <" + Resources.rdfsLabel+"> ?subjectName } ."
+ " OPTIONAL { ?subject a ?subjectType }} ";
logger.debug("Submitting the query: \"" + queryString + "\"");
List<BindingSet> sparqlresults = this.repoManager.query(queryString);
logger.debug("The result returned " + sparqlresults.size() + " results");
List<IncomingNodeStruct> results = new ArrayList<>();
for (BindingSet result : sparqlresults) {
IncomingNodeStruct struct = new IncomingNodeStruct()
.withSubject(result.getValue("subject").stringValue())
.withPredicate(result.getValue("predicate").stringValue());
if (result.getValue("subjectType") != null) {
struct.withSubjectType(result.getValue("subjectType").stringValue());
}
if (result.getValue("subjectName") != null) {
struct.withSubjectName(result.getValue("subjectName").stringValue());
}
results.add(struct);
}
return results;
}
示例14: getVarValue
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
private Value getVarValue(Var var, BindingSet bindings) {
if (var == null) {
return null;
} else if (var.hasValue()) {
return var.getValue();
} else {
return bindings.getValue(var.getName());
}
}
示例15: selectOutgoing
import org.openrdf.query.BindingSet; //導入方法依賴的package包/類
public List<OutgoingNodeStruct> selectOutgoing(String resourceURI) throws QueryExecutionException {
String queryString = "SELECT DISTINCT ?predicate ?object ?objectType ?objectName"
+ " WHERE { "
+ " <" + resourceURI + "> ?predicate ?object ."
+ " OPTIONAL { ?object <"+Resources.rdfsLabel+"> ?objectName } ."
+ " OPTIONAL { ?object a ?objectType }} ";
System.out.println("QUERY"+queryString);
logger.debug("Submitting the query: \"" + queryString + "\"");
List<BindingSet> sparqlresults = this.repoManager.query(queryString);
logger.debug("The result returned " + sparqlresults.size() + " results");
List<OutgoingNodeStruct> results = new ArrayList<>();
for (BindingSet result : sparqlresults) {
OutgoingNodeStruct struct = new OutgoingNodeStruct()
.withObject(result.getValue("object").stringValue())
.withPredicate(result.getValue("predicate").stringValue());
if (result.getValue("objectType") != null) {
struct.withObjectType(result.getValue("objectType").stringValue());
}
if (result.getValue("objectName") != null) {
struct.withObjectName(result.getValue("objectName").stringValue());
}
results.add(struct);
}
return results;
}