1

I would need to get all data related to a subject. I tried to query for

SELECT * WHERE {?s ?p ?o}

But the problem is that some of the ?o objects are URIs and I also need those connections, until the connections end. For example, I have:

http://www.example.com/data/subject-test http://www.example.com#hasNetListPrice http://www.example.com/data/price-subject-test.


http://www.example.com/data/price-subject-test http://www.example.com/si-cpq/data/price-currency http://www.example.com/data/EURO.

And so on, until the triples are no longer connected to the initial subject, http://www.example.com/si-cpq/data/subject-test.

Also, there are sometimes 4 triples connected, sometimes more, so I could not use the same pattern for all. Also, would need a general select query, not one that works only for the price triples, because the data has more attributes.

Ian Kurtis
  • 137
  • 7
  • `select ?s ?p ?o { (

    |!

    )* ?s . ?s ?p ?o }`

    – UninformedUser Feb 24 '22 at 20:05
  • I tried this approach but it triggers : ``` Cannot resolve relative IRI p because no base IRI was set. ``` – Ian Kurtis Feb 25 '22 at 09:18
  • then just use any property URI either an existing or a non existing like `` - the pattern is nothing more than a wildcard for any property as it follows the path by either `p` or `not p` one of this is always true. Try `select ?s ?p ?o { (|!)* ?s . ?s ?p ?o }` – UninformedUser Feb 25 '22 at 12:00
  • Note, if you use Blazegraph, this triple store does also provide non-standard extension for graph traversal which will be way more efficient. – UninformedUser Feb 25 '22 at 12:01

1 Answers1

1

(This is probably only a partial answer yet, but might be improved by more information from comments/edits):

First of all it might be necessary to specify which rdf:types you accept in the result. Also, you probably will have to add "layers of optional intermediate variables":


# untested due to the lack of data

prefix cpq: <http://www.example.com/si-cpq/data/>
SELECT * WHERE
{
    # defining admissible types (here: guessed type-names)
    VALUES ?t {cpq:Currency cpq:Foobar} 

    ?s ?p ?o1. # first relation
    {
      # direct connection between ?s and target type
      ?o1 rdf:type ?t.
     
    }
    UNION
    {
      # level 1 indirect connection between ?s and target type
      ?o1 ?p2 ?o2.
      ?o2 rdf:type ?t.
    }
    UNION
    {
      # level 2 indirect connection between ?s and target type
      ?o1 ?p2 ?o2.
      ?o2 ?p3 ?o3.
      ?o3 rdf:type ?t.
    }
# add more levels and restrictions as needed

}

You might also have a look on property paths, but they are only applicable for fixed (i.e. not variable) properties.

cknoll
  • 2,130
  • 4
  • 18
  • 34