final String queryString = "SELECT ?title ?price WHERE { " +
"?x <http://purl.org/dc/elements/1.1/title> ?title . " +
"OPTIONAL { ?x <http://example.org/ns#price> ?price . } " +
"}";
Variable title = new Variable("title");
Variable price = new Variable("price");
SimpleSelectQuery selectQuery = new SimpleSelectQuery();
selectQuery.addSelection(title);
selectQuery.addSelection(price);
Variable x = new Variable("x");
Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
triplePatterns.add(new SimpleTriplePattern(x,
new UriRef("http://purl.org/dc/elements/1.1/title"), title));
SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);