Hi,

the common pattern in SPARQL is to get the aggregated value in an inner query first, then in the outer query get the entity with the aggregated value:

SELECT ?house ?person ?lowestAge {
  ?person foaf:age ?lowestAge .
  ?person covidepid:livesIn ?house .


{SELECT ?house (min(?age) as ?lowestAge)
WHERE {
  ?person foaf:age ?age .
  ?person covidepid:livesIn ?house .
}
GROUP BY ?house}
}



On 03.12.21 02:16, Jakub Jałowiec wrote:
Hi,
I would appreciate any help with the following problem. I have a bunch of
(foaf:Persons, myOntology:livesIn, myOntology:Place) triples. I am trying
to find the youngest person in each myOntology:Place (i.e. the person with
the earliest value of foaf:age for each myOntology:Place).
What I've tried so far were:
- OWL complex classes (Class Expression Syntax (protegeproject.github.io)
<http://protegeproject.github.io/protege/class-expression-syntax/>) - per
my understanding they have too weak expressivity to express aggregates
among other individuals associated with them
- SPARQL query - something along those lines would work fine but I do not
know how to retrieve the IRI of the youngest person:

SELECT ?house (min(?age) as ?lowestAge)
WHERE {
   ?person foaf:age ?age .
   ?person covidepid:livesIn ?house .
}
GROUP BY ?house

I am curious if extraction of the lowest foaf:age value among a group of
people could be achieved using Apache Jena rules. From the documentation (
https://jena.apache.org/documentation/inference/#rules) it seems to me that
the closest it gets to it is to write my custom built-in function that
would do exactly that. Is that correct?

Best regards,
Jakub

Reply via email to