Giter Club home page Giter Club logo

Comments (3)

gkellogg avatar gkellogg commented on June 2, 2024

I think this is a case where the documentation is out of sync with the intended implementation. The fact that a variable does not match against the default graph stems from SPARQL semantics, where querying using an unbound graph name variable will not match the default graph. See 13.3.1 Accessing Graph Names:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?src ?bobNick
FROM NAMED <http://example.org/foaf/aliceFoaf>
FROM NAMED <http://example.org/foaf/bobFoaf>
WHERE
  {
    GRAPH ?src
    { ?x foaf:mbox <mailto:[email protected]> .
      ?x foaf:nick ?bobNick
    }
  }

Within RDF.rb, this happens because RDF::Query::Variable#eql?(false) always returns false, which it needs to do to be able to effectively do SPARQL queries. You can see how this is explicitly defined for RDF::Repository#query_pattern:

rdf/lib/rdf/repository.rb

Lines 405 to 412 in a889ba9

# Match elements with `eql?`, not `==`
#
# `graph_name` of `false` matches default graph. Unbound variable matches
# non-false graph name
#
# @private
# @see RDF::Queryable#query_pattern
def query_pattern(pattern, **options, &block)

Of course, a different Repository implementation could do this differently, but I believe it would fail various SPARQL tests.

I believe the corrective action here is to update the method signatures in RDF::Query to match this behavior. I'm afraid I don't have an easy solution to query against both the default and named graphs and get back the bound graph name. If you query a repository without using a variable for the graph_name position, you will get back all solutions, but you will not know what graph the solution came from.

from rdf.

Richard-Degenne avatar Richard-Degenne commented on June 2, 2024

Ok, that makes sense. Thank you for the write-up!

I guess I'm also confused by the fact that I use the SPARQL gem to build queries, and the way it handles the default graph differs from the way our usual triple store handles it.

I'll leave the issue open for that adjustment in the documentation, but other than that, it's good for me.

from rdf.

gkellogg avatar gkellogg commented on June 2, 2024

Ok, that makes sense. Thank you for the write-up!

I guess I'm also confused by the fact that I use the SPARQL gem to build queries, and the way it handles the default graph differs from the way our usual triple store handles it.

I'll leave the issue open for that adjustment in the documentation, but other than that, it's good for me.

Some triple stores treat the default graph as the union of all graphs in the dataset, but this is not a normative requirement. You can likely use the MergeGraph class from https://github.com/ruby-rdf/rdf-aggregate-repo/blob/3.3.0/lib/rdf/aggregate_repo/merge_graph.rb to simulate this behavior, but it could also be a pretty trivial wrapper around an RDF::Dataset/Repository as well.

from rdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.