Re: [Virtuoso-users] Question for querying with a variable as a predicate?

2018-05-31 Thread Jason Koh
Hi Kingsely,

Thanks for the kind reply. It works for me. I guess I was confused that
subProperty should be transitive instead of making the target property a
subproperty of a transitive property.

Thanks.


With regards,
Jason Koh
cseweb.ucsd.edu/~jbkoh

On Thu, May 31, 2018 at 7:05 AM, Kingsley Idehen 
wrote:

> On 5/23/18 8:32 PM, Jason Koh wrote:
>
> Hi,
>
> First I would like to appreciate this community where I am receiving a lot
> of help.
>
> I have a query would like to get answers but a variable predicate.
>
> The dataset is:
> ```
> # Insert Triples
> sparql
>
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> insert data {
> graph  {
> :PropB a owl:TransitiveProperty.
> :PropB1 rdfs:subPropertyOf :PropB.
> :PropB2 rdfs:subPropertyOf :propB1.
>
> :b a :EntityB.
> :b1 a :EntityB.
> :b2 a :EntityB.
> :aaa a :EntityB;
>  :propB :b;
>  :propB1 :b1;
>  :propB2 :b2.
> }
> };
> ```
> Basically there is "aaa" who is related to "b", "b1", "b2" with "PropB",
> "PropB1", "PropB2". And they have a hierarchy as PropB2 is a sub property
> of PropB1 that is a sub property of PropB.
>
> However, below query does not return anything:
> ```
> sparql
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> select ?s ?p ?o from  where {
> ?p rdfs:subPropertyOf* :PropB.
> ?s ?p ?o.
> };
> ```
>
> So I added reasoning rules based on Kingsley's previous comment.
>
> Here's the rule graph:
> ```
> sparql
> prefix owl: 
> prefix rdfs: 
> prefix : 
>
> insert data {
> graph  {
> :PropB a owl:TransitiveProperty.
> :PropB1 rdfs:subPropertyOf :PropB.
> :PropB2 rdfs:subPropertyOf :propB1.
> }
> };
> ```
>
> Then I inserted the rule with a command:
> ``rdfs_rule_set ('urn:proptest:rules', 'urn:proptest:rules') ;``
>
> Then I enabled the rule in the query:
> ```
> sparql
> DEFINE input:inference 'urn:proptest:rules'
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> select ?s ?p ?o from  where {
> ?p rdfs:subPropertyOf* :PropB.
> ?s ?p ?o.
> };
> ```
> But still it does not return anything.
>
> I am not sure if the query is valid in SPARQL or there is something I miss
> in Virtuoso.
>
> If there is anything that I can learn about, please let me know.
>
> Thank you!
>
>
> With regards,
> Jason Koh
> cseweb.ucsd.edu/~jbkoh 
>
>
> Jason,
>
> Here is a complete script. Please study it.
>
> ```
>
> -- Clear Graphs
>
> SPARQL CLEAR GRAPH  ;
> SPARQL CLEAR GRAPH   ;
>
>
>
> -- Load TBox Data
>
> SPARQL
> PREFIX owl: 
> 
> PREFIX rdfs: 
> 
> PREFIX : <#>
>
> INSERT DATA {
> GRAPH 
> {
> rdfs:subPropertyOf a owl:TransitiveProperty .
> rdfs:subClassOf a owl:TransitiveProperty .
> :rel1 a rdf:Property .
> :rel2 rdfs:subPropertyOf :rel1 .
> :rel3 rdfs:subPropertyOf :rel2 .
>
> }
> };
>
> -- Load Abox Data
>
> SPARQL
> PREFIX owl: 
> 
> PREFIX rdfs: 
> 
> PREFIX : <#>
>
> INSERT DATA {
> GRAPH 
> {
> :this :rel3 :that .
> :this :rel3 :that .
> :that :rel2 :other .
> :other :rel1 :final .
> }
> };
>
> SPARQL
>
> SELECT *
> FROM 
> WHERE {?s ?p ?o} ;
>
> RDFS_RULE_SET ('urn:rdfs:inference:rules', 'urn:rdfs:inference:rules:def')
> ;
>
> SELECT *
> FROM DB.DBA.SYS_RDF_SCHEMA
> WHERE RS_NAME = 'urn:rdfs:inference:rules' ;
>
> -- Test Query 1 using Property Path "+" operator
>
> SPARQL
>
> DEFINE input:inference 'urn:rdfs:inference:rules'
> PREFIX owl: 
> 
> PREFIX rdf: 
> 
> PREFIX rdfs: 
> 
> PREFIX : <#>
>
> SELECT DISTINCT :this ?p ?o
> FROM 
> WHERE {
> :this :rel1+ ?o ;
>?p ?o2.
>
> } ;
>
>
> -- Test Query 2 using Property Path "*" operator
>
> SPARQL
>
> DEFINE input:inference 'urn:rdfs:inference:rules'
> PREFIX owl: 
> 

Re: [Virtuoso-users] Question for querying with a variable as a predicate?

2018-05-31 Thread Kingsley Idehen
On 5/23/18 8:32 PM, Jason Koh wrote:
> Hi,
>
> First I would like to appreciate this community where I am receiving a
> lot of help. 
>
> I have a query would like to get answers but a variable predicate.
>
> The dataset is:
> ```
> # Insert Triples
> sparql
>
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> insert data {
> graph  {
> :PropB a owl:TransitiveProperty.
> :PropB1 rdfs:subPropertyOf :PropB.
> :PropB2 rdfs:subPropertyOf :propB1.
>
> :b a :EntityB.
> :b1 a :EntityB.
> :b2 a :EntityB.
> :aaa a :EntityB;
>      :propB :b;
>      :propB1 :b1;
>      :propB2 :b2.
> }
> };
> ```
> Basically there is "aaa" who is related to "b", "b1", "b2" with
> "PropB", "PropB1", "PropB2". And they have a hierarchy as PropB2 is a
> sub property of PropB1 that is a sub property of PropB.
>
> However, below query does not return anything:
> ```
> sparql
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> select ?s ?p ?o from  where {
> ?p rdfs:subPropertyOf* :PropB.
> ?s ?p ?o.
> };
> ```
>
> So I added reasoning rules based on Kingsley's previous comment.
>
> Here's the rule graph:
> ```
> sparql
> prefix owl: 
> prefix rdfs: 
> prefix : 
>
> insert data {
> graph  {
> :PropB a owl:TransitiveProperty.
> :PropB1 rdfs:subPropertyOf :PropB.
> :PropB2 rdfs:subPropertyOf :propB1.
> }
> };
> ```
>
> Then I inserted the rule with a command:
> ``rdfs_rule_set ('urn:proptest:rules', 'urn:proptest:rules') ;``
>
> Then I enabled the rule in the query:
> ```
> sparql
> DEFINE input:inference 'urn:proptest:rules'
> prefix owl: 
> prefix rdf: 
> prefix rdfs: 
> prefix : 
>
> select ?s ?p ?o from  where {
> ?p rdfs:subPropertyOf* :PropB.
> ?s ?p ?o.
> };
> ```
> But still it does not return anything.
>
> I am not sure if the query is valid in SPARQL or there is something I
> miss in Virtuoso. 
>
> If there is anything that I can learn about, please let me know.
>
> Thank you!
>
>
> With regards,
> Jason Koh
> cseweb.ucsd.edu/~jbkoh 


Jason,

Here is a complete script. Please study it.

```

