You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by illusionz <de...@gmail.com> on 2013/04/14 08:01:36 UTC

Need help to get BGP from SPRQL string

Hi,

I am currently creating an app that will extract BGP and based on the BGP's
load the graphs from a custom data source.

Kindly help me with a code snipplet  that would return list of BGP's from a
SPARQL query so that I can traverse and load the graphs matching those
patterns.

Regards,
Depanker Sharna

Re: Need help to get BGP from SPRQL string

Posted by illusionz <de...@gmail.com>.
Diogo/Andy,

Thanks for point out the solution.

Query is something like below mentioned and  as suggested by Diogo I had
written a transformer implementation to retrieve BasicPattern.

Another useful link was
https://github.com/apache/jena/blob/trunk/jena-arq/src-examples/arq/examples/engine/MyQueryEngine.java:

(?pinUri rdf:type <http://example.com/ontology#post>) (?pinUri <
http://example.com/ontology#createdDate> ?createdDate) (?pinUri <
http://example.com/ontology#belongsTo> ?userUri) (?pinUri rdf:type
?pinType) (?pinUri <http://example.com/ontology#publicKey> ?pinKey)
(?pinUri <http://example.com/ontology#source> ?mediaUri) (?pinUri <
http://example.com/ontology#title> ?mediaTitle) (?pinUri <
http://example.com/ontology#tag> ?boardUri) (?boardUri <
http://example.com/ontology#label> ?boardLabel) (?userUri <
http://example.com/ontology#profileName> ?profileName) (?userUri <
http://example.com/ontology#publicKey> ?userKey)

(?boardUri <http://example.com/ontology#description> ?boardDescription)
(?userUri <http://example.com/ontology#profileImage> ?profileImage)
(?pinUri <http://example.com/ontology#description> ?mediaDescription)

String query = "select ?pinKey ?pinType ?mediaUri ?mediaTitle
?mediaDescription ?boardLabel ?boardDescription ?profileName
?profileImage  ?userKey" +

  "            where " +

  "            {" +

  "            " +

  "                ?pinUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://example.com/ontology#post> ." +

  "                ?pinUri <http://example.com/ontology#createdDate>
?createdDate ." +

  "                ?pinUri <http://example.com/ontology#belongsTo> ?userUri
." +

  "                ?pinUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
?pinType ." +

  "                ?pinUri <http://example.com/ontology#publicKey>  ?pinKey
." +

  "                ?pinUri <http://example.com/ontology#source>  ?mediaUri
." +

  "                ?pinUri <http://example.com/ontology#title>  ?mediaTitle
." +

  "                ?pinUri <http://example.com/ontology#tag>  ?boardUri ."+


  "                ?boardUri <http://example.com/ontology#label>
?boardLabel ." +

"                ?userUri <http://example.com/ontology#profileName>
?profileName ." +

  "                ?userUri <http://example.com/ontology#publicKey>
?userKey ." +


  "                OPTIONAL " +

  "                {" +

  "                  ?boardUri <http://example.com/ontology#description>
?boardDescription ." +

  "                  ?userUri <http://example.com/ontology#profileImage>
?profileImage ." +

  "                  ?pinUri <http://example.com/ontology#description>
?mediaDescription ." +

  "                }" +

  "                " +

  "                filter(str(?pinType) != \"
http://example.com/ontology#post\")" +

  "            }" +

  "            ORDER BY DESC(?createdDate)" +

  "                 LIMIT 10 " +

  "                 OFFSET 0";


Thanks

Depanker Sharma


On Sun, Apr 14, 2013 at 10:43 PM, Andy Seaborne <an...@apache.org> wrote:

> Depanker,
>
> if your query is a string or a Query object:
>
> Query query = QueryFactory.create(**querystring) ;
> Op op = Algebra.compile(query) ;
>
> and look in the Op object (see the link from Diogo.  If it's a simple
> query, like
>
> SELECT * {
>   ?s ?p ?o
> }
>
> the op will be a OpBGP and you can get the BGP. For more complicated
> queries, you'll need to walk the op in some way.
>
>         Andy
>
>
>
>
> On 14/04/13 13:38, Diogo FC Patrao wrote:
>
>> Hi Depanker
>>
>> Try the Transformer class; here is some examples:
>>
>> http://jena.apache.org/**documentation/query/**
>> manipulating_sparql_using_arq.**html<http://jena.apache.org/documentation/query/manipulating_sparql_using_arq.html>
>>
>>
>>
>> --
>> diogo patrão
>>
>>
>>
>>
>> On Sun, Apr 14, 2013 at 3:01 AM, illusionz <de...@gmail.com>
>> wrote:
>>
>>  Hi,
>>>
>>> I am currently creating an app that will extract BGP and based on the
>>> BGP's
>>> load the graphs from a custom data source.
>>>
>>> Kindly help me with a code snipplet  that would return list of BGP's
>>> from a
>>> SPARQL query so that I can traverse and load the graphs matching those
>>> patterns.
>>>
>>> Regards,
>>> Depanker Sharna
>>>
>>>
>>
>

Re: Need help to get BGP from SPRQL string

Posted by Andy Seaborne <an...@apache.org>.
Depanker,

if your query is a string or a Query object:

Query query = QueryFactory.create(querystring) ;
Op op = Algebra.compile(query) ;

and look in the Op object (see the link from Diogo.  If it's a simple 
query, like

SELECT * {
   ?s ?p ?o
}

the op will be a OpBGP and you can get the BGP. For more complicated 
queries, you'll need to walk the op in some way.

	Andy



On 14/04/13 13:38, Diogo FC Patrao wrote:
> Hi Depanker
>
> Try the Transformer class; here is some examples:
>
> http://jena.apache.org/documentation/query/manipulating_sparql_using_arq.html
>
>
>
> --
> diogo patrão
>
>
>
>
> On Sun, Apr 14, 2013 at 3:01 AM, illusionz <de...@gmail.com> wrote:
>
>> Hi,
>>
>> I am currently creating an app that will extract BGP and based on the BGP's
>> load the graphs from a custom data source.
>>
>> Kindly help me with a code snipplet  that would return list of BGP's from a
>> SPARQL query so that I can traverse and load the graphs matching those
>> patterns.
>>
>> Regards,
>> Depanker Sharna
>>
>


Re: Need help to get BGP from SPRQL string

Posted by Diogo FC Patrao <dj...@gmail.com>.
Hi Depanker

Try the Transformer class; here is some examples:

http://jena.apache.org/documentation/query/manipulating_sparql_using_arq.html



--
diogo patrão




On Sun, Apr 14, 2013 at 3:01 AM, illusionz <de...@gmail.com> wrote:

> Hi,
>
> I am currently creating an app that will extract BGP and based on the BGP's
> load the graphs from a custom data source.
>
> Kindly help me with a code snipplet  that would return list of BGP's from a
> SPARQL query so that I can traverse and load the graphs matching those
> patterns.
>
> Regards,
> Depanker Sharna
>