Code Monkey home page Code Monkey logo

Comments (7)

gkellogg avatar gkellogg commented on June 2, 2024 1

Might have some other side-effects, such as caching a value of a list when in the process of modifying the underlying graph, but that might not actually get triggered.

Arguably, graphs shouldn't be mutable at all (and datasets aren't, in fact), but mutating operations should always just yield another graph/repository, but that would break a bunch of contracts.

If you're up for it, why don't you try to implement it your way and see if it passes all the tests. This code mostly pre-dates my involvement.

Also be good to get @no-reply's opinion, or any other lurkers.

from rdf.

gkellogg avatar gkellogg commented on June 2, 2024 1

Probably the best thing is to wrap list operations in a transaction, which can either be committed or aborted.

I'm working on a wrap_transaction option to the List initializer, which will create transaction around the callback, which should do what you want. You can then either commit or abort the transaction to either apply changes atomically or have no writes at all go back to the base graph.

Creating an internal cache for the list and isolating all operations to that cache and requiring a separate commit operation would require more of an extensive rewrite to the class, but could have some performance advantages at the potential for losing changes and having operations not be consistent across other graph queries.

Note that the Notation-3 gem implements RDF::N3::List, which is cached, as in N3, lists are first-class objects, but it's not compatible with repositories that aren't specifically designed to implement it.

from rdf.

gkellogg avatar gkellogg commented on June 2, 2024

It should be the case the it only modifies the graph when initialized with values, or when one of the methods which specifically adds or removes entries is called. Perhaps we need tests to verify this behavior.

Do you have an example which shows it modifying the graph?

from rdf.

doriantaylor avatar doriantaylor commented on June 2, 2024

I'll dig one out in a bit…

from rdf.

doriantaylor avatar doriantaylor commented on June 2, 2024

Ah, okay, looking at the constructor a little more closely: my understanding is if you want to retrieve an existing list from the graph, you pass it the graph: and the subject: which is supposed to be the bnode at the head of the list, and do not pass it any values:, and the list's contents won't get retrieved until you call #to_a.

Reading the code for RDF::List it seems like it's "lazy to read, eager to write", like it's very easy to spur it into making changes to the graph when that might not have been what you wanted.

I think if I were to design an rdf:List implementation I'd be inclined to bias it the other way: you pass the head of the list to the constructor (along with the repo) and it eagerly slurps up and validates the entire thing, and then stores a representation of it internally along with its corresponding bnodes. Any modifications you make to the list do not get published back to the graph until you do something analogous to applying a changeset. (This would also have the added benefit of making RDF::List manipulations more transactable.)

from rdf.

gkellogg avatar gkellogg commented on June 2, 2024

@doriantaylor Let me know if this satisfies your needs; otherwise, we can keep it open for a more extensive change later.

from rdf.

gkellogg avatar gkellogg commented on June 2, 2024

I'm going to close and release this change. We can always re-open or create something else in the future.

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.