Java Code Examples for org.openrdf.query.BindingSet#getBindingNames()

The following examples show how to use org.openrdf.query.BindingSet#getBindingNames() . 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: SPARQLUpdateTestv2.java    From database with GNU General Public License v2.0 6 votes vote down vote up
protected long debugPrintSolutions(final String query)
        throws QueryEvaluationException, RepositoryException,
        MalformedQueryException {
    TupleQueryResult result = con.prepareTupleQuery(QueryLanguage.SPARQL,
            query).evaluate();
    try {
        long n = 0;
        while (result.hasNext()) {
            System.err.println("==> NEXT SOLUTION");
            final BindingSet bset = result.next();
            for (final String bindingName : bset.getBindingNames()) {
                final Binding b = bset.getBinding(bindingName);
                System.err.println(bindingName + " -> " + b);
            }
            n++;
        }
        return n;
    } finally {
        result.close();
    }
}
 
Example 2
Source File: BigdataSparqlTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private void printBindingSet(StringBuilder message, BindingSet bs) {
//		message.append(bs);
    	for (String bn: bs.getBindingNames()) {
    		Value v = bs.getBinding(bn).getValue();
			message.append(bn).append('=').append(v);
    		if (v instanceof BigdataValue) {
    			message.append(' ').append(((BigdataValue)v).getIV()).append(' ');
    		}
    	}
	}
 
Example 3
Source File: CustomSesameDataset.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
/**
 * Execute a SELECT SPARQL query against the graphs
 * 
 * @param qs
 *            SELECT SPARQL query
 * @return list of solutions, each containing a hashmap of bindings
 */
public List<HashMap<String, Value>> runSPARQL(String qs) {
	try {
		RepositoryConnection con = currentRepository.getConnection();
		try {
			TupleQuery query = con.prepareTupleQuery(
					org.openrdf.query.QueryLanguage.SPARQL, qs);
			//System.exit(0);
			TupleQueryResult qres = query.evaluate();
			ArrayList<HashMap<String, Value>> reslist = new ArrayList<HashMap<String, Value>>();
			while (qres.hasNext()) {
				BindingSet b = qres.next();

				Set<String> names = b.getBindingNames();
				HashMap<String, Value> hm = new HashMap<String, Value>();
				for (String n : names) {
					hm.put(n, b.getValue(n));
				}
				reslist.add(hm);
			}
			return reslist;
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: BigdataGraph.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Convert SPARQL/RDF results into PG form.
 */
protected BigdataBindingSet convert(final BindingSet bs) {
    
    final BigdataBindingSet bbs = new BigdataBindingSet();
    
    for (String key : bs.getBindingNames()) {
        
        final Value val= bs.getBinding(key).getValue();
        
        final Object o;
        if (val instanceof Literal) {
            o = factory.fromLiteral((Literal) val);
        } else if (val instanceof URI) {
            o = factory.fromURI((URI) val);
        } else {
            continue;
        }
        
        bbs.put(key, o);
        
    }
    
    return bbs;
    
}