You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Laura Morales <la...@mail.com> on 2018/04/24 09:54:38 UTC

[sparql] Return only one property of many with the same name

If I have this node

    :Alice :name "Alice", "Alice Smith" ;
           :age 25 .

how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)

Re: [sparql] Return only one property of many with the same name

Posted by Laura Morales <la...@mail.com>.
oh very nice! SAMPLE is really interesting for my use case :)
Thank you for the hint.

 
 

Sent: Tuesday, April 24, 2018 at 2:26 PM
From: "Osma Suominen" <os...@helsinki.fi>
To: users@jena.apache.org
Subject: Re: [sparql] Return only one property of many with the same name
Hi Laura!

If LIMIT is not applicable (e.g. you want to query for many similar
resources in one query), you can also consider using SAMPLE (with a
GROUP BY).

If you want to make the choice deterministic, you can use LIMIT together
with ORDER BY.

-Osma

Laura Morales kirjoitti 24.04.2018 klo 15:23:
> Yeah I'd prefer one over the other, but I don't think there is any simple way to distinguish them, I think multiple values are just supposed to be unordered.
> I'll end up using LIMIT or DISTINCT. Thank you.
>
>
>
> Sent: Tuesday, April 24, 2018 at 2:12 PM
> From: ajs6f <aj...@apache.org>
> To: users@jena.apache.org
> Subject: Re: [sparql] Return only one property of many with the same name
> Do you care about which one?
>
> If not, just use the LIMIT keyword to get only one. Otherwise, it's going to depend on which one you want and how you want to distinguish them.
>
> ajs6f
>
>> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>>
>> If I have this node
>>
>> :Alice :name "Alice", "Alice Smith" ;
>> :age 25 .
>>
>> how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)
>
>

--
Osma Suominen
D.Sc. (Tech), Information Systems Specialist
National Library of Finland
P.O. Box 26 (Kaikukatu 4)
00014 HELSINGIN YLIOPISTO
Tel. +358 50 3199529
osma.suominen@helsinki.fi
http://www.nationallibrary.fi

Re: [sparql] Return only one property of many with the same name

Posted by Andy Seaborne <an...@apache.org>.
Non-deterministically, a subselect can be used rather than SAMPLE overall:

SELECT ?name ?age
{ { SELECT * { ?A :name ?name } LIMIT 1 }
   ?A :age ?age
}

If you add GROUPing and the suggestions here to the subselect, the 
overall results are deterministic, even though the order within the 
results isn't.

	Andy

On 25/04/18 07:08, Lorenz Buehmann wrote:
> Making it deterministic can be done via MIN/MAX instead of SAMPLE.
> 
> 
> On 24.04.2018 14:26, Osma Suominen wrote:
>> Hi Laura!
>>
>> If LIMIT is not applicable (e.g. you want to query for many similar
>> resources in one query), you can also consider using SAMPLE (with a
>> GROUP BY).
>>
>> If you want to make the choice deterministic, you can use LIMIT
>> together with ORDER BY.
>>
>> -Osma
>>
>> Laura Morales kirjoitti 24.04.2018 klo 15:23:
>>> Yeah I'd prefer one over the other, but I don't think there is any
>>> simple way to distinguish them, I think multiple values are just
>>> supposed to be unordered.
>>> I'll end up using LIMIT or DISTINCT. Thank you.
>>>     
>>> Sent: Tuesday, April 24, 2018 at 2:12 PM
>>> From: ajs6f <aj...@apache.org>
>>> To: users@jena.apache.org
>>> Subject: Re: [sparql] Return only one property of many with the same
>>> name
>>> Do you care about which one?
>>>
>>> If not, just use the LIMIT keyword to get only one. Otherwise, it's
>>> going to depend on which one you want and how you want to distinguish
>>> them.
>>>
>>> ajs6f
>>>
>>>> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>>>>
>>>> If I have this node
>>>>
>>>> :Alice :name "Alice", "Alice Smith" ;
>>>> :age 25 .
>>>>
>>>> how can I return *only one* of the ":name" properties with SPARQL?
>>>> For example return ("Alice", 25)
>>>   
>>
> 

Re: [sparql] Return only one property of many with the same name

Posted by Lorenz Buehmann <bu...@informatik.uni-leipzig.de>.
Making it deterministic can be done via MIN/MAX instead of SAMPLE.


