How about:
prefix : <http://example.org/>
Select ?alice ?address where {
?alice :hasAddress ?address;
:hasName "Alice"
}
On Thu, Jun 7, 2018, 12:36 AM Samita Bai / PhD CS Scholar @ City Campus <
[email protected]> wrote:
> I need some help with the following code. I am using parameterized sparql
> string and I want to display combined results of both queries how can I do
> that. Any help or suggestion would be truly appreciated.
>
>
>
> final static String filename = "/home/samita/turtleContent.ttl";
>
> static Model model= null;
>
>
> final static String turtleContent = "" +
> "@prefix : <http://example.org/> .\n" +
> "\n" +
> ":alice :hasName \"Alice\" .\n" +
> ":alice :hasAddress \"4222 Clinton Way\" .\n" +
> ":herman :hasName \"Herman\".\n" +
> ":herman :hasAddress \"1313 Mockingbird Lane\" .\n" +
> ":DrWho :hasAddress \"The TARDIS\"" +
> "";
>
>
> // Read the model from the turtle content
> final static Model model = ModelFactory.createDefaultModel()
> // .read( new ByteArrayInputStream( turtleContent.getBytes()),
> null, "TURTLE" );
>
>
> final static String findAlice = "prefix : <http://example.org/>" +
> "select ?alice where {" +
> "?alice :hasName \"Alice\" }" ;
>
> final static String findAliceAddress = "prefix : <http://example.org/>"
> +
> "select ?address where {" +
> " ?alice :hasAddress ?address }";
>
> public static void useParameterizedSPARQLString() {
> System.out.println( "== useParameterizedSPARQLString ==" );
> // execute the query that finds a (single) binding for ?alice.
> Then create
> // a query solution map containing those results.
> final ResultSet aliceResults = QueryExecutionFactory.create(
> findAlice, model ).execSelect();
> final QuerySolutionMap map = new QuerySolutionMap();
> map.addAll( aliceResults.next() );
> // Create a ParameterizedSparqlString from the findAliceAddress
> query string (if this
> // approach were taken, findAliceAddress could actually *be* a
> Param.SparqlString, of
> // course).
> final ParameterizedSparqlString pss = new
> ParameterizedSparqlString( findAliceAddress );
> System.out.println( pss.toString() );
> pss.setParams( map );
> System.out.println( pss.toString() );
> // execute the query and show the results
> ResultSetFormatter.out( QueryExecutionFactory.create(
> pss.toString(), model ).execSelect() );
> }
>
> The results I get is:
>
> ----------------------
> | address |
> ======================
> | "4222 Clinton Way" |
> ----------------------
>
> Is there any way to display the variable ?alice also
>
> Like
>
> alice address
>
> http://example.org/alice "4222 Clinton Way"<
> http://example.org/alice>
>
>
>
>
>
> P : Please consider the environment before printing this e-mail
>
> ________________________________
>
> CONFIDENTIALITY / DISCLAIMER NOTICE: This e-mail and any attachments may
> contain confidential and privileged information. If you are not the
> intended recipient, please notify the sender immediately by return e-mail,
> delete this e-mail and destroy any copies. Any dissemination or use of this
> information by a person other than the intended recipient is unauthorized
> and may be illegal.
>
> ________________________________
>