Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [rdf4j-dev] rdf4j-dev Digest, Vol 23, Issue 3

Thanks for the replies everyone. I still don't understand how SPARQL would bind node2Label to some arbitrary resource, since it is inside the optional block. Also, having tried to run your code, I get an error saying the variable  node2Label is not bound. Any idea as to why that might be? I've attached the ontology in case anyone would like to query it themselves. 
As always, thanks a lot for your help. 

On Mon, Dec 11, 2017 at 7:58 AM, <rdf4j-dev-request@xxxxxxxxxxx> wrote:
Send rdf4j-dev mailing list submissions to
        rdf4j-dev@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
        https://dev.eclipse.org/mailman/listinfo/rdf4j-dev
or, via email, send a message with subject or body 'help' to
        rdf4j-dev-request@xxxxxxxxxxx

You can reach the person managing the list at
        rdf4j-dev-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of rdf4j-dev digest..."


Today's Topics:

   1. Re: sparql aggregate query not working (Jeen Broekstra)
   2. Re: sparql aggregate query not working (Damyan Ognyanov)


----------------------------------------------------------------------

Message: 1
Date: Mon, 11 Dec 2017 09:00:58 +1100
From: Jeen Broekstra <jeen.broekstra@xxxxxxxxx>
To: rdf4j-dev@xxxxxxxxxxx
Cc: RDF4J Users <rdf4j-users@xxxxxxxxxxxxxxxx>
Subject: Re: [rdf4j-dev] sparql aggregate query not working
Message-ID: <e2e951cf-b25e-d163-89b3-dfaa48240226@xxxxxxxxx>
Content-Type: text/plain; charset="utf-8"; Format="flowed"


Hi Boris,

On 9/12/17 02:04, Boris Metodiev wrote:
> Hello all, I was wondering if anyone could help me with this query:
>
> I'm trying to retrieve certain elements from an rdf ontology using
> rdflib, which uses SPARQL 1.1. The ontology is of the human body, and
> all the parts have their own class. Here is an example:
>
> <owl:Class rdf:about="http://human.owl#NCI_C12909">
> <http://human.owl/#NCI_C12909%22%3E><rdfs:label
> rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Hematopoietic_System
> <http://www.w3.org/2001/XMLSchema#string%22%3EHematopoietic_System></rdfs:label><rdfs:subClassOf
> rdf:resource="http://human.owl#NCI_C41166"/>
> <http://human.owl/#NCI_C41166%22/%3E>rdfs:subClassOfowl:Restriction<owl:onProperty
> rdf:resource="http://human.owl#UNDEFINED_part_of"/>
> <http://human.owl/#UNDEFINED_part_of%22/%3E><owl:someValuesFrom
> rdf:resource="http://human.owl#NCI_C41165"/>
> <http://human.owl/#NCI_C41165%22/%3E></owl:Restriction></rdfs:subClassOf><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7506"/>
> <http://human.owl/#genid7506%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7507"/>
> <http://human.owl/#genid7507%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7508"/>
> <http://human.owl/#genid7508%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7509"/>
> <http://human.owl/#genid7509%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7510"/>
> <http://human.owl/#genid7510%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7511"/>
> <http://human.owl/#genid7511%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7513"/>
> <http://human.owl/#genid7513%22/%3E></owl:Class>
>
> As you can see, some of the classes have properties with multiple
> values, such as hasRelatedSynonym, and SomeValuesFrom. I'm trying to
> run a query that returns the class, the class label, the super class,
> the superclass label, and any other hasRelatedSynonym values and
> SomeValuesFrom values. I would like to use group_concat for the
> properties with the multiple values, and have tried the following query:
>
> querytrial4=graph.query("""SELECT ?node ?nodeLabel ?superclass
> ?superclassLabel (group_concat(DISTINCT ?node2) as ?node2s)
> (group_concat(DISTINCT ?node2Label) as ?node2Labels) where {
> ?node rdf:type owl:Class .
> ?node rdfs:subClassOf ?superclass .
> OPTIONAL { ?node rdfs:subClassOf ?restriction }
> OPTIONAL { ?restriction a owl:Restriction }
> OPTIONAL { ?restriction owl:someValuesFrom ?node2 }
> ?node rdfs:label ?nodeLabel .
> ?superclass rdfs:label ?superclassLabel .
> OPTIONAL { ?node2 rdfs:label ?node2Label }
> }
> group by ?node ?nodeLabel ?superclass ?superclassLabel ?node2 ?node2Label
> LIMIT 10""")
>
> The query seems to execute, but when I try to iterate over its rows
> and print them, Jupyter Notebook goes on thinking forever and doesn't
> return anything. Could it be that I've made a mistake and have created
> some kind of recursive infinite loop? Any help would be much appreciated.
>
It's unlikely that you have created an infinite loop. There's at least
two possibilities I see: 1. your code somehow doesn't properly
open/close resources, resulting in a deadlock on the store, or 2. on
your dataset the evaluation of the group_concat takes a long time. How
large is your repository?

Other than that, it's hard to say anything more definite without seeing
your actual code and/or getting a sample of your dataset that we can use
to reproduce the problem.

Cheers,

Jeen

PS You're actually on the wrong mailinglist with this. rdf4j-users
<https://groups.google.com/d/forum/rdf4j-users> is the group for
community support of rdf4j, the rdf4j-dev mailinglist is intended for
the rdf4j development team's internal discussions.? If you follow up on
this, can we please move the discussion to rdf4j-users? Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://dev.eclipse.org/mailman/private/rdf4j-dev/attachments/20171211/e34cc69a/attachment.html>

------------------------------

