If anyone is trying to do something like I was above, get all the triples
within a certain distance of an initial subject, then this is the sparql
that I ended up with:
==================================
prefix : <http://example.org/ontology/test/>
with <http://example.org/dataset/test/>
SELECT distinct ?s ?p ?o bif:either(isIri(?o),'URI',datatype(?o)) as ?type
WHERE
{
             ?anchor ?pp ?s
                          OPTION ( TRANSITIVE,
                                       t_min (0),
                                       t_max (2), #
                                       t_in (?anchor),
                                       t_out (?s),
                                       t_no_cycles,
                                       t_distinct ) .
                          FILTER ( ?anchor = <
http://example.org/data/test/DummyClass_1>)
             ?s ?p ?o .
  }
ORDER BY ?s
==================================

Transitivity in Virtuoso seems very elegant, this replaced pages of code
that was generating complicated nested queries and seems to work very well.


On 3 December 2013 18:48, Quentin <quent...@clearbluewater.com.au> wrote:

> Prematurely sent.
>
> The query that gets me 'almost' there is:
>
> =========================
> prefix : <http://example.org/ontology/test/>
> with <http://example.org/dataset/test/>
> SELECT
> *
> WHERE
>   {
>     {
>       SELECT ?anchor ?s ?p ?o
>       WHERE
>         {
>           ?anchor ?anchorPred ?s .
>
>           ?s ?p ?o .
>         }
>     }
>     OPTION ( TRANSITIVE,
>              t_distinct,
>              t_in(?anchor),
>              t_out(?s),
>              t_min (0),
>              t_max (3) ,
> t_no_cycles,
>    t_step (?anchor) as ?link, t_step ('path_id') as ?path,
>
>              t_step ('step_no') as ?dist ) .
>     FILTER ( ?anchor = <http://example.org/data/test/DummyClass_1>)
>   }
> ORDER BY ?dist
> =========================
>
>
> On 3 December 2013 18:47, Quentin <quent...@clearbluewater.com.au> wrote:
>
>>
>> Assuming some data as below:
>> ========================================
>> prefix : <http://example.org/ontology/test/>
>> with <http://example.org/dataset/test/>
>> insert
>> {
>> <http://example.org/data/test/DummyClass_1> a :DummyClass .
>> <http://example.org/data/test/DummyClass_1> :predA "Entity 1" .
>> <http://example.org/data/test/DummyClass_1> :objPred  <
>> http://example.org/data/test/DummyClass_2> .
>> <http://example.org/data/test/DummyClass_2> a :DummyClass .
>> <http://example.org/data/test/DummyClass_2> :predA "Entity 2" .
>> <http://example.org/data/test/DummyClass_2> :objPred  <
>> http://example.org/data/test/DummyClass_3> .
>> <http://example.org/data/test/DummyClass_3> a :DummyClass .
>> <http://example.org/data/test/DummyClass_3> :predA "Entity 3" .
>> <http://example.org/data/test/DummyClass_3> :objPred  <
>> http://example.org/data/test/DummyClass_4> .
>> <http://example.org/data/test/DummyClass_4> a :DummyClass .
>> <http://example.org/data/test/DummyClass_4> :predA "Entity 4" .
>> <http://example.org/data/test/DummyClass_4> :objPred  <
>> http://example.org/data/test/DummyClass_1> .
>> }
>> ========================================
>> I want to get some results back that include every triple from some
>> anchor point to a given depth.  So, say I start with <
>> http://example.org/data/test/DummyClass_1> and use depth 2, I'd like to
>> get everything for DummyClass_1/DummyClass_2/DummyClass_3 but not
>> DummyClass_4.
>>
>> I figure this might be possible with transitivity and the OPTION clause
>> but I can't seem to get more than about 90% to what I need.
>>
>>
>>
>>
>>
>>
>> Secondly, I got a DB crash doing this query with the below data:
>> ===================================================
>> prefix : <http://example.org/ontology/test/>
>> with <http://example.org/dataset/test/>
>> SELECT
>> *
>> WHERE
>>   {
>>     {
>>       SELECT ?anchor ?s ?p ?o
>>       WHERE
>>         {
>>           ?anchor ?pred ?s .
>>           ?s ?p ?o .
>>         }
>>     }
>>     OPTION ( TRANSITIVE,
>>              t_distinct,
>>              t_in(?anchor),
>>              t_out(?s),
>>              t_min (0),
>>              t_max (3) ,
>> t_no_cycles,
>>   t_step (?s) as ?link, t_step ('path_id') as ?path,
>>              t_step ('step_no') as ?dist ) .
>>     FILTER ( ?anchor = <http://example.org/data/test/DummyClass_1>)
>>   }
>> ORDER BY ?dist
>> ===================================================
>>  I'm pretty sure this is because I used ?s in the t_step parameter
>> instead of ?anchor but I'm not quite sure why this caused a crash.
>> This seems to occur on DBPedia also (sorry).
>>
>> --
>> Quentin | Clear Blue Water Pty Ltd
>> quent...@clearbluewater.com.au
>>
>
>
>
> --
> Quentin | Clear Blue Water Pty Ltd
> quent...@clearbluewater.com.au
>



-- 
Quentin | Clear Blue Water Pty Ltd
quent...@clearbluewater.com.au
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Virtuoso-users mailing list
Virtuoso-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/virtuoso-users

Reply via email to