Comments (7)
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.
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.
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.
I'll dig one out in a bit…
from rdf.
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.
@doriantaylor Let me know if this satisfies your needs; otherwise, we can keep it open for a more extensive change later.
from rdf.
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)
- RDF::NTriples::Reader does not `require 'strscan'` HOT 3
- Ruby 2.7.1, URI.decode is obsolete
- blank nodes reuse memory addresses, causing problems for persistent stores HOT 3
- Is there a "prettier" HOT 1
- Is there a more 'elegant' way to do this? HOT 3
- Strange "file missing" error with 3.1.14 release HOT 6
- Comparing two repositories HOT 2
- Verbose warnings on 2.7+ Ruby HOT 2
- 3.2.1 removes `RDF::Repository::Implementation::SerializedTransaction` HOT 5
- Is it possible to change the standard prefixes? HOT 7
- docmentation: how to create new vocabs, and langage-tagged strings in vocabs HOT 3
- Weird `require 'enumerator'` issue caused by this gem HOT 5
- change from DateTime < Literal to DateTime < Temporal breaks downstream customization HOT 5
- Invalid argument @ rb_sysopen - (Errno:EINVAL) when using local files on Windows HOT 10
- RDF::Vocabulary.find on RDF vocab returns RDF class HOT 5
- Ruby regexp warning: character class has duplicated range HOT 10
- Errno::EINVAL using `each_statement` with a LARGE, local NTriples file HOT 1
- RDF::Query#graph_name does not behave has documented HOT 3
- Error when using local files on Windows HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rdf.