How to match a relative IRI of a Subject in an RDF triple in SPARQL query language?

934 Views Asked by At

I am trying to use SPARQL to match an IRI that is relative to the base. Here's an example snippet of rdf-xml code:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:bqbiol="http://biomodels.net/biology-qualifiers/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xml:base="base-uri.rdf">
  <rdf:Description rdf:about="metaid_1">
    <bqbiol:is rdf:resource="https://identifiers.org/uniprot/P0DP23"/>
  </rdf:Description>
</rdf:RDF>

I want to match this triple based on the subject rdf:about="metaid_1". If I run the following sparql query:

// query 1


SELECT ?x ?y ?z
WHERE {
  ?x ?y ?z
}

The result is:

@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rs:      <http://www.w3.org/2001/sw/DataAccess/tests/result-set#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

[]    rdf:type      rs:ResultSet ;
      rs:resultVariable  "x" ;
      rs:resultVariable  "y" ;
      rs:resultVariable  "z" ;
      rs:solution   [ rs:binding    [ rs:variable   "x" ;
                                      rs:value      <metaid_1>
                                    ] ; 
                      rs:binding    [ rs:variable   "y" ;
                                      rs:value      <http://biomodels.net/biology-qualifiers/is>
                                    ] ; 
                      rs:binding    [ rs:variable   "z" ;
                                      rs:value      <https://identifiers.org/uniprot/P0DP23>
                                    ] 
      ] .

But when I run any of the following, I get an empty result:

// query 2
SELECT ?y ?z
WHERE {
  <metaid_1> ?y ?z
}

// query 3
SELECT ?y ?z
WHERE {
  <base-uri.rdf#metaid_1> ?y ?z
}


// query 4
SELECT ?y ?z
WHERE {
  <base-uri.rdf/metaid_1> ?y ?z
}

Could anybody suggest an alternative query for matching triples based on the relative metaid_1 iri?

edit - response to comments

I forgot to mention that I did try using BASE like so:

// query 5
SELECT ?y ?z
WHERE {
  <BASE/metaid_1> ?y ?z
}

and a few variants, but not was suggested in the comment which was:


// query 6
BASE <base-uri.rdf>
SELECT ?y ?z
WHERE {
  <metaid_1> ?y ?z
}

Which also returns an empty set of results.

edit 2 - response to more comments

@uninformedUser is correct in that I was going for local iri's because these subjects are essentially metaid attributes on xml elements for local xml strings. I suppose when the package I'm writing is used online they would become https://, but for now they are just strings created for testing.

I have tried changing the xml:base to file:///mnt/d/libsemsim/tests/base-uri.rdf so now the xml snippet reads:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:bqbiol="http://biomodels.net/biology-qualifiers/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xml:base="file:///mnt/d/libsemsim/tests/base-uri.rdf">
  <rdf:Description rdf:about="metaid_1">
    <bqbiol:is rdf:resource="https://identifiers.org/uniprot/P0DP23"/>
  </rdf:Description>
</rdf:RDF>

And the query:

BASE <file:///mnt/d/libsemsim/tests/base-uri.rdf> 
SELECT ?y ?z
WHERE {
  <metaid_1> ?y ?z
}

But still my result set is empty. I'm wondering whether the problem is that I'm querying the rdf model itself, which is a central object in the librdf package and not necessarily a serialized representation of the xml as I've been showing here.

0

There are 0 best solutions below