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 2017/04/14 14:17:58 UTC

SELECTing s properties in the same query
If I have these nquands (in Turtle syntax)


    <subject-1>
        ns:name "My name" ;
        ns:address [
            ns:street "Street name" ;
            ns:number "42" .
        ] .
    
    <subject-2>
        ns:name "Another name" ;
        ns:address [
            ns:street "Another street" ;
            ns:number "24" .
        ] .

    etc....


here, ns:address links to blank nodes. What I'd like to do is "SELECT everything about <subject-1>", but if I do a SELECT on <subject-1> what I get in return is something like

{
  {
    "s": <subject-1>
    "p": ns:name
    "o": "My name"
  }
  {
    "s": <subject-1>
    "p": ns:address
    "o": "name-of-the-blank-node"
  }
}

so I have to perform another query to retrieve the properties of "name-of-the-blank-node". How can I retrieve all information in one single query instead (= subject's name + full address instead of a blank node id)?

Re: SELECTing s properties in the same query Posted by Rurik Thomas Greenall <ru...@gmail.com>.
In a trivial way, perhaps you can specify something like:

SELECT * WHERE {
  <subject-1> ?property ?object
  OPTIONAL {
    ?object ?subProperty ?subObject .
    FILTER (isBlank(?object))
  }
}

This assumes nothing about structure and may perform badly.


On Fri, Apr 14, 2017 at 4:17 PM, Laura Morales <la...@mail.com> wrote:

> If I have these nquands (in Turtle syntax)
>
>
>     <subject-1>
>         ns:name "My name" ;
>         ns:address [
>             ns:street "Street name" ;
>             ns:number "42" .
>         ] .
>
>     <subject-2>
>         ns:name "Another name" ;
>         ns:address [
>             ns:street "Another street" ;
>             ns:number "24" .
>         ] .
>
>     etc....
>
>
> here, ns:address links to blank nodes. What I'd like to do is "SELECT
> everything about <subject-1>", but if I do a SELECT on <subject-1> what I
> get in return is something like
>
> {
>   {
>     "s": <subject-1>
>     "p": ns:name
>     "o": "My name"
>   }
>   {
>     "s": <subject-1>
>     "p": ns:address
>     "o": "name-of-the-blank-node"
>   }
> }
>
> so I have to perform another query to retrieve the properties of
> "name-of-the-blank-node". How can I retrieve all information in one single
> query instead (= subject's name + full address instead of a blank node id)?
>

Re: SELECTing s properties in the same query Posted by "A. Soroka" <aj...@virginia.edu>.
Jena's DESCRIBE behavior is pluggable. [1] If you can live with one "hop" on bnode traversal, you can use a plain query with isBlank. I'm sure this could be written better, but something like:

CONSTRUCT { ?sub ?pred ?obj } 

WHERE { 

  {  VALUES ?sub { <myuri> }
     ?sub ?pred ?obj . }
UNION
   { <myuri> ?somepred ?sub . 
    ?sub ?pred ?obj.  
    FILTER isBlank(?sub) }
 }

The legs account one for properties directly on the resource and the other for properties on bnodes connected to the resource. If you may have bnodes connecting to bnodes, you can also iterate a query like that to get the closure. For most people, one "hop" is likely enough.

---
A. Soroka
The University of Virginia Library

[1] https://jena.apache.org/documentation/query/extension.html#describe-handlers

> On Apr 15, 2017, at 5:58 AM, james anderson <ja...@dydra.com> wrote:
> 
> good afternoon;
> 
>> On 2017-04-15, at 11:43, Laura Morales <la...@mail.com> wrote:
>> 
>>> Blank node closure is non-trivial
>> 
>> wouldn't be this the same problem with URLs as well?
> 
> yes, in general.
> 
>> For example if a node is pointing to another resource's URL and I want to retrieve some properties of that linked resource from the same query?
> 
> although one often sees sparql’s ‘describe’ treated with antiseptic isolation gloves, there is a thorough description of how one might implement it[1], which is followed in various respects in several sparql implementations.
> by this approach, the distinction between iri and blank nodes bounds the description.
> 
> best regards, from berlin,
> - - -
> [1] : https://www.w3.org/Submission/CBD/
> - - -
> 
> 


Re: SELECTing s properties in the same query Posted by james anderson <ja...@dydra.com>.
good afternoon;

> On 2017-04-15, at 11:43, Laura Morales <la...@mail.com> wrote:
> 
>> Blank node closure is non-trivial
> 
> wouldn't be this the same problem with URLs as well?

yes, in general.

> For example if a node is pointing to another resource's URL and I want to retrieve some properties of that linked resource from the same query?

although one often sees sparql’s ‘describe’ treated with antiseptic isolation gloves, there is a thorough description of how one might implement it[1], which is followed in various respects in several sparql implementations.
by this approach, the distinction between iri and blank nodes bounds the description.

best regards, from berlin,
- - -
[1] : https://www.w3.org/Submission/CBD/
- - -



Re: SELECTing s properties in the same query Posted by Laura Morales <la...@mail.com>.
> Blank node closure is non-trivial

wouldn't be this the same problem with URLs as well? For example if a node is pointing to another resource's URL and I want to retrieve some properties of that linked resource from the same query?

Re: SELECTing s properties in the same query Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
Blank node closure is non-trivial and not part of the SPARQL specs. That
means, you either

a) have to do some pre-processing of the data
b) use some extensions, e.g. in Jena you can use a DESCRIBE query which
supports blank nodes closure, see [1] (Note, that DESCRIBE returns an
RDF graph instead of a resultset)

[1] https://jena.apache.org/documentation/query/extension.html

> If I have these nquands (in Turtle syntax)
>
>
>     <subject-1>
>         ns:name "My name" ;
>         ns:address [
>             ns:street "Street name" ;
>             ns:number "42" .
>         ] .
>     
>     <subject-2>
>         ns:name "Another name" ;
>         ns:address [
>             ns:street "Another street" ;
>             ns:number "24" .
>         ] .
>
>     etc....
>
>
> here, ns:address links to blank nodes. What I'd like to do is "SELECT everything about <subject-1>", but if I do a SELECT on <subject-1> what I get in return is something like
>
> {
>   {
>     "s": <subject-1>
>     "p": ns:name
>     "o": "My name"
>   }
>   {
>     "s": <subject-1>
>     "p": ns:address
>     "o": "name-of-the-blank-node"
>   }
> }
>
> so I have to perform another query to retrieve the properties of "name-of-the-blank-node". How can I retrieve all information in one single query instead (= subject's name + full address instead of a blank node id)?
>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center