levelgraph / levelgraph-jsonld

The Object Document Mapper for LevelGraph based on JSON-LD
113 stars 16 forks source link

Graph "scrubbing" is too agressive #45

Closed BigBlueHat closed 7 years ago

BigBlueHat commented 7 years ago

I'm working on a test for this (and understanding more about what changed), but here's the set of steps for playing with on the playground.

  1. empty graph
  2. put
    {"@context": "https://schema.org/", "@id": "http://bigbluehat.com/#", "name": "BigBlueHat"}
  3. expect(triples).to.have.length(1) is true
  4. put
    {"@context": "https://schema.org/", "name": "BigBlueHat"}
  5. expect(triples).to.have.length(2) is false...there's only one. It replaced (maybe?) the original statement that had the ID. 😕
  6. put the JSON-LD from # 2 (above)
  7. expect(triples).to.have.length(2) is true...um...OK...
  8. put the JSON-LD from # 4 (above)...trying again
  9. expect(triples).to.have.length(3) is true...gah! WAT?! I'm back down to 1 😢

Obviously...I'm missing something important here... 😀

@jmatsushita thoughts?

jmatsushita commented 7 years ago

The original put is quite aggressive which is why I've started contributing here and added a preserve option, you might want to use it by default when you open the db. I'm not exactly sure about what happens with step 4 though. It's likely it will be addressed by using preserve: true but it's still a bit mysterious.

BigBlueHat commented 7 years ago

Yeah. I'm adding it as an option to the playground per put().

However, it's currently false in the playground. Which means I've also found this bit of mystery (which you can try in the console on the playground):

  1. Load some stuff into the graph (aka. click the "put" button).
  2. Run this in the console:
    db.jsonld.put('{"@context": "https://schema.org/", "name": "BigBlueHat"}', console.log.bind(console));
  3. Say goodbye the entirety of the graph...except that statement...

Regardless of the above (which I assume are bugs), I think setting preserve to true by default is prudent. I'd much rather have messy data than no data. 😄

jmatsushita commented 7 years ago

Yes I think having preserve to true by default makes sense too. @mcollina Should we go all the way here? (i.e. change the default to preserve true)

jmatsushita commented 7 years ago

@BigBlueHat you might be interested in #46 as well

jmatsushita commented 7 years ago

Ok I've been able to reproduce the problem @BigBlueHat and since I can build the playground now I'll work on a fix.

jmatsushita commented 7 years ago

Well turns out there were several things at play here:

So if you do correct the options and use a "@context" object then things work as expected. I'll get to the fix now.

BigBlueHat commented 7 years ago

New Playground with options settings is up!

Consequently, you'll find some more interesting things...

Basically, there's all kinds of crazy variations depending on where @base shows up, what @id is set to, or if any of its missing.

Right now, the playground is passing in {base: "", preserve: true} by default, fwiw.

Oh, and db and app can be access from the console. app.displayTriples({}) is your friend there. 😄