On 24.04.2018 14:26, Osma Suominen wrote:
> Hi Laura!
>
> If LIMIT is not applicable (e.g. you want to query for many similar
> resources in one query), you can also consider using SAMPLE (with a
> GROUP BY).
>
> If you want to make the choice deterministic, you can use LIMIT
> together with ORDER BY.
>
> -Osma
>
> Laura Morales kirjoitti 24.04.2018 klo 15:23:
>> Yeah I'd prefer one over the other, but I don't think there is any
>> simple way to distinguish them, I think multiple values are just
>> supposed to be unordered.
>> I'll end up using LIMIT or DISTINCT. Thank you.
>>    
>> Sent: Tuesday, April 24, 2018 at 2:12 PM
>> From: ajs6f <aj...@apache.org>
>> To: users@jena.apache.org
>> Subject: Re: [sparql] Return only one property of many with the same
>> name
>> Do you care about which one?
>>
>> If not, just use the LIMIT keyword to get only one. Otherwise, it's
>> going to depend on which one you want and how you want to distinguish
>> them.
>>
>> ajs6f
>>
>>> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>>>
>>> If I have this node
>>>
>>> :Alice :name "Alice", "Alice Smith" ;
>>> :age 25 .
>>>
>>> how can I return *only one* of the ":name" properties with SPARQL?
>>> For example return ("Alice", 25)
>>  
>


Re: [sparql] Return only one property of many with the same name

Posted by Osma Suominen <os...@helsinki.fi>.
Hi Laura!

If LIMIT is not applicable (e.g. you want to query for many similar 
resources in one query), you can also consider using SAMPLE (with a 
GROUP BY).

If you want to make the choice deterministic, you can use LIMIT together 
with ORDER BY.

-Osma

Laura Morales kirjoitti 24.04.2018 klo 15:23:
> Yeah I'd prefer one over the other, but I don't think there is any simple way to distinguish them, I think multiple values are just supposed to be unordered.
> I'll end up using LIMIT or DISTINCT. Thank you.
>   
>   
> 
> Sent: Tuesday, April 24, 2018 at 2:12 PM
> From: ajs6f <aj...@apache.org>
> To: users@jena.apache.org
> Subject: Re: [sparql] Return only one property of many with the same name
> Do you care about which one?
> 
> If not, just use the LIMIT keyword to get only one. Otherwise, it's going to depend on which one you want and how you want to distinguish them.
> 
> ajs6f
> 
>> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>>
>> If I have this node
>>
>> :Alice :name "Alice", "Alice Smith" ;
>> :age 25 .
>>
>> how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)
>   
> 

-- 
Osma Suominen
D.Sc. (Tech), Information Systems Specialist
National Library of Finland
P.O. Box 26 (Kaikukatu 4)
00014 HELSINGIN YLIOPISTO
Tel. +358 50 3199529
osma.suominen@helsinki.fi
http://www.nationallibrary.fi

Re: [sparql] Return only one property of many with the same name

Posted by ajs6f <aj...@apache.org>.
It's worth remembering that RDF graphs have no inherent order, though we may give one when we write them down or iterate through them.

If your data has a defined order that you need to maintain, that needs to be represented explicitly in the RDF. There are lots of ways to do that, depending on the use case, but ordering is almost never something to be assumed when you are working with RDF.

ajs6f

> On Apr 24, 2018, at 8:23 AM, Laura Morales <la...@mail.com> wrote:
> 
> Yeah I'd prefer one over the other, but I don't think there is any simple way to distinguish them, I think multiple values are just supposed to be unordered.
> I'll end up using LIMIT or DISTINCT. Thank you.
>  
>  
> 
> Sent: Tuesday, April 24, 2018 at 2:12 PM
> From: ajs6f <aj...@apache.org>
> To: users@jena.apache.org
> Subject: Re: [sparql] Return only one property of many with the same name
> Do you care about which one?
> 
> If not, just use the LIMIT keyword to get only one. Otherwise, it's going to depend on which one you want and how you want to distinguish them.
> 
> ajs6f
> 
>> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>> 
>> If I have this node
>> 
>> :Alice :name "Alice", "Alice Smith" ;
>> :age 25 .
>> 
>> how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)
>  


Re: [sparql] Return only one property of many with the same name

Posted by Laura Morales <la...@mail.com>.
Yeah I'd prefer one over the other, but I don't think there is any simple way to distinguish them, I think multiple values are just supposed to be unordered.
I'll end up using LIMIT or DISTINCT. Thank you.
 
 

Sent: Tuesday, April 24, 2018 at 2:12 PM
From: ajs6f <aj...@apache.org>
To: users@jena.apache.org
Subject: Re: [sparql] Return only one property of many with the same name
Do you care about which one?

If not, just use the LIMIT keyword to get only one. Otherwise, it's going to depend on which one you want and how you want to distinguish them.

ajs6f

> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
>
> If I have this node
>
> :Alice :name "Alice", "Alice Smith" ;
> :age 25 .
>
> how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)
 

Re: [sparql] Return only one property of many with the same name

Posted by ajs6f <aj...@apache.org>.
Do you care about which one?

If not, just use the LIMIT keyword to get only one. Otherwise, it's going to depend on which one you want and how you want to distinguish them.

ajs6f

> On Apr 24, 2018, at 5:54 AM, Laura Morales <la...@mail.com> wrote:
> 
> If I have this node
> 
>    :Alice :name "Alice", "Alice Smith" ;
>           :age 25 .
> 
> how can I return *only one* of the ":name" properties with SPARQL? For example return ("Alice", 25)