badrebelabbess
6/22/2016 - 8:50 AM

Utility method to process rdf, sparql and semantic web

Utility method to process rdf, sparql and semantic web

// Create a SPARQL query
try {
			SPARQLRepository repository = new SPARQLRepository(endpointUrl);
			RepositoryConnection connection;
			TupleQuery query;
			repository.initialize();
			connection = repository.getConnection();
			query = connection.prepareTupleQuery(SPARQL,SAMPLE_QUERY);
			TupleQueryResult queryResult = query.evaluate();
}

// Result of a query into list
List<BindingSet> resultList;
TupleQueryResult queryResult = query.evaluate();
resultList = QueryResults.asList(queryResult); 

// Display result of a query
Value sensors_list=binding.getValue("sensorUri")

// If there are multiple bindding (e.g x and y)
BindingSet binding = queryResult.next();
Value sensor1 = binding.getValue(bindingNames.get(0));