-- Clear Graphs

SPARQL CLEAR GRAPH  ;
SPARQL CLEAR GRAPH   ;



-- Load TBox Data

SPARQL
PREFIX owl: 
PREFIX rdfs: 
PREFIX : <#>

INSERT DATA {
                GRAPH 
                {
                    rdfs:subPropertyOf a owl:TransitiveProperty .
                    rdfs:subClassOf a owl:TransitiveProperty .
                    :rel1 a rdf:Property .
                    :rel2 rdfs:subPropertyOf :rel1 .
                    :rel3 rdfs:subPropertyOf :rel2 .
                   
                }
};

-- Load Abox Data

SPARQL
PREFIX owl: 
PREFIX rdfs: 
PREFIX : <#>

INSERT DATA {
                GRAPH 
                {
                    :this :rel3 :that .
    :this :rel3 :that .
    :that :rel2 :other .
    :other :rel1 :final .
                }
};

SPARQL

SELECT *
FROM  
WHERE {?s ?p ?o} ;

RDFS_RULE_SET ('urn:rdfs:inference:rules', 'urn:rdfs:inference:rules:def') ;

SELECT *
FROM DB.DBA.SYS_RDF_SCHEMA
WHERE RS_NAME = 'urn:rdfs:inference:rules' ;

-- Test Query 1 using Property Path "+" operator

SPARQL

DEFINE input:inference 'urn:rdfs:inference:rules'
PREFIX owl: 
PREFIX rdf: 
PREFIX rdfs: 
PREFIX : <#>

SELECT DISTINCT :this ?p ?o
FROM 
WHERE {
        :this :rel1+ ?o ;
   ?p ?o2.

} ;


-- Test Query 2 using Property Path "*" operator

SPARQL

DEFINE input:inference 'urn:rdfs:inference:rules'
PREFIX owl: 
PREFIX rdf: 
PREFIX rdfs: 
PREFIX : <#>

SELECT DISTINCT :this ?o ?p ?o2
FROM 
WHERE {
    :this :rel1* ?o .
    ?o ?p ?o2 .
} ;


```


-- 
Regards,

Kingsley Idehen   
Founder & CEO 
OpenLink Software   (Home Page: http://www.openlinksw.com)

Weblogs (Blogs):
Legacy Blog: http://www.openlinksw.com/blog/~kidehen/
Blogspot Blog: http://kidehen.blogspot.com
Medium Blog: https://medium.com/@kidehen

Profile Pages:
Pinterest: https://www.pinterest.com/kidehen/
Quora: https://www.quora.com/profile/Kingsley-Uyi-Idehen
Twitter: https://twitter.com/kidehen
Google+: https://plus.google.com/+KingsleyIdehen/about
LinkedIn: http://www.linked