Message: 2
Date: Mon, 11 Dec 2017 08:58:33 +0200
From: Damyan Ognyanov <damyan.ognyanov@xxxxxxxxxxxx>
To: rdf4j developer discussions <rdf4j-dev@xxxxxxxxxxx>,        Boris
        Metodiev <boris.mtdv@xxxxxxxxx>
Subject: Re: [rdf4j-dev] sparql aggregate query not working
Message-ID: <9f69520b-e6ef-c15f-7c92-945e12d4253d@xxxxxxxxxxxx>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Hi Boris,

the OPTIONAL expressions in you query are composed in a way that you may
end up with a Cartesian product of solutions for the variable ?node2

e.g. in case that the value bound to ?node is not related with a
rdfs:subClassOf to something that is of type Restriction or if it is,
then it may not have a ow:someValuesFrom relation.
What happens next is that, when such partial solution is found, the
third OPTIONAL would not bind anything to ?node2 and as a consequence,
the last OPTIONAL will start to provide bindings to ?node2 from all the
statements with the rdfs:label predicate ... which is probably not
exactly what you are aiming for...

Can suggest you to use nested optionals like below, if such pattern
matches your intentions:
{code}
SELECT ?node ?nodeLabel ?superclass ?superclassLabel
(group_concat(DISTINCT ?node2) as ?node2s) (group_concat(DISTINCT
?node2Label) as ?node2Labels) where {
 ??? ?node rdf:type owl:Class .
 ??? ?node rdfs:subClassOf ?superclass .
 ??? OPTIONAL {
 ??? ??? ?node rdfs:subClassOf ?restriction .
 ??? ??? ?restriction a owl:Restriction .
 ??? ??? ?restriction owl:someValuesFrom ?node2 .
 ??? ??? OPTIONAL { ?node2 rdfs:label ?node2Label }
 ??? }
 ??? ?node rdfs:label ?nodeLabel .
 ??? ?superclass rdfs:label ?superclassLabel .
}
group by ?node ?nodeLabel ?superclass ?superclassLabel ?node2 ?node2Label
LIMIT 10
{code}

HTH
Damyan

On 08/12/2017 17:04, Boris Metodiev wrote:
> Hello all, I was wondering if anyone could help me with this query:
>
> I'm trying to retrieve certain elements from an rdf ontology using
> rdflib, which uses SPARQL 1.1. The ontology is of the human body, and
> all the parts have their own class. Here is an example:
>
> <owl:Class rdf:about="http://human.owl#NCI_C12909">
> <http://human.owl/#NCI_C12909%22%3E><rdfs:label
> rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Hematopoietic_System
> <http://www.w3.org/2001/XMLSchema#string%22%3EHematopoietic_System></rdfs:label><rdfs:subClassOf
> rdf:resource="http://human.owl#NCI_C41166"/>
> <http://human.owl/#NCI_C41166%22/%3E>rdfs:subClassOfowl:Restriction<owl:onProperty
> rdf:resource="http://human.owl#UNDEFINED_part_of"/>
> <http://human.owl/#UNDEFINED_part_of%22/%3E><owl:someValuesFrom
> rdf:resource="http://human.owl#NCI_C41165"/>
> <http://human.owl/#NCI_C41165%22/%3E></owl:Restriction></rdfs:subClassOf><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7506"/>
> <http://human.owl/#genid7506%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7507"/>
> <http://human.owl/#genid7507%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7508"/>
> <http://human.owl/#genid7508%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7509"/>
> <http://human.owl/#genid7509%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7510"/>
> <http://human.owl/#genid7510%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7511"/>
> <http://human.owl/#genid7511%22/%3E><oboInOwl:hasRelatedSynonym
> rdf:resource="http://human.owl#genid7513"/>
> <http://human.owl/#genid7513%22/%3E></owl:Class>
>
> As you can see, some of the classes have properties with multiple
> values, such as hasRelatedSynonym, and SomeValuesFrom. I'm trying to
> run a query that returns the class, the class label, the super class,
> the superclass label, and any other hasRelatedSynonym values and
> SomeValuesFrom values. I would like to use group_concat for the
> properties with the multiple values, and have tried the following query:
>
> querytrial4=graph.query("""SELECT ?node ?nodeLabel ?superclass
> ?superclassLabel (group_concat(DISTINCT ?node2) as ?node2s)
> (group_concat(DISTINCT ?node2Label) as ?node2Labels) where {
> ?node rdf:type owl:Class .
> ?node rdfs:subClassOf ?superclass .
> OPTIONAL { ?node rdfs:subClassOf ?restriction }
> OPTIONAL { ?restriction a owl:Restriction }
> OPTIONAL { ?restriction owl:someValuesFrom ?node2 }
> ?node rdfs:label ?nodeLabel .
> ?superclass rdfs:label ?superclassLabel .
> OPTIONAL { ?node2 rdfs:label ?node2Label }
> }
> group by ?node ?nodeLabel ?superclass ?superclassLabel ?node2 ?node2Label
> LIMIT 10""")
>
> The query seems to execute, but when I try to iterate over its rows
> and print them, Jupyter Notebook goes on thinking forever and doesn't
> return anything. Could it be that I've made a mistake and have created
> some kind of recursive infinite loop? Any help would be much appreciated.
>
>
>
> _______________________________________________
> rdf4j-dev mailing list
> rdf4j-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/rdf4j-dev


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://dev.eclipse.org/mailman/private/rdf4j-dev/attachments/20171211/80e30c96/attachment.html>

------------------------------

_______________________________________________
rdf4j-dev mailing list
rdf4j-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/rdf4j-dev


End of rdf4j-dev Digest, Vol 23, Issue 3
****************************************

Attachment: human.owl
Description: application/rdf


Back to the top