Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [rdf4j-dev] sparql aggregate query not working


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"><rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Hematopoietic_System</rdfs:label><rdfs:subClassOf rdf:resource="http://human.owl#NCI_C41166"/>rdfs:subClassOfowl:Restriction<owl:onProperty rdf:resource="http://human.owl#UNDEFINED_part_of"/><owl:someValuesFrom rdf:resource="http://human.owl#NCI_C41165"/></owl:Restriction></rdfs:subClassOf><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7506"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7507"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7508"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7509"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7510"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7511"/><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid7513"/></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 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.

Back